Module: sip-router
Branch: master
Commit: 29f0779226712f631eff5664f08cdada96f4eef0
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=29f0779…
Author: Hugh Waite <hugh.waite(a)crocodile-rcs.com>
Committer: Hugh Waite <hugh.waite(a)crocodile-rcs.com>
Date: Mon Mar 11 17:37:12 2013 +0000
registrar: New set_q_override function
The set_q_override function will override the value of the q parameter
from the Contact header in subsequent calls to the save() function for
the current request.
Currently exported as a C-API function
---
modules/registrar/api.c | 15 +++++++++++++++
modules/registrar/api.h | 4 ++++
modules/registrar/save.c | 22 +++++++++++++++++++++-
modules/registrar/save.h | 1 +
4 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/modules/registrar/api.c b/modules/registrar/api.c
index adce1be..04fdc0e 100644
--- a/modules/registrar/api.c
+++ b/modules/registrar/api.c
@@ -111,6 +111,20 @@ int regapi_registered(struct sip_msg *msg, char *table)
/**
*
*/
+int regapi_set_q_override(struct sip_msg *msg, str *new_q)
+{
+ int _q;
+ if (str2q(&_q, new_q->s, new_q->len) < 0)
+ {
+ LM_ERR("invalid q parameter\n");
+ return -1;
+ }
+ return set_q_override(msg, _q);
+}
+
+/**
+ *
+ */
int bind_registrar(registrar_api_t* api)
{
if (!api) {
@@ -122,6 +136,7 @@ int bind_registrar(registrar_api_t* api)
api->lookup = regapi_lookup;
api->lookup_uri = regapi_lookup_uri;
api->registered = regapi_registered;
+ api->set_q_override = regapi_set_q_override;
return 0;
}
diff --git a/modules/registrar/api.h b/modules/registrar/api.h
index 006c596..2968ded 100644
--- a/modules/registrar/api.h
+++ b/modules/registrar/api.h
@@ -43,6 +43,9 @@ int regapi_lookup(struct sip_msg *msg, char *table);
typedef int (*regapi_lookup_uri_f)(struct sip_msg *msg, char *table, str *uri);
int regapi_lookup_uri(struct sip_msg *msg, char *table, str *uri);
+typedef int (*regapi_set_q_override_f)(struct sip_msg *msg, str *new_q);
+int regapi_set_q_override(struct sip_msg *msg, str *new_q);
+
/**
* @brief REGISTRAR API structure
*/
@@ -52,6 +55,7 @@ typedef struct registrar_api {
regapi_lookup_f lookup;
regapi_lookup_uri_f lookup_uri;
regapi_lookup_f registered;
+ regapi_set_q_override_f set_q_override;
} registrar_api_t;
typedef int (*bind_registrar_f)(registrar_api_t* api);
diff --git a/modules/registrar/save.c b/modules/registrar/save.c
index 7596c6a..aa2d2b3 100644
--- a/modules/registrar/save.c
+++ b/modules/registrar/save.c
@@ -81,6 +81,9 @@ static int mem_only = 0;
extern sruid_t _reg_sruid;
+static int q_override_msg_id;
+static qvalue_t q_override_value;
+
/*! \brief
* Process request that contained a star, in that case,
* we will remove all bindings with the given username
@@ -308,7 +311,11 @@ static inline ucontact_info_t* pack_ci( struct sip_msg* _m,
contact_t* _c,
ci.c = &_c->uri;
/* Calculate q value of the contact */
- if (calc_contact_q(_c->q, &ci.q) < 0) {
+ if (m && m->id == q_override_msg_id)
+ {
+ ci.q = q_override_value;
+ }
+ else if (calc_contact_q(_c->q, &ci.q) < 0) {
rerrno = R_INV_Q;
LM_ERR("failed to calculate q\n");
goto error;
@@ -914,3 +921,16 @@ int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri)
return 1;
}
+int set_q_override(struct sip_msg* _m, int _q)
+{
+ if ((_q < 0) || (_q > 1000))
+ {
+ LM_ERR("Invalid q value\n");
+ return -1;
+ }
+ q_override_msg_id = _m->id;
+ q_override_value = _q;
+ return 1;
+}
+
+
diff --git a/modules/registrar/save.h b/modules/registrar/save.h
index 69e1352..e7e385c 100644
--- a/modules/registrar/save.h
+++ b/modules/registrar/save.h
@@ -48,6 +48,7 @@
*/
int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str* _uri);
int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri);
+int set_q_override(struct sip_msg* _m, int _q);
#endif /* SAVE_H */