Browse code

ims_ipsec_pcscf: clean local parsed tm uas request headers

Daniel-Constantin Mierla authored on 04/05/2022 07:57:53
Showing 1 changed files
... ...
@@ -140,7 +140,7 @@ static str get_www_auth_param(const char* param_name, str www_auth)
140 140
     return val;
141 141
 }
142 142
 
143
-static int fill_contact(struct pcontact_info* ci, struct sip_msg* m)
143
+static int fill_contact(struct pcontact_info* ci, struct sip_msg* m, tm_cell_t *t)
144 144
 {
145 145
     contact_body_t* cb = NULL;
146 146
     struct via_body* vb = NULL;
... ...
@@ -244,7 +244,6 @@ static int fill_contact(struct pcontact_info* ci, struct sip_msg* m)
244 244
 		}
245 245
 	}
246 246
     else if(m->first_line.type == SIP_REPLY) {
247
-        struct cell *t = tmb.t_gett();
248 247
         if (!t || t == (void*) -1) {
249 248
             LM_ERR("Reply without transaction\n");
250 249
             return -1;
... ...
@@ -651,9 +650,13 @@ int ipsec_create(struct sip_msg* m, udomain_t* d, int _cflags)
651 650
     pcontact_t* pcontact = NULL;
652 651
     struct pcontact_info ci;
653 652
     int ret = IPSEC_CMD_FAIL;   // FAIL by default
653
+	tm_cell_t *t = NULL;
654 654
 
655
+    if(m->first_line.type == SIP_REPLY) {
656
+        t = tmb.t_gett();
657
+    }
655 658
     // Find the contact
656
-    if(fill_contact(&ci, m) != 0) {
659
+    if(fill_contact(&ci, m, t) != 0) {
657 660
         LM_ERR("Error filling in contact data\n");
658 661
         return ret;
659 662
     }
... ...
@@ -681,7 +684,7 @@ int ipsec_create(struct sip_msg* m, udomain_t* d, int _cflags)
681 684
     }
682 685
 
683 686
     // Get request from reply
684
-    struct cell *t = tmb.t_gett();
687
+    if (!t) t = tmb.t_gett();
685 688
     if (!t || t == (void*) -1) {
686 689
         LM_ERR("Reply without transaction\n");
687 690
         goto cleanup;
... ...
@@ -765,6 +768,9 @@ cleanup:
765 768
     // Do not free str* sec_header! It will be freed in data_lump.c -> free_lump()
766 769
     ul.unlock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
767 770
     pkg_free(ci.received_host.s);
771
+	if(t) {
772
+		tmb.t_uas_request_clean_parsed(t);
773
+	}
768 774
     return ret;
769 775
 }
770 776
 
... ...
@@ -778,11 +784,12 @@ int ipsec_forward(struct sip_msg* m, udomain_t* d, int _cflags)
778 784
     unsigned short dst_port = 0;
779 785
     unsigned short src_port = 0;
780 786
     ip_addr_t via_host;
781
-    
782 787
     struct sip_msg* req = NULL;
788
+    struct cell *t = NULL;
789
+
783 790
     if(m->first_line.type == SIP_REPLY) {
784 791
         // Get request from reply
785
-        struct cell *t = tmb.t_gett();
792
+        t = tmb.t_gett();
786 793
         if (!t) {
787 794
             LM_ERR("Error getting transaction\n");
788 795
             return ret;
... ...
@@ -796,7 +803,7 @@ int ipsec_forward(struct sip_msg* m, udomain_t* d, int _cflags)
796 803
     //
797 804
     // Find the contact
798 805
     //
799
-    if(fill_contact(&ci, m) != 0) {
806
+    if(fill_contact(&ci, m, t) != 0) {
800 807
         LM_ERR("Error filling in contact data\n");
801 808
         return ret;
802 809
     }
... ...
@@ -864,7 +871,7 @@ int ipsec_forward(struct sip_msg* m, udomain_t* d, int _cflags)
864 871
 
865 872
         // for Request sends from P-CSCF client port
866 873
         src_port = s->port_pc;
867
-        
874
+
868 875
         // for Request sends to UE server port
869 876
         dst_port = s->port_us;
870 877
     }
... ...
@@ -934,6 +941,9 @@ int ipsec_forward(struct sip_msg* m, udomain_t* d, int _cflags)
934 941
 cleanup:
935 942
     ul.unlock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
936 943
     pkg_free(ci.received_host.s);
944
+	if(t) {
945
+		tmb.t_uas_request_clean_parsed(t);
946
+	}
937 947
     return ret;
938 948
 }
939 949
 
... ...
@@ -943,11 +953,14 @@ int ipsec_destroy(struct sip_msg* m, udomain_t* d)
943 953
     struct pcontact_info ci;
944 954
     pcontact_t* pcontact = NULL;
945 955
     int ret = IPSEC_CMD_FAIL; // FAIL by default
956
+	tm_cell_t *t = NULL;
957
+
958
+    if(m->first_line.type == SIP_REPLY) {
959
+        t = tmb.t_gett();
960
+    }
946 961
 
947
-    //
948 962
     // Find the contact
949
-    //
950
-    if(fill_contact(&ci, m) != 0) {
963
+    if(fill_contact(&ci, m, t) != 0) {
951 964
         LM_ERR("Error filling in contact data\n");
952 965
         return ret;
953 966
     }
... ...
@@ -978,6 +991,9 @@ int ipsec_destroy(struct sip_msg* m, udomain_t* d)
978 991
 cleanup:
979 992
     ul.unlock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
980 993
     pkg_free(ci.received_host.s);
994
+	if(t) {
995
+		tmb.t_uas_request_clean_parsed(t);
996
+	}
981 997
     return ret;
982 998
 }
983 999