kipatra 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/kipatra +12 -5
- data/lib/kipatra.rb +13 -10
- data/lib/kipatra/sipatra.rb +30 -0
- data/lib/kipatra/version.rb +3 -0
- metadata +85 -66
- data/lib/sipatra/log4j-1.2.17.jar +0 -0
- data/lib/sipatra_app.rb +0 -39
data/bin/kipatra
CHANGED
@@ -6,7 +6,7 @@ require 'rubygems'
|
|
6
6
|
require 'kipatra'
|
7
7
|
require 'optparse'
|
8
8
|
|
9
|
-
options = {:udp => [], :tcp => [], :sipatra => false}
|
9
|
+
options = {:udp => [], :tcp => [], :sipatra => false, :example => false}
|
10
10
|
option_parser = OptionParser.new do |opts|
|
11
11
|
|
12
12
|
opts.on("-u UDP","--udp UDP") do |udp|
|
@@ -21,8 +21,12 @@ option_parser = OptionParser.new do |opts|
|
|
21
21
|
options[:tcp] << {:host => host, :port => port}
|
22
22
|
end
|
23
23
|
|
24
|
-
opts.on("-
|
25
|
-
options[:
|
24
|
+
opts.on("-w", "--war") do
|
25
|
+
options[:war] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-e EXAMPLE", "--example EXAMPLE") do |example_name|
|
29
|
+
options[:example] = example_name
|
26
30
|
end
|
27
31
|
end
|
28
32
|
option_parser.parse!
|
@@ -31,10 +35,13 @@ option_parser.parse!
|
|
31
35
|
#puts options.inspect
|
32
36
|
|
33
37
|
dir_or_file = ARGV.shift
|
38
|
+
if options[:example]
|
39
|
+
dir_or_file = File.join(File.dirname(__FILE__), '../examples', options[:example], 'sample.rb')
|
40
|
+
end
|
34
41
|
|
35
|
-
raise "No application to start." if dir_or_file.nil?
|
42
|
+
raise "No application (or WAR) to start." if dir_or_file.nil?
|
36
43
|
|
37
|
-
if
|
44
|
+
if options[:war]
|
38
45
|
options[:war] = dir_or_file
|
39
46
|
else
|
40
47
|
options[:app_file] = dir_or_file
|
data/lib/kipatra.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'kipatra/cipango'
|
2
|
+
require 'kipatra/sipatra'
|
2
3
|
|
3
4
|
module Kipatra
|
4
5
|
class Server
|
5
6
|
include Cipango
|
6
7
|
|
7
8
|
def initialize(opts)
|
8
|
-
@war, @app_file, @
|
9
|
-
# useless
|
9
|
+
@war, @app_file, @tcp, @udp = opts[:war], opts[:app_file], opts[:tcp], opts[:udp]
|
10
10
|
unless @war || @app_file
|
11
11
|
raise ArgumentError, "Either :war or :app_file must be defined"
|
12
12
|
end
|
@@ -35,6 +35,10 @@ module Kipatra
|
|
35
35
|
def manage_connectors
|
36
36
|
conns = []
|
37
37
|
|
38
|
+
if @udp.empty? and @tcp.empty?
|
39
|
+
@udp = [{:host => '0.0.0.0', :port => 5060}]
|
40
|
+
end
|
41
|
+
|
38
42
|
@udp.each do |args|
|
39
43
|
conn = UdpConnector.new
|
40
44
|
conn.host, conn.port = args[:host], args[:port]
|
@@ -56,16 +60,15 @@ module Kipatra
|
|
56
60
|
ctxt = SipAppContext.new
|
57
61
|
ctxt.context_path = '/'
|
58
62
|
ctxt.war = @war
|
59
|
-
elsif @sipatra
|
60
|
-
ctxt = SipAppContext.new('/', '/')
|
61
|
-
proc = Proc.new {}
|
62
|
-
servlet = eval(File.read(File.expand_path(File.join(File.dirname(__FILE__), '../lib/sipatra_app.rb'))), proc.binding, 'lib/sipatra_app.rb')
|
63
|
-
ctxt.add_sip_servlet SipServletHolder::new(servlet)
|
64
63
|
else
|
65
|
-
ctxt = SipAppContext.new('/', '
|
64
|
+
ctxt = SipAppContext.new('/', '.')
|
66
65
|
proc = Proc.new {}
|
67
|
-
|
68
|
-
|
66
|
+
begin
|
67
|
+
load @app_file
|
68
|
+
rescue Exception => e
|
69
|
+
raise "Sipatra Load Error : #{e.inspect}\n#{e.backtrace.join("\n")}"
|
70
|
+
end
|
71
|
+
ctxt.add_sip_servlet SipServletHolder.new(SipatraServlet.new)
|
69
72
|
end
|
70
73
|
|
71
74
|
ctxt
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sipatra'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Kipatra
|
5
|
+
class SipatraServlet < Kipatra::Cipango::SipServlet
|
6
|
+
def doRequest(req)
|
7
|
+
invoke req, :do_request
|
8
|
+
end
|
9
|
+
|
10
|
+
def doResponse(req)
|
11
|
+
invoke req, :do_response
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def invoke(msg, method_name)
|
17
|
+
begin
|
18
|
+
log = Logger.new(STDOUT)
|
19
|
+
app = Sipatra::Application::new
|
20
|
+
session = msg.session
|
21
|
+
app.set_bindings session.servlet_context, session.servlet_context.getAttribute(Kipatra::Cipango::SipServlet::SIP_FACTORY), session, msg, log
|
22
|
+
app.send method_name
|
23
|
+
rescue => e
|
24
|
+
# TODO XXX
|
25
|
+
puts "SIPATRA EXCEPTION: #{e}\n#{e.backtrace.join("\n")}"
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,85 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: kipatra
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
7
|
+
authors:
|
8
|
+
- Dominique Broeglin
|
9
|
+
- Alexandre Moutot
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
date: 2012-07-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sipatra
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.1.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rspec
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.0.0
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.0
|
26
47
|
description: Cipango powered Sipatra server
|
27
|
-
email:
|
28
|
-
|
29
|
-
|
48
|
+
email:
|
49
|
+
- dominique.broeglin@gmail.com
|
50
|
+
- alexscottt@gmail.com
|
51
|
+
executables:
|
52
|
+
- kipatra
|
30
53
|
extensions: []
|
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
|
-
- README.md
|
54
|
+
extra_rdoc_files:
|
55
|
+
- README.md
|
56
|
+
- LICENSES
|
57
|
+
files:
|
58
|
+
- lib/kipatra.rb
|
59
|
+
- lib/kipatra/cipango.rb
|
60
|
+
- lib/kipatra/cipango/cipango-dar-2.0.0.jar
|
61
|
+
- lib/kipatra/cipango/cipango-deploy-2.0.0.jar
|
62
|
+
- lib/kipatra/cipango/cipango-server-2.0.0.jar
|
63
|
+
- lib/kipatra/cipango/jetty-continuation-7.2.2.v20101205.jar
|
64
|
+
- lib/kipatra/cipango/jetty-http-7.2.2.v20101205.jar
|
65
|
+
- lib/kipatra/cipango/jetty-io-7.2.2.v20101205.jar
|
66
|
+
- lib/kipatra/cipango/jetty-security-7.2.2.v20101205.jar
|
67
|
+
- lib/kipatra/cipango/jetty-server-7.2.2.v20101205.jar
|
68
|
+
- lib/kipatra/cipango/jetty-servlet-7.2.2.v20101205.jar
|
69
|
+
- lib/kipatra/cipango/jetty-util-7.2.2.v20101205.jar
|
70
|
+
- lib/kipatra/cipango/jetty-webapp-7.2.2.v20101205.jar
|
71
|
+
- lib/kipatra/cipango/jetty-xml-7.2.2.v20101205.jar
|
72
|
+
- lib/kipatra/cipango/servlet-api-2.5.jar
|
73
|
+
- lib/kipatra/cipango/sip-api-1.1.jar
|
74
|
+
- lib/kipatra/sipatra.rb
|
75
|
+
- lib/kipatra/version.rb
|
76
|
+
- bin/kipatra
|
77
|
+
- LICENSES
|
78
|
+
- README.md
|
57
79
|
homepage: http://github.com/dbroeglin/kipatra
|
58
80
|
licenses: []
|
59
|
-
|
60
81
|
post_install_message:
|
61
|
-
rdoc_options:
|
62
|
-
|
63
|
-
require_paths:
|
64
|
-
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
87
|
none: false
|
67
|
-
requirements:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
93
|
none: false
|
73
|
-
requirements:
|
74
|
-
|
75
|
-
|
76
|
-
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
77
98
|
requirements: []
|
78
|
-
|
79
99
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.24
|
81
101
|
signing_key:
|
82
102
|
specification_version: 3
|
83
103
|
summary: Sipatra server powered by Cipango
|
84
104
|
test_files: []
|
85
|
-
|
Binary file
|
data/lib/sipatra_app.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'sipatra'
|
2
|
-
require 'sipatra/log4j-1.2.17.jar'
|
3
|
-
include_class "org.apache.log4j.Logger"
|
4
|
-
|
5
|
-
if File.exists?("log4j.properties")
|
6
|
-
include_class "org.apache.log4j.PropertyConfigurator"
|
7
|
-
PropertyConfigurator.configure("log4j.properties")
|
8
|
-
else
|
9
|
-
include_class "org.apache.log4j.BasicConfigurator"
|
10
|
-
BasicConfigurator.configure
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
load @app_file
|
15
|
-
rescue Exception => e
|
16
|
-
puts "Load Error : #{e.inspect}\n#{e.backtrace.join("\n")}"
|
17
|
-
end
|
18
|
-
|
19
|
-
class SipatraApp < Kipatra::Cipango::SipServlet
|
20
|
-
def doRequest(req)
|
21
|
-
invoke req, :do_request
|
22
|
-
end
|
23
|
-
|
24
|
-
def doResponse(req)
|
25
|
-
invoke req, :do_response
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def invoke(msg, method_name)
|
31
|
-
log = Logger.getLogger('Kipatra')
|
32
|
-
app = Sipatra::Application::new
|
33
|
-
session = msg.session
|
34
|
-
app.set_bindings session.servlet_context, session.servlet_context.getAttribute(Kipatra::Cipango::SipServlet::SIP_FACTORY), session, msg, log
|
35
|
-
app.send method_name
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
SipatraApp.new
|