/src/kamailio/src/core/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 Kamailio, a free SIP server. |
5 | | * |
6 | | * Kamailio 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 | | * Kamailio 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 | | */ |
21 | | |
22 | | /*! \file |
23 | | * \brief Parser :: Cseq header field handling |
24 | | * |
25 | | * \ingroup parser |
26 | | */ |
27 | | |
28 | | |
29 | | #include "../comp_defs.h" |
30 | | #include "parse_cseq.h" |
31 | | #include "parser_f.h" /* eat_space_end and so on */ |
32 | | #include "../dprint.h" |
33 | | #include "parse_def.h" |
34 | | #include "parse_methods.h" |
35 | | #include "../mem/mem.h" |
36 | | |
37 | | /* parse cseq header */ |
38 | | char *parse_cseq( |
39 | | char *const buf, const char *const end, struct cseq_body *const cb) |
40 | 16.6k | { |
41 | 16.6k | char *t, *m, *m_end; |
42 | | |
43 | 16.6k | cb->error = PARSE_ERROR; |
44 | 16.6k | t = buf; |
45 | | |
46 | 16.6k | cb->number.s = t; |
47 | 16.6k | t = eat_token_end(t, end); |
48 | 16.6k | if(t >= end) |
49 | 76 | goto error; |
50 | 16.5k | cb->number.len = t - cb->number.s; |
51 | | |
52 | 16.5k | m = eat_space_end(t, end); |
53 | 16.5k | m_end = eat_token_end(m, end); |
54 | | |
55 | 16.5k | if(m_end >= end) { |
56 | 256 | LM_ERR("method terminated unexpectedly\n"); |
57 | 256 | goto error; |
58 | 256 | } |
59 | 16.2k | if(m_end == m) { |
60 | | /* null method*/ |
61 | 48 | LM_ERR("no method found\n"); |
62 | 48 | goto error; |
63 | 48 | } |
64 | 16.2k | cb->method.s = m; |
65 | 16.2k | t = m_end; |
66 | 16.2k | cb->method.len = t - cb->method.s; |
67 | | |
68 | | /* Cache method id */ |
69 | 16.2k | if(parse_method_name(&cb->method, &cb->method_id) != 0) { |
70 | 0 | LM_ERR("Cannot parse method string\n"); |
71 | 0 | goto error; |
72 | 0 | } |
73 | | |
74 | | /* there may be trailing LWS */ |
75 | 16.2k | t = eat_lws_end(t, end); |
76 | | /*check if the header ends here*/ |
77 | 16.2k | if(t >= end) { |
78 | 1.98k | LM_ERR("strange EoHF\n"); |
79 | 1.98k | goto error; |
80 | 1.98k | } |
81 | 14.2k | if(*t == '\r' && t + 1 < end && *(t + 1) == '\n') { |
82 | 246 | cb->error = PARSE_OK; |
83 | 246 | return t + 2; |
84 | 246 | } |
85 | 13.9k | if(*t == '\n') { |
86 | 13.2k | cb->error = PARSE_OK; |
87 | 13.2k | return t + 1; |
88 | 13.2k | } |
89 | 695 | LM_ERR("CSeq EoL expected\n"); |
90 | | |
91 | 3.06k | error: |
92 | 3.06k | LM_ERR("bad cseq\n"); |
93 | 3.06k | return t; |
94 | 695 | } |
95 | | |
96 | | |
97 | | void free_cseq(struct cseq_body *const cb) |
98 | 16.6k | { |
99 | 16.6k | pkg_free(cb); |
100 | 16.6k | } |