aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-21 23:34:25 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-21 23:34:25 -0800
commit2b451eed4ee00d3752117016413582ac08782291 (patch)
treecf64d2d8343f4449c4c05fbcba470e88a2c9da7c /src
parente7e2616dd9939966ac356063dfc156c99f318ebd (diff)
downloadtinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.gz
tinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.bz2
tinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.xz
tinyrad-2b451eed4ee00d3752117016413582ac08782291.zip
tinyrad-dict: removing utility
Diffstat (limited to 'src')
-rw-r--r--src/tinyrad-dict.c258
1 files changed, 0 insertions, 258 deletions
diff --git a/src/tinyrad-dict.c b/src/tinyrad-dict.c
deleted file mode 100644
index ea76f77..0000000
--- a/src/tinyrad-dict.c
+++ /dev/null
@@ -1,258 +0,0 @@
1/*
2 * Tiny RADIUS Client Library
3 * Copyright (C) 2021 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _SRC_UTILITIES_TINYRAD_C 1
32
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include <tinyrad_utils.h>
42
43#include <stdio.h>
44#include <stdarg.h>
45#include <stdlib.h>
46#include <string.h>
47#include <strings.h>
48#include <unistd.h>
49#include <getopt.h>
50
51
52///////////////////
53// //
54// Definitions //
55// //
56///////////////////
57#pragma mark - Definitions
58
59#undef PROGRAM_NAME
60#define PROGRAM_NAME "tinyrad"
61
62#define MY_OPT_DICT_DEFAULTS 0x0001
63#define MY_OPT_DICT_DUMP 0x0002
64
65
66//////////////////
67// //
68// Prototypes //
69// //
70//////////////////
71#pragma mark - Prototypes
72
73int main( int argc, char * argv[] );
74
75void my_usage( void );
76
77
78/////////////////
79// //
80// Functions //
81// //
82/////////////////
83#pragma mark - Functions
84
85int main(int argc, char * argv[])
86{
87 int opt;
88 int c;
89 int opt_index;
90 int rc;
91 int opts;
92 unsigned tr_opts;
93 TinyRadDict * dict;
94 size_t pos;
95 char ** errs;
96 char ** paths;
97 char ** files;
98
99 // getopt options
100 static char short_opt[] = "d:D:hI:qVv";
101 static struct option long_opt[] =
102 {
103 {"debug", optional_argument, NULL, 'd' },
104 {"help", no_argument, NULL, 'h' },
105 {"quiet", no_argument, NULL, 'q' },
106 {"silent", no_argument, NULL, 'q' },
107 {"version", no_argument, NULL, 'V' },
108 {"verbose", no_argument, NULL, 'v' },
109 {"defaults", no_argument, NULL, 2 },
110 {"dictionary-dump", no_argument, NULL, 1 },
111 { NULL, 0, NULL, 0 }
112 };
113
114 trutils_initialize(PROGRAM_NAME);
115
116 opts = 0;
117 tr_opts = 0;
118 paths = NULL;
119 files = NULL;
120
121 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
122 {
123 switch(c)
124 {
125 case -1: /* no more arguments */
126 case 0: /* long options toggles */
127 break;
128
129 case 1:
130 opts |= MY_OPT_DICT_DUMP;
131 break;
132
133 case 2:
134 tr_opts |= TRAD_BUILTIN_DICT;
135 break;
136
137 case 'D':
138 if (tinyrad_strsadd(&files, optarg) != TRAD_SUCCESS)
139 {
140 fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME);
141 tinyrad_strsfree(files);
142 tinyrad_strsfree(paths);
143 return(trutils_exit_code(TRAD_ENOMEM));
144 };
145 break;
146
147 case 'd':
148 opt = ((optarg)) ? (int)strtol(optarg, NULL, 0) : TRAD_DEBUG_ANY;
149 tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt);
150 break;
151
152 case 'h':
153 my_usage();
154 return(0);
155
156 case 'I':
157 if (tinyrad_strsadd(&paths, optarg) != TRAD_SUCCESS)
158 {
159 fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME);
160 tinyrad_strsfree(files);
161 tinyrad_strsfree(paths);
162 return(trutils_exit_code(TRAD_ENOMEM));
163 };
164 break;
165
166 case 'V':
167 trutils_version();
168 return(0);
169
170 case 'q':
171 opts |= TRUTILS_OPT_QUIET;
172 opts &= ~TRUTILS_OPT_VERBOSE;
173 break;
174
175 case 'v':
176 opts |= TRUTILS_OPT_VERBOSE;
177 opts &= ~TRUTILS_OPT_QUIET;
178 break;
179
180 case '?':
181 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
182 return(trutils_exit_code(TRAD_EUNKNOWN));
183
184 default:
185 fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
186 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
187 return(trutils_exit_code(TRAD_EUNKNOWN));
188 };
189 };
190
191 // initialize dictionary
192 if ((rc = tinyrad_dict_initialize(&dict, tr_opts)) != TRAD_SUCCESS)
193 {
194 tinyrad_strsfree(files);
195 tinyrad_strsfree(paths);
196 fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME);
197 return(trutils_exit_code(rc));
198 };
199
200 // add paths
201 for(pos = 0; ( ((paths)) && ((paths[pos])) ); pos++)
202 {
203 if ((rc = tinyrad_dict_add_path(dict, paths[pos])) != TRAD_SUCCESS)
204 {
205 tinyrad_strsfree(paths);
206 tinyrad_strsfree(files);
207 tinyrad_free(dict);
208 trutils_error(opts, NULL, "%s: %s", optarg, tinyrad_strerror(rc));
209 return(trutils_exit_code(rc));
210 };
211 };
212
213 // add dictionary files
214 for(pos = 0; ( ((files)) && ((files[pos])) ); pos++)
215 {
216 if ((rc = tinyrad_dict_parse(dict, files[pos], &errs, 0)) != TRAD_SUCCESS)
217 {
218 trutils_error(opts, errs, NULL);
219 tinyrad_strsfree(errs);
220 tinyrad_strsfree(paths);
221 tinyrad_strsfree(files);
222 tinyrad_free(dict);
223 return(trutils_exit_code(rc));
224 };
225 };
226
227 // dump dictionary
228 if ((opts & MY_OPT_DICT_DUMP))
229 tinyrad_dict_print(dict, 0xffff);
230
231 // frees resources
232 tinyrad_strsfree(paths);
233 tinyrad_strsfree(files);
234 tinyrad_free(dict);
235
236 return(0);
237}
238
239
240void my_usage(void)
241{
242 printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME);
243 printf("OPTIONS:\n");
244 printf(" -D dictionary include dictionary\n");
245 printf(" -d level, --debug=level print debug messages\n");
246 printf(" -h, --help print this help and exit\n");
247 printf(" -I path add path to dictionary search paths\n");
248 printf(" -q, --quiet, --silent do not print messages\n");
249 printf(" -V, --version print version number and exit\n");
250 printf(" -v, --verbose print verbose messages\n");
251 printf(" --defaults load default dictionaries\n");
252 printf(" --dictionary-dump print imported dictionaries\n");
253 printf("\n");
254 return;
255}
256
257
258/* end of source */