]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Break out more headers
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 19 Jul 2018 02:53:25 +0000 (22:53 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 19 Jul 2018 02:53:25 +0000 (22:53 -0400)
22 files changed:
src/lib/io/control.c
src/lib/io/master.c
src/lib/io/message.c
src/lib/io/ring_buffer.c
src/lib/io/schedule.c
src/lib/tls/conf.c
src/lib/util/base.h
src/lib/util/fifo.c
src/lib/util/fifo.h [new file with mode: 0644]
src/lib/util/fring.h
src/lib/util/log.c
src/lib/util/log.h
src/lib/util/misc.c
src/lib/util/misc.h [new file with mode: 0644]
src/lib/util/print.c
src/lib/util/print.h [new file with mode: 0644]
src/lib/util/rbtree.c
src/lib/util/snprintf.h
src/lib/util/strerror.h [new file with mode: 0644]
src/lib/util/syserror.h [new file with mode: 0644]
src/lib/util/value.c
src/lib/util/value.h

index a1e42065d3da90f41086461e1145de96418f0fc4..0842e1c72da229c0d244a7ea7d789464940c85ff 100644 (file)
@@ -26,7 +26,8 @@ RCSID("$Id$")
 
 #include <freeradius-devel/io/control.h>
 #include <freeradius-devel/io/ring_buffer.h>
-#include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/strerror.h>
+#include <freeradius-devel/util/syserror.h>
 
 #include <string.h>
 #include <sys/event.h>
index 49a0310ec0ef57ca436a88e7f38c5ef1f70049cc..86a19267e167e7bda8d988c99883479c1ac57eb3 100644 (file)
@@ -27,6 +27,7 @@
 #include <freeradius-devel/server/modules.h>
 #include <freeradius-devel/unlang/base.h>
 #include <freeradius-devel/io/master.h>
+#include <freeradius-devel/util/syserror.h>
 #include <freeradius-devel/server/rad_assert.h>
 
 #define PR_CONNECTION_MAGIC (0x434f4e4e)
index 2b2029134f2cbf1c14c889e23b4bd623105248e1..a5f6b1b302d84ab101d7ca68492b624773ae2016 100644 (file)
@@ -25,7 +25,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/io/message.h>
-#include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/strerror.h>
 
 #include <string.h>
 
index d0bfc9febd8e11c8469917f1d988a470360ffa24..0a4f232718c7be6511ef80074e1eedfd6c38db8f 100644 (file)
@@ -25,7 +25,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/io/ring_buffer.h>
-#include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/strerror.h>
 #include <freeradius-devel/server/rad_assert.h>
 #include <string.h>
 
index a05de82a9d860c9b6f8b4372039c02a5544be7fa..3908866aa35aefa932bf7e3929444c702a90b1fe 100644 (file)
@@ -29,6 +29,7 @@ RCSID("$Id$")
 #include <freeradius-devel/io/schedule.h>
 #include <freeradius-devel/util/dlist.h>
 #include <freeradius-devel/util/rbtree.h>
+#include <freeradius-devel/util/syserror.h>
 
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
index 4f330f5bea66c5d69be3847e2c511b3828a3c249..52cfe2f895bc7e55c0612664c82af9487a6f6666 100644 (file)
@@ -38,6 +38,7 @@ USES_APPLE_DEPRECATED_API     /* OpenSSL API has been deprecated by Apple */
 #include <freeradius-devel/server/base.h>
 #include <freeradius-devel/server/modules.h>
 #include <freeradius-devel/server/rad_assert.h>
+#include <freeradius-devel/util/syserror.h>
 #include <freeradius-devel/tls/base.h>
 
 /** Certificate formats
index d303747f3ac95537cd06b9ea012524da4eb5de52..f0c182c96a5b52d3e60d3ce0ecd11ff3308ad14c 100644 (file)
@@ -50,6 +50,11 @@ RCSIDH(libradius_h, "$Id$")
 #  include <limits.h>
 #endif
 
+#include <freeradius-devel/autoconf.h>
+
+#include <freeradius-devel/util/strerror.h>
+#include <freeradius-devel/util/syserror.h>
+#include <freeradius-devel/util/misc.h>
 #include <freeradius-devel/util/threads.h>
 #include <freeradius-devel/util/inet.h>
 #include <freeradius-devel/util/dict.h>
@@ -58,19 +63,22 @@ RCSIDH(libradius_h, "$Id$")
 #include <freeradius-devel/util/pair_cursor.h>
 
 #include <freeradius-devel/util/packet.h>
-#include <freeradius-devel/radius/defs.h>
-#include <freeradius-devel/radius/radius.h>
 #include <freeradius-devel/util/talloc.h>
 #include <freeradius-devel/util/hash.h>
 #include <freeradius-devel/util/regex.h>
 #include <freeradius-devel/util/proto.h>
+#include <freeradius-devel/util/print.h>
 #include <freeradius-devel/util/conf.h>
-#include <freeradius-devel/autoconf.h>
+
 #include <freeradius-devel/util/rbtree.h>
 #include <freeradius-devel/util/log.h>
 #include <freeradius-devel/util/version.h>
 #include <freeradius-devel/util/value.h>
 #include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/fifo.h>
+
+#include <freeradius-devel/radius/defs.h>
+#include <freeradius-devel/radius/radius.h>
 
 #ifdef SIZEOF_UNSIGNED_INT
 #  if SIZEOF_UNSIGNED_INT != 4
@@ -96,56 +104,10 @@ typedef void (*sig_t)(int);
 #  define FREE_MAGIC (0xF4EEF4EE)
 #endif
 
-/*
- *     Printing functions.
- */
-size_t         fr_utf8_char(uint8_t const *str, ssize_t inlen);
-ssize_t                fr_utf8_str(uint8_t const *str, ssize_t inlen);
-char const             *fr_utf8_strchr(int *chr_len, char const *str, char const *chr);
-size_t         fr_snprint(char *out, size_t outlen, char const *in, ssize_t inlen, char quote);
-size_t         fr_snprint_len(char const *in, ssize_t inlen, char quote);
-char           *fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote);
-char           *fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap);
-char           *fr_asprintf(TALLOC_CTX *ctx, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
-
-#define                is_truncated(_ret, _max) ((_ret) >= (size_t)(_max))
-#define                truncate_len(_ret, _max) (((_ret) >= (size_t)(_max)) ? (((size_t)(_max)) - 1) : _ret)
-
-/** Boilerplate for checking truncation
- *
- * If truncation has occurred, advance _p as far as possible without
- * overrunning the output buffer, and \0 terminate.  Then return the length
- * of the buffer we would have needed to write the full value.
- *
- * If truncation has not occurred, advance _p by whatever the copy or print
- * function returned.
- */
-#define RETURN_IF_TRUNCATED(_p, _ret, _max) \
-do { \
-       if (is_truncated(_ret, _max)) { \
-               size_t _r = (_p - out) + _ret; \
-               _p += truncate_len(_ret, _max); \
-               *_p = '\0'; \
-               return _r; \
-       } \
-       _p += _ret; \
-} while (0)
-
 /*
  *     Several handy miscellaneous functions.
  */
-int            fr_set_signal(int sig, sig_t func);
-int            fr_talloc_link_ctx(TALLOC_CTX *parent, TALLOC_CTX *child);
-int            fr_unset_signal(int sig);
-int            rad_lockfd(int fd, int lock_len);
-int            rad_lockfd_nonblock(int fd, int lock_len);
-int            rad_unlockfd(int fd, int lock_len);
-char           *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen);
-size_t         fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
-size_t         fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
-uint64_t       fr_strtoull(char const *value, char **end);
-int64_t                fr_strtoll(char const *value, char **end);
-char           *fr_trim(char const *str, size_t size);
+
 
 /** Check whether the string is all whitespace
  *
@@ -216,31 +178,6 @@ static inline bool is_zero(char const *value)
        return true;
 }
 
-int            fr_nonblock(int fd);
-int            fr_blocking(int fd);
-ssize_t                fr_writev(int fd, struct iovec[], int iovcnt, struct timeval *timeout);
-
-ssize_t                fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen);
-size_t         fr_snprint_uint128(char *out, size_t outlen, uint128_t const num);
-int            fr_time_from_str(time_t *date, char const *date_str);
-void           fr_timeval_from_ms(struct timeval *out, uint64_t ms);
-void           fr_timeval_from_usec(struct timeval *out, uint64_t usec);
-void           fr_timeval_subtract(struct timeval *out, struct timeval const *end, struct timeval const *start);
-void           fr_timeval_add(struct timeval *out, struct timeval const *a, struct timeval const *b);
-void           fr_timeval_divide(struct timeval *out, struct timeval const *in, int divisor);
-
-int            fr_timeval_cmp(struct timeval const *a, struct timeval const *b);
-int            fr_timeval_from_str(struct timeval *out, char const *in);
-bool           fr_timeval_isset(struct timeval const *tv);
-
-void           fr_timespec_subtract(struct timespec *out, struct timespec const *end, struct timespec const *start);
-
-bool           fr_multiply(uint64_t *result, uint64_t lhs, uint64_t rhs);
-int            fr_size_from_str(size_t *out, char const *str);
-int8_t         fr_pointer_cmp(void const *a, void const *b);
-void           fr_quick_sort(void const *to_sort[], int min_idx, int max_idx, fr_cmp_t cmp);
-int            fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length) CC_HINT(nonnull);
-
 /*
  *     Define TALLOC_DEBUG to check overflows with talloc.
  *     we can't use valgrind, because the memory used by
@@ -282,49 +219,6 @@ void               fr_rand_seed(void const *, size_t ); /* seed the random pool */
 /* crypt wrapper from crypt.c */
 int            fr_crypt_check(char const *password, char const *reference_crypt);
 
-/*
- *     FIFOs
- */
-typedef struct fr_fifo_t fr_fifo_t;
-typedef void (*fr_fifo_free_t)(void *);
-
-/** Creates a fifo that verifies elements are of a specific talloc type
- *
- * @param[in] _ctx             to tie fifo lifetime to.
- *                             If ctx is freed, fifo will free any nodes, calling the
- *                             free function if set.
- * @param[in] _max_entries     Maximum number of entries.
- * @param[in] _talloc_type     of elements.
- * @param[in] _node_free       Optional function used to free data if tree nodes are
- *                             deleted or replaced.
- * @return
- *     - A new fifo on success.
- *     - NULL on failure.
- */
-#define fr_fifo_talloc_create(_ctx, _talloc_type, _max_entries, _node_free) \
-       _fr_fifo_create(_ctx, #_talloc_type, _max_entries, _node_free)
-
-/** Creates a fifo
- *
- * @param[in] _ctx             to tie fifo lifetime to.
- *                             If ctx is freed, fifo will free any nodes, calling the
- *                             free function if set.
- * @param[in] _max_entries     Maximum number of entries.
- * @param[in] _node_free       Optional function used to free data if tree nodes are
- *                             deleted or replaced.
- * @return
- *     - A new fifo on success.
- *     - NULL on failure.
- */
-#define fr_fifo_create(_ctx, _max_entries, _node_free) \
-       _fr_fifo_create(_ctx, NULL, _max_entries, _node_free)
-
-fr_fifo_t      *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max_entries, fr_fifo_free_t free_node);
-int            fr_fifo_push(fr_fifo_t *fi, void *data);
-void           *fr_fifo_pop(fr_fifo_t *fi);
-void           *fr_fifo_peek(fr_fifo_t *fi);
-unsigned int   fr_fifo_num_elements(fr_fifo_t *fi);
-
 /*
  *     socket.c
  */
index cddc875fa7ce2aa811eafee7cf4d23d72a215794..fbc926e3867becb75c1ad7289a037cf3fbfe2caf 100644 (file)
  */
 RCSID("$Id$")
 
-#include <freeradius-devel/util/base.h>
+#include <string.h>
+#include <talloc.h>
+
+#include "fifo.h"
 
 struct fr_fifo_t {
        unsigned int    num;            //!< How many elements exist in the fifo.
diff --git a/src/lib/util/fifo.h b/src/lib/util/fifo.h
new file mode 100644 (file)
index 0000000..33587aa
--- /dev/null
@@ -0,0 +1,67 @@
+#pragma once
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Non-thread-safe fifo (FIFO) implementation
+ *
+ * @file src/lib/util/fifo.c
+ *
+ * @copyright 2005,2006  The FreeRADIUS server project
+ * @copyright 2005  Alan DeKok <aland@ox.org>
+ */
+RCSIDH(fifo_h, "$Id$")
+
+#include <talloc.h>
+
+typedef struct fr_fifo_t fr_fifo_t;
+typedef void (*fr_fifo_free_t)(void *);
+
+/** Creates a fifo that verifies elements are of a specific talloc type
+ *
+ * @param[in] _ctx             to tie fifo lifetime to.
+ *                             If ctx is freed, fifo will free any nodes, calling the
+ *                             free function if set.
+ * @param[in] _max_entries     Maximum number of entries.
+ * @param[in] _talloc_type     of elements.
+ * @param[in] _node_free       Optional function used to free data if tree nodes are
+ *                             deleted or replaced.
+ * @return
+ *     - A new fifo on success.
+ *     - NULL on failure.
+ */
+#define fr_fifo_talloc_create(_ctx, _talloc_type, _max_entries, _node_free) \
+       _fr_fifo_create(_ctx, #_talloc_type, _max_entries, _node_free)
+
+/** Creates a fifo
+ *
+ * @param[in] _ctx             to tie fifo lifetime to.
+ *                             If ctx is freed, fifo will free any nodes, calling the
+ *                             free function if set.
+ * @param[in] _max_entries     Maximum number of entries.
+ * @param[in] _node_free       Optional function used to free data if tree nodes are
+ *                             deleted or replaced.
+ * @return
+ *     - A new fifo on success.
+ *     - NULL on failure.
+ */
+#define fr_fifo_create(_ctx, _max_entries, _node_free) \
+       _fr_fifo_create(_ctx, NULL, _max_entries, _node_free)
+
+fr_fifo_t      *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max_entries, fr_fifo_free_t free_node);
+int            fr_fifo_push(fr_fifo_t *fi, void *data);
+void           *fr_fifo_pop(fr_fifo_t *fi);
+void           *fr_fifo_peek(fr_fifo_t *fi);
+unsigned int   fr_fifo_num_elements(fr_fifo_t *fi);
index 569498ad6a7237eb497fc37a780df443a59762c5..1414230b7e2ae65432b3a1e2b1fec402a25a12d1 100644 (file)
@@ -21,6 +21,8 @@
  *
  * @copyright 2015-2017 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
  */
+RCSIDH(fring_h, "$Id$")
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <talloc.h>
index 30c2830b07a6dcf0f49500c889556b5c5069580f..590d0af968f1005d1d993f800f20a1dbe833fa54 100644 (file)
@@ -37,7 +37,8 @@ RCSID("$Id$")
 
 #include <fcntl.h>
 
-FILE *fr_log_fp = NULL;
+FILE   *fr_log_fp = NULL;
+int    fr_debug_lvl = 0;
 
 /** Canonicalize error strings, removing tabs, and generate spaces for error marker
  *
index 042bec6fb6a1d985a395dffe2719e5deadf39b48..5e2cdd8bb845857023ff9c24d86911f23acc2f3f 100644 (file)
@@ -32,19 +32,8 @@ extern FILE  *fr_log_fp;
  *     Error functions.
  */
 void           fr_printf_log(char const *, ...) CC_HINT(format (printf, 1, 2));
-
-void           fr_strerror_printf(char const *, ...) CC_HINT(format (printf, 1, 2));
-void           fr_strerror_printf_push(char const *fmt, ...)  CC_HINT(format (printf, 1, 2));
-
-char const     *fr_strerror(void);
-char const     *fr_strerror_peek(void);
-char const     *fr_strerror_pop(void);
-
-void           fr_perror(char const *, ...) CC_HINT(format (printf, 1, 2));
-void           fr_strerror_free(void);
 void           fr_canonicalize_error(TALLOC_CTX *ctx, char **spaces, char **text, ssize_t slen, char const *msg);
 
-char const     *fr_syserror(int num);
 extern bool    fr_reverse_lookups;     /* do IP -> hostname lookups? */
 extern bool    fr_hostname_lookups; /* do hostname -> IP lookups? */
 extern int     fr_debug_lvl;   /* 0 = no debugging information */
index 4e9ccf0dc83d3c9f10fd2afc44428d3c8fcfc926..275129b13d115f92feffb2abb6053abc2ebc1e83 100644 (file)
@@ -22,7 +22,7 @@
  */
 RCSID("$Id$")
 
-#include <freeradius-devel/util/base.h>
+#include "misc.h"
 
 #include <ctype.h>
 #include <sys/file.h>
@@ -30,10 +30,17 @@ RCSID("$Id$")
 #include <grp.h>
 #include <pwd.h>
 #include <sys/uio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
 
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
+#include <freeradius-devel/util/syserror.h>
+#include <freeradius-devel/util/strerror.h>
+#include <freeradius-devel/util/debug.h>
 
+#ifdef HAVE_DIRENT_H
+#  include <dirent.h>
 /*
  *     Some versions of Linux don't have closefrom(), but they will
  *     have /proc.
@@ -43,15 +50,15 @@ RCSID("$Id$")
  *     OSX doesn't have closefrom() or /proc/self/fd, but it does
  *     have /dev/fd
  */
-#ifdef __linux__
-#define CLOSEFROM_DIR "/proc/self/fd"
-#elif defined(__APPLE__)
-#define CLOSEFROM_DIR "/dev/fd"
-#else
-#undef HAVE_DIRENT_H
+#  ifdef __linux__
+#    define CLOSEFROM_DIR "/proc/self/fd"
+#  elif defined(__APPLE__)
+#    define CLOSEFROM_DIR "/dev/fd"
+#  else
+#    undef HAVE_DIRENT_H
+#  endif
 #endif
 
-#endif
 
 #define FR_PUT_LE16(a, val)\
        do {\
@@ -59,8 +66,6 @@ RCSID("$Id$")
                a[0] = ((uint16_t) (val)) & 0xff;\
        } while (0)
 
-int    fr_debug_lvl = 0;
-
 static char const *months[] = {
        "jan", "feb", "mar", "apr", "may", "jun",
        "jul", "aug", "sep", "oct", "nov", "dec" };
diff --git a/src/lib/util/misc.h b/src/lib/util/misc.h
new file mode 100644 (file)
index 0000000..08f3a15
--- /dev/null
@@ -0,0 +1,69 @@
+#pragma once
+/*
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Various miscellaneous utility functions
+ *
+ * @file src/lib/util/misc.h
+ *
+ * @copyright 2000,2006  The FreeRADIUS server project
+ */
+RCSIDH(misc_h, "$Id$")
+
+#include <talloc.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <freeradius-devel/missing.h>
+
+typedef                int8_t (*fr_cmp_t)(void const *a, void const *b);
+
+int            fr_set_signal(int sig, sig_t func);
+int            fr_talloc_link_ctx(TALLOC_CTX *parent, TALLOC_CTX *child);
+int            fr_unset_signal(int sig);
+int            rad_lockfd(int fd, int lock_len);
+int            rad_lockfd_nonblock(int fd, int lock_len);
+int            rad_unlockfd(int fd, int lock_len);
+char           *fr_abin2hex(TALLOC_CTX *ctx, uint8_t const *bin, size_t inlen);
+size_t         fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
+size_t         fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
+uint64_t       fr_strtoull(char const *value, char **end);
+int64_t                fr_strtoll(char const *value, char **end);
+char           *fr_trim(char const *str, size_t size);
+
+int            fr_nonblock(int fd);
+int            fr_blocking(int fd);
+
+ssize_t                fr_writev(int fd, struct iovec vector[], int iovcnt, struct timeval *timeout);
+ssize_t                fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen);
+size_t         fr_snprint_uint128(char *out, size_t outlen, uint128_t const num);
+int            fr_time_from_str(time_t *date, char const *date_str);
+void           fr_timeval_from_ms(struct timeval *out, uint64_t ms);
+void           fr_timeval_from_usec(struct timeval *out, uint64_t usec);
+void           fr_timeval_subtract(struct timeval *out, struct timeval const *end, struct timeval const *start);
+void           fr_timeval_add(struct timeval *out, struct timeval const *a, struct timeval const *b);
+void           fr_timeval_divide(struct timeval *out, struct timeval const *in, int divisor);
+
+int            fr_timeval_cmp(struct timeval const *a, struct timeval const *b);
+int            fr_timeval_from_str(struct timeval *out, char const *in);
+bool           fr_timeval_isset(struct timeval const *tv);
+
+void           fr_timespec_subtract(struct timespec *out, struct timespec const *end, struct timespec const *start);
+
+bool           fr_multiply(uint64_t *result, uint64_t lhs, uint64_t rhs);
+int            fr_size_from_str(size_t *out, char const *str);
+int8_t         fr_pointer_cmp(void const *a, void const *b);
+void           fr_quick_sort(void const *to_sort[], int min_idx, int max_idx, fr_cmp_t cmp);
+int            fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length) CC_HINT(nonnull);
index 7eace77c503827e5f803ad1f5ed722a06897a60f..daf84cc69f14c70514c9a404d0624e21b3db7200 100644 (file)
  */
 RCSID("$Id$")
 
-#include       <freeradius-devel/util/base.h>
-#include       <ctype.h>
+#include "print.h"
+
+#include <ctype.h>
+#include <string.h>
+#include <talloc.h>
+
+#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/pair.h>
+#include <freeradius-devel/util/talloc.h>
+#include <freeradius-devel/util/misc.h>
+#include <freeradius-devel/util/strerror.h>
 
 /** Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8
  *
diff --git a/src/lib/util/print.h b/src/lib/util/print.h
new file mode 100644 (file)
index 0000000..3574144
--- /dev/null
@@ -0,0 +1,58 @@
+#pragma once
+/*
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Functions to produce and parse the FreeRADIUS presentation format
+ *
+ * @file src/lib/util/print.h
+ *
+ * @copyright 2000,2006  The FreeRADIUS server project
+ */
+RCSIDH(print_h, "$Id$")
+
+#include <talloc.h>
+
+size_t         fr_utf8_char(uint8_t const *str, ssize_t inlen);
+ssize_t                fr_utf8_str(uint8_t const *str, ssize_t inlen);
+char const             *fr_utf8_strchr(int *chr_len, char const *str, char const *chr);
+size_t         fr_snprint(char *out, size_t outlen, char const *in, ssize_t inlen, char quote);
+size_t         fr_snprint_len(char const *in, ssize_t inlen, char quote);
+char           *fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote);
+char           *fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap);
+char           *fr_asprintf(TALLOC_CTX *ctx, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
+
+#define                is_truncated(_ret, _max) ((_ret) >= (size_t)(_max))
+#define                truncate_len(_ret, _max) (((_ret) >= (size_t)(_max)) ? (((size_t)(_max)) - 1) : _ret)
+
+/** Boilerplate for checking truncation
+ *
+ * If truncation has occurred, advance _p as far as possible without
+ * overrunning the output buffer, and \0 terminate.  Then return the length
+ * of the buffer we would have needed to write the full value.
+ *
+ * If truncation has not occurred, advance _p by whatever the copy or print
+ * function returned.
+ */
+#define RETURN_IF_TRUNCATED(_p, _ret, _max) \
+do { \
+       if (is_truncated(_ret, _max)) { \
+               size_t _r = (_p - out) + _ret; \
+               _p += truncate_len(_ret, _max); \
+               *_p = '\0'; \
+               return _r; \
+       } \
+       _p += _ret; \
+} while (0)
index 8cbb26e1a5eafac771b533e49f9fcdcb9788472d..42a15d2141d97c5622acb93a04242be0e2226774 100644 (file)
  */
 RCSID("$Id$")
 
-#include <freeradius-devel/util/rbtree.h>
+#include "rbtree.h"
+
 #include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/strerror.h>
+
 #include <pthread.h>
 
 /* Red-Black tree description */
index 2ac0a964986a9524ed2f1ab56b4ee5f7ec2f72b8..8e9cafb2843a50d49f365c30fd6c11106a0876e9 100644 (file)
@@ -1,3 +1,4 @@
+#pragma once
 /*
  *   This program is is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
diff --git a/src/lib/util/strerror.h b/src/lib/util/strerror.h
new file mode 100644 (file)
index 0000000..118c787
--- /dev/null
@@ -0,0 +1,35 @@
+#pragma once
+/*
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Support functions to allow libraries to provide errors to their callers
+ *
+ * @file src/lib/util/strerror.h
+ *
+ * @copyright 2017 The FreeRADIUS server project
+ * @copyright 2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+RCSIDH(strerror_h, "$Id$")
+
+void           fr_strerror_printf(char const *, ...) CC_HINT(format (printf, 1, 2));
+void           fr_strerror_printf_push(char const *fmt, ...)  CC_HINT(format (printf, 1, 2));
+
+char const     *fr_strerror(void);
+char const     *fr_strerror_peek(void);
+char const     *fr_strerror_pop(void);
+
+void           fr_perror(char const *, ...) CC_HINT(format (printf, 1, 2));
+void           fr_strerror_free(void);
diff --git a/src/lib/util/syserror.h b/src/lib/util/syserror.h
new file mode 100644 (file)
index 0000000..e4c5483
--- /dev/null
@@ -0,0 +1,27 @@
+#pragma once
+/*
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Support functions to allow libraries to get system errors in a threadsafe and easily debuggable way
+ *
+ * @file src/lib/util/syserror.c
+ *
+ * @copyright 2017 The FreeRADIUS server project
+ * @copyright 2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+RCSIDH(syserror_h, "$Id$")
+
+char const     *fr_syserror(int num);
index 4545c75279ac6d477be4d7ea2509845eeb944704..97c0bf299177cfed79b6d8c15b6c6f8b5d399115 100644 (file)
@@ -45,6 +45,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/util/base.h>
+#include <freeradius-devel/util/strerror.h>
 #include <freeradius-devel/server/rad_assert.h>
 #include <ctype.h>
 
index 31ae26da0d0d4d56dab9e7566822b3033e51317a..fd01a05b88dcc59c47d6d2482ccc0100c1e07f38 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 #include <freeradius-devel/util/types.h>
 #include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/strerror.h>
 
 /*
  *     Avoid circular type references.