Browse code

sip: patch temporary Contact-HFs instead of the given ones

Raphael Coeffic authored on 19/11/2013 12:25:53
Showing 3 changed files
... ...
@@ -59,6 +59,27 @@ int  copy_hdrs_len_no_via(const list<sip_header*>& hdrs)
59 59
     return ret;
60 60
 }
61 61
 
62
+int  copy_hdrs_len_no_via_contact(const list<sip_header*>& hdrs)
63
+{
64
+    int ret = 0;
65
+
66
+    list<sip_header*>::const_iterator it = hdrs.begin();
67
+    for(;it != hdrs.end(); ++it){
68
+
69
+      switch((*it)->type) {
70
+      case sip_header::H_VIA:
71
+      case sip_header::H_CONTACT:
72
+	continue;
73
+
74
+      default:
75
+	ret += copy_hdr_len(*it);
76
+	break;
77
+      }
78
+    }
79
+    
80
+    return ret;
81
+}
82
+
62 83
 void copy_hdrs_wr(char** c, const list<sip_header*>& hdrs)
63 84
 {
64 85
     list<sip_header*>::const_iterator it = hdrs.begin();
... ...
@@ -77,3 +98,20 @@ void copy_hdrs_wr_no_via(char** c, const list<sip_header*>& hdrs)
77 98
         copy_hdr_wr(c,*it);
78 99
     }
79 100
 }
101
+
102
+void copy_hdrs_wr_no_via_contact(char** c, const list<sip_header*>& hdrs)
103
+{
104
+    list<sip_header*>::const_iterator it = hdrs.begin();
105
+    for(;it != hdrs.end(); ++it){
106
+
107
+      switch((*it)->type) {
108
+      case sip_header::H_VIA:
109
+      case sip_header::H_CONTACT:
110
+	continue;
111
+
112
+      default:
113
+	copy_hdr_wr(c,*it);
114
+	break;
115
+      }
116
+    }
117
+}
... ...
@@ -179,10 +179,11 @@ using std::list;
179 179
 
180 180
 
181 181
 int  copy_hdrs_len(const list<sip_header*>& hdrs);
182
-int  copy_hdrs_len_no_via(const list<sip_header*>& hdrs);
182
+int  copy_hdrs_len_no_via_contact(const list<sip_header*>& hdrs);
183 183
 
184 184
 void copy_hdrs_wr(char** c, const list<sip_header*>& hdrs);
185 185
 void copy_hdrs_wr_no_via(char** c, const list<sip_header*>& hdrs);
186
+void copy_hdrs_wr_no_via_contact(char** c, const list<sip_header*>& hdrs);
186 187
 
187 188
 
188 189
 #endif
... ...
@@ -1170,17 +1170,20 @@ static int generate_and_parse_new_msg(sip_msg* msg, sip_msg*& p_msg)
1170 1170
     vector<string> contact_buffers(msg->contacts.size());
1171 1171
     vector<string>::iterator contact_buf_it = contact_buffers.begin();
1172 1172
 
1173
+    list<sip_header*> n_contacts;
1173 1174
     for(list<sip_header*>::iterator contact_it = msg->contacts.begin();
1174 1175
 	contact_it != msg->contacts.end(); contact_it++, contact_buf_it++) {
1175 1176
 	
1176
-	patch_contact_transport(*contact_it,trsp,*contact_buf_it);
1177
+	n_contacts.push_back(new sip_header(**contact_it));
1178
+	patch_contact_transport(n_contacts.back(),trsp,*contact_buf_it);
1177 1179
     }
1178 1180
 
1179 1181
     // add 'rport' parameter defaultwise? yes, for now
1180 1182
     request_len += via_len(trsp,stl2cstr(via),branch,true);
1181 1183
  
1182 1184
     request_len += copy_hdrs_len(msg->vias);
1183
-    request_len += copy_hdrs_len_no_via(msg->hdrs);
1185
+    request_len += copy_hdrs_len_no_via_contact(msg->hdrs);
1186
+    request_len += copy_hdrs_len(n_contacts);
1184 1187
      
1185 1188
     string content_len = int2str(msg->body.len);
1186 1189
      
... ...
@@ -1203,7 +1206,10 @@ static int generate_and_parse_new_msg(sip_msg* msg, sip_msg*& p_msg)
1203 1206
  
1204 1207
     via_wr(&c,trsp,stl2cstr(via),branch,true);
1205 1208
     copy_hdrs_wr(&c,msg->vias);
1206
-    copy_hdrs_wr_no_via(&c,msg->hdrs);
1209
+    copy_hdrs_wr_no_via_contact(&c,msg->hdrs);
1210
+
1211
+    copy_hdrs_wr(&c,n_contacts);
1212
+    free_headers(n_contacts);
1207 1213
 
1208 1214
     content_length_wr(&c,stl2cstr(content_len));
1209 1215