noderb-http 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
1
  require "mkmf"
2
2
 
3
+ $CFLAGS = CONFIG['CFLAGS'] = " -fPIC -shared "
4
+
3
5
  create_makefile("noderb_http_extension")
@@ -1,73 +1,62 @@
1
1
  #include <noderb_http.h>
2
2
 
3
3
  typedef struct {
4
- long parser;
4
+ VALUE parser;
5
5
  int pre_headers;
6
6
  } nodeRb_http;
7
7
 
8
8
  VALUE nodeRbHttpParser;
9
9
  VALUE nodeRbHttpPointer;
10
10
 
11
- VALUE nodeRb_get_object_from_id(long id) {
12
- return rb_funcall(rb_const_get(rb_cObject, rb_intern("ObjectSpace")), rb_intern("_id2ref"), 1, rb_int2inum(id));
13
- }
14
-
15
11
  int nodeRb_http_on_message_begin(http_parser* parser) {
16
12
  nodeRb_http* client = parser->data;
17
- VALUE self = nodeRb_get_object_from_id(client->parser);
18
- rb_funcall(self, rb_intern("on_message_begin"), 0);
13
+ rb_funcall(client->parser, rb_intern("on_message_begin"), 0);
19
14
  return 0;
20
15
  }
21
16
 
22
17
  int nodeRb_http_on_url(http_parser* parser, const char *buf, size_t len) {
23
18
  nodeRb_http* client = parser->data;
24
- VALUE self = nodeRb_get_object_from_id(client->parser);
25
19
  if(parser->type == HTTP_REQUEST){
26
- rb_funcall(self, rb_intern("on_method"), 1, rb_str_new2(http_method_str(parser->method)));
20
+ rb_funcall(client->parser, rb_intern("on_method"), 1, rb_str_new2(http_method_str(parser->method)));
27
21
  }
28
- rb_funcall(self, rb_intern("on_url"), 1, rb_str_new(buf, len));
22
+ rb_funcall(client->parser, rb_intern("on_url"), 1, rb_str_new(buf, len));
29
23
  return 0;
30
24
  }
31
25
 
32
26
  int nodeRb_http_on_header_field(http_parser* parser, const char *buf, size_t len) {
33
27
  nodeRb_http* client = parser->data;
34
- VALUE self = nodeRb_get_object_from_id(client->parser);
35
- rb_funcall(self, rb_intern("on_header_field"), 1, rb_str_new(buf, len));
28
+ rb_funcall(client->parser, rb_intern("on_header_field"), 1, rb_str_new(buf, len));
36
29
  return 0;
37
30
  }
38
31
 
39
32
  int nodeRb_http_on_header_value(http_parser* parser, const char *buf, size_t len) {
40
33
  nodeRb_http* client = parser->data;
41
- VALUE self = nodeRb_get_object_from_id(client->parser);
42
- rb_funcall(self, rb_intern("on_header_value"), 1, rb_str_new(buf, len));
34
+ rb_funcall(client->parser, rb_intern("on_header_value"), 1, rb_str_new(buf, len));
43
35
  return 0;
44
36
  }
45
37
 
46
38
  int nodeRb_http_on_headers_complete(http_parser* parser) {
47
39
  nodeRb_http* client = parser->data;
48
- VALUE self = nodeRb_get_object_from_id(client->parser);
49
- rb_funcall(self, rb_intern("on_version"), 2, rb_int2inum(parser->http_major), rb_int2inum(parser->http_minor));
40
+ rb_funcall(client->parser, rb_intern("on_version"), 2, rb_int2inum(parser->http_major), rb_int2inum(parser->http_minor));
50
41
  if(parser->type == HTTP_RESPONSE){
51
- rb_funcall(self, rb_intern("on_status_code"), 1, rb_int2inum(parser->status_code));
42
+ rb_funcall(client->parser, rb_intern("on_status_code"), 1, rb_int2inum(parser->status_code));
52
43
  }
53
44
  if (http_should_keep_alive(parser)) {
54
- rb_funcall(self, rb_intern("on_keep_alive"), 1, Qtrue);
45
+ rb_funcall(client->parser, rb_intern("on_keep_alive"), 1, Qtrue);
55
46
  }
56
- rb_funcall(self, rb_intern("on_headers_complete"), 0);
47
+ rb_funcall(client->parser, rb_intern("on_headers_complete"), 0);
57
48
  return 0;
58
49
  }
59
50
 
60
51
  int nodeRb_http_on_body(http_parser* parser, const char *buf, size_t len) {
61
52
  nodeRb_http* client = parser->data;
62
- VALUE self = nodeRb_get_object_from_id(client->parser);
63
- rb_funcall(self, rb_intern("on_body"), 1, rb_str_new(buf, len));
53
+ rb_funcall(client->parser, rb_intern("on_body"), 1, rb_str_new(buf, len));
64
54
  return 0;
65
55
  }
66
56
 
67
57
  int nodeRb_http_on_message_complete(http_parser* parser) {
68
58
  nodeRb_http* client = parser->data;
69
- VALUE self = nodeRb_get_object_from_id(client->parser);
70
- rb_funcall(self, rb_intern("on_message_complete"), 0);
59
+ rb_funcall(client->parser, rb_intern("on_message_complete"), 0);
71
60
  return 0;
72
61
  }
73
62
 
@@ -96,12 +85,13 @@ VALUE nodeRb_http_setup(VALUE self, VALUE type) {
96
85
  }
97
86
 
98
87
  nodeRb_http* client = malloc(sizeof (nodeRb_http));
88
+ client->parser = self;
99
89
  parser->data = client;
100
90
 
101
- client->parser = rb_num2long(rb_obj_id(self));
102
-
103
- rb_iv_set(self, "@settings", Data_Wrap_Struct(nodeRbHttpPointer, 0, NULL, settings));
104
- rb_iv_set(self, "@parser", Data_Wrap_Struct(nodeRbHttpPointer, 0, NULL, parser));
91
+ rb_iv_set(self, "settings", Data_Wrap_Struct(nodeRbHttpPointer, 0, NULL, settings));
92
+ rb_iv_set(self, "parser", Data_Wrap_Struct(nodeRbHttpPointer, 0, NULL, parser));
93
+
94
+ return self;
105
95
  };
106
96
 
107
97
  VALUE nodeRb_http_parse(VALUE self, VALUE data) {
@@ -109,15 +99,12 @@ VALUE nodeRb_http_parse(VALUE self, VALUE data) {
109
99
  http_parser_settings* settings;
110
100
  http_parser* parser;
111
101
 
112
- VALUE rsettings = rb_iv_get(self, "@settings");
113
- VALUE rparser = rb_iv_get(self, "@parser");
114
-
102
+ VALUE rsettings = rb_iv_get(self, "settings");
103
+ VALUE rparser = rb_iv_get(self, "parser");
115
104
 
116
105
  Data_Get_Struct(rsettings, http_parser_settings, settings);
117
106
  Data_Get_Struct(rparser, http_parser, parser);
118
107
 
119
- nodeRb_http* client = parser->data;
120
-
121
108
  size_t parsed = http_parser_execute(parser, settings, rb_string_value_cstr(&data), RSTRING_LEN(data));
122
109
 
123
110
  if (parser->upgrade) {
@@ -125,18 +112,21 @@ VALUE nodeRb_http_parse(VALUE self, VALUE data) {
125
112
  } else if (parsed != (unsigned) RSTRING_LEN(data)) {
126
113
  rb_funcall(self, rb_intern("on_error"), 2, rb_str_new2(http_errno_name(parser->http_errno)), rb_str_new2(http_errno_description(parser->http_errno)));
127
114
  };
115
+
116
+ return self;
128
117
  };
129
118
 
130
119
  VALUE nodeRb_http_dispose(VALUE self) {
131
120
  http_parser_settings* settings;
132
121
  http_parser* parser;
133
122
 
134
- Data_Get_Struct(rb_iv_get(self, "@settings"), http_parser_settings, settings);
135
- Data_Get_Struct(rb_iv_get(self, "@parser"), http_parser, parser);
123
+ Data_Get_Struct(rb_iv_get(self, "settings"), http_parser_settings, settings);
124
+ Data_Get_Struct(rb_iv_get(self, "parser"), http_parser, parser);
136
125
 
137
126
  free(parser->data);
138
127
  free(settings);
139
128
  free(parser);
129
+ return self;
140
130
  };
141
131
 
142
132
  void Init_noderb_http_extension() {
@@ -2,7 +2,7 @@ module NodeRb
2
2
  module Modules
3
3
  module Http
4
4
 
5
- VERSION = "0.0.3" unless const_defined?(:VERSION)
5
+ VERSION = "0.0.4" unless const_defined?(:VERSION)
6
6
 
7
7
  end
8
8
  end
data/test/init.rb CHANGED
@@ -1,10 +1,10 @@
1
- $: << File.expand_path("../../ext/noderb_http_extension", __FILE__)
2
- $: << File.expand_path("../../lib", __FILE__)
3
-
1
+ #$: << File.expand_path("../../ext/noderb_http_extension", __FILE__)
2
+ #$: << File.expand_path("../../lib", __FILE__)
3
+ require "rubygems"
4
4
  require "noderb-http"
5
5
 
6
6
  class TestParser
7
-
7
+
8
8
  include NodeRb::Modules::Http::Parser
9
9
 
10
10
  attr_accessor :headers, :version_major, :version_minor, :method, :url, :body, :keep_alive, :upgrade
@@ -41,6 +41,7 @@ Dir.glob(File.expand_path("../cases/*.rb", __FILE__)) do |file|
41
41
  require file
42
42
  end
43
43
 
44
+ puts "** Testing noderb-http"
44
45
  failed = false
45
46
  CASES.each do |test|
46
47
  parser = TestParser.new
@@ -57,6 +58,7 @@ CASES.each do |test|
57
58
  puts "** Test <#{test[:name]}> failed on #{result}" if result != "OK"
58
59
  failed = true
59
60
  end
61
+ parser.dispose
60
62
  end
61
63
 
62
- puts "** All test passed OK" unless failed
64
+ puts "** All test passed OK" unless failed
metadata CHANGED
@@ -1,24 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: noderb-http
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Marek Jelen
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000Z
17
+
18
+ date: 2011-10-01 00:00:00 Z
13
19
  dependencies: []
20
+
14
21
  description: Fast and full-featured HTTP parser.
15
- email:
22
+ email:
16
23
  - marek@jelen.biz
17
24
  executables: []
18
- extensions:
25
+
26
+ extensions:
19
27
  - ext/noderb_http_extension/extconf.rb
20
28
  extra_rdoc_files: []
21
- files:
29
+
30
+ files:
22
31
  - lib/noderb/modules/http/parser.rb
23
32
  - lib/noderb/modules/http/version.rb
24
33
  - lib/noderb/modules/http.rb
@@ -26,12 +35,8 @@ files:
26
35
  - ext/noderb_http_extension/extconf.rb
27
36
  - ext/noderb_http_extension/http_parser.c
28
37
  - ext/noderb_http_extension/http_parser.h
29
- - ext/noderb_http_extension/http_parser.o
30
- - ext/noderb_http_extension/Makefile
31
38
  - ext/noderb_http_extension/noderb_http.c
32
39
  - ext/noderb_http_extension/noderb_http.h
33
- - ext/noderb_http_extension/noderb_http.o
34
- - ext/noderb_http_extension/noderb_http_extension.bundle
35
40
  - test/cases/curl_get.rb
36
41
  - test/cases/patch_request.rb
37
42
  - test/cases/response.rb
@@ -41,26 +46,38 @@ files:
41
46
  - README.md
42
47
  homepage: http://github.com/noderb/noderb-http
43
48
  licenses: []
49
+
44
50
  post_install_message:
45
51
  rdoc_options: []
46
- require_paths:
52
+
53
+ require_paths:
47
54
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
55
+ required_ruby_version: !ruby/object:Gem::Requirement
49
56
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
65
  none: false
56
- requirements:
57
- - - ! '>='
58
- - !ruby/object:Gem::Version
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 23
70
+ segments:
71
+ - 1
72
+ - 3
73
+ - 6
59
74
  version: 1.3.6
60
75
  requirements: []
76
+
61
77
  rubyforge_project:
62
- rubygems_version: 1.8.5
78
+ rubygems_version: 1.8.8
63
79
  signing_key:
64
80
  specification_version: 3
65
81
  summary: Fast and full-featured HTTP parser
66
82
  test_files: []
83
+
@@ -1,187 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /Users/marek/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1
8
- hdrdir = /Users/marek/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1
9
- arch_hdrdir = /Users/marek/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/$(arch)
10
- VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
11
- prefix = $(DESTDIR)/Users/marek/.rvm/rubies/ruby-1.9.2-p290
12
- rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
13
- exec_prefix = $(prefix)
14
- vendorhdrdir = $(rubyhdrdir)/vendor_ruby
15
- sitehdrdir = $(rubyhdrdir)/site_ruby
16
- rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
17
- vendordir = $(rubylibprefix)/vendor_ruby
18
- sitedir = $(rubylibprefix)/site_ruby
19
- ridir = $(datarootdir)/$(RI_BASE_NAME)
20
- mandir = $(datarootdir)/man
21
- localedir = $(datarootdir)/locale
22
- libdir = $(exec_prefix)/lib
23
- psdir = $(docdir)
24
- pdfdir = $(docdir)
25
- dvidir = $(docdir)
26
- htmldir = $(docdir)
27
- infodir = $(datarootdir)/info
28
- docdir = $(datarootdir)/doc/$(PACKAGE)
29
- oldincludedir = $(DESTDIR)/usr/include
30
- includedir = $(prefix)/include
31
- localstatedir = $(prefix)/var
32
- sharedstatedir = $(prefix)/com
33
- sysconfdir = $(prefix)/etc
34
- datadir = $(datarootdir)
35
- datarootdir = $(prefix)/share
36
- libexecdir = $(exec_prefix)/libexec
37
- sbindir = $(exec_prefix)/sbin
38
- bindir = $(exec_prefix)/bin
39
- rubylibdir = $(rubylibprefix)/$(ruby_version)
40
- archdir = $(rubylibdir)/$(arch)
41
- sitelibdir = $(sitedir)/$(ruby_version)
42
- sitearchdir = $(sitelibdir)/$(sitearch)
43
- vendorlibdir = $(vendordir)/$(ruby_version)
44
- vendorarchdir = $(vendorlibdir)/$(sitearch)
45
-
46
- CC = gcc
47
- CXX = g++
48
- LIBRUBY = $(LIBRUBY_SO)
49
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
50
- LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
51
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
52
- OUTFLAG = -o
53
- COUTFLAG = -o
54
-
55
- RUBY_EXTCONF_H =
56
- cflags = $(optflags) $(debugflags) $(warnflags)
57
- optflags = -O3
58
- debugflags = -ggdb
59
- warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
60
- CFLAGS = -fno-common $(cflags) -fno-common -pipe
61
- INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
62
- DEFS =
63
- CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
64
- CXXFLAGS = $(CFLAGS) $(cxxflags)
65
- ldflags = -L. -L/usr/local/lib
66
- dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
67
- ARCH_FLAG =
68
- DLDFLAGS = $(ldflags) $(dldflags)
69
- LDSHARED = $(CC) -dynamic -bundle
70
- LDSHAREDXX = $(CXX) -dynamic -bundle
71
- AR = ar
72
- EXEEXT =
73
-
74
- RUBY_BASE_NAME = ruby
75
- RUBY_INSTALL_NAME = ruby
76
- RUBY_SO_NAME = ruby.1.9.1
77
- arch = x86_64-darwin10.8.0
78
- sitearch = $(arch)
79
- ruby_version = 1.9.1
80
- ruby = /Users/marek/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
81
- RUBY = $(ruby)
82
- RM = rm -f
83
- RM_RF = $(RUBY) -run -e rm -- -rf
84
- RMDIRS = $(RUBY) -run -e rmdir -- -p
85
- MAKEDIRS = /usr/local/bin/gmkdir -p
86
- INSTALL = /usr/local/bin/ginstall -c
87
- INSTALL_PROG = $(INSTALL) -m 0755
88
- INSTALL_DATA = $(INSTALL) -m 644
89
- COPY = cp
90
-
91
- #### End of system configuration section. ####
92
-
93
- preload =
94
-
95
- libpath = . $(libdir)
96
- LIBPATH = -L. -L$(libdir)
97
- DEFFILE =
98
-
99
- CLEANFILES = mkmf.log
100
- DISTCLEANFILES =
101
- DISTCLEANDIRS =
102
-
103
- extout =
104
- extout_prefix =
105
- target_prefix =
106
- LOCAL_LIBS =
107
- LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
108
- SRCS = http_parser.c noderb_http.c
109
- OBJS = http_parser.o noderb_http.o
110
- TARGET = noderb_http_extension
111
- DLLIB = $(TARGET).bundle
112
- EXTSTATIC =
113
- STATIC_LIB =
114
-
115
- BINDIR = $(bindir)
116
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
117
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
118
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
119
- HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
120
- ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
121
-
122
- TARGET_SO = $(DLLIB)
123
- CLEANLIBS = $(TARGET).bundle
124
- CLEANOBJS = *.o *.bak
125
-
126
- all: $(DLLIB)
127
- static: $(STATIC_LIB)
128
- .PHONY: all install static install-so install-rb
129
- .PHONY: clean clean-so clean-rb
130
-
131
- clean-rb-default::
132
- clean-rb::
133
- clean-so::
134
- clean: clean-so clean-rb-default clean-rb
135
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
136
-
137
- distclean-rb-default::
138
- distclean-rb::
139
- distclean-so::
140
- distclean: clean distclean-so distclean-rb-default distclean-rb
141
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
142
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
143
- @-$(RMDIRS) $(DISTCLEANDIRS)
144
-
145
- realclean: distclean
146
- install: install-so install-rb
147
-
148
- install-so: $(RUBYARCHDIR)
149
- install-so: $(RUBYARCHDIR)/$(DLLIB)
150
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
151
- @-$(MAKEDIRS) $(@D)
152
- $(INSTALL_PROG) $(DLLIB) $(@D)
153
- install-rb: pre-install-rb install-rb-default
154
- install-rb-default: pre-install-rb-default
155
- pre-install-rb: Makefile
156
- pre-install-rb-default: Makefile
157
- $(RUBYARCHDIR):
158
- $(MAKEDIRS) $@
159
-
160
- site-install: site-install-so site-install-rb
161
- site-install-so: install-so
162
- site-install-rb: install-rb
163
-
164
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
165
-
166
- .cc.o:
167
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
168
-
169
- .cxx.o:
170
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
171
-
172
- .cpp.o:
173
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
174
-
175
- .C.o:
176
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
177
-
178
- .c.o:
179
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
180
-
181
- $(DLLIB): $(OBJS) Makefile
182
- @-$(RM) $(@)
183
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
184
-
185
-
186
-
187
- $(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h