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