Core: move logging function and macros to their own module, adapt perl binding

This commit is contained in:
Benjamin Dauvergne 2010-06-12 00:43:49 +00:00
parent c4ac4f652c
commit a9b673cd4a
10 changed files with 232 additions and 95 deletions

View File

@ -141,10 +141,31 @@ GHashTable*\tT_PTRREF
#include "XSUB.h"
#include <stdio.h>
#if defined(__GNUC__)
# define lasso_log(level, filename, line, function, format, args...) \
g_log("Lasso", level, "%s:%i:%s" format, filename, line, function, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define lasso_log(level, format, line, function, ...) \
g_log("Lasso", leve, "%s:%i:%s" format, filename, line, function, __VA_ARGS__)
#else
static inline void lasso_log(GLogLevelFlags level, const char *filename,
int line, const char *function, const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
g_log("Lasso", level, "%s:%i:%s %s", filename, line, function, s);
}
#define lasso_log lasso_log
#endif
#include "./gobject_handling.c"
#include "./glist_handling.c"
#include "./ghashtable_handling.c"
#define lasso_assign_simple(a,b) a = b;
typedef char* string_non_null;

View File

@ -20,10 +20,10 @@ lib_LTLIBRARIES = liblasso.la
liblassoinclude_HEADERS = export.h lasso.h lasso_config.h errors.h \
registry.h
nodist_liblassoinclude_HEADERS = debug.h utils.h registry-private.h
nodist_liblassoinclude_HEADERS = debug.h utils.h registry-private.h logging.h backward_comp.h
BUILT_SOURCES = types.c errors.c symbols.sym
liblasso_la_SOURCES = lasso.c errors.c registry.c utils.c debug.h
liblasso_la_SOURCES = lasso.c errors.c registry.c utils.c logging.c
if WSF_ENABLED
SYMBOLS_ARGS = -wsf
@ -42,8 +42,8 @@ MAINTAINERCLEANFILES = \
clean-local:
-rm -f types.c symbols.sym errors.c
EXTRA_DIST = utils.h extract_types.py extract_symbols.py build_strerror.py \
registry-private.h errors.c.in backward_comp.h extract_sections.py
EXTRA_DIST = $(nodist_liblassoinclude_HEADERS) extract_types.py extract_symbols.py build_strerror.py \
errors.c.in extract_sections.py
if WSF_ENABLED
WSF_LIB_FILE = $(top_builddir)/lasso/id-wsf/liblasso-id-wsf.la

View File

@ -28,6 +28,7 @@
*
**/
#include "../utils.h"
#include "../xml/private.h"
#include "name_identifier_mapping.h"

View File

@ -75,12 +75,13 @@
#include <xmlsec/crypto.h>
#include <libxslt/xslt.h>
#include <config.h>
#include "lasso.h"
#include "lasso_config.h"
#include "debug.h"
#include "backward_comp.h"
#include "registry-private.h"
#include "xml/private.h"
#include "./lasso.h"
#include "./lasso_config.h"
#include "./debug.h"
#include "./backward_comp.h"
#include "./registry-private.h"
#include "./xml/private.h"
#include "./utils.h"
/* Set to true, it forces lasso_provider_verify_signature and lasso_query_verify_signature to always
* return TRUE. */

View File

@ -2,4 +2,4 @@
/* Define if ID-WSF support is enabled */
#undef LASSO_WSF_ENABLED
#define LASSO_LOG_DOMAIN "Lasso"

67
lasso/logging.c Normal file
View File

@ -0,0 +1,67 @@
/* $Id$
*
* Lasso - A free implementation of the Liberty Alliance specifications.
*
* Copyright (C) 2004-2007 Entr'ouvert
* http://lasso.entrouvert.org
*
* Authors: See AUTHORS file in top-level directory.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "./logging.h"
#include "./lasso_config.h"
#include <glib.h>
void
lasso_log(GLogLevelFlags level, const char *filename, int line,
const char *function, const char *format, ...)
{
char debug_string[1024];
time_t ts;
char date[20];
va_list args;
va_start(args, format);
g_vsnprintf(debug_string, 1024, format, args);
va_end(args);
time(&ts);
strftime(date, 20, "%Y-%m-%d %H:%M:%S", localtime(&ts));
if (level == G_LOG_LEVEL_DEBUG || level == G_LOG_LEVEL_CRITICAL) {
g_log(LASSO_LOG_DOMAIN, level, "%s (%s/%s:%d) %s",
date, filename, function, line, debug_string);
} else {
g_log(LASSO_LOG_DOMAIN, level, "%s\t%s", date, debug_string);
}
}
int
lasso_log_error_code(G_GNUC_UNUSED GLogLevelFlags level, int error, ...)
{
const char *format;
char message[1024];
va_list args;
format = lasso_strerror(error);
va_start(args, error);
g_vsnprintf(message, 1024, format, args);
va_end(args);
return error;
}

130
lasso/logging.h Normal file
View File

@ -0,0 +1,130 @@
/* $Id$
*
* Lasso - A free implementation of the Liberty Alliance specifications.
*
* Copyright (C) 2004-2007 Entr'ouvert
* http://lasso.entrouvert.org
*
* Authors: See AUTHORS file in top-level directory.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LASSO_LOGGING_H__
#define __LASSO_LOGGING_H__ 1
#include <glib.h>
#include "./errors.h"
#ifndef lasso_log
void lasso_log(GLogLevelFlags level, const char *filename, int line,
const char *function, const char *format, ...);
#endif
int lasso_log_error_code(GLogLevelFlags level, int error, ...);
#ifndef __FUNCTION__
# define __FUNCTION__ ""
#endif
#if defined(__GNUC__)
# define message(level, format, args...) \
lasso_log(level, __FILE__, __LINE__, __FUNCTION__, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define message(level, ...) \
lasso_log(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
static inline void message(GLogLevelFlags level, const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
lasso_log(level, __FILE__, __LINE__, __FUNCTION__, s);
}
#endif
/* debug logging */
#if defined(LASSO_DEBUG)
#if defined(__GNUC__)
#define debug(format, args...) \
message(G_LOG_LEVEL_DEBUG, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
#define debug(...) message(G_LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
static inline void debug(const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
message(G_LOG_LEVEL_DEBUG, "%s", s);
}
#endif
#else
#if defined(__GNUC__)
# define debug(format, args...) ;
#elif defined(HAVE_VARIADIC_MACROS)
# define debug(...) ;
#else
static inline void debug(const char *format, ...)
{
va_list ap;
va_start(ap, format);
va_end(ap);
}
#endif
#endif
#if defined(__GNUC__)
# define warning(format, args...) \
message(G_LOG_LEVEL_DEBUG, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define warning(...) message(G_LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
static inline void warning(const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
message(G_LOG_LEVEL_WARNING, "%s", s);
}
#endif
#if defined(__GNUC__)
# define critical(format, args...) \
message(G_LOG_LEVEL_DEBUG, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define critical(...) message(G_LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
static inline void critical(const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
message(G_LOG_LEVEL_CRITICAL, "%s", s);
}
#endif
#define critical_error(rc) (critical("%s", lasso_strerror(rc)), rc)
#endif /* __LASSO_LOGGING_H_ */

View File

@ -32,6 +32,7 @@
#include "./backward_comp.h"
#include "./xml/private.h"
#include "./xml/tools.h"
#include "./logging.h"
#ifdef LASSO_DEBUG
#ifdef __GNUC__

View File

@ -171,52 +171,9 @@ xmlNode* lasso_xml_get_soap_content(xmlNode *root);
gboolean lasso_xml_is_soap(xmlNode *root);
void _debug(GLogLevelFlags level, const char *filename, int line,
const char *function, const char *format, ...);
int error_code(GLogLevelFlags level, int error, ...);
gboolean lasso_eval_xpath_expression(xmlXPathContextPtr xpath_ctx, const char *expression,
xmlXPathObjectPtr *xpath_object_ptr, int *xpath_error_code);
#if defined(LASSO_DEBUG) && defined(__GNUC__)
# define debug(format, args...) \
_debug(G_LOG_LEVEL_DEBUG, __FILE__, __LINE__,__FUNCTION__, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define debug(...) ;
#else
static inline void debug(const char *format, ...)
{
va_list ap;
va_start(ap, format);
va_end(ap);
}
#endif
#ifndef __FUNCTION__
# define __FUNCTION__ ""
#endif
#if defined(__GNUC__)
# define message(level, format, args...) \
_debug(level, __FILE__, __LINE__, __FUNCTION__, format, ##args)
#elif defined(HAVE_VARIADIC_MACROS)
# define message(level, ...) \
_debug(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
static inline void message(GLogLevelFlags level, const char *format, ...)
{
va_list ap;
char s[1024];
va_start(ap, format);
g_vsnprintf(s, 1024, format, ap);
va_end(ap);
_debug(level, __FILE__, __LINE__, __FUNCTION__, s);
}
#endif
#define critical_error(rc) error_code(G_LOG_LEVEL_CRITICAL, rc)
#define IF_SAML2(profile) \
if (lasso_provider_get_protocol_conformance(LASSO_PROVIDER(profile->server)) == \
LASSO_PROTOCOL_SAML_2_0)

View File

@ -929,47 +929,6 @@ urlencoded_to_strings(const char *str)
return result;
}
void
_debug(GLogLevelFlags level, const char *filename, int line,
const char *function, const char *format, ...)
{
char debug_string[1024];
time_t ts;
char date[20];
va_list args;
va_start(args, format);
g_vsnprintf(debug_string, 1024, format, args);
va_end(args);
time(&ts);
strftime(date, 20, "%Y-%m-%d %H:%M:%S", localtime(&ts));
if (level == G_LOG_LEVEL_DEBUG || level == G_LOG_LEVEL_CRITICAL) {
g_log("Lasso", level, "%s (%s/%s:%d) %s",
date, filename, function, line, debug_string);
} else {
g_log("Lasso", level, "%s\t%s", date, debug_string);
}
}
int
error_code(G_GNUC_UNUSED GLogLevelFlags level, int error, ...)
{
const char *format;
char message[1024];
va_list args;
format = lasso_strerror(error);
va_start(args, error);
g_vsnprintf(message, 1024, format, args);
va_end(args);
return error;
}
/**
* lasso_sign_node:
* @xmlnode: the xmlnode to sign