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