Browse code

msilo(k): simplified getting of From/To

Daniel-Constantin Mierla authored on 05/01/2011 19:00:49
Showing 1 changed files
... ...
@@ -480,7 +480,7 @@ static int child_init(int rank)
480 480
 static int m_store(struct sip_msg* msg, char* owner, char* s2)
481 481
 {
482 482
 	str body, str_hdr, ctaddr;
483
-	struct to_body to, *pto, *pfrom;
483
+	struct to_body *pto, *pfrom;
484 484
 	struct sip_uri puri;
485 485
 	str duri, owner_s;
486 486
 	db_key_t db_keys[NR_KEYS-1];
... ...
@@ -528,34 +528,13 @@ static int m_store(struct sip_msg* msg, char* owner, char* s2)
528 528
 	}
529 529
 	
530 530
 	/* get TO URI */
531
-	if(!msg->to || !msg->to->body.s)
531
+	if(parse_to_header(msg)<0)
532 532
 	{
533
-	    LM_ERR("cannot find 'to' header!\n");
533
+	    LM_ERR("failed getting 'to' header!\n");
534 534
 	    goto error;
535 535
 	}
536 536
 	
537
-	if(msg->to->parsed != NULL)
538
-	{
539
-		pto = (struct to_body*)msg->to->parsed;
540
-		LM_DBG("the 'To' header ALREADY PARSED: <%.*s>\n",
541
-			pto->uri.len, pto->uri.s );	
542
-	}
543
-	else
544
-	{
545
-		LM_DBG("the 'To' header NOT PARSED ->parsing ...\n");
546
-		memset( &to , 0, sizeof(to) );
547
-		parse_to(msg->to->body.s, msg->to->body.s+msg->to->body.len+1, &to);
548
-		if(to.uri.len > 0) /* && to.error == PARSE_OK) */
549
-		{
550
-			LM_DBG("'To' parsed OK <%.*s>.\n", to.uri.len, to.uri.s);
551
-			pto = &to;
552
-		}
553
-		else
554
-		{
555
-			LM_ERR("'To' cannot be parsed\n");
556
-			goto error;
557
-		}
558
-	}
537
+	pto = get_to(msg);
559 538
 	
560 539
 	/* get the owner */
561 540
 	memset(&puri, 0, sizeof(struct sip_uri));
... ...
@@ -649,23 +628,12 @@ static int m_store(struct sip_msg* msg, char* owner, char* s2)
649 649
 	nr_keys++;
650 650
 
651 651
 	/* check FROM URI */
652
-	if(!msg->from || !msg->from->body.s)
652
+	if ( parse_from_header( msg )<0 ) 
653 653
 	{
654
-		LM_ERR("cannot find 'from' header!\n");
654
+		LM_ERR("cannot parse From header\n");
655 655
 		goto error;
656 656
 	}
657
-
658
-	if(msg->from->parsed == NULL)
659
-	{
660
-		LM_DBG("'From' header not parsed\n");
661
-		/* parsing from header */
662
-		if ( parse_from_header( msg )<0 ) 
663
-		{
664
-			LM_ERR("cannot parse From header\n");
665
-			goto error;
666
-		}
667
-	}
668
-	pfrom = (struct to_body*)msg->from->parsed;
657
+	pfrom = get_from(msg);
669 658
 	LM_DBG("'From' header: <%.*s>\n", pfrom->uri.len, pfrom->uri.s);	
670 659
 	
671 660
 	db_keys[nr_keys] = &sc_from;
... ...
@@ -859,7 +827,7 @@ error:
859 859
  */
860 860
 static int m_dump(struct sip_msg* msg, char* owner, char* str2)
861 861
 {
862
-	struct to_body to, *pto = NULL;
862
+	struct to_body *pto = NULL;
863 863
 	db_key_t db_keys[3];
864 864
 	db_key_t ob_key;
865 865
 	db_op_t  db_ops[3];
... ...
@@ -900,32 +868,13 @@ static int m_dump(struct sip_msg* msg, char* owner, char* str2)
900 900
 	body_str.len=1024;
901 901
 	
902 902
 	/* check for TO header */
903
-	if(msg->to==NULL && (parse_headers(msg, HDR_TO_F, 0)==-1
904
-				|| msg->to==NULL || msg->to->body.s==NULL))
903
+	if(parse_to_header(msg)<0)
905 904
 	{
906
-		LM_ERR("cannot find TO HEADER!\n");
905
+		LM_ERR("failed parsing  To header\n");
907 906
 		goto error;
908 907
 	}
909 908
 
910
-	/* get TO header URI */
911
-	if(msg->to->parsed != NULL)
912
-	{
913
-		pto = (struct to_body*)msg->to->parsed;
914
-		LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",
915
-			pto->uri.len, pto->uri.s );	
916
-	}
917
-	else
918
-	{
919
-		memset( &to , 0, sizeof(to) );
920
-		parse_to(msg->to->body.s,
921
-			msg->to->body.s + msg->to->body.len + 1, &to);
922
-		if(to.uri.len <= 0) /* || to.error != PARSE_OK) */
923
-		{
924
-			LM_ERR("'To' header NOT parsed\n");
925
-			goto error;
926
-		}
927
-		pto = &to;
928
-	}
909
+	pto = get_to(msg);
929 910
 
930 911
 	/**
931 912
 	 * check if has expires=0 (REGISTER)