From 321093b22ea2f61ae804eb515438a4309e392618 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 5 Oct 2003 09:38:07 +0000 Subject: [PATCH] silc_client_send_[channel|private]_message now returns boolean return value. --- lib/silcclient/client_channel.c | 27 ++++++++++++++++++--------- lib/silcclient/client_prvmsg.c | 13 ++++++++++--- lib/silcclient/silcclient.h | 14 ++++++++++---- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lib/silcclient/client_channel.c b/lib/silcclient/client_channel.c index 679fe5ee..72209637 100644 --- a/lib/silcclient/client_channel.c +++ b/lib/silcclient/client_channel.c @@ -32,7 +32,7 @@ with the next receiver's key. The `data' is the channel message. If the `force_send' is TRUE then the packet is sent immediately. */ -void silc_client_send_channel_message(SilcClient client, +bool silc_client_send_channel_message(SilcClient client, SilcClientConnection conn, SilcChannelEntry channel, SilcChannelPrivateKey key, @@ -50,6 +50,7 @@ void silc_client_send_channel_message(SilcClient client, unsigned char *id_string; int block_len; SilcChannelUser chu; + bool ret = FALSE; assert(client && conn && channel); sock = conn->sock; @@ -58,18 +59,18 @@ void silc_client_send_channel_message(SilcClient client, chu = silc_client_on_channel(channel, conn->local_entry); if (!chu) { SILC_LOG_ERROR(("Cannot send message to channel we are not joined")); - return; + return FALSE; } /* Check if it is allowed to send messages to this channel by us. */ if (channel->mode & SILC_CHANNEL_MODE_SILENCE_USERS && !chu->mode) - return; + return FALSE; if (channel->mode & SILC_CHANNEL_MODE_SILENCE_OPERS && chu->mode & SILC_CHANNEL_UMODE_CHANOP && !(chu->mode & SILC_CHANNEL_UMODE_CHANFO)) - return; + return FALSE; if (chu->mode & SILC_CHANNEL_UMODE_QUIET) - return; + return FALSE; /* Take the key to be used */ if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) { @@ -102,8 +103,10 @@ void silc_client_send_channel_message(SilcClient client, hmac = channel->hmac; } - if (!cipher || !hmac) - return; + if (!cipher || !hmac) { + SILC_LOG_ERROR(("No cipher and HMAC for channel")); + return FALSE; + } block_len = silc_cipher_get_block_len(cipher); @@ -111,8 +114,10 @@ void silc_client_send_channel_message(SilcClient client, payload = silc_message_payload_encode(flags, data, data_len, TRUE, FALSE, cipher, hmac, client->rng, NULL, client->private_key, client->sha1hash); - if (!payload) - return; + if (!payload) { + SILC_LOG_ERROR(("Error encoding channel message")); + return FALSE; + } /* Get data used in packet header encryption, keys and stuff. */ cipher = conn->internal->send_key; @@ -167,9 +172,13 @@ void silc_client_send_channel_message(SilcClient client, silc_client_rekey_callback, sock, 0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); + ret = TRUE; + out: silc_buffer_free(payload); silc_free(id_string); + + return ret; } typedef struct { diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index 9b6f454a..d0b72c97 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -32,7 +32,7 @@ message. The `data' is the private message. If the `force_send' is TRUE the packet is sent immediately. */ -void silc_client_send_private_message(SilcClient client, +bool silc_client_send_private_message(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry, SilcMessageFlags flags, @@ -47,6 +47,7 @@ void silc_client_send_private_message(SilcClient client, SilcCipher cipher; SilcHmac hmac; int block_len; + bool ret = FALSE; assert(client && conn && client_entry); sock = conn->sock; @@ -60,8 +61,10 @@ void silc_client_send_private_message(SilcClient client, client_entry->hmac_send, client->rng, NULL, client->private_key, client->sha1hash); - if (!buffer) - return; + if (!buffer) { + SILC_LOG_ERROR(("Error encoding private message")); + return FALSE; + } /* If we don't have private message specific key then private messages are just as any normal packet thus call normal packet sending. If @@ -128,8 +131,12 @@ void silc_client_send_private_message(SilcClient client, silc_free(packetdata.dst_id); + ret = TRUE; + out: silc_buffer_free(buffer); + + return ret; } static void silc_client_private_message_cb(SilcClient client, diff --git a/lib/silcclient/silcclient.h b/lib/silcclient/silcclient.h index bcfa8ea5..bdab95a9 100644 --- a/lib/silcclient/silcclient.h +++ b/lib/silcclient/silcclient.h @@ -1115,7 +1115,7 @@ void silc_client_close_connection(SilcClient client, * * SYNOPSIS * - * void silc_client_send_channel_message(SilcClient client, + * bool silc_client_send_channel_message(SilcClient client, * SilcClientConnection conn, * SilcChannelEntry channel, * SilcChannelPrivateKey key, @@ -1142,8 +1142,12 @@ void silc_client_close_connection(SilcClient client, * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be * digitally signed with the SILC key pair. * + * Returns TRUE if the message was sent, and FALSE if error occurred or + * the sending is not allowed due to channel modes (like sending is + * blocked). + * ***/ -void silc_client_send_channel_message(SilcClient client, +bool silc_client_send_channel_message(SilcClient client, SilcClientConnection conn, SilcChannelEntry channel, SilcChannelPrivateKey key, @@ -1156,7 +1160,7 @@ void silc_client_send_channel_message(SilcClient client, * * SYNOPSIS * - * void silc_client_send_private_message(SilcClient client, + * bool silc_client_send_private_message(SilcClient client, * SilcClientConnection conn, * SilcClientEntry client_entry, * SilcMessageFlags flags, @@ -1177,8 +1181,10 @@ void silc_client_send_channel_message(SilcClient client, * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be * digitally signed with the SILC key pair. * + * Returns TRUE if the message was sent, and FALSE if error occurred. + * ***/ -void silc_client_send_private_message(SilcClient client, +bool silc_client_send_private_message(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry, SilcMessageFlags flags, -- 2.43.0