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.
This commit is contained in:
Artem Savkov 2017-01-18 15:43:46 +01:00
parent cda4010f14
commit 73708b540a
6 changed files with 91 additions and 0 deletions

4
.gitignore vendored
View File

@ -18,3 +18,7 @@ libtool.m4
lt*.m4
Makefile
Makefile.in
config.h*
stamp-h1
TAGS
src/TAGS

15
README
View File

@ -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

View File

@ -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

View File

@ -14,6 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <bitlbee/json_util.h>
#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);

View File

@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <bitlbee/http_client.h>
#include <bitlbee/json.h>
#include <bitlbee/json_util.h>
@ -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);

View File

@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <bitlbee/ssl_client.h>
#include <bitlbee/events.h>
@ -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);