ca0bf789c5e62169dd32529a38b421f8780f7645
[sip-router] / src / core / parser / msg_parser.c
1 /*
2  * sip msg. header proxy parser
3  *
4  * Copyright (C) 2001-2003 FhG Fokus
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 /** Parser :: SIP Message header proxy parser.
25  * @file
26  * @ingroup parser
27  */
28
29 /*! \defgroup parser SIP-router SIP message parser
30  *
31  * The SIP message parser
32  *
33  */
34
35
36 #include <string.h>
37 #include <stdlib.h>
38 #include <sys/time.h>
39
40 #include "../comp_defs.h"
41 #include "msg_parser.h"
42 #include "parser_f.h"
43 #include "../ut.h"
44 #include "../error.h"
45 #include "../dprint.h"
46 #include "../data_lump_rpl.h"
47 #include "../mem/mem.h"
48 #include "../error.h"
49 #include "../core_stats.h"
50 #include "../globals.h"
51 #include "parse_hname2.h"
52 #include "parse_uri.h"
53 #include "parse_content.h"
54 #include "parse_to.h"
55 #include "../compiler_opt.h"
56
57 #ifdef DEBUG_DMALLOC
58 #include <mem/dmalloc.h>
59 #endif
60
61
62 #define parse_hname(_b,_e,_h) parse_hname2((_b),(_e),(_h))
63
64 /* number of via's encountered */
65 int via_cnt;
66 /* global request flags */
67 unsigned int global_req_flags = 0;
68
69 /* returns pointer to next header line, and fill hdr_f ;
70  * if at end of header returns pointer to the last crlf  (always buf)*/
71 char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hdr)
72 {
73
74         char *tmp = 0;
75         char *match;
76         struct via_body *vb;
77         struct cseq_body* cseq_b;
78         struct to_body* to_b;
79         int integer, err;
80         unsigned uval;
81
82         if(!buf) {
83                 DBG("null buffer pointer\n");
84                 goto error;
85         }
86
87         if ((*buf)=='\n' || (*buf)=='\r'){
88                 /* double crlf or lflf or crcr */
89                 DBG("found end of header\n");
90                 hdr->type=HDR_EOH_T;
91                 return buf;
92         }
93
94         tmp=parse_hname(buf, end, hdr);
95         if (hdr->type==HDR_ERROR_T){
96                 ERR("bad header\n");
97                 goto error;
98         }
99
100         /* eliminate leading whitespace */
101         tmp=eat_lws_end(tmp, end);
102         if (tmp>=end) {
103                 ERR("HF empty\n");
104                 goto error;
105         }
106
107         /* if header-field well-known, parse it, find its end otherwise ;
108          * after leaving the hdr->type switch, tmp should be set to the
109          * next header field
110          */
111         switch(hdr->type){
112                 case HDR_VIA_T:
113                         /* keep number of vias parsed -- we want to report it in
114                            replies for diagnostic purposes */
115                         via_cnt++;
116                         vb=pkg_malloc(sizeof(struct via_body));
117                         if (vb==0){
118                                 PKG_MEM_ERROR;
119                                 goto error;
120                         }
121                         memset(vb,0,sizeof(struct via_body));
122                         hdr->body.s=tmp;
123                         tmp=parse_via(tmp, end, vb);
124                         if (vb->error==PARSE_ERROR){
125                                 ERR("bad via\n");
126                                 free_via_list(vb);
127                                 goto error;
128                         }
129                         hdr->parsed=vb;
130                         vb->hdr.s=hdr->name.s;
131                         vb->hdr.len=hdr->name.len;
132                         hdr->body.len=tmp-hdr->body.s;
133                         break;
134                 case HDR_CSEQ_T:
135                         cseq_b=pkg_malloc(sizeof(struct cseq_body));
136                         if (cseq_b==0){
137                                 PKG_MEM_ERROR;
138                                 goto error;
139                         }
140                         memset(cseq_b, 0, sizeof(struct cseq_body));
141                         hdr->body.s=tmp;
142                         tmp=parse_cseq(tmp, end, cseq_b);
143                         if (cseq_b->error==PARSE_ERROR){
144                                 ERR("bad cseq\n");
145                                 free_cseq(cseq_b);
146                                 goto error;
147                         }
148                         hdr->parsed=cseq_b;
149                         hdr->body.len=tmp-hdr->body.s;
150                         DBG("cseq <%.*s>: <%.*s> <%.*s>\n", hdr->name.len, ZSW(hdr->name.s),
151                                         cseq_b->number.len, ZSW(cseq_b->number.s), cseq_b->method.len,
152                                         cseq_b->method.s);
153                         break;
154                 case HDR_TO_T:
155                         to_b=pkg_malloc(sizeof(struct to_body));
156                         if (to_b==0){
157                                 PKG_MEM_ERROR;
158                                 goto error;
159                         }
160                         memset(to_b, 0, sizeof(struct to_body));
161                         hdr->body.s=tmp;
162                         tmp=parse_to(tmp, end,to_b);
163                         if (to_b->error==PARSE_ERROR){
164                                 ERR("bad to header\n");
165                                 free_to(to_b);
166                                 goto error;
167                         }
168                         hdr->parsed=to_b;
169                         hdr->body.len=tmp-hdr->body.s;
170                         DBG("<%.*s> [%d]; uri=[%.*s]\n", hdr->name.len, ZSW(hdr->name.s),
171                                         hdr->body.len, to_b->uri.len, ZSW(to_b->uri.s));
172                         DBG("to body [%.*s], to tag [%.*s]\n", to_b->body.len,
173                                         ZSW(to_b->body.s), to_b->tag_value.len,
174                                         ZSW(to_b->tag_value.s));
175                         break;
176                 case HDR_CONTENTLENGTH_T:
177                         hdr->body.s=tmp;
178                         tmp=parse_content_length(tmp,end, &integer);
179                         if (tmp==0){
180                                 ERR("bad content_length header\n");
181                                 goto error;
182                         }
183                         hdr->parsed=(void*)(long)integer;
184                         hdr->body.len=tmp-hdr->body.s;
185                         DBG("content_length=%d\n", (int)(long)hdr->parsed);
186                         break;
187                 case HDR_RETRY_AFTER_T:
188                         hdr->body.s=tmp;
189                         tmp=parse_retry_after(tmp,end, &uval, &err);
190                         if (err){
191                                 ERR("bad retry_after header\n");
192                                 goto error;
193                         }
194                         hdr->parsed=(void*)(unsigned long)uval;
195                         hdr->body.len=tmp-hdr->body.s;
196                         DBG("retry_after=%d\n", (unsigned)(long)hdr->parsed);
197                         break;
198                 case HDR_IDENTITY_T:
199                 case HDR_DATE_T:
200                 case HDR_IDENTITY_INFO_T:
201                 case HDR_SUPPORTED_T:
202                 case HDR_REQUIRE_T:
203                 case HDR_CONTENTTYPE_T:
204                 case HDR_FROM_T:
205                 case HDR_CALLID_T:
206                 case HDR_CONTACT_T:
207                 case HDR_ROUTE_T:
208                 case HDR_RECORDROUTE_T:
209                 case HDR_MAXFORWARDS_T:
210                 case HDR_AUTHORIZATION_T:
211                 case HDR_EXPIRES_T:
212                 case HDR_MIN_EXPIRES_T:
213                 case HDR_PROXYAUTH_T:
214                 case HDR_PROXYREQUIRE_T:
215                 case HDR_UNSUPPORTED_T:
216                 case HDR_ALLOW_T:
217                 case HDR_EVENT_T:
218                 case HDR_ACCEPT_T:
219                 case HDR_ACCEPTLANGUAGE_T:
220                 case HDR_ORGANIZATION_T:
221                 case HDR_PRIORITY_T:
222                 case HDR_SUBJECT_T:
223                 case HDR_USERAGENT_T:
224                 case HDR_SERVER_T:
225                 case HDR_CONTENTDISPOSITION_T:
226                 case HDR_DIVERSION_T:
227                 case HDR_RPID_T:
228                 case HDR_SIPIFMATCH_T:
229                 case HDR_REFER_TO_T:
230                 case HDR_SESSIONEXPIRES_T:
231                 case HDR_MIN_SE_T:
232                 case HDR_SUBSCRIPTION_STATE_T:
233                 case HDR_ACCEPTCONTACT_T:
234                 case HDR_ALLOWEVENTS_T:
235                 case HDR_CONTENTENCODING_T:
236                 case HDR_REFERREDBY_T:
237                 case HDR_REJECTCONTACT_T:
238                 case HDR_REQUESTDISPOSITION_T:
239                 case HDR_WWW_AUTHENTICATE_T:
240                 case HDR_PROXY_AUTHENTICATE_T:
241                 case HDR_PATH_T:
242                 case HDR_PRIVACY_T:
243                 case HDR_PAI_T:
244                 case HDR_PPI_T:
245                 case HDR_REASON_T:
246                 case HDR_CALLINFO_T:
247                 case HDR_OTHER_T:
248                         /* just skip over it */
249                         hdr->body.s=tmp;
250                         /* find end of header */
251                         /* find lf */
252                         do{
253                                 match=q_memchr(tmp, '\n', end-tmp);
254                                 if (match){
255                                         match++;
256                                 } else {
257                                         ERR("no eol - bad body for <%.*s> (hdr type: %d) [%.*s]\n",
258                                                          hdr->name.len, hdr->name.s,
259                                                         hdr->type, ((end-tmp)>128)?128:(int)(end-tmp), tmp);
260                                         /* abort(); */
261                                         tmp=end;
262                                         goto error;
263                                 }
264                                 tmp=match;
265                         }while( match<end &&( (*match==' ')||(*match=='\t') ) );
266                         tmp=match;
267                         hdr->body.len=match-hdr->body.s;
268                         break;
269                 default:
270                         BUG("unknown header type %d [%.*s]\n", hdr->type,
271                                          ((end-buf)>128)?128:(int)(end-buf), buf);
272                         goto error;
273         }
274         /* jku: if \r covered by current length, shrink it */
275         trim_r( hdr->body );
276         hdr->len=tmp-hdr->name.s;
277         return tmp;
278 error:
279         DBG("error exit\n");
280         STATS_BAD_MSG_HDR();
281         hdr->type=HDR_ERROR_T;
282         hdr->len=tmp-hdr->name.s;
283         return tmp;
284 }
285
286
287
288 /* parse the headers and adds them to msg->headers and msg->to, from etc.
289  * It stops when all the headers requested in flags were parsed, on error
290  * (bad header) or end of headers
291  * WARNING: parse_headers was changed to use hdr_flags_t (the flags are now
292  *          different from the header types). Don't call it with a header type
293  *          (HDR_xxx_T), only with header flags (HDR_xxx_F)!*/
294 /* note: it continues where it previously stopped and goes ahead until
295    end is encountered or desired HFs are found; if you call it twice
296    for the same HF which is present only once, it will fail the second
297    time; if you call it twice and the HF is found on second time too,
298    it's not replaced in the well-known HF pointer but just added to
299    header list; if you want to use a dumb convenience function which will
300    give you the first occurrence of a header you are interested in,
301    look at check_transaction_quadruple
302 */
303 int parse_headers(struct sip_msg* const msg, const hdr_flags_t flags, const int next)
304 {
305         struct hdr_field* hf;
306         char* tmp;
307         char* rest;
308         char* end;
309         hdr_flags_t orig_flag;
310
311         end=msg->buf+msg->len;
312         tmp=msg->unparsed;
313
314         if (unlikely(next)) {
315                 orig_flag = msg->parsed_flag;
316                 msg->parsed_flag &= ~flags;
317         }else
318                 orig_flag=0;
319
320 #ifdef EXTRA_DEBUG
321         DBG("flags=%llx\n", (unsigned long long)flags);
322 #endif
323         while( tmp<end && (flags & msg->parsed_flag) != flags){
324                 prefetch_loc_r(tmp+64, 1);
325                 hf=pkg_malloc(sizeof(struct hdr_field));
326                 if (unlikely(hf==0)){
327                         PKG_MEM_ERROR;
328                         ser_error=E_OUT_OF_MEM;
329                         goto error;
330                 }
331                 memset(hf,0, sizeof(struct hdr_field));
332                 hf->type=HDR_ERROR_T;
333                 rest=get_hdr_field(tmp, end, hf);
334                 switch (hf->type){
335                         case HDR_ERROR_T:
336                                 ERR("bad header field [%.*s]\n",
337                                                 (end-tmp>100)?100:(int)(end-tmp), tmp);
338                                 goto  error;
339                         case HDR_EOH_T:
340                                 msg->eoh=tmp; /* or rest?*/
341                                 msg->parsed_flag|=HDR_EOH_F;
342                                 pkg_free(hf);
343                                 goto skip;
344                         case HDR_ACCEPTCONTACT_T:
345                         case HDR_ALLOWEVENTS_T:
346                         case HDR_CONTENTENCODING_T:
347                         case HDR_REFERREDBY_T:
348                         case HDR_REJECTCONTACT_T:
349                         case HDR_REQUESTDISPOSITION_T:
350                         case HDR_WWW_AUTHENTICATE_T:
351                         case HDR_PROXY_AUTHENTICATE_T:
352                         case HDR_RETRY_AFTER_T:
353                         case HDR_OTHER_T: /* mark the type as found/parsed*/
354                                 msg->parsed_flag|=HDR_T2F(hf->type);
355                                 break;
356                         case HDR_CALLID_T:
357                                 if (msg->callid==0) msg->callid=hf;
358                                 msg->parsed_flag|=HDR_CALLID_F;
359                                 break;
360                         case HDR_SIPIFMATCH_T:
361                                 if (msg->sipifmatch==0) msg->sipifmatch=hf;
362                                 msg->parsed_flag|=HDR_SIPIFMATCH_F;
363                                 break;
364                         case HDR_TO_T:
365                                 if (msg->to==0) msg->to=hf;
366                                 msg->parsed_flag|=HDR_TO_F;
367                                 break;
368                         case HDR_CSEQ_T:
369                                 if (msg->cseq==0) msg->cseq=hf;
370                                 msg->parsed_flag|=HDR_CSEQ_F;
371                                 break;
372                         case HDR_FROM_T:
373                                 if (msg->from==0) msg->from=hf;
374                                 msg->parsed_flag|=HDR_FROM_F;
375                                 break;
376                         case HDR_CONTACT_T:
377                                 if (msg->contact==0) msg->contact=hf;
378                                 msg->parsed_flag|=HDR_CONTACT_F;
379                                 break;
380                         case HDR_MAXFORWARDS_T:
381                                 if(msg->maxforwards==0) msg->maxforwards=hf;
382                                 msg->parsed_flag|=HDR_MAXFORWARDS_F;
383                                 break;
384                         case HDR_ROUTE_T:
385                                 if (msg->route==0) msg->route=hf;
386                                 msg->parsed_flag|=HDR_ROUTE_F;
387                                 break;
388                         case HDR_RECORDROUTE_T:
389                                 if (msg->record_route==0) msg->record_route = hf;
390                                 msg->parsed_flag|=HDR_RECORDROUTE_F;
391                                 break;
392                         case HDR_CONTENTTYPE_T:
393                                 if (msg->content_type==0) msg->content_type = hf;
394                                 msg->parsed_flag|=HDR_CONTENTTYPE_F;
395                                 break;
396                         case HDR_CONTENTLENGTH_T:
397                                 if (msg->content_length==0) msg->content_length = hf;
398                                 msg->parsed_flag|=HDR_CONTENTLENGTH_F;
399                                 break;
400                         case HDR_AUTHORIZATION_T:
401                                 if (msg->authorization==0) msg->authorization = hf;
402                                 msg->parsed_flag|=HDR_AUTHORIZATION_F;
403                                 break;
404                         case HDR_EXPIRES_T:
405                                 if (msg->expires==0) msg->expires = hf;
406                                 msg->parsed_flag|=HDR_EXPIRES_F;
407                                 break;
408                         case HDR_MIN_EXPIRES_T:
409                                 if (msg->min_expires==0) msg->min_expires = hf;
410                                 msg->parsed_flag|=HDR_MIN_EXPIRES_F;
411                                 break;
412                         case HDR_PROXYAUTH_T:
413                                 if (msg->proxy_auth==0) msg->proxy_auth = hf;
414                                 msg->parsed_flag|=HDR_PROXYAUTH_F;
415                                 break;
416                         case HDR_PROXYREQUIRE_T:
417                                 if (msg->proxy_require==0) msg->proxy_require = hf;
418                                 msg->parsed_flag|=HDR_PROXYREQUIRE_F;
419                                 break;
420                         case HDR_SUPPORTED_T:
421                                 if (msg->supported==0) msg->supported=hf;
422                                 msg->parsed_flag|=HDR_SUPPORTED_F;
423                                 break;
424                         case HDR_REQUIRE_T:
425                                 if (msg->require==0) msg->require=hf;
426                                 msg->parsed_flag|=HDR_REQUIRE_F;
427                                 break;
428                         case HDR_UNSUPPORTED_T:
429                                 if (msg->unsupported==0) msg->unsupported=hf;
430                                 msg->parsed_flag|=HDR_UNSUPPORTED_F;
431                                 break;
432                         case HDR_ALLOW_T:
433                                 if (msg->allow==0) msg->allow = hf;
434                                 msg->parsed_flag|=HDR_ALLOW_F;
435                                 break;
436                         case HDR_EVENT_T:
437                                 if (msg->event==0) msg->event = hf;
438                                 msg->parsed_flag|=HDR_EVENT_F;
439                                 break;
440                         case HDR_ACCEPT_T:
441                                 if (msg->accept==0) msg->accept = hf;
442                                 msg->parsed_flag|=HDR_ACCEPT_F;
443                                 break;
444                         case HDR_ACCEPTLANGUAGE_T:
445                                 if (msg->accept_language==0) msg->accept_language = hf;
446                                 msg->parsed_flag|=HDR_ACCEPTLANGUAGE_F;
447                                 break;
448                         case HDR_ORGANIZATION_T:
449                                 if (msg->organization==0) msg->organization = hf;
450                                 msg->parsed_flag|=HDR_ORGANIZATION_F;
451                                 break;
452                         case HDR_PRIORITY_T:
453                                 if (msg->priority==0) msg->priority = hf;
454                                 msg->parsed_flag|=HDR_PRIORITY_F;
455                                 break;
456                         case HDR_SUBJECT_T:
457                                 if (msg->subject==0) msg->subject = hf;
458                                 msg->parsed_flag|=HDR_SUBJECT_F;
459                                 break;
460                         case HDR_USERAGENT_T:
461                                 if (msg->user_agent==0) msg->user_agent = hf;
462                                 msg->parsed_flag|=HDR_USERAGENT_F;
463                                 break;
464                         case HDR_SERVER_T:
465                                 if (msg->server==0) msg->server = hf;
466                                 msg->parsed_flag|=HDR_SERVER_F;
467                                 break;
468                         case HDR_CONTENTDISPOSITION_T:
469                                 if (msg->content_disposition==0) msg->content_disposition = hf;
470                                 msg->parsed_flag|=HDR_CONTENTDISPOSITION_F;
471                                 break;
472                         case HDR_DIVERSION_T:
473                                 if (msg->diversion==0) msg->diversion = hf;
474                                 msg->parsed_flag|=HDR_DIVERSION_F;
475                                 break;
476                         case HDR_RPID_T:
477                                 if (msg->rpid==0) msg->rpid = hf;
478                                 msg->parsed_flag|=HDR_RPID_F;
479                                 break;
480                         case HDR_REFER_TO_T:
481                                 if (msg->refer_to==0) msg->refer_to = hf;
482                                 msg->parsed_flag|=HDR_REFER_TO_F;
483                                 break;
484                         case HDR_SESSIONEXPIRES_T:
485                                 if (msg->session_expires==0) msg->session_expires = hf;
486                                 msg->parsed_flag|=HDR_SESSIONEXPIRES_F;
487                                 break;
488                         case HDR_MIN_SE_T:
489                                 if (msg->min_se==0) msg->min_se = hf;
490                                 msg->parsed_flag|=HDR_MIN_SE_F;
491                                 break;
492                         case HDR_SUBSCRIPTION_STATE_T:
493                                 if (msg->subscription_state==0) msg->subscription_state = hf;
494                                 msg->parsed_flag|=HDR_SUBSCRIPTION_STATE_F;
495                                 break;
496                         case HDR_VIA_T:
497                                 msg->parsed_flag|=HDR_VIA_F;
498                                 DBG("Via found, flags=%llx\n", (unsigned long long)flags);
499                                 if (msg->via1==0) {
500                                         DBG("this is the first via\n");
501                                         msg->h_via1=hf;
502                                         msg->via1=hf->parsed;
503                                         if (msg->via1->next){
504                                                 msg->via2=msg->via1->next;
505                                                 msg->parsed_flag|=HDR_VIA2_F;
506                                         }
507                                 }else if (msg->via2==0){
508                                         msg->h_via2=hf;
509                                         msg->via2=hf->parsed;
510                                         msg->parsed_flag|=HDR_VIA2_F;
511                                         DBG("this is the second via\n");
512                                 }
513                                 break;
514                         case HDR_DATE_T:
515                                 if (msg->date==0) msg->date=hf;
516                                 msg->parsed_flag|=HDR_DATE_F;
517                                 break;
518                         case HDR_IDENTITY_T:
519                                 if (msg->identity==0) msg->identity=hf;
520                                 msg->parsed_flag|=HDR_IDENTITY_F;
521                                 break;
522                         case HDR_IDENTITY_INFO_T:
523                                 if (msg->identity_info==0) msg->identity_info=hf;
524                                 msg->parsed_flag|=HDR_IDENTITY_INFO_F;
525                                 break;
526                     case HDR_PATH_T:
527                                 if (msg->path==0) msg->path=hf;
528                                 msg->parsed_flag|=HDR_PATH_F;
529                                 break;
530                     case HDR_PRIVACY_T:
531                                 if (msg->privacy==0) msg->privacy=hf;
532                                 msg->parsed_flag|=HDR_PRIVACY_F;
533                                 break;
534                     case HDR_PAI_T:
535                                 if (msg->pai==0) msg->pai=hf;
536                                 msg->parsed_flag|=HDR_PAI_F;
537                                 break;
538                     case HDR_PPI_T:
539                                 if (msg->ppi==0) msg->ppi=hf;
540                                 msg->parsed_flag|=HDR_PPI_F;
541                                 break;
542                     case HDR_REASON_T:
543                                 msg->parsed_flag|=HDR_REASON_F;
544                                 break;
545                         case HDR_CALLINFO_T:
546                                 msg->parsed_flag|=HDR_CALLINFO_F;
547                                 break;
548                         default:
549                                 BUG("unknown header type %d\n", hf->type);
550                                 goto error;
551                 }
552                 /* add the header to the list*/
553                 if (msg->last_header==0){
554                         msg->headers=hf;
555                         msg->last_header=hf;
556                 }else{
557                         msg->last_header->next=hf;
558                         msg->last_header=hf;
559                 }
560 #ifdef EXTRA_DEBUG
561                 DBG("header field type %d, name=<%.*s>, body=<%.*s>\n", hf->type,
562                                 hf->name.len, ZSW(hf->name.s), hf->body.len, ZSW(hf->body.s));
563 #endif
564                 tmp=rest;
565         }
566 skip:
567         msg->unparsed=tmp;
568         /* restore original flags */
569         msg->parsed_flag |= orig_flag;
570         return 0;
571
572 error:
573         ser_error=E_BAD_REQ;
574         if (hf) pkg_free(hf);
575         /* restore original flags */
576         msg->parsed_flag |= orig_flag;
577         return -1;
578 }
579
580
581
582
583
584 /* returns 0 if ok, -1 for errors */
585 int parse_msg(char* const buf, const unsigned int len, struct sip_msg* const msg)
586 {
587
588         char *tmp;
589         char* rest;
590         struct msg_start *fl;
591         int offset;
592         hdr_flags_t flags;
593
594         /* eat crlf & whitespaces from the beginning */
595         for (tmp=buf; (tmp-buf < len)
596                         && (*tmp=='\n' || *tmp=='\r' || *tmp=='\0'
597                                 || *tmp=='\t' || *tmp==' ');
598                         tmp++);
599         offset=tmp-buf;
600         fl=&(msg->first_line);
601         rest=parse_first_line(tmp, len-offset, fl);
602         offset+=rest-tmp;
603         tmp=rest;
604         switch(fl->type){
605                 case SIP_INVALID:
606                         DBG("invalid message\n");
607                         goto error;
608                         break;
609                 case SIP_REQUEST:
610                         DBG("SIP Request:\n");
611                         DBG(" method:  <%.*s>\n", fl->u.request.method.len,
612                                         ZSW(fl->u.request.method.s));
613                         DBG(" uri:     <%.*s>\n", fl->u.request.uri.len,
614                                         ZSW(fl->u.request.uri.s));
615                         DBG(" version: <%.*s>\n", fl->u.request.version.len,
616                                         ZSW(fl->u.request.version.s));
617                         flags=HDR_VIA_F;
618                         break;
619                 case SIP_REPLY:
620                         DBG("SIP Reply  (status):\n");
621                         DBG(" version: <%.*s>\n", fl->u.reply.version.len,
622                                         ZSW(fl->u.reply.version.s));
623                         DBG(" status:  <%.*s>\n", fl->u.reply.status.len,
624                                         ZSW(fl->u.reply.status.s));
625                         DBG(" reason:  <%.*s>\n", fl->u.reply.reason.len,
626                                         ZSW(fl->u.reply.reason.s));
627                         /* flags=HDR_VIA | HDR_VIA2; */
628                         /* we don't try to parse VIA2 for local messages; -Jiri */
629                         flags=HDR_VIA_F;
630                         break;
631                 default:
632                         DBG("unknown type %d\n", fl->type);
633                         goto error;
634         }
635         msg->unparsed=tmp;
636         /*find first Via: */
637         if (parse_headers(msg, flags, 0)==-1) goto error;
638
639 #ifdef EXTRA_DEBUG
640         /* dump parsed data */
641         if (msg->via1){
642                 DBG("first via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
643                                 msg->via1->name.len, ZSW(msg->via1->name.s),
644                                 msg->via1->version.len, ZSW(msg->via1->version.s),
645                                 msg->via1->transport.len, ZSW(msg->via1->transport.s),
646                                 msg->via1->host.len, ZSW(msg->via1->host.s),
647                                 msg->via1->port_str.len, ZSW(msg->via1->port_str.s),
648                                 msg->via1->port);
649                 if (msg->via1->params.s)
650                         DBG(";<%.*s>", msg->via1->params.len, ZSW(msg->via1->params.s));
651                 if (msg->via1->comment.s)
652                         DBG(" <%.*s>", msg->via1->comment.len, ZSW(msg->via1->comment.s));
653                 DBG ("\n");
654         }
655         if (msg->via2){
656                 DBG("second via: <%.*s/%.*s/%.*s> <%.*s:%.*s(%d)>",
657                                 msg->via2->name.len, ZSW(msg->via2->name.s),
658                                 msg->via2->version.len, ZSW(msg->via2->version.s),
659                                 msg->via2->transport.len, ZSW(msg->via2->transport.s),
660                                 msg->via2->host.len, ZSW(msg->via2->host.s),
661                                 msg->via2->port_str.len, ZSW(msg->via2->port_str.s),
662                                 msg->via2->port);
663                 if (msg->via2->params.s)
664                         DBG(";<%.*s>", msg->via2->params.len, ZSW(msg->via2->params.s));
665                 if (msg->via2->comment.s)
666                         DBG(" <%.*s>", msg->via2->comment.len, ZSW(msg->via2->comment.s));
667                 DBG ("\n");
668         }
669 #endif
670
671
672 #ifdef EXTRA_DEBUG
673         DBG("exiting parse_msg\n");
674 #endif
675
676         return 0;
677
678 error:
679         /* more debugging, msg->orig is/should be null terminated*/
680         LOG(cfg_get(core, core_cfg, corelog), "ERROR: parse_msg: message=<%.*s>\n",
681                         (int)msg->len, ZSW(msg->buf));
682         return -1;
683 }
684
685
686
687 void free_reply_lump( struct lump_rpl *lump)
688 {
689         struct lump_rpl *foo, *bar;
690         for(foo=lump;foo;)
691         {
692                 bar=foo->next;
693                 free_lump_rpl(foo);
694                 foo = bar;
695         }
696 }
697
698
699 /*only the content*/
700 void free_sip_msg(struct sip_msg* const msg)
701 {
702         reset_new_uri(msg);
703         reset_dst_uri(msg);
704         reset_path_vector(msg);
705         reset_instance(msg);
706         reset_ruid(msg);
707         reset_ua(msg);
708         if (msg->headers)     free_hdr_field_lst(msg->headers);
709         if (msg->body && msg->body->free) msg->body->free(&msg->body);
710         if (msg->add_rm)      free_lump_list(msg->add_rm);
711         if (msg->body_lumps)  free_lump_list(msg->body_lumps);
712         if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
713         msg_ldata_reset(msg);
714         /* don't free anymore -- now a pointer to a static buffer */
715 #       ifdef DYN_BUF
716         pkg_free(msg->buf);
717 #       endif
718 }
719
720 /**
721  * reset new uri value
722  */
723 void reset_new_uri(struct sip_msg* const msg)
724 {
725         if(msg->new_uri.s != 0) {
726                 pkg_free(msg->new_uri.s);
727         }
728         msg->new_uri.s = 0;
729         msg->new_uri.len = 0;
730         msg->parsed_uri_ok = 0;
731 }
732
733
734 /*
735  * Make a private copy of the string and assign it to dst_uri
736  */
737 int set_dst_uri(struct sip_msg* const msg, const str* const uri)
738 {
739         char* ptr;
740
741         if (unlikely(!msg || !uri)) {
742                 ERR("Invalid parameter value\n");
743                 return -1;
744         }
745
746         if (unlikely(uri->len == 0)) {
747                 reset_dst_uri(msg);
748         }else if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
749                 memcpy(msg->dst_uri.s, uri->s, uri->len);
750                 msg->dst_uri.len = uri->len;
751         } else {
752                 ptr = (char*)pkg_malloc(uri->len + 1);
753                 if (!ptr) {
754                         PKG_MEM_ERROR;
755                         return -1;
756                 }
757
758                 memcpy(ptr, uri->s, uri->len);
759                 if (msg->dst_uri.s) pkg_free(msg->dst_uri.s);
760                 msg->dst_uri.s = ptr;
761                 msg->dst_uri.len = uri->len;
762                 msg->dst_uri.s[msg->dst_uri.len] = '\0';
763         }
764         return 0;
765 }
766
767
768 void reset_dst_uri(struct sip_msg* const msg)
769 {
770         if(msg->dst_uri.s != 0) {
771                 pkg_free(msg->dst_uri.s);
772         }
773         msg->dst_uri.s = 0;
774         msg->dst_uri.len = 0;
775 }
776
777 int set_path_vector(struct sip_msg* msg, str* path)
778 {
779         char* ptr;
780
781         if (unlikely(!msg || !path)) {
782                 ERR("invalid parameter value\n");
783                 return -1;
784         }
785
786         if (unlikely(path->len == 0)) {
787                 reset_path_vector(msg);
788         } else if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
789                 memcpy(msg->path_vec.s, path->s, path->len);
790                 msg->path_vec.len = path->len;
791         } else {
792                 ptr = (char*)pkg_malloc(path->len);
793                 if (!ptr) {
794                         PKG_MEM_ERROR;
795                         return -1;
796                 }
797
798                 memcpy(ptr, path->s, path->len);
799                 if (msg->path_vec.s) pkg_free(msg->path_vec.s);
800                 msg->path_vec.s = ptr;
801                 msg->path_vec.len = path->len;
802         }
803         return 0;
804 }
805
806
807 void reset_path_vector(struct sip_msg* const msg)
808 {
809         if (!shm_address_in(msg->path_vec.s)) {
810                 if (msg->path_vec.s)
811                         pkg_free(msg->path_vec.s);
812                 msg->path_vec.s = 0;
813                 msg->path_vec.len = 0;
814         } else {
815                 LM_WARN("Found path_vec that is not in pkg mem!\n");
816         }
817 }
818
819
820 int set_instance(struct sip_msg* msg, str* instance)
821 {
822         char* ptr;
823
824         if (unlikely(!msg || !instance)) {
825                 ERR("invalid instance parameter value\n");
826                 return -1;
827         }
828
829         if (unlikely(instance->len == 0)) {
830                 reset_instance(msg);
831         } else if (msg->instance.s && (msg->instance.len >= instance->len)) {
832                 memcpy(msg->instance.s, instance->s, instance->len);
833                 msg->instance.len = instance->len;
834         } else {
835                 ptr = (char*)pkg_malloc(instance->len);
836                 if (!ptr) {
837                         PKG_MEM_ERROR;
838                         return -1;
839                 }
840                 memcpy(ptr, instance->s, instance->len);
841                 if (msg->instance.s) pkg_free(msg->instance.s);
842                 msg->instance.s = ptr;
843                 msg->instance.len = instance->len;
844         }
845         return 0;
846 }
847
848
849 void reset_instance(struct sip_msg* const msg)
850 {
851         if(msg->instance.s != 0) {
852                 pkg_free(msg->instance.s);
853         }
854         msg->instance.s = 0;
855         msg->instance.len = 0;
856 }
857
858
859 int set_ruid(struct sip_msg* msg, str* ruid)
860 {
861         char* ptr;
862
863         if (unlikely(!msg || !ruid)) {
864                 ERR("invalid ruid parameter value\n");
865                 return -1;
866         }
867
868         if (unlikely(ruid->len == 0)) {
869                 reset_ruid(msg);
870         } else if (msg->ruid.s && (msg->ruid.len >= ruid->len)) {
871                 memcpy(msg->ruid.s, ruid->s, ruid->len);
872                 msg->ruid.len = ruid->len;
873         } else {
874                 ptr = (char*)pkg_malloc(ruid->len);
875                 if (!ptr) {
876                         PKG_MEM_ERROR;
877                         return -1;
878                 }
879                 memcpy(ptr, ruid->s, ruid->len);
880                 if (msg->ruid.s) pkg_free(msg->ruid.s);
881                 msg->ruid.s = ptr;
882                 msg->ruid.len = ruid->len;
883         }
884         return 0;
885 }
886
887
888 void reset_ruid(struct sip_msg* const msg)
889 {
890         if(msg->ruid.s != 0) {
891                 pkg_free(msg->ruid.s);
892         }
893         msg->ruid.s = 0;
894         msg->ruid.len = 0;
895 }
896
897
898 int set_ua(struct sip_msg* msg, str* location_ua)
899 {
900         char* ptr;
901
902         if (unlikely(!msg || !location_ua)) {
903                 ERR("invalid location_ua parameter value\n");
904                 return -1;
905         }
906
907         if (unlikely(location_ua->len == 0)) {
908                 reset_ua(msg);
909         } else if (msg->location_ua.s && (msg->location_ua.len >= location_ua->len)) {
910                 memcpy(msg->location_ua.s, location_ua->s, location_ua->len);
911                 msg->location_ua.len = location_ua->len;
912         } else {
913                 ptr = (char*)pkg_malloc(location_ua->len);
914                 if (!ptr) {
915                         PKG_MEM_ERROR;
916                         return -1;
917                 }
918                 memcpy(ptr, location_ua->s, location_ua->len);
919                 if (msg->location_ua.s) pkg_free(msg->location_ua.s);
920                 msg->location_ua.s = ptr;
921                 msg->location_ua.len = location_ua->len;
922         }
923         return 0;
924 }
925
926
927 void reset_ua(struct sip_msg* const msg)
928 {
929         if(msg->location_ua.s != 0) {
930                 pkg_free(msg->location_ua.s);
931         }
932         msg->location_ua.s = 0;
933         msg->location_ua.len = 0;
934 }
935
936 /**
937  * reset content of msg->ldv (msg_ldata_t structure)
938  */
939 void msg_ldata_reset(sip_msg_t *msg)
940 {
941         if(msg==NULL)
942                 return;
943         memset(&msg->ldv, 0, sizeof(msg_ldata_t));
944 }
945
946
947 hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
948 {
949         hdr_field_t *hdr;
950
951         if (msg->parsed_flag & HDR_T2F(ht))
952                 for(hdr = msg->headers; hdr; hdr = hdr->next) {
953                         if(hdr->type == ht) return hdr;
954                 }
955         return NULL;
956 }
957
958
959 hdr_field_t* next_sibling_hdr(const hdr_field_t* const hf)
960 {
961         hdr_field_t *hdr;
962
963         for(hdr = hf->next; hdr; hdr = hdr->next) {
964                 if(hdr->type == hf->type) return hdr;
965         }
966         return NULL;
967 }
968
969 hdr_field_t* get_hdr_by_name(const sip_msg_t* const msg, const char* const name, const int name_len)
970 {
971         hdr_field_t *hdr;
972
973         for(hdr = msg->headers; hdr; hdr = hdr->next) {
974                 if(hdr->name.len == name_len && *hdr->name.s==*name
975                                 && strncasecmp(hdr->name.s, name, name_len)==0)
976                         return hdr;
977         }
978         return NULL;
979 }
980
981 /** not used yet */
982 hdr_field_t* next_sibling_hdr_by_name(const hdr_field_t* const hf)
983 {
984         hdr_field_t *hdr;
985
986         for(hdr = hf->next; hdr; hdr = hdr->next) {
987                 if(hdr->name.len == hf->name.len && *hdr->name.s==*hf->name.s
988                                 && strncasecmp(hdr->name.s, hf->name.s, hf->name.len)==0)
989                         return hdr;
990         }
991         return NULL;
992 }
993
994 /**
995  * set msg context id
996  * - return: -1 on error; 0 - on set
997  */
998 int msg_ctx_id_set(const sip_msg_t* const msg, msg_ctx_id_t* const mid)
999 {
1000         if(msg==NULL || mid==NULL)
1001                 return -1;
1002         mid->msgid = msg->id;
1003         mid->pid = msg->pid;
1004         return 0;
1005 }
1006
1007 /**
1008  * check msg context id
1009  * - return: -1 on error; 0 - on no match; 1 - on match
1010  */
1011 int msg_ctx_id_match(const sip_msg_t* const msg, const msg_ctx_id_t* const mid)
1012 {
1013         if(msg==NULL || mid==NULL)
1014                 return -1;
1015         if(msg->id != mid->msgid || msg->pid!=mid->pid)
1016                 return 0;
1017         return 1;
1018 }
1019
1020 /**
1021  * set msg time value
1022  */
1023 int msg_set_time(sip_msg_t* const msg)
1024 {
1025         if(unlikely(msg==NULL))
1026                 return -2;
1027         if(msg->tval.tv_sec!=0)
1028                 return 0;
1029         return gettimeofday(&msg->tval, NULL);
1030 }
1031
1032 /**
1033  * get source ip, port and protocol in SIP URI format
1034  * - tmode - 0: short format (transport=udp is not added, being default)
1035  */
1036 int get_src_uri(sip_msg_t *m, int tmode, str *uri)
1037 {
1038         static char buf[MAX_URI_SIZE];
1039         char* p;
1040         str ip, port;
1041         int len;
1042         str proto;
1043
1044         if (!uri || !m) {
1045                 ERR("invalid parameter value\n");
1046                 return -1;
1047         }
1048
1049         if(tmode==0) {
1050                 switch(m->rcv.proto) {
1051                         case PROTO_NONE:
1052                         case PROTO_UDP:
1053                                 proto.s = 0; /* Do not add transport parameter, UDP is default */
1054                                 proto.len = 0;
1055                         break;
1056                         default:
1057                                 if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
1058                                         ERR("unknown transport protocol\n");
1059                                         return -1;
1060                                 }
1061                 }
1062         } else {
1063                 if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
1064                         ERR("unknown transport protocol\n");
1065                         return -1;
1066                 }
1067         }
1068
1069         ip.s = ip_addr2a(&m->rcv.src_ip);
1070         ip.len = strlen(ip.s);
1071
1072         port.s = int2str(m->rcv.src_port, &port.len);
1073
1074         len = 4 + ip.len + 2*(m->rcv.src_ip.af==AF_INET6)+ 1 + port.len;
1075         if (proto.s) {
1076                 len += TRANSPORT_PARAM_LEN;
1077                 len += proto.len;
1078         }
1079
1080         if (len > MAX_URI_SIZE) {
1081                 ERR("buffer too small\n");
1082                 return -1;
1083         }
1084
1085         p = buf;
1086         memcpy(p, "sip:", 4);
1087         p += 4;
1088
1089         if (m->rcv.src_ip.af==AF_INET6)
1090                 *p++ = '[';
1091         memcpy(p, ip.s, ip.len);
1092         p += ip.len;
1093         if (m->rcv.src_ip.af==AF_INET6)
1094                 *p++ = ']';
1095
1096         *p++ = ':';
1097
1098         memcpy(p, port.s, port.len);
1099         p += port.len;
1100
1101         if (proto.s) {
1102                 memcpy(p, TRANSPORT_PARAM, TRANSPORT_PARAM_LEN);
1103                 p += TRANSPORT_PARAM_LEN;
1104
1105                 memcpy(p, proto.s, proto.len);
1106                 p += proto.len;
1107         }
1108
1109         uri->s = buf;
1110         uri->len = len;
1111
1112         return 0;
1113 }
1114
1115 /**
1116  * get source proto:ip:port (socket address format)
1117  */
1118 int get_src_address_socket(sip_msg_t *m, str *ssock)
1119 {
1120         static char buf[MAX_URI_SIZE];
1121         char* p;
1122         str ip, port;
1123         int len;
1124         str proto;
1125
1126         if (!ssock || !m) {
1127                 ERR("invalid parameter value\n");
1128                 return -1;
1129         }
1130
1131         if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
1132                 ERR("unknown transport protocol\n");
1133                 return -1;
1134         }
1135
1136         ip.s = ip_addr2a(&m->rcv.src_ip);
1137         ip.len = strlen(ip.s);
1138
1139         port.s = int2str(m->rcv.src_port, &port.len);
1140
1141         len = proto.len + 1 + ip.len + 2*(m->rcv.src_ip.af==AF_INET6)+ 1 + port.len;
1142
1143         if (len+1 >= MAX_URI_SIZE) {
1144                 ERR("buffer too small\n");
1145                 return -1;
1146         }
1147
1148         p = buf;
1149
1150         memcpy(p, proto.s, proto.len);
1151         p += proto.len;
1152
1153         *p++ = ':';
1154
1155         if (m->rcv.src_ip.af==AF_INET6)
1156                 *p++ = '[';
1157         memcpy(p, ip.s, ip.len);
1158         p += ip.len;
1159         if (m->rcv.src_ip.af==AF_INET6)
1160                 *p++ = ']';
1161
1162         *p++ = ':';
1163
1164         memcpy(p, port.s, port.len);
1165         p += port.len;
1166         *p = '\0';
1167
1168         ssock->s = buf;
1169         ssock->len = len;
1170
1171         return 0;
1172 }
1173
1174 /**
1175  * get received-on-socket ip, port and protocol in SIP URI format
1176  * - tmode - 0: short format (transport=udp is not added, being default)
1177  * - atype - 0: listen address; 1: advertised address
1178  */
1179 int get_rcv_socket_uri(sip_msg_t *m, int tmode, str *uri, int atype)
1180 {
1181         static char buf[MAX_URI_SIZE];
1182         char* p;
1183         str ip, port;
1184         int len;
1185         str proto;
1186
1187         if (!uri || !m || !m->rcv.bind_address) {
1188                 ERR("invalid parameter value\n");
1189                 return -1;
1190         }
1191
1192         if(tmode==0) {
1193                 switch(m->rcv.proto) {
1194                         case PROTO_NONE:
1195                         case PROTO_UDP:
1196                                 proto.s = 0; /* Do not add transport parameter, UDP is default */
1197                                 proto.len = 0;
1198                         break;
1199                         default:
1200                                 if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
1201                                         ERR("unknown transport protocol\n");
1202                                         return -1;
1203                                 }
1204                 }
1205         } else {
1206                 if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
1207                         ERR("unknown transport protocol\n");
1208                         return -1;
1209                 }
1210         }
1211
1212         if(atype==0 || m->rcv.bind_address->useinfo.address_str.len<=0) {
1213                 ip.s = m->rcv.bind_address->address_str.s;
1214                 ip.len = m->rcv.bind_address->address_str.len;
1215         } else {
1216                 ip.s = m->rcv.bind_address->useinfo.address_str.s;
1217                 ip.len = m->rcv.bind_address->useinfo.address_str.len;
1218         }
1219
1220         if(atype==0|| m->rcv.bind_address->useinfo.port_no_str.len <= 0) {
1221                 port.s = m->rcv.bind_address->port_no_str.s;
1222                 port.len = m->rcv.bind_address->port_no_str.len;
1223         } else {
1224                 port.s = m->rcv.bind_address->useinfo.port_no_str.s;
1225                 port.len = m->rcv.bind_address->useinfo.port_no_str.len;
1226         }
1227
1228         len = 4 + ip.len + 2*(m->rcv.src_ip.af==AF_INET6)+ 1 + port.len;
1229         if (proto.s) {
1230                 len += TRANSPORT_PARAM_LEN;
1231                 len += proto.len;
1232         }
1233
1234         if (len > MAX_URI_SIZE) {
1235                 ERR("buffer too small\n");
1236                 return -1;
1237         }
1238
1239         p = buf;
1240         memcpy(p, "sip:", 4);
1241         p += 4;
1242
1243         if (m->rcv.src_ip.af==AF_INET6)
1244                 *p++ = '[';
1245         memcpy(p, ip.s, ip.len);
1246         p += ip.len;
1247         if (m->rcv.src_ip.af==AF_INET6)
1248                 *p++ = ']';
1249
1250         *p++ = ':';
1251
1252         memcpy(p, port.s, port.len);
1253         p += port.len;
1254
1255         if (proto.s) {
1256                 memcpy(p, TRANSPORT_PARAM, TRANSPORT_PARAM_LEN);
1257                 p += TRANSPORT_PARAM_LEN;
1258
1259                 memcpy(p, proto.s, proto.len);
1260                 p += proto.len;
1261         }
1262
1263         uri->s = buf;
1264         uri->len = len;
1265
1266         return 0;
1267 }
1268
1269
1270 /*! \brief returns a pointer to the begining of the msg's body
1271  */
1272 char* get_body(sip_msg_t* const msg)
1273 {
1274         int offset;
1275         unsigned int len;
1276
1277         if ( parse_headers(msg, HDR_EOH_F, 0)==-1 ) {
1278                 LM_ERR("failed to parse to end of headers\n");
1279                 return 0;
1280         }
1281
1282         if (msg->unparsed) {
1283                 len=(unsigned int)(msg->unparsed-msg->buf);
1284         } else {
1285                 LM_ERR("unparsed hook for end of headers is not set\n");
1286                 return 0;
1287         }
1288
1289         if ((len+2<=msg->len) && (strncmp(CRLF,msg->unparsed,CRLF_LEN)==0) ) {
1290                 offset = CRLF_LEN;
1291         } else if ( (len+1<=msg->len) &&
1292                                 (*(msg->unparsed)=='\n' || *(msg->unparsed)=='\r' ) ) {
1293                 offset = 1;
1294         } else {
1295                 LM_ERR("failed to locate end of headers (%p %p - %d %d [%s])\n",
1296                                 msg->buf, msg->unparsed, msg->len, len, msg->unparsed);
1297                 return 0;
1298         }
1299
1300         return msg->unparsed + offset;
1301 }
1302
1303 /*! \brief make sure all HFs needed for transaction identification have been
1304  * parsed; return 0 if those HFs can't be found
1305 */
1306 int check_transaction_quadruple(sip_msg_t* const msg)
1307 {
1308         if ( parse_headers(msg, HDR_FROM_F|HDR_TO_F|HDR_CALLID_F|HDR_CSEQ_F,0)!=-1
1309                 && msg->from && msg->to && msg->callid && msg->cseq ) {
1310                 return 1;
1311         } else {
1312                 ser_error=E_BAD_TUPEL;
1313                 return 0;
1314         }
1315 }