]> source.dussan.org Git - rspamd.git/commitdiff
Add method to insert documentation to the specific path
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 2 Jan 2016 17:37:28 +0000 (17:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 2 Jan 2016 17:37:28 +0000 (17:37 +0000)
src/libserver/cfg_rcl.c
src/libserver/cfg_rcl.h

index 44e84aceaed5e7bf312ff633096477a78a8e92c8..a493e9c324abc28c1074271371e2261909221b1a 100644 (file)
@@ -3063,3 +3063,50 @@ rspamd_rcl_add_doc_obj (ucl_object_t *doc_target,
 
        return doc_obj;
 }
+
+ucl_object_t *
+rspamd_rcl_add_doc_by_path (struct rspamd_config *cfg,
+               const gchar *doc_path,
+               const char *doc_string,
+               const char *doc_name,
+               ucl_type_t type,
+               rspamd_rcl_default_handler_t handler,
+               gint flags)
+{
+       const ucl_object_t *found, *cur;
+       ucl_object_t *obj;
+       gchar **path_components, **comp;
+
+       found = ucl_lookup_path (cfg->doc_strings, doc_path);
+
+       if (found != NULL) {
+               return rspamd_rcl_add_doc_obj ((ucl_object_t *)found,
+                               doc_string, doc_name, type, handler, flags);
+       }
+
+       /* Otherwise we need to insert all components of the path */
+       path_components = g_strsplit_set (doc_path, ".", -1);
+       cur = cfg->doc_strings;
+
+       for (comp = path_components; *comp != NULL; comp ++) {
+               if (ucl_object_type (cur) != UCL_OBJECT) {
+                       msg_err_config ("Bad path while lookup for '%s' at %s",
+                                       doc_path, *comp);
+                       return NULL;
+               }
+
+               found = ucl_object_find_key (cur, *comp);
+
+               if (found == NULL) {
+                       obj = ucl_object_typed_new (UCL_OBJECT);
+                       ucl_object_insert_key ((ucl_object_t *)cur, obj, *comp, 0, true);
+                       cur = obj;
+               }
+               else {
+                       cur = found;
+               }
+       }
+
+       return rspamd_rcl_add_doc_obj ((ucl_object_t *) cur,
+                       doc_string, doc_name, type, handler, flags);
+}
index 38f54582526c82836bf592bdb1d0f0cf05224695..b114e765c93afee1c3d5031e50ac69cf62ddb749 100644 (file)
@@ -358,4 +358,16 @@ ucl_object_t* rspamd_rcl_add_doc_obj (ucl_object_t *doc_target,
                ucl_type_t type,
                rspamd_rcl_default_handler_t handler,
                gint flags);
+
+/**
+ * Adds new documentation option specified by path `doc_path` that should be
+ * splitted by dots
+ */
+ucl_object_t *rspamd_rcl_add_doc_by_path (struct rspamd_config *cfg,
+               const gchar *doc_path,
+               const char *doc_string,
+               const char *doc_name,
+               ucl_type_t type,
+               rspamd_rcl_default_handler_t handler,
+               gint flags);
 #endif /* CFG_RCL_H_ */