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 #include <ubfutil.h>
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 exprivate int call_cache(char *dbname, char *key, int interpret)
0070 {
0071 UBFH *p_ub = (UBFH *)tpalloc("UBF", "", 1024);
0072 int ret=EXSUCCEED;
0073 long rcvlen;
0074 char *svcnm;
0075 char cmd = NDRX_CACHE_SVCMD_CLCDUMP;
0076 ndrx_tpcache_data_t cdata;
0077 char *keydata = NULL;
0078 char *data = NULL;
0079 char *odata = NULL;
0080 long olen;
0081
0082 svcnm = ndrx_cache_mgt_getsvc();
0083
0084
0085 if (NULL==p_ub)
0086 {
0087 NDRX_LOG(log_error, "Failed to alloc FB!");
0088 EXFAIL_OUT(ret);
0089 }
0090
0091 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_CMD, 0, &cmd, 0L))
0092 {
0093 NDRX_LOG(log_error, "Failed to install command code: %s",
0094 Bstrerror(Berror));
0095 EXFAIL_OUT(ret);
0096 }
0097
0098 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_DBNAME, 0, dbname, 0L))
0099 {
0100 NDRX_LOG(log_error, "Failed to install db name to buffer: %s",
0101 Bstrerror(Berror));
0102 EXFAIL_OUT(ret);
0103 }
0104
0105 if (EXSUCCEED!=Bchg(p_ub, EX_CACHE_OPEXPR, 0, key, 0L))
0106 {
0107 NDRX_LOG(log_error, "Failed to install key to buffer: %s",
0108 Bstrerror(Berror));
0109 EXFAIL_OUT(ret);
0110 }
0111
0112
0113 if (EXSUCCEED!=tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rcvlen, 0L))
0114 {
0115 if (Bpres(p_ub, EX_TPSTRERROR, 0))
0116 {
0117 fprintf(stderr, "%s\n", Bfind(p_ub, EX_TPSTRERROR, 0, 0L));
0118 }
0119 else
0120 {
0121 NDRX_LOG(log_error, "Failed to call [%s]: %s", svcnm, tpstrerror(tperrno));
0122 fprintf(stderr, "Failed to call cache server [%s]: %s\n",
0123 svcnm, tpstrerror(tperrno));
0124 }
0125
0126 EXFAIL_OUT(ret);
0127 }
0128
0129
0130
0131
0132 if (EXSUCCEED!=ndrx_cache_mgt_ubf2data(p_ub, &cdata, &data, &keydata,
0133 &odata, &olen))
0134 {
0135 NDRX_LOG(log_error, "Failed to get mandatory UBF data!");
0136 EXFAIL_OUT(ret);
0137 }
0138
0139 ndrx_debug_dump_UBF(log_debug, "Got reply buffer", p_ub);
0140
0141
0142 printf("nodeid: %hd\n", cdata.nodeid);
0143 printf("saved_tperrno: %d\n", cdata.saved_tperrno);
0144 printf("saved_tpurcode: %ld\n", cdata.saved_tpurcode);
0145 printf("time_added: %ld (%s)\n", cdata.t, ndrx_get_strtstamp_from_sec(0, cdata.t));
0146 printf("time_added_usec: %ld\n", cdata.tusec);
0147 printf("time_hit: %ld (%s)\n", cdata.hit_t, ndrx_get_strtstamp_from_sec(0, cdata.hit_t));
0148 printf("time_hit_usec: %ld\n", cdata.hit_tusec);
0149 printf("hits: %ld\n", cdata.hits);
0150 printf("atmi_type_id: %hd\n", cdata.atmi_type_id);
0151 printf("atmi_buf_len: %ld\n", cdata.atmi_buf_len);
0152
0153
0154 printf("---------------------------------- HEX DUMP ------------------------------------\n");
0155 STDOUT_DUMP(log_info, "Massage dump", data, cdata.atmi_buf_len);
0156 printf("--------------------------------------------------------------------------------\n\n");
0157
0158 if (interpret)
0159 {
0160 UBFH *p_ubf_h = (UBFH *)odata;
0161
0162
0163 if (BUF_TYPE_UBF==cdata.atmi_type_id)
0164 {
0165 printf("---------------------------------- UBF BUFFER ----------------------------------\n");
0166 Bprint(p_ubf_h);
0167 printf("--------------------------------------------------------------------------------\n");
0168 }
0169 }
0170
0171 out:
0172
0173 if (NULL!=p_ub)
0174 {
0175 tpfree((char *)p_ub);
0176 }
0177
0178 if (NULL!=keydata)
0179 {
0180 NDRX_FREE(keydata);
0181 }
0182
0183 if (NULL!=odata)
0184 {
0185 tpfree(odata);
0186 }
0187
0188 if (NULL!=data)
0189 {
0190 NDRX_FREE(data);
0191 }
0192
0193 return ret;
0194 }
0195
0196
0197
0198
0199
0200
0201
0202
0203 expublic int cmd_cd(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0204 {
0205 int ret=EXSUCCEED;
0206 char dbname[NDRX_CCTAG_MAX+1]={EXEOS};
0207 char key[PATH_MAX+1]={EXEOS};
0208 int interpret = EXFALSE;
0209 ncloptmap_t clopt[] =
0210 {
0211 {'d', BFLD_STRING, (void *)dbname, sizeof(dbname),
0212 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Database name"},
0213 {'k', BFLD_STRING, (void *)key, sizeof(key),
0214 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Key string"},
0215
0216
0217
0218
0219 {'i', BFLD_SHORT, (void *)&interpret, sizeof(interpret),
0220 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Interpret?"},
0221 {0}
0222 };
0223
0224
0225 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0226 {
0227 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0228 EXFAIL_OUT(ret);
0229 }
0230
0231
0232 if (EXSUCCEED!=tpinit(NULL))
0233 {
0234 fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0235 EXFAIL_OUT(ret);
0236 }
0237
0238 if (EXSUCCEED!=call_cache(dbname, key, interpret))
0239 {
0240 NDRX_LOG(log_debug, "Failed to call cache server for db [%s]", dbname);
0241 fprintf(stderr, "Failed to call cache server!\n");
0242 EXFAIL_OUT(ret);
0243 }
0244
0245 out:
0246 return ret;
0247 }
0248
0249