/src/kamailio/src/core/parser/parse_retry_after.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2007 iptelorg GmbH |
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 :: Retry-After: header parser |
24 | | * |
25 | | * \ingroup parser |
26 | | */ |
27 | | |
28 | | |
29 | | #include "../comp_defs.h" |
30 | | #include "parse_retry_after.h" |
31 | | #include "parser_f.h" /* eat_space_end and so on */ |
32 | | #include "parse_def.h" |
33 | | #include "../dprint.h" |
34 | | #include "../mem/mem.h" |
35 | | |
36 | | /*! \brief Parse the Retry-after header field */ |
37 | | char *parse_retry_after(char *const buf, const char *const end, |
38 | | unsigned *const after, int *const err) |
39 | 2.21k | { |
40 | 2.21k | char *t; |
41 | 2.21k | int i; |
42 | 2.21k | unsigned val; |
43 | | |
44 | 2.21k | val = 0; |
45 | 2.21k | t = buf; |
46 | | |
47 | 2.21k | t = eat_lws_end(t, end); |
48 | 2.21k | if(t >= end) |
49 | 0 | goto error; |
50 | 9.68k | for(i = 0; t < end; i++, t++) { |
51 | 9.63k | if((*t >= '0') && (*t <= '9')) { |
52 | 7.46k | val = val * 10 + (*t - '0'); |
53 | 7.46k | } else { |
54 | 2.17k | switch(*t) { |
55 | | /* for now we don't care about retry-after params or comment*/ |
56 | 270 | case ' ': |
57 | 545 | case '\t': |
58 | 792 | case ';': |
59 | 1.12k | case '\r': |
60 | 1.83k | case '\n': |
61 | 2.07k | case '(': |
62 | 2.07k | goto found; |
63 | 101 | default: |
64 | | /* invalid char */ |
65 | 101 | goto error; |
66 | 2.17k | } |
67 | 2.17k | } |
68 | 9.63k | } |
69 | 41 | goto error_nocrlf; /* end reached without encountering cr or lf */ |
70 | 2.07k | found: |
71 | 2.07k | if(i > 10 || i == 0) /* too many or too few digits */ |
72 | 223 | goto error; |
73 | 1.85k | *after = val; |
74 | | /* find the end of header */ |
75 | 13.3k | for(; t < end; t++) { |
76 | 12.9k | if(*t == '\n') { |
77 | 1.96k | if(((t + 1) < end) && (*(t + 1) == ' ' || *(t + 1) == '\t')) { |
78 | 471 | t++; |
79 | 471 | continue; /* line folding ... */ |
80 | 471 | } |
81 | 1.49k | *err = 0; |
82 | 1.49k | return t + 1; |
83 | 1.96k | } |
84 | 12.9k | } |
85 | 397 | error_nocrlf: |
86 | 397 | LM_ERR("strange EoHF\n"); |
87 | 397 | goto error; |
88 | 721 | error: |
89 | 721 | LM_ERR("bad Retry-After header \n"); |
90 | 721 | *err = 1; |
91 | 721 | return t; |
92 | 1.85k | } |