adhearsion 1.2.6 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,64 +0,0 @@
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
- new.tap 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
@@ -1,17 +0,0 @@
1
- module Adhearsion
2
- module VoIP
3
- module Commands
4
- def self.for(platform_name)
5
- Adhearsion::VoIP.const_get(platform_name.to_s.classify).const_get("Commands")
6
- end
7
- end
8
-
9
- class PlaybackError < StandardError
10
- # Represents failure to play audio, such as when the sound file cannot be found
11
- end
12
-
13
- class RecordError < StandardError
14
- # Represents failure to record such as when a file cannot be written.
15
- end
16
- end
17
- end
@@ -1,39 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,252 +0,0 @@
1
- # Hardcoding require for now since for some reason it's not being loaded
2
- require 'adhearsion/voip/dsl/dialplan/control_passing_exception'
3
-
4
- require 'adhearsion/version'
5
- # JRuby contains a bug that breaks some of the menu functionality
6
- # See: https://adhearsion.lighthouseapp.com/projects/5871/tickets/92-menu-method-under-jruby-does-not-appear-to-work
7
- begin
8
- curver = Adhearsion::PkgVersion.new(JRUBY_VERSION)
9
- minver = Adhearsion::PkgVersion.new("1.6.0")
10
- if curver < minver
11
- puts "****************************************************************************"
12
- puts "Versions of JRuby prior to 1.6.0 contain a bug that impacts"
13
- puts "using the \"+\" operator to jump from one context to another."
14
- puts "Adhearsion has detected JRuby version #{JRUBY_VERSION}. For more information see:"
15
- puts "https://adhearsion.lighthouseapp.com/projects/5871/tickets/92-menu-method-under-jruby-does-not-appear-to-work"
16
- puts "****************************************************************************"
17
- end
18
- rescue NameError
19
- # In case JRUBY_VERSION is not defined.
20
- rescue ArgumentError
21
- # Needed to handle ActiveSupport's handling of missing constants
22
- # with anonymous modules under Ruby 1.9
23
- end
24
-
25
- module Adhearsion
26
- class DialPlan
27
- attr_accessor :loader, :entry_points
28
- def initialize(loader = Loader)
29
- @loader = loader
30
- @entry_points = @loader.load_dialplans.contexts
31
- end
32
-
33
- ##
34
- # Lookup and return an entry point by context name
35
- #
36
- def lookup(context_name)
37
- entry_points[context_name]
38
- end
39
-
40
- ##
41
- # Executable environment for a dial plan in the scope of a call. This class has all the dialplan methods mixed into it.
42
- #
43
- class ExecutionEnvironment
44
-
45
- class << self
46
- def create(*args)
47
- new(*args).tap { |instance| instance.stage! }
48
- end
49
- end
50
-
51
- attr_reader :call
52
- def initialize(call, entry_point)
53
- @call, @entry_point = call, entry_point
54
- end
55
-
56
- ##
57
- # Adds the methods to this ExecutionEnvironment which make it useful. e.g. dialplan-related methods, call variables,
58
- # and component methods.
59
- #
60
- def stage!
61
- extend_with_voip_commands!
62
- extend_with_call_variables!
63
- extend_with_dialplan_component_methods!
64
- end
65
-
66
- def run
67
- raise "Cannot run ExecutionEnvironment without an entry point!" unless entry_point
68
- current_context = entry_point
69
- answer if AHN_CONFIG.automatically_answer_incoming_calls
70
- begin
71
- instance_eval(&current_context)
72
- rescue Adhearsion::VoIP::DSL::Dialplan::ControlPassingException => exception
73
- current_context = exception.target
74
- retry
75
- end
76
- end
77
-
78
- protected
79
-
80
- attr_reader :entry_point
81
-
82
-
83
- def extend_with_voip_commands!
84
- extend Adhearsion::VoIP::Conveniences
85
- extend Adhearsion::VoIP::Commands.for(call.originating_voip_platform)
86
- end
87
-
88
- def extend_with_call_variables!
89
- call.define_variable_accessors self
90
- end
91
-
92
- def extend_with_dialplan_component_methods!
93
- Components.component_manager.extend_object_with(self, :dialplan) if Components.component_manager
94
- end
95
-
96
- end
97
-
98
- class Manager
99
-
100
- class NoContextError < StandardError; end
101
-
102
- class << self
103
- def handle(call)
104
- new.handle(call)
105
- end
106
- end
107
-
108
- attr_accessor :dial_plan, :context
109
- def initialize
110
- @dial_plan = DialPlan.new
111
- end
112
-
113
- def handle(call)
114
- if call.failed_call?
115
- environment = ExecutionEnvironment.create(call, nil)
116
- call.extract_failed_reason_from environment
117
- raise FailedExtensionCallException.new(environment)
118
- end
119
-
120
- if call.hungup_call?
121
- raise HungupExtensionCallException.new(ExecutionEnvironment.new(call, nil))
122
- end
123
-
124
- starting_entry_point = entry_point_for call
125
- raise NoContextError, "No dialplan entry point for call context '#{call.context}' -- Ignoring call!" unless starting_entry_point
126
- @context = ExecutionEnvironment.create(call, starting_entry_point)
127
- inject_context_names_into_environment @context
128
- @context.run
129
- end
130
-
131
- # Find the dialplan by the context name from the call or from the
132
- # first path entry in the AGI URL
133
- def entry_point_for(call)
134
-
135
- # Try the request URI for an entry point first
136
- if call.respond_to?(:request) && m = call.request.path.match(%r{/([^/]+)})
137
- if entry_point = dial_plan.lookup(m[1].to_sym)
138
- return entry_point
139
- else
140
- ahn_log.warn "AGI URI requested context \"#{m[1]}\" but matching Adhearsion context not found! Falling back to Asterisk context."
141
- end
142
- end
143
-
144
- # Fall back to the matching Asterisk context name
145
- if entry_point = dial_plan.lookup(call.context.to_sym)
146
- return entry_point
147
- end
148
- end
149
-
150
- protected
151
-
152
- def inject_context_names_into_environment(environment)
153
- return unless dial_plan.entry_points
154
- dial_plan.entry_points.each do |name, context|
155
- environment.meta_def(name) { context }
156
- end
157
- end
158
-
159
- end
160
-
161
- class Loader
162
- class << self
163
- attr_accessor :default_dial_plan_file_name
164
-
165
- def load(dial_plan_as_string)
166
- string_io = StringIO.new dial_plan_as_string
167
- def string_io.path
168
- "(eval)"
169
- end
170
- load_dialplans string_io
171
- end
172
-
173
- def load_dialplans(*files)
174
- files = Adhearsion::AHN_CONFIG.files_from_setting("paths", "dialplan") if files.empty?
175
- files = Array files
176
- files.map! do |file|
177
- case file
178
- when File, StringIO
179
- file
180
- when String
181
- File.new file
182
- else
183
- raise ArgumentError, "Unrecognized type of file #{file.inspect}"
184
- end
185
- end
186
- new.tap do |loader|
187
- files.each do |file|
188
- loader.load file
189
- end
190
- end
191
- end
192
-
193
- end
194
-
195
- self.default_dial_plan_file_name ||= 'dialplan.rb'
196
-
197
- def initialize
198
- @context_collector = ContextNameCollector.new
199
- end
200
-
201
- def contexts
202
- @context_collector.contexts
203
- end
204
-
205
- def load(dialplan_file)
206
- dialplan_code = dialplan_file.read
207
- @context_collector.instance_eval(dialplan_code, dialplan_file.path)
208
- ensure
209
- dialplan_file.close
210
- nil
211
- end
212
-
213
- class ContextNameCollector# < ::BlankSlate
214
-
215
- class << self
216
-
217
- def const_missing(name)
218
- super
219
- rescue ArgumentError
220
- raise NameError, %(undefined constant "#{name}")
221
- end
222
-
223
- end
224
-
225
- attr_reader :contexts
226
- def initialize
227
- @contexts = {}
228
- end
229
-
230
- def method_missing(name, *args, &block)
231
- super if !block_given? || args.any?
232
- contexts[name] = DialplanContextProc.new(name, &block)
233
- end
234
-
235
- end
236
- end
237
- class DialplanContextProc < Proc
238
-
239
- attr_reader :name
240
-
241
- def initialize(name, &block)
242
- super(&block)
243
- @name = name
244
- end
245
-
246
- def +@
247
- raise Adhearsion::VoIP::DSL::Dialplan::ControlPassingException.new(self)
248
- end
249
-
250
- end
251
- end
252
- end
@@ -1,151 +0,0 @@
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/foundation/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
- @table.clone.tap 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 then merge! other
120
- when ProviderDefinition then 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 then 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 < StandardError; end
146
-
147
- end
148
- end
149
- end
150
- end
151
- end