mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
makeMessage and makePresence now use new stanza classes
fixed component usage of stanzas
This commit is contained in:
parent
8854509ccd
commit
ca044a4934
2 changed files with 14 additions and 55 deletions
|
@ -187,63 +187,22 @@ class basexmpp(object):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.event_handlers[name].pop(self.event_handlers[name].index(handler))
|
self.event_handlers[name].pop(self.event_handlers[name].index(handler))
|
||||||
|
|
||||||
def makeMessage(self, mto, mbody='', msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None):
|
def makeMessage(self, mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None):
|
||||||
message = ET.Element('{%s}message' % self.default_ns)
|
message = self.Message(sto=mto, stype=mtype, sfrom=mfrom)
|
||||||
if mfrom is None:
|
message['body'] = mbody
|
||||||
message.attrib['from'] = self.fulljid
|
message['subject'] = msubject
|
||||||
else:
|
message['nick'] = mnick
|
||||||
message.attrib['from'] = mfrom
|
message['html'] = mhtml
|
||||||
message.attrib['to'] = mto
|
|
||||||
if not mtype:
|
|
||||||
mtype='chat'
|
|
||||||
message.attrib['type'] = mtype
|
|
||||||
if mtype == 'none':
|
|
||||||
del message.attrib['type']
|
|
||||||
if mbody:
|
|
||||||
body = ET.Element('body')
|
|
||||||
body.text = mbody
|
|
||||||
message.append(body)
|
|
||||||
if mhtml :
|
|
||||||
html = ET.Element('{http://jabber.org/protocol/xhtml-im}html')
|
|
||||||
html_body = ET.XML('<body xmlns="http://www.w3.org/1999/xhtml">' + mhtml + '</body>')
|
|
||||||
html.append(html_body)
|
|
||||||
message.append(html)
|
|
||||||
if msubject:
|
|
||||||
subject = ET.Element('subject')
|
|
||||||
subject.text = msubject
|
|
||||||
message.append(subject)
|
|
||||||
if mnick:
|
|
||||||
print("generating nick")
|
|
||||||
nick = ET.Element("{http://jabber.org/protocol/nick}nick")
|
|
||||||
nick.text = mnick
|
|
||||||
message.append(nick)
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def makePresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None):
|
def makePresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None):
|
||||||
if pshow == 'unavailable':
|
presence = self.Presence(stype=ptype, sfrom=pfrom, sto=pto)
|
||||||
pshow = None
|
if pshow is not None:
|
||||||
ptype = 'unavailable'
|
presence['type'] = pshow
|
||||||
presence = ET.Element('{%s}presence' % self.default_ns)
|
if pfrom is None: #maybe this should be done in stanzabase
|
||||||
if ptype:
|
presence['from'] = self.fulljid
|
||||||
presence.attrib['type'] = ptype
|
presence['priority'] = ppriority
|
||||||
if pshow:
|
presence['status'] = pstatus
|
||||||
show = ET.Element('show')
|
|
||||||
show.text = pshow
|
|
||||||
presence.append(show)
|
|
||||||
if pstatus:
|
|
||||||
status = ET.Element('status')
|
|
||||||
status.text = pstatus
|
|
||||||
presence.append(status)
|
|
||||||
if ppriority:
|
|
||||||
priority = ET.Element('priority')
|
|
||||||
priority.text = str(ppriority)
|
|
||||||
presence.append(priority)
|
|
||||||
if pto:
|
|
||||||
presence.attrib['to'] = pto
|
|
||||||
if pfrom is None:
|
|
||||||
presence.attrib['from'] = self.fulljid
|
|
||||||
else:
|
|
||||||
presence.attrib['from'] = pfrom
|
|
||||||
return presence
|
return presence
|
||||||
|
|
||||||
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):
|
||||||
|
|
|
@ -100,7 +100,7 @@ class ComponentXMPP(basexmpp, XMLStream):
|
||||||
sid = xml.get('id', '')
|
sid = xml.get('id', '')
|
||||||
handshake = ET.Element('{jabber:component:accept}handshake')
|
handshake = ET.Element('{jabber:component:accept}handshake')
|
||||||
handshake.text = hashlib.sha1(bytes("%s%s" % (sid, self.secret), 'utf-8')).hexdigest().lower()
|
handshake.text = hashlib.sha1(bytes("%s%s" % (sid, self.secret), 'utf-8')).hexdigest().lower()
|
||||||
self.send(handshake)
|
self.sendXML(handshake)
|
||||||
|
|
||||||
def _handleHandshake(self, xml):
|
def _handleHandshake(self, xml):
|
||||||
self.event("session_start")
|
self.event("session_start")
|
||||||
|
|
Loading…
Reference in a new issue