mirror of
https://github.com/bqv/weechat-xmpp/
synced 2024-11-18 03:25:37 +00:00
formatted stanza logs
This commit is contained in:
parent
020c61af84
commit
fe5caf0594
4
Makefile
4
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
|
||||
|
52
account.c
52
account.c
@ -7,6 +7,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#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);
|
||||
|
||||
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)
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user