eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

command.h (3078B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2017-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #define COMMAND_OPTION_USERNAME		"username"
     24 #define COMMAND_OPTION_PASSWORD		"password"
     25 #define COMMAND_OPTION_PASSPHRASE	"passphrase"
     26 #define COMMAND_OPTION_DONTASK		"dont-ask"
     27 
     28 typedef char *(*command_completion_func_t)(const char *text, int state,
     29 						const char *entity);
     30 typedef char *(*command_rl_completion_func_t)(const char *text, int state);
     31 
     32 
     33 enum cmd_status {
     34 	CMD_STATUS_TRIGGERED,
     35 	CMD_STATUS_DONE,
     36 	CMD_STATUS_INVALID_ARGS,
     37 	CMD_STATUS_INVALID_VALUE,
     38 	CMD_STATUS_UNSUPPORTED,
     39 	CMD_STATUS_FAILED,
     40 };
     41 
     42 struct command {
     43 	const char *entity;
     44 	const char *cmd;
     45 	const char *arg;
     46 	enum cmd_status (*function)(const char *entity,
     47 						char **argv, int argc);
     48 	const char *desc;
     49 	const bool refreshable;
     50 	command_completion_func_t completion;
     51 };
     52 
     53 struct command_family {
     54 	const char *caption;
     55 	const char *name;
     56 	const struct command *command_list;
     57 	command_rl_completion_func_t family_arg_completion;
     58 	command_rl_completion_func_t entity_arg_completion;
     59 };
     60 
     61 bool command_option_get(const char *name, const char **value_out);
     62 bool command_needs_no_agent(void);
     63 
     64 bool command_line_find_token(const char *token, uint8_t num_to_inspect);
     65 char **command_completion(const char *text, int start, int end);
     66 char *command_entity_arg_completion(const char *text, int state,
     67 					const struct command *command_list);
     68 
     69 void command_process_prompt(char **argv, int argc);
     70 
     71 void command_noninteractive_trigger(void);
     72 bool command_is_interactive_mode(void);
     73 int command_get_exit_status(void);
     74 void command_set_exit_status(int status);
     75 
     76 void command_family_register(const struct command_family *family);
     77 void command_family_unregister(const struct command_family *family);
     78 
     79 struct command_family_desc {
     80 	const char *name;
     81 	int (*init)(void);
     82 	void (*exit)(void);
     83 } __attribute__((aligned(8)));
     84 
     85 #define COMMAND_FAMILY(name, init, exit)				\
     86 	_Pragma("GCC diagnostic push")					\
     87 	_Pragma("GCC diagnostic ignored \"-Wattributes\"")		\
     88 	static struct command_family_desc __command_family_ ## name	\
     89 		__attribute__((used, retain,				\
     90 				section("__command"), aligned(8))) = {	\
     91 			#name, init, exit				\
     92 		};							\
     93 	_Pragma("GCC diagnostic pop")
     94 
     95 bool command_init(char **argv, int argc);
     96 void command_exit(void);