phprpc 3.0.0

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.
@@ -0,0 +1,55 @@
1
+ ############################################################
2
+ # #
3
+ # The implementation of PHPRPC Protocol 3.0 #
4
+ # #
5
+ # server.rb #
6
+ # #
7
+ # Release 3.0.0 #
8
+ # Copyright (c) 2005-2008 by Team-PHPRPC #
9
+ # #
10
+ # WebSite: http://www.phprpc.org/ #
11
+ # http://www.phprpc.net/ #
12
+ # http://www.phprpc.com/ #
13
+ # http://sourceforge.net/projects/php-rpc/ #
14
+ # #
15
+ # Authors: Ma Bingyao <andot@ujn.edu.cn> #
16
+ # #
17
+ # This file may be distributed and/or modified under the #
18
+ # terms of the GNU Lesser General Public License (LGPL) #
19
+ # version 3.0 as published by the Free Software Foundation #
20
+ # and appearing in the included file LICENSE. #
21
+ # #
22
+ ############################################################
23
+ #
24
+ # PHPRPC Server library.
25
+ #
26
+ # Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
27
+ # Version: 3.0
28
+ # LastModified: Sep 13, 2008
29
+ # This library is free. You can redistribute it and/or modify it.
30
+
31
+ module PHPRPC
32
+
33
+ autoload :CGIServer, 'phprpc/cgi_server'
34
+ autoload :MongrelServer, 'phprpc/mongrel_server'
35
+ autoload :ThinServer, 'phprpc/thin_server'
36
+ autoload :FCGIServer, 'phprpc/fcgi_server'
37
+ autoload :SCGIServer, 'phprpc/scgi_server'
38
+ autoload :LSAPIServer, 'phprpc/lsapi_server'
39
+ autoload :EbbServer, 'phprpc/ebb_server'
40
+ autoload :WEBrickServer, 'phprpc/webrick_server'
41
+ autoload :FakeServer, 'phprpc/fake_server'
42
+
43
+ ARGV[0] = '' if ARGV[0].nil?
44
+ Server = case ARGV[0].downcase
45
+ when 'mongrel' then MongrelServer
46
+ when 'thin' then ThinServer
47
+ when 'fcgi' then FCGIServer
48
+ when 'scgi' then SCGIServer
49
+ when 'lsapi' then LSAPIServer
50
+ when 'ebb' then EbbServer
51
+ when 'webrick' then WEBrickServer
52
+ else (ENV['GATEWAY_INTERFACE'] =~ /CGI\/\d.\d/ ? CGIServer : FakeServer)
53
+ end # class Server
54
+
55
+ end # module PHPRPC
@@ -0,0 +1,161 @@
1
+ ############################################################
2
+ # #
3
+ # The implementation of PHPRPC Protocol 3.0 #
4
+ # #
5
+ # thin_server.rb #
6
+ # #
7
+ # Release 3.0.0 #
8
+ # Copyright (c) 2005-2008 by Team-PHPRPC #
9
+ # #
10
+ # WebSite: http://www.phprpc.org/ #
11
+ # http://www.phprpc.net/ #
12
+ # http://www.phprpc.com/ #
13
+ # http://sourceforge.net/projects/php-rpc/ #
14
+ # #
15
+ # Authors: Ma Bingyao <andot@ujn.edu.cn> #
16
+ # #
17
+ # This file may be distributed and/or modified under the #
18
+ # terms of the GNU Lesser General Public License (LGPL) #
19
+ # version 3.0 as published by the Free Software Foundation #
20
+ # and appearing in the included file LICENSE. #
21
+ # #
22
+ ############################################################
23
+ #
24
+ # PHPRPC ThinServer library.
25
+ #
26
+ # Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
27
+ # Version: 3.0
28
+ # LastModified: Sep 14, 2008
29
+ # This library is free. You can redistribute it and/or modify it.
30
+
31
+ require 'thin'
32
+ require "phprpc/base_server"
33
+
34
+ module PHPRPC
35
+
36
+ class ThinServer < BaseServer
37
+
38
+ def initialize(options = {})
39
+ super()
40
+ @options = {
41
+ :address => '0.0.0.0',
42
+ :port => Thin::Server::DEFAULT_PORT,
43
+ :timeout => Thin::Server::DEFAULT_TIMEOUT,
44
+ :daemonize => false,
45
+ :log => 'log/thin.log',
46
+ :pid => 'log/thin.pid',
47
+ :max_conns => Thin::Server::DEFAULT_MAXIMUM_CONNECTIONS,
48
+ :max_persistent_conns => Thin::Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS,
49
+ :threaded => false,
50
+ :chdir => Dir.pwd,
51
+ :session_mode => :file,
52
+ :path => "/",
53
+ :expire_after => 1800,
54
+ :debug => false,
55
+ :trace => false,
56
+ }.update(options)
57
+ @opts = OptionParser.new
58
+ @opts.banner = "Usage: #{@opts.program_name} thin [options]"
59
+ @opts.separator ""
60
+ @opts.separator "Server options:"
61
+ @opts.on("-a", "--address HOST", "Bind to HOST address (default: #{@options[:address]})") { |host| @options[:address] = host }
62
+ @opts.on("-p", "--port PORT", "Use PORT (default: #{@options[:port]})") { |port| @options[:port] = port.to_i }
63
+ @opts.on("-S", "--socket FILE", "Bind to unix domain socket") { |file| @options[:socket] = file }
64
+ @opts.on("-y", "--swiftiply [KEY]", "Run using swiftiply") { |key| @options[:swiftiply] = key }
65
+ @opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) }
66
+ @opts.on("--stats PATH", "Mount the Stats adapter under PATH") { |path| @options[:stats] = path }
67
+ unless Thin.win? # Daemonizing not supported on Windows
68
+ @opts.separator ""
69
+ @opts.separator "Daemon options:"
70
+ @opts.on("-d", "--daemonize", "Run daemonized in the background") { @options[:daemonize] = true }
71
+ @opts.on("-l", "--log FILE", "File to redirect output", "(default: #{@options[:log]})") { |file| @options[:log] = file }
72
+ @opts.on("-P", "--pid FILE", "File to store PID", "(default: #{@options[:pid]})") { |file| @options[:pid] = file }
73
+ @opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| @options[:user] = user }
74
+ @opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| @options[:group] = group }
75
+ end
76
+ @opts.separator ""
77
+ @opts.separator "Tuning options:"
78
+ @opts.on("-b", "--backend CLASS", "Backend to use, full classname") { |name| @options[:backend] = name }
79
+ @opts.on("-t", "--timeout SEC", "Request or command timeout in sec", "(default: #{@options[:timeout]})") { |sec| @options[:timeout] = sec.to_i }
80
+ @opts.on("--max-conns NUM", "Maximum number of connections", "(default: #{@options[:max_conns]})",
81
+ "Might require sudo to set higher then 1024") { |num| @options[:max_conns] = num.to_i } unless Thin.win?
82
+ @opts.on("--max-persistent-conns NUM", "Maximum number of persistent connections",
83
+ "(default: #{@options[:max_persistent_conns]})") { |num| @options[:max_persistent_conns] = num.to_i }
84
+ @opts.on("--threaded", "Call the Rack application in threads", "[experimental]") { @options[:threaded] = true }
85
+ @opts.separator ""
86
+ @opts.separator "Session options:"
87
+ @opts.on('-s', '--session-mode MODE', [:file, :memcache, :pool], "Select Session mode (file, memcache, pool)", "(default: #{@options[:session_mode].to_s})") { |mode| @options[:session_mode] = mode }
88
+ @opts.on('-e','--expire-after TIME', Integer, "Session expire after (default: #{@options[:expire_after]})") { |time| @options[:expire_after] = time }
89
+ @opts.on('-m','--memcache_server SERVER', String, "Memcache server used by session in", "memcache mode (default: localhost:11211)") { |server| @options[:memcache_server] = server }
90
+ @opts.on('--prefix PATH', String, "Mount the PHPRPC Server under PATH", "(start with /)") { |path| @options[:path] = path }
91
+ @opts.separator ""
92
+ @opts.separator "Common options:"
93
+ @opts.on_tail("-D", "--debug", "Set debbuging on") { @options[:debug] = true }
94
+ @opts.on_tail("-V", "--trace", "Set tracing on (log raw request/response)") { @options[:trace] = true }
95
+ @opts.on_tail("-?", "-h", "--help", "Show this message") { puts @opts; exit }
96
+ @opts.on_tail('-v', '--version', "Show version") { puts Thin::SERVER; exit }
97
+ begin
98
+ @opts.parse!(ARGV)
99
+ rescue OptionParser::ParseError
100
+ puts @opts
101
+ exit
102
+ end
103
+ @app = PHPRPC::BaseServer.new
104
+ self.debug = @options[:debug]
105
+ end
106
+
107
+ def start()
108
+ @options[:backend] = eval(@options[:backend], TOPLEVEL_BINDING) if @options[:backend]
109
+ app = self
110
+ if [:memcache, :pool].include?(@options[:session_mode]) then
111
+ begin
112
+ require 'rack'
113
+ if @options[:session_mode] == :memcache then
114
+ app = Rack::Session::Memcache.new(self, @options)
115
+ else
116
+ app = Rack::Session::Pool.new(self, @options)
117
+ end
118
+ rescue Exception
119
+ app = self
120
+ end
121
+ end
122
+ Dir.chdir(@options[:chdir])
123
+ Thin::Logging.debug = @options[:debug]
124
+ Thin::Logging.trace = @options[:trace]
125
+ server = Thin::Server.new(@options[:socket] || @options[:address], # Server detects kind of socket
126
+ @options[:port], # Port ignored on UNIX socket
127
+ @options,
128
+ app)
129
+
130
+ # Set options
131
+ server.pid_file = @options[:pid]
132
+ server.log_file = @options[:log]
133
+ server.timeout = @options[:timeout]
134
+ server.maximum_connections = @options[:max_conns]
135
+ server.maximum_persistent_connections = @options[:max_persistent_conns]
136
+ server.threaded = @options[:threaded]
137
+
138
+ # Detach the process, after this line the current process returns
139
+ server.daemonize if @options[:daemonize]
140
+
141
+ # +config+ must be called before changing privileges since it might require superuser power.
142
+ server.config
143
+
144
+ server.change_privilege @options[:user], @options[:group] if @options[:user] && @options[:group]
145
+
146
+ # If a prefix is required, wrap in Rack URL mapper
147
+ server.app = Rack::URLMap.new(@options[:path] => server.app) if @options[:path]
148
+
149
+ # If a stats URL is specified, wrap in Stats adapter
150
+ server.app = Thin::Stats::Adapter.new(server.app, @options[:stats]) if @options[:stats]
151
+
152
+ # Register restart procedure which just start another process with same options,
153
+ # so that's why this is done here.
154
+ server.on_restart { Thin::Command.run(:start, @options) }
155
+
156
+ server.start
157
+ end
158
+
159
+ end # class ThinServer
160
+
161
+ end # module PHPRPC
@@ -0,0 +1,139 @@
1
+ ############################################################
2
+ # #
3
+ # The implementation of PHPRPC Protocol 3.0 #
4
+ # #
5
+ # webrick_server.rb #
6
+ # #
7
+ # Release 3.0.0 #
8
+ # Copyright (c) 2005-2008 by Team-PHPRPC #
9
+ # #
10
+ # WebSite: http://www.phprpc.org/ #
11
+ # http://www.phprpc.net/ #
12
+ # http://www.phprpc.com/ #
13
+ # http://sourceforge.net/projects/php-rpc/ #
14
+ # #
15
+ # Authors: Ma Bingyao <andot@ujn.edu.cn> #
16
+ # #
17
+ # This file may be distributed and/or modified under the #
18
+ # terms of the GNU Lesser General Public License (LGPL) #
19
+ # version 3.0 as published by the Free Software Foundation #
20
+ # and appearing in the included file LICENSE. #
21
+ # #
22
+ ############################################################
23
+ #
24
+ # PHPRPC WEBrickServer library.
25
+ #
26
+ # Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
27
+ # Version: 3.0
28
+ # LastModified: Sep 12, 2008
29
+ # This library is free. You can redistribute it and/or modify it.
30
+
31
+ require 'webrick'
32
+ require "phprpc/base_server"
33
+
34
+ module PHPRPC
35
+
36
+ class WEBrickServlet < BaseServer
37
+
38
+ def get_instance(*a)
39
+ self
40
+ end
41
+
42
+ def service(request, response)
43
+ env = request.meta_vars
44
+ env.delete_if { |k, v| v.nil? }
45
+ env["HTTPS"] = ENV["HTTPS"]
46
+ env["rack.input"] = StringIO.new(request.body.to_s)
47
+ env['rack.multithread'] = true # this variable only used for rack pool session on debug mode
48
+ env["rack.url_scheme"] = ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
49
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
50
+ env["QUERY_STRING"] ||= ""
51
+ env["REQUEST_PATH"] ||= "/"
52
+ status, headers, body = @app.call(env)
53
+ response.status = status.to_i
54
+ headers.each { |k, v| response[k] = v }
55
+ response.body = body
56
+ end
57
+
58
+ end # class WEBrickServlet
59
+
60
+ class WEBrickServer < WEBrickServlet
61
+
62
+ def initialize(options = {})
63
+ super()
64
+ @app = self
65
+ @options = {
66
+ :BindAddress => '0.0.0.0',
67
+ :Port => 3000,
68
+ :Logger => nil,
69
+ :MaxClients => 100,
70
+ :RequestTimeout => 30,
71
+ :session_mode => :file,
72
+ :path => "/",
73
+ :expire_after => 1800,
74
+ }.update(options)
75
+ @opts = OptionParser.new
76
+ @opts.banner = "Usage: #{@opts.program_name} webrick [options]"
77
+ @opts.separator ""
78
+ @opts.separator "Server options:"
79
+ @opts.on('-a', '--address IP', String, "Address to bind to (default: #{@options[:BindAddress]})") { |ip| @options[:BindAddress] = ip }
80
+ @opts.on('-p', '--port PORT', Integer, "Which port to bind to (default: #{@options[:Port]})") { |port| @options[:Port] = port }
81
+ @opts.on('-l', '--log FILE', String, "File to redirect output") { |file| @options[:Logger] = WEBrick::Log.new(file); }
82
+ @opts.on('-L', '--accesslog FILE', String, "File to redirect access info") { |file|
83
+ file = open(file, "a+")
84
+ @options[:AccessLog] = [
85
+ [ file, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
86
+ [ file, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
87
+ ]
88
+ }
89
+ @opts.separator ""
90
+ @opts.separator "Tuning options:"
91
+ @opts.on('-n', '--max-clients INT', Integer, "Maximum number of the concurrent", "connections (default: #{@options[:MaxClients]})") { |num| @options[:MaxClients] = num }
92
+ @opts.on('-t', '--timeout TIME', Integer, "Request timeout (in seconds)", "(default: #{@options[:RequestTimeout]})") { |time| @options[:RequestTimeout] = time }
93
+ @opts.separator ""
94
+ @opts.separator "Session options:"
95
+ @opts.on('-s', '--session-mode MODE', [:file, :memcache, :pool], "Select Session mode (file, memcache, pool)", "(default: #{@options[:session_mode].to_s})") { |mode| @options[:session_mode] = mode }
96
+ @opts.on('-e','--expire-after TIME', Integer, "Session expire after (default: #{@options[:expire_after]})") { |time| @options[:expire_after] = time }
97
+ @opts.on('-m','--memcache_server SERVER', String, "Memcache server used by session in", "memcache mode (default: localhost:11211)") { |server| @options[:memcache_server] = server }
98
+ @opts.on('--prefix PATH', String, "Mount the PHPRPC Server under PATH", "(start with /)") { |path| @options[:path] = path }
99
+ @opts.separator ""
100
+ @opts.separator "Common options:"
101
+ @opts.on_tail('-D', '--debug', "Set debbuging on (default: disabled)") { self.debug = true }
102
+ @opts.on_tail('-?', '-h', '--help', "Show this help message.") { puts @opts; exit }
103
+ @opts.on_tail('-v', '--version', "Show version") { puts "WEBrick/#{WEBrick::VERSION} (Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})"; exit }
104
+ begin
105
+ @opts.parse!(ARGV)
106
+ rescue OptionParser::ParseError
107
+ puts @opts
108
+ exit
109
+ end
110
+ end
111
+
112
+ def start
113
+ if [:memcache, :pool].include?(@options[:session_mode]) then
114
+ old_app = @app
115
+ begin
116
+ require 'rubygems'
117
+ require 'rack'
118
+ if @options[:session_mode] == :memcache then
119
+ @app = Rack::Session::Memcache.new(@app, @options)
120
+ else
121
+ @app = Rack::Session::Pool.new(@app, @options)
122
+ end
123
+ rescue Exception
124
+ @app = old_app
125
+ end
126
+ end
127
+ @options.delete(:ServerType)
128
+ @options.delete(:DocumentRoot)
129
+ @options.delete(:RequestCallback)
130
+ @options.delete(:RequestHandler)
131
+ server = WEBrick::HTTPServer.new(@options)
132
+ server.mount(@options[:path], self)
133
+ trap(:INT) { server.shutdown }
134
+ server.start
135
+ end
136
+
137
+ end # class WEBrickServer
138
+
139
+ end # module PHPRPC
data/lib/powmod.rb ADDED
@@ -0,0 +1,39 @@
1
+ ############################################################
2
+ # #
3
+ # The implementation of PHPRPC Protocol 3.0 #
4
+ # #
5
+ # powmod.rb #
6
+ # #
7
+ # Release 3.0.0 #
8
+ # Copyright (c) 2005-2008 by Team-PHPRPC #
9
+ # #
10
+ # WebSite: http://www.phprpc.org/ #
11
+ # http://www.phprpc.net/ #
12
+ # http://www.phprpc.com/ #
13
+ # http://sourceforge.net/projects/php-rpc/ #
14
+ # #
15
+ # Authors: Ma Bingyao <andot@ujn.edu.cn> #
16
+ # #
17
+ # This file may be distributed and/or modified under the #
18
+ # terms of the GNU Lesser General Public License (LGPL) #
19
+ # version 3.0 as published by the Free Software Foundation #
20
+ # and appearing in the included file LICENSE. #
21
+ # #
22
+ ############################################################
23
+ #
24
+ # Math.powmod
25
+ #
26
+ # Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
27
+ # Version: 1.0
28
+ # LastModified: Aug 21, 2008
29
+ # This library is free. You can redistribute it and/or modify it.
30
+
31
+ def Math.powmod(x, y, z)
32
+ r = 1
33
+ while y > 0
34
+ r = (r * x) % z if (y & 1) == 1
35
+ x = (x * x) % z
36
+ y >>= 1
37
+ end
38
+ return r
39
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phprpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - MA Bingyao ( andot )
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-16 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: andot@ujn.edu.cn
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - examples/client.rb
26
+ - examples/server.rb
27
+ - lib/crypt
28
+ - lib/crypt/xxtea.rb
29
+ - lib/dhparams
30
+ - lib/dhparams/1024.dhp
31
+ - lib/dhparams/128.dhp
32
+ - lib/dhparams/1536.dhp
33
+ - lib/dhparams/160.dhp
34
+ - lib/dhparams/192.dhp
35
+ - lib/dhparams/2048.dhp
36
+ - lib/dhparams/256.dhp
37
+ - lib/dhparams/3072.dhp
38
+ - lib/dhparams/4096.dhp
39
+ - lib/dhparams/512.dhp
40
+ - lib/dhparams/768.dhp
41
+ - lib/dhparams/96.dhp
42
+ - lib/php
43
+ - lib/php/formator.rb
44
+ - lib/phprpc
45
+ - lib/phprpc/base_server.rb
46
+ - lib/phprpc/cgi_server.rb
47
+ - lib/phprpc/client.rb
48
+ - lib/phprpc/ebb_server.rb
49
+ - lib/phprpc/fake_server.rb
50
+ - lib/phprpc/fcgi_server.rb
51
+ - lib/phprpc/lsapi_server.rb
52
+ - lib/phprpc/mongrel_server.rb
53
+ - lib/phprpc/scgi_server.rb
54
+ - lib/phprpc/server.rb
55
+ - lib/phprpc/thin_server.rb
56
+ - lib/phprpc/webrick_server.rb
57
+ - lib/phprpc.rb
58
+ - lib/powmod.rb
59
+ - AUTHORS
60
+ - examples
61
+ - lib
62
+ - LICENSE
63
+ - README
64
+ has_rdoc: false
65
+ homepage: http://phprpc.rubyforge.org/
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: phprpc
86
+ rubygems_version: 1.2.0
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: PHPRPC is a Remote Procedure Calling protocol that works over the Internet. It is secure and fast. It has a smaller overhead. It is powerful and easy to use. This project is the client and server implementations of the PHPRPC for Ruby.
90
+ test_files: []
91
+