diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-17 21:58:31 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-17 21:58:31 -0800 |
| commit | 3d08f101207d0e68f44442933f7e2440b85be848 (patch) | |
| tree | 5257fa76b07e8a1f28f8791a61cf37080f63c61f /src | |
| parent | 07e187d3243ab227ca768602483591a5745fe7d4 (diff) | |
| download | tinyrad-3d08f101207d0e68f44442933f7e2440b85be848.tar.gz tinyrad-3d08f101207d0e68f44442933f7e2440b85be848.tar.bz2 tinyrad-3d08f101207d0e68f44442933f7e2440b85be848.tar.xz tinyrad-3d08f101207d0e68f44442933f7e2440b85be848.zip | |
tinyrad: updating CLI options
Diffstat (limited to 'src')
| -rw-r--r-- | src/tinyrad.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/tinyrad.c b/src/tinyrad.c index d2cd6d5..e12afdf 100644 --- a/src/tinyrad.c +++ b/src/tinyrad.c | |||
| @@ -101,6 +101,7 @@ main( | |||
| 101 | int | 101 | int |
| 102 | my_dict_load( | 102 | my_dict_load( |
| 103 | int opts, | 103 | int opts, |
| 104 | unsigned tr_opts, | ||
| 104 | TinyRadDict ** dictp, | 105 | TinyRadDict ** dictp, |
| 105 | char ** dict_files, | 106 | char ** dict_files, |
| 106 | char ** dict_paths ); | 107 | char ** dict_paths ); |
| @@ -123,6 +124,7 @@ int main(int argc, char * argv[]) | |||
| 123 | int c; | 124 | int c; |
| 124 | int opt_index; | 125 | int opt_index; |
| 125 | int rc; | 126 | int rc; |
| 127 | unsigned tr_opts; | ||
| 126 | TinyRadDict * dict; | 128 | TinyRadDict * dict; |
| 127 | TinyRad * tr; | 129 | TinyRad * tr; |
| 128 | const char * url; | 130 | const char * url; |
| @@ -149,6 +151,8 @@ int main(int argc, char * argv[]) | |||
| 149 | trutils_initialize(PROGRAM_NAME); | 151 | trutils_initialize(PROGRAM_NAME); |
| 150 | 152 | ||
| 151 | opts = 0; | 153 | opts = 0; |
| 154 | tr_opts = 0; | ||
| 155 | url = NULL; | ||
| 152 | dict = NULL; | 156 | dict = NULL; |
| 153 | dict_files = NULL; | 157 | dict_files = NULL; |
| 154 | dict_paths = NULL; | 158 | dict_paths = NULL; |
| @@ -166,7 +170,7 @@ int main(int argc, char * argv[]) | |||
| 166 | break; | 170 | break; |
| 167 | 171 | ||
| 168 | case 2: | 172 | case 2: |
| 169 | opts |= MY_OPT_DICT_DEFAULTS; | 173 | tr_opts |= TRAD_BUILTIN_DICT; |
| 170 | break; | 174 | break; |
| 171 | 175 | ||
| 172 | case 'D': | 176 | case 'D': |
| @@ -222,19 +226,22 @@ int main(int argc, char * argv[]) | |||
| 222 | return(1); | 226 | return(1); |
| 223 | }; | 227 | }; |
| 224 | }; | 228 | }; |
| 225 | if (optind >= argc) | 229 | if (optind < argc) |
| 226 | { | 230 | { |
| 227 | fprintf(stderr, "%s: missing required argument\n", PROGRAM_NAME); | 231 | url = argv[optind]; |
| 232 | optind++; | ||
| 233 | }; | ||
| 234 | if (optind < argc) | ||
| 235 | { | ||
| 236 | fprintf(stderr, "%s: unrecognized argument -- %s\n", PROGRAM_NAME, argv[optind]); | ||
| 228 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | 237 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); |
| 229 | tinyrad_strsfree(dict_files); | 238 | tinyrad_strsfree(dict_files); |
| 230 | tinyrad_strsfree(dict_paths); | 239 | tinyrad_strsfree(dict_paths); |
| 231 | return(1); | 240 | return(1); |
| 232 | }; | 241 | }; |
| 233 | url = argv[optind]; | ||
| 234 | optind++; | ||
| 235 | 242 | ||
| 236 | // load RADIUS dictionary | 243 | // load RADIUS dictionary |
| 237 | if ((rc = my_dict_load(opts, &dict, dict_files, dict_paths)) != TRAD_SUCCESS) | 244 | if ((rc = my_dict_load(opts, tr_opts, &dict, dict_files, dict_paths)) != TRAD_SUCCESS) |
| 238 | { | 245 | { |
| 239 | tinyrad_strsfree(dict_files); | 246 | tinyrad_strsfree(dict_files); |
| 240 | tinyrad_strsfree(dict_paths); | 247 | tinyrad_strsfree(dict_paths); |
| @@ -244,7 +251,7 @@ int main(int argc, char * argv[]) | |||
| 244 | tinyrad_strsfree(dict_files); | 251 | tinyrad_strsfree(dict_files); |
| 245 | 252 | ||
| 246 | // initialize tinyrad handle | 253 | // initialize tinyrad handle |
| 247 | if ((tinyrad_initialize(&tr, dict, url, 0)) != TRAD_SUCCESS) | 254 | if ((tinyrad_initialize(&tr, dict, url, tr_opts)) != TRAD_SUCCESS) |
| 248 | { | 255 | { |
| 249 | tinyrad_free(dict); | 256 | tinyrad_free(dict); |
| 250 | return(1); | 257 | return(1); |
| @@ -270,6 +277,7 @@ int main(int argc, char * argv[]) | |||
| 270 | int | 277 | int |
| 271 | my_dict_load( | 278 | my_dict_load( |
| 272 | int opts, | 279 | int opts, |
| 280 | unsigned tr_opts, | ||
| 273 | TinyRadDict ** dictp, | 281 | TinyRadDict ** dictp, |
| 274 | char ** dict_files, | 282 | char ** dict_files, |
| 275 | char ** dict_paths ) | 283 | char ** dict_paths ) |
| @@ -287,7 +295,7 @@ my_dict_load( | |||
| 287 | return(TRAD_SUCCESS); | 295 | return(TRAD_SUCCESS); |
| 288 | 296 | ||
| 289 | // initialize dictionary | 297 | // initialize dictionary |
| 290 | if ((rc = tinyrad_dict_initialize(&dict, 0)) != TRAD_SUCCESS) | 298 | if ((rc = tinyrad_dict_initialize(&dict, tr_opts)) != TRAD_SUCCESS) |
| 291 | { | 299 | { |
| 292 | trutils_error(opts, NULL, "out of virtual memory"); | 300 | trutils_error(opts, NULL, "out of virtual memory"); |
| 293 | return(rc); | 301 | return(rc); |
| @@ -336,7 +344,7 @@ my_dict_load( | |||
| 336 | 344 | ||
| 337 | void my_usage(void) | 345 | void my_usage(void) |
| 338 | { | 346 | { |
| 339 | printf("Usage: %s [OPTIONS] url\n", PROGRAM_NAME); | 347 | printf("Usage: %s [OPTIONS] [url]\n", PROGRAM_NAME); |
| 340 | printf("OPTIONS:\n"); | 348 | printf("OPTIONS:\n"); |
| 341 | printf(" -D dictionary include dictionary\n"); | 349 | printf(" -D dictionary include dictionary\n"); |
| 342 | printf(" -d level, --debug=level print debug messages\n"); | 350 | printf(" -d level, --debug=level print debug messages\n"); |
