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
|
endif
|
||||||
RM=rm -f
|
RM=rm -f
|
||||||
FIND=find
|
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)
|
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)
|
LDFLAGS+=$(DBGLDFLAGS) -shared -g $(DBGCFLAGS)
|
||||||
LDLIBS=-lstrophe -lpthread
|
LDLIBS=-lstrophe -lpthread $(shell xml2-config --libs)
|
||||||
|
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
LIBDIR ?= $(PREFIX)/lib
|
LIBDIR ?= $(PREFIX)/lib
|
||||||
|
62
account.c
62
account.c
@ -7,6 +7,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <libxml/xmlwriter.h>
|
||||||
#include <weechat/weechat-plugin.h>
|
#include <weechat/weechat-plugin.h>
|
||||||
|
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
@ -14,8 +15,6 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "account.h"
|
#include "account.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
//#include "xmpp-api.h"
|
|
||||||
//#include "xmpp-request.h"
|
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "buffer.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);
|
time_t date = time(NULL);
|
||||||
const char *timestamp = weechat_util_get_time_string(&date);
|
const char *timestamp = weechat_util_get_time_string(&date);
|
||||||
|
|
||||||
weechat_printf(
|
char *xml;
|
||||||
account ? account->buffer : NULL,
|
if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL))
|
||||||
_("%s%s (%s): %s"),
|
{
|
||||||
weechat_prefix("error"), area,
|
FILE *nullfd = fopen("/dev/null", "w+");
|
||||||
log_level_name[level], msg);
|
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)
|
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_channel *new_channel, *ptr_channel;
|
||||||
struct t_gui_buffer *ptr_buffer;
|
struct t_gui_buffer *ptr_buffer;
|
||||||
struct t_hook *typing_timer;
|
struct t_hook *typing_timer;
|
||||||
char buffer_name[128];
|
|
||||||
|
|
||||||
if (!account || !id || !name || !name[0])
|
if (!account || !id || !name || !name[0])
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -192,10 +191,7 @@ struct t_channel *channel__new(struct t_account *account,
|
|||||||
return ptr_channel;
|
return ptr_channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_name[0] = '#';
|
ptr_buffer = channel__create_buffer(account, type, name);
|
||||||
strncpy(&buffer_name[1], name, sizeof(buffer_name));
|
|
||||||
|
|
||||||
ptr_buffer = channel__create_buffer(account, type, buffer_name);
|
|
||||||
if (!ptr_buffer)
|
if (!ptr_buffer)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user