updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 27 Feb 2001 13:14:36 +0000 (13:14 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 27 Feb 2001 13:14:36 +0000 (13:14 +0000)
CHANGES
apps/silc/local_command.c
apps/silc/silc.c
includes/clientlibincludes.h
lib/silcclient/client.c
lib/silcclient/client.h
lib/silcclient/command.c
lib/silcclient/idlist.c
lib/silcclient/idlist.h
lib/silcclient/protocol.c

diff --git a/CHANGES b/CHANGES
index e8a991092d4d460194785070eb0f5396e51a0e60..77481f17141d1f0f30cafc030acab683c16e6bb3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,16 @@
+Tue Feb 27 13:30:52 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Removed lib/silcclient/ops.h file.
+
+         Redefined parts of the SILC Client Library API. Created new
+         file silcapi.h that deprecates the ops.h file and defines the
+         published Client Library API.  Defined also private message key
+         API and channel private key API into the file.
+
+         This is the file that the application must include from the
+         SILC Client Library.  Other files need not be included by
+         the application anymore.
+
 Tue Feb 27 11:28:31 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Added new packet type: SILC_PACKET_KEY_AGREEMENT.  This packet
index 58a76660ce2ce505aa1068140c5e6f19f591f818..6429bfc5a10bb5854046e8a6d45ff8ea62efd041 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.6  2001/02/24 15:50:23  priikone
- *     implemented KICK command
- *
- * Revision 1.5  2001/02/19 13:47:30  priikone
- *     updates.
- *
- * Revision 1.4  2001/02/16 00:33:23  priikone
- *     updates.
- *
- * Revision 1.3  2001/02/14 15:31:33  priikone
- *     Do not allow several server connections.
- *
- * Revision 1.2  2001/01/30 21:40:21  priikone
- *     updates.
- *
- * Revision 1.1  2000/09/13 17:47:54  priikone
- *     Created SILC Client Libary by moving stuff from silc/ directory.
- *     SILC client library is SILC client without UI. Old UI still exists
- *     in silc/ directory and uses the new client.
- *
- *     Bug fixes and several new functions, structures and functions
- *     naming changes during the change was made.
- *
- */
+/* $Id$ */
 
 #include "clientincludes.h"
 
@@ -162,9 +136,9 @@ SILC_CLIENT_LCMD_FUNC(msg)
   silc_print(client, "-> *%s* %s", cmd->argv[1], cmd->argv[2]);
 
   /* Send the private message */
-  silc_client_packet_send_private_message(client, conn->sock, client_entry,
-                                         cmd->argv[2], cmd->argv_lens[2],
-                                         TRUE);
+  silc_client_send_private_message(client, conn, client_entry,
+                                  cmd->argv[2], cmd->argv_lens[2],
+                                  TRUE);
 
  out:
   silc_client_command_free(cmd);
index 16753c5f1a08a44d76fabfa205e12aab71c87bdb..3ebe26a080449f33336c3349d41579ac3d522dac 100644 (file)
@@ -546,7 +546,7 @@ static void silc_client_process_message(SilcClientInternal app)
 
     /* Allocate command context. This and its internals must be free'd 
        by the command routine receiving it. */
-    ctx = silc_calloc(1, sizeof(*ctx));
+    ctx = silc_client_command_alloc();
     ctx->client = app->client;
     ctx->conn = app->conn;
     ctx->command = cmd;
@@ -563,10 +563,10 @@ static void silc_client_process_message(SilcClientInternal app)
     if (len && app->conn && app->conn->current_channel &&
        app->conn->current_channel->on_channel == TRUE) {
       silc_print(app->client, "> %s", data);
-      silc_client_packet_send_to_channel(app->client, 
-                                        app->conn->sock,
-                                        app->conn->current_channel,
-                                        data, strlen(data), TRUE);
+      silc_client_send_channel_message(app->client, 
+                                      app->conn,
+                                      app->conn->current_channel,
+                                      data, strlen(data), TRUE);
     }
   }
 
index d0c3c9593a5f6f74fef57fe2a0f347817fc054af..8e02600276e9a53f7387680b2a30bc476297cff0 100644 (file)
@@ -32,6 +32,6 @@
 #include "command_reply.h"
 #include "idlist.h"
 #include "protocol.h"
-#include "ops.h"
+#include "silcapi.h"
 
 #endif
index d393ec3f0e970ef16818c2a8b2fd9d5ee2265b8c..5e567801f60775d801ff09c6d381e00263a2630c 100644 (file)
@@ -49,7 +49,7 @@ SilcClient silc_client_alloc(SilcClientOperations *ops, void *application)
   return new_client;
 }
 
-/* Free's client object */
+/* Frees client object and its internals. */
 
 void silc_client_free(SilcClient client)
 {
@@ -63,7 +63,7 @@ void silc_client_free(SilcClient client)
 
 /* Initializes the client. This makes all the necessary steps to make
    the client ready to be run. One must call silc_client_run to run the
-   client. */
+   client. Returns FALSE if error occured, TRUE otherwise. */
 
 int silc_client_init(SilcClient client)
 {
@@ -109,7 +109,8 @@ void silc_client_stop(SilcClient client)
   SILC_LOG_DEBUG(("Client stopped"));
 }
 
-/* Runs the client. */
+/* Runs the client. This starts the scheduler from the utility library.
+   When this functions returns the execution of the appliation is over. */
 
 void silc_client_run(SilcClient client)
 {
@@ -124,7 +125,9 @@ void silc_client_run(SilcClient client)
    connection to the connection table and returns a pointer to it. A client
    can have multiple connections to multiple servers. Every connection must
    be added to the client using this function. User data `context' may
-   be sent as argument. */
+   be sent as argument. This function is normally used only if the 
+   application performed the connecting outside the library. The library
+   however may use this internally. */
 
 SilcClientConnection silc_client_add_connection(SilcClient client,
                                                char *hostname,
@@ -161,7 +164,7 @@ SilcClientConnection silc_client_add_connection(SilcClient client,
   return conn;
 }
 
-/* Removes connection from client. */
+/* Removes connection from client. Frees all memory. */
 
 void silc_client_del_connection(SilcClient client, SilcClientConnection conn)
 {
@@ -218,7 +221,10 @@ silc_client_connect_to_server_internal(SilcClientInternalConnectContext *ctx)
 /* Connects to remote server. This is the main routine used to connect
    to SILC server. Returns -1 on error and the created socket otherwise. 
    The `context' is user context that is saved into the SilcClientConnection
-   that is created after the connection is created. */
+   that is created after the connection is created. Note that application
+   may handle the connecting process outside the library. If this is the
+   case then this function is not used at all. When the connecting is
+   done the `connect' client operation is called. */
 
 int silc_client_connect_to_server(SilcClient client, int port,
                                  char *host, void *context)
@@ -254,7 +260,9 @@ int silc_client_connect_to_server(SilcClient client, int port,
 /* Start SILC Key Exchange (SKE) protocol to negotiate shared secret
    key material between client and server.  This function can be called
    directly if application is performing its own connecting and does not
-   use the connecting provided by this library. */
+   use the connecting provided by this library. This function is normally
+   used only if the application performed the connecting outside the library.
+   The library however may use this internally. */
 
 int silc_client_start_key_exchange(SilcClient client,
                                   SilcClientConnection conn,
@@ -599,13 +607,13 @@ SILC_TASK_CALLBACK(silc_client_packet_process)
         close the connection */
       if (SILC_IS_DISCONNECTING(sock)) {
        client->ops->disconnect(client, conn);
-       silc_client_close_connection(client, sock);
+       silc_client_close_connection(client, conn);
        return;
       }
       
       SILC_LOG_DEBUG(("EOF from connection %d", sock->sock));
       client->ops->disconnect(client, conn);
-      silc_client_close_connection(client, sock);
+      silc_client_close_connection(client, conn);
       return;
     }
 
@@ -950,21 +958,22 @@ void silc_client_packet_send(SilcClient client,
   silc_client_packet_send_real(client, sock, force_send);
 }
 
-/* Sends packet to a channel. Packet to channel is always encrypted
+/* Sends packet to the `channel'. Packet to channel is always encrypted
    differently from "normal" packets. SILC header of the packet is 
    encrypted with the next receiver's key and the rest of the packet is
    encrypted with the channel specific key. Padding and HMAC is computed
-   with the next receiver's key. */
+   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_packet_send_to_channel(SilcClient client, 
-                                       SilcSocketConnection sock,
-                                       SilcChannelEntry channel,
-                                       unsigned char *data, 
-                                       unsigned int data_len, 
-                                       int force_send)
+void silc_client_send_channel_message(SilcClient client, 
+                                     SilcClientConnection conn,
+                                     SilcChannelEntry channel,
+                                     unsigned char *data, 
+                                     unsigned int data_len, 
+                                     int force_send)
 {
   int i;
-  SilcClientConnection conn = (SilcClientConnection)sock->user_data;
+  SilcSocketConnection sock = conn->sock;
   SilcBuffer payload;
   SilcPacketContext packetdata;
   SilcCipher cipher;
@@ -1062,16 +1071,17 @@ void silc_client_packet_send_to_channel(SilcClient client,
    normal session keys. Private messages are special packets in SILC
    network hence we need this own function for them. This is similiar
    to silc_client_packet_send_to_channel except that we send private
-   message. */
-
-void silc_client_packet_send_private_message(SilcClient client,
-                                            SilcSocketConnection sock,
-                                            SilcClientEntry client_entry,
-                                            unsigned char *data, 
-                                            unsigned int data_len, 
-                                            int force_send)
+   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,
+                                     SilcClientConnection conn,
+                                     SilcClientEntry client_entry,
+                                     unsigned char *data, 
+                                     unsigned int data_len, 
+                                     int force_send)
 {
-  SilcClientConnection conn = (SilcClientConnection)sock->user_data;
+  SilcSocketConnection sock = conn->sock;
   SilcBuffer buffer;
   SilcPacketContext packetdata;
   unsigned int nick_len;
@@ -1167,9 +1177,9 @@ void silc_client_packet_send_private_message(SilcClient client,
    for some information such as nickname etc. that are valid at all time. */
 
 void silc_client_close_connection(SilcClient client,
-                                 SilcSocketConnection sock)
+                                 SilcClientConnection conn)
 {
-  SilcClientConnection conn;
+  SilcSocketConnection sock = conn->sock;
 
   /* We won't listen for this connection anymore */
   silc_schedule_unset_listen_fd(sock->sock);
@@ -1186,8 +1196,6 @@ void silc_client_close_connection(SilcClient client,
 
   /* Free everything */
   if (sock->user_data) {
-    conn = (SilcClientConnection)sock->user_data;
-
     /* XXX Free all client entries and channel entries. */
 
     /* Clear ID caches */
@@ -1256,7 +1264,7 @@ void silc_client_disconnected_by_server(SilcClient client,
   silc_free(msg);
 
   SILC_SET_DISCONNECTED(sock);
-  silc_client_close_connection(client, sock);
+  silc_client_close_connection(client, sock->user_data);
 }
 
 /* Received error message from server. Display it on the screen. 
@@ -1366,7 +1374,7 @@ void silc_client_notify_by_server(SilcClient client,
       goto out;
 
     /* Find Client entry and if not found query it */
-    client_entry = silc_idlist_get_client_by_id(client, conn, client_id);
+    client_entry = silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry) {
       silc_client_notify_by_server_resolve(client, conn, packet, client_id);
       goto out;
@@ -1412,7 +1420,7 @@ void silc_client_notify_by_server(SilcClient client,
       goto out;
 
     /* Find Client entry and if not found query it */
-    client_entry = silc_idlist_get_client_by_id(client, conn, client_id);
+    client_entry = silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry) {
       silc_client_notify_by_server_resolve(client, conn, packet, client_id);
       goto out;
@@ -1471,7 +1479,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1518,7 +1526,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1566,7 +1574,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1615,7 +1623,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry and if not found query it */
     client_entry2 = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry2) {
       silc_client_notify_by_server_resolve(client, conn, packet, client_id);
       goto out;
@@ -1633,7 +1641,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find old Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1677,7 +1685,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1724,7 +1732,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -1747,7 +1755,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find target Client entry */
     client_entry2 = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry2)
       goto out;
 
@@ -1847,7 +1855,7 @@ void silc_client_notify_by_server(SilcClient client,
 
     /* Find Client entry */
     client_entry = 
-      silc_idlist_get_client_by_id(client, conn, client_id);
+      silc_client_get_client_by_id(client, conn, client_id);
     if (!client_entry)
       goto out;
 
@@ -2190,9 +2198,9 @@ void silc_client_private_message(SilcClient client,
       goto out;
 
     /* Send the away message */
-    silc_client_packet_send_private_message(client, sock, remote_client,
-                                           conn->away->away,
-                                           strlen(conn->away->away), TRUE);
+    silc_client_send_private_message(client, conn, remote_client,
+                                    conn->away->away,
+                                    strlen(conn->away->away), TRUE);
   }
 
  out:
index 864aaf8f533343fad035d5079b996f48a378c3d7..10fc21396b92a91c42758a51afa4f294cd4f1143 100644 (file)
@@ -29,7 +29,7 @@ typedef struct SilcClientConnectionObject *SilcClientConnection;
 
 #include "idlist.h"
 #include "command.h"
-#include "ops.h"
+#include "silcapi.h"
 
 /* Structure to hold ping time information. Every PING command will 
    add entry of this structure and is removed after reply to the ping
@@ -222,22 +222,8 @@ do {                                                       \
  (__sock) = (__x)->conns[__i]->sock;                   \
 } while(0)
 
-/* Prototypes */
-
-SilcClient silc_client_alloc(SilcClientOperations *ops, void *application);
-void silc_client_free(SilcClient client);
-int silc_client_init(SilcClient client);
-void silc_client_stop(SilcClient client);
-void silc_client_run(SilcClient client);
-SilcClientConnection silc_client_add_connection(SilcClient client,
-                                               char *hostname,
-                                               int port,
-                                               void *context);
-int silc_client_connect_to_server(SilcClient client, int port,
-                                 char *host, void *context);
-int silc_client_start_key_exchange(SilcClient client,
-                                  SilcClientConnection conn,
-                                   int fd);
+/* Prototypes (some of the prototypes are defined in the silcapi.h) */
+
 void silc_client_packet_send(SilcClient client, 
                             SilcSocketConnection sock,
                             SilcPacketType type, 
@@ -248,20 +234,6 @@ void silc_client_packet_send(SilcClient client,
                             unsigned char *data, 
                             unsigned int data_len, 
                             int force_send);
-void silc_client_packet_send_to_channel(SilcClient client, 
-                                       SilcSocketConnection sock,
-                                       SilcChannelEntry channel,
-                                       unsigned char *data, 
-                                       unsigned int data_len, 
-                                       int force_send);
-void silc_client_packet_send_private_message(SilcClient client,
-                                            SilcSocketConnection sock,
-                                            SilcClientEntry client_entry,
-                                            unsigned char *data, 
-                                            unsigned int data_len, 
-                                            int force_send);
-void silc_client_close_connection(SilcClient client,
-                                 SilcSocketConnection sock);
 void silc_client_disconnected_by_server(SilcClient client,
                                        SilcSocketConnection sock,
                                        SilcBuffer message);
index e81fa2303ca92db5cc93d989b34e5e0858fb2bcc..24406e0bfa428da264e48e2546da6e9ac2662bfc 100644 (file)
@@ -217,6 +217,16 @@ static void silc_client_command_destructor(void *context)
   silc_client_command_free((SilcClientCommandContext)context);
 }
 
+/* silc_client_get_client completion callback */
+void silc_client_command_completion(SilcClient client,
+                                   SilcClientConnection conn,
+                                   SilcClientEntry clients,
+                                   unsigned int clients_count,
+                                   void *context)
+{
+
+}
+
 /* Command WHOIS. This command is used to query information about 
    specific user. */
 
@@ -490,7 +500,7 @@ SILC_CLIENT_CMD_FUNC(invite)
   }
 
   /* Find channel entry */
-  channel_entry = silc_idlist_get_channel(client, conn, cmd->argv[2]);
+  channel_entry = silc_client_get_channel(client, conn, cmd->argv[2]);
   if (!channel_entry) {
     cmd->client->ops->say(cmd->client, conn, "You are not on that channel");
     COMMAND_ERROR;
@@ -531,7 +541,7 @@ SILC_TASK_CALLBACK(silc_client_command_quit_cb)
 
   /* Close connection */
   q->client->ops->disconnect(q->client, q->conn);
-  silc_client_close_connection(q->client, q->conn->sock);
+  silc_client_close_connection(q->client, q->conn->sock->user_data);
 
   silc_free(q);
 }
@@ -834,7 +844,7 @@ SILC_CLIENT_CMD_FUNC(cmode)
   } else {
     name = cmd->argv[1];
 
-    channel = silc_idlist_get_channel(cmd->client, conn, name);
+    channel = silc_client_get_channel(cmd->client, conn, name);
     if (!channel) {
       cmd->client->ops->say(cmd->client, conn, "You are on that channel");
       COMMAND_ERROR;
@@ -1023,7 +1033,7 @@ SILC_CLIENT_CMD_FUNC(cumode)
   } else {
     name = cmd->argv[1];
 
-    channel = silc_idlist_get_channel(cmd->client, conn, name);
+    channel = silc_client_get_channel(cmd->client, conn, name);
     if (!channel) {
       cmd->client->ops->say(cmd->client, conn, "You are on that channel");
       COMMAND_ERROR;
index 0236c812f28ddc836b2f91d62e149cf44bb0c70b..c50b8a5f8d5420e1a6d2f3fd0d5ac279cd33f9e7 100644 (file)
 
 #include "clientlibincludes.h"
 
-/* Finds client entry from cache by nickname. If the entry is not found
-   from the cache this function queries it from the server. If `server'
-   and `num' are defined as well thisk checks the match from multiple
-   cache entries thus providing support for multiple same nickname
-   handling. This also ignores case-sensitivity. */
+typedef struct {
+  SilcClientCommandContext cmd;
+  SilcGetClientCallback completion;
+  char *nickname;
+  char *server;
+  void *context;
+  int found;
+} *GetClientInternal;
+
+SILC_CLIENT_CMD_FUNC(get_client_callback)
+{
+  GetClientInternal i = (GetClientInternal)context;
+  SilcClientEntry *clients;
+  unsigned int clients_count;
+
+  /* Get the clients */
+  clients = silc_client_get_clients_local(i->cmd->client, i->cmd->conn,
+                                         i->nickname, i->server,
+                                         &clients_count);
+  if (clients) {
+    i->completion(i->cmd->client, i->cmd->conn, NULL, 0, i->context);
+    i->found = TRUE;
+    silc_free(clients);
+  }
+}
+
+static void silc_client_get_client_destructor(void *context)
+{
+  GetClientInternal i = (GetClientInternal)context;
+
+  if (i->found == FALSE)
+    i->completion(i->cmd->client, i->cmd->conn, NULL, 0, i->context);
+
+  silc_client_command_free(i->cmd);
+  if (i->nickname)
+    silc_free(i->nickname);
+  if (i->server)
+    silc_free(i->server);
+  silc_free(i);
+}
+
+/* Finds client entry or entries by the `nickname' and `server'. The 
+   completion callback will be called when the client entries has been found.
+
+   Note: this function is always asynchronous and resolves the client
+   information from the server. Thus, if you already know the client
+   information then use the silc_client_get_client_by_id function to
+   get the client entry since this function may be very slow and should
+   be used only to initially get the client entries. */
+
+void silc_client_get_clients(SilcClient client,
+                            SilcClientConnection conn,
+                            char *nickname,
+                            char *server,
+                            SilcGetClientCallback completion,
+                            void *context)
+{
+  char ident[512];
+  SilcClientCommandContext ctx;
+  GetClientInternal i = silc_calloc(1, sizeof(*i));
+      
+  /* No ID found. Do query from the server. The query is done by 
+     sending simple IDENTIFY command to the server. */
+  ctx = silc_client_command_alloc();
+  ctx->client = client;
+  ctx->conn = conn;
+  ctx->command = silc_client_command_find("IDENTIFY");
+  memset(ident, 0, sizeof(ident));
+  snprintf(ident, sizeof(ident), "IDENTIFY %s", nickname);
+  silc_parse_command_line(ident, &ctx->argv, &ctx->argv_lens, 
+                         &ctx->argv_types, &ctx->argc, 2);
+  ctx->command->cb(ctx);
+      
+  i->cmd = ctx;
+  i->nickname = nickname ? strdup(nickname) : NULL;
+  i->server = server ? strdup(server) : NULL;
+  i->completion = completion;
+  i->context = context;
+
+  /* Add pending callback */
+  silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, 
+                             ++conn->cmd_ident, 
+                             silc_client_get_client_destructor,
+                             silc_client_command_get_client_callback, 
+                             (void *)i);
+}
+
+/* Same as above function but does not resolve anything from the server.
+   This checks local cache and returns all clients from the cache. */
+
+SilcClientEntry *silc_client_get_clients_local(SilcClient client,
+                                              SilcClientConnection conn,
+                                              char *nickname,
+                                              char *server,
+                                              unsigned int *clients_count)
+{
+  SilcIDCacheEntry id_cache;
+  SilcIDCacheList list = NULL;
+  SilcClientEntry entry, *clients;
+  int i = 0;
+
+  /* Find ID from cache */
+  if (!silc_idcache_find_by_data_loose(conn->client_cache, nickname, &list))
+    return NULL;
+
+  if (silc_idcache_list_count(list) == 0)
+    return NULL;
+
+  clients = silc_calloc(silc_idcache_list_count(list), sizeof(*clients));
+  *clients_count = silc_idcache_list_count(list);
+
+  if (!server) {
+    /* Take all without any further checking */
+    silc_idcache_list_first(list, &id_cache);
+    while (id_cache) {
+      clients[i++] = id_cache->context;
+      if (!silc_idcache_list_next(list, &id_cache))
+       break;
+    }
+  } else {
+    /* Check multiple cache entries for match */
+    silc_idcache_list_first(list, &id_cache);
+    while (id_cache) {
+      entry = (SilcClientEntry)id_cache->context;
+      
+      if (entry->server && 
+         strncasecmp(server, entry->server, strlen(server))) {
+       if (!silc_idcache_list_next(list, &id_cache)) {
+         break;
+       } else {
+         continue;
+       }
+      }
+      
+      clients[i++] = id_cache->context;
+      if (!silc_idcache_list_next(list, &id_cache))
+       break;
+    }
+  }
+
+  if (list)
+    silc_idcache_list_free(list);
+
+  return clients;
+}
+
+/* The old style function to find client entry. This is used by the
+   library internally. If `query' is TRUE then the client information is
+   requested by the server. The pending command callback must be set
+   by the caller. */
 
 SilcClientEntry silc_idlist_get_client(SilcClient client,
                                       SilcClientConnection conn,
@@ -43,8 +188,8 @@ SilcClientEntry silc_idlist_get_client(SilcClient client,
   identify:
 
     if (query) {
-      SilcClientCommandContext ctx;
       char ident[512];
+      SilcClientCommandContext ctx;
       
       SILC_LOG_DEBUG(("Requesting Client ID from server"));
       
@@ -62,7 +207,7 @@ SilcClientEntry silc_idlist_get_client(SilcClient client,
       
       if (list)
        silc_idcache_list_free(list);
-      
+
       return NULL;
     }
     return NULL;
@@ -106,9 +251,10 @@ SilcClientEntry silc_idlist_get_client(SilcClient client,
   return entry;
 }
 
-/* Finds client entry from cache by Client ID. */
+/* Finds entry for client by the client's ID. Returns the entry or NULL
+   if the entry was not found. */
 
-SilcClientEntry silc_idlist_get_client_by_id(SilcClient client,
+SilcClientEntry silc_client_get_client_by_id(SilcClient client,
                                             SilcClientConnection conn,
                                             SilcClientID *client_id)
 {
@@ -127,9 +273,11 @@ SilcClientEntry silc_idlist_get_client_by_id(SilcClient client,
   return (SilcClientEntry)id_cache->context;
 }
 
-/* Finds channel entry from ID cache by channel name. */
+/* Finds entry for channel by the channel name. Returns the entry or NULL
+   if the entry was not found. It is found only if the client is joined
+   to the channel. */
 
-SilcChannelEntry silc_idlist_get_channel(SilcClient client,
+SilcChannelEntry silc_client_get_channel(SilcClient client,
                                         SilcClientConnection conn,
                                         char *channel)
 {
index 4b831db68c91ade45424989c0853f90e9a86256a..d5bfbf98ba4b5f8f19d26d104a71a88a741fd467 100644 (file)
@@ -70,7 +70,7 @@ typedef struct SilcChannelEntryStruct {
    commands to routers. */
 #define SILC_IDLIST_IDENT 3333
 
-/* Prototypes */
+/* Prototypes (some functions are defined in the silcapi.h) */
 
 SilcClientEntry silc_idlist_get_client(SilcClient client,
                                       SilcClientConnection conn,
@@ -78,11 +78,5 @@ SilcClientEntry silc_idlist_get_client(SilcClient client,
                                       char *server,
                                       unsigned int num,
                                       int query);
-SilcClientEntry silc_idlist_get_client_by_id(SilcClient client,
-                                            SilcClientConnection conn,
-                                            SilcClientID *client_id);
-SilcChannelEntry silc_idlist_get_channel(SilcClient client,
-                                        SilcClientConnection conn,
-                                        char *channel);
 
 #endif
index 1cc78d5267221991a71a638df27e964da501b76c..c50c2318c23e5959aaa76f9b8d776afcc5bd3638 100644 (file)
@@ -124,7 +124,7 @@ static void silc_client_protocol_ke_set_keys(SilcSKE ske,
 SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version,
                                     unsigned int len)
 {
-  SilcSocketConnection conn = (SilcSocketConnection)ske->sock->user_data;
+  SilcClientConnection conn = (SilcClientConnection)ske->sock->user_data;
   SilcClient client = (SilcClient)ske->user_data;
   SilcSKEStatus status = SILC_SKE_STATUS_OK;