How to create custom task with using "ast_cli_entry"?


#1

How to create custom task with using “ast_cli_entry”?
Please show me an examples.

I’m transferring the old code from asterisk 1.4.2. on asterisk 13.21 and met some troubles:

asterisk 13.21.0

struct ast_cli_entry {
    const char * const cmda[AST_MAX_CMD_LEN];    /*!< words making up the command.
                             * set the first entry to NULL for a new-style entry.
                             */

    const char * const summary;             /*!< Summary of the command (< 60 characters) */
    const char * usage;                 /*!< Detailed usage information */

    int inuse;                 /*!< For keeping track of usage */
    struct module *module;            /*!< module this belongs to */
    char *_full_cmd;            /*!< built at load time from cmda[] */
    int cmdlen;                /*!< len up to the first invalid char [<{% */
    /*! \brief This gets set in ast_cli_register()
     */
    int args;                /*!< number of non-null entries in cmda */
    char *command;                /*!< command, non-null for new-style entries */
    char *(*handler)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
    /*! For linking */
    AST_LIST_ENTRY(ast_cli_entry) list;
};

asterisk 1.4.2

struct ast_cli_entry {
    char * const cmda[AST_MAX_CMD_LEN];
    /*! Handler for the command (fd for output, # of args, argument list).
      Returns RESULT_SHOWUSAGE for improper arguments.
      argv[] has argc 'useful' entries, and an additional NULL entry
      at the end so that clients requiring NULL terminated arrays
      can use it without need for copies.
      You can overwrite argv or the strings it points to, but remember
      that this memory is deallocated after the handler returns.
     */
    int (*handler)(int fd, int argc, char *argv[]);
    /*! Summary of the command (< 60 characters) */
    const char *summary;
    /*! Detailed usage information */
    const char *usage;
    /*! Generate the n-th (starting from 0) possible completion
      for a given 'word' following 'line' in position 'pos'.
      'line' and 'word' must not be modified.
      Must return a malloc'ed string with the n-th value when available,
      or NULL if the n-th completion does not exist.
      Typically, the function is called with increasing values for n
      until a NULL is returned.
     */
    char *(*generator)(const char *line, const char *word, int pos, int n);
    struct ast_cli_entry *deprecate_cmd;
    /*! For keeping track of usage */
    int inuse;
    struct module *module;    /*! module this belongs to */
    char *_full_cmd;    /* built at load time from cmda[] */
    /* This gets set in ast_cli_register()
      It then gets set to something different when the deprecated command
      is run for the first time (ie; after we warn the user that it's deprecated)
     */
    int deprecated;
    char *_deprecated_by;    /* copied from the "parent" _full_cmd, on deprecated commands */
    /*! For linking */
    AST_LIST_ENTRY(ast_cli_entry) list;
};

#2

Please use the developer mailing list or IRC channels for developer questions.


#3

CLI commands are present in numerous modules, I’d suggest looking at one of those current implementations. The apps/app_skel.c source code also has an example.


#4

Thank you bro!
P.S. As usual you are the most useful. Many thanks.