aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorturret <turret@duck.com>2024-03-30 21:24:36 -0500
committerturret <turret@duck.com>2024-03-30 21:24:36 -0500
commitf6b38bbdeeaa3645e1921ccc6114d43e25dd1083 (patch)
tree776bcc8958260522e83306c9b393b46c7afbe1ef
parente9cf9c79ff159b59cfc61887ad8a69164785a1c9 (diff)
downloaddiscord-bot-skeleton-f6b38bbdeeaa3645e1921ccc6114d43e25dd1083.tar.gz
discord-bot-skeleton-f6b38bbdeeaa3645e1921ccc6114d43e25dd1083.tar.bz2
discord-bot-skeleton-f6b38bbdeeaa3645e1921ccc6114d43e25dd1083.zip
net: add prints for data when unhandled
mainly for early building process net: make curl ws_handle non-static
-rw-r--r--util/net.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/util/net.c b/util/net.c
index 42fb004..77e944f 100644
--- a/util/net.c
+++ b/util/net.c
@@ -40,7 +40,7 @@ static struct {
#undef E
} ev_handlers;
-static CURL *ws_handle;
+CURL *ws_handle;
static char *gateway_url;
static char *token_header;
@@ -203,6 +203,10 @@ static void ws_handle_event(cJSON *event)
int (*ev_handler)(cJSON *) = *ev_get_handler(ev);
if(ev_handler != NULL) {
ev_handler(data);
+ } else {
+ char *ev_payload = cJSON_Print(data);
+ print("ws: unhandled event %s (data below)\n%s", event, ev_payload);
+ free(ev_payload);
}
break;
case 1: /* Heartbeat request */
@@ -217,9 +221,11 @@ static void ws_handle_event(cJSON *event)
break;
}
/* FALLTHROUGH */
- case 7: /* Reconnect */
+ case 7: ; /* Reconnect */
/* TODO */
- panic("ws: cannot reconnect to ws after failure (Not supported)");
+ char *msg = cJSON_Print(data);
+ panic("ws: cannot reconnect to ws after failure (Not supported)\n%s", msg);
+ free(msg); /* at least the effort is there (not a memory leak) */
break;
case 10: ; /* Hello */
int heartbeat_wait = cJSON_GetObjectItem(data,