Browse Source

- modules named flag support in modparams (registrar, acc_*)
E.g.:

flags foo, bar, nat;
modparam("registrar", "nat_flag", "nat")

or modparam("registrar", "nat_flag", "f:9") # uses flag 9 and "names" it f

Andrei Pelinescu-Onciul 19 years ago
parent
commit
6d35d70ed4
4 changed files with 64 additions and 3 deletions
  1. 1 1
      config.h
  2. 1 1
      flags.c
  3. 59 1
      sr_module.c
  4. 3 0
      sr_module.h

+ 1 - 1
config.h

@@ -57,7 +57,7 @@
 /* default number of child processes started */
 /* default number of child processes started */
 #define CHILD_NO    8
 #define CHILD_NO    8
 
 
-#define RT_NO 20 /* routing tables number */
+#define RT_NO 2 /* routing tables number */
 #define FAILURE_RT_NO RT_NO /* on_failure routing tables number */
 #define FAILURE_RT_NO RT_NO /* on_failure routing tables number */
 #define ONREPLY_RT_NO RT_NO /* on_reply routing tables number */
 #define ONREPLY_RT_NO RT_NO /* on_reply routing tables number */
 #define BRANCH_RT_NO RT_NO /* branch_route routing tables number */
 #define BRANCH_RT_NO RT_NO /* branch_route routing tables number */

+ 1 - 1
flags.c

@@ -173,7 +173,7 @@ int register_flag(char* name, int pos)
 	/* check if the name already exists */
 	/* check if the name already exists */
 	e=flag_search(&name2flags[h], name, len);
 	e=flag_search(&name2flags[h], name, len);
 	if (e){
 	if (e){
-		LOG(L_WARN, "WARNING: register_flag: flag %.*s already registered\n",
+		LOG(L_ERR, "ERROR: register_flag: flag %.*s already registered\n",
 					len, name);
 					len, name);
 		return -2;
 		return -2;
 	}
 	}

+ 59 - 1
sr_module.c

@@ -33,7 +33,9 @@
  *  2003-03-29  cleaning pkg_mallocs introduced (jiri)
  *  2003-03-29  cleaning pkg_mallocs introduced (jiri)
  *  2003-04-24  module version checking introduced (jiri)
  *  2003-04-24  module version checking introduced (jiri)
  *  2004-09-19  compile flags are checked too (andrei)
  *  2004-09-19  compile flags are checked too (andrei)
- *  2005-01-07  removed find_module-overloading problems, added find_export_record
+ *  2005-01-07  removed find_module-overloading problems, added 
+ *               find_export_record
+ *  2006-02-07  added fix_flag (andrei)
  */
  */
 
 
 
 
@@ -44,6 +46,7 @@
 #include "core_cmd.h"
 #include "core_cmd.h"
 #include "ut.h"
 #include "ut.h"
 #include "route_struct.h"
 #include "route_struct.h"
+#include "flags.h"
 
 
 #include <regex.h>
 #include <regex.h>
 #include <dlfcn.h>
 #include <dlfcn.h>
@@ -664,3 +667,58 @@ int fixup_get_param_count(void **cur_param, int cur_param_no) {
 	else
 	else
 		return -1;
 		return -1;
 }
 }
+
+
+/* fixes flag params (resolves possible named flags)
+ * use PARAM_USE_FUNC|PARAM_STRING as a param. type and create
+ * a wrapper function that does just:
+ * return fix_flag(type, val, "my_module", "my_param", &flag_var)
+ * see also param_func_t.
+ */
+int fix_flag( modparam_t type, void* val,
+					char* mod_name, char* param_name, int* flag)
+{
+	int num;
+	int err;
+	int f, len;
+	char* s;
+	char *p;
+	
+	if ((type & PARAM_STRING)==0){
+		LOG(L_CRIT, "BUG: %s: fix_flag(%s): bad parameter type\n",
+					mod_name, param_name);
+		return -1;
+	}
+	s=(char*)val;
+	len=strlen(s);
+	f=-1;
+	/* try to see if it's a number */
+	num = str2s(s, len, &err);
+	if (err != 0) {
+		/* see if it's in the name:<no> format */
+		p=strchr(s, ':');
+		if (p){
+			f= str2s(p+1, strlen(p+1), &err);
+			if (err!=0){
+				LOG(L_ERR, "ERROR: %s: invalid %s format:"
+						" \"%s\"", mod_name, param_name, s);
+				return -1;
+			}
+			*p=0;
+		}
+		if ((num=get_flag_no(s, len))<0){
+			/* not declared yet, declare it */
+			num=register_flag(s, f);
+		}
+		if (num<0){
+			LOG(L_ERR, "ERROR: %s: bad %s %s\n", mod_name, param_name, s);
+			return -1;
+		} else if ((f>0) && (num!=f)){
+			LOG(L_ERR, "WARNING: %s: flag %s already defined"
+					" as %d (and not %d), using %s:%d\n",
+					mod_name, s, num, f, s, num);
+		}
+	}
+	*flag=num;
+	return 0;
+}

+ 3 - 0
sr_module.h

@@ -207,4 +207,7 @@ int fixup_regex_2(void** param, int param_no);
 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
 int fixup_get_param_count(void **cur_param, int cur_param_no);
 int fixup_get_param_count(void **cur_param, int cur_param_no);
 
 
+int fix_flag( modparam_t type, void* val,
+					char* mod_name, char* param_name, int* flag);
+
 #endif /* sr_module_h */
 #endif /* sr_module_h */