mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
bugfixes
This commit is contained in:
parent
e59d43ff3e
commit
2349f849e3
3 changed files with 63 additions and 6 deletions
|
@ -181,6 +181,7 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
self.send(self.makeIqGet('jabber:iq:roster'))
|
self.send(self.makeIqGet('jabber:iq:roster'))
|
||||||
|
|
||||||
def _handleStreamFeatures(self, features):
|
def _handleStreamFeatures(self, features):
|
||||||
|
self.features = []
|
||||||
for sub in features.xml:
|
for sub in features.xml:
|
||||||
self.features.append(sub.tag)
|
self.features.append(sub.tag)
|
||||||
for subelement in features.xml:
|
for subelement in features.xml:
|
||||||
|
@ -191,7 +192,7 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def handler_starttls(self, xml):
|
def handler_starttls(self, xml):
|
||||||
if self.ssl_support:
|
if not self.authenticated and self.ssl_support:
|
||||||
self.add_handler("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_tls_start, instream=True)
|
self.add_handler("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_tls_start, instream=True)
|
||||||
self.send(xml)
|
self.send(xml)
|
||||||
return True
|
return True
|
||||||
|
@ -205,6 +206,8 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
raise RestartStream()
|
raise RestartStream()
|
||||||
|
|
||||||
def handler_sasl_auth(self, xml):
|
def handler_sasl_auth(self, xml):
|
||||||
|
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
|
||||||
|
return False
|
||||||
logging.debug("Starting SASL Auth")
|
logging.debug("Starting SASL Auth")
|
||||||
self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True)
|
self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True)
|
||||||
self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True)
|
self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True)
|
||||||
|
|
|
@ -326,8 +326,8 @@ class basexmpp(object):
|
||||||
def sendMessage(self, mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None):
|
def sendMessage(self, mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None):
|
||||||
self.send(self.makeMessage(mto,mbody,msubject,mtype,mhtml,mfrom,mnick))
|
self.send(self.makeMessage(mto,mbody,msubject,mtype,mhtml,mfrom,mnick))
|
||||||
|
|
||||||
def sendPresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, pfrom=None):
|
def sendPresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, pfrom=None, ptype=None):
|
||||||
self.send(self.makePresence(pshow,pstatus,ppriority,pto, pfrom=pfrom))
|
self.send(self.makePresence(pshow,pstatus,ppriority,pto, ptype=ptype, pfrom=pfrom))
|
||||||
if not self.sentpresence:
|
if not self.sentpresence:
|
||||||
self.event('sent_presence')
|
self.event('sent_presence')
|
||||||
self.sentpresence = True
|
self.sentpresence = True
|
||||||
|
|
|
@ -31,9 +31,9 @@ class xep_0045(base.base_plugin):
|
||||||
self.rooms = {}
|
self.rooms = {}
|
||||||
self.ourNicks = {}
|
self.ourNicks = {}
|
||||||
self.xep = '0045'
|
self.xep = '0045'
|
||||||
self.description = 'Multi User Chat (Very Basic Still)'
|
self.description = 'Multi User Chat'
|
||||||
self.xmpp.add_handler("<message xmlns='%s' type='groupchat'><body/></message>" % self.xmpp.default_ns, self.handle_groupchat_message)
|
self.xmpp.add_handler("<message xmlns='%s' type='groupchat'><body/></message>" % self.xmpp.default_ns, self.handle_groupchat_message)
|
||||||
self.xmpp.add_handler("<presence />", self.handle_groupchat_presence)
|
self.xmpp.add_handler("<presence xmlns='%s' />" % self.xmpp.default_ns, self.handle_groupchat_presence)
|
||||||
|
|
||||||
def handle_groupchat_presence(self, xml):
|
def handle_groupchat_presence(self, xml):
|
||||||
""" Handle a presence in a muc.
|
""" Handle a presence in a muc.
|
||||||
|
@ -49,6 +49,8 @@ class xep_0045(base.base_plugin):
|
||||||
}
|
}
|
||||||
if 'type' in xml.attrib.keys():
|
if 'type' in xml.attrib.keys():
|
||||||
entry['type'] = xml.attrib['type']
|
entry['type'] = xml.attrib['type']
|
||||||
|
else:
|
||||||
|
entry['type'] = 'available'
|
||||||
for tag in ['status','show','priority']:
|
for tag in ['status','show','priority']:
|
||||||
if xml.find(('{%s}' % self.xmpp.default_ns) + tag) != None:
|
if xml.find(('{%s}' % self.xmpp.default_ns) + tag) != None:
|
||||||
entry[tag] = xml.find(('{%s}' % self.xmpp.default_ns) + tag).text
|
entry[tag] = xml.find(('{%s}' % self.xmpp.default_ns) + tag).text
|
||||||
|
@ -87,6 +89,39 @@ class xep_0045(base.base_plugin):
|
||||||
mtype = xml.attrib.get('type', 'normal')
|
mtype = xml.attrib.get('type', 'normal')
|
||||||
self.xmpp.event("groupchat_message", {'room': mfrom, 'name': resource, 'type': mtype, 'subject': subject, 'message': message})
|
self.xmpp.event("groupchat_message", {'room': mfrom, 'name': resource, 'type': mtype, 'subject': subject, 'message': message})
|
||||||
|
|
||||||
|
def getRoomForm(self, room, ifrom=None):
|
||||||
|
iq = self.xmpp.makeIqGet()
|
||||||
|
iq.attrib['to'] = room
|
||||||
|
if ifrom is not None:
|
||||||
|
iq.attrib['from'] = ifrom
|
||||||
|
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||||
|
iq.append(query)
|
||||||
|
result = self.xmpp.send(iq, self.xmpp.makeIq(id=iq.get('id')))
|
||||||
|
if result.get('type', 'error') == 'error':
|
||||||
|
return False
|
||||||
|
xform = result.find('{http://jabber.org/protocol/muc#owner}query/{jabber:x:data}x')
|
||||||
|
if xform is None: return False
|
||||||
|
form = self.xmpp.plugin['xep_0004'].buildForm(xform)
|
||||||
|
return form
|
||||||
|
|
||||||
|
def configureRoom(self, room, form=None, ifrom=None):
|
||||||
|
if form is None:
|
||||||
|
form = self.getRoomForm(room, ifrom=ifrom)
|
||||||
|
#form = self.xmpp.plugin['xep_0004'].makeForm(ftype='submit')
|
||||||
|
#form.addField('FORM_TYPE', value='http://jabber.org/protocol/muc#roomconfig')
|
||||||
|
iq = self.xmpp.makeIqSet()
|
||||||
|
iq.attrib['to'] = room
|
||||||
|
if ifrom is not None:
|
||||||
|
iq.attrib['from'] = ifrom
|
||||||
|
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||||
|
form = form.getXML('submit')
|
||||||
|
query.append(form)
|
||||||
|
iq.append(query)
|
||||||
|
result = self.xmpp.send(iq, self.xmpp.makeIq(iq.get('id')))
|
||||||
|
if result.get('type', 'error') == 'error':
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def joinMUC(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None):
|
def joinMUC(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None):
|
||||||
""" Join the specified room, requesting 'maxhistory' lines of history.
|
""" Join the specified room, requesting 'maxhistory' lines of history.
|
||||||
"""
|
"""
|
||||||
|
@ -104,11 +139,30 @@ class xep_0045(base.base_plugin):
|
||||||
self.xmpp.send(stanza)
|
self.xmpp.send(stanza)
|
||||||
else:
|
else:
|
||||||
#wait for our own room presence back
|
#wait for our own room presence back
|
||||||
expect = ET.Element('{jabber:client}presence', {'from':"%s/%s" % (room, nick)})
|
expect = ET.Element("{%s}presence" % self.xmpp.default_ns, {'from':"%s/%s" % (room, nick)})
|
||||||
self.xmpp.send(stanza, expect)
|
self.xmpp.send(stanza, expect)
|
||||||
self.rooms[room] = {}
|
self.rooms[room] = {}
|
||||||
self.ourNicks[room] = nick
|
self.ourNicks[room] = nick
|
||||||
|
|
||||||
|
def destroy(self, room, reason='', altroom = '', ifrom=None):
|
||||||
|
iq = self.xmpp.makeIqSet()
|
||||||
|
if ifrom is not None:
|
||||||
|
iq.attrib['from'] = ifrom
|
||||||
|
iq.attrib['to'] = room
|
||||||
|
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||||
|
destroy = ET.Element('destroy')
|
||||||
|
if altroom:
|
||||||
|
destroy.attrib['jid'] = altroom
|
||||||
|
xreason = ET.Element('reason')
|
||||||
|
xreason.text = reason
|
||||||
|
destroy.append(xreason)
|
||||||
|
query.append(destroy)
|
||||||
|
iq.append(query)
|
||||||
|
r = self.xmpp.send(iq, self.xmpp.makeIq(iq.get('id')))
|
||||||
|
if r is None or r.get('type', 'error') == 'error':
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def setAffiliation(self, room, jid, affiliation='member'):
|
def setAffiliation(self, room, jid, affiliation='member'):
|
||||||
""" Change room affiliation."""
|
""" Change room affiliation."""
|
||||||
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
||||||
|
|
Loading…
Reference in a new issue