aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-22 10:44:42 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-22 10:44:42 -0800
commit7243bd0e592b0f7741bd554f5b5cf23a40cea1e0 (patch)
treedff8f409a2d5cb9e1ae6d11ea17e260ac8fd2cf3 /src
parent82f5942079ffee4ba21d2b9d9be6dd25f96fd694 (diff)
downloadtinyrad-7243bd0e592b0f7741bd554f5b5cf23a40cea1e0.tar.gz
tinyrad-7243bd0e592b0f7741bd554f5b5cf23a40cea1e0.tar.bz2
tinyrad-7243bd0e592b0f7741bd554f5b5cf23a40cea1e0.tar.xz
tinyrad-7243bd0e592b0f7741bd554f5b5cf23a40cea1e0.zip
tinyrad: replacing my_dict_load() with my_tinyrad_load()
Diffstat (limited to 'src')
-rw-r--r--src/tinyrad.c91
1 files changed, 41 insertions, 50 deletions
diff --git a/src/tinyrad.c b/src/tinyrad.c
index 9c0a95d..6832b00 100644
--- a/src/tinyrad.c
+++ b/src/tinyrad.c
@@ -99,10 +99,11 @@ main(
99 99
100 100
101int 101int
102my_dict_load( 102my_tinyrad_load(
103 int opts, 103 int opts,
104 unsigned tr_opts, 104 unsigned tr_opts,
105 TinyRadDict ** dictp, 105 TinyRad ** trp,
106 const char * url,
106 char ** dict_files, 107 char ** dict_files,
107 char ** dict_paths ); 108 char ** dict_paths );
108 109
@@ -240,26 +241,12 @@ int main(int argc, char * argv[])
240 return(1); 241 return(1);
241 }; 242 };
242 243
243 // load RADIUS dictionary 244 // load TinyRad handle
244 if ((dict_files)) 245 rc = my_tinyrad_load(opts, tr_opts, &tr, url, dict_files, dict_paths);
245 {
246 if ((rc = my_dict_load(opts, tr_opts, &dict, dict_files, dict_paths)) != TRAD_SUCCESS)
247 {
248 tinyrad_strsfree(dict_files);
249 tinyrad_strsfree(dict_paths);
250 return(trutils_exit_code(rc));
251 };
252 };
253 tinyrad_strsfree(dict_paths);
254 tinyrad_strsfree(dict_files); 246 tinyrad_strsfree(dict_files);
255 247 tinyrad_strsfree(dict_paths);
256 // initialize tinyrad handle 248 if (rc != TRAD_SUCCESS)
257 if ((rc = tinyrad_initialize(&tr, dict, url, tr_opts)) != TRAD_SUCCESS)
258 {
259 tinyrad_free(dict);
260 return(trutils_exit_code(rc)); 249 return(trutils_exit_code(rc));
261 };
262 tinyrad_free(dict);
263 250
264 // display dictionary 251 // display dictionary
265 if ((opts & MY_OPT_DICT_DUMP)) 252 if ((opts & MY_OPT_DICT_DUMP))
@@ -278,10 +265,11 @@ int main(int argc, char * argv[])
278 265
279 266
280int 267int
281my_dict_load( 268my_tinyrad_load(
282 int opts, 269 int opts,
283 unsigned tr_opts, 270 unsigned tr_opts,
284 TinyRadDict ** dictp, 271 TinyRad ** trp,
272 const char * url,
285 char ** dict_files, 273 char ** dict_files,
286 char ** dict_paths ) 274 char ** dict_paths )
287{ 275{
@@ -290,46 +278,49 @@ my_dict_load(
290 size_t pos; 278 size_t pos;
291 TinyRadDict * dict; 279 TinyRadDict * dict;
292 280
293 assert(dictp != NULL); 281 assert(trp != NULL);
294 282
295 errs = NULL; 283 errs = NULL;
284 dict = NULL;
285 *trp = NULL;
296 286
297 if (!(dict_files)) 287 if ((dict_files))
298 return(TRAD_SUCCESS);
299
300 // initialize dictionary
301 if ((rc = tinyrad_dict_initialize(&dict, tr_opts)) != TRAD_SUCCESS)
302 {
303 trutils_error(opts, NULL, "out of virtual memory");
304 return(rc);
305 };
306
307 // set paths
308 if ((dict_paths))
309 { 288 {
310 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, dict_paths)) != TRAD_SUCCESS) 289 // initialize dictionary
290 if ((rc = tinyrad_dict_initialize(&dict, tr_opts)) != TRAD_SUCCESS)
311 { 291 {
312 trutils_error(opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc)); 292 trutils_error(opts, NULL, "out of virtual memory");
313 tinyrad_free(dict);
314 return(rc); 293 return(rc);
315 }; 294 };
316 };
317 295
318 // parse dictionary files 296 // set paths
319 for(pos = 0; ( ((dict_files)) && ((dict_files[pos])) ); pos++) 297 if ((dict_paths))
320 {
321 if ((rc = tinyrad_dict_parse(dict, dict_files[pos], &errs, 0)) != TRAD_SUCCESS)
322 { 298 {
323 trutils_error(opts, errs, NULL); 299 if ((rc = tinyrad_dict_set_option(dict, TRAD_DICT_OPT_PATHS, dict_paths)) != TRAD_SUCCESS)
324 tinyrad_strsfree(errs); 300 {
325 tinyrad_free(dict); 301 trutils_error(opts, NULL, "tinyrad_dict_set_option(TRAD_DICT_OPT_PATHS): %s", tinyrad_strerror(rc));
326 return(rc); 302 tinyrad_free(dict);
303 return(rc);
304 };
327 }; 305 };
328 };
329 306
330 *dictp = dict; 307 // parse dictionary files
308 for(pos = 0; ( ((dict_files)) && ((dict_files[pos])) ); pos++)
309 {
310 if ((rc = tinyrad_dict_parse(dict, dict_files[pos], &errs, 0)) != TRAD_SUCCESS)
311 {
312 trutils_error(opts, errs, NULL);
313 tinyrad_strsfree(errs);
314 tinyrad_free(dict);
315 return(rc);
316 };
317 };
318 };
331 319
332 return(TRAD_SUCCESS); 320 // initialize tinyrad handle
321 rc = tinyrad_initialize(trp, dict, url, tr_opts);
322 tinyrad_free(dict);
323 return(rc);
333} 324}
334 325
335 326