0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <nstdutil.h>
0043
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <utlist.h>
0048 #include <Exfields.h>
0049
0050 #include "xa_cmn.h"
0051 #include "nclopt.h"
0052 #include <ndrx.h>
0053 #include <qcommon.h>
0054 #include <atmi_cache.h>
0055 #include <typed_buf.h>
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 exprivate int call_cache(char *dbname, char *key, int regexp)
0069 {
0070 UBFH *p_ub = (UBFH *)tpalloc("UBF", "", 1024);
0071 int ret=EXSUCCEED;
0072 long rcvlen;
0073 char *svcnm;
0074 char cmd = NDRX_CACHE_SVCMD_CLDEL;
0075 long flags = 0;
0076 long deleted;
0077
0078 svcnm = ndrx_cache_mgt_getsvc();
0079
0080
0081 if (NULL==p_ub)
0082 {
0083 NDRX_LOG(log_error, "Failed to alloc FB!");
0084 EXFAIL_OUT(ret);
0085 }
0086
0087 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_CMD, 0, &cmd, 0L))
0088 {
0089 NDRX_LOG(log_error, "Failed to install command code: %s",
0090 Bstrerror(Berror));
0091 EXFAIL_OUT(ret);
0092 }
0093
0094 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_DBNAME, 0, dbname, 0L))
0095 {
0096 NDRX_LOG(log_error, "Failed to install db name to buffer: %s",
0097 Bstrerror(Berror));
0098 EXFAIL_OUT(ret);
0099 }
0100
0101
0102 if (EXEOS!=key[0])
0103 {
0104 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_OPEXPR, 0, key, 0L))
0105 {
0106 NDRX_LOG(log_error, "Failed to install key to buffer: %s",
0107 Bstrerror(Berror));
0108 EXFAIL_OUT(ret);
0109 }
0110 }
0111
0112 if (regexp)
0113 {
0114 flags|=NDRX_CACHE_SVCMDF_DELREG;
0115 }
0116
0117 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_FLAGS, 0, (char *)&flags, 0L))
0118 {
0119 NDRX_LOG(log_error, "Failed to set EX_CACHE_FLAGS: %s",
0120 Bstrerror(Berror));
0121 EXFAIL_OUT(ret);
0122 }
0123
0124
0125 if (EXSUCCEED!=tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rcvlen, 0L))
0126 {
0127 NDRX_LOG(log_error, "Failed to call [%s]: %s", svcnm, tpstrerror(tperrno));
0128 fprintf(stderr, "Failed to call cache server [%s]: %s\n",
0129 svcnm, tpstrerror(tperrno));
0130
0131 if (Bpres(p_ub, EX_TPSTRERROR, 0))
0132 {
0133 fprintf(stderr, "%s\n", Bfind(p_ub, EX_TPSTRERROR, 0, 0L));
0134 }
0135
0136 EXFAIL_OUT(ret);
0137 }
0138
0139 if (Bpres(p_ub, EX_CACHE_NRDEL, 0))
0140 {
0141 if (EXSUCCEED!=Bget(p_ub, EX_CACHE_NRDEL, 0, (char *)&deleted, 0L))
0142 {
0143 NDRX_LOG(log_error, "Failed to get EX_CACHE_NRDEL: %s",
0144 Bstrerror(Berror));
0145 fprintf(stderr, "WARNING: Failed to get delete results from EX_CACHE_NRDEL: %s\n",
0146 Bstrerror(Berror));
0147 }
0148 else
0149 {
0150 fprintf(stderr, "%ld records deleted\n", deleted);
0151 }
0152 }
0153
0154 out:
0155
0156 if (NULL!=p_ub)
0157 {
0158 tpfree((char *)p_ub);
0159 }
0160
0161 return ret;
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171 expublic int cmd_ci(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0172 {
0173 int ret=EXSUCCEED;
0174 char dbname[NDRX_CCTAG_MAX+1]={EXEOS};
0175 char key[PATH_MAX+1]={EXEOS};
0176 int regex = EXFALSE;
0177 ncloptmap_t clopt[] =
0178 {
0179 {'d', BFLD_STRING, (void *)dbname, sizeof(dbname),
0180 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Database name"},
0181 {'k', BFLD_STRING, (void *)key, sizeof(key),
0182 NCLOPT_OPT|NCLOPT_HAVE_VALUE, "Key string"},
0183
0184
0185
0186
0187 {'r', BFLD_SHORT, (void *)®ex, sizeof(regex),
0188 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Use regexp?"},
0189 {0}
0190 };
0191
0192
0193 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0194 {
0195 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0196 EXFAIL_OUT(ret);
0197 }
0198
0199
0200 if (EXSUCCEED!=tpinit(NULL))
0201 {
0202 fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0203 EXFAIL_OUT(ret);
0204 }
0205
0206 if (EXSUCCEED!=call_cache(dbname, key, regex))
0207 {
0208 NDRX_LOG(log_debug, "Failed to call cache server for db [%s]", dbname);
0209 fprintf(stderr, "Failed to call cache server!\n");
0210 EXFAIL_OUT(ret);
0211 }
0212
0213 out:
0214 return ret;
0215 }
0216
0217