Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8e510e1
added the port number. For some reason the server wont bind auto on 443
jimmykane Mar 8, 2012
b9d4512
fixed
jimmykane Mar 8, 2012
c7fafe1
fixed typo
jimmykane Mar 8, 2012
a479cc2
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 9, 2012
99e6fac
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 11, 2012
e0b60cc
imported and set system encoding to utf-8 due to some plugins not wor…
jimmykane Mar 11, 2012
ce4cd45
sorry i had uploaded my server port
jimmykane Mar 11, 2012
819af51
Testing in public
jimmykane Mar 11, 2012
d4503a9
fixind already timeout connections trying to reset the schedule timer
jimmykane Mar 11, 2012
26ef1a0
delay set to 30 due to speech thinking and not request based. More po…
jimmykane Mar 11, 2012
0e905a5
delay set to 30 due to speech thinking and not request based. More po…
jimmykane Mar 11, 2012
3dc8419
fixed info
jimmykane Mar 11, 2012
203666d
goint to Jans
jimmykane Mar 12, 2012
c3b60e8
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 15, 2012
756748b
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 16, 2012
e7c0a5b
Added support for Chinese and other languages
jimmykane Mar 16, 2012
2440f6a
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 19, 2012
d2d6994
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 19, 2012
4d5358c
added support for forcelanguge argument and switched to arg parser
jimmykane Mar 19, 2012
56d9b79
added forcing of language plus FR and CH localizations on errors etc...
jimmykane Mar 19, 2012
73531ad
global config values
jimmykane Mar 19, 2012
3e58fbb
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 21, 2012
269e100
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 21, 2012
ba92f32
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 21, 2012
d00e126
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 25, 2012
6d7056a
latest
jimmykane Mar 26, 2012
4407955
Merge remote-tracking branch 'upstream/master'
jimmykane Mar 27, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions SiriProtocolHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import sqlite3
import time
import twisted
import config
import uuid




class SiriProtocolHandler(Siri):
__not_recognized = {"de-DE": u"Entschuldigung, ich verstehe \"{0}\" nicht.", "en-US": u"Sorry I don't understand {0}", "fr-FR": u"Désolé je ne comprends pas ce que \"{0}\" veut dire."}
__websearch = {"de-DE": u"Websuche", "en-US": u"Websearch", "fr-FR": u"Rechercher sur le Web"}
__not_recognized = {"de-DE": u"Entschuldigung, ich verstehe \"{0}\" nicht.", "en-US": u"Sorry, I don't understand {0}’.", "fr-FR": u"Désolé je ne comprends pas ce que \"{0}\" veut dire.", "zh-CN": u"对不起,我不知道“{0}”是什么意思。"}
__websearch = {"de-DE": u"Websuche", "en-US": u"Search the web", "fr-FR": u"Rechercher sur le Web", "zh-CN": u"搜索网页"}
__scheduling_interval_timeout__ = 20
__timeout_delay = 10

Expand Down Expand Up @@ -319,6 +318,14 @@ def received_plist(self, plist):
self.assistant.timeZoneId = objProperties['timeZoneId']
self.assistant.language = objProperties['language']
self.assistant.region = objProperties['region']
#Here it is possible to support more languages combined with anyvoice package
#We can make assumption that the region will define the language.
if config.forcelanguage==True:
#Chinese Example
if self.assistant.region=="zh-CN":
self.assistant.language = "zh-CN"
self.logger.debug("Forced language to {0}".format(self.assistant.language))

#Record the user firstName and nickName
try:
self.assistant.firstName = objProperties["meCards"][0]["properties"]["firstName"].encode("utf-8")
Expand All @@ -334,7 +341,7 @@ def received_plist(self, plist):
c.close()
except:
self.send_plist({"class":"CommandFailed", "properties": {"reason":"Database error", "errorCode":2, "callbacks":[]}, "aceId": str(uuid.uuid4()), "refId": plist['aceId'], "group":"com.apple.ace.system"})
self.logger.error("Database Error on setting assistant data")
self.logger.error("Error on setting assistant data")
else:
self.send_plist({"class":"CommandFailed", "properties": {"reason":"Assistant to set data not found", "errorCode":2, "callbacks":[]}, "aceId": str(uuid.uuid4()), "refId": plist['aceId'], "group":"com.apple.ace.system"})
self.logger.warning("Trying to set assistant data without having a valid assistant")
Expand Down
34 changes: 21 additions & 13 deletions SiriServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
exit(-1)

from SiriProtocolHandler import SiriProtocolHandler
from optparse import OptionParser
#switched to argparse due to optionparser is a depriciated module and connot handle empty argument values
import argparse
from os.path import exists
from socket import gethostname
import PluginManager
import db
import config
import logging
import sys

Expand Down Expand Up @@ -46,12 +48,12 @@ def __init__(self):
self.numberOfConnections = 0
self.sessionCert = None
self.sessionCACert = None
self.dbConnection = None
self.dbConnection = None

def buildProtocol(self, addr):
return SiriProtocolHandler(self, addr)

def startFactory(self):
def startFactory(self):
logging.getLogger().info("Loading Session Certificates")
caFile = open("keys/SessionCACert.pem")
self.sessionCACert = crypto.load_certificate(crypto.FILETYPE_PEM,caFile.read())
Expand Down Expand Up @@ -188,24 +190,30 @@ def create_self_signed_cert():

def main():

parser = OptionParser()
parser.add_option('-l', '--loglevel', default='info', dest='logLevel', help='This sets the logging level you have these options: debug, info, warning, error, critical \t\tThe standard value is info')
parser.add_option('-p', '--port', default=4443, type='int', dest='port', help='This options lets you use a custom port instead of 443 (use a port > 1024 to run as non root user)')
parser.add_option('--logfile', default=None, dest='logfile', help='Log to a file instead of stdout.')
(options, _) = parser.parse_args()
parser = argparse.ArgumentParser(description='SiriServerCore\n')
parser.add_argument('-l', '--loglevel', default='info', dest='logLevel', help='This sets the logging level you have these options: debug, info, warning, error, critical \t\tThe standard value is info')
parser.add_argument('-p', '--port', default=4443, type=int, dest='port', help='This options lets you use a custom port instead of 443 (use a port > 1024 to run as non root user)')
parser.add_argument('--logfile', default=None, dest='logfile', help='Log to a file instead of stdout.')
parser.add_argument('-f', '--forcelanguage', action='store_true', default=False, dest='forcelanguage', help='Force the server use language by region of device and ignore the Siri Settings language. Usefull with anyvoice cydia package. Adds functionallity for unsupported languages')
options = parser.parse_args()

x = logging.getLogger()
x.setLevel(log_levels[options.logLevel])

x.setLevel(log_levels[options.logLevel])
if options.logfile != None:
h = logging.FileHandler(options.logfile)
h = logging.FileHandler(options.logfile)
else:
h = logging.StreamHandler()

h = logging.StreamHandler()
f = logging.Formatter(u"%(levelname)s %(message)s")
h.setFormatter(f)
x.addHandler(h)

if options.forcelanguage != False:
config.forcelanguage=True
x.info("Forcing languages to device region and ignoring Siri Languge settings")
else:
config.forcelanguage=False

create_self_signed_cert()

try:
Expand Down
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#This can be used as a module to set some config values for all classes
#It is not thread safe! But is safe for per server run values
forcelanguage=False