| 1 | /* | 
|---|
| 2 | * Copyright (c) 2008 Tim Post | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | * modification, are permitted provided that the following conditions | 
|---|
| 7 | * are met: | 
|---|
| 8 | * | 
|---|
| 9 | * - Redistributions of source code must retain the above copyright | 
|---|
| 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 15 | *   derived from this software without specific prior written permission. | 
|---|
| 16 | * | 
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | #ifndef CMDS_H | 
|---|
| 30 | #define CMDS_H | 
|---|
| 31 |  | 
|---|
| 32 | #include "config.h" | 
|---|
| 33 | #include "scli.h" | 
|---|
| 34 |  | 
|---|
| 35 | /* Temporary to store strings */ | 
|---|
| 36 | #define EXT_HELP      "extended" | 
|---|
| 37 | #define SHORT_HELP    "short" | 
|---|
| 38 | #define TEST_ANNOUNCE "Hello, this is :" | 
|---|
| 39 |  | 
|---|
| 40 | /* Simple levels of help displays */ | 
|---|
| 41 | #define HELP_SHORT 0 | 
|---|
| 42 | #define HELP_LONG  1 | 
|---|
| 43 |  | 
|---|
| 44 | /* Acceptable buffer sizes (for strn functions) */ | 
|---|
| 45 | /* TODO: Move me, other files duplicate these needlessly */ | 
|---|
| 46 | #define BUFF_LARGE  1024 | 
|---|
| 47 | #define BUFF_SMALL  255 | 
|---|
| 48 |  | 
|---|
| 49 | /* Return macros for int type entry points */ | 
|---|
| 50 | #define CMD_FAILURE 1 | 
|---|
| 51 | #define CMD_SUCCESS 0 | 
|---|
| 52 |  | 
|---|
| 53 | /* Types for module command entry and help */ | 
|---|
| 54 | typedef int (* mod_entry_t)(char **); | 
|---|
| 55 | typedef void (* mod_help_t)(unsigned int); | 
|---|
| 56 |  | 
|---|
| 57 | /* Built-in commands need to be able to modify cliuser_t */ | 
|---|
| 58 | typedef int (* builtin_entry_t)(char **, cliuser_t *); | 
|---|
| 59 | typedef void (* builtin_help_t)(unsigned int); | 
|---|
| 60 |  | 
|---|
| 61 | /* Module structure */ | 
|---|
| 62 | typedef struct { | 
|---|
| 63 | const char *name;   /* Name of the command */ | 
|---|
| 64 | const char *desc;   /* Description of the command */ | 
|---|
| 65 | mod_entry_t entry;  /* Command (exec) entry function */ | 
|---|
| 66 | mod_help_t help;    /* Command (help) entry function */ | 
|---|
| 67 | } module_t; | 
|---|
| 68 |  | 
|---|
| 69 | /* Builtin structure, same as modules except different types of entry points */ | 
|---|
| 70 | typedef struct { | 
|---|
| 71 | const char *name; | 
|---|
| 72 | const char *desc; | 
|---|
| 73 | builtin_entry_t entry; | 
|---|
| 74 | builtin_help_t help; | 
|---|
| 75 | int restricted; | 
|---|
| 76 | } builtin_t; | 
|---|
| 77 |  | 
|---|
| 78 | /* Declared in cmds/modules/modules.h and cmds/builtins/builtins.h | 
|---|
| 79 | * respectively */ | 
|---|
| 80 | extern module_t modules[]; | 
|---|
| 81 | extern builtin_t builtins[]; | 
|---|
| 82 |  | 
|---|
| 83 | /* Prototypes for module launchers */ | 
|---|
| 84 | extern int module_is_restricted(int); | 
|---|
| 85 | extern int is_module(const char *); | 
|---|
| 86 | extern int is_module_alias(const char *); | 
|---|
| 87 | extern char *alias_for_module(const char *); | 
|---|
| 88 | extern int help_module(int, unsigned int); | 
|---|
| 89 | extern int run_module(int, char *[], iostate_t *); | 
|---|
| 90 |  | 
|---|
| 91 | /* Prototypes for builtin launchers */ | 
|---|
| 92 | extern int builtin_is_restricted(int); | 
|---|
| 93 | extern int is_builtin(const char *); | 
|---|
| 94 | extern int is_builtin_alias(const char *); | 
|---|
| 95 | extern char *alias_for_builtin(const char *); | 
|---|
| 96 | extern int help_builtin(int, unsigned int); | 
|---|
| 97 | extern int run_builtin(int, char *[], cliuser_t *, iostate_t *); | 
|---|
| 98 |  | 
|---|
| 99 | #endif | 
|---|