2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/common/commands.py
|
2006-07-17 15:40:25 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006-2007 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Tomasz Melcer <liori AT exroot.org>
|
|
|
|
## Copyright (C) 2007 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
2006-07-17 15:40:25 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-07-17 15:40:25 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-07-17 15:40:25 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-07-17 15:40:25 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-07-17 15:40:25 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
import xmpp
|
|
|
|
import helpers
|
|
|
|
import dataforms
|
|
|
|
import gajim
|
|
|
|
|
|
|
|
class AdHocCommand:
|
|
|
|
commandnode = 'command'
|
|
|
|
commandname = 'The Command'
|
|
|
|
commandfeatures = (xmpp.NS_DATA,)
|
|
|
|
|
|
|
|
@staticmethod
|
2006-07-17 19:52:37 +02:00
|
|
|
def isVisibleFor(samejid):
|
|
|
|
''' This returns True if that command should be visible and invokable
|
|
|
|
for others.
|
2007-01-14 22:38:34 +01:00
|
|
|
samejid - True when command is invoked by an entity with the same bare
|
|
|
|
jid.'''
|
2006-07-17 19:52:37 +02:00
|
|
|
return True
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
def __init__(self, conn, jid, sessionid):
|
|
|
|
self.connection = conn
|
|
|
|
self.jid = jid
|
|
|
|
self.sessionid = sessionid
|
|
|
|
|
2007-01-14 22:38:34 +01:00
|
|
|
def buildResponse(self, request, status = 'executing', defaultaction = None,
|
|
|
|
actions = None):
|
2006-07-17 15:40:25 +02:00
|
|
|
assert status in ('executing', 'completed', 'canceled')
|
|
|
|
|
|
|
|
response = request.buildReply('result')
|
|
|
|
cmd = response.addChild('command', {
|
2008-01-21 00:24:03 +01:00
|
|
|
'xmlns': xmpp.NS_COMMANDS,
|
2006-07-17 15:40:25 +02:00
|
|
|
'sessionid': self.sessionid,
|
|
|
|
'node': self.commandnode,
|
2008-01-21 00:24:03 +01:00
|
|
|
'status': status})
|
2006-07-17 15:40:25 +02:00
|
|
|
if defaultaction is not None or actions is not None:
|
|
|
|
if defaultaction is not None:
|
2007-01-14 22:38:34 +01:00
|
|
|
assert defaultaction in ('cancel', 'execute', 'prev', 'next',
|
|
|
|
'complete')
|
2006-07-17 15:40:25 +02:00
|
|
|
attrs = {'action': defaultaction}
|
|
|
|
else:
|
|
|
|
attrs = {}
|
|
|
|
|
|
|
|
cmd.addChild('actions', attrs, actions)
|
|
|
|
return response, cmd
|
|
|
|
|
2006-11-18 19:39:02 +01:00
|
|
|
def badRequest(self, stanza):
|
2007-01-14 22:38:34 +01:00
|
|
|
self.connection.connection.send(xmpp.Error(stanza, xmpp.NS_STANZAS + \
|
|
|
|
' bad-request'))
|
2006-07-17 19:52:37 +02:00
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
def cancel(self, request):
|
2007-01-14 22:38:34 +01:00
|
|
|
response, cmd = self.buildResponse(request, status = 'canceled')
|
2006-07-17 19:52:37 +02:00
|
|
|
self.connection.connection.send(response)
|
2006-07-17 15:40:25 +02:00
|
|
|
return False # finish the session
|
|
|
|
|
|
|
|
class ChangeStatusCommand(AdHocCommand):
|
|
|
|
commandnode = 'change-status'
|
2007-01-14 22:38:34 +01:00
|
|
|
commandname = _('Change status information')
|
2006-07-17 15:40:25 +02:00
|
|
|
|
2006-07-17 19:52:37 +02:00
|
|
|
@staticmethod
|
|
|
|
def isVisibleFor(samejid):
|
|
|
|
''' Change status is visible only if the entity has the same bare jid. '''
|
|
|
|
return samejid
|
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
def execute(self, request):
|
|
|
|
# first query...
|
2007-01-14 22:38:34 +01:00
|
|
|
response, cmd = self.buildResponse(request, defaultaction = 'execute',
|
|
|
|
actions = ['execute'])
|
2006-07-17 15:40:25 +02:00
|
|
|
|
2007-01-14 22:38:34 +01:00
|
|
|
cmd.addChild(node = dataforms.SimpleDataForm(
|
|
|
|
title = _('Change status'),
|
|
|
|
instructions = _('Set the presence type and description'),
|
|
|
|
fields = [
|
2006-11-18 19:39:02 +01:00
|
|
|
dataforms.Field('list-single',
|
2007-01-14 22:38:34 +01:00
|
|
|
var = 'presence-type',
|
|
|
|
label = 'Type of presence:',
|
|
|
|
options = [
|
|
|
|
(u'free-for-chat', _('Free for chat')),
|
|
|
|
(u'online', _('Online')),
|
|
|
|
(u'away', _('Away')),
|
|
|
|
(u'xa', _('Extended away')),
|
|
|
|
(u'dnd', _('Do not disturb')),
|
|
|
|
(u'offline', _('Offline - disconnect'))],
|
|
|
|
value = 'online',
|
|
|
|
required = True),
|
2006-11-18 19:39:02 +01:00
|
|
|
dataforms.Field('text-multi',
|
2007-01-14 22:38:34 +01:00
|
|
|
var = 'presence-desc',
|
|
|
|
label = _('Presence description:'))]))
|
2006-07-17 15:40:25 +02:00
|
|
|
|
2006-07-17 19:52:37 +02:00
|
|
|
self.connection.connection.send(response)
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
# for next invocation
|
|
|
|
self.execute = self.changestatus
|
|
|
|
|
|
|
|
return True # keep the session
|
|
|
|
|
|
|
|
def changestatus(self, request):
|
|
|
|
# check if the data is correct
|
|
|
|
try:
|
2007-01-14 22:38:34 +01:00
|
|
|
form = dataforms.SimpleDataForm(extend = request.getTag('command').\
|
|
|
|
getTag('x'))
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2006-11-18 19:39:02 +01:00
|
|
|
self.badRequest(request)
|
2006-07-17 15:40:25 +02:00
|
|
|
return False
|
2007-01-14 22:38:34 +01:00
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
try:
|
2006-11-18 19:39:02 +01:00
|
|
|
presencetype = form['presence-type'].value
|
|
|
|
if not presencetype in \
|
2007-02-04 19:57:25 +01:00
|
|
|
('free-for-chat', 'online', 'away', 'xa', 'dnd', 'offline'):
|
2006-11-18 19:39:02 +01:00
|
|
|
self.badRequest(request)
|
2006-07-17 19:52:37 +02:00
|
|
|
return False
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception: # KeyError if there's no presence-type field in form or
|
2006-11-18 19:39:02 +01:00
|
|
|
# AttributeError if that field is of wrong type
|
|
|
|
self.badRequest(request)
|
2006-07-17 19:52:37 +02:00
|
|
|
return False
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
try:
|
2006-11-18 19:39:02 +01:00
|
|
|
presencedesc = form['presence-desc'].value
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception: # same exceptions as in last comment
|
2006-07-17 15:40:25 +02:00
|
|
|
presencedesc = u''
|
|
|
|
|
2007-01-14 22:38:34 +01:00
|
|
|
response, cmd = self.buildResponse(request, status = 'completed')
|
|
|
|
cmd.addChild('note', {}, _('The status has been changed.'))
|
2006-07-17 15:40:25 +02:00
|
|
|
|
2007-01-06 20:05:45 +01:00
|
|
|
# if going offline, we need to push response so it won't go into
|
|
|
|
# queue and disappear
|
2007-03-15 13:53:29 +01:00
|
|
|
self.connection.connection.send(response, now = presencetype == 'offline')
|
2006-07-17 15:40:25 +02:00
|
|
|
|
2006-07-17 19:52:37 +02:00
|
|
|
# send new status
|
2007-01-14 22:38:34 +01:00
|
|
|
gajim.interface.roster.send_status(self.connection.name, presencetype,
|
|
|
|
presencedesc)
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
return False # finish the session
|
|
|
|
|
2007-01-14 22:38:34 +01:00
|
|
|
def find_current_groupchats(account):
|
|
|
|
import message_control
|
|
|
|
rooms = []
|
|
|
|
for gc_control in gajim.interface.msg_win_mgr.get_controls(
|
2008-09-26 19:41:07 +02:00
|
|
|
message_control.TYPE_GC) + gajim.interface.minimized_controls[account].\
|
|
|
|
values():
|
2007-01-14 22:38:34 +01:00
|
|
|
acct = gc_control.account
|
|
|
|
# check if account is the good one
|
|
|
|
if acct != account:
|
|
|
|
continue
|
|
|
|
room_jid = gc_control.room_jid
|
|
|
|
nick = gc_control.nick
|
2008-10-07 22:41:59 +02:00
|
|
|
if room_jid in gajim.gc_connected[acct] and \
|
2007-01-14 22:38:34 +01:00
|
|
|
gajim.gc_connected[acct][room_jid]:
|
|
|
|
rooms.append((room_jid, nick,))
|
|
|
|
return rooms
|
|
|
|
|
|
|
|
|
|
|
|
class LeaveGroupchatsCommand(AdHocCommand):
|
|
|
|
commandnode = 'leave-groupchats'
|
2007-12-02 20:29:22 +01:00
|
|
|
commandname = _('Leave Groupchats')
|
2007-01-14 22:38:34 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def isVisibleFor(samejid):
|
|
|
|
''' Change status is visible only if the entity has the same bare jid. '''
|
|
|
|
return samejid
|
|
|
|
|
|
|
|
def execute(self, request):
|
|
|
|
# first query...
|
|
|
|
response, cmd = self.buildResponse(request, defaultaction = 'execute',
|
|
|
|
actions=['execute'])
|
|
|
|
options = []
|
|
|
|
account = self.connection.name
|
|
|
|
for gc in find_current_groupchats(account):
|
|
|
|
options.append((u'%s' %(gc[0]), _('%(nickname)s on %(room_jid)s') % \
|
|
|
|
{'nickname': gc[1], 'room_jid': gc[0]}))
|
|
|
|
if not len(options):
|
|
|
|
response, cmd = self.buildResponse(request, status = 'completed')
|
|
|
|
cmd.addChild('note', {}, _('You have not joined a groupchat.'))
|
|
|
|
|
|
|
|
self.connection.connection.send(response)
|
|
|
|
return False
|
|
|
|
|
|
|
|
cmd.addChild(node=dataforms.SimpleDataForm(
|
|
|
|
title = _('Leave Groupchats'),
|
|
|
|
instructions = _('Choose the groupchats you want to leave'),
|
|
|
|
fields=[
|
|
|
|
dataforms.Field('list-multi',
|
|
|
|
var = 'groupchats',
|
|
|
|
label = _('Groupchats'),
|
|
|
|
options = options,
|
|
|
|
required = True)]))
|
|
|
|
|
|
|
|
self.connection.connection.send(response)
|
|
|
|
|
|
|
|
# for next invocation
|
|
|
|
self.execute = self.leavegroupchats
|
2008-05-13 03:59:10 +02:00
|
|
|
|
2007-01-14 22:38:34 +01:00
|
|
|
return True # keep the session
|
|
|
|
|
|
|
|
def leavegroupchats(self, request):
|
|
|
|
# check if the data is correct
|
|
|
|
try:
|
|
|
|
form = dataforms.SimpleDataForm(extend = request.getTag('command').\
|
|
|
|
getTag('x'))
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2007-01-14 22:38:34 +01:00
|
|
|
self.badRequest(request)
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
gc = form['groupchats'].values
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception: # KeyError if there's no groupchats in form
|
2007-01-14 22:38:34 +01:00
|
|
|
self.badRequest(request)
|
|
|
|
return False
|
|
|
|
account = self.connection.name
|
|
|
|
try:
|
|
|
|
for room_jid in gc:
|
2008-05-13 03:59:10 +02:00
|
|
|
gc_control = gajim.interface.msg_win_mgr.get_gc_control(room_jid,
|
2007-01-14 22:38:34 +01:00
|
|
|
account)
|
2008-09-26 19:41:07 +02:00
|
|
|
if not gc_control:
|
|
|
|
gc_control = gajim.interface.minimized_controls[account]\
|
|
|
|
[room_jid]
|
|
|
|
gc_control.shutdown()
|
|
|
|
gajim.interface.roster.remove_groupchat(room_jid, account)
|
|
|
|
continue
|
2007-01-14 22:38:34 +01:00
|
|
|
gc_control.parent_win.remove_tab(gc_control, None, force = True)
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception: # KeyError if there's no such room opened
|
2007-01-14 22:38:34 +01:00
|
|
|
self.badRequest(request)
|
|
|
|
return False
|
|
|
|
response, cmd = self.buildResponse(request, status = 'completed')
|
2007-01-21 15:13:39 +01:00
|
|
|
note = _('You left the following groupchats:')
|
2007-01-14 22:38:34 +01:00
|
|
|
for room_jid in gc:
|
|
|
|
note += '\n\t' + room_jid
|
|
|
|
cmd.addChild('note', {}, note)
|
|
|
|
|
|
|
|
self.connection.connection.send(response)
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2007-06-23 21:44:09 +02:00
|
|
|
class ForwardMessagesCommand(AdHocCommand):
|
|
|
|
# http://www.xmpp.org/extensions/xep-0146.html#forward
|
|
|
|
commandnode = 'forward-messages'
|
|
|
|
commandname = _('Forward unread messages')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def isVisibleFor(samejid):
|
|
|
|
''' Change status is visible only if the entity has the same bare jid. '''
|
|
|
|
return samejid
|
|
|
|
|
|
|
|
def execute(self, request):
|
|
|
|
account = self.connection.name
|
|
|
|
# Forward messages
|
|
|
|
events = gajim.events.get_events(account, types=['chat', 'normal'])
|
|
|
|
j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
|
|
|
|
for jid in events:
|
|
|
|
for event in events[jid]:
|
|
|
|
self.connection.send_message(j, event.parameters[0], '',
|
|
|
|
type=event.type_, subject=event.parameters[1],
|
2008-09-26 13:11:38 +02:00
|
|
|
resource=resource, forward_from=jid, delayed=event.time_)
|
2007-06-23 21:44:09 +02:00
|
|
|
|
|
|
|
# Inform other client of completion
|
|
|
|
response, cmd = self.buildResponse(request, status = 'completed')
|
|
|
|
cmd.addChild('note', {}, _('All unread messages have been forwarded.'))
|
|
|
|
|
|
|
|
self.connection.connection.send(response)
|
|
|
|
|
|
|
|
return False # finish the session
|
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
class ConnectionCommands:
|
|
|
|
''' This class depends on that it is a part of Connection() class. '''
|
|
|
|
def __init__(self):
|
|
|
|
# a list of all commands exposed: node -> command class
|
|
|
|
self.__commands = {}
|
2007-06-23 21:44:09 +02:00
|
|
|
for cmdobj in (ChangeStatusCommand, ForwardMessagesCommand,
|
|
|
|
LeaveGroupchatsCommand):
|
2006-07-17 15:40:25 +02:00
|
|
|
self.__commands[cmdobj.commandnode] = cmdobj
|
|
|
|
|
|
|
|
# a list of sessions; keys are tuples (jid, sessionid, node)
|
|
|
|
self.__sessions = {}
|
|
|
|
|
2006-07-17 19:52:37 +02:00
|
|
|
def getOurBareJID(self):
|
|
|
|
return gajim.get_jid_from_account(self.name)
|
|
|
|
|
|
|
|
def isSameJID(self, jid):
|
|
|
|
''' Tests if the bare jid given is the same as our bare jid. '''
|
|
|
|
return xmpp.JID(jid).getStripped() == self.getOurBareJID()
|
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
def commandListQuery(self, con, iq_obj):
|
|
|
|
iq = iq_obj.buildReply('result')
|
|
|
|
jid = helpers.get_full_jid_from_iq(iq_obj)
|
|
|
|
q = iq.getTag('query')
|
2007-10-01 11:40:34 +02:00
|
|
|
# buildReply don't copy the node attribute. Re-add it
|
|
|
|
q.setAttr('node', xmpp.NS_COMMANDS)
|
2006-07-17 15:40:25 +02:00
|
|
|
|
|
|
|
for node, cmd in self.__commands.iteritems():
|
2006-07-17 19:52:37 +02:00
|
|
|
if cmd.isVisibleFor(self.isSameJID(jid)):
|
2006-07-17 15:40:25 +02:00
|
|
|
q.addChild('item', {
|
|
|
|
# TODO: find the jid
|
2007-01-14 22:38:34 +01:00
|
|
|
'jid': self.getOurBareJID() + u'/' + self.server_resource,
|
2006-07-17 15:40:25 +02:00
|
|
|
'node': node,
|
|
|
|
'name': cmd.commandname})
|
|
|
|
|
|
|
|
self.connection.send(iq)
|
|
|
|
|
2007-12-01 12:46:46 +01:00
|
|
|
def commandInfoQuery(self, con, iq_obj):
|
|
|
|
''' Send disco#info result for query for command (JEP-0050, example 6.).
|
2006-07-17 15:40:25 +02:00
|
|
|
Return True if the result was sent, False if not. '''
|
|
|
|
jid = helpers.get_full_jid_from_iq(iq_obj)
|
|
|
|
node = iq_obj.getTagAttr('query', 'node')
|
|
|
|
|
|
|
|
if node not in self.__commands: return False
|
|
|
|
|
|
|
|
cmd = self.__commands[node]
|
2006-07-17 19:52:37 +02:00
|
|
|
if cmd.isVisibleFor(self.isSameJID(jid)):
|
2006-07-17 15:40:25 +02:00
|
|
|
iq = iq_obj.buildReply('result')
|
|
|
|
q = iq.getTag('query')
|
|
|
|
q.addChild('identity', attrs = {'type': 'command-node',
|
2007-02-04 19:57:25 +01:00
|
|
|
'category': 'automation',
|
|
|
|
'name': cmd.commandname})
|
2006-07-17 15:40:25 +02:00
|
|
|
q.addChild('feature', attrs = {'var': xmpp.NS_COMMANDS})
|
|
|
|
for feature in cmd.commandfeatures:
|
|
|
|
q.addChild('feature', attrs = {'var': feature})
|
|
|
|
|
|
|
|
self.connection.send(iq)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2007-12-01 12:46:46 +01:00
|
|
|
def commandItemsQuery(self, con, iq_obj):
|
|
|
|
''' Send disco#items result for query for command.
|
|
|
|
Return True if the result was sent, False if not. '''
|
|
|
|
jid = helpers.get_full_jid_from_iq(iq_obj)
|
|
|
|
node = iq_obj.getTagAttr('query', 'node')
|
|
|
|
|
|
|
|
if node not in self.__commands: return False
|
|
|
|
|
|
|
|
cmd = self.__commands[node]
|
|
|
|
if cmd.isVisibleFor(self.isSameJID(jid)):
|
|
|
|
iq = iq_obj.buildReply('result')
|
|
|
|
self.connection.send(iq)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
def _CommandExecuteCB(self, con, iq_obj):
|
|
|
|
jid = helpers.get_full_jid_from_iq(iq_obj)
|
|
|
|
|
|
|
|
cmd = iq_obj.getTag('command')
|
|
|
|
if cmd is None: return
|
|
|
|
|
|
|
|
node = cmd.getAttr('node')
|
|
|
|
if node is None: return
|
|
|
|
|
|
|
|
sessionid = cmd.getAttr('sessionid')
|
|
|
|
if sessionid is None:
|
|
|
|
# we start a new command session... only if we are visible for the jid
|
2006-12-17 00:30:07 +01:00
|
|
|
# and command exist
|
|
|
|
if node not in self.__commands.keys():
|
|
|
|
self.connection.send(
|
2007-01-14 22:38:34 +01:00
|
|
|
xmpp.Error(iq_obj, xmpp.NS_STANZAS + ' item-not-found'))
|
2006-12-17 00:30:07 +01:00
|
|
|
raise xmpp.NodeProcessed
|
|
|
|
|
2006-07-17 15:40:25 +02:00
|
|
|
newcmd = self.__commands[node]
|
2006-07-17 19:52:37 +02:00
|
|
|
if not newcmd.isVisibleFor(self.isSameJID(jid)):
|
2006-07-17 15:40:25 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
# generate new sessionid
|
|
|
|
sessionid = self.connection.getAnID()
|
|
|
|
|
|
|
|
# create new instance and run it
|
2007-01-14 22:38:34 +01:00
|
|
|
obj = newcmd(conn = self, jid = jid, sessionid = sessionid)
|
2006-07-17 15:40:25 +02:00
|
|
|
rc = obj.execute(iq_obj)
|
|
|
|
if rc:
|
|
|
|
self.__sessions[(jid, sessionid, node)] = obj
|
2006-07-17 19:52:37 +02:00
|
|
|
raise xmpp.NodeProcessed
|
2006-07-17 15:40:25 +02:00
|
|
|
else:
|
|
|
|
# the command is already running, check for it
|
|
|
|
magictuple = (jid, sessionid, node)
|
|
|
|
if magictuple not in self.__sessions:
|
|
|
|
# we don't have this session... ha!
|
|
|
|
return
|
|
|
|
|
|
|
|
action = cmd.getAttr('action')
|
|
|
|
obj = self.__sessions[magictuple]
|
|
|
|
|
|
|
|
try:
|
2007-01-14 22:38:34 +01:00
|
|
|
if action == 'cancel':
|
|
|
|
rc = obj.cancel(iq_obj)
|
|
|
|
elif action == 'prev':
|
|
|
|
rc = obj.prev(iq_obj)
|
|
|
|
elif action == 'next':
|
|
|
|
rc = obj.next(iq_obj)
|
2006-11-18 19:39:02 +01:00
|
|
|
elif action == 'execute' or action is None:
|
2007-01-14 22:38:34 +01:00
|
|
|
rc = obj.execute(iq_obj)
|
|
|
|
elif action == 'complete':
|
|
|
|
rc = obj.complete(iq_obj)
|
2006-07-17 15:40:25 +02:00
|
|
|
else:
|
|
|
|
# action is wrong. stop the session, send error
|
2006-07-17 19:52:37 +02:00
|
|
|
raise AttributeError
|
2006-07-17 15:40:25 +02:00
|
|
|
except AttributeError:
|
|
|
|
# the command probably doesn't handle invoked action...
|
|
|
|
# stop the session, return error
|
|
|
|
del self.__sessions[magictuple]
|
|
|
|
return
|
|
|
|
|
|
|
|
# delete the session if rc is False
|
|
|
|
if not rc:
|
|
|
|
del self.__sessions[magictuple]
|
|
|
|
|
|
|
|
raise xmpp.NodeProcessed
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-15 05:20:23 +02:00
|
|
|
# vim: se ts=3:
|