diff --git a/Makefile b/Makefile index 657cd60..1f137d2 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ ifdef DEBUG endif RM=rm -f FIND=find -INCLUDES=-Ilibstrophe +INCLUDES=-Ilibstrophe $(shell xml2-config --cflags) CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers $(INCLUDES) LDFLAGS+=$(DBGLDFLAGS) -shared -g $(DBGCFLAGS) -LDLIBS=-lstrophe -lpthread +LDLIBS=-lstrophe -lpthread $(shell xml2-config --libs) PREFIX ?= /usr/local LIBDIR ?= $(PREFIX)/lib diff --git a/account.c b/account.c index e490634..9b20bcc 100644 --- a/account.c +++ b/account.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "plugin.h" @@ -14,8 +15,6 @@ #include "input.h" #include "account.h" #include "connection.h" -//#include "xmpp-api.h" -//#include "xmpp-request.h" #include "user.h" #include "channel.h" #include "buffer.h" @@ -94,11 +93,60 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve time_t date = time(NULL); const char *timestamp = weechat_util_get_time_string(&date); - weechat_printf( - account ? account->buffer : NULL, - _("%s%s (%s): %s"), - weechat_prefix("error"), area, - log_level_name[level], msg); + char *xml; + if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL)) + { + FILE *nullfd = fopen("/dev/null", "w+"); + xmlGenericErrorContext = nullfd; + + const char *header = strndup(msg, xml - msg); + xmlDocPtr *doc = xmlRecoverMemory(xml, strlen(xml)); + if (doc == NULL) { + weechat_printf( + account ? account->buffer : NULL, + "xml: Error parsing the xml document"); + fclose(nullfd); + return; + } + xmlChar *buf = malloc(strlen(xml) * 2); + if (buf == NULL) { + weechat_printf( + account ? account->buffer : NULL, + "xml: Error allocating the xml buffer"); + fclose(nullfd); + return; + } + int size = -1; + xmlDocDumpFormatMemory(doc, &buf, &size, 1); + if (size <= 0) { + weechat_printf( + account ? account->buffer : NULL, + "xml: Error formatting the xml document"); + fclose(nullfd); + return; + } + const char **lines = weechat_string_split(buf, "\r\n", NULL, + 0, 0, &size); + weechat_printf( + account ? account->buffer : NULL, + _("%s%s (%s): %s"), + weechat_prefix("error"), area, + log_level_name[level], header); + for (int i = 1; i < size; i++) + weechat_printf( + account ? account->buffer : NULL, + _("%s"), lines[i]); + + fclose(nullfd); + } + else + { + weechat_printf( + account ? account->buffer : NULL, + _("%s%s (%s): %s"), + weechat_prefix("error"), area, + log_level_name[level], msg); + } } struct t_account *account__alloc(const char *name) diff --git a/channel.c b/channel.c index 546ec9c..04c277f 100644 --- a/channel.c +++ b/channel.c @@ -181,7 +181,6 @@ struct t_channel *channel__new(struct t_account *account, struct t_channel *new_channel, *ptr_channel; struct t_gui_buffer *ptr_buffer; struct t_hook *typing_timer; - char buffer_name[128]; if (!account || !id || !name || !name[0]) return NULL; @@ -192,10 +191,7 @@ struct t_channel *channel__new(struct t_account *account, return ptr_channel; } - buffer_name[0] = '#'; - strncpy(&buffer_name[1], name, sizeof(buffer_name)); - - ptr_buffer = channel__create_buffer(account, type, buffer_name); + ptr_buffer = channel__create_buffer(account, type, name); if (!ptr_buffer) return NULL;