Chnaged "disconnect" client operation to deliver the reason
[silc.git] / lib / silcclient / silcclient.h
1 /*
2
3   silcclient.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2000 - 2002 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 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct 
70                                            *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
72
73 /* General definitions */
74
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
76  *
77  * NAME
78  *
79  *    typedef enum { ... } SilcKeyAgreementStatus;
80  *
81  * DESCRIPTION
82  *
83  *    Key agreement status types indicating the status of the key
84  *    agreement protocol.  These types are returned to the application 
85  *    in the SilcKeyAgreementCallback callback function.
86  *
87  * SOURCE
88  */
89 typedef enum {
90   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
91   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
92   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
93   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
94   SILC_KEY_AGREEMENT_ABORTED,          /* The protocol aborted */
95   SILC_KEY_AGREEMENT_ALREADY_STARTED,  /* Already started */
96   SILC_KEY_AGREEMENT_SELF_DENIED,      /* Negotiationg with itself denied */
97 } SilcKeyAgreementStatus;
98 /***/
99
100 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
101  *
102  * SYNOPSIS
103  *
104  *    typedef void (*SilcKeyAgreementCallback)(SilcClient client,
105  *                                             SilcClientConnection conn,
106  *                                             SilcClientEntry client_entry,
107  *                                             SilcKeyAgreementStatus status,
108  *                                             SilcSKEKeyMaterial *key,
109  *                                             void *context);
110  *
111  * DESCRIPTION
112  *
113  *    Key agreement callback that is called after the key agreement protocol
114  *    has been performed. This is called also if error occurred during the
115  *    key agreement protocol. The `key' is the allocated key material and
116  *    the caller is responsible of freeing it. The `key' is NULL if error
117  *    has occurred. The application can freely use the `key' to whatever
118  *    purpose it needs. See lib/silcske/silcske.h for the definition of
119  *    the SilcSKEKeyMaterial structure.
120  *
121  ***/
122 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
123                                          SilcClientConnection conn,
124                                          SilcClientEntry client_entry,
125                                          SilcKeyAgreementStatus status,
126                                          SilcSKEKeyMaterial *key,
127                                          void *context);
128
129 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
130  *
131  * NAME
132  *
133  *    typedef struct { ... } SilcPrivateMessageKeys;
134  *
135  * DESCRIPTION
136  *
137  *    Structure to hold the list of private message keys. The array of this
138  *    structure is returned by the silc_client_list_private_message_keys
139  *    function.
140  *
141  * SOURCE
142  */
143 typedef struct {
144   SilcClientEntry client_entry;       /* The remote client entry */
145   char *cipher;                       /* The cipher name */
146   unsigned char *key;                 /* The original key, If the appliation
147                                          provided it. This is NULL if the
148                                          library generated the key or if
149                                          the SKE key material was used. */
150   SilcUInt32 key_len;                 /* The key length */
151 } *SilcPrivateMessageKeys;
152 /***/
153
154 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
155  *
156  * NAME
157  *
158  *    typedef struct { ... } SilcChannelPrivateKey;
159  *
160  * DESCRIPTION
161  *
162  *    Structure to hold one channel private key. The array of this structure
163  *    is returned by silc_client_list_channel_private_keys function.
164  *
165  * SOURCE
166  */
167 typedef struct SilcChannelPrivateKeyStruct {
168   char *name;                         /* Application given name */
169   SilcCipher cipher;                  /* The cipher and key */
170   SilcHmac hmac;                      /* The HMAC and hmac key */
171   unsigned char *key;                 /* The key data */
172   SilcUInt32 key_len;                 /* The key length */
173 } *SilcChannelPrivateKey;
174 /***/
175
176 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
177  *
178  * SYNOPSIS
179  *
180  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
181  *                                      SilcUInt32 passphrase_len,
182  *                                      void *context);
183  *
184  * DESCRIPTION
185  *
186  *    Ask passphrase callback. This is called by the application when the
187  *    library calls `ask_passphrase' client operation.  The callback delivers
188  *    the passphrase to the library.  The passphrases in SILC protocol
189  *    MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
190  *    encoded, and if it is not then library will attempt to encode it.
191  *
192  ***/
193 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
194                                   SilcUInt32 passphrase_len,
195                                   void *context);
196
197 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
198  *
199  * SYNOPSIS
200  *
201  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
202  *
203  * DESCRIPTION
204  *
205  *    Public key (or certificate) verification callback. This is called
206  *    by the application to indicate that the public key verification was
207  *    either success or failure.
208  *
209  ***/
210 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
211
212 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
213  *
214  * SYNOPSIS
215  *
216  *    typedef void (*SilcGetAuthMeth)(bool success, 
217  *                                    SilcProtocolAuthMeth auth_meth,
218  *                                    const unsigned char *auth_data,
219  *                                    SilcUInt32 auth_data_len, void *context);
220  * 
221  * DESCRIPTION
222  *
223  *    Authentication method resolving callback. This is called by the
224  *    application to return the resolved authentication method. The client
225  *    library has called the get_auth_method client operation and given
226  *    this function pointer as argument. The `success' will indicate whether
227  *    the authentication method could be resolved. The `auth_meth' is the
228  *    resolved authentication method. The `auth_data' and the `auth_data_len'
229  *    are the resolved authentication data. The `context' is the libary's
230  *    context sent to the get_auth_method client operation.
231  *
232  ***/
233 typedef void (*SilcGetAuthMeth)(bool success, 
234                                 SilcProtocolAuthMeth auth_meth,
235                                 const unsigned char *auth_data,
236                                 SilcUInt32 auth_data_len, void *context);
237
238 /****d* silcclient/SilcClientAPI/SilcClientMessageType
239  *
240  * NAME
241  *
242  *    typedef enum { ... } SilcClientMessageType;
243  *
244  * DESCRIPTION
245  *
246  *    Different message types for `say' client operation.  The application
247  *    may filter the message sent by the library according this type.
248  *
249  * SOURCE
250  */
251 typedef enum {
252   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
253   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
254   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
255   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
256 } SilcClientMessageType;
257 /***/
258
259 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
260  *
261  * NAME
262  *
263  *    typedef enum { ... } SilcClientConnectionStatus
264  *
265  * DESCRIPTION
266  *
267  *    This type is returned to the `connect' client operation to indicate
268  *    the status of the created connection.  It can indicated if it was
269  *    successful or whether an error occurred.
270  *
271  * SOURCE
272  */
273 typedef enum {
274   SILC_CLIENT_CONN_SUCCESS,            /* Successfully connected */
275   SILC_CLIENT_CONN_SUCCESS_RESUME,     /* Successfully connected and
276                                           resumed old detached session */
277   SILC_CLIENT_CONN_ERROR,              /* Error occurred during connecting */
278 } SilcClientConnectionStatus;
279 /***/
280
281 /****s* silcclient/SilcClientAPI/SilcClientOperations
282  *
283  * NAME
284  *
285  *    typedef struct { ... } SilcClientOperations;
286  *
287  * DESCRIPTION
288  *
289  *    SILC Client Operations. These must be implemented by the application.
290  *    The Client library may call any of these routines at any time.  The
291  *    routines are used to deliver certain information to the application
292  *    or from the application to the client library.
293  *
294  * SOURCE
295  */
296 typedef struct {
297   /* Message sent to the application by library. `conn' associates the
298      message to a specific connection.  `conn', however, may be NULL. 
299      The `type' indicates the type of the message sent by the library.
300      The applicationi can for example filter the message according the
301      type. */
302   void (*say)(SilcClient client, SilcClientConnection conn, 
303               SilcClientMessageType type, char *msg, ...);
304
305   /* Message for a channel. The `sender' is the sender of the message 
306      The `channel' is the channel. The `msg' is the message.  Note that
307      `msg' maybe NULL. */
308   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
309                           SilcClientEntry sender, SilcChannelEntry channel, 
310                           SilcMessageFlags flags,
311                           const unsigned char *message,
312                           SilcUInt32 message_len);
313
314   /* Private message to the client. The `sender' is the sender of the
315      message. */
316   void (*private_message)(SilcClient client, SilcClientConnection conn,
317                           SilcClientEntry sender, SilcMessageFlags flags,
318                           const unsigned char *message,
319                           SilcUInt32 message_len);
320
321   /* Notify message to the client. The notify arguments are sent in the
322      same order as servers sends them. The arguments are same as received
323      from the server except for ID's.  If ID is received application receives
324      the corresponding entry to the ID. For example, if Client ID is received
325      application receives SilcClientEntry.  Also, if the notify type is
326      for channel the channel entry is sent to application (even if server
327      does not send it because client library gets the channel entry from
328      the Channel ID in the packet's header). */
329   void (*notify)(SilcClient client, SilcClientConnection conn, 
330                  SilcNotifyType type, ...);
331
332   /* Command handler. This function is called always in the command function.
333      If error occurs it will be called as well. `conn' is the associated
334      client connection. `cmd_context' is the command context that was
335      originally sent to the command. `success' is FALSE if error occurred
336      during command. `command' is the command being processed. It must be
337      noted that this is not reply from server. This is merely called just
338      after application has called the command. Just to tell application
339      that the command really was processed. */
340   void (*command)(SilcClient client, SilcClientConnection conn, 
341                   SilcClientCommandContext cmd_context, bool success,
342                   SilcCommand command, SilcStatus status);
343
344   /* Command reply handler. This function is called always in the command reply
345      function. If error occurs it will be called as well. Normal scenario
346      is that it will be called after the received command data has been parsed
347      and processed. The function is used to pass the received command data to
348      the application. 
349      
350      `conn' is the associated client connection. `cmd_payload' is the command
351      payload data received from server and it can be ignored. It is provided
352      if the application would like to re-parse the received command data,
353      however, it must be noted that the data is parsed already by the library
354      thus the payload can be ignored. `success' is FALSE if error occurred.
355      In this case arguments are not sent to the application. The `status' is
356      the command reply status server returned. The `command' is the command
357      reply being processed. The function has variable argument list and each
358      command defines the number and type of arguments it passes to the
359      application (on error they are not sent).
360
361      The arguments are sent in the same order as servers sends them.  The 
362      arguments are same as received from the server except for ID's.  If 
363      ID is received application receives the corresponding entry to the 
364      ID. For example, if Client ID is receives application receives 
365      SilcClientEntry. */
366   void (*command_reply)(SilcClient client, SilcClientConnection conn,
367                         SilcCommandPayload cmd_payload, bool success,
368                         SilcCommand command, SilcStatus status, ...);
369
370   /* Called to indicate that connection was either successfully established
371      or connecting failed.  This is also the first time application receives
372      the SilcClientConnection object which it should save somewhere.
373      The `status' indicated whether the connection were successful.  If it
374      is error value the application must always call the function
375      silc_client_close_connection. */
376   void (*connect)(SilcClient client, SilcClientConnection conn,
377                   SilcClientConnectionStatus status);
378
379   /* Called to indicate that connection was disconnected to the server.
380      The `status' may tell the reason of the disconnection, and if the
381      `message' is non-NULL it may include the disconnection message
382      received from server. */
383   void (*disconnect)(SilcClient client, SilcClientConnection conn,
384                      SilcStatus status, const char *message);
385
386   /* Find authentication method and authentication data by hostname and
387      port. The hostname may be IP address as well. When the authentication
388      method has been resolved the `completion' callback with the found
389      authentication method and authentication data is called. The `conn'
390      may be NULL. */
391   void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
392                           char *hostname, SilcUInt16 port,
393                           SilcGetAuthMeth completion, void *context);
394
395   /* Verifies received public key. The `conn_type' indicates which entity
396      (server, client etc.) has sent the public key. If user decides to trust
397      the key may be saved as trusted public key for later use. The 
398      `completion' must be called after the public key has been verified. */
399   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
400                             SilcSocketType conn_type, unsigned char *pk, 
401                             SilcUInt32 pk_len, SilcSKEPKType pk_type,
402                             SilcVerifyPublicKey completion, void *context);
403
404   /* Ask (interact, that is) a passphrase from user. The passphrase is
405      returned to the library by calling the `completion' callback with
406      the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
407      if not then the library will attempt to encode. */
408   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
409                          SilcAskPassphrase completion, void *context);
410
411   /* Notifies application that failure packet was received.  This is called
412      if there is some protocol active in the client.  The `protocol' is the
413      protocol context.  The `failure' is opaque pointer to the failure
414      indication.  Note, that the `failure' is protocol dependant and
415      application must explicitly cast it to correct type.  Usually `failure'
416      is 32 bit failure type (see protocol specs for all protocol failure
417      types). */
418   void (*failure)(SilcClient client, SilcClientConnection conn, 
419                   SilcProtocol protocol, void *failure);
420
421   /* Asks whether the user would like to perform the key agreement protocol.
422      This is called after we have received an key agreement packet or an
423      reply to our key agreement packet. This returns TRUE if the user wants
424      the library to perform the key agreement protocol and FALSE if it is not
425      desired (application may start it later by calling the function
426      silc_client_perform_key_agreement). If TRUE is returned also the
427      `completion' and `context' arguments must be set by the application. */
428   int (*key_agreement)(SilcClient client, SilcClientConnection conn,
429                        SilcClientEntry client_entry, const char *hostname,
430                        SilcUInt16 port, SilcKeyAgreementCallback *completion,
431                        void **context);
432
433   /* Notifies application that file transfer protocol session is being
434      requested by the remote client indicated by the `client_entry' from
435      the `hostname' and `port'. The `session_id' is the file transfer
436      session and it can be used to either accept or reject the file
437      transfer request, by calling the silc_client_file_receive or
438      silc_client_file_close, respectively. */
439   void (*ftp)(SilcClient client, SilcClientConnection conn,
440               SilcClientEntry client_entry, SilcUInt32 session_id,
441               const char *hostname, SilcUInt16 port);
442
443   /* Delivers SILC session detachment data indicated by `detach_data' to the
444      application.  If application has issued SILC_COMMAND_DETACH command     
445      the client session in the SILC network is not quit.  The client remains 
446      in the network but is detached.  The detachment data may be used later
447      to resume the session in the SILC Network.  The appliation is   
448      responsible of saving the `detach_data', to for example in a file.
449
450      The detachment data can be given as argument to the functions
451      silc_client_connect_to_server, or silc_client_add_connection when
452      creating connection to remote server, inside SilcClientConnectionParams
453      structure.  If it is provided the client library will attempt to resume
454      the session in the network.  After the connection is created
455      successfully, the application is responsible of setting the user
456      interface for user into the same state it was before detaching (showing
457      same channels, channel modes, etc).  It can do this by fetching the
458      information (like joined channels) from the client library. */
459   void (*detach)(SilcClient client, SilcClientConnection conn,
460                  const unsigned char *detach_data,
461                  SilcUInt32 detach_data_len);
462 } SilcClientOperations;
463 /***/
464
465 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
466  *
467  * SYNOPSIS
468  *
469  *    typedef void (*SilcNicknameFormatParse)(const char *nickname,
470  *                                            char **ret_nickname);
471  *
472  * DESCRIPTION
473  *
474  *    A callback function provided by the application for the library in
475  *    SilcClientParams structure. This function parses the formatted
476  *    nickname string `nickname' and returns the true nickname to the
477  *    `ret_nickname' pointer. The library can call this function at
478  *    any time.
479  *
480  ***/
481 typedef void (*SilcNicknameFormatParse)(const char *nickname,
482                                         char **ret_nickname);
483
484 /****s* silcclient/SilcClientAPI/SilcClientParams
485  *
486  * NAME
487  *
488  *    typedef struct { ... } SilcClientParams;
489  *
490  * DESCRIPTION
491  *
492  *    Client parameters. This can be filled with proper values and
493  *    given as argument to the silc_client_alloc function. The structure
494  *    hold various parameters which affects the function of the client.
495  *
496  * SOURCE
497  */
498 typedef struct {
499   /* Number of maximum tasks the client library's scheduler can handle.
500      If set to zero, the default value will be used (200). For WIN32
501      systems this should be set to 64 as it is the hard limit dictated
502      by the WIN32. */
503   int task_max;
504
505   /* Rekey timeout in seconds. The client will perform rekey in this
506      time interval. If set to zero, the default value will be used. */
507   unsigned int rekey_secs;
508
509   /* Connection authentication method request timeout. If server does not
510      reply back the current authentication method when we've requested it
511      in this time interval we'll assume the reply will not come at all. 
512      If set to zero, the default value (2 seconds) will be used. */
513   unsigned int connauth_request_secs;
514
515   /* Nickname format string. This can be used to order the client library
516      to save the nicknames in the library in a certain format. Since 
517      nicknames are not unique in SILC it is possible to have multiple same
518      nicknames. Using this format string it is possible to order the library
519      to separate the multiple same nicknames from each other. The format
520      types are defined below and they can appear in any order in the format
521      string. If this is NULL then default format is used which is the
522      default nickname without anything else. The string MUST be NULL
523      terminated.
524      
525      Following format types are available:
526      
527      %n  nickname      - the real nickname returned by the server (mandatory)
528      %h  hostname      - the stripped hostname of the client
529      %H  full hostname - the full hostname of the client
530      %s  server name   - the server name the client is connected
531      %S  full server   - the full server name the client is connected
532      %a  number        - ascending number in case there are several
533                          same nicknames (fe. nick@host and nick@host2)
534
535      Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
536                              "%a!%n@%s"  (fe. nick@server, 2!nick@server)
537                              "%n@%H"     (fe. nick@host.domain.com)
538
539      By default this format is employed to the nicknames by the libary
540      only when there appears multiple same nicknames. If the library has
541      only one nickname cached the nickname is saved as is and without the
542      defined format. If you want always to save the nickname in the defined
543      format set the boolean field `nickname_force_format' to value TRUE.
544   */
545   char nickname_format[32];
546
547   /* If this is set to TRUE then the `nickname_format' is employed to all
548      saved nicknames even if there are no multiple same nicknames in the 
549      cache. By default this is FALSE, which means that the `nickname_format'
550      is employed only if the library will receive a nickname that is
551      already saved in the cache. It is recommended to leave this to FALSE
552      value. */
553   bool nickname_force_format;
554
555   /* A callback function provided by the application for the library to
556      parse the nickname from the formatted nickname string. Even though
557      the libary formats the nicknames the application knows generally the
558      format better so this function should be provided for the library
559      if the application sets the `nickname_format' field. The library
560      will call this to get the true nickname from the provided formatted
561      nickname string whenever it needs the true nickname. */
562   SilcNicknameFormatParse nickname_parse;
563
564 } SilcClientParams;
565 /***/
566
567
568 /* Initialization functions (client.c) */
569
570 /****f* silcclient/SilcClientAPI/silc_client_alloc
571  *
572  * SYNOPSIS
573  *
574  *    SilcClient silc_client_alloc(SilcClientOperations *ops, 
575  *                                 SilcClientParams *params,
576  *                                 void *application,
577  *                                 const char *silc_version);
578  *
579  * DESCRIPTION
580  *
581  *    Allocates new client object. This has to be done before client may
582  *    work. After calling this one must call silc_client_init to initialize
583  *    the client. The `application' is application specific user data pointer
584  *    and caller must free it. The `silc_version' is the application version
585  *    that will be used to compare against remote host's (usually a server)
586  *    version string.  The `application' context is accessible by the
587  *    application by client->application, client being SilcClient.
588  *
589  ***/
590 SilcClient silc_client_alloc(SilcClientOperations *ops, 
591                              SilcClientParams *params,
592                              void *application,
593                              const char *silc_version);
594
595 /****f* silcclient/SilcClientAPI/silc_client_free
596  *
597  * SYNOPSIS
598  *
599  *    void silc_client_free(SilcClient client);
600  *
601  * DESCRIPTION
602  *
603  *    Frees client object and its internals.  The execution of the client
604  *    should be stopped with silc_client_stop function before calling
605  *    this function.
606  *
607  ***/
608 void silc_client_free(SilcClient client);
609
610 /****f* silcclient/SilcClientAPI/silc_client_init
611  *
612  * SYNOPSIS
613  *
614  *    int silc_client_init(SilcClient client);
615  *
616  * DESCRIPTION
617  *
618  *    Initializes the client. This makes all the necessary steps to make
619  *    the client ready to be run. One must call silc_client_run to run the
620  *    client. Returns FALSE if error occurred, TRUE otherwise.
621  *
622  ***/
623 int silc_client_init(SilcClient client);
624
625 /****f* silcclient/SilcClientAPI/silc_client_run
626  *
627  * SYNOPSIS
628  *
629  *    void silc_client_run(SilcClient client);
630  *
631  * DESCRIPTION
632  *
633  *    Runs the client. This starts the scheduler from the utility library.
634  *    When this functions returns the execution of the appliation is over.
635  *
636  ***/
637 void silc_client_run(SilcClient client);
638
639 /****f* silcclient/SilcClientAPI/silc_client_run_one
640  *
641  * SYNOPSIS
642  *
643  *    void silc_client_run_one(SilcClient client);
644  *
645  * DESCRIPTION
646  *
647  *    Runs the client and returns immeadiately. This function is used when
648  *    the SILC Client object indicated by the `client' is run under some
649  *    other scheduler, or event loop or main loop.  On GUI applications,
650  *    for example this may be desired to used to run the client under the
651  *    GUI application's main loop.  Typically the GUI application would
652  *    register an idle task that calls this function multiple times in
653  *    a second to quickly process the SILC specific data.
654  *
655  ***/
656 void silc_client_run_one(SilcClient client);
657
658 /****f* silcclient/SilcClientAPI/silc_client_stop
659  *
660  * SYNOPSIS
661  *
662  *    void silc_client_stop(SilcClient client);
663  *
664  * DESCRIPTION
665  *
666  *    Stops the client. This is called to stop the client and thus to stop
667  *    the program.  The client context must be freed with the silc_client_free
668  *    function.
669  *
670  ***/
671 void silc_client_stop(SilcClient client);
672
673
674 /* Connecting functions (client.c) */
675
676 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
677  *
678  * NAME
679  *
680  *    typedef struct { ... } SilcClientConnectionParams;
681  *
682  * DESCRIPTION
683  *
684  *    Client connection parameters.  This can be filled by the application
685  *    and given as argument to silc_client_connect_to_server or to
686  *    silc_client_add_connection.
687  *
688  * SOURCE
689  */
690 typedef struct {
691   /* The SILC session detachment data that was returned by `detach' client
692      operation when the application detached from the network.  Application
693      is responsible of saving the data and giving it as argument here
694      for resuming the session in the SILC network.
695
696      If this is provided here the client library will attempt to resume
697      the session in the network.  After the connection is created
698      successfully, the application is responsible of setting the user
699      interface for user into the same state it was before detaching (showing
700      same channels, channel modes, etc).  It can do this by fetching the
701      information (like joined channels) from the client library. */
702   unsigned char *detach_data;
703   SilcUInt32 detach_data_len;
704
705 } SilcClientConnectionParams;
706 /***/
707
708 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
709  *
710  * SYNOPSIS
711  *
712  *    int silc_client_connect_to_server(SilcClient client, 
713  *                                      SilcClientConnectionParams *params,
714  *                                      int port, char *host, void *context);
715  *
716  * DESCRIPTION
717  *
718  *    Connects to remote server. This is the main routine used to connect
719  *    to SILC server. Returns -1 on error and the created socket otherwise. 
720  *    The `context' is user context that is saved into the SilcClientConnection
721  *    that is created after the connection is created. Note that application
722  *    may handle the connecting process outside the library. If this is the
723  *    case then this function is not used at all. When the connecting is
724  *    done the `connect' client operation is called, and the `context' is
725  *    accessible with conn->context, conn being SilcClientConnection.
726  *    If the `params' is provided they are used by the routine.
727  *
728  ***/
729 int silc_client_connect_to_server(SilcClient client, 
730                                   SilcClientConnectionParams *params,
731                                   int port, char *host, void *context);
732
733 /****f* silcclient/SilcClientAPI/silc_client_add_connection
734  *
735  * SYNOPSIS
736  *
737  *
738  *    SilcClientConnection
739  *    silc_client_add_connection(SilcClient client,
740  *                               SilcClientConnectionParams *params,
741  *                               char *hostname, int port, void *context);
742  *
743  * DESCRIPTION
744  *
745  *    Allocates and adds new connection to the client. This adds the allocated
746  *    connection to the connection table and returns a pointer to it. A client
747  *    can have multiple connections to multiple servers. Every connection must
748  *    be added to the client using this function. User data `context' may
749  *    be sent as argument.  If the `params' is provided they are used by 
750  *    the routine.
751  *
752  * NOTES
753  *
754  *    This function is normally used only if the application performed 
755  *    the connecting outside the library, and did not called the
756  *    silc_client_connect_to_server function at all. The library
757  *    however may use this internally.
758  *
759  ***/
760 SilcClientConnection
761 silc_client_add_connection(SilcClient client,
762                            SilcClientConnectionParams *params,
763                            char *hostname, int port, void *context);
764
765 /****f* silcclient/SilcClientAPI/silc_client_del_connection
766  *
767  * SYNOPSIS
768  *
769  *    void silc_client_del_connection(SilcClient client, 
770  *                                    SilcClientConnection conn);
771  *
772  * DESCRIPTION
773  *
774  *    Removes connection from client. Frees all memory. The library
775  *    call this function automatically for all connection contexts.
776  *    The application however may free the connection contexts it has
777  *    allocated.
778  *
779  ***/
780 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
781
782 /****f* silcclient/SilcClientAPI/silc_client_add_socket
783  *
784  * SYNOPSIS
785  *
786  *    void silc_client_add_socket(SilcClient client, 
787  *                                SilcSocketConnection sock);
788  *
789  * DESCRIPTION
790  *
791  *    Adds listener socket to the listener sockets table. This function is
792  *    used to add socket objects that are listeners to the client.  This should
793  *    not be used to add other connection objects.
794  *
795  ***/
796 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
797
798 /****f* silcclient/SilcClientAPI/silc_client_del_socket
799  *
800  * SYNOPSIS
801  *
802  *    void silc_client_del_socket(SilcClient client, 
803  *                                SilcSocketConnection sock);
804  *
805  * DESCRIPTION
806  *
807  *    Deletes listener socket from the listener sockets table.  If the
808  *    application has added a socket with silc_client_add_socket it must
809  *    also free it using this function.
810  *
811  ***/
812 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
813
814 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
815  *
816  * SYNOPSIS
817  *
818  *    void silc_client_start_key_exchange(SilcClient client,
819  *                                        SilcClientConnection conn,
820  *                                        int fd);
821  *
822  * DESCRIPTION
823  *
824  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
825  *    key material between client and server.  This function can be called
826  *    directly if application is performing its own connecting and does not
827  *    use the connecting provided by this library. This function is normally
828  *    used only if the application performed the connecting outside the
829  *    library. The library however may use this internally.  After the
830  *    key exchange is performed the `connect' client operation is called.
831  *
832  ***/
833 void silc_client_start_key_exchange(SilcClient client,
834                                     SilcClientConnection conn,
835                                     int fd);
836
837 /****f* silcclient/SilcClientAPI/silc_client_close_connection
838  *
839  * SYNOPSIS
840  *
841  *    void silc_client_close_connection(SilcClient client,
842  *                                      SilcClientConnection conn);
843  *
844  * DESCRIPTION
845  *
846  *    Closes connection to remote end. Free's all allocated data except
847  *    for some information such as nickname etc. that are valid at all time. 
848  *
849  ***/
850 void silc_client_close_connection(SilcClient client,
851                                   SilcClientConnection conn);
852
853
854 /* Message sending functions (client_channel.c and client_prvmsg.c) */
855
856 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
857  *
858  * SYNOPSIS
859  *
860  *    void silc_client_send_channel_message(SilcClient client, 
861  *                                          SilcClientConnection conn,
862  *                                          SilcChannelEntry channel,
863  *                                          SilcChannelPrivateKey key,
864  *                                          SilcMessageFlags flags,
865  *                                          unsigned char *data, 
866  *                                          SilcUInt32 data_len, 
867  *                                          int force_send);
868  *
869  * DESCRIPTION
870  *
871  *    Sends packet to the `channel'. Packet to channel is always encrypted
872  *    differently from "normal" packets. SILC header of the packet is 
873  *    encrypted with the next receiver's key and the rest of the packet is
874  *    encrypted with the channel specific key. Padding and HMAC is computed
875  *    with the next receiver's key. The `data' is the channel message. If
876  *    the `force_send' is TRUE then the packet is sent immediately. 
877  *
878  *    If `key' is provided then that private key is used to encrypt the
879  *    channel message.  If it is not provided, private keys has not been
880  *    set at all, the normal channel key is used automatically.  If private
881  *    keys are set then the first key (the key that was added first as
882  *    private key) is used. 
883  *
884  ***/
885 void silc_client_send_channel_message(SilcClient client, 
886                                       SilcClientConnection conn,
887                                       SilcChannelEntry channel,
888                                       SilcChannelPrivateKey key,
889                                       SilcMessageFlags flags,
890                                       unsigned char *data, 
891                                       SilcUInt32 data_len, 
892                                       int force_send);
893
894 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
895  *
896  * SYNOPSIS
897  *
898  *    void silc_client_send_private_message(SilcClient client,
899  *                                          SilcClientConnection conn,
900  *                                          SilcClientEntry client_entry,
901  *                                          SilcMessageFlags flags,
902  *                                          unsigned char *data, 
903  *                                          SilcUInt32 data_len, 
904  *                                          int force_send);
905  *
906  * DESCRIPTION
907  *
908  *    Sends private message to remote client. If private message key has
909  *    not been set with this client then the message will be encrypted using
910  *    normal session keys. Private messages are special packets in SILC
911  *    network hence we need this own function for them. This is similar
912  *    to silc_client_packet_send_to_channel except that we send private
913  *    message. The `data' is the private message. If the `force_send' is
914  *    TRUE the packet is sent immediately. 
915  *
916  ***/
917 void silc_client_send_private_message(SilcClient client,
918                                       SilcClientConnection conn,
919                                       SilcClientEntry client_entry,
920                                       SilcMessageFlags flags,
921                                       unsigned char *data, 
922                                       SilcUInt32 data_len, 
923                                       int force_send);
924
925
926 /* Client and Channel entry retrieval (idlist.c) */
927
928 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
929  *
930  * SYNOPSIS
931  *
932  *    typedef void (*SilcGetClientCallback)(SilcClient client,
933  *                                          SilcClientConnection conn,
934  *                                          SilcClientEntry *clients,
935  *                                          SilcUInt32 clients_count,
936  *                                          void *context);
937  *
938  * DESCRIPTION
939  *
940  *    Callback function given to the silc_client_get_client function. The
941  *    found entries are allocated into the `clients' array. The array must
942  *    not be freed by the receiver, the library will free it later. If the
943  *    `clients' is NULL, no such clients exist in the SILC Network.
944  *
945  ***/
946 typedef void (*SilcGetClientCallback)(SilcClient client,
947                                       SilcClientConnection conn,
948                                       SilcClientEntry *clients,
949                                       SilcUInt32 clients_count,
950                                       void *context);
951
952 /****f* silcclient/SilcClientAPI/silc_client_get_clients
953  *
954  * SYNOPSIS
955  *
956  *    void silc_client_get_clients(SilcClient client,
957  *                                 SilcClientConnection conn,
958  *                                 const char *nickname,
959  *                                 const char *server,
960  *                                 SilcGetClientCallback completion,
961  *                                 void *context);
962  *
963  * DESCRIPTION
964  *
965  *    Finds client entry or entries by the `nickname' and `server'. The 
966  *    completion callback will be called when the client entries has been
967  *    found.  After the server returns the client information it is cached
968  *    and can be accesses locally at a later time.
969  *
970  * NOTES
971  *
972  *    NOTE: This function is always asynchronous and resolves the client
973  *    information from the server. Thus, if you already know the client
974  *    information then use the silc_client_get_client_by_id function to
975  *    get the client entry since this function may be very slow and should
976  *    be used only to initially get the client entries. 
977  *
978  ***/
979 void silc_client_get_clients(SilcClient client,
980                              SilcClientConnection conn,
981                              const char *nickname,
982                              const char *server,
983                              SilcGetClientCallback completion,
984                              void *context);
985
986 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
987  *
988  * SYNOPSIS
989  *
990  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
991  *                                                   SilcClientConnection conn,
992  *                                                   const char *nickname,
993  *                                                   const char *format,
994  *                                                   SilcUInt32 *clients_count);
995  *
996  * DESCRIPTION
997  *
998  *    Same as silc_client_get_clients function but does not resolve anything
999  *    from the server. This checks local cache and returns all matching
1000  *    clients from the local cache. If none was found this returns NULL.
1001  *    The `nickname' is the real nickname of the client, and the `format'
1002  *    is the formatted nickname to find exact match from multiple found
1003  *    entries. The format must be same as given in the SilcClientParams
1004  *    structure to the client library. If the `format' is NULL all found
1005  *    clients by `nickname' are returned. The caller must return the
1006  *    returned array.
1007  *
1008  ***/
1009 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1010                                                SilcClientConnection conn,
1011                                                const char *nickname,
1012                                                const char *format,
1013                                                SilcUInt32 *clients_count);
1014
1015 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1016  *
1017  * SYNOPSIS
1018  *
1019  *    void silc_client_get_clients_by_list(SilcClient client,
1020  *                                         SilcClientConnection conn,
1021  *                                         SilcUInt32 list_count,
1022  *                                         SilcBuffer client_id_list,
1023  *                                         SilcGetClientCallback completion,
1024  *                                         void *context);
1025  *
1026  * DESCRIPTION
1027  *
1028  *    Gets client entries by the list of client ID's `client_id_list'. This
1029  *    always resolves those client ID's it does not know yet from the server
1030  *    so this function might take a while. The `client_id_list' is a list
1031  *    of ID Payloads added one after other.  JOIN command reply and USERS
1032  *    command reply for example returns this sort of list. The `completion'
1033  *    will be called after the entries are available. When server returns
1034  *    the client information it will be cached and can be accessed locally
1035  *    at a later time.
1036  *
1037  ***/
1038 void silc_client_get_clients_by_list(SilcClient client,
1039                                      SilcClientConnection conn,
1040                                      SilcUInt32 list_count,
1041                                      SilcBuffer client_id_list,
1042                                      SilcGetClientCallback completion,
1043                                      void *context);
1044
1045 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1046  *
1047  * SYNOPSIS
1048  *
1049  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1050  *                                                 SilcClientConnection conn,
1051  *                                                 SilcClientID *client_id);
1052  *
1053  * DESCRIPTION
1054  *
1055  *    Find entry for client by the client's ID. Returns the entry or NULL
1056  *    if the entry was not found.  This checks the local cache and does
1057  *    not resolve anything from server.
1058  *
1059  ***/
1060 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1061                                              SilcClientConnection conn,
1062                                              SilcClientID *client_id);
1063
1064 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1065  *
1066  * SYNOPSIS
1067  *
1068  *    void 
1069  *    silc_client_get_client_by_id_resolve(SilcClient client,
1070  *                                         SilcClientConnection conn,
1071  *                                         SilcClientID *client_id,
1072  *                                         SilcGetClientCallback completion,
1073  *                                         void *context);
1074  *
1075  * DESCRIPTION
1076  *
1077  *    Same as silc_client_get_client_by_id but will always resolve the
1078  *    information from the server. Use this only if you know that you
1079  *    do not have the entry and the only thing you know about the client
1080  *    is its ID. When server returns the client information it will be
1081  *    cache and can be accessed locally at a later time.
1082  *
1083  ***/
1084 void silc_client_get_client_by_id_resolve(SilcClient client,
1085                                           SilcClientConnection conn,
1086                                           SilcClientID *client_id,
1087                                           SilcGetClientCallback completion,
1088                                           void *context);
1089
1090 /****f* silcclient/SilcClientAPI/silc_client_del_client
1091  *
1092  * SYNOPSIS
1093  *
1094  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1095  *                                SilcClientEntry client_entry)
1096  *
1097  * DESCRIPTION
1098  *
1099  *    Removes client from local cache by the client entry indicated by
1100  *    the `client_entry'.  Returns TRUE if the deletion were successful.
1101  *
1102  ***/
1103 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1104                             SilcClientEntry client_entry);
1105
1106 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1107  *
1108  * SYNOPSIS
1109  *
1110  *    typedef void (*SilcGetChannelCallback)(SilcClient client,
1111  *                                           SilcClientConnection conn,
1112  *                                           SilcChannelEntry *channels,
1113  *                                           SilcUInt32 channels_count,
1114  *                                           void *context);
1115  *
1116  * DESCRIPTION
1117  *
1118  *    Callback function given to the silc_client_get_channel_* functions.
1119  *    The found entries are allocated into the `channels' array. The array
1120  *    must not be freed by the receiver, the library will free it later.
1121  *    If the `channel' is NULL, no such channel exist in the SILC Network.
1122  *
1123  ***/
1124 typedef void (*SilcGetChannelCallback)(SilcClient client,
1125                                        SilcClientConnection conn,
1126                                        SilcChannelEntry *channels,
1127                                        SilcUInt32 channels_count,
1128                                        void *context);
1129
1130 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1131  *
1132  * SYNOPSIS
1133  *
1134  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
1135  *                                             SilcClientConnection conn,
1136  *                                             char *channel);
1137  *
1138  * DESCRIPTION
1139  *
1140  *    Finds entry for channel by the channel name. Returns the entry or NULL
1141  *    if the entry was not found. It is found only if the client is joined
1142  *    to the channel. 
1143  *
1144  ***/
1145 SilcChannelEntry silc_client_get_channel(SilcClient client,
1146                                          SilcClientConnection conn,
1147                                          char *channel);
1148
1149 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1150  *
1151  * SYNOPSIS
1152  *
1153  *    void 
1154  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1155  *                                          SilcClientConnection conn,
1156  *                                          SilcChannelID *channel_id,
1157  *                                          SilcGetClientCallback completion,
1158  *                                          void *context);
1159  *
1160  * DESCRIPTION
1161  *
1162  *    Finds channel entry by the channel name. Returns the entry or NULL
1163  *    if it was not found.
1164  *
1165  ***/
1166 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1167                                                SilcClientConnection conn,
1168                                                SilcChannelID *channel_id);
1169
1170 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1171  *
1172  * SYNOPSIS
1173  *
1174  *    void 
1175  *    silc_client_get_channel_by_id_resolve(SilcClient client,
1176  *                                          SilcClientConnection conn,
1177  *                                          SilcChannelID *channel_id,
1178  *                                          SilcGetClientCallback completion,
1179  *                                          void *context);
1180  *
1181  * DESCRIPTION
1182  *
1183  *    Resolves the channel information (its name mainly) from the server
1184  *    by the `channel_id'. Use this only if you know that you do not have
1185  *    the entry cached locally.
1186  *
1187  ***/
1188 void silc_client_get_channel_by_id_resolve(SilcClient client,
1189                                            SilcClientConnection conn,
1190                                            SilcChannelID *channel_id,
1191                                            SilcGetChannelCallback completion,
1192                                            void *context);
1193
1194 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1195  *
1196  * SYNOPSIS
1197  *
1198  *    bool silc_client_del_channel(SilcClient client, 
1199  *                                 SilcClientConnection conn,
1200  *                                 SilcChannelEntry channel)
1201  *
1202  * DESCRIPTION
1203  *
1204  *    Removes channel from local cache by the channel entry indicated by
1205  *    the `channel'.  Returns TRUE if the deletion were successful.
1206  *
1207  ***/
1208 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1209                              SilcChannelEntry channel);
1210
1211 /****f* silcclient/SilcClientAPI/silc_client_get_server
1212  *
1213  * SYNOPSIS
1214  *
1215  *    SilcServerEntry silc_client_get_server(SilcClient client,
1216  *                                           SilcClientConnection conn,
1217  *                                           char *server_name)
1218  *
1219  * DESCRIPTION
1220  *
1221  *    Finds entry for server by the server name. Returns the entry or NULL
1222  *    if the entry was not found.
1223  *
1224  ***/
1225 SilcServerEntry silc_client_get_server(SilcClient client,
1226                                        SilcClientConnection conn,
1227                                        char *server_name);
1228
1229 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1230  *
1231  * SYNOPSIS
1232  *
1233  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1234  *                                                 SilcClientConnection conn,
1235  *                                                 SilcServerID *server_id);
1236  *
1237  * DESCRIPTION
1238  *
1239  *    Finds entry for server by the server ID. Returns the entry or NULL
1240  *    if the entry was not found.
1241  *
1242  ***/
1243 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1244                                              SilcClientConnection conn,
1245                                              SilcServerID *server_id);
1246
1247 /****f* silcclient/SilcClientAPI/silc_client_del_server
1248  *
1249  * SYNOPSIS
1250  *
1251  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1252  *                                SilcServerEntry server);
1253  *
1254  * DESCRIPTION
1255  *
1256  *    Removes server from local cache by the server entry indicated by
1257  *    the `server'.  Returns TRUE if the deletion were successful.
1258  *
1259  ***/
1260 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1261                             SilcServerEntry server);
1262
1263 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1264  *
1265  * SYNOPSIS
1266  *
1267  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1268  *                                           SilcClientEntry client_entry);
1269  *
1270  * DESCRIPTION
1271  *
1272  *    Returns the ChannelUser entry if the `client_entry' is joined on the 
1273  *    channel indicated by the `channel'. NULL if client is not joined on
1274  *    the channel. 
1275  *
1276  ***/
1277 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1278                                        SilcClientEntry client_entry);
1279
1280 /* Command management (command.c) */
1281
1282 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1283  *
1284  * SYNOPSIS
1285  *
1286  *    SilcClientCommandContext silc_client_command_alloc(void);
1287  *
1288  * DESCRIPTION
1289  *
1290  *    Allocate Command Context. The context is defined in `command.h' file.
1291  *    The context is used by the library commands and applications should use
1292  *    it as well. However, application may choose to use some own context
1293  *    for its local commands. All library commands, however, must use this
1294  *    context. 
1295  *
1296  ***/
1297 SilcClientCommandContext silc_client_command_alloc(void);
1298
1299 /****f* silcclient/SilcClientAPI/silc_client_command_free
1300  *
1301  * SYNOPSIS
1302  *
1303  *    void silc_client_command_free(SilcClientCommandContext ctx);
1304  *
1305  * DESCRIPTION
1306  *
1307  *    Free command context and its internals.  If the contex was duplicated
1308  *    with silc_client_command_dup this may not actually free the data, 
1309  *    instead it will decrease the reference counter of the context.  The
1310  *    context will be freed when the reference counter hits zero.
1311  *
1312  ***/
1313 void silc_client_command_free(SilcClientCommandContext ctx);
1314
1315 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1316  *
1317  * SYNOPSIS
1318  *
1319  *    SilcClientCommandContext 
1320  *    silc_client_command_dup(SilcClientCommandContext ctx);
1321  *
1322  * DESCRIPTION
1323  *
1324  *    Duplicate Command Context by adding reference counter. The context won't
1325  *    be free'd untill it hits zero. 
1326  *
1327  ***/
1328 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1329
1330 /****f* silcclient/SilcClientAPI/silc_client_command_find
1331  *
1332  * SYNOPSIS
1333  *
1334  *    SilcClientCommand silc_client_command_find(SilcClient client,
1335  *                                               const char *name);
1336  *
1337  * DESCRIPTION
1338  *
1339  *    Finds and returns a pointer to the command list. Return NULL if the
1340  *    command is not found. See the `command.[ch]' for the command list. 
1341  *    Command names are not case-sensitive.
1342  *
1343  ***/
1344 SilcClientCommand silc_client_command_find(SilcClient client,
1345                                            const char *name);
1346
1347 /****f* silcclient/SilcClientAPI/silc_client_command_call
1348  *
1349  * SYNOPSIS
1350  *
1351  *    void silc_client_command_call(SilcClientCommand command);
1352  *
1353  * DESCRIPTION
1354  *
1355  *    Calls the command (executes it).  Application can call this after
1356  *    it has allocated the SilcClientCommandContext with the function
1357  *    silc_client_command_alloc and found the command from the client
1358  *    library by calling silc_client_command_find.  This will execute
1359  *    the command.
1360  *
1361  *    Application can call the command function directly too if it
1362  *    wishes to do so.  See the command.h for details of the
1363  *    SilcClientCommand structure.
1364  *
1365  ***/
1366 void silc_client_command_call(SilcClientCommand command,
1367                               SilcClientCommandContext cmd);
1368
1369 /****f* silcclient/SilcClientAPI/silc_client_command_send
1370  *
1371  * SYNOPSIS
1372  *
1373  *    void silc_client_command_send(SilcClient client, 
1374  *                                  SilcClientConnection conn,
1375  *                                  SilcCommand command, SilcUInt16 ident,
1376  *                                  SilcUInt32 argc, ...);
1377  *
1378  * DESCRIPTION
1379  *
1380  *    Generic function to send any command. The arguments must be sent already
1381  *    encoded into correct form and in correct order. If application wants
1382  *    to perform the commands by itself, it can do so and send the data
1383  *    directly to the server using this function.  If application is using
1384  *    the silc_client_command_call, this function is usually not used.
1385  *
1386  ***/
1387 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1388                               SilcCommand command, SilcUInt16 ident,
1389                               SilcUInt32 argc, ...);
1390
1391 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1392  *
1393  * SYNOPSIS
1394  *
1395  *    void silc_client_command_pending(SilcClientConnection conn,
1396  *                                     SilcCommand reply_cmd,
1397  *                                     SilcUInt16 ident,
1398  *                                     SilcCommandCb callback,
1399  *                                     void *context);
1400  *
1401  * DESCRIPTION
1402  *
1403  *    Add new pending command to be executed when reply to a command has been
1404  *    received.  The `reply_cmd' is the command that will call the `callback'
1405  *    with `context' when reply has been received.  If `ident' is non-zero
1406  *    the `callback' will be executed when received reply with command 
1407  *    identifier `ident'. 
1408  *
1409  *    Note that the application is notified about the received command
1410  *    reply through the `command_reply' client operation before calling
1411  *    the `callback` pending command callback.
1412  *
1413  ***/
1414 void silc_client_command_pending(SilcClientConnection conn,
1415                                  SilcCommand reply_cmd,
1416                                  SilcUInt16 ident,
1417                                  SilcCommandCb callback,
1418                                  void *context);
1419
1420
1421 /* Private Message key management (client_prvmsg.c) */
1422
1423 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1424  *
1425  * SYNOPSIS
1426  *
1427  *    int silc_client_add_private_message_key(SilcClient client,
1428  *                                            SilcClientConnection conn,
1429  *                                            SilcClientEntry client_entry,
1430  *                                            char *cipher,
1431  *                                            unsigned char *key,
1432  *                                            SilcUInt32 key_len,
1433  *                                            bool generate_key,
1434  *                                            bool responder);
1435  *
1436  * DESCRIPTION
1437  *
1438  *    Adds private message key to the client library. The key will be used to
1439  *    encrypt all private message between the client and the remote client
1440  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1441  *    value `generate_key' is TRUE the library will generate random key.
1442  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1443  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1444  *    requirements of the SILC protocol are met. The API, however, allows
1445  *    to allocate any cipher.
1446  *
1447  *    If `responder' is TRUE then the sending and receiving keys will be
1448  *    set according the client being the receiver of the private key.  If
1449  *    FALSE the client is being the sender (or negotiator) of the private
1450  *    key.
1451  *
1452  *    It is not necessary to set key for normal private message usage. If the
1453  *    key is not set then the private messages are encrypted using normal
1454  *    session keys. Setting the private key, however, increases the security. 
1455  *
1456  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1457  *    otherwise. 
1458  *
1459  ***/
1460 int silc_client_add_private_message_key(SilcClient client,
1461                                         SilcClientConnection conn,
1462                                         SilcClientEntry client_entry,
1463                                         char *cipher,
1464                                         unsigned char *key,
1465                                         SilcUInt32 key_len,
1466                                         bool generate_key,
1467                                         bool responder);
1468
1469 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1470  *
1471  * SYNOPSIS
1472  *
1473  *    int silc_client_add_private_message_key_ske(SilcClient client,
1474  *                                                SilcClientConnection conn,
1475  *                                                SilcClientEntry client_entry,
1476  *                                                char *cipher,
1477  *                                                SilcSKEKeyMaterial *key);
1478  *
1479  * DESCRIPTION
1480  *
1481  *    Same as silc_client_add_private_message_key but takes the key material
1482  *    from the SKE key material structure. This structure is received if
1483  *    the application uses the silc_client_send_key_agreement to negotiate
1484  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1485  *    also in the SKE protocol. 
1486  *
1487  ***/
1488 int silc_client_add_private_message_key_ske(SilcClient client,
1489                                             SilcClientConnection conn,
1490                                             SilcClientEntry client_entry,
1491                                             char *cipher,
1492                                             SilcSKEKeyMaterial *key,
1493                                             bool responder);
1494
1495 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1496  *
1497  * SYNOPSIS
1498  *
1499  *    int silc_client_send_private_message_key(SilcClient client,
1500  *                                             SilcClientConnection conn,
1501  *                                             SilcClientEntry client_entry,
1502  *                                             int force_send);
1503  *
1504  * DESCRIPTION
1505  *
1506  *    Sends private message key payload to the remote client indicated by
1507  *    the `client_entry'. If the `force_send' is TRUE the packet is sent
1508  *    immediately. Returns FALSE if error occurs, TRUE otherwise. The
1509  *    application should call this function after setting the key to the
1510  *    client.
1511  *
1512  *    Note that the key sent using this function is sent to the remote client
1513  *    through the SILC network. The packet is protected using normal session
1514  *    keys. 
1515  *
1516  ***/
1517 int silc_client_send_private_message_key(SilcClient client,
1518                                          SilcClientConnection conn,
1519                                          SilcClientEntry client_entry,
1520                                          int force_send);
1521
1522 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1523  *
1524  * SYNOPSIS
1525  *
1526  *    int silc_client_del_private_message_key(SilcClient client,
1527  *                                            SilcClientConnection conn,
1528  *                                            SilcClientEntry client_entry);
1529  *
1530  * DESCRIPTION
1531  *
1532  *    Removes the private message from the library. The key won't be used
1533  *    after this to protect the private messages with the remote `client_entry'
1534  *    client. Returns FALSE on error, TRUE otherwise. 
1535  *
1536  ***/
1537 int silc_client_del_private_message_key(SilcClient client,
1538                                         SilcClientConnection conn,
1539                                         SilcClientEntry client_entry);
1540
1541 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1542  *
1543  * SYNOPSIS
1544  *
1545  *    SilcPrivateMessageKeys
1546  *    silc_client_list_private_message_keys(SilcClient client,
1547  *                                          SilcClientConnection conn,
1548  *                                          SilcUInt32 *key_count);
1549  * 
1550  * DESCRIPTION
1551  *
1552  *    Returns array of set private message keys associated to the connection
1553  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1554  *    count to the `key_count' argument. The array must be freed by the caller
1555  *    by calling the silc_client_free_private_message_keys function. Note: 
1556  *    the keys returned in the array is in raw format. It might not be desired
1557  *    to show the keys as is. The application might choose not to show the keys
1558  *    at all or to show the fingerprints of the keys. 
1559  *
1560  ***/
1561 SilcPrivateMessageKeys
1562 silc_client_list_private_message_keys(SilcClient client,
1563                                       SilcClientConnection conn,
1564                                       SilcUInt32 *key_count);
1565
1566 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1567  *
1568  * SYNOPSIS
1569  *
1570  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1571  *                                               SilcUInt32 key_count);
1572  * 
1573  * DESCRIPTION
1574  *
1575  *    Frees the SilcPrivateMessageKeys array returned by the function
1576  *    silc_client_list_private_message_keys. 
1577  *
1578  ***/
1579 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1580                                            SilcUInt32 key_count);
1581
1582
1583 /* Channel private key management (client_channel.c, 
1584    SilcChannelPrivateKey is defined in idlist.h) */
1585
1586 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1587  *
1588  * SYNOPSIS
1589  *
1590  *    int silc_client_add_channel_private_key(SilcClient client,
1591  *                                            SilcClientConnection conn,
1592  *                                            SilcChannelEntry channel,
1593  *                                            const char *name,
1594  *                                            char *cipher,
1595  *                                            char *hmac,
1596  *                                            unsigned char *key,
1597  *                                            SilcUInt32 key_len);
1598  * 
1599  * DESCRIPTION
1600  *
1601  *    Adds private key for channel. This may be set only if the channel's mode
1602  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1603  *    mode is not set. When channel has private key then the messages are
1604  *    encrypted using that key. All clients on the channel must also know the
1605  *    key in order to decrypt the messages. However, it is possible to have
1606  *    several private keys per one channel. In this case only some of the
1607  *    clients on the channel may know the one key and only some the other key.
1608  *    The `name' can be application given name for the key.
1609  *
1610  *    The private key for channel is optional. If it is not set then the
1611  *    channel messages are encrypted using the channel key generated by the
1612  *    server. However, setting the private key (or keys) for the channel 
1613  *    significantly adds security. If more than one key is set the library
1614  *    will automatically try all keys at the message decryption phase. Note:
1615  *    setting many keys slows down the decryption phase as all keys has to
1616  *    be tried in order to find the correct decryption key. However, setting
1617  *    a few keys does not have big impact to the decryption performace. 
1618  *
1619  * NOTES
1620  *
1621  *    NOTE: This is entirely local setting. The key set using this function
1622  *    is not sent to the network at any phase.
1623  *
1624  *    NOTE: If the key material was originated by the SKE protocol (using
1625  *    silc_client_send_key_agreement) then the `key' MUST be the
1626  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1627  *    currently it is not expected that the SKE key material would be used
1628  *    as channel private key. However, this API allows it. 
1629  *
1630  ***/
1631 int silc_client_add_channel_private_key(SilcClient client,
1632                                         SilcClientConnection conn,
1633                                         SilcChannelEntry channel,
1634                                         const char *name,
1635                                         char *cipher,
1636                                         char *hmac,
1637                                         unsigned char *key,
1638                                         SilcUInt32 key_len);
1639
1640 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1641  *
1642  * SYNOPSIS
1643  *
1644  *    int silc_client_del_channel_private_keys(SilcClient client,
1645  *                                             SilcClientConnection conn,
1646  *                                             SilcChannelEntry channel);
1647  * 
1648  * DESCRIPTION
1649  *
1650  *    Removes all private keys from the `channel'. The old channel key is used
1651  *    after calling this to protect the channel messages. Returns FALSE on
1652  *    on error, TRUE otherwise. 
1653  *
1654  ***/
1655 int silc_client_del_channel_private_keys(SilcClient client,
1656                                          SilcClientConnection conn,
1657                                          SilcChannelEntry channel);
1658
1659 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1660  *
1661  * SYNOPSIS
1662  *
1663  *    int silc_client_del_channel_private_key(SilcClient client,
1664  *                                            SilcClientConnection conn,
1665  *                                            SilcChannelEntry channel,
1666  *                                            SilcChannelPrivateKey key);
1667  * 
1668  * DESCRIPTION
1669  *
1670  *    Removes and frees private key `key' from the channel `channel'. 
1671  *    The `key' is retrieved by calling the function 
1672  *    silc_client_list_channel_private_keys. The key is not used after
1673  *    this. If the key was last private key then the old channel key is
1674  *    used hereafter to protect the channel messages. This returns FALSE
1675  *    on error, TRUE otherwise. 
1676  *
1677  ***/
1678 int silc_client_del_channel_private_key(SilcClient client,
1679                                         SilcClientConnection conn,
1680                                         SilcChannelEntry channel,
1681                                         SilcChannelPrivateKey key);
1682
1683 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1684  *
1685  * SYNOPSIS
1686  *
1687  *    SilcChannelPrivateKey *
1688  *    silc_client_list_channel_private_keys(SilcClient client,
1689  *                                          SilcClientConnection conn,
1690  *                                          SilcChannelEntry channel,
1691  *                                          SilcUInt32 *key_count);
1692  *
1693  * DESCRIPTION
1694  *
1695  *    Returns array (pointers) of private keys associated to the `channel'.
1696  *    The caller must free the array by calling the function
1697  *    silc_client_free_channel_private_keys. The pointers in the array may be
1698  *    used to delete the specific key by giving the pointer as argument to the
1699  *    function silc_client_del_channel_private_key. 
1700  *
1701  ***/
1702 SilcChannelPrivateKey *
1703 silc_client_list_channel_private_keys(SilcClient client,
1704                                       SilcClientConnection conn,
1705                                       SilcChannelEntry channel,
1706                                       SilcUInt32 *key_count);
1707
1708 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1709  *
1710  * SYNOPSIS
1711  *
1712  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1713  *                                               SilcUInt32 key_count);
1714  *
1715  * DESCRIPTION
1716  *
1717  *    Frees the SilcChannelPrivateKey array.
1718  *
1719  ***/
1720 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1721                                            SilcUInt32 key_count);
1722
1723 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1724  *
1725  * SYNOPSIS
1726  *
1727  *    void silc_client_current_channel_private_key(SilcClient client,
1728  *                                                 SilcClientConnection conn,
1729  *                                                 SilcChannelEntry channel,
1730  *                                                 SilcChannelPrivateKey key);
1731  *
1732  * DESCRIPTION
1733  *
1734  *    Sets the `key' to be used as current channel private key on the
1735  *    `channel'.  Packet sent after calling this function will be secured
1736  *    with `key'.
1737  *
1738  ***/
1739 void silc_client_current_channel_private_key(SilcClient client,
1740                                              SilcClientConnection conn,
1741                                              SilcChannelEntry channel,
1742                                              SilcChannelPrivateKey key);
1743
1744
1745 /* Key Agreement routines (client_keyagr.c) */
1746
1747 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1748  *
1749  * SYNOPSIS
1750  *
1751  *    void silc_client_send_key_agreement(SilcClient client,
1752  *                                        SilcClientConnection conn,
1753  *                                        SilcClientEntry client_entry,
1754  *                                        char *hostname,
1755  *                                        int port,
1756  *                                        SilcUInt32 timeout_secs,
1757  *                                        SilcKeyAgreementCallback completion,
1758  *                                        void *context);
1759  *
1760  * DESCRIPTION
1761  *
1762  *    Sends key agreement request to the remote client indicated by the
1763  *    `client_entry'. If the caller provides the `hostname' and the `port'
1764  *    arguments then the library will bind the client to that hostname and
1765  *    that port for the key agreement protocol. It also sends the `hostname'
1766  *    and the `port' in the key agreement packet to the remote client. This
1767  *    would indicate that the remote client may initiate the key agreement
1768  *    protocol to the `hostname' on the `port'.  If port is zero then the
1769  *    bound port is undefined (the operating system defines it).
1770  *
1771  *    If the `hostname' and `port' is not provided then empty key agreement
1772  *    packet is sent to the remote client. The remote client may reply with
1773  *    the same packet including its hostname and port. If the library receives
1774  *    the reply from the remote client the `key_agreement' client operation
1775  *    callback will be called to verify whether the user wants to perform the
1776  *    key agreement or not. 
1777  *
1778  * NOTES
1779  *
1780  *    NOTE: If the application provided the `hostname' and the `port' and the 
1781  *    remote side initiates the key agreement protocol it is not verified
1782  *    from the user anymore whether the protocol should be executed or not.
1783  *    By setting the `hostname' and `port' the user gives permission to
1784  *    perform the protocol (we are responder in this case).
1785  *
1786  *    NOTE: If the remote side decides not to initiate the key agreement
1787  *    or decides not to reply with the key agreement packet then we cannot
1788  *    perform the key agreement at all. If the key agreement protocol is
1789  *    performed the `completion' callback with the `context' will be called.
1790  *    If remote side decides to ignore the request the `completion' will be
1791  *    called after the specified timeout, `timeout_secs'. 
1792  *
1793  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1794  *    will not be called at all since this does nothing more than sending
1795  *    a packet to the remote host.
1796  *
1797  *    NOTE: There can be only one active key agreement for one client entry.
1798  *    Before setting new one, the old one must be finished (it is finished
1799  *    after calling the completion callback) or the function 
1800  *    silc_client_abort_key_agreement must be called. 
1801  *
1802  ***/
1803 void silc_client_send_key_agreement(SilcClient client,
1804                                     SilcClientConnection conn,
1805                                     SilcClientEntry client_entry,
1806                                     const char *hostname,
1807                                     const char *bindhost,
1808                                     int port,
1809                                     SilcUInt32 timeout_secs,
1810                                     SilcKeyAgreementCallback completion,
1811                                     void *context);
1812
1813 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1814  *
1815  * SYNOPSIS
1816  *
1817  *    void 
1818  *    silc_client_perform_key_agreement(SilcClient client,
1819  *                                      SilcClientConnection conn,
1820  *                                      SilcClientEntry client_entry,
1821  *                                      char *hostname,
1822  *                                      int port,
1823  *                                      SilcKeyAgreementCallback completion,
1824  *                                      void *context);
1825  *
1826  * DESCRIPTION
1827  *
1828  *    Performs the actual key agreement protocol. Application may use this
1829  *    to initiate the key agreement protocol. This can be called for example
1830  *    after the application has received the `key_agreement' client operation,
1831  *    and did not return TRUE from it.
1832  *
1833  *    The `hostname' is the remote hostname (or IP address) and the `port'
1834  *    is the remote port. The `completion' callback with the `context' will
1835  *    be called after the key agreement protocol.
1836  *
1837  * NOTES
1838  * 
1839  *    NOTE: If the application returns TRUE in the `key_agreement' client
1840  *    operation the library will automatically start the key agreement. In this
1841  *    case the application must not call this function. However, application
1842  *    may choose to just ignore the `key_agreement' client operation (and
1843  *    merely just print information about it on the screen) and call this
1844  *    function when the user whishes to do so (by, for example, giving some
1845  *    specific command). Thus, the API provides both, automatic and manual
1846  *    initiation of the key agreement. Calling this function is the manual
1847  *    initiation and returning TRUE in the `key_agreement' client operation
1848  *    is the automatic initiation. 
1849  *
1850  ***/
1851 void silc_client_perform_key_agreement(SilcClient client,
1852                                        SilcClientConnection conn,
1853                                        SilcClientEntry client_entry,
1854                                        char *hostname,
1855                                        int port,
1856                                        SilcKeyAgreementCallback completion,
1857                                        void *context);
1858
1859 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1860  *
1861  * SYNOPSIS
1862  *
1863  *    void
1864  *    silc_client_perform_key_agreement_fd(SilcClient client,
1865  *                                         SilcClientConnection conn,
1866  *                                         SilcClientEntry client_entry,
1867  *                                         int sock,
1868  *                                         char *hostname,
1869  *                                         SilcKeyAgreementCallback completion,
1870  *                                         void *context);
1871  *
1872  * DESCRIPTION
1873  *
1874  *    Same as above but application has created already the connection to 
1875  *    the remote host. The `sock' is the socket to the remote connection. 
1876  *    Application can use this function if it does not want the client library
1877  *    to create the connection. 
1878  *
1879  ***/
1880 void silc_client_perform_key_agreement_fd(SilcClient client,
1881                                           SilcClientConnection conn,
1882                                           SilcClientEntry client_entry,
1883                                           int sock,
1884                                           char *hostname,
1885                                           SilcKeyAgreementCallback completion,
1886                                           void *context);
1887
1888 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1889  *
1890  * SYNOPSIS
1891  *
1892  *    void silc_client_abort_key_agreement(SilcClient client,
1893  *                                         SilcClientConnection conn,
1894  *                                         SilcClientEntry client_entry);
1895  *
1896  * DESCRIPTION
1897  *
1898  *    This function can be called to unbind the hostname and the port for
1899  *    the key agreement protocol. However, this function has effect only 
1900  *    before the key agreement protocol has been performed. After it has
1901  *    been performed the library will automatically unbind the port. The 
1902  *    `client_entry' is the client to which we sent the key agreement 
1903  *    request.  The key agreement completion callback will be called
1904  *    with SILC_KEY_AGREEMENT_ABORTED status.
1905  *
1906  ***/
1907 void silc_client_abort_key_agreement(SilcClient client,
1908                                      SilcClientConnection conn,
1909                                      SilcClientEntry client_entry);
1910
1911
1912 /* Misc functions */
1913
1914 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1915  *
1916  * SYNOPSIS
1917  *
1918  *    void silc_client_set_away_message(SilcClient client,
1919  *                                      SilcClientConnection conn,
1920  *                                      char *message);
1921  *
1922  * DESCRIPTION
1923  *
1924  *    Sets away `message'.  The away message may be set when the client's
1925  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1926  *    to anyone who sends private message.  The `message' will be sent
1927  *    automatically back to the the client who send private message.  If
1928  *    away message is already set this replaces the old message with the
1929  *    new one.  If `message' is NULL the old away message is removed. 
1930  *    The sender may freely free the memory of the `message'. 
1931  *
1932  ***/
1933 void silc_client_set_away_message(SilcClient client,
1934                                   SilcClientConnection conn,
1935                                   char *message);
1936
1937
1938 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1939  *
1940  * SYNOPSIS
1941  *
1942  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1943  *                                              SilcClientConnection conn,
1944  *                                              SilcAuthMethod auth_meth,
1945  *                                              void *context);
1946  *
1947  * DESCRIPTION
1948  *
1949  *    Connection authentication method request callback. This is called
1950  *    by the client library after it has received the authentication method
1951  *    that the application requested by calling the function
1952  *    silc_client_request_authentication_method.
1953  *
1954  ***/
1955 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1956                                           SilcClientConnection conn,
1957                                           SilcAuthMethod auth_meth,
1958                                           void *context);
1959
1960 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1961  *
1962  * SYNOPSIS
1963  *
1964  *    void 
1965  *    silc_client_request_authentication_method(SilcClient client,
1966  *                                              SilcClientConnection conn,
1967  *                                              SilcConnectionAuthRequest 
1968  *                                                callback,
1969  *                                              void *context);
1970  *
1971  * DESCRIPTION
1972  *
1973  *    This function can be used to request the current authentication method
1974  *    from the server. This may be called when connecting to the server
1975  *    and the client library requests the authentication data from the
1976  *    application. If the application does not know the current authentication
1977  *    method it can request it from the server using this function.
1978  *    The `callback' with `context' will be called after the server has
1979  *    replied back with the current authentication method.
1980  *
1981  ***/
1982 void 
1983 silc_client_request_authentication_method(SilcClient client,
1984                                           SilcClientConnection conn,
1985                                           SilcConnectionAuthRequest callback,
1986                                           void *context);
1987
1988 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1989  *
1990  * NAME
1991  *
1992  *    typedef enum { ... } SilcClientMonitorStatus;
1993  *
1994  * DESCRIPTION
1995  *
1996  *    File transmission session status types.  These will indicate
1997  *    the status of the file transmission session.
1998  *
1999  * SOURCE
2000  */
2001 typedef enum {
2002   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
2003   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
2004   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
2005   SILC_CLIENT_FILE_MONITOR_GET,
2006   SILC_CLIENT_FILE_MONITOR_PUT,
2007   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
2008   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
2009 } SilcClientMonitorStatus;
2010 /***/
2011
2012 /****d* silcclient/SilcClientAPI/SilcClientFileError
2013  *
2014  * NAME
2015  *
2016  *    typedef enum { ... } SilcClientFileError;
2017  *
2018  * DESCRIPTION
2019  *
2020  *    File transmission error types.  These types are returned by
2021  *    some of the file transmission functions, and by the monitor
2022  *    callback to indicate error.
2023  *
2024  * SOURCE
2025  */
2026 typedef enum {
2027   SILC_CLIENT_FILE_OK,
2028   SILC_CLIENT_FILE_ERROR,
2029   SILC_CLIENT_FILE_UNKNOWN_SESSION,
2030   SILC_CLIENT_FILE_ALREADY_STARTED,
2031   SILC_CLIENT_FILE_NO_SUCH_FILE,
2032   SILC_CLIENT_FILE_PERMISSION_DENIED,
2033   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2034 } SilcClientFileError;
2035 /***/
2036
2037 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2038  *
2039  * SYNOPSIS
2040  *
2041  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
2042  *                                          SilcClientConnection conn,
2043  *                                          SilcClientMonitorStatus status,
2044  *                                          SilcClientFileError error,
2045  *                                          SilcUInt64 offset,
2046  *                                          SilcUInt64 filesize,
2047  *                                          SilcClientEntry client_entry,
2048  *                                          SilcUInt32 session_id,
2049  *                                          const char *filepath,
2050  *                                          void *context);
2051  *
2052  * DESCRIPTION
2053  *
2054  *    Monitor callback that is called during the file transmission to
2055  *    monitor the transmission process.  The `status' indicates the current
2056  *    monitoring process.  The `error' will indicate the error type
2057  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
2058  *    currently transmitted amount of total `filesize'.  The `client_entry'
2059  *    indicates the remote client, and the transmission session ID is the 
2060  *    `session_id'.  The filename being transmitted is indicated by the 
2061  *    `filepath'.
2062  *
2063  ***/
2064 typedef void (*SilcClientFileMonitor)(SilcClient client,
2065                                       SilcClientConnection conn,
2066                                       SilcClientMonitorStatus status,
2067                                       SilcClientFileError error,
2068                                       SilcUInt64 offset,
2069                                       SilcUInt64 filesize,
2070                                       SilcClientEntry client_entry,
2071                                       SilcUInt32 session_id,
2072                                       const char *filepath,
2073                                       void *context);
2074
2075 /****f* silcclient/SilcClientAPI/silc_client_file_send
2076  *
2077  * SYNOPSIS
2078  *
2079  *    SilcClientFileError 
2080  *    silc_client_file_send(SilcClient client,
2081  *                          SilcClientConnection conn,
2082  *                          SilcClientFileMonitor monitor,
2083  *                          void *monitor_context,
2084  *                          const char *local_ip,
2085  *                          SilcUInt32 local_port,
2086  *                          SilcClientEntry client_entry,
2087  *                          const char *filepath);
2088  *                          SilcUInt32 *session_id);
2089  *
2090  * DESCRIPTION
2091  *
2092  *    Sends a file indicated by the `filepath' to the remote client 
2093  *    indicated by the `client_entry'.  This will negotiate a secret key
2094  *    with the remote client before actually starting the transmission of
2095  *    the file.  The `monitor' callback will be called to monitor the
2096  *    transmission of the file.
2097  *
2098  *    This returns a file session ID for the file transmission to the
2099  *    `session_id' pointer..  It can be used to close the session (and
2100  *    abort the file transmission) by calling the silc_client_file_close
2101  *    function.  The session ID is also returned in the `monitor' callback. 
2102  *
2103  *    If the `local_ip' is provided then this will try to bind the 
2104  *    listener for key exchange protocol to that IP.  If `local_port' is
2105  *    non-zero that port is used.  If `local_ip' is NULL then this will
2106  *    automatically attempt to bind it to local IP address of the machine.
2107  *    If that fails then this does not bind to any address and port, and
2108  *    assume that the remote client will provide the listener for the
2109  *    key exchange protocol.
2110  *
2111  *    If error will occur during the file transfer process the error
2112  *    status will be returned in the monitor callback.  In this case
2113  *    the application must call silc_client_file_close to close the
2114  *    session.
2115  *
2116  ***/
2117 SilcClientFileError 
2118 silc_client_file_send(SilcClient client,
2119                       SilcClientConnection conn,
2120                       SilcClientFileMonitor monitor,
2121                       void *monitor_context,
2122                       const char *local_ip,
2123                       SilcUInt32 local_port,
2124                       SilcClientEntry client_entry,
2125                       const char *filepath,
2126                       SilcUInt32 *session_id);
2127
2128 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2129  *
2130  * SYNOPSIS
2131  *
2132  *    SilcClientFileError 
2133  *    silc_client_file_receive(SilcClient client,
2134  *                             SilcClientConnection conn,
2135  *                             SilcClientFileMonitor monitor,
2136  *                             void *monitor_context,
2137  *                             const char *path,
2138  *                             SilcUInt32 session_id);
2139  *
2140  * DESCRIPTION
2141  *
2142  *    Receives a file from a client indicated by the `client_entry'.  The
2143  *    `session_id' indicates the file transmission session and it has been
2144  *    received in the `ftp' client operation function.  This will actually
2145  *    perform the key agreement protocol with the remote client before
2146  *    actually starting the file transmission.  The `monitor' callback
2147  *    will be called to monitor the transmission.  If `path' is non NULL
2148  *    the file will be saved into that directory.  If NULL the file is
2149  *    saved in the current working directory.
2150  *
2151  *    If error will occur during the file transfer process the error
2152  *    status will be returned in the monitor callback.  In this case
2153  *    the application must call silc_client_file_close to close the
2154  *    session.
2155  *
2156  ***/
2157 SilcClientFileError 
2158 silc_client_file_receive(SilcClient client,
2159                          SilcClientConnection conn,
2160                          SilcClientFileMonitor monitor,
2161                          void *monitor_context,
2162                          const char *path,
2163                          SilcUInt32 session_id);
2164
2165 /****f* silcclient/SilcClientAPI/silc_client_file_close
2166  *
2167  * SYNOPSIS
2168  *
2169  *    SilcClientFileError silc_client_file_close(SilcClient client,
2170  *                                               SilcClientConnection conn,
2171  *                                               SilcUInt32 session_id);
2172  *
2173  * DESCRIPTION
2174  *
2175  *    Closes file transmission session indicated by the `session_id'.
2176  *    If file transmission is being conducted it will be aborted
2177  *    automatically. This function is also used to close the session
2178  *    after successful file transmission. This function can be used
2179  *    also to reject incoming file transmission request.
2180  *
2181  ***/
2182 SilcClientFileError silc_client_file_close(SilcClient client,
2183                                            SilcClientConnection conn,
2184                                            SilcUInt32 session_id);
2185
2186 #include "client.h"
2187 #include "command.h"
2188 #include "command_reply.h"
2189 #include "idlist.h"
2190 #include "protocol.h"
2191
2192 #ifdef __cplusplus
2193 }
2194 #endif
2195
2196 #endif /* SILCCLIENT_H */