- backport from opensips, revision 4480, include Daniels changes from rev4540
authorHenning Westerholt <henning.westerholt@1und1.de>
Mon, 4 Aug 2008 15:30:51 +0000 (15:30 +0000)
committerHenning Westerholt <henning.westerholt@1und1.de>
Mon, 4 Aug 2008 15:30:51 +0000 (15:30 +0000)
- fixed some bugs regarding event 'dialog;sla' processing
- Credits goes to Anca Vamanu

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4543 689a6050-402a-0410-94f2-e92a70836424

modules_k/presence/presentity.c
modules_k/presence/publish.c
modules_k/presence/subscribe.c
modules_k/presence/utils_func.h

index f056e96..d7e2a1c 100644 (file)
@@ -172,8 +172,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires,
        int size, init_len;
        
        /* allocating memory for presentity */
-       size = sizeof(presentity_t)+ (domain->len+ user->len+ etag->len + 50)
-               * sizeof(char);
+       size = sizeof(presentity_t)+ domain->len+ user->len+ etag->len +1;
        if(sender)
                size+= sizeof(str)+ sender->len* sizeof(char);
        
index 7bf7f08..ba25742 100644 (file)
@@ -465,7 +465,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                }
                if(parse_uri(buf, buf_len, &puri)!=0)
                {
-                       LM_ERR("bad owner SIP address!\n");
+                       LM_ERR("bad sender SIP address!\n");
                        reply_code= 400; 
                        reply_str= pu_400a_rpl;
                        goto error;
index 6f7098e..9ff0019 100644 (file)
@@ -660,7 +660,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        if(reason.s)
                pkg_free(reason.s);
        
-       if(parsed_event->parsed!= EVENT_DIALOG && subs.pres_uri.s)
+//     if(parsed_event->parsed!= EVENT_DIALOG && subs.pres_uri.s)
                pkg_free(subs.pres_uri.s);
        
        if((!server_address.s) || (server_address.len== 0))
@@ -692,7 +692,8 @@ error:
                }
        }
 
-       if(parsed_event->parsed!= EVENT_DIALOG &&subs.pres_uri.s)
+//  if(parsed_event->parsed!= EVENT_DIALOG &&subs.pres_uri.s)
+       if(subs.pres_uri.s)     
                pkg_free(subs.pres_uri.s);
        
        if(subs.auth_rules_doc)
@@ -824,11 +825,6 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp, int* to_tag
                subs->from_domain = uri.host;
        }
 
-       if(subs->event->evp->parsed== EVENT_DIALOG)
-       {
-               subs->pres_uri= pfrom->uri;
-       }
-
        /*generate to_tag if the message does not have a to_tag*/
        if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
        {  
@@ -892,6 +888,23 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp, int* to_tag
        LM_DBG("subs->contact= %.*s - len = %d\n",subs->contact.len,
                        subs->contact.s, subs->contact.len);    
 
+    if(subs->event->evp->parsed== EVENT_DIALOG)
+    {
+        /* user_contact@from_domain */
+        if(parse_uri(subs->contact.s, subs->contact.len, &uri)< 0)
+        {
+            LM_ERR("failed to parse contact uri\n");
+            goto error;
+        }
+        if(uandd_to_uri(uri.user, subs->from_domain, &subs->pres_uri)< 0)
+        {
+            LM_ERR("failed to construct uri\n");
+            goto error;
+        }
+        LM_DBG("&&&&&&&&&&&&&&& dialog pres_uri= %.*s\n",subs->pres_uri.len, subs->pres_uri.s);
+    }
+
+
        /*process record route and add it to a string*/
        if(*to_tag_gen && msg->record_route!=NULL)
        {
@@ -948,12 +961,18 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code,
 
        /* first try to_user== pres_user and to_domain== pres_domain */
 
-       uandd_to_uri(subs->to_user, subs->to_domain, &pres_uri);
-       if(pres_uri.s== NULL)
-       {
-               LM_ERR("creating uri from user and domain\n");
-               return -1;
-       }
+    if(subs->pres_uri.s == NULL)
+    {
+           uandd_to_uri(subs->to_user, subs->to_domain, &pres_uri);
+           if(pres_uri.s== NULL)
+           {
+                   LM_ERR("creating uri from user and domain\n");
+                   return -1;
+           }
+    }
+    else
+        pres_uri = subs->pres_uri;
+
        hash_code= core_hash(&pres_uri, &subs->event->name, shtable_size);
        lock_get(&subs_htable[hash_code].lock);
        i= hash_code;
@@ -965,9 +984,14 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code,
        }
        lock_release(&subs_htable[hash_code].lock);
 
-       pkg_free(pres_uri.s);
+    if(subs->pres_uri.s)
+        goto not_found;
+       
+    pkg_free(pres_uri.s);
        pres_uri.s= NULL;
-       LM_DBG("record not found using R-URI search iteratively\n");
+       
+
+    LM_DBG("record not found using R-URI search iteratively\n");
        /* take one row at a time */
        for(i= 0; i< shtable_size; i++)
        {
@@ -993,6 +1017,8 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code,
                return get_database_info(msg, subs, reply_code, reply_str);     
        }
 
+not_found:
+
        LM_ERR("record not found in hash_table\n");
        *reply_code= 481;
        *reply_str= pu_481_rpl;
index a4dfee3..58da566 100644 (file)
@@ -55,8 +55,8 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
                return -1;
 
        size = user.len + domain.len+7;
+       out->s = (char*)pkg_malloc(size);
 
-       out->s = (char*)pkg_malloc(size*sizeof(char));
        if(out->s == NULL)
        {
                LM_ERR("no more memory\n");
@@ -66,15 +66,13 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
        out->len = 4;
        if(user.s!=NULL && user.len>0)
        {
-               strncpy(out->s+out->len, user.s, user.len);
+               memcpy(out->s+out->len, user.s, user.len);
                out->len += user.len;
-               out->s[out->len] = '@';
-               out->len+= 1;
+               out->s[out->len++] = '@';
        }
-       strncpy(out->s + out->len, domain.s, domain.len);
+       memcpy(out->s + out->len, domain.s, domain.len);
        out->len += domain.len;
-
-       out->s[out->len] = 0;
+       out->s[out->len] = '\0';
        
        return 0;
 }
@@ -93,7 +91,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
                LM_ERR("No more memory\n");
                return NULL;
        }
-       contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE* sizeof(char));
+       contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE);
        if(contact->s== NULL)
        {
                LM_ERR("No more memory\n");
@@ -101,7 +99,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
                return NULL;
        }
 
-       memset(contact->s, 0, LCONTACT_BUF_SIZE*sizeof(char));
+       memset(contact->s, 0, LCONTACT_BUF_SIZE);
        contact->len= 0;
        
        if(msg->rcv.proto== PROTO_NONE || msg->rcv.proto==PROTO_UDP)