1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/*
* $Id: parse_hname2.c,v 1.4 2006/02/28 18:56:09 bogdan_iancu Exp $
*
* Fast 32-bit Header Field Name Parser
*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* openser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2003-02-28 scratchpad compatibility abandoned (jiri)
* 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
* 2003-05-01 added support for Accept HF (janakj)
* 2006-02-17 Session-Expires, Min-SE (dhsueh@somanetworks.com)
*/
#include "parse_hname2.h"
#include "keys.h"
#include "../ut.h" /* q_memchr */
#define LOWER_BYTE(b) ((b) | 0x20)
#define LOWER_DWORD(d) ((d) | 0x20202020)
/*
* Skip all white-chars and return position of the first
* non-white char
*/
static inline char* skip_ws(char* p, unsigned int size)
{
char* end;
end = p + size;
for(; p < end; p++) {
if ((*p != ' ') && (*p != '\t')) return p;
}
return p;
}
/*
* Parser macros
*/
#include "case_via.h" /* Via */
#include "case_from.h" /* From */
#include "case_to.h" /* To */
#include "case_cseq.h" /* CSeq */
#include "case_call.h" /* Call-ID */
#include "case_cont.h" /* Contact, Content-Type, Content-Length,
Content-Purpose, Content-Action,
Content-Disposition */
#include "case_rout.h" /* Route */
#include "case_max.h" /* Max-Forwards */
#include "case_reco.h" /* Record-Route */
#include "case_path.h" /* Path */
#include "case_auth.h" /* Authorization */
#include "case_expi.h" /* Expires */
#include "case_prox.h" /* Proxy-Authorization, Proxy-Require */
#include "case_allo.h" /* Allow */
#include "case_unsu.h" /* Unsupported */
#include "case_even.h" /* Event */
#include "case_acce.h" /* Accept, Accept-Language */
#include "case_orga.h" /* Organization */
#include "case_prio.h" /* Priority */
#include "case_subj.h" /* Subject */
#include "case_user.h" /* User-Agent */
#include "case_supp.h" /* Supported */
#include "case_dive.h" /* Diversion */
#include "case_remo.h" /* Remote-Party-ID */
#include "case_refe.h" /* Refer-To */
#include "case_sess.h" /* Session-Expires */
#include "case_min_.h" /* Min-SE */
#define READ(val) \
(*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
#define FIRST_QUATERNIONS \
case _via1_: via1_CASE; \
case _from_: from_CASE; \
case _to12_: to12_CASE; \
case _cseq_: cseq_CASE; \
case _call_: call_CASE; \
case _cont_: cont_CASE; \
case _rout_: rout_CASE; \
case _max__: max_CASE; \
case _reco_: reco_CASE; \
case _via2_: via2_CASE; \
case _auth_: auth_CASE; \
case _supp_: supp_CASE; \
case _expi_: expi_CASE; \
case _prox_: prox_CASE; \
case _allo_: allo_CASE; \
case _path_: path_CASE; \
case _unsu_: unsu_CASE; \
case _even_: even_CASE; \
case _acce_: acce_CASE; \
case _orga_: orga_CASE; \
case _prio_: prio_CASE; \
case _subj_: subj_CASE; \
case _user_: user_CASE; \
case _dive_: dive_CASE; \
case _remo_: remo_CASE; \
case _refe_: refe_CASE; \
case _sess_: sess_CASE; \
case _min__: min__CASE; \
#define PARSE_COMPACT(id) \
switch(*(p + 1)) { \
case ' ': \
hdr->type = id; \
p += 2; \
goto dc_end; \
\
case ':': \
hdr->type = id; \
hdr->name.len = 1; \
return (p + 2); \
}
char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
{
register char* p;
register unsigned int val;
if ((end - begin) < 4) {
hdr->type = HDR_ERROR_T;
return begin;
}
p = begin;
val = LOWER_DWORD(READ(p));
hdr->name.s = begin;
switch(val) {
FIRST_QUATERNIONS;
default:
switch(LOWER_BYTE(*p)) {
case 't':
switch(LOWER_BYTE(*(p + 1))) {
case 'o':
case ' ':
hdr->type = HDR_TO_T;
p += 2;
goto dc_end;
case ':':
hdr->type = HDR_TO_T;
hdr->name.len = 1;
return (p + 2);
}
break;
case 'v': PARSE_COMPACT(HDR_VIA_T); break;
case 'f': PARSE_COMPACT(HDR_FROM_T); break;
case 'i': PARSE_COMPACT(HDR_CALLID_T); break;
case 'm': PARSE_COMPACT(HDR_CONTACT_T); break;
case 'l': PARSE_COMPACT(HDR_CONTENTLENGTH_T); break;
case 'k': PARSE_COMPACT(HDR_SUPPORTED_T); break;
case 'c': PARSE_COMPACT(HDR_CONTENTTYPE_T); break;
case 'o': PARSE_COMPACT(HDR_EVENT_T); break;
case 'x': PARSE_COMPACT(HDR_SESSION_EXPIRES_T); break;
}
goto other;
}
/* Double colon hasn't been found yet */
dc_end:
p = skip_ws(p, end - p);
if (*p != ':') {
goto other;
} else {
hdr->name.len = p - hdr->name.s;
return (p + 1);
}
/* Unknown header type */
other:
p = q_memchr(p, ':', end - p);
if (!p) { /* No double colon found, error.. */
hdr->type = HDR_ERROR_T;
hdr->name.s = 0;
hdr->name.len = 0;
return 0;
} else {
hdr->type = HDR_OTHER_T;
hdr->name.len = p - hdr->name.s;
return (p + 1);
}
}
|