Browse code

To parsing and tag used in ACK matching

Bogdan-Andrei Iancu authored on 07/02/2002 16:02:45
Showing 10 changed files
... ...
@@ -170,6 +170,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
170 170
 	goto error;
171 171
    new_cell->relaied_reply_branch   = -1;
172 172
    new_cell->T_canceled = T_UNDEFINED;
173
+   new_cell->tag=&(get_to(new_cell->inbound_request)->tag_value);
173 174
 #ifndef USE_SYNONIM
174 175
    src[0]= p_msg->from->body;
175 176
    src[1]= p_msg->to->body;
... ...
@@ -78,18 +78,17 @@ typedef struct cell
78 78
 
79 79
 	/* useful data */
80 80
 	/* UA Server */
81
-	struct sip_msg 		*inbound_request;
81
+	struct sip_msg             *inbound_request;
82 82
 	struct retrans_buff	outbound_response;
83
-	unsigned int		status;
84
-	str*				tag;
85
-	unsigned int		inbound_request_isACKed;
86
-	int					relaied_reply_branch;
87
-	int					nr_of_outgoings;
83
+	unsigned int                status;
84
+	str                                 *tag;
85
+	unsigned int                inbound_request_isACKed;
86
+	int                                 relaied_reply_branch;
87
+	int                                 nr_of_outgoings;
88 88
 	/* UA Clients */
89
-	struct retrans_buff	*outbound_request[ MAX_FORK ];
90
-	struct sip_msg		*inbound_response[ MAX_FORK ];
91
-	/* unsigned int		outbound_request_isACKed[MAX_FORK]; */
92
-	struct retrans_buff	*outbound_ack[ MAX_FORK ];
89
+	struct retrans_buff      *outbound_request[ MAX_FORK ];
90
+	struct sip_msg             *inbound_response[ MAX_FORK ];
91
+	struct retrans_buff      *outbound_ack[ MAX_FORK ];
93 92
 
94 93
 	/* protection against concurrent reply processing */
95 94
 	ser_lock_t	reply_mutex;
... ...
@@ -12,474 +12,6 @@
12 12
 
13 13
 #define ROUND4(s) ((s)%4)?((s)+4)/4*4:(s)
14 14
 
15
-struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_body *org_via);
16
-struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_msg, struct hdr_field *hdr);
17
-
18
-struct via_body* via_body_cloner_2( char* new_buf , char *org_buf , struct via_body *org_via, char **p);
19
-
20
-
21
-struct sip_msg* sip_msg_cloner_1( struct sip_msg *org_msg )
22
-{
23
-    struct sip_msg   *new_msg=0;
24
-    struct hdr_field  *header, *last_hdr, *new_hdr;
25
-
26
-    /* clones the sip_msg structure */
27
-    new_msg = (struct sip_msg*)sh_malloc( sizeof( struct sip_msg) );
28
-    if (!new_msg) {
29
-	DBG("DEBUG: sip_msg_cloner: sip_msg allocation failed\n");
30
-	return NULL;
31
-    }
32
-    memcpy( new_msg , org_msg , sizeof( struct sip_msg) );
33
-
34
-    /* if something bad happens during the allocation process,
35
-       don't try to release pointers which were cloned
36
-    */
37
-    new_msg->new_uri.s=NULL;
38
-    new_msg->headers=NULL;
39
-    new_msg->add_rm=NULL;
40
-    new_msg->repl_add_rm=NULL;
41
-    new_msg->orig=NULL;
42
-    new_msg->buf=NULL;
43
-
44
-    /* the original message - orig ( char*  type) */
45
-    new_msg->orig = (char*)sh_malloc( new_msg->len+1 );
46
-    if (!new_msg->orig) {
47
-	DBG("DEBUG: sip_msg_cloner: new_msg->orig allocation failed\n");
48
-	goto error;
49
-    }
50
-    memcpy( new_msg->orig , org_msg->orig, new_msg->len );
51
-    new_msg->orig[ new_msg->len ] = 0;
52
-
53
-    /* the scratch pad - buf ( char* type) */
54
-    new_msg->buf = (char*)sh_malloc( new_msg->len+1 );
55
-    if (!new_msg->buf) {
56
-	DBG("DEBUG: sip_msg_cloner:  new_msg->buf allocation failed\n");
57
-	goto error;
58
-    }
59
-    memcpy( new_msg->buf , org_msg->buf, new_msg->len );
60
-    new_msg->buf[ new_msg->len ] = 0;
61
-
62
-    /* where the parse stopped - unparsed (char* type)*/
63
-    new_msg->unparsed = translate_pointer( new_msg->buf , org_msg->buf , org_msg->unparsed );
64
-
65
-    /* end of header - eoh (char* type)*/
66
-    new_msg->eoh = translate_pointer( new_msg->buf , org_msg->buf , org_msg->eoh );
67
-
68
-    /* first_line (struct msg_start type) */
69
-    if ( org_msg->first_line.type==SIP_REQUEST )
70
-    {
71
-	/* method (str type) */
72
-	new_msg->first_line.u.request.method.s = translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.request.method.s );
73
-	/* uri (str type) */
74
-	new_msg->first_line.u.request.uri.s = translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.request.uri.s );
75
-	/* version (str type) */
76
-	new_msg->first_line.u.request.version.s = translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.request.version.s );
77
-    }
78
-    else if ( org_msg->first_line.type==SIP_REPLY )
79
-    {
80
-	/* version (str type) */
81
-	new_msg->first_line.u.reply.version.s = translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.reply.version.s );
82
-	/* status (str type) */
83
-	new_msg->first_line.u.reply.status.s =  translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.reply.status.s );
84
-	/* reason (str type) */
85
-	new_msg->first_line.u.reply.reason.s =  translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.reply.reason.s );
86
-    }
87
-
88
-    /* new_uri  ( str type )*/
89
-	if (org_msg->new_uri.s){
90
-		if (!(new_msg->new_uri.s = (char*)sh_malloc( org_msg->new_uri.len )))
91
-		{
92
-			DBG("DEBUG: sip_msg_cloner: new_msg->new_uri.s allocation failed\n");
93
-			goto error;
94
-		}
95
-		memcpy( new_msg->new_uri.s , org_msg->new_uri.s ,
96
-				org_msg->new_uri.len );
97
-	}
98
-
99
-    /* add_rm ( struct lump* )  -> have to be changed!!!!!!! */
100
-    new_msg->add_rm  = 0;
101
-    /* repl_add_rm ( struct lump* ) -> have to be changed!!!!!!!  */
102
-    new_msg->repl_add_rm  = 0;
103
-
104
-    /* all the headers */
105
-    new_msg->via1=0;
106
-    new_msg->via2=0;
107
-    for( header = org_msg->headers , last_hdr=0  ;  header ; header=header->next)
108
-    {
109
-	new_hdr = header_cloner( new_msg , org_msg , header );
110
-	if (!new_hdr) {
111
-		DBG("DEBUG: sip_msg_cloner: new_hdr allocation failed\n");
112
-		goto error;
113
-	}
114
-	switch ( header->type )
115
-	{
116
-	    case HDR_VIA :
117
-		if ( !new_msg->via1 )
118
-		{
119
-		    new_msg->h_via1 = new_hdr;
120
-		    new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
121
-		    if (!new_msg->via1) {
122
-			DBG("DEBUG: sip_msg_cloner:  new_msg->via1 allocation failed\n");
123
-			goto hf_error;
124
-		    }
125
-
126
-		    new_hdr->parsed  = (void*)new_msg->via1;
127
-		     if ( new_msg->via1->next )
128
-		        new_msg->via2 = new_msg->via1->next;
129
-		}
130
-		else if ( !new_msg->via2 && new_msg->via1 )
131
-		{
132
-		     new_msg->h_via2 = new_hdr;
133
-		     if ( new_msg->via1->next )
134
-		        new_hdr->parsed = (void*)new_msg->via1->next;
135
-		     else{
136
-		        new_msg->via2 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
137
-			if (!new_msg->via2) {
138
-				DBG("DEBUG: sip_msg_cloner:  new_msg->via2 allocation failed\n");
139
-				goto hf_error;
140
-			}
141
-		        new_hdr->parsed  = (void*)new_msg->via2;
142
-		     }
143
-		}
144
-		else if ( new_msg->via2 && new_msg->via1 )
145
-		{
146
-		    new_hdr->parsed  = new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
147
-		    if (!new_hdr->parsed) {
148
-				DBG("DEBUG: sip_msg_cloner:  new_hdr->parsed  via1 allocation failed\n");
149
-				goto hf_error;
150
-		    }
151
-		}
152
-		break;
153
-	    case HDR_FROM :
154
-		new_msg->from = new_hdr;
155
-		break;
156
-	    case HDR_TO :
157
-		new_msg->to = new_hdr;
158
-		break;
159
-	    case HDR_CSEQ :
160
-		if (header->parsed)
161
-		{
162
-		  new_hdr->parsed = (void*)sh_malloc( sizeof(struct cseq_body) );
163
-		  if (!new_hdr->parsed) {
164
-			DBG("DEBUG: sip_msg_cloner:  new_hdr->parsed  cseq allocation failed\n");
165
-			goto hf_error;
166
-		  }
167
-		  memcpy( new_hdr->parsed , header->parsed , sizeof(struct cseq_body) );
168
-		  ((struct cseq_body*)new_hdr->parsed)->number.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->number.s );
169
-		  ((struct cseq_body*)new_hdr->parsed)->method.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->method.s );
170
-		}
171
-		new_msg->cseq = new_hdr;
172
-		break;
173
-	    case HDR_CALLID :
174
-		new_msg->callid = new_hdr;
175
-		break;
176
-	    case HDR_CONTACT :
177
-		new_msg->contact = new_hdr;
178
-		break;
179
-	    case HDR_MAXFORWARDS :
180
-		new_msg->maxforwards = new_hdr;
181
-		break;
182
-	    case HDR_ROUTE :
183
-		new_msg->route = new_hdr;
184
-		break;
185
-	    default :
186
-		break;
187
-	}
188
-
189
-	if ( last_hdr )
190
-	{
191
-	    last_hdr->next = new_hdr;
192
-	    last_hdr=last_hdr->next;
193
-	 }
194
-	 else
195
-	 {
196
-	    last_hdr=new_hdr;
197
-	    new_msg->headers =new_hdr;
198
-	}
199
-    	last_hdr->next = 0;
200
-    	new_msg->last_header = last_hdr;
201
-    }
202
-
203
-    return new_msg;
204
-
205
-hf_error:
206
-	sh_free( new_hdr );
207
-error:
208
-	sip_msg_free( new_msg );
209
-	/* sh_free( new_msg ); */
210
-	return 0;
211
-
212
-}
213
-
214
-
215
-
216
-
217
-struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_body *org_via)
218
-{
219
-    struct via_body *new_via;
220
-
221
-    /* clones the via_body structure */
222
-    new_via = (struct via_body*)sh_malloc( sizeof( struct via_body) );
223
-    if (!new_via) return NULL;
224
-    memcpy( new_via , org_via , sizeof( struct via_body) );
225
-
226
-    /* hdr (str type) */
227
-    new_via->hdr.s = translate_pointer( new_buf , org_buf , org_via->hdr.s );
228
-    /* name (str type) */
229
-    new_via->name.s = translate_pointer( new_buf , org_buf , org_via->name.s );
230
-    /* version (str type) */
231
-    new_via->version.s = translate_pointer( new_buf , org_buf , org_via->version.s );
232
-    /* transport (str type) */
233
-    new_via->transport.s = translate_pointer( new_buf , org_buf , org_via->transport.s );
234
-    /* host (str type) */
235
-    new_via->host.s = translate_pointer( new_buf , org_buf , org_via->host.s );
236
-    /* port_str (str type) */
237
-    new_via->port_str.s = translate_pointer( new_buf , org_buf , org_via->port_str.s );
238
-    /* params (str type) */
239
-    new_via->params.s = translate_pointer( new_buf , org_buf , org_via->params.s );
240
-    /* comment (str type) */
241
-    new_via->comment.s = translate_pointer( new_buf , org_buf , org_via->comment.s );
242
-
243
-    if ( org_via->next ) {
244
-        new_via->next = via_body_cloner( new_buf , org_buf , org_via->next );
245
-	if (!new_via->next)
246
-		goto error;
247
-    }
248
-
249
-    new_via->param_lst = NULL;
250
-    if ( org_via->param_lst )
251
-    {
252
-       struct via_param *vp, *new_vp, *last_new_vp, *delete_i, *dummy;
253
-       for( vp=org_via->param_lst, last_new_vp=0 ; vp ; vp=vp->next )
254
-       {
255
-          new_vp = (struct via_param*)sh_malloc(sizeof(struct via_param));
256
-	  if (!new_vp) {
257
-		for (delete_i=new_via->param_lst; delete_i;  ) {
258
-			dummy=delete_i->next;
259
-			sh_free( delete_i );
260
-			delete_i = dummy;
261
-		}
262
-		goto error;
263
-	  }
264
-          memcpy( new_vp , vp , sizeof(struct via_param));
265
-          new_vp->name.s = translate_pointer( new_buf , org_buf , vp->name.s );
266
-          new_vp->value.s = translate_pointer( new_buf , org_buf , vp->value.s );
267
-
268
-          if (new_vp->type==PARAM_BRANCH)
269
-             new_via->branch = new_vp;
270
-
271
-          if (last_new_vp)
272
-             last_new_vp->next = new_vp;
273
-          else
274
-             new_via->param_lst = new_vp;
275
-
276
-          last_new_vp = new_vp;
277
-	  last_new_vp->next = NULL;
278
-       }
279
-       new_via->last_param = new_vp;
280
-    }
281
-
282
-
283
-
284
-   return new_via;
285
-
286
-error:
287
-	sh_free(new_via);
288
-	return NULL;
289
-}
290
-
291
-
292
-
293
-
294
-struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_msg, struct hdr_field *org_hdr)
295
-{
296
-    struct hdr_field* new_hdr;
297
-
298
-    new_hdr = (struct hdr_field*)sh_malloc( sizeof(struct hdr_field) );
299
-    if (!new_hdr) return NULL;
300
-    memcpy( new_hdr , org_hdr , sizeof(struct hdr_field) );
301
-
302
-    /* name */
303
-    new_hdr->name.s =  translate_pointer( new_msg->buf , org_msg->buf , org_hdr->name.s );
304
-    /* body */
305
-    new_hdr->body.s =  translate_pointer( new_msg->buf , org_msg->buf , org_hdr->body.s );
306
-
307
-    return new_hdr;
308
-}
309
-
310
-
311
- /*
312
-char*   translate_pointer( char* new_buf , char *org_buf , char* p)
313
-{
314
-    if (!p)
315
-	return 0;
316
-    else
317
-	return new_buf + (p-org_buf);
318
-}
319
-*/
320
-
321
-
322
-
323
-/* Frees the memory occupied by a SIP message
324
-  */
325
-void sh_free_lump(struct lump* lmp)
326
-{
327
-	if (lmp && (lmp->op==LUMP_ADD)){
328
-		if (lmp->u.value) sh_free(lmp->u.value);
329
-		lmp->u.value=0;
330
-		lmp->len=0;
331
-	}
332
-}
333
-
334
-
335
-
336
-void sh_free_lump_list(struct lump* l)
337
-{
338
-	struct lump* t, *r, *foo,*crt;
339
-	t=l;
340
-	while(t){
341
-		crt=t;
342
-		t=t->next;
343
-	/*
344
-		 dangerous recursive clean
345
-		if (crt->before) free_lump_list(crt->before);
346
-		if (crt->after)  free_lump_list(crt->after);
347
-	*/
348
-		/* no more recursion, clean after and before and that's it */
349
-		r=crt->before;
350
-		while(r){
351
-			foo=r; r=r->before;
352
-			sh_free_lump(foo);
353
-			sh_free(foo);
354
-		}
355
-		r=crt->after;
356
-		while(r){
357
-			foo=r; r=r->after;
358
-			sh_free_lump(foo);
359
-			sh_free(foo);
360
-		}
361
-
362
-		/*clean current elem*/
363
-		sh_free_lump(crt);
364
-		sh_free(crt);
365
-	}
366
-}
367
-
368
-
369
-
370
-void sh_free_uri(struct sip_uri* u)
371
-{
372
-   if (u)
373
-   {
374
-     if (u->user.s)
375
-         sh_free(u->user.s);
376
-     if (u->passwd.s)
377
-         sh_free(u->passwd.s);
378
-     if (u->host.s)
379
-         sh_free(u->host.s);
380
-     if (u->port.s)
381
-         sh_free(u->port.s);
382
-     if (u->params.s)
383
-         sh_free(u->params.s);
384
-     if (u->headers.s)
385
-         sh_free(u->headers.s);
386
-   }
387
-}
388
-
389
-
390
-
391
-void sh_free_via_param_list(struct via_param* vp)
392
-{
393
-   struct via_param* foo;
394
-   while(vp)
395
-    {
396
-       foo=vp;
397
-       vp=vp->next;
398
-       sh_free(foo);
399
-    }
400
-}
401
-
402
-
403
-
404
-void sh_free_via_list(struct via_body* vb)
405
-{
406
-   struct via_body* foo;
407
-   while(vb)
408
-    {
409
-      foo=vb;
410
-      vb=vb->next;
411
-     if (foo->param_lst)
412
-        sh_free_via_param_list(foo->param_lst);
413
-      sh_free(foo);
414
-    }
415
-}
416
-
417
-
418
-/* frees a hdr_field structure,
419
- * WARNING: it frees only parsed (and not name.s, body.s)*/
420
-void sh_clean_hdr_field(struct hdr_field* hf)
421
-{
422
-   if (hf->parsed)
423
-   {
424
-      switch(hf->type)
425
-      {
426
-         case HDR_VIA:
427
-               sh_free_via_list(hf->parsed);
428
-             break;
429
-         case HDR_CSEQ:
430
-                sh_free(hf->parsed);
431
-             break;
432
-         default:
433
-      }
434
-   }
435
-}
436
-
437
-
438
-
439
-/* frees a hdr_field list,
440
- * WARNING: frees only ->parsed and ->next*/
441
-void sh_free_hdr_field_lst(struct hdr_field* hf)
442
-{
443
-   struct hdr_field* foo;
444
-
445
-   while(hf)
446
-    {
447
-       foo=hf;
448
-       hf=hf->next;
449
-       sh_clean_hdr_field(foo);
450
-       sh_free(foo);
451
-    }
452
-}
453
-
454
-
455
-
456
-void sip_msg_free_1(struct sip_msg* msg)
457
-{
458
-   if (!msg) return;
459
-
460
-   DBG("DEBUG: sip_msg_free : start\n");
461
-
462
-   if (msg->new_uri.s)
463
-   {
464
-      sh_free(msg->new_uri.s);
465
-      msg->new_uri.len=0;
466
-   }
467
-   if (msg->headers)
468
-      sh_free_hdr_field_lst(msg->headers);
469
-   if (msg->add_rm)
470
-      sh_free_lump_list(msg->add_rm);
471
-   if (msg->repl_add_rm)
472
-      sh_free_lump_list(msg->repl_add_rm);
473
-   if (msg->orig) sh_free( msg->orig );
474
-   if (msg->buf) sh_free( msg->buf );
475
-
476
-   sh_free(msg);
477
-   DBG("DEBUG: sip_msg_free : done\n");
478
-}
479
-
480
-
481
-/******************************* New fuctions ************************************/
482
-
483 15
 #define  lump_len( _lump)  (ROUND4(sizeof(struct lump)) + \
484 16
                ROUND4( ((_lump)->op==LUMP_ADD)?(_lump)->len:0 ))
485 17
 
... ...
@@ -493,12 +25,15 @@ void sip_msg_free_1(struct sip_msg* msg)
493 25
           (_ptr)+=ROUND4((_old)->len);}\
494 26
       }
495 27
 
496
-struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
28
+struct via_body* via_body_cloner_2( char* new_buf , char *org_buf , struct via_body *org_via, char **p);
29
+
30
+struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
497 31
 {
498 32
    unsigned int         len;
499 33
    struct hdr_field    *hdr,*new_hdr,*last_hdr;
500 34
    struct via_body    *via;
501 35
    struct via_param *prm;
36
+   struct to_param   *to_prm,*new_to_prm;
502 37
    struct sip_msg     *new_msg;
503 38
    struct lump          *lump_chain, *lump_tmp, **lump_anchor, **lump_anchor2;
504 39
    char                       *p;
... ...
@@ -521,6 +56,13 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
521 56
          case HDR_CSEQ:
522 57
                    len+=ROUND4(sizeof(struct cseq_body));
523 58
                    break;
59
+         case HDR_TO:
60
+                   len+=ROUND4(sizeof(struct to_body));
61
+                   /*to param*/
62
+                   to_prm = ((struct to_body*)(hdr->parsed))->param_lst;
63
+                   for(;to_prm;to_prm=to_prm->next)
64
+                      len+=ROUND4(sizeof(struct to_param ));
65
+                   break;
524 66
          case HDR_VIA:
525 67
                    for (via=(struct via_body*)hdr->parsed;via;via=via->next)
526 68
                    {
... ...
@@ -643,12 +185,47 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
643 185
                    ((struct cseq_body*)new_hdr->parsed)->method.s =  translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)hdr->parsed)->method.s );
644 186
                    new_msg->cseq = new_hdr;
645 187
                    break;
646
-         case HDR_CALLID:
647
-                   new_msg->callid = new_hdr;
648
-                   break;
649 188
          case HDR_TO:
189
+                   new_hdr->parsed = p;
190
+                   p +=ROUND4(sizeof(struct to_body));
191
+                   memcpy( new_hdr->parsed , hdr->parsed ,
192
+                    sizeof(struct to_body) );
193
+                   ((struct to_body*)new_hdr->parsed)->body.s =
194
+                        translate_pointer( new_msg->buf , org_msg->buf ,
195
+                        ((struct to_body*)hdr->parsed)->body.s );
196
+                   if ( ((struct to_body*)hdr->parsed)->tag_value.s )
197
+                         ((struct to_body*)new_hdr->parsed)->tag_value.s
198
+                         = translate_pointer( new_msg->buf , org_msg->buf ,
199
+                            ((struct to_body*)hdr->parsed)->tag_value.s );
200
+                    /*to params*/
201
+                   to_prm = ((struct to_body*)(hdr->parsed))->param_lst;
202
+                   for(;to_prm;to_prm=to_prm->next)
203
+                   {
204
+                      /*alloc*/
205
+                      new_to_prm = (struct to_param*)p;
206
+                      p +=ROUND4(sizeof(struct to_param ));
207
+                      /*coping*/
208
+                      memcpy( new_to_prm, to_prm, sizeof(struct to_param ));
209
+                      ((struct to_body*)new_hdr->parsed)->param_lst = 0;
210
+                      new_to_prm->name.s = translate_pointer( new_msg->buf,
211
+                         org_msg->buf , to_prm->name.s );
212
+                      new_to_prm->value.s = translate_pointer( new_msg->buf,
213
+                         org_msg->buf , to_prm->value.s );
214
+                      /*linking*/
215
+                      if ( !((struct to_body*)new_hdr->parsed)->param_lst )
216
+                         ((struct to_body*)new_hdr->parsed)->param_lst
217
+                            = new_to_prm;
218
+                      else
219
+                         ((struct to_body*)new_hdr->parsed)->last_param->next
220
+                            = new_to_prm;
221
+                      ((struct to_body*)new_hdr->parsed)->last_param
222
+                         = new_to_prm;
223
+                   }
650 224
                    new_msg->to = new_hdr;
651 225
                    break;
226
+         case HDR_CALLID:
227
+                   new_msg->callid = new_hdr;
228
+                   break;
652 229
          case HDR_FROM:
653 230
                    new_msg->from = new_hdr;
654 231
                    break;
... ...
@@ -10,20 +10,11 @@
10 10
 
11 11
 #include "sh_malloc.h"
12 12
 
13
-#define sip_msg_cloner(p_msg) \
14
-    sip_msg_cloner_2(p_msg)
15
-
16 13
 #define  sip_msg_free(_p_msg) shm_free( (_p_msg ))
17 14
 #define  sip_msg_free_unsafe(_p_msg) shm_free_unsafe( (_p_msg) )
18 15
 
19 16
 
20
-struct sip_msg*  sip_msg_cloner_1( struct sip_msg *org_msg );
21
-struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg );
22
-void                     sip_msg_free_1( struct sip_msg *org_msg );
23
-
24
-
25
-
26
-//char*   translate_pointer( char* new_buf , char *org_buf , char* p);
17
+struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg );
27 18
 
28 19
 
29 20
 #endif
... ...
@@ -450,6 +450,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
450 450
 		/* release previously hold message */
451 451
 		backup = T->inbound_response[branch];
452 452
 		T->inbound_response[branch] = clone;
453
+		T->tag=&(get_to(clone)->tag_value);
453 454
 	} else {
454 455
 		backup = NULL;
455 456
 		sip_msg_free( clone );
... ...
@@ -15,7 +15,8 @@
15 15
 
16 16
 
17 17
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
18
-#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, \
18
+#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\
19
+	translate_pointer(p_msg->orig,p_msg->buf,p_msg->_hf->body.s), \
19 20
 	p_msg->_hf->body.len)==0)
20 21
 #define EQ_REQ_URI_LEN\
21 22
 	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
... ...
@@ -115,15 +116,16 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
115 116
          if ( EQ_LEN(callid) && EQ_LEN(cseq) )
116 117
             if ( EQ_REQ_URI_LEN )
117 118
                 if ( EQ_VIA_LEN(via1) )
118
-                   if ( EQ_LEN(from) && EQ_LEN(to) )
119
-                     /* so far the lengths are the same -> let's check the contents */
119
+                   if ( EQ_LEN(from) && EQ_LEN(to)  )
120
+                     /* so far the lengths are the same
121
+                     -> let's check the contents */
120 122
                      if ( EQ_STR(callid) && EQ_STR(cseq) )
121
-                      if ( EQ_REQ_URI_STR )
122
-                          if ( EQ_VIA_STR(via1) )
123
-                             if ( EQ_STR(from) && EQ_STR(to) )
124
-                              { /* WE FOUND THE GOLDEN EGG !!!! */
125
-                                 goto found;
126
-                              }
123
+                        if ( EQ_REQ_URI_STR )
124
+                           if ( EQ_VIA_STR(via1) )
125
+                              if ( EQ_STR(from) && EQ_STR(to) )
126
+                               { /* WE FOUND THE GOLDEN EGG !!!! */
127
+                                  goto found;
128
+                               }
127 129
       }
128 130
       else
129 131
       { /* it's a ACK request*/
... ...
@@ -134,16 +136,16 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
134 136
                   if ( EQ_REQ_URI_LEN )
135 137
                      if (/*VIA1 len*/ EQ_VIA_LEN(via1) )
136 138
                        if ( /*from length*/ EQ_LEN(from) )
137
-                         //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
138
-                            //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
139
+                         if (get_to(t_msg)->body.len==get_to(p_msg)->body.len)
140
+                            if (p_cell->tag->len==get_to(p_msg)->tag_value.len )
139 141
                             /* so far the lengths are the same -> let's check the contents */
140 142
                                 if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
141 143
                                    if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
142 144
                                       if (/*URI len*/ EQ_REQ_URI_STR )
143 145
                                          if (/*VIA1*/ EQ_VIA_STR(via1) )
144 146
                                             if ( /*from*/ EQ_STR(from) )
145
-                                            //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
146
-                                              //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
147
+                                               if (!memcmp(get_to(t_msg)->body.s,get_to(p_msg)->body.s,get_to(t_msg)->body.len))
148
+                                                 if (!memcmp(p_cell->tag->s,get_to(p_msg)->tag_value.s , p_cell->tag->len))
147 149
                                               { /* WE FOUND THE GOLDEN EGG !!!! */
148 150
                                                  goto found;
149 151
                                               }
... ...
@@ -167,11 +167,11 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
167 167
 	*tmp=0;
168 168
 	fl->u.request.version.s=third;
169 169
 	fl->u.request.version.len=tmp-third;
170
-	
170
+
171 171
 	return nl;
172 172
 
173 173
 error:
174
-	LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n", 
174
+	LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n",
175 175
 		(fl->type==SIP_REPLY)?"reply(status)":"request");
176 176
 error1:
177 177
 	fl->type=SIP_INVALID;
... ...
@@ -192,6 +192,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
192 192
 	char *match;
193 193
 	struct via_body *vb;
194 194
 	struct cseq_body* cseq_b;
195
+	struct to_body* to_b;
195 196
 
196 197
 	if ((*buf)=='\n' || (*buf)=='\r'){
197 198
 		/* double crlf or lflf or crcr */
... ...
@@ -246,6 +247,24 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
246 247
 					hdr->name.s, cseq_b->number.s, cseq_b->method.s);
247 248
 			break;
248 249
 		case HDR_TO:
250
+			to_b=pkg_malloc(sizeof(struct to_body));
251
+			if (to_b==0){
252
+				LOG(L_ERR, "get_hdr_field: out of memory\n");
253
+				goto error;
254
+			}
255
+			memset(to_b, 0, sizeof(struct to_body));
256
+			hdr->body.s=tmp;
257
+			tmp=parse_to(tmp, end,to_b);
258
+			if (to_b->error==PARSE_ERROR){
259
+				LOG(L_ERR, "ERROR: get_hdr_field: bad to header\n");
260
+				pkg_free(to_b);
261
+				goto error;
262
+			}
263
+			hdr->parsed=to_b;
264
+			hdr->body.len=tmp-hdr->body.s;
265
+			DBG("get_hdr_field: to <%s>: <%s> %c [%d]\n",
266
+				hdr->name.s, to_b->body.s,*tmp,hdr->body.len);
267
+			break;
249 268
 		case HDR_FROM:
250 269
 		case HDR_CALLID:
251 270
 		case HDR_CONTACT:
... ...
@@ -256,7 +275,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
256 275
 			/* just skip over it */
257 276
 			hdr->body.s=tmp;
258 277
 			/* find end of header */
259
-			
278
+
260 279
 			/* find lf */
261 280
 			do{
262 281
 				match=q_memchr(tmp, '\n', end-tmp);
... ...
@@ -295,7 +314,7 @@ char* parse_hostport(char* buf, str* host, short int* port)
295 314
 {
296 315
 	char *tmp;
297 316
 	int err;
298
-	
317
+
299 318
 	host->s=buf;
300 319
 	for(tmp=buf;(*tmp)&&(*tmp!=':');tmp++);
301 320
 	host->len=tmp-buf;
... ...
@@ -334,7 +353,7 @@ char * parse_cseq(char *buf, char* end, struct cseq_body* cb)
334 353
 	*t=0; /*null terminate it*/
335 354
 	cb->number.len=t-cb->number.s;
336 355
 	DBG("parse_cseq: found number %s\n", cb->number.s);
337
-	
356
+
338 357
 	if (m_end>=end) goto error;
339 358
 	if (m_end==m){
340 359
 		/* null method*/
... ...
@@ -776,8 +795,19 @@ void free_via_list(struct via_body* vb)
776 795
 	}
777 796
 }
778 797
 
798
+void free_to(struct to_body* tb)
799
+{
800
+	struct to_param *tp=tb->param_lst;
801
+	struct to_param *foo;
802
+	while (tp){
803
+		foo = tp->next;
804
+		pkg_free(tp);
805
+		tp=foo;
806
+	}
807
+	pkg_free(tb);
808
+}
779 809
 
780
-/* frees a hdr_field structure, 
810
+/* frees a hdr_field structure,
781 811
  * WARNING: it frees only parsed (and not name.s, body.s)*/
782 812
 void clean_hdr_field(struct hdr_field* hf)
783 813
 {
... ...
@@ -786,6 +816,9 @@ void clean_hdr_field(struct hdr_field* hf)
786 816
 			case HDR_VIA:
787 817
 				free_via_list(hf->parsed);
788 818
 				break;
819
+			case HDR_TO:
820
+				free_to(hf->parsed);
821
+				break;
789 822
 			case HDR_CSEQ:
790 823
 				pkg_free(hf->parsed);
791 824
 				break;
... ...
@@ -44,8 +44,13 @@ enum{
44 44
 		PARAM_ERROR
45 45
 };
46 46
 
47
+enum{
48
+		TAG_PARAM=400, GENERAL_PARAM
49
+};
50
+
47 51
 /* casting macro for accessing CSEQ body */
48
-#define get_cseq( p_msg)    ((struct cseq_body*)(p_msg)->cseq->parsed)
52
+#define get_cseq( p_msg)  ((struct cseq_body*)(p_msg)->cseq->parsed)
53
+#define get_to( p_msg)      ((struct to_body*)(p_msg)->to->parsed)
49 54
 
50 55
 
51 56
 
... ...
@@ -127,13 +132,27 @@ struct via_body{  /* format: name/version/transport host:port;params comment */
127 132
 	struct via_param* last_param; /*last via parameter, internal use*/
128 133
 	/* shortcuts to "important" params*/
129 134
 	struct via_param* branch;
130
-	
135
+
131 136
 	struct via_body* next; /* pointer to next via body string if
132
-							  compact via or null */
137
+         compact via or null */
133 138
 };
134 139
 
135 140
 
136 141
 
142
+struct to_param{
143
+	int type;
144
+	str name;
145
+	str value;
146
+	struct to_param* next;
147
+};
148
+
149
+struct to_body{
150
+	int error;
151
+	str body;
152
+	str tag_value;
153
+	struct to_param *param_lst;
154
+	struct to_param *last_param;
155
+};
137 156
 
138 157
 
139 158
 struct cseq_body{
... ...
@@ -165,7 +184,6 @@ struct sip_msg{
165 184
 	struct hdr_field* route;
166 185
 	struct hdr_field* record_route;
167 186
 	char* eoh; /* pointer to the end of header (if found) or null */
168
-
169 187
 	char* unparsed; /* here we stopped parsing*/
170 188
 
171 189
 	unsigned int src_ip;
... ...
@@ -216,6 +234,7 @@ void free_uri(struct sip_uri* u);
216 234
 
217 235
 char* parse_hname(char* buf, char* end, struct hdr_field* hdr);
218 236
 char* parse_via(char* buffer, char* end, struct via_body *vb);
237
+char* parse_to(char* buffer, char* end, struct to_body *to_b);
219 238
 char* parse_cseq(char* buffer, char* end, struct cseq_body *cb);
220 239
 
221 240
 void free_via_param_list(struct via_param *vp);
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * $Id$ 
3 3
  *
4 4
  * via parsing automaton
... ...
@@ -64,21 +64,21 @@ enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
64 64
 
65 65
 
66 66
 
67
-/* entry state must be F_PARAM, or saved_state=F_PARAM and 
67
+/* entry state must be F_PARAM, or saved_state=F_PARAM and
68 68
  * state=F_{LF,CR,CRLF}!
69
- * output state = L_PARAM or F_PARAM or END_OF_HEADER 
69
+ * output state = L_PARAM or F_PARAM or END_OF_HEADER
70 70
  * (and saved_state= last state); everything else => error */
71
-__inline char* parse_via_param(	char* p, char* end, int* pstate, 
71
+__inline char* parse_via_param(	char* p, char* end, int* pstate,
72 72
 								int* psaved_state, struct via_param* param)
73 73
 {
74 74
 	char* tmp;
75 75
 	register int state;
76 76
 	int saved_state;
77
-	
77
+
78 78
 	state=*pstate;
79 79
 	saved_state=*psaved_state;
80 80
 	param->type=PARAM_ERROR;
81
-	
81
+
82 82
 	for (tmp=p;tmp<end;tmp++){
83 83
 		switch(*tmp){
84 84
 			case ' ':
... ...
@@ -253,7 +253,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
253 253
 						goto endofparam;
254 254
 				}
255 255
 				break;
256
-				
256
+
257 257
 				/* param names */
258 258
 			case 'h':
259 259
 			case 'H':
... ...
@@ -618,7 +618,7 @@ find_value:
618 618
 					case P_STRING:
619 619
 						saved_state=state;
620 620
 						state=F_LF;
621
-						break; 
621
+						break;
622 622
 					case P_VALUE:
623 623
 						*tmp=0;
624 624
 						saved_state=L_PARAM;
... ...
@@ -645,7 +645,7 @@ find_value:
645 645
 					case P_STRING:
646 646
 						saved_state=state;
647 647
 						state=F_CR;
648
-						break; 
648
+						break;
649 649
 					case P_VALUE:
650 650
 						*tmp=0;
651 651
 						param->value.len=tmp-param->value.s;
... ...
@@ -775,17 +775,17 @@ endofvalue:
775 775
 	param->size=tmp-p;
776 776
 	*pstate=state;
777 777
 	*psaved_state=saved_state;
778
-	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type, 
778
+	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type,
779 779
 			param->name.s, param->value.s, state);
780 780
 	return tmp;
781
-	
781
+
782 782
 end_via:
783 783
 	/* if we are here we found an "unexpected" end of via
784 784
 	 *  (cr/lf). This is valid only if the param type is GEN_PARAM*/
785 785
 	if (param->type==GEN_PARAM) goto endofparam;
786 786
 	*pstate=state;
787 787
 	*psaved_state=saved_state;
788
-	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n", 
788
+	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n",
789 789
 		param->type, param->name.s, state, saved_state);
790 790
 
791 791
 error:
... ...
@@ -1587,7 +1587,7 @@ main_via:
1587 1587
 						memset(param,0, sizeof(struct via_param));
1588 1588
 						tmp=parse_via_param(tmp, end, &state, &saved_state,
1589 1589
 											param);
1590
-						
1590
+
1591 1591
 						switch(state){
1592 1592
 							case L_PARAM:
1593 1593
 							case F_PARAM:
... ...
@@ -1655,9 +1655,9 @@ main_via:
1655 1655
 							*tmp, state);
1656 1656
 						goto error;
1657 1657
 				}
1658
-				
1659
-					
1660
-		}			
1658
+
1659
+
1660
+		}
1661 1661
 	}
1662 1662
 
1663 1663
 	DBG("end of packet reached, state=%d\n", state);
... ...
@@ -1684,7 +1684,7 @@ endofpacket:
1684 1684
 					" state %d\n", state);
1685 1685
 			goto error;
1686 1686
 	}
1687
-	
1687
+
1688 1688
 
1689 1689
 	/*
1690 1690
 	if (proto) printf("<SIP/2.0/%s>\n", proto);
... ...
@@ -1695,7 +1695,7 @@ endofpacket:
1695 1695
 	if(next_via) printf("next_via= <%s>\n", next_via);
1696 1696
 	*/
1697 1697
 	/*DBG("parse_via: rest=<%s>\n", tmp);*/
1698
-	
1698
+
1699 1699
 	vb->error=VIA_PARSE_OK;
1700 1700
 	vb->bsize=tmp-buffer;
1701 1701
 	if (vb->port_str.s){
... ...
@@ -45,6 +45,24 @@ route{
45 45
                    mf_add_maxfwd_header( "10" );
46 46
              };
47 47
 
48
+             #if (method=="INVITE")
49
+             #{
50
+              #  log("SER : runing CPL!! :)\n");
51
+              #  if ( !cpl_run_script() )
52
+               # {
53
+               #    log("SER : Error during running CPL script!\n");
54
+               # }else{
55
+                #   if ( cpl_is_response_reject() )
56
+                  # {
57
+                    #   t_add_transaction();
58
+                      # t_send_reply("486","I am not available!");
59
+                       #drop();
60
+                 #  }else if ( cpl_is_response_redirect() ) {
61
+                   #      log("SER : redirect\n");
62
+                  # };
63
+               # };
64
+             #};
65
+
48 66
              #if ( !rewriteFromRoute() )
49 67
              #{
50 68
                 log( " SER : no route found!\n");