Merged silc_1_1_branch to trunk.
[silc.git] / lib / silcclient / silcclient_entry.h
index 60ba5f0a0533a7fcd1780c9122e04071ee546ba0..4b57f859bcde386d125d05cc3be20e44160df1ad 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2006 Pekka Riikonen
+  Copyright (C) 2006 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
 
 */
 
+/****h* silcclient/Client Library Interface
+ *
+ * DESCRIPTION
+ *
+ * This header file includes the SilcClientEntry, SilcChannelEntry and
+ * SilcServer entry structures and various routines to search, resolve and
+ * handle these structures.
+ *
+ * All entries (SilcClientEntry, SilcChannelEntry and SilcServerEntry) are
+ * reference counted.  If application wishes to save an entry pointer it must
+ * always first acquire a reference.  The reference must be released once the
+ * entry is not needed anymore.  If application wants to read any data from
+ * the entry structure it must first lock the entry.  This protects access to
+ * the entries in multithreaded environment.  If threads are not used, locking
+ * the entries is not needed.  They however still must be referenced even
+ * when threads are not used.
+ *
+ ***/
+
 #ifndef SILCCLIENT_ENTRY_H
 #define SILCCLIENT_ENTRY_H
 
@@ -49,7 +68,7 @@
  *    it should always duplicated them.
  *
  *    None of the string arrays are set if the first character is '\0'.
- *    All string arrays are always NULL terminated.
+ *    All string arrays are always zero ('\0') terminated.
  *
  *    If application stores the SilcClientEntry it must always take
  *    a reference of it by calling silc_client_ref_client function.  The
@@ -59,7 +78,7 @@
  * SOURCE
  */
 struct SilcClientEntryStruct {
-  char nickname[128 + 1];           /* Nickname */
+  char nickname[256 + 1];           /* Nickname */
   char username[128 + 1];           /* Username */
   char hostname[256 + 1];           /* Hostname */
   char server  [256 + 1];           /* SILC server name */
@@ -105,14 +124,18 @@ struct SilcClientEntryStruct {
  */
 struct SilcChannelEntryStruct {
   char *channel_name;               /* Channel name */
+  char server[256 + 1];                     /* SILC server name */
   char *topic;                      /* Current topic, may be NULL */
   SilcPublicKey founder_key;        /* Founder key, may be NULL */
+  SilcDList channel_pubkeys;        /* Channel public keys, may be NULL */
   SilcChannelID id;                 /* Channel ID */
   SilcUInt32 mode;                  /* Channel mode, ChannelModes. */
   SilcUInt32 user_limit;            /* User limit on channel */
   SilcHashTable user_list;          /* Joined users.  Key to hash table is
                                        SilcClientEntry, context is
                                        SilcChannelUser. */
+  const char *cipher;               /* Current channel cipher algorithm*/
+  const char *hmac;                 /* Current channel HMAC algorithm */
 
   void *context;                    /* Application specific context */
   SilcChannelEntryInternal internal;
@@ -194,23 +217,66 @@ typedef void (*SilcGetClientCallback)(SilcClient client,
                                      SilcDList clients,
                                      void *context);
 
+/****f* silcclient/SilcClientAPI/silc_client_lock_client
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_lock_client(SilcClientEntry client_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Acquires lock for the client entry indicate by `client_entry'.  When
+ *    application wants to access `client_entry' it must lock the entry
+ *    before reading any data from the `client_entry'.  The lock must be
+ *    unlocked with silc_client_unlock_client.
+ *
+ * NOTES
+ *
+ *    The entry must be unlocked before calling any Client Library API
+ *    functions where the entry is given as argument, unless otherwise stated.
+ *
+ *    The entry should not be locked for long periods of time.  For example,
+ *    it is not appropriate to hold the lock while waiting user interface to
+ *    be drawn.  The appropriate way is to read the data and duplicate it if
+ *    necessary, unlock the entry, then draw on the user interface.
+ *
+ *    This function is not needed if application is not multithreaded.
+ *
+ ***/
+void silc_client_lock_client(SilcClientEntry client_entry);
+
+/****f* silcclient/SilcClientAPI/silc_client_unlock_client
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_unlock_client(SilcClientEntry client_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Releases the lock acquired with silc_client_lock_client.
+ *
+ ***/
+void silc_client_unlock_client(SilcClientEntry client_entry);
+
 /****f* silcclient/SilcClientAPI/silc_client_ref_client
  *
  * SYNOPSIS
  *
- *    void silc_client_ref_client(SilcClient client,
- *                                SilcClientConnection conn,
- *                                SilcClientEntry client_entry);
+ *    SilcClientEntry
+ *    silc_client_ref_client(SilcClient client,
+ *                           SilcClientConnection conn,
+ *                           SilcClientEntry client_entry);
  *
  * DESCRIPTION
  *
  *    Takes a reference of the client entry indicated by `client_entry'
  *    The reference must be released by calling silc_client_unref_client
- *    after it is not needed anymore.
+ *    after it is not needed anymore.  Returns `client_entry'.
  *
  ***/
-void silc_client_ref_client(SilcClient client, SilcClientConnection conn,
-                           SilcClientEntry client_entry);
+SilcClientEntry silc_client_ref_client(SilcClient client,
+                                      SilcClientConnection conn,
+                                      SilcClientEntry client_entry);
 
 /****f* silcclient/SilcClientAPI/silc_client_unref_client
  *
@@ -262,8 +328,13 @@ void silc_client_list_free(SilcClient client, SilcClientConnection conn,
  *    completion callback will be called when the client entries has been
  *    found.  After the server returns the client information it is cached
  *    and can be accesses locally at a later time.  The resolving is done
- *    with IDENTIFY command.  The `server' may be NULL.  Returns 0 on
- *    error and the command identifier used with the command otherwise.
+ *    with IDENTIFY command.  The `server' may be NULL.  The server
+ *    associated with the nickname may be in the `nickname' (nick@server).
+ *    The `nickname' may also be a formatted nickname in which case the
+ *    formatting is ignored and the base nickname is used.  If the nickname
+ *    is formatted it must be formatted as defined in SilcClientParams.
+ *    Returns 0 on error and the command identifier used with the command
+ *    otherwise.
  *
  * NOTES
  *
@@ -305,8 +376,13 @@ SilcUInt16 silc_client_get_clients(SilcClient client,
  *    completion callback will be called when the client entries has been
  *    found.  After the server returns the client information it is cached
  *    and can be accesses locally at a later time.  The resolving is done
- *    with WHOIS command.  The `server' may be NULL.  Returns 0 on error,
- *    and the command identifier used with the command otherwise.
+ *    with WHOIS command.  The `server' may be NULL.  The server
+ *    associated with the nickname may be in the `nickname' (nick@server).
+ *    The `nickname' may also be a formatted nickname in which case the
+ *    formatting is ignored and the base nickname is used.  If the nickname
+ *    is formatted it must be formatted as defined in SilcClientParams.
+ *    Returns 0 on error and the command identifier used with the command
+ *    otherwise.
  *
  *    If the `attributes' is non-NULL then the buffer includes Requested
  *    Attributes which can be used to fetch very detailed information
@@ -337,19 +413,20 @@ SilcUInt16 silc_client_get_clients_whois(SilcClient client,
  *    SilcDList silc_client_get_clients_local(SilcClient client,
  *                                            SilcClientConnection conn,
  *                                            const char *nickname,
- *                                            const char *format);
+ *                                            SilcBool return_all);
  *
  * DESCRIPTION
  *
  *    Same as silc_client_get_clients function but does not resolve anything
- *    from the server.  This checks local cache and returns all matching
- *    clients from the local cache.  If none was found this returns NULL.
- *    The `nickname' is the real nickname of the client, and the `format'
- *    is the formatted nickname to find exact match from multiple found
- *    entries.  The format must be same as given in the SilcClientParams
- *    structure to the client library.  If the `format' is NULL all found
- *    clients by `nickname' are returned.  The caller must free the
- *    returned list by silc_client_list_free function.
+ *    from the server.  This checks local cache and returns matching clients
+ *    from the local cache.  If none was found this returns NULL.  The
+ *    `nickname' is the nickname to find and it may be a formatted nickname
+ *    or a base nickname.  If the `return_all' is TRUE this call will return
+ *    all clients matching the `nickname' base.  If it is FALSE this will
+ *    return the exact match if `nickname' is a formatted nickname or the
+ *    first matching nickname if it is not formatted.  The formatted nickname
+ *    must of the format specified in SilcClientParams.  The caller must free
+ *    the returned list by calling silc_client_list_free function.
  *
  * NOTES
  *
@@ -364,82 +441,7 @@ SilcUInt16 silc_client_get_clients_whois(SilcClient client,
 SilcDList silc_client_get_clients_local(SilcClient client,
                                        SilcClientConnection conn,
                                        const char *nickname,
-                                       const char *format);
-
-/****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
- *
- * SYNOPSIS
- *
- *    void silc_client_get_clients_by_channel(SilcClient client,
- *                                            SilcClientConnection conn,
- *                                            SilcChannelEntry channel,
- *                                            SilcGetClientCallback completion,
- *                                            void *context);
- *
- * DESCRIPTION
- *
- *    Gets client entries by the channel indicated by `channel'. Thus,
- *    it resovles the users currently on that channel. If all users are
- *    already resolved this returns the users from the channel. If the
- *    users are resolved only partially this resolves the complete user
- *    information. If no users are resolved on this channel at all, this
- *    calls USERS command to resolve all users on the channel. The `completion'
- *    will be called after the entries are available. When server returns
- *    the client information it will be cached and can be accessed locally
- *    at a later time.
- *
- *    This function can be used for example in SILC_COMMAND_JOIN command
- *    reply handling in application to resolve users on that channel.  It
- *    also can be used after calling silc_client_get_channel_resolve to
- *    resolve users on that channel.
- *
- * NOTES
- *
- *    The resolving is done with WHOIS command.  For this reason this
- *    command may take a long time because it resolves detailed user
- *    information.
- *
- ***/
-void silc_client_get_clients_by_channel(SilcClient client,
-                                       SilcClientConnection conn,
-                                       SilcChannelEntry channel,
-                                       SilcGetClientCallback completion,
-                                       void *context);
-
-/****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
- *
- * SYNOPSIS
- *
- *    void silc_client_get_clients_by_list(SilcClient client,
- *                                         SilcClientConnection conn,
- *                                         SilcUInt32 list_count,
- *                                         SilcBuffer client_id_list,
- *                                         SilcGetClientCallback completion,
- *                                         void *context);
- *
- * DESCRIPTION
- *
- *    Gets client entries by the list of client ID's `client_id_list'. This
- *    always resolves those client ID's it doesn't know about from the server.
- *    The `client_id_list' is a list of ID Payloads added one after other.
- *    JOIN command reply and USERS command reply for example returns this sort
- *    of list. The `completion' will be called after the entries are available.
- *    When server returns the client information it will be cached and can be
- *    accessed locally at a later time.  The resolving is done with WHOIS
- *    command.
- *
- * NOTES
- *
- *    If even after resolving some Client ID in the `client_id_list' is
- *    unknown it will be ignored and error is not returned.
- *
- ***/
-void silc_client_get_clients_by_list(SilcClient client,
-                                    SilcClientConnection conn,
-                                    SilcUInt32 list_count,
-                                    SilcBuffer client_id_list,
-                                    SilcGetClientCallback completion,
-                                    void *context);
+                                       SilcBool return_all);
 
 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
  *
@@ -470,7 +472,7 @@ SilcClientEntry silc_client_get_client_by_id(SilcClient client,
  *
  * SYNOPSIS
  *
- *    void
+ *    SilcUInt16
  *    silc_client_get_client_by_id_resolve(SilcClient client,
  *                                         SilcClientConnection conn,
  *                                         SilcClientID *client_id,
@@ -487,6 +489,9 @@ SilcClientEntry silc_client_get_client_by_id(SilcClient client,
  *    cache and can be accessed locally at a later time. The resolving
  *    is done by sending WHOIS command.
  *
+ *    Returns command identifier for the resolving.  It can be used to attach
+ *    a pending command to it, if needed.  Returns 0 on error.
+ *
  *    If the `attributes' is non-NULL then the buffer includes Requested
  *    Attributes which can be used to fetch very detailed information
  *    about the user. If it is NULL then only normal WHOIS query is
@@ -495,12 +500,13 @@ SilcClientEntry silc_client_get_client_by_id(SilcClient client,
  *    function.
  *
  ***/
-void silc_client_get_client_by_id_resolve(SilcClient client,
-                                         SilcClientConnection conn,
-                                         SilcClientID *client_id,
-                                         SilcBuffer attributes,
-                                         SilcGetClientCallback completion,
-                                         void *context);
+SilcUInt16
+silc_client_get_client_by_id_resolve(SilcClient client,
+                                    SilcClientConnection conn,
+                                    SilcClientID *client_id,
+                                    SilcBuffer attributes,
+                                    SilcGetClientCallback completion,
+                                    void *context);
 
 /* SilcChannelEntry routines */
 
@@ -536,23 +542,66 @@ typedef void (*SilcGetChannelCallback)(SilcClient client,
                                       SilcDList channels,
                                       void *context);
 
+/****f* silcclient/SilcClientAPI/silc_client_lock_channel
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_lock_channel(SilcChannelEntry channel_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Acquires lock for the channel entry indicate by `channel_entry'.  When
+ *    application wants to access `channel_entry' it must lock the entry
+ *    before reading any data from the `channel_entry'.  The lock must be
+ *    unlocked with silc_client_unlock_channel.
+ *
+ * NOTES
+ *
+ *    The entry must be unlocked before calling any Client Library API
+ *    functions where the entry is given as argument, unless otherwise stated.
+ *
+ *    The entry should not be locked for long periods of time.  For example,
+ *    it is not appropriate to hold the lock while waiting user interface to
+ *    be drawn.  The appropriate way is to read the data and duplicate it if
+ *    necessary, unlock the entry, then draw on the user interface.
+ *
+ *    This function is not needed if application is not multithreaded.
+ *
+ ***/
+void silc_client_lock_channel(SilcChannelEntry channel_entry);
+
+/****f* silcclient/SilcClientAPI/silc_client_unlock_channel
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_unlock_channel(SilcChannelEntry channel_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Releases the lock acquired with silc_client_lock_channel.
+ *
+ ***/
+void silc_client_unlock_channel(SilcChannelEntry channel_entry);
+
 /****f* silcclient/SilcClientAPI/silc_client_ref_channel
  *
  * SYNOPSIS
  *
- *    void silc_client_ref_channel(SilcClient client,
- *                                 SilcClientConnection conn,
- *                                 SilcChannelEntry channel_entry);
+ *    SilcChannelEntry
+ *    silc_client_ref_channel(SilcClient client,
+ *                            SilcClientConnection conn,
+ *                            SilcChannelEntry channel_entry);
  *
  * DESCRIPTION
  *
  *    Takes a reference of the channel entry indicated by `channel_entry'
  *    The reference must be released by calling silc_client_unref_channel
- *    after it is not needed anymore.
+ *    after it is not needed anymore.  Returns `channel_entry'.
  *
  ***/
-void silc_client_ref_channel(SilcClient client, SilcClientConnection conn,
-                            SilcChannelEntry channel_entry);
+SilcChannelEntry silc_client_ref_channel(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcChannelEntry channel_entry);
 
 /****f* silcclient/SilcClientAPI/silc_client_unref_channel
  *
@@ -630,7 +679,7 @@ SilcChannelEntry silc_client_get_channel(SilcClient client,
  *    Resolves entry for channel by the channel name from the server.
  *    The resolving is done with IDENTIFY command. Note that users on
  *    the channel are not resolved at the same time. Use for example
- *    silc_client_get_clients_by_channel to resolve all users on a channel.
+ *    USERS command to resolve all users on a channel.
  *
  ***/
 void silc_client_get_channel_resolve(SilcClient client,
@@ -669,7 +718,7 @@ SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
  *
  * SYNOPSIS
  *
- *    void
+ *    SilcUInt16
  *    silc_client_get_channel_by_id_resolve(SilcClient client,
  *                                          SilcClientConnection conn,
  *                                          SilcChannelID *channel_id,
@@ -682,16 +731,19 @@ SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
  *    by the `channel_id'. Use this only if you know that you do not have
  *    the entry cached locally. The resolving is done with IDENTIFY command.
  *
+ *    Returns command identifier for the resolving.  It can be used to attach
+ *    a pending command to it, if needed.  Returns 0 on error.
+ *
  *    Note that users on the channel are not resolved at the same time.
- *    Use for example silc_client_get_clients_by_channel to resolve all
- *    users on a channel.
+ *    Use for example USERS command to resolve all users on a channel.
  *
  ***/
-void silc_client_get_channel_by_id_resolve(SilcClient client,
-                                          SilcClientConnection conn,
-                                          SilcChannelID *channel_id,
-                                          SilcGetChannelCallback completion,
-                                          void *context);
+SilcUInt16
+silc_client_get_channel_by_id_resolve(SilcClient client,
+                                     SilcClientConnection conn,
+                                     SilcChannelID *channel_id,
+                                     SilcGetChannelCallback completion,
+                                     void *context);
 
 /* SilcServerEntry routines */
 
@@ -727,23 +779,66 @@ typedef void (*SilcGetServerCallback)(SilcClient client,
                                      SilcDList servers,
                                      void *context);
 
+/****f* silcclient/SilcClientAPI/silc_client_lock_server
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_lock_server(SilcServerEntry server_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Acquires lock for the server entry indicate by `server_entry'.  When
+ *    application wants to access `server_entry' it must lock the entry
+ *    before reading any data from the `server_entry'.  The lock must be
+ *    unlocked with silc_client_unlock_server.
+ *
+ * NOTES
+ *
+ *    The entry must be unlocked before calling any Client Library API
+ *    functions where the entry is given as argument, unless otherwise stated.
+ *
+ *    The entry should not be locked for long periods of time.  For example,
+ *    it is not appropriate to hold the lock while waiting user interface to
+ *    be drawn.  The appropriate way is to read the data and duplicate it if
+ *    necessary, unlock the entry, then draw on the user interface.
+ *
+ *    This function is not needed if application is not multithreaded.
+ *
+ ***/
+void silc_client_lock_server(SilcServerEntry server_entry);
+
+/****f* silcclient/SilcClientAPI/silc_client_unlock_server
+ *
+ * SYNOPSIS
+ *
+ *    void silc_client_unlock_server(SilcServerEntry server_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Releases the lock acquired with silc_client_lock_server.
+ *
+ ***/
+void silc_client_unlock_server(SilcServerEntry server_entry);
+
 /****f* silcclient/SilcClientAPI/silc_client_ref_server
  *
  * SYNOPSIS
  *
- *    void silc_client_ref_server(SilcClient client,
- *                                SilcClientConnection conn,
- *                                SilcServerEntry server_entry);
+ *    SilcServerEntry
+ *    silc_client_ref_server(SilcClient client,
+ *                           SilcClientConnection conn,
+ *                           SilcServerEntry server_entry);
  *
  * DESCRIPTION
  *
  *    Takes a reference of the server entry indicated by `server_entry'
  *    The reference must be released by calling silc_client_unref_server
- *    after it is not needed anymore.
+ *    after it is not needed anymore.  Returns `server_entry'.
  *
  ***/
-void silc_client_ref_server(SilcClient client, SilcClientConnection conn,
-                            SilcServerEntry server_entry);
+SilcServerEntry silc_client_ref_server(SilcClient client,
+                                      SilcClientConnection conn,
+                                      SilcServerEntry server_entry);
 
 /****f* silcclient/SilcClientAPI/silc_client_unref_server
  *
@@ -819,7 +914,7 @@ SilcServerEntry silc_client_get_server_by_id(SilcClient client,
  *
  * SYNOPSIS
  *
- *    void
+ *    SilcUInt16
  *    silc_client_get_server_by_id_resolve(SilcClient client,
  *                                         SilcClientConnection conn,
  *                                         SilcServerID *server_id,
@@ -831,11 +926,15 @@ SilcServerEntry silc_client_get_server_by_id(SilcClient client,
  *    Resolves the server information by the `server_id'.  The resolved
  *    server is returned into the `completion' callback.
  *
+ *    Returns command identifier for the resolving.  It can be used to attach
+ *    a pending command to it, if needed.  Returns 0 on error.
+ *
  ***/
-void silc_client_get_server_by_id_resolve(SilcClient client,
-                                         SilcClientConnection conn,
-                                         SilcServerID *server_id,
-                                         SilcGetServerCallback completion,
-                                         void *context);
+SilcUInt16
+silc_client_get_server_by_id_resolve(SilcClient client,
+                                    SilcClientConnection conn,
+                                    SilcServerID *server_id,
+                                    SilcGetServerCallback completion,
+                                    void *context);
 
 #endif /* SILCCLIENT_ENTRY_H */