aboutsummaryrefslogtreecommitdiffstats
path: root/src/visibility.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-11-17 08:37:54 +0000
committerWerner Koch <[email protected]>2017-11-17 08:48:30 +0000
commit1b653e7f37e2eb2a8f590a43651eb8aecbe8756e (patch)
tree07981a1260494dc7a94e3e266743fb58070416a2 /src/visibility.c
parentNew configure options and macros for internal use. (diff)
downloadlibgpg-error-1b653e7f37e2eb2a8f590a43651eb8aecbe8756e.tar.gz
libgpg-error-1b653e7f37e2eb2a8f590a43651eb8aecbe8756e.zip
core: Add logging API.
* src/visibility.c (gpgrt_get_errorcount): New API. (gpgrt_inc_errorcount): New API. (gpgrt_log_set_sink): New API. (gpgrt_log_set_socket_dir_cb): New API. (gpgrt_log_set_pid_suffix_cb): New API. (gpgrt_log_set_prefix): New API. (gpgrt_log_get_prefix): New API. (gpgrt_log_test_fd): New API. (gpgrt_log_get_fd): New API. (gpgrt_log_get_stream): New API. (gpgrt_log): New API. (gpgrt_logv): New API. (gpgrt_logv_prefix): New API. (gpgrt_log_string): New API. (gpgrt_log_info): New API. (gpgrt_log_error): New API. (gpgrt_log_fatal): New API. (gpgrt_log_bug): New API. (gpgrt_log_debug): New API. (gpgrt_log_debug_string): New API. (gpgrt_log_printf): New API. (gpgrt_log_flush): New API. (gpgrt_log_printhex): New API. (gpgrt_log_clock): New API. (_gpgrt_log_assert): New function for the ABI. * src/visibility.h: Add corresponding macros. * src/gpg-error.def.in: Add new functions. * src/gpg-error.vers: Add new functions. * src/gpg-error.h.in (GPGRT_LOG_WITH_PREFIX): New constant. (GPGRT_LOG_WITH_TIME): New constant. (GPGRT_LOG_WITH_PID): New constant. (GPGRT_LOG_RUN_DETACHED): New constant. (GPGRT_LOG_NO_REGISTRY): New constant. (GPGRT_LOG_BEGIN): New enum value. (GPGRT_LOG_CONT): New enum value. (GPGRT_LOG_INFO): New enum value. (GPGRT_LOG_WARN): New enum value. (GPGRT_LOG_ERROR): New enum value. (GPGRT_LOG_FATAL): New enum value. (GPGRT_LOG_BUG): New enum value. (GPGRT_LOG_DEBUG): New enum value. (log_get_errorcount, log_inc_errorcount, log_set_file, log_set_fd) (log_set_stream, log_set_socket_dir_cb, log_set_pid_suffix_cb) (log_set_prefix, log_get_prefix, log_test_fd, log_get_fd) (log_get_stream, log_log, log_logv, log_logv_prefix, log_string) (log_bug, log_fatal, log_error, log_info, log_debug, log_debug_string) (log_printf, log_printhex, log_clock) (log_flush) [GPGRT_ENABLE_LOG_MACROS]: New wrapper macros. (gpgrt_assert): New macro. * src/gpgrt-int.h: Add prototypes for logging.c. (gpgrt_assert): Redefine for internal use. * src/logging.h: Remove. * src/logging.c: Include gpgrt-int.h instead of the stuff from GnuPG. Use _gpgrt malloc funcsions and the internal versions of the estream functions. Rename all public fucntions with a _gpgrt_ prefix. (print_prefix): Return the printed length. (_gpgrt_logv_internal): Ditto. (_gpgrt_log_printhex): Change order of args and turn into a printf like function. (_gpgrt_logv_printhex): New. Take the core of the former log_printhex. (_gpgrt_log_clock): Turn into a printf like functions. (_gpgrt_logv_clock): New. Take the core of the former log_clock. -- This logging API is a slightly modified version of what we are using in GnuPG. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/visibility.c')
-rw-r--r--src/visibility.c204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/visibility.c b/src/visibility.c
index b637e7a..569c3e6 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -15,10 +15,12 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier: LGPL-2.1+
*/
#include <config.h>
#include <stdarg.h>
+#include <stdlib.h> /* For abort(). */
#define _GPGRT_INCL_BY_VISIBILITY_C 1
#include "gpgrt-int.h"
@@ -712,6 +714,8 @@ gpgrt_vsnprintf (char *buf, size_t bufsize,
return _gpgrt_estream_vsnprintf (buf, bufsize, format, arg_ptr);
}
+
+
gpgrt_b64state_t
gpgrt_b64dec_start (const char *title)
{
@@ -730,3 +734,203 @@ gpgrt_b64dec_finish (gpgrt_b64state_t state)
{
return _gpgrt_b64dec_finish (state);
}
+
+
+
+int
+gpgrt_get_errorcount (int clear)
+{
+ return _gpgrt_get_errorcount (clear);
+}
+
+void
+gpgrt_inc_errorcount (void)
+{
+ _gpgrt_inc_errorcount ();
+}
+
+void
+gpgrt_log_set_sink (const char *name, estream_t stream, int fd)
+{
+ _gpgrt_log_set_sink (name, stream, fd);
+}
+
+void
+gpgrt_log_set_socket_dir_cb (const char *(*fnc)(void))
+{
+ _gpgrt_log_set_socket_dir_cb (fnc);
+}
+
+void
+gpgrt_log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value))
+{
+ _gpgrt_log_set_pid_suffix_cb (cb);
+}
+
+void
+gpgrt_log_set_prefix (const char *text, unsigned int flags)
+{
+ _gpgrt_log_set_prefix (text, flags);
+}
+
+const char *
+gpgrt_log_get_prefix (unsigned int *flags)
+{
+ return _gpgrt_log_get_prefix (flags);
+}
+
+int
+gpgrt_log_test_fd (int fd)
+{
+ return _gpgrt_log_test_fd (fd);
+}
+
+int
+gpgrt_log_get_fd (void)
+{
+ return _gpgrt_log_get_fd ();
+}
+
+estream_t
+gpgrt_log_get_stream (void)
+{
+ return _gpgrt_log_get_stream ();
+}
+
+void
+gpgrt_log (int level, const char *fmt, ...)
+{
+ va_list arg_ptr ;
+
+ va_start (arg_ptr, fmt) ;
+ _gpgrt_logv (level, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_logv (int level, const char *fmt, va_list arg_ptr)
+{
+ _gpgrt_logv (level, fmt, arg_ptr);
+}
+
+void
+gpgrt_logv_prefix (int level, const char *prefix,
+ const char *fmt, va_list arg_ptr)
+{
+ _gpgrt_logv_prefix (level, prefix, fmt, arg_ptr);
+}
+
+void
+gpgrt_log_string (int level, const char *string)
+{
+ _gpgrt_log_string (level, string);
+}
+
+void
+gpgrt_log_info (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (GPGRT_LOG_INFO, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_error (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (GPGRT_LOG_ERROR, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_fatal (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (GPGRT_LOG_FATAL, fmt, arg_ptr);
+ va_end (arg_ptr);
+ abort (); /* Never called; just to make the compiler happy. */
+}
+
+void
+gpgrt_log_bug (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (GPGRT_LOG_BUG, fmt, arg_ptr);
+ va_end (arg_ptr);
+ abort (); /* Never called; just to make the compiler happy. */
+}
+
+void
+gpgrt_log_debug (const char *fmt, ...)
+{
+ va_list arg_ptr ;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (GPGRT_LOG_DEBUG, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_debug_string (const char *string, const char *fmt, ...)
+{
+ va_list arg_ptr ;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv_internal (GPGRT_LOG_DEBUG, 0, string, NULL, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_printf (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv (fmt ? GPGRT_LOG_CONT : GPGRT_LOG_BEGIN, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_flush (void)
+{
+ _gpgrt_log_flush ();
+}
+
+void
+gpgrt_log_printhex (const void *buffer, size_t length, const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv_printhex (buffer, length, fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+gpgrt_log_clock (const char *fmt, ...)
+{
+ va_list arg_ptr;
+
+ va_start (arg_ptr, fmt);
+ _gpgrt_logv_clock (fmt, arg_ptr);
+ va_end (arg_ptr);
+}
+
+void
+_gpgrt_log_assert (const char *expr, const char *file,
+ int line, const char *func)
+{
+#ifdef GPGRT_HAVE_MACRO_FUNCTION
+ _gpgrt__log_assert (expr, file, line, func);
+#else
+ _gpgrt__log_assert (expr, file, line);
+#endif
+}