Module: sip-router Branch: master Commit: 1ff39475221c823a3da2cc02b10121771137b780 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1ff39475...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Mon Apr 16 23:05:40 2012 +0200
registrar(k): add gruu parameters only when supported
- check Supported header for gruu tag in order to ad pub/temp-gruu to the Contact header in 200ok
---
modules_k/registrar/reply.c | 23 ++++++++++++++++++----- modules_k/registrar/reply.h | 2 +- modules_k/registrar/save.c | 24 ++++++++++++------------ 3 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/modules_k/registrar/reply.c b/modules_k/registrar/reply.c index 818888a..a759aeb 100644 --- a/modules_k/registrar/reply.c +++ b/modules_k/registrar/reply.c @@ -89,8 +89,9 @@ static struct { /*! \brief * Calculate the length of buffer needed to * print contacts + * - mode specifies if GRUU header params are added */ -static inline unsigned int calc_buf_len(ucontact_t* c, str *host) +static inline unsigned int calc_buf_len(ucontact_t* c, str *host, int mode) { unsigned int len; int qlen; @@ -112,7 +113,7 @@ static inline unsigned int calc_buf_len(ucontact_t* c, str *host) + 1 /* dquote */ ; } - if (c->instance.len>0) { + if (c->instance.len>0 && mode==1) { /* pub-gruu */ len += PUB_GRUU_PARAM_LEN + 1 /* " */ @@ -137,6 +138,8 @@ static inline unsigned int calc_buf_len(ucontact_t* c, str *host) - 1 /* = */ + 1 /* " */ ; + } + if (c->instance.len>0) { /* +sip-instance */ len += SIP_INSTANCE_PARAM_LEN + 1 /* " */ @@ -157,7 +160,7 @@ static inline unsigned int calc_buf_len(ucontact_t* c, str *host) * Allocate a memory buffer and print Contact * header fields into it */ -int build_contact(ucontact_t* c, str *host) +int build_contact(sip_msg_t *msg, ucontact_t* c, str *host) { char *p, *cp; char *a; @@ -166,9 +169,17 @@ int build_contact(ucontact_t* c, str *host) str inst; unsigned int ahash; unsigned short digit; + int mode; +
+ if(msg!=NULL && parse_supported(msg)==0 + && (get_supported(msg) & F_SUPPORTED_GRUU)) + mode = 1; + else + mode = 0; + + contact.data_len = calc_buf_len(c, host, mode);
- contact.data_len = calc_buf_len(c, host); if (!contact.data_len) return 0;
if (!contact.buf || (contact.buf_len < contact.data_len)) { @@ -228,7 +239,7 @@ int build_contact(ucontact_t* c, str *host) p += c->received.len; *p++ = '"'; } - if (c->instance.len>0) { + if (c->instance.len>0 && mode==1) { user.s = c->aor->s; a = memchr(c->aor->s, '@', c->aor->len); if(a!=NULL) { @@ -284,7 +295,9 @@ int build_contact(ucontact_t* c, str *host) memcpy(p, GR_PARAM, GR_PARAM_LEN); p += GR_PARAM_LEN - 1; *p++ = '"'; + }
+ if (c->instance.len>0) { /* +sip-instance */ memcpy(p, SIP_INSTANCE_PARAM, SIP_INSTANCE_PARAM_LEN); p += SIP_INSTANCE_PARAM_LEN; diff --git a/modules_k/registrar/reply.h b/modules_k/registrar/reply.h index 963d970..f17f3c0 100644 --- a/modules_k/registrar/reply.h +++ b/modules_k/registrar/reply.h @@ -44,7 +44,7 @@ int reg_send_reply(struct sip_msg* _m); /*! \brief * Build Contact HF for reply */ -int build_contact(ucontact_t* c, str* host); +int build_contact(sip_msg_t *msg, ucontact_t* c, str* host);
/*! \brief diff --git a/modules_k/registrar/save.c b/modules_k/registrar/save.c index 36bff89..78e0c24 100644 --- a/modules_k/registrar/save.c +++ b/modules_k/registrar/save.c @@ -85,7 +85,7 @@ extern sruid_t _reg_sruid; * we will remove all bindings with the given username * from the usrloc and return 200 OK response */ -static inline int star(udomain_t* _d, str* _a, str *_h) +static inline int star(sip_msg_t *_m, udomain_t* _d, str* _a, str *_h) { urecord_t* r; ucontact_t* c; @@ -115,7 +115,7 @@ static inline int star(udomain_t* _d, str* _a, str *_h) */ rerrno = R_UL_DEL_R; if (!ul.get_urecord(_d, _a, &r)) { - build_contact(r->contacts, _h); + build_contact(_m, r->contacts, _h); ul.release_urecord(r); } ul.unlock_udomain(_d, _a); @@ -186,7 +186,7 @@ static struct socket_info *get_sock_hdr(struct sip_msg *msg) * containing a list of all existing bindings for the * given username (in To HF) */ -static inline int no_contacts(udomain_t* _d, str* _a, str* _h) +static inline int no_contacts(sip_msg_t *_m, udomain_t* _d, str* _a, str* _h) { urecord_t* r; int res; @@ -201,10 +201,10 @@ static inline int no_contacts(udomain_t* _d, str* _a, str* _h) } if (res == 0) { /* Contacts found */ - build_contact(r->contacts, _h); + build_contact(_m, r->contacts, _h); ul.release_urecord(r); } else { /* No contacts found */ - build_contact(NULL, _h); + build_contact(_m, NULL, _h); } ul.unlock_udomain(_d, _a); return 0; @@ -508,10 +508,10 @@ static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a)
if (r) { if (r->contacts) - build_contact(r->contacts, &u->host); + build_contact(_m, r->contacts, &u->host); ul.release_urecord(r); } else { /* No contacts found */ - build_contact(NULL, &u->host); + build_contact(_m, NULL, &u->host); }
#ifdef USE_TCP @@ -788,12 +788,12 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
if (res == 0) { /* Contacts found */ if ((ret=update_contacts(_m, r, _mode)) < 0) { - build_contact(r->contacts, &u->host); + build_contact(_m, r->contacts, &u->host); ul.release_urecord(r); ul.unlock_udomain(_d, _a); return -3; } - build_contact(r->contacts, &u->host); + build_contact(_m, r->contacts, &u->host); ul.release_urecord(r); } else { if (insert_contacts(_m, _d, _a) < 0) { @@ -846,10 +846,10 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
if (c == 0) { if (st) { - if (star((udomain_t*)_d, &aor, &u->host) < 0) goto error; + if (star(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=3; } else { - if (no_contacts((udomain_t*)_d, &aor, &u->host) < 0) goto error; + if (no_contacts(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=4; } } else { @@ -889,7 +889,7 @@ int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri) return -1; }
- if (star(_d, &aor, &u->host) < 0) + if (star(_m, _d, &aor, &u->host) < 0) { LM_ERR("error unregistering user [%.*s]\n", aor.len, aor.s); return -1;