[36ab7c7] | 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 |
|
---|
[216d6fc] | 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 */
|
---|
[809813d] | 50 | #define CMD_FAILURE 1
|
---|
[216d6fc] | 51 | #define CMD_SUCCESS 0
|
---|
| 52 |
|
---|
| 53 | /* Types for module command entry and help */
|
---|
[1433ecda] | 54 | typedef int (*mod_entry_t)(char **);
|
---|
| 55 | typedef void (*mod_help_t)(unsigned int);
|
---|
[216d6fc] | 56 |
|
---|
| 57 | /* Built-in commands need to be able to modify cliuser_t */
|
---|
[1433ecda] | 58 | typedef int (*builtin_entry_t)(char **, cliuser_t *);
|
---|
| 59 | typedef void (*builtin_help_t)(unsigned int);
|
---|
[216d6fc] | 60 |
|
---|
| 61 | /* Module structure */
|
---|
| 62 | typedef struct {
|
---|
[a000878c] | 63 | const char *name; /* Name of the command */
|
---|
| 64 | const char *desc; /* Description of the command */
|
---|
[216d6fc] | 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 {
|
---|
[a000878c] | 71 | const char *name;
|
---|
| 72 | const char *desc;
|
---|
[216d6fc] | 73 | builtin_entry_t entry;
|
---|
| 74 | builtin_help_t help;
|
---|
| 75 | int restricted;
|
---|
| 76 | } builtin_t;
|
---|
| 77 |
|
---|
[7c3fb9b] | 78 | /*
|
---|
| 79 | * Declared in cmds/modules/modules.h and cmds/builtins/builtins.h
|
---|
| 80 | * respectively
|
---|
| 81 | */
|
---|
[216d6fc] | 82 | extern module_t modules[];
|
---|
| 83 | extern builtin_t builtins[];
|
---|
| 84 |
|
---|
| 85 | /* Prototypes for module launchers */
|
---|
| 86 | extern int module_is_restricted(int);
|
---|
| 87 | extern int is_module(const char *);
|
---|
| 88 | extern int is_module_alias(const char *);
|
---|
[a000878c] | 89 | extern char *alias_for_module(const char *);
|
---|
[216d6fc] | 90 | extern int help_module(int, unsigned int);
|
---|
[6ea9a1d] | 91 | extern int run_module(int, char *[], iostate_t *);
|
---|
[216d6fc] | 92 |
|
---|
| 93 | /* Prototypes for builtin launchers */
|
---|
| 94 | extern int builtin_is_restricted(int);
|
---|
| 95 | extern int is_builtin(const char *);
|
---|
| 96 | extern int is_builtin_alias(const char *);
|
---|
[a000878c] | 97 | extern char *alias_for_builtin(const char *);
|
---|
[216d6fc] | 98 | extern int help_builtin(int, unsigned int);
|
---|
[6ea9a1d] | 99 | extern int run_builtin(int, char *[], cliuser_t *, iostate_t *);
|
---|
[216d6fc] | 100 |
|
---|
| 101 | #endif
|
---|