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

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

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