Annotation of libaitcli/inc/aitcli.h, revision 1.8

1.1       misho       1: /*************************************************************************
                      2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
1.8     ! misho       6: * $Id: aitcli.h,v 1.7.4.2 2013/10/08 11:29:59 misho Exp $
1.1       misho       7: *
1.4       misho       8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
1.6       misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
1.4       misho      16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
1.1       misho      46: #ifndef __AITCLI_H
                     47: #define __AITCLI_H
                     48: 
                     49: 
1.3       misho      50: #include <termios.h>
                     51: #include <sys/queue.h>
                     52: 
                     53: 
1.5       misho      54: #ifndef STRSIZ
1.3       misho      55: #define STRSIZ         256
1.5       misho      56: #endif
1.3       misho      57: 
                     58: /* Key definitions */
                     59: 
                     60: #define        K_F1            "\x1b\x4f\x50"
                     61: #define        K_F2            "\x1b\x4f\x51"
                     62: #define        K_F3            "\x1b\x4f\x52"
                     63: #define        K_F4            "\x1b\x4f\x53"
                     64: #define        K_F5            "\x1b\x5b\x31\x35\x7e"
                     65: #define        K_F6            "\x1b\x5b\x31\x37\x7e"
                     66: #define        K_F7            "\x1b\x5b\x31\x38\x7e"
                     67: #define        K_F8            "\x1b\x5b\x31\x39\x7e"
                     68: #define        K_F9            "\x1b\x5b\x32\x30\x7e"
                     69: #define        K_F10           "\x1b\x5b\x32\x31\x7e"
                     70: #define        K_F11           "\x1b\x5b\x32\x33\x7e"
                     71: #define        K_F12           "\x1b\x5b\x32\x34\x7e"
                     72: #define K_CTRL_F1      "\x1b\x5b\x6b"
                     73: #define K_CTRL_F2      "\x1b\x5b\x6c"
                     74: #define K_CTRL_F3      "\x1b\x5b\x6d"
                     75: #define K_CTRL_F4      "\x1b\x5b\x6e"
                     76: #define K_CTRL_F5      "\x1b\x5b\x6f"
                     77: #define K_CTRL_F6      "\x1b\x5b\x70"
                     78: #define K_CTRL_F7      "\x1b\x5b\x71"
                     79: #define K_CTRL_F8      "\x1b\x5b\x72"
                     80: #define K_CTRL_F9      "\x1b\x5b\x73"
                     81: #define K_CTRL_F10     "\x1b\x5b\x74"
                     82: #define K_CTRL_F11     "\x1b\x5b\x75"
                     83: #define K_CTRL_F12     "\x1b\x5b\x76"
                     84: #define K_CTRL_SH_F1   "\x1b\x5b\x77"
                     85: #define K_CTRL_SH_F2   "\x1b\x5b\x78"
                     86: #define K_CTRL_SH_F3   "\x1b\x5b\x79"
                     87: #define K_CTRL_SH_F4   "\x1b\x5b\x7a"
                     88: #define K_CTRL_SH_F5   "\x1b\x5b\x40"
                     89: #define K_CTRL_SH_F6   "\x1b\x5b\x5b"
                     90: #define K_CTRL_SH_F7   "\x1b\x5b\x5c"
                     91: #define K_CTRL_SH_F8   "\x1b\x5b\x5d"
                     92: #define K_CTRL_SH_F9   "\x1b\x5b\x5e"
                     93: #define K_CTRL_SH_F10  "\x1b\x5b\x5f"
                     94: #define K_CTRL_SH_F11  "\x1b\x5b\x60"
                     95: #define K_CTRL_SH_F12  "\x1b\x5b\x7b"
                     96: 
                     97: #define K_INS          "\x1b\x5b\x32\x7e"
                     98: #define K_DEL          "\x1b\x5b\x33\x7e"
                     99: #define K_PGUP         "\x1b\x5b\x35\x7e"
                    100: #define K_PGDN         "\x1b\x5b\x36\x7e"
                    101: #define K_HOME         "\x1b\x5b\x48"
                    102: #define K_END          "\x1b\x5b\x46"
                    103: #define K_UP           "\x1b\x5b\x41"
                    104: #define K_DOWN         "\x1b\x5b\x42"
                    105: #define K_RIGHT                "\x1b\x5b\x43"
                    106: #define K_LEFT         "\x1b\x5b\x44"
                    107: 
                    108: #define K_NULL         "\x0"
                    109: #define K_CR           "\xd"
                    110: #define K_BTAB         "\x1b\x5b\x5a"
                    111: #define K_TAB          "\x9"
                    112: #define K_ENTER                "\xa"
                    113: #define K_ESC          "\x1b"
                    114: #define K_BACKSPACE    "\x7f"
                    115: #define K_SPACE                "\x20"
                    116: 
                    117: #define K_CTRL_SPACE   K_NULL
                    118: #define K_CTRL_2       K_NULL
                    119: #define K_CTRL_A       "\x1"
                    120: #define K_CTRL_B       "\x2"
                    121: #define K_CTRL_C       "\x3"
                    122: #define K_CTRL_D       "\x4"
                    123: #define K_CTRL_E       "\x5"
                    124: #define K_CTRL_F       "\x6"
                    125: #define K_CTRL_G       "\x7"
                    126: #define K_CTRL_H       "\x8"
                    127: #define K_CTRL_I       K_TAB
                    128: #define K_CTRL_J       K_ENTER
                    129: #define K_CTRL_K       "\xb"
                    130: #define K_CTRL_L       "\xc"
                    131: #define K_CTRL_M       K_ENTER         // K_CR
                    132: #define K_CTRL_N       "\xe"
                    133: #define K_CTRL_O       "\xf"
                    134: #define K_CTRL_P       "\x10"
                    135: #define K_CTRL_Q       "\x11"
                    136: #define K_CTRL_R       "\x12"
                    137: #define K_CTRL_S       "\x13"
                    138: #define K_CTRL_T       "\x14"
                    139: #define K_CTRL_U       "\x15"
                    140: #define K_CTRL_V       "\x16"
                    141: #define K_CTRL_W       "\x17"
                    142: #define K_CTRL_X       "\x18"
                    143: #define K_CTRL_Y       "\x19"
                    144: #define K_CTRL_Z       "\x1a"
                    145: #define K_CTRL_LBRACE  "\x1b"
                    146: #define K_CTRL_PIPE    "\x1c"
                    147: #define K_CTRL_RBRACE  "\x1d"
                    148: #define K_CTRL_6       "\x1e"
                    149: #define K_CTRL__       "\x1f"
                    150: 
                    151: 
                    152: #define K_X_CTRL_INS   "\x1b\x5b\x32\x3b\x35\x7e"
                    153: #define K_X_CTRL_DEL   "\x1b\x5b\x33\x3b\x35\x7e"
                    154: #define K_X_CTRL_PGUP  "\x1b\x5b\x35\x3b\x35\x7e"
                    155: #define K_X_CTRL_PGDN  "\x1b\x5b\x36\x3b\x35\x7e"
                    156: #define K_X_CTRL_HOME  "\x1b\x5b\x31\x3b\x35\x48"
                    157: #define K_X_CTRL_END   "\x1b\x5b\x31\x3b\x35\x46"
                    158: #define K_X_CTRL_UP    "\x1b\x5b\x31\x3b\x35\x41"
                    159: #define K_X_CTRL_DOWN  "\x1b\x5b\x31\x3b\x35\x42"
                    160: #define K_X_CTRL_RIGHT "\x1b\x5b\x31\x3b\x35\x43"
                    161: #define K_X_CTRL_LEFT  "\x1b\x5b\x31\x3b\x35\x44"
                    162: 
                    163: #define K_X_ALT_INS    "\x1b\x5b\x32\x3b\x33\x7e"
                    164: #define K_X_ALT_DEL    "\x1b\x5b\x33\x3b\x33\x7e"
                    165: #define K_X_ALT_PGUP   "\x1b\x5b\x35\x3b\x33\x7e"
                    166: #define K_X_ALT_PGDN   "\x1b\x5b\x36\x3b\x33\x7e"
                    167: #define K_X_ALT_HOME   "\x1b\x5b\x31\x3b\x33\x48"
                    168: #define K_X_ALT_END    "\x1b\x5b\x31\x3b\x33\x46"
                    169: #define K_X_ALT_UP     "\x1b\x5b\x31\x3b\x33\x41"
                    170: #define K_X_ALT_DOWN   "\x1b\x5b\x31\x3b\x33\x42"
                    171: #define K_X_ALT_RIGHT  "\x1b\x5b\x31\x3b\x33\x43"
                    172: #define K_X_ALT_LEFT   "\x1b\x5b\x31\x3b\x33\x44"
                    173: 
                    174: #define K_X_CTL_A_INS  "\x1b\x5b\x32\x3b\x37\x7e"
                    175: #define K_X_CTL_A_DEL  "\x1b\x5b\x33\x3b\x37\x7e"
                    176: #define K_X_CTL_A_PGUP "\x1b\x5b\x35\x3b\x37\x7e"
                    177: #define K_X_CTL_A_PGDN "\x1b\x5b\x36\x3b\x37\x7e"
                    178: #define K_X_CTL_A_HOME "\x1b\x5b\x31\x3b\x37\x48"
                    179: #define K_X_CTL_A_END  "\x1b\x5b\x31\x3b\x37\x46"
                    180: #define K_X_CTL_A_UP   "\x1b\x5b\x31\x3b\x37\x41"
                    181: #define K_X_CTL_A_DOWN "\x1b\x5b\x31\x3b\x37\x42"
                    182: #define K_X_CTL_A_RIGHT        "\x1b\x5b\x31\x3b\x37\x43"
                    183: #define K_X_CTL_A_LEFT "\x1b\x5b\x31\x3b\x37\x44"
                    184: 
                    185: 
                    186: /* History types */
                    187: 
                    188: struct tagHistory {
1.6       misho     189:        int                     hist_len;
                    190:        char                    hist_line[BUFSIZ];
1.3       misho     191: 
                    192:        TAILQ_ENTRY(tagHistory) hist_next;
1.1       misho     193: };
1.3       misho     194: typedef TAILQ_HEAD(tqHistoryHead, tagHistory) history_t;
                    195: 
                    196: /* Bind keys structure types */
                    197: 
1.7       misho     198: typedef int (*bindkey_func_t)(int idx, /* linebuffer_t * */ void * __restrict cli_buffer);
1.3       misho     199: typedef struct {
                    200:        int             key_len;
                    201:        unsigned char   key_ch[8];
                    202:        bindkey_func_t  key_func;
                    203: } bindkey_t;
                    204: 
                    205: 
                    206: /* Commands structure for CLI */
                    207: 
1.7       misho     208: typedef int (*cmd_func_t)(/*linebuffer_t **/ void * __restrict cli_buffer, int idx, 
                    209:                char ** __restrict args);
1.3       misho     210: struct tagCommand {
                    211:        int                     cmd_level;
                    212: 
                    213:        int                     cmd_len;
                    214:        char                    cmd_name[STRSIZ];
                    215: 
                    216:        char                    cmd_info[STRSIZ];
                    217:        char                    cmd_help[STRSIZ];
                    218: 
                    219:        cmd_func_t              cmd_func;
                    220: 
                    221:        SLIST_ENTRY(tagCommand) cmd_next;
                    222: };
                    223: typedef SLIST_HEAD(slCommandHead, tagCommand) commands_t;
                    224: 
                    225: 
                    226: /* Main structure, Buffer for CLI work with thread models ;-) special designed by M.Punov */
1.1       misho     227: 
1.3       misho     228: typedef struct {
                    229:        char                    line_mode;
1.1       misho     230: 
1.3       misho     231:        char                    *line_prompt;
                    232: 
                    233:        int                     line_bol;
                    234:        int                     line_eol;
                    235:        int                     line_len;
                    236:        char                    *line_buf;
                    237: 
                    238:        const struct tagHistory *line_h;
                    239:        history_t               line_history;
                    240: 
                    241:        bindkey_t               *line_keys;
                    242: 
                    243:        int                     line_level;
                    244:        commands_t              line_cmds;
                    245: 
                    246:        int                     line_in;
                    247:        int                     line_out;
                    248: } linebuffer_t;
                    249: 
                    250: 
                    251: /* Error support functions */
1.1       misho     252: 
                    253: // cli_GetErrno() Get error code of last operation
1.6       misho     254: int cli_GetErrno();
1.1       misho     255: // cli_GetError() Get error text of last operation
1.6       misho     256: const char *cli_GetError();
1.1       misho     257: 
1.3       misho     258: 
1.4       misho     259: /* TELNET support for CLI */
                    260: 
                    261: #define MAX_SUB_LEN    255
                    262: 
                    263: struct telnetAttrs {
                    264:        unsigned char ta_cmd;
                    265:        unsigned char ta_opt;
                    266:        unsigned char ta_sublen;
                    267:        unsigned char ta_sub[MAX_SUB_LEN];
                    268: };
                    269: 
                    270: 
                    271: #ifndef NDEBUG
                    272: /*
1.6       misho     273:  * cli_telnetDumpAttrs() - Telnet debug attributes list, if NDEBUG defined not include
                    274:  *
1.4       misho     275:  * @attr = attributes list
                    276:  * @nAttr = attributes list size
                    277:  * return: none
                    278: */
                    279: void cli_telnetDumpAttrs(struct telnetAttrs *attr, int nAttr);
                    280: #else
                    281: extern void cli_telnetDumpAttrs(struct telnetAttrs *, int);
                    282: #endif
                    283: 
                    284: 
                    285: /*
1.6       misho     286:  * cli_telnetRecv() - Telnet receive commands, negotiate with telnet peer
                    287:  *
1.4       misho     288:  * @sock = socket for communication
                    289:  * @attr = received attributes list, must be free after use, but if NULL receive in binary mode
                    290:  * @nAttr = received attributes list size, if is NULL receive in binary mode
                    291:  * @pdata = received data in supplied buffer
                    292:  * @datLen = buffer pdata size
                    293:  * return: 0 not present data; -1 error:: can`t read; -2 timeout; -3 EOF; >0 number of received bytes
                    294: */
                    295: int cli_telnetRecv(int sock, struct telnetAttrs **attr, int *nAttr, void *data, int datLen);
                    296: /*
1.6       misho     297:  * cli_telnetSend() - Telnet send commands, negotiate with telnet peer
                    298:  *
1.4       misho     299:  * @sock = socket for communication
                    300:  * @attr = send attributes list
                    301:  * @nAttr = send attributes list size
                    302:  * @data = data for send
                    303:  * @datLen = data size
                    304:  * @Term = Terminate with GA (Go Ahead), 1 send after data GA command
                    305:  * return: 0 not sended commands; -1 error:: can`t send; >0 number of sended bytes
                    306: */
                    307: int cli_telnetSend(int sock, struct telnetAttrs *attr, int nAttr, void *data, int datLen, int Term);
                    308: 
                    309: /*
1.6       misho     310:  * cli_telnet_Get_SubOpt() - Telnet get sub option function
                    311:  *
1.4       misho     312:  * @attr = input attribute
                    313:  * @code = sub-option code for opt
                    314:  * @data = sub-option data
                    315:  * @datLen = data size set max size in input, output return copy size
                    316:  * return: -1 can`t get option; !=-1 option code
                    317: */
1.6       misho     318: int cli_telnet_Get_SubOpt(struct telnetAttrs *attr, unsigned char *code, 
1.4       misho     319:                void *data, unsigned char *datLen);
                    320: /*
1.6       misho     321:  * cli_telnet_Set_SubOpt() - Telnet set sub option function
                    322:  *
1.4       misho     323:  * @attr = output attribute
                    324:  * @opt = attribute option
                    325:  * @code = sub-option code for opt, if 0xff not specified
                    326:  * @data = sub-option data, if NULL not specified
                    327:  * @datLen = data size, if 0 not specified
                    328:  * return: -1 can`t set sub-otion; 0 ok
                    329: */
1.6       misho     330: int cli_telnet_Set_SubOpt(struct telnetAttrs *attr, unsigned char opt, unsigned char code, 
1.4       misho     331:                void *data, unsigned char datLen);
                    332: 
                    333: /*
1.6       misho     334:  * cli_telnet_GetCmd() - Telnet get command
                    335:  *
1.4       misho     336:  * @attr = input attribute
                    337:  * return: -1 can`t get command; !=-1 command <<24 return sublen, <<8 return option, <<0 command
                    338: */
1.6       misho     339: unsigned int cli_telnet_GetCmd(struct telnetAttrs *attr);
1.4       misho     340: /*
1.6       misho     341:  * cli_telnet_SetCmd() - Telnet set command
                    342:  *
1.4       misho     343:  * @attr = input attribute
                    344:  * @cmd = command
                    345:  * @opt = option, if 0xff not specified
                    346:  * @arg1 = sub-option code, if 0xff not specified
                    347:  * @arg2 = sub-option data, if NULL not specified
                    348:  * @arg3 = sub-option data size, if 0 not specified data
                    349:  * return: -1 can`t set command; !=-1 ok
                    350: */
1.6       misho     351: int cli_telnet_SetCmd(struct telnetAttrs *attr, unsigned char cmd, unsigned char opt, ...);
1.4       misho     352: 
                    353: /*
1.6       misho     354:  * cli_telnet_Answer() - Automatic generate commands answer to send from telnet
                    355:  *
1.4       misho     356:  * @caps = Array of capability options
                    357:  * @nCaps = number of capability options
                    358:  * @attr = input attribute
                    359:  * @nAttr = number of input attributes
1.6       misho     360:  * @ans = output answered attributes, must be e_free() after use
1.4       misho     361:  * @Ans = number of output answered attributes
                    362:  * return: -1 can`t answer; !=-1 ok
                    363: */
                    364: int cli_telnet_Answer(unsigned char *caps, int nCaps, struct telnetAttrs *attr, int nAttr, 
                    365:                struct telnetAttrs **ans, int *Ans);
                    366: 
                    367: 
                    368: // Add capability option, x = 0 false, 1 true
                    369: #define ADD_CAPS(opt, x)       ((opt) | (x) ? 0x80 : 0)
                    370: // Is supported this option ...
                    371: #define SUP_CAPS(caps)         ((caps) & 0x80)
                    372: // get capability option
                    373: #define CAP(caps)              ((caps) & 0x7f)
                    374: 
                    375: 
1.3       misho     376: /* CLI Helper functions */
                    377: 
                    378: /*
1.6       misho     379:  * cli_Cmd_Unsupported() - Builtin helper function for unsupported commands
                    380:  *
1.7       misho     381:  * @cli_buffer = CLI buffer
1.8     ! misho     382:  * @idx = Config level
1.3       misho     383:  * @args = Parsed arguments array
                    384:  * return: RETCODE_OK ok
                    385: */
1.7       misho     386: int cli_Cmd_Unsupported(void * __restrict cli_buffer, int idx, char ** __restrict args);
1.3       misho     387: 
                    388: 
                    389: /* CLI Functions */
                    390: 
1.1       misho     391: /*
1.6       misho     392:  * cli_BindKey() - Bind function to key
                    393:  *
1.3       misho     394:  * @key = key structure
1.7       misho     395:  * @cli_buffer = CLI buffer
1.3       misho     396:  * return: RETCODE_ERR error, RETCODE_OK ok, >0 bind at position
1.1       misho     397: */
1.7       misho     398: int cli_BindKey(bindkey_t * __restrict key, linebuffer_t * __restrict cli_buffer);
1.3       misho     399: 
1.1       misho     400: 
                    401: /*
1.6       misho     402:  * cli_addCommand() - Add command to CLI session
                    403:  *
1.7       misho     404:  * @cli_buffer = CLI buffer
1.3       misho     405:  * @csCmd = Command name
1.8     ! misho     406:  * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels
1.3       misho     407:  * @funcCmd = Callback function when user call command
                    408:  * @csInfo = Inline information for command
                    409:  * @csHelp = Help line when call help
                    410:  * return: RETCODE_ERR error, RETCODE_OK ok
1.2       misho     411: */
1.3       misho     412: int
1.7       misho     413: cli_addCommand(linebuffer_t * __restrict cli_buffer, const char *csCmd, 
                    414:                int cliLevel, cmd_func_t funcCmd, 
1.3       misho     415:                const char *csInfo, const char *csHelp);
1.2       misho     416: /*
1.6       misho     417:  * cli_delCommand() - Delete command from CLI session
                    418:  *
1.7       misho     419:  * @cli_buffer = CLI buffer
1.3       misho     420:  * @csCmd = Command name
1.8     ! misho     421:  * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels
1.3       misho     422:  * return: RETCODE_ERR error, RETCODE_OK ok
1.1       misho     423: */
1.3       misho     424: int
1.7       misho     425: cli_delCommand(linebuffer_t * __restrict cli_buffer, const char *csCmd, int cliLevel);
1.1       misho     426: /*
1.6       misho     427:  * cli_updCommand() - Update command in CLI session
                    428:  *
1.7       misho     429:  * @cli_buffer = CLI buffer
1.3       misho     430:  * @csCmd = Command name
1.8     ! misho     431:  * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels
1.3       misho     432:  * @funcCmd = Callback function when user call command
                    433:  * @csInfo = Inline information for command
                    434:  * @csHelp = Help line when call help
                    435:  * return: RETCODE_ERR error, RETCODE_OK ok
1.2       misho     436: */
1.3       misho     437: int
1.7       misho     438: cli_updCommand(linebuffer_t * __restrict cli_buffer, const char *csCmd, 
                    439:                int cliLevel, cmd_func_t funcCmd, 
1.3       misho     440:                const char *csInfo, const char *csHelp);
                    441: 
1.2       misho     442: 
                    443: /*
1.6       misho     444:  * cli_addHistory() - Add line to history
                    445:  *
1.7       misho     446:  * @cli_buffer = CLI buffer
1.3       misho     447:  * @str = Add custom text or if NULL use readed line from CLI buffer
                    448:  * return: RETCODE_ERR error, RETCODE_OK ok
1.2       misho     449: */
1.7       misho     450: int cli_addHistory(linebuffer_t * __restrict cli_buffer, const char * __restrict str);
1.2       misho     451: /*
1.6       misho     452:  * cli_saveHistory() - Save history to file
                    453:  *
1.7       misho     454:  * @cli_buffer = CLI buffer
1.3       misho     455:  * @histfile = History filename, if NULL will be use default name
                    456:  * @lines = Maximum history lines to save
                    457:  * return: RETCODE_ERR error, RETCODE_OK ok
1.2       misho     458: */
1.7       misho     459: int cli_saveHistory(linebuffer_t * __restrict cli_buffer, const char *histfile, int lines);
1.3       misho     460: /*
1.6       misho     461:  * cli_loadHistory() - Load history from file
                    462:  *
1.7       misho     463:  * @cli_buffer = CLI buffer
1.3       misho     464:  * @histfile = History filename, if NULL will be use default name
                    465:  * return: RETCODE_ERR error, RETCODE_OK ok
                    466: */
1.7       misho     467: int cli_loadHistory(linebuffer_t * __restrict cli_buffer, const char *histfile);
1.1       misho     468: /*
1.6       misho     469:  * cli_resetHistory() - Reset history search in CLI session
                    470:  *
1.7       misho     471:  * @cli_buffer = CLI buffer
1.1       misho     472:  * return: none
                    473: */
1.7       misho     474: void cli_resetHistory(linebuffer_t * __restrict cli_buffer);
1.1       misho     475: 
                    476: /*
1.6       misho     477:  * cli_freeLine() - Clear entire line
                    478:  *
1.7       misho     479:  * @cli_buffer = CLI buffer
1.3       misho     480:  * return: RETCODE_ERR error, RETCODE_OK ok
                    481: */
1.7       misho     482: int cli_freeLine(linebuffer_t * __restrict cli_buffer);
1.3       misho     483: /*
1.6       misho     484:  * cli_setPrompt() - Set new prompt for CLI session
                    485:  *
1.7       misho     486:  * @cli_buffer = CLI buffer
1.3       misho     487:  * @prompt = new text for prompt or if NULL disable prompt
                    488:  * return: none
1.1       misho     489: */
1.7       misho     490: void cli_setPrompt(linebuffer_t * __restrict cli_buffer, const char *prompt);
1.1       misho     491: /*
1.6       misho     492:  * cli_Printf() - Send message to CLI session
                    493:  *
1.7       misho     494:  * @cli_buffer = CLI buffer
1.3       misho     495:  * @fmt = printf format string
                    496:  * @... = arguments defined in fmt
                    497:  * return: none
1.1       misho     498: */
1.7       misho     499: void cli_Printf(linebuffer_t * __restrict cli_buffer, char *fmt, ...);
1.1       misho     500: /*
1.6       misho     501:  * cli_PrintHelp() - Print help screen
                    502:  *
1.7       misho     503:  * @cli_buffer = CLI buffer
1.3       misho     504:  * return: none
1.1       misho     505: */
1.7       misho     506: void cli_PrintHelp(linebuffer_t * __restrict cli_buffer);
1.1       misho     507: 
1.3       misho     508: /*
1.6       misho     509:  * cliEnd() - Clear data, Free resources and close CLI session
                    510:  *
1.7       misho     511:  * @cli_buffer = CLI buffer
1.3       misho     512:  * return: RETCODE_ERR error, RETCODE_OK ok
                    513: */
1.7       misho     514: void cliEnd(linebuffer_t * __restrict cli_buffer);
1.3       misho     515: /*
1.6       misho     516:  * cliInit() - Start CLI session, allocate memory for resources and bind keys
                    517:  *
1.3       misho     518:  * @fin = Input device handle
                    519:  * @fout = Output device handle
                    520:  * @prompt = text for prompt, if NULL disable prompt
                    521:  * return: NULL if error or !=NULL CLI buffer
                    522: */
                    523: linebuffer_t *cliInit(int fin, int fout, const char *prompt);
1.1       misho     524: 
                    525: /*
1.6       misho     526:  * cliInitLine() - Init CLI input line terminal
                    527:  *
1.7       misho     528:  * @cli_buffer = CLI buffer
1.3       misho     529:  * return: none
1.1       misho     530: */
1.7       misho     531: int cliInitLine(linebuffer_t * __restrict cli_buffer);
1.1       misho     532: /*
1.6       misho     533:  * cliReadLine() - Read line from opened CLI session
                    534:  *
1.7       misho     535:  * @cli_buffer = CLI buffer
1.6       misho     536:  * return: NULL if error or !=NULL readed line, must be e_free after use!
1.1       misho     537: */
1.7       misho     538: char *cliReadLine(linebuffer_t * __restrict cli_buffer);
1.1       misho     539: 
                    540: /*
1.6       misho     541:  * cliLoop() - CLI main loop
                    542:  *
1.7       misho     543:  * @cli_buffer = CLI buffer
1.3       misho     544:  * @csHistFile = History file name
                    545:  * return: RETCODE_ERR error, RETCODE_OK ok
1.1       misho     546: */
1.7       misho     547: int cliLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile);
1.1       misho     548: /*
1.6       misho     549:  * cliNetLoop() - CLI network main loop binded to socket
                    550:  *
1.7       misho     551:  * @cli_buffer = CLI buffer
1.3       misho     552:  * @csHistFile = History file name
                    553:  * @sock = client socket
                    554:  * @term = stdin termios
                    555:  * @win = window size of tty
                    556:  * return: RETCODE_ERR error, RETCODE_OK ok
1.1       misho     557: */
1.7       misho     558: int cliNetLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, int sock);
1.1       misho     559: 
                    560: 
                    561: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>