Annotation of embedtools/src/xmler.c, revision 1.1.2.3
1.1.2.1 misho 1: #include "global.h"
1.1.2.2 misho 2: #include <axl.h>
3: #include <axl_ns.h>
4: #include <axl_decl.h>
5: #include "xmler.h"
1.1.2.1 misho 6:
7:
1.1.2.2 misho 8: int Verbose;
9: extern char compiled[], compiledby[], compilehost[];
10:
11:
12: static void Usage()
13: {
14:
15: printf( "XMLer is tool for managment R/W operation with XMLs\n"
16: "=== %s === %s@%s ===\n\n"
17: " Syntax: xmler [options] <file.xml> [data]\n\n"
18: "\t-v\t\tVerbose ...\n"
19: "\t-s <av_pair>\tSet Attribute/Value pair\n"
20: "\t-g <av_pair>\tGet Attribute/Value pair\n"
21: "*\"av_pair\" format: [ns:]node[[|attribute[=value]]?data]\n"
22: "\n", compiled, compiledby, compilehost);
23: }
24:
1.1.2.1 misho 25: int
26: main(int argc, char **argv)
27: {
1.1.2.2 misho 28: char ch, *ctx, str[STRSIZ], szName[MAXPATHLEN], m = 0;
1.1.2.3 ! misho 29: int ctxlen, n, ret = 0;
1.1.2.2 misho 30: axlDoc *doc = NULL;
31: axlError *err = NULL;
32: axlNode *node = NULL;
33: struct tagReqXML xr;
34:
35: memset(str, 0, STRSIZ);
36: memset(&xr, 0, sizeof xr);
37: while ((ch = getopt(argc, argv, "hvs:g:")) != -1)
38: switch (ch) {
39: case 'v':
40: Verbose++;
41: break;
42: case 's':
43: if (m) {
44: Usage();
45: return 1;
46: } else
47: m = 's';
48: strlcpy(str, optarg, STRSIZ);
49: if ((ret = ioXMLGet(str, &xr)) < 1) {
50: printf("Error:: in XML request %s\n", str);
51: return 1;
52: }
53: VERB(3) printf("Verbose(3):: XMLGet=0x%x\n", ret);
54: break;
55: case 'g':
56: if (m) {
57: Usage();
58: return 1;
59: } else
60: m = 'g';
61: strlcpy(str, optarg, STRSIZ);
62: if ((ret = ioXMLGet(str, &xr)) < 1) {
63: printf("Error:: in XML request %s\n", str);
64: return 1;
65: }
66: VERB(3) printf("Verbose(3):: XMLGet=0x%x\n", ret);
67: break;
68: case 'h':
69: default:
70: Usage();
71: return 1;
72: }
73: argc -= optind;
74: argv += optind;
75: if (!argc) {
76: Usage();
77: return 1;
78: } else
79: strlcpy(szName, *argv, MAXPATHLEN);
80: if (argc > 1 && argv[1]) {
81: xr.xml_data.value = argv[1];
82: xr.xml_data.vallen = strlen(argv[1]);
83: }
84:
85: axl_init();
86: if (!(doc = axl_doc_parse_from_file(szName, &err))) {
87: printf("Error:: xml file %s #%d - %s\n", szName,
88: axl_error_get_code(err), axl_error_get(err));
89: axl_error_free(err);
90: axl_end();
91: return 2;
92: }
93: if (!axl_ns_doc_validate(doc, &err)) {
94: printf("Error:: xml file %s namespace validation #%d - %s\n", szName,
95: axl_error_get_code(err), axl_error_get(err));
96: axl_error_free(err);
97: axl_end();
98: return 2;
99: }
100:
101: switch (m) {
102: case 's':
103: break;
104: case 'g':
105: if (!xr.xml_namespace.vallen) {
1.1.2.3 ! misho 106: if (ret == 32) {
! 107: if (!(ctx = (char*) axl_doc_get_content_at(doc, xr.xml_node.path.value, &ctxlen))) {
! 108: printf("GET:: path %s - not found!\n", xr.xml_node.path.value);
! 109: ret = 1;
! 110: goto end;
! 111: }
! 112: } else {
! 113: if (!(node = axl_doc_find_called(doc, xr.xml_node.container.value))) {
! 114: printf("GET:: node %s - not found!\n", xr.xml_node.container.value);
! 115: ret = 1;
! 116: goto end;
! 117: }
1.1.2.2 misho 118: }
119: } else {
120: strlcpy(str, xr.xml_namespace.value, sizeof str);
121: strlcat(str, ":", sizeof str);
1.1.2.3 ! misho 122: strlcat(str, xr.xml_node.container.value, sizeof str);
! 123: if (ret == 32) {
! 124: if (!(ctx = (char*) axl_doc_get_content_at(doc, str, &ctxlen))) {
! 125: printf("GET:: path %s:%s - not found!\n", xr.xml_namespace.value,
! 126: xr.xml_node.path.value);
! 127: ret = 1;
! 128: goto end;
! 129: }
! 130: } else {
! 131: if (!(node = axl_doc_find_called(doc, str))) {
! 132: printf("GET:: node %s:%s - not found!\n", xr.xml_namespace.value,
! 133: xr.xml_node.container.value);
! 134: ret = 1;
! 135: goto end;
! 136: }
1.1.2.2 misho 137: }
138: }
139:
1.1.2.3 ! misho 140: if (!(ret & 32) && xr.xml_data.vallen) {
1.1.2.2 misho 141: if (!(ctx = (char*) axl_node_get_content(node, &ctxlen))) {
142: printf("GET:: data %s for node %s - not found!\n",
1.1.2.3 ! misho 143: xr.xml_data.value, xr.xml_node.container.value);
1.1.2.2 misho 144: ret = 1;
145: goto end;
146: } else
147: VERB(3) printf("Verbose(3):: Returned bytes %d\n", ctxlen);
148:
149: VERB(1) printf("\n");
1.1.2.3 ! misho 150: if (!strcmp(ctx, xr.xml_data.value))
1.1.2.2 misho 151: printf("DATA::1\n");
152: else
153: printf("DATA::0\n");
154: }
155:
1.1.2.3 ! misho 156: if (!(ret & 32) && xr.xml_attribute.vallen) {
! 157: if ((n = axl_node_num_attributes(node)) < 1) {
1.1.2.2 misho 158: printf("GET:: attribute %s for node %s - not found!\n",
1.1.2.3 ! misho 159: xr.xml_attribute.value, xr.xml_node.container.value);
1.1.2.2 misho 160: ret = 1;
161: goto end;
162: } else {
1.1.2.3 ! misho 163: VERB(1) printf("Verbose:: node have %d attributes\n", n);
1.1.2.2 misho 164:
165: if (!(ctx = (char*) axl_node_get_attribute_value(node, xr.xml_attribute.value))) {
166: printf("GET:: attribute %s for node %s - not found!\n",
1.1.2.3 ! misho 167: xr.xml_attribute.value, xr.xml_node.container.value);
1.1.2.2 misho 168: ret = 1;
169: goto end;
170: }
171:
172: if (xr.xml_value.vallen) {
1.1.2.3 ! misho 173: if (!strcmp(ctx, xr.xml_value.value))
1.1.2.2 misho 174: ctx = "VALUE::1";
175: else
176: ctx = "VALUE::0";
177: }
178: }
179: } else {
1.1.2.3 ! misho 180: if (!(ret & 32) && !(ctx = (char*) axl_node_get_content(node, &ctxlen))) {
! 181: printf("GET:: data for node %s - not found!\n", xr.xml_node.container.value);
! 182: ret = 1;
! 183: goto end;
! 184: } else
! 185: VERB(3) printf("Verbose(3):: Returned bytes %d\n", ctxlen);
1.1.2.2 misho 186: }
187:
188: VERB(1) printf("\n");
189: printf("%s\n", ctx);
190: ret = 0;
191: break;
192: default:
1.1.2.3 ! misho 193: if (xr.xml_data.vallen) {
! 194: if (!(node = axl_doc_find_called(doc, xr.xml_data.value))) {
! 195: printf("GET:: node %s - not found!\n", xr.xml_data.value);
! 196: ret = 1;
! 197: goto end;
! 198: }
! 199: axl_node_dump_pretty(node, &ctx, &ctxlen, 4);
! 200: VERB(1) printf("Verbose:: Node length=%d\n", ctxlen);
! 201: } else {
! 202: axl_doc_dump_pretty(doc, &ctx, &ctxlen, 4);
! 203: VERB(1) printf("Verbose:: Document length=%d\n", ctxlen);
! 204: }
1.1.2.2 misho 205:
206: VERB(1) printf("\n");
207: printf("%s\n", ctx);
1.1.2.3 ! misho 208: if (ctx)
! 209: free(ctx);
1.1.2.2 misho 210: }
211: end:
212: axl_doc_free(doc);
213: axl_end();
214: return ret;
1.1.2.1 misho 215: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>