From 0c99b6be87c8a752b91670b9493cef2e2ba9afb8 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Thu, 24 Mar 2022 16:51:40 -0800 Subject: tinyrad: splitting source into source file and header file --- Makefile.am | 3 +- src/tinyradutil/tinyradutil.c | 118 +----------------------- src/tinyradutil/tinyradutil.h | 209 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+), 117 deletions(-) create mode 100644 src/tinyradutil/tinyradutil.h diff --git a/Makefile.am b/Makefile.am index f6f9abb..78d3bfc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -305,7 +305,8 @@ lib_libutils_a_SOURCES = $(noinst_HEADERS) $(include_HEADERS) \ src_tinyrad_DEPENDENCIES = $(lib_LTLIBRARIES) $(noinst_LIBRARIES) src_tinyrad_LDADD = $(lib_LTLIBRARIES) $(noinst_LIBRARIES) src_tinyrad_SOURCES = $(noinst_HEADERS) $(include_HEADERS) \ - src/tinyradutil/tinyradutil.c + src/tinyradutil/tinyradutil.c \ + src/tinyradutil/tinyradutil.h # macros for src/tinyrad-url 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 @@ * SUCH DAMAGE. */ #define _SRC_TINYRADUTIL_TINYRADUTIL_C 1 +#include "tinyradutil.h" /////////////// // // @@ -62,40 +63,6 @@ /////////////////// #pragma mark - Definitions -#undef PROGRAM_NAME -#define PROGRAM_NAME "tinyrad" - -#define MY_OPT_DICT_DEFAULTS 0x0001UL -#define MY_OPT_DICT_DUMP 0x0002UL -#define MY_OPT_DICT_LOADED 0x0004UL -#define MY_OPT_CONFIG_PRINT 0x0008UL - - -#define MY_GETOPT_MATCHED -2 -#define MY_GETOPT_ERROR -3 -#define MY_GETOPT_EXIT -4 - - -#define TINYRAD_GETOPT_SHORT "d:f:hqVv" -#define TINYRAD_GETOPT_LONG \ - { "debug", optional_argument, NULL, 'd' }, \ - { "help", no_argument, NULL, 'h' }, \ - { "quiet", no_argument, NULL, 'q' }, \ - { "silent", no_argument, NULL, 'q' }, \ - { "version", no_argument, NULL, 'V' }, \ - { "verbose", no_argument, NULL, 'v' }, \ - { NULL, 0, NULL, 0 } - - -#define TINYRAD_DICT_GETOPT_SHORT "bD:I:" -#define TINYRAD_DICT_GETOPT_LONG \ - { "builtin-dict", no_argument, NULL, 'b' }, \ - - -#define TINYRAD_REQ_GETOPT_SHORT "D:I:" -#define TINYRAD_REQ_GETOPT_LONG \ - { "file", optional_argument, NULL, 'f' }, \ - ////////////////// // // @@ -104,47 +71,6 @@ ////////////////// #pragma mark - Data Types -typedef struct tinyrad_util_config TinyRadUtilConf; -typedef struct tinyrad_util_widget TinyRadUtilWidget; - - -typedef struct my_request_av -{ - char * attr_name; - char * attr_value; -} MyRequestAV; - - -struct tinyrad_util_config -{ - unsigned opts; - unsigned tr_opts; - int padint; - int cmd_argc; - char ** cmd_argv; - const char * cmd_name; - size_t cmd_len; - void * padptr; - const TinyRadUtilWidget * cmd; - TinyRad * tr; - const char * url; - char ** dict_files; - char ** dict_paths; -}; - - -struct tinyrad_util_widget -{ - const char * name; - int (*func)(TinyRadUtilConf * cnf); - const char * shortopts; - struct option * longopts; - int min_arg; - int max_arg; - const char * usage; - const char * desc; -}; - ////////////////// // // @@ -153,46 +79,6 @@ struct tinyrad_util_widget ////////////////// #pragma mark - Prototypes -int -main( - int argc, - char * argv[] ); - - -void -tru_cleanup( - TinyRadUtilConf * cnf ); - - -int -tru_widget_config( - TinyRadUtilConf * cnf ); - - -int -tru_widget_dict( - TinyRadUtilConf * cnf ); - - -int -tru_getopt( - TinyRadUtilConf * cnf, - int argc, - char * const * argv, - const char * short_opt, - const struct option * long_opt, - int * opt_index ); - - -int -tru_load_tinyrad( - TinyRadUtilConf * cnf ); - - -int -tru_usage( - TinyRadUtilConf * cnf ); - ///////////////// // // @@ -202,7 +88,7 @@ tru_usage( #pragma mark - Variables #pragma mark tinyrad_cmdmap[] -static const TinyRadUtilWidget tru_widget_map[] = +const TinyRadUtilWidget tru_widget_map[] = { { .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 @@ +/* + * Tiny RADIUS Client Library + * Copyright (C) 2021 David M. Syzdek . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of David M. Syzdek nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#ifndef _SRC_TINYRADUTIL_TINYRADUTIL_H +#define _SRC_TINYRADUTIL_TINYRADUTIL_H 1 + +/////////////// +// // +// Headers // +// // +/////////////// +#pragma mark - Headers + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/////////////////// +// // +// Definitions // +// // +/////////////////// +#pragma mark - Definitions + +#undef PROGRAM_NAME +#define PROGRAM_NAME "tinyrad" + +#define MY_OPT_DICT_DEFAULTS 0x0001UL +#define MY_OPT_DICT_DUMP 0x0002UL +#define MY_OPT_DICT_LOADED 0x0004UL +#define MY_OPT_CONFIG_PRINT 0x0008UL + + +#define MY_GETOPT_MATCHED -2 +#define MY_GETOPT_ERROR -3 +#define MY_GETOPT_EXIT -4 + + +#define TINYRAD_GETOPT_SHORT "d:f:hqVv" +#define TINYRAD_GETOPT_LONG \ + { "debug", optional_argument, NULL, 'd' }, \ + { "help", no_argument, NULL, 'h' }, \ + { "quiet", no_argument, NULL, 'q' }, \ + { "silent", no_argument, NULL, 'q' }, \ + { "version", no_argument, NULL, 'V' }, \ + { "verbose", no_argument, NULL, 'v' }, \ + { NULL, 0, NULL, 0 } + + +#define TINYRAD_DICT_GETOPT_SHORT "bD:I:" +#define TINYRAD_DICT_GETOPT_LONG \ + { "builtin-dict", no_argument, NULL, 'b' }, \ + + +#define TINYRAD_REQ_GETOPT_SHORT "D:I:" +#define TINYRAD_REQ_GETOPT_LONG \ + { "file", optional_argument, NULL, 'f' }, \ + + +////////////////// +// // +// Data Types // +// // +////////////////// +#pragma mark - Data Types + +typedef struct tinyrad_util_config TinyRadUtilConf; +typedef struct tinyrad_util_widget TinyRadUtilWidget; + + +typedef struct my_request_av +{ + char * attr_name; + char * attr_value; +} MyRequestAV; + + +struct tinyrad_util_config +{ + unsigned opts; + unsigned tr_opts; + int padint; + int cmd_argc; + char ** cmd_argv; + const char * cmd_name; + size_t cmd_len; + void * padptr; + const TinyRadUtilWidget * cmd; + TinyRad * tr; + const char * url; + char ** dict_files; + char ** dict_paths; +}; + + +struct tinyrad_util_widget +{ + const char * name; + int (*func)(TinyRadUtilConf * cnf); + const char * shortopts; + struct option * longopts; + int min_arg; + int max_arg; + const char * usage; + const char * desc; +}; + + +///////////////// +// // +// Variables // +// // +///////////////// +#pragma mark - Variables + +#pragma mark tinyrad_cmdmap[] +extern const TinyRadUtilWidget tru_widget_map[]; + + +////////////////// +// // +// Prototypes // +// // +////////////////// +#pragma mark - Prototypes + +int +main( + int argc, + char * argv[] ); + + +void +tru_cleanup( + TinyRadUtilConf * cnf ); + + +int +tru_widget_config( + TinyRadUtilConf * cnf ); + + +int +tru_widget_dict( + TinyRadUtilConf * cnf ); + + +int +tru_getopt( + TinyRadUtilConf * cnf, + int argc, + char * const * argv, + const char * short_opt, + const struct option * long_opt, + int * opt_index ); + + +int +tru_load_tinyrad( + TinyRadUtilConf * cnf ); + + +int +tru_usage( + TinyRadUtilConf * cnf ); + + +#endif /* end of header */ -- cgit v1.2.3