From b87ddd7a6c71ae14777bc30374da65cdb77ac546 Mon Sep 17 00:00:00 2001 From: Tony Olagbaiye Date: Tue, 1 May 2018 13:32:51 +0100 Subject: [PATCH] switch to gnutls to avoid gcrypt state corruption --- Makefile | 2 +- slack-api.c | 33 +++++++++++++++++---------------- slack-teaminfo.c | 2 +- slack-workspace.c | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index fda87ab..cb2b6a2 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CXX=clang++ RM=rm -f CFLAGS=-fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -I libwebsockets/include -I json-c LDFLAGS=-shared -g -LDLIBS=-lssl +LDLIBS=-lgnutls SRCS=slack.c \ slack-api.c \ diff --git a/slack-api.c b/slack-api.c index 0cd3b78..b9510fa 100644 --- a/slack-api.c +++ b/slack-api.c @@ -1,4 +1,5 @@ #include +#include #include #include "weechat-plugin.h" @@ -32,7 +33,7 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason, weechat_prefix("network"), SLACK_PLUGIN_NAME); break; - /* chunks of chunked content, with header removed */ + /* data is never chunked */ case LWS_CALLBACK_CLIENT_RECEIVE: weechat_printf( workspace->buffer, @@ -40,25 +41,25 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason, weechat_prefix("network"), SLACK_PLUGIN_NAME, (const char *)in); { - struct t_json_chunk *new_chunk, *last_chunk; + char *json_string; + json_object *response, *type; - new_chunk = malloc(sizeof(*new_chunk)); - new_chunk->data = malloc((1024 * sizeof(char)) + 1); - new_chunk->data[0] = '\0'; - new_chunk->next = NULL; + json_string = strdup((const char *)in); - strncat(new_chunk->data, in, (int)len); - - if (workspace->json_chunks) - { - for (last_chunk = workspace->json_chunks; last_chunk->next; - last_chunk = last_chunk->next); - last_chunk->next = new_chunk; - } - else + response = json_tokener_parse(json_string); + type = json_object_object_get(response, "type"); + if (!type) { - workspace->json_chunks = new_chunk; + weechat_printf( + workspace->buffer, + _("%s%s: unexpected data received from websocket: closing"), + weechat_prefix("error"), SLACK_PLUGIN_NAME); + json_object_put(response); + free(json_string); + return -1; } + + free(json_string); } return 0; /* don't passthru */ diff --git a/slack-teaminfo.c b/slack-teaminfo.c index e8185ad..431bfd7 100644 --- a/slack-teaminfo.c +++ b/slack-teaminfo.c @@ -34,7 +34,7 @@ static inline int json_valid(json_object *object) { weechat_printf( NULL, - _("%s%s: Error retrieving workspace info: unexpected response from server"), + _("%s%s: error retrieving workspace info: unexpected response from server"), weechat_prefix("error"), SLACK_PLUGIN_NAME); return 0; } diff --git a/slack-workspace.c b/slack-workspace.c index da55346..32fcf30 100644 --- a/slack-workspace.c +++ b/slack-workspace.c @@ -29,7 +29,7 @@ static inline int json_valid(json_object *object, struct t_slack_workspace *work { weechat_printf( workspace->buffer, - _("%s%s: Error requesting websocket: unexpected response from server"), + _("%s%s: error requesting websocket: unexpected response from server"), weechat_prefix("error"), SLACK_PLUGIN_NAME); return 0; }