Module: sip-router
Branch: master
Commit: cd1ff5364786f8b32058921be6f3216b48e34792
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cd1ff53…
Author: Anca Vamanu <anca.vamanu(a)1and1.ro>
Committer: Anca Vamanu <anca.vamanu(a)1and1.ro>
Date: Wed May 2 18:42:55 2012 +0300
modules_k/presence Fixed wrong cseq and wrong expires bugs
1. Wrong cseq bug: happened in subs_db_mode!= DB_ONLY when generating
Notify with expires=0 that was not triggered by a received Subscribe
2. Problem with expires raported in Notify message. There was a static
buffer used twice when building the extra headers for Notify leading to
expires parameter value always having last digits '70' (the value of
Max-Forwards).
---
modules_k/presence/notify.c | 116 ++++++++++++++--------------------------
modules_k/presence/presence.c | 4 +-
modules_k/presence/subscribe.c | 2 +
3 files changed, 45 insertions(+), 77 deletions(-)
diff --git a/modules_k/presence/notify.c b/modules_k/presence/notify.c
index 4f8d68b..f778511 100644
--- a/modules_k/presence/notify.c
+++ b/modules_k/presence/notify.c
@@ -134,18 +134,17 @@ int build_str_hdr(subs_t* subs, int is_body, str* hdr)
pres_ev_t* event= subs->event;
str expires = {0, 0};
str status = {0, 0};
- str tmp = {0, 0};
+ char* p;
str trans = {";transport=", 11};
- if(hdr == NULL)
- {
+ if(hdr == NULL) {
LM_ERR("bad parameter\n");
return -1;
}
expires.s = int2str(subs->expires, &expires.len);
+
status.s= get_status_str(subs->status);
- if(status.s == NULL)
- {
+ if(status.s == NULL) {
LM_ERR("bad status %d\n", subs->status);
return -1;
}
@@ -161,104 +160,71 @@ int build_str_hdr(subs_t* subs, int is_body, str* hdr)
(14 /*Content-Type: */+subs->event->content_type.len + CRLF_LEN):0) + 1;
hdr->s = (char*)pkg_malloc(hdr->len);
- if(hdr->s == NULL)
- {
- LM_ERR("no more pkg\n");
+ if(hdr->s == NULL) {
+ LM_ERR("no more pkg memory\n");
return -1;
}
- strncpy(hdr->s, "Max-Forwards: ", 14);
- tmp.s = int2str((unsigned long)MAX_FORWARD, &tmp.len);
- strncpy(hdr->s+14, tmp.s, tmp.len);
- tmp.s = hdr->s + tmp.len + 14;
- strncpy(tmp.s, CRLF, CRLF_LEN);
- tmp.s += CRLF_LEN;
-
- strncpy(tmp.s ,"Event: ", 7);
- tmp.s += 7;
- strncpy(tmp.s, event->name.s, event->name.len);
- tmp.s += event->name.len;
- if(subs->event_id.len && subs->event_id.s)
- {
- strncpy(tmp.s, ";id=", 4);
- tmp.s += 4;
- strncpy(tmp.s, subs->event_id.s, subs->event_id.len);
- tmp.s += subs->event_id.len;
- }
- strncpy(tmp.s, CRLF, CRLF_LEN);
- tmp.s += CRLF_LEN;
-
- strncpy(tmp.s, "Contact: <", 10);
- tmp.s += 10;
- strncpy(tmp.s, subs->local_contact.s, subs->local_contact.len);
- tmp.s += subs->local_contact.len;
+ p = hdr->s;
+ p += sprintf(p, "Max-Forwards: %d\r\n", MAX_FORWARD);
+
+ p += sprintf(p ,"Event: %.*s", event->name.len, event->name.s);
+ if(subs->event_id.len && subs->event_id.s) {
+ p += sprintf(p, ";id=%.*s", subs->event_id.len, subs->event_id.s);
+ }
+ memcpy(p, CRLF, CRLF_LEN);
+ p += CRLF_LEN;
+
+ p += sprintf(p, "Contact: <%.*s", subs->local_contact.len,
subs->local_contact.s);
if(subs->sockinfo_str.s!=NULL
- && str_search(&subs->local_contact, &trans)==0)
- {
+ && str_search(&subs->local_contact, &trans)==0) {
/* fix me */
switch(subs->sockinfo_str.s[0]) {
case 's':
case 'S':
- strncpy(tmp.s, ";transport=sctp", 15);
- tmp.s += 15;
+ memcpy(p, ";transport=sctp", 15);
+ p += 15;
break;
case 't':
case 'T':
switch(subs->sockinfo_str.s[1]) {
case 'c':
case 'C':
- strncpy(tmp.s, ";transport=tcp", 14);
- tmp.s += 14;
+ memcpy(p, ";transport=tcp", 14);
+ p += 14;
break;
case 'l':
case 'L':
- strncpy(tmp.s, ";transport=tls", 14);
- tmp.s += 14;
+ memcpy(p, ";transport=tls", 14);
+ p += 14;
break;
}
break;
}
}
- *tmp.s = '>';
- tmp.s++;
- strncpy(tmp.s, CRLF, CRLF_LEN);
- tmp.s += CRLF_LEN;
-
- strncpy(tmp.s, "Subscription-State: ", 20);
- tmp.s += 20;
- strncpy(tmp.s, status.s, status.len);
- tmp.s += status.len;
-
- if(subs->status == TERMINATED_STATUS)
- {
+ *p = '>';
+ p++;
+ memcpy(p, CRLF, CRLF_LEN);
+ p += CRLF_LEN;
+
+ p += sprintf(p, "Subscription-State: %.*s", status.len, status.s);
+
+ if(subs->status == TERMINATED_STATUS) {
LM_DBG("state = terminated\n");
-
- strncpy(tmp.s, ";reason=", 8);
- tmp.s += 8;
- strncpy(tmp.s, subs->reason.s, subs->reason.len);
- tmp.s += subs->reason.len;
- } else {
- strncpy(tmp.s, ";expires=", 9);
- tmp.s += 9;
- LM_DBG("expires = %d\n", subs->expires);
- strncpy(tmp.s, expires.s, expires.len);
- tmp.s += expires.len;
- }
- strncpy(tmp.s, CRLF, CRLF_LEN);
- tmp.s += CRLF_LEN;
-
- if(is_body)
- {
- strncpy(tmp.s,"Content-Type: ", 14);
- tmp.s += 14;
- strncpy(tmp.s, event->content_type.s, event->content_type.len);
- tmp.s += event->content_type.len;
- strncpy(tmp.s, CRLF, CRLF_LEN);
- tmp.s += CRLF_LEN;
+ p += sprintf(p, ";reason=%.*s", subs->reason.len, subs->reason.s);
+ } else {
+ p += sprintf(p, ";expires=%.*s", expires.len, expires.s);
+ }
+ memcpy(p, CRLF, CRLF_LEN);
+ p += CRLF_LEN;
+
+ if(is_body) {
+ p += sprintf(p,"Content-Type: %.*s\r\n", event->content_type.len,
+ event->content_type.s);
}
- *tmp.s = '\0';
- hdr->len = tmp.s - hdr->s;
+ *p = '\0';
+ hdr->len = p - hdr->s;
return 0;
}
diff --git a/modules_k/presence/presence.c b/modules_k/presence/presence.c
index 1580942..e9b5681 100644
--- a/modules_k/presence/presence.c
+++ b/modules_k/presence/presence.c
@@ -1143,7 +1143,6 @@ send_notify:
while(s)
{
-
if(notify(s, NULL, NULL, 0)< 0)
{
LM_ERR( "sending Notify request\n");
@@ -1376,7 +1375,7 @@ static int update_pw_dialogs_dbonlymode(subs_t* subs, subs_t**
subs_array)
pa_dbf.free_result(pa_db, result);
return(-1);
}
-
+ cs->local_cseq++;
cs->next= (*subs_array);
(*subs_array)= cs;
@@ -1458,6 +1457,7 @@ static int update_pw_dialogs(subs_t* subs, unsigned int hash_code,
subs_t** subs
lock_release(&subs_htable[hash_code].lock);
return -1;
}
+ cs->local_cseq++;
cs->expires-= (int)time(NULL);
cs->next= (*subs_array);
(*subs_array)= cs;
diff --git a/modules_k/presence/subscribe.c b/modules_k/presence/subscribe.c
index 161a2a0..add1581 100644
--- a/modules_k/presence/subscribe.c
+++ b/modules_k/presence/subscribe.c
@@ -1472,6 +1472,7 @@ int handle_expired_subs(subs_t* s)
s->reason.s= "timeout";
s->reason.len= 7;
s->expires= 0;
+ s->local_cseq++;
if(send_notify_request(s, NULL, NULL, 1)< 0)
{
@@ -2270,6 +2271,7 @@ int refresh_watcher(str* pres_uri, str* watcher_uri, str* event,
return -1;
}
lock_release(&subs_htable[hash_code].lock);
+ s_copy->local_cseq++;
if(notify(s_copy, NULL, NULL, 0)< 0)
{
LM_ERR("in notify function\n");