sant0sk1-adhearsion 0.7.999
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +456 -0
- data/README.txt +5 -0
- data/Rakefile +75 -0
- data/adhearsion.gemspec +136 -0
- data/app_generators/ahn/USAGE +5 -0
- data/app_generators/ahn/ahn_generator.rb +77 -0
- data/app_generators/ahn/templates/.ahnrc +36 -0
- data/app_generators/ahn/templates/README +8 -0
- data/app_generators/ahn/templates/Rakefile +18 -0
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/lib/simon_game.rb +61 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +14 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +31 -0
- data/app_generators/ahn/templates/config/startup.rb +53 -0
- data/app_generators/ahn/templates/dialplan.rb +4 -0
- data/bin/ahn +28 -0
- data/bin/ahnctl +68 -0
- data/bin/jahn +32 -0
- data/lib/adhearsion.rb +32 -0
- data/lib/adhearsion/blank_slate.rb +5 -0
- data/lib/adhearsion/cli.rb +106 -0
- data/lib/adhearsion/component_manager.rb +277 -0
- data/lib/adhearsion/core_extensions/all.rb +9 -0
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/custom_daemonizer.rb +45 -0
- data/lib/adhearsion/core_extensions/global.rb +1 -0
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/metaprogramming.rb +17 -0
- data/lib/adhearsion/core_extensions/numeric.rb +4 -0
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/publishable.rb +73 -0
- data/lib/adhearsion/core_extensions/relationship_properties.rb +40 -0
- data/lib/adhearsion/core_extensions/string.rb +26 -0
- data/lib/adhearsion/core_extensions/thread.rb +13 -0
- data/lib/adhearsion/core_extensions/thread_safety.rb +7 -0
- 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 +9 -0
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +9 -0
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +9 -0
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/events_support.rb +26 -0
- data/lib/adhearsion/hooks.rb +57 -0
- data/lib/adhearsion/host_definitions.rb +63 -0
- data/lib/adhearsion/initializer.rb +246 -0
- data/lib/adhearsion/initializer/asterisk.rb +59 -0
- data/lib/adhearsion/initializer/configuration.rb +236 -0
- data/lib/adhearsion/initializer/database.rb +49 -0
- data/lib/adhearsion/initializer/drb.rb +25 -0
- data/lib/adhearsion/initializer/freeswitch.rb +22 -0
- data/lib/adhearsion/initializer/rails.rb +40 -0
- data/lib/adhearsion/logging.rb +92 -0
- data/lib/adhearsion/tasks.rb +15 -0
- data/lib/adhearsion/tasks/database.rb +5 -0
- data/lib/adhearsion/tasks/generating.rb +20 -0
- data/lib/adhearsion/tasks/lint.rb +4 -0
- data/lib/adhearsion/tasks/testing.rb +37 -0
- data/lib/adhearsion/version.rb +9 -0
- data/lib/adhearsion/voip/asterisk.rb +10 -0
- data/lib/adhearsion/voip/asterisk/agi_server.rb +81 -0
- data/lib/adhearsion/voip/asterisk/ami.rb +147 -0
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +238 -0
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +871 -0
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +109 -0
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +262 -0
- data/lib/adhearsion/voip/asterisk/commands.rb +1284 -0
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +140 -0
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +101 -0
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +250 -0
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +240 -0
- data/lib/adhearsion/voip/asterisk/config_manager.rb +71 -0
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +80 -0
- data/lib/adhearsion/voip/call.rb +436 -0
- data/lib/adhearsion/voip/call_routing.rb +64 -0
- data/lib/adhearsion/voip/commands.rb +9 -0
- data/lib/adhearsion/voip/constants.rb +39 -0
- data/lib/adhearsion/voip/conveniences.rb +18 -0
- data/lib/adhearsion/voip/dial_plan.rb +207 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +151 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +37 -0
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +27 -0
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +124 -0
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +71 -0
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +16 -0
- data/lib/adhearsion/voip/dsl/numerical_string.rb +117 -0
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +48 -0
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +58 -0
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +129 -0
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +38 -0
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +195 -0
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +80 -0
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +123 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +58 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +149 -0
- metadata +167 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module VoIP
|
3
|
+
module CallRouting
|
4
|
+
class Rule
|
5
|
+
attr_reader :patterns, :providers, :options
|
6
|
+
|
7
|
+
def initialize(*args, &block)
|
8
|
+
@options = args.pop
|
9
|
+
@patterns = Array(args)
|
10
|
+
@providers = Array(options[:to])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class RuleSet < Array
|
15
|
+
def [](index)
|
16
|
+
case index
|
17
|
+
when String
|
18
|
+
detect do |rule|
|
19
|
+
rule.patterns.any? do |pattern|
|
20
|
+
index =~ pattern
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Router
|
30
|
+
class << self
|
31
|
+
attr_accessor :rules
|
32
|
+
|
33
|
+
def define(&block)
|
34
|
+
returning new do |router|
|
35
|
+
router.define(&block)
|
36
|
+
rules.concat router.rules
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def calculate_route_for(end_point)
|
41
|
+
if rule = rules[end_point.to_s]
|
42
|
+
rule.providers
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
self.rules ||= RuleSet.new
|
48
|
+
|
49
|
+
attr_reader :rules
|
50
|
+
def initialize
|
51
|
+
@rules = []
|
52
|
+
end
|
53
|
+
|
54
|
+
def define(&block)
|
55
|
+
instance_eval(&block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def route(*args, &block)
|
59
|
+
rules << Rule.new(*args, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Adhearsion, open source collaboration framework
|
2
|
+
# Copyright (C) 2006,2007,2008 Jay Phillips
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
module Adhearsion
|
19
|
+
module VoIP
|
20
|
+
|
21
|
+
# Please help adjust these if they may be inaccurate!
|
22
|
+
module Constants
|
23
|
+
US_LOCAL_NUMBER = /^[1-9]\d{6}$/
|
24
|
+
US_NATIONAL_NUMBER = /^1?[1-9]\d{2}[1-9]\d{6}$/
|
25
|
+
ISN = /^\d+\*\d+$/ # See http://freenum.org
|
26
|
+
SIP_URI = /^sip:[\w\._%+-]+@[\w\.-]+\.[a-zA-Z]{2,4}$/
|
27
|
+
|
28
|
+
# Type of Number definitions given over PRI. Taken from the Q.931-ITU spec, page 68.
|
29
|
+
Q931_TYPE_OF_NUMBER = Hash.new(:unknown).merge 0b001 => :international,
|
30
|
+
0b010 => :national,
|
31
|
+
0b011 => :network_specific,
|
32
|
+
0b100 => :subscriber,
|
33
|
+
0b110 => :abbreviated_number
|
34
|
+
end
|
35
|
+
|
36
|
+
include Constants
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module VoIP
|
3
|
+
module Conveniences
|
4
|
+
|
5
|
+
# Compiles the provided Asterisk dialplan pattern into a Ruby regular
|
6
|
+
# expression. For more usage of Asterisk's pattern syntax, see
|
7
|
+
# http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns
|
8
|
+
def _(pattern)
|
9
|
+
# Uncomment the following code fragment for complete compatibility.
|
10
|
+
# The fragment handles the seldom-used hyphen number spacer with no
|
11
|
+
# meaning.
|
12
|
+
Regexp.new '^' << pattern.# gsub(/(?!\[[\w+-]+)-(?![\w-]+\])/,'').
|
13
|
+
gsub('X', '[0-9]').gsub('Z', '[1-9]').gsub('N','[2-9]').
|
14
|
+
gsub('.','.+').gsub('!','.*') << '$'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# Hardcoding require for now since for some reason it's not being loaded
|
2
|
+
require 'adhearsion/blank_slate'
|
3
|
+
require 'adhearsion/component_manager'
|
4
|
+
require 'adhearsion/voip/dsl/dialplan/control_passing_exception'
|
5
|
+
|
6
|
+
module Adhearsion
|
7
|
+
class DialPlan
|
8
|
+
attr_accessor :loader, :entry_points
|
9
|
+
def initialize(loader = Loader)
|
10
|
+
@loader = loader
|
11
|
+
@entry_points = @loader.load_dial_plan.contexts
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Lookup and return an entry point by context name
|
16
|
+
#
|
17
|
+
def lookup(context_name)
|
18
|
+
entry_points[context_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Executable environment for a dial plan in the scope of a call. This class has all the dialplan methods mixed into it.
|
23
|
+
#
|
24
|
+
class ExecutionEnvironment
|
25
|
+
|
26
|
+
attr_reader :call
|
27
|
+
def initialize(call, entry_point=nil)
|
28
|
+
@call, @entry_point = call, entry_point
|
29
|
+
extend_with_voip_commands!
|
30
|
+
extend_with_call_variables!
|
31
|
+
extend_with_components_with_call_context!
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
raise "Cannot run ExecutionEnvironment without an entry point!" unless entry_point
|
36
|
+
current_context = entry_point
|
37
|
+
answer if AHN_CONFIG.automatically_answer_incoming_calls
|
38
|
+
begin
|
39
|
+
instance_eval(¤t_context)
|
40
|
+
rescue Adhearsion::VoIP::DSL::Dialplan::ControlPassingException => exception
|
41
|
+
current_context = exception.target
|
42
|
+
retry
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
attr_reader :entry_point
|
48
|
+
|
49
|
+
def extend_with_voip_commands!
|
50
|
+
extend(Adhearsion::VoIP::Conveniences)
|
51
|
+
extend(Adhearsion::VoIP::Commands.for(call.originating_voip_platform))
|
52
|
+
end
|
53
|
+
|
54
|
+
def extend_with_call_variables!
|
55
|
+
call.define_variable_accessors self
|
56
|
+
end
|
57
|
+
|
58
|
+
def extend_with_components_with_call_context!
|
59
|
+
ComponentManager.components_with_call_context.keys.each do |component_name|
|
60
|
+
eval <<-COMPONENT_BUILDER
|
61
|
+
def self.new_#{component_name.underscore}(*args, &block)
|
62
|
+
ComponentManager.components_with_call_context['#{component_name}'].instantiate_with_call_context(self, *args, &block)
|
63
|
+
end
|
64
|
+
COMPONENT_BUILDER
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Manager
|
70
|
+
|
71
|
+
class NoContextError < Exception; end
|
72
|
+
|
73
|
+
class << self
|
74
|
+
def handle(call)
|
75
|
+
new.handle(call)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
attr_accessor :dial_plan, :context
|
80
|
+
def initialize
|
81
|
+
@dial_plan = DialPlan.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle(call)
|
85
|
+
if call.failed_call?
|
86
|
+
environment = ExecutionEnvironment.new(call)
|
87
|
+
call.extract_failed_reason_from(environment)
|
88
|
+
raise FailedExtensionCallException.new(environment)
|
89
|
+
end
|
90
|
+
|
91
|
+
if call.hungup_call?
|
92
|
+
raise HungupExtensionCallException.new(ExecutionEnvironment.new(call))
|
93
|
+
end
|
94
|
+
|
95
|
+
starting_entry_point = entry_point_for call
|
96
|
+
raise NoContextError, "No dialplan entry point for call context '#{call.context}' -- Ignoring call!" unless starting_entry_point
|
97
|
+
|
98
|
+
@context = ExecutionEnvironment.new(call, starting_entry_point)
|
99
|
+
inject_context_names_into_environment(@context)
|
100
|
+
@context.run
|
101
|
+
end
|
102
|
+
|
103
|
+
# Find the dialplan by the context name from the call or from the
|
104
|
+
# first path entry in the AGI URL
|
105
|
+
def entry_point_for(call)
|
106
|
+
if entry_point = dial_plan.lookup(call.context.to_sym)
|
107
|
+
entry_point
|
108
|
+
elsif m = call.request.path.match(%r{/([^/]+)})
|
109
|
+
dial_plan.lookup(m[1].to_sym)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
protected
|
114
|
+
|
115
|
+
def inject_context_names_into_environment(environment)
|
116
|
+
return unless dial_plan.entry_points
|
117
|
+
dial_plan.entry_points.each do |name, context|
|
118
|
+
environment.meta_def(name) { context }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
class Loader
|
125
|
+
class << self
|
126
|
+
attr_accessor :default_dial_plan_file_name
|
127
|
+
|
128
|
+
def load(dial_plan_as_string)
|
129
|
+
returning new do |loader|
|
130
|
+
inject_dial_plan_component_classes_into dial_plan_as_string
|
131
|
+
loader.load(dial_plan_as_string)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def load_dial_plan(file_name = default_dial_plan_file_name)
|
136
|
+
load read_dialplan_file(AHN_ROOT.dial_plan_named(file_name))
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
def inject_dial_plan_component_classes_into(dial_plan_as_string)
|
141
|
+
dial_plan_as_string[0, 0] = ComponentManager.components_with_call_context.keys.map do |component|
|
142
|
+
"#{component} = ::Adhearsion::ComponentManager.components_with_call_context['#{component}'] unless defined? #{component}\n"
|
143
|
+
end.join
|
144
|
+
end
|
145
|
+
|
146
|
+
def read_dialplan_file(filename)
|
147
|
+
File.read filename
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
self.default_dial_plan_file_name ||= 'dialplan.rb'
|
153
|
+
|
154
|
+
attr_reader :contexts
|
155
|
+
def initialize
|
156
|
+
@contexts = {}
|
157
|
+
end
|
158
|
+
|
159
|
+
def load(dial_plan_as_string)
|
160
|
+
contexts.update(ContextNameCollector.build(dial_plan_as_string))
|
161
|
+
end
|
162
|
+
|
163
|
+
class ContextNameCollector# < ::BlankSlate
|
164
|
+
|
165
|
+
class << self
|
166
|
+
|
167
|
+
def build(dial_plan_as_string)
|
168
|
+
builder = new
|
169
|
+
builder.instance_eval(dial_plan_as_string)
|
170
|
+
builder.contexts
|
171
|
+
end
|
172
|
+
|
173
|
+
def const_missing(name)
|
174
|
+
super
|
175
|
+
rescue ArgumentError
|
176
|
+
raise NameError, %(undefined constant "#{name}")
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
attr_reader :contexts
|
182
|
+
def initialize
|
183
|
+
@contexts = {}
|
184
|
+
end
|
185
|
+
|
186
|
+
def method_missing(name, *args, &block)
|
187
|
+
super if !block_given? || args.any?
|
188
|
+
contexts[name] = DialplanContextProc.new(name, &block)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
class DialplanContextProc < Proc
|
193
|
+
|
194
|
+
attr_reader :name
|
195
|
+
|
196
|
+
def initialize(name, &block)
|
197
|
+
super(&block)
|
198
|
+
@name = name
|
199
|
+
end
|
200
|
+
|
201
|
+
def +@
|
202
|
+
raise Adhearsion::VoIP::DSL::Dialplan::ControlPassingException.new(self)
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# Adhearsion, open source collaboration framework
|
2
|
+
# Copyright (C) 2006,2007,2008 Jay Phillips
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
require 'adhearsion/core_extensions/metaprogramming'
|
19
|
+
require 'adhearsion/voip/conveniences'
|
20
|
+
require 'adhearsion/voip/constants'
|
21
|
+
require 'adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches'
|
22
|
+
|
23
|
+
module Adhearsion
|
24
|
+
module VoIP
|
25
|
+
module DSL
|
26
|
+
class DialingDSL
|
27
|
+
|
28
|
+
extend Conveniences
|
29
|
+
include Constants
|
30
|
+
|
31
|
+
Regexp.class_eval do
|
32
|
+
include Adhearsion::VoIP::DSL::DialingDSL::MonkeyPatches::RegexpMonkeyPatch
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.inherited(klass)
|
36
|
+
klass.class_eval do
|
37
|
+
[:@@providers, :@@routes].each do |var|
|
38
|
+
class_variable_set(var, [])
|
39
|
+
cattr_reader var.to_s.gsub('@@', '')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.calculate_routes_for(destination)
|
45
|
+
destination = destination.to_s
|
46
|
+
routes.select { |defined_route| defined_route === destination }.map &:providers
|
47
|
+
end
|
48
|
+
|
49
|
+
class ProviderDefinition < OpenStruct
|
50
|
+
|
51
|
+
def initialize(name)
|
52
|
+
super()
|
53
|
+
self.name = name.to_s.to_sym
|
54
|
+
end
|
55
|
+
|
56
|
+
def >>(other)
|
57
|
+
RouteRule.new :providers => [self, other]
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_number_for_platform(number, platform=:asterisk)
|
61
|
+
case platform
|
62
|
+
when :asterisk
|
63
|
+
[protocol || "SIP", name || "default", number].join '/'
|
64
|
+
else
|
65
|
+
raise "Unsupported platform #{platform}!"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_number_for_platform(number, platform=:asterisk)
|
70
|
+
case platform
|
71
|
+
when :asterisk
|
72
|
+
[protocol || "SIP", name || "default", number].join '/'
|
73
|
+
else
|
74
|
+
raise "Unsupported platform #{platform}!"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def defined_properties_without_name
|
79
|
+
returning @table.clone do |copy|
|
80
|
+
copy.delete :name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
def self.provider(name, &block)
|
89
|
+
raise ArgumentError, "no block given" unless block_given?
|
90
|
+
|
91
|
+
options = ProviderDefinition.new name
|
92
|
+
yield options
|
93
|
+
|
94
|
+
providers << options
|
95
|
+
meta_def(name) { options }
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.route(route)
|
99
|
+
routes << route
|
100
|
+
end
|
101
|
+
|
102
|
+
class RouteRule
|
103
|
+
|
104
|
+
attr_reader :patterns, :providers
|
105
|
+
|
106
|
+
def initialize(hash={})
|
107
|
+
@patterns = Array hash[:patterns]
|
108
|
+
@providers = Array hash[:providers]
|
109
|
+
end
|
110
|
+
|
111
|
+
def merge!(other)
|
112
|
+
providers.concat other.providers
|
113
|
+
patterns.concat other.patterns
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def >>(other)
|
118
|
+
case other
|
119
|
+
when RouteRule: merge! other
|
120
|
+
when ProviderDefinition: providers << other
|
121
|
+
else raise RouteException, "Unrecognized object in route definition: #{other.inspect}"
|
122
|
+
end
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def |(other)
|
127
|
+
case other
|
128
|
+
when RouteRule: merge! other
|
129
|
+
when Regexp
|
130
|
+
patterns << other
|
131
|
+
self
|
132
|
+
else raise other.inspect
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def ===(other)
|
137
|
+
patterns.each { |pattern| return true if pattern === other }
|
138
|
+
false
|
139
|
+
end
|
140
|
+
|
141
|
+
def unshift_pattern(pattern)
|
142
|
+
patterns.unshift pattern
|
143
|
+
end
|
144
|
+
|
145
|
+
class RouteException < Exception; end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|