Hi list,

now, as Kannel maintains its own way of "knowing" what config directives are allowed in group sections, this is a problem if external modules, ie. Rene's sqlbox or Paul's Mbuni need to use the same gwlib/cfg.[ch] thingies.

I tried to introduce a generic hooking mechanism for the 2 functions is_allowed_in_group() and is_single_group() that use the #include "cfg.def" for the core.

Now extenal modules can use cfg_add_hooks(void *a, void *b) to offer their own "version" of these 2 routines and hence #include "foobar-cfg.def" in their own code space.

The hooks are appended to a list and a wrapper loops arround the functiokns in the lists to get a boolean value.

I know that this is not the most elegant way. Alex suggested using dlopne() and dlsym(), which are of course a "better" approach, but still we need to "concatenate" the defined groups and I had no idea how to do.

Please review and vote.

Stipe

-------------------------------------------------------------------
Kölner Landstrasse 419
40589 Düsseldorf, NRW, Germany

tolj.org system architecture      Kannel Software Foundation (KSF)
http://www.tolj.org/              http://www.kannel.org/

mailto:st_{at}_tolj.org           mailto:stolj_{at}_kannel.org
-------------------------------------------------------------------
### Eclipse Workspace Patch 1.0
#P gateway-cvs
Index: gwlib/cfg.h
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.h,v
retrieving revision 1.14
diff -u -r1.14 cfg.h
--- gwlib/cfg.h 11 Feb 2005 15:35:48 -0000      1.14
+++ gwlib/cfg.h 2 Jun 2006 15:33:27 -0000
@@ -73,6 +73,7 @@
 Cfg *cfg_create(Octstr *filename);
 void cfg_destroy(Cfg *cfg);
 int cfg_read(Cfg *cfg);
+void cfg_add_hooks(void *allowed, void *single);
 
 CfgGroup *cfg_get_single_group(Cfg *cfg, Octstr *name);
 List *cfg_get_multi_group(Cfg *cfg, Octstr *name);
Index: gwlib/cfg.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.c,v
retrieving revision 1.30
diff -u -r1.30 cfg.c
--- gwlib/cfg.c 11 Feb 2005 15:35:48 -0000      1.30
+++ gwlib/cfg.c 2 Jun 2006 15:33:27 -0000
@@ -152,7 +152,16 @@
 };
 
 
-static int is_allowed_in_group(Octstr *group, Octstr *variable)
+/********************************************************************
+ * Section providing hooks to external modules to apply their specific
+ * is_allowed_in_group() and is_single_group() with their own
+ * foobar-cfg.def.
+ */
+
+static List *allowed_hooks;
+static List *single_hooks;
+
+static int core_is_allowed_in_group(Octstr *group, Octstr *variable)
 {
     Octstr *groupstr;
     
@@ -181,7 +190,7 @@
 }
 
 
-static int is_single_group(Octstr *query)
+static int core_is_single_group(Octstr *query)
 {
     #define OCTSTR(name)
     #define SINGLE_GROUP(name, fields) \
@@ -195,6 +204,43 @@
 }
 
 
+static int is_allowed_in_group(Octstr *group, Octstr *variable)
+{
+    long i;
+    int r = 0;
+
+    for (i = 0; i < gwlist_len(allowed_hooks); ++i) {
+        r += ((int(*)(Octstr *, Octstr *))
+            gwlist_get(allowed_hooks, i))(group, variable);
+    }
+
+    return (r > 0);
+}
+
+
+static int is_single_group(Octstr *query)
+{
+    long i;
+    int r = 0;
+
+    for (i = 0; i < gwlist_len(single_hooks); ++i) {
+        r += ((int(*)(Octstr *))
+            gwlist_get(single_hooks, i))(query);
+    }
+
+    return (r > 0);
+}
+
+
+void cfg_add_hooks(void *allowed, void *single)
+{
+    gwlist_append(allowed_hooks, allowed);
+    gwlist_append(single_hooks, single);
+}
+
+
+
+
 static int add_group(Cfg *cfg, CfgGroup *grp)
 {
     Octstr *groupname;
@@ -247,6 +293,14 @@
     cfg->filename = octstr_duplicate(filename);
     cfg->single_groups = dict_create(64, destroy_group);
     cfg->multi_groups = dict_create(64, destroy_group_list);
+
+   /* make sure we put our own core hooks into the lists */
+    allowed_hooks = gwlist_create();
+    single_hooks = gwlist_create();
+
+    gwlist_append(allowed_hooks, &core_is_allowed_in_group);
+    gwlist_append(single_hooks, &core_is_single_group);
+
     return cfg;
 }
 

Reply via email to