Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:53 2009

## Asterisk developer's documentation

# cli.h

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  * \brief Standard Command Line Interface
    00021  */
    00022
    00023 #ifndef _ASTERISK_CLI_H
    00024 #define _ASTERISK_CLI_H
    00025
    00026 #if defined(__cplusplus) || defined(c_plusplus)
    00027 extern "C" {
    00028 #endif
    00029
    00030 #include <stdarg.h>
    00031
    00032 extern void ast_cli(int fd, char *fmt, ...)
    00033    __attribute__ ((format (printf, 2, 3)));
    00034
    00035 #define RESULT_SUCCESS     0
    00036 #define RESULT_SHOWUSAGE   1
    00037 #define RESULT_FAILURE     2
    00038
    00039 #define AST_MAX_CMD_LEN    16
    00040
    00041 #define AST_MAX_ARGS 64
    00042
    00043 #define AST_CLI_COMPLETE_EOF  "_EOF_"
    00044
    00045 /*! \brief A command line entry */
    00046 struct ast_cli_entry {
    00047    /*! Null terminated list of the words of the command */
    00048    char *cmda[AST_MAX_CMD_LEN];
    00049    /*! Handler for the command (fd for output, # of arguments, argument list).  Returns RESULT_SHOWUSAGE for improper arguments */
    00050    int (*handler)(int fd, int argc, char *argv[]);
    00051    /*! Summary of the command (< 60 characters) */
    00052    char *summary;
    00053    /*! Detailed usage information */
    00054    char *usage;
    00055    /*! Generate a list of possible completions for a given word */
    00056    char *(*generator)(char *line, char *word, int pos, int state);
    00057    /*! For linking */
    00058    struct ast_cli_entry *next;
    00059    /*! For keeping track of usage */
    00060    int inuse;
    00061 };
    00062
    00063 /*! \brief Interprets a command
    00064  * Interpret a command s, sending output to fd
    00065  * Returns 0 on succes, -1 on failure
    00066  */
    00067 extern int ast_cli_command(int fd, char *s);
    00068
    00069 /*! \brief Registers a command or an array of commands
    00070  * \param e which cli entry to register
    00071  * Register your own command
    00072  * Returns 0 on success, -1 on failure
    00073  */
    00074 extern int ast_cli_register(struct ast_cli_entry *e);
    00075
    00076 /*!
    00077  * \brief Register multiple commands
    00078  * \param e pointer to first cli entry to register
    00079  * \param len number of entries to register
    00080  */
    00081 extern void ast_cli_register_multiple(struct ast_cli_entry *e, int len);
    00082
    00083 /*! \brief Unregisters a command or an array of commands
    00084  *
    00085  * \param e which cli entry to unregister
    00086  * Unregister your own command.  You must pass a completed ast_cli_entry structure
    00087  * Returns 0.
    00088  */
    00089 extern int ast_cli_unregister(struct ast_cli_entry *e);
    00090
    00091 /*!
    00092  * \brief Unregister multiple commands
    00093  * \param e pointer to first cli entry to unregister
    00094  * \param len number of entries to unregister
    00095  */
    00096 extern void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
    00097
    00098 /*! \brief Readline madness
    00099  * Useful for readline, that's about it
    00100  * Returns 0 on success, -1 on failure
    00101  */
    00102 extern char *ast_cli_generator(char *, char *, int);
    00103
    00104 extern int ast_cli_generatornummatches(char *, char *);
    00105 extern char **ast_cli_completion_matches(char *, char *);
    00106
    00107 #if defined(__cplusplus) || defined(c_plusplus)
    00108 }
    00109 #endif
    00110
    00111 #endif /* _ASTERISK_CLI_H */