aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/tru/tinyradutil.c134
-rw-r--r--src/tru/tinyradutil.h64
2 files changed, 114 insertions, 84 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{
diff --git a/src/tru/tinyradutil.h b/src/tru/tinyradutil.h
index f8f2033..b2e4f92 100644
--- a/src/tru/tinyradutil.h
+++ b/src/tru/tinyradutil.h
@@ -160,60 +160,64 @@ extern const TinyRadUtilWidget tru_widget_map[];
160////////////////// 160//////////////////
161#pragma mark - Prototypes 161#pragma mark - Prototypes
162 162
163//--------------------------//
164// miscellaneous prototypes //
165//--------------------------//
166#pragma mark miscellaneous prototypes
167
168int
169tru_load_tinyrad(
170 TinyRadUtilConf * cnf );
171
172
173//------------------//
174// usage prototypes //
175//------------------//
176#pragma mark usage prototypes
177
163int 178int
164main( 179tru_getopt(
180 TinyRadUtilConf * cnf,
165 int argc, 181 int argc,
166 char * argv[] ); 182 char * const * argv,
183 const char * short_opt,
184 const struct option * long_opt,
185 int * opt_index );
167 186
168 187
169void 188int
170tru_cleanup( 189tru_usage(
171 TinyRadUtilConf * cnf ); 190 TinyRadUtilConf * cnf );
172 191
173 192
174void 193void
175tru_usage_options( 194tru_usage_options(
176 TinyRadUtilConf * cnf ); 195 TinyRadUtilConf * cnf );
177 196
178 197
179void 198void
180tru_usage_summary( 199tru_usage_summary(
181 TinyRadUtilConf * cnf ); 200 TinyRadUtilConf * cnf );
182 201
183 202
203//-------------------//
204// widget prototypes //
205//-------------------//
206#pragma mark widget prototypes
207
184int 208int
185tru_widget_config( 209tru_widget_config(
186 TinyRadUtilConf * cnf ); 210 TinyRadUtilConf * cnf );
187 211
188 212
189int 213int
190tru_widget_dict( 214tru_widget_dict(
191 TinyRadUtilConf * cnf ); 215 TinyRadUtilConf * cnf );
192 216
193 217
194int 218int
195tru_widget_url( 219tru_widget_url(
196 TinyRadUtilConf * cnf ); 220 TinyRadUtilConf * cnf );
197
198
199int
200tru_getopt(
201 TinyRadUtilConf * cnf,
202 int argc,
203 char * const * argv,
204 const char * short_opt,
205 const struct option * long_opt,
206 int * opt_index );
207
208
209int
210tru_load_tinyrad(
211 TinyRadUtilConf * cnf );
212
213
214int
215tru_usage(
216 TinyRadUtilConf * cnf );
217 221
218 222
219#endif /* end of header */ 223#endif /* end of header */