Beispiel #1
0
 def onDiscoInfo(self,iq):
     v_id=gen.jidToId(iq.get("to"))
     cmdList=self.makeCmdList(iq.get("to"),v_id)
     resp=createReply(iq)
     resp.set("type","result")
     q=addChild(resp,"query",'http://jabber.org/protocol/disco#info')
     node=iq.find('{http://jabber.org/protocol/disco#info}query').get("node")
     q.set('node',node)
     if (node=='http://jabber.org/protocol/commands'):
         # FIXME
         name=u"Команды [ad-hoc]"
         
         #addChild(q,'identity',attrs={"name":u"Команды [ad-hoc]","category":"automation","type":"command-node"})
             #q.addElement("identity").attributes={"name":"pyvk-t commands","category":"automation","type":"command-node"}
         #else:
             #addChild(q,'identity',attrs={"name":"pyvk-t commands","category":"automation","type":"command-node"})
             #q.addElement("identity").attributes={"category":"automation","type":"command-node"}
         ntype="command-list"    
     else:
         try:
             cmd=cmdList[node[4:]]
             name=cmd.name
         except KeyError:
             name="unknown"
         ntype="command-node"
     addChild(q,'identity',attrs={"name":name,"category":"automation","type":ntype})
     addChild(q,"feature",attrs={'var':'http://jabber.org/protocol/commands'})
     addChild(q,"feature",attrs={'var':'jabber:x:data'})
     return resp
Beispiel #2
0
 def onDiscoItems(self,iq):
     cmdList={}
     #if (iq["to"]==self.trans.jid):
         #cmdList=self.transportCmdList
     v_id=gen.jidToId(iq.get("to"))
     cmdList=self.makeCmdList(iq.get("from"),v_id)
     #resp=xmlstream.toResponse(iq)
     resp=createReply(iq)
     resp.set("type",'result')
     q=addChild(resp,"query",'http://jabber.org/protocol/disco#items',attrs={'node':'http://jabber.org/protocol/commands'})
     #q["node"]='http://jabber.org/protocol/commands'
     for i in cmdList:
         addChild(q,'item',attrs={"jid":iq.get("to"), "node":"cmd:%s"%i, "name":cmdList[i].name})
         #q.addElement("item").attributes=
     return resp
Beispiel #3
0
    def onIqSet(self,iq):
        URI='http://jabber.org/protocol/commands'
        iqcmd=iq.find('{http://jabber.org/protocol/commands}command')
        node=iqcmd.get("node")[4:]
        v_id=gen.jidToId(iq.get("to"))
        cmdList=self.makeCmdList(iq.get("from"),v_id)
        if (cmdList.has_key(node)):
            #FIXME different actions
            act=iqcmd.get('action')
            
            if act=="cancel":
                ans=createReply(iq,'result')
                q=addChild(ans,'command',URI,{'status':'cancelled','node':node})
                sid=iqcmd.get('sessionid',None)
                if sid:
                    q.set("sessionid",sid)
                return ans
            x=iqcmd.find('{jabber:x:data}x')
            if (x!=None):
                args=self.getXdata(x)
            else:
                args={}
            cmd=cmdList[node]
            res=cmd.run(iq.get("from"),args,to_id=v_id)
            resp=createReply(iq,'result')
            c=addChild(resp,'command',URI,{'node':'cmd:%s'%node,'status':res['status'],'sessionid':'0'})
            x=addChild(c,'x','jabber:x:data')
            if (res.has_key("form")):
                act=addChild(c,'actions',attrs={'execute':'next'})
                addChild(act,'next')
                x.set('type','form')
            else:
                x.set('type','result')
            try:
                addChild(x,'title').text=res["title"]
            except KeyError:
                addChild(x,'title','result')
            try:
                addChild(x,'instructions').text=res["message"]
            except KeyError:
                pass
            try:
                fields=res["form"]["fields"]
                for i in fields:
                    try:
                        ft=fields[i][0]
                    except IndexError:
                        ft='text-single'
                    try:
                        fd=fields[i][1]
                    except IndexError:
                        fd=i
                    try:
                        val=fields[i][2]
                        #print "val=",val
                        if (val==True):
                            val='1'
                        elif(val==False):
                            val='0'
                        #FIXME
                    except IndexError:
                        #print "initial value isn't set"
                        val=''
                    fn=addChild(x,'field',attrs={"type":ft, 'var':i,'label':fd})
                    if(val):
                        addChild(fn,'value').text=val

                    #f=x.addElement("field")
                    ##f.attributes={"type":ft, 'var':i,'label':fd}
                    #f.addElement("value").addContent(val)
            except KeyError:
                pass
            return resp
        else:
            err=createReply(iq,'error')
            addChild(err,'{urn:ietf:params:xml:ns:xmpp-stanzas}item-not-found')
            logging.warning('cant find command %s'%node)
            return err
            #FIXME error strnza
            pass