123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- #ifndef ZEPHYR_INCLUDE_NET_HTTP_PARSER_H_
- #define ZEPHYR_INCLUDE_NET_HTTP_PARSER_H_
- #define HTTP_PARSER_VERSION_MAJOR 2
- #define HTTP_PARSER_VERSION_MINOR 7
- #define HTTP_PARSER_VERSION_PATCH 1
- #include <sys/types.h>
- #if defined(_WIN32) && !defined(__MINGW32__) && \
- (!defined(_MSC_VER) || _MSC_VER < 1600) && !defined(__WINE__)
- #include <BaseTsd.h>
- #include <stddef.h>
- typedef __int8 int8_t;
- typedef unsigned __int8 uint8_t;
- typedef __int16 int16_t;
- typedef unsigned __int16 uint16_t;
- typedef __int32 int32_t;
- typedef unsigned __int32 uint32_t;
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
- #else
- #include <zephyr/types.h>
- #include <stddef.h>
- #endif
- #include <net/http_parser_state.h>
- #include <net/http_parser_url.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifndef HTTP_MAX_HEADER_SIZE
- # define HTTP_MAX_HEADER_SIZE (80 * 1024)
- #endif
- struct http_parser;
- struct http_parser_settings;
- typedef int (*http_data_cb)(struct http_parser *, const char *at,
- size_t length);
- typedef int (*http_cb)(struct http_parser *);
- enum http_method {
- HTTP_DELETE = 0,
- HTTP_GET = 1,
- HTTP_HEAD = 2,
- HTTP_POST = 3,
- HTTP_PUT = 4,
- HTTP_CONNECT = 5,
- HTTP_OPTIONS = 6,
- HTTP_TRACE = 7,
- HTTP_COPY = 8,
- HTTP_LOCK = 9,
- HTTP_MKCOL = 10,
- HTTP_MOVE = 11,
- HTTP_PROPFIND = 12,
- HTTP_PROPPATCH = 13,
- HTTP_SEARCH = 14,
- HTTP_UNLOCK = 15,
- HTTP_BIND = 16,
- HTTP_REBIND = 17,
- HTTP_UNBIND = 18,
- HTTP_ACL = 19,
- HTTP_REPORT = 20,
- HTTP_MKACTIVITY = 21,
- HTTP_CHECKOUT = 22,
- HTTP_MERGE = 23,
- HTTP_MSEARCH = 24,
- HTTP_NOTIFY = 25,
- HTTP_SUBSCRIBE = 26,
- HTTP_UNSUBSCRIBE = 27,
- HTTP_PATCH = 28,
- HTTP_PURGE = 29,
- HTTP_MKCALENDAR = 30,
- HTTP_LINK = 31,
- HTTP_UNLINK = 32
- };
- enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
- enum flags {
- F_CHUNKED = 1 << 0,
- F_CONNECTION_KEEP_ALIVE = 1 << 1,
- F_CONNECTION_CLOSE = 1 << 2,
- F_CONNECTION_UPGRADE = 1 << 3,
- F_TRAILING = 1 << 4,
- F_UPGRADE = 1 << 5,
- F_SKIPBODY = 1 << 6,
- F_CONTENTLENGTH = 1 << 7
- };
- enum http_errno {
- HPE_OK,
- HPE_CB_message_begin,
- HPE_CB_url,
- HPE_CB_header_field,
- HPE_CB_header_value,
- HPE_CB_headers_complete,
- HPE_CB_body,
- HPE_CB_message_complete,
- HPE_CB_status,
- HPE_CB_chunk_header,
- HPE_CB_chunk_complete,
- HPE_INVALID_EOF_STATE,
- HPE_HEADER_OVERFLOW,
- HPE_CLOSED_CONNECTION,
- HPE_INVALID_VERSION,
- HPE_INVALID_STATUS,
- HPE_INVALID_METHOD,
- HPE_INVALID_URL,
- HPE_INVALID_HOST,
- HPE_INVALID_PORT,
- HPE_INVALID_PATH,
- HPE_INVALID_QUERY_STRING,
- HPE_INVALID_FRAGMENT,
- HPE_LF_EXPECTED,
- HPE_INVALID_HEADER_TOKEN,
- HPE_INVALID_CONTENT_LENGTH,
- HPE_UNEXPECTED_CONTENT_LENGTH,
- HPE_INVALID_CHUNK_SIZE,
- HPE_INVALID_CONSTANT,
- HPE_INVALID_INTERNAL_STATE,
- HPE_STRICT,
- HPE_PAUSED,
- HPE_UNKNOWN
- };
- #define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
- struct http_parser {
-
- unsigned int type : 2;
- unsigned int flags : 8;
- unsigned int state : 7;
- unsigned int header_state : 7;
- unsigned int index : 7;
- unsigned int lenient_http_headers : 1;
- uint32_t nread;
- uint64_t content_length;
-
- unsigned short http_major;
- unsigned short http_minor;
- unsigned int status_code : 16;
- unsigned int method : 8;
- unsigned int http_errno : 7;
-
- unsigned int upgrade : 1;
-
- void *data;
-
- const struct sockaddr *addr;
- };
- struct http_parser_settings {
- http_cb on_message_begin;
- http_data_cb on_url;
- http_data_cb on_status;
- http_data_cb on_header_field;
- http_data_cb on_header_value;
- http_cb on_headers_complete;
- http_data_cb on_body;
- http_cb on_message_complete;
-
- http_cb on_chunk_header;
- http_cb on_chunk_complete;
- };
- unsigned long http_parser_version(void);
- void http_parser_init(struct http_parser *parser, enum http_parser_type type);
- void http_parser_settings_init(struct http_parser_settings *settings);
- size_t http_parser_execute(struct http_parser *parser,
- const struct http_parser_settings *settings,
- const char *data, size_t len);
- int http_should_keep_alive(const struct http_parser *parser);
- const char *http_method_str(enum http_method m);
- const char *http_errno_name(enum http_errno err);
- const char *http_errno_description(enum http_errno err);
- void http_parser_pause(struct http_parser *parser, int paused);
- int http_body_is_final(const struct http_parser *parser);
- #ifdef __cplusplus
- }
- #endif
- #endif
|