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