check that the connexion exists before sending something
This commit is contained in:
parent
cf96fc22e6
commit
1de83250e5
1 changed files with 135 additions and 113 deletions
26
Core/core.py
26
Core/core.py
|
@ -427,6 +427,7 @@ class GajimCore:
|
||||||
log.debug("subscribe request from %s" % who)
|
log.debug("subscribe request from %s" % who)
|
||||||
if self.cfgParser.Core['alwaysauth'] == 1 or \
|
if self.cfgParser.Core['alwaysauth'] == 1 or \
|
||||||
who.find("@") <= 0:
|
who.find("@") <= 0:
|
||||||
|
if con:
|
||||||
con.send(common.jabber.Presence(who, 'subscribed'))
|
con.send(common.jabber.Presence(who, 'subscribed'))
|
||||||
if who.find("@") <= 0:
|
if who.find("@") <= 0:
|
||||||
self.hub.sendPlugin('NOTIFY', self.connexions[con], \
|
self.hub.sendPlugin('NOTIFY', self.connexions[con], \
|
||||||
|
@ -740,6 +741,7 @@ class GajimCore:
|
||||||
self.hub.sendPlugin('STATUS', ev[1], ev[2][0])
|
self.hub.sendPlugin('STATUS', ev[1], ev[2][0])
|
||||||
#('MSG', account, (jid, msg, keyID))
|
#('MSG', account, (jid, msg, keyID))
|
||||||
elif ev[0] == 'MSG':
|
elif ev[0] == 'MSG':
|
||||||
|
if con:
|
||||||
msgtxt = ev[2][1]
|
msgtxt = ev[2][1]
|
||||||
msgenc = ''
|
msgenc = ''
|
||||||
if ev[2][2] and USE_GPG:
|
if ev[2][2] and USE_GPG:
|
||||||
|
@ -754,6 +756,7 @@ class GajimCore:
|
||||||
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
||||||
#('SUB', account, (jid, txt))
|
#('SUB', account, (jid, txt))
|
||||||
elif ev[0] == 'SUB':
|
elif ev[0] == 'SUB':
|
||||||
|
if con:
|
||||||
log.debug('subscription request for %s' % ev[2][0])
|
log.debug('subscription request for %s' % ev[2][0])
|
||||||
pres = common.jabber.Presence(ev[2][0], 'subscribe')
|
pres = common.jabber.Presence(ev[2][0], 'subscribe')
|
||||||
if ev[2][1]:
|
if ev[2][1]:
|
||||||
|
@ -763,12 +766,15 @@ class GajimCore:
|
||||||
con.send(pres)
|
con.send(pres)
|
||||||
#('REQ', account, jid)
|
#('REQ', account, jid)
|
||||||
elif ev[0] == 'AUTH':
|
elif ev[0] == 'AUTH':
|
||||||
|
if con:
|
||||||
con.send(common.jabber.Presence(ev[2], 'subscribed'))
|
con.send(common.jabber.Presence(ev[2], 'subscribed'))
|
||||||
#('DENY', account, jid)
|
#('DENY', account, jid)
|
||||||
elif ev[0] == 'DENY':
|
elif ev[0] == 'DENY':
|
||||||
|
if con:
|
||||||
con.send(common.jabber.Presence(ev[2], 'unsubscribed'))
|
con.send(common.jabber.Presence(ev[2], 'unsubscribed'))
|
||||||
#('UNSUB', account, jid)
|
#('UNSUB', account, jid)
|
||||||
elif ev[0] == 'UNSUB':
|
elif ev[0] == 'UNSUB':
|
||||||
|
if con:
|
||||||
delauth = 1
|
delauth = 1
|
||||||
if self.cfgParser.Core.has_key('delauth'):
|
if self.cfgParser.Core.has_key('delauth'):
|
||||||
delauth = self.cfgParser.Core['delauth']
|
delauth = self.cfgParser.Core['delauth']
|
||||||
|
@ -781,6 +787,7 @@ class GajimCore:
|
||||||
con.removeRosterItem(ev[2])
|
con.removeRosterItem(ev[2])
|
||||||
#('UNSUB_AGENT', account, agent)
|
#('UNSUB_AGENT', account, agent)
|
||||||
elif ev[0] == 'UNSUB_AGENT':
|
elif ev[0] == 'UNSUB_AGENT':
|
||||||
|
if con:
|
||||||
con.removeRosterItem(ev[2])
|
con.removeRosterItem(ev[2])
|
||||||
con.requestRegInfo(ev[2])
|
con.requestRegInfo(ev[2])
|
||||||
agent_info = con.getRegInfo()
|
agent_info = con.getRegInfo()
|
||||||
|
@ -797,6 +804,7 @@ class GajimCore:
|
||||||
self.hub.sendPlugin('AGENT_REMOVED', ev[1], ev[2])
|
self.hub.sendPlugin('AGENT_REMOVED', ev[1], ev[2])
|
||||||
#('UPDUSER', account, (jid, name, groups))
|
#('UPDUSER', account, (jid, name, groups))
|
||||||
elif ev[0] == 'UPDUSER':
|
elif ev[0] == 'UPDUSER':
|
||||||
|
if con:
|
||||||
con.updateRosterItem(jid=ev[2][0], name=ev[2][1], \
|
con.updateRosterItem(jid=ev[2][0], name=ev[2][1], \
|
||||||
groups=ev[2][2])
|
groups=ev[2][2])
|
||||||
#('REQ_AGENTS', account, ())
|
#('REQ_AGENTS', account, ())
|
||||||
|
@ -805,11 +813,13 @@ class GajimCore:
|
||||||
self.request_infos(ev[1], con, config['hostname'])
|
self.request_infos(ev[1], con, config['hostname'])
|
||||||
#('REG_AGENT_INFO', account, agent)
|
#('REG_AGENT_INFO', account, agent)
|
||||||
elif ev[0] == 'REG_AGENT_INFO':
|
elif ev[0] == 'REG_AGENT_INFO':
|
||||||
|
if con:
|
||||||
con.requestRegInfo(ev[2])
|
con.requestRegInfo(ev[2])
|
||||||
agent_info = con.getRegInfo()
|
agent_info = con.getRegInfo()
|
||||||
self.hub.sendPlugin('REG_AGENT_INFO', ev[1], (ev[2], agent_info))
|
self.hub.sendPlugin('REG_AGENT_INFO', ev[1], (ev[2], agent_info))
|
||||||
#('REG_AGENT', account, infos)
|
#('REG_AGENT', account, infos)
|
||||||
elif ev[0] == 'REG_AGENT':
|
elif ev[0] == 'REG_AGENT':
|
||||||
|
if con:
|
||||||
con.sendRegInfo(ev[2])
|
con.sendRegInfo(ev[2])
|
||||||
#('NEW_ACC', (hostname, login, password, name, ressource, prio, \
|
#('NEW_ACC', (hostname, login, password, name, ressource, prio, \
|
||||||
# use_proxy, proxyhost, proxyport))
|
# use_proxy, proxyhost, proxyport))
|
||||||
|
@ -852,12 +862,14 @@ class GajimCore:
|
||||||
self.connexions[con] = ev[2]
|
self.connexions[con] = ev[2]
|
||||||
#('ASK_VCARD', account, jid)
|
#('ASK_VCARD', account, jid)
|
||||||
elif ev[0] == 'ASK_VCARD':
|
elif ev[0] == 'ASK_VCARD':
|
||||||
|
if con:
|
||||||
iq = common.jabber.Iq(to=ev[2], type="get")
|
iq = common.jabber.Iq(to=ev[2], type="get")
|
||||||
iq._setTag('vCard', common.jabber.NS_VCARD)
|
iq._setTag('vCard', common.jabber.NS_VCARD)
|
||||||
iq.setID(con.getAnID())
|
iq.setID(con.getAnID())
|
||||||
con.send(iq)
|
con.send(iq)
|
||||||
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
||||||
elif ev[0] == 'VCARD':
|
elif ev[0] == 'VCARD':
|
||||||
|
if con:
|
||||||
iq = common.jabber.Iq(type="set")
|
iq = common.jabber.Iq(type="set")
|
||||||
iq.setID(con.getAnID())
|
iq.setID(con.getAnID())
|
||||||
iq2 = iq._setTag('vCard', common.jabber.NS_VCARD)
|
iq2 = iq._setTag('vCard', common.jabber.NS_VCARD)
|
||||||
|
@ -872,6 +884,7 @@ class GajimCore:
|
||||||
con.send(iq)
|
con.send(iq)
|
||||||
#('AGENT_LOGGING', account, (agent, typ))
|
#('AGENT_LOGGING', account, (agent, typ))
|
||||||
elif ev[0] == 'AGENT_LOGGING':
|
elif ev[0] == 'AGENT_LOGGING':
|
||||||
|
if con:
|
||||||
t = ev[2][1];
|
t = ev[2][1];
|
||||||
if not t:
|
if not t:
|
||||||
t='available';
|
t='available';
|
||||||
|
@ -908,23 +921,27 @@ class GajimCore:
|
||||||
self.loadPlugins(ev[2])
|
self.loadPlugins(ev[2])
|
||||||
#('GC_JOIN', account, (nick, room, server, passwd))
|
#('GC_JOIN', account, (nick, room, server, passwd))
|
||||||
elif ev[0] == 'GC_JOIN':
|
elif ev[0] == 'GC_JOIN':
|
||||||
|
if con:
|
||||||
p = common.jabber.Presence(to='%s@%s/%s' % (ev[2][1], ev[2][2], \
|
p = common.jabber.Presence(to='%s@%s/%s' % (ev[2][1], ev[2][2], \
|
||||||
ev[2][0]))
|
ev[2][0]))
|
||||||
con.send(p)
|
con.send(p)
|
||||||
#('GC_MSG', account, (jid, msg))
|
#('GC_MSG', account, (jid, msg))
|
||||||
elif ev[0] == 'GC_MSG':
|
elif ev[0] == 'GC_MSG':
|
||||||
|
if con:
|
||||||
msg = common.jabber.Message(ev[2][0], ev[2][1])
|
msg = common.jabber.Message(ev[2][0], ev[2][1])
|
||||||
msg.setType('groupchat')
|
msg.setType('groupchat')
|
||||||
con.send(msg)
|
con.send(msg)
|
||||||
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
||||||
#('GC_SUBJECT', account, (jid, subject))
|
#('GC_SUBJECT', account, (jid, subject))
|
||||||
elif ev[0] == 'GC_SUBJECT':
|
elif ev[0] == 'GC_SUBJECT':
|
||||||
|
if con:
|
||||||
msg = common.jabber.Message(ev[2][0])
|
msg = common.jabber.Message(ev[2][0])
|
||||||
msg.setType('groupchat')
|
msg.setType('groupchat')
|
||||||
msg.setSubject(ev[2][1])
|
msg.setSubject(ev[2][1])
|
||||||
con.send(msg)
|
con.send(msg)
|
||||||
#('GC_STATUS', account, (nick, jid, show, status))
|
#('GC_STATUS', account, (nick, jid, show, status))
|
||||||
elif ev[0] == 'GC_STATUS':
|
elif ev[0] == 'GC_STATUS':
|
||||||
|
if con:
|
||||||
if ev[2][2] == 'offline':
|
if ev[2][2] == 'offline':
|
||||||
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
||||||
ev[2][0]), type = 'unavailable', status = ev[2][3]))
|
ev[2][0]), type = 'unavailable', status = ev[2][3]))
|
||||||
|
@ -934,8 +951,10 @@ class GajimCore:
|
||||||
ev[2][3]))
|
ev[2][3]))
|
||||||
#('GC_SET_ROLE', account, (room_jid, nick, role))
|
#('GC_SET_ROLE', account, (room_jid, nick, role))
|
||||||
elif ev[0] == 'GC_SET_ROLE':
|
elif ev[0] == 'GC_SET_ROLE':
|
||||||
|
if con:
|
||||||
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
||||||
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).insertTag('item')
|
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).\
|
||||||
|
insertTag('item')
|
||||||
item.putAttr('nick', ev[2][1])
|
item.putAttr('nick', ev[2][1])
|
||||||
item.putAttr('role', ev[2][2])
|
item.putAttr('role', ev[2][2])
|
||||||
id = con.getAnID()
|
id = con.getAnID()
|
||||||
|
@ -943,8 +962,10 @@ class GajimCore:
|
||||||
con.send(iq)
|
con.send(iq)
|
||||||
#('GC_SET_AFFILIATION', account, (room_jid, jid, affiliation))
|
#('GC_SET_AFFILIATION', account, (room_jid, jid, affiliation))
|
||||||
elif ev[0] == 'GC_SET_AFFILIATION':
|
elif ev[0] == 'GC_SET_AFFILIATION':
|
||||||
|
if con:
|
||||||
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
||||||
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).insertTag('item')
|
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).\
|
||||||
|
insertTag('item')
|
||||||
item.putAttr('jid', ev[2][1])
|
item.putAttr('jid', ev[2][1])
|
||||||
item.putAttr('affiliation', ev[2][2])
|
item.putAttr('affiliation', ev[2][2])
|
||||||
id = con.getAnID()
|
id = con.getAnID()
|
||||||
|
@ -962,6 +983,7 @@ class GajimCore:
|
||||||
self.passwords[ev[1]] = ev[2]
|
self.passwords[ev[1]] = ev[2]
|
||||||
#('CHANGE_PASSWORD', account, (new_password, username))
|
#('CHANGE_PASSWORD', account, (new_password, username))
|
||||||
elif ev[0] == 'CHANGE_PASSWORD':
|
elif ev[0] == 'CHANGE_PASSWORD':
|
||||||
|
if con:
|
||||||
hostname = self.cfgParser.tab[ev[1]]['hostname']
|
hostname = self.cfgParser.tab[ev[1]]['hostname']
|
||||||
iq = common.jabber.Iq(type='set', to=hostname)
|
iq = common.jabber.Iq(type='set', to=hostname)
|
||||||
q = iq.setQuery(common.jabber.NS_REGISTER)
|
q = iq.setQuery(common.jabber.NS_REGISTER)
|
||||||
|
|
Loading…
Add table
Reference in a new issue