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 82
 	regex_t preg;
81 83
 	int mod_found, len;
82 84
 	char* reg;
85
+	int n;
83 86
 
84 87
 	len = strlen(regex);
85 88
 	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 105
 
103 106
 	for(t = modules; t; t = t->next) {
104 107
 		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);
108
+			DBG("set_mod_param_regex: %s matches module %s\n",
109
+					regex, t->exports->name);
106 110
 			mod_found = 1;
107 111
 			for(param=t->exports->params;param && param->name ; param++) {
108 112
 				if ((strcmp(name, param->name) == 0) &&
109
-				    (param->type == type)) {
113
+				( PARAM_TYPE_MASK(param->type) == type)) {
110 114
 					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;
115
+						name, t->exports->name, t->path);
116
+
117
+					if (param->type&USE_FUNC_PARAM) {
118
+						n = ((param_func_t)(param->param_pointer))
119
+							(type, (param_func_param_t)(char*)val );
120
+						if (n<0)
121
+							return -4;
122
+					} else {
123
+						switch(type) {
124
+							case STR_PARAM:
125
+								*((char**)(param->param_pointer)) =
126
+									strdup((char*)val);
127
+								break;
128
+							case INT_PARAM:
129
+								*((int*)(param->param_pointer)) =
130
+									(int)(long)val;
131
+								break;
132
+						}
121 133
 					}
122 134
 
123 135
 					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 53
 typedef int (*child_init_function)(int rank);
52 54
 
53 55
 
54
-typedef enum {
55
-	STR_PARAM,  /* String parameter type */
56
-	INT_PARAM,  /* Integer parameter type */
57
-} modparam_t;       /* Allowed types of parameters */
56
+#define STR_PARAM        (1<<0)  /* String parameter type */
57
+#define INT_PARAM        (1<<1)  /* Integer parameter type */
58
+#define USE_FUNC_PARAM   (1<<(8*sizeof(int)-1))
59
+#define PARAM_TYPE_MASK(_x)   ((_x)&(~USE_FUNC_PARAM))
60
+
61
+typedef int modparam_t;
62
+
63
+typedef union {
64
+	int integer;
65
+	char *string;
66
+} param_func_param_t;
67
+
68
+typedef int (*param_func_t)( modparam_t type, param_func_param_t param_val);
58 69
 
59 70
 #define REQUEST_ROUTE 1  /* Function can be used in request route blocks */
60 71
 #define FAILURE_ROUTE 2  /* Function can be used in reply route blocks */