OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / user / ser / parser / parse_cseq.c
1 /* 
2  * $Id: parse_cseq.c,v 1.6 2004/08/24 09:01:25 janakj Exp $ 
3  *
4  * Copyright (C) 2001-2003 FhG Fokus
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser 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  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License 
24  * along with this program; if not, write to the Free Software 
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  * 
27  * History:
28  * --------
29  * 2003-02-28 scratchpad compatibility abandoned (jiri)
30  * 2003-01-22 zero-termination in CSeq eliminated (jiri)
31  */
32
33
34 #include "../comp_defs.h"
35 #include "parse_cseq.h"
36 #include "parser_f.h"  /* eat_space_end and so on */
37 #include "../dprint.h"
38 #include "parse_def.h"
39 #include "../mem/mem.h"
40
41 /*
42  * Parse CSeq header field
43  */
44
45 /*BUGGY*/
46 char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
47 {
48         char *t, *m, *m_end;
49         
50         cb->error=PARSE_ERROR;
51         t=buf;
52         
53         cb->number.s=t;
54         t=eat_token_end(t, end);
55         if (t>=end) goto error;
56         cb->number.len=t-cb->number.s;
57
58         m=eat_space_end(t, end);
59         m_end=eat_token_end(m, end);
60
61         if (m_end>=end) {
62                         LOG(L_ERR, "ERROR: parse_cseq: "
63                                                 "method terminated unexpectedly\n");
64                         goto error;
65         }
66         if (m_end==m){
67                 /* null method*/
68                 LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
69                 goto error;
70         }
71         cb->method.s=m;
72         t=m_end;
73         cb->method.len=t-cb->method.s;
74
75         /* there may be trailing LWS 
76          * (it was not my idea to put it in SIP; -jiri )
77          */
78         t=eat_lws_end(t, end);
79         /*check if the header ends here*/
80         if (t>=end) {
81                 LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
82                 goto error;
83         }
84         if (*t=='\r' && t+1<end && *(t+1)=='\n') {
85                         cb->error=PARSE_OK;
86                         return t+2;
87         }
88         if (*t=='\n') {
89                         cb->error=PARSE_OK;
90                         return t+1;
91         }
92         LOG(L_ERR, "ERROR: CSeq EoL expected\n");
93
94 error:
95         LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
96         return t;
97 }
98
99
100 void free_cseq(struct cseq_body* cb)
101 {
102         pkg_free(cb);
103 }