Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
589fd699 by lovetox at 2021-05-27T20:38:15+02:00
AdHoc: Don’t expect session id for one stage commands

- - - - -


1 changed file:

- nbxmpp/modules/adhoc.py


Changes:

=====================================
nbxmpp/modules/adhoc.py
=====================================
@@ -66,18 +66,18 @@ class AdHoc(BaseModule):
         yield command_list
 
     @iq_request_task
-    def execute_command(self, command, action=None, dataform=None):
+    def execute_command(self, cmd, action=None, dataform=None):
         _task = yield
 
         if action is None:
             action = AdHocAction.EXECUTE
-        attrs = {'node': command.node,
+        attrs = {'node': cmd.node,
                  'xmlns': Namespace.COMMANDS,
                  'action': action.value}
-        if command.sessionid is not None:
-            attrs['sessionid'] = command.sessionid
+        if cmd.sessionid is not None:
+            attrs['sessionid'] = cmd.sessionid
 
-        response = yield _make_command(command, attrs, dataform)
+        response = yield _make_command(cmd, attrs, dataform)
         if response.isError():
             raise StanzaError(response)
 
@@ -89,10 +89,6 @@ class AdHoc(BaseModule):
         if node is None:
             raise MalformedStanzaError('node attribute missing', response)
 
-        sessionid = command.getAttr('sessionid')
-        if sessionid is None:
-            raise MalformedStanzaError('sessionid attribute missing', response)
-
         status = command.getAttr('status')
         if status is None:
             raise MalformedStanzaError('status attribute missing', response)
@@ -103,6 +99,10 @@ class AdHoc(BaseModule):
 
         status = AdHocStatus(status)
 
+        sessionid = command.getAttr('sessionid')
+        if sessionid is None and _expect_sessionid(status, cmd.sessionid):
+            raise MalformedStanzaError('sessionid attribute missing', response)
+
         try:
             notes = _parse_notes(command)
         except ValueError as error:
@@ -192,3 +192,9 @@ def _parse_actions(command):
         default = actions[0]
 
     return actions, default
+
+
+def _expect_sessionid(status, sent_sessionid):
+    # Session id should only be expected for multiple stage commands
+    # or when we initialize the session (set the session attribute)
+    return status != status.COMPLETED or sent_sessionid is not None



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/589fd69983bac85a6947004e010f3e22b5cb5053

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/589fd69983bac85a6947004e010f3e22b5cb5053
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to