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