Browse code

Modules_k/registrar Other module variables added to configuration framework

Also added callback that modify the statistics to reflect the changes via sercmd

Marius Zbihlei authored on 17/02/2010 11:52:48
Showing 7 changed files
... ...
@@ -56,7 +56,8 @@ int extract_aor(str* _uri, str* _a)
56 56
 	int_str avp_val;
57 57
 	struct usr_avp *avp;
58 58
 	str *uri;
59
-
59
+	str realm_prefix;
60
+	
60 61
 	memset(aor_buf, 0, MAX_AOR_LEN);
61 62
 	if (aor_avp_name.n!=0) {
62 63
 		avp = search_first_avp( aor_avp_type, aor_avp_name, &avp_val, 0);
... ...
@@ -98,6 +99,8 @@ int extract_aor(str* _uri, str* _a)
98 98
 		if (user_len)
99 99
 			aor_buf[_a->len++] = '@';
100 100
 		/* strip prefix (if defined) */
101
+		realm_prefix.s = cfg_get(registrar, registrar_cfg, realm_pref);
102
+		realm_prefix.len = strlen(realm_prefix.s);
101 103
 		if (realm_prefix.len && realm_prefix.len<puri.host.len &&
102 104
 		(memcmp(realm_prefix.s, puri.host.s, realm_prefix.len)==0) ) {
103 105
 			memcpy(aor_buf + _a->len, puri.host.s + realm_prefix.len,
... ...
@@ -39,17 +39,20 @@ struct cfg_group_registrar	default_registrar_cfg = {
39 39
 		0,	/* max_expires */
40 40
 		0,	/* max_contacts */
41 41
 		0,	/* retry_after */
42
-		0	/* case_sensitive */
43
-	};
42
+		0,	/* case_sensitive */
43
+		Q_UNSPECIFIED,	/* default_q */
44
+		1,	/* append_branches */
45
+		"",	/* realm_pref */
46
+	    };
44 47
 
45 48
 void	*registrar_cfg = &default_registrar_cfg;
46 49
 
47 50
 cfg_def_t	registrar_cfg_def[] = {
48
-	{"default_expires",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
51
+	{"default_expires",	CFG_VAR_INT | CFG_CB_ONLY_ONCE,	0, 0, 0, default_expires_stats_update,
49 52
 		"Contains number of second to expire if no expire hf or contact expire present" },
50
-	{"min_expires",		CFG_VAR_INT | CFG_ATOMIC, 	0, 0, 0, 0,
53
+	{"min_expires",		CFG_VAR_INT | CFG_CB_ONLY_ONCE,	0, 0, 0, min_expires_stats_update,
51 54
 		"The minimum expires value of a Contact. Value 0 disables the checking. "},
52
-	{"max_expires",		CFG_VAR_INT | CFG_ATOMIC, 	0, 0, 0, 0,
55
+	{"max_expires",		CFG_VAR_INT | CFG_CB_ONLY_ONCE,	0, 0, 0, max_expires_stats_update,
53 56
 		"The maximum expires value of a Contact. Value 0 disables the checking. "},
54 57
 	{"max_contacts",	CFG_VAR_INT | CFG_ATOMIC, 	0, 0, 0, 0,
55 58
 		"The maximum number of Contacts for an AOR. Value 0 disables the checking. "},
... ...
@@ -57,5 +60,11 @@ cfg_def_t	registrar_cfg_def[] = {
57 57
 		"If you want to add the Retry-After header field in 5xx replies, set this parameter to a value grater than zero"},
58 58
 	{"case_sensitive",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
59 59
 		"If set to 1 then AOR comparison will be case sensitive. Recommended and default is 0, case insensitive"},
60
+	{"default_q",		CFG_VAR_INT | CFG_ATOMIC,	-1, 1000, 0, 0,
61
+		"The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */
62
+	{"append_branches",	CFG_VAR_INT ,			0, 0, 0, 0,
63
+		"If set to 1(default), lookup will put all contacts found in msg structure"},
64
+	{"realm_pref",		CFG_VAR_STR ,			0, 0, 0, 0,
65
+		"Realm prefix to be removed. Default is \"\""},
60 66
 	{0, 0, 0, 0, 0, 0}
61 67
 };
... ...
@@ -21,6 +21,7 @@
21 21
 #ifndef _REGISTRAR_CONFIG_H
22 22
 #define _REGISTRAR_CONFIG_H
23 23
 
24
+#include "../../qvalue.h"
24 25
 
25 26
 #include "../../cfg/cfg.h"
26 27
 #include "../../str.h"
... ...
@@ -32,11 +33,18 @@ struct cfg_group_registrar {
32 32
 	unsigned int	max_contacts;
33 33
 	unsigned int	retry_after;
34 34
 	unsigned int	case_sensitive;
35
+	qvalue_t	default_q;
36
+	unsigned int	append_branches;
37
+	char* 		realm_pref;
38
+	char*		rcv_param;
35 39
 };
36 40
 
37 41
 extern struct cfg_group_registrar	default_registrar_cfg;
38 42
 extern void	*registrar_cfg;
39 43
 extern cfg_def_t	registrar_cfg_def[];
40 44
 
45
+extern void default_expires_stats_update(str*, str*);
46
+extern void min_expires_stats_update(str*, str*);
47
+extern void max_expires_stats_update(str*, str*);
41 48
 
42 49
 #endif
... ...
@@ -45,7 +45,7 @@
45 45
 #include "regtime.h"
46 46
 #include "reg_mod.h"
47 47
 #include "lookup.h"
48
-
48
+#include "config.h"
49 49
 
50 50
 #define allowed_method(_msg, _c) \
51 51
 	( !method_filtering || ((_msg)->REQ_METHOD)&((_c)->methods) )
... ...
@@ -144,7 +144,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _s)
144 144
 	}
145 145
 
146 146
 	/* Append branches if enabled */
147
-	if (!append_branches) goto done;
147
+	if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done;
148 148
 
149 149
 	for( ; ptr ; ptr = ptr->next ) {
150 150
 		if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
... ...
@@ -94,10 +94,6 @@ static int fetchc_fixup(void** param, int param_no);
94 94
 /*! \brief Functions */
95 95
 static int add_sock_hdr(struct sip_msg* msg, char *str, char *foo);
96 96
 
97
-
98
-qvalue_t default_q  = Q_UNSPECIFIED;		/*!< Default q value multiplied by 1000 */
99
-int append_branches = 1;			/*!< If set to 1, lookup will put all contacts found in msg structure */
100
-int case_sensitive  = 0;			/*!< If set to 1, username in aor will be case sensitive */
101 97
 int tcp_persistent_flag = -1;			/*!< if the TCP connection should be kept open */
102 98
 int method_filtering = 0;			/*!< if the looked up contacts should be filtered based on supported methods */
103 99
 int path_enabled = 0;				/*!< if the Path HF should be handled */
... ...
@@ -124,8 +120,6 @@ unsigned short rcv_avp_type = 0;
124 124
 int_str rcv_avp_name;
125 125
 
126 126
 int reg_use_domain = 0;
127
-char* realm_pref    = "";   			/*!< Realm prefix to be removed */
128
-str realm_prefix;
129 127
 
130 128
 int sock_flag = -1;
131 129
 str sock_hdr_name = {0,0};
... ...
@@ -183,11 +177,11 @@ static cmd_export_t cmds[] = {
183 183
  */
184 184
 static param_export_t params[] = {
185 185
 	{"default_expires",    INT_PARAM, &default_registrar_cfg.default_expires     	},
186
-	{"default_q",          INT_PARAM, &default_q           				},
187
-	{"append_branches",    INT_PARAM, &append_branches     				},
186
+	{"default_q",          INT_PARAM, &default_registrar_cfg.default_q		},
187
+	{"append_branches",    INT_PARAM, &default_registrar_cfg.append_branches	},
188 188
 	{"case_sensitive",     INT_PARAM, &default_registrar_cfg.case_sensitive		},
189 189
 	/*	{"tcp_persistent_flag",INT_PARAM, &tcp_persistent_flag }, */
190
-	{"realm_prefix",       STR_PARAM, &realm_pref          				},
190
+	{"realm_prefix",       STR_PARAM, &default_registrar_cfg.realm_pref          	},
191 191
 	{"min_expires",        INT_PARAM, &default_registrar_cfg.min_expires		},
192 192
 	{"max_expires",        INT_PARAM, &default_registrar_cfg.max_expires		},
193 193
 	{"received_param",     STR_PARAM, &rcv_param           				},
... ...
@@ -261,9 +255,6 @@ static int mod_init(void)
261 261
 		return -1;
262 262
 	}
263 263
 
264
-	realm_prefix.s = realm_pref;
265
-	realm_prefix.len = strlen(realm_pref);
266
-
267 264
 	rcv_param.len = strlen(rcv_param.s);
268 265
 	
269 266
 	if(cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), &registrar_cfg)){
... ...
@@ -333,16 +324,17 @@ static int mod_init(void)
333 333
 	}
334 334
 
335 335
 	/* Normalize default_q parameter */
336
-	if (default_q != Q_UNSPECIFIED) {
337
-		if (default_q > MAX_Q) {
338
-			LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", default_q, MAX_Q);
339
-			default_q = MAX_Q;
340
-		} else if (default_q < MIN_Q) {
341
-			LM_DBG("default_q = %d, raising to MIN_Q: %d\n", default_q, MIN_Q);
342
-			default_q = MIN_Q;
336
+	qvalue_t dq = cfg_get(registrar, registrar_cfg, default_q);
337
+	if ( dq!= Q_UNSPECIFIED) {
338
+		if (dq > MAX_Q) {
339
+			LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q);
340
+			dq = MAX_Q;
341
+		} else if (dq < MIN_Q) {
342
+			LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q);
343
+			dq = MIN_Q;
343 344
 		}
344 345
 	}
345
-	
346
+	cfg_get(registrar, registrar_cfg, default_q) = dq;
346 347
 
347 348
 	if (bind_usrloc(&ul) < 0) {
348 349
 		return -1;
... ...
@@ -536,3 +528,14 @@ error:
536 536
 	return -1;
537 537
 }
538 538
 
539
+void default_expires_stats_update(str* gname, str* name){
540
+	update_stat(default_expires_stat, cfg_get(registrar, registrar_cfg, default_expires));
541
+}
542
+
543
+void min_expires_stats_update(str* gname, str* name){
544
+	update_stat(min_expires_stat, cfg_get(registrar, registrar_cfg, min_expires));
545
+}
546
+
547
+void max_expires_stats_update(str* gname, str* name){
548
+	update_stat(max_expires_stat, cfg_get(registrar, registrar_cfg, max_expires));
549
+}
... ...
@@ -67,15 +67,10 @@
67 67
 #define REG_SAVE_REPL_FL    (1<<2)
68 68
 #define REG_SAVE_ALL_FL     ((1<<3)-1)
69 69
 
70
-extern int default_expires;
71
-extern qvalue_t default_q;
72
-extern int append_branches;
73
-extern int case_sensitive;
74 70
 extern int nat_flag;
75 71
 extern int tcp_persistent_flag;
76 72
 extern int received_avp;
77 73
 extern int reg_use_domain;
78
-extern str realm_prefix;
79 74
 extern float def_q;
80 75
 
81 76
 extern unsigned short aor_avp_type;
... ...
@@ -101,4 +96,8 @@ extern struct sl_binds slb;
101 101
 extern stat_var *accepted_registrations;
102 102
 extern stat_var *rejected_registrations;
103 103
 
104
+extern void default_expires_stats_update(str*, str*);
105
+extern void min_expires_stats_update(str*, str*);
106
+extern void max_expires_stats_update(str*, str*);
107
+
104 108
 #endif /* REG_MOD_H */
... ...
@@ -261,7 +261,7 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)
261 261
 int calc_contact_q(param_t* _q, qvalue_t* _r)
262 262
 {
263 263
 	if (!_q || (_q->body.len == 0)) {
264
-		*_r = default_q;
264
+		*_r = cfg_get(registrar, registrar_cfg, default_q);
265 265
 	} else {
266 266
 		if (str2q(_r, _q->body.s, _q->body.len) < 0) {
267 267
 			rerrno = R_INV_Q; /* Invalid q parameter */