Skip to content
Permalink
Browse files

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...
plamoni committed Dec 4, 2011
1 parent b8aef43 commit 468b21998e8b8116a64d082bd811dbac33dad929
@@ -19,7 +19,7 @@ if config.plugins
if plugin.is_a? String
gem "siriproxy-#{plugin.downcase}"
else
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :require => plugin['require']
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
end
end
end
@@ -98,9 +98,10 @@ def start_server
end

def gen_certs
ca_name = @ca_name ||= ""
command = File.join(File.dirname(__FILE__), '..', "..", "scripts", 'gen_certs.sh')
sp_root = File.join(File.dirname(__FILE__), '..', "..")
puts `#{command} "#{sp_root}"`
puts `#{command} "#{sp_root}" "#{ca_name}"`
end

def update(directory=nil)
@@ -151,6 +152,9 @@ def parse_options
opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
@branch = branch
end
opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
@ca_name = ca_name
end
opts.on_tail('-v', '--version', ' show version') do
require "siriproxy/version"
puts "SiriProxy version #{SiriProxy::VERSION}"
@@ -174,7 +174,12 @@ def prep_received_object(object)
pp object if $LOG_LEVEL > 3

#keeping this for filters
object = received_object(object)
new_obj = received_object(object)
if new_obj == nil
puts "[Info - Dropping Object from #{self.name}] #{object["class"]}" if $LOG_LEVEL > 1
pp object if $LOG_LEVEL > 3
return nil
end

#block the rest of the session if a plugin claims ownership
speech = SiriProxy::Interpret.speech_recognized(object)
@@ -193,7 +198,7 @@ def prep_received_object(object)

#Stub -- override in subclass
def received_object(object)

object
end

@@ -13,8 +13,8 @@ def connection_completed
end

def received_object(object)
object
return plugin_manager.process_filters(object, :from_guzzoni)

#plugin_manager.object_from_guzzoni(object, self)
end

@@ -24,7 +24,8 @@ def ssl_handshake_completed
end

def received_object(object)
object
return plugin_manager.process_filters(object, :from_iphone)

#plugin_manager.object_from_client(object, self)
end
end
@@ -6,8 +6,9 @@ def request_completed
end

#use send_object(object, target: :guzzoni) to send to guzzoni
def send_object(object, options={:target => :iphone})
def send_object(object, options={})
(object = object.to_hash) rescue nil #convert SiriObjects to a hash
options[:target] = options[:target] ||= :iphone

if(options[:target] == :iphone)
self.manager.guzzoni_conn.inject_object_to_output_stream(object)
@@ -19,4 +20,35 @@ def send_object(object, options={:target => :iphone})
def last_ref_id
self.manager.iphone_conn.last_ref_id
end

#direction should be :from_iphone, or :from_guzzoni
def process_filters(object, direction)
return nil if object == nil
f = filters[object["class"]]
if(f != nil && (f[:direction] == :both || f[:direction] == direction))
object = instance_exec(object, &f[:block])
end

object
end

class << self
def filter(class_names, options={}, &block)
[class_names].flatten.each do |class_name|
filters[class_name] = {
direction: (options[:direction] ||= :both),
block: block
}
end
end

def filters
@filters ||= {}
end
end

def filters
self.class.filters
end

end
@@ -28,6 +28,18 @@ def load_plugins()
log "Plugins laoded: #{@plugins}"
end

def process_filters(object, direction)
object_class = object.class #This way, if we change the object class we won't need to modify this code.
plugins.each do |plugin|
#log "Processing filters on #{plugin} for '#{object["class"]}'"
new_obj = plugin.process_filters(object, direction)
object = new_obj if(new_obj == false || new_obj.class == object_class) #prevent accidental poorly formed returns
return nil if object == false #if any filter returns "false," then the object should be dropped
end

return object
end

def process(text)
result = super(text)
self.guzzoni_conn.block_rest_of_session if result
@@ -1,3 +1,3 @@
class SiriProxy
VERSION = "0.2.2"
VERSION = "0.2.3"
end
@@ -1,5 +1,6 @@
require 'cora'
require 'siri_objects'
require 'pp'

#######
# This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds
@@ -14,6 +15,18 @@ def initialize(config)
#if you have custom configuration options, process them here!
end

#get the user's location and display it in the logs
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"

#Note about returns from filters:
# - Return false to stop the object from being forwarded
# - Return a Hash to substitute or update the object
# - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
# modifications made to it)
end

listen_for /test siri proxy/i do
say "Siri Proxy is up and running!" #say something to the user!

@@ -1,13 +1,18 @@
#!/usr/bin/env bash

commonName=$2

if [ "${commonName}" == "" ]
then
commonName="SiriProxyCA"
fi

# Feel free to change any of these defaults
countryName="US"
stateOrProvinceName="Missouri"
localityName=""
organizationName="Siri Proxy"
organizationalUnitName=""
commonName="SiriProxyCA"
emailAddress=""

#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.
You can’t perform that action at this time.