<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -14,13 +14,17 @@ class AdHocCommands:
         self.commands = xmpp.commands.Commands(transport.disco)
         self.commands.PlugIn(transport.jabber)
 
-        # jep-0133 commands:
-        transport.cmdonlineusers = Online_Users_Command(transport.userlist,jid=config.jid)
-        transport.cmdonlineusers.plugin(self.commands)
-        transport.cmdactiveusers = Active_Users_Command(transport.userlist,jid=config.jid)
-        transport.cmdactiveusers.plugin(self.commands)
-        transport.cmdregisteredusers = Registered_Users_Command(self.userfile,jid=config.jid)
-        transport.cmdregisteredusers.plugin(self.commands)
+        # XEP-0133 commands:
+        transport.cmdadduser = Add_User_Command(self.userfile,jid=config.jid)
+        transport.cmdadduser.plugin(self.commands)
+        transport.cmddeleteuser = Delete_User_Command(self.userfile,jid=config.jid)
+        transport.cmddeleteuser.plugin(self.commands)
+        transport.cmdlistregisteredusers = List_Registered_Users_Command(self.userfile,jid=config.jid)
+        transport.cmdlistregisteredusers.plugin(self.commands)
+        transport.cmdlistonlineusers = List_Online_Users_Command(transport.userlist,jid=config.jid)
+        transport.cmdlistonlineusers.plugin(self.commands)
+        transport.cmdlistactiveusers = List_Active_Users_Command(transport.userlist,jid=config.jid)
+        transport.cmdlistactiveusers.plugin(self.commands)
         transport.cmdeditadminusers = Edit_Admin_List_Command(jid=config.jid)
         transport.cmdeditadminusers.plugin(self.commands)
         transport.cmdrestartservice = Restart_Service_Command(transport,jid=config.jid)</diff>
      <filename>adhoc.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,20 @@
 
-# Service administration commands Jep-0133 for the xmpppy based transports written by Mike Albon
+# Service administration commands XEP-0133 for the xmpppy based transports written by Mike Albon
 import xmpp, string
 from xmpp.protocol import *
 import xmpp.commands
 import config
 from xml.dom.minidom import parse
 
-&quot;&quot;&quot;This file is the JEP-0133 commands that are applicable to the transports.
+&quot;&quot;&quot;This file is the XEP-0133 commands that are applicable to the transports.
 
 Implemented commands as follows:
 
-4.18. Registered_Users_Command: Return a list of Registered Users
-4.20. Online_Users_Command: Return a list of Online Users
-4.21. Active_Users_Command: Return a list of Active Users
+4.1.  Add_User_Command: 
+4.2.  Delete_User_Command: 
+4.18. List_Registered_Users_Command: Return a list of Registered Users
+4.20. List_Online_Users_Command: Return a list of Online Users
+4.21. List_Active_Users_Command: Return a list of Active Users
 4.29. Edit_Admin_List_Command: Edit the Administrators list
 4.30. Restart_Service_Command: Restarts the Service
 4.31. Shutdown_Service_Command: Shuts down the Service
@@ -20,18 +22,148 @@ Implemented commands as follows:
 
 &quot;&quot;&quot;
 
-class Online_Users_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This is the online users command as documented in section 4.20 of JEP-0133.
+class Add_User_Command(xmpp.commands.Command_Handler_Prototype):
+    &quot;&quot;&quot;This is the add user command as documented in section 4.1 of XEP-0133.&quot;&quot;&quot;
+    name = NS_ADMIN_ADD_USER
+    description = 'Add User'
+    discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
+
+    def __init__(self,userfile,jid=''):
+        &quot;&quot;&quot;Initialise the command object&quot;&quot;&quot;
+        xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
+        self.initial = {'execute':self.cmdFirstStage }
+        self.userfile = userfile
+
+    def _DiscoHandler(self,conn,request,type):
+        &quot;&quot;&quot;The handler for discovery events&quot;&quot;&quot;
+        if request.getFrom().getStripped() in config.admins:
+            return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
+        else:
+            return None
+
+    def cmdFirstStage(self,conn,request):
+        &quot;&quot;&quot;Set the session ID, and return the form containing the user's jid&quot;&quot;&quot;
+        if request.getFrom().getStripped() in config.admins:
+           # Setup session ready for form reply
+           session = self.getSessionID()
+           self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
+           # Setup form with existing data in
+           reply = request.buildReply('result')
+           form = DataForm(title='Adding a User',data=['Fill out this form to add a user', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The Jabber ID for the account to be added', typ='jid-single', name='accountjid')])
+           replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
+           reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
+           self._owner.send(reply)
+        else:
+           self._owner.send(Error(request,ERR_FORBIDDEN))
+        raise NodeProcessed
+
+    def cmdSecondStage(self,conn,request):
+        &quot;&quot;&quot;Apply and save the config&quot;&quot;&quot;
+        form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
+        session = request.getTagAttr('command','sessionid')
+        if self.sessions.has_key(session):
+            if self.sessions[session]['jid'] == request.getFrom():
+                reply = request.buildReply('result')
+                fromstripped = form.getField('accountjid').getValue().encode('utf8')
+                if not self.userfile.has_key(fromstripped):
+                    self.userfile[fromstripped] = {}
+                    self.userfile.sync()
+                reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
+                self._owner.send(reply)
+            else:
+                self._owner.send(Error(request,ERR_BAD_REQUEST))
+        else:
+            self._owner.send(Error(request,ERR_BAD_REQUEST))   
+        raise NodeProcessed
+
+    def cmdCancel(self,conn,request):
+        session = request.getTagAttr('command','sessionid')
+        if self.sessions.has_key(session):
+            del self.sessions[session]
+            reply = request.buildReply('result')
+            reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
+            self._owner.send(reply)
+        else:
+            self._owner.send(Error(request,ERR_BAD_REQUEST))
+        raise NodeProcessed
+
+class Delete_User_Command(xmpp.commands.Command_Handler_Prototype):
+    &quot;&quot;&quot;This is the delete user command as documented in section 4.1 of XEP-0133.&quot;&quot;&quot;
+    name = NS_ADMIN_DELETE_USER
+    description = 'Delete User'
+    discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
+
+    def __init__(self,userfile,jid=''):
+        &quot;&quot;&quot;Initialise the command object&quot;&quot;&quot;
+        xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
+        self.initial = {'execute':self.cmdFirstStage }
+        self.userfile = userfile
+
+    def _DiscoHandler(self,conn,request,type):
+        &quot;&quot;&quot;The handler for discovery events&quot;&quot;&quot;
+        if request.getFrom().getStripped() in config.admins:
+            return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
+        else:
+            return None
+
+    def cmdFirstStage(self,conn,request):
+        &quot;&quot;&quot;Set the session ID, and return the form containing the user's jid&quot;&quot;&quot;
+        if request.getFrom().getStripped() in config.admins:
+           # Setup session ready for form reply
+           session = self.getSessionID()
+           self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
+           # Setup form with existing data in
+           reply = request.buildReply('result')
+           form = DataForm(title='Deleting a User',data=['Fill out this form to delete a user', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The Jabber ID for the account to be deleted', typ='jid-single', name='accountjid')])
+           replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
+           reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
+           self._owner.send(reply)
+        else:
+           self._owner.send(Error(request,ERR_FORBIDDEN))
+        raise NodeProcessed
+
+    def cmdSecondStage(self,conn,request):
+        &quot;&quot;&quot;Apply and save the config&quot;&quot;&quot;
+        form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
+        session = request.getTagAttr('command','sessionid')
+        if self.sessions.has_key(session):
+            if self.sessions[session]['jid'] == request.getFrom():
+                reply = request.buildReply('result')
+                fromstripped = form.getField('accountjid').getValue().encode('utf8')
+                if self.userfile.has_key(fromstripped):
+                    del self.userfile[fromstripped]
+                    self.userfile.sync()
+                reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
+                self._owner.send(reply)
+            else:
+                self._owner.send(Error(request,ERR_BAD_REQUEST))
+        else:
+            self._owner.send(Error(request,ERR_BAD_REQUEST))   
+        raise NodeProcessed
+
+    def cmdCancel(self,conn,request):
+        session = request.getTagAttr('command','sessionid')
+        if self.sessions.has_key(session):
+            del self.sessions[session]
+            reply = request.buildReply('result')
+            reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
+            self._owner.send(reply)
+        else:
+            self._owner.send(Error(request,ERR_BAD_REQUEST))
+        raise NodeProcessed
+
+class List_Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
+    &quot;&quot;&quot;This is the registered users command as documented in section 4.18 of XEP-0133.
     At the current time, no provision is made for splitting the userlist into sections&quot;&quot;&quot;
-    name = NS_ADMIN_ONLINE_USERS_LIST
-    description = 'Get List of Online Users'
+    name = NS_ADMIN_REGISTERED_USERS_LIST
+    description = 'Get List of Registered Users'
     discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
 
-    def __init__(self,users,jid=''):
+    def __init__(self,userfile,jid=''):
         &quot;&quot;&quot;Initialise the command object&quot;&quot;&quot;
         xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
         self.initial = { 'execute':self.cmdFirstStage }
-        self.users = users
+        self.userfile = userfile
 
     def _DiscoHandler(self,conn,request,type):
         &quot;&quot;&quot;The handler for discovery events&quot;&quot;&quot;
@@ -44,18 +176,18 @@ class Online_Users_Command(xmpp.commands.Command_Handler_Prototype):
         &quot;&quot;&quot;Build the reply to complete the request&quot;&quot;&quot;
         if request.getFrom().getStripped() in config.admins:
             reply = request.buildReply('result')
-            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of online users',name='onlineuserjids',value=self.users.keys(),typ='jid-multi')])
+            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of registered users',name='registereduserjids',value=self.userfile.keys(),typ='jid-multi')])
             reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
             self._owner.send(reply)
         else:
             self._owner.send(Error(request,ERR_FORBIDDEN))
         raise NodeProcessed
 
-class Active_Users_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This is the active users command as documented in section 4.21 of JEP-0133.
+class List_Online_Users_Command(xmpp.commands.Command_Handler_Prototype):
+    &quot;&quot;&quot;This is the online users command as documented in section 4.20 of XEP-0133.
     At the current time, no provision is made for splitting the userlist into sections&quot;&quot;&quot;
-    name = NS_ADMIN_ACTIVE_USERS_LIST
-    description = 'Get List of Active Users'
+    name = NS_ADMIN_ONLINE_USERS_LIST
+    description = 'Get List of Online Users'
     discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
 
     def __init__(self,users,jid=''):
@@ -75,25 +207,25 @@ class Active_Users_Command(xmpp.commands.Command_Handler_Prototype):
         &quot;&quot;&quot;Build the reply to complete the request&quot;&quot;&quot;
         if request.getFrom().getStripped() in config.admins:
             reply = request.buildReply('result')
-            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of active users',name='activeuserjids',value=self.users.keys(),typ='jid-multi')])
+            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of online users',name='onlineuserjids',value=self.users.keys(),typ='jid-multi')])
             reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
             self._owner.send(reply)
         else:
             self._owner.send(Error(request,ERR_FORBIDDEN))
         raise NodeProcessed
 
-class Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This is the active users command as documented in section 4.18 of JEP-0133.
+class List_Active_Users_Command(xmpp.commands.Command_Handler_Prototype):
+    &quot;&quot;&quot;This is the active users command as documented in section 4.21 of XEP-0133.
     At the current time, no provision is made for splitting the userlist into sections&quot;&quot;&quot;
-    name = NS_ADMIN_REGISTERED_USERS_LIST
-    description = 'Get List of Registered Users'
+    name = NS_ADMIN_ACTIVE_USERS_LIST
+    description = 'Get List of Active Users'
     discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
 
-    def __init__(self,userfile,jid=''):
+    def __init__(self,users,jid=''):
         &quot;&quot;&quot;Initialise the command object&quot;&quot;&quot;
         xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
         self.initial = { 'execute':self.cmdFirstStage }
-        self.userfile = userfile
+        self.users = users
 
     def _DiscoHandler(self,conn,request,type):
         &quot;&quot;&quot;The handler for discovery events&quot;&quot;&quot;
@@ -106,7 +238,7 @@ class Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
         &quot;&quot;&quot;Build the reply to complete the request&quot;&quot;&quot;
         if request.getFrom().getStripped() in config.admins:
             reply = request.buildReply('result')
-            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of registered users',name='registereduserjids',value=self.userfile.keys(),typ='jid-multi')])
+            form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of active users',name='activeuserjids',value=self.users.keys(),typ='jid-multi')])
             reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
             self._owner.send(reply)
         else:
@@ -115,8 +247,8 @@ class Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
 
 
 class Edit_Admin_List_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This command enables the editing of the administrators list as documented in section 4.29 of JEP-0133.
-    (the users of JEP-0133 commands in this case)&quot;&quot;&quot;
+    &quot;&quot;&quot;This command enables the editing of the administrators list as documented in section 4.29 of XEP-0133.
+    (the users of XEP-0133 commands in this case)&quot;&quot;&quot;
     name = NS_ADMIN_EDIT_ADMIN
     description = 'Edit Admin List'
     discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
@@ -205,7 +337,7 @@ class Edit_Admin_List_Command(xmpp.commands.Command_Handler_Prototype):
 
 
 class Restart_Service_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This is the restart service command as documented in section 4.30 of JEP-0133.&quot;&quot;&quot;
+    &quot;&quot;&quot;This is the restart service command as documented in section 4.30 of XEP-0133.&quot;&quot;&quot;
     name = NS_ADMIN_RESTART
     description = 'Restart Service'
     discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
@@ -269,7 +401,7 @@ class Restart_Service_Command(xmpp.commands.Command_Handler_Prototype):
         raise NodeProcessed
 
 class Shutdown_Service_Command(xmpp.commands.Command_Handler_Prototype):
-    &quot;&quot;&quot;This is the shutdown service command as documented in section 4.31 of JEP-0133.&quot;&quot;&quot;
+    &quot;&quot;&quot;This is the shutdown service command as documented in section 4.31 of XEP-0133.&quot;&quot;&quot;
     name = NS_ADMIN_SHUTDOWN
     description = 'Shut Down Service'
     discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]</diff>
      <filename>jep0133.py</filename>
    </modified>
    <modified>
      <diff>@@ -454,18 +454,18 @@ class Transport:
 
     def xmpp_iq_register_get(self, con, event):
         if event.getTo() == config.jid:
-            username = []
-            password = []
-            clientid = []
+            username = ''
+            password = ''
+            clientid = ''
             fromjid = event.getFrom().getStripped().encode('utf8')
             queryPayload = [Node('instructions', payload = 'Please provide your MXit username and password')]
             if userfile.has_key(fromjid):
-                try:
+                if userfile[fromjid].has_key('username'):
                     username = userfile[fromjid]['username']
+                if userfile[fromjid].has_key('password'):
                     password = userfile[fromjid]['password']
+                if userfile[fromjid].has_key('clientid'):
                     clientid = userfile[fromjid]['clientid']
-                except:
-                    pass
                 queryPayload += [
                     Node('username',payload=username),
                     Node('password',payload=password),
@@ -496,15 +496,6 @@ class Transport:
             password = False
             clientid = False
             fromjid = event.getFrom().getStripped().encode('utf8')
-            #for each in event.getQueryPayload():
-            #    if each.getName() == 'username':
-            #        username = each.getData()
-            #        print &quot;Have username &quot;, username
-            #    elif each.getName() == 'password':
-            #        password = each.getData()
-            #        print &quot;Have password &quot;, password
-            #    elif each.getName() == 'remove':
-            #        remove = True
             query = event.getTag('query')
             if query.getTag('username'):
                 username = query.getTagData('username')
@@ -601,11 +592,12 @@ class Transport:
             v = m.addChild(name='vCard', namespace=NS_VCARD)
             nick = mxitid
             groups = []
-            for each in self.userlist[fromstripped].buddylist.keys():
-                for (buddymxitid,buddynick) in self.userlist[fromstripped].buddylist[each]:
-                    if mxitid == buddymxitid:
-                        nick = buddynick
-                        groups.append(each)
+            if self.userlist.has_key(fromstripped):
+                for each in self.userlist[fromstripped].buddylist.keys():
+                    for (buddymxitid,buddynick) in self.userlist[fromstripped].buddylist[each]:
+                        if mxitid == buddymxitid:
+                            nick = buddynick
+                            groups.append(each)
             v.setTagData(tag='NICKNAME', val=nick)
             v.setTagData(tag='ROLE', val=','.join(groups))            
             if userfile[fromstripped].has_key('avatar') and \</diff>
      <filename>mxit.py</filename>
    </modified>
    <modified>
      <diff>@@ -23,7 +23,7 @@ def mxit_mkhdr(length, packettype, status, sessionid):
     return 'ln=%s%s' % (len(data) + length - 1, data)
 
 def mxit_dehdr(text):
-    # Unpack yahoo header into list
+    # Unpack mxit header into list
     zeroat = text.find('\x00')
     if zeroat &lt; 0: return [[0,0,0,0],'']
     hdr = text[:zeroat].split('=')</diff>
      <filename>mxit_helpers.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>86a6e21244bb5d8a4dc949cde16689f70bf6c6fa</id>
    </parent>
  </parents>
  <author>
    <name>Norman Rasmussen</name>
    <email>norman@rasmussen.co.za</email>
  </author>
  <url>http://github.com/normanr/mxit-transport/commit/28635eb3ca419ada13124cc196702743093c4018</url>
  <id>28635eb3ca419ada13124cc196702743093c4018</id>
  <committed-date>2007-07-21T18:15:57-07:00</committed-date>
  <authored-date>2007-07-21T18:15:57-07:00</authored-date>
  <message>Added service admin commands for adding and deleting users</message>
  <tree>53d8c41e2bb3a1f6169c3511a2ddf547385b97d6</tree>
  <committer>
    <name>Norman Rasmussen</name>
    <email>norman@rasmussen.co.za</email>
  </committer>
</commit>
