def pres(): self.index += 1 presence = xmppim.AvailablePresence( statuses={ None: 'status message (%d)' % (self.index, ) }) xs.send(presence)
def connectionInitialized(self): self.parent.log.info(u"Connected") xmppim.MessageProtocol.connectionInitialized(self) xmppim.PresenceClientProtocol.connectionInitialized(self) xmppim.RosterClientProtocol.connectionInitialized(self) self.xmlstream.send(xmppim.AvailablePresence()) self.roster = self.getRoster() #See section 7.3 of http://www.ietf.org/rfc/rfc3921.txt self.name = self.parent.name self.parent.send = self.send self.parent.proto = self for room in self.parent.rooms: self.join(room) event = Event(self.parent.name, u'source') event.status = u'connected' ibid.dispatcher.dispatch(event)
def connectionInitialized(self): xmppim.MessageProtocol.connectionInitialized(self) print "[MessageBot] Connected %s" % self.ownjid self.roster = yield self.rosterProt.getRoster() self.send(xmppim.AvailablePresence())
def authenticated(self, xs): print "Authenticated." xs.addObserver('/*', self.stanza, xs=xs) xs.addObserver('/message', self.message, xs=xs) presence = xmppim.AvailablePresence(statuses={None: 'status message'}, priority=0) xs.send(presence) ver = client.IQ(xs, 'get') ver.addElement((xmlstream2.NS_IQ_VERSION, 'query')) ver.send(self.network) info = client.IQ(xs, 'get') info.addElement((xmlstream2.NS_DISCO_INFO, 'query')) info.send(self.network) items = client.IQ(xs, 'get') q = items.addElement((xmlstream2.NS_DISCO_ITEMS, 'query')) q['node'] = xmlstream2.NS_PROTO_COMMANDS items.send(self.network) items = client.IQ(xs, 'get') q = items.addElement((xmlstream2.NS_DISCO_ITEMS, 'query')) q['node'] = xmlstream2.NS_MESSAGE_UPLOAD items.send(self.network) def testProbe(): if self.peer is not None: userid, resource = util.split_userid(self.peer) presence = xmppim.Presence(jid.JID(tuple=(userid, self.network, resource)), 'probe') presence['id'] = util.rand_str(8) xs.send(presence) def testMassProbe(): global count, num num = 400 count = 0 def _presence(stanza): global count, num count += 1 if count >= 400: print 'received all presence' xs.addObserver('/presence', _presence) for n in range(num): userid = util.rand_str(util.USERID_LENGTH, util.CHARSBOX_HEX_LOWERCASE) presence = xmppim.Presence(jid.JID(tuple=(userid, self.network, None)), 'probe') xs.send(presence) def testRoster(): global count, num num = 400 count = 0 def _presence(stanza): global count, num count += 1 if count >= 400: print 'received all presence' xs.addObserver('/presence', _presence) _jid = jid.JID(tuple=(None, self.network, None)) r = domish.Element((None, 'iq')) r.addUniqueId() r['type'] = 'get' q = r.addElement((xmppim.NS_ROSTER, 'query')) for n in range(num): _jid.user = util.rand_str(util.USERID_LENGTH, util.CHARSBOX_HEX_LOWERCASE) item = q.addElement((None, 'item')) item['jid'] = _jid.userhost() xs.send(r) if self.peer is not None: _jid = util.userid_to_jid(self.peer, self.network) r = domish.Element((None, 'iq')) r['type'] = 'get' r['id'] = util.rand_str(8) q = r.addElement((xmppim.NS_ROSTER, 'query')) item = q.addElement((None, 'item')) item['jid'] = _jid.userhost() xs.send(r) def testSubscribe(): # subscription request self.index = 0 if self.peer is not None: userid, resource = util.split_userid(self.peer) presence = xmppim.Presence(jid.JID(tuple=(userid, self.network, None)), 'subscribe') presence['id'] = util.rand_str(8) xs.send(presence) else: def pres(): self.index += 1 presence = xmppim.AvailablePresence(statuses={None: 'status message (%d)' % (self.index, )}) xs.send(presence) LoopingCall(pres).start(2, False) def testMessage(): jid = xs.authenticator.jid message = domish.Element((None, 'message')) message['id'] = 'kontalk' + util.rand_str(8, util.CHARSBOX_AZN_LOWERCASE) message['type'] = 'chat' if self.peer: message['to'] = util.userid_to_jid(self.peer, self.network).full() else: message['to'] = jid.userhost() message.addElement((None, 'body'), content='test message') message.addElement(('urn:xmpp:server-receipts', 'request')) xs.send(message) #xs.sendFooter() def testMsgLoop(): global counter counter = 0 def _loop(): global counter counter += 1 jid = xs.authenticator.jid message = domish.Element((None, 'message')) message['id'] = 'kontalk' + util.rand_str(8, util.CHARSBOX_AZN_LOWERCASE) message['type'] = 'chat' if self.peer: message['to'] = util.userid_to_jid(self.peer, self.network).full() else: message['to'] = jid.userhost() message.addElement((None, 'body'), content=('%d' % counter)) message.addElement(('urn:xmpp:server-receipts', 'request')) xs.send(message) LoopingCall(_loop).start(1) def testRegisterRequest(): reg = client.IQ(xs, 'get') reg.addElement((xmlstream2.NS_IQ_REGISTER, 'query')) reg.send(self.network) def testRegister(): reg = client.IQ(xs, 'set') query = reg.addElement((xmlstream2.NS_IQ_REGISTER, 'query')) form = query.addElement(('jabber:x:data', 'x')) form['type'] = 'submit' hidden = form.addElement((None, 'field')) hidden['type'] = 'hidden' hidden['var'] = 'FORM_TYPE' hidden.addElement((None, 'value'), content=xmlstream2.NS_IQ_REGISTER) phone = form.addElement((None, 'field')) phone['type'] = 'text-single' phone['label'] = 'Phone number' phone['var'] = 'phone' phone.addElement((None, 'value'), content='+39123456') reg.send(self.network) def testValidate(): reg = client.IQ(xs, 'set') query = reg.addElement((xmlstream2.NS_IQ_REGISTER, 'query')) form = query.addElement(('jabber:x:data', 'x')) form['type'] = 'submit' hidden = form.addElement((None, 'field')) hidden['type'] = 'hidden' hidden['var'] = 'FORM_TYPE' hidden.addElement((None, 'value'), content='http://kontalk.org/protocol/register#code') code = form.addElement((None, 'field')) code['type'] = 'text-single' code['label'] = 'Validation code' code['var'] = 'code' code.addElement((None, 'value'), content='686129') reg.send(self.network) def testCommand(): cmd = client.IQ(xs, 'set') ch = cmd.addElement((xmlstream2.NS_PROTO_COMMANDS, 'command')) ch['node'] = 'serverlist' ch['action'] = 'execute' cmd.send(self.network) def testUpload(): cmd = client.IQ(xs, 'set') ch = cmd.addElement((xmlstream2.NS_MESSAGE_UPLOAD, 'upload')) ch['node'] = 'kontalkbox' media = ch.addElement((None, 'media')) media['type'] = 'image/png' cmd.send(self.network) def testBad(): receipt = domish.Element((None, 'message')) receipt['id'] = util.rand_str(8) receipt['type'] = 'chat' receipt['to'] = self.peer + '@' + self.network child = receipt.addElement(('urn:xmpp:server-receipts', 'received')) #child['id'] = util.rand_str(40) xs.send(receipt)
def join(self, room): self.parent.log.info(u"Joining %s", room) jid = JID('%s/%s' % (room, self.parent.nick)) presence = xmppim.AvailablePresence(to=jid) self.xmlstream.send(presence) self.rooms.append(room.lower())
def connectionMade(self): print "[Message] Connected" self.send(xmppim.AvailablePresence())