Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-http/http_parser/http_parser.h@0:a21b8a29df03, 2021-10-09 (annotated)
- Committer:
- Hiroaki_Okoshi
- Date:
- Sat Oct 09 14:23:23 2021 +0000
- Revision:
- 0:a21b8a29df03
Sample web server via WiFi program. for mbed os 5.15
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Hiroaki_Okoshi | 0:a21b8a29df03 | 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 2 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 4 | * of this software and associated documentation files (the "Software"), to |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 5 | * deal in the Software without restriction, including without limitation the |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 7 | * sell copies of the Software, and to permit persons to whom the Software is |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 8 | * furnished to do so, subject to the following conditions: |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 9 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 10 | * The above copyright notice and this permission notice shall be included in |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 11 | * all copies or substantial portions of the Software. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 12 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 19 | * IN THE SOFTWARE. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 20 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 21 | #ifndef http_parser_h |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 22 | #define http_parser_h |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 23 | #ifdef __cplusplus |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 24 | extern "C" { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 25 | #endif |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 26 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 27 | /* Also update SONAME in the Makefile whenever you change these. */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 28 | #define HTTP_PARSER_VERSION_MAJOR 2 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 29 | #define HTTP_PARSER_VERSION_MINOR 7 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 30 | #define HTTP_PARSER_VERSION_PATCH 1 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 31 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 32 | typedef unsigned int size_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 33 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 34 | #if defined(_WIN32) && !defined(__MINGW32__) && \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 35 | (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 36 | #include <BaseTsd.h> |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 37 | #include <stddef.h> |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 38 | typedef __int8 int8_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 39 | typedef unsigned __int8 uint8_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 40 | typedef __int16 int16_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 41 | typedef unsigned __int16 uint16_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 42 | typedef __int32 int32_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 43 | typedef unsigned __int32 uint32_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 44 | typedef __int64 int64_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 45 | typedef unsigned __int64 uint64_t; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 46 | #else |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 47 | #include <stdint.h> |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 48 | #endif |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 49 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 50 | /* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 51 | * faster |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 52 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 53 | #ifndef HTTP_PARSER_STRICT |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 54 | # define HTTP_PARSER_STRICT 1 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 55 | #endif |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 56 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 57 | /* Maximium header size allowed. If the macro is not defined |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 58 | * before including this header then the default is used. To |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 59 | * change the maximum header size, define the macro in the build |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 60 | * environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 61 | * the effective limit on the size of the header, define the macro |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 62 | * to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 63 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 64 | #ifndef HTTP_MAX_HEADER_SIZE |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 65 | # define HTTP_MAX_HEADER_SIZE (80*1024) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 66 | #endif |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 67 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 68 | typedef struct http_parser http_parser; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 69 | typedef struct http_parser_settings http_parser_settings; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 70 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 71 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 72 | /* Callbacks should return non-zero to indicate an error. The parser will |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 73 | * then halt execution. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 74 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 75 | * The one exception is on_headers_complete. In a HTTP_RESPONSE parser |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 76 | * returning '1' from on_headers_complete will tell the parser that it |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 77 | * should not expect a body. This is used when receiving a response to a |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 78 | * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding: |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 79 | * chunked' headers that indicate the presence of a body. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 80 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 81 | * Returning `2` from on_headers_complete will tell parser that it should not |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 82 | * expect neither a body nor any futher responses on this connection. This is |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 83 | * useful for handling responses to a CONNECT request which may not contain |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 84 | * `Upgrade` or `Connection: upgrade` headers. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 85 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 86 | * http_data_cb does not return data chunks. It will be called arbitrarily |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 87 | * many times for each string. E.G. you might get 10 callbacks for "on_url" |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 88 | * each providing just a few characters more data. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 89 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 90 | typedef int (*http_data_cb) (http_parser*, const char *at, size_t length); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 91 | typedef int (*http_cb) (http_parser*); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 92 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 93 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 94 | /* Status Codes */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 95 | #define HTTP_STATUS_MAP(XX) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 96 | XX(100, CONTINUE, Continue) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 97 | XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 98 | XX(102, PROCESSING, Processing) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 99 | XX(200, OK, OK) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 100 | XX(201, CREATED, Created) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 101 | XX(202, ACCEPTED, Accepted) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 102 | XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 103 | XX(204, NO_CONTENT, No Content) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 104 | XX(205, RESET_CONTENT, Reset Content) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 105 | XX(206, PARTIAL_CONTENT, Partial Content) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 106 | XX(207, MULTI_STATUS, Multi-Status) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 107 | XX(208, ALREADY_REPORTED, Already Reported) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 108 | XX(226, IM_USED, IM Used) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 109 | XX(300, MULTIPLE_CHOICES, Multiple Choices) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 110 | XX(301, MOVED_PERMANENTLY, Moved Permanently) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 111 | XX(302, FOUND, Found) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 112 | XX(303, SEE_OTHER, See Other) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 113 | XX(304, NOT_MODIFIED, Not Modified) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 114 | XX(305, USE_PROXY, Use Proxy) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 115 | XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 116 | XX(308, PERMANENT_REDIRECT, Permanent Redirect) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 117 | XX(400, BAD_REQUEST, Bad Request) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 118 | XX(401, UNAUTHORIZED, Unauthorized) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 119 | XX(402, PAYMENT_REQUIRED, Payment Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 120 | XX(403, FORBIDDEN, Forbidden) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 121 | XX(404, NOT_FOUND, Not Found) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 122 | XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 123 | XX(406, NOT_ACCEPTABLE, Not Acceptable) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 124 | XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 125 | XX(408, REQUEST_TIMEOUT, Request Timeout) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 126 | XX(409, CONFLICT, Conflict) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 127 | XX(410, GONE, Gone) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 128 | XX(411, LENGTH_REQUIRED, Length Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 129 | XX(412, PRECONDITION_FAILED, Precondition Failed) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 130 | XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 131 | XX(414, URI_TOO_LONG, URI Too Long) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 132 | XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 133 | XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 134 | XX(417, EXPECTATION_FAILED, Expectation Failed) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 135 | XX(421, MISDIRECTED_REQUEST, Misdirected Request) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 136 | XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 137 | XX(423, LOCKED, Locked) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 138 | XX(424, FAILED_DEPENDENCY, Failed Dependency) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 139 | XX(426, UPGRADE_REQUIRED, Upgrade Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 140 | XX(428, PRECONDITION_REQUIRED, Precondition Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 141 | XX(429, TOO_MANY_REQUESTS, Too Many Requests) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 142 | XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 143 | XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 144 | XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 145 | XX(501, NOT_IMPLEMENTED, Not Implemented) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 146 | XX(502, BAD_GATEWAY, Bad Gateway) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 147 | XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 148 | XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 149 | XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 150 | XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 151 | XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 152 | XX(508, LOOP_DETECTED, Loop Detected) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 153 | XX(510, NOT_EXTENDED, Not Extended) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 154 | XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 155 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 156 | enum http_status |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 157 | { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 158 | #define XX(num, name, string) HTTP_STATUS_##name = num, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 159 | HTTP_STATUS_MAP(XX) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 160 | #undef XX |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 161 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 162 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 163 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 164 | /* Request Methods */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 165 | #define HTTP_METHOD_MAP(XX) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 166 | XX(0, DELETE, DELETE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 167 | XX(1, GET, GET) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 168 | XX(2, HEAD, HEAD) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 169 | XX(3, POST, POST) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 170 | XX(4, PUT, PUT) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 171 | /* pathological */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 172 | XX(5, CONNECT, CONNECT) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 173 | XX(6, OPTIONS, OPTIONS) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 174 | XX(7, TRACE, TRACE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 175 | /* WebDAV */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 176 | XX(8, COPY, COPY) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 177 | XX(9, LOCK, LOCK) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 178 | XX(10, MKCOL, MKCOL) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 179 | XX(11, MOVE, MOVE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 180 | XX(12, PROPFIND, PROPFIND) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 181 | XX(13, PROPPATCH, PROPPATCH) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 182 | XX(14, SEARCH, SEARCH) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 183 | XX(15, UNLOCK, UNLOCK) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 184 | XX(16, BIND, BIND) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 185 | XX(17, REBIND, REBIND) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 186 | XX(18, UNBIND, UNBIND) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 187 | XX(19, ACL, ACL) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 188 | /* subversion */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 189 | XX(20, REPORT, REPORT) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 190 | XX(21, MKACTIVITY, MKACTIVITY) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 191 | XX(22, CHECKOUT, CHECKOUT) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 192 | XX(23, MERGE, MERGE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 193 | /* upnp */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 194 | XX(24, MSEARCH, M-SEARCH) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 195 | XX(25, NOTIFY, NOTIFY) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 196 | XX(26, SUBSCRIBE, SUBSCRIBE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 197 | XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 198 | /* RFC-5789 */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 199 | XX(28, PATCH, PATCH) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 200 | XX(29, PURGE, PURGE) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 201 | /* CalDAV */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 202 | XX(30, MKCALENDAR, MKCALENDAR) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 203 | /* RFC-2068, section 19.6.1.2 */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 204 | XX(31, LINK, LINK) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 205 | XX(32, UNLINK, UNLINK) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 206 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 207 | enum http_method |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 208 | { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 209 | #define XX(num, name, string) HTTP_##name = num, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 210 | HTTP_METHOD_MAP(XX) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 211 | #undef XX |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 212 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 213 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 214 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 215 | enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 216 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 217 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 218 | /* Flag values for http_parser.flags field */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 219 | enum flags |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 220 | { F_CHUNKED = 1 << 0 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 221 | , F_CONNECTION_KEEP_ALIVE = 1 << 1 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 222 | , F_CONNECTION_CLOSE = 1 << 2 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 223 | , F_CONNECTION_UPGRADE = 1 << 3 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 224 | , F_TRAILING = 1 << 4 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 225 | , F_UPGRADE = 1 << 5 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 226 | , F_SKIPBODY = 1 << 6 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 227 | , F_CONTENTLENGTH = 1 << 7 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 228 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 229 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 230 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 231 | /* Map for errno-related constants |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 232 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 233 | * The provided argument should be a macro that takes 2 arguments. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 234 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 235 | #define HTTP_ERRNO_MAP(XX) \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 236 | /* No error */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 237 | XX(OK, "success") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 238 | \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 239 | /* Callback-related errors */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 240 | XX(CB_message_begin, "the on_message_begin callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 241 | XX(CB_url, "the on_url callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 242 | XX(CB_header_field, "the on_header_field callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 243 | XX(CB_header_value, "the on_header_value callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 244 | XX(CB_headers_complete, "the on_headers_complete callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 245 | XX(CB_body, "the on_body callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 246 | XX(CB_message_complete, "the on_message_complete callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 247 | XX(CB_status, "the on_status callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 248 | XX(CB_chunk_header, "the on_chunk_header callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 249 | XX(CB_chunk_complete, "the on_chunk_complete callback failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 250 | \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 251 | /* Parsing-related errors */ \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 252 | XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 253 | XX(HEADER_OVERFLOW, \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 254 | "too many header bytes seen; overflow detected") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 255 | XX(CLOSED_CONNECTION, \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 256 | "data received after completed connection: close message") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 257 | XX(INVALID_VERSION, "invalid HTTP version") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 258 | XX(INVALID_STATUS, "invalid HTTP status code") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 259 | XX(INVALID_METHOD, "invalid HTTP method") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 260 | XX(INVALID_URL, "invalid URL") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 261 | XX(INVALID_HOST, "invalid host") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 262 | XX(INVALID_PORT, "invalid port") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 263 | XX(INVALID_PATH, "invalid path") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 264 | XX(INVALID_QUERY_STRING, "invalid query string") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 265 | XX(INVALID_FRAGMENT, "invalid fragment") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 266 | XX(LF_EXPECTED, "LF character expected") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 267 | XX(INVALID_HEADER_TOKEN, "invalid character in header") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 268 | XX(INVALID_CONTENT_LENGTH, \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 269 | "invalid character in content-length header") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 270 | XX(UNEXPECTED_CONTENT_LENGTH, \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 271 | "unexpected content-length header") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 272 | XX(INVALID_CHUNK_SIZE, \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 273 | "invalid character in chunk size header") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 274 | XX(INVALID_CONSTANT, "invalid constant string") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 275 | XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 276 | XX(STRICT, "strict mode assertion failed") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 277 | XX(PAUSED, "parser is paused") \ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 278 | XX(UNKNOWN, "an unknown error occurred") |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 279 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 280 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 281 | /* Define HPE_* values for each errno value above */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 282 | #define HTTP_ERRNO_GEN(n, s) HPE_##n, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 283 | enum http_errno { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 284 | HTTP_ERRNO_MAP(HTTP_ERRNO_GEN) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 285 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 286 | #undef HTTP_ERRNO_GEN |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 287 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 288 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 289 | /* Get an http_errno value from an http_parser */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 290 | #define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno) |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 291 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 292 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 293 | struct http_parser { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 294 | /** PRIVATE **/ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 295 | unsigned int type : 2; /* enum http_parser_type */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 296 | unsigned int flags : 8; /* F_* values from 'flags' enum; semi-public */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 297 | unsigned int state : 7; /* enum state from http_parser.c */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 298 | unsigned int header_state : 7; /* enum header_state from http_parser.c */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 299 | unsigned int index : 7; /* index into current matcher */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 300 | unsigned int lenient_http_headers : 1; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 301 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 302 | uint32_t nread; /* # bytes read in various scenarios */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 303 | uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 304 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 305 | /** READ-ONLY **/ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 306 | unsigned short http_major; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 307 | unsigned short http_minor; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 308 | unsigned int status_code : 16; /* responses only */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 309 | unsigned int method : 8; /* requests only */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 310 | unsigned int http_errno : 7; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 311 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 312 | /* 1 = Upgrade header was present and the parser has exited because of that. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 313 | * 0 = No upgrade header present. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 314 | * Should be checked when http_parser_execute() returns in addition to |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 315 | * error checking. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 316 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 317 | unsigned int upgrade : 1; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 318 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 319 | /** PUBLIC **/ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 320 | void *data; /* A pointer to get hook to the "connection" or "socket" object */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 321 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 322 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 323 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 324 | struct http_parser_settings { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 325 | http_cb on_message_begin; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 326 | http_data_cb on_url; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 327 | http_data_cb on_status; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 328 | http_data_cb on_header_field; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 329 | http_data_cb on_header_value; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 330 | http_cb on_headers_complete; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 331 | http_data_cb on_body; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 332 | http_cb on_message_complete; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 333 | /* When on_chunk_header is called, the current chunk length is stored |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 334 | * in parser->content_length. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 335 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 336 | http_cb on_chunk_header; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 337 | http_cb on_chunk_complete; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 338 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 339 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 340 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 341 | enum http_parser_url_fields |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 342 | { UF_SCHEMA = 0 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 343 | , UF_HOST = 1 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 344 | , UF_PORT = 2 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 345 | , UF_PATH = 3 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 346 | , UF_QUERY = 4 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 347 | , UF_FRAGMENT = 5 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 348 | , UF_USERINFO = 6 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 349 | , UF_MAX = 7 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 350 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 351 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 352 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 353 | /* Result structure for http_parser_parse_url(). |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 354 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 355 | * Callers should index into field_data[] with UF_* values iff field_set |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 356 | * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 357 | * because we probably have padding left over), we convert any port to |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 358 | * a uint16_t. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 359 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 360 | struct http_parser_url { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 361 | uint16_t field_set; /* Bitmask of (1 << UF_*) values */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 362 | uint16_t port; /* Converted UF_PORT string */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 363 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 364 | struct { |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 365 | uint16_t off; /* Offset into buffer in which field starts */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 366 | uint16_t len; /* Length of run in buffer */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 367 | } field_data[UF_MAX]; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 368 | }; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 369 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 370 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 371 | /* Returns the library version. Bits 16-23 contain the major version number, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 372 | * bits 8-15 the minor version number and bits 0-7 the patch level. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 373 | * Usage example: |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 374 | * |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 375 | * unsigned long version = http_parser_version(); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 376 | * unsigned major = (version >> 16) & 255; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 377 | * unsigned minor = (version >> 8) & 255; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 378 | * unsigned patch = version & 255; |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 379 | * printf("http_parser v%u.%u.%u\n", major, minor, patch); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 380 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 381 | unsigned long http_parser_version(void); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 382 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 383 | void http_parser_init(http_parser *parser, enum http_parser_type type); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 384 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 385 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 386 | /* Initialize http_parser_settings members to 0 |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 387 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 388 | void http_parser_settings_init(http_parser_settings *settings); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 389 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 390 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 391 | /* Executes the parser. Returns number of parsed bytes. Sets |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 392 | * `parser->http_errno` on error. */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 393 | size_t http_parser_execute(http_parser *parser, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 394 | const http_parser_settings *settings, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 395 | const char *data, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 396 | size_t len); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 397 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 398 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 399 | /* If http_should_keep_alive() in the on_headers_complete or |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 400 | * on_message_complete callback returns 0, then this should be |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 401 | * the last message on the connection. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 402 | * If you are the server, respond with the "Connection: close" header. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 403 | * If you are the client, close the connection. |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 404 | */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 405 | int http_should_keep_alive(const http_parser *parser); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 406 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 407 | /* Returns a string version of the HTTP method. */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 408 | const char *http_method_str(enum http_method m); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 409 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 410 | /* Return a string name of the given error */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 411 | const char *http_errno_name(enum http_errno err); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 412 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 413 | /* Return a string description of the given error */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 414 | const char *http_errno_description(enum http_errno err); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 415 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 416 | /* Initialize all http_parser_url members to 0 */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 417 | void http_parser_url_init(struct http_parser_url *u); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 418 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 419 | /* Parse a URL; return nonzero on failure */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 420 | int http_parser_parse_url(const char *buf, size_t buflen, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 421 | int is_connect, |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 422 | struct http_parser_url *u); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 423 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 424 | /* Pause or un-pause the parser; a nonzero value pauses */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 425 | void http_parser_pause(http_parser *parser, int paused); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 426 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 427 | /* Checks if this is the final chunk of the body. */ |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 428 | int http_body_is_final(const http_parser *parser); |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 429 | |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 430 | #ifdef __cplusplus |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 431 | } |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 432 | #endif |
| Hiroaki_Okoshi | 0:a21b8a29df03 | 433 | #endif |