Browse code

- 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 authored on 07/02/2006 19:17:38
Showing 4 changed files
... ...
@@ -57,7 +57,7 @@
57 57
 /* default number of child processes started */
58 58
 #define CHILD_NO    8
59 59
 
60
-#define RT_NO 20 /* routing tables number */
60
+#define RT_NO 2 /* routing tables number */
61 61
 #define FAILURE_RT_NO RT_NO /* on_failure routing tables number */
62 62
 #define ONREPLY_RT_NO RT_NO /* on_reply routing tables number */
63 63
 #define BRANCH_RT_NO RT_NO /* branch_route routing tables number */
... ...
@@ -173,7 +173,7 @@ int register_flag(char* name, int pos)
173 173
 	/* check if the name already exists */
174 174
 	e=flag_search(&name2flags[h], name, len);
175 175
 	if (e){
176
-		LOG(L_WARN, "WARNING: register_flag: flag %.*s already registered\n",
176
+		LOG(L_ERR, "ERROR: register_flag: flag %.*s already registered\n",
177 177
 					len, name);
178 178
 		return -2;
179 179
 	}
... ...
@@ -33,7 +33,9 @@
33 33
  *  2003-03-29  cleaning pkg_mallocs introduced (jiri)
34 34
  *  2003-04-24  module version checking introduced (jiri)
35 35
  *  2004-09-19  compile flags are checked too (andrei)
36
- *  2005-01-07  removed find_module-overloading problems, added find_export_record
36
+ *  2005-01-07  removed find_module-overloading problems, added 
37
+ *               find_export_record
38
+ *  2006-02-07  added fix_flag (andrei)
37 39
  */
38 40
 
39 41
 
... ...
@@ -44,6 +46,7 @@
44 44
 #include "core_cmd.h"
45 45
 #include "ut.h"
46 46
 #include "route_struct.h"
47
+#include "flags.h"
47 48
 
48 49
 #include <regex.h>
49 50
 #include <dlfcn.h>
... ...
@@ -664,3 +667,58 @@ int fixup_get_param_count(void **cur_param, int cur_param_no) {
664 664
 	else
665 665
 		return -1;
666 666
 }
667
+
668
+
669
+/* fixes flag params (resolves possible named flags)
670
+ * use PARAM_USE_FUNC|PARAM_STRING as a param. type and create
671
+ * a wrapper function that does just:
672
+ * return fix_flag(type, val, "my_module", "my_param", &flag_var)
673
+ * see also param_func_t.
674
+ */
675
+int fix_flag( modparam_t type, void* val,
676
+					char* mod_name, char* param_name, int* flag)
677
+{
678
+	int num;
679
+	int err;
680
+	int f, len;
681
+	char* s;
682
+	char *p;
683
+	
684
+	if ((type & PARAM_STRING)==0){
685
+		LOG(L_CRIT, "BUG: %s: fix_flag(%s): bad parameter type\n",
686
+					mod_name, param_name);
687
+		return -1;
688
+	}
689
+	s=(char*)val;
690
+	len=strlen(s);
691
+	f=-1;
692
+	/* try to see if it's a number */
693
+	num = str2s(s, len, &err);
694
+	if (err != 0) {
695
+		/* see if it's in the name:<no> format */
696
+		p=strchr(s, ':');
697
+		if (p){
698
+			f= str2s(p+1, strlen(p+1), &err);
699
+			if (err!=0){
700
+				LOG(L_ERR, "ERROR: %s: invalid %s format:"
701
+						" \"%s\"", mod_name, param_name, s);
702
+				return -1;
703
+			}
704
+			*p=0;
705
+		}
706
+		if ((num=get_flag_no(s, len))<0){
707
+			/* not declared yet, declare it */
708
+			num=register_flag(s, f);
709
+		}
710
+		if (num<0){
711
+			LOG(L_ERR, "ERROR: %s: bad %s %s\n", mod_name, param_name, s);
712
+			return -1;
713
+		} else if ((f>0) && (num!=f)){
714
+			LOG(L_ERR, "WARNING: %s: flag %s already defined"
715
+					" as %d (and not %d), using %s:%d\n",
716
+					mod_name, s, num, f, s, num);
717
+		}
718
+	}
719
+	*flag=num;
720
+	return 0;
721
+}
... ...
@@ -207,4 +207,7 @@ int fixup_regex_2(void** param, int param_no);
207 207
 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
208 208
 int fixup_get_param_count(void **cur_param, int cur_param_no);
209 209
 
210
+int fix_flag( modparam_t type, void* val,
211
+					char* mod_name, char* param_name, int* flag);
212
+
210 213
 #endif /* sr_module_h */