1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to 5 * deal in the Software without restriction, including without limitation the 6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 * sell copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 * IN THE SOFTWARE. 20 */ 21 #ifndef url_parser_h 22 #define url_parser_h 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Also update SONAME in the Makefile whenever you change these. */ 28 #define HTTP_PARSER_VERSION_MAJOR 2 29 #define HTTP_PARSER_VERSION_MINOR 9 30 #define HTTP_PARSER_VERSION_PATCH 1 31 32 #include <stddef.h> 33 #if defined(_WIN32) && !defined(__MINGW32__) && \ 34 (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__) 35 #include <BaseTsd.h> 36 typedef __int8 int8_t; 37 typedef unsigned __int8 uint8_t; 38 typedef __int16 int16_t; 39 typedef unsigned __int16 uint16_t; 40 typedef __int32 int32_t; 41 typedef unsigned __int32 uint32_t; 42 typedef __int64 int64_t; 43 typedef unsigned __int64 uint64_t; 44 #else 45 #include <stdint.h> 46 #endif 47 48 /* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run 49 * faster 50 */ 51 #ifndef HTTP_PARSER_STRICT 52 # define HTTP_PARSER_STRICT 1 53 #endif 54 55 enum http_parser_url_fields 56 { UF_SCHEMA = 0 57 , UF_HOST = 1 58 , UF_PORT = 2 59 , UF_PATH = 3 60 , UF_QUERY = 4 61 , UF_FRAGMENT = 5 62 , UF_USERINFO = 6 63 , UF_MAX = 7 64 }; 65 66 67 /* Result structure for http_parser_parse_url(). 68 * 69 * Callers should index into field_data[] with UF_* values iff field_set 70 * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and 71 * because we probably have padding left over), we convert any port to 72 * a uint16_t. 73 */ 74 struct http_parser_url { 75 uint16_t field_set; /* Bitmask of (1 << UF_*) values */ 76 uint16_t port; /* Converted UF_PORT string */ 77 78 struct { 79 uint16_t off; /* Offset into buffer in which field starts */ 80 uint16_t len; /* Length of run in buffer */ 81 } field_data[UF_MAX]; 82 }; 83 84 /* Initialize all http_parser_url members to 0 */ 85 void http_parser_url_init(struct http_parser_url *u); 86 87 /* Parse a URL; return nonzero on failure */ 88 int http_parser_parse_url(const char *buf, size_t buflen, 89 int is_connect, 90 struct http_parser_url *u); 91 #ifdef __cplusplus 92 } 93 #endif 94 #endif 95