From 73708b540a27652f8f916ca87ff8cf2ce5e1e42f Mon Sep 17 00:00:00 2001 From: Artem Savkov Date: Wed, 18 Jan 2017 15:43:46 +0100 Subject: [PATCH] Add a debug option to configure. Add --enable-debug option to configure that enables bitlbee-discord to dump all traffic to stdout. Update README with some info on debugging. --- .gitignore | 4 +++ README | 15 ++++++++++++ configure.ac | 8 ++++++ src/discord-handlers.c | 6 +++++ src/discord-http.c | 53 ++++++++++++++++++++++++++++++++++++++++ src/discord-websockets.c | 5 ++++ 6 files changed, 91 insertions(+) diff --git a/.gitignore b/.gitignore index 1c0c45f..728f907 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ libtool.m4 lt*.m4 Makefile Makefile.in +config.h* +stamp-h1 +TAGS +src/TAGS diff --git a/README b/README index da5b6dc..34b4395 100644 --- a/README +++ b/README @@ -135,6 +135,21 @@ This section describes options available throug "account set" bitlbee command 0 - #general 3 - #bee.general +Debugging +--------- +You can enable extra debug output for bitlbee-discord, to do so add +"--enable-debug" option to "./configure". This will enable bitlbee-discord to +print all traffic it exchanges with discord servers to stdout and there is a +lot of it. To get it on your screen run bitlbee by hand in foreground mode: +"bitlbee -nvD", then connect with an irc client as you usually do. +WARNING: there IS sensitive information in this debug output, such as auth +tokens, your plaintext password and, obviosly, your incoming and outgoing +messages. Be sure to remove any information you are not willing to share before +posting it anywhere. + +If you are experiencing crashes please refer to this page for information on +how to get a meaningful backtrace: https://wiki.bitlbee.org/DebuggingCrashes + Bugs ---- Please report bugs at github: https://github.com/sm00th/bitlbee-discord/issues diff --git a/configure.ac b/configure.ac index c4d5225..98e41c9 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,8 @@ m4_define_default( PKG_CHECK_MODULES([BITLBEE], [bitlbee >= 3.5]) PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.32]) +AC_CONFIG_HEADERS([config.h]) + # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T @@ -71,5 +73,11 @@ AS_IF( AC_SUBST([plugindir]) +AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],[Enable debugging support]), + [ if test x$enableval = xyes ; then + AC_DEFINE(DEBUG,1,[ Define to enable debugging info. ]) + fi + ]) + AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT diff --git a/src/discord-handlers.c b/src/discord-handlers.c index 32d4d78..d83f2de 100644 --- a/src/discord-handlers.c +++ b/src/discord-handlers.c @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include #include #include "discord-util.h" @@ -573,6 +575,10 @@ void discord_parse_message(struct im_connection *ic, gchar *buf, guint64 size) discord_data *dd = ic->proto_data; json_value *js = json_parse((gchar*)buf, size); +#ifdef DEBUG + g_print("<<< %s: %lu\n%s\n\n", __func__, size, buf); +#endif + if (!js || js->type != json_object) { imcb_error(ic, "Failed to parse json reply."); imc_logout(ic, TRUE); diff --git a/src/discord-http.c b/src/discord-http.c index 54daaec..a34c946 100644 --- a/src/discord-http.c +++ b/src/discord-http.c @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include #include #include @@ -48,6 +49,10 @@ static void discord_http_get(struct im_connection *ic, const char *api_path, set_getstr(&ic->acc->set, "host"), dd->token); +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&ic->acc->set, "host"), 443, 1, request->str, cb_func, data); g_string_free(request, TRUE); @@ -57,6 +62,11 @@ static void discord_http_gateway_cb(struct http_request *req) { struct im_connection *ic = req->data; +#ifdef DEBUG + g_print("<<< %s: [%d] %d\n%s\n\n", __func__, req->status_code, + req->body_size, req->reply_body); +#endif + if (req->status_code == 200) { json_value *js = json_parse(req->reply_body, req->body_size); if (!js || js->type != json_object) { @@ -129,6 +139,11 @@ static void discord_http_mfa_cb(struct http_request *req) { struct im_connection *ic = req->data; +#ifdef DEBUG + g_print("<<< %s: [%d] %d\n%s\n\n", __func__, req->status_code, + req->body_size, req->reply_body); +#endif + json_value *js = json_parse(req->reply_body, req->body_size); if (!js || js->type != json_object) { imcb_error(ic, "Failed to parse json reply."); @@ -154,6 +169,11 @@ static void discord_http_login_cb(struct http_request *req) { struct im_connection *ic = req->data; +#ifdef DEBUG + g_print("<<< %s: [%d] %d\n%s\n\n", __func__, req->status_code, + req->body_size, req->reply_body); +#endif + json_value *js = json_parse(req->reply_body, req->body_size); if (!js || js->type != json_object) { imcb_error(ic, "Failed to parse json reply."); @@ -190,6 +210,12 @@ static void discord_http_noop_cb(struct http_request *req) static void discord_http_send_msg_cb(struct http_request *req) { struct im_connection *ic = req->data; + +#ifdef DEBUG + g_print("<<< %s: [%d] %d\n%s\n\n", __func__, req->status_code, + req->body_size, req->reply_body); +#endif + if (req->status_code != 200) { imcb_error(ic, "Failed to send message (%d).", req->status_code); } @@ -198,6 +224,12 @@ static void discord_http_send_msg_cb(struct http_request *req) static void discord_http_backlog_cb(struct http_request *req) { struct im_connection *ic = req->data; + +#ifdef DEBUG + g_print("<<< %s: [%d] %d\n%s\n\n", __func__, req->status_code, + req->body_size, req->reply_body); +#endif + if (req->status_code != 200) { imcb_error(ic, "Failed to get backlog (%d).", req->status_code); } else { @@ -358,6 +390,10 @@ void discord_http_send_msg(struct im_connection *ic, const char *id, content->len, content->str); +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&ic->acc->set, "host"), 443, 1, request->str, discord_http_send_msg_cb, ic); @@ -386,6 +422,10 @@ void discord_http_send_ack(struct im_connection *ic, const char *channel_id, set_getstr(&ic->acc->set, "host"), dd->token); +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&ic->acc->set, "host"), 443, 1, request->str, discord_http_noop_cb, NULL); @@ -413,6 +453,10 @@ void discord_http_mfa_auth(struct im_connection *ic, const char *msg) auth->len, auth->str); +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&ic->acc->set, "host"), 443, 1, request->str, discord_http_mfa_cb, ic); @@ -441,6 +485,10 @@ void discord_http_login(account_t *acc) jlogin->len, jlogin->str); +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&acc->set, "host"), 443, 1, request->str, discord_http_login_cb, acc->ic); @@ -509,6 +557,11 @@ void discord_http_create_and_send_msg(struct im_connection *ic, casm_data *cd = g_new0(casm_data, 1); cd->ic = ic; cd->msg = g_strdup(msg); + +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, request->len, request->str); +#endif + (void) http_dorequest(set_getstr(&ic->acc->set, "host"), 443, 1, request->str, discord_http_casm_cb, cd); diff --git a/src/discord-websockets.c b/src/discord-websockets.c index d70f507..b05f355 100644 --- a/src/discord-websockets.c +++ b/src/discord-websockets.c @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include #include @@ -43,6 +44,10 @@ static int discord_ws_send_payload(discord_data *dd, const char *pload, guchar mkey[4]; gchar *mpload; +#ifdef DEBUG + g_print(">>> %s: %lu\n%s\n\n", __func__, psize, pload); +#endif + random_bytes(mkey, sizeof(mkey)); mpload = discord_ws_mask(mkey, pload, psize);