version 1.1.2.5, 2010/09/28 12:38:34
|
version 1.1.2.9, 2010/09/29 16:38:08
|
Line 1
|
Line 1
|
|
/************************************************************************* |
|
* (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com> |
|
* by Michael Pounov <misho@aitbg.com> |
|
* |
|
* $Author$ |
|
* $Id$ |
|
* |
|
*************************************************************************/ |
#include "global.h" |
#include "global.h" |
#include <axl.h> |
#include <axl.h> |
#include <axl_ns.h> |
#include <axl_ns.h> |
Line 17 Usage()
|
Line 25 Usage()
|
"=== %s === %s@%s ===\n\n" |
"=== %s === %s@%s ===\n\n" |
" Syntax: xmler [options] <file.xml> [data]\n\n" |
" Syntax: xmler [options] <file.xml> [data]\n\n" |
"\t-v\t\tVerbose ...\n" |
"\t-v\t\tVerbose ...\n" |
|
"\t-l <av_pair>\tList node\n" |
"\t-d <av_pair>\tDelete node\n" |
"\t-d <av_pair>\tDelete node\n" |
"\t-s <av_pair>\tSet node command\n" |
"\t-s <av_pair>\tSet node command\n" |
"\t-g <av_pair>\tGet node command\n" |
"\t-g <av_pair>\tGet node command\n" |
Line 53 ShowXML(axlDoc *doc, const char *csNode)
|
Line 62 ShowXML(axlDoc *doc, const char *csNode)
|
return 0; |
return 0; |
} |
} |
|
|
|
static int |
|
ShowItem(axlNode *node, int lvl) |
|
{ |
|
register int i; |
|
int ctxlen; |
|
axlNode *child; |
|
|
|
for (i = 0; i < axl_node_get_child_num(node); i++) { |
|
child = axl_node_get_child_nth(node, i); |
|
|
|
if (!lvl) |
|
printf("%s %s \"%s\"", axl_node_get_name(node), axl_node_get_name(child), |
|
axl_node_get_content(child, &ctxlen)); |
|
else |
|
printf(" %s \"%s\"", axl_node_get_name(child), axl_node_get_content(child, &ctxlen)); |
|
|
|
ShowItem(child, 1); |
|
|
|
if (!lvl) |
|
printf("\n"); |
|
} |
|
|
|
return 0; |
|
} |
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
char ch, *ctx, str[STRSIZ], szName[MAXPATHLEN], m = 0; | char ch, str[STRSIZ], szName[MAXPATHLEN], *ctx = NULL, m = 0; |
int ctxlen, n, ret = 0; |
int ctxlen, n, ret = 0; |
axlDoc *doc = NULL; |
axlDoc *doc = NULL; |
axlError *err = NULL; |
axlError *err = NULL; |
Line 65 main(int argc, char **argv)
|
Line 99 main(int argc, char **argv)
|
|
|
memset(str, 0, STRSIZ); |
memset(str, 0, STRSIZ); |
memset(&xr, 0, sizeof xr); |
memset(&xr, 0, sizeof xr); |
while ((ch = getopt(argc, argv, "hvs:g:d:")) != -1) | while ((ch = getopt(argc, argv, "hvl:s:g:d:")) != -1) |
switch (ch) { |
switch (ch) { |
case 'v': |
case 'v': |
Verbose++; |
Verbose++; |
break; |
break; |
|
case 'l': |
|
if (m) { |
|
Usage(); |
|
return 1; |
|
} else |
|
m = 'l'; |
|
strlcpy(str, optarg, STRSIZ); |
|
if ((ret = ioXMLGet(str, &xr)) < 1) { |
|
printf("Error:: in XML request %s\n", str); |
|
return 1; |
|
} |
|
VERB(3) printf("Verbose(3):: XMLGet=0x%x\n", ret); |
|
break; |
case 'd': |
case 'd': |
if (m) { |
if (m) { |
Usage(); |
Usage(); |
Line 272 main(int argc, char **argv)
|
Line 319 main(int argc, char **argv)
|
break; |
break; |
case 's': |
case 's': |
if (ret == 32) { |
if (ret == 32) { |
if (!(nnode = axl_node_create(xr.xml_data.value))) { | if (!xr.xml_data.vallen || !(nnode = axl_node_create(xr.xml_data.value))) { |
printf("SET:: container %s at path %s - Error!\n", |
printf("SET:: container %s at path %s - Error!\n", |
xr.xml_data.value, xr.xml_node.path.value); |
xr.xml_data.value, xr.xml_node.path.value); |
ret = 1; |
ret = 1; |
Line 332 main(int argc, char **argv)
|
Line 379 main(int argc, char **argv)
|
if (ret & 32) |
if (ret & 32) |
axl_node_set_child(node, nnode); |
axl_node_set_child(node, nnode); |
ret = ShowXML(doc, NULL); |
ret = ShowXML(doc, NULL); |
|
break; |
|
case 'l': |
|
if (!xr.xml_namespace.vallen) { |
|
if (ret == 32) { |
|
if (!(node = axl_doc_get(doc, xr.xml_node.path.value))) { |
|
printf("DEL:: path %s - not found!\n", xr.xml_node.path.value); |
|
ret = 1; |
|
goto end; |
|
} |
|
} else { |
|
if (!(node = axl_doc_find_called(doc, xr.xml_node.container.value))) { |
|
printf("DEL:: node %s - not found!\n", xr.xml_node.container.value); |
|
ret = 1; |
|
goto end; |
|
} |
|
} |
|
} else { |
|
strlcpy(str, xr.xml_namespace.value, sizeof str); |
|
strlcat(str, ":", sizeof str); |
|
strlcat(str, xr.xml_node.container.value, sizeof str); |
|
if (ret == 32) { |
|
if (!(node = axl_doc_get(doc, str))) { |
|
printf("DEL:: path %s:%s - not found!\n", xr.xml_namespace.value, |
|
xr.xml_node.path.value); |
|
ret = 1; |
|
goto end; |
|
} |
|
} else { |
|
if (!(node = axl_doc_find_called(doc, str))) { |
|
printf("DEL:: node %s:%s - not found!\n", xr.xml_namespace.value, |
|
xr.xml_node.container.value); |
|
ret = 1; |
|
goto end; |
|
} |
|
} |
|
} |
|
|
|
ret = ShowItem(node, 0); |
break; |
break; |
default: |
default: |
ret = ShowXML(doc, xr.xml_data.vallen ? xr.xml_data.value : NULL); |
ret = ShowXML(doc, xr.xml_data.vallen ? xr.xml_data.value : NULL); |