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
248
Core/core.py
248
Core/core.py
|
@ -427,7 +427,8 @@ 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:
|
||||||
con.send(common.jabber.Presence(who, 'subscribed'))
|
if con:
|
||||||
|
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], \
|
||||||
(prs.getFrom().getStripped(), 'offline', 'offline', \
|
(prs.getFrom().getStripped(), 'offline', 'offline', \
|
||||||
|
@ -740,77 +741,86 @@ 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':
|
||||||
msgtxt = ev[2][1]
|
if con:
|
||||||
msgenc = ''
|
msgtxt = ev[2][1]
|
||||||
if ev[2][2] and USE_GPG:
|
msgenc = ''
|
||||||
#encrypt
|
if ev[2][2] and USE_GPG:
|
||||||
msgenc = self.gpg[ev[1]].encrypt(ev[2][1], [ev[2][2]])
|
#encrypt
|
||||||
if msgenc: msgtxt = '[this message is encrypted]'
|
msgenc = self.gpg[ev[1]].encrypt(ev[2][1], [ev[2][2]])
|
||||||
msg = common.jabber.Message(ev[2][0], msgtxt)
|
if msgenc: msgtxt = '[this message is encrypted]'
|
||||||
msg.setType('chat')
|
msg = common.jabber.Message(ev[2][0], msgtxt)
|
||||||
if msgenc:
|
msg.setType('chat')
|
||||||
msg.setX(common.jabber.NS_XENCRYPTED).insertData(msgenc)
|
if msgenc:
|
||||||
con.send(msg)
|
msg.setX(common.jabber.NS_XENCRYPTED).insertData(msgenc)
|
||||||
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
con.send(msg)
|
||||||
|
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
||||||
#('SUB', account, (jid, txt))
|
#('SUB', account, (jid, txt))
|
||||||
elif ev[0] == 'SUB':
|
elif ev[0] == 'SUB':
|
||||||
log.debug('subscription request for %s' % ev[2][0])
|
if con:
|
||||||
pres = common.jabber.Presence(ev[2][0], 'subscribe')
|
log.debug('subscription request for %s' % ev[2][0])
|
||||||
if ev[2][1]:
|
pres = common.jabber.Presence(ev[2][0], 'subscribe')
|
||||||
pres.setStatus(ev[2][1])
|
if ev[2][1]:
|
||||||
else:
|
pres.setStatus(ev[2][1])
|
||||||
pres.setStatus(_("I would like to add you to my roster."))
|
else:
|
||||||
con.send(pres)
|
pres.setStatus(_("I would like to add you to my roster."))
|
||||||
|
con.send(pres)
|
||||||
#('REQ', account, jid)
|
#('REQ', account, jid)
|
||||||
elif ev[0] == 'AUTH':
|
elif ev[0] == 'AUTH':
|
||||||
con.send(common.jabber.Presence(ev[2], 'subscribed'))
|
if con:
|
||||||
|
con.send(common.jabber.Presence(ev[2], 'subscribed'))
|
||||||
#('DENY', account, jid)
|
#('DENY', account, jid)
|
||||||
elif ev[0] == 'DENY':
|
elif ev[0] == 'DENY':
|
||||||
con.send(common.jabber.Presence(ev[2], 'unsubscribed'))
|
if con:
|
||||||
|
con.send(common.jabber.Presence(ev[2], 'unsubscribed'))
|
||||||
#('UNSUB', account, jid)
|
#('UNSUB', account, jid)
|
||||||
elif ev[0] == 'UNSUB':
|
elif ev[0] == 'UNSUB':
|
||||||
delauth = 1
|
if con:
|
||||||
if self.cfgParser.Core.has_key('delauth'):
|
delauth = 1
|
||||||
delauth = self.cfgParser.Core['delauth']
|
if self.cfgParser.Core.has_key('delauth'):
|
||||||
delroster = 1
|
delauth = self.cfgParser.Core['delauth']
|
||||||
if self.cfgParser.Core.has_key('delroster'):
|
delroster = 1
|
||||||
delroster = self.cfgParser.Core['delroster']
|
if self.cfgParser.Core.has_key('delroster'):
|
||||||
if delauth:
|
delroster = self.cfgParser.Core['delroster']
|
||||||
con.send(common.jabber.Presence(ev[2], 'unsubscribe'))
|
if delauth:
|
||||||
if delroster:
|
con.send(common.jabber.Presence(ev[2], 'unsubscribe'))
|
||||||
con.removeRosterItem(ev[2])
|
if delroster:
|
||||||
|
con.removeRosterItem(ev[2])
|
||||||
#('UNSUB_AGENT', account, agent)
|
#('UNSUB_AGENT', account, agent)
|
||||||
elif ev[0] == 'UNSUB_AGENT':
|
elif ev[0] == 'UNSUB_AGENT':
|
||||||
con.removeRosterItem(ev[2])
|
if con:
|
||||||
con.requestRegInfo(ev[2])
|
con.removeRosterItem(ev[2])
|
||||||
agent_info = con.getRegInfo()
|
con.requestRegInfo(ev[2])
|
||||||
if not agent_info:
|
agent_info = con.getRegInfo()
|
||||||
return
|
if not agent_info:
|
||||||
key = agent_info['key']
|
return
|
||||||
iq = common.jabber.Iq(to=ev[2], type="set")
|
key = agent_info['key']
|
||||||
q = iq.setQuery(common.jabber.NS_REGISTER)
|
iq = common.jabber.Iq(to=ev[2], type="set")
|
||||||
q.insertTag('remove')
|
q = iq.setQuery(common.jabber.NS_REGISTER)
|
||||||
q.insertTag('key').insertData(key)
|
q.insertTag('remove')
|
||||||
id = con.getAnID()
|
q.insertTag('key').insertData(key)
|
||||||
iq.setID(id)
|
id = con.getAnID()
|
||||||
con.send(iq)
|
iq.setID(id)
|
||||||
self.hub.sendPlugin('AGENT_REMOVED', ev[1], ev[2])
|
con.send(iq)
|
||||||
|
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':
|
||||||
con.updateRosterItem(jid=ev[2][0], name=ev[2][1], \
|
if con:
|
||||||
groups=ev[2][2])
|
con.updateRosterItem(jid=ev[2][0], name=ev[2][1], \
|
||||||
|
groups=ev[2][2])
|
||||||
#('REQ_AGENTS', account, ())
|
#('REQ_AGENTS', account, ())
|
||||||
elif ev[0] == 'REQ_AGENTS':
|
elif ev[0] == 'REQ_AGENTS':
|
||||||
config = self.cfgParser.__getattr__(ev[1])
|
config = self.cfgParser.__getattr__(ev[1])
|
||||||
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':
|
||||||
con.requestRegInfo(ev[2])
|
if con:
|
||||||
agent_info = con.getRegInfo()
|
con.requestRegInfo(ev[2])
|
||||||
self.hub.sendPlugin('REG_AGENT_INFO', ev[1], (ev[2], agent_info))
|
agent_info = con.getRegInfo()
|
||||||
|
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':
|
||||||
con.sendRegInfo(ev[2])
|
if con:
|
||||||
|
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))
|
||||||
elif ev[0] == 'NEW_ACC':
|
elif ev[0] == 'NEW_ACC':
|
||||||
|
@ -852,31 +862,34 @@ 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':
|
||||||
iq = common.jabber.Iq(to=ev[2], type="get")
|
if con:
|
||||||
iq._setTag('vCard', common.jabber.NS_VCARD)
|
iq = common.jabber.Iq(to=ev[2], type="get")
|
||||||
iq.setID(con.getAnID())
|
iq._setTag('vCard', common.jabber.NS_VCARD)
|
||||||
con.send(iq)
|
iq.setID(con.getAnID())
|
||||||
|
con.send(iq)
|
||||||
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
||||||
elif ev[0] == 'VCARD':
|
elif ev[0] == 'VCARD':
|
||||||
iq = common.jabber.Iq(type="set")
|
if con:
|
||||||
iq.setID(con.getAnID())
|
iq = common.jabber.Iq(type="set")
|
||||||
iq2 = iq._setTag('vCard', common.jabber.NS_VCARD)
|
iq.setID(con.getAnID())
|
||||||
for i in ev[2].keys():
|
iq2 = iq._setTag('vCard', common.jabber.NS_VCARD)
|
||||||
if i != 'jid':
|
for i in ev[2].keys():
|
||||||
if type(ev[2][i]) == type({}):
|
if i != 'jid':
|
||||||
iq3 = iq2.insertTag(i)
|
if type(ev[2][i]) == type({}):
|
||||||
for j in ev[2][i].keys():
|
iq3 = iq2.insertTag(i)
|
||||||
iq3.insertTag(j).putData(ev[2][i][j])
|
for j in ev[2][i].keys():
|
||||||
else:
|
iq3.insertTag(j).putData(ev[2][i][j])
|
||||||
iq2.insertTag(i).putData(ev[2][i])
|
else:
|
||||||
con.send(iq)
|
iq2.insertTag(i).putData(ev[2][i])
|
||||||
|
con.send(iq)
|
||||||
#('AGENT_LOGGING', account, (agent, typ))
|
#('AGENT_LOGGING', account, (agent, typ))
|
||||||
elif ev[0] == 'AGENT_LOGGING':
|
elif ev[0] == 'AGENT_LOGGING':
|
||||||
t = ev[2][1];
|
if con:
|
||||||
if not t:
|
t = ev[2][1];
|
||||||
t='available';
|
if not t:
|
||||||
p = common.jabber.Presence(to=ev[2][0], type=t)
|
t='available';
|
||||||
con.send(p)
|
p = common.jabber.Presence(to=ev[2][0], type=t)
|
||||||
|
con.send(p)
|
||||||
#('LOG_NB_LINE', account, jid)
|
#('LOG_NB_LINE', account, jid)
|
||||||
elif ev[0] == 'LOG_NB_LINE':
|
elif ev[0] == 'LOG_NB_LINE':
|
||||||
fic = open(LOGPATH + ev[2], "r")
|
fic = open(LOGPATH + ev[2], "r")
|
||||||
|
@ -908,48 +921,56 @@ 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':
|
||||||
p = common.jabber.Presence(to='%s@%s/%s' % (ev[2][1], ev[2][2], \
|
if con:
|
||||||
ev[2][0]))
|
p = common.jabber.Presence(to='%s@%s/%s' % (ev[2][1], ev[2][2], \
|
||||||
con.send(p)
|
ev[2][0]))
|
||||||
|
con.send(p)
|
||||||
#('GC_MSG', account, (jid, msg))
|
#('GC_MSG', account, (jid, msg))
|
||||||
elif ev[0] == 'GC_MSG':
|
elif ev[0] == 'GC_MSG':
|
||||||
msg = common.jabber.Message(ev[2][0], ev[2][1])
|
if con:
|
||||||
msg.setType('groupchat')
|
msg = common.jabber.Message(ev[2][0], ev[2][1])
|
||||||
con.send(msg)
|
msg.setType('groupchat')
|
||||||
self.hub.sendPlugin('MSGSENT', ev[1], ev[2])
|
con.send(msg)
|
||||||
|
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':
|
||||||
msg = common.jabber.Message(ev[2][0])
|
if con:
|
||||||
msg.setType('groupchat')
|
msg = common.jabber.Message(ev[2][0])
|
||||||
msg.setSubject(ev[2][1])
|
msg.setType('groupchat')
|
||||||
con.send(msg)
|
msg.setSubject(ev[2][1])
|
||||||
|
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 ev[2][2] == 'offline':
|
if con:
|
||||||
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
if ev[2][2] == 'offline':
|
||||||
ev[2][0]), type = 'unavailable', status = ev[2][3]))
|
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
||||||
else:
|
ev[2][0]), type = 'unavailable', status = ev[2][3]))
|
||||||
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
else:
|
||||||
ev[2][0]), type = 'available', show = ev[2][2], status = \
|
con.send(common.jabber.Presence(to = '%s/%s' % (ev[2][1], \
|
||||||
ev[2][3]))
|
ev[2][0]), type = 'available', show = ev[2][2], status = \
|
||||||
|
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':
|
||||||
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
if con:
|
||||||
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).insertTag('item')
|
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
||||||
item.putAttr('nick', ev[2][1])
|
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).\
|
||||||
item.putAttr('role', ev[2][2])
|
insertTag('item')
|
||||||
id = con.getAnID()
|
item.putAttr('nick', ev[2][1])
|
||||||
iq.setID(id)
|
item.putAttr('role', ev[2][2])
|
||||||
con.send(iq)
|
id = con.getAnID()
|
||||||
|
iq.setID(id)
|
||||||
|
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':
|
||||||
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
if con:
|
||||||
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).insertTag('item')
|
iq = common.jabber.Iq(type='set', to=ev[2][0])
|
||||||
item.putAttr('jid', ev[2][1])
|
item = iq.setQuery(common.jabber.NS_P_MUC_ADMIN).\
|
||||||
item.putAttr('affiliation', ev[2][2])
|
insertTag('item')
|
||||||
id = con.getAnID()
|
item.putAttr('jid', ev[2][1])
|
||||||
iq.setID(id)
|
item.putAttr('affiliation', ev[2][2])
|
||||||
con.send(iq)
|
id = con.getAnID()
|
||||||
|
iq.setID(id)
|
||||||
|
con.send(iq)
|
||||||
#('GPGPASSPHRASE', account, passphrase)
|
#('GPGPASSPHRASE', account, passphrase)
|
||||||
elif ev[0] == 'GPGPASSPHRASE':
|
elif ev[0] == 'GPGPASSPHRASE':
|
||||||
if USE_GPG:
|
if USE_GPG:
|
||||||
|
@ -962,14 +983,15 @@ 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':
|
||||||
hostname = self.cfgParser.tab[ev[1]]['hostname']
|
if con:
|
||||||
iq = common.jabber.Iq(type='set', to=hostname)
|
hostname = self.cfgParser.tab[ev[1]]['hostname']
|
||||||
q = iq.setQuery(common.jabber.NS_REGISTER)
|
iq = common.jabber.Iq(type='set', to=hostname)
|
||||||
q.insertTag('username').insertData(ev[2][1])
|
q = iq.setQuery(common.jabber.NS_REGISTER)
|
||||||
q.insertTag('password').insertData(ev[2][0])
|
q.insertTag('username').insertData(ev[2][1])
|
||||||
id = con.getAnID()
|
q.insertTag('password').insertData(ev[2][0])
|
||||||
iq.setID(id)
|
id = con.getAnID()
|
||||||
con.send(iq)
|
iq.setID(id)
|
||||||
|
con.send(iq)
|
||||||
else:
|
else:
|
||||||
log.debug(_("Unknown Command %s") % ev[0])
|
log.debug(_("Unknown Command %s") % ev[0])
|
||||||
if self.mode == 'server':
|
if self.mode == 'server':
|
||||||
|
|
Loading…
Add table
Reference in a new issue