summaryrefslogtreecommitdiff
path: root/ext/http-parser/contrib
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-27 13:54:59 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-27 13:54:59 -0400
commite6e825da706f6a59e597aac7ab65b846ea3a7fd4 (patch)
treee55018b0c5dbcc7a84d2942ec2a10bca3a269e99 /ext/http-parser/contrib
parent917b95a1d688904ed0ca34b96fafc0849867d9fb (diff)
downloadinfinitytier-e6e825da706f6a59e597aac7ab65b846ea3a7fd4.tar.gz
infinitytier-e6e825da706f6a59e597aac7ab65b846ea3a7fd4.zip
Get rid of built-in HTTP. If we do HTTP it will probably be via libcurl to support HTTPS and chunking and other complexities.
Diffstat (limited to 'ext/http-parser/contrib')
-rw-r--r--ext/http-parser/contrib/parsertrace.c156
-rw-r--r--ext/http-parser/contrib/url_parser.c44
2 files changed, 0 insertions, 200 deletions
diff --git a/ext/http-parser/contrib/parsertrace.c b/ext/http-parser/contrib/parsertrace.c
deleted file mode 100644
index c9bc71ec..00000000
--- a/ext/http-parser/contrib/parsertrace.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev
- *
- * Additional changes are licensed under the same terms as NGINX and
- * copyright Joyent, Inc. and other Node contributors. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/* Dump what the parser finds to stdout as it happen */
-
-#include "http_parser.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int on_message_begin(http_parser* _) {
- (void)_;
- printf("\n***MESSAGE BEGIN***\n\n");
- return 0;
-}
-
-int on_headers_complete(http_parser* _) {
- (void)_;
- printf("\n***HEADERS COMPLETE***\n\n");
- return 0;
-}
-
-int on_message_complete(http_parser* _) {
- (void)_;
- printf("\n***MESSAGE COMPLETE***\n\n");
- return 0;
-}
-
-int on_url(http_parser* _, const char* at, size_t length) {
- (void)_;
- printf("Url: %.*s\n", (int)length, at);
- return 0;
-}
-
-int on_header_field(http_parser* _, const char* at, size_t length) {
- (void)_;
- printf("Header field: %.*s\n", (int)length, at);
- return 0;
-}
-
-int on_header_value(http_parser* _, const char* at, size_t length) {
- (void)_;
- printf("Header value: %.*s\n", (int)length, at);
- return 0;
-}
-
-int on_body(http_parser* _, const char* at, size_t length) {
- (void)_;
- printf("Body: %.*s\n", (int)length, at);
- return 0;
-}
-
-void usage(const char* name) {
- fprintf(stderr,
- "Usage: %s $type $filename\n"
- " type: -x, where x is one of {r,b,q}\n"
- " parses file as a Response, reQuest, or Both\n",
- name);
- exit(EXIT_FAILURE);
-}
-
-int main(int argc, char* argv[]) {
- enum http_parser_type file_type;
-
- if (argc != 3) {
- usage(argv[0]);
- }
-
- char* type = argv[1];
- if (type[0] != '-') {
- usage(argv[0]);
- }
-
- switch (type[1]) {
- /* in the case of "-", type[1] will be NUL */
- case 'r':
- file_type = HTTP_RESPONSE;
- break;
- case 'q':
- file_type = HTTP_REQUEST;
- break;
- case 'b':
- file_type = HTTP_BOTH;
- break;
- default:
- usage(argv[0]);
- }
-
- char* filename = argv[2];
- FILE* file = fopen(filename, "r");
- if (file == NULL) {
- perror("fopen");
- return EXIT_FAILURE;
- }
-
- fseek(file, 0, SEEK_END);
- long file_length = ftell(file);
- if (file_length == -1) {
- perror("ftell");
- return EXIT_FAILURE;
- }
- fseek(file, 0, SEEK_SET);
-
- char* data = malloc(file_length);
- if (fread(data, 1, file_length, file) != (size_t)file_length) {
- fprintf(stderr, "couldn't read entire file\n");
- free(data);
- return EXIT_FAILURE;
- }
-
- http_parser_settings settings;
- memset(&settings, 0, sizeof(settings));
- settings.on_message_begin = on_message_begin;
- settings.on_url = on_url;
- settings.on_header_field = on_header_field;
- settings.on_header_value = on_header_value;
- settings.on_headers_complete = on_headers_complete;
- settings.on_body = on_body;
- settings.on_message_complete = on_message_complete;
-
- http_parser parser;
- http_parser_init(&parser, file_type);
- size_t nparsed = http_parser_execute(&parser, &settings, data, file_length);
- free(data);
-
- if (nparsed != (size_t)file_length) {
- fprintf(stderr,
- "Error: %s (%s)\n",
- http_errno_description(HTTP_PARSER_ERRNO(&parser)),
- http_errno_name(HTTP_PARSER_ERRNO(&parser)));
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/ext/http-parser/contrib/url_parser.c b/ext/http-parser/contrib/url_parser.c
deleted file mode 100644
index b1f9c979..00000000
--- a/ext/http-parser/contrib/url_parser.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "http_parser.h"
-#include <stdio.h>
-#include <string.h>
-
-void
-dump_url (const char *url, const struct http_parser_url *u)
-{
- unsigned int i;
-
- printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
- for (i = 0; i < UF_MAX; i++) {
- if ((u->field_set & (1 << i)) == 0) {
- printf("\tfield_data[%u]: unset\n", i);
- continue;
- }
-
- printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
- i,
- u->field_data[i].off,
- u->field_data[i].len,
- u->field_data[i].len,
- url + u->field_data[i].off);
- }
-}
-
-int main(int argc, char ** argv) {
- if (argc != 3) {
- printf("Syntax : %s connect|get url\n", argv[0]);
- return 1;
- }
- struct http_parser_url u;
- int len = strlen(argv[2]);
- int connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
- printf("Parsing %s, connect %d\n", argv[2], connect);
-
- int result = http_parser_parse_url(argv[2], len, connect, &u);
- if (result != 0) {
- printf("Parse error : %d\n", result);
- return result;
- }
- printf("Parse ok, result : \n");
- dump_url(argv[2], &u);
- return 0;
-} \ No newline at end of file