Forráskód Böngészése

hiding command from autocompletion if not permitted

stefan 1 éve
szülő
commit
8c35d8ba95

+ 1 - 1
src/shellmatta.c

@@ -625,7 +625,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
 
 #ifdef SHELLMATTA_AUTHENTICATION
                             cmdRet = SHELLMATTA_OK;
-                            if (SHELLMATTA_OK == shellmatta_auth_is_cmd_permitted(handle, cmd))
+                            if (SHELLMATTA_OK == shellmatta_auth_is_cmd_permitted(inst, cmd))
                             {
                                 cmdExecuted = 1u;
                                 cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);

+ 1 - 2
src/shellmatta_auth.c

@@ -348,10 +348,9 @@ shellmatta_retCode_t shellmatta_auth_init(shellmatta_handle_t   handle,
     return ret;
 }
 
-shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(shellmatta_handle_t handle, shellmatta_cmd_t *cmd)
+shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(const shellmatta_instance_t *inst, shellmatta_cmd_t *cmd)
 {
     shellmatta_retCode_t    ret     = SHELLMATTA_ERROR;
-    shellmatta_instance_t   *inst   = (shellmatta_instance_t*)handle;
     shellmatta_auth_perm_t  *permList;
     uint32_t                i;
 

+ 2 - 2
src/shellmatta_auth.h

@@ -29,8 +29,8 @@ extern const shellmatta_cmd_t shellmatta_auth_loginCmd;
 extern const shellmatta_cmd_t shellmatta_auth_logoutCmd;
 
 
-extern shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(shellmatta_handle_t    handle,
-                                                             shellmatta_cmd_t       *cmd);
+shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(const shellmatta_instance_t   *inst,
+                                                      shellmatta_cmd_t              *cmd);
 
 #endif
 

+ 17 - 0
src/shellmatta_autocomplete.c

@@ -20,6 +20,9 @@
 #include "shellmatta.h"
 #include "shellmatta_autocomplete.h"
 #include "shellmatta_utils.h"
+#ifdef SHELLMATTA_AUTHENTICATION
+#include "shellmatta_auth.h"
+#endif
 #include <stdint.h>
 #include <string.h>
 
@@ -50,6 +53,13 @@ void autocomplete_run(shellmatta_instance_t *inst)
         /** -# loop through all registered commands */
         while (NULL != cmd)
         {
+#ifdef SHELLMATTA_AUTHENTICATION
+            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(inst, cmd))
+            {
+                cmd = cmd->next;
+                continue;
+            }
+#endif
             /** -# check if command matches the input */
             if(    (strlen(cmd->cmd) >= inst->cursor)
                 && (0 == strncmp(cmd->cmd, inst->buffer, inst->cursor)))
@@ -98,6 +108,13 @@ void autocomplete_run(shellmatta_instance_t *inst)
         /** -# loop through all registered commands */
         while (NULL != cmd)
         {
+#ifdef SHELLMATTA_AUTHENTICATION
+            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(inst, cmd))
+            {
+                cmd = cmd->next;
+                continue;
+            }
+#endif
             /** -# check if command matches the input */
             if(    (strlen(cmd->cmd) >= inst->cursor)
                 && (0 == strncmp(cmd->cmd, inst->buffer, inst->cursor)))

+ 2 - 2
src/shellmatta_utils.c

@@ -398,7 +398,7 @@ static shellmatta_retCode_t helpCmdFct(const shellmatta_handle_t handle, const c
         while(NULL != cmd)
         {
 #ifdef SHELLMATTA_AUTHENTICATION
-            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(handle, cmd))
+            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(inst, cmd))
             {
                 cmd = cmd->next;
                 continue;
@@ -417,7 +417,7 @@ static shellmatta_retCode_t helpCmdFct(const shellmatta_handle_t handle, const c
         while(NULL != cmd)
         {
 #ifdef SHELLMATTA_AUTHENTICATION
-            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(handle, cmd))
+            if (SHELLMATTA_OK != shellmatta_auth_is_cmd_permitted(inst, cmd))
             {
                 cmd = cmd->next;
                 continue;