]> source.dussan.org Git - rspamd.git/commitdiff
Improve xml->rcl conversion.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Oct 2013 13:20:53 +0000 (14:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Oct 2013 13:20:53 +0000 (14:20 +0100)
src/cfg_utils.c
src/cfg_xml.c

index 9e3ae4761925da00cb4660cccfd5932de70f9424..87adc7d22ba54d5c9f29fcb195bda48e759fe3d0 100644 (file)
@@ -960,7 +960,7 @@ read_xml_config (struct config_file *cfg, const gchar *filename)
 {
        struct stat                     st;
        gint                            fd;
-       gchar                          *data;
+       gchar                          *data, *rcl;
        gboolean                        res;
        GMarkupParseContext            *ctx;
        GError                         *err = NULL;
@@ -994,7 +994,10 @@ read_xml_config (struct config_file *cfg, const gchar *filename)
 
        munmap (data, st.st_size);
 
-       return res;
+       rcl = ucl_object_emit (cfg->rcl_obj, UCL_EMIT_CONFIG);
+       printf ("%s", rcl);
+
+       return FALSE;
 }
 
 static void
index ce83782534372b7a8089265795d37b3a838bd015..7aa770267d1ae426a9bdaa032a22f9d2f461dd66 100644 (file)
@@ -1173,9 +1173,7 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam
                                                                const gchar **attribute_values, gpointer user_data, GError **error)
 {
        struct rspamd_xml_userdata *ud = user_data;
-       struct xml_subparser       *subparser;
-       struct classifier_config   *ccf;
-       gchar                      *res, *condition;
+       gchar                      *res;
        ucl_object_t                *obj;
 
 
@@ -1192,51 +1190,27 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam
                        break;
                case XML_READ_PARAM:
                        /* Read parameter name and try to find among list of known parameters */
-                       if (g_ascii_strcasecmp (element_name, "classifier") == 0) {
-                               if (extract_attr ("type", attribute_names, attribute_values, &res)) {
-                                       ud->state = XML_READ_CLASSIFIER;
+                       /* Legacy XML support */
+                       if (g_ascii_strcasecmp (element_name, "param") == 0) {
+                               if (extract_attr ("value", attribute_names, attribute_values, &res)) {
+                                       element_name = res;
                                }
                                else {
-                                       *error = g_error_new (xml_error_quark (), XML_PARAM_MISSING, "param 'type' is required for tag 'classifier'");
+                                       *error = g_error_new (xml_error_quark (), XML_PARAM_MISSING, "param 'value' is required for tag 'param'");
                                        ud->state = XML_ERROR;
                                }
                        }
-                       else {
-                               /* Legacy XML support */
-                               if (g_ascii_strcasecmp (element_name, "param") == 0) {
-                                       if (extract_attr ("value", attribute_names, attribute_values, &res)) {
-                                               element_name = res;
-                                       }
-                                       else {
-                                               *error = g_error_new (xml_error_quark (), XML_PARAM_MISSING, "param 'value' is required for tag 'param'");
-                                               ud->state = XML_ERROR;
-                                       }
-                               }
 
-                               if (ud->nested == 0) {
-                                       /* Top object */
-                                       obj = ucl_object_new ();
-                                       obj->type = UCL_OBJECT;
-                                       ud->parent_pointer[0] = obj;
-                                       ucl_object_insert_key (ud->cfg->rcl_obj, obj, element_name, 0, true);
-                                       process_attrs (attribute_names, attribute_values, obj);
-                               }
-                               rspamd_strlcpy (ud->section_name[ud->nested], element_name, MAX_NAME);
-                               ud->nested ++;
-                       }
-                       break;
-               case XML_READ_CLASSIFIER:
-                       if (g_ascii_strcasecmp (element_name, "statfile") == 0) {
-                               ud->state = XML_READ_STATFILE;
-
-                               /* Now section pointer is statfile and parent pointer is classifier */
-                               ud->parent_pointer[0] = ud->section_pointer;
-                               ud->section_pointer = check_statfile_conf (ud->cfg, NULL);
-                       }
-                       else {
-                               rspamd_strlcpy (ud->section_name[ud->nested], element_name, MAX_NAME);
-                               /* Save attributes */
+                       if (ud->nested == 0) {
+                               /* Top object */
+                               obj = ucl_object_new ();
+                               obj->type = UCL_OBJECT;
+                               ud->parent_pointer[0] = obj;
+                               ud->cfg->rcl_obj = ucl_object_insert_key (ud->cfg->rcl_obj, obj, element_name, 0, true);
+                               process_attrs (attribute_names, attribute_values, obj);
                        }
+                       rspamd_strlcpy (ud->section_name[ud->nested], element_name, MAX_NAME);
+                       ud->nested ++;
                        break;
                default:
                        if (*error == NULL) {
@@ -1254,11 +1228,17 @@ rspamd_xml_end_element (GMarkupParseContext     *context, const gchar *element_name,
 
        struct rspamd_xml_userdata *ud = user_data;
 
-       if (g_ascii_strcasecmp (ud->section_name[ud->nested - 1], element_name) == 0) {
-               ud->nested --;
+       if (ud->nested > 0) {
+               if (g_ascii_strcasecmp (ud->section_name[ud->nested - 1], element_name) == 0) {
+                       ud->nested --;
+               }
+               else {
+                       *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is umatched", element_name);
+                       ud->state = XML_ERROR;
+               }
        }
-       else {
-               *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is umatched", element_name);
+       else if (g_ascii_strcasecmp ("rspamd", element_name) != 0) {
+               *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is umatched on the top level", element_name);
                ud->state = XML_ERROR;
        }
 }
@@ -1279,9 +1259,10 @@ rspamd_xml_text (GMarkupParseContext *context, const gchar *text, gsize text_len
                return;
        }
 
-       top = ud->parent_pointer[ud->nested - 1];
-       ucl_object_insert_key (top, ucl_object_fromstring_common (text, text_len, UCL_STRING_PARSE),
-                       ud->section_name[ud->nested], 0, true);
+       top = ud->parent_pointer[0];
+       ud->parent_pointer[0] =
+                       ucl_object_insert_key (top, ucl_object_fromstring_common (text, text_len, UCL_STRING_PARSE),
+                       ud->section_name[ud->nested - 1], 0, true);
 }
 
 void