Module: sip-router Branch: master Commit: c2b7096ec4705252637c7e8fb13450c1c5172d17 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c2b7096e...
Author: Marius Zbihlei marius.zbihlei@1and1.ro Committer: Marius Zbihlei marius.zbihlei@1and1.ro Date: Wed Feb 17 13:52:48 2010 +0200
Modules_k/registrar Other module variables added to configuration framework
Also added callback that modify the statistics to reflect the changes via sercmd
---
modules_k/registrar/common.c | 5 +++- modules_k/registrar/config.c | 19 +++++++++++++---- modules_k/registrar/config.h | 8 +++++++ modules_k/registrar/lookup.c | 4 +- modules_k/registrar/reg_mod.c | 43 +++++++++++++++++++++------------------- modules_k/registrar/reg_mod.h | 9 +++---- modules_k/registrar/sip_msg.c | 2 +- 7 files changed, 56 insertions(+), 34 deletions(-)
diff --git a/modules_k/registrar/common.c b/modules_k/registrar/common.c index 1118d7d..824b635 100644 --- a/modules_k/registrar/common.c +++ b/modules_k/registrar/common.c @@ -56,7 +56,8 @@ int extract_aor(str* _uri, str* _a) int_str avp_val; struct usr_avp *avp; str *uri; - + str realm_prefix; + memset(aor_buf, 0, MAX_AOR_LEN); if (aor_avp_name.n!=0) { avp = search_first_avp( aor_avp_type, aor_avp_name, &avp_val, 0); @@ -98,6 +99,8 @@ int extract_aor(str* _uri, str* _a) if (user_len) aor_buf[_a->len++] = '@'; /* strip prefix (if defined) */ + realm_prefix.s = cfg_get(registrar, registrar_cfg, realm_pref); + realm_prefix.len = strlen(realm_prefix.s); if (realm_prefix.len && realm_prefix.len<puri.host.len && (memcmp(realm_prefix.s, puri.host.s, realm_prefix.len)==0) ) { memcpy(aor_buf + _a->len, puri.host.s + realm_prefix.len, diff --git a/modules_k/registrar/config.c b/modules_k/registrar/config.c index 8f58478..3c56a54 100644 --- a/modules_k/registrar/config.c +++ b/modules_k/registrar/config.c @@ -39,17 +39,20 @@ struct cfg_group_registrar default_registrar_cfg = { 0, /* max_expires */ 0, /* max_contacts */ 0, /* retry_after */ - 0 /* case_sensitive */ - }; + 0, /* case_sensitive */ + Q_UNSPECIFIED, /* default_q */ + 1, /* append_branches */ + "", /* realm_pref */ + };
void *registrar_cfg = &default_registrar_cfg;
cfg_def_t registrar_cfg_def[] = { - {"default_expires", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, + {"default_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, default_expires_stats_update, "Contains number of second to expire if no expire hf or contact expire present" }, - {"min_expires", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, + {"min_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, min_expires_stats_update, "The minimum expires value of a Contact. Value 0 disables the checking. "}, - {"max_expires", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, + {"max_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, max_expires_stats_update, "The maximum expires value of a Contact. Value 0 disables the checking. "}, {"max_contacts", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, "The maximum number of Contacts for an AOR. Value 0 disables the checking. "}, @@ -57,5 +60,11 @@ cfg_def_t registrar_cfg_def[] = { "If you want to add the Retry-After header field in 5xx replies, set this parameter to a value grater than zero"}, {"case_sensitive", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, "If set to 1 then AOR comparison will be case sensitive. Recommended and default is 0, case insensitive"}, + {"default_q", CFG_VAR_INT | CFG_ATOMIC, -1, 1000, 0, 0, + "The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */ + {"append_branches", CFG_VAR_INT , 0, 0, 0, 0, + "If set to 1(default), lookup will put all contacts found in msg structure"}, + {"realm_pref", CFG_VAR_STR , 0, 0, 0, 0, + "Realm prefix to be removed. Default is """}, {0, 0, 0, 0, 0, 0} }; diff --git a/modules_k/registrar/config.h b/modules_k/registrar/config.h index bd30b82..1c20fd3 100644 --- a/modules_k/registrar/config.h +++ b/modules_k/registrar/config.h @@ -21,6 +21,7 @@ #ifndef _REGISTRAR_CONFIG_H #define _REGISTRAR_CONFIG_H
+#include "../../qvalue.h"
#include "../../cfg/cfg.h" #include "../../str.h" @@ -32,11 +33,18 @@ struct cfg_group_registrar { unsigned int max_contacts; unsigned int retry_after; unsigned int case_sensitive; + qvalue_t default_q; + unsigned int append_branches; + char* realm_pref; + char* rcv_param; };
extern struct cfg_group_registrar default_registrar_cfg; extern void *registrar_cfg; extern cfg_def_t registrar_cfg_def[];
+extern void default_expires_stats_update(str*, str*); +extern void min_expires_stats_update(str*, str*); +extern void max_expires_stats_update(str*, str*);
#endif diff --git a/modules_k/registrar/lookup.c b/modules_k/registrar/lookup.c index 67accc7..c758c84 100644 --- a/modules_k/registrar/lookup.c +++ b/modules_k/registrar/lookup.c @@ -45,7 +45,7 @@ #include "regtime.h" #include "reg_mod.h" #include "lookup.h" - +#include "config.h"
#define allowed_method(_msg, _c) \ ( !method_filtering || ((_msg)->REQ_METHOD)&((_c)->methods) ) @@ -144,7 +144,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _s) }
/* Append branches if enabled */ - if (!append_branches) goto done; + if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done;
for( ; ptr ; ptr = ptr->next ) { if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) { diff --git a/modules_k/registrar/reg_mod.c b/modules_k/registrar/reg_mod.c index 5c6fbb6..877810b 100644 --- a/modules_k/registrar/reg_mod.c +++ b/modules_k/registrar/reg_mod.c @@ -94,10 +94,6 @@ static int fetchc_fixup(void** param, int param_no); /*! \brief Functions */ static int add_sock_hdr(struct sip_msg* msg, char *str, char *foo);
- -qvalue_t default_q = Q_UNSPECIFIED; /*!< Default q value multiplied by 1000 */ -int append_branches = 1; /*!< If set to 1, lookup will put all contacts found in msg structure */ -int case_sensitive = 0; /*!< If set to 1, username in aor will be case sensitive */ int tcp_persistent_flag = -1; /*!< if the TCP connection should be kept open */ int method_filtering = 0; /*!< if the looked up contacts should be filtered based on supported methods */ int path_enabled = 0; /*!< if the Path HF should be handled */ @@ -124,8 +120,6 @@ unsigned short rcv_avp_type = 0; int_str rcv_avp_name;
int reg_use_domain = 0; -char* realm_pref = ""; /*!< Realm prefix to be removed */ -str realm_prefix;
int sock_flag = -1; str sock_hdr_name = {0,0}; @@ -183,11 +177,11 @@ static cmd_export_t cmds[] = { */ static param_export_t params[] = { {"default_expires", INT_PARAM, &default_registrar_cfg.default_expires }, - {"default_q", INT_PARAM, &default_q }, - {"append_branches", INT_PARAM, &append_branches }, + {"default_q", INT_PARAM, &default_registrar_cfg.default_q }, + {"append_branches", INT_PARAM, &default_registrar_cfg.append_branches }, {"case_sensitive", INT_PARAM, &default_registrar_cfg.case_sensitive }, /* {"tcp_persistent_flag",INT_PARAM, &tcp_persistent_flag }, */ - {"realm_prefix", STR_PARAM, &realm_pref }, + {"realm_prefix", STR_PARAM, &default_registrar_cfg.realm_pref }, {"min_expires", INT_PARAM, &default_registrar_cfg.min_expires }, {"max_expires", INT_PARAM, &default_registrar_cfg.max_expires }, {"received_param", STR_PARAM, &rcv_param }, @@ -261,9 +255,6 @@ static int mod_init(void) return -1; }
- realm_prefix.s = realm_pref; - realm_prefix.len = strlen(realm_pref); - rcv_param.len = strlen(rcv_param.s); if(cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), ®istrar_cfg)){ @@ -333,16 +324,17 @@ static int mod_init(void) }
/* Normalize default_q parameter */ - if (default_q != Q_UNSPECIFIED) { - if (default_q > MAX_Q) { - LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", default_q, MAX_Q); - default_q = MAX_Q; - } else if (default_q < MIN_Q) { - LM_DBG("default_q = %d, raising to MIN_Q: %d\n", default_q, MIN_Q); - default_q = MIN_Q; + qvalue_t dq = cfg_get(registrar, registrar_cfg, default_q); + if ( dq!= Q_UNSPECIFIED) { + if (dq > MAX_Q) { + LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q); + dq = MAX_Q; + } else if (dq < MIN_Q) { + LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q); + dq = MIN_Q; } } - + cfg_get(registrar, registrar_cfg, default_q) = dq;
if (bind_usrloc(&ul) < 0) { return -1; @@ -536,3 +528,14 @@ error: return -1; }
+void default_expires_stats_update(str* gname, str* name){ + update_stat(default_expires_stat, cfg_get(registrar, registrar_cfg, default_expires)); +} + +void min_expires_stats_update(str* gname, str* name){ + update_stat(min_expires_stat, cfg_get(registrar, registrar_cfg, min_expires)); +} + +void max_expires_stats_update(str* gname, str* name){ + update_stat(max_expires_stat, cfg_get(registrar, registrar_cfg, max_expires)); +} diff --git a/modules_k/registrar/reg_mod.h b/modules_k/registrar/reg_mod.h index 4c420c5..477cfb4 100644 --- a/modules_k/registrar/reg_mod.h +++ b/modules_k/registrar/reg_mod.h @@ -67,15 +67,10 @@ #define REG_SAVE_REPL_FL (1<<2) #define REG_SAVE_ALL_FL ((1<<3)-1)
-extern int default_expires; -extern qvalue_t default_q; -extern int append_branches; -extern int case_sensitive; extern int nat_flag; extern int tcp_persistent_flag; extern int received_avp; extern int reg_use_domain; -extern str realm_prefix; extern float def_q;
extern unsigned short aor_avp_type; @@ -101,4 +96,8 @@ extern struct sl_binds slb; extern stat_var *accepted_registrations; extern stat_var *rejected_registrations;
+extern void default_expires_stats_update(str*, str*); +extern void min_expires_stats_update(str*, str*); +extern void max_expires_stats_update(str*, str*); + #endif /* REG_MOD_H */ diff --git a/modules_k/registrar/sip_msg.c b/modules_k/registrar/sip_msg.c index 2e5f65c..d44e5ca 100644 --- a/modules_k/registrar/sip_msg.c +++ b/modules_k/registrar/sip_msg.c @@ -261,7 +261,7 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e) int calc_contact_q(param_t* _q, qvalue_t* _r) { if (!_q || (_q->body.len == 0)) { - *_r = default_q; + *_r = cfg_get(registrar, registrar_cfg, default_q); } else { if (str2q(_r, _q->body.s, _q->body.len) < 0) { rerrno = R_INV_Q; /* Invalid q parameter */