Browse code

- fixed not updating remote target to the Contact of the in-dialog Subscribe messages (reported by Marco Happenhofer <marco.happenhofer@tuwien.ac.at>)

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

Anca Vamanu authored on 04/03/2008 15:03:31
Showing 5 changed files
... ...
@@ -91,7 +91,8 @@ void destroy_shtable(shtable_t htable, int hash_size)
91 91
 	for(i= 0; i< hash_size; i++)
92 92
 	{
93 93
 		lock_destroy(&htable[i].lock);
94
-		free_subs_list(htable[i].entries, SHM_MEM_TYPE);
94
+		free_subs_list(htable[i].entries->next, SHM_MEM_TYPE, 1);
95
+		shm_free(htable[i].entries);
95 96
 	}
96 97
 	shm_free(htable);
97 98
 	htable= NULL;
... ...
@@ -181,11 +182,72 @@ error:
181 181
 	return NULL;
182 182
 }
183 183
 
184
+
185
+subs_t* mem_copy_subs_noc(subs_t* s)
186
+{
187
+	int size;
188
+	subs_t* dest;
189
+
190
+	size= sizeof(subs_t)+ (s->pres_uri.len+ s->to_user.len
191
+		+ s->to_domain.len+ s->from_user.len+ s->from_domain.len+ s->callid.len
192
+		+ s->to_tag.len+ s->from_tag.len+s->sockinfo_str.len+s->event_id.len
193
+		+ s->local_contact.len + s->record_route.len+
194
+		+ s->reason.len+ 1)*sizeof(char);
195
+
196
+	dest= (subs_t*)shm_malloc(size);
197
+	if(dest== NULL)
198
+	{
199
+		ERR_MEM(SHARE_MEM);
200
+	}
201
+	memset(dest, 0, size);
202
+	size= sizeof(subs_t);
203
+
204
+	CONT_COPY(dest, dest->pres_uri, s->pres_uri)
205
+	CONT_COPY(dest, dest->to_user, s->to_user)
206
+	CONT_COPY(dest, dest->to_domain, s->to_domain)
207
+	CONT_COPY(dest, dest->from_user, s->from_user)
208
+	CONT_COPY(dest, dest->from_domain, s->from_domain)
209
+	CONT_COPY(dest, dest->to_tag, s->to_tag)
210
+	CONT_COPY(dest, dest->from_tag, s->from_tag)
211
+	CONT_COPY(dest, dest->callid, s->callid)
212
+	CONT_COPY(dest, dest->sockinfo_str, s->sockinfo_str)
213
+	CONT_COPY(dest, dest->local_contact, s->local_contact)
214
+	CONT_COPY(dest, dest->record_route, s->record_route)
215
+	if(s->event_id.s)
216
+		CONT_COPY(dest, dest->event_id, s->event_id)
217
+	if(s->reason.s)
218
+		CONT_COPY(dest, dest->reason, s->reason)
219
+
220
+	dest->event= s->event;
221
+	dest->local_cseq= s->local_cseq;
222
+	dest->remote_cseq= s->remote_cseq;
223
+	dest->status= s->status;
224
+	dest->version= s->version;
225
+	dest->send_on_cback= s->send_on_cback;
226
+	dest->expires= s->expires;
227
+	dest->db_flag= s->db_flag;
228
+
229
+	dest->contact.s= (char*)shm_malloc(s->contact.len* sizeof(char));
230
+	if(dest->contact.s== NULL)
231
+	{
232
+		ERR_MEM(SHARE_MEM);
233
+	}
234
+	memcpy(dest->contact.s, s->contact.s, s->contact.len);
235
+	dest->contact.len= s->contact.len;
236
+
237
+	return dest;
238
+
239
+error:
240
+	if(dest)
241
+			shm_free(dest);
242
+	return NULL;
243
+}
244
+
184 245
 int insert_shtable(shtable_t htable,unsigned int hash_code, subs_t* subs)
185 246
 {
186 247
 	subs_t* new_rec= NULL;
187
-		
188
-	new_rec= mem_copy_subs(subs, SHM_MEM_TYPE);
248
+
249
+	new_rec= mem_copy_subs_noc(subs);
189 250
 	if(new_rec== NULL)
190 251
 	{
191 252
 		LM_ERR("copying in share memory a subs_t structure\n");
... ...
@@ -228,6 +290,7 @@ int delete_shtable(shtable_t htable,unsigned int hash_code,str to_tag)
228 228
 		{
229 229
 			found= s->local_cseq;
230 230
 			ps->next= s->next;
231
+			shm_free(s->contact.s);
231 232
 			shm_free(s);
232 233
 			break;
233 234
 		}
... ...
@@ -238,7 +301,7 @@ int delete_shtable(shtable_t htable,unsigned int hash_code,str to_tag)
238 238
 	return found;
239 239
 }
240 240
 
241
-void free_subs_list(subs_t* s_array, int mem_type)
241
+void free_subs_list(subs_t* s_array, int mem_type, int ic)
242 242
 {
243 243
 	subs_t* s;
244 244
 
... ...
@@ -247,9 +310,17 @@ void free_subs_list(subs_t* s_array, int mem_type)
247 247
 		s= s_array;
248 248
 		s_array= s_array->next;
249 249
 		if(mem_type & PKG_MEM_TYPE)
250
+		{
251
+			if(ic)
252
+				pkg_free(s->contact.s);
250 253
 			pkg_free(s);
254
+		}
251 255
 		else
256
+		{
257
+			if(ic)
258
+				shm_free(s->contact.s);
252 259
 			shm_free(s);
260
+		}
253 261
 	}
254 262
 	
255 263
 }
... ...
@@ -281,6 +352,21 @@ int update_shtable(shtable_t htable,unsigned int hash_code,
281 281
 		s->local_cseq++;	
282 282
 		s->version= subs->version+ 1;
283 283
 	}
284
+	
285
+	if(strncmp(s->contact.s, subs->contact.s, subs->contact.len))
286
+	{
287
+		shm_free(s->contact.s);
288
+		s->contact.s= (char*)shm_malloc(subs->contact.len* sizeof(char));
289
+		if(s->contact.s== NULL)
290
+		{
291
+			lock_release(&htable[hash_code].lock);
292
+			LM_ERR("no more shared memory\n");
293
+			return -1;
294
+		}
295
+		memcpy(s->contact.s, subs->contact.s, subs->contact.len);
296
+		s->contact.len= subs->contact.len;
297
+	}
298
+
284 299
 	s->status= subs->status;
285 300
 	s->event= subs->event;
286 301
 	subs->db_flag= s->db_flag;
... ...
@@ -416,7 +502,7 @@ int insert_phtable(str* pres_uri, int event, char* sphere)
416 416
 	
417 417
 	if(sphere)
418 418
 	{
419
-		p->sphere= (char*)shm_malloc(strlen(sphere)*sizeof(char));
419
+		p->sphere= (char*)shm_malloc((strlen(sphere)+ 1)*sizeof(char));
420 420
 		if(p->sphere== NULL)
421 421
 		{
422 422
 			lock_release(&pres_htable[hash_code].lock);
... ...
@@ -530,7 +616,7 @@ int update_phtable(presentity_t* presentity, str pres_uri, str body)
530 530
 	}
531 531
 
532 532
 
533
-	p->sphere= (char*)shm_malloc(strlen(sphere)*sizeof(char));
533
+	p->sphere= (char*)shm_malloc((strlen(sphere)+ 1)*sizeof(char));
534 534
 	if(p->sphere== NULL)
535 535
 	{
536 536
 		lock_release(&pres_htable[hash_code].lock);
... ...
@@ -77,7 +77,7 @@ int update_shtable(shtable_t htable, unsigned int hash_code, struct subscription
77 77
 
78 78
 struct subscription* mem_copy_subs(struct subscription* s, int mem_type);
79 79
 
80
-void free_subs_list(struct subscription* s_array, int mem_type);
80
+void free_subs_list(struct subscription* s_array, int mem_type, int ic);
81 81
 
82 82
 void destroy_shtable(shtable_t htable, int hash_size);
83 83
 
... ...
@@ -1199,7 +1199,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
1199 1199
 	return s_array;
1200 1200
 
1201 1201
 error:
1202
-	free_subs_list(s_array, PKG_MEM_TYPE);
1202
+	free_subs_list(s_array, PKG_MEM_TYPE, 0);
1203 1203
 	return NULL;
1204 1204
 	
1205 1205
 }
... ...
@@ -1243,7 +1243,7 @@ int publ_notify(presentity_t* p, str pres_uri, str* body, str* offline_etag, str
1243 1243
 	ret_code= 0;
1244 1244
 
1245 1245
 done:
1246
-	free_subs_list(subs_array, PKG_MEM_TYPE);
1246
+	free_subs_list(subs_array, PKG_MEM_TYPE, 0);
1247 1247
 	
1248 1248
 	if(notify_body!=NULL)
1249 1249
 	{
... ...
@@ -1299,7 +1299,7 @@ int query_db_notify(str* pres_uri, pres_ev_t* event, subs_t* watcher_subs )
1299 1299
 	ret_code= 1;
1300 1300
 
1301 1301
 done:
1302
-	free_subs_list(subs_array, PKG_MEM_TYPE);
1302
+	free_subs_list(subs_array, PKG_MEM_TYPE, 0);
1303 1303
 	if(notify_body!=NULL)
1304 1304
 	{
1305 1305
 		if(notify_body->s)
... ...
@@ -764,13 +764,13 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)
764 764
 		s= s->next;
765 765
 	}
766 766
 	
767
-	free_subs_list(subs_array, PKG_MEM_TYPE);
767
+	free_subs_list(subs_array, PKG_MEM_TYPE, 0);
768 768
 	return 0;
769 769
 
770 770
 done:
771 771
 	if(result)
772 772
 		pa_dbf.free_result(pa_db, result);
773
-	free_subs_list(subs_array, PKG_MEM_TYPE);
773
+	free_subs_list(subs_array, PKG_MEM_TYPE, 0);
774 774
 	return err_ret;
775 775
 }
776 776
 
... ...
@@ -682,14 +682,19 @@ char* extract_sphere(str body)
682 682
 	{
683 683
 		LM_DBG("found sphere definition\n");
684 684
 		cont= (char*)xmlNodeGetContent(node);
685
-		sphere= (char*)pkg_malloc(strlen(cont)*sizeof(char));
685
+		if(cont== NULL)
686
+		{
687
+			LM_ERR("failed to extract sphere node content\n");
688
+			goto error;
689
+		}
690
+		sphere= (char*)pkg_malloc((strlen(cont)+ 1)*sizeof(char));
686 691
 		if(sphere== NULL)
687 692
 		{
688 693
 			xmlFree(cont);
689 694
 			ERR_MEM(PKG_MEM_STR);
690 695
 		}
691
-		xmlFree(cont);
692 696
 		strcpy(sphere, cont);
697
+		xmlFree(cont);
693 698
 	}
694 699
 	else
695 700
 		LM_DBG("didn't find sphere definition\n");
... ...
@@ -842,8 +847,8 @@ char* get_sphere(str* pres_uri)
842 842
 	sphere= extract_sphere(body);
843 843
 
844 844
 	pa_dbf.free_result(pa_db, result);
845
-	return sphere;
846 845
 
846
+	return sphere;
847 847
 
848 848
 error:
849 849
 	if(result)