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