def makeService(config): s = service.MultiService() # Create backend service with storage if config['backend'] == 'pgsql': from twisted.enterprise import adbapi from idavoll.pgsql_storage import Storage from psycopg2.extras import NamedTupleConnection dbpool = adbapi.ConnectionPool( 'psycopg2', user=config['dbuser'], password=config['dbpass'], database=config['dbname'], host=config['dbhost'], port=config['dbport'], cp_reconnect=True, client_encoding='utf-8', connection_factory=NamedTupleConnection, ) st = Storage(dbpool) elif config['backend'] == 'memory': from idavoll.memory_storage import Storage st = Storage() bs = BackendService(st) bs.setName('backend') bs.setServiceParent(s) # Set up XMPP server-side component with publish-subscribe capabilities cs = Component(config["rhost"], int(config["rport"]), config["jid"].full(), config["secret"]) cs.setName('component') cs.setServiceParent(s) cs.factory.maxDelay = 900 if config["verbose"]: cs.logTraffic = True FallbackHandler().setHandlerParent(cs) VersionHandler('Idavoll', __version__).setHandlerParent(cs) DiscoHandler().setHandlerParent(cs) resource = IPubSubResource(bs) resource.hideNodes = config["hide-nodes"] resource.serviceJID = config["jid"] ps = PubSubService(resource) ps.setHandlerParent(cs) resource.pubsubService = ps return s
def makeService(config): s = service.MultiService() # Create backend service with storage if config['backend'] == 'pgsql': from twisted.enterprise import adbapi from idavoll.pgsql_storage import Storage from psycopg2.extras import NamedTupleConnection dbpool = adbapi.ConnectionPool('psycopg2', user=config['dbuser'], password=config['dbpass'], database=config['dbname'], host=config['dbhost'], port=config['dbport'], cp_reconnect=True, client_encoding='utf-8', connection_factory=NamedTupleConnection, ) st = Storage(dbpool) elif config['backend'] == 'memory': from idavoll.memory_storage import Storage st = Storage() bs = BackendService(st) bs.setName('backend') bs.setServiceParent(s) # Set up XMPP server-side component with publish-subscribe capabilities cs = Component(config["rhost"], int(config["rport"]), config["jid"].full(), config["secret"]) cs.setName('component') cs.setServiceParent(s) cs.factory.maxDelay = 900 if config["verbose"]: cs.logTraffic = True FallbackHandler().setHandlerParent(cs) VersionHandler('Idavoll', __version__).setHandlerParent(cs) DiscoHandler().setHandlerParent(cs) resource = IPubSubResource(bs) resource.hideNodes = config["hide-nodes"] resource.serviceJID = config["jid"] ps = PubSubService(resource) ps.setHandlerParent(cs) resource.pubsubService = ps return s
from twisted.words.xish import domish application = service.Application("smsgateway") sc = service.IServiceCollection(application) # read configuration configuration.init() conf = configuration.getConfig() readXmlConfig("/opt/smsgateway/config.xml", configuration.getConfig()) # initialize database database.init(conf.mysqlHost, conf.mysqlUsername, conf.mysqlPassword, conf.mysqlDatabase) # start xmpp component xmpp = Component(conf.jabberHost, conf.jabberPort, conf.jabberComponentName, conf.jabberPassword) xmpp.logTraffic = False handler = XMPPComponent() handler.setHandlerParent(xmpp) # fallback handling generic.FallbackHandler().setHandlerParent(xmpp) # version handling generic.VersionHandler("SMS.de Gateway", "1.0").setHandlerParent(xmpp) # allow disco handling disco.DiscoHandler().setHandlerParent(xmpp) DiscoResponder().setHandlerParent(xmpp) # add handler for gateway requests
''' Created on Feb 24, 2012 @author: leen ''' import sys sys.path.append('../') from boardgame.zeromq.MsgQueue_XMPP import MsgQueue_XMPP from twisted.application import service from twisted.words.protocols.jabber import jid from twisted.internet import reactor from wokkel.component import Component from boardgame.xmpp.GameBotProtocol import GameBotProtocol from boardgame.xmpp.ThreadOutput import ThreadOutput from boardgame.main_config import XMPP_SERVICE_HOST, XMPP_SERVICE_PORT, XMPP_SERVICE_NAME, XMPP_SERVICE_PASSWORD, XMPP_SERVICE_LOG msgqueue = MsgQueue_XMPP() #msgqueue = None echobot = GameBotProtocol(component=True, socket=msgqueue) #ping_protocol = PingClientProtocol() thread_output = ThreadOutput(msgqueue, echobot) thread_output.start() application = service.Application("GameBot") xmppcomponent = Component(XMPP_SERVICE_HOST, XMPP_SERVICE_PORT, XMPP_SERVICE_NAME, XMPP_SERVICE_PASSWORD) xmppcomponent.logTraffic = XMPP_SERVICE_LOG echobot.setHandlerParent(xmppcomponent) xmppcomponent.setServiceParent(application) #reactor.run()