eric-adhearsion 0.7.999 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +96 -24
- data/adhearsion.gemspec +148 -0
- data/app_generators/ahn/ahn_generator.rb +24 -9
- data/app_generators/ahn/templates/.ahnrc +25 -3
- data/app_generators/ahn/templates/Rakefile +22 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -0
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion.rb +17 -11
- data/lib/adhearsion/cli.rb +141 -24
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/events_support.rb +84 -0
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer.rb +229 -73
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk.rb +2 -2
- data/lib/adhearsion/voip/asterisk/agi_server.rb +9 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +106 -4
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/call.rb +51 -2
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/theatre.rb +151 -0
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- metadata +63 -138
- data/Manifest.txt +0 -149
- data/README.txt +0 -6
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/services/scheduler.rb +0 -5
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_helper.rb +0 -94
- data/spec/test_hooks.rb +0 -37
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -105
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -451
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -372
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -1,109 +0,0 @@
|
|
1
|
-
module Adhearsion
|
2
|
-
module VoIP
|
3
|
-
module Asterisk
|
4
|
-
class AMI
|
5
|
-
module Machine
|
6
|
-
%%{
|
7
|
-
machine ami;
|
8
|
-
|
9
|
-
cr = "\r";
|
10
|
-
lf = "\n";
|
11
|
-
crlf = cr lf;
|
12
|
-
|
13
|
-
action _key { mark("key") }
|
14
|
-
action key { set("key"); }
|
15
|
-
action _value { mark("value") }
|
16
|
-
action value { set("value"); }
|
17
|
-
Attr = [a-zA-Z\-]+ >_key %key ': ' (any* -- crlf) >_value %value crlf;
|
18
|
-
Privilege = "Privilege" >_key %key ': ' (any* -- crlf) >_value %value crlf;
|
19
|
-
ActionID = "ActionID" >_key %key ': ' (any* -- crlf) >_value %value crlf;
|
20
|
-
|
21
|
-
action _event { mark("event") }
|
22
|
-
action event { set("event"); @current_packet = EventPacket.new(@__ragel_event) }
|
23
|
-
Event = "Event: " alpha+ >_event %event crlf;
|
24
|
-
|
25
|
-
action _success { @current_packet = Packet.new; }
|
26
|
-
action _error { @current_packet = ErrorPacket.new; }
|
27
|
-
Response = "Response: ";
|
28
|
-
Success = Response "Success" >_success crlf;
|
29
|
-
Pong = Response "Pong" >_success crlf;
|
30
|
-
Error = Response "Error" >_error crlf;
|
31
|
-
Events = Response "Events " ("On" | "Off") >_success crlf;
|
32
|
-
|
33
|
-
action _follows { @current_packet = FollowsPacket.new; }
|
34
|
-
Follows = Response "Follows" >_follows crlf;
|
35
|
-
EndFollows = "--END COMMAND--" crlf;
|
36
|
-
|
37
|
-
# Capture the prompt. Signal any waiters.
|
38
|
-
Prompt = "Asterisk Call Manager/";
|
39
|
-
prompt := |*
|
40
|
-
graph+ >{ mark("version"); };
|
41
|
-
crlf >{ set("version"); @signal.signal } => { fgoto main; };
|
42
|
-
*|;
|
43
|
-
|
44
|
-
# For typical commands with responses with headers
|
45
|
-
response_normal := |*
|
46
|
-
Attr => { pair; };
|
47
|
-
crlf => { packet; fgoto main; };
|
48
|
-
*|;
|
49
|
-
|
50
|
-
# For immediate or raw commands
|
51
|
-
Raw = (any+ >{ mark_array("raw"); } -- lf) lf;
|
52
|
-
|
53
|
-
# For immediate or raw commands
|
54
|
-
Imm = (any+ >{ mark_array("raw") } -- crlf) crlf %{ insert("raw") };
|
55
|
-
|
56
|
-
# For raw commands
|
57
|
-
response_follows := |*
|
58
|
-
Privilege => { pair; };
|
59
|
-
ActionID => { pair; };
|
60
|
-
Raw => { insert("raw") };
|
61
|
-
EndFollows crlf => { packet; fgoto main; };
|
62
|
-
*|;
|
63
|
-
|
64
|
-
main := |*
|
65
|
-
Prompt @{ fgoto prompt; };
|
66
|
-
Success @{ fgoto response_normal; };
|
67
|
-
Pong @{ fgoto response_normal; };
|
68
|
-
Error @{ fgoto response_normal; };
|
69
|
-
Event @{ fgoto response_normal; };
|
70
|
-
Events @{ fgoto response_normal; };
|
71
|
-
Follows @{ fgoto response_follows; };
|
72
|
-
|
73
|
-
# Must also handle immediate responses with raw data
|
74
|
-
Imm crlf crlf => { @current_packet = ImmediatePacket.new; packet; };
|
75
|
-
*|;
|
76
|
-
}%%
|
77
|
-
|
78
|
-
class << self
|
79
|
-
def extended(base)
|
80
|
-
# Rename the Ragel variables. Not strictly necessary if
|
81
|
-
# we were to make accessors for them.
|
82
|
-
base.instance_eval do
|
83
|
-
%%{
|
84
|
-
variable p @__ragel_p;
|
85
|
-
variable pe @__ragel_pe;
|
86
|
-
variable cs @__ragel_cs;
|
87
|
-
variable act @__ragel_act;
|
88
|
-
variable data @__ragel_data;
|
89
|
-
variable tokstart @__ragel_tokstart;
|
90
|
-
variable tokend @__ragel_tokend;
|
91
|
-
write data nofinal;
|
92
|
-
}%%
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
def ragel_init
|
99
|
-
%% write init;
|
100
|
-
end
|
101
|
-
|
102
|
-
def ragel_exec
|
103
|
-
%% write exec;
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,262 +0,0 @@
|
|
1
|
-
require 'drb'
|
2
|
-
require 'adhearsion/voip/asterisk/ami/machine'
|
3
|
-
|
4
|
-
module Adhearsion
|
5
|
-
module VoIP
|
6
|
-
module Asterisk
|
7
|
-
class AMI
|
8
|
-
class Packet < Hash
|
9
|
-
def error?
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def raw?
|
14
|
-
false
|
15
|
-
end
|
16
|
-
|
17
|
-
def is_event?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
# Return the hash, without the internal Action ID
|
22
|
-
def body
|
23
|
-
returning clone do |packet|
|
24
|
-
packet.delete 'ActionID'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def message
|
29
|
-
self['Message']
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class EventPacket < Packet
|
34
|
-
attr_accessor :event
|
35
|
-
def initialize(event)
|
36
|
-
@event = event
|
37
|
-
super(false)
|
38
|
-
end
|
39
|
-
|
40
|
-
def is_event?
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class ErrorPacket < Packet
|
46
|
-
def error?
|
47
|
-
true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class FollowsPacket < Packet
|
52
|
-
def raw?
|
53
|
-
true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class ImmediatePacket < Packet
|
58
|
-
def raw?
|
59
|
-
true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Parser
|
64
|
-
# Size of the scanner buffer
|
65
|
-
BUFSIZE = 1024
|
66
|
-
|
67
|
-
attr_accessor :logger
|
68
|
-
attr_reader :events
|
69
|
-
|
70
|
-
def initialize
|
71
|
-
self.extend Machine
|
72
|
-
|
73
|
-
# Add the variables and accessors used for marking seen data
|
74
|
-
%w(event key value version).each do |name|
|
75
|
-
instance_eval <<-STR
|
76
|
-
class << self
|
77
|
-
send(:attr_accessor, "__ragel_mark_#{name}")
|
78
|
-
send(:attr_accessor, "__ragel_#{name}")
|
79
|
-
end
|
80
|
-
send("__ragel_mark_#{name}=", 0)
|
81
|
-
send("__ragel_#{name}=", nil)
|
82
|
-
STR
|
83
|
-
end
|
84
|
-
|
85
|
-
%w(raw).each do |name|
|
86
|
-
instance_eval <<-STR
|
87
|
-
class << self
|
88
|
-
send(:attr_accessor, "__ragel_mark_#{name}")
|
89
|
-
send(:attr_accessor, "__ragel_#{name}")
|
90
|
-
end
|
91
|
-
send("__ragel_mark_#{name}=", 0)
|
92
|
-
send("__ragel_#{name}=", [])
|
93
|
-
STR
|
94
|
-
end
|
95
|
-
@signal = ConditionVariable.new
|
96
|
-
@mutex = Mutex.new
|
97
|
-
@events = Queue.new
|
98
|
-
@current_packet = nil
|
99
|
-
@logger = Logger.new STDOUT
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
|
104
|
-
# Set the starting marker position
|
105
|
-
def mark(name)
|
106
|
-
send("__ragel_mark_#{name}=", @__ragel_p)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Set the starting marker position for capturing raw data in an array
|
110
|
-
def mark_array(name)
|
111
|
-
send("__ragel_mark_#{name}=", @__ragel_p)
|
112
|
-
end
|
113
|
-
|
114
|
-
# Capture the marked data from the marker to the current position
|
115
|
-
def set(name)
|
116
|
-
mark = send("__ragel_mark_#{name}")
|
117
|
-
return if @__ragel_p == mark
|
118
|
-
send("__ragel_#{name}=", @__ragel_data[mark..@__ragel_p-1])
|
119
|
-
send("__ragel_mark_#{name}=", 0)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Insert the data marked from the marker to the current position in the array
|
123
|
-
def insert(name)
|
124
|
-
mark = send("__ragel_mark_#{name}")
|
125
|
-
return if @__ragel_p == mark
|
126
|
-
var = send("__ragel_#{name}")
|
127
|
-
var << @__ragel_data[mark..@__ragel_p-1]
|
128
|
-
send("__ragel_#{name}=", var)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Capture a key / value pair in a response packet
|
132
|
-
def pair
|
133
|
-
@current_packet[@__ragel_key] = @__ragel_value
|
134
|
-
end
|
135
|
-
|
136
|
-
# This method completes a packet. Add the current raw data to it if it
|
137
|
-
# is an immediate or raw response packet. If it has an action ID, it belongs
|
138
|
-
# to a command, so signal any waiters. If it does not, it is an asynchronous
|
139
|
-
# event, so add it to the event queue.
|
140
|
-
def packet
|
141
|
-
return if not @current_packet
|
142
|
-
@current_packet[:raw] = @__ragel_raw.join("\n") if @current_packet.raw?
|
143
|
-
action_id = nil
|
144
|
-
if not @current_packet.is_event? or @current_packet['ActionID']
|
145
|
-
action_id = @current_packet['ActionID'] || 0
|
146
|
-
end
|
147
|
-
logger.debug "Packet end: #{@__ragel_p}, #{@current_packet.class}, #{action_id.inspect}"
|
148
|
-
logger.debug "=====>#{@current_packet[:raw]}<=====" if @current_packet.raw?
|
149
|
-
if action_id
|
150
|
-
# Packets with IDs are associated with the action of the same ID
|
151
|
-
action = Actions::Action[action_id]
|
152
|
-
action << @current_packet
|
153
|
-
else
|
154
|
-
# Asynchronous events without IDs go into the event queue
|
155
|
-
@events.push(@current_packet)
|
156
|
-
end
|
157
|
-
@signal.broadcast
|
158
|
-
@current_packet = nil
|
159
|
-
@__ragel_raw = []
|
160
|
-
end
|
161
|
-
|
162
|
-
public
|
163
|
-
# Wait for any packets (including events) that have the specified Action ID.
|
164
|
-
# Do not stop waiting until all of the packets for the specified Action ID
|
165
|
-
# have been seen.
|
166
|
-
def wait(action)
|
167
|
-
logger.debug "Waiting for #{action.action_id.inspect}"
|
168
|
-
@mutex.synchronize do
|
169
|
-
loop do
|
170
|
-
action.check_error!
|
171
|
-
return action.packets! if action.done?
|
172
|
-
@signal.wait(@mutex)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
# Receive an event packet from the event packet queue.
|
178
|
-
def receive
|
179
|
-
@events.pop
|
180
|
-
end
|
181
|
-
|
182
|
-
# Stop the scanner.
|
183
|
-
def stop
|
184
|
-
@mutex.synchronize do
|
185
|
-
@thread.kill if @thread
|
186
|
-
end
|
187
|
-
@thread = nil
|
188
|
-
end
|
189
|
-
|
190
|
-
# Run the scanner on the specified socket.
|
191
|
-
def run(socket)
|
192
|
-
@__ragel_eof = nil
|
193
|
-
@__ragel_data = " " * BUFSIZE
|
194
|
-
@__ragel_raw = []
|
195
|
-
|
196
|
-
ragel_init
|
197
|
-
|
198
|
-
# Synchronize, so we can wait for the command prompt before the
|
199
|
-
# scanner actually starts.
|
200
|
-
@mutex.synchronize do
|
201
|
-
@thread = Thread.new do
|
202
|
-
have = 0
|
203
|
-
loop do
|
204
|
-
# Grab as many bytes as we can for now.
|
205
|
-
space = BUFSIZE - have
|
206
|
-
raise RuntimeError, "No space" if space == 0
|
207
|
-
bytes = 0
|
208
|
-
begin
|
209
|
-
socket.synchronize do
|
210
|
-
if IO.select([socket], nil, nil, 1.0)
|
211
|
-
bytes = socket.read_nonblock(space)
|
212
|
-
else
|
213
|
-
retry
|
214
|
-
end
|
215
|
-
end
|
216
|
-
rescue Errno::EAGAIN
|
217
|
-
# Nothing available. Try again.
|
218
|
-
retry
|
219
|
-
rescue EOFError
|
220
|
-
# Socket closed. We are done.
|
221
|
-
break
|
222
|
-
end
|
223
|
-
|
224
|
-
# Adjust the pointers.
|
225
|
-
logger.debug "Got #{bytes.length} bytes, #{bytes.inspect}"
|
226
|
-
@__ragel_p = have
|
227
|
-
@__ragel_data[@__ragel_p..@__ragel_p + bytes.size - 1] = bytes
|
228
|
-
@__ragel_pe = @__ragel_p + bytes.size
|
229
|
-
logger.debug "P: #{@__ragel_p} PE: #{@__ragel_pe}"
|
230
|
-
|
231
|
-
# Run the scanner state machine.
|
232
|
-
@mutex.synchronize do
|
233
|
-
ragel_exec
|
234
|
-
end
|
235
|
-
|
236
|
-
if @__ragel_tokstart.nil? or @__ragel_tokstart == 0
|
237
|
-
have = 0
|
238
|
-
else
|
239
|
-
# Slide the window.
|
240
|
-
have = @__ragel_pe - @__ragel_tokstart
|
241
|
-
logger.debug "Sliding #{have} from #{@__ragel_tokstart} to 0 (tokend: #{@__ragel_tokend.inspect})"
|
242
|
-
@__ragel_data[0..have-1] = @__ragel_data[@__ragel_tokstart..@__ragel_tokstart + have - 1]
|
243
|
-
@__ragel_tokend -= @__ragel_tokstart if @__ragel_tokend
|
244
|
-
@__ragel_tokstart = 0
|
245
|
-
logger.debug "Data: #{@__ragel_data[0..have-1].inspect}"
|
246
|
-
end
|
247
|
-
end
|
248
|
-
@thread = nil
|
249
|
-
end
|
250
|
-
# Wait for the command prompt.
|
251
|
-
while @__ragel_version.blank?
|
252
|
-
@signal.wait(@mutex)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
# Return the version number.
|
256
|
-
@__ragel_version
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, "test_unit"]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, "test_unit"]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/fixtures/dialplan.rb
DELETED
@@ -1,267 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
|
3
|
-
context "Configuration defaults" do
|
4
|
-
include ConfigurationTestHelper
|
5
|
-
attr_reader :config
|
6
|
-
|
7
|
-
setup do
|
8
|
-
@config = default_config
|
9
|
-
end
|
10
|
-
|
11
|
-
test "incoming calls are answered by default" do
|
12
|
-
assert config.automatically_answer_incoming_calls
|
13
|
-
end
|
14
|
-
|
15
|
-
test "calls are ended when hung up" do
|
16
|
-
assert config.end_call_on_hangup
|
17
|
-
end
|
18
|
-
|
19
|
-
test "if an error occurs, a call is hungup" do
|
20
|
-
assert config.end_call_on_error
|
21
|
-
end
|
22
|
-
|
23
|
-
test "asterisk is enabled by default" do
|
24
|
-
assert config.asterisk_enabled?
|
25
|
-
end
|
26
|
-
|
27
|
-
test "default asterisk configuration is available" do
|
28
|
-
assert_kind_of Adhearsion::Configuration::AsteriskConfiguration, config.asterisk
|
29
|
-
end
|
30
|
-
|
31
|
-
test "database access is NOT enabled by default" do
|
32
|
-
assert !config.database_enabled?
|
33
|
-
end
|
34
|
-
|
35
|
-
test "freeswith is NOT enabled by default" do
|
36
|
-
assert !config.freeswitch_enabled?
|
37
|
-
end
|
38
|
-
|
39
|
-
test "AMI is NOT enabled by default" do
|
40
|
-
assert !config.asterisk.ami_enabled?
|
41
|
-
end
|
42
|
-
|
43
|
-
test "Drb is NOT enabled by default" do
|
44
|
-
assert !config.drb_enabled?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "Asterisk AGI configuration defaults" do
|
49
|
-
attr_reader :config
|
50
|
-
|
51
|
-
setup do
|
52
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration.new
|
53
|
-
end
|
54
|
-
|
55
|
-
test "asterisk configuration sets default listening port" do
|
56
|
-
config.listening_port.should.equal Adhearsion::Configuration::AsteriskConfiguration.default_listening_port
|
57
|
-
end
|
58
|
-
|
59
|
-
test "asterisk configuration sets default listening host" do
|
60
|
-
config.listening_host.should.equal Adhearsion::Configuration::AsteriskConfiguration.default_listening_host
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'Logging configuration' do
|
65
|
-
|
66
|
-
attr_reader :config
|
67
|
-
before :each do
|
68
|
-
@config = Adhearsion::Configuration.new
|
69
|
-
end
|
70
|
-
|
71
|
-
after :each do
|
72
|
-
Adhearsion::Logging.logging_level = :fatal
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'the logging level should translate from symbols into Log4r constants' do
|
76
|
-
Adhearsion::Logging.logging_level.should.not.equal Log4r::WARN
|
77
|
-
config.logging :level => :warn
|
78
|
-
Adhearsion::Logging.logging_level.should.equal Log4r::WARN
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
context "AMI configuration defaults" do
|
84
|
-
attr_reader :config
|
85
|
-
|
86
|
-
setup do
|
87
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.new
|
88
|
-
end
|
89
|
-
|
90
|
-
test "ami configuration sets default port" do
|
91
|
-
config.port.should.equal Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.default_port
|
92
|
-
end
|
93
|
-
|
94
|
-
test "ami allows you to configure a username and a password, both of which default to nil" do
|
95
|
-
config.username.should.be.nil
|
96
|
-
config.password.should.be.nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "Rails configuration defaults" do
|
101
|
-
test "should require the path to the Rails app in the constructor" do
|
102
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => "path here doesn't matter right now", :env => :development
|
103
|
-
config.rails_root.should.not.be.nil
|
104
|
-
end
|
105
|
-
|
106
|
-
test "should expand_path() the first constructor parameter" do
|
107
|
-
rails_root = "gui"
|
108
|
-
flexmock(File).should_receive(:expand_path).once.with(rails_root)
|
109
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => rails_root, :env => :development
|
110
|
-
end
|
111
|
-
|
112
|
-
test "should ensure that the environment provided is one supported by Rails" do
|
113
|
-
the_following_code {
|
114
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :this_is_not_a_rails_env
|
115
|
-
}.should.raise ArgumentError
|
116
|
-
|
117
|
-
the_following_code {
|
118
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :development
|
119
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :production
|
120
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :test
|
121
|
-
}.should.not.raise ArgumentError
|
122
|
-
end
|
123
|
-
|
124
|
-
test "should convert the environment into a Symbol" do
|
125
|
-
Adhearsion::Configuration::RailsConfiguration::SUPPORTED_RAILS_ENVIRONMENTS.should.not.be.empty
|
126
|
-
Adhearsion::Configuration::RailsConfiguration::SUPPORTED_RAILS_ENVIRONMENTS.each do |env|
|
127
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => env.to_s
|
128
|
-
config.environment.should.equal env
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "Database configuration defaults" do
|
134
|
-
|
135
|
-
setup do
|
136
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
137
|
-
Adhearsion::Configuration.configure {}
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should store the constructor's argument in connection_options()" do
|
141
|
-
sample_options = { :adapter => "sqlite3", :dbfile => "foo.sqlite3" }
|
142
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options)
|
143
|
-
config.connection_options.should.equal sample_options
|
144
|
-
end
|
145
|
-
it "should remove the :orm key from the connection options" do
|
146
|
-
sample_options = { :orm => :active_record, :adapter => "mysql", :host => "::1",
|
147
|
-
:user => "a", :pass => "b", :database => "ahn" }
|
148
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options.clone)
|
149
|
-
config.orm.should.equal sample_options.delete(:orm)
|
150
|
-
config.connection_options.should.equal sample_options
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "Freeswitch configuration defaults" do
|
155
|
-
attr_reader :config
|
156
|
-
|
157
|
-
setup do
|
158
|
-
@config = Adhearsion::Configuration::FreeswitchConfiguration.new
|
159
|
-
end
|
160
|
-
|
161
|
-
test "freeswitch configuration sets default listening port" do
|
162
|
-
config.listening_port.should.equal Adhearsion::Configuration::FreeswitchConfiguration.default_listening_port
|
163
|
-
end
|
164
|
-
|
165
|
-
test "freeswitch configuration sets default listening host" do
|
166
|
-
config.listening_host.should.equal Adhearsion::Configuration::FreeswitchConfiguration.default_listening_host
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "Configuration scenarios" do
|
171
|
-
include ConfigurationTestHelper
|
172
|
-
|
173
|
-
test "enabling AMI using all its defaults" do
|
174
|
-
config = enable_ami
|
175
|
-
|
176
|
-
assert config.asterisk.ami_enabled?
|
177
|
-
config.asterisk.ami.should.be.kind_of Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration
|
178
|
-
end
|
179
|
-
|
180
|
-
test "enabling AMI with custom configuration overrides the defaults" do
|
181
|
-
overridden_port = 911
|
182
|
-
config = enable_ami :port => overridden_port
|
183
|
-
config.asterisk.ami.port.should.equal overridden_port
|
184
|
-
end
|
185
|
-
|
186
|
-
test "enabling Drb without any configuration" do
|
187
|
-
config = enable_drb
|
188
|
-
assert config.drb
|
189
|
-
config.drb.should.be.kind_of Adhearsion::Configuration::DrbConfiguration
|
190
|
-
end
|
191
|
-
|
192
|
-
test "enabling Drb with a port specified sets the port" do
|
193
|
-
target_port = 911
|
194
|
-
config = enable_drb :port => target_port
|
195
|
-
config.drb.port.should.be.equal target_port
|
196
|
-
end
|
197
|
-
|
198
|
-
private
|
199
|
-
def enable_ami(*overrides)
|
200
|
-
default_config do |config|
|
201
|
-
config.asterisk.enable_ami(*overrides)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def enable_drb(*overrides)
|
206
|
-
default_config do |config|
|
207
|
-
config.enable_drb *overrides
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context "AHN_CONFIG" do
|
213
|
-
setup do
|
214
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
215
|
-
end
|
216
|
-
|
217
|
-
test "Running configure sets configuration to Adhearsion::AHN_CONFIG" do
|
218
|
-
assert !Adhearsion.const_defined?(:AHN_CONFIG)
|
219
|
-
Adhearsion::Configuration.configure do |config|
|
220
|
-
# Nothing needs to happen here
|
221
|
-
end
|
222
|
-
|
223
|
-
assert Adhearsion.const_defined?(:AHN_CONFIG)
|
224
|
-
Adhearsion::AHN_CONFIG.should.be.kind_of(Adhearsion::Configuration)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "DRb configuration" do
|
229
|
-
test "should not add any ACL rules when :raw_acl is passed in" do
|
230
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :raw_acl => :this_is_an_acl
|
231
|
-
config.acl.should.equal :this_is_an_acl
|
232
|
-
end
|
233
|
-
|
234
|
-
test "should, by default, allow only localhost connections" do
|
235
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
236
|
-
config.acl.should == %w[allow 127.0.0.1]
|
237
|
-
end
|
238
|
-
|
239
|
-
test "should add ACL 'deny' rules before 'allow' rules" do
|
240
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => %w[1.1.1.1 2.2.2.2],
|
241
|
-
:deny => %w[9.9.9.9]
|
242
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1 allow 2.2.2.2]
|
243
|
-
end
|
244
|
-
|
245
|
-
test "should allow both an Array and a String to be passed as an allow/deny ACL rule" do
|
246
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => "1.1.1.1", :deny => "9.9.9.9"
|
247
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1]
|
248
|
-
end
|
249
|
-
|
250
|
-
test "should have a default host and port" do
|
251
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
252
|
-
config.host.should.not.equal nil
|
253
|
-
config.port.should.not.equal nil
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|
257
|
-
|
258
|
-
BEGIN {
|
259
|
-
module ConfigurationTestHelper
|
260
|
-
def default_config(&block)
|
261
|
-
Adhearsion::Configuration.new do |config|
|
262
|
-
config.enable_asterisk
|
263
|
-
yield config if block_given?
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
}
|