cool.io 1.2.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,403 +0,0 @@
1
- #line 1 "http11_parser.rl"
2
- /**
3
- * Copyright (c) 2005 Zed A. Shaw
4
- * You can redistribute it and/or modify it under the same terms as Ruby.
5
- */
6
-
7
- #include "http11_parser.h"
8
- #include <stdio.h>
9
- #include <assert.h>
10
- #include <stdlib.h>
11
- #include <ctype.h>
12
- #include <string.h>
13
-
14
- #define LEN(AT, FPC) (FPC - buffer - parser->AT)
15
- #define MARK(M,FPC) (parser->M = (FPC) - buffer)
16
- #define PTR_TO(F) (buffer + parser->F)
17
- #define L(M) fprintf(stderr, "" # M "\n");
18
-
19
-
20
- /** machine **/
21
- #line 95 "http11_parser.rl"
22
-
23
-
24
- /** Data **/
25
-
26
- #line 27 "http11_parser.c"
27
- static const char _httpclient_parser_actions[] = {
28
- 0, 1, 0, 1, 1, 1, 2, 1,
29
- 3, 1, 4, 1, 5, 1, 7, 1,
30
- 8, 1, 10, 2, 2, 3, 2, 6,
31
- 0, 2, 6, 5, 2, 9, 10, 2,
32
- 10, 9, 3, 2, 3, 4
33
- };
34
-
35
- static const short _httpclient_parser_key_offsets[] = {
36
- 0, 10, 10, 11, 22, 26, 27, 28,
37
- 39, 54, 75, 90, 110, 125, 146, 161,
38
- 181, 196, 214, 229, 246, 247, 248, 249,
39
- 250, 252, 255, 257, 260, 262, 264, 266,
40
- 268, 269, 270, 286, 302, 304, 305, 306
41
- };
42
-
43
- static const char _httpclient_parser_trans_keys[] = {
44
- 13, 48, 59, 72, 49, 57, 65, 70,
45
- 97, 102, 10, 13, 32, 59, 9, 12,
46
- 48, 57, 65, 70, 97, 102, 13, 32,
47
- 9, 12, 10, 10, 13, 32, 59, 9,
48
- 12, 48, 57, 65, 70, 97, 102, 33,
49
- 124, 126, 35, 39, 42, 43, 45, 46,
50
- 48, 57, 65, 90, 94, 122, 13, 32,
51
- 33, 59, 61, 124, 126, 9, 12, 35,
52
- 39, 42, 43, 45, 46, 48, 57, 65,
53
- 90, 94, 122, 33, 124, 126, 35, 39,
54
- 42, 43, 45, 46, 48, 57, 65, 90,
55
- 94, 122, 13, 32, 33, 59, 124, 126,
56
- 9, 12, 35, 39, 42, 43, 45, 46,
57
- 48, 57, 65, 90, 94, 122, 33, 124,
58
- 126, 35, 39, 42, 43, 45, 46, 48,
59
- 57, 65, 90, 94, 122, 13, 32, 33,
60
- 59, 61, 124, 126, 9, 12, 35, 39,
61
- 42, 43, 45, 46, 48, 57, 65, 90,
62
- 94, 122, 33, 124, 126, 35, 39, 42,
63
- 43, 45, 46, 48, 57, 65, 90, 94,
64
- 122, 13, 32, 33, 59, 124, 126, 9,
65
- 12, 35, 39, 42, 43, 45, 46, 48,
66
- 57, 65, 90, 94, 122, 33, 124, 126,
67
- 35, 39, 42, 43, 45, 46, 48, 57,
68
- 65, 90, 94, 122, 13, 33, 59, 61,
69
- 124, 126, 35, 39, 42, 43, 45, 46,
70
- 48, 57, 65, 90, 94, 122, 33, 124,
71
- 126, 35, 39, 42, 43, 45, 46, 48,
72
- 57, 65, 90, 94, 122, 13, 33, 59,
73
- 124, 126, 35, 39, 42, 43, 45, 46,
74
- 48, 57, 65, 90, 94, 122, 84, 84,
75
- 80, 47, 48, 57, 46, 48, 57, 48,
76
- 57, 32, 48, 57, 48, 57, 48, 57,
77
- 48, 57, 13, 32, 13, 10, 13, 33,
78
- 124, 126, 35, 39, 42, 43, 45, 46,
79
- 48, 57, 65, 90, 94, 122, 33, 58,
80
- 124, 126, 35, 39, 42, 43, 45, 46,
81
- 48, 57, 65, 90, 94, 122, 13, 32,
82
- 13, 13, 0
83
- };
84
-
85
- static const char _httpclient_parser_single_lengths[] = {
86
- 4, 0, 1, 3, 2, 1, 1, 3,
87
- 3, 7, 3, 6, 3, 7, 3, 6,
88
- 3, 6, 3, 5, 1, 1, 1, 1,
89
- 0, 1, 0, 1, 0, 0, 0, 2,
90
- 1, 1, 4, 4, 2, 1, 1, 0
91
- };
92
-
93
- static const char _httpclient_parser_range_lengths[] = {
94
- 3, 0, 0, 4, 1, 0, 0, 4,
95
- 6, 7, 6, 7, 6, 7, 6, 7,
96
- 6, 6, 6, 6, 0, 0, 0, 0,
97
- 1, 1, 1, 1, 1, 1, 1, 0,
98
- 0, 0, 6, 6, 0, 0, 0, 0
99
- };
100
-
101
- static const unsigned char _httpclient_parser_index_offsets[] = {
102
- 0, 8, 8, 10, 18, 22, 24, 26,
103
- 34, 44, 59, 69, 83, 93, 108, 118,
104
- 132, 142, 155, 165, 177, 179, 181, 183,
105
- 185, 187, 190, 192, 195, 197, 199, 201,
106
- 204, 206, 208, 219, 230, 233, 235, 237
107
- };
108
-
109
- static const char _httpclient_parser_indicies[] = {
110
- 14, 15, 17, 18, 16, 16, 16, 0,
111
- 30, 0, 63, 37, 64, 37, 39, 39,
112
- 39, 0, 19, 32, 32, 0, 29, 0,
113
- 31, 0, 38, 37, 40, 37, 39, 39,
114
- 39, 0, 58, 58, 58, 58, 58, 58,
115
- 58, 58, 58, 0, 42, 41, 43, 44,
116
- 45, 43, 43, 41, 43, 43, 43, 43,
117
- 43, 43, 0, 59, 59, 59, 59, 59,
118
- 59, 59, 59, 59, 0, 34, 33, 35,
119
- 36, 35, 35, 33, 35, 35, 35, 35,
120
- 35, 35, 0, 70, 70, 70, 70, 70,
121
- 70, 70, 70, 70, 0, 65, 41, 66,
122
- 67, 68, 66, 66, 41, 66, 66, 66,
123
- 66, 66, 66, 0, 69, 69, 69, 69,
124
- 69, 69, 69, 69, 69, 0, 60, 33,
125
- 61, 62, 61, 61, 33, 61, 61, 61,
126
- 61, 61, 61, 0, 10, 10, 10, 10,
127
- 10, 10, 10, 10, 10, 0, 24, 25,
128
- 26, 27, 25, 25, 25, 25, 25, 25,
129
- 25, 25, 0, 11, 11, 11, 11, 11,
130
- 11, 11, 11, 11, 0, 21, 22, 23,
131
- 22, 22, 22, 22, 22, 22, 22, 22,
132
- 0, 1, 0, 56, 0, 2, 0, 5,
133
- 0, 7, 0, 6, 7, 0, 13, 0,
134
- 12, 13, 0, 4, 0, 3, 0, 57,
135
- 0, 54, 55, 53, 49, 48, 28, 0,
136
- 19, 20, 20, 20, 20, 20, 20, 20,
137
- 20, 20, 0, 8, 9, 8, 8, 8,
138
- 8, 8, 8, 8, 8, 0, 47, 52,
139
- 51, 47, 46, 49, 50, 0, 0
140
- };
141
-
142
- static const char _httpclient_parser_trans_targs_wi[] = {
143
- 1, 21, 23, 30, 29, 24, 26, 25,
144
- 35, 36, 17, 19, 28, 27, 2, 3,
145
- 7, 16, 20, 5, 35, 2, 19, 16,
146
- 2, 17, 16, 18, 34, 39, 39, 39,
147
- 4, 4, 5, 11, 8, 4, 5, 7,
148
- 8, 4, 5, 9, 8, 10, 37, 33,
149
- 32, 33, 32, 37, 36, 32, 33, 38,
150
- 22, 31, 9, 11, 6, 15, 12, 6,
151
- 12, 6, 13, 12, 14, 15, 13
152
- };
153
-
154
- static const char _httpclient_parser_trans_actions_wi[] = {
155
- 0, 0, 0, 0, 1, 0, 0, 0,
156
- 0, 5, 3, 7, 13, 0, 0, 1,
157
- 1, 0, 1, 0, 3, 9, 0, 9,
158
- 34, 0, 34, 19, 0, 17, 28, 31,
159
- 0, 9, 9, 0, 9, 15, 15, 0,
160
- 15, 34, 34, 0, 34, 19, 0, 9,
161
- 0, 11, 1, 7, 7, 22, 25, 22,
162
- 0, 0, 3, 7, 9, 0, 9, 15,
163
- 15, 34, 0, 34, 19, 7, 3
164
- };
165
-
166
- static const int httpclient_parser_start = 0;
167
-
168
- static const int httpclient_parser_first_final = 39;
169
-
170
- static const int httpclient_parser_error = 1;
171
-
172
- #line 99 "http11_parser.rl"
173
-
174
- int httpclient_parser_init(httpclient_parser *parser) {
175
- int cs = 0;
176
-
177
- #line 178 "http11_parser.c"
178
- {
179
- cs = httpclient_parser_start;
180
- }
181
- #line 103 "http11_parser.rl"
182
- parser->cs = cs;
183
- parser->body_start = 0;
184
- parser->content_len = 0;
185
- parser->mark = 0;
186
- parser->nread = 0;
187
- parser->field_len = 0;
188
- parser->field_start = 0;
189
-
190
- return(1);
191
- }
192
-
193
-
194
- /** exec **/
195
- size_t httpclient_parser_execute(httpclient_parser *parser, const char *buffer, size_t len, size_t off) {
196
- const char *p, *pe;
197
- int cs = parser->cs;
198
-
199
- assert(off <= len && "offset past end of buffer");
200
-
201
- p = buffer+off;
202
- pe = buffer+len;
203
-
204
- assert(*pe == '\0' && "pointer does not end on NUL");
205
- assert(pe - p == len - off && "pointers aren't same distance");
206
-
207
-
208
-
209
- #line 210 "http11_parser.c"
210
- {
211
- int _klen;
212
- unsigned int _trans;
213
- const char *_acts;
214
- unsigned int _nacts;
215
- const char *_keys;
216
-
217
- if ( p == pe )
218
- goto _out;
219
- _resume:
220
- if ( cs == 1 )
221
- goto _out;
222
- _keys = _httpclient_parser_trans_keys + _httpclient_parser_key_offsets[cs];
223
- _trans = _httpclient_parser_index_offsets[cs];
224
-
225
- _klen = _httpclient_parser_single_lengths[cs];
226
- if ( _klen > 0 ) {
227
- const char *_lower = _keys;
228
- const char *_mid;
229
- const char *_upper = _keys + _klen - 1;
230
- while (1) {
231
- if ( _upper < _lower )
232
- break;
233
-
234
- _mid = _lower + ((_upper-_lower) >> 1);
235
- if ( (*p) < *_mid )
236
- _upper = _mid - 1;
237
- else if ( (*p) > *_mid )
238
- _lower = _mid + 1;
239
- else {
240
- _trans += (_mid - _keys);
241
- goto _match;
242
- }
243
- }
244
- _keys += _klen;
245
- _trans += _klen;
246
- }
247
-
248
- _klen = _httpclient_parser_range_lengths[cs];
249
- if ( _klen > 0 ) {
250
- const char *_lower = _keys;
251
- const char *_mid;
252
- const char *_upper = _keys + (_klen<<1) - 2;
253
- while (1) {
254
- if ( _upper < _lower )
255
- break;
256
-
257
- _mid = _lower + (((_upper-_lower) >> 1) & ~1);
258
- if ( (*p) < _mid[0] )
259
- _upper = _mid - 2;
260
- else if ( (*p) > _mid[1] )
261
- _lower = _mid + 2;
262
- else {
263
- _trans += ((_mid - _keys)>>1);
264
- goto _match;
265
- }
266
- }
267
- _trans += _klen;
268
- }
269
-
270
- _match:
271
- _trans = _httpclient_parser_indicies[_trans];
272
- cs = _httpclient_parser_trans_targs_wi[_trans];
273
-
274
- if ( _httpclient_parser_trans_actions_wi[_trans] == 0 )
275
- goto _again;
276
-
277
- _acts = _httpclient_parser_actions + _httpclient_parser_trans_actions_wi[_trans];
278
- _nacts = (unsigned int) *_acts++;
279
- while ( _nacts-- > 0 )
280
- {
281
- switch ( *_acts++ )
282
- {
283
- case 0:
284
- #line 23 "http11_parser.rl"
285
- {MARK(mark, p); }
286
- break;
287
- case 1:
288
- #line 25 "http11_parser.rl"
289
- { MARK(field_start, p); }
290
- break;
291
- case 2:
292
- #line 27 "http11_parser.rl"
293
- {
294
- parser->field_len = LEN(field_start, p);
295
- }
296
- break;
297
- case 3:
298
- #line 31 "http11_parser.rl"
299
- { MARK(mark, p); }
300
- break;
301
- case 4:
302
- #line 33 "http11_parser.rl"
303
- {
304
- parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
305
- }
306
- break;
307
- case 5:
308
- #line 37 "http11_parser.rl"
309
- {
310
- parser->reason_phrase(parser->data, PTR_TO(mark), LEN(mark, p));
311
- }
312
- break;
313
- case 6:
314
- #line 41 "http11_parser.rl"
315
- {
316
- parser->status_code(parser->data, PTR_TO(mark), LEN(mark, p));
317
- }
318
- break;
319
- case 7:
320
- #line 45 "http11_parser.rl"
321
- {
322
- parser->http_version(parser->data, PTR_TO(mark), LEN(mark, p));
323
- }
324
- break;
325
- case 8:
326
- #line 49 "http11_parser.rl"
327
- {
328
- parser->chunk_size(parser->data, PTR_TO(mark), LEN(mark, p));
329
- }
330
- break;
331
- case 9:
332
- #line 53 "http11_parser.rl"
333
- {
334
- parser->last_chunk(parser->data, NULL, 0);
335
- }
336
- break;
337
- case 10:
338
- #line 57 "http11_parser.rl"
339
- {
340
- parser->body_start = p - buffer + 1;
341
- if(parser->header_done != NULL)
342
- parser->header_done(parser->data, p + 1, pe - p - 1);
343
- goto _out;
344
- }
345
- break;
346
- #line 347 "http11_parser.c"
347
- }
348
- }
349
-
350
- _again:
351
- if ( ++p != pe )
352
- goto _resume;
353
- _out: {}
354
- }
355
- #line 130 "http11_parser.rl"
356
-
357
- parser->cs = cs;
358
- parser->nread += p - (buffer + off);
359
-
360
- assert(p <= pe && "buffer overflow after parsing execute");
361
- assert(parser->nread <= len && "nread longer than length");
362
- assert(parser->body_start <= len && "body starts after buffer end");
363
- assert(parser->mark < len && "mark is after buffer end");
364
- assert(parser->field_len <= len && "field has length longer than whole buffer");
365
- assert(parser->field_start < len && "field starts after buffer end");
366
-
367
- if(parser->body_start) {
368
- /* final \r\n combo encountered so stop right here */
369
-
370
- #line 371 "http11_parser.c"
371
- #line 144 "http11_parser.rl"
372
- parser->nread++;
373
- }
374
-
375
- return(parser->nread);
376
- }
377
-
378
- int httpclient_parser_finish(httpclient_parser *parser)
379
- {
380
- int cs = parser->cs;
381
-
382
-
383
- #line 384 "http11_parser.c"
384
- #line 155 "http11_parser.rl"
385
-
386
- parser->cs = cs;
387
-
388
- if (httpclient_parser_has_error(parser) ) {
389
- return -1;
390
- } else if (httpclient_parser_is_finished(parser) ) {
391
- return 1;
392
- } else {
393
- return 0;
394
- }
395
- }
396
-
397
- int httpclient_parser_has_error(httpclient_parser *parser) {
398
- return parser->cs == httpclient_parser_error;
399
- }
400
-
401
- int httpclient_parser_is_finished(httpclient_parser *parser) {
402
- return parser->cs == httpclient_parser_first_final;
403
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright (c) 2005 Zed A. Shaw
3
- * You can redistribute it and/or modify it under the same terms as Ruby.
4
- */
5
-
6
- #ifndef http11_parser_h
7
- #define http11_parser_h
8
-
9
- #include <sys/types.h>
10
-
11
- #if defined(_WIN32)
12
- #include <stddef.h>
13
- #endif
14
-
15
- typedef void (*element_cb)(void *data, const char *at, size_t length);
16
- typedef void (*field_cb)(void *data, const char *field, size_t flen, const char *value, size_t vlen);
17
-
18
- typedef struct httpclient_parser {
19
- int cs;
20
- size_t body_start;
21
- int content_len;
22
- size_t nread;
23
- size_t mark;
24
- size_t field_start;
25
- size_t field_len;
26
-
27
- void *data;
28
-
29
- field_cb http_field;
30
- element_cb reason_phrase;
31
- element_cb status_code;
32
- element_cb chunk_size;
33
- element_cb http_version;
34
- element_cb header_done;
35
- element_cb last_chunk;
36
-
37
-
38
- } httpclient_parser;
39
-
40
- int httpclient_parser_init(httpclient_parser *parser);
41
- int httpclient_parser_finish(httpclient_parser *parser);
42
- size_t httpclient_parser_execute(httpclient_parser *parser, const char *data, size_t len, size_t off);
43
- int httpclient_parser_has_error(httpclient_parser *parser);
44
- int httpclient_parser_is_finished(httpclient_parser *parser);
45
-
46
- #define httpclient_parser_nread(parser) (parser)->nread
47
-
48
- #endif