Browse code

tm: backup/restore lists of avps for usage t_uac

- when sending a self-generated request while processing other sip
message, backup the list of avps and restore afterwards
- reported by Sebastian Damm
- added helper function to backup/restore the lists of avps from msg
context to static var and use transaction lists

Daniel-Constantin Mierla authored on 01/08/2011 12:36:39
Showing 3 changed files
... ...
@@ -487,4 +487,41 @@ error0:
487 487
 }
488 488
 
489 489
 
490
+/**
491
+ * backup xdata from/to msg context to local var and use T lists
492
+ * - mode = 0 - from msg context to _txdata and use T lists
493
+ * - mode = 1 - restore to msg context from _txdata
494
+ */
495
+void tm_xdata_swap(tm_cell_t *t, int mode)
496
+{
497
+	static tm_xdata_t _txdata;
498
+	tm_xdata_t *x;
499
+
500
+	x = &_txdata;
501
+
502
+	if(mode==0) {
503
+		if(t==NULL)
504
+			return;
505
+		x->uri_avps_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, &t->uri_avps_from );
506
+		x->uri_avps_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, &t->uri_avps_to );
507
+		x->user_avps_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, &t->user_avps_from );
508
+		x->user_avps_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, &t->user_avps_to );
509
+		x->domain_avps_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, &t->domain_avps_from );
510
+		x->domain_avps_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, &t->domain_avps_to );
511
+#ifdef WITH_XAVP
512
+		x->xavps_list = xavp_set_list(&t->xavps_list);
513
+#endif
514
+	} else if(mode==1) {
515
+		/* restore original avp list */
516
+		set_avp_list( AVP_TRACK_FROM | AVP_CLASS_URI, x->uri_avps_from );
517
+		set_avp_list( AVP_TRACK_TO | AVP_CLASS_URI, x->uri_avps_to );
518
+		set_avp_list( AVP_TRACK_FROM | AVP_CLASS_USER, x->user_avps_from );
519
+		set_avp_list( AVP_TRACK_TO | AVP_CLASS_USER, x->user_avps_to );
520
+		set_avp_list( AVP_TRACK_FROM | AVP_CLASS_DOMAIN, x->domain_avps_from );
521
+		set_avp_list( AVP_TRACK_TO | AVP_CLASS_DOMAIN, x->domain_avps_to );
522
+#ifdef WITH_XAVP
523
+		xavp_set_list(x->xavps_list);
524
+#endif
525
+	}
490 526
 
527
+}
... ...
@@ -300,6 +300,25 @@ struct totag_elem {
300 300
  * saves us 2*2 bytes */
301 301
 typedef unsigned short retr_timeout_t;
302 302
 
303
+
304
+/**
305
+ * extra data from SIP message context to transaction storage
306
+ */
307
+typedef struct tm_xdata
308
+{
309
+	/* lists with avps */
310
+	struct usr_avp **uri_avps_from;
311
+	struct usr_avp **uri_avps_to;
312
+	struct usr_avp **user_avps_from;
313
+	struct usr_avp **user_avps_to;
314
+	struct usr_avp **domain_avps_from;
315
+	struct usr_avp **domain_avps_to;
316
+#ifdef WITH_XAVP
317
+	sr_xavp_t **xavps_list;
318
+#endif
319
+} tm_xdata_t;
320
+
321
+
303 322
 /* transaction context */
304 323
 
305 324
 typedef struct cell
... ...
@@ -370,7 +389,7 @@ typedef struct cell
370 389
 	 * many due to downstream forking; */
371 390
 	struct totag_elem *fwded_totags;
372 391
 
373
-	     /* list with avp */
392
+	     /* lists with avps */
374 393
 	struct usr_avp *uri_avps_from;
375 394
 	struct usr_avp *uri_avps_to;
376 395
 	struct usr_avp *user_avps_from;
... ...
@@ -543,6 +562,11 @@ inline static void remove_from_hash_table_unsafe( struct cell * p_cell)
543 562
 	t_stats_deleted( is_local(p_cell) );
544 563
 }
545 564
 
565
+/**
566
+ * backup xdata from/to msg context to local var and use T lists
567
+ */
568
+void tm_xdata_swap(tm_cell_t *t, int mode);
569
+
546 570
 #endif
547 571
 
548 572
 
... ...
@@ -352,9 +352,8 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
352 352
 			#ifdef USE_COMP
353 353
 				lreq.rcv.comp=dst.comp;
354 354
 			#endif /* USE_COMP */
355
-				/* AVPs are reset anyway afterwards, so no need to 
356
-				   backup/restore them*/
357 355
 				sflag_bk = getsflags();
356
+				tm_xdata_swap(new_cell, 0);
358 357
 
359 358
 				/* run the route */
360 359
 				backup_route_type = get_route_type();
... ...
@@ -373,6 +372,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
373 372
 				set_route_type( backup_route_type );
374 373
 
375 374
 				/* restore original environment */
375
+				tm_xdata_swap(new_cell, 1);
376 376
 				setsflagsval(sflag_bk);
377 377
 
378 378
 				if (unlikely(lreq.new_uri.s))
... ...
@@ -408,13 +408,6 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
408 408
 	}
409 409
 #endif
410 410
 
411
-	/* better reset avp list now - anyhow, it's useless from
412
-	 * this point (bogdan) */
413
-	reset_avps();
414
-#ifdef WITH_XAVP
415
-	xavp_reset_list();
416
-#endif
417
-
418 411
 	new_cell->method.s = buf;
419 412
 	new_cell->method.len = uac_r->method->len;
420 413