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