]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Start arrays support in xmlrpc output
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 12 Jan 2018 21:27:30 +0000 (21:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 12 Jan 2018 21:27:30 +0000 (21:27 +0000)
src/lua/lua_xmlrpc.c

index 27d94471268edf891d7f434d6dafda2d5b9db76f..01850af70e608d42056bf8a5953f173d8999d792 100644 (file)
@@ -132,6 +132,12 @@ xmlrpc_start_element (GMarkupParseContext *context,
                        lua_newtable (ud->L);
                        ud->depth++;
                }
+               else if (g_ascii_strcasecmp (name, "array") == 0) {
+                       ud->parser_state = 14;
+                       /* Create new param of table type */
+                       lua_newtable (ud->L);
+                       ud->depth++;
+               }
                else if (g_ascii_strcasecmp (name, "string") == 0) {
                        ud->parser_state = 11;
                        ud->got_text = FALSE;
@@ -202,6 +208,66 @@ xmlrpc_start_element (GMarkupParseContext *context,
                        lua_newtable (ud->L);
                        ud->depth++;
                }
+               else if (g_ascii_strcasecmp (name, "array") == 0) {
+                       ud->parser_state = 14;
+                       /* Create new param of table type */
+                       lua_newtable (ud->L);
+                       ud->depth++;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
+       case 14:
+               /* Parse array */
+               /* Expect data */
+               if (g_ascii_strcasecmp (name, "data") == 0) {
+                       ud->parser_state = 15;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
+       case 15:
+               /* Accept array value */
+               if (g_ascii_strcasecmp (name, "value") == 0) {
+                       ud->parser_state = 16;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
+       case 16:
+               /* Parse any values */
+               /* Primitives */
+               if (g_ascii_strcasecmp (name, "string") == 0) {
+                       ud->parser_state = 11;
+                       ud->got_text = FALSE;
+               }
+               else if (g_ascii_strcasecmp (name, "int") == 0) {
+                       ud->parser_state = 12;
+                       ud->got_text = FALSE;
+               }
+               else if (g_ascii_strcasecmp (name, "double") == 0) {
+                       ud->parser_state = 13;
+                       ud->got_text = FALSE;
+               }
+               /* Structure */
+               else if (g_ascii_strcasecmp (name, "struct") == 0) {
+                       ud->parser_state = 5;
+                       /* Create new param of table type */
+                       lua_newtable (ud->L);
+                       ud->depth++;
+               }
+               else if (g_ascii_strcasecmp (name, "array") == 0) {
+                       ud->parser_state = 14;
+                       /* Create new param of table type */
+                       lua_newtable (ud->L);
+                       ud->depth++;
+               }
                else {
                        /* Error state */
                        ud->parser_state = 99;
@@ -348,6 +414,39 @@ xmlrpc_end_element (GMarkupParseContext *context,
                        ud->parser_state = 99;
                }
                break;
+       case 14:
+               /* Got tag array */
+               if (g_ascii_strcasecmp (name, "array") == 0) {
+                       ud->parser_state = 4;
+                       ud->depth--;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
+       case 15:
+               /* Got tag data */
+               if (g_ascii_strcasecmp (name, "data") == 0) {
+                       ud->parser_state = 14;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
+       case 17:
+               /* Got tag value */
+               if (g_ascii_strcasecmp (name, "value") == 0) {
+                       guint tbl_len = rspamd_lua_table_size (ud->L, -2);
+                       lua_rawseti (ud->L, -2, tbl_len + 1);
+                       ud->parser_state = 15;
+               }
+               else {
+                       /* Error state */
+                       ud->parser_state = 99;
+               }
+               break;
        }
 
        if (ud->parser_state == 99) {