1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
From: Per Andersson <avtobiff@gmail.com>
Date: Mon, 17 Jun 2013 02:09:37 +0200
Subject: Build with system libhttp-parser
---
ext/ruby_http_parser/extconf.rb | 37 +++++++++++++++++----------------
ext/ruby_http_parser/ruby_http_parser.c | 28 ++++++++++++-------------
2 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/ext/ruby_http_parser/extconf.rb b/ext/ruby_http_parser/extconf.rb
index d2f6e51..1d5ad3d 100644
--- a/ext/ruby_http_parser/extconf.rb
+++ b/ext/ruby_http_parser/extconf.rb
@@ -1,24 +1,25 @@
require 'mkmf'
-# check out code if it hasn't been already
-if Dir[File.expand_path('../vendor/http-parser/*', __FILE__)].empty?
- Dir.chdir(File.expand_path('../../../', __FILE__)) do
- xsystem 'git submodule init'
- xsystem 'git submodule update'
- end
-end
+## check out code if it hasn't been already
+#if Dir[File.expand_path('../vendor/http-parser/*', __FILE__)].empty?
+# Dir.chdir(File.expand_path('../../../', __FILE__)) do
+# xsystem 'git submodule init'
+# xsystem 'git submodule update'
+# end
+#end
-# mongrel and http-parser both define http_parser_(init|execute), so we
-# rename functions in http-parser before using them.
-vendor_dir = File.expand_path('../vendor/http-parser/', __FILE__)
-src_dir = File.expand_path('../', __FILE__)
-%w[ http_parser.c http_parser.h ].each do |file|
- File.open(File.join(src_dir, "ryah_#{file}"), 'w'){ |f|
- f.write File.read(File.join(vendor_dir, file)).gsub('http_parser', 'ryah_http_parser')
- }
-end
+## mongrel and http-parser both define http_parser_(init|execute), so we
+## rename functions in http-parser before using them.
+#vendor_dir = File.expand_path('../vendor/http-parser/', __FILE__)
+#src_dir = File.expand_path('../', __FILE__)
+#%w[ http_parser.c http_parser.h ].each do |file|
+# File.open(File.join(src_dir, "ryah_#{file}"), 'w'){ |f|
+# f.write File.read(File.join(vendor_dir, file)).gsub('http_parser', 'ryah_http_parser')
+# }
+#end
-$CFLAGS << " -I#{src_dir}"
+#$CFLAGS << " -I#{src_dir}"
+$LDFLAGS << " -lhttp_parser"
-dir_config("ruby_http_parser")
+dir_config("ruby_http_parser", '/usr/include', '/usr/lib/http-parser')
create_makefile("ruby_http_parser")
diff --git a/ext/ruby_http_parser/ruby_http_parser.c b/ext/ruby_http_parser/ruby_http_parser.c
index 5650652..3a447f5 100644
--- a/ext/ruby_http_parser/ruby_http_parser.c
+++ b/ext/ruby_http_parser/ruby_http_parser.c
@@ -1,6 +1,6 @@
#include "ruby.h"
#include "ext_help.h"
-#include "ryah_http_parser.h"
+#include "http_parser.h"
#define GET_WRAPPER(N, from) ParserWrapper *N = (ParserWrapper *)(from)->data;
#define HASH_CAT(h, k, ptr, len) \
@@ -14,7 +14,7 @@
} while(0)
typedef struct ParserWrapper {
- ryah_http_parser parser;
+ http_parser parser;
VALUE request_url;
@@ -36,11 +36,11 @@ typedef struct ParserWrapper {
VALUE last_field_name;
VALUE curr_field_name;
- enum ryah_http_parser_type type;
+ enum http_parser_type type;
} ParserWrapper;
void ParserWrapper_init(ParserWrapper *wrapper) {
- ryah_http_parser_init(&wrapper->parser, wrapper->type);
+ http_parser_init(&wrapper->parser, wrapper->type);
wrapper->parser.status_code = 0;
wrapper->parser.http_major = 0;
wrapper->parser.http_minor = 0;
@@ -98,7 +98,7 @@ static VALUE Smixed;
/** Callbacks **/
-int on_message_begin(ryah_http_parser *parser) {
+int on_message_begin(http_parser *parser) {
GET_WRAPPER(wrapper, parser);
wrapper->request_url = rb_str_new2("");
@@ -121,13 +121,13 @@ int on_message_begin(ryah_http_parser *parser) {
}
}
-int on_url(ryah_http_parser *parser, const char *at, size_t length) {
+int on_url(http_parser *parser, const char *at, size_t length) {
GET_WRAPPER(wrapper, parser);
rb_str_cat(wrapper->request_url, at, length);
return 0;
}
-int on_header_field(ryah_http_parser *parser, const char *at, size_t length) {
+int on_header_field(http_parser *parser, const char *at, size_t length) {
GET_WRAPPER(wrapper, parser);
if (wrapper->curr_field_name == Qnil) {
@@ -140,7 +140,7 @@ int on_header_field(ryah_http_parser *parser, const char *at, size_t length) {
return 0;
}
-int on_header_value(ryah_http_parser *parser, const char *at, size_t length) {
+int on_header_value(http_parser *parser, const char *at, size_t length) {
GET_WRAPPER(wrapper, parser);
int new_field = 0;
@@ -186,7 +186,7 @@ int on_header_value(ryah_http_parser *parser, const char *at, size_t length) {
return 0;
}
-int on_headers_complete(ryah_http_parser *parser) {
+int on_headers_complete(http_parser *parser) {
GET_WRAPPER(wrapper, parser);
VALUE ret = Qnil;
@@ -207,7 +207,7 @@ int on_headers_complete(ryah_http_parser *parser) {
}
}
-int on_body(ryah_http_parser *parser, const char *at, size_t length) {
+int on_body(http_parser *parser, const char *at, size_t length) {
GET_WRAPPER(wrapper, parser);
VALUE ret = Qnil;
@@ -226,7 +226,7 @@ int on_body(ryah_http_parser *parser, const char *at, size_t length) {
}
}
-int on_message_complete(ryah_http_parser *parser) {
+int on_message_complete(http_parser *parser) {
GET_WRAPPER(wrapper, parser);
VALUE ret = Qnil;
@@ -246,7 +246,7 @@ int on_message_complete(ryah_http_parser *parser) {
}
}
-static ryah_http_parser_settings settings = {
+static http_parser_settings settings = {
.on_message_begin = on_message_begin,
.on_url = on_url,
.on_header_field = on_header_field,
@@ -256,7 +256,7 @@ static ryah_http_parser_settings settings = {
.on_message_complete = on_message_complete
};
-VALUE Parser_alloc_by_type(VALUE klass, enum ryah_http_parser_type type) {
+VALUE Parser_alloc_by_type(VALUE klass, enum http_parser_type type) {
ParserWrapper *wrapper = ALLOC_N(ParserWrapper, 1);
wrapper->type = type;
wrapper->parser.data = wrapper;
@@ -317,7 +317,7 @@ VALUE Parser_execute(VALUE self, VALUE data) {
DATA_GET(self, ParserWrapper, wrapper);
wrapper->stopped = Qfalse;
- size_t nparsed = ryah_http_parser_execute(&wrapper->parser, &settings, ptr, len);
+ size_t nparsed = http_parser_execute(&wrapper->parser, &settings, ptr, len);
if (wrapper->parser.upgrade) {
if (RTEST(wrapper->stopped))
|