Преглед на файлове

- 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 преди 21 години
родител
ревизия
7887854088
променени са 3 файла, в които са добавени 40 реда и са изтрити 17 реда
  1. 1 1
      Makefile
  2. 24 12
      modparam.c
  3. 15 4
      sr_module.h

+ 1 - 1
Makefile

@@ -46,7 +46,7 @@ skip_modules?=
 exclude_modules?= 			cpl ext extcmd \
 							postgres snmp \
 							im radius_acc radius_auth \
-							jabber mysql \
+							jabber \
 							auth_radius group_radius uri_radius 
 # always exclude the CVS dir
 override exclude_modules+= CVS $(skip_modules)

+ 24 - 12
modparam.c

@@ -28,6 +28,8 @@
  * History:
  * -------
  * 2003-03-20  regex support in modparam (janakj)
+ * 2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
+ *             instead of copying the param value, a func is called (bogdan)
  */
 
 
@@ -80,6 +82,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
 	regex_t preg;
 	int mod_found, len;
 	char* reg;
+	int n;
 
 	len = strlen(regex);
 	reg = pkg_malloc(len + 2 + 1);
@@ -102,22 +105,31 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
 
 	for(t = modules; t; t = t->next) {
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
-			DBG("set_mod_param_regex: %s matches module %s\n", regex, t->exports->name);
+			DBG("set_mod_param_regex: %s matches module %s\n",
+					regex, t->exports->name);
 			mod_found = 1;
 			for(param=t->exports->params;param && param->name ; param++) {
 				if ((strcmp(name, param->name) == 0) &&
-				    (param->type == type)) {
+				( PARAM_TYPE_MASK(param->type) == type)) {
 					DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
-					    name, t->exports->name, t->path);
-
-					switch(type) {
-					case STR_PARAM:
-						*((char**)(param->param_pointer)) = strdup((char*)val);
-						break;
-						
-					case INT_PARAM:
-						*((int*)(param->param_pointer)) = (int)(long)val;
-						break;
+						name, t->exports->name, t->path);
+
+					if (param->type&USE_FUNC_PARAM) {
+						n = ((param_func_t)(param->param_pointer))
+							(type, (param_func_param_t)(char*)val );
+						if (n<0)
+							return -4;
+					} else {
+						switch(type) {
+							case STR_PARAM:
+								*((char**)(param->param_pointer)) =
+									strdup((char*)val);
+								break;
+							case INT_PARAM:
+								*((int*)(param->param_pointer)) =
+									(int)(long)val;
+								break;
+						}
 					}
 
 					break;

+ 15 - 4
sr_module.h

@@ -33,6 +33,8 @@
  *               and param_export (andrei)
  *  2003-03-16  Added flags field to cmd_export_ (janakj)
  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
+ *  2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
+ *              instead of copying the param value, a func is called (bogdan)
  */
 
 
@@ -51,10 +53,19 @@ typedef int (*init_function)(void);
 typedef int (*child_init_function)(int rank);
 
 
-typedef enum {
-	STR_PARAM,  /* String parameter type */
-	INT_PARAM,  /* Integer parameter type */
-} modparam_t;       /* Allowed types of parameters */
+#define STR_PARAM        (1<<0)  /* String parameter type */
+#define INT_PARAM        (1<<1)  /* Integer parameter type */
+#define USE_FUNC_PARAM   (1<<(8*sizeof(int)-1))
+#define PARAM_TYPE_MASK(_x)   ((_x)&(~USE_FUNC_PARAM))
+
+typedef int modparam_t;
+
+typedef union {
+	int integer;
+	char *string;
+} param_func_param_t;
+
+typedef int (*param_func_t)( modparam_t type, param_func_param_t param_val);
 
 #define REQUEST_ROUTE 1  /* Function can be used in request route blocks */
 #define FAILURE_ROUTE 2  /* Function can be used in reply route blocks */