Browse code

topos: simplified tps_dlg_message_update()

(cherry picked from commit 7e5c4c30d2f0bbed2b566d46e5141b6abba315e7)

Daniel-Constantin Mierla authored on 26/04/2021 10:48:37
Showing 1 changed files
... ...
@@ -306,7 +306,7 @@ error:
306 306
  */
307 307
 int tps_dlg_message_update(sip_msg_t *msg, tps_data_t *ptsd, int ctmode)
308 308
 {
309
-	str tmp;
309
+	str tuuid = STR_NULL;
310 310
 	int ret;
311 311
 
312 312
 	if(parse_sip_msg_uri(msg)<0) {
... ...
@@ -314,14 +314,15 @@ int tps_dlg_message_update(sip_msg_t *msg, tps_data_t *ptsd, int ctmode)
314 314
 		return -1;
315 315
 	}
316 316
 
317
+	if(msg->parsed_uri.sip_params.len<10) {
318
+		LM_DBG("not an expected %s format\n", (ctmode==0)?"user":"param");
319
+		return 1;
320
+	}
321
+
317 322
 	if (ctmode == 1 || ctmode == 2) {
318
-		if(msg->parsed_uri.sip_params.len<10) {
319
-			LM_DBG("not an expected param format\n");
320
-			return 1;
321
-		}
322
-		// find parameter, there might be others
323
+		/* find the r-uri parameter */
323 324
 		ret = tps_get_param_value(&msg->parsed_uri.params,
324
-			&_tps_cparam_name, &tmp);
325
+			&_tps_cparam_name, &tuuid);
325 326
 		if (ret < 0) {
326 327
 			LM_ERR("failed to parse param\n");
327 328
 			return -1;
... ...
@@ -330,31 +331,20 @@ int tps_dlg_message_update(sip_msg_t *msg, tps_data_t *ptsd, int ctmode)
330 331
 			LM_DBG("prefix para not found\n");
331 332
 			return 1;
332 333
 		}
333
-		if(memcmp(tmp.s, "atpsh-", 6)==0) {
334
-			ptsd->a_uuid = tmp;
335
-			return 0;
336
-		}
337
-		if(memcmp(tmp.s, "btpsh-", 6)==0) {
338
-			ptsd->a_uuid = tmp;
339
-			ptsd->b_uuid = tmp;
340
-			return 0;
341
-		}
342
-
343 334
 	} else {
344
-		if(msg->parsed_uri.user.len<10) {
345
-			LM_DBG("not an expected user format\n");
346
-			return 1;
347
-		}
348
-		if(memcmp(msg->parsed_uri.user.s, "atpsh-", 6)==0) {
349
-			ptsd->a_uuid = msg->parsed_uri.user;
350
-			return 0;
351
-		}
352
-		if(memcmp(msg->parsed_uri.user.s, "btpsh-", 6)==0) {
353
-			ptsd->a_uuid = msg->parsed_uri.user;
354
-			ptsd->b_uuid = msg->parsed_uri.user;
355
-			return 0;
356
-		}
335
+		tuuid = msg->parsed_uri.user;
336
+	}
337
+
338
+	if(memcmp(tuuid.s, "atpsh-", 6)==0) {
339
+		ptsd->a_uuid = tuuid;
340
+		return 0;
341
+	}
342
+	if(memcmp(tuuid.s, "btpsh-", 6)==0) {
343
+		ptsd->a_uuid = tuuid;
344
+		ptsd->b_uuid = tuuid;
345
+		return 0;
357 346
 	}
347
+
358 348
 	LM_DBG("not an expected prefix\n");
359 349
 
360 350
 	return 1;
... ...
@@ -840,7 +830,6 @@ int tps_request_received(sip_msg_t *msg, int dialog)
840 830
 	if(((get_cseq(msg)->method_id) & (METHOD_BYE|METHOD_PRACK|METHOD_UPDATE))
841 831
 			&& stsd.b_contact.len <= 0) {
842 832
 		/* no B-side contact, look for INVITE transaction record */
843
-		memset(&stsd, 0, sizeof(tps_data_t));
844 833
 		if((get_cseq(msg)->method_id) & (METHOD_UPDATE)) {
845 834
 			/* detect direction - via from-tag */
846 835
 			if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) {
... ...
@@ -850,6 +839,8 @@ int tps_request_received(sip_msg_t *msg, int dialog)
850 839
 		if(tps_storage_link_msg(msg, &mtsd, direction) < 0) {
851 840
 			goto error;
852 841
 		}
842
+		mtsd.direction = direction;
843
+		memset(&stsd, 0, sizeof(tps_data_t));
853 844
 		if(tps_storage_load_branch(msg, &mtsd, &stsd, 1) < 0) {
854 845
 			goto error;
855 846
 		}
... ...
@@ -859,9 +850,9 @@ int tps_request_received(sip_msg_t *msg, int dialog)
859 850
 		if(tps_dlg_detect_direction(msg, &stsd, &direction) < 0) {
860 851
 			goto error;
861 852
 		}
853
+		mtsd.direction = direction;
862 854
 	}
863 855
 
864
-	mtsd.direction = direction;
865 856
 
866 857
 	tps_storage_lock_release(&lkey);
867 858