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 "tpadmsv.h"
0052 #include <ndrx.h>
0053 #include <qcommon.h>
0054 #include <nclopt.h>
0055 #include <tpadm.h>
0056 #include <ubfutil.h>
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 expublic int cmd_mibget(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0072 {
0073 int ret = EXSUCCEED;
0074 char clazz[MAXTIDENT+1];
0075 char lmid[MAXTIDENT+1] = {EXEOS};
0076 UBFH *p_ub = NULL;
0077 UBFH *p_ub_rsp = NULL;
0078 long have_more = EXTRUE;
0079 long flags = 0;
0080 int first = EXTRUE;
0081 long cnt = 0;
0082 long rsplen;
0083 short machine_fmt = EXFALSE;
0084 int i, j;
0085 char tmpbuf[1024];
0086 BFLDLEN flen;
0087 char msg[MAX_TP_ERROR_LEN+1] = {EXEOS};
0088 long fldid = 0;
0089 long error_code = 0;
0090 ndrx_adm_class_map_t *clazz_descr;
0091 ndrx_growlist_t table;
0092 ndrx_growlist_t coltypes;
0093
0094 ncloptmap_t clopt[] =
0095 {
0096 {'c', BFLD_STRING, clazz, sizeof(clazz),
0097 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Class name"},
0098
0099
0100
0101
0102 {'m', BFLD_SHORT, (void *)&machine_fmt, 0,
0103 NCLOPT_OPT | NCLOPT_TRUEBOOL, "Machine output"},
0104 {0}
0105 };
0106
0107
0108 ndrx_tab_init(&table);
0109 ndrx_growlist_init(&coltypes, 100, sizeof(long));
0110
0111
0112 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0113 {
0114 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0115 EXFAIL_OUT(ret);
0116 }
0117
0118
0119 if (EXSUCCEED!=tpinit(NULL))
0120 {
0121 fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0122 EXFAIL_OUT(ret);
0123 }
0124
0125
0126 clazz_descr = ndrx_adm_class_map_get(clazz);
0127
0128
0129 p_ub = (UBFH *)tpalloc("UBF", NULL, 0);
0130
0131 if (NULL==p_ub)
0132 {
0133 fprintf(stderr, "Failed to allocate call buffer: %s\n", tpstrerror(tperrno));
0134 EXFAIL_OUT(ret);
0135 }
0136
0137 if (EXEOS!=lmid[0])
0138 {
0139 flags|=MIB_LOCAL;
0140 }
0141
0142
0143
0144 if (EXFAIL==Bchg(p_ub, TA_OPERATION, 0, NDRX_TA_GET, 0L)
0145 || EXFAIL==Bchg(p_ub, TA_CLASS, 0, clazz, 0)
0146 || EXFAIL==Bchg(p_ub, TA_FLAGS, 0, (char *)&flags, 0)
0147 || (EXEOS!=lmid[0] && EXFAIL==Bchg(p_ub, TA_LMID, 0, lmid, 0))
0148 )
0149 {
0150 NDRX_LOG(log_error, "Failed to setup UBF buffer: %s", Bstrerror(Berror));
0151 fprintf(stderr, "Failed to setup UBF buffer: %s\n", Bstrerror(Berror));
0152 EXFAIL_OUT(ret);
0153 }
0154
0155 while (have_more)
0156 {
0157 have_more = 0;
0158
0159 ndrx_debug_dump_UBF(log_info, ".TMIB Request buffer:", p_ub);
0160
0161 if (EXFAIL==tpcall(NDRX_SVC_TMIB, (char *)p_ub, 0,
0162 (char **)&p_ub_rsp, &rsplen, 0))
0163 {
0164 if (TPESVCFAIL==tperrno && NULL!=p_ub_rsp)
0165 {
0166
0167 ndrx_debug_dump_UBF(log_info, ".TMIB Response (ERR) buffer:", p_ub_rsp);
0168
0169
0170 Bget(p_ub_rsp, TA_ERROR, 0, (char *)&error_code, 0L);
0171 Bget(p_ub_rsp, TA_STATUS, 0, msg, 0L);
0172 Bget(p_ub_rsp, TA_BADFLD, 0, (char *)&fldid, 0L);
0173
0174 fprintf(stderr, "TMIB failed with %ld on field %u: %s\n",
0175 error_code, (unsigned int)fldid, msg);
0176 EXFAIL_OUT(ret);
0177 }
0178 else
0179 {
0180 NDRX_LOG(log_error, "Failed to call [%s]: %s", NDRX_SVC_TMIB,
0181 tpstrerror(tperrno));
0182 fprintf(stderr, "Failed to call [%s]: %s\n", NDRX_SVC_TMIB,
0183 tpstrerror(tperrno));
0184 }
0185
0186 EXFAIL_OUT(ret);
0187 }
0188
0189 ndrx_debug_dump_UBF(log_info, ".TMIB Response buffer:", p_ub_rsp);
0190
0191
0192 if (EXSUCCEED!=Bget(p_ub_rsp, TA_OCCURS, 0, (char *)&cnt, NULL))
0193 {
0194 NDRX_LOG(log_error, "Failed to get TA_OCCURS: %s", Bstrerror(Berror));
0195 fprintf(stderr, "Failed to get TA_OCCURS: %s\n", Bstrerror(Berror));
0196 EXFAIL_OUT(ret);
0197 }
0198
0199 if (EXSUCCEED!=Bget(p_ub_rsp, TA_MORE, 0, (char *)&have_more, NULL))
0200 {
0201 NDRX_LOG(log_error, "Failed to get TA_MORE: %s", Bstrerror(Berror));
0202 fprintf(stderr, "Failed to get TA_MORE: %s\n", Bstrerror(Berror));
0203 EXFAIL_OUT(ret);
0204 }
0205
0206 if (first)
0207 {
0208
0209 for (i=0; BBADFLDID!=clazz_descr->fields_map[i].fid; i++)
0210 {
0211 long typ;
0212
0213 if (machine_fmt)
0214 {
0215 fprintf(stderr, "%s|", clazz_descr->fields_map[i].name);
0216 }
0217 else
0218 {
0219
0220 if (EXSUCCEED!=ndrx_tab_add_col(&table, i,
0221 clazz_descr->fields_map[i].name))
0222 {
0223 fprintf(stderr, "Failed to prepare results\n");
0224 }
0225
0226 typ = Bfldtype(clazz_descr->fields_map[i].fid);
0227
0228 if (TA_DOMAINID==clazz_descr->fields_map[i].fid ||
0229 TA_LMID==clazz_descr->fields_map[i].fid)
0230 {
0231
0232 typ=BFLD_SHORT;
0233 }
0234
0235
0236 if (EXSUCCEED!=ndrx_growlist_add(&coltypes, (char *)&typ,
0237 coltypes.maxindexused+1))
0238 {
0239 NDRX_LOG(log_error, "Failed to add column type code");
0240 fprintf(stderr, "Failed to add column type code\n");
0241 EXFAIL_OUT(ret);
0242 }
0243 }
0244 }
0245
0246 if (machine_fmt)
0247 {
0248 fprintf(stderr, "\n");
0249 }
0250
0251 first = EXFALSE;
0252 }
0253
0254 if (cnt > 0)
0255 {
0256
0257 for (i=0; i<cnt; i++)
0258 {
0259 for (j=0; BBADFLDID!=clazz_descr->fields_map[j].fid; j++)
0260 {
0261 flen = sizeof(tmpbuf);
0262
0263 if (EXSUCCEED!=CBget(p_ub_rsp, clazz_descr->fields_map[j].fid,
0264 i, tmpbuf, &flen, BFLD_STRING))
0265 {
0266
0267 NDRX_LOG(log_error, "Failed to get [%s] at %d occ: %s",
0268 Bfname(clazz_descr->fields_map[j].fid), i,
0269 Bstrerror(Berror));
0270
0271 fprintf(stderr, "Failed to get [%s] at %d occ\n",
0272 Bfname(clazz_descr->fields_map[j].fid), i);
0273 EXFAIL_OUT(ret);
0274 }
0275
0276 if (machine_fmt)
0277 {
0278 fprintf(stdout, "%s|", tmpbuf);
0279 }
0280 else
0281 {
0282
0283 if (EXSUCCEED!=ndrx_tab_add_col(&table, j, tmpbuf))
0284 {
0285 fprintf(stderr, "Failed to prepare results\n");
0286 }
0287 }
0288 }
0289
0290 if (machine_fmt)
0291 {
0292 fprintf(stdout, "\n");
0293 }
0294 }
0295 }
0296
0297 if (have_more)
0298 {
0299 char cursid[MAXTIDENT+1];
0300
0301 if (EXSUCCEED!=Bchg(p_ub, TA_OPERATION, 0, NDRX_TA_GETNEXT, 0L))
0302 {
0303 NDRX_LOG(log_error, "Failed to setup UBF buffer: %s",
0304 Bstrerror(Berror));
0305 fprintf(stderr, "Failed to setup UBF buffer: %s\n",
0306 Bstrerror(Berror));
0307 EXFAIL_OUT(ret);
0308 }
0309
0310 flen = sizeof(cursid);
0311
0312 if (EXSUCCEED!=Bget(p_ub_rsp, TA_CURSOR, 0, cursid, &flen))
0313 {
0314 NDRX_LOG(log_error, "Failed to get TA_CURSOR: %s",
0315 Bstrerror(Berror));
0316 fprintf(stderr, "Failed to get TA_CURSOR: %s\n",
0317 Bstrerror(Berror));
0318 EXFAIL_OUT(ret);
0319 }
0320
0321 if (EXSUCCEED!=Bchg(p_ub, TA_CURSOR, 0, cursid, 0L))
0322 {
0323 NDRX_LOG(log_error, "Failed to setup TA_CURSOR: %s",
0324 Bstrerror(Berror));
0325 fprintf(stderr, "Failed to setup TA_CURSOR: %s\n",
0326 Bstrerror(Berror));
0327 EXFAIL_OUT(ret);
0328 }
0329 }
0330 }
0331
0332 if (!machine_fmt)
0333 {
0334 ndrx_tab_print(&table, &coltypes);
0335 }
0336 out:
0337
0338 if (NULL!=p_ub)
0339 {
0340 tpfree((char *)p_ub);
0341 }
0342
0343 if (NULL!=p_ub_rsp)
0344 {
0345 tpfree((char *)p_ub_rsp);
0346 }
0347
0348 ndrx_tab_free(&table);
0349 ndrx_growlist_free(&coltypes);
0350
0351
0352 return ret;
0353 }
0354
0355