2006-06-30 16:42:12 -04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2005 Zed A. Shaw
|
|
|
|
* You can redistribute it and/or modify it under the same terms as Ruby.
|
2016-09-06 16:23:59 -04:00
|
|
|
* License 3-clause BSD
|
2006-06-30 16:42:12 -04:00
|
|
|
*/
|
2006-05-21 10:46:42 -04:00
|
|
|
|
2006-01-28 14:03:53 -05:00
|
|
|
#ifndef http11_parser_h
|
|
|
|
#define http11_parser_h
|
|
|
|
|
2013-09-04 14:15:56 -04:00
|
|
|
#define RSTRING_NOT_MODIFIED 1
|
2011-09-15 01:07:27 -04:00
|
|
|
#include "ruby.h"
|
|
|
|
|
2006-01-28 14:03:53 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-02-03 00:42:08 -05:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
2011-09-15 01:07:27 -04:00
|
|
|
#define BUFFER_LEN 1024
|
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
struct puma_parser;
|
2011-09-15 01:07:27 -04:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
typedef void (*element_cb)(struct puma_parser* hp,
|
2011-09-15 01:07:27 -04:00
|
|
|
const char *at, size_t length);
|
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
typedef void (*field_cb)(struct puma_parser* hp,
|
2011-09-15 01:07:27 -04:00
|
|
|
const char *field, size_t flen,
|
|
|
|
const char *value, size_t vlen);
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
typedef struct puma_parser {
|
2006-01-28 14:03:53 -05:00
|
|
|
int cs;
|
2006-05-14 19:41:22 -04:00
|
|
|
size_t body_start;
|
2006-01-28 14:03:53 -05:00
|
|
|
int content_len;
|
|
|
|
size_t nread;
|
2006-05-14 19:41:22 -04:00
|
|
|
size_t mark;
|
|
|
|
size_t field_start;
|
2006-01-28 14:03:53 -05:00
|
|
|
size_t field_len;
|
2006-08-07 22:07:24 -04:00
|
|
|
size_t query_start;
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2011-09-15 01:07:27 -04:00
|
|
|
VALUE request;
|
2011-09-18 16:02:34 -04:00
|
|
|
VALUE body;
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
field_cb http_field;
|
|
|
|
element_cb request_method;
|
2006-02-03 00:42:08 -05:00
|
|
|
element_cb request_uri;
|
2007-10-15 14:00:40 -04:00
|
|
|
element_cb fragment;
|
2006-08-08 05:26:23 -04:00
|
|
|
element_cb request_path;
|
2006-01-28 14:03:53 -05:00
|
|
|
element_cb query_string;
|
|
|
|
element_cb http_version;
|
2006-03-19 00:18:11 -05:00
|
|
|
element_cb header_done;
|
2011-09-15 01:07:27 -04:00
|
|
|
|
|
|
|
char buf[BUFFER_LEN];
|
2006-03-19 00:18:11 -05:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
} puma_parser;
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
int puma_parser_init(puma_parser *parser);
|
|
|
|
int puma_parser_finish(puma_parser *parser);
|
|
|
|
size_t puma_parser_execute(puma_parser *parser, const char *data,
|
2011-09-15 01:07:27 -04:00
|
|
|
size_t len, size_t off);
|
2013-07-18 14:22:18 -04:00
|
|
|
int puma_parser_has_error(puma_parser *parser);
|
|
|
|
int puma_parser_is_finished(puma_parser *parser);
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
#define puma_parser_nread(parser) (parser)->nread
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
#endif
|