1 /** @file oathtool_cmd.h
2  *  @brief The header file for the command line option parser
3  *  generated by GNU Gengetopt version 2.22.6
4  *  http://www.gnu.org/software/gengetopt.
5  *  DO NOT modify this file, since it can be overwritten
6  *  @author GNU Gengetopt by Lorenzo Bettini */
7 
8 #ifndef OATHTOOL_CMD_H
9 #define OATHTOOL_CMD_H
10 
11 /* If we use autoconf.  */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <stdio.h> /* for FILE */
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
21 
22 #ifndef CMDLINE_PARSER_PACKAGE
23 /** @brief the program name (used for printing errors) */
24 #define CMDLINE_PARSER_PACKAGE PACKAGE
25 #endif
26 
27 #ifndef CMDLINE_PARSER_PACKAGE_NAME
28 /** @brief the complete program name (used for help and version) */
29 #ifdef PACKAGE_NAME
30 #define CMDLINE_PARSER_PACKAGE_NAME PACKAGE_NAME
31 #else
32 #define CMDLINE_PARSER_PACKAGE_NAME PACKAGE
33 #endif
34 #endif
35 
36 #ifndef CMDLINE_PARSER_VERSION
37 /** @brief the program version */
38 #define CMDLINE_PARSER_VERSION VERSION
39 #endif
40 
41 /** @brief Where the command line options are stored */
42 struct gengetopt_args_info
43 {
44   const char *help_help; /**< @brief Print help and exit help description.  */
45   const char *version_help; /**< @brief Print version and exit help description.  */
46   int hotp_flag;	/**< @brief use event-based HOTP mode (default=on).  */
47   const char *hotp_help; /**< @brief use event-based HOTP mode help description.  */
48   char * totp_arg;	/**< @brief use time-variant TOTP mode (default='sha1').  */
49   char * totp_orig;	/**< @brief use time-variant TOTP mode original value given at command line.  */
50   const char *totp_help; /**< @brief use time-variant TOTP mode help description.  */
51   int base32_flag;	/**< @brief use base32 encoding of KEY instead of hex (default=off).  */
52   const char *base32_help; /**< @brief use base32 encoding of KEY instead of hex help description.  */
53   #if defined(HAVE_LONG_LONG_INT) || defined(HAVE_LONG_LONG_INT)
54   long long int counter_arg;	/**< @brief HOTP counter value.  */
55   #else
56   long counter_arg;	/**< @brief HOTP counter value.  */
57   #endif
58   char * counter_orig;	/**< @brief HOTP counter value original value given at command line.  */
59   const char *counter_help; /**< @brief HOTP counter value help description.  */
60   char * time_step_size_arg;	/**< @brief TOTP time-step duration (default='30s').  */
61   char * time_step_size_orig;	/**< @brief TOTP time-step duration original value given at command line.  */
62   const char *time_step_size_help; /**< @brief TOTP time-step duration help description.  */
63   char * start_time_arg;	/**< @brief when to start counting time steps for TOTP (default='1970-01-01 00:00:00 UTC').  */
64   char * start_time_orig;	/**< @brief when to start counting time steps for TOTP original value given at command line.  */
65   const char *start_time_help; /**< @brief when to start counting time steps for TOTP help description.  */
66   char * now_arg;	/**< @brief use this time as current time for TOTP (default='now').  */
67   char * now_orig;	/**< @brief use this time as current time for TOTP original value given at command line.  */
68   const char *now_help; /**< @brief use this time as current time for TOTP help description.  */
69   int digits_arg;	/**< @brief number of digits in one-time password.  */
70   char * digits_orig;	/**< @brief number of digits in one-time password original value given at command line.  */
71   const char *digits_help; /**< @brief number of digits in one-time password help description.  */
72   int window_arg;	/**< @brief window of counter values to test when validating OTPs.  */
73   char * window_orig;	/**< @brief window of counter values to test when validating OTPs original value given at command line.  */
74   const char *window_help; /**< @brief window of counter values to test when validating OTPs help description.  */
75   int verbose_flag;	/**< @brief explain what is being done (default=off).  */
76   const char *verbose_help; /**< @brief explain what is being done help description.  */
77 
78   unsigned int help_given ;	/**< @brief Whether help was given.  */
79   unsigned int version_given ;	/**< @brief Whether version was given.  */
80   unsigned int hotp_given ;	/**< @brief Whether hotp was given.  */
81   unsigned int totp_given ;	/**< @brief Whether totp was given.  */
82   unsigned int base32_given ;	/**< @brief Whether base32 was given.  */
83   unsigned int counter_given ;	/**< @brief Whether counter was given.  */
84   unsigned int time_step_size_given ;	/**< @brief Whether time-step-size was given.  */
85   unsigned int start_time_given ;	/**< @brief Whether start-time was given.  */
86   unsigned int now_given ;	/**< @brief Whether now was given.  */
87   unsigned int digits_given ;	/**< @brief Whether digits was given.  */
88   unsigned int window_given ;	/**< @brief Whether window was given.  */
89   unsigned int verbose_given ;	/**< @brief Whether verbose was given.  */
90 
91   char **inputs ; /**< @brief unamed options (options without names) */
92   unsigned inputs_num ; /**< @brief unamed options number */
93 } ;
94 
95 /** @brief The additional parameters to pass to parser functions */
96 struct cmdline_parser_params
97 {
98   int override; /**< @brief whether to override possibly already present options (default 0) */
99   int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */
100   int check_required; /**< @brief whether to check that all required options were provided (default 1) */
101   int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */
102   int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */
103 } ;
104 
105 /** @brief the purpose string of the program */
106 extern const char *gengetopt_args_info_purpose;
107 /** @brief the usage string of the program */
108 extern const char *gengetopt_args_info_usage;
109 /** @brief the description string of the program */
110 extern const char *gengetopt_args_info_description;
111 /** @brief all the lines making the help output */
112 extern const char *gengetopt_args_info_help[];
113 
114 /**
115  * The command line parser
116  * @param argc the number of command line options
117  * @param argv the command line options
118  * @param args_info the structure where option information will be stored
119  * @return 0 if everything went fine, NON 0 if an error took place
120  */
121 int cmdline_parser (int argc, char **argv,
122   struct gengetopt_args_info *args_info);
123 
124 /**
125  * The command line parser (version with additional parameters - deprecated)
126  * @param argc the number of command line options
127  * @param argv the command line options
128  * @param args_info the structure where option information will be stored
129  * @param override whether to override possibly already present options
130  * @param initialize whether to initialize the option structure my_args_info
131  * @param check_required whether to check that all required options were provided
132  * @return 0 if everything went fine, NON 0 if an error took place
133  * @deprecated use cmdline_parser_ext() instead
134  */
135 int cmdline_parser2 (int argc, char **argv,
136   struct gengetopt_args_info *args_info,
137   int override, int initialize, int check_required);
138 
139 /**
140  * The command line parser (version with additional parameters)
141  * @param argc the number of command line options
142  * @param argv the command line options
143  * @param args_info the structure where option information will be stored
144  * @param params additional parameters for the parser
145  * @return 0 if everything went fine, NON 0 if an error took place
146  */
147 int cmdline_parser_ext (int argc, char **argv,
148   struct gengetopt_args_info *args_info,
149   struct cmdline_parser_params *params);
150 
151 /**
152  * Save the contents of the option struct into an already open FILE stream.
153  * @param outfile the stream where to dump options
154  * @param args_info the option struct to dump
155  * @return 0 if everything went fine, NON 0 if an error took place
156  */
157 int cmdline_parser_dump(FILE *outfile,
158   struct gengetopt_args_info *args_info);
159 
160 /**
161  * Save the contents of the option struct into a (text) file.
162  * This file can be read by the config file parser (if generated by gengetopt)
163  * @param filename the file where to save
164  * @param args_info the option struct to save
165  * @return 0 if everything went fine, NON 0 if an error took place
166  */
167 int cmdline_parser_file_save(const char *filename,
168   struct gengetopt_args_info *args_info);
169 
170 /**
171  * Print the help
172  */
173 void cmdline_parser_print_help(void);
174 /**
175  * Print the version
176  */
177 void cmdline_parser_print_version(void);
178 
179 /**
180  * Initializes all the fields a cmdline_parser_params structure
181  * to their default values
182  * @param params the structure to initialize
183  */
184 void cmdline_parser_params_init(struct cmdline_parser_params *params);
185 
186 /**
187  * Allocates dynamically a cmdline_parser_params structure and initializes
188  * all its fields to their default values
189  * @return the created and initialized cmdline_parser_params structure
190  */
191 struct cmdline_parser_params *cmdline_parser_params_create(void);
192 
193 /**
194  * Initializes the passed gengetopt_args_info structure's fields
195  * (also set default values for options that have a default)
196  * @param args_info the structure to initialize
197  */
198 void cmdline_parser_init (struct gengetopt_args_info *args_info);
199 /**
200  * Deallocates the string fields of the gengetopt_args_info structure
201  * (but does not deallocate the structure itself)
202  * @param args_info the structure to deallocate
203  */
204 void cmdline_parser_free (struct gengetopt_args_info *args_info);
205 
206 /**
207  * Checks that all the required options were specified
208  * @param args_info the structure to check
209  * @param prog_name the name of the program that will be used to print
210  *   possible errors
211  * @return
212  */
213 int cmdline_parser_required (struct gengetopt_args_info *args_info,
214   const char *prog_name);
215 
216 extern const char *cmdline_parser_totp_values[];  /**< @brief Possible values for totp. */
217 
218 
219 #ifdef __cplusplus
220 }
221 #endif /* __cplusplus */
222 #endif /* OATHTOOL_CMD_H */
223