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
0043 #include <ndrx.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <nclopt.h>
0048 #include <ubf.h>
0049 #include <exdb.h>
0050 #include <fdatatype.h>
0051 #include <cconfig.h>
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 expublic int cmd_pubfdb(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0068 {
0069 int ret=EXSUCCEED;
0070 EDB_env * dbenv;
0071 EDB_dbi *dbi_id, *dbi_nm;
0072 EDB_txn *txn = NULL;
0073 EDB_cursor * cursor;
0074 int tran_started = EXFALSE;
0075 EDB_cursor_op op;
0076 EDB_val keydb, data;
0077 int cursor_open = EXFALSE;
0078 BFLDID bfldid;
0079 BFLDID bfldno;
0080 short fldtype;
0081 char fldname[UBFFLDMAX+1];
0082 int first = EXTRUE;
0083
0084
0085 if (EXFAIL==(ret=Bflddbload()))
0086 {
0087 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "Failed to load UBF field database: %s\n",
0088 Bstrerror(Berror));
0089 EXFAIL_OUT(ret);
0090 }
0091
0092 if (EXTRUE!=ret)
0093 {
0094 fprintf(stderr, "WARNING ! No configuration defined for UBF DB!\n");
0095 goto out;
0096 }
0097
0098
0099 ret = EXSUCCEED;
0100
0101
0102 if (NULL==(dbenv=Bfldddbgetenv(&dbi_id, &dbi_nm)))
0103 {
0104 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "Failed to load UBF DB env handler: %s\n",
0105 Bstrerror(Berror));
0106 EXFAIL_OUT(ret);
0107 }
0108
0109
0110 if (EXSUCCEED!=(ret=edb_txn_begin(dbenv, NULL, EDB_RDONLY, &txn)))
0111 {
0112 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "Failed to start LMDB transaction: %s\n",
0113 edb_strerror(ret));
0114 EXFAIL_OUT(ret);
0115 }
0116
0117 tran_started = EXTRUE;
0118
0119
0120
0121 if (EXSUCCEED!=(ret=edb_cursor_open(txn, *dbi_nm, &cursor)))
0122 {
0123 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "Failed to open cursor: %s\n",
0124 edb_strerror(ret));
0125 EXFAIL_OUT(ret);
0126 }
0127 cursor_open = EXTRUE;
0128
0129 op = EDB_FIRST;
0130 do
0131 {
0132 if (EXSUCCEED!=(ret=edb_cursor_get(cursor, &keydb, &data, op)))
0133 {
0134 if (ret!=EDB_NOTFOUND)
0135 {
0136 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "cursor get failed: %s\n",
0137 edb_strerror(ret));
0138 }
0139 goto out;
0140 }
0141
0142 if (EXSUCCEED!=Bflddbget(&data, &fldtype, &bfldno, &bfldid,
0143 fldname, sizeof(fldname)))
0144 {
0145 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "failed to decode db data: %s\n",
0146 Bstrerror(Berror));
0147 EXFAIL_OUT(ret);
0148 }
0149
0150
0151 if (first)
0152 {
0153 fprintf(stderr, "NO ID TYPE Field Name\n");
0154 fprintf(stderr, "---------- ---------- ---------- --------------------\n");
0155 first = EXFALSE;
0156 }
0157 printf("%-10d %-10d %-10.10s %s\n",
0158 bfldno, bfldid, G_dtype_str_map[fldtype].fldname, fldname);
0159
0160 if (EDB_FIRST == op)
0161 {
0162 op = EDB_NEXT;
0163 }
0164
0165 } while (EXSUCCEED==ret);
0166
0167 out:
0168
0169 if (cursor_open)
0170 {
0171 edb_cursor_close(cursor);
0172 }
0173
0174 if (tran_started)
0175 {
0176 edb_txn_abort(txn);
0177 }
0178
0179 Bflddbunload();
0180
0181 return ret;
0182 }
0183