diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-24 01:53:32 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-24 01:53:32 -0800 |
| commit | 3716d0f4d85edb31d310fc409a3ac50680cd5b19 (patch) | |
| tree | ec10bdb8f5db4139ab7ee1e0babdbd3cc9b654b1 | |
| parent | 6a8891969c257d2bfee953bfbe2756c319a8b72e (diff) | |
| download | tinyrad-3716d0f4d85edb31d310fc409a3ac50680cd5b19.tar.gz tinyrad-3716d0f4d85edb31d310fc409a3ac50680cd5b19.tar.bz2 tinyrad-3716d0f4d85edb31d310fc409a3ac50680cd5b19.tar.xz tinyrad-3716d0f4d85edb31d310fc409a3ac50680cd5b19.zip | |
tinyrad: refactoring tinyrad_load_dict()
| -rw-r--r-- | src/tinyrad.c | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/src/tinyrad.c b/src/tinyrad.c index b7f3459..80008e6 100644 --- a/src/tinyrad.c +++ b/src/tinyrad.c | |||
| @@ -150,12 +150,7 @@ tinyrad_cleanup( | |||
| 150 | 150 | ||
| 151 | int | 151 | int |
| 152 | tinyrad_load_dict( | 152 | tinyrad_load_dict( |
| 153 | int opts, | 153 | TinyRadConf * cnf ); |
| 154 | unsigned tr_opts, | ||
| 155 | TinyRad ** trp, | ||
| 156 | const char * url, | ||
| 157 | char ** dict_files, | ||
| 158 | char ** dict_paths ); | ||
| 159 | 154 | ||
| 160 | 155 | ||
| 161 | int | 156 | int |
| @@ -309,7 +304,7 @@ int main(int argc, char * argv[]) | |||
| 309 | }; | 304 | }; |
| 310 | 305 | ||
| 311 | // load TinyRad handle | 306 | // load TinyRad handle |
| 312 | rc = tinyrad_load_dict(cnf->opts, cnf->tr_opts, &cnf->tr, cnf->url, cnf->dict_files, cnf->dict_paths); | 307 | rc = tinyrad_load_dict(cnf); |
| 313 | if (rc != TRAD_SUCCESS) | 308 | if (rc != TRAD_SUCCESS) |
| 314 | { | 309 | { |
| 315 | tinyrad_cleanup(cnf); | 310 | tinyrad_cleanup(cnf); |
| @@ -355,50 +350,42 @@ tinyrad_cleanup( | |||
| 355 | 350 | ||
| 356 | int | 351 | int |
| 357 | tinyrad_load_dict( | 352 | tinyrad_load_dict( |
| 358 | int opts, | 353 | TinyRadConf * cnf ) |
| 359 | unsigned tr_opts, | ||
| 360 | TinyRad ** trp, | ||
| 361 | const char * url, | ||
| 362 | char ** dict_files, | ||
| 363 | char ** dict_paths ) | ||
| 364 | { | 354 | { |
| 365 | int rc; | 355 | int rc; |
| 366 | char ** errs; | 356 | char ** errs; |
| 367 | size_t pos; | 357 | size_t pos; |
| 368 | TinyRadDict * dict; | 358 | TinyRadDict * dict; |
| 369 | 359 | ||
| 370 | assert(trp != NULL); | ||
| 371 | |||
| 372 | errs = NULL; | 360 | errs = NULL; |
| 373 | dict = NULL; | 361 | dict = NULL; |
| 374 | *trp = NULL; | ||
| 375 | 362 | ||
| 376 | if ((dict_files)) | 363 | if ((cnf->dict_files)) |
| 377 | { | 364 | { |
| 378 | // initialize dictionary | 365 | // initialize dictionary |
| 379 | if ((rc = tinyrad_dict_initialize(&dict, tr_opts)) != TRAD_SUCCESS) | 366 | if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) |
| 380 | { | 367 | { |
| 381 | trutils_error(opts, NULL, "out of virtual memory"); | 368 | trutils_error(cnf->opts, NULL, "out of virtual memory"); |
| 382 | return(rc); | 369 | return(rc); |
| 383 | }; | 370 | }; |
| 384 | 371 | ||
| 385 | // set paths | 372 | // set paths |
| 386 | if ((dict_paths)) | 373 | if ((cnf->dict_paths)) |
| 387 | { | 374 | { |
| 388 | if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, dict_paths)) != TRAD_SUCCESS) | 375 | if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) |
| 389 | { | 376 | { |
| 390 | trutils_error(opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); | 377 | trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); |
| 391 | tinyrad_free(dict); | 378 | tinyrad_free(dict); |
| 392 | return(rc); | 379 | return(rc); |
| 393 | }; | 380 | }; |
| 394 | }; | 381 | }; |
| 395 | 382 | ||
| 396 | // parse dictionary files | 383 | // parse dictionary files |
| 397 | for(pos = 0; ( ((dict_files)) && ((dict_files[pos])) ); pos++) | 384 | for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++) |
| 398 | { | 385 | { |
| 399 | if ((rc = tinyrad_dict_parse(dict, dict_files[pos], &errs, 0)) != TRAD_SUCCESS) | 386 | if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) |
| 400 | { | 387 | { |
| 401 | trutils_error(opts, errs, NULL); | 388 | trutils_error(cnf->opts, errs, NULL); |
| 402 | tinyrad_strsfree(errs); | 389 | tinyrad_strsfree(errs); |
| 403 | tinyrad_free(dict); | 390 | tinyrad_free(dict); |
| 404 | return(rc); | 391 | return(rc); |
| @@ -407,7 +394,7 @@ tinyrad_load_dict( | |||
| 407 | }; | 394 | }; |
| 408 | 395 | ||
| 409 | // initialize tinyrad handle | 396 | // initialize tinyrad handle |
| 410 | rc = tinyrad_initialize(trp, dict, url, tr_opts); | 397 | rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts); |
| 411 | tinyrad_free(dict); | 398 | tinyrad_free(dict); |
| 412 | return(rc); | 399 | return(rc); |
| 413 | } | 400 | } |
