aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tru/tinyradutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tru/tinyradutil.c')
-rw-r--r--src/tru/tinyradutil.c77
1 files changed, 67 insertions, 10 deletions
diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c
index fafd309..b07492a 100644
--- a/src/tru/tinyradutil.c
+++ b/src/tru/tinyradutil.c
@@ -218,6 +218,65 @@ int main(int argc, char * argv[])
218} 218}
219 219
220 220
221//-------------------//
222// logging functions //
223//-------------------//
224#pragma mark logging functions
225
226int
227tru_error(
228 TinyRadUtilConf * cnf,
229 int rc,
230 const char * fmt,
231 ... )
232{
233 va_list args;
234 const char * prog_name;
235
236 if ((cnf->opts & TRUTILS_OPT_QUIET))
237 return(rc);
238
239 prog_name = ((cnf->prog_name)) ? cnf->prog_name : PROGRAM_NAME;
240
241 fprintf(stderr, "%s: ", prog_name);
242
243 if (!(fmt))
244 {
245 fprintf(stderr, "%s\n", tinyrad_strerror(rc));
246 return(rc);
247 }
248
249 va_start(args, fmt);
250 vfprintf(stderr, fmt, args);
251 va_end(args);
252 fprintf(stderr, "\n");
253
254 return(rc);
255}
256
257
258int
259tru_errors(
260 TinyRadUtilConf * cnf,
261 int rc,
262 char ** errs )
263{
264 int pos;
265 const char * prog_name;
266
267 if ((cnf->opts & TRUTILS_OPT_QUIET))
268 return(rc);
269
270 prog_name = ((cnf->prog_name)) ? cnf->prog_name : PROGRAM_NAME;
271
272 if ((errs))
273 for(pos = 0; ((errs[pos])); pos++)
274 fprintf(stderr, "%s: %s\n", prog_name, errs[pos]);
275
276 return(rc);
277}
278
279
221//-------------------------// 280//-------------------------//
222// miscellaneous functions // 281// miscellaneous functions //
223//-------------------------// 282//-------------------------//
@@ -262,17 +321,14 @@ tru_load_tinyrad(
262 { 321 {
263 // initialize dictionary 322 // initialize dictionary
264 if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS) 323 if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS)
265 { 324 return(tru_error(cnf, rc, "out of virtual memory"));
266 trutils_error(cnf->opts, NULL, "out of virtual memory");
267 return(rc);
268 };
269 325
270 // set paths 326 // set paths
271 if ((cnf->dict_paths)) 327 if ((cnf->dict_paths))
272 { 328 {
273 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS) 329 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS)
274 { 330 {
275 trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); 331 tru_error(cnf, rc, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc));
276 tinyrad_free(dict); 332 tinyrad_free(dict);
277 return(rc); 333 return(rc);
278 }; 334 };
@@ -283,7 +339,7 @@ tru_load_tinyrad(
283 { 339 {
284 if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS) 340 if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS)
285 { 341 {
286 trutils_error(cnf->opts, errs, NULL); 342 tru_errors(cnf, rc, errs);
287 tinyrad_strsfree(errs); 343 tinyrad_strsfree(errs);
288 tinyrad_free(dict); 344 tinyrad_free(dict);
289 return(rc); 345 return(rc);
@@ -361,6 +417,7 @@ tru_getopt(
361 const struct option * long_opt, 417 const struct option * long_opt,
362 int * opt_index ) 418 int * opt_index )
363{ 419{
420 int rc;
364 int c; 421 int c;
365 int opt; 422 int opt;
366 423
@@ -379,9 +436,9 @@ tru_getopt(
379 return(TRU_GETOPT_MATCHED); 436 return(TRU_GETOPT_MATCHED);
380 437
381 case 'D': 438 case 'D':
382 if (tinyrad_strsadd(&cnf->dict_files, optarg) != TRAD_SUCCESS) 439 if ((rc = tinyrad_strsadd(&cnf->dict_files, optarg)) != TRAD_SUCCESS)
383 { 440 {
384 trutils_error(cnf->opts, NULL, "out of virtual memory"); 441 tru_error(cnf, rc, "out of virtual memory");
385 return(TRU_GETOPT_ERROR); 442 return(TRU_GETOPT_ERROR);
386 }; 443 };
387 return(TRU_GETOPT_MATCHED); 444 return(TRU_GETOPT_MATCHED);
@@ -396,9 +453,9 @@ tru_getopt(
396 return(TRU_GETOPT_MATCHED); 453 return(TRU_GETOPT_MATCHED);
397 454
398 case 'I': 455 case 'I':
399 if (tinyrad_strsadd(&cnf->dict_paths, optarg) != TRAD_SUCCESS) 456 if ((rc = tinyrad_strsadd(&cnf->dict_paths, optarg)) != TRAD_SUCCESS)
400 { 457 {
401 trutils_error(cnf->opts, NULL, "out of virtual memory"); 458 tru_error(cnf, rc, "out of virtual memory");
402 return(TRU_GETOPT_ERROR); 459 return(TRU_GETOPT_ERROR);
403 }; 460 };
404 return(TRU_GETOPT_MATCHED); 461 return(TRU_GETOPT_MATCHED);