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.c134
1 files changed, 80 insertions, 54 deletions
diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c
index 9c7c3cc..e4ecbf8 100644
--- a/src/tru/tinyradutil.c
+++ b/src/tru/tinyradutil.c
@@ -80,10 +80,21 @@
80////////////////// 80//////////////////
81#pragma mark - Prototypes 81#pragma mark - Prototypes
82 82
83int
84main(
85 int argc,
86 char * argv[] );
87
88
89void
90tru_cleanup(
91 TinyRadUtilConf * cnf );
92
93
83static const TinyRadUtilWidget * 94static const TinyRadUtilWidget *
84tru_widget_lookup( 95tru_widget_lookup(
85 const char * wname, 96 const char * wname,
86 int exact ); 97 int exact );
87 98
88 99
89///////////////// 100/////////////////
@@ -146,6 +157,11 @@ const TinyRadUtilWidget tru_widget_map[] =
146///////////////// 157/////////////////
147#pragma mark - Functions 158#pragma mark - Functions
148 159
160//---------------//
161// main function //
162//---------------//
163#pragma mark main function
164
149int main(int argc, char * argv[]) 165int main(int argc, char * argv[])
150{ 166{
151 int c; 167 int c;
@@ -260,6 +276,11 @@ int main(int argc, char * argv[])
260} 276}
261 277
262 278
279//-------------------------//
280// miscellaneous functions //
281//-------------------------//
282#pragma mark miscellaneous functions
283
263void 284void
264tru_cleanup( 285tru_cleanup(
265 TinyRadUtilConf * cnf ) 286 TinyRadUtilConf * cnf )
@@ -272,6 +293,63 @@ tru_cleanup(
272 293
273 294
274int 295int
296tru_load_tinyrad(
297 TinyRadUtilConf * cnf )
298{
299 int rc;
300 char ** errs;
301 size_t pos;
302 TinyRadDict * dict;
303
304 errs = NULL;
305 dict = NULL;
306
307 if ((cnf->dict_files))
308 {
309 // initialize dictionary
310 if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS)
311 {
312 trutils_error(cnf->opts, NULL, "out of virtual memory");
313 return(rc);
314 };
315
316 // set paths
317 if ((cnf->dict_paths))
318 {
319 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS)
320 {
321 trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc));
322 tinyrad_free(dict);
323 return(rc);
324 };
325 };
326
327 // parse dictionary files
328 for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++)
329 {
330 if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS)
331 {
332 trutils_error(cnf->opts, errs, NULL);
333 tinyrad_strsfree(errs);
334 tinyrad_free(dict);
335 return(rc);
336 };
337 };
338 };
339
340 // initialize tinyrad handle
341 rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts);
342 tinyrad_free(dict);
343 return(rc);
344}
345
346
347//-----------------//
348// usage functions //
349//-----------------//
350#pragma mark usage functions
351
352int
275tru_getopt( 353tru_getopt(
276 TinyRadUtilConf * cnf, 354 TinyRadUtilConf * cnf,
277 int argc, 355 int argc,
@@ -337,58 +415,6 @@ tru_getopt(
337 415
338 416
339int 417int
340tru_load_tinyrad(
341 TinyRadUtilConf * cnf )
342{
343 int rc;
344 char ** errs;
345 size_t pos;
346 TinyRadDict * dict;
347
348 errs = NULL;
349 dict = NULL;
350
351 if ((cnf->dict_files))
352 {
353 // initialize dictionary
354 if ((rc = tinyrad_dict_initialize(&dict, cnf->tr_opts)) != TRAD_SUCCESS)
355 {
356 trutils_error(cnf->opts, NULL, "out of virtual memory");
357 return(rc);
358 };
359
360 // set paths
361 if ((cnf->dict_paths))
362 {
363 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, cnf->dict_paths)) != TRAD_SUCCESS)
364 {
365 trutils_error(cnf->opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc));
366 tinyrad_free(dict);
367 return(rc);
368 };
369 };
370
371 // parse dictionary files
372 for(pos = 0; ( ((cnf->dict_files)) && ((cnf->dict_files[pos])) ); pos++)
373 {
374 if ((rc = tinyrad_dict_parse(dict, cnf->dict_files[pos], &errs, 0)) != TRAD_SUCCESS)
375 {
376 trutils_error(cnf->opts, errs, NULL);
377 tinyrad_strsfree(errs);
378 tinyrad_free(dict);
379 return(rc);
380 };
381 };
382 };
383
384 // initialize tinyrad handle
385 rc = tinyrad_initialize(&cnf->tr, dict, cnf->url, cnf->tr_opts);
386 tinyrad_free(dict);
387 return(rc);
388}
389
390
391int
392tru_usage( 418tru_usage(
393 TinyRadUtilConf * cnf ) 419 TinyRadUtilConf * cnf )
394{ 420{