Fixed CMODE sending and receiving when it comes to channel
[silc.git] / lib / silcclient / silcclient.h
index 69083194cebaddbe5760cd83e6d10e9208be9d1d..f491e37e75bc5d0a8712f902d1a48546a404221f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2006 Pekka Riikonen
+  Copyright (C) 2000 - 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
  * DESCRIPTION
  *
  * This interface defines the SILC Client Library API for the application.
- * The client operations are defined first.  These are callback functions that
- * the application MUST implement since the library may call the functions
- * at any time.  At the end of file is the API for the application that
- * it can use from the library.  This is the only file that the application
- * may include from the SIlC Client Library.
- *
- * o SILC Client Operations
- *
- *   These functions must be implemented by the application calling the SILC
- *   client library. The client library can call these functions at any time.
- *
- *   To use this structure: define a static SilcClientOperations variable,
- *   fill it and pass its pointer to silc_client_alloc function.
- *
- * o SILC Client Library API
- *
- *   This is the API that is published by the SILC Client Library for the
- *   applications.  These functions are implemented in the SILC Client Library.
- *   Application may freely call these functions from the library.
+ * The Client Library is a full featured SILC client without user interface.
+ * A simple interface called SILC Client Operations (SilcClientOperations)
+ * is provided for applications to implmeent the necessary functions to use
+ * the client library.  The silcclient.h header file includes client library
+ * API, such as command handling and message sending.  The silcclient_entry.h
+ * header file includes entry handling, such as channel and user entry
+ * handling.
+ *
+ * Practically all functions in the Client Library API accepts SilcClient
+ * and SilcClientConnection as their first two argument.  The first argument
+ * is the actual SilcClient context and the second is the SilcClientConnection
+ * context of the connection in question.  Application may create and handle
+ * multiple connections in one SilcClient.  Connections can be created to
+ * servers and other clients.
+ *
+ * The Client Library support multiple threads and is threads safe if used
+ * correctly.  Messages can be sent from multiple threads without any
+ * locking.  Messages however are always received only in one thread unless
+ * message waiting (see silc_client_private_message_wait as an example) is
+ * used.  The threads can be turned on and off by giving a parameter to the
+ * SilcClient.  When turned on, each new connection to remote host is always
+ * executed in an own thread.  All tasks related to that connection are then
+ * executed in that thread.  This means that client operation callbacks for
+ * that connections may be called from threads and application will need to
+ * employ concurrency control if the callbacks need to access shared data
+ * in the application.  Messages are also received in that thread.
  *
  ***/
 
@@ -135,12 +142,21 @@ typedef void (*SilcClientStopped)(SilcClient client, void *context);
  *    by the `status'.  It is called after the connection has been
  *    established to the remote host and when connection is disconnected
  *    by the remote host.  The `context' is the context given as argument
- *    to the connecting function.
+ *    to the connecting function.  If the `status' is an error the `error'
+ *    may indicate more detailed error.  If `error' is SILC_STATUS_OK no
+ *    detailed error message is available.
  *
  *    When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
  *    indicate the reason for disconnection.  If the `message' is non-NULL
  *    it delivers error or disconnection message.
  *
+ *    The `conn' is the connection to the remote host.  In case error
+ *    occurred the `conn' may be NULL, however, in some cases a valid `conn'
+ *    is returned even in error.  If `conn' is non-NULL the receiver is
+ *    responsible of closing the connection with silc_client_close_connection
+ *    function, except when SILC_CLINET_CONN_DISCONNECTED or some error
+ *    was received.  In these cases the library will close the connection.
+ *
  ***/
 typedef void (*SilcClientConnectCallback)(SilcClient client,
                                          SilcClientConnection conn,
@@ -375,7 +391,8 @@ typedef struct {
  */
 struct SilcChannelPrivateKeyStruct {
   char *name;                        /* Application given name */
-  SilcCipher cipher;                 /* The cipher and key */
+  SilcCipher send_key;               /* The cipher and key */
+  SilcCipher receive_key;            /* The cipher and key */
   SilcHmac hmac;                     /* The HMAC and hmac key */
 };
 /***/
@@ -427,18 +444,23 @@ typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
  *
  * DESCRIPTION
  *
- *    Authentication method resolving callback. This is called by the
- *    application to return the resolved authentication method. The client
+ *    Authentication data resolving callback. This is called by the
+ *    application to return the resolved authentication data. The client
  *    library has called the get_auth_method client operation and given
- *    this function pointer as argument. The `success' will indicate whether
- *    the authentication method could be resolved. The `auth_meth' is the
- *    resolved authentication method. The `auth_data' and the `auth_data_len'
+ *    this function pointer as argument. The `auth_meth' is the selected
+ *    authentication method. The `auth_data' and the `auth_data_len'
  *    are the resolved authentication data. The `context' is the libary's
  *    context sent to the get_auth_method client operation.
  *
+ *    If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
+ *    is the passphrase and its length.  If it is SILC_AUTH_PUBLIC_KEY the
+ *    `auth' must be NULL.  The library will use the private key given as
+ *    argument to silc_client_connect_to_server, silc_client_connect_to_client
+ *    or silc_client_key_exchange.  If it is SILC_AUTH_NONE, both `auth' and
+ *    `auth_len' are ignored.
+ *
  ***/
-typedef void (*SilcGetAuthMeth)(SilcBool success,
-                               SilcAuthMethod auth_meth,
+typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
                                void *auth, SilcUInt32 auth_len,
                                void *context);
 
@@ -459,6 +481,7 @@ typedef enum {
   SILC_CLIENT_MESSAGE_INFO,           /* Informational */
   SILC_CLIENT_MESSAGE_WARNING,        /* Warning */
   SILC_CLIENT_MESSAGE_ERROR,          /* Error */
+  SILC_CLIENT_MESSAGE_COMMAND_ERROR,   /* Error during command */
   SILC_CLIENT_MESSAGE_AUDIT,          /* Auditable */
 } SilcClientMessageType;
 /***/
@@ -492,7 +515,8 @@ typedef struct {
      The `channel' is the channel. The `message' is the message.  Note
      that `message' maybe NULL.  The `flags' indicates message flags
      and it is used to determine how the message can be interpreted
-     (like it may tell the message is multimedia message). */
+     (like it may tell the message is multimedia message).  The `payload'
+     may be used to retrieve all the details of the message. */
   void (*channel_message)(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, SilcChannelEntry channel,
                          SilcMessagePayload payload,
@@ -504,20 +528,16 @@ typedef struct {
      message. The message is `message'and maybe NULL.  The `flags'
      indicates message flags  and it is used to determine how the message
      can be interpreted (like it may tell the message is multimedia
-     message). */
+     message).  The `payload' may be used to retrieve all the details of
+     the message. */
   void (*private_message)(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, SilcMessagePayload payload,
                          SilcMessageFlags flags, const unsigned char *message,
                          SilcUInt32 message_len);
 
-  /* Notify message to the client. The notify arguments are sent in the
-     same order as servers sends them. The arguments are same as received
-     from the server except for ID's.  If ID is received application receives
-     the corresponding entry to the ID. For example, if Client ID is received
-     application receives SilcClientEntry.  Also, if the notify type is
-     for channel the channel entry is sent to application (even if server
-     does not send it because client library gets the channel entry from
-     the Channel ID in the packet's header). */
+  /* Notify message to the client.  The arguments are notify `type' specific.
+     See separate documentation in the Toolkit Reference Manual for the notify
+     arguments. */
   void (*notify)(SilcClient client, SilcClientConnection conn,
                 SilcNotifyType type, ...);
 
@@ -534,52 +554,49 @@ typedef struct {
                  SilcBool success, SilcCommand command, SilcStatus status,
                  SilcUInt32 argc, unsigned char **argv);
 
-  /* Command reply handler. This function is called always in the command reply
-     function. If error occurs it will be called as well. Normal scenario
-     is that it will be called after the received command data has been parsed
-     and processed. The function is used to pass the received command data to
-     the application.
-
-     `conn' is the associated client connection. `cmd_payload' is the command
-     payload data received from server and it can be ignored. It is provided
-     if the application would like to re-parse the received command data,
-     however, it must be noted that the data is parsed already by the library
-     thus the payload can be ignored. `success' is FALSE if error occurred.
-     In this case arguments are not sent to the application. The `status' is
-     the command reply status server returned. The `command' is the command
-     reply being processed. The function has variable argument list and each
-     command defines the number and type of arguments it passes to the
-     application (on error they are not sent).
-
-     The arguments are sent in the same order as servers sends them.  The
-     arguments are same as received from the server except for ID's.  If
-     ID is received application receives the corresponding entry to the
-     ID. For example, if Client ID is receives application receives
-     SilcClientEntry. */
+  /* Command reply handler.  Delivers a reply to command that was sent
+     earlier.  The `conn' is the associated client connection.  The `command'
+     indicates the command reply type.  If the `status' other than
+     SILC_STATUS_OK an error occurred.  In this case the `error' will indicate
+     the error.  It is possible to receive list of command replies and list
+     of errors.  In this case the `status' will indicate it is an list entry
+     (the `status' is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM and/or
+     SILC_STATUS_LIST_END).
+
+     The arguments received in `ap' are command specific.  See a separate
+     documentation in the Toolkit Reference Manual for the command reply
+     arguments. */
   void (*command_reply)(SilcClient client, SilcClientConnection conn,
                        SilcCommand command, SilcStatus status,
                        SilcStatus error, va_list ap);
 
   /* Find authentication method and authentication data by hostname and
-     port. The hostname may be IP address as well. When the authentication
-     method has been resolved the `completion' callback with the found
-     authentication method and authentication data is called. The `conn'
-     may be NULL. */
+     port. The hostname may be IP address as well. The `auth_method' is
+     the authentication method the remote connection requires.  It is
+     however possible that remote accepts also some other authentication
+     method.  Application should use the method that may have been
+     configured for this connection.  If none has been configured it should
+     use the required `auth_method'.  If the `auth_method' is
+     SILC_AUTH_NONE, server does not require any authentication or the
+     required authentication method is not known.  The `completion'
+     callback must be called to deliver the chosen authentication method
+     and data. The `conn' may be NULL. */
   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
                          char *hostname, SilcUInt16 port,
+                         SilcAuthMethod auth_method,
                          SilcGetAuthMeth completion, void *context);
 
-  /* Verifies received public key. The `conn_type' indicates which entity
-     (server, client etc.) has sent the public key. If user decides to trust
-     the application may save the key as trusted public key for later
-     use. The `completion' must be called after the public key has been
-     verified. */
+  /* Called to verify received public key. The `conn_type' indicates which
+     entity (server or client) has sent the public key. If user decides to
+     trust the key the application may save the key as trusted public key for
+     later use. The `completion' must be called after the public key has
+     been verified. */
   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
                            SilcConnectionType conn_type,
                            SilcPublicKey public_key,
                            SilcVerifyPublicKey completion, void *context);
 
-  /* Ask (interact, that is) a passphrase from user. The passphrase is
+  /* Ask from end user a passphrase or a password. The passphrase is
      returned to the library by calling the `completion' callback with
      the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
      if not then the library will attempt to encode. */
@@ -588,7 +605,7 @@ typedef struct {
 
   /* Called to indicate that incoming key agreement request has been
      received.  If the application wants to perform key agreement it may
-     call silc_client_perform_key_agreement to initiate key agreementn or
+     call silc_client_perform_key_agreement to initiate key agreement or
      silc_client_send_key_agreement to provide connection point to the
      remote client in case the `hostname' is NULL.  If key agreement is
      not desired this request can be ignored.  The `protocol' is either
@@ -632,12 +649,6 @@ typedef struct {
      in the callbacks to protect application specific data. */
   SilcBool threads;
 
-  /* Connection authentication method request timeout. If server does not
-     reply back the current authentication method when we've requested it
-     in this time interval we'll assume the reply will not come at all.
-     If set to zero, the default value (2 seconds) will be used. */
-  unsigned int connauth_request_secs;
-
   /* Nickname format string. This can be used to order the client library
      to save the nicknames in the library in a certain format. Since
      nicknames are not unique in SILC it is possible to have multiple same
@@ -649,20 +660,18 @@ typedef struct {
      Following format types are available:
 
      %n  nickname      - the real nickname returned by the server (mandatory)
+     %a  number        - ascending number in case there are several
+                         same nicknames (fe. nick#2 and nick#3)
      %h  hostname      - the stripped hostname of the client
      %H  full hostname - the full hostname of the client
-     %s  server name   - the server name the client is connected
-     %S  full server   - the full server name the client is connected
-     %a  number        - ascending number in case there are several
-                         same nicknames (fe. nick@host and nick@host2)
 
-     Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
-                             "%a!%n@%s"  (fe. nick@server, 2!nick@server)
-                            "%n@%H"     (fe. nick@host.domain.com)
+     Example format strings: "%n#%a"     (fe. nick#2, nick#3)
+                             "%n@%h%a"   (fe. nick@host, nick@host2)
+                             "%a!%n@%h"  (fe. nick@host, 2!nick@host)
 
      Note that there must always be some separator characters around '%n'
      format.  It is not possible to put format characters before or after
-     '%n' without separators (such ash '@').  Also note that the separator
+     '%n' without separators (such ash '#').  Also note that the separator
      character should be a character that cannot be part of normal nickname.
   */
   char nickname_format[32];
@@ -745,10 +754,10 @@ void silc_client_free(SilcClient client);
  *    operating system, `hostname' is the client's host name and the
  *    `realname' is the user's real name.
  *
- *    The `running' callback is called after the client is running after
- *    silc_client_run or silc_client_run_one has been called.  Application
- *    may start using the Client library API after that.  Setting the
- *    callback is optional, but recommended.
+ *    The `running' callback with `context' is called after the client is
+ *    running after silc_client_run or silc_client_run_one has been called.
+ *    Application may start using the Client library API after that.  Setting
+ *    the callback is optional, but recommended.
  *
  ***/
 SilcBool silc_client_init(SilcClient client, const char *username,
@@ -789,7 +798,6 @@ void silc_client_run(SilcClient client);
  ***/
 void silc_client_run_one(SilcClient client);
 
-
 /****f* silcclient/SilcClientAPI/silc_client_stop
  *
  * SYNOPSIS
@@ -907,7 +915,7 @@ typedef struct {
   /* Rekey timeout in seconds.  The client will perform rekey in this
      time interval.  If set to zero, the default value will be used
      (3600 seconds, 1 hour). */
-  unsigned int rekey_secs;
+  SilcUInt32 rekey_secs;
 
   /* If this is set to TRUE then the client will ignore all incoming
      Requested Attributes queries and does not reply anything back.  This
@@ -929,6 +937,7 @@ typedef struct {
  *    silc_client_connect_to_server(SilcClient client,
  *                                  SilcClientConnectionParams *params,
  *                                  SilcPublicKey public_key,
+ *                                  SilcPrivateKey private_key,
  *                                  char *remote_host, int port,
  *                                  SilcClientConnectCallback callback,
  *                                  void *context);
@@ -971,6 +980,7 @@ silc_client_connect_to_server(SilcClient client,
  *    silc_client_connect_to_client(SilcClient client,
  *                                  SilcClientConnectionParams *params,
  *                                  SilcPublicKey public_key,
+ *                                  SilcPrivateKey private_key,
  *                                  char *remote_host, int port,
  *                                  SilcClientConnectCallback callback,
  *                                  void *context);
@@ -1039,7 +1049,8 @@ silc_client_connect_to_client(SilcClient client,
  *    session.  The `callback' with `context' will be called after the session
  *    has been set up.  It will also be called later when remote host
  *    disconnects.  The `conn_type' is the type of session this is going to
- *    be.
+ *    be.  If the remote is SILC server it is SILC_CONN_SERVER or if it is
+ *    SILC client it is SILC_CONN_CLIENT.
  *
  *    Returns SilcAsyncOperation which can be used to cancel the connecting,
  *    or NULL on error.  Note that the returned pointer becomes invalid
@@ -1099,7 +1110,7 @@ silc_client_key_exchange(SilcClient client,
 void silc_client_close_connection(SilcClient client,
                                  SilcClientConnection conn);
 
-/* Message sending functions (client_channel.c and client_prvmsg.c) */
+/* Message sending functions */
 
 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
  *
@@ -1116,20 +1127,18 @@ void silc_client_close_connection(SilcClient client,
  *
  * DESCRIPTION
  *
- *    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. The `data' is the channel message.
+ *    Sends encrypted message to the `channel'.  The plaintext message is
+ *    the `data' of `data_len' bytes in length.
  *
- *    If `key' is provided then that private key is used to encrypt the
- *    channel message.  If it is not provided, private keys has not been
- *    set at all, the normal channel key is used automatically.  If private
- *    keys are set then the first key (the key that was added first as
- *    private key) is used.
+ *    If `key' is provided then that private channel message key is used to
+ *    encrypt the message.  If it is not provided and the `channel' does not
+ *    have SILC_CHANNEL_MODE_PRIVKEY set, the curent channel key is used
+ *    instead.  If the mode is set but `key' is NULL the key that was added
+ *    first as private channel message key will be used.
  *
  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
- *    digitally signed with the SILC key pair.
+ *    digitally signed with the SILC key pair associated with the `conn'.
+ *    In this case the `hash' pointer must be provided as well.
  *
  *    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
@@ -1146,16 +1155,6 @@ SilcBool silc_client_send_channel_message(SilcClient client,
                                          unsigned char *data,
                                          SilcUInt32 data_len);
 
-/* Block process until channel message from `channel' is received */
-SilcBool
-silc_client_receive_channel_message(SilcClient client,
-                                   SilcClientConnection conn,
-                                   SilcChannelEntry channel,
-                                   SilcClientEntry *return_sender,
-                                   SilcMessageFlags *return_flags,
-                                   const unsigned char **return_message,
-                                   SilcUInt32 *return_message_len);
-
 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
  *
  * SYNOPSIS
@@ -1172,10 +1171,10 @@ silc_client_receive_channel_message(SilcClient client,
  *
  *    Sends private message to remote client. If private message key has
  *    not been set with this client then the message will be encrypted using
- *    normal session keys.  If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
- *    the message will be digitally signed with the SILC key pair.  In this
- *    case the caller must also provide the `hash' pointer.  By default, the
- *    hash function must be SHA-1.
+ *    the session keys used in `conn' connection.  If the `flags' includes
+ *    SILC_MESSAGE_FLAG_SIGNED the message will be digitally signed with the
+ *    SILC key pair associated with `conn'.  In this case the caller must also
+ *    provide the `hash' pointer.
  *
  *    Returns TRUE if the message was sent, and FALSE if error occurred.
  *    This function is thread safe and private messages can be sent from
@@ -1190,6 +1189,83 @@ SilcBool silc_client_send_private_message(SilcClient client,
                                          unsigned char *data,
                                          SilcUInt32 data_len);
 
+/****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init
+ *
+ * SYNOPSIS
+ *
+ *    SilcBool
+ *    silc_client_private_message_wait_init(SilcClient client,
+ *                                          SilcClientConnection conn);
+ *
+ * DESCRIPTION
+ *
+ *    Initializes private message waiting functionality for the connection
+ *    indicated by `conn'.  Once this is called private message from remote
+ *    connection indicated by `conn' for any client entry beloning to that
+ *    connection may be waited for, for example in a thread.  The function
+ *    silc_client_private_message_wait is used to block the current thread
+ *    until a private message is received from a specified client entry.
+ *    Return FALSE in case an internal error occurred.
+ *
+ ***/
+SilcBool silc_client_private_message_wait_init(SilcClient client,
+                                              SilcClientConnection conn);
+
+/****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit
+ *
+ * SYNOPSIS
+ *
+ *    void
+ *    silc_client_private_message_wait_uninit(SilcClient client,
+ *                                            SilcClientConnection conn);
+ *
+ * DESCRIPTION
+ *
+ *    Unintializes private message waiting for connection indicated by
+ *    `conn'.  After this call private message cannot be waited anymore.
+ *    This call may be called from any thread.  This call will signal all
+ *    private message waiting threads to stop waiting.
+ *
+ ***/
+void silc_client_private_message_wait_uninit(SilcClient client,
+                                            SilcClientConnection conn);
+
+/****f* silcclient/SilcClientAPI/silc_client_private_message_wait
+ *
+ * SYNOPSIS
+ *
+ *    SilcBool
+ *    silc_client_private_message_wait(SilcClient client,
+ *                                     SilcClientConnection conn,
+ *                                     SilcClientEntry client_entry,
+ *                                     SilcMessagePayload *payload);
+ *
+ * DESCRIPTION
+ *
+ *    Blocks current thread or process until a private message has been
+ *    received from the remote client indicated by `client_entry'.  Before
+ *    private messages can be waited the silc_client_private_message_wait_init
+ *    must be called.  This function can be used from a thread to wait for
+ *    private message from the specified client.  Multiple threads can be
+ *    created to wait messages from multiple clients.  Any other private
+ *    message received from the connection indicated by `conn' will be
+ *    forwarded to the normal `private_message' client operation callback.
+ *    The private messages from `client_entry' will not be delivered to the
+ *    `private_message' client operation callback.
+ *
+ *    Returns TRUE and the received private message into `payload'.  The caller
+ *    must free the returned SilcMessagePayload.  If this function returns
+ *    FALSE the private messages cannot be waited anymore.  This happens
+ *    when some other thread calls silc_client_private_message_wait_uninit.
+ *    This returns FALSE also if silc_client_private_message_wait_init has
+ *    not been called.
+ *
+ ***/
+SilcBool silc_client_private_message_wait(SilcClient client,
+                                         SilcClientConnection conn,
+                                         SilcClientEntry client_entry,
+                                         SilcMessagePayload *payload);
+
 /****f* silcclient/SilcClientAPI/silc_client_on_channel
  *
  * SYNOPSIS
@@ -1231,12 +1307,12 @@ SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
  *    with NULL.
  *
  *    Returns FALSE if the command is not known and TRUE after command.
- *    execution.  The "command" client operation is called when the
- *    command is executed to indicate whether the command executed
- *    successfully or not.
+ *    execution.  The `command' client operation callback will be called when
+ *    the command is executed to indicate whether or not the command executed
+ *    successfully.
  *
- *    The "command_reply" client operation will be called when reply is
- *    received from the server to the command.  Application may also use
+ *    The `command_reply' client operation callbak will be called when reply
+ *    is received from the server to the command.  Application may also use
  *    the silc_client_command_pending to attach to the command reply.
  *    The command identifier for silc_client_command_pending function after
  *    this function call is conn->cmd_ident, which application may use.
@@ -1260,10 +1336,40 @@ SilcUInt16 silc_client_command_call(SilcClient client,
                                    SilcClientConnection conn,
                                    const char *command_line, ...);
 
-/* If FALSE is returned the callback will not be called again, even if there
-   is more data coming in in the command reply.  If there are other pending
-   commands waiting for the reply, they will receive it even if some other
-   command reply has returned FALSE. */
+/****f* silcclient/SilcClientAPI/SilcClientCommandReply
+ *
+ * SYNOPSIS
+ *
+ *    typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
+ *                                               SilcClientConnection conn,
+ *                                               SilcCommand command,
+ *                                               SilcStatus status,
+ *                                               SilcStatus error,
+ *                                               void *context,
+ *                                               va_list ap);
+ *
+ * DESCRIPTION
+ *
+ *    The command reply callback function given as argument to functions
+ *    silc_client_command_send and silc_client_command_pending.  This is
+ *    called to deliver the command replies to the caller.  Each command
+ *    reply received from the server to the `command' will be delivered
+ *    separately to the caller by calling this callback.  The `status' will
+ *    indicate whether there is only one reply or multiple replies.  The
+ *    `error' will indicate if an error occurred.  The `ap' will include
+ *    command reply arguments.  They are the same arguments as for
+ *    `command_reply' client operation callback in SilcClientOperations.
+ *
+ *    If `status' is SILC_STATUS_OK only one reply was received and error
+ *    did not occur.  If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
+ *    or SILC_STATUS_LIST_END, there are will be two or more replies.  The
+ *    first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
+ *
+ *    If FALSE is returned in this function this callback will not be called
+ *    again for `command' even if there are more comand replies.  By returning
+ *    FALSE the caller my stop the command reply handling when needed.
+ *
+ ***/
 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
                                           SilcClientConnection conn,
                                           SilcCommand command,
@@ -1299,14 +1405,12 @@ typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
  *
  *    The `reply' callback must be provided, and it is called when the
  *    command reply is received from the server.  Note that, when using this
- *    function the default `command_reply' client operation will not be
- *    called, when reply is received.  Note however that, `reply' is almost
- *    identical with `command_reply' callback, and application may forward
- *    the reply from `reply' to `command_reply' callback, if desired.
+ *    function the default `command_reply' client operation callback will not
+ *    be called when reply is received.
  *
  *    Returns command identifier for this sent command.  It can be used
  *    to additionally attach to the command reply using the function
- *    silc_client_command_pending, if needed.  Returns 0 on error,
+ *    silc_client_command_pending, if needed.  Returns 0 on error.
  *
  * EXAMPLE
  *
@@ -1327,20 +1431,17 @@ SilcUInt16 silc_client_command_send(SilcClient client,
  * SYNOPSIS
  *
  *    void silc_client_command_pending(SilcClientConnection conn,
- *                                     SilcCommand reply_cmd,
- *                                     SilcUInt16 cmd-ident,
- *                                     SilcCommandCb callback,
+ *                                     SilcCommand command,
+ *                                     SilcUInt16 cmd_ident,
+ *                                     SilcClientCommandReply reply,
  *                                     void *context);
  *
  * DESCRIPTION
  *
  *    This function can be used to add pending command callback to be
  *    called when an command reply is received to an earlier sent command.
- *    The `reply_cmd' is the command that must be received in order for
+ *    The `command' is the command that must be received in order for
  *    the pending command callback indicated by `callback' to be called.
- *    The `callback' will deliver the `context' and
- *    SilcClientCommandReplyContext which includes the internals of the
- *    command reply.
  *
  *    The `cmd_ident' is a command identifier which was set for the earlier
  *    sent command.  The command reply will include the same identifier
@@ -1351,9 +1452,7 @@ SilcUInt16 silc_client_command_send(SilcClient client,
  *
  *    Application may use this function to add its own command reply
  *    handlers if it wishes not to use the standard `command_reply'
- *    client operation.  However, note that the pending command callback
- *    does not deliver parsed command reply, but application must parse
- *    it itself.
+ *    client operation.
  *
  *    Note also that the application is notified about the received command
  *    reply through the `command_reply' client operation before calling
@@ -1361,15 +1460,12 @@ SilcUInt16 silc_client_command_send(SilcClient client,
  *    command reply handling, and is called regardless whether pending
  *    command callbacks are used or not.
  *
- *    Commands that application calls with silc_client_command_call
- *    will use a command identifier from conn->cmd_ident variable.  After
- *    calling the silc_client_command_call, the conn->cmd_ident includes
- *    the command identifier that was used for the command sending.
- *
  * EXAMPLE
  *
- *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
- *    silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
+ *    SilcUInt16 cmd_ident;
+ *    cmd_ident = silc_client_command_call(client, conn,
+ *                                         "PING silc.silcnet.org");
+ *    silc_client_command_pending(conn, SILC_COMMAND_PING, cmd_ident,
  *                                my_ping_handler, my_ping_context);
  *
  ***/
@@ -1380,7 +1476,7 @@ SilcBool silc_client_command_pending(SilcClientConnection conn,
                                     void *context);
 
 
-/* Private Message key management (client_prvmsg.c) */
+/* Private Message key management */
 
 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
  *
@@ -1412,7 +1508,7 @@ SilcBool silc_client_command_pending(SilcClientConnection conn,
  *
  *    It is not necessary to set key for normal private message usage. If the
  *    key is not set then the private messages are encrypted using normal
- *    session keys.  Setting the private key, however, increases the security.
+ *    session keys.  Setting the private key, however, increases security.
  *
  *    Returns FALSE if the key is already set for the `client_entry', TRUE
  *    otherwise.
@@ -1458,9 +1554,10 @@ SilcBool silc_client_add_private_message_key_ske(SilcClient client,
  *
  * SYNOPSIS
  *
- *    SilcBool silc_client_del_private_message_key(SilcClient client,
- *                                             SilcClientConnection conn,
- *                                             SilcClientEntry client_entry);
+ *    SilcBool
+ *    silc_client_del_private_message_key(SilcClient client,
+ *                                        SilcClientConnection conn,
+ *                                        SilcClientEntry client_entry);
  *
  * DESCRIPTION
  *
@@ -1514,23 +1611,43 @@ silc_client_list_private_message_keys(SilcClient client,
 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
                                           SilcUInt32 key_count);
 
+/****f* silcclient/SilcClientAPI/silc_client_private_message_key_is_set
+ *
+ * SYNOPSIS
+ *
+ *    SilcBool
+ *    silc_client_private_message_key_is_set(SilcClient client,
+ *                                           SilcClientConnection conn,
+ *                                           SilcClientEntry client_entry);
+ *
+ * DESCRIPTION
+ *
+ *    Returns TRUE if the private message key has been set for the client
+ *    entry indicated by `client_entry'.
+ *
+ ***/
+SilcBool
+silc_client_private_message_key_is_set(SilcClient client,
+                                      SilcClientConnection conn,
+                                      SilcClientEntry client_entry);
+
 
-/* Channel private key management (client_channel.c,
-   SilcChannelPrivateKey is defined in idlist.h) */
+/* Channel private key management */
 
 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
  *
  * SYNOPSIS
  *
- *    SilcBool silc_client_add_channel_private_key(SilcClient client,
- *                                             SilcClientConnection conn,
- *                                             SilcChannelEntry channel,
- *                                             const char *name,
- *                                             char *cipher,
- *                                             char *hmac,
- *                                             unsigned char *key,
- *                                             SilcUInt32 key_len,
- *                                             SilcChannelPrivateKey *ret_key);
+ *    SilcBool
+ *    silc_client_add_channel_private_key(SilcClient client,
+ *                                        SilcClientConnection conn,
+ *                                        SilcChannelEntry channel,
+ *                                        const char *name,
+ *                                        char *cipher,
+ *                                        char *hmac,
+ *                                        unsigned char *key,
+ *                                        SilcUInt32 key_len,
+ *                                        SilcChannelPrivateKey *ret_key);
  *
  * DESCRIPTION
  *
@@ -1582,8 +1699,8 @@ SilcBool silc_client_add_channel_private_key(SilcClient client,
  * SYNOPSIS
  *
  *    SilcBool silc_client_del_channel_private_keys(SilcClient client,
- *                                              SilcClientConnection conn,
- *                                              SilcChannelEntry channel);
+ *                                                  SilcClientConnection conn,
+ *                                                  SilcChannelEntry channel);
  *
  * DESCRIPTION
  *
@@ -1601,9 +1718,9 @@ SilcBool silc_client_del_channel_private_keys(SilcClient client,
  * SYNOPSIS
  *
  *    SilcBool silc_client_del_channel_private_key(SilcClient client,
- *                                            SilcClientConnection conn,
- *                                            SilcChannelEntry channel,
- *                                            SilcChannelPrivateKey key);
+ *                                                 SilcClientConnection conn,
+ *                                                 SilcChannelEntry channel,
+ *                                                 SilcChannelPrivateKey key);
  *
  * DESCRIPTION
  *
@@ -1632,10 +1749,10 @@ SilcBool silc_client_del_channel_private_key(SilcClient client,
  * DESCRIPTION
  *
  *    Returns list of private keys associated to the `channel'.  The caller
- *    must free the returned list.  The pointers in the list may be
- *    used to delete the specific key by giving the pointer as argument to the
- *    function silc_client_del_channel_private_key.  Each entry in the list
- *    is SilcChannelPrivateKey.
+ *    must free the returned list with silc_dlist_uninit.  The pointers in
+ *    the list may be used to delete the specific key by giving the pointer
+ *    as argument to the function silc_client_del_channel_private_key.  Each
+ *    entry in the list is SilcChannelPrivateKey.
  *
  ***/
 SilcDList silc_client_list_channel_private_keys(SilcClient client,
@@ -1791,7 +1908,8 @@ void silc_client_perform_key_agreement(SilcClient client,
  * DESCRIPTION
  *
  *    Same as silc_client_perform_key_agreement but the caller has created
- *    the connection.  The `stream' is the created connection.
+ *    the connection to remote client.  The `stream' is the created
+ *    connection.
  *
  ***/
 void
@@ -1835,9 +1953,9 @@ void silc_client_abort_key_agreement(SilcClient client,
  *
  * SYNOPSIS
  *
- *    void silc_client_set_away_message(SilcClient client,
- *                                      SilcClientConnection conn,
- *                                      char *message);
+ *    SilcBool silc_client_set_away_message(SilcClient client,
+ *                                          SilcClientConnection conn,
+ *                                          char *message);
  *
  * DESCRIPTION
  *
@@ -1847,73 +1965,47 @@ void silc_client_abort_key_agreement(SilcClient client,
  *    automatically back to the the client who send private message.  If
  *    away message is already set this replaces the old message with the
  *    new one.  If `message' is NULL the old away message is removed.
- *    The sender may freely free the memory of the `message'.
+ *    The sender may freely free the memory of the `message'.  Returns
+ *    FALSE on error.
  *
  ***/
-void silc_client_set_away_message(SilcClient client,
-                                 SilcClientConnection conn,
-                                 char *message);
+SilcBool silc_client_set_away_message(SilcClient client,
+                                     SilcClientConnection conn,
+                                     char *message);
 
-/****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
+/****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
  *
- * SYNOPSIS
+ * NAME
  *
- *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
- *                                              SilcClientConnection conn,
- *                                              SilcAuthMethod auth_meth,
- *                                              void *context);
+ *    typedef enum { ... } SilcClientMonitorStatus;
  *
  * DESCRIPTION
  *
- *    Connection authentication method request callback. This is called
- *    by the client library after it has received the authentication method
- *    that the application requested by calling the function
- *    silc_client_request_authentication_method.
- *
- ***/
-typedef void (*SilcConnectionAuthRequest)(SilcClient client,
-                                         SilcClientConnection conn,
-                                         SilcAuthMethod auth_meth,
-                                         void *context);
-
-/****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
- *
- * SYNOPSIS
- *
- *    void
- *    silc_client_request_authentication_method(SilcClient client,
- *                                              SilcClientConnection conn,
- *                                              SilcConnectionAuthRequest
- *                                                callback,
- *                                              void *context);
- *
- * DESCRIPTION
+ *    File transmission session status types.  These will indicate
+ *    the status of the file transmission session.
  *
- *    This function can be used to request the current authentication method
- *    from the server. This may be called when connecting to the server
- *    and the client library requests the authentication data from the
- *    application. If the application does not know the current authentication
- *    method it can request it from the server using this function.
- *    The `callback' with `context' will be called after the server has
- *    replied back with the current authentication method.
+ *    The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session
+ *    is key exchange phase.
  *
- ***/
-void
-silc_client_request_authentication_method(SilcClient client,
-                                         SilcClientConnection conn,
-                                         SilcConnectionAuthRequest callback,
-                                         void *context);
-
-/****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
+ *    The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent
+ *    to remote client.
  *
- * NAME
+ *    The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being
+ *    recieved from remote client.
  *
- *    typedef enum { ... } SilcClientMonitorStatus;
+ *    The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user
+ *    issues silc_client_file_close.  If needed, it may be ignored in the
+ *    monitor callback.
  *
- * DESCRIPTION
+ *    The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote
+ *    disconnects the session connection.  The silc_client_file_close must
+ *    be called when this status is received.  The session is over when
+ *    this is received.
  *
- *    File transmission session status types.  These will indicate
- *    the status of the file transmission session.
+ *    The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error
+ *    occured.  The SilcClientFileError will indicate more detailed error
+ *    condition.  The silc_client_file_close must be called when this status
+ *    is received.  The session is over when this is received.
  *
  * SOURCE
  */
@@ -1921,9 +2013,10 @@ typedef enum {
   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
   SILC_CLIENT_FILE_MONITOR_SEND,            /* Sending file */
   SILC_CLIENT_FILE_MONITOR_RECEIVE,         /* Receiving file */
-  SILC_CLIENT_FILE_MONITOR_GET,
-  SILC_CLIENT_FILE_MONITOR_PUT,
+  SILC_CLIENT_FILE_MONITOR_GET,                     /* Unsupported */
+  SILC_CLIENT_FILE_MONITOR_PUT,                     /* Unsupported */
   SILC_CLIENT_FILE_MONITOR_CLOSED,          /* Session closed */
+  SILC_CLIENT_FILE_MONITOR_DISCONNECT,      /* Session disconnected */
   SILC_CLIENT_FILE_MONITOR_ERROR,           /* Error during session */
 } SilcClientMonitorStatus;
 /***/
@@ -1944,12 +2037,15 @@ typedef enum {
  */
 typedef enum {
   SILC_CLIENT_FILE_OK,
-  SILC_CLIENT_FILE_ERROR,
-  SILC_CLIENT_FILE_UNKNOWN_SESSION,
-  SILC_CLIENT_FILE_ALREADY_STARTED,
-  SILC_CLIENT_FILE_NO_SUCH_FILE,
-  SILC_CLIENT_FILE_PERMISSION_DENIED,
-  SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
+  SILC_CLIENT_FILE_ERROR,                   /* Generic error */
+  SILC_CLIENT_FILE_UNKNOWN_SESSION,         /* Unknown session ID */
+  SILC_CLIENT_FILE_ALREADY_STARTED,         /* Session already started */
+  SILC_CLIENT_FILE_NO_SUCH_FILE,            /* No such file */
+  SILC_CLIENT_FILE_PERMISSION_DENIED,       /* Permission denied */
+  SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,     /* Key exchange failed */
+  SILC_CLIENT_FILE_CONNECT_FAILED,          /* Error during connecting */
+  SILC_CLIENT_FILE_TIMEOUT,                 /* Connecting timedout */
+  SILC_CLIENT_FILE_NO_MEMORY,               /* System out of memory */
 } SilcClientFileError;
 /***/
 
@@ -1977,7 +2073,8 @@ typedef enum {
  *    currently transmitted amount of total `filesize'.  The `client_entry'
  *    indicates the remote client, and the transmission session ID is the
  *    `session_id'.  The filename being transmitted is indicated by the
- *    `filepath'.
+ *    `filepath'.  The `conn' is NULL if the connection to remote client
+ *    does not exist yet.
  *
  ***/
 typedef void (*SilcClientFileMonitor)(SilcClient client,
@@ -2022,7 +2119,7 @@ typedef void (*SilcClientFileName)(const char *filepath,
  *
  * DESCRIPTION
  *
- *    File name asking callback, that is called if it is given to the
+ *    File name asking callback that is called if it is given to the
  *    silc_client_file_receive and the path given to that as argument was
  *    NULL.  The library calls this to ask the filename and filepath to
  *    where the file is to be saved.  The 'remote_filename' is the file
@@ -2046,13 +2143,13 @@ typedef void (*SilcClientFileAskName)(SilcClient client,
  *    SilcClientFileError
  *    silc_client_file_send(SilcClient client,
  *                          SilcClientConnection conn,
+ *                          SilcClientEntry client_entry,
+ *                          SilcClientConnectionParams *params,
+ *                          SilcPublicKey public_key,
+ *                          SilcPrivateKey private_key,
  *                          SilcClientFileMonitor monitor,
  *                          void *monitor_context,
- *                          const char *local_ip,
- *                          SilcUInt32 local_port,
- *                          SilcBool do_not_bind,
- *                          SilcClientEntry client_entry,
- *                          const char *filepath);
+ *                          const char *filepath,
  *                          SilcUInt32 *session_id);
  *
  * DESCRIPTION
@@ -2068,29 +2165,32 @@ typedef void (*SilcClientFileAskName)(SilcClient client,
  *    abort the file transmission) by calling the silc_client_file_close
  *    function.  The session ID is also returned in the `monitor' callback.
  *
- *    If the `local_ip' is provided then this will try to bind the
- *    listener for key exchange protocol to that IP.  If `local_port' is
- *    non-zero that port is used.  If `local_ip' is NULL then this will
- *    automatically attempt to bind it to local IP address of the machine.
- *    If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
- *    ignored and it is expected that the receiver will provide the
- *    point of contact.  This is usefull if the sender is behind NAT.
+ *    If `params' is non-NULL and it has the `local_ip' and `local_port' set
+ *    the caller will provide the connection endpoint for the key agreement
+ *    connection.  The `bind_ip' can be used to bind to that IP instead of
+ *    `local_ip'.  Caller may also set the `repository', `verify_notfound'
+ *    and `timeout_secs' fields in `params'.  Other fields are ignored.
+ *    If `params' is NULL, then the `client_entry' is expected to provide
+ *    the connection endpoint for us.  It is recommended the `timeout_secs'
+ *    is specified in case the remote client does not reply anything to
+ *    the request.
+ *
+ *    The `public_key' and `private_key' is our identity in the key agreement.
  *
- *    If error will occur during the file transfer process the error
- *    status will be returned in the monitor callback.  In this case
- *    the application must call silc_client_file_close to close the
- *    session.
+ *    If error will occur during the file transfer process the error status
+ *    will be returned in the monitor callback.  In this case the application
+ *    must call silc_client_file_close to close the session.
  *
  ***/
 SilcClientFileError
 silc_client_file_send(SilcClient client,
                      SilcClientConnection conn,
+                     SilcClientEntry client_entry,
+                     SilcClientConnectionParams *params,
+                     SilcPublicKey public_key,
+                     SilcPrivateKey private_key,
                      SilcClientFileMonitor monitor,
                      void *monitor_context,
-                     const char *local_ip,
-                     SilcUInt32 local_port,
-                     SilcBool do_not_bind,
-                     SilcClientEntry client_entry,
                      const char *filepath,
                      SilcUInt32 *session_id);
 
@@ -2101,6 +2201,9 @@ silc_client_file_send(SilcClient client,
  *    SilcClientFileError
  *    silc_client_file_receive(SilcClient client,
  *                             SilcClientConnection conn,
+ *                             SilcClientConnectionParams *params,
+ *                             SilcPublicKey public_key,
+ *                             SilcPrivateKey private_key,
  *                             SilcClientFileMonitor monitor,
  *                             void *monitor_context,
  *                             const char *path,
@@ -2112,7 +2215,7 @@ silc_client_file_send(SilcClient client,
  *
  *    Receives a file from a client indicated by the `client_entry'.  The
  *    `session_id' indicates the file transmission session and it has been
- *    received in the `ftp' client operation function.  This will actually
+ *    received in the `ftp' client operation callback.  This will actually
  *    perform the key agreement protocol with the remote client before
  *    actually starting the file transmission.  The `monitor' callback
  *    will be called to monitor the transmission.  If `path' is non-NULL
@@ -2121,15 +2224,26 @@ silc_client_file_send(SilcClient client,
  *    callback is non-NULL.  In this case the callback is called to ask
  *    the path and filename from application.
  *
- *    If error will occur during the file transfer process the error
- *    status will be returned in the monitor callback.  In this case
- *    the application must call silc_client_file_close to close the
- *    session.
+ *    The `params' is the connection related parameters.  If the remote client
+ *    provided connection point the `params' will be used when creating
+ *    connection to the remote client.  If remote client did not provide
+ *    connection point the `params' is used to provide connection point
+ *    locally for the remote client.  See silc_client_file_send for more
+ *    information on providing connection point for remote client.
+ *
+ *    The `public_key' and `private_key' is our identity in the key agreement.
+ *
+ *    If error will occur during the file transfer process the error status
+ *    will be returned in the monitor callback.  In this case the application
+ *    must call silc_client_file_close to close the session.
  *
  ***/
 SilcClientFileError
 silc_client_file_receive(SilcClient client,
                         SilcClientConnection conn,
+                        SilcClientConnectionParams *params,
+                        SilcPublicKey public_key,
+                        SilcPrivateKey private_key,
                         SilcClientFileMonitor monitor,
                         void *monitor_context,
                         const char *path,
@@ -2309,6 +2423,30 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
                                            SilcClientEntry client_entry,
                                            SilcBool priority);
 
+/****f* silcclient/SilcClientAPI/silc_client_nickname_parse
+ *
+ * SYNOPSIS
+ *
+ *    SilcBool silc_client_nickname_parse(SilcClient client,
+ *                                        SilcClientConnection conn,
+ *                                        char *nickname,
+ *                                        char **ret_nick);
+ *
+ * DESCRIPTION
+ *
+ *    Parses the `nickname' according to the format string given in the
+ *    SilcClientParams.  Returns the parsed nickname into the `ret_nick'.
+ *    The caller must free the returned pointer.  Returns FALSE if error
+ *    occurred during parsing.  Returns TRUE if the nickname was parsed,
+ *    it was not formatted or if the format string has not been specified
+ *    in SilcClientParams.
+ *
+ ***/
+SilcBool silc_client_nickname_parse(SilcClient client,
+                                   SilcClientConnection conn,
+                                   char *nickname,
+                                   char **ret_nick);
+
 #ifdef __cplusplus
 }
 #endif