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