http_parser.rb 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGMxN2Q5N2MzMTlmNjEyY2NhMmQzNjdjMDRiYmQxNGY4ZjIyMzM0Mg==
5
- data.tar.gz: !binary |-
6
- YmVhZTVjYmMxNGM3YjUwOWQ3NmUwYzEwZThlZWM5NDQ0ZGMwYTgwNA==
2
+ SHA256:
3
+ metadata.gz: cb02853976523252e0d5f36af3ba83b363010d4c163d9a4951b419054e7486ae
4
+ data.tar.gz: 3b7ac3ea5df5866582e0f68653d205764498e60e01835d2e19661cf4e1089d1b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWM3ZDZmMjdmYzQxMTZiN2VjZTMxYjczMjgxN2ZjYWY0YjE3ODllYjM5Nzg0
10
- OTUwOTk3ODYwZGJhNGIwMjA0Mjg1MTFkNDgxY2ZlMGIzZjQwNmQ1ODVkMjFj
11
- ZjQyYzVmNjlkYTQ0NDZkMzhhYjE1M2FhZTdiOTdlYzAxMzljOWY=
12
- data.tar.gz: !binary |-
13
- M2ZiYTcwYTg2ZDJjZDc2N2Y0NzhmMzE0MzExNTY5M2I3MzAxMTkzNzUyYzUz
14
- NGM2YzRmOGM3OGQ4NDNkMmIwYjM2MjYyMGJlNTU1MTVlNzFiYjgxZjJiYmNi
15
- Y2Q4N2YyZWFjODYwYzlhNGMwMzcxNTcwZjIwMWJjNDViNjQ1MTc=
6
+ metadata.gz: 67516e3f1024e4bbf8dd00ae441646d53ca279313683b6f8da24668901c59b364608ecd9c69dab63709d9f89245ddc5363e0865f294a5af9d8e0b39d4712328f
7
+ data.tar.gz: 505a790706bc8f84404c2c6dd7e2b0025d591ca30311ca93d4eda4cf58a274c105acf68ed029ce96e38b04b040b86d4e953cf944a80a1e66a72f2a737d8cbfba
@@ -0,0 +1,23 @@
1
+ name: Testing on Ubuntu
2
+ on:
3
+ - push
4
+ - pull_request
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ '2.6', '2.7', '3.0' ]
12
+ os: [ 'ubuntu-latest' ]
13
+ name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: unit testing
20
+ run: |
21
+ gem install bundler rake
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
@@ -0,0 +1,23 @@
1
+ name: Testing on Windows
2
+ on:
3
+ - push
4
+ - pull_request
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ '2.6', '2.7', '3.0' ]
12
+ os: [ 'windows-latest' ]
13
+ name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: unit testing
20
+ run: |
21
+ gem install bundler rake
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
- tmp
1
+ *.bundle
2
2
  *.bundle
3
3
  *.gem
4
+ *.jar
4
5
  *.o
6
+ *.rbc
5
7
  *.so
6
- *.bundle
7
- *.jar
8
8
  *.swp
9
+ Gemfile.lock
9
10
  Makefile
10
11
  tags
11
- *.rbc
12
+ tmp
data/.gitmodules CHANGED
@@ -1,6 +1,6 @@
1
1
  [submodule "http-parser"]
2
2
  path = ext/ruby_http_parser/vendor/http-parser
3
- url = git://github.com/joyent/http-parser.git
3
+ url = https://github.com/nodejs/http-parser.git
4
4
  [submodule "http-parser-java"]
5
5
  path = ext/ruby_http_parser/vendor/http-parser-java
6
- url = git://github.com/tmm1/http-parser.java
6
+ url = https://github.com/tmm1/http-parser.java
data/README.md CHANGED
@@ -3,13 +3,13 @@
3
3
  A simple callback-based HTTP request/response parser for writing http
4
4
  servers, clients and proxies.
5
5
 
6
- This gem is built on top of [joyent/http-parser](http://github.com/joyent/http-parser) and its java port [http-parser/http-parser.java](http://github.com/http-parser/http-parser.java).
6
+ This gem is built on top of [joyent/http-parser](https://github.com/joyent/http-parser) and its java port [http-parser/http-parser.java](https://github.com/http-parser/http-parser.java).
7
7
 
8
8
  ## Supported Platforms
9
9
 
10
10
  This gem aims to work on all major Ruby platforms, including:
11
11
 
12
- - MRI 1.8 and 1.9
12
+ - MRI 1.8, 1.9 and 2.0; should work on MRI 2.4+
13
13
  - Rubinius
14
14
  - JRuby
15
15
  - win32
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- # load tasks
2
- Dir['tasks/*.rake'].sort.each { |f| load f }
1
+ require 'bundler/gem_tasks'
3
2
 
4
3
  # default task
5
4
  task :compile => :submodules
6
5
  task :default => [:compile, :spec]
6
+
7
+ # load tasks
8
+ Dir['tasks/*.rake'].sort.each { |f| load f }
@@ -18,7 +18,7 @@ src_dir = File.expand_path('../', __FILE__)
18
18
  }
19
19
  end
20
20
 
21
- $CFLAGS << " -I#{src_dir}"
21
+ $CFLAGS << " -I\"#{src_dir}\""
22
22
 
23
23
  dir_config("ruby_http_parser")
24
24
  create_makefile("ruby_http_parser")
@@ -8,6 +8,9 @@ import http_parser.lolevel.HTTPDataCallback;
8
8
  import http_parser.lolevel.ParserSettings;
9
9
 
10
10
  import java.nio.ByteBuffer;
11
+ import java.util.Arrays;
12
+ import java.util.ArrayList;
13
+ import java.util.List;
11
14
 
12
15
  import org.jcodings.Encoding;
13
16
  import org.jcodings.specific.UTF8Encoding;
@@ -81,6 +84,10 @@ public class RubyHttpParser extends RubyObject {
81
84
 
82
85
  private static final Encoding UTF8 = UTF8Encoding.INSTANCE;
83
86
 
87
+ private static final List<String> VALUE_TYPES = new ArrayList<String>(
88
+ Arrays.asList("mixed", "arrays", "strings")
89
+ );
90
+
84
91
  public RubyHttpParser(final Ruby runtime, RubyClass clazz) {
85
92
  super(runtime, clazz);
86
93
 
@@ -474,7 +481,7 @@ public class RubyHttpParser extends RubyObject {
474
481
  @JRubyMethod(name = "header_value_type=")
475
482
  public IRubyObject set_header_value_type(IRubyObject val) {
476
483
  String valString = val.toString();
477
- if (valString != "mixed" && valString != "arrays" && valString != "strings") {
484
+ if (!VALUE_TYPES.contains(valString)) {
478
485
  throw runtime.newArgumentError("Invalid header value type");
479
486
  }
480
487
  header_value_type = val;
@@ -16,6 +16,7 @@
16
16
  typedef struct ParserWrapper {
17
17
  ryah_http_parser parser;
18
18
 
19
+ VALUE status;
19
20
  VALUE request_url;
20
21
 
21
22
  VALUE headers;
@@ -45,6 +46,7 @@ void ParserWrapper_init(ParserWrapper *wrapper) {
45
46
  wrapper->parser.http_major = 0;
46
47
  wrapper->parser.http_minor = 0;
47
48
 
49
+ wrapper->status = Qnil;
48
50
  wrapper->request_url = Qnil;
49
51
 
50
52
  wrapper->upgrade_data = Qnil;
@@ -59,6 +61,7 @@ void ParserWrapper_init(ParserWrapper *wrapper) {
59
61
  void ParserWrapper_mark(void *data) {
60
62
  if(data) {
61
63
  ParserWrapper *wrapper = (ParserWrapper *) data;
64
+ rb_gc_mark_maybe(wrapper->status);
62
65
  rb_gc_mark_maybe(wrapper->request_url);
63
66
  rb_gc_mark_maybe(wrapper->upgrade_data);
64
67
  rb_gc_mark_maybe(wrapper->headers);
@@ -101,6 +104,7 @@ static VALUE Smixed;
101
104
  int on_message_begin(ryah_http_parser *parser) {
102
105
  GET_WRAPPER(wrapper, parser);
103
106
 
107
+ wrapper->status = rb_str_new2("");
104
108
  wrapper->request_url = rb_str_new2("");
105
109
  wrapper->headers = rb_hash_new();
106
110
  wrapper->upgrade_data = rb_str_new2("");
@@ -121,9 +125,28 @@ int on_message_begin(ryah_http_parser *parser) {
121
125
  }
122
126
  }
123
127
 
128
+ int on_status(ryah_http_parser *parser, const char *at, size_t length) {
129
+ GET_WRAPPER(wrapper, parser);
130
+
131
+ if (at && length) {
132
+ if (wrapper->status == Qnil) {
133
+ wrapper->status = rb_str_new(at, length);
134
+ } else {
135
+ rb_str_cat(wrapper->status, at, length);
136
+ }
137
+ }
138
+ return 0;
139
+ }
140
+
124
141
  int on_url(ryah_http_parser *parser, const char *at, size_t length) {
125
142
  GET_WRAPPER(wrapper, parser);
126
- rb_str_cat(wrapper->request_url, at, length);
143
+ if (at && length) {
144
+ if (wrapper->request_url == Qnil) {
145
+ wrapper->request_url = rb_str_new(at, length);
146
+ } else {
147
+ rb_str_cat(wrapper->request_url, at, length);
148
+ }
149
+ }
127
150
  return 0;
128
151
  }
129
152
 
@@ -136,7 +159,6 @@ int on_header_field(ryah_http_parser *parser, const char *at, size_t length) {
136
159
  } else {
137
160
  rb_str_cat(wrapper->curr_field_name, at, length);
138
161
  }
139
-
140
162
  return 0;
141
163
  }
142
164
 
@@ -248,6 +270,7 @@ int on_message_complete(ryah_http_parser *parser) {
248
270
 
249
271
  static ryah_http_parser_settings settings = {
250
272
  .on_message_begin = on_message_begin,
273
+ .on_status = on_status,
251
274
  .on_url = on_url,
252
275
  .on_header_field = on_header_field,
253
276
  .on_header_value = on_header_value,
@@ -293,7 +316,17 @@ VALUE Parser_initialize(int argc, VALUE *argv, VALUE self) {
293
316
  ParserWrapper *wrapper = NULL;
294
317
  DATA_GET(self, ParserWrapper, wrapper);
295
318
 
296
- wrapper->header_value_type = rb_iv_get(CLASS_OF(self), "@default_header_value_type");
319
+ VALUE default_header_value_type = Qnil;
320
+
321
+ if (argc > 0 && RB_TYPE_P(argv[argc-1], T_HASH)) {
322
+ ID keyword_ids[1];
323
+ keyword_ids[0] = rb_intern("default_header_value_type");
324
+ rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, &default_header_value_type);
325
+ if (default_header_value_type == Qundef) {
326
+ default_header_value_type = Qnil;
327
+ }
328
+ --argc;
329
+ }
297
330
 
298
331
  if (argc == 1) {
299
332
  wrapper->callback_object = argv[0];
@@ -301,7 +334,13 @@ VALUE Parser_initialize(int argc, VALUE *argv, VALUE self) {
301
334
 
302
335
  if (argc == 2) {
303
336
  wrapper->callback_object = argv[0];
304
- wrapper->header_value_type = argv[1];
337
+ default_header_value_type = argv[1];
338
+ }
339
+
340
+ if (default_header_value_type == Qnil) {
341
+ wrapper->header_value_type = rb_iv_get(CLASS_OF(self), "@default_header_value_type");
342
+ } else {
343
+ wrapper->header_value_type = default_header_value_type;
305
344
  }
306
345
 
307
346
  return self;
@@ -320,11 +359,12 @@ VALUE Parser_execute(VALUE self, VALUE data) {
320
359
  size_t nparsed = ryah_http_parser_execute(&wrapper->parser, &settings, ptr, len);
321
360
 
322
361
  if (wrapper->parser.upgrade) {
323
- if (RTEST(wrapper->stopped))
362
+ if (RTEST(wrapper->stopped) && !RTEST(wrapper->completed))
324
363
  nparsed += 1;
325
364
 
326
- rb_str_cat(wrapper->upgrade_data, ptr + nparsed, len - nparsed);
327
-
365
+ if (nparsed < len)
366
+ rb_str_cat(wrapper->upgrade_data, ptr + nparsed, len - nparsed);
367
+
328
368
  } else if (nparsed != (size_t)len) {
329
369
  if (!RTEST(wrapper->stopped) && !RTEST(wrapper->completed))
330
370
  rb_raise(eParserError, "Could not parse data entirely (%zu != %zu)", nparsed, len);
@@ -438,6 +478,7 @@ VALUE Parser_status_code(VALUE self) {
438
478
  return wrapper->name; \
439
479
  }
440
480
 
481
+ DEFINE_GETTER(status);
441
482
  DEFINE_GETTER(request_url);
442
483
  DEFINE_GETTER(headers);
443
484
  DEFINE_GETTER(upgrade_data);
@@ -464,6 +505,10 @@ VALUE Parser_reset(VALUE self) {
464
505
  }
465
506
 
466
507
  void Init_ruby_http_parser() {
508
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
509
+ rb_ext_ractor_safe(true);
510
+ #endif
511
+
467
512
  VALUE mHTTP = rb_define_module("HTTP");
468
513
  cParser = rb_define_class_under(mHTTP, "Parser", rb_cObject);
469
514
  cRequestParser = rb_define_class_under(mHTTP, "RequestParser", cParser);
@@ -505,6 +550,7 @@ void Init_ruby_http_parser() {
505
550
  rb_define_method(cParser, "http_method", Parser_http_method, 0);
506
551
  rb_define_method(cParser, "status_code", Parser_status_code, 0);
507
552
 
553
+ rb_define_method(cParser, "status", Parser_status, 0);
508
554
  rb_define_method(cParser, "request_url", Parser_request_url, 0);
509
555
  rb_define_method(cParser, "headers", Parser_headers, 0);
510
556
  rb_define_method(cParser, "upgrade_data", Parser_upgrade_data, 0);
@@ -28,5 +28,41 @@ Andre Caron <andre.l.caron@gmail.com>
28
28
  Ivo Raisr <ivosh@ivosh.net>
29
29
  James McLaughlin <jamie@lacewing-project.org>
30
30
  David Gwynne <loki@animata.net>
31
- LE ROUX Thomas <thomas@procheo.fr>
31
+ Thomas LE ROUX <thomas@november-eleven.fr>
32
32
  Randy Rizun <rrizun@ortivawireless.com>
33
+ Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
34
+ Simon Zimmermann <simonz05@gmail.com>
35
+ Erik Dubbelboer <erik@dubbelboer.com>
36
+ Martell Malone <martellmalone@gmail.com>
37
+ Bertrand Paquet <bpaquet@octo.com>
38
+ BogDan Vatra <bogdan@kde.org>
39
+ Peter Faiman <peter@thepicard.org>
40
+ Corey Richardson <corey@octayn.net>
41
+ Tóth Tamás <tomika_nospam@freemail.hu>
42
+ Cam Swords <cam.swords@gmail.com>
43
+ Chris Dickinson <christopher.s.dickinson@gmail.com>
44
+ Uli Köhler <ukoehler@btronik.de>
45
+ Charlie Somerville <charlie@charliesomerville.com>
46
+ Patrik Stutz <patrik.stutz@gmail.com>
47
+ Fedor Indutny <fedor.indutny@gmail.com>
48
+ runner <runner.mei@gmail.com>
49
+ Alexis Campailla <alexis@janeasystems.com>
50
+ David Wragg <david@wragg.org>
51
+ Vinnie Falco <vinnie.falco@gmail.com>
52
+ Alex Butum <alexbutum@linux.com>
53
+ Rex Feng <rexfeng@gmail.com>
54
+ Alex Kocharin <alex@kocharin.ru>
55
+ Mark Koopman <markmontymark@yahoo.com>
56
+ Helge Heß <me@helgehess.eu>
57
+ Alexis La Goutte <alexis.lagoutte@gmail.com>
58
+ George Miroshnykov <george.miroshnykov@gmail.com>
59
+ Maciej Małecki <me@mmalecki.com>
60
+ Marc O'Morain <github.com@marcomorain.com>
61
+ Jeff Pinner <jpinner@twitter.com>
62
+ Timothy J Fontaine <tjfontaine@gmail.com>
63
+ Akagi201 <akagi201@gmail.com>
64
+ Romain Giraud <giraud.romain@gmail.com>
65
+ Jay Satiro <raysatiro@yahoo.com>
66
+ Arne Steen <Arne.Steen@gmx.de>
67
+ Kjell Schubert <kjell.schubert@gmail.com>
68
+ Olivier Mengué <dolmen@cpan.org>
@@ -1,8 +1,4 @@
1
- http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
2
- Igor Sysoev.
3
-
4
- Additional changes are licensed under the same terms as NGINX and
5
- copyright Joyent, Inc. and other Node contributors. All rights reserved.
1
+ Copyright Joyent, Inc. and other Node contributors.
6
2
 
7
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
4
  of this software and associated documentation files (the "Software"), to
@@ -1,20 +1,80 @@
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
+ PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
22
+ HELPER ?=
23
+ BINEXT ?=
24
+ SOLIBNAME = libhttp_parser
25
+ SOMAJOR = 2
26
+ SOMINOR = 8
27
+ SOREV = 1
28
+ ifeq (darwin,$(PLATFORM))
29
+ SOEXT ?= dylib
30
+ SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT)
31
+ LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT)
32
+ else ifeq (wine,$(PLATFORM))
33
+ CC = winegcc
34
+ BINEXT = .exe.so
35
+ HELPER = wine
36
+ else
37
+ SOEXT ?= so
38
+ SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR)
39
+ LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV)
40
+ endif
41
+
1
42
  CC?=gcc
2
43
  AR?=ar
3
44
 
45
+ CPPFLAGS ?=
46
+ LDFLAGS ?=
47
+
4
48
  CPPFLAGS += -I.
5
- CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1 -DHTTP_PARSER_DEBUG=1
49
+ CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
6
50
  CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
7
- CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0 -DHTTP_PARSER_DEBUG=0
51
+ CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
8
52
  CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
53
+ CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
9
54
 
10
55
  CFLAGS += -Wall -Wextra -Werror
11
56
  CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
12
57
  CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
58
+ CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
13
59
  CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
14
60
 
61
+ LDFLAGS_LIB = $(LDFLAGS) -shared
62
+
63
+ INSTALL ?= install
64
+ PREFIX ?= /usr/local
65
+ LIBDIR = $(PREFIX)/lib
66
+ INCLUDEDIR = $(PREFIX)/include
67
+
68
+ ifeq (darwin,$(PLATFORM))
69
+ LDFLAGS_LIB += -Wl,-install_name,$(LIBDIR)/$(SONAME)
70
+ else
71
+ # TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
72
+ LDFLAGS_LIB += -Wl,-soname=$(SONAME)
73
+ endif
74
+
15
75
  test: test_g test_fast
16
- ./test_g
17
- ./test_fast
76
+ $(HELPER) ./test_g$(BINEXT)
77
+ $(HELPER) ./test_fast$(BINEXT)
18
78
 
19
79
  test_g: http_parser_g.o test_g.o
20
80
  $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
@@ -31,11 +91,17 @@ test_fast: http_parser.o test.o http_parser.h
31
91
  test.o: test.c http_parser.h Makefile
32
92
  $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
33
93
 
94
+ bench: http_parser.o bench.o
95
+ $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
96
+
97
+ bench.o: bench.c http_parser.h Makefile
98
+ $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
99
+
34
100
  http_parser.o: http_parser.c http_parser.h Makefile
35
101
  $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
36
102
 
37
103
  test-run-timed: test_fast
38
- while(true) do time ./test_fast > /dev/null; done
104
+ while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done
39
105
 
40
106
  test-valgrind: test_g
41
107
  valgrind ./test_g
@@ -44,15 +110,51 @@ libhttp_parser.o: http_parser.c http_parser.h Makefile
44
110
  $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
45
111
 
46
112
  library: libhttp_parser.o
47
- $(CC) -shared -o libhttp_parser.so libhttp_parser.o
113
+ $(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $<
48
114
 
49
115
  package: http_parser.o
50
116
  $(AR) rcs libhttp_parser.a http_parser.o
51
117
 
118
+ url_parser: http_parser.o contrib/url_parser.c
119
+ $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
120
+
121
+ url_parser_g: http_parser_g.o contrib/url_parser.c
122
+ $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
123
+
124
+ parsertrace: http_parser.o contrib/parsertrace.c
125
+ $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT)
126
+
127
+ parsertrace_g: http_parser_g.o contrib/parsertrace.c
128
+ $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT)
129
+
52
130
  tags: http_parser.c http_parser.h test.c
53
131
  ctags $^
54
132
 
133
+ install: library
134
+ $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h
135
+ $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
136
+ ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
137
+ ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
138
+
139
+ install-strip: library
140
+ $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h
141
+ $(INSTALL) -D -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
142
+ ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
143
+ ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
144
+
145
+ uninstall:
146
+ rm $(DESTDIR)$(INCLUDEDIR)/http_parser.h
147
+ rm $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
148
+ rm $(DESTDIR)$(LIBDIR)/$(SONAME)
149
+ rm $(DESTDIR)$(LIBDIR)/$(LIBNAME)
150
+
55
151
  clean:
56
- rm -f *.o *.a test test_fast test_g http_parser.tar tags libhttp_parser.so libhttp_parser.o
152
+ rm -f *.o *.a tags test test_fast test_g \
153
+ http_parser.tar libhttp_parser.so.* \
154
+ url_parser url_parser_g parsertrace parsertrace_g \
155
+ *.exe *.exe.so
156
+
157
+ contrib/url_parser.c: http_parser.h
158
+ contrib/parsertrace.c: http_parser.h
57
159
 
58
- .PHONY: clean package test-run test-run-timed test-valgrind
160
+ .PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall