4 * Copyright (C) 2007 iptelorg GmbH
6 * This file is part of ser, a free SIP server.
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
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:
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.
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
27 * 2007-05-28 lightweight parser implemented for build_local_reparse()
28 * function. Basically copy-pasted from the core parser (Miklos)
31 #include "../../parser/keys.h"
32 #include "../../parser/hf.h"
33 #include "../../parser/parser_f.h"
34 #include "lw_parser.h"
36 /* macros from the core parser */
37 #define LOWER_BYTE(b) ((b) | 0x20)
38 #define LOWER_DWORD(d) ((d) | 0x20202020)
41 (*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
44 * lightweight header field name parser
45 * used by build_local_reparse() function in order to construct ACK or CANCEL request
46 * from the INVITE buffer
47 * this parser supports only the header fields which are needed by build_local_reparse()
49 char *lw_get_hf_name(char *begin, char *end,
50 enum _hdr_types_t *type)
56 if (end - begin < 4) {
62 val = LOWER_DWORD(READ(p));
66 case _cseq_: /* Cseq */
71 case _via1_: /* Via */
77 case _from_: /* From */
87 case _requ_: /* Require */
89 val = LOWER_DWORD(READ(p));
96 *type = HDR_REQUIRE_T;
106 case _prox_: /* Proxy-Require */
108 if ((LOWER_DWORD(READ(p+4)) == _y_re_)
109 && (LOWER_DWORD(READ(p+8)) == _quir_)
110 && (LOWER_BYTE(*(p+12)) == 'e')) {
113 *type = HDR_PROXYREQUIRE_T;
121 case _cont_: /* Content-Length */
123 if ((LOWER_DWORD(READ(p+4)) == _ent__)
124 && (LOWER_DWORD(READ(p+8)) == _leng_)
125 && (LOWER_BYTE(*(p+12)) == 't')
126 && (LOWER_BYTE(*(p+13)) == 'h')) {
129 *type = HDR_CONTENTLENGTH_T;
136 case _call_: /* Call-Id */
139 val = LOWER_DWORD(READ(p));
146 *type = HDR_CALLID_T;
156 case _rout_: /* Route */
158 if (LOWER_BYTE(*(p+4)) == 'e') {
167 case _max__: /* Max-Forwards */
169 if ((LOWER_DWORD(READ(p+4)) == _forw_)
170 && (LOWER_DWORD(READ(p+8)) == _ards_)) {
173 *type = HDR_MAXFORWARDS_T;
181 /* compact headers */
182 switch(LOWER_BYTE(*p)) {
185 if ((*(p+1) == ' ') || (*(p+1) == ':')) {
194 if ((*(p+1) == ' ') || (*(p+1) == ':')) {
203 if (LOWER_BYTE(*(p+1)) == 'o') {
208 if ((*(p+1) == ' ') || (*(p+1) == ':')) {
216 case 'l': /* Content-Length */
217 if ((*(p+1) == ' ') || (*(p+1) == ':')) {
219 *type = HDR_CONTENTLENGTH_T;
225 case 'i': /* Call-Id */
226 if ((*(p+1) == ' ') || (*(p+1) == ':')) {
228 *type = HDR_CALLID_T;
243 /* returns a pointer to the next line */
244 char *lw_next_line(char *buf, char *buf_end)
250 while ((c < buf_end) && (*c != '\n')) c++;
251 if (c < buf_end) c++;
253 } while ((c < buf_end) &&
254 ((*c == ' ') || (*c == '\t'))); /* next line begins with whitespace line folding */