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