Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

2.3.3 Added filters preview and custom commonName

-Added "-n" option for "gencerts" to allow you to define the commonName (this is useful when you have multiple certs)
-Added an early preview of filters for low level handling of arbitrary objects. Please provide feedback on these in the IRC chat!
-Added an inspect method to the SiriProxy::Plugin class.
-Added support for selecting a branch for plugins in the config.yml
  • Loading branch information...
commit 468b21998e8b8116a64d082bd811dbac33dad929 1 parent b8aef43
Pete plamoni authored
2  Gemfile
@@ -19,7 +19,7 @@ if config.plugins
19 19 if plugin.is_a? String
20 20 gem "siriproxy-#{plugin.downcase}"
21 21 else
22   - gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :require => plugin['require']
  22 + gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
23 23 end
24 24 end
25 25 end
6 lib/siriproxy/command_line.rb
@@ -98,9 +98,10 @@ def start_server
98 98 end
99 99
100 100 def gen_certs
  101 + ca_name = @ca_name ||= ""
101 102 command = File.join(File.dirname(__FILE__), '..', "..", "scripts", 'gen_certs.sh')
102 103 sp_root = File.join(File.dirname(__FILE__), '..', "..")
103   - puts `#{command} "#{sp_root}"`
  104 + puts `#{command} "#{sp_root}" "#{ca_name}"`
104 105 end
105 106
106 107 def update(directory=nil)
@@ -151,6 +152,9 @@ def parse_options
151 152 opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
152 153 @branch = branch
153 154 end
  155 + opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
  156 + @ca_name = ca_name
  157 + end
154 158 opts.on_tail('-v', '--version', ' show version') do
155 159 require "siriproxy/version"
156 160 puts "SiriProxy version #{SiriProxy::VERSION}"
9 lib/siriproxy/connection.rb
@@ -174,7 +174,12 @@ def prep_received_object(object)
174 174 pp object if $LOG_LEVEL > 3
175 175
176 176 #keeping this for filters
177   - object = received_object(object)
  177 + new_obj = received_object(object)
  178 + if new_obj == nil
  179 + puts "[Info - Dropping Object from #{self.name}] #{object["class"]}" if $LOG_LEVEL > 1
  180 + pp object if $LOG_LEVEL > 3
  181 + return nil
  182 + end
178 183
179 184 #block the rest of the session if a plugin claims ownership
180 185 speech = SiriProxy::Interpret.speech_recognized(object)
@@ -193,7 +198,7 @@ def prep_received_object(object)
193 198
194 199 #Stub -- override in subclass
195 200 def received_object(object)
196   -
  201 +
197 202 object
198 203 end
199 204
4 lib/siriproxy/connection/guzzoni.rb
@@ -13,8 +13,8 @@ def connection_completed
13 13 end
14 14
15 15 def received_object(object)
16   - object
17   -
  16 + return plugin_manager.process_filters(object, :from_guzzoni)
  17 +
18 18 #plugin_manager.object_from_guzzoni(object, self)
19 19 end
20 20
3  lib/siriproxy/connection/iphone.rb
@@ -24,7 +24,8 @@ def ssl_handshake_completed
24 24 end
25 25
26 26 def received_object(object)
27   - object
  27 + return plugin_manager.process_filters(object, :from_iphone)
  28 +
28 29 #plugin_manager.object_from_client(object, self)
29 30 end
30 31 end
34 lib/siriproxy/plugin.rb
@@ -6,8 +6,9 @@ def request_completed
6 6 end
7 7
8 8 #use send_object(object, target: :guzzoni) to send to guzzoni
9   - def send_object(object, options={:target => :iphone})
  9 + def send_object(object, options={})
10 10 (object = object.to_hash) rescue nil #convert SiriObjects to a hash
  11 + options[:target] = options[:target] ||= :iphone
11 12
12 13 if(options[:target] == :iphone)
13 14 self.manager.guzzoni_conn.inject_object_to_output_stream(object)
@@ -19,4 +20,35 @@ def send_object(object, options={:target => :iphone})
19 20 def last_ref_id
20 21 self.manager.iphone_conn.last_ref_id
21 22 end
  23 +
  24 + #direction should be :from_iphone, or :from_guzzoni
  25 + def process_filters(object, direction)
  26 + return nil if object == nil
  27 + f = filters[object["class"]]
  28 + if(f != nil && (f[:direction] == :both || f[:direction] == direction))
  29 + object = instance_exec(object, &f[:block])
  30 + end
  31 +
  32 + object
  33 + end
  34 +
  35 + class << self
  36 + def filter(class_names, options={}, &block)
  37 + [class_names].flatten.each do |class_name|
  38 + filters[class_name] = {
  39 + direction: (options[:direction] ||= :both),
  40 + block: block
  41 + }
  42 + end
  43 + end
  44 +
  45 + def filters
  46 + @filters ||= {}
  47 + end
  48 + end
  49 +
  50 + def filters
  51 + self.class.filters
  52 + end
  53 +
22 54 end
12 lib/siriproxy/plugin_manager.rb
@@ -28,6 +28,18 @@ def load_plugins()
28 28 log "Plugins laoded: #{@plugins}"
29 29 end
30 30
  31 + def process_filters(object, direction)
  32 + object_class = object.class #This way, if we change the object class we won't need to modify this code.
  33 + plugins.each do |plugin|
  34 + #log "Processing filters on #{plugin} for '#{object["class"]}'"
  35 + new_obj = plugin.process_filters(object, direction)
  36 + object = new_obj if(new_obj == false || new_obj.class == object_class) #prevent accidental poorly formed returns
  37 + return nil if object == false #if any filter returns "false," then the object should be dropped
  38 + end
  39 +
  40 + return object
  41 + end
  42 +
31 43 def process(text)
32 44 result = super(text)
33 45 self.guzzoni_conn.block_rest_of_session if result
2  lib/siriproxy/version.rb
... ... @@ -1,3 +1,3 @@
1 1 class SiriProxy
2   - VERSION = "0.2.2"
  2 + VERSION = "0.2.3"
3 3 end
13 plugins/siriproxy-example/lib/siriproxy-example.rb
... ... @@ -1,5 +1,6 @@
1 1 require 'cora'
2 2 require 'siri_objects'
  3 +require 'pp'
3 4
4 5 #######
5 6 # This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds
@@ -14,6 +15,18 @@ def initialize(config)
14 15 #if you have custom configuration options, process them here!
15 16 end
16 17
  18 + #get the user's location and display it in the logs
  19 + #filters are still in their early stages. Their interface may be modified
  20 + filter "SetRequestOrigin", direction: :from_iphone do |object|
  21 + puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"
  22 +
  23 + #Note about returns from filters:
  24 + # - Return false to stop the object from being forwarded
  25 + # - Return a Hash to substitute or update the object
  26 + # - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
  27 + # modifications made to it)
  28 + end
  29 +
17 30 listen_for /test siri proxy/i do
18 31 say "Siri Proxy is up and running!" #say something to the user!
19 32
7 scripts/gen_certs.sh
... ... @@ -1,5 +1,11 @@
1 1 #!/usr/bin/env bash
2 2
  3 +commonName=$2
  4 +
  5 +if [ "${commonName}" == "" ]
  6 +then
  7 + commonName="SiriProxyCA"
  8 +fi
3 9
4 10 # Feel free to change any of these defaults
5 11 countryName="US"
@@ -7,7 +13,6 @@ stateOrProvinceName="Missouri"
7 13 localityName=""
8 14 organizationName="Siri Proxy"
9 15 organizationalUnitName=""
10   -commonName="SiriProxyCA"
11 16 emailAddress=""
12 17
13 18 #You probably don't need to modify these unless you know what you're doing.

0 comments on commit 468b219

Please sign in to comment.
Something went wrong with that request. Please try again.