639b0f58bd4fa9d2f00b7dbcbade55ee0b267e93
[sip-router] / parser / parse_cseq.c
1 /* 
2  * $Id$ 
3  */
4
5 #include "parse_cseq.h"
6 #include "parser_f.h"  /* eat_space_end and so on */
7 #include "../dprint.h"
8 #include "parse_def.h"
9 #include "../mem/mem.h"
10
11 /*
12  * Parse CSeq header field
13  */
14
15 /*BUGGY*/
16 char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
17 {
18         char *t, *m, *m_end;
19         char c;
20         
21         cb->error=PARSE_ERROR;
22         t=eat_space_end(buf, end);
23         if (t>=end) goto error;
24         
25         cb->number.s=t;
26         t=eat_token_end(t, end);
27         if (t>=end) goto error;
28         m=eat_space_end(t, end);
29         m_end=eat_token_end(m, end);
30         *t=0; /*null terminate it*/
31         cb->number.len=t-cb->number.s;
32
33         if (m_end>=end) goto error;
34         if (m_end==m){
35                 /* null method*/
36                 LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
37                 goto error;
38         }
39         cb->method.s=m;
40         t=m_end;
41         c=*t;
42         *t=0; /*null terminate it*/
43         cb->method.len=t-cb->method.s;
44         t++;
45         /*check if the header ends here*/
46         if (c=='\n') goto check_continue;
47         do{
48                 for (;(t<end)&&((*t==' ')||(*t=='\t')||(*t=='\r'));t++);
49                 if (t>=end) goto error;
50                 if (*t!='\n'){
51                         LOG(L_ERR, "ERROR:parse_cseq: unexpected char <%c> at end of"
52                                         " cseq\n", *t);
53                         goto error;
54                 }
55                 t++;
56 check_continue:
57                 ;
58         }while( (t<end) && ((*t==' ')||(*t=='\t')) );
59
60         cb->error=PARSE_OK;
61         return t;
62 error:
63         LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
64         return t;
65 }
66
67
68 void free_cseq(struct cseq_body* cb)
69 {
70         pkg_free(cb);
71 }