silc_client_send_[channel|private]_message now returns boolean
authorPekka Riikonen <priikone@silcnet.org>
Sun, 5 Oct 2003 09:38:07 +0000 (09:38 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 5 Oct 2003 09:38:07 +0000 (09:38 +0000)
return value.

lib/silcclient/client_channel.c
lib/silcclient/client_prvmsg.c
lib/silcclient/silcclient.h

index 679fe5ee5bcea58b7ad439667d83674c394e7ed0..722096378e6d2eaef018f85c42bf5bd9e2f6deec 100644 (file)
@@ -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 {
index 9b6f454ab572a77a0f0a2edf8da1b87b61f704a6..d0b72c97ccda970a3aaa20306794a02b99c0afb5 100644 (file)
@@ -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,
index bcfa8ea5ca9f40520c03a9f8b5f4a0fa32fcf5b3..bdab95a9630b5c89b20854f8ecc2bfff5bfefb48 100644 (file)
@@ -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,