Exemplo n.º 1
0
    def __init__(self, config):
        log("master: jid:%s" % (config.component, ))

        self.running = True
        self.connection = CONNECTION.idle

        self.config = config
        self.regdb = DatabaseAPI()

        Component.__init__(
            self,
            JID(config.component),
            config.secret,
            config.server,
            int(config.port),
            disco_name="Vipadia Ltd Skype Gateway",
            disco_type="skype",
            disco_category="gateway",
        )

        self.disco_info.add_feature('http://jabber.org/protocol/disco#info')
        self.disco_info.add_feature('jabber:iq:register')
        self.disco_info.add_feature('jabber:iq:time')
        self.disco_info.add_feature('jabber:iq:version')
        self.disco_info.add_feature('http://jabber.org/protocol/rosterx')
Exemplo n.º 2
0
Arquivo: chat.py Projeto: mor1/karaka
    def authenticated(self):
        dbg("authenticated: jid:%s" % (self.jid.as_utf8(),))
        
        self.connection = CONNECTION.connected
        Component.authenticated(self)
        
        self.stream.set_iq_get_handler("query", "jabber:iq:version",  self.get_version)
        self.stream.set_iq_get_handler("query", "jabber:iq:register", self.get_register)
        self.stream.set_iq_set_handler("query", "jabber:iq:register", self.set_register)

        self.stream.set_presence_handler("available",    self.presence_available)
        self.stream.set_presence_handler("unavailable",  self.presence_unavailable)
        self.stream.set_presence_handler("error",        self.presence_error)        
        self.stream.set_presence_handler("probe",        self.probe)        

        self.stream.set_presence_handler("subscribe",    self.subscribe)
        self.stream.set_presence_handler("subscribed",   self.subscribed)

        self.stream.set_presence_handler("unsubscribe",  self.unsubscribe)
        self.stream.set_presence_handler("unsubscribed", self.unsubscribed)

        ## default handlers
        self.stream.set_message_handler("normal", self.default_handler)

        self.default_presence_handler = self.stream.process_presence
        self.stream.process_presence = self.default_handler

        ## not possible to set a default IQ handler since all IQs either handled
        ## by user handler, or cause feature-not-implemented or bad-request to
        ## be sent
        
        self.stream.set_iq_set_handler(
            "x", "http://jabber.org/protocol/rosterx", self.default_handler)
        self.stream.set_iq_set_handler(
            "command", "http://vipadia.com/skype", self.vipadia_command)
Exemplo n.º 3
0
    def authenticated(self):
        Component.authenticated(self)

        handle_presence = getattr(self, 'handle_presence', None)
        if callable(handle_presence):
            self.stream.set_presence_handler("available", handle_presence)
            self.stream.set_presence_handler("unavailable", handle_presence)

        handle_subscribe = getattr(self, 'handle_subscribe', None)
        if callable(handle_subscribe):
            self.stream.set_presence_handler("subscribe", handle_subscribe)
            self.stream.set_presence_handler("subscribed", handle_subscribe)
            self.stream.set_presence_handler("unsubscribe", handle_subscribe)
            self.stream.set_presence_handler("unsubscribed", handle_subscribe)

        handle_error = getattr(self, 'handle_error', None)
        if callable(handle_error):
            self.stream.set_presence_handler("error", handle_error)

        handle_message = getattr(self, 'handle_message', None)
        if callable(handle_message):
            self.stream.set_message_handler('normal', handle_message)
 
        handle_connect = getattr(self, 'handle_connect', None)
        if callable(handle_connect):
            handle_connect()
Exemplo n.º 4
0
    def __init__(self, jid, secret, server, port, **options):
        if not isinstance(jid, JID):
            jid = JID(jid)

        kwargs = {
            'disco_name':"pyjirc",
            'disco_category':"x-service",
            'disco_type':"bridge",
        }
        kwargs.update(options)
        Component.__init__(self, jid, secret, server, port, **kwargs)
        self.disco_info.add_feature("jabber:iq:version")
Exemplo n.º 5
0
    def authenticated(self):
        dbg("authenticated: jid:%s" % (self.jid.as_utf8(),))

        Component.authenticated(self)

        self.connection = CONNECTION.connected

        self.stream.set_iq_get_handler("query", "jabber:iq:version", self.get_version)
        self.stream.set_iq_set_handler("command", "http://vipadia.com/skype", self.vipadia_command)
        self.stream.set_presence_handler("available", self.presence)
        self.stream.set_presence_handler("unavailable", self.presence)
        self.stream.set_message_handler("normal", self.message)
Exemplo n.º 6
0
 def authenticated(self):
     dbg("authenticated: jid:%s" % (self.jid.as_utf8(),))
     
     Component.authenticated(self)
     
     self.connection = CONNECTION.connected
     
     self.stream.set_iq_get_handler("query", "jabber:iq:version",  self.get_version)
     self.stream.set_iq_set_handler(
         "command", "http://vipadia.com/skype", self.vipadia_command)
     self.stream.set_presence_handler("available",    self.presence)
     self.stream.set_presence_handler("unavailable",  self.presence)
     self.stream.set_message_handler("normal", self.message)
Exemplo n.º 7
0
    def __init__(self, config):
        log("muc: jid:%s" % (config.muc,))
        
        self.connection = CONNECTION.idle
        self.running = True
        self.config = config
        Component.__init__(
            self, JID(config.muc), config.secret, config.server, int(config.port),
            disco_name="Vipadia Ltd Skype Muc Gateway",
            )

        self.disco_info.add_feature('http://jabber.org/protocol/disco#info')
        self.disco_info.add_feature('jabber:iq:version')
Exemplo n.º 8
0
 def authenticated(self):
     self.logger.info('Trying to authenticate with server...')
     Component.authenticated(self)
     self.logger.info('JoggerBot component authenticated')
     # set up handlers for supported <iq/> queries
     self.stream.set_iq_get_handler('query', 'jabber:iq:version', self.getVersionQuery)
     self.stream.set_iq_get_handler('query', 'jabber:iq:register', self.getRegisterQuery)
     self.stream.set_iq_set_handler('query', 'jabber:iq:register', self.setRegisterQuery)
     self.stream.set_iq_get_handler('query', 'jabber:iq:last', self.onLastQuery)        
     # set up handlers for <presence/> stanzas
     self.stream.set_presence_handler('probe', self.onProbe)
     self.stream.set_presence_handler('available', self.onPresence)
     self.stream.set_presence_handler('subscribe', self.onSubscriptionChange)
     self.stream.set_presence_handler('unsubscribe', self.onSubscriptionChange)
     # set up handler for <message stanza>
     self.stream.set_message_handler('normal', self.onMessage)
Exemplo n.º 9
0
Arquivo: chat.py Projeto: mor1/karaka
    def __init__(self, config):
        log("master: jid:%s" % (config.component,))
        
        self.running = True
        self.connection = CONNECTION.idle

        self.config = config
        self.regdb = DatabaseAPI()
        
        Component.__init__(
            self, JID(config.component), config.secret, config.server, int(config.port),
            disco_name="Vipadia Ltd Skype Gateway",
            disco_type="skype", disco_category="gateway",
            )

        self.disco_info.add_feature('http://jabber.org/protocol/disco#info')
        self.disco_info.add_feature('jabber:iq:register')
        self.disco_info.add_feature('jabber:iq:time')
        self.disco_info.add_feature('jabber:iq:version')
        self.disco_info.add_feature('http://jabber.org/protocol/rosterx')
Exemplo n.º 10
0
 def __init__(self, config, logger):
     """Create instance and initialize from configuration options.
     Also set logger to global default one."""
     self.serverOpts = config.getOptions('server')
     self.mysqlOpts = config.getOptions('mysql')
     self.compOpts = config.getOptions('component')
     # initialize component
     logger.info('JoggerBot component initializing')
     name = self.compOpts['name']
     secret = self.serverOpts['secret']
     serverHostname = self.serverOpts['hostname']
     port = int(self.serverOpts['port'])
     try:
         fullName = self.compOpts['fullname']
     except KeyError:
         # using old configuration data
         self.logger.warning('Old configuration data is used')
         fullName = name
     Component.__init__(self,
                        JID(name),
                        secret,
                        serverHostname,
                        port,
                        disco_name=fullName,
                        disco_category='x-service',
                        disco_type='x-jogger')
     self.disco_info.add_feature('jabber:iq:version')
     logger.info('JoggerBot component initialized')
     self.startTime = time.time()
     self.cfg = config
     self.logger = logger
     # the signals we should respond to with graceful exit
     # for debug purpose also check Win platform
     if sys.platform == 'win32':
         signals = (signal.SIGTERM, signal.SIGINT)
     else:
         signals = (signal.SIGHUP, signal.SIGKILL, signal.SIGTERM,
                    signal.SIGINT)
     for sign in signals:
         signal.signal(sign, self.shutdown)
     self._connectDB()
Exemplo n.º 11
0
    def authenticated(self):
        dbg("authenticated: jid:%s" % (self.jid.as_utf8(), ))

        self.connection = CONNECTION.connected
        Component.authenticated(self)

        self.stream.set_iq_get_handler("query", "jabber:iq:version",
                                       self.get_version)
        self.stream.set_iq_get_handler("query", "jabber:iq:register",
                                       self.get_register)
        self.stream.set_iq_set_handler("query", "jabber:iq:register",
                                       self.set_register)

        self.stream.set_presence_handler("available", self.presence_available)
        self.stream.set_presence_handler("unavailable",
                                         self.presence_unavailable)
        self.stream.set_presence_handler("error", self.presence_error)
        self.stream.set_presence_handler("probe", self.probe)

        self.stream.set_presence_handler("subscribe", self.subscribe)
        self.stream.set_presence_handler("subscribed", self.subscribed)

        self.stream.set_presence_handler("unsubscribe", self.unsubscribe)
        self.stream.set_presence_handler("unsubscribed", self.unsubscribed)

        ## default handlers
        self.stream.set_message_handler("normal", self.default_handler)

        self.default_presence_handler = self.stream.process_presence
        self.stream.process_presence = self.default_handler

        ## not possible to set a default IQ handler since all IQs either handled
        ## by user handler, or cause feature-not-implemented or bad-request to
        ## be sent

        self.stream.set_iq_set_handler("x",
                                       "http://jabber.org/protocol/rosterx",
                                       self.default_handler)
        self.stream.set_iq_set_handler("command", "http://vipadia.com/skype",
                                       self.vipadia_command)
Exemplo n.º 12
0
 def authenticated(self):
     self.logger.info('Trying to authenticate with server...')
     Component.authenticated(self)
     self.logger.info('JoggerBot component authenticated')
     # set up handlers for supported <iq/> queries
     self.stream.set_iq_get_handler('query', 'jabber:iq:version',
                                    self.getVersionQuery)
     self.stream.set_iq_get_handler('query', 'jabber:iq:register',
                                    self.getRegisterQuery)
     self.stream.set_iq_set_handler('query', 'jabber:iq:register',
                                    self.setRegisterQuery)
     self.stream.set_iq_get_handler('query', 'jabber:iq:last',
                                    self.onLastQuery)
     # set up handlers for <presence/> stanzas
     self.stream.set_presence_handler('probe', self.onProbe)
     self.stream.set_presence_handler('available', self.onPresence)
     self.stream.set_presence_handler('subscribe',
                                      self.onSubscriptionChange)
     self.stream.set_presence_handler('unsubscribe',
                                      self.onSubscriptionChange)
     # set up handler for <message stanza>
     self.stream.set_message_handler('normal', self.onMessage)
Exemplo n.º 13
0
 def __init__(self, config, logger):
     """Create instance and initialize from configuration options.
     Also set logger to global default one."""
     self.serverOpts = config.getOptions('server')
     self.mysqlOpts = config.getOptions('mysql')
     self.compOpts = config.getOptions('component')
     # initialize component
     logger.info('JoggerBot component initializing')
     name = self.compOpts['name']
     secret = self.serverOpts['secret']
     serverHostname = self.serverOpts['hostname']
     port = int(self.serverOpts['port'])
     try:
         fullName = self.compOpts['fullname']
     except KeyError:
         # using old configuration data
         self.logger.warning('Old configuration data is used')
         fullName = name
     Component.__init__(self, JID(name), secret, serverHostname, port,
         disco_name=fullName, disco_category='x-service',
         disco_type='x-jogger')
     self.disco_info.add_feature('jabber:iq:version')
     logger.info('JoggerBot component initialized')
     self.startTime = time.time()
     self.cfg = config
     self.logger = logger
     # the signals we should respond to with graceful exit
     # for debug purpose also check Win platform
     if sys.platform == 'win32':
         signals = (signal.SIGTERM, signal.SIGINT)
     else:
         signals = (signal.SIGHUP, signal.SIGKILL, 
             signal.SIGTERM, signal.SIGINT)
     for sign in signals:
         signal.signal(sign, self.shutdown)
     self._connectDB()
Exemplo n.º 14
0
def main():
    global source
    global config
    global dest
    global users
    global shutdown

    config_file="xdb_copy.xml"
    user_file="xdb_copy.users"

    try:
        try:
            config=Config(config_file)
        except:
            print >>sys.stderr,"Couldn't load config file:",str(sys.exc_value)
            sys.exit(1)
	try:
	    userfile=codecs.open(user_file, "r", "utf-8")
        except:
            print >>sys.stderr,"Couldn't load users file:",str(sys.exc_value)
            sys.exit(1)
	
	users=userfile.readlines()
	source=Component(jid=config.source.jid,server=config.source.host,port=config.source.port,secret=config.source.secret);
	source.authenticated=authenticated
        source.connect()
	dest=Component(jid=config.destination.jid,server=config.destination.host,port=config.destination.port,secret=config.destination.secret);
	dest.authenticated=auth_dest
        dest.connect()
	shutdown=None
        try:
            while (not shutdown and source.stream and not source.stream.eof and source.stream.socket is not None):
                try:
                    source.stream.loop_iter(1)
                    dest.stream.loop_iter(1)
		    
                except (KeyboardInterrupt,SystemExit,FatalStreamError,StreamError):
                    raise
                except:
                    source.print_exception()
        finally:
            source.disconnect()
            source.debug("Exitting normally")
	

    except FatalError,e:
        print e
        print "Aborting."
        sys.exit(1)