diff --git a/lasso/lasso.c b/lasso/lasso.c index 0b93d873..ca3be951 100644 --- a/lasso/lasso.c +++ b/lasso/lasso.c @@ -72,6 +72,7 @@ #include /* strcmp */ #include #include +#include #include #include #include "lasso.h" @@ -129,13 +130,17 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) #include "types.c" static void -lasso_xml_generic_error_func(G_GNUC_UNUSED void *ctx, const char *msg, ...) +lasso_xml_structured_error_func(G_GNUC_UNUSED void *user_data, xmlErrorPtr error) { - va_list args; + g_log("libxml2", G_LOG_LEVEL_DEBUG, "libxml2: %s", error->message); +} - va_start(args, msg); - g_logv(LASSO_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, msg, args); - va_end(args); +void +lasso_xmlsec_errors_callback(const char *file G_GNUC_UNUSED, int line G_GNUC_UNUSED, const char *func G_GNUC_UNUSED, + const char *errorObject G_GNUC_UNUSED, const char *errorSubject G_GNUC_UNUSED, int reason G_GNUC_UNUSED, + const char *msg) +{ + g_log("libxmlsec", G_LOG_LEVEL_DEBUG, "libxmlsec: %s:%d:%s:%s:%s:%s:%s", file, line, func, errorObject, errorSubject, xmlSecErrorsGetMsg(reason), msg); } /** @@ -196,7 +201,8 @@ int lasso_init() return LASSO_ERROR_UNDEFINED; } lasso_flag_parse_environment_variable(); - xmlSetGenericErrorFunc(NULL, lasso_xml_generic_error_func); + xmlSetStructuredErrorFunc(NULL, lasso_xml_structured_error_func); + xmlSecErrorsSetCallback(lasso_xmlsec_errors_callback); return 0; } diff --git a/tests/basic_tests.c b/tests/basic_tests.c index 8bdde3e8..398d7897 100644 --- a/tests/basic_tests.c +++ b/tests/basic_tests.c @@ -50,9 +50,9 @@ END_TEST START_TEST(test02_server_load_dump_random_string) { LassoServer *serverContext; - begin_check_do_log(G_LOG_LEVEL_CRITICAL, "libxml2: Start tag expected, '<' not found\\n", FALSE); + begin_check_do_log("libxml2", G_LOG_LEVEL_DEBUG, "libxml2: Start tag expected, '<' not found\n", FALSE); serverContext = lasso_server_new_from_dump("foo"); - end_check_do_log(); + end_check_do_log("libxml2"); fail_unless(serverContext == NULL, "serverContext was created from a fake dump"); } @@ -61,9 +61,9 @@ END_TEST START_TEST(test03_server_load_dump_random_xml) { LassoServer *serverContext; - begin_check_do_log(G_LOG_LEVEL_CRITICAL, " Unable to build a LassoNode from a xmlNode", TRUE); + begin_check_do_log(NULL, G_LOG_LEVEL_CRITICAL, " Unable to build a LassoNode from a xmlNode", TRUE); serverContext = lasso_server_new_from_dump(""); - end_check_do_log(); + end_check_do_log(NULL); fail_unless(serverContext == NULL, "serverContext was created from fake (but valid XML) dump"); } @@ -174,9 +174,9 @@ START_TEST(test08_test_new_from_xmlNode) "LassoTest", &this_info, 0); r = lasso_registry_default_add_direct_mapping("http://example.com", "Test1", LASSO_LASSO_HREF, "LassoTest"); fail_unless(r == 0, "no mapping for http://example.com:Test1 should exist"); - begin_check_do_log(G_LOG_LEVEL_WARNING, " Class LassoTest has no node_data so no initialization is possible", TRUE); + begin_check_do_log(NULL, G_LOG_LEVEL_WARNING, " Class LassoTest has no node_data so no initialization is possible", TRUE); node = lasso_node_new_from_dump(""); - end_check_do_log(); + end_check_do_log(NULL); fail_unless(node != NULL, "parsing should return an object"); fail_unless(strcmp(G_OBJECT_TYPE_NAME(node), "LassoTest") == 0, "node classname should be LassoTest"); g_object_unref(node); diff --git a/tests/login_tests.c b/tests/login_tests.c index e006e007..9a49b913 100644 --- a/tests/login_tests.c +++ b/tests/login_tests.c @@ -295,10 +295,10 @@ START_TEST(test02_serviceProviderLogin) fail_unless(found != NULL, "We must find an InResponseTo attribute"); found[sizeof("InResponseTo=\"")] = '?'; lasso_set_flag("no-verify-signature"); - begin_check_do_log(G_LOG_LEVEL_CRITICAL, " If inResponseTo attribute is present, a matching " + begin_check_do_log(NULL, G_LOG_LEVEL_CRITICAL, " If inResponseTo attribute is present, a matching " "request must be present too in the LassoLogin object", TRUE); check_not_equals(lasso_login_process_response_msg(spLoginContext, soapResponseMsg), 0); - end_check_do_log(); + end_check_do_log(NULL); lasso_set_flag("verify-signature"); check_good_rc(lasso_login_accept_sso(spLoginContext)); fail_unless(rc == 0, "lasso_login_accept_sso must fail"); diff --git a/tests/tests.h b/tests/tests.h index 0f2a6c9e..2391bd29 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -142,15 +142,15 @@ static inline void add_check_log(GLogLevelFlags log_level, const char *message, * message emitted between the two macros is one equals to message at the level level, * or ending with message if endswith is True. */ -static inline void begin_check_do_log(GLogLevelFlags level, const char *message, gboolean endswith) { +static inline void begin_check_do_log(char *domain, GLogLevelFlags level, const char *message, gboolean endswith) { memset(&checking_logger_user_data, 0, sizeof(struct CheckingLogHandlerUserData)); add_check_log(level, message, endswith); - checking_log_handler = g_log_set_handler(LASSO_LOG_DOMAIN, level, checking_logger, &checking_logger_user_data); + checking_log_handler = g_log_set_handler(domain ? domain : LASSO_LOG_DOMAIN, level, checking_logger, &checking_logger_user_data); checking_log_handler_flag = 1; } -static inline void end_check_do_log() { - g_log_remove_handler(LASSO_LOG_DOMAIN, checking_log_handler); +static inline void end_check_do_log(const char *domain) { + g_log_remove_handler(domain ? domain : LASSO_LOG_DOMAIN, checking_log_handler); checking_log_handler = 0; fail_unless(checking_log_handler_flag, "Logging failure: expected log level %d and message «%s», got %d and «%s»", checking_logger_user_data.log_levels[0],