Added Parameter dont_register_crypto_library to
[silc.git] / lib / silcclient / silcclient.h
1 /*
2
3   silcclient.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2000 - 2004 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcclient/Client Library Interface
21  *
22  * DESCRIPTION
23  *
24  * This interface defines the SILC Client Library API for the application.
25  * The client operations are defined first.  These are callback functions that
26  * the application MUST implement since the library may call the functions
27  * at any time.  At the end of file is the API for the application that
28  * it can use from the library.  This is the only file that the application
29  * may include from the SIlC Client Library.
30  *
31  * o SILC Client Operations
32  *
33  *   These functions must be implemented by the application calling the SILC
34  *   client library. The client library can call these functions at any time.
35  *
36  *   To use this structure: define a static SilcClientOperations variable,
37  *   fill it and pass its pointer to silc_client_alloc function.
38  *
39  * o SILC Client Library API
40  *
41  *   This is the API that is published by the SILC Client Library for the
42  *   applications.  These functions are implemented in the SILC Client Library.
43  *   Application may freely call these functions from the library.
44  *
45  ***/
46
47 #ifndef SILCCLIENT_H
48 #define SILCCLIENT_H
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 #include "client.h"
55
56 /* General definitions */
57
58 /****s* silcclient/SilcClientAPI/SilcClient
59  *
60  * NAME
61  *
62  *    typedef struct SilcClientStruct { ... } *SilcClient
63  *
64  * DESCRIPTION
65  *
66  *    This is the actual SILC Client structure which represents one
67  *    SILC Client.  It is allocated with the silc_client_alloc function
68  *    and given as argument to all SILC Client Library functions.  It
69  *    is initialized with silc_client_init function, and freed with
70  *    silc_client_free function.
71  *
72  * SOURCE
73  */
74 struct SilcClientStruct {
75   /*
76    * The following fields are set by application
77    */
78   char *nickname;               /* Nickname, MAY be set by application  */
79   char *username;               /* Username, MUST be set by application */
80   char *hostname;               /* hostname, MUST be set by application */
81   char *realname;               /* Real name, MUST be set be application */
82
83   SilcPublicKey public_key;     /* Public key of user, set by application */
84   SilcPrivateKey private_key;   /* Private key of user, set by application */
85   SilcPKCS pkcs;                /* PKCS allocated by application */
86
87   /*
88    * The following fields are set by the library
89    */
90
91   /* Scheduler, set by library.  Application may use this pointer. */
92   SilcSchedule schedule;
93
94   /* Random Number Generator. Application should use this as its primary
95      random number generator. */
96   SilcRng rng;
97
98   /* Application specific user data pointer. Client library does not
99      touch this.  This the context sent as argument to silc_client_alloc.
100      Application can use it freely. */
101   void *application;
102
103   /* Generic hash context for application usage */
104   SilcHash md5hash;
105   SilcHash sha1hash;
106
107   /* Internal data for client library. Application cannot access this
108      data at all. */
109   SilcClientInternal internal;
110 };
111 /***/
112
113 /****s* silcclient/SilcClientAPI/SilcClientConnection
114  *
115  * NAME
116  *
117  *    typedef struct SilcClientConnectionStruct { ... }
118  *                      *SilcClientConnection
119  *
120  * DESCRIPTION
121  *
122  *    This structure represents a connection.  When connection is created
123  *    to server this is context is returned to the application in the
124  *    "connected" client operation.  It includes all the important
125  *    data for the session, such as nickname, local and remote IDs, and
126  *    other information.
127  *
128  * SOURCE
129  */
130 struct SilcClientConnectionStruct {
131   /*
132    * Local data
133    */
134   char *nickname;                 /* Current nickname */
135   SilcClientEntry local_entry;    /* Own Client Entry */
136   SilcClientID *local_id;         /* Current Client ID */
137   unsigned char *local_id_data;   /* Current Client ID decoded */
138   SilcUInt32 local_id_data_len;
139
140   /*
141    * Remote data
142    */
143   char *remote_host;              /* Remote host name */
144   int remote_port;                /* Remote port */
145   SilcServerID *remote_id;        /* Remote Server ID */
146   unsigned char *remote_id_data;  /* Remote Server ID decoded */
147   SilcUInt32 remote_id_data_len;
148
149   /*
150    * Common data
151    */
152
153   /* Current command identifier for a command that was sent last.
154      Application may get the value from this variable to find out the
155      command identifier for last command. */
156   SilcUInt16 cmd_ident;
157
158   /* User data context. Library does not touch this. Application may
159      freely set and use this pointer for its needs. */
160   void *context;
161
162   /* Pointer back to the SilcClient.  Application may use this. */
163   SilcClient client;
164
165   /* Current channel.  Application may use and set this pointer if needed. */
166   SilcChannelEntry current_channel;
167
168   /* Socket connection object for this connection.  Application may
169      use this if needed.  The sock->user_data is back pointer to this
170      structure. */
171   SilcSocketConnection sock;
172
173   /* Internal data for client library. Application cannot access this
174      data at all. */
175   SilcClientConnectionInternal internal;
176 };
177 /***/
178
179 /****s* silcclient/SilcClientAPI/SilcClientEntry
180  *
181  * NAME
182  *
183  *    typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
184  *
185  * DESCRIPTION
186  *
187  *    This structure represents a client or a user in the SILC network.
188  *    The local user has this structure also and it can be accessed from
189  *    SilcClientConnection structure.  All other users in the SILC network
190  *    that are accessed using the Client Library routines will have their
191  *    own SilcClientEntry structure.  For example, when finding users by
192  *    their nickname the Client Library returns this structure back to
193  *    the application.
194  *
195  * SOURCE
196  */
197 struct SilcClientEntryStruct {
198   /* General information */
199   char *nickname;               /* nickname */
200   char *username;               /* username */
201   char *hostname;               /* hostname */
202   char *server;                 /* SILC server name */
203   char *realname;               /* Realname (userinfo) */
204
205   /* Mode, ID and other information */
206   SilcUInt32 mode;              /* User mode in SILC, see SilcUserMode */
207   SilcClientID *id;             /* The Client ID */
208   SilcDList attrs;              /* Requested Attributes (maybe NULL) */
209   unsigned char *fingerprint;   /* Fingerprint of client's public key */
210   SilcUInt32 fingerprint_len;   /* Length of the fingerprint */
211   SilcPublicKey public_key;     /* User's public key, may be NULL */
212
213   /* Private message keys */
214   SilcCipher send_key;          /* Private message key for sending */
215   SilcCipher receive_key;       /* Private message key for receiving */
216   SilcHmac hmac_send;           /* Private mesage key HMAC for sending */
217   SilcHmac hmac_receive;        /* Private mesage key HMAC for receiving */
218   unsigned char *key;           /* Set only if application provided the
219                                    key material. NULL if the library
220                                    generated the key. */
221   SilcUInt32 key_len;           /* Key length */
222   SilcClientKeyAgreement ke;    /* Current key agreement context or NULL */
223
224   /* SilcClientEntry status information */
225   SilcEntryStatus status;       /* Status mask */
226   SilcHashTable channels;       /* All channels client has joined */
227   SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
228   unsigned int generated   : 1; /* TRUE if library generated `key' */
229   unsigned int valid       : 1; /* FALSE if this entry is not valid */
230   unsigned int prv_resp    : 1; /* TRUE if private message key indicator
231                                    has been received (responder). */
232
233   /* Application specific data.  Application may set here whatever it wants. */
234   void *context;
235 };
236 /***/
237
238 /****s* silcclient/SilcClientAPI/SilcChannelEntry
239  *
240  * NAME
241  *
242  *    typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
243  *
244  * DESCRIPTION
245  *
246  *    This structure represents a channel in the SILC network.  All
247  *    channels that the client are aware of or have joined in will be
248  *    represented as SilcChannelEntry.  The structure includes information
249  *    about the channel.
250  *
251  * SOURCE
252  */
253 struct SilcChannelEntryStruct {
254   /* General information */
255   char *channel_name;                        /* Channel name */
256   SilcChannelID *id;                         /* Channel ID */
257   SilcUInt32 mode;                           /* Channel mode, ChannelModes. */
258   char *topic;                               /* Current topic, may be NULL */
259   SilcPublicKey founder_key;                 /* Founder key, may be NULL */
260   SilcUInt32 user_limit;                     /* User limit on channel */
261
262   /* All clients that has joined this channel.  The key to the table is the
263      SilcClientEntry and the context is SilcChannelUser context. */
264   SilcHashTable user_list;
265
266   /* Channel keys */
267   SilcCipher channel_key;                    /* The channel key */
268   unsigned char *key;                        /* Raw key data */
269   SilcUInt32 key_len;                        /* Raw key data length */
270   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
271   SilcHmac hmac;                             /* Current HMAC */
272
273   /* Channel private keys */
274   SilcDList private_keys;                    /* List of private keys or NULL */
275   SilcChannelPrivateKey curr_key;            /* Current private key */
276
277   /* SilcChannelEntry status information */
278   SilcDList old_channel_keys;
279   SilcDList old_hmacs;
280   SilcUInt16 resolve_cmd_ident;              /* Command identifier when
281                                                 resolving this entry */
282
283   /* Application specific data.  Application may set here whatever it wants. */
284   void *context;
285 };
286 /***/
287
288 /****s* silcclient/SilcClientAPI/SilcChannelUser
289  *
290  * NAME
291  *
292  *    typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
293  *
294  * DESCRIPTION
295  *
296  *    This structure represents a client that has joined to a channel.
297  *    It shows the client and the channel and the client's mode (channel
298  *    user mode) on the channel.
299  *
300  * SOURCE
301  */
302 struct SilcChannelUserStruct {
303   SilcClientEntry client;                    /* Client joined on channel */
304   SilcUInt32 mode;                           /* mode, ChannelUserModes */
305   SilcChannelEntry channel;                  /* The channel user has joined */
306
307   /* Application specific data.  Application may set here whatever it wants. */
308   void *context;
309 };
310 /***/
311
312 /****s* silcclient/SilcClientAPI/SilcServerEntry
313  *
314  * NAME
315  *
316  *    typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
317  *
318  * DESCRIPTION
319  *
320  *    This structure represents a server in the SILC network.  All servers
321  *    that the client is aware of and have for example resolved with
322  *    SILC_COMMAND_INFO command have their on SilcServerEntry structure.
323  *
324  * SOURCE
325  */
326 struct SilcServerEntryStruct {
327   /* General information */
328   char *server_name;                         /* Server name */
329   char *server_info;                         /* Server info */
330   SilcServerID *server_id;                   /* Server ID */
331   SilcUInt16 resolve_cmd_ident;              /* Command identifier when
332                                                 resolving this entry */
333
334   /* Application specific data.  Application may set here whatever it wants. */
335   void *context;
336 };
337 /***/
338
339 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
340  *
341  * NAME
342  *
343  *    typedef enum { ... } SilcKeyAgreementStatus;
344  *
345  * DESCRIPTION
346  *
347  *    Key agreement status types indicating the status of the key
348  *    agreement protocol.  These types are returned to the application
349  *    in the SilcKeyAgreementCallback callback function.
350  *
351  * SOURCE
352  */
353 typedef enum {
354   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
355   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
356   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
357   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
358   SILC_KEY_AGREEMENT_ABORTED,          /* The protocol aborted */
359   SILC_KEY_AGREEMENT_ALREADY_STARTED,  /* Already started */
360   SILC_KEY_AGREEMENT_SELF_DENIED,      /* Negotiationg with itself denied */
361 } SilcKeyAgreementStatus;
362 /***/
363
364 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
365  *
366  * SYNOPSIS
367  *
368  *    typedef void (*SilcKeyAgreementCallback)(SilcClient client,
369  *                                             SilcClientConnection conn,
370  *                                             SilcClientEntry client_entry,
371  *                                             SilcKeyAgreementStatus status,
372  *                                             SilcSKEKeyMaterial *key,
373  *                                             void *context);
374  *
375  * DESCRIPTION
376  *
377  *    Key agreement callback that is called after the key agreement protocol
378  *    has been performed. This is called also if error occurred during the
379  *    key agreement protocol. The `key' is the allocated key material and
380  *    the caller is responsible of freeing it. The `key' is NULL if error
381  *    has occurred. The application can freely use the `key' to whatever
382  *    purpose it needs. See lib/silcske/silcske.h for the definition of
383  *    the SilcSKEKeyMaterial structure.
384  *
385  ***/
386 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
387                                          SilcClientConnection conn,
388                                          SilcClientEntry client_entry,
389                                          SilcKeyAgreementStatus status,
390                                          SilcSKEKeyMaterial *key,
391                                          void *context);
392
393 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
394  *
395  * NAME
396  *
397  *    typedef struct { ... } SilcPrivateMessageKeys;
398  *
399  * DESCRIPTION
400  *
401  *    Structure to hold the list of private message keys. The array of this
402  *    structure is returned by the silc_client_list_private_message_keys
403  *    function.
404  *
405  * SOURCE
406  */
407 typedef struct {
408   SilcClientEntry client_entry;       /* The remote client entry */
409   char *cipher;                       /* The cipher name */
410   unsigned char *key;                 /* The original key, If the appliation
411                                          provided it. This is NULL if the
412                                          library generated the key or if
413                                          the SKE key material was used. */
414   SilcUInt32 key_len;                 /* The key length */
415 } *SilcPrivateMessageKeys;
416 /***/
417
418 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
419  *
420  * NAME
421  *
422  *    typedef struct SilcChannelPrivateKeyStruct { ... }
423  *                      *SilcChannelPrivateKey;
424  *
425  * DESCRIPTION
426  *
427  *    Structure to hold one channel private key. The array of this structure
428  *    is returned by silc_client_list_channel_private_keys function.
429  *
430  * SOURCE
431  */
432 struct SilcChannelPrivateKeyStruct {
433   char *name;                         /* Application given name */
434   SilcCipher cipher;                  /* The cipher and key */
435   SilcHmac hmac;                      /* The HMAC and hmac key */
436   unsigned char *key;                 /* The key data */
437   SilcUInt32 key_len;                 /* The key length */
438 };
439 /***/
440
441 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
442  *
443  * SYNOPSIS
444  *
445  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
446  *                                      SilcUInt32 passphrase_len,
447  *                                      void *context);
448  *
449  * DESCRIPTION
450  *
451  *    Ask passphrase callback. This is called by the application when the
452  *    library calls `ask_passphrase' client operation.  The callback delivers
453  *    the passphrase to the library.  The passphrases in SILC protocol
454  *    MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
455  *    encoded, and if it is not then library will attempt to encode it.
456  *
457  ***/
458 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
459                                   SilcUInt32 passphrase_len,
460                                   void *context);
461
462 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
463  *
464  * SYNOPSIS
465  *
466  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
467  *
468  * DESCRIPTION
469  *
470  *    Public key (or certificate) verification callback. This is called
471  *    by the application to indicate that the public key verification was
472  *    either success or failure.
473  *
474  ***/
475 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
476
477 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
478  *
479  * SYNOPSIS
480  *
481  *    typedef void (*SilcGetAuthMeth)(bool success,
482  *                                    SilcProtocolAuthMeth auth_meth,
483  *                                    const unsigned char *auth_data,
484  *                                    SilcUInt32 auth_data_len, void *context);
485  *
486  * DESCRIPTION
487  *
488  *    Authentication method resolving callback. This is called by the
489  *    application to return the resolved authentication method. The client
490  *    library has called the get_auth_method client operation and given
491  *    this function pointer as argument. The `success' will indicate whether
492  *    the authentication method could be resolved. The `auth_meth' is the
493  *    resolved authentication method. The `auth_data' and the `auth_data_len'
494  *    are the resolved authentication data. The `context' is the libary's
495  *    context sent to the get_auth_method client operation.
496  *
497  ***/
498 typedef void (*SilcGetAuthMeth)(bool success,
499                                 SilcProtocolAuthMeth auth_meth,
500                                 const unsigned char *auth_data,
501                                 SilcUInt32 auth_data_len, void *context);
502
503 /****d* silcclient/SilcClientAPI/SilcClientMessageType
504  *
505  * NAME
506  *
507  *    typedef enum { ... } SilcClientMessageType;
508  *
509  * DESCRIPTION
510  *
511  *    Different message types for `say' client operation.  The application
512  *    may filter the message sent by the library according this type.
513  *
514  * SOURCE
515  */
516 typedef enum {
517   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
518   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
519   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
520   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
521 } SilcClientMessageType;
522 /***/
523
524 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
525  *
526  * NAME
527  *
528  *    typedef enum { ... } SilcClientConnectionStatus
529  *
530  * DESCRIPTION
531  *
532  *    This type is returned to the `connect' client operation to indicate
533  *    the status of the created connection.  It can indicate if it was
534  *    successful or whether an error occurred.
535  *
536  * SOURCE
537  */
538 typedef enum {
539   SILC_CLIENT_CONN_SUCCESS,            /* Successfully connected */
540   SILC_CLIENT_CONN_SUCCESS_RESUME,     /* Successfully connected and
541                                           resumed old detached session */
542   SILC_CLIENT_CONN_ERROR,              /* Unknown error occurred during
543                                           connecting */
544   SILC_CLIENT_CONN_ERROR_KE,           /* Key Exchange failed */
545   SILC_CLIENT_CONN_ERROR_AUTH,         /* Authentication failed */
546   SILC_CLIENT_CONN_ERROR_RESUME,       /* Resuming failed */
547   SILC_CLIENT_CONN_ERROR_TIMEOUT,      /* Timeout during connecting */
548 } SilcClientConnectionStatus;
549 /***/
550
551 /****s* silcclient/SilcClientAPI/SilcClientOperations
552  *
553  * NAME
554  *
555  *    typedef struct { ... } SilcClientOperations;
556  *
557  * DESCRIPTION
558  *
559  *    SILC Client Operations. These must be implemented by the application.
560  *    The Client library may call any of these routines at any time.  The
561  *    routines are used to deliver certain information to the application
562  *    or from the application to the client library.
563  *
564  * SOURCE
565  */
566 typedef struct {
567   /* Message sent to the application by library. `conn' associates the
568      message to a specific connection.  `conn', however, may be NULL.
569      The `type' indicates the type of the message sent by the library.
570      The application can for example filter the message according the
571      type.  The variable argument list is arguments to the formatted
572      message that `msg' may be. */
573   void (*say)(SilcClient client, SilcClientConnection conn,
574               SilcClientMessageType type, char *msg, ...);
575
576   /* Message for a channel. The `sender' is the sender of the message
577      The `channel' is the channel. The `message' is the message.  Note
578      that `message' maybe NULL.  The `flags' indicates message flags
579      and it is used to determine how the message can be interpreted
580      (like it may tell the message is multimedia message). */
581   void (*channel_message)(SilcClient client, SilcClientConnection conn,
582                           SilcClientEntry sender, SilcChannelEntry channel,
583                           SilcMessagePayload payload,
584                           SilcChannelPrivateKey key, SilcMessageFlags flags,
585                           const unsigned char *message,
586                           SilcUInt32 message_len);
587
588   /* Private message to the client. The `sender' is the sender of the
589      message. The message is `message'and maybe NULL.  The `flags'
590      indicates message flags  and it is used to determine how the message
591      can be interpreted (like it may tell the message is multimedia
592      message). */
593   void (*private_message)(SilcClient client, SilcClientConnection conn,
594                           SilcClientEntry sender, SilcMessagePayload payload,
595                           SilcMessageFlags flags,
596                           const unsigned char *message,
597                           SilcUInt32 message_len);
598
599   /* Notify message to the client. The notify arguments are sent in the
600      same order as servers sends them. The arguments are same as received
601      from the server except for ID's.  If ID is received application receives
602      the corresponding entry to the ID. For example, if Client ID is received
603      application receives SilcClientEntry.  Also, if the notify type is
604      for channel the channel entry is sent to application (even if server
605      does not send it because client library gets the channel entry from
606      the Channel ID in the packet's header). */
607   void (*notify)(SilcClient client, SilcClientConnection conn,
608                  SilcNotifyType type, ...);
609
610   /* Command handler. This function is called always in the command function.
611      If error occurs it will be called as well. `conn' is the associated
612      client connection. `cmd_context' is the command context that was
613      originally sent to the command. `success' is FALSE if error occurred
614      during command. `command' is the command being processed. It must be
615      noted that this is not reply from server. This is merely called just
616      after application has called the command. Just to tell application
617      that the command really was processed. */
618   void (*command)(SilcClient client, SilcClientConnection conn,
619                   SilcClientCommandContext cmd_context, bool success,
620                   SilcCommand command, SilcStatus status);
621
622   /* Command reply handler. This function is called always in the command reply
623      function. If error occurs it will be called as well. Normal scenario
624      is that it will be called after the received command data has been parsed
625      and processed. The function is used to pass the received command data to
626      the application.
627
628      `conn' is the associated client connection. `cmd_payload' is the command
629      payload data received from server and it can be ignored. It is provided
630      if the application would like to re-parse the received command data,
631      however, it must be noted that the data is parsed already by the library
632      thus the payload can be ignored. `success' is FALSE if error occurred.
633      In this case arguments are not sent to the application. The `status' is
634      the command reply status server returned. The `command' is the command
635      reply being processed. The function has variable argument list and each
636      command defines the number and type of arguments it passes to the
637      application (on error they are not sent).
638
639      The arguments are sent in the same order as servers sends them.  The
640      arguments are same as received from the server except for ID's.  If
641      ID is received application receives the corresponding entry to the
642      ID. For example, if Client ID is receives application receives
643      SilcClientEntry. */
644   void (*command_reply)(SilcClient client, SilcClientConnection conn,
645                         SilcCommandPayload cmd_payload, bool success,
646                         SilcCommand command, SilcStatus status, ...);
647
648   /* Called to indicate that connection was either successfully established
649      or connecting failed.  This is also the first time application receives
650      the SilcClientConnection object which it should save somewhere.
651      The `status' indicated whether the connection were successful.  If it
652      is error value the application must always call the function
653      silc_client_close_connection. */
654   void (*connected)(SilcClient client, SilcClientConnection conn,
655                     SilcClientConnectionStatus status);
656
657   /* Called to indicate that connection was disconnected to the server.
658      The `status' may tell the reason of the disconnection, and if the
659      `message' is non-NULL it may include the disconnection message
660      received from server. Application must not call the
661      silc_client_close_connection in this callback.  The 'conn' is also
662      invalid after this function returns back to library. */
663   void (*disconnected)(SilcClient client, SilcClientConnection conn,
664                        SilcStatus status, const char *message);
665
666   /* Find authentication method and authentication data by hostname and
667      port. The hostname may be IP address as well. When the authentication
668      method has been resolved the `completion' callback with the found
669      authentication method and authentication data is called. The `conn'
670      may be NULL. */
671   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
672                           char *hostname, SilcUInt16 port,
673                           SilcGetAuthMeth completion, void *context);
674
675   /* Verifies received public key. The `conn_type' indicates which entity
676      (server, client etc.) has sent the public key. If user decides to trust
677      the application may save the key as trusted public key for later
678      use. The `completion' must be called after the public key has been
679      verified. */
680   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
681                             SilcSocketType conn_type, unsigned char *pk,
682                             SilcUInt32 pk_len, SilcSKEPKType pk_type,
683                             SilcVerifyPublicKey completion, void *context);
684
685   /* Ask (interact, that is) a passphrase from user. The passphrase is
686      returned to the library by calling the `completion' callback with
687      the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
688      if not then the library will attempt to encode. */
689   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
690                          SilcAskPassphrase completion, void *context);
691
692   /* Notifies application that failure packet was received.  This is called
693      if there is some protocol active in the client.  The `protocol' is the
694      protocol context.  The `failure' is opaque pointer to the failure
695      indication.  Note, that the `failure' is protocol dependant and
696      application must explicitly cast it to correct type.  Usually `failure'
697      is 32 bit failure type (see protocol specs for all protocol failure
698      types). */
699   void (*failure)(SilcClient client, SilcClientConnection conn,
700                   SilcProtocol protocol, void *failure);
701
702   /* Asks whether the user would like to perform the key agreement protocol.
703      This is called after we have received an key agreement packet or an
704      reply to our key agreement packet. This returns TRUE if the user wants
705      the library to perform the key agreement protocol and FALSE if it is not
706      desired (application may start it later by calling the function
707      silc_client_perform_key_agreement). If TRUE is returned also the
708      `completion' and `context' arguments must be set by the application. */
709   bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
710                         SilcClientEntry client_entry, const char *hostname,
711                         SilcUInt16 port, SilcKeyAgreementCallback *completion,
712                         void **context);
713
714   /* Notifies application that file transfer protocol session is being
715      requested by the remote client indicated by the `client_entry' from
716      the `hostname' and `port'. The `session_id' is the file transfer
717      session and it can be used to either accept or reject the file
718      transfer request, by calling the silc_client_file_receive or
719      silc_client_file_close, respectively. */
720   void (*ftp)(SilcClient client, SilcClientConnection conn,
721               SilcClientEntry client_entry, SilcUInt32 session_id,
722               const char *hostname, SilcUInt16 port);
723
724   /* Delivers SILC session detachment data indicated by `detach_data' to the
725      application.  If application has issued SILC_COMMAND_DETACH command
726      the client session in the SILC network is not quit.  The client remains
727      in the network but is detached.  The detachment data may be used later
728      to resume the session in the SILC Network.  The appliation is
729      responsible of saving the `detach_data', to for example in a file.
730
731      The detachment data can be given as argument to the functions
732      silc_client_connect_to_server, or silc_client_add_connection when
733      creating connection to remote server, inside SilcClientConnectionParams
734      structure.  If it is provided the client library will attempt to resume
735      the session in the network.  After the connection is created
736      successfully, the application is responsible of setting the user
737      interface for user into the same state it was before detaching (showing
738      same channels, channel modes, etc).  It can do this by fetching the
739      information (like joined channels) from the client library. */
740   void (*detach)(SilcClient client, SilcClientConnection conn,
741                  const unsigned char *detach_data,
742                  SilcUInt32 detach_data_len);
743 } SilcClientOperations;
744 /***/
745
746 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
747  *
748  * SYNOPSIS
749  *
750  *    typedef void (*SilcNicknameFormatParse)(const char *nickname,
751  *                                            char **ret_nickname);
752  *
753  * DESCRIPTION
754  *
755  *    A callback function provided by the application for the library in
756  *    SilcClientParams structure. This function parses the formatted
757  *    nickname string `nickname' and returns the true nickname to the
758  *    `ret_nickname' pointer. The library can call this function at
759  *    any time.
760  *
761  ***/
762 typedef void (*SilcNicknameFormatParse)(const char *nickname,
763                                         char **ret_nickname);
764
765 /****s* silcclient/SilcClientAPI/SilcClientParams
766  *
767  * NAME
768  *
769  *    typedef struct { ... } SilcClientParams;
770  *
771  * DESCRIPTION
772  *
773  *    Client parameters. This can be filled with proper values and
774  *    given as argument to the silc_client_alloc function. The structure
775  *    hold various parameters which affects the function of the client.
776  *
777  * SOURCE
778  */
779 typedef struct {
780   /* Number of maximum tasks the client library's scheduler can handle.
781      If set to zero, the default value will be used (200). For WIN32
782      systems this should be set to 64 as it is the hard limit dictated
783      by the WIN32. */
784   int task_max;
785
786   /* Rekey timeout in seconds. The client will perform rekey in this
787      time interval. If set to zero, the default value will be used. */
788   unsigned int rekey_secs;
789
790   /* Connection authentication method request timeout. If server does not
791      reply back the current authentication method when we've requested it
792      in this time interval we'll assume the reply will not come at all.
793      If set to zero, the default value (2 seconds) will be used. */
794   unsigned int connauth_request_secs;
795
796   /* Nickname format string. This can be used to order the client library
797      to save the nicknames in the library in a certain format. Since
798      nicknames are not unique in SILC it is possible to have multiple same
799      nicknames. Using this format string it is possible to order the library
800      to separate the multiple same nicknames from each other. The format
801      types are defined below and they can appear in any order in the format
802      string. If this is NULL then default format is used which is the
803      default nickname without anything else. The string MUST be NULL
804      terminated.
805
806      Following format types are available:
807
808      %n  nickname      - the real nickname returned by the server (mandatory)
809      %h  hostname      - the stripped hostname of the client
810      %H  full hostname - the full hostname of the client
811      %s  server name   - the server name the client is connected
812      %S  full server   - the full server name the client is connected
813      %a  number        - ascending number in case there are several
814                          same nicknames (fe. nick@host and nick@host2)
815
816      Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
817                              "%a!%n@%s"  (fe. nick@server, 2!nick@server)
818                              "%n@%H"     (fe. nick@host.domain.com)
819
820      By default this format is employed to the nicknames by the libary
821      only when there appears multiple same nicknames. If the library has
822      only one nickname cached the nickname is saved as is and without the
823      defined format. If you want always to save the nickname in the defined
824      format set the boolean field `nickname_force_format' to value TRUE.
825   */
826   char nickname_format[32];
827
828   /* If this is set to TRUE then the `nickname_format' is employed to all
829      saved nicknames even if there are no multiple same nicknames in the
830      cache. By default this is FALSE, which means that the `nickname_format'
831      is employed only if the library will receive a nickname that is
832      already saved in the cache. It is recommended to leave this to FALSE
833      value. */
834   bool nickname_force_format;
835
836   /* A callback function provided by the application for the library to
837      parse the nickname from the formatted nickname string. Even though
838      the libary formats the nicknames the application knows generally the
839      format better so this function should be provided for the library
840      if the application sets the `nickname_format' field. The library
841      will call this to get the true nickname from the provided formatted
842      nickname string whenever it needs the true nickname. */
843   SilcNicknameFormatParse nickname_parse;
844
845   /* If this is set to TRUE then the client will ignore all incoming
846      Requested Attributes queries and does not reply anything back.  This
847      usually leads into situation where server does not anymore send
848      the queries after seeing that client does not reply anything back.
849      If your application does not support Requested Attributes or you do
850      not want to use them set this to TRUE.  See SilcAttribute and
851      silc_client_attribute_add for more information on attributes. */
852   bool ignore_requested_attributes;
853   
854   /* If this is set to TRUE, the silcclient library will not register and 
855      deregister the cipher, pkcs, hash and hmac algorithms. The application
856          itself will need to handle that. */
857   bool dont_register_crypto_library;
858
859 } SilcClientParams;
860 /***/
861
862
863 /* Initialization functions (client.c) */
864
865 /****f* silcclient/SilcClientAPI/silc_client_alloc
866  *
867  * SYNOPSIS
868  *
869  *    SilcClient silc_client_alloc(SilcClientOperations *ops,
870  *                                 SilcClientParams *params,
871  *                                 void *application,
872  *                                 const char *silc_version);
873  *
874  * DESCRIPTION
875  *
876  *    Allocates new client object. This has to be done before client may
877  *    work. After calling this one must call silc_client_init to initialize
878  *    the client. The `application' is application specific user data pointer
879  *    and caller must free it. The `silc_version' is the application version
880  *    that will be used to compare against remote host's (usually a server)
881  *    version string.  The `application' context is accessible by the
882  *    application by client->application, client being SilcClient.
883  *
884  ***/
885 SilcClient silc_client_alloc(SilcClientOperations *ops,
886                              SilcClientParams *params,
887                              void *application,
888                              const char *version_string);
889
890 /****f* silcclient/SilcClientAPI/silc_client_free
891  *
892  * SYNOPSIS
893  *
894  *    void silc_client_free(SilcClient client);
895  *
896  * DESCRIPTION
897  *
898  *    Frees client object and its internals.  The execution of the client
899  *    should be stopped with silc_client_stop function before calling
900  *    this function.
901  *
902  ***/
903 void silc_client_free(SilcClient client);
904
905 /****f* silcclient/SilcClientAPI/silc_client_init
906  *
907  * SYNOPSIS
908  *
909  *    bool silc_client_init(SilcClient client);
910  *
911  * DESCRIPTION
912  *
913  *    Initializes the client. This makes all the necessary steps to make
914  *    the client ready to be run. One must call silc_client_run to run the
915  *    client. Returns FALSE if error occurred, TRUE otherwise.
916  *
917  ***/
918 bool silc_client_init(SilcClient client);
919
920 /****f* silcclient/SilcClientAPI/silc_client_run
921  *
922  * SYNOPSIS
923  *
924  *    void silc_client_run(SilcClient client);
925  *
926  * DESCRIPTION
927  *
928  *    Runs the client. This starts the scheduler from the utility library.
929  *    When this functions returns the execution of the appliation is over.
930  *    The client must be initialized before calling this.
931  *
932  ***/
933 void silc_client_run(SilcClient client);
934
935 /****f* silcclient/SilcClientAPI/silc_client_run_one
936  *
937  * SYNOPSIS
938  *
939  *    void silc_client_run_one(SilcClient client);
940  *
941  * DESCRIPTION
942  *
943  *    Runs the client and returns immeadiately. This function is used when
944  *    the SILC Client object indicated by the `client' is run under some
945  *    other scheduler, or event loop or main loop.  On GUI applications,
946  *    for example this may be desired to used to run the client under the
947  *    GUI application's main loop.  Typically the GUI application would
948  *    register an idle task that calls this function multiple times in
949  *    a second to quickly process the SILC specific data.
950  *
951  ***/
952 void silc_client_run_one(SilcClient client);
953
954 /****f* silcclient/SilcClientAPI/silc_client_stop
955  *
956  * SYNOPSIS
957  *
958  *    void silc_client_stop(SilcClient client);
959  *
960  * DESCRIPTION
961  *
962  *    Stops the client. This is called to stop the client and thus to stop
963  *    the program.  The client context must be freed with the silc_client_free
964  *    function.
965  *
966  ***/
967 void silc_client_stop(SilcClient client);
968
969
970 /* Connecting functions (client.c) */
971
972 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
973  *
974  * NAME
975  *
976  *    typedef struct { ... } SilcClientConnectionParams;
977  *
978  * DESCRIPTION
979  *
980  *    Client connection parameters.  This can be filled by the application
981  *    and given as argument to silc_client_connect_to_server or to
982  *    silc_client_add_connection.
983  *
984  * SOURCE
985  */
986 typedef struct {
987   /* The SILC session detachment data that was returned by `detach' client
988      operation when the application detached from the network.  Application
989      is responsible of saving the data and giving it as argument here
990      for resuming the session in the SILC network.
991
992      If this is provided here the client library will attempt to resume
993      the session in the network.  After the connection is created
994      successfully, the application is responsible of setting the user
995      interface for user into the same state it was before detaching (showing
996      same channels, channel modes, etc).  It can do this by fetching the
997      information (like joined channels) from the client library. */
998   unsigned char *detach_data;
999   SilcUInt32 detach_data_len;
1000
1001 } SilcClientConnectionParams;
1002 /***/
1003
1004 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
1005  *
1006  * SYNOPSIS
1007  *
1008  *    int silc_client_connect_to_server(SilcClient client,
1009  *                                      SilcClientConnectionParams *params,
1010  *                                      int port, char *host, void *context);
1011  *
1012  * DESCRIPTION
1013  *
1014  *    Connects to remote server. This is the main routine used to connect
1015  *    to SILC server. Returns -1 on error and the created socket otherwise.
1016  *    The `context' is user context that is saved into the SilcClientConnection
1017  *    that is created after the connection is created. Note that application
1018  *    may handle the connecting process outside the library. If this is the
1019  *    case then this function is not used at all. When the connecting is
1020  *    done the `connect' client operation is called, and the `context' is
1021  *    accessible with conn->context, conn being SilcClientConnection.
1022  *    If the `params' is provided they are used by the routine.
1023  *
1024  ***/
1025 int silc_client_connect_to_server(SilcClient client,
1026                                   SilcClientConnectionParams *params,
1027                                   int port, char *host, void *context);
1028
1029 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1030  *
1031  * SYNOPSIS
1032  *
1033  *
1034  *    SilcClientConnection
1035  *    silc_client_add_connection(SilcClient client,
1036  *                               SilcClientConnectionParams *params,
1037  *                               char *hostname, int port, void *context);
1038  *
1039  * DESCRIPTION
1040  *
1041  *    Allocates and adds new connection to the client. This adds the allocated
1042  *    connection to the connection table and returns a pointer to it. A client
1043  *    can have multiple connections to multiple servers. Every connection must
1044  *    be added to the client using this function. User data `context' may
1045  *    be sent as argument.  If the `params' is provided they are used by
1046  *    the routine.
1047  *
1048  * NOTES
1049  *
1050  *    This function is normally used only if the application performed
1051  *    the connecting outside the library, and did not called the
1052  *    silc_client_connect_to_server function at all. The library
1053  *    however may use this internally.
1054  *
1055  ***/
1056 SilcClientConnection
1057 silc_client_add_connection(SilcClient client,
1058                            SilcClientConnectionParams *params,
1059                            char *hostname, int port, void *context);
1060
1061 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1062  *
1063  * SYNOPSIS
1064  *
1065  *    void silc_client_del_connection(SilcClient client,
1066  *                                    SilcClientConnection conn);
1067  *
1068  * DESCRIPTION
1069  *
1070  *    Removes connection from client. Frees all memory. The library
1071  *    call this function automatically for all connection contexts.
1072  *    The application however may free the connection contexts it has
1073  *    allocated.
1074  *
1075  ***/
1076 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1077
1078 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1079  *
1080  * SYNOPSIS
1081  *
1082  *    void silc_client_add_socket(SilcClient client,
1083  *                                SilcSocketConnection sock);
1084  *
1085  * DESCRIPTION
1086  *
1087  *    Adds listener socket to the listener sockets table. This function is
1088  *    used to add socket objects that are listeners to the client.  This should
1089  *    not be used to add other connection objects.
1090  *
1091  ***/
1092 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1093
1094 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1095  *
1096  * SYNOPSIS
1097  *
1098  *    void silc_client_del_socket(SilcClient client,
1099  *                                SilcSocketConnection sock);
1100  *
1101  * DESCRIPTION
1102  *
1103  *    Deletes listener socket from the listener sockets table.  If the
1104  *    application has added a socket with silc_client_add_socket it must
1105  *    also free it using this function.
1106  *
1107  ***/
1108 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1109
1110 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1111  *
1112  * SYNOPSIS
1113  *
1114  *    void silc_client_start_key_exchange(SilcClient client,
1115  *                                        SilcClientConnection conn,
1116  *                                        int fd);
1117  *
1118  * DESCRIPTION
1119  *
1120  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1121  *    key material between client and server.  This function can be called
1122  *    directly if application is performing its own connecting and does not
1123  *    use the connecting provided by this library. This function is normally
1124  *    used only if the application performed the connecting outside the
1125  *    library. The library however may use this internally.  After the
1126  *    key exchange is performed the `connect' client operation is called.
1127  *
1128  * NOTES
1129  *
1130  *    The silc_client_add_connection must be called before calling this
1131  *    function to create the SilcClientConnection context for this
1132  *    connection.
1133  *
1134  ***/
1135 void silc_client_start_key_exchange(SilcClient client,
1136                                     SilcClientConnection conn,
1137                                     int fd);
1138
1139 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1140  *
1141  * SYNOPSIS
1142  *
1143  *    void silc_client_close_connection(SilcClient client,
1144  *                                      SilcClientConnection conn);
1145  *
1146  * DESCRIPTION
1147  *
1148  *    Closes connection to remote end. Free's all allocated data except
1149  *    for some information such as nickname etc. that are valid at all time.
1150  *    Usually application does not need to directly call this, except
1151  *    when explicitly closing the connection, or if an error occurs
1152  *    during connection to server (see 'connect' client operation for
1153  *    more information).
1154  *
1155  ***/
1156 void silc_client_close_connection(SilcClient client,
1157                                   SilcClientConnection conn);
1158
1159
1160 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1161
1162 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1163  *
1164  * SYNOPSIS
1165  *
1166  *    bool silc_client_send_channel_message(SilcClient client,
1167  *                                          SilcClientConnection conn,
1168  *                                          SilcChannelEntry channel,
1169  *                                          SilcChannelPrivateKey key,
1170  *                                          SilcMessageFlags flags,
1171  *                                          unsigned char *data,
1172  *                                          SilcUInt32 data_len,
1173  *                                          bool_force_send);
1174  *
1175  * DESCRIPTION
1176  *
1177  *    Sends packet to the `channel'. Packet to channel is always encrypted
1178  *    differently from "normal" packets. SILC header of the packet is
1179  *    encrypted with the next receiver's key and the rest of the packet is
1180  *    encrypted with the channel specific key. Padding and HMAC is computed
1181  *    with the next receiver's key. The `data' is the channel message. If
1182  *    the `force_send' is TRUE then the packet is sent immediately.
1183  *
1184  *    If `key' is provided then that private key is used to encrypt the
1185  *    channel message.  If it is not provided, private keys has not been
1186  *    set at all, the normal channel key is used automatically.  If private
1187  *    keys are set then the first key (the key that was added first as
1188  *    private key) is used.
1189  *
1190  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1191  *    digitally signed with the SILC key pair.
1192  *
1193  *    Returns TRUE if the message was sent, and FALSE if error occurred or
1194  *    the sending is not allowed due to channel modes (like sending is
1195  *    blocked).
1196  *
1197  ***/
1198 bool silc_client_send_channel_message(SilcClient client,
1199                                       SilcClientConnection conn,
1200                                       SilcChannelEntry channel,
1201                                       SilcChannelPrivateKey key,
1202                                       SilcMessageFlags flags,
1203                                       unsigned char *data,
1204                                       SilcUInt32 data_len,
1205                                       bool force_send);
1206
1207 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1208  *
1209  * SYNOPSIS
1210  *
1211  *    bool silc_client_send_private_message(SilcClient client,
1212  *                                          SilcClientConnection conn,
1213  *                                          SilcClientEntry client_entry,
1214  *                                          SilcMessageFlags flags,
1215  *                                          unsigned char *data,
1216  *                                          SilcUInt32 data_len,
1217  *                                          bool force_send);
1218  *
1219  * DESCRIPTION
1220  *
1221  *    Sends private message to remote client. If private message key has
1222  *    not been set with this client then the message will be encrypted using
1223  *    normal session keys. Private messages are special packets in SILC
1224  *    network hence we need this own function for them. This is similar
1225  *    to silc_client_packet_send_to_channel except that we send private
1226  *    message. The `data' is the private message. If the `force_send' is
1227  *    TRUE the packet is sent immediately.
1228  *
1229  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1230  *    digitally signed with the SILC key pair.
1231  *
1232  *    Returns TRUE if the message was sent, and FALSE if error occurred.
1233  *
1234  ***/
1235 bool silc_client_send_private_message(SilcClient client,
1236                                       SilcClientConnection conn,
1237                                       SilcClientEntry client_entry,
1238                                       SilcMessageFlags flags,
1239                                       unsigned char *data,
1240                                       SilcUInt32 data_len,
1241                                       bool force_send);
1242
1243
1244 /* Client and Channel entry retrieval (idlist.c) */
1245
1246 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1247  *
1248  * SYNOPSIS
1249  *
1250  *    typedef void (*SilcGetClientCallback)(SilcClient client,
1251  *                                          SilcClientConnection conn,
1252  *                                          SilcClientEntry *clients,
1253  *                                          SilcUInt32 clients_count,
1254  *                                          void *context);
1255  *
1256  * DESCRIPTION
1257  *
1258  *    Callback function given to the silc_client_get_client function. The
1259  *    found entries are allocated into the `clients' array. The array must
1260  *    not be freed by the receiver, the library will free it later. If the
1261  *    `clients' is NULL, no such clients exist in the SILC Network.
1262  *
1263  ***/
1264 typedef void (*SilcGetClientCallback)(SilcClient client,
1265                                       SilcClientConnection conn,
1266                                       SilcClientEntry *clients,
1267                                       SilcUInt32 clients_count,
1268                                       void *context);
1269
1270 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1271  *
1272  * SYNOPSIS
1273  *
1274  *    void silc_client_get_clients(SilcClient client,
1275  *                                 SilcClientConnection conn,
1276  *                                 const char *nickname,
1277  *                                 const char *server,
1278  *                                 SilcGetClientCallback completion,
1279  *                                 void *context);
1280  *
1281  * DESCRIPTION
1282  *
1283  *    Finds client entry or entries by the `nickname' and `server'. The
1284  *    completion callback will be called when the client entries has been
1285  *    found.  After the server returns the client information it is cached
1286  *    and can be accesses locally at a later time.  The resolving is done
1287  *    with IDENTIFY command.  The `server' may be NULL.
1288  *
1289  * NOTES
1290  *
1291  *    NOTE: This function is always asynchronous and resolves the client
1292  *    information from the server. Thus, if you already know the client
1293  *    information then use the silc_client_get_client_by_id function to
1294  *    get the client entry since this function may be very slow and should
1295  *    be used only to initially get the client entries.
1296  *
1297  *    Since this routine resolves with IDENTIFY command only the relevant
1298  *    information (user's nickname and username) is resolved.  For example,
1299  *    user's real name, channel list and others are not resolved.  Caller
1300  *    can/must resolve those separately if they are needed (for example,
1301  *    with silc_client_get_client_by_id_resolve).
1302  *
1303  ***/
1304 void silc_client_get_clients(SilcClient client,
1305                              SilcClientConnection conn,
1306                              const char *nickname,
1307                              const char *server,
1308                              SilcGetClientCallback completion,
1309                              void *context);
1310
1311 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
1312  *
1313  * SYNOPSIS
1314  *
1315  *    void silc_client_get_clients_whois(SilcClient client,
1316  *                                       SilcClientConnection conn,
1317  *                                       const char *nickname,
1318  *                                       const char *server,
1319  *                                       SilcBuffer attributes,
1320  *                                       SilcGetClientCallback completion,
1321  *                                       void *context);
1322  *
1323  * DESCRIPTION
1324  *
1325  *    Finds client entry or entries by the `nickname' and `server'. The
1326  *    completion callback will be called when the client entries has been
1327  *    found.  After the server returns the client information it is cached
1328  *    and can be accesses locally at a later time.  The resolving is done
1329  *    with WHOIS command.  The `server' may be NULL.
1330  *
1331  *    If the `attributes' is non-NULL then the buffer includes Requested
1332  *    Attributes which can be used to fetch very detailed information
1333  *    about the user. If it is NULL then only normal WHOIS query is
1334  *    made (for more information about attributes see SilcAttribute).
1335  *    Caller may create the `attributes' with silc_client_attributes_request
1336  *    function.
1337  *
1338  * NOTES
1339  *
1340  *    The resolving is done with WHOIS command. For this reason this
1341  *    command may take a long time because it resolves detailed user
1342  *    information.
1343  *
1344  ***/
1345 void silc_client_get_clients_whois(SilcClient client,
1346                                    SilcClientConnection conn,
1347                                    const char *nickname,
1348                                    const char *server,
1349                                    SilcBuffer attributes,
1350                                    SilcGetClientCallback completion,
1351                                    void *context);
1352
1353 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1354  *
1355  * SYNOPSIS
1356  *
1357  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1358  *                                                   SilcClientConnection conn,
1359  *                                                   const char *nickname,
1360  *                                                   const char *format,
1361  *                                                   SilcUInt32 *clients_count);
1362  *
1363  * DESCRIPTION
1364  *
1365  *    Same as silc_client_get_clients function but does not resolve anything
1366  *    from the server. This checks local cache and returns all matching
1367  *    clients from the local cache. If none was found this returns NULL.
1368  *    The `nickname' is the real nickname of the client, and the `format'
1369  *    is the formatted nickname to find exact match from multiple found
1370  *    entries. The format must be same as given in the SilcClientParams
1371  *    structure to the client library. If the `format' is NULL all found
1372  *    clients by `nickname' are returned. The caller must return the
1373  *    returned array.
1374  *
1375  ***/
1376 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1377                                                SilcClientConnection conn,
1378                                                const char *nickname,
1379                                                const char *format,
1380                                                SilcUInt32 *clients_count);
1381
1382 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1383  *
1384  * SYNOPSIS
1385  *
1386  *    void silc_client_get_clients_by_channel(SilcClient client,
1387  *                                            SilcClientConnection conn,
1388  *                                            SilcChannelEntry channel,
1389  *                                            SilcGetClientCallback completion,
1390  *                                            void *context);
1391  *
1392  * DESCRIPTION
1393  *
1394  *    Gets client entries by the channel indicated by `channel'. Thus,
1395  *    it resovles the users currently on that channel. If all users are
1396  *    already resolved this returns the users from the channel. If the
1397  *    users are resolved only partially this resolves the complete user
1398  *    information. If no users are resolved on this channel at all, this
1399  *    calls USERS command to resolve all users on the channel. The `completion'
1400  *    will be called after the entries are available. When server returns
1401  *    the client information it will be cached and can be accessed locally
1402  *    at a later time.
1403  *
1404  *    This function can be used for example in SILC_COMMAND_JOIN command
1405  *    reply handling in application to resolve users on that channel.  It
1406  *    also can be used after calling silc_client_get_channel_resolve to
1407  *    resolve users on that channel.
1408  *
1409  * NOTES
1410  *
1411  *    The resolving is done with WHOIS command. For this reason this
1412  *    command may take a long time because it resolves detailed user
1413  *    information.
1414  *
1415  ***/
1416 void silc_client_get_clients_by_channel(SilcClient client,
1417                                         SilcClientConnection conn,
1418                                         SilcChannelEntry channel,
1419                                         SilcGetClientCallback completion,
1420                                         void *context);
1421
1422 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1423  *
1424  * SYNOPSIS
1425  *
1426  *    void silc_client_get_clients_by_list(SilcClient client,
1427  *                                         SilcClientConnection conn,
1428  *                                         SilcUInt32 list_count,
1429  *                                         SilcBuffer client_id_list,
1430  *                                         SilcGetClientCallback completion,
1431  *                                         void *context);
1432  *
1433  * DESCRIPTION
1434  *
1435  *    Gets client entries by the list of client ID's `client_id_list'. This
1436  *    always resolves those client ID's it does not know yet from the server
1437  *    so this function might take a while. The `client_id_list' is a list
1438  *    of ID Payloads added one after other.  JOIN command reply and USERS
1439  *    command reply for example returns this sort of list. The `completion'
1440  *    will be called after the entries are available. When server returns
1441  *    the client information it will be cached and can be accessed locally
1442  *    at a later time.
1443  *
1444  * NOTES
1445  *
1446  *    The resolving is done with IDENTIFY command. This means that only
1447  *    the relevant information of user (it's nickname and username) is
1448  *    resolved. For example, user's real name, channel lists and others
1449  *    are not resolved. Caller can/must resolve those separately if they
1450  *    are needed (for example, with silc_client_get_client_by_id_resolve).
1451  *
1452  ***/
1453 void silc_client_get_clients_by_list(SilcClient client,
1454                                      SilcClientConnection conn,
1455                                      SilcUInt32 list_count,
1456                                      SilcBuffer client_id_list,
1457                                      SilcGetClientCallback completion,
1458                                      void *context);
1459
1460 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1461  *
1462  * SYNOPSIS
1463  *
1464  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1465  *                                                 SilcClientConnection conn,
1466  *                                                 SilcClientID *client_id);
1467  *
1468  * DESCRIPTION
1469  *
1470  *    Find entry for client by the client's ID. Returns the entry or NULL
1471  *    if the entry was not found.  This checks the local cache and does
1472  *    not resolve anything from server.
1473  *
1474  ***/
1475 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1476                                              SilcClientConnection conn,
1477                                              SilcClientID *client_id);
1478
1479 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1480  *
1481  * SYNOPSIS
1482  *
1483  *    void
1484  *    silc_client_get_client_by_id_resolve(SilcClient client,
1485  *                                         SilcClientConnection conn,
1486  *                                         SilcClientID *client_id,
1487  *                                         SilcBuffer attributes,
1488  *                                         SilcGetClientCallback completion,
1489  *                                         void *context);
1490  *
1491  * DESCRIPTION
1492  *
1493  *    Same as silc_client_get_client_by_id but will always resolve the
1494  *    information from the server. Use this only if you know that you
1495  *    do not have the entry and the only thing you know about the client
1496  *    is its ID. When server returns the client information it will be
1497  *    cache and can be accessed locally at a later time. The resolving
1498  *    is done by sending WHOIS command.
1499  *
1500  *    If the `attributes' is non-NULL then the buffer includes Requested
1501  *    Attributes which can be used to fetch very detailed information
1502  *    about the user. If it is NULL then only normal WHOIS query is
1503  *    made (for more information about attributes see SilcAttribute).
1504  *    Caller may create the `attributes' with silc_client_attributes_request
1505  *    function.
1506  *
1507  ***/
1508 void silc_client_get_client_by_id_resolve(SilcClient client,
1509                                           SilcClientConnection conn,
1510                                           SilcClientID *client_id,
1511                                           SilcBuffer attributes,
1512                                           SilcGetClientCallback completion,
1513                                           void *context);
1514
1515 /****f* silcclient/SilcClientAPI/silc_client_del_client
1516  *
1517  * SYNOPSIS
1518  *
1519  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1520  *                                SilcClientEntry client_entry)
1521  *
1522  * DESCRIPTION
1523  *
1524  *    Removes client from local cache by the client entry indicated by
1525  *    the `client_entry'.  Returns TRUE if the deletion were successful.
1526  *
1527  ***/
1528 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1529                             SilcClientEntry client_entry);
1530
1531 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1532  *
1533  * SYNOPSIS
1534  *
1535  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
1536  *                                           SilcClientConnection conn,
1537  *                                           SilcChannelEntry *channels,
1538  *                                           SilcUInt32 channels_count,
1539  *                                           void *context);
1540  *
1541  * DESCRIPTION
1542  *
1543  *    Callback function given to the silc_client_get_channel_* functions.
1544  *    The found entries are allocated into the `channels' array. The array
1545  *    must not be freed by the receiver, the library will free it later.
1546  *    If the `channel' is NULL, no such channel exist in the SILC Network.
1547  *
1548  ***/
1549 typedef void (*SilcGetChannelCallback)(SilcClient client,
1550                                        SilcClientConnection conn,
1551                                        SilcChannelEntry *channels,
1552                                        SilcUInt32 channels_count,
1553                                        void *context);
1554
1555 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1556  *
1557  * SYNOPSIS
1558  *
1559  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
1560  *                                             SilcClientConnection conn,
1561  *                                             char *channel_name);
1562  *
1563  * DESCRIPTION
1564  *
1565  *    Finds entry for channel by the channel name. Returns the entry or NULL
1566  *    if the entry was not found. It is found only if the client is joined
1567  *    to the channel.  Use silc_client_get_channel_resolve or
1568  *    silc_client_get_channel_by_id_resolve to resolve channel that client
1569  *    is not joined.
1570  *
1571  ***/
1572 SilcChannelEntry silc_client_get_channel(SilcClient client,
1573                                          SilcClientConnection conn,
1574                                          char *channel_name);
1575
1576 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1577  *
1578  * SYNOPSIS
1579  *
1580  *    void silc_client_get_channel_resolve(SilcClient client,
1581  *                                         SilcClientConnection conn,
1582  *                                         char *channel_name,
1583  *                                         SilcGetChannelCallback completion,
1584  *                                         void *context);
1585  *
1586  * DESCRIPTION
1587  *
1588  *    Resolves entry for channel by the channel name from the server.
1589  *    The resolving is done with IDENTIFY command. Note that users on
1590  *    the channel are not resolved at the same time. Use for example
1591  *    silc_client_get_clients_by_channel to resolve all users on a channel.
1592  *
1593  ***/
1594 void silc_client_get_channel_resolve(SilcClient client,
1595                                      SilcClientConnection conn,
1596                                      char *channel_name,
1597                                      SilcGetChannelCallback completion,
1598                                      void *context);
1599
1600 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1601  *
1602  * SYNOPSIS
1603  *
1604  *    SilcChannelEntry
1605  *    silc_client_get_channel_by_id(SilcClient client,
1606  *                                  SilcClientConnection conn,
1607  *                                  SilcChannelID *channel_id);
1608  *
1609  * DESCRIPTION
1610  *
1611  *    Finds channel entry by the channel ID. Returns the entry or NULL
1612  *    if the entry was not found.  This checks the local cache and does
1613  *    not resolve anything from server.
1614  *
1615  ***/
1616 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1617                                                SilcClientConnection conn,
1618                                                SilcChannelID *channel_id);
1619
1620 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1621  *
1622  * SYNOPSIS
1623  *
1624  *    void
1625  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1626  *                                          SilcClientConnection conn,
1627  *                                          SilcChannelID *channel_id,
1628  *                                          SilcGetClientCallback completion,
1629  *                                          void *context);
1630  *
1631  * DESCRIPTION
1632  *
1633  *    Resolves the channel information (its name mainly) from the server
1634  *    by the `channel_id'. Use this only if you know that you do not have
1635  *    the entry cached locally. The resolving is done with IDENTIFY command.
1636  *
1637  *    Note that users on the channel are not resolved at the same time.
1638  *    Use for example silc_client_get_clients_by_channel to resolve all
1639  *    users on a channel.
1640  *
1641  ***/
1642 void silc_client_get_channel_by_id_resolve(SilcClient client,
1643                                            SilcClientConnection conn,
1644                                            SilcChannelID *channel_id,
1645                                            SilcGetChannelCallback completion,
1646                                            void *context);
1647
1648 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1649  *
1650  * SYNOPSIS
1651  *
1652  *    bool silc_client_del_channel(SilcClient client,
1653  *                                 SilcClientConnection conn,
1654  *                                 SilcChannelEntry channel)
1655  *
1656  * DESCRIPTION
1657  *
1658  *    Removes channel from local cache by the channel entry indicated by
1659  *    the `channel'.  Returns TRUE if the deletion were successful.
1660  *
1661  ***/
1662 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1663                              SilcChannelEntry channel);
1664
1665 /****f* silcclient/SilcClientAPI/silc_client_get_server
1666  *
1667  * SYNOPSIS
1668  *
1669  *    SilcServerEntry silc_client_get_server(SilcClient client,
1670  *                                           SilcClientConnection conn,
1671  *                                           char *server_name)
1672  *
1673  * DESCRIPTION
1674  *
1675  *    Finds entry for server by the server name. Returns the entry or NULL
1676  *    if the entry was not found.
1677  *
1678  ***/
1679 SilcServerEntry silc_client_get_server(SilcClient client,
1680                                        SilcClientConnection conn,
1681                                        char *server_name);
1682
1683 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1684  *
1685  * SYNOPSIS
1686  *
1687  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1688  *                                                 SilcClientConnection conn,
1689  *                                                 SilcServerID *server_id);
1690  *
1691  * DESCRIPTION
1692  *
1693  *    Finds entry for server by the server ID. Returns the entry or NULL
1694  *    if the entry was not found.
1695  *
1696  ***/
1697 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1698                                              SilcClientConnection conn,
1699                                              SilcServerID *server_id);
1700
1701 /****f* silcclient/SilcClientAPI/silc_client_del_server
1702  *
1703  * SYNOPSIS
1704  *
1705  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1706  *                                SilcServerEntry server);
1707  *
1708  * DESCRIPTION
1709  *
1710  *    Removes server from local cache by the server entry indicated by
1711  *    the `server'.  Returns TRUE if the deletion were successful.
1712  *
1713  ***/
1714 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1715                             SilcServerEntry server);
1716
1717 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1718  *
1719  * SYNOPSIS
1720  *
1721  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1722  *                                           SilcClientEntry client_entry);
1723  *
1724  * DESCRIPTION
1725  *
1726  *    Returns the SilcChannelUser entry if the `client_entry' is joined on the
1727  *    channel indicated by the `channel'. NULL if client is not joined on
1728  *    the channel.
1729  *
1730  ***/
1731 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1732                                        SilcClientEntry client_entry);
1733
1734 /* Command management (command.c) */
1735
1736 /****f* silcclient/SilcClientAPI/silc_client_command_call
1737  *
1738  * SYNOPSIS
1739  *
1740  *    bool silc_client_command_call(SilcClient client,
1741  *                                  SilcClientConnection conn,
1742  *                                  const char *command_line, ...);
1743  *
1744  * DESCRIPTION
1745  *
1746  *    Calls and executes the command indicated by the `command_name'.
1747  *    The `command_line' is a string which includes the command's name and
1748  *    its arguments separated with whitespaces (' ').  If `command_line'
1749  *    is non-NULL then all variable arguments are ignored by default.
1750  *
1751  *    If `command_line' is NULL, then the variable arguments define the
1752  *    command's name and its arguments.  The first variable argument must
1753  *    be the command name.  The variable argument list must be terminated
1754  *    with NULL.
1755  *
1756  *    Returns FALSE if the command is not known and TRUE after command.
1757  *    execution.  The "command" client operation is called when the
1758  *    command is executed to indicate whether the command executed
1759  *    successfully or not.
1760  *
1761  *    The "command_reply" client operation will be called when reply is
1762  *    received from the server to the command.  Application may also use
1763  *    the silc_client_command_pending to attach to the command reply.
1764  *    The command identifier for silc_client_command_pending function after
1765  *    this function call is conn->cmd_ident, which application may use.
1766  *
1767  * EXAMPLE
1768  *
1769  *    silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1770  *                             NULL);
1771  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1772  *
1773  * NOTES
1774  *
1775  *    This command executes the commands implemented inside the client
1776  *    library.  These commands are designed for command line applications,
1777  *    but GUI application may call them too if needed.  Alternatively
1778  *    application may override the library and use silc_client_command_send
1779  *    function instead.
1780  *
1781  ***/
1782 bool silc_client_command_call(SilcClient client,
1783                               SilcClientConnection conn,
1784                               const char *command_line, ...);
1785
1786 /****f* silcclient/SilcClientAPI/silc_client_command_send
1787  *
1788  * SYNOPSIS
1789  *
1790  *    void silc_client_command_send(SilcClient client,
1791  *                                  SilcClientConnection conn,
1792  *                                  SilcCommand command, SilcUInt16 ident,
1793  *                                  SilcUInt32 argc, ...);
1794  *
1795  * DESCRIPTION
1796  *
1797  *    Generic function to send any command. The arguments must be sent already
1798  *    encoded into correct form and in correct order. If application wants
1799  *    to perform the commands by itself, it can do so and send the data
1800  *    directly to the server using this function.  If application is using
1801  *    the silc_client_command_call, this function is usually not used.
1802  *    Note that this overriders the Client Librarys commands and sends
1803  *    the command packet directly to server.
1804  *
1805  *    Programmer should get familiar with the SILC protocol commands
1806  *    specification when using this function, as the arguments needs to
1807  *    be encoded as specified in the protocol.
1808  *
1809  *    The variable arguments are a pair of { type, data, data_length },
1810  *    and the `argc' is the number of these pairs.
1811  *
1812  * EXAMPLE
1813  *
1814  *    silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1815  *                             1, nickname, strlen(nickname));
1816  *
1817  ***/
1818 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1819                               SilcCommand command, SilcUInt16 ident,
1820                               SilcUInt32 argc, ...);
1821
1822 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1823  *
1824  * SYNOPSIS
1825  *
1826  *    void silc_client_command_pending(SilcClientConnection conn,
1827  *                                     SilcCommand reply_cmd,
1828  *                                     SilcUInt16 ident,
1829  *                                     SilcCommandCb callback,
1830  *                                     void *context);
1831  *
1832  * DESCRIPTION
1833  *
1834  *    This function can be used to add pending command callback to be
1835  *    called when an command reply is received to an earlier sent command.
1836  *    The `reply_cmd' is the command that must be received in order for
1837  *    the pending command callback indicated by `callback' to be called.
1838  *    The `callback' will deliver the `context' and
1839  *    SilcClientCommandReplyContext which includes the internals of the
1840  *    command reply.
1841  *
1842  *    The `ident' is a command identifier which was set for the earlier
1843  *    sent command.  The command reply will include the same identifier
1844  *    and pending command callback will be called when the reply is
1845  *    received with the same command identifier.  It is possible to
1846  *    add multiple pending command callbacks for same command and for
1847  *    same identifier.
1848  *
1849  *    Application may use this function to add its own command reply
1850  *    handlers if it wishes not to use the standard `command_reply'
1851  *    client operation.  However, note that the pending command callback
1852  *    does not deliver parsed command reply, but application must parse
1853  *    it itself.
1854  *
1855  *    Note also that the application is notified about the received command
1856  *    reply through the `command_reply' client operation before calling
1857  *    the `callback` pending command callback.  That is the normal
1858  *    command reply handling, and is called regardless whether pending
1859  *    command callbacks are used or not.
1860  *
1861  *    Commands that application calls with silc_client_command_call
1862  *    will use a command identifier from conn->cmd_ident variable.  After
1863  *    calling the silc_client_command_call, the conn->cmd_ident includes
1864  *    the command identifier that was used for the command sending.
1865  *
1866  * EXAMPLE
1867  *
1868  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1869  *    silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1870  *                                my_ping_handler, my_ping_context);
1871  *
1872  ***/
1873 void silc_client_command_pending(SilcClientConnection conn,
1874                                  SilcCommand reply_cmd,
1875                                  SilcUInt16 ident,
1876                                  SilcCommandCb callback,
1877                                  void *context);
1878
1879
1880 /* Private Message key management (client_prvmsg.c) */
1881
1882 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1883  *
1884  * SYNOPSIS
1885  *
1886  *    bool silc_client_add_private_message_key(SilcClient client,
1887  *                                             SilcClientConnection conn,
1888  *                                             SilcClientEntry client_entry,
1889  *                                             const char *cipher,
1890  *                                             const char *hmac,
1891  *                                             unsigned char *key,
1892  *                                             SilcUInt32 key_len,
1893  *                                             bool generate_key,
1894  *                                             bool responder);
1895  *
1896  * DESCRIPTION
1897  *
1898  *    Adds private message key to the client library. The key will be used to
1899  *    encrypt all private message between the client and the remote client
1900  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1901  *    value `generate_key' is TRUE the library will generate random key.
1902  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1903  *    The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1904  *    that the requirements of the SILC protocol are met. The API, however,
1905  *    allows to allocate any cipher and HMAC.
1906  *
1907  *    If `responder' is TRUE then the sending and receiving keys will be
1908  *    set according the client being the receiver of the private key.  If
1909  *    FALSE the client is being the sender (or negotiator) of the private
1910  *    key.
1911  *
1912  *    It is not necessary to set key for normal private message usage. If the
1913  *    key is not set then the private messages are encrypted using normal
1914  *    session keys. Setting the private key, however, increases the security.
1915  *
1916  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1917  *    otherwise.
1918  *
1919  ***/
1920 bool silc_client_add_private_message_key(SilcClient client,
1921                                          SilcClientConnection conn,
1922                                          SilcClientEntry client_entry,
1923                                          const char *cipher,
1924                                          const char *hmac,
1925                                          unsigned char *key,
1926                                          SilcUInt32 key_len,
1927                                          bool generate_key,
1928                                          bool responder);
1929
1930 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1931  *
1932  * SYNOPSIS
1933  *
1934  *    bool
1935  *    silc_client_add_private_message_key_ske(SilcClient client,
1936  *                                            SilcClientConnection conn,
1937  *                                            SilcClientEntry client_entry,
1938  *                                            const char *cipher,
1939  *                                            const char *hmac,
1940  *                                            SilcSKEKeyMaterial *key);
1941  *
1942  * DESCRIPTION
1943  *
1944  *    Same as silc_client_add_private_message_key but takes the key material
1945  *    from the SKE key material structure. This structure is received if
1946  *    the application uses the silc_client_send_key_agreement to negotiate
1947  *    the key material. The `cipher' and `hmac' SHOULD be provided as it is
1948  *    negotiated also in the SKE protocol.
1949  *
1950  ***/
1951 bool silc_client_add_private_message_key_ske(SilcClient client,
1952                                              SilcClientConnection conn,
1953                                              SilcClientEntry client_entry,
1954                                              const char *cipher,
1955                                              const char *hmac,
1956                                              SilcSKEKeyMaterial *key,
1957                                              bool responder);
1958
1959 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1960  *
1961  * SYNOPSIS
1962  *
1963  *    bool silc_client_del_private_message_key(SilcClient client,
1964  *                                             SilcClientConnection conn,
1965  *                                             SilcClientEntry client_entry);
1966  *
1967  * DESCRIPTION
1968  *
1969  *    Removes the private message from the library. The key won't be used
1970  *    after this to protect the private messages with the remote `client_entry'
1971  *    client. Returns FALSE on error, TRUE otherwise.
1972  *
1973  ***/
1974 bool silc_client_del_private_message_key(SilcClient client,
1975                                          SilcClientConnection conn,
1976                                          SilcClientEntry client_entry);
1977
1978 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1979  *
1980  * SYNOPSIS
1981  *
1982  *    SilcPrivateMessageKeys
1983  *    silc_client_list_private_message_keys(SilcClient client,
1984  *                                          SilcClientConnection conn,
1985  *                                          SilcUInt32 *key_count);
1986  *
1987  * DESCRIPTION
1988  *
1989  *    Returns array of set private message keys associated to the connection
1990  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1991  *    count to the `key_count' argument. The array must be freed by the caller
1992  *    by calling the silc_client_free_private_message_keys function. Note:
1993  *    the keys returned in the array is in raw format. It might not be desired
1994  *    to show the keys as is. The application might choose not to show the keys
1995  *    at all or to show the fingerprints of the keys.
1996  *
1997  ***/
1998 SilcPrivateMessageKeys
1999 silc_client_list_private_message_keys(SilcClient client,
2000                                       SilcClientConnection conn,
2001                                       SilcUInt32 *key_count);
2002
2003 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key_request
2004  *
2005  * SYNOPSIS
2006  *
2007  *    bool
2008  *    silc_client_send_private_message_key_request(SilcClient client,
2009  *                                               SilcClientConnection conn,
2010  *                                               SilcClientEntry client_entry);
2011  *
2012  * DESCRIPTION
2013  *
2014  *    This function can be used to send an private message key indicator
2015  *    request to the remote client indicated by 'client_entry'.  This can
2016  *    be used when setting a static or pre-shared private message key.
2017  *    The sender of this packet is the initiator and must set the 'responder'
2018  *    argument in silc_client_add_private_message_key function to FALSE.
2019  *    The receiver of this indicator request must set it to TRUE, if the
2020  *    receiver decides to set a private message key.  By using this
2021  *    function applications may automate initiator/responder setting in
2022  *    private message key functions, without asking from user which one is
2023  *    the initiator and which one is responder.
2024  *
2025  * NOTES
2026  *
2027  *    The sender of this packet must set the private message key for
2028  *    'client_entry' before calling this function.  The 'responder'
2029  *    argument MUST be set to FALSE when setting the key.
2030  *
2031  ***/
2032 bool
2033 silc_client_send_private_message_key_request(SilcClient client,
2034                                              SilcClientConnection conn,
2035                                              SilcClientEntry client_entry);
2036
2037 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
2038  *
2039  * SYNOPSIS
2040  *
2041  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2042  *                                               SilcUInt32 key_count);
2043  *
2044  * DESCRIPTION
2045  *
2046  *    Frees the SilcPrivateMessageKeys array returned by the function
2047  *    silc_client_list_private_message_keys.
2048  *
2049  ***/
2050 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2051                                            SilcUInt32 key_count);
2052
2053
2054 /* Channel private key management (client_channel.c,
2055    SilcChannelPrivateKey is defined in idlist.h) */
2056
2057 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
2058  *
2059  * SYNOPSIS
2060  *
2061  *    bool silc_client_add_channel_private_key(SilcClient client,
2062  *                                             SilcClientConnection conn,
2063  *                                             SilcChannelEntry channel,
2064  *                                             const char *name,
2065  *                                             char *cipher,
2066  *                                             char *hmac,
2067  *                                             unsigned char *key,
2068  *                                             SilcUInt32 key_len,
2069  *                                             SilcChannelPrivateKey *ret_key);
2070  *
2071  * DESCRIPTION
2072  *
2073  *    Adds private key for channel. When channel has private key then the
2074  *    messages are encrypted using that key. All clients on the channel
2075  *    must also know the key in order to decrypt the messages. However,
2076  *    it is possible to have several private keys per one channel. In this
2077  *    case only some of the clients on the channel may know the one key
2078  *    and only some the other key.  The `name' can be application given
2079  *    name for the key.  This returns the created key to the 'ret_key'
2080  *    pointer if it is non-NULL;
2081  *
2082  *    If `cipher' and/or `hmac' is NULL then default values will be used
2083  *    (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
2084  *
2085  *    The private key for channel is optional. If it is not set then the
2086  *    channel messages are encrypted using the channel key generated by the
2087  *    server. However, setting the private key (or keys) for the channel
2088  *    significantly adds security. If more than one key is set the library
2089  *    will automatically try all keys at the message decryption phase. Note:
2090  *    setting many keys slows down the decryption phase as all keys has to
2091  *    be tried in order to find the correct decryption key. However, setting
2092  *    a few keys does not have big impact to the decryption performace.
2093  *
2094  * NOTES
2095  *
2096  *    NOTE: This is entirely local setting. The key set using this function
2097  *    is not sent to the network at any phase.
2098  *
2099  *    NOTE: If the key material was originated by the SKE protocol (using
2100  *    silc_client_send_key_agreement) then the `key' MUST be the
2101  *    key->send_enc_key as this is dictated by the SILC protocol. However,
2102  *    currently it is not expected that the SKE key material would be used
2103  *    as channel private key. However, this API allows it.
2104  *
2105  ***/
2106 bool silc_client_add_channel_private_key(SilcClient client,
2107                                          SilcClientConnection conn,
2108                                          SilcChannelEntry channel,
2109                                          const char *name,
2110                                          char *cipher,
2111                                          char *hmac,
2112                                          unsigned char *key,
2113                                          SilcUInt32 key_len,
2114                                          SilcChannelPrivateKey *ret_key);
2115
2116 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2117  *
2118  * SYNOPSIS
2119  *
2120  *    bool silc_client_del_channel_private_keys(SilcClient client,
2121  *                                              SilcClientConnection conn,
2122  *                                              SilcChannelEntry channel);
2123  *
2124  * DESCRIPTION
2125  *
2126  *    Removes all private keys from the `channel'. The old channel key is used
2127  *    after calling this to protect the channel messages. Returns FALSE on
2128  *    on error, TRUE otherwise.
2129  *
2130  ***/
2131 bool silc_client_del_channel_private_keys(SilcClient client,
2132                                           SilcClientConnection conn,
2133                                           SilcChannelEntry channel);
2134
2135 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2136  *
2137  * SYNOPSIS
2138  *
2139  *    bool silc_client_del_channel_private_key(SilcClient client,
2140  *                                            SilcClientConnection conn,
2141  *                                            SilcChannelEntry channel,
2142  *                                            SilcChannelPrivateKey key);
2143  *
2144  * DESCRIPTION
2145  *
2146  *    Removes and frees private key `key' from the channel `channel'.
2147  *    The `key' is retrieved by calling the function
2148  *    silc_client_list_channel_private_keys. The key is not used after
2149  *    this. If the key was last private key then the old channel key is
2150  *    used hereafter to protect the channel messages. This returns FALSE
2151  *    on error, TRUE otherwise.
2152  *
2153  ***/
2154 bool silc_client_del_channel_private_key(SilcClient client,
2155                                          SilcClientConnection conn,
2156                                          SilcChannelEntry channel,
2157                                          SilcChannelPrivateKey key);
2158
2159 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2160  *
2161  * SYNOPSIS
2162  *
2163  *    SilcChannelPrivateKey *
2164  *    silc_client_list_channel_private_keys(SilcClient client,
2165  *                                          SilcClientConnection conn,
2166  *                                          SilcChannelEntry channel,
2167  *                                          SilcUInt32 *key_count);
2168  *
2169  * DESCRIPTION
2170  *
2171  *    Returns array (pointers) of private keys associated to the `channel'.
2172  *    The caller must free the array by calling the function
2173  *    silc_client_free_channel_private_keys. The pointers in the array may be
2174  *    used to delete the specific key by giving the pointer as argument to the
2175  *    function silc_client_del_channel_private_key.
2176  *
2177  ***/
2178 SilcChannelPrivateKey *
2179 silc_client_list_channel_private_keys(SilcClient client,
2180                                       SilcClientConnection conn,
2181                                       SilcChannelEntry channel,
2182                                       SilcUInt32 *key_count);
2183
2184 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2185  *
2186  * SYNOPSIS
2187  *
2188  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2189  *                                               SilcUInt32 key_count);
2190  *
2191  * DESCRIPTION
2192  *
2193  *    Frees the SilcChannelPrivateKey array.
2194  *
2195  ***/
2196 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2197                                            SilcUInt32 key_count);
2198
2199 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2200  *
2201  * SYNOPSIS
2202  *
2203  *    void silc_client_current_channel_private_key(SilcClient client,
2204  *                                                 SilcClientConnection conn,
2205  *                                                 SilcChannelEntry channel,
2206  *                                                 SilcChannelPrivateKey key);
2207  *
2208  * DESCRIPTION
2209  *
2210  *    Sets the `key' to be used as current channel private key on the
2211  *    `channel'.  Packet sent after calling this function will be secured
2212  *    with `key'.
2213  *
2214  ***/
2215 void silc_client_current_channel_private_key(SilcClient client,
2216                                              SilcClientConnection conn,
2217                                              SilcChannelEntry channel,
2218                                              SilcChannelPrivateKey key);
2219
2220
2221 /* Key Agreement routines (client_keyagr.c) */
2222
2223 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2224  *
2225  * SYNOPSIS
2226  *
2227  *    void silc_client_send_key_agreement(SilcClient client,
2228  *                                        SilcClientConnection conn,
2229  *                                        SilcClientEntry client_entry,
2230  *                                        char *hostname,
2231  *                                        int port,
2232  *                                        SilcUInt32 timeout_secs,
2233  *                                        SilcKeyAgreementCallback completion,
2234  *                                        void *context);
2235  *
2236  * DESCRIPTION
2237  *
2238  *    Sends key agreement request to the remote client indicated by the
2239  *    `client_entry'. If the caller provides the `hostname' and the `port'
2240  *    arguments then the library will bind the client to that hostname and
2241  *    that port for the key agreement protocol. It also sends the `hostname'
2242  *    and the `port' in the key agreement packet to the remote client. This
2243  *    would indicate that the remote client may initiate the key agreement
2244  *    protocol to the `hostname' on the `port'.  If port is zero then the
2245  *    bound port is undefined (the operating system defines it).
2246  *
2247  *    If the `hostname' and `port' is not provided then empty key agreement
2248  *    packet is sent to the remote client. The remote client may reply with
2249  *    the same packet including its hostname and port. If the library receives
2250  *    the reply from the remote client the `key_agreement' client operation
2251  *    callback will be called to verify whether the user wants to perform the
2252  *    key agreement or not.
2253  *
2254  * NOTES
2255  *
2256  *    NOTE: If the application provided the `hostname' and the `port' and the
2257  *    remote side initiates the key agreement protocol it is not verified
2258  *    from the user anymore whether the protocol should be executed or not.
2259  *    By setting the `hostname' and `port' the user gives permission to
2260  *    perform the protocol (we are responder in this case).
2261  *
2262  *    NOTE: If the remote side decides not to initiate the key agreement
2263  *    or decides not to reply with the key agreement packet then we cannot
2264  *    perform the key agreement at all. If the key agreement protocol is
2265  *    performed the `completion' callback with the `context' will be called.
2266  *    If remote side decides to ignore the request the `completion' will be
2267  *    called after the specified timeout, `timeout_secs'.
2268  *
2269  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
2270  *    will not be called at all since this does nothing more than sending
2271  *    a packet to the remote host.
2272  *
2273  *    NOTE: There can be only one active key agreement for one client entry.
2274  *    Before setting new one, the old one must be finished (it is finished
2275  *    after calling the completion callback) or the function
2276  *    silc_client_abort_key_agreement must be called.
2277  *
2278  ***/
2279 void silc_client_send_key_agreement(SilcClient client,
2280                                     SilcClientConnection conn,
2281                                     SilcClientEntry client_entry,
2282                                     const char *hostname,
2283                                     const char *bindhost,
2284                                     int port,
2285                                     SilcUInt32 timeout_secs,
2286                                     SilcKeyAgreementCallback completion,
2287                                     void *context);
2288
2289 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2290  *
2291  * SYNOPSIS
2292  *
2293  *    void
2294  *    silc_client_perform_key_agreement(SilcClient client,
2295  *                                      SilcClientConnection conn,
2296  *                                      SilcClientEntry client_entry,
2297  *                                      char *hostname,
2298  *                                      int port,
2299  *                                      SilcKeyAgreementCallback completion,
2300  *                                      void *context);
2301  *
2302  * DESCRIPTION
2303  *
2304  *    Performs the actual key agreement protocol. Application may use this
2305  *    to initiate the key agreement protocol. This can be called for example
2306  *    after the application has received the `key_agreement' client operation,
2307  *    and did not return TRUE from it.
2308  *
2309  *    The `hostname' is the remote hostname (or IP address) and the `port'
2310  *    is the remote port. The `completion' callback with the `context' will
2311  *    be called after the key agreement protocol.
2312  *
2313  * NOTES
2314  *
2315  *    NOTE: If the application returns TRUE in the `key_agreement' client
2316  *    operation the library will automatically start the key agreement. In this
2317  *    case the application must not call this function. However, application
2318  *    may choose to just ignore the `key_agreement' client operation (and
2319  *    merely just print information about it on the screen) and call this
2320  *    function when the user whishes to do so (by, for example, giving some
2321  *    specific command). Thus, the API provides both, automatic and manual
2322  *    initiation of the key agreement. Calling this function is the manual
2323  *    initiation and returning TRUE in the `key_agreement' client operation
2324  *    is the automatic initiation.
2325  *
2326  ***/
2327 void silc_client_perform_key_agreement(SilcClient client,
2328                                        SilcClientConnection conn,
2329                                        SilcClientEntry client_entry,
2330                                        char *hostname,
2331                                        int port,
2332                                        SilcKeyAgreementCallback completion,
2333                                        void *context);
2334
2335 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2336  *
2337  * SYNOPSIS
2338  *
2339  *    void
2340  *    silc_client_perform_key_agreement_fd(SilcClient client,
2341  *                                         SilcClientConnection conn,
2342  *                                         SilcClientEntry client_entry,
2343  *                                         int sock,
2344  *                                         char *hostname,
2345  *                                         SilcKeyAgreementCallback completion,
2346  *                                         void *context);
2347  *
2348  * DESCRIPTION
2349  *
2350  *    Same as above but application has created already the connection to
2351  *    the remote host. The `sock' is the socket to the remote connection.
2352  *    Application can use this function if it does not want the client library
2353  *    to create the connection.
2354  *
2355  ***/
2356 void silc_client_perform_key_agreement_fd(SilcClient client,
2357                                           SilcClientConnection conn,
2358                                           SilcClientEntry client_entry,
2359                                           int sock,
2360                                           char *hostname,
2361                                           SilcKeyAgreementCallback completion,
2362                                           void *context);
2363
2364 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2365  *
2366  * SYNOPSIS
2367  *
2368  *    void silc_client_abort_key_agreement(SilcClient client,
2369  *                                         SilcClientConnection conn,
2370  *                                         SilcClientEntry client_entry);
2371  *
2372  * DESCRIPTION
2373  *
2374  *    This function can be called to unbind the hostname and the port for
2375  *    the key agreement protocol. However, this function has effect only
2376  *    before the key agreement protocol has been performed. After it has
2377  *    been performed the library will automatically unbind the port. The
2378  *    `client_entry' is the client to which we sent the key agreement
2379  *    request.  The key agreement completion callback will be called
2380  *    with SILC_KEY_AGREEMENT_ABORTED status.
2381  *
2382  ***/
2383 void silc_client_abort_key_agreement(SilcClient client,
2384                                      SilcClientConnection conn,
2385                                      SilcClientEntry client_entry);
2386
2387
2388 /* Misc functions */
2389
2390 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2391  *
2392  * SYNOPSIS
2393  *
2394  *    void silc_client_set_away_message(SilcClient client,
2395  *                                      SilcClientConnection conn,
2396  *                                      char *message);
2397  *
2398  * DESCRIPTION
2399  *
2400  *    Sets away `message'.  The away message may be set when the client's
2401  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
2402  *    to anyone who sends private message.  The `message' will be sent
2403  *    automatically back to the the client who send private message.  If
2404  *    away message is already set this replaces the old message with the
2405  *    new one.  If `message' is NULL the old away message is removed.
2406  *    The sender may freely free the memory of the `message'.
2407  *
2408  ***/
2409 void silc_client_set_away_message(SilcClient client,
2410                                   SilcClientConnection conn,
2411                                   char *message);
2412
2413 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2414  *
2415  * SYNOPSIS
2416  *
2417  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2418  *                                              SilcClientConnection conn,
2419  *                                              SilcAuthMethod auth_meth,
2420  *                                              void *context);
2421  *
2422  * DESCRIPTION
2423  *
2424  *    Connection authentication method request callback. This is called
2425  *    by the client library after it has received the authentication method
2426  *    that the application requested by calling the function
2427  *    silc_client_request_authentication_method.
2428  *
2429  ***/
2430 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2431                                           SilcClientConnection conn,
2432                                           SilcAuthMethod auth_meth,
2433                                           void *context);
2434
2435 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2436  *
2437  * SYNOPSIS
2438  *
2439  *    void
2440  *    silc_client_request_authentication_method(SilcClient client,
2441  *                                              SilcClientConnection conn,
2442  *                                              SilcConnectionAuthRequest
2443  *                                                callback,
2444  *                                              void *context);
2445  *
2446  * DESCRIPTION
2447  *
2448  *    This function can be used to request the current authentication method
2449  *    from the server. This may be called when connecting to the server
2450  *    and the client library requests the authentication data from the
2451  *    application. If the application does not know the current authentication
2452  *    method it can request it from the server using this function.
2453  *    The `callback' with `context' will be called after the server has
2454  *    replied back with the current authentication method.
2455  *
2456  ***/
2457 void
2458 silc_client_request_authentication_method(SilcClient client,
2459                                           SilcClientConnection conn,
2460                                           SilcConnectionAuthRequest callback,
2461                                           void *context);
2462
2463 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2464  *
2465  * NAME
2466  *
2467  *    typedef enum { ... } SilcClientMonitorStatus;
2468  *
2469  * DESCRIPTION
2470  *
2471  *    File transmission session status types.  These will indicate
2472  *    the status of the file transmission session.
2473  *
2474  * SOURCE
2475  */
2476 typedef enum {
2477   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
2478   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
2479   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
2480   SILC_CLIENT_FILE_MONITOR_GET,
2481   SILC_CLIENT_FILE_MONITOR_PUT,
2482   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
2483   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
2484 } SilcClientMonitorStatus;
2485 /***/
2486
2487 /****d* silcclient/SilcClientAPI/SilcClientFileError
2488  *
2489  * NAME
2490  *
2491  *    typedef enum { ... } SilcClientFileError;
2492  *
2493  * DESCRIPTION
2494  *
2495  *    File transmission error types.  These types are returned by
2496  *    some of the file transmission functions, and by the monitor
2497  *    callback to indicate error.
2498  *
2499  * SOURCE
2500  */
2501 typedef enum {
2502   SILC_CLIENT_FILE_OK,
2503   SILC_CLIENT_FILE_ERROR,
2504   SILC_CLIENT_FILE_UNKNOWN_SESSION,
2505   SILC_CLIENT_FILE_ALREADY_STARTED,
2506   SILC_CLIENT_FILE_NO_SUCH_FILE,
2507   SILC_CLIENT_FILE_PERMISSION_DENIED,
2508   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2509 } SilcClientFileError;
2510 /***/
2511
2512 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2513  *
2514  * SYNOPSIS
2515  *
2516  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
2517  *                                          SilcClientConnection conn,
2518  *                                          SilcClientMonitorStatus status,
2519  *                                          SilcClientFileError error,
2520  *                                          SilcUInt64 offset,
2521  *                                          SilcUInt64 filesize,
2522  *                                          SilcClientEntry client_entry,
2523  *                                          SilcUInt32 session_id,
2524  *                                          const char *filepath,
2525  *                                          void *context);
2526  *
2527  * DESCRIPTION
2528  *
2529  *    Monitor callback that is called during the file transmission to
2530  *    monitor the transmission process.  The `status' indicates the current
2531  *    monitoring process.  The `error' will indicate the error type
2532  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
2533  *    currently transmitted amount of total `filesize'.  The `client_entry'
2534  *    indicates the remote client, and the transmission session ID is the
2535  *    `session_id'.  The filename being transmitted is indicated by the
2536  *    `filepath'.
2537  *
2538  ***/
2539 typedef void (*SilcClientFileMonitor)(SilcClient client,
2540                                       SilcClientConnection conn,
2541                                       SilcClientMonitorStatus status,
2542                                       SilcClientFileError error,
2543                                       SilcUInt64 offset,
2544                                       SilcUInt64 filesize,
2545                                       SilcClientEntry client_entry,
2546                                       SilcUInt32 session_id,
2547                                       const char *filepath,
2548                                       void *context);
2549
2550 /****f* silcclient/SilcClientAPI/SilcClientFileName
2551  *
2552  * SYNOPSIS
2553  *
2554  *    typedef void (*SilcClientFileName)(const char *filepath,
2555  *                                       void *context);
2556  *
2557  * DESCRIPTION
2558  *
2559  *    Completion callback for the SilcClientFileAskName callback function.
2560  *    Application calls this to deliver the filepath and filename where
2561  *    the downloaded file is to be saved.
2562  *
2563  ***/
2564 typedef void (*SilcClientFileName)(const char *filepath,
2565                                    void *context);
2566
2567 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2568  *
2569  * SYNOPSIS
2570  *
2571  *    typedef void (*SilcClientFileAskName)(SilcClient client,
2572  *                                          SilcClientConnection conn,
2573  *                                          SilcUInt32 session_id,
2574  *                                          const char *remote_filename,
2575  *                                          SilcClientFileName completion,
2576  *                                          void *completion_context,
2577  *                                          void *context);
2578  *
2579  * DESCRIPTION
2580  *
2581  *    File name asking callback, that is called if it is given to the
2582  *    silc_client_file_receive and the path given to that as argument was
2583  *    NULL.  The library calls this to ask the filename and filepath to
2584  *    where the file is to be saved.  The 'remote_filename' is the file
2585  *    that is being downloaded.  Application must call the 'completion'
2586  *    with 'completion_context' to continue with the file downloading.
2587  *    It is not mandatory to provide this to the silc_client_file_receive.
2588  *
2589  ***/
2590 typedef void (*SilcClientFileAskName)(SilcClient client,
2591                                       SilcClientConnection conn,
2592                                       SilcUInt32 session_id,
2593                                       const char *remote_filename,
2594                                       SilcClientFileName completion,
2595                                       void *completion_context,
2596                                       void *context);
2597
2598 /****f* silcclient/SilcClientAPI/silc_client_file_send
2599  *
2600  * SYNOPSIS
2601  *
2602  *    SilcClientFileError
2603  *    silc_client_file_send(SilcClient client,
2604  *                          SilcClientConnection conn,
2605  *                          SilcClientFileMonitor monitor,
2606  *                          void *monitor_context,
2607  *                          const char *local_ip,
2608  *                          SilcUInt32 local_port,
2609  *                          bool do_not_bind,
2610  *                          SilcClientEntry client_entry,
2611  *                          const char *filepath);
2612  *                          SilcUInt32 *session_id);
2613  *
2614  * DESCRIPTION
2615  *
2616  *    Sends a file indicated by the `filepath' to the remote client
2617  *    indicated by the `client_entry'.  This will negotiate a secret key
2618  *    with the remote client before actually starting the transmission of
2619  *    the file.  The `monitor' callback will be called to monitor the
2620  *    transmission of the file.
2621  *
2622  *    This returns a file session ID for the file transmission to the
2623  *    `session_id' pointer.  It can be used to close the session (and
2624  *    abort the file transmission) by calling the silc_client_file_close
2625  *    function.  The session ID is also returned in the `monitor' callback.
2626  *
2627  *    If the `local_ip' is provided then this will try to bind the
2628  *    listener for key exchange protocol to that IP.  If `local_port' is
2629  *    non-zero that port is used.  If `local_ip' is NULL then this will
2630  *    automatically attempt to bind it to local IP address of the machine.
2631  *    If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2632  *    ignored and it is expected that the receiver will provide the
2633  *    point of contact.  This is usefull if the sender is behind NAT.
2634  *
2635  *    If error will occur during the file transfer process the error
2636  *    status will be returned in the monitor callback.  In this case
2637  *    the application must call silc_client_file_close to close the
2638  *    session.
2639  *
2640  ***/
2641 SilcClientFileError
2642 silc_client_file_send(SilcClient client,
2643                       SilcClientConnection conn,
2644                       SilcClientFileMonitor monitor,
2645                       void *monitor_context,
2646                       const char *local_ip,
2647                       SilcUInt32 local_port,
2648                       bool do_not_bind,
2649                       SilcClientEntry client_entry,
2650                       const char *filepath,
2651                       SilcUInt32 *session_id);
2652
2653 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2654  *
2655  * SYNOPSIS
2656  *
2657  *    SilcClientFileError
2658  *    silc_client_file_receive(SilcClient client,
2659  *                             SilcClientConnection conn,
2660  *                             SilcClientFileMonitor monitor,
2661  *                             void *monitor_context,
2662  *                             const char *path,
2663  *                             SilcUInt32 session_id,
2664  *                             SilcClientFileAskName ask_name,
2665  *                             void *ask_name_context);
2666  *
2667  * DESCRIPTION
2668  *
2669  *    Receives a file from a client indicated by the `client_entry'.  The
2670  *    `session_id' indicates the file transmission session and it has been
2671  *    received in the `ftp' client operation function.  This will actually
2672  *    perform the key agreement protocol with the remote client before
2673  *    actually starting the file transmission.  The `monitor' callback
2674  *    will be called to monitor the transmission.  If `path' is non-NULL
2675  *    the file will be saved into that directory.  If NULL the file is
2676  *    saved in the current working directory, unless the 'ask_name'
2677  *    callback is non-NULL.  In this case the callback is called to ask
2678  *    the path and filename from application.
2679  *
2680  *    If error will occur during the file transfer process the error
2681  *    status will be returned in the monitor callback.  In this case
2682  *    the application must call silc_client_file_close to close the
2683  *    session.
2684  *
2685  ***/
2686 SilcClientFileError
2687 silc_client_file_receive(SilcClient client,
2688                          SilcClientConnection conn,
2689                          SilcClientFileMonitor monitor,
2690                          void *monitor_context,
2691                          const char *path,
2692                          SilcUInt32 session_id,
2693                          SilcClientFileAskName ask_name,
2694                          void *ask_name_context);
2695
2696 /****f* silcclient/SilcClientAPI/silc_client_file_close
2697  *
2698  * SYNOPSIS
2699  *
2700  *    SilcClientFileError silc_client_file_close(SilcClient client,
2701  *                                               SilcClientConnection conn,
2702  *                                               SilcUInt32 session_id);
2703  *
2704  * DESCRIPTION
2705  *
2706  *    Closes file transmission session indicated by the `session_id'.
2707  *    If file transmission is being conducted it will be aborted
2708  *    automatically. This function is also used to close the session
2709  *    after successful file transmission. This function can be used
2710  *    also to reject incoming file transmission request.  If the
2711  *    session was already started and the monitor callback was set
2712  *    the monitor callback will be called with the monitor status
2713  *    SILC_CLIENT_FILE_MONITOR_CLOSED.
2714  *
2715  ***/
2716 SilcClientFileError silc_client_file_close(SilcClient client,
2717                                            SilcClientConnection conn,
2718                                            SilcUInt32 session_id);
2719
2720 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2721  *
2722  * SYNOPSIS
2723  *
2724  *    SilcAttributePayload
2725  *    silc_client_attribute_add(SilcClient client,
2726  *                              SilcClientConnection conn,
2727  *                              SilcAttribute attribute,
2728  *                              void *object,
2729  *                              SilcUInt32 object_size);
2730  *
2731  * DESCRIPTION
2732  *
2733  *    Add new Requsted Attribute for WHOIS command to the client library.
2734  *    The `attribute' object indicated by `object' is added and allocated
2735  *    SilcAttributePayload is returned.  The `object' must be of correct
2736  *    type and of correct size.  See the SilcAttribute for object types
2737  *    for different attributes.  You may also get all added attributes
2738  *    from the client with silc_client_attributes_get function.
2739  *
2740  *    Requested Attributes are different personal information about the
2741  *    user, status information and other information which other users
2742  *    may query with WHOIS command.  Application may set these so that
2743  *    if someone sends WHOIS query these attributes will be replied back
2744  *    to the sender.  The library always puts the public key to the
2745  *    Requested Attributes, but if application wishes to add additional
2746  *    public keys (or certificates) it can be done with this interface.
2747  *    Library also always computes digital signature of the attributes
2748  *    automatically, so application does not need to do that.
2749  *
2750  ***/
2751 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2752                                                SilcClientConnection conn,
2753                                                SilcAttribute attribute,
2754                                                void *object,
2755                                                SilcUInt32 object_size);
2756
2757 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2758  *
2759  * SYNOPSIS
2760  *
2761  *    bool silc_client_attribute_del(SilcClient client,
2762  *                                   SilcClientConnection conn,
2763  *                                   SilcAttribute attribute,
2764  *                                   SilcAttributePayload attr);
2765  *
2766  * DESCRIPTION
2767  *
2768  *    Delete a Requested Attribute from the client.  If the `attribute'
2769  *    is non-zero then all attributes of that type are deleted and the
2770  *    `attr' is ignored.  If `attr' is non-NULL then that specific
2771  *    attribute is deleted and `attribute' is ignored.
2772  *
2773  *    You may get all added attributes with the function
2774  *    silc_client_attributes_get and to get the SilcAttributePayload.
2775  *    This function Returns TRUE if the attribute was found and deleted.
2776  *
2777  ***/
2778 bool silc_client_attribute_del(SilcClient client,
2779                                SilcClientConnection conn,
2780                                SilcAttribute attribute,
2781                                SilcAttributePayload attr);
2782
2783 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2784  *
2785  * SYNOPSIS
2786  *
2787  *    const SilcHashTable
2788  *    silc_client_attributes_get(SilcClient client,
2789  *                               SilcClientConnection conn);
2790  *
2791  * DESCRIPTION
2792  *
2793  *    Returns pointer to the SilcHashTable which includes all the added
2794  *    Requested Attributes.  The caller must not free the hash table.
2795  *    The caller may use SilcHashTableList and silc_hash_table_list to
2796  *    traverse the table.  Each entry in the hash table is one added
2797  *    SilcAttributePayload.  It is possible to delete a attribute
2798  *    payload while traversing the table.
2799  *
2800  ***/
2801 const SilcHashTable silc_client_attributes_get(SilcClient client,
2802                                                SilcClientConnection conn);
2803
2804 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2805  *
2806  * SYNOPSIS
2807  *
2808  *    SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2809  *
2810  * DESCRIPTION
2811  *
2812  *    Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2813  *    then all attributes are requested.  Alternatively, `attribute' and
2814  *    all variable arguments can each be requested attribute.  In this case
2815  *    the last must be set to zero (0) to complete the variable list of
2816  *    requested attributes.  See SilcAttribute for all attributes.
2817  *    You can give the returned buffer as argument to for example
2818  *    silc_client_get_client_by_id_resolve function.
2819  *
2820  * EXAMPLE
2821  *
2822  *    Request all attributes
2823  *    buffer = silc_client_attributes_request(0);
2824  *
2825  *    Request only the following attributes
2826  *    buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2827  *                                            SILC_ATTRIBUTE_SERVICE,
2828  *                                            SILC_ATTRIBUTE_MOOD, 0);
2829  *
2830  ***/
2831 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2832
2833 /* Low level packet sending functions */
2834
2835 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2836  *
2837  * SYNOPSIS
2838  *
2839  *     bool silc_client_send_packet(SilcClient client,
2840  *                                  SilcClientConnection conn,
2841  *                                  SilcPacketType type,
2842  *                                  const unsigned char *data,
2843  *                                  SilcUInt32 data_len);
2844  *
2845  * DESCRIPTION
2846  *
2847  *    This routine can be used by application to send packets directly
2848  *    to a connection indicated by `conn'.  Usually application does not
2849  *    need this routine since the Client Library handles the packet
2850  *    sending.  The `type' indicates the packet type.  If `data' is
2851  *    NULL then empty packet is sent.  This returns FALSE if packet cannot
2852  *    be sent.
2853  *
2854  ***/
2855 bool silc_client_send_packet(SilcClient client,
2856                              SilcClientConnection conn,
2857                              SilcPacketType type,
2858                              const unsigned char *data,
2859                              SilcUInt32 data_len);
2860
2861 #include "command.h"
2862 #include "command_reply.h"
2863 #include "idlist.h"
2864 #include "protocol.h"
2865
2866 #ifdef __cplusplus
2867 }
2868 #endif
2869
2870 #endif /* SILCCLIENT_H */