/src/opensips/parser/parse_cseq.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version |
10 | | * |
11 | | * opensips is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | * |
20 | | * History: |
21 | | * -------- |
22 | | * 2003-02-28 scratchpad compatibility abandoned (jiri) |
23 | | * 2003-01-22 zero-termination in CSeq eliminated (jiri) |
24 | | */ |
25 | | |
26 | | |
27 | | #include "../dprint.h" |
28 | | #include "parse_cseq.h" |
29 | | #include "parser_f.h" /* eat_space_end and so on */ |
30 | | #include "parse_def.h" |
31 | | #include "parse_methods.h" |
32 | | #include "../mem/mem.h" |
33 | | |
34 | | /* |
35 | | * Parse CSeq header field |
36 | | */ |
37 | | |
38 | | char* parse_cseq(char *buf, char* end, struct cseq_body* cb) |
39 | 0 | { |
40 | 0 | char *t, *m, *m_end; |
41 | |
|
42 | 0 | cb->error=PARSE_ERROR; |
43 | 0 | t=buf; |
44 | |
|
45 | 0 | cb->number.s=t; |
46 | 0 | t=eat_token_end(t, end); |
47 | 0 | if (t>=end) goto error; |
48 | 0 | cb->number.len=t-cb->number.s; |
49 | |
|
50 | 0 | m=eat_space_end(t, end); |
51 | 0 | m_end=eat_token_end(m, end); |
52 | |
|
53 | 0 | if (m_end>=end) { |
54 | 0 | LM_ERR("method terminated unexpectedly\n"); |
55 | 0 | goto error; |
56 | 0 | } |
57 | 0 | if (m_end==m){ |
58 | | /* null method*/ |
59 | 0 | LM_ERR("no method found\n"); |
60 | 0 | goto error; |
61 | 0 | } |
62 | 0 | cb->method.s=m; |
63 | 0 | t=m_end; |
64 | 0 | cb->method.len=t-cb->method.s; |
65 | | |
66 | | /* cache the method id */ |
67 | 0 | if(parse_method(cb->method.s, t, (unsigned int*)&cb->method_id)==0) |
68 | 0 | { |
69 | 0 | LM_ERR("cannot parse the method\n"); |
70 | 0 | goto error; |
71 | 0 | } |
72 | | |
73 | | /* there may be trailing LWS |
74 | | * (it was not my idea to put it in SIP; -jiri ) |
75 | | */ |
76 | 0 | t=eat_lws_end(t, end); |
77 | | /*check if the header ends here*/ |
78 | 0 | if (t>=end) { |
79 | 0 | LM_ERR("strange EoHF\n"); |
80 | 0 | goto error; |
81 | 0 | } |
82 | 0 | if (*t=='\r' && t+1<end && *(t+1)=='\n') { |
83 | 0 | cb->error=PARSE_OK; |
84 | 0 | return t+2; |
85 | 0 | } |
86 | 0 | if (*t=='\n') { |
87 | 0 | cb->error=PARSE_OK; |
88 | 0 | return t+1; |
89 | 0 | } |
90 | 0 | LM_ERR("expecting CSeq EoL\n"); |
91 | |
|
92 | 0 | error: |
93 | 0 | LM_ERR("bad cseq\n"); |
94 | 0 | return t; |
95 | 0 | } |
96 | | |
97 | | |
98 | | void free_cseq(struct cseq_body* cb) |
99 | 0 | { |
100 | 0 | pkg_free(cb); |
101 | 0 | } |