/[resiprocate]/branches/b-identity-0505/HeaderHash.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/HeaderHash.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 13418 byte(s)
set svn:eol-style to LF
1 /* C++ code produced by gperf version 2.7.2 */
2 /* Command-line: gperf -D --enum -E -L C++ -t -k '*' --compare-strncmp -Z HeaderHash HeaderHash.gperf */
3 #include <string.h>
4 #include <ctype.h>
5 #include "resiprocate/HeaderTypes.hxx"
6
7 namespace resip
8 {
9 using namespace std;
10 struct headers { char *name; Headers::Type type; };
11 /* maximum key range = 540, duplicates = 4 */
12
13 class HeaderHash
14 {
15 private:
16 static inline unsigned int hash (const char *str, unsigned int len);
17 public:
18 static struct headers *in_word_set (const char *str, unsigned int len);
19 };
20
21 inline unsigned int
22 HeaderHash::hash (register const char *str, register unsigned int len)
23 {
24 static unsigned short asso_values[] =
25 {
26 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
27 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
28 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
29 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
30 541, 541, 541, 541, 541, 0, 541, 541, 541, 541,
31 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
32 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
33 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
34 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
35 541, 541, 541, 541, 541, 541, 541, 0, 55, 20,
36 0, 0, 75, 100, 5, 10, 0, 35, 15, 90,
37 0, 0, 65, 0, 50, 30, 40, 0, 45, 5,
38 95, 65, 25, 541, 541, 541, 541, 541, 541, 541,
39 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
40 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
41 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
42 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
43 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
44 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
45 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
46 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
47 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
48 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
49 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
50 541, 541, 541, 541, 541, 541, 541, 541, 541, 541,
51 541, 541, 541, 541, 541, 541
52 };
53 register int hval = len;
54
55 switch (hval)
56 {
57 default:
58 case 25:
59 hval += asso_values[(unsigned char)tolower(str[24])];
60 case 24:
61 hval += asso_values[(unsigned char)tolower(str[23])];
62 case 23:
63 hval += asso_values[(unsigned char)tolower(str[22])];
64 case 22:
65 hval += asso_values[(unsigned char)tolower(str[21])];
66 case 21:
67 hval += asso_values[(unsigned char)tolower(str[20])];
68 case 20:
69 hval += asso_values[(unsigned char)tolower(str[19])];
70 case 19:
71 hval += asso_values[(unsigned char)tolower(str[18])];
72 case 18:
73 hval += asso_values[(unsigned char)tolower(str[17])];
74 case 17:
75 hval += asso_values[(unsigned char)tolower(str[16])];
76 case 16:
77 hval += asso_values[(unsigned char)tolower(str[15])];
78 case 15:
79 hval += asso_values[(unsigned char)tolower(str[14])];
80 case 14:
81 hval += asso_values[(unsigned char)tolower(str[13])];
82 case 13:
83 hval += asso_values[(unsigned char)tolower(str[12])];
84 case 12:
85 hval += asso_values[(unsigned char)tolower(str[11])];
86 case 11:
87 hval += asso_values[(unsigned char)tolower(str[10])];
88 case 10:
89 hval += asso_values[(unsigned char)tolower(str[9])];
90 case 9:
91 hval += asso_values[(unsigned char)tolower(str[8])];
92 case 8:
93 hval += asso_values[(unsigned char)tolower(str[7])];
94 case 7:
95 hval += asso_values[(unsigned char)tolower(str[6])];
96 case 6:
97 hval += asso_values[(unsigned char)tolower(str[5])];
98 case 5:
99 hval += asso_values[(unsigned char)tolower(str[4])];
100 case 4:
101 hval += asso_values[(unsigned char)tolower(str[3])];
102 case 3:
103 hval += asso_values[(unsigned char)tolower(str[2])];
104 case 2:
105 hval += asso_values[(unsigned char)tolower(str[1])];
106 case 1:
107 hval += asso_values[(unsigned char)tolower(str[0])];
108 break;
109 }
110 return hval;
111 }
112
113 struct headers *
114 HeaderHash::in_word_set (register const char *str, register unsigned int len)
115 {
116 enum
117 {
118 TOTAL_KEYWORDS = 98,
119 MIN_WORD_LENGTH = 1,
120 MAX_WORD_LENGTH = 25,
121 MIN_HASH_VALUE = 1,
122 MAX_HASH_VALUE = 540
123 };
124
125 static struct headers wordlist[] =
126 {
127 {"e", Headers::ContentEncoding},
128 {"i", Headers::CallID},
129 {"join", Headers::Join},
130 {"join", Headers::Join},
131 {"l", Headers::ContentLength},
132 {"hide", Headers::UNKNOWN},
133 {"c", Headers::ContentType},
134 {"s", Headers::Subject},
135 {"k", Headers::Supported},
136 {"allow", Headers::Allow},
137 {"t", Headers::To},
138 {"to", Headers::To},
139 {"date", Headers::Date},
140 {"v", Headers::Via},
141 {"r", Headers::ReferTo},
142 {"cseq", Headers::CSeq},
143 {"b", Headers::ReferredBy},
144 {"via", Headers::Via},
145 {"y", Headers::Identity},
146 {"call-id", Headers::CallID},
147 {"f", Headers::From},
148 {"rseq", Headers::RSeq},
149 {"reason", Headers::Reason},
150 {"event", Headers::Event},
151 {"m", Headers::Contact},
152 {"route", Headers::Route},
153 {"x", Headers::SessionExpires},
154 {"rack", Headers::RAck},
155 {"path", Headers::Path},
156 {"require", Headers::Require},
157 {"content-id", Headers::ContentId},
158 {"contact", Headers::Contact},
159 {"min-se", Headers::MinSE},
160 {"call-info", Headers::CallInfo},
161 {"accept", Headers::Accept},
162 {"subject", Headers::Subject},
163 {"allow-events", Headers::AllowEvents},
164 {"warning", Headers::Warning},
165 {"identity", Headers::Identity},
166 {"server", Headers::Server},
167 {"www-authenticate",Headers::WWWAuthenticate},
168 {"replaces",Headers::Replaces},
169 {"authorization", Headers::Authorization},
170 {"alert-info",Headers::AlertInfo},
171 {"from", Headers::From},
172 {"record-route", Headers::RecordRoute},
173 {"refer-to",Headers::ReferTo},
174 {"user-agent", Headers::UserAgent},
175 {"reply-to", Headers::ReplyTo},
176 {"reject-contact", Headers::RejectContact},
177 {"error-info", Headers::ErrorInfo},
178 {"content-encoding", Headers::ContentEncoding},
179 {"organization", Headers::Organization},
180 {"sip-etag", Headers::SIPETag},
181 {"in-reply-to", Headers::InReplyTo},
182 {"expires", Headers::Expires},
183 {"service-route", Headers::ServiceRoute},
184 {"service-route", Headers::ServiceRoute},
185 {"supported", Headers::Supported},
186 {"encryption", Headers::UNKNOWN},
187 {"unsupported", Headers::Unsupported},
188 {"privacy", Headers::Privacy},
189 {"identity-info", Headers::IdentityInfo},
190 {"authentication-info", Headers::AuthenticationInfo},
191 {"p-associated-uri", Headers::PAssociatedUri},
192 {"p-associated-uri", Headers::PAssociatedUri},
193 {"content-length", Headers::ContentLength},
194 {"accept-contact", Headers::AcceptContact},
195 {"content-type", Headers::ContentType},
196 {"response-key", Headers::UNKNOWN},
197 {"accept-encoding", Headers::AcceptEncoding},
198 {"priority", Headers::Priority},
199 {"content-disposition", Headers::ContentDisposition},
200 {"security-client", Headers::SecurityClient},
201 {"content-language", Headers::ContentLanguage},
202 {"request-disposition", Headers::RequestDisposition},
203 {"mime-version", Headers::MIMEVersion},
204 {"referred-by",Headers::ReferredBy},
205 {"sip-if-match", Headers::SIPIfMatch},
206 {"min-expires", Headers::MinExpires},
207 {"p-called-party-id", Headers::PCalledPartyId},
208 {"p-called-party-id", Headers::PCalledPartyId},
209 {"session-expires", Headers::SessionExpires},
210 {"p-media-authorization", Headers::PMediaAuthorization},
211 {"target-dialog", Headers::TargetDialog},
212 {"timestamp", Headers::Timestamp},
213 {"accept-language", Headers::AcceptLanguage},
214 {"retry-after", Headers::RetryAfter},
215 {"proxy-require", Headers::ProxyRequire},
216 {"p-asserted-identity", Headers::PAssertedIdentity},
217 {"security-server", Headers::SecurityServer},
218 {"max-forwards", Headers::MaxForwards},
219 {"subscription-state",Headers::SubscriptionState},
220 {"proxy-authenticate", Headers::ProxyAuthenticate},
221 {"proxy-authorization", Headers::ProxyAuthorization},
222 {"security-verify", Headers::SecurityVerify},
223 {"content-transfer-encoding", Headers::ContentTransferEncoding},
224 {"p-preferred-identity", Headers::PPreferredIdentity}
225 };
226
227 static short lookup[] =
228 {
229 -1, 0, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, 1, -1, -1, -116, -1,
231 4, -96, -2, 5, -1, 6, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, 7,
233 -1, -1, -1, -1, 8, -1, -1, -1,
234 9, 10, 11, -1, 12, -1, 13, -1,
235 -1, -1, -1, 14, -1, -1, 15, -1,
236 16, -1, 17, -1, -1, -1, -1, -1,
237 -1, -1, 18, 19, -1, -1, -1, -1,
238 -1, -1, -1, -1, 20, -1, -1, -1,
239 -1, -1, -1, -1, 21, -1, 22, -1,
240 -1, -1, 23, 24, -1, -1, -1, 25,
241 26, -1, -1, -1, -1, -1, -1, -1,
242 -1, -1, -1, -1, -1, 27, -1, -1,
243 -1, -1, 28, -1, -1, 29, -1, -1,
244 30, -1, -1, -1, -1, -1, -1, 31,
245 -1, -1, -1, -1, -1, -1, -1, -1,
246 32, -1, -1, -1, -1, -1, -1, -1,
247 33, -1, -1, -1, -1, -1, -1, 34,
248 35, -1, -1, -1, -1, -1, -1, -1,
249 -1, -1, 36, -1, -1, -1, -1, -1,
250 -1, -1, -1, -1, 37, 38, -1, -1,
251 -1, -1, -1, -1, -1, 39, -1, -1,
252 -1, -1, 40, -1, 41, -1, -1, -1,
253 -1, 42, -1, -1, -1, -1, -1, -1,
254 43, -1, -1, -1, -1, -1, -1, -1,
255 -1, -1, -1, -1, -1, -1, -1, -1,
256 -1, -1, -1, 44, -1, -1, 45, 46,
257 -1, -1, -1, -1, -1, -1, 47, -1,
258 -1, -1, -1, -1, -1, -1, -1, -1,
259 -1, -1, -1, 48, 49, 50, 51, 52,
260 -1, -1, -1, -1, -1, 53, -1, -1,
261 54, 55, -363, 58, 59, 60, 61, 62,
262 -42, -2, -1, -1, -1, 63, -1, -371,
263 -34, -2, 66, -1, -1, -1, -1, 67,
264 -1, -1, 68, -1, -1, -1, -1, 69,
265 -1, -1, 70, -1, -1, -1, -1, -1,
266 -1, -1, 71, -1, -1, -1, -1, -1,
267 -1, -1, -1, -1, -1, -1, -1, -1,
268 -1, -1, 72, 73, -1, -1, -1, -1,
269 -1, -1, -1, -1, -1, -1, -1, -1,
270 -1, -1, -1, 74, -1, -1, 75, -1,
271 -1, 76, -1, -1, -1, -1, -1, -1,
272 -1, -1, -1, -1, -1, -1, -1, -1,
273 -1, -1, -1, -1, 77, 78, -1, -1,
274 -1, 79, -462, -18, -2, 82, 83, -1,
275 84, -1, -1, -1, -1, -1, 85, 86,
276 -1, -1, -1, -1, -1, 87, -1, -1,
277 -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, 88, 89,
279 -1, -1, -1, -1, -1, 90, -1, 91,
280 -1, -1, -1, -1, -1, -1, -1, -1,
281 -1, -1, -1, -1, -1, -1, -1, -1,
282 -1, -1, -1, -1, -1, -1, -1, -1,
283 -1, -1, -1, -1, -1, -1, 92, -1,
284 -1, -1, -1, -1, -1, -1, -1, -1,
285 93, -1, -1, -1, -1, -1, -1, -1,
286 -1, -1, -1, -1, -1, -1, -1, -1,
287 -1, -1, -1, -1, -1, -1, -1, -1,
288 -1, -1, 94, 95, -1, -1, -1, -1,
289 -1, -1, -1, -1, -1, -1, -1, -1,
290 -1, -1, -1, -1, -1, -1, -1, -1,
291 -1, -1, -1, -1, 96, -1, -1, -1,
292 -1, -1, -1, -1, -1, -1, -1, -1,
293 -1, -1, -1, -1, -1, -1, -1, -1,
294 -1, -1, -1, -1, -1, -1, -1, -1,
295 -1, -1, -1, -1, -1, -1, -1, -1,
296 -1, -1, -1, -1, 97
297 };
298
299 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
300 {
301 register int key = hash (str, len);
302
303 if (key <= MAX_HASH_VALUE && key >= 0)
304 {
305 register int index = lookup[key];
306
307 if (index >= 0)
308 {
309 register const char *s = wordlist[index].name;
310
311 if (tolower(*str) == *s && !strncasecmp (str + 1, s + 1, len - 1) && s[len] == '\0')
312 return &wordlist[index];
313 }
314 else if (index < -TOTAL_KEYWORDS)
315 {
316 register int offset = - 1 - TOTAL_KEYWORDS - index;
317 register struct headers *wordptr = &wordlist[TOTAL_KEYWORDS + lookup[offset]];
318 register struct headers *wordendptr = wordptr + -lookup[offset + 1];
319
320 while (wordptr < wordendptr)
321 {
322 register const char *s = wordptr->name;
323
324 if (tolower(*str) == *s && !strncasecmp (str + 1, s + 1, len - 1) && s[len] == '\0')
325 return wordptr;
326 wordptr++;
327 }
328 }
329 }
330 }
331 return 0;
332 }
333 }

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27