Module: sip-router
Branch: master
Commit: fb021d55b09bfbb5503d5879a902f968f1bcabfd
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fb021d5…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Oct 6 19:06:42 2010 +0200
registrar(s): support for disabled code, reason and contact AVPs
reply_code_attr, reply_reason_attr and contact_attr modparams can
now be set to "" to disable setting the corresponding AVPs when
a save*_noreply() is used (speed-up if not needed).
---
modules_s/registrar/reg_mod.c | 70 +++++++++++++++++++++++------------------
modules_s/registrar/reg_mod.h | 1 +
modules_s/registrar/reply.c | 48 ++++++++++++++++------------
3 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/modules_s/registrar/reg_mod.c b/modules_s/registrar/reg_mod.c
index f623d1b..b21039d 100644
--- a/modules_s/registrar/reg_mod.c
+++ b/modules_s/registrar/reg_mod.c
@@ -174,42 +174,50 @@ static int parse_attr_params(void)
{
str tmp;
- tmp = reply_code_attr;
- trim(&tmp);
- if (!tmp.len || tmp.s[0] != '$') {
- ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
- }
- tmp.s++; tmp.len--;
- if (parse_avp_ident(&tmp, &avpid_code) < 0) {
- ERR("Error while parsing attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
+ if (reply_code_attr.len) {
+ tmp = reply_code_attr;
+ trim(&tmp);
+ if (!tmp.len || tmp.s[0] != '$') {
+ ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
+ return -1;
+ }
+ tmp.s++; tmp.len--;
+ if (parse_avp_ident(&tmp, &avpid_code) < 0) {
+ ERR("Error while parsing attribute name '%.*s'\n",
+ tmp.len, tmp.s);
+ return -1;
+ }
}
- tmp = reply_reason_attr;
- trim(&tmp);
- if (!tmp.len || tmp.s[0] != '$') {
- ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
- }
- tmp.s++; tmp.len--;
- if (parse_avp_ident(&tmp, &avpid_reason) < 0) {
- ERR("Error while parsing attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
+ if (reply_reason_attr.len) {
+ tmp = reply_reason_attr;
+ trim(&tmp);
+ if (!tmp.len || tmp.s[0] != '$') {
+ ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
+ return -1;
+ }
+ tmp.s++; tmp.len--;
+ if (parse_avp_ident(&tmp, &avpid_reason) < 0) {
+ ERR("Error while parsing attribute name '%.*s'\n",
+ tmp.len, tmp.s);
+ return -1;
+ }
}
- tmp = contact_attr;
- trim(&tmp);
- if (!tmp.len || tmp.s[0] != '$') {
- ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
- }
- tmp.s++; tmp.len--;
- if (parse_avp_ident(&tmp, &avpid_contact) < 0) {
- ERR("Error while parsing attribute name '%.*s'\n", tmp.len, tmp.s);
- return -1;
+ if (contact_attr.len) {
+ tmp = contact_attr;
+ trim(&tmp);
+ if (!tmp.len || tmp.s[0] != '$') {
+ ERR("Invalid attribute name '%.*s'\n", tmp.len, tmp.s);
+ return -1;
+ }
+ tmp.s++; tmp.len--;
+ if (parse_avp_ident(&tmp, &avpid_contact) < 0) {
+ ERR("Error while parsing attribute name '%.*s'\n",
+ tmp.len, tmp.s);
+ return -1;
+ }
}
-
return 0;
}
diff --git a/modules_s/registrar/reg_mod.h b/modules_s/registrar/reg_mod.h
index 6b61c29..027a571 100644
--- a/modules_s/registrar/reg_mod.h
+++ b/modules_s/registrar/reg_mod.h
@@ -57,6 +57,7 @@ extern usrloc_api_t ul; /* Structure containing pointers to usrloc
functions */
extern sl_api_t slb;
+extern str reply_code_attr, reply_reason_attr, contact_attr;
extern avp_ident_t avpid_code, avpid_reason, avpid_contact;
#endif /* REG_MOD_H */
diff --git a/modules_s/registrar/reply.c b/modules_s/registrar/reply.c
index 9661bdb..7e65596 100644
--- a/modules_s/registrar/reply.c
+++ b/modules_s/registrar/reply.c
@@ -349,40 +349,46 @@ int setup_attrs(struct sip_msg* msg)
str reason, c;
avp_value_t val;
- reason.s = NULL;
- reason.len = 0;
code = codes[rerrno];
- switch(code) {
- case 200: reason.s = MSG_200; reason.len = sizeof(MSG_200) - 1; break;
- case 400: reason.s = MSG_400; reason.len = sizeof(MSG_400) - 1; break;
- case 500: reason.s = MSG_500; reason.len = sizeof(MSG_500) - 1; break;
- case 503: reason.s = MSG_503; reason.len = sizeof(MSG_503) - 1; break;
- }
- val.n = code;
- if (add_avp(avpid_code.flags, avpid_code.name, val) < 0) {
- ERR("Error while creating reply code attribute\n");
- return -1;
+ if (reply_code_attr.len) {
+ val.n = code;
+ if (add_avp(avpid_code.flags, avpid_code.name, val) < 0) {
+ ERR("Error while creating reply code attribute\n");
+ return -1;
+ }
}
- val.s = reason;
- if (add_avp(avpid_reason.flags | AVP_VAL_STR, avpid_reason.name, val) < 0) {
- ERR("Error while creating reply reason attribute\n");
- return -1;
- }
+ if (reply_reason_attr.len) {
+ reason.s = NULL;
+ reason.len = 0;
+ switch(code) {
+ case 200: reason.s = MSG_200; reason.len = sizeof(MSG_200) - 1; break;
+ case 400: reason.s = MSG_400; reason.len = sizeof(MSG_400) - 1; break;
+ case 500: reason.s = MSG_500; reason.len = sizeof(MSG_500) - 1; break;
+ case 503: reason.s = MSG_503; reason.len = sizeof(MSG_503) - 1; break;
+ }
+ val.s = reason;
+ if (add_avp(avpid_reason.flags | AVP_VAL_STR, avpid_reason.name, val)
+ < 0) {
+ ERR("Error while creating reply reason attribute\n");
+ return -1;
+ }
+ }
- if (contact.data_len > 0) {
+ if (contact_attr.len && contact.data_len > 0) {
c.s = contact.buf;
c.len = contact.data_len;
val.s = c;
- if (add_avp(avpid_contact.flags | AVP_VAL_STR, avpid_contact.name, val) < 0) {
+ if (add_avp(avpid_contact.flags | AVP_VAL_STR, avpid_contact.name, val)
+ < 0) {
ERR("Error while creating contact attribute\n");
return -1;
- }
+ }
contact.data_len = 0;
- }
+ }
return 0;
}