File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / swanctl / command.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 09:46:45 2020 UTC (4 years, 4 months ago) by misho
Branches: strongswan, MAIN
CVS tags: v5_9_2p0, v5_8_4p7, HEAD
Strongswan

    1: /*
    2:  * Copyright (C) 2009 Martin Willi
    3:  * HSR Hochschule fuer Technik Rapperswil
    4:  *
    5:  * This program is free software; you can redistribute it and/or modify it
    6:  * under the terms of the GNU General Public License as published by the
    7:  * Free Software Foundation; either version 2 of the License, or (at your
    8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
    9:  *
   10:  * This program is distributed in the hope that it will be useful, but
   11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13:  * for more details.
   14:  */
   15: 
   16: /**
   17:  * @defgroup command command
   18:  * @{ @ingroup swanctl
   19:  */
   20: 
   21: #ifndef COMMAND_H_
   22: #define COMMAND_H_
   23: 
   24: #include <libvici.h>
   25: #include <library.h>
   26: 
   27: /**
   28:  * Maximum number of commands (+1).
   29:  */
   30: #define MAX_COMMANDS 26
   31: 
   32: /**
   33:  * Maximum number of options in a command (+3)
   34:  */
   35: #define MAX_OPTIONS 34
   36: 
   37: /**
   38:  * Maximum number of usage summary lines (+1)
   39:  */
   40: #define MAX_LINES 10
   41: 
   42: typedef struct command_t command_t;
   43: typedef struct command_option_t command_option_t;
   44: typedef enum command_format_options_t command_format_options_t;
   45: 
   46: /**
   47:  * Option specification
   48:  */
   49: struct command_option_t {
   50: 	/** long option string of the option */
   51: 	char *name;
   52: 	/** short option character of the option */
   53: 	char op;
   54: 	/** expected argument to option, no/req/opt_argument */
   55: 	int arg;
   56: 	/** description of the option */
   57: 	char *desc;
   58: };
   59: 
   60: /**
   61:  * Command specification.
   62:  */
   63: struct command_t {
   64: 	/** Function implementing the command */
   65: 	int (*call)(vici_conn_t *conn);
   66: 	/** short option character */
   67: 	char op;
   68: 	/** long option string */
   69: 	char *cmd;
   70: 	/** description of the command */
   71: 	char *description;
   72: 	/** usage summary of the command */
   73: 	char *line[MAX_LINES];
   74: 	/** list of options the command accepts */
   75: 	command_option_t options[MAX_OPTIONS];
   76: };
   77: 
   78: /**
   79:  * Command format options
   80: */
   81: enum command_format_options_t {
   82: 	COMMAND_FORMAT_NONE   = 0,
   83: 	COMMAND_FORMAT_RAW    = (1<<0),
   84: 	COMMAND_FORMAT_PRETTY = (1<<1),
   85: 	COMMAND_FORMAT_PEM    = (1<<2),
   86: };
   87: 
   88: /**
   89:  * Get the next option, as with getopt.
   90:  */
   91: int command_getopt(char **arg);
   92: 
   93: /**
   94:  * Register a command.
   95:  */
   96: void command_register(command_t command);
   97: 
   98: /**
   99:  * Dispatch commands.
  100:  */
  101: int command_dispatch(int argc, char *argv[]);
  102: 
  103: /**
  104:  * Show usage information of active command.
  105:  */
  106: int command_usage(char *error, ...);
  107: 
  108: #endif /** COMMAND_H_ @}*/

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