aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-24 16:51:40 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-24 16:51:40 -0800
commit0c99b6be87c8a752b91670b9493cef2e2ba9afb8 (patch)
tree75e97f6e9f21359da1341646822a7ce6b3954a03 /src
parent1971dccbb4c2c453010952364e65905ce44c467f (diff)
downloadtinyrad-0c99b6be87c8a752b91670b9493cef2e2ba9afb8.tar.gz
tinyrad-0c99b6be87c8a752b91670b9493cef2e2ba9afb8.tar.bz2
tinyrad-0c99b6be87c8a752b91670b9493cef2e2ba9afb8.tar.xz
tinyrad-0c99b6be87c8a752b91670b9493cef2e2ba9afb8.zip
tinyrad: splitting source into source file and header file
Diffstat (limited to 'src')
-rw-r--r--src/tinyradutil/tinyradutil.c118
-rw-r--r--src/tinyradutil/tinyradutil.h209
2 files changed, 211 insertions, 116 deletions
diff --git a/src/tinyradutil/tinyradutil.c b/src/tinyradutil/tinyradutil.c
index b9eac75..b8c7a60 100644
--- a/src/tinyradutil/tinyradutil.c
+++ b/src/tinyradutil/tinyradutil.c
@@ -29,6 +29,7 @@
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31#define _SRC_TINYRADUTIL_TINYRADUTIL_C 1 31#define _SRC_TINYRADUTIL_TINYRADUTIL_C 1
32#include "tinyradutil.h"
32 33
33/////////////// 34///////////////
34// // 35// //
@@ -62,40 +63,6 @@
62/////////////////// 63///////////////////
63#pragma mark - Definitions 64#pragma mark - Definitions
64 65
65#undef PROGRAM_NAME
66#define PROGRAM_NAME "tinyrad"
67
68#define MY_OPT_DICT_DEFAULTS 0x0001UL
69#define MY_OPT_DICT_DUMP 0x0002UL
70#define MY_OPT_DICT_LOADED 0x0004UL
71#define MY_OPT_CONFIG_PRINT 0x0008UL
72
73
74#define MY_GETOPT_MATCHED -2
75#define MY_GETOPT_ERROR -3
76#define MY_GETOPT_EXIT -4
77
78
79#define TINYRAD_GETOPT_SHORT "d:f:hqVv"
80#define TINYRAD_GETOPT_LONG \
81 { "debug", optional_argument, NULL, 'd' }, \
82 { "help", no_argument, NULL, 'h' }, \
83 { "quiet", no_argument, NULL, 'q' }, \
84 { "silent", no_argument, NULL, 'q' }, \
85 { "version", no_argument, NULL, 'V' }, \
86 { "verbose", no_argument, NULL, 'v' }, \
87 { NULL, 0, NULL, 0 }
88
89
90#define TINYRAD_DICT_GETOPT_SHORT "bD:I:"
91#define TINYRAD_DICT_GETOPT_LONG \
92 { "builtin-dict", no_argument, NULL, 'b' }, \
93
94
95#define TINYRAD_REQ_GETOPT_SHORT "D:I:"
96#define TINYRAD_REQ_GETOPT_LONG \
97 { "file", optional_argument, NULL, 'f' }, \
98
99 66
100////////////////// 67//////////////////
101// // 68// //
@@ -104,47 +71,6 @@
104////////////////// 71//////////////////
105#pragma mark - Data Types 72#pragma mark - Data Types
106 73
107typedef struct tinyrad_util_config TinyRadUtilConf;
108typedef struct tinyrad_util_widget TinyRadUtilWidget;
109
110
111typedef struct my_request_av
112{
113 char * attr_name;
114 char * attr_value;
115} MyRequestAV;
116
117
118struct tinyrad_util_config
119{
120 unsigned opts;
121 unsigned tr_opts;
122 int padint;
123 int cmd_argc;
124 char ** cmd_argv;
125 const char * cmd_name;
126 size_t cmd_len;
127 void * padptr;
128 const TinyRadUtilWidget * cmd;
129 TinyRad * tr;
130 const char * url;
131 char ** dict_files;
132 char ** dict_paths;
133};
134
135
136struct tinyrad_util_widget
137{
138 const char * name;
139 int (*func)(TinyRadUtilConf * cnf);
140 const char * shortopts;
141 struct option * longopts;
142 int min_arg;
143 int max_arg;
144 const char * usage;
145 const char * desc;
146};
147
148 74
149////////////////// 75//////////////////
150// // 76// //
@@ -153,46 +79,6 @@ struct tinyrad_util_widget
153////////////////// 79//////////////////
154#pragma mark - Prototypes 80#pragma mark - Prototypes
155 81
156int
157main(
158 int argc,
159 char * argv[] );
160
161
162void
163tru_cleanup(
164 TinyRadUtilConf * cnf );
165
166
167int
168tru_widget_config(
169 TinyRadUtilConf * cnf );
170
171
172int
173tru_widget_dict(
174 TinyRadUtilConf * cnf );
175
176
177int
178tru_getopt(
179 TinyRadUtilConf * cnf,
180 int argc,
181 char * const * argv,
182 const char * short_opt,
183 const struct option * long_opt,
184 int * opt_index );
185
186
187int
188tru_load_tinyrad(
189 TinyRadUtilConf * cnf );
190
191
192int
193tru_usage(
194 TinyRadUtilConf * cnf );
195
196 82
197///////////////// 83/////////////////
198// // 84// //
@@ -202,7 +88,7 @@ tru_usage(
202#pragma mark - Variables 88#pragma mark - Variables
203 89
204#pragma mark tinyrad_cmdmap[] 90#pragma mark tinyrad_cmdmap[]
205static const TinyRadUtilWidget tru_widget_map[] = 91const TinyRadUtilWidget tru_widget_map[] =
206{ 92{
207 { 93 {
208 .name = "configuration", 94 .name = "configuration",
diff --git a/src/tinyradutil/tinyradutil.h b/src/tinyradutil/tinyradutil.h
new file mode 100644
index 0000000..aa76803
--- /dev/null
+++ b/src/tinyradutil/tinyradutil.h
@@ -0,0 +1,209 @@
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#ifndef _SRC_TINYRADUTIL_TINYRADUTIL_H
32#define _SRC_TINYRADUTIL_TINYRADUTIL_H 1
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#include <sys/types.h>
51#include <sys/stat.h>
52#include <sys/uio.h>
53#include <unistd.h>
54#include <assert.h>
55#include <fcntl.h>
56#include <errno.h>
57
58
59///////////////////
60// //
61// Definitions //
62// //
63///////////////////
64#pragma mark - Definitions
65
66#undef PROGRAM_NAME
67#define PROGRAM_NAME "tinyrad"
68
69#define MY_OPT_DICT_DEFAULTS 0x0001UL
70#define MY_OPT_DICT_DUMP 0x0002UL
71#define MY_OPT_DICT_LOADED 0x0004UL
72#define MY_OPT_CONFIG_PRINT 0x0008UL
73
74
75#define MY_GETOPT_MATCHED -2
76#define MY_GETOPT_ERROR -3
77#define MY_GETOPT_EXIT -4
78
79
80#define TINYRAD_GETOPT_SHORT "d:f:hqVv"
81#define TINYRAD_GETOPT_LONG \
82 { "debug", optional_argument, NULL, 'd' }, \
83 { "help", no_argument, NULL, 'h' }, \
84 { "quiet", no_argument, NULL, 'q' }, \
85 { "silent", no_argument, NULL, 'q' }, \
86 { "version", no_argument, NULL, 'V' }, \
87 { "verbose", no_argument, NULL, 'v' }, \
88 { NULL, 0, NULL, 0 }
89
90
91#define TINYRAD_DICT_GETOPT_SHORT "bD:I:"
92#define TINYRAD_DICT_GETOPT_LONG \
93 { "builtin-dict", no_argument, NULL, 'b' }, \
94
95
96#define TINYRAD_REQ_GETOPT_SHORT "D:I:"
97#define TINYRAD_REQ_GETOPT_LONG \
98 { "file", optional_argument, NULL, 'f' }, \
99
100
101//////////////////
102// //
103// Data Types //
104// //
105//////////////////
106#pragma mark - Data Types
107
108typedef struct tinyrad_util_config TinyRadUtilConf;
109typedef struct tinyrad_util_widget TinyRadUtilWidget;
110
111
112typedef struct my_request_av
113{
114 char * attr_name;
115 char * attr_value;
116} MyRequestAV;
117
118
119struct tinyrad_util_config
120{
121 unsigned opts;
122 unsigned tr_opts;
123 int padint;
124 int cmd_argc;
125 char ** cmd_argv;
126 const char * cmd_name;
127 size_t cmd_len;
128 void * padptr;
129 const TinyRadUtilWidget * cmd;
130 TinyRad * tr;
131 const char * url;
132 char ** dict_files;
133 char ** dict_paths;
134};
135
136
137struct tinyrad_util_widget
138{
139 const char * name;
140 int (*func)(TinyRadUtilConf * cnf);
141 const char * shortopts;
142 struct option * longopts;
143 int min_arg;
144 int max_arg;
145 const char * usage;
146 const char * desc;
147};
148
149
150/////////////////
151// //
152// Variables //
153// //
154/////////////////
155#pragma mark - Variables
156
157#pragma mark tinyrad_cmdmap[]
158extern const TinyRadUtilWidget tru_widget_map[];
159
160
161//////////////////
162// //
163// Prototypes //
164// //
165//////////////////
166#pragma mark - Prototypes
167
168int
169main(
170 int argc,
171 char * argv[] );
172
173
174void
175tru_cleanup(
176 TinyRadUtilConf * cnf );
177
178
179int
180tru_widget_config(
181 TinyRadUtilConf * cnf );
182
183
184int
185tru_widget_dict(
186 TinyRadUtilConf * cnf );
187
188
189int
190tru_getopt(
191 TinyRadUtilConf * cnf,
192 int argc,
193 char * const * argv,
194 const char * short_opt,
195 const struct option * long_opt,
196 int * opt_index );
197
198
199int
200tru_load_tinyrad(
201 TinyRadUtilConf * cnf );
202
203
204int
205tru_usage(
206 TinyRadUtilConf * cnf );
207
208
209#endif /* end of header */