Browse code

- set_mod_param uses set_mod_param_regex - set_mod_param_regex str/string type casting - rr_mod ignore_user removed, i_user as str param

Tomas Mandys authored on 08/01/2006 23:51:12
Showing 2 changed files
... ...
@@ -773,7 +773,7 @@ module_stm:	LOADMODULE STRING	{ DBG("loading module %s\n", $2);
773 773
 								}
774 774
 		 | LOADMODULE error	{ yyerror("string expected");  }
775 775
                  | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
776
-			 if (set_mod_param_regex($3, $5, PARAM_STR|PARAM_STRING, $7) != 0) {
776
+			 if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
777 777
 				 yyerror("Can't set module parameter");
778 778
 			 }
779 779
 		   }
... ...
@@ -41,62 +41,29 @@
41 41
 #include <regex.h>
42 42
 #include <string.h>
43 43
 
44
-
45 44
 int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
46 45
 {
47
-	void* ptr;
48
-	modparam_t param_type;
49
-
50
-	if (!_mod) {
51
-		LOG(L_ERR, "set_mod_param(): Invalid _mod parameter value\n");
52
-		return -1;
53
-	}
54
-
55
-	if (!_name) {
56
-		LOG(L_ERR, "set_mod_param(): Invalid _name parameter value\n");
57
-		return -2;
58
-	}
59
-
60
-
61
-	ptr = find_param_export(find_module_by_name(_mod), _name, _type, &param_type);
62
-	if (!ptr) {
63
-		LOG(L_ERR, "set_mod_param(): Parameter not found\n");
64
-		return -3;
65
-	}
66
-
67
-	if (param_type & PARAM_USE_FUNC) {
68
-		if ( ((param_func_t)(ptr))(param_type, _val) < 0) {
69
-			return -4;
70
-		}
71
-	}
72
-	else {
73
-		switch(PARAM_TYPE_MASK(param_type)) {
74
-			case PARAM_STRING:
75
-				*((char**)ptr) = strdup((char*)_val);
76
-				break;
77
-
78
-			case PARAM_STR:
79
-				((str*)ptr)->s = strdup((char*)_val);
80
-				((str*)ptr)->len = strlen(((str*)ptr)->s);
81
-				break;
82
-
83
-			case PARAM_INT:
84
-				*((int*)ptr) = (int)(long)_val;
85
-				break;
86
-		}
87
-	}
88
-	return 0;
46
+	return set_mod_param_regex(_mod, _name, _type, _val);
89 47
 }
90 48
 
91
-
92 49
 int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
93 50
 {
94 51
 	struct sr_module* t;
95 52
 	regex_t preg;
96 53
 	int mod_found, len;
97 54
 	char* reg;
98
-	void *ptr;
55
+	void *ptr, *val2;
99 56
 	modparam_t param_type;
57
+	str s;
58
+
59
+	if (!regex) {
60
+		LOG(L_ERR, "set_mod_param_regex(): Invalid mod parameter value\n");
61
+		return -5;
62
+	}
63
+	if (!name) {
64
+		LOG(L_ERR, "set_mod_param_regex(): Invalid name parameter value\n");
65
+		return -6;
66
+	}
100 67
 
101 68
 	len = strlen(regex);
102 69
 	reg = pkg_malloc(len + 2 + 1);
... ...
@@ -120,11 +87,23 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
120 120
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
121 121
 			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
122 122
 			mod_found = 1;
123
-			ptr = find_param_export(t, name, type, &param_type);
123
+			ptr = find_param_export(t, name, type | (type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0, &param_type);
124 124
 			if (ptr) {
125
+				// type casting
126
+				if (type == PARAM_STRING && PARAM_TYPE_MASK(param_type) == PARAM_STR) {
127
+					s.s = (char*)val;
128
+					s.len = s.s?strlen(s.s):0;
129
+					val2 = &s;
130
+				} else if (type == PARAM_STR && PARAM_TYPE_MASK(param_type) == PARAM_STRING) {
131
+					val2 = s.s;	// zero terminator expected
132
+				}
133
+				else
134
+					val2 = val;
135
+
136
+
125 137
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
126 138
 				if (param_type & PARAM_USE_FUNC) {
127
-					if ( ((param_func_t)(ptr))(param_type, val) < 0) {
139
+					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
128 140
 						regfree(&preg);
129 141
 						pkg_free(reg);
130 142
 						return -4;
... ...
@@ -133,16 +112,16 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
133 133
 				else {
134 134
 					switch(PARAM_TYPE_MASK(param_type)) {
135 135
 						case PARAM_STRING:
136
-							*((char**)ptr) = strdup((char*)val);
136
+							*((char**)ptr) = strdup((char*)val2);
137 137
 							break;
138 138
 
139 139
 						case PARAM_STR:
140
-							((str*)ptr)->s = strdup((char*)val);
141
-							((str*)ptr)->len = strlen(((str*)ptr)->s);
140
+							((str*)ptr)->s = strdup(((str*)val2)->s);
141
+							((str*)ptr)->len = ((str*)ptr)->s?strlen(((str*)ptr)->s):0;
142 142
 							break;
143 143
 
144 144
 						case PARAM_INT:
145
-							*((int*)ptr) = (int)(long)val;
145
+							*((int*)ptr) = (int)(long)val2;
146 146
 							break;
147 147
 					}
148 148
 				}