Ver código fonte

- backport from opensips, revision 4480, include Daniels changes from rev4540
- 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

Henning Westerholt 17 anos atrás
pai
commit
360a429406

+ 1 - 2
modules_k/presence/presentity.c

@@ -172,8 +172,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires,
 	int size, init_len;
 	int size, init_len;
 	
 	
 	/* allocating memory for presentity */
 	/* 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)
 	if(sender)
 		size+= sizeof(str)+ sender->len* sizeof(char);
 		size+= sizeof(str)+ sender->len* sizeof(char);
 	
 	

+ 1 - 1
modules_k/presence/publish.c

@@ -465,7 +465,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
 		}
 		}
 		if(parse_uri(buf, buf_len, &puri)!=0)
 		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_code= 400; 
 			reply_str= pu_400a_rpl;
 			reply_str= pu_400a_rpl;
 			goto error;
 			goto error;

+ 41 - 15
modules_k/presence/subscribe.c

@@ -660,7 +660,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 	if(reason.s)
 	if(reason.s)
 		pkg_free(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);
 		pkg_free(subs.pres_uri.s);
 	
 	
 	if((!server_address.s) || (server_address.len== 0))
 	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);
 		pkg_free(subs.pres_uri.s);
 	
 	
 	if(subs.auth_rules_doc)
 	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;
 		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*/
 	/*generate to_tag if the message does not have a to_tag*/
 	if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
 	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,
 	LM_DBG("subs->contact= %.*s - len = %d\n",subs->contact.len,
 			subs->contact.s, 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*/
 	/*process record route and add it to a string*/
 	if(*to_tag_gen && msg->record_route!=NULL)
 	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 */
 	/* 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);
 	hash_code= core_hash(&pres_uri, &subs->event->name, shtable_size);
 	lock_get(&subs_htable[hash_code].lock);
 	lock_get(&subs_htable[hash_code].lock);
 	i= hash_code;
 	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);
 	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;
 	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 */
 	/* take one row at a time */
 	for(i= 0; i< shtable_size; i++)
 	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);	
 		return get_database_info(msg, subs, reply_code, reply_str);	
 	}
 	}
 
 
+not_found:
+
 	LM_ERR("record not found in hash_table\n");
 	LM_ERR("record not found in hash_table\n");
 	*reply_code= 481;
 	*reply_code= 481;
 	*reply_str= pu_481_rpl;
 	*reply_str= pu_481_rpl;

+ 7 - 9
modules_k/presence/utils_func.h

@@ -55,8 +55,8 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
 		return -1;
 		return -1;
 
 
 	size = user.len + domain.len+7;
 	size = user.len + domain.len+7;
+	out->s = (char*)pkg_malloc(size);
 
 
-	out->s = (char*)pkg_malloc(size*sizeof(char));
 	if(out->s == NULL)
 	if(out->s == NULL)
 	{
 	{
 		LM_ERR("no more memory\n");
 		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;
 	out->len = 4;
 	if(user.s!=NULL && user.len>0)
 	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->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->len += domain.len;
-
-	out->s[out->len] = 0;
+	out->s[out->len] = '\0';
 	
 	
 	return 0;
 	return 0;
 }
 }
@@ -93,7 +91,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
 		LM_ERR("No more memory\n");
 		LM_ERR("No more memory\n");
 		return NULL;
 		return NULL;
 	}
 	}
-	contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE* sizeof(char));
+	contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE);
 	if(contact->s== NULL)
 	if(contact->s== NULL)
 	{
 	{
 		LM_ERR("No more memory\n");
 		LM_ERR("No more memory\n");
@@ -101,7 +99,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
 		return NULL;
 		return NULL;
 	}
 	}
 
 
-	memset(contact->s, 0, LCONTACT_BUF_SIZE*sizeof(char));
+	memset(contact->s, 0, LCONTACT_BUF_SIZE);
 	contact->len= 0;
 	contact->len= 0;
 	
 	
 	if(msg->rcv.proto== PROTO_NONE || msg->rcv.proto==PROTO_UDP)
 	if(msg->rcv.proto== PROTO_NONE || msg->rcv.proto==PROTO_UDP)