diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-21 17:53:51 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-21 17:53:51 -0800 |
| commit | 7ec7a20d9da6283c687611493ab6a6d29e65a9dc (patch) | |
| tree | 73680d5d6f684068e24d2b314c4defb56ce506a7 /lib | |
| parent | 0c4a1fa9ea6cc43d017761ddaccb5515ce5ad741 (diff) | |
| download | tinyrad-7ec7a20d9da6283c687611493ab6a6d29e65a9dc.tar.gz tinyrad-7ec7a20d9da6283c687611493ab6a6d29e65a9dc.tar.bz2 tinyrad-7ec7a20d9da6283c687611493ab6a6d29e65a9dc.tar.xz tinyrad-7ec7a20d9da6283c687611493ab6a6d29e65a9dc.zip | |
libtinyrad: refactoring tinyrad_conf_opt()
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libtinyrad/lconf.c | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/lib/libtinyrad/lconf.c b/lib/libtinyrad/lconf.c index f569b93..2bb5b66 100644 --- a/lib/libtinyrad/lconf.c +++ b/lib/libtinyrad/lconf.c | |||
| @@ -50,6 +50,7 @@ | |||
| 50 | #include <assert.h> | 50 | #include <assert.h> |
| 51 | 51 | ||
| 52 | #include "ldict.h" | 52 | #include "ldict.h" |
| 53 | #include "lmap.h" | ||
| 53 | #include "lstrings.h" | 54 | #include "lstrings.h" |
| 54 | 55 | ||
| 55 | 56 | ||
| @@ -325,6 +326,7 @@ tinyrad_conf_opt( | |||
| 325 | { | 326 | { |
| 326 | int i; | 327 | int i; |
| 327 | int rc; | 328 | int rc; |
| 329 | uint64_t optid; | ||
| 328 | char * endptr; | 330 | char * endptr; |
| 329 | char ** strs; | 331 | char ** strs; |
| 330 | struct timeval tv; | 332 | struct timeval tv; |
| @@ -336,21 +338,21 @@ tinyrad_conf_opt( | |||
| 336 | tr = ( ((tr)) && (!(tr->opts & TRAD_STOPINIT)) ) ? tr : NULL; | 338 | tr = ( ((tr)) && (!(tr->opts & TRAD_STOPINIT)) ) ? tr : NULL; |
| 337 | dict = ( ((dict)) && (!(dict->opts & TRAD_STOPINIT)) ) ? dict : NULL; | 339 | dict = ( ((dict)) && (!(dict->opts & TRAD_STOPINIT)) ) ? dict : NULL; |
| 338 | 340 | ||
| 339 | if (!(strcasecmp(name, "bind_address"))) | 341 | if ((optid = tinyrad_map_lookup_name(tinyrad_conf_options, name, NULL)) == 0) |
| 342 | return(TRAD_SUCCESS); | ||
| 343 | |||
| 344 | switch(optid) | ||
| 340 | { | 345 | { |
| 346 | case TRAD_CONF_BIND_ADDRESS: | ||
| 341 | if ( (!(tr)) || ((tr->bind_sa)) || ((tr->bind_sa6)) || (!(value)) ) | 347 | if ( (!(tr)) || ((tr->bind_sa)) || ((tr->bind_sa6)) || (!(value)) ) |
| 342 | return(TRAD_SUCCESS); | 348 | return(TRAD_SUCCESS); |
| 343 | return(tinyrad_set_option(tr, TRAD_OPT_SOCKET_BIND_ADDRESSES, value)); | 349 | return(tinyrad_set_option(tr, TRAD_OPT_SOCKET_BIND_ADDRESSES, value)); |
| 344 | }; | ||
| 345 | 350 | ||
| 346 | if (!(strcasecmp(name, "builtin_dictionary"))) | 351 | case TRAD_CONF_BUILTIN_DICTIONARY: |
| 347 | { | ||
| 348 | tinyrad_conf_opt_bool(NULL, dict, TRAD_BUILTIN_DICT, value); | 352 | tinyrad_conf_opt_bool(NULL, dict, TRAD_BUILTIN_DICT, value); |
| 349 | return(TRAD_SUCCESS); | 353 | return(TRAD_SUCCESS); |
| 350 | }; | ||
| 351 | 354 | ||
| 352 | if (!(strcasecmp(name, "dictionary"))) | 355 | case TRAD_CONF_DICTIONARY: |
| 353 | { | ||
| 354 | if (!(dict)) | 356 | if (!(dict)) |
| 355 | return(TRAD_SUCCESS); | 357 | return(TRAD_SUCCESS); |
| 356 | if ((dict->default_dictfile)) | 358 | if ((dict->default_dictfile)) |
| @@ -358,10 +360,8 @@ tinyrad_conf_opt( | |||
| 358 | if ((dict->default_dictfile = tinyrad_strdup(value)) == NULL) | 360 | if ((dict->default_dictfile = tinyrad_strdup(value)) == NULL) |
| 359 | return(TRAD_ENOMEM); | 361 | return(TRAD_ENOMEM); |
| 360 | return(TRAD_SUCCESS); | 362 | return(TRAD_SUCCESS); |
| 361 | }; | ||
| 362 | 363 | ||
| 363 | if (!(strcasecmp(name, "network_timeout"))) | 364 | case TRAD_CONF_NETWORK_TIMEOUT: |
| 364 | { | ||
| 365 | if ( (!(tr)) || ((tr->net_timeout)) || (!(value)) ) | 365 | if ( (!(tr)) || ((tr->net_timeout)) || (!(value)) ) |
| 366 | return(TRAD_SUCCESS); | 366 | return(TRAD_SUCCESS); |
| 367 | if ((i = (int)strtoll(value, &endptr, 10)) < 1) | 367 | if ((i = (int)strtoll(value, &endptr, 10)) < 1) |
| @@ -370,10 +370,8 @@ tinyrad_conf_opt( | |||
| 370 | return(TRAD_SUCCESS); | 370 | return(TRAD_SUCCESS); |
| 371 | memset(&tv, 0, sizeof(struct timeval)); | 371 | memset(&tv, 0, sizeof(struct timeval)); |
| 372 | return(tinyrad_set_option(tr, TRAD_OPT_TIMEOUT, &tv)); | 372 | return(tinyrad_set_option(tr, TRAD_OPT_TIMEOUT, &tv)); |
| 373 | }; | ||
| 374 | 373 | ||
| 375 | if (!(strcasecmp(name, "paths"))) | 374 | case TRAD_CONF_PATHS: |
| 376 | { | ||
| 377 | if ( (!(dict)) || ((dict->paths)) || (!(value)) ) | 375 | if ( (!(dict)) || ((dict->paths)) || (!(value)) ) |
| 378 | return(TRAD_SUCCESS); | 376 | return(TRAD_SUCCESS); |
| 379 | if ((rc = tinyrad_strsplit(value, ':', &strs, &i)) != TRAD_SUCCESS) | 377 | if ((rc = tinyrad_strsplit(value, ':', &strs, &i)) != TRAD_SUCCESS) |
| @@ -385,30 +383,22 @@ tinyrad_conf_opt( | |||
| 385 | }; | 383 | }; |
| 386 | dict->paths = strs; | 384 | dict->paths = strs; |
| 387 | return(TRAD_SUCCESS); | 385 | return(TRAD_SUCCESS); |
| 388 | }; | ||
| 389 | 386 | ||
| 390 | if (!(strcasecmp(name, "secret"))) | 387 | case TRAD_CONF_SECRET: |
| 391 | { | ||
| 392 | if ( (!(tr)) || ((tr->secret)) || (!(value)) ) | 388 | if ( (!(tr)) || ((tr->secret)) || (!(value)) ) |
| 393 | return(TRAD_SUCCESS); | 389 | return(TRAD_SUCCESS); |
| 394 | return(tinyrad_set_option(tr, TRAD_OPT_SECRET_FILE, value)); | 390 | return(tinyrad_set_option(tr, TRAD_OPT_SECRET, value)); |
| 395 | }; | ||
| 396 | 391 | ||
| 397 | if (!(strcasecmp(name, "secret_file"))) | 392 | case TRAD_CONF_SECRET_FILE: |
| 398 | { | ||
| 399 | if ( (!(tr)) || ((tr->secret)) || (!(value)) ) | 393 | if ( (!(tr)) || ((tr->secret)) || (!(value)) ) |
| 400 | return(TRAD_SUCCESS); | 394 | return(TRAD_SUCCESS); |
| 401 | return(tinyrad_set_option(tr, TRAD_OPT_SECRET, value)); | 395 | return(tinyrad_set_option(tr, TRAD_OPT_SECRET_FILE, value)); |
| 402 | }; | ||
| 403 | 396 | ||
| 404 | if (!(strcasecmp(name, "stopinit"))) | 397 | case TRAD_CONF_STOPINIT: |
| 405 | { | ||
| 406 | tinyrad_conf_opt_bool(tr, dict, TRAD_STOPINIT, value); | 398 | tinyrad_conf_opt_bool(tr, dict, TRAD_STOPINIT, value); |
| 407 | return(TRAD_SUCCESS); | 399 | return(TRAD_SUCCESS); |
| 408 | }; | ||
| 409 | 400 | ||
| 410 | if (!(strcasecmp(name, "timeout"))) | 401 | case TRAD_CONF_TIMEOUT: |
| 411 | { | ||
| 412 | if ( (!(tr)) || (tr->timeout != -1) || (!(value)) ) | 402 | if ( (!(tr)) || (tr->timeout != -1) || (!(value)) ) |
| 413 | return(TRAD_SUCCESS); | 403 | return(TRAD_SUCCESS); |
| 414 | if ((i = (int)strtoll(value, &endptr, 10)) < 1) | 404 | if ((i = (int)strtoll(value, &endptr, 10)) < 1) |
| @@ -416,13 +406,14 @@ tinyrad_conf_opt( | |||
| 416 | if ((endptr[0])) | 406 | if ((endptr[0])) |
| 417 | return(TRAD_SUCCESS); | 407 | return(TRAD_SUCCESS); |
| 418 | return(tinyrad_set_option(tr, TRAD_OPT_TIMEOUT, &i)); | 408 | return(tinyrad_set_option(tr, TRAD_OPT_TIMEOUT, &i)); |
| 419 | }; | ||
| 420 | 409 | ||
| 421 | if (!(strcasecmp(name, "uri"))) | 410 | case TRAD_CONF_URI: |
| 422 | { | ||
| 423 | if ( (!(tr)) || ((tr->trud)) || (!(value)) ) | 411 | if ( (!(tr)) || ((tr->trud)) || (!(value)) ) |
| 424 | return(TRAD_SUCCESS); | 412 | return(TRAD_SUCCESS); |
| 425 | return(tinyrad_set_option(tr, TRAD_OPT_URI, value)); | 413 | return(tinyrad_set_option(tr, TRAD_OPT_URI, value)); |
| 414 | |||
| 415 | default: | ||
| 416 | break; | ||
| 426 | }; | 417 | }; |
| 427 | 418 | ||
| 428 | return(TRAD_SUCCESS); | 419 | return(TRAD_SUCCESS); |
