ngxmodgen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5961c31367d229409f53f3e37fce9422551c7bda
4
+ data.tar.gz: 37dcd694b286e3024303ea6c6b6e44069722bcf5
5
+ SHA512:
6
+ metadata.gz: 2b38018c6de37587182b532f8781b2ba1cb701824781e2c6ea64b666f55eedfe6e7a3704b2d8d9c65008c372c1bcda20b1755e94e6f5e4697d0bb275f5d7d438
7
+ data.tar.gz: ea3c6b57a15b527beb52cf2afb49448e55ca86c791c80f4d8776ca7b42a54653287dd4b573678c591e2c3bc3429fec482449b1ba1f7530d777cfc9d35230271c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ngxmodgen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tatsuhiko Kubo <cubicdaiya@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # ngxmodgen
2
+
3
+ ngxmodgen is the code generator for a nginx module
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ngxmodgen'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ngxmodgen
18
+
19
+ ## Usage
20
+
21
+ $ NGINX_MODULE_NAME=hoge
22
+ $ ngxcodegen -n $NGINX_MODULE_NAME # generate ngx_http_hoge_module.c and config
23
+ $ ngxcodegen -n $NGINX_MODULE_NAME -t http # generate ngx_http_hoge_module.c and config
24
+ $ ngxcodegen -n $NGINX_MODULE_NAME -t http_filter # generate ngx_http_hoge_filter_module.c and config
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'test'
4
+ task :test do
5
+ exec 'ruby test/test.rb'
6
+ end
data/bin/ngxmodgen ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'rubygems' unless defined?(gem)
4
+ here = File.dirname(__FILE__)
5
+ $LOAD_PATH << File.expand_path(File.join(here, '..', 'lib'))
6
+ require 'ngxmodgen'
@@ -0,0 +1,23 @@
1
+ class NginxModuleConfigGenerator
2
+
3
+ def initialize(module_name)
4
+ @module_name = module_name
5
+ end
6
+
7
+ def generate
8
+ <<"EOS"
9
+ ngx_addon_name=ngx_http_#{@module_name}_module
10
+ HTTP_MODULES="$HTTP_MODULES ngx_http_#{@module_name}_module"
11
+ NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_#{@module_name}_module.c"
12
+ EOS
13
+ end
14
+
15
+ def filter_generate
16
+ <<"EOS"
17
+ ngx_addon_name=ngx_http_#{@module_name}_module
18
+ HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES ngx_http_#{@module_name}_filter_module"
19
+ NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_#{@module_name}_filter_module.c"
20
+ EOS
21
+ end
22
+
23
+ end
@@ -0,0 +1,134 @@
1
+ class NginxModuleSourceGenerator
2
+
3
+ def initialize(module_name)
4
+ @module_name = module_name
5
+ end
6
+
7
+ def generate
8
+ <<"EOS"
9
+
10
+ #include <ngx_config.h>
11
+ #include <ngx_core.h>
12
+ #include <ngx_http.h>
13
+
14
+ static ngx_command_t ngx_http_#{@module_name}_commands[] = {
15
+ /*
16
+ {
17
+ ngx_string("command_name"),
18
+ NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
19
+ NULL,
20
+ 0,
21
+ 0,
22
+ NULL
23
+ },
24
+ */
25
+ ngx_null_command
26
+ };
27
+
28
+ static ngx_http_module_t ngx_http_#{@module_name}_module_ctx = {
29
+ NULL, /* preconfiguration */
30
+ NULL, /* postconfiguration */
31
+
32
+ NULL, /* create main configuration */
33
+ NULL, /* init main configuration */
34
+
35
+ NULL, /* create server configuration */
36
+ NULL, /* merge server configuration */
37
+
38
+ NULL, /* create location configuration */
39
+ NULL /* merge location configuration */
40
+ };
41
+
42
+ ngx_module_t ngx_http_#{@module_name}_module = {
43
+ NGX_MODULE_V1,
44
+ &ngx_http_#{@module_name}_module_ctx, /* module context */
45
+ ngx_http_#{@module_name}_commands, /* module directives */
46
+ NGX_HTTP_MODULE, /* module type */
47
+ NULL, /* init master */
48
+ NULL, /* init module */
49
+ NULL, /* init process */
50
+ NULL, /* init thread */
51
+ NULL, /* exit thread */
52
+ NULL, /* exit process */
53
+ NULL, /* exit master */
54
+ NGX_MODULE_V1_PADDING
55
+ };
56
+
57
+ EOS
58
+ end
59
+
60
+ def filter_generate
61
+ <<"EOS"
62
+
63
+ #include <ngx_config.h>
64
+ #include <ngx_core.h>
65
+ #include <ngx_http.h>
66
+
67
+ static ngx_int_t ngx_http_#{@module_name}_filter_init(ngx_conf_t *cf);
68
+
69
+ static ngx_http_module_t ngx_http_#{@module_name}_filter_module_ctx = {
70
+ NULL, /* preconfiguration */
71
+ ngx_http_#{@module_name}_filter_init, /* postconfiguration */
72
+
73
+ NULL, /* create main configuration */
74
+ NULL, /* init main configuration */
75
+
76
+ NULL, /* create server configuration */
77
+ NULL, /* merge server configuration */
78
+
79
+ NULL, /* create location configuration */
80
+ NULL /* merge location configuration */
81
+ };
82
+
83
+ ngx_module_t ngx_http_#{@module_name}_filter_module = {
84
+ NGX_MODULE_V1,
85
+ &ngx_http_#{@module_name}_filter_module_ctx, /* module context */
86
+ NULL, /* module directives */
87
+ NGX_HTTP_MODULE, /* module type */
88
+ NULL, /* init master */
89
+ NULL, /* init module */
90
+ NULL, /* init process */
91
+ NULL, /* init thread */
92
+ NULL, /* exit thread */
93
+ NULL, /* exit process */
94
+ NULL, /* exit master */
95
+ NGX_MODULE_V1_PADDING
96
+ };
97
+
98
+ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
99
+ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
100
+
101
+ static ngx_int_t ngx_http_#{@module_name}_header_filter(ngx_http_request_t *r)
102
+ {
103
+ return ngx_http_next_header_filter(r);
104
+ }
105
+
106
+
107
+ static ngx_int_t ngx_http_#{@module_name}_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
108
+ {
109
+ return ngx_http_next_body_filter(r, in);
110
+ }
111
+
112
+ static ngx_int_t ngx_http_#{@module_name}_filter_init(ngx_conf_t *cf)
113
+ {
114
+ ngx_http_next_header_filter = ngx_http_top_header_filter;
115
+ ngx_http_top_header_filter = ngx_http_#{@module_name}_header_filter;
116
+
117
+ ngx_http_next_body_filter = ngx_http_top_body_filter;
118
+ ngx_http_top_body_filter = ngx_http_#{@module_name}_body_filter;
119
+
120
+ return NGX_OK;
121
+ }
122
+
123
+ EOS
124
+ end
125
+
126
+ def module_name
127
+ "ngx_http_#{@module_name}_module"
128
+ end
129
+
130
+ def filter_module_name
131
+ "ngx_http_#{@module_name}_filter_module"
132
+ end
133
+
134
+ end
@@ -0,0 +1,3 @@
1
+ module Ngxmodgen
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ngxmodgen.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "ngxmodgen/version"
2
+ require "ngxmodgen/configgen"
3
+ require "ngxmodgen/srcgen"
4
+
5
+ require 'optparse'
6
+
7
+ op = OptionParser.new
8
+
9
+ module_name = ""
10
+ module_type = "http"
11
+
12
+ op.on('-n', '--name NAME', "nginx module name") {|s|
13
+ module_name = s
14
+ }
15
+
16
+ op.on('-t', '--type [TYPE]', "module type(default: #{module_type})") {|s|
17
+ module_type = s
18
+ }
19
+
20
+ op.parse!(ARGV)
21
+
22
+ if module_name == ""
23
+ e = OptionParser::ParseError.new;
24
+ raise e, "module name was not specified"
25
+ end
26
+
27
+ config_gen = NginxModuleConfigGenerator.new(module_name)
28
+ src_gen = NginxModuleSourceGenerator.new(module_name)
29
+
30
+ if module_type == "http"
31
+ File.open('config', 'w') {|f| f.write(config_gen.generate()) }
32
+ File.open("#{src_gen.module_name}.c", 'w') {|f| f.write(src_gen.generate()) }
33
+ puts "#{src_gen.module_name}.c and config is generated"
34
+ elsif module_type == "http_filter"
35
+ File.open('config', 'w') {|f| f.write(config_gen.filter_generate()) }
36
+ File.open("#{src_gen.filter_module_name}.c", 'w') {|f| f.write(src_gen.filter_generate()) }
37
+ puts "#{src_gen.filter_module_name}.c and config is generated"
38
+ else
39
+ puts "module type is invalid. Input 'http' or 'http_filter'"
40
+ exit(1)
41
+ end
42
+
data/ngxmodgen.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ngxmodgen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ngxmodgen"
8
+ spec.version = Ngxmodgen::VERSION
9
+ spec.authors = ["Tatsuhiko Kubo"]
10
+ spec.email = ["cubicdaiya@gmail.com"]
11
+ spec.description = %q{Nginx Module Generator}
12
+ spec.summary = %q{Nginx Module Generator}
13
+ spec.homepage = "https://github.com/cubicdaiya/ngxmodgen"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ end
data/test/test.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "minitest/unit"
2
+ require "minitest/autorun"
3
+ require "ngxmodgen/configgen"
4
+ require "ngxmodgen/srcgen"
5
+
6
+ class TestNgxmodgen < MiniTest::Unit::TestCase
7
+ def setup
8
+ @module_name = "hoge"
9
+ @config_gen = NginxModuleConfigGenerator.new(@module_name)
10
+ @src_gen = NginxModuleSourceGenerator.new(@module_name)
11
+ end
12
+
13
+ def teardown
14
+
15
+ end
16
+
17
+ def test_module_name
18
+ assert_equal "ngx_http_hoge_module", @src_gen.module_name
19
+ end
20
+
21
+ def test_filter_module_name
22
+ assert_equal "ngx_http_hoge_filter_module", @src_gen.filter_module_name
23
+ end
24
+
25
+ def test_http_module_config
26
+ r = /^HTTP_MODULES/
27
+ assert r.match(@config_gen.generate), "HTTP_MODULE is not included"
28
+ end
29
+
30
+ def test_http_filter_module_config
31
+ r = /^HTTP_FILTER_MODULES/
32
+ assert r.match(@config_gen.filter_generate), "HTTP_FILTER_MODULE is not included"
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ngxmodgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuhiko Kubo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Nginx Module Generator
56
+ email:
57
+ - cubicdaiya@gmail.com
58
+ executables:
59
+ - ngxmodgen
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/ngxmodgen
69
+ - lib/ngxmodgen.rb
70
+ - lib/ngxmodgen/configgen.rb
71
+ - lib/ngxmodgen/srcgen.rb
72
+ - lib/ngxmodgen/version.rb
73
+ - ngxmodgen.gemspec
74
+ - test/test.rb
75
+ homepage: https://github.com/cubicdaiya/ngxmodgen
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Nginx Module Generator
99
+ test_files:
100
+ - test/test.rb