Browse code

msxml: finished keyinfo type handling msxml: fixed wrkptr json keyinfo type

Kevin Lin authored on 2015/03/14 00:23:40
Showing 2 changed files
... ...
@@ -82,7 +82,7 @@ static const struct key_entry *msxml_check_key(struct msxml_ctx *mxctx, const ch
82 82
     return &blank_key;
83 83
 }
84 84
 
85
-static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader, int rlvl)
85
+static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader, int rlvl, void *jptr)
86 86
 {
87 87
     const xmlChar *element_name = NULL;
88 88
     const xmlChar *node_name = NULL, *node_value = NULL;
... ...
@@ -90,8 +90,10 @@ static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader,
90 90
     int ret, state, node_type, endtag = 0;
91 91
     cli_ctx *ctx = mxctx->ctx;
92 92
 #if HAVE_JSON
93
-    json_object *parent = mxctx->wrkptr;
93
+    json_object *parent = (json_object *)jptr;
94 94
     json_object *thisjobj = NULL;
95
+#else
96
+    void *thisjobj = NULL;
95 97
 #endif
96 98
 
97 99
     cli_msxmlmsg("in msxml_parse_element @ layer %d\n", rlvl);
... ...
@@ -131,13 +133,22 @@ static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader,
131 131
 
132 132
         cli_msxmlmsg("key:  %s\n", keyinfo->key);
133 133
         cli_msxmlmsg("name: %s\n", keyinfo->name);
134
-        cli_msxmlmsg("type: %d\n", keyinfo->type);
134
+        cli_msxmlmsg("type: 0x%x\n", keyinfo->type);
135
+
136
+        /* element and contents are ignored */
137
+        if (keyinfo->type & MSXML_IGNORE_ELEM) {
138
+            cli_msxmlmsg("msxml_parse_element: IGNORING ELEMENT %s\n", keyinfo->name);
139
+
140
+            state = xmlTextReaderNext(reader);
141
+            check_state(state);
142
+            return CL_SUCCESS;
143
+        }
135 144
 
136 145
 #if HAVE_JSON
137 146
         if (keyinfo->type & MSXML_JSON_TRACK) {
138
-            if (MSXML_JSON_ROOT)
147
+            if (keyinfo->type & MSXML_JSON_ROOT)
139 148
                 thisjobj = cli_jsonobj(mxctx->root, keyinfo->name);
140
-            else if (MSXML_JSON_WRKPTR)
149
+            else if (keyinfo->type & MSXML_JSON_WRKPTR)
141 150
                 thisjobj = cli_jsonobj(parent, keyinfo->name);
142 151
 
143 152
             if (!thisjobj) {
... ...
@@ -214,7 +225,7 @@ static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader,
214 214
 
215 215
             switch (node_type) {
216 216
             case XML_READER_TYPE_ELEMENT:
217
-                ret = msxml_parse_element(mxctx, reader, rlvl+1);
217
+                ret = msxml_parse_element(mxctx, reader, rlvl+1, thisjobj);
218 218
                 if (ret != CL_SUCCESS) {
219 219
                     return ret;
220 220
                 }
... ...
@@ -225,14 +236,17 @@ static int msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader,
225 225
 
226 226
                 cli_msxmlmsg("TEXT: %s\n", node_value);
227 227
 
228
-                /*
229
-                  ret = ooxml_parse_value(thisjobj, "Value", node_value);
230
-                  if (ret != CL_SUCCESS)
231
-                  return ret;
232
-
233
-                  cli_dbgmsg("ooxml_parse_element: added json value [%s: %s]\n", element_tag, node_value);
234
-                */
235
-
228
+#if HAVE_JSON
229
+                if (thisjobj && (keyinfo->type & MSXML_JSON_VALUE)) {
230
+                    /*
231
+                      ret = ooxml_parse_value(thisjobj, "Value", node_value);
232
+                      if (ret != CL_SUCCESS)
233
+                      return ret;
234
+                    */
235
+                    cli_jsonstr(thisjobj, "Value", (const char *)node_value);
236
+                    cli_dbgmsg("ooxml_parse_element: added json value [%s: %s]\n", keyinfo->name, (const char *)node_value);
237
+                }
238
+#endif
236 239
 
237 240
                 /* scanning protocol for embedded objects encoded in base64 */
238 241
                 if (keyinfo->type & MSXML_SCAN_B64) {
... ...
@@ -355,15 +369,17 @@ int cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const struct
355 355
     mxctx.keys = keys;
356 356
     mxctx.num_keys = num_keys;
357 357
 #if HAVE_JSON
358
-    if (mode) {
358
+    if (mode)
359 359
         mxctx.root = ctx->wrkproperty;
360
-        mxctx.wrkptr = ctx->wrkproperty;
361
-    }
362 360
 #endif
363 361
 
364 362
     /* Main Processing Loop */
365 363
     while ((state = xmlTextReaderRead(reader)) == 1) {
366
-        msxml_parse_element(&mxctx, reader, 0);
364
+#if HAVE_JSON
365
+        ret = msxml_parse_element(&mxctx, reader, 0, mxctx.root);
366
+#else
367
+        ret = msxml_parse_element(&mxctx, reader, 0, NULL);
368
+#endif
367 369
         if (ret != CL_SUCCESS && ret != CL_ETIMEOUT && ret != CL_BREAK) {
368 370
             cli_warnmsg("cli_msxml_parse_document: encountered issue in parsing xml document\n");
369 371
             break;
... ...
@@ -69,7 +69,6 @@ struct msxml_ctx {
69 69
 
70 70
 #if HAVE_JSON
71 71
     json_object *root;
72
-    json_object *wrkptr;
73 72
 #endif
74 73
 };
75 74