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