예제 #1
0
    def addRoute(self, destination, xs):
        """
        Add a new route.

        The passed XML Stream C{xs} will have an observer for all stanzas
        added to route its outgoing traffic. In turn, traffic for
        C{destination} will be passed to this stream.

        @param destination: Destination of the route to be added as a host name
                            or C{None} for the default route.
        @type destination: C{str} or C{NoneType}.
        @param xs: XML Stream to register the route for.
        @type xs: L{EventDispatcher<utility.EventDispatcher>}.
        """

        stanza = Presence()
        stanza['from'] = destination

        log.info("adversiting component %s" % (destination, ))
        self.broadcast(stanza)

        # advertise this component about the others
        stanza = Presence()
        stanza['to'] = destination
        for host in self.routes.iterkeys():
            if host is not None:
                stanza['from'] = host
                xs.send(stanza)

        # add route and observers
        self.routes[destination] = xs
        xs.addObserver('/bind', self.bind, 100, xs=xs)
        xs.addObserver('/unbind', self.unbind, 100, xs=xs)
        xs.addObserver('/*', self.route, xs=xs)
예제 #2
0
 def connectionMade(self):
     self.send(AvailablePresence())
     # join room
     pres = Presence()
     pres['to'] = self.room + '/' + self.nick
     x = pres.addElement((NS_MUC, 'x'))
     if not self.password is None:
         x.addElement('password', content = self.password)
     self.send(pres)
예제 #3
0
    def sendOnePresence(self, room_name, nick, role, recipient, presenceType):
        p = Presence(recipient, presenceType)
        p['from'] = "%s@%s/%s" % (room_name, self.jid, nick)
        x = p.addElement(('http://jabber.org/protocol/muc#user', 'x'))
        item = x.addElement('item')
        item['affiliation'] = 'none'
        item['role'] = role

        self.send(p)
예제 #4
0
파일: stenotype.py 프로젝트: mick/stenotype
    def connectionMade(self):
        self.send(AvailablePresence())

        # add handlers

        # join room
        pres = Presence()
        pres['to'] = self.room + '/' + self.nick
        pres.addElement((NS_MUC, 'x'))
        self.send(pres)
예제 #5
0
    def connectionMade(self):
        self.send(AvailablePresence())

        # add handlers

        # join room
        pres = Presence()
        pres['to'] = self.room + '/' + self.nick
        x = pres.addElement((NS_MUC, 'x'))
        if not self.password is None:
            x.addElement('password', content = self.password)
        self.send(pres)
예제 #6
0
 def send_routes(self, host, xs):
     stanza = Presence()
     stanza['to'] = host
     for h, stream in self.routes.iteritems():
         # ignore default route and do not send back to requesting stream
         if h is not None and stream != xs:
             stanza['from'] = h
             xs.send(stanza)
예제 #7
0
    def advertise(self, host, xs=None):
        stanza = Presence()
        stanza['from'] = host

        log.info("advertising component %s" % (host, ))
        self.broadcast(stanza, xs=xs)
예제 #8
0
파일: xmpp.py 프로젝트: morgenroth/pysms-t
    def __init__(self, user=None, to=None, type=None):
        Presence.__init__(self, to, type)

        if user is not None:
            self["from"] = user.full()
예제 #9
0
파일: xmpp.py 프로젝트: morgenroth/pysms-t
    def _onSetRegister(self, iq):
        fromjid = jid.internJID(iq["from"])
        data = iq.query

        username = None
        password = None
        phone = None
        msgtype = "message"
        report = False

        if data.x == None:
            """ use standard form if no xdata is returned """
            username = data.username
            password = data.password
            phone = data.phone
        else:
            """ xdata available, take it! """
            for field in data.x.elements():
                if field.name == "field":
                    if field.getAttribute("var") == "username":
                        username = str(field.value)
                    if field.getAttribute("var") == "smstype":
                        smstyp = str(field.value)
                    if field.getAttribute("var") == "password":
                        password = str(field.value)
                    if field.getAttribute("var") == "phone":
                        phone = str(field.value)
                    if field.getAttribute("var") == "msgtype":
                        msgtype = str(field.value)
                    if field.getAttribute("var") == "report":
                        report = str(field.value)

        # set password to None if there isn't one
        if password == "": password = None

        # remove or register?
        if data.remove == None:
            # register new account
            database.createUser(fromjid, username, phone, password)

            # set the default message type if set
            if smstyp != None:
                database.setDefaultMessageType(fromjid, smstyp)

            database.setMessageAsChat(fromjid, (msgtype == "chat"))
            database.setReportRequested(fromjid, (report == "yes"))

            # send own subscribe
            self.send(Presence(to=fromjid, type='subscribe'))

            # create welcome message
            httpkey = database.getHTTPGetKey(fromjid.userhost())
            welcomemsg = messages.getInfoMessage("welcome",
                                                 str(fromjid.userhost()),
                                                 httpkey)

            # send welcome message
            welcome = domish.Element((None, "message"))
            welcome["to"] = iq["from"]
            welcome.addElement("subject", content=welcomemsg[0])
            welcome.addElement("body", content=welcomemsg[1])
            self.send(welcome)
        else:
            # remove the account
            database.removeUser(fromjid)
예제 #10
0
파일: xmpp.py 프로젝트: morgenroth/pysms-t
    def __init__(self, user=None, to=None, type=None):
        Presence.__init__(self, to, type)

        if user is not None:
            self["from"] = user.full()