summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-10-07 19:12:14 +0200
committerxengineering <me@xengineering.eu>2022-10-07 19:12:14 +0200
commitf5e15fdf39f5afe6a852025c410ced5c701e3ee1 (patch)
tree10226c21afc3817c4ecfb3c448f8d5ddb51bc040
parentd724097397a470755ce1cb203cb3870d7a349f53 (diff)
downloadlimox-f5e15fdf39f5afe6a852025c410ced5c701e3ee1.tar
limox-f5e15fdf39f5afe6a852025c410ced5c701e3ee1.tar.zst
limox-f5e15fdf39f5afe6a852025c410ced5c701e3ee1.zip
Handle case of message to send while offline
-rw-r--r--net.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/net.c b/net.c
index a3e30a3..9fa5df4 100644
--- a/net.c
+++ b/net.c
@@ -222,13 +222,14 @@ void net_disconnect(void) {
void net_send_message(const char* sender, const char* content,
const char* recipient) {
- // TODO what happens if client is disconnected and this function is called?
-
- char* uuid = xmpp_uuid_gen(ctx);
-
- xmpp_stanza_t* msg = xmpp_message_new(ctx, "chat", recipient, uuid);
- xmpp_stanza_set_from(msg, sender);
- xmpp_message_set_body(msg, content);
- xmpp_send(conn, msg);
+ if (xmpp_conn_is_connected(conn)) {
+ char* uuid = xmpp_uuid_gen(ctx);
+ xmpp_stanza_t* msg = xmpp_message_new(ctx, "chat", recipient, uuid);
+ xmpp_stanza_set_from(msg, sender);
+ xmpp_message_set_body(msg, content);
+ xmpp_send(conn, msg);
+ } else {
+ fprintf(stderr, "net_send_message() called while not connected\n");
+ }
}