Browse code

*** empty log message ***

Bogdan-Andrei Iancu authored on 26/11/2001 21:48:53
Showing 1 changed files
... ...
@@ -1,9 +1,9 @@
1 1
 #include "sip_msg.h"
2 2
 #include "../../dprint.h"
3 3
 
4
+
4 5
 char*   translate_pointer( char* new_buf , char *org_buf , char* p);
5 6
 struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_body *org_via);
6
-
7 7
 struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_msg, struct hdr_field *hdr);
8 8
 
9 9
 
... ...
@@ -161,6 +161,29 @@ struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_bod
161 161
     /* comment (str type) */
162 162
     new_via->comment.s = translate_pointer( new_buf , org_buf , org_via->comment.s );
163 163
 
164
+    if ( new_via->param_lst )
165
+    {
166
+       struct via_param *vp, *new_vp, *last_new_vp;
167
+       for( vp=new_via->param_lst, last_new_vp=0 ; vp ; vp=vp->next )
168
+       {
169
+          new_vp = (struct via_param*)sh_malloc(sizeof(struct via_param));
170
+          memcpy( new_vp , vp , sizeof(struct via_param));
171
+          new_vp->name.s = translate_pointer( new_buf , org_buf , vp->name.s );
172
+          new_vp->value.s = translate_pointer( new_buf , org_buf , vp->value.s );
173
+
174
+          if (new_vp->type==PARAM_BRANCH)
175
+             new_via->branch = new_vp;
176
+
177
+        if (last_new_vp)
178
+             last_new_vp->next = new_vp;
179
+          else
180
+             new_via->param_lst = new_vp;
181
+
182
+          last_new_vp = new_vp;
183
+       }
184
+       new_via->last_param = new_vp;
185
+    }
186
+
164 187
     if ( new_via->next )
165 188
 	new_via->next = via_body_cloner( new_buf , org_buf , org_via->next );
166 189
 }
... ...
@@ -196,4 +219,113 @@ char*   translate_pointer( char* new_buf , char *org_buf , char* p)
196 219
 
197 220
 
198 221
 
222
+/* Frees the memory occupied by a SIP message
223
+  */
224
+void free_uri(struct sip_uri* u)
225
+{
226
+   if (u)
227
+   {
228
+     if (u->user.s)
229
+         sh_free(u->user.s);
230
+     if (u->passwd.s)
231
+         sh_free(u->passwd.s);
232
+     if (u->host.s)
233
+         sh_free(u->host.s);
234
+     if (u->port.s)
235
+         sh_free(u->port.s);
236
+     if (u->params.s)
237
+         sh_free(u->params.s);
238
+     if (u->headers.s)
239
+         sh_free(u->headers.s);
240
+   }
241
+}
242
+
243
+
244
+
245
+void free_via_param_list(struct via_param* vp)
246
+{
247
+   struct via_param* foo;
248
+   while(vp)
249
+    {
250
+       foo=vp;
251
+       vp=vp->next;
252
+       sh_free(foo);
253
+    }
254
+}
255
+
256
+
257
+
258
+void free_via_list(struct via_body* vb)
259
+{
260
+   struct via_body* foo;
261
+   while(vb)
262
+    {
263
+      foo=vb;
264
+      vb=vb->next;
265
+     if (foo->param_lst)
266
+        free_via_param_list(foo->param_lst);
267
+      sh_free(foo);
268
+    }
269
+}
270
+
271
+
272
+/* frees a hdr_field structure,
273
+ * WARNING: it frees only parsed (and not name.s, body.s)*/
274
+void clean_hdr_field(struct hdr_field* hf)
275
+{
276
+   if (hf->parsed)
277
+   {
278
+      switch(hf->type)
279
+      {
280
+         case HDR_VIA:
281
+               free_via_list(hf->parsed);
282
+             break;
283
+         case HDR_CSEQ:
284
+                sh_free(hf->parsed);
285
+             break;
286
+         default:
287
+      }
288
+   }
289
+}
290
+
291
+
292
+
293
+/* frees a hdr_field list,
294
+ * WARNING: frees only ->parsed and ->next*/
295
+void free_hdr_field_lst(struct hdr_field* hf)
296
+{
297
+   struct hdr_field* foo;
298
+
299
+   while(hf)
300
+    {
301
+       foo=hf;
302
+       hf=hf->next;
303
+       clean_hdr_field(foo);
304
+       pkg_free(foo);
305
+    }
306
+}
307
+
308
+
309
+
310
+/*only the content*/
311
+void sip_msg_free(struct sip_msg* msg)
312
+{
313
+   if (msg->new_uri.s)
314
+   {
315
+      sh_free(msg->new_uri.s);
316
+      msg->new_uri.len=0;
317
+   }
318
+   if (msg->headers)
319
+      free_hdr_field_lst(msg->headers);
320
+   if (msg->add_rm)
321
+      free_lump_list(msg->add_rm);
322
+   if (msg->repl_add_rm)
323
+      free_lump_list(msg->repl_add_rm);
324
+   sh_free( msg->orig );
325
+   sh_free( msg->buf );
326
+}
327
+
328
+
329
+
330
+
199 331