aboutsummaryrefslogtreecommitdiffstatshomepage
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
parente7e2616dd9939966ac356063dfc156c99f318ebd (diff)
downloadtinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.gz
tinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.bz2
tinyrad-2b451eed4ee00d3752117016413582ac08782291.tar.xz
tinyrad-2b451eed4ee00d3752117016413582ac08782291.zip
tinyrad-dict: removing utility
-rw-r--r--Makefile.am11
-rw-r--r--acinclude.m433
-rw-r--r--configure.ac2
-rw-r--r--src/tinyrad-dict.c258
-rwxr-xr-xtests/test-dict-defaults.sh2
5 files changed, 1 insertions, 305 deletions
diff --git a/Makefile.am b/Makefile.am
index 612de70..c10a08d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -105,7 +105,6 @@ EXTRA_PROGRAMS = examples/socket-example \
105EXTRA = lib/libtinyrad.a \ 105EXTRA = lib/libtinyrad.a \
106 lib/libtinyrad.la \ 106 lib/libtinyrad.la \
107 src/tinyrad \ 107 src/tinyrad \
108 src/tinyrad-dict \
109 src/tinyrad-url \ 108 src/tinyrad-url \
110 src/tinyradproxy \ 109 src/tinyradproxy \
111 include/tinyrad.h 110 include/tinyrad.h
@@ -207,9 +206,6 @@ else
207endif 206endif
208if ENABLE_TINYRAD 207if ENABLE_TINYRAD
209 bin_PROGRAMS += src/tinyrad 208 bin_PROGRAMS += src/tinyrad
210endif
211if ENABLE_TINYRAD_DICT
212 bin_PROGRAMS += src/tinyrad-dict
213 TESTS += tests/test-dict-defaults.sh 209 TESTS += tests/test-dict-defaults.sh
214endif 210endif
215if ENABLE_TINYRAD_URL 211if ENABLE_TINYRAD_URL
@@ -306,13 +302,6 @@ src_tinyrad_SOURCES = $(noinst_HEADERS) $(include_HEADERS) \
306 src/tinyrad.c 302 src/tinyrad.c
307 303
308 304
309# macros for src/tinyrad-dict
310src_tinyrad_dict_DEPENDENCIES = $(lib_LTLIBRARIES) $(noinst_LIBRARIES)
311src_tinyrad_dict_LDADD = $(lib_LTLIBRARIES) $(noinst_LIBRARIES)
312src_tinyrad_dict_SOURCES = $(noinst_HEADERS) $(include_HEADERS) \
313 src/tinyrad-dict.c
314
315
316# macros for src/tinyrad-url 305# macros for src/tinyrad-url
317src_tinyrad_url_DEPENDENCIES = $(lib_LTLIBRARIES) $(noinst_LIBRARIES) 306src_tinyrad_url_DEPENDENCIES = $(lib_LTLIBRARIES) $(noinst_LIBRARIES)
318src_tinyrad_url_LDADD = $(lib_LTLIBRARIES) $(noinst_LIBRARIES) 307src_tinyrad_url_LDADD = $(lib_LTLIBRARIES) $(noinst_LIBRARIES)
diff --git a/acinclude.m4 b/acinclude.m4
index 4b2a169..cc01489 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -39,7 +39,6 @@ AC_DEFUN([AC_TINYRAD_COMMON],[dnl
39 AC_REQUIRE([AC_TINYRAD_DOCUMENTATION]) 39 AC_REQUIRE([AC_TINYRAD_DOCUMENTATION])
40 AC_REQUIRE([AC_TINYRAD_LIBTINYRAD]) 40 AC_REQUIRE([AC_TINYRAD_LIBTINYRAD])
41 AC_REQUIRE([AC_TINYRAD_TINYRAD]) 41 AC_REQUIRE([AC_TINYRAD_TINYRAD])
42 AC_REQUIRE([AC_TINYRAD_TINYRAD_DICT])
43 AC_REQUIRE([AC_TINYRAD_TINYRAD_URL]) 42 AC_REQUIRE([AC_TINYRAD_TINYRAD_URL])
44 AC_REQUIRE([AC_TINYRAD_TINYRADPROXY]) 43 AC_REQUIRE([AC_TINYRAD_TINYRADPROXY])
45 44
@@ -47,7 +46,6 @@ AC_DEFUN([AC_TINYRAD_COMMON],[dnl
47 if test "x${ENABLE_DOCUMENATION}" = "xyes";then ENABLE_TINYRAD_COMMON="yes" 46 if test "x${ENABLE_DOCUMENATION}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
48 elif test "x${ENABLE_LIBTINYRAD}" = "xyes";then ENABLE_TINYRAD_COMMON="yes" 47 elif test "x${ENABLE_LIBTINYRAD}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
49 elif test "x${ENABLE_TINYRAD}" = "xyes";then ENABLE_TINYRAD_COMMON="yes" 48 elif test "x${ENABLE_TINYRAD}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
50 elif test "x${ENABLE_TINYRAD_DICT}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
51 elif test "x${ENABLE_TINYRAD_URL}" = "xyes";then ENABLE_TINYRAD_COMMON="yes" 49 elif test "x${ENABLE_TINYRAD_URL}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
52 elif test "x${ENABLE_TINYRADPROXY}" = "xyes";then ENABLE_TINYRAD_COMMON="yes" 50 elif test "x${ENABLE_TINYRADPROXY}" = "xyes";then ENABLE_TINYRAD_COMMON="yes"
53 fi; 51 fi;
@@ -218,37 +216,6 @@ AC_DEFUN([AC_TINYRAD_TINYRAD],[dnl
218])dnl 216])dnl
219 217
220 218
221# AC_TINYRAD_TINYRAD_DICT()
222# ______________________________________________________________________________
223AC_DEFUN([AC_TINYRAD_TINYRAD_DICT],[dnl
224
225 AC_REQUIRE([AC_TINYRAD_UTILITIES])
226
227 enableval=""
228 AC_ARG_ENABLE(
229 tinyrad-dict,
230 [AS_HELP_STRING([--enable-tinyrad-dict], [enable tinyrad-dict utility])],
231 [ ETINYRADDICT=$enableval ],
232 [ ETINYRADDICT=$enableval ]
233 )
234
235 if test "x${ETINYRADDICT}" == "xyes";then
236 ENABLE_TINYRAD_DICT="yes"
237 elif test "x${ETINYRADDICT}" == "xno";then
238 ENABLE_TINYRAD_DICT="no"
239 elif test "x${ENABLE_UTILITIES}" == "xyes";then
240 ENABLE_TINYRAD_DICT="yes"
241 elif test "x${ENABLE_UTILITIES}" == "xno";then
242 ENABLE_TINYRAD_DICT="no"
243 else
244 ENABLE_TINYRAD_DICT="no"
245 fi
246
247 AM_CONDITIONAL([ENABLE_TINYRAD_DICT], [test "$ENABLE_TINYRAD_DICT" = "yes"])
248 AM_CONDITIONAL([DISABLE_TINYRAD_DICT], [test "$ENABLE_TINYRAD_DICT" = "no"])
249])dnl
250
251
252# AC_TINYRAD_TINYRAD_URL() 219# AC_TINYRAD_TINYRAD_URL()
253# ______________________________________________________________________________ 220# ______________________________________________________________________________
254AC_DEFUN([AC_TINYRAD_TINYRAD_URL],[dnl 221AC_DEFUN([AC_TINYRAD_TINYRAD_URL],[dnl
diff --git a/configure.ac b/configure.ac
index 70b244f..bc7592e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,7 +194,6 @@ AC_TINYRAD_LIBTINYRAD
194AC_TINYRAD_UTILITIES 194AC_TINYRAD_UTILITIES
195AC_TINYRAD_TINYRAD 195AC_TINYRAD_TINYRAD
196AC_TINYRAD_TINYRADPROXY 196AC_TINYRAD_TINYRADPROXY
197AC_TINYRAD_TINYRAD_DICT
198AC_TINYRAD_TINYRAD_URL 197AC_TINYRAD_TINYRAD_URL
199AC_TINYRAD_EXAMPLES 198AC_TINYRAD_EXAMPLES
200AC_TINYRAD_DOCUMENTATION 199AC_TINYRAD_DOCUMENTATION
@@ -223,7 +222,6 @@ AC_MSG_NOTICE([ Build examples ${ENABLE_EXAMPLES}])
223AC_MSG_NOTICE([ Install extra docs ${ENABLE_DOCUMENATION}]) 222AC_MSG_NOTICE([ Install extra docs ${ENABLE_DOCUMENATION}])
224AC_MSG_NOTICE([ Install libtinyrad.la ${ENABLE_LIBTINYRAD}]) 223AC_MSG_NOTICE([ Install libtinyrad.la ${ENABLE_LIBTINYRAD}])
225AC_MSG_NOTICE([ Install tinyrad ${ENABLE_TINYRAD}]) 224AC_MSG_NOTICE([ Install tinyrad ${ENABLE_TINYRAD}])
226AC_MSG_NOTICE([ Install tinyrad-dict ${ENABLE_TINYRAD_DICT}])
227AC_MSG_NOTICE([ Install tinyrad-url ${ENABLE_TINYRAD_URL}]) 225AC_MSG_NOTICE([ Install tinyrad-url ${ENABLE_TINYRAD_URL}])
228AC_MSG_NOTICE([ Install tinyradproxy ${ENABLE_TINYRADPROXY}]) 226AC_MSG_NOTICE([ Install tinyradproxy ${ENABLE_TINYRADPROXY}])
229AC_MSG_NOTICE([ Install common files ${ENABLE_TINYRAD_COMMON}]) 227AC_MSG_NOTICE([ Install common files ${ENABLE_TINYRAD_COMMON}])
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 */
diff --git a/tests/test-dict-defaults.sh b/tests/test-dict-defaults.sh
index 7a681b9..70c1c95 100755
--- a/tests/test-dict-defaults.sh
+++ b/tests/test-dict-defaults.sh
@@ -32,7 +32,7 @@
32 32
33CODE=0 33CODE=0
34 34
35test -x src/tinyrad-dict || exit 77 35test -x src/tinyrad || exit 77
36 36
37TINYRADNOINIT=1 37TINYRADNOINIT=1
38export TINYRADNOINIT 38export TINYRADNOINIT