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