Checks if the module function is called with the right number of parameters * and all mandatory parameters are given * Return: * 0 - correct call * -1 - too few parameters * -2 - too many parameters * -3 - mandatory parameter omitted */
| 41 | * -3 - mandatory parameter omitted |
| 42 | */ |
| 43 | int check_cmd_call_params(const cmd_export_t *cmd, action_elem_t *elems, int no_params) |
| 44 | { |
| 45 | const struct cmd_param *param; |
| 46 | int n=0, m=0, i; |
| 47 | |
| 48 | for (param=cmd->params; param->flags; param++, n++) |
| 49 | if (!(param->flags & CMD_PARAM_OPT)) |
| 50 | m = n+1; |
| 51 | |
| 52 | if (no_params < m) /* check the minimum number of arguments for the call, |
| 53 | * including optional params that must be explicitly omitted */ |
| 54 | return -1; |
| 55 | else if (no_params > n) |
| 56 | return -2; |
| 57 | |
| 58 | for (i=1, param=cmd->params; i<=no_params; i++, param++) |
| 59 | if (!(param->flags & CMD_PARAM_OPT) && elems[i].type == NULLV_ST) |
| 60 | return -3; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* simillar function to check_cmd_call_params but for async cmds */ |
| 66 | int check_acmd_call_params(const acmd_export_t *acmd, action_elem_t *elems, int no_params) |
no outgoing calls
no test coverage detected