Browse code

- modparam types switched to flags; USE_FUNC_PARAM flag added for param type - instead of copying the param value, a func is called to process it

Bogdan-Andrei Iancu authored on 12/03/2004 14:15:22
Showing 3 changed files
... ...
@@ -46,7 +46,7 @@ skip_modules?=
46 46
 exclude_modules?= 			cpl ext extcmd \
47 47
 							postgres snmp \
48 48
 							im radius_acc radius_auth \
49
-							jabber mysql \
49
+							jabber \
50 50
 							auth_radius group_radius uri_radius 
51 51
 # always exclude the CVS dir
52 52
 override exclude_modules+= CVS $(skip_modules)
... ...
@@ -28,6 +28,8 @@
28 28
  * History:
29 29
  * -------
30 30
  * 2003-03-20  regex support in modparam (janakj)
31
+ * 2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
32
+ *             instead of copying the param value, a func is called (bogdan)
31 33
  */
32 34
 
33 35
 
... ...
@@ -80,6 +82,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
80 80
 	regex_t preg;
81 81
 	int mod_found, len;
82 82
 	char* reg;
83
+	int n;
83 84
 
84 85
 	len = strlen(regex);
85 86
 	reg = pkg_malloc(len + 2 + 1);
... ...
@@ -102,22 +105,31 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
102 102
 
103 103
 	for(t = modules; t; t = t->next) {
104 104
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
105
-			DBG("set_mod_param_regex: %s matches module %s\n", regex, t->exports->name);
105
+			DBG("set_mod_param_regex: %s matches module %s\n",
106
+					regex, t->exports->name);
106 107
 			mod_found = 1;
107 108
 			for(param=t->exports->params;param && param->name ; param++) {
108 109
 				if ((strcmp(name, param->name) == 0) &&
109
-				    (param->type == type)) {
110
+				( PARAM_TYPE_MASK(param->type) == type)) {
110 111
 					DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
111
-					    name, t->exports->name, t->path);
112
-
113
-					switch(type) {
114
-					case STR_PARAM:
115
-						*((char**)(param->param_pointer)) = strdup((char*)val);
116
-						break;
117
-						
118
-					case INT_PARAM:
119
-						*((int*)(param->param_pointer)) = (int)(long)val;
120
-						break;
112
+						name, t->exports->name, t->path);
113
+
114
+					if (param->type&USE_FUNC_PARAM) {
115
+						n = ((param_func_t)(param->param_pointer))
116
+							(type, (param_func_param_t)(char*)val );
117
+						if (n<0)
118
+							return -4;
119
+					} else {
120
+						switch(type) {
121
+							case STR_PARAM:
122
+								*((char**)(param->param_pointer)) =
123
+									strdup((char*)val);
124
+								break;
125
+							case INT_PARAM:
126
+								*((int*)(param->param_pointer)) =
127
+									(int)(long)val;
128
+								break;
129
+						}
121 130
 					}
122 131
 
123 132
 					break;
... ...
@@ -33,6 +33,8 @@
33 33
  *               and param_export (andrei)
34 34
  *  2003-03-16  Added flags field to cmd_export_ (janakj)
35 35
  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
36
+ *  2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
37
+ *              instead of copying the param value, a func is called (bogdan)
36 38
  */
37 39
 
38 40
 
... ...
@@ -51,10 +53,19 @@ typedef int (*init_function)(void);
51 51
 typedef int (*child_init_function)(int rank);
52 52
 
53 53
 
54
-typedef enum {
55
-	STR_PARAM,  /* String parameter type */
56
-	INT_PARAM,  /* Integer parameter type */
57
-} modparam_t;       /* Allowed types of parameters */
54
+#define STR_PARAM        (1<<0)  /* String parameter type */
55
+#define INT_PARAM        (1<<1)  /* Integer parameter type */
56
+#define USE_FUNC_PARAM   (1<<(8*sizeof(int)-1))
57
+#define PARAM_TYPE_MASK(_x)   ((_x)&(~USE_FUNC_PARAM))
58
+
59
+typedef int modparam_t;
60
+
61
+typedef union {
62
+	int integer;
63
+	char *string;
64
+} param_func_param_t;
65
+
66
+typedef int (*param_func_t)( modparam_t type, param_func_param_t param_val);
58 67
 
59 68
 #define REQUEST_ROUTE 1  /* Function can be used in request route blocks */
60 69
 #define FAILURE_ROUTE 2  /* Function can be used in reply route blocks */