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