adhearsion 1.2.6 → 2.0.0.alpha1
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.
- data/.gitignore +17 -10
- data/CHANGELOG.md +273 -0
- data/Gemfile +1 -1
- data/Guardfile +17 -0
- data/README.markdown +61 -9
- data/Rakefile +16 -48
- data/adhearsion.gemspec +21 -7
- data/bin/ahn +3 -1
- data/cucumber.yml +4 -0
- data/features/app_generator.feature +42 -0
- data/features/cli.feature +108 -0
- data/features/step_definitions/app_generator_steps.rb +6 -0
- data/features/step_definitions/cli_steps.rb +74 -0
- data/features/support/aruba_helper.rb +22 -0
- data/features/support/env.rb +37 -0
- data/features/support/utils.rb +8 -0
- data/lib/adhearsion.rb +85 -41
- data/lib/adhearsion/call.rb +176 -0
- data/lib/adhearsion/call_controller.rb +134 -0
- data/lib/adhearsion/call_controller/dial.rb +70 -0
- data/lib/adhearsion/call_controller/input.rb +173 -0
- data/lib/adhearsion/call_controller/menu.rb +124 -0
- data/lib/adhearsion/call_controller/output.rb +267 -0
- data/lib/adhearsion/call_controller/record.rb +42 -0
- data/lib/adhearsion/call_controller/utility.rb +60 -0
- data/lib/adhearsion/calls.rb +81 -0
- data/lib/adhearsion/cli.rb +1 -3
- data/lib/adhearsion/cli_commands.rb +142 -0
- data/lib/adhearsion/configuration.rb +149 -0
- data/lib/adhearsion/console.rb +19 -8
- data/lib/adhearsion/dialplan_controller.rb +9 -0
- data/lib/adhearsion/events.rb +84 -0
- data/lib/adhearsion/foundation/all.rb +0 -7
- data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
- data/lib/adhearsion/foundation/exception_handler.rb +9 -0
- data/lib/adhearsion/foundation/object.rb +26 -8
- data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
- data/lib/adhearsion/foundation/thread_safety.rb +17 -1
- data/lib/adhearsion/generators/app/app_generator.rb +4 -13
- data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
- data/lib/adhearsion/generators/app/templates/Procfile +1 -0
- data/lib/adhearsion/generators/app/templates/README.md +28 -0
- data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
- data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
- data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
- data/lib/adhearsion/initializer.rb +151 -293
- data/lib/adhearsion/initializer/logging.rb +33 -0
- data/lib/adhearsion/logging.rb +65 -69
- data/lib/adhearsion/menu_dsl.rb +15 -0
- data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
- data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
- data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
- data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
- data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
- data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
- data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
- data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
- data/lib/adhearsion/outbound_call.rb +64 -0
- data/lib/adhearsion/plugin.rb +319 -0
- data/lib/adhearsion/plugin/collection.rb +19 -0
- data/lib/adhearsion/plugin/initializer.rb +37 -0
- data/lib/adhearsion/plugin/methods_container.rb +6 -0
- data/lib/adhearsion/process.rb +94 -0
- data/lib/adhearsion/punchblock_plugin.rb +29 -0
- data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
- data/lib/adhearsion/router.rb +30 -0
- data/lib/adhearsion/router/route.rb +42 -0
- data/lib/adhearsion/script_ahn_loader.rb +2 -2
- data/lib/adhearsion/tasks.rb +14 -9
- data/lib/adhearsion/tasks/configuration.rb +26 -0
- data/lib/adhearsion/tasks/plugins.rb +17 -0
- data/lib/adhearsion/version.rb +8 -14
- data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
- data/spec/adhearsion/call_controller/input_spec.rb +278 -0
- data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
- data/spec/adhearsion/call_controller/output_spec.rb +466 -0
- data/spec/adhearsion/call_controller/record_spec.rb +125 -0
- data/spec/adhearsion/call_controller_spec.rb +395 -0
- data/spec/adhearsion/call_spec.rb +438 -0
- data/spec/adhearsion/calls_spec.rb +47 -0
- data/spec/adhearsion/configuration_spec.rb +308 -0
- data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
- data/spec/adhearsion/events_spec.rb +112 -0
- data/spec/adhearsion/initializer/logging_spec.rb +58 -0
- data/spec/adhearsion/initializer_spec.rb +209 -122
- data/spec/adhearsion/logging_spec.rb +58 -47
- data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
- data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
- data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
- data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
- data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
- data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
- data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
- data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
- data/spec/adhearsion/menu_dsl_spec.rb +12 -0
- data/spec/adhearsion/outbound_call_spec.rb +174 -0
- data/spec/adhearsion/plugin_spec.rb +489 -0
- data/spec/adhearsion/process_spec.rb +34 -0
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
- data/spec/adhearsion/router/route_spec.rb +99 -0
- data/spec/adhearsion/router_spec.rb +106 -0
- data/spec/adhearsion_spec.rb +46 -0
- data/spec/spec_helper.rb +14 -14
- data/spec/support/call_controller_test_helpers.rb +48 -0
- data/spec/support/initializer_stubs.rb +8 -13
- data/spec/support/punchblock_mocks.rb +6 -0
- metadata +255 -253
- data/CHANGELOG +0 -174
- data/bin/ahnctl +0 -68
- data/bin/jahn +0 -43
- data/examples/asterisk_manager_interface/standalone.rb +0 -51
- data/lib/adhearsion/commands.rb +0 -302
- data/lib/adhearsion/component_manager.rb +0 -278
- data/lib/adhearsion/component_manager/component_tester.rb +0 -54
- data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
- data/lib/adhearsion/events_support.rb +0 -65
- data/lib/adhearsion/foundation/blank_slate.rb +0 -3
- data/lib/adhearsion/foundation/event_socket.rb +0 -205
- data/lib/adhearsion/foundation/future_resource.rb +0 -36
- data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
- data/lib/adhearsion/foundation/numeric.rb +0 -13
- data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
- data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
- data/lib/adhearsion/foundation/string.rb +0 -26
- data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
- data/lib/adhearsion/generators/app/templates/README +0 -8
- data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
- data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
- data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
- data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
- data/lib/adhearsion/generators/app/templates/events.rb +0 -33
- data/lib/adhearsion/host_definitions.rb +0 -67
- data/lib/adhearsion/initializer/asterisk.rb +0 -86
- data/lib/adhearsion/initializer/configuration.rb +0 -324
- data/lib/adhearsion/initializer/database.rb +0 -60
- data/lib/adhearsion/initializer/drb.rb +0 -31
- data/lib/adhearsion/initializer/freeswitch.rb +0 -22
- data/lib/adhearsion/initializer/ldap.rb +0 -57
- data/lib/adhearsion/initializer/rails.rb +0 -41
- data/lib/adhearsion/initializer/xmpp.rb +0 -42
- data/lib/adhearsion/tasks/components.rb +0 -32
- data/lib/adhearsion/tasks/database.rb +0 -5
- data/lib/adhearsion/tasks/deprecations.rb +0 -59
- data/lib/adhearsion/tasks/generating.rb +0 -20
- data/lib/adhearsion/tasks/lint.rb +0 -4
- data/lib/adhearsion/voip/asterisk.rb +0 -4
- data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
- data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
- data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
- data/lib/adhearsion/voip/call.rb +0 -521
- data/lib/adhearsion/voip/call_routing.rb +0 -64
- data/lib/adhearsion/voip/commands.rb +0 -17
- data/lib/adhearsion/voip/constants.rb +0 -39
- data/lib/adhearsion/voip/conveniences.rb +0 -18
- data/lib/adhearsion/voip/dial_plan.rb +0 -252
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
- data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
- data/lib/adhearsion/xmpp/connection.rb +0 -61
- data/lib/theatre.rb +0 -147
- data/lib/theatre/README.markdown +0 -64
- data/lib/theatre/callback_definition_loader.rb +0 -86
- data/lib/theatre/guid.rb +0 -23
- data/lib/theatre/invocation.rb +0 -131
- data/lib/theatre/namespace_manager.rb +0 -153
- data/lib/theatre/version.rb +0 -2
- data/spec/adhearsion/cli_spec.rb +0 -306
- data/spec/adhearsion/component_manager_spec.rb +0 -292
- data/spec/adhearsion/constants_spec.rb +0 -8
- data/spec/adhearsion/drb_spec.rb +0 -65
- data/spec/adhearsion/fixtures/dialplan.rb +0 -3
- data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
- data/spec/adhearsion/host_definitions_spec.rb +0 -79
- data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
- data/spec/adhearsion/initializer/loading_spec.rb +0 -154
- data/spec/adhearsion/initializer/paths_spec.rb +0 -74
- data/spec/adhearsion/relationship_properties_spec.rb +0 -54
- data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
- data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
- data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
- data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
- data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
- data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
- data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
- data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
- data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
- data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
- data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
- data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
- data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
- data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
- data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
- data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
- data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
- data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
- data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
- data/spec/support/the_following_code.rb +0 -3
- data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
- data/spec/theatre/dsl_spec.rb +0 -69
- data/spec/theatre/invocation_spec.rb +0 -182
- data/spec/theatre/namespace_spec.rb +0 -125
- data/spec/theatre/spec_helper_spec.rb +0 -28
- data/spec/theatre/theatre_class_spec.rb +0 -148
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module Adhearsion
|
|
2
|
-
module VoIP
|
|
3
|
-
module DSL
|
|
4
|
-
class DialingDSL
|
|
5
|
-
module MonkeyPatches
|
|
6
|
-
module RegexpMonkeyPatch
|
|
7
|
-
|
|
8
|
-
def |(other)
|
|
9
|
-
case other
|
|
10
|
-
when RouteRule
|
|
11
|
-
other.unshift_pattern self
|
|
12
|
-
other
|
|
13
|
-
when Regexp
|
|
14
|
-
RouteRule.new :patterns => [self, other]
|
|
15
|
-
else
|
|
16
|
-
raise ArgumentError, "Unsupported pattern type #{other.inspect}"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def >>(other)
|
|
21
|
-
case other
|
|
22
|
-
when ProviderDefinition
|
|
23
|
-
RouteRule.new :patterns => self, :providers => other
|
|
24
|
-
when RouteRule
|
|
25
|
-
other.tap do |route|
|
|
26
|
-
route.unshift_pattern self
|
|
27
|
-
end
|
|
28
|
-
else raise ArgumentError, "Unsupported route definition #{other.inspect}"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Adhearsion
|
|
2
|
-
module VoIP
|
|
3
|
-
module DSL
|
|
4
|
-
module Dialplan
|
|
5
|
-
# A ControlPassingException is used internally to stop execution of one
|
|
6
|
-
# dialplan context and begin execution of another proc instead. It is
|
|
7
|
-
# most notably used by the ~@ unary operator that can be called on a
|
|
8
|
-
# context name within a dialplan to transfer control entirely to that
|
|
9
|
-
# particular context. The serve() method in the servlet_container actually
|
|
10
|
-
# rescues these exceptions specifically and then does +e.target to execute
|
|
11
|
-
# that code.
|
|
12
|
-
class ControlPassingException < StandardError
|
|
13
|
-
|
|
14
|
-
attr_reader :target
|
|
15
|
-
|
|
16
|
-
def initialize(target)
|
|
17
|
-
super()
|
|
18
|
-
@target = target
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
class ContextNotFoundException < StandardError; end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
module Adhearsion
|
|
2
|
-
module VoIP
|
|
3
|
-
module DSL
|
|
4
|
-
module Dialplan
|
|
5
|
-
|
|
6
|
-
class ReturnValue < StandardError
|
|
7
|
-
attr_reader :obj
|
|
8
|
-
def initialize(obj)
|
|
9
|
-
@obj = obj
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class Hangup < StandardError; end
|
|
15
|
-
|
|
16
|
-
# Instantiated and returned in every dialplan command
|
|
17
|
-
class EventCommand
|
|
18
|
-
|
|
19
|
-
attr_accessor :app, :args, :response_block, :returns, :on_keypress
|
|
20
|
-
|
|
21
|
-
def initialize(app, *args, &block)
|
|
22
|
-
@hash = args.pop if args.last.kind_of?(Hash)
|
|
23
|
-
@app, @args = app, args
|
|
24
|
-
|
|
25
|
-
if @hash
|
|
26
|
-
@returns = @hash[:returns] || :raw
|
|
27
|
-
@on_keypress = @hash[:on_keypress]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
@response_block = block if block_given?
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def on_keypress(&block)
|
|
34
|
-
block_given? ? @on_keypress = block : @on_keypress
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def on_break(&block)
|
|
38
|
-
block_given? ? @on_break = block : @on_break
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
class NoOpEventCommand < EventCommand
|
|
44
|
-
attr_reader :timeout, :on_keypress
|
|
45
|
-
def initialize(timeout=nil, hash={})
|
|
46
|
-
@timeout = timeout
|
|
47
|
-
@on_keypress = hash[:on_keypress]
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
class ExitingEventCommand < EventCommand; end
|
|
52
|
-
|
|
53
|
-
# Serves as a EventCommand proxy for handling EventCommands. Useful
|
|
54
|
-
# if doing any pre-processing.
|
|
55
|
-
#
|
|
56
|
-
# For example, when sending commands over the event socket to FreeSwitch,
|
|
57
|
-
# every command must start with "api", but, when doing an originate, it
|
|
58
|
-
# must begin with an ampersand. These two pre-processors would be developed
|
|
59
|
-
# as separate CommandDispatchers.
|
|
60
|
-
class CommandDispatcher
|
|
61
|
-
|
|
62
|
-
attr_reader :factory, :context
|
|
63
|
-
|
|
64
|
-
def initialize(factory, context=nil)
|
|
65
|
-
@context = context
|
|
66
|
-
@factory = factory.new context
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def dispatch!(event_command)
|
|
70
|
-
raise NotImplementedError, "Must subclass #{self.class} and override this!"
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def method_missing(name, *args, &block)
|
|
74
|
-
*commands = *@factory.send(name, *args, &block)
|
|
75
|
-
commands.map do |command|
|
|
76
|
-
if command.kind_of? Proc
|
|
77
|
-
instance_eval(&command)
|
|
78
|
-
elsif command.kind_of? EventCommand
|
|
79
|
-
dispatched_command = dispatch! command
|
|
80
|
-
if command.response_block
|
|
81
|
-
while (new_cmd = command.response_block.call(dispatched_command)).kind_of? EventCommand
|
|
82
|
-
dispatched_command = dispatch! new_cmd
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
dispatched_command
|
|
86
|
-
else
|
|
87
|
-
command
|
|
88
|
-
end
|
|
89
|
-
end.last
|
|
90
|
-
rescue ReturnValue => r
|
|
91
|
-
return r.obj
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def return!(obj)
|
|
95
|
-
raise DSL::Dialplan::ReturnValue.new(obj)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def break!(uuid=@context)
|
|
99
|
-
raise NotImplementedError, "Must subclass #{self.class} and override this!"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Takes a Hash and meta_def()'s a method for each key that returns
|
|
103
|
-
# the key's value in the Hash.
|
|
104
|
-
def def_keys!(hash)
|
|
105
|
-
hash.each_pair do |k,v|
|
|
106
|
-
meta_def(k) { v } rescue nil
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def clone
|
|
111
|
-
super.tap do |nemesis|
|
|
112
|
-
instance_variables.each do |iv|
|
|
113
|
-
value = instance_variable_get(iv)
|
|
114
|
-
nemesis.instance_variable_set iv, value.clone if value
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
require 'ostruct'
|
|
2
|
-
|
|
3
|
-
module Adhearsion
|
|
4
|
-
module VoIP
|
|
5
|
-
module DSL
|
|
6
|
-
module Dialplan
|
|
7
|
-
#TODO: This is obsolete, but we still need it for Freeswitch until we port that to the new 0.8.0 APIs
|
|
8
|
-
module DialplanParser
|
|
9
|
-
|
|
10
|
-
# Create a container and then clone that. when the container is created
|
|
11
|
-
# it should have all the contexts meta_def'd into it. for each call coming
|
|
12
|
-
# in, the cloned copy has the variables meta_def'd and set as instance
|
|
13
|
-
# variables
|
|
14
|
-
|
|
15
|
-
#TODO: separate into smaller pieces
|
|
16
|
-
def self.get_contexts
|
|
17
|
-
envelope = ContextsEnvelope.new
|
|
18
|
-
|
|
19
|
-
dialplans = AHN_CONFIG.files_from_setting "paths", "dialplan"
|
|
20
|
-
ahn_log.dialplan.warn "No dialplan files were found!" if dialplans.empty?
|
|
21
|
-
|
|
22
|
-
{}.tap do |contexts|
|
|
23
|
-
dialplans.each do |file|
|
|
24
|
-
raise "Dialplan file #{file} does not exist!" unless File.exists? file
|
|
25
|
-
envelope.instance_eval do
|
|
26
|
-
eval File.read(file)
|
|
27
|
-
end
|
|
28
|
-
current_contexts = envelope.parsed_contexts
|
|
29
|
-
current_contexts.each_pair do |name, block|
|
|
30
|
-
if contexts.has_key? name
|
|
31
|
-
warn %'Dialplan context "#{name}" exists in both #{contexts[name].file} and #{file}.' +
|
|
32
|
-
%' Using the "#{name}" context from #{contexts[name].file}.'
|
|
33
|
-
else
|
|
34
|
-
contexts[name] = OpenStruct.new.tap do |metadata|
|
|
35
|
-
metadata.file = file
|
|
36
|
-
metadata.name = name
|
|
37
|
-
metadata.block = block
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class ContextsEnvelope
|
|
47
|
-
|
|
48
|
-
keep = [:define_method, :instance_eval, :meta_def, :meta_eval, :metaclass, :methods, :object_id]
|
|
49
|
-
(instance_methods.map{|m| m.to_sym} - keep).each { |m| undef_method m unless m.to_s =~ /^__/ }
|
|
50
|
-
|
|
51
|
-
def initialize
|
|
52
|
-
@parsed_contexts = {}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
attr_reader :parsed_contexts
|
|
56
|
-
|
|
57
|
-
def method_missing(name, *args, &block)
|
|
58
|
-
super unless block_given?
|
|
59
|
-
@parsed_contexts[name] = block
|
|
60
|
-
meta_def(name) { block }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
module Adhearsion
|
|
2
|
-
module VoIP
|
|
3
|
-
module DSL
|
|
4
|
-
# In Ruby, a number with a leading zero such as 023.45 or 023 does not evaluate as expected.
|
|
5
|
-
# In the case of the float 023.45, you get a syntax error. In the case of 023 the number is
|
|
6
|
-
# parsed as being in octal form and the number 19 is returned.
|
|
7
|
-
#
|
|
8
|
-
# In Adhearsion, various strings that are entirely numeric might start with zero and that zero
|
|
9
|
-
# should be preserved when converting that string of numbers into a number. The numerical string
|
|
10
|
-
# retains the zero while still allowing it to be compared to other numbers.
|
|
11
|
-
#
|
|
12
|
-
# [[I think this leading zero thing is only part of the reason that NumericalString exists. I'm
|
|
13
|
-
# currently writing tests for this leading zero stuff so I thought I'd dump some of my assumptions
|
|
14
|
-
# about it here in the documentation.]]
|
|
15
|
-
class NumericalString
|
|
16
|
-
class << self
|
|
17
|
-
def starts_with_leading_zero?(string)
|
|
18
|
-
string.to_s[/^0\d+/]
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
(instance_methods.map{|m| m.to_sym} - [:instance_eval, :object_id, :class]).each { |m| undef_method m unless m.to_s =~ /^__/ }
|
|
23
|
-
|
|
24
|
-
attr_reader :__real_num, :__real_string
|
|
25
|
-
|
|
26
|
-
def initialize(str)
|
|
27
|
-
@__real_string = str.to_s
|
|
28
|
-
@__real_num = str.to_i if @__real_string =~ /^\d+$/
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def method_missing(name, *args, &block)
|
|
32
|
-
@__real_string.__send__ name, *args, &block
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def respond_to?(m)
|
|
36
|
-
@__real_string.respond_to?(m) || m == :__real_num || m == :__real_string
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def ==(x)
|
|
40
|
-
return x.is_a?(Fixnum) ? x == @__real_num : x == @__real_string
|
|
41
|
-
end
|
|
42
|
-
alias :=== :==
|
|
43
|
-
|
|
44
|
-
def is_a?(obj)
|
|
45
|
-
case obj.to_s
|
|
46
|
-
when "Fixnum" then true
|
|
47
|
-
when "String" then true
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
alias :kind_of? :is_a?
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# The PhoneNumber class is used by one object throughout Adhearsion: the AGI
|
|
55
|
-
# "extension" variable. Using some clevery Ruby hackery, the Extension class allows
|
|
56
|
-
# dialplan writers to use the best of Fixnum and String usage such as
|
|
57
|
-
#
|
|
58
|
-
# - Dialing international numbers
|
|
59
|
-
# - Using a regexp in a case statement for "extension"
|
|
60
|
-
# - Using a numerical range against extension -- e.g. (100...200)
|
|
61
|
-
# - Using the thousands separator
|
|
62
|
-
class PhoneNumber < NumericalString
|
|
63
|
-
|
|
64
|
-
# Checks against a pattern identifying US local numbers (i.e numbers
|
|
65
|
-
# without an area code seven digits long)
|
|
66
|
-
def us_local_number?() to_s =~ Adhearsion::VoIP::Constants::US_LOCAL_NUMBER end
|
|
67
|
-
|
|
68
|
-
# Checks against a pattern identifying US domestic numbers.
|
|
69
|
-
def us_national_number?() to_s =~ Adhearsion::VoIP::Constants::US_NATIONAL_NUMBER end
|
|
70
|
-
|
|
71
|
-
# Checks against a pattern identifying an ISN number. See http://freenum.org
|
|
72
|
-
# for more info.
|
|
73
|
-
def isn?() to_s =~ Adhearsion::VoIP::Constants::ISN end
|
|
74
|
-
|
|
75
|
-
# Useful for dialing those 1-800-FUDGEME type numbers with letters in them. Letters
|
|
76
|
-
# in the argument will be converted to their appropriate keypad key.
|
|
77
|
-
def self.from_vanity str
|
|
78
|
-
str.gsub(/\W/, '').upcase.tr('A-Z', '22233344455566677778889999')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# These monkey patches are necessary for the NumericalString to work, unfortunately.
|
|
88
|
-
class Class
|
|
89
|
-
def alias_method_once(new_name, old_name)
|
|
90
|
-
unless instance_methods.map{|m| m.to_sym}.include?(new_name.to_sym)
|
|
91
|
-
alias_method(new_name, old_name)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
[Object, Range, class << String; self; end].each do |klass|
|
|
97
|
-
klass.alias_method_once(:pre_modified_threequal, :===)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
class Object
|
|
101
|
-
def ===(arg)
|
|
102
|
-
if arg.respond_to? :__real_string
|
|
103
|
-
arg = arg.__real_num if kind_of?(Numeric) || kind_of?(Range)
|
|
104
|
-
pre_modified_threequal arg
|
|
105
|
-
else
|
|
106
|
-
pre_modified_threequal arg
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
class Range
|
|
112
|
-
alias_method_once(:original_threequal, :===)
|
|
113
|
-
def ===(arg)
|
|
114
|
-
if (arg.respond_to? :__real_string) && !arg.__real_num.nil?
|
|
115
|
-
arg = arg.__real_num
|
|
116
|
-
original_threequal arg
|
|
117
|
-
else
|
|
118
|
-
original_threequal arg
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
class << String
|
|
124
|
-
alias_method_once(:original_threequal, :===)
|
|
125
|
-
def ===(arg)
|
|
126
|
-
arg.respond_to?(:__real_string) || original_threequal(arg)
|
|
127
|
-
end
|
|
128
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module Adhearsion
|
|
2
|
-
module VoIP
|
|
3
|
-
module FreeSwitch
|
|
4
|
-
|
|
5
|
-
class BasicConnectionManager
|
|
6
|
-
|
|
7
|
-
def initialize(io)
|
|
8
|
-
@io = io
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# The send-command operator
|
|
12
|
-
def <<(str)
|
|
13
|
-
@io.write str + "\n\n"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def get_header
|
|
17
|
-
separate_pairs get_raw_header
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def get_raw_header
|
|
21
|
-
([].tap do |lines|
|
|
22
|
-
until line = @io.gets and line.chomp.empty?
|
|
23
|
-
lines << line.chomp
|
|
24
|
-
end
|
|
25
|
-
end) * "\n"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def next_event
|
|
29
|
-
header = get_raw_header
|
|
30
|
-
length = header.first[/\d+$/].to_i
|
|
31
|
-
# puts "Reading an event of #{length} bytes"
|
|
32
|
-
separate_pairs @io.read(length)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def separate_pairs(lines)
|
|
36
|
-
lines.split("\n").inject({}) do |h,line|
|
|
37
|
-
h.tap do |hash|
|
|
38
|
-
k,v = line.split(/\s*:\s*/)
|
|
39
|
-
hash[k] = URI.unescape(v).strip if k && v
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|