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