updates.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 18 Feb 2001 22:49:05 +0000 (22:49 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 18 Feb 2001 22:49:05 +0000 (22:49 +0000)
CHANGES
apps/silc/client_ops.c
apps/silc/client_ops.h
lib/silcclient/client.c
lib/silcclient/ops.h

diff --git a/CHANGES b/CHANGES
index f4e6ed1bc52f7f72ea79ad054475cd29e2ff61e0..14b9cebdaed00349e7a4f2b6246be0ca5bb2627b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,15 @@
+Mon Feb 19 00:50:57 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Changed the client operation API: channel_message operation's
+         `sender' is now the client entry of the sender, not the nickname
+         and the `channel' is the channel entry, not the channel name.
+
+         In the private_message operation the `sender' is now also the
+         client entry of the sender not the nickname.
+
+         Affected file is lib/silcclient/ops.h and all applications
+         using the client operations.
+
 Sat Feb 17 22:11:50 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Moved the calling of ops->connect() from connect_to_server_final
index cb73029339a7706440659f7e7ad9924c670d539b..d87393a71c7a4cb8f03747ba3d8533000be359a1 100644 (file)
@@ -46,22 +46,26 @@ void silc_say(SilcClient client, SilcClientConnection conn,
    received in the packet. The `channel_name' is the name of the channel. */
 
 void silc_channel_message(SilcClient client, SilcClientConnection conn,
-                         char *sender, char *channel_name, char *msg)
+                         SilcClientEntry sender, SilcChannelEntry channel
+                         , char *msg)
 {
   /* Message from client */
-  if (conn && !strcmp(conn->current_channel->channel_name, channel_name))
-    silc_print(client, "<%s> %s", sender, msg);
+  if (conn && !strcmp(conn->current_channel->channel_name, 
+                     channel->channel_name))
+    silc_print(client, "<%s> %s", sender ? sender->nickname : "[<unknown>]", 
+              msg);
   else
-    silc_print(client, "<%s:%s> %s", sender, channel_name, msg);
+    silc_print(client, "<%s:%s> %s", sender ? sender->nickname : "[<unknown>]",
+              channel->channel_name, msg);
 }
 
 /* Private message to the client. The `sender' is the nickname of the
    sender received in the packet. */
 
 void silc_private_message(SilcClient client, SilcClientConnection conn,
-                         char *sender, char *msg)
+                         SilcClientEntry sender, char *msg)
 {
-  silc_print(client, "*%s* %s", sender, msg);
+  silc_print(client, "*%s* %s", sender->nickname, msg);
 }
 
 
index db8f1af9b3dbac01eb07f60d364fa7d848f53b5c..7d58937f0794c750039d085be1f054c2ca10ab71 100644 (file)
 
 void silc_say(SilcClient client, SilcClientConnection conn, char *msg, ...);
 void silc_channel_message(SilcClient client, SilcClientConnection conn,
-                         char *sender, char *channel_name, char *msg);
+                         SilcClientEntry sender, 
+                         SilcChannelEntry channel, char *msg);
 void silc_private_message(SilcClient client, SilcClientConnection conn,
-                         char *sender, char *msg);
+                         SilcClientEntry sender, char *msg);
 void silc_notify(SilcClient client, SilcClientConnection conn, 
                 SilcNotifyType type, ...);
 void silc_command(SilcClient client, SilcClientConnection conn, 
index 29a352f768702cd82fc3a8edd9ac095d772a9b3d..b40bd47fbd1e8e1fb8aaba220e3acbfda5e66a8e 100644 (file)
@@ -1996,7 +1996,7 @@ void silc_client_channel_message(SilcClient client,
   SilcChannelUser chu;
   SilcIDCacheEntry id_cache = NULL;
   SilcClientID *client_id = NULL;
-  char *nickname;
+  int found = FALSE;
 
   /* Sanity checks */
   if (packet->dst_id_type != SILC_ID_CHANNEL)
@@ -2030,20 +2030,18 @@ void silc_client_channel_message(SilcClient client,
   if (!payload)
     goto out;
 
-  /* Find nickname */
-  nickname = "[unknown]";
+  /* Find client entry */
   silc_list_start(channel->clients);
   while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
     if (!SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) {
-      nickname = chu->client->nickname;
+      found = TRUE;
       break;
     }
   }
 
   /* Pass the message to application */
-  client->ops->channel_message(client, conn, nickname,
-                              channel->channel_name,
-                              silc_channel_get_data(payload, NULL));
+  client->ops->channel_message(client, conn, found ? chu->client : NULL,
+                              channel, silc_channel_get_data(payload, NULL));
 
  out:
   if (id)
@@ -2063,10 +2061,16 @@ void silc_client_private_message(SilcClient client,
 {
   SilcClientConnection conn = (SilcClientConnection)sock->user_data;
   SilcBuffer buffer = packet->buffer;
+  SilcIDCacheEntry id_cache;
+  SilcClientID *remote_id = NULL;
+  SilcClientEntry remote_client;
   unsigned short nick_len;
-  unsigned char *nickname, *message;
+  unsigned char *nickname, *message = NULL;
   int ret;
 
+  if (packet->src_id_type != SILC_ID_CLIENT)
+    goto out;
+
   /* Get nickname */
   ret = silc_buffer_unformat(buffer, 
                             SILC_STR_UI16_NSTRING_ALLOC(&nickname, &nick_len),
@@ -2079,47 +2083,39 @@ void silc_client_private_message(SilcClient client,
   message = silc_calloc(buffer->len + 1, sizeof(char));
   memcpy(message, buffer->data, buffer->len);
 
+  remote_id = silc_id_str2id(packet->src_id, packet->src_id_len, 
+                            SILC_ID_CLIENT);
+  if (!remote_id)
+    goto out;
+
+  /* Check whether we know this client already */
+  if (!silc_idcache_find_by_id_one(conn->client_cache, remote_id,
+                                  SILC_ID_CLIENT, &id_cache))
+    {
+      /* Allocate client entry */
+      remote_client = silc_calloc(1, sizeof(*remote_client));
+      remote_client->id = remote_id;
+      silc_parse_nickname(nickname, &remote_client->nickname, 
+                         &remote_client->server, &remote_client->num);
+      
+      /* Save the client to cache */
+      silc_idcache_add(conn->client_cache, remote_client->nickname,
+                      SILC_ID_CLIENT, remote_client->id, remote_client, 
+                      TRUE);
+    } else {
+      remote_client = (SilcClientEntry)id_cache->context;
+    }
+
   /* Pass the private message to application */
-  client->ops->private_message(client, conn, nickname, message);
+  client->ops->private_message(client, conn, remote_client, message);
 
   /* See if we are away (gone). If we are away we will reply to the
      sender with the set away message. */
   if (conn->away && conn->away->away) {
-    SilcClientID *remote_id;
-    SilcClientEntry remote_client;
-    SilcIDCacheEntry id_cache;
-
-    if (packet->src_id_type != SILC_ID_CLIENT)
-      goto out;
-
-    remote_id = silc_id_str2id(packet->src_id, packet->src_id_len, 
-                              SILC_ID_CLIENT);
-    if (!remote_id)
-      goto out;
-
     /* If it's me, ignore */
     if (!SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id))
       goto out;
 
-    /* Check whether we know this client already */
-    if (!silc_idcache_find_by_id_one(conn->client_cache, remote_id,
-                                    SILC_ID_CLIENT, &id_cache))
-      {
-       /* Allocate client entry */
-       remote_client = silc_calloc(1, sizeof(*remote_client));
-       remote_client->id = remote_id;
-       silc_parse_nickname(nickname, &remote_client->nickname, 
-                           &remote_client->server, &remote_client->num);
-
-       /* Save the client to cache */
-       silc_idcache_add(conn->client_cache, remote_client->nickname,
-                        SILC_ID_CLIENT, remote_client->id, remote_client, 
-                        TRUE);
-      } else {
-       silc_free(remote_id);
-       remote_client = (SilcClientEntry)id_cache->context;
-      }
-
     /* Send the away message */
     silc_client_packet_send_private_message(client, sock, remote_client,
                                            conn->away->away,
@@ -2127,8 +2123,13 @@ void silc_client_private_message(SilcClient client,
   }
 
  out:
-  memset(message, 0, buffer->len);
-  silc_free(message);
+  if (remote_id)
+    silc_free(remote_id);
+
+  if (message) {
+    memset(message, 0, buffer->len);
+    silc_free(message);
+  }
   silc_free(nickname);
 }
 
index 5c619192c2856dad9c5814ce44cae859de7c9305..648a812106a3076334e49f0796b6707df2b84774 100644 (file)
 typedef struct {
   void (*say)(SilcClient client, SilcClientConnection conn, char *msg, ...);
   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
-                         char *sender, char *channel_name, char *msg);
+                         SilcClientEntry sender, SilcChannelEntry channel, 
+                         char *msg);
   void (*private_message)(SilcClient client, SilcClientConnection conn,
-                         char *sender, char *msg);
+                         SilcClientEntry sender, char *msg);
   void (*notify)(SilcClient client, SilcClientConnection conn, 
                 SilcNotifyType type, ...);
   void (*command)(SilcClient client, SilcClientConnection conn, 
@@ -70,18 +71,19 @@ typedef struct {
    message to a specific connection.  `conn', however, may be NULL.
 
 
-   void (*channel_message)(client, SilcClientConnection conn, 
-                          char *sender, char *channel_name, char *msg);
+   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
+                          SilcClientEntry client, SilcChannelEntry channel, 
+                          char *msg);
 
-   Message for a channel. The `sender' is the nickname of the sender 
-   received in the packet. The `channel_name' is the name of the channel. 
+   Message for a channel. The `sender' is the sender of the message 
+   The `channel' is the channel.
 
 
-   void (*private_message)(client, SilcClientConnection conn,
+   void (*private_message)(SilcClient client, SilcClientConnection conn,
                           char *sender, char *msg);
 
-   Private message to the client. The `sender' is the nickname of the
-   sender received in the packet.
+   Private message to the client. The `sender' is the sender of the
+   message.
 
 
    void (*notify)(SilcClient client, SilcClientConnection conn, ...);