summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-06-12 00:43:49 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-06-12 00:43:49 +0000
commita9b673cd4a9a5ee64d8d04f5e3c03978a799f837 (patch)
tree9e53f873a2384b92f9378dd1a4a78a602708cefe
parentc4ac4f652c0a3646ee12c9d947e6eada70315ebb (diff)
downloadlasso-a9b673cd4a9a5ee64d8d04f5e3c03978a799f837.tar.gz
lasso-a9b673cd4a9a5ee64d8d04f5e3c03978a799f837.tar.xz
lasso-a9b673cd4a9a5ee64d8d04f5e3c03978a799f837.zip
Core: move logging function and macros to their own module, adapt perl binding
-rw-r--r--bindings/perl/lang.py21
-rw-r--r--lasso/Makefile.am8
-rw-r--r--lasso/id-ff/name_identifier_mapping.c1
-rw-r--r--lasso/lasso.c13
-rw-r--r--lasso/lasso_config.h.in2
-rw-r--r--lasso/logging.c67
-rw-r--r--lasso/logging.h130
-rw-r--r--lasso/utils.h1
-rw-r--r--lasso/xml/private.h43
-rw-r--r--lasso/xml/tools.c41
10 files changed, 232 insertions, 95 deletions
diff --git a/bindings/perl/lang.py b/bindings/perl/lang.py
index 64e9d189..f01c88ba 100644
--- a/bindings/perl/lang.py
+++ b/bindings/perl/lang.py
@@ -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;
diff --git a/lasso/Makefile.am b/lasso/Makefile.am
index 7861fda2..24b5d8a4 100644
--- a/lasso/Makefile.am
+++ b/lasso/Makefile.am
@@ -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
diff --git a/lasso/id-ff/name_identifier_mapping.c b/lasso/id-ff/name_identifier_mapping.c
index a91b6d71..7a463a2a 100644
--- a/lasso/id-ff/name_identifier_mapping.c
+++ b/lasso/id-ff/name_identifier_mapping.c
@@ -28,6 +28,7 @@
*
**/
+#include "../utils.h"
#include "../xml/private.h"
#include "name_identifier_mapping.h"
diff --git a/lasso/lasso.c b/lasso/lasso.c
index 2a7a13b6..d35e072d 100644
--- a/lasso/lasso.c
+++ b/lasso/lasso.c
@@ -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. */
diff --git a/lasso/lasso_config.h.in b/lasso/lasso_config.h.in
index d420a547..4e8a7761 100644
--- a/lasso/lasso_config.h.in
+++ b/lasso/lasso_config.h.in
@@ -2,4 +2,4 @@
/* Define if ID-WSF support is enabled */
#undef LASSO_WSF_ENABLED
-
+#define LASSO_LOG_DOMAIN "Lasso"
diff --git a/lasso/logging.c b/lasso/logging.c
new file mode 100644
index 00000000..511e4985
--- /dev/null
+++ b/lasso/logging.c
@@ -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;
+}
diff --git a/lasso/logging.h b/lasso/logging.h
new file mode 100644
index 00000000..6c659d1b
--- /dev/null
+++ b/lasso/logging.h
@@ -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_ */
diff --git a/lasso/utils.h b/lasso/utils.h
index 1cde5be4..134b3712 100644
--- a/lasso/utils.h
+++ b/lasso/utils.h
@@ -32,6 +32,7 @@
#include "./backward_comp.h"
#include "./xml/private.h"
#include "./xml/tools.h"
+#include "./logging.h"
#ifdef LASSO_DEBUG
#ifdef __GNUC__
diff --git a/lasso/xml/private.h b/lasso/xml/private.h
index a90d35c7..cfaf016d 100644
--- a/lasso/xml/private.h
+++ b/lasso/xml/private.h
@@ -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)
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index fe36f4ad..96b4f139 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -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