a94648bcf58d9095f45127be5b0ac80ff6b1adee
[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 } SilcClientOperations;
611 /***/
612
613 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
614  *
615  * SYNOPSIS
616  *
617  *    typedef void (*SilcNicknameFormatParse)(const char *nickname,
618  *                                            char **ret_nickname);
619  *
620  * DESCRIPTION
621  *
622  *    A callback function provided by the application for the library in
623  *    SilcClientParams structure. This function parses the formatted
624  *    nickname string `nickname' and returns the true nickname to the
625  *    `ret_nickname' pointer. The library can call this function at
626  *    any time.
627  *
628  ***/
629 typedef void (*SilcNicknameFormatParse)(const char *nickname,
630                                         char **ret_nickname);
631
632 /****s* silcclient/SilcClientAPI/SilcClientParams
633  *
634  * NAME
635  *
636  *    typedef struct { ... } SilcClientParams;
637  *
638  * DESCRIPTION
639  *
640  *    Client parameters. This can be filled with proper values and
641  *    given as argument to the silc_client_alloc function. The structure
642  *    hold various parameters which affects the function of the client.
643  *
644  * SOURCE
645  */
646 typedef struct {
647   /* If this boolean is set to TRUE then the client library will use
648      threads.  Any of the callback functions in the SilcClientOperations
649      and other callbacks may be called at any time in a thread.  The
650      application may need to employ appropriate concurrency control
651      in the callbacks to protect application specific data. */
652   SilcBool threads;
653
654   /* Connection authentication method request timeout. If server does not
655      reply back the current authentication method when we've requested it
656      in this time interval we'll assume the reply will not come at all.
657      If set to zero, the default value (2 seconds) will be used. */
658   unsigned int connauth_request_secs;
659
660   /* Nickname format string. This can be used to order the client library
661      to save the nicknames in the library in a certain format. Since
662      nicknames are not unique in SILC it is possible to have multiple same
663      nicknames. Using this format string it is possible to order the library
664      to separate the multiple same nicknames from each other. The format
665      types are defined below and they can appear in any order in the format
666      string. If this is NULL then default format is used which is the
667      default nickname without anything else. The string MUST be NULL
668      terminated.
669
670      Following format types are available:
671
672      %n  nickname      - the real nickname returned by the server (mandatory)
673      %h  hostname      - the stripped hostname of the client
674      %H  full hostname - the full hostname of the client
675      %s  server name   - the server name the client is connected
676      %S  full server   - the full server name the client is connected
677      %a  number        - ascending number in case there are several
678                          same nicknames (fe. nick@host and nick@host2)
679
680      Example format strings: "%n@%h%a"   (fe. nick@host, nick@host2)
681                              "%a!%n@%s"  (fe. nick@server, 2!nick@server)
682                              "%n@%H"     (fe. nick@host.domain.com)
683
684      By default this format is employed to the nicknames by the libary
685      only when there appears multiple same nicknames. If the library has
686      only one nickname cached the nickname is saved as is and without the
687      defined format. If you want always to save the nickname in the defined
688      format set the boolean field `nickname_force_format' to value TRUE.
689   */
690   char nickname_format[32];
691
692   /* If this is set to TRUE then the `nickname_format' is employed to all
693      saved nicknames even if there are no multiple same nicknames in the
694      cache. By default this is FALSE, which means that the `nickname_format'
695      is employed only if the library will receive a nickname that is
696      already saved in the cache. It is recommended to leave this to FALSE
697      value. */
698   SilcBool nickname_force_format;
699
700   /* A callback function provided by the application for the library to
701      parse the nickname from the formatted nickname string. Even though
702      the libary formats the nicknames the application knows generally the
703      format better so this function should be provided for the library
704      if the application sets the `nickname_format' field. The library
705      will call this to get the true nickname from the provided formatted
706      nickname string whenever it needs the true nickname. */
707   SilcNicknameFormatParse nickname_parse;
708
709   /* If this is set to TRUE then the client will ignore all incoming
710      Requested Attributes queries and does not reply anything back.  This
711      usually leads into situation where server does not anymore send
712      the queries after seeing that client does not reply anything back.
713      If your application does not support Requested Attributes or you do
714      not want to use them set this to TRUE.  See SilcAttribute and
715      silc_client_attribute_add for more information on attributes. */
716   SilcBool ignore_requested_attributes;
717
718   /* If this is set to TRUE, the silcclient library will not register and
719      deregister the cipher, pkcs, hash and hmac algorithms. The application
720      itself will need to handle that. */
721   SilcBool dont_register_crypto_library;
722
723 } SilcClientParams;
724 /***/
725
726
727 /* Initialization functions (client.c) */
728
729 /****f* silcclient/SilcClientAPI/silc_client_alloc
730  *
731  * SYNOPSIS
732  *
733  *    SilcClient silc_client_alloc(SilcClientOperations *ops,
734  *                                 SilcClientParams *params,
735  *                                 void *application,
736  *                                 const char *silc_version);
737  *
738  * DESCRIPTION
739  *
740  *    Allocates new client object. This has to be done before client may
741  *    work. After calling this one must call silc_client_init to initialize
742  *    the client. The `application' is application specific user data pointer
743  *    and caller must free it. The `silc_version' is the application version
744  *    that will be used to compare against remote host's (usually a server)
745  *    version string.  The `application' context is accessible by the
746  *    application by client->application, client being SilcClient.
747  *
748  ***/
749 SilcClient silc_client_alloc(SilcClientOperations *ops,
750                              SilcClientParams *params,
751                              void *application,
752                              const char *version_string);
753
754 /****f* silcclient/SilcClientAPI/silc_client_free
755  *
756  * SYNOPSIS
757  *
758  *    void silc_client_free(SilcClient client);
759  *
760  * DESCRIPTION
761  *
762  *    Frees client object and its internals.  The execution of the client
763  *    should be stopped with silc_client_stop function before calling
764  *    this function.
765  *
766  ***/
767 void silc_client_free(SilcClient client);
768
769 /****f* silcclient/SilcClientAPI/silc_client_init
770  *
771  * SYNOPSIS
772  *
773  *    SilcBool silc_client_init(SilcClient client, const char *username,
774  *                              const char *hostname, const char *realname,
775  *                              SilcClientRunning running, void *context);
776  *
777  * DESCRIPTION
778  *
779  *    Initializes the client. This makes all the necessary steps to make
780  *    the client ready to be run. One must call silc_client_run to run the
781  *    client. Returns FALSE if error occurred, TRUE otherwise.
782  *
783  *    The `username', `hostname' and `realname' strings must be given and
784  *    they must be UTF-8 encoded.  The `username' is the client's username
785  *    in the operating system, `hostname' is the client's host name and
786  *    the `realname' is the user's real name.
787  *
788  *    The `running' callback is called after the client is running after
789  *    silc_client_run or silc_client_run_one has been called.  Application
790  *    may start using the Client library API after that.  Setting the
791  *    callback is optional, but recommended.
792  *
793  ***/
794 SilcBool silc_client_init(SilcClient client, const char *username,
795                           const char *hostname, const char *realname,
796                           SilcClientRunning running, void *context);
797
798 /****f* silcclient/SilcClientAPI/silc_client_run
799  *
800  * SYNOPSIS
801  *
802  *    void silc_client_run(SilcClient client);
803  *
804  * DESCRIPTION
805  *
806  *    Runs the client.  This starts the scheduler from the utility library.
807  *    When this functions returns the execution of the application is over.
808  *    The client must be initialized before calling this.
809  *
810  ***/
811 void silc_client_run(SilcClient client);
812
813 /****f* silcclient/SilcClientAPI/silc_client_run_one
814  *
815  * SYNOPSIS
816  *
817  *    void silc_client_run_one(SilcClient client);
818  *
819  * DESCRIPTION
820  *
821  *    Runs the client and returns immeadiately. This function is used when
822  *    the SILC Client object indicated by the `client' is run under some
823  *    other scheduler, or event loop or main loop.  On GUI applications,
824  *    for example this may be desired to used to run the client under the
825  *    GUI application's main loop.  Typically the GUI application would
826  *    register an idle task that calls this function multiple times in
827  *    a second to quickly process the SILC specific data.
828  *
829  ***/
830 void silc_client_run_one(SilcClient client);
831
832
833 /****f* silcclient/SilcClientAPI/silc_client_stop
834  *
835  * SYNOPSIS
836  *
837  *    void silc_client_stop(SilcClient client, SilcClientStopped stopped,
838  *                          void *context);
839  *
840  * DESCRIPTION
841  *
842  *    Stops the client. This is called to stop the client and thus to stop
843  *    the program.  The client context must be freed with the silc_client_free
844  *    function.  All connections that exist in this client must be closed
845  *    before calling this function.  Connections can be closed by calling
846  *    silc_client_close_connection.
847  *
848  *    The `stopped' will be called once the client and all connections have
849  *    finished.  The client may be freed after that.  Note that the `stopped'
850  *    won't be called before all connections have finished.  Setting the
851  *    callback is optional.
852  *
853  ***/
854 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
855                       void *context);
856
857 /* Connecting functions */
858
859 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
860  *
861  * NAME
862  *
863  *    typedef struct { ... } SilcClientConnectionParams;
864  *
865  * DESCRIPTION
866  *
867  *    Client connection parameters.  This can be filled by the application
868  *    and given as argument to silc_client_connect_to_server,
869  *    silc_client_connect_to_client, silc_client_key_exchange or
870  *    silc_client_send_key_agreement.
871  *
872  * SOURCE
873  */
874 typedef struct {
875   /* If this is provided the user's nickname in the network will be the
876      string given here.  If it is given, it must be UTF-8 encoded.  If this
877      string is not given, the user's username by default is used as nickname.
878      The nickname may later be changed by using NICK command.  The maximum
879      length for the nickname string is 128 bytes. */
880   char *nickname;
881
882   /* If this key repository pointer is non-NULL then public key received in
883      the key exchange protocol will be verified from this repository.  If
884      this is not provided then the `verify_public_key' client operation will
885      be called back to application.  If the boolean `verify_notfound' is set
886      to TRUE then the `verify_public_key' client operation will be called
887      in case the public key is not found in `repository'.  Only public keys
888      added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
889      be checked, other keys will be ignored. */
890   SilcSKR repository;
891   SilcBool verify_notfound;
892
893   /* Authentication data.  Application may set here the authentication data
894      and authentication method to be used in connecting.  If `auth_set'
895      boolean is TRUE then authentication data is provided by application.
896      If the authentication method is public key authentication then the key
897      pair given as argument when connecting will be used and `auth' field
898      is NULL.  If it is passphrase authentication, it can be provided in
899      `auth' and `auth_len' fields.  If `auth_set' is FALSE
900      the `get_auth_method' client operation will be called to get the
901      authentication method and data from application. */
902   SilcBool auth_set;
903   SilcAuthMethod auth_method;
904   void *auth;
905   SilcUInt32 auth_len;
906
907   /* If this boolean is set to TRUE then the connection will use UDP instead
908      of TCP.  If UDP is set the also the next `local_ip' and `local_port'
909      must be set. */
910   SilcBool udp;
911
912   /* The `local_ip' specifies the local IP address used with the connection.
913      It must be non-NULL if `udp' boolean is TRUE.  If the `local_port' is
914      non-zero it will be used as local port with UDP connection.  The remote
915      host will also send packets to the specified address and port.  If the
916      `bind_ip' is non-NULL a listener is bound to that address instead of
917      `local_ip'. */
918   char *local_ip;
919   char *bind_ip;
920   int local_port;
921
922   /* If this boolean is set to TRUE then the key exchange is done with
923      perfect forward secrecy. */
924   SilcBool pfs;
925
926   /* If this boolean is set to TRUE then connection authentication protocol
927      is not performed during connecting.  Only key exchange protocol is
928      performed.  This usually must be set to TRUE when connecting to another
929      client, but must be FALSE with server connections. */
930   SilcBool no_authentication;
931
932   /* The SILC session detachment data that was returned in the `command_reply'
933      client operation for SILC_COMMAND_DETACH command.  If this is provided
934      here the client library will attempt to resume the session in the network.
935      After the connection is created and the session has been resumed the
936      client will receive SILC_COMMAND_NICK command_reply for the client's
937      nickname in the network and SILC_COMMAND_JOIN command reply for all the
938      channels that the client has joined in the network.  It may also receive
939      SILC_COMMAND_UMODE command reply to set user's mode on the network. */
940   unsigned char *detach_data;
941   SilcUInt32 detach_data_len;
942
943   /* Connection timeout.  If non-zero, the connection will timeout unless
944      the SILC connection is completed in the specified amount of time. */
945   SilcUInt32 timeout_secs;
946
947   /* Rekey timeout in seconds.  The client will perform rekey in this
948      time interval.  If set to zero, the default value will be used
949      (3600 seconds, 1 hour). */
950   unsigned int rekey_secs;
951
952 } SilcClientConnectionParams;
953 /***/
954
955 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
956  *
957  * SYNOPSIS
958  *
959  *    SilcAsyncOperation
960  *    silc_client_connect_to_server(SilcClient client,
961  *                                  SilcClientConnectionParams *params,
962  *                                  SilcPublicKey public_key,
963  *                                  char *remote_host, int port,
964  *                                  SilcClientConnectCallback callback,
965  *                                  void *context);
966  *
967  * DESCRIPTION
968  *
969  *    Connects to remote server `remote_host' at port `port'.  This function
970  *    can be used to create connection to remote SILC server and start
971  *    SILC session in the SILC network.  The `params' may be provided
972  *    to provide various connection parameters.  The `public_key' and the
973  *    `private_key' is your identity used in this connection.  When
974  *    authentication method is based on digital signatures, this key pair
975  *    will be used.  The `callback' with `context' will be called after the
976  *    connection has been created.  It will also be called later when remote
977  *    host disconnects.
978  *
979  *    If application wishes to create the network connection itself, use
980  *    the silc_client_key_exchange after creating the connection to start
981  *    key exchange and authentication with the server.
982  *
983  *    Returns SilcAsyncOperation which can be used to cancel the connecting,
984  *    or NULL on error.  Note that the returned pointer becomes invalid
985  *    after the `callback' is called.
986  *
987  ***/
988 SilcAsyncOperation
989 silc_client_connect_to_server(SilcClient client,
990                               SilcClientConnectionParams *params,
991                               SilcPublicKey public_key,
992                               SilcPrivateKey private_key,
993                               char *remote_host, int port,
994                               SilcClientConnectCallback callback,
995                               void *context);
996
997 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
998  *
999  * SYNOPSIS
1000  *
1001  *    SilcAsyncOperation
1002  *    silc_client_connect_to_client(SilcClient client,
1003  *                                  SilcClientConnectionParams *params,
1004  *                                  SilcPublicKey public_key,
1005  *                                  char *remote_host, int port,
1006  *                                  SilcClientConnectCallback callback,
1007  *                                  void *context);
1008  *
1009  * DESCRIPTION
1010  *
1011  *    Connects to remote client `remote_host' at port `port'.  This function
1012  *    can be used to create peer-to-peer connection to another SILC client,
1013  *    for example, for direct conferencing, or file transfer or for other
1014  *    purposes.  The `params' may be provided to provide various connection
1015  *    parameters.  The `public_key' and the `private_key' is your identity
1016  *    used in this connection.  The `callback' with `context' will be called
1017  *    after the connection has been created.  It will also be called later
1018  *    when remote host disconnects.
1019  *
1020  *    If application wishes to create the network connection itself, use
1021  *    the silc_client_key_exchange after creating the connection to start
1022  *    key exchange with the client.
1023  *
1024  *    Returns SilcAsyncOperation which can be used to cancel the connecting,
1025  *    or NULL on error.  Note that the returned pointer becomes invalid
1026  *    after the `callback' is called.
1027  *
1028  ***/
1029 SilcAsyncOperation
1030 silc_client_connect_to_client(SilcClient client,
1031                               SilcClientConnectionParams *params,
1032                               SilcPublicKey public_key,
1033                               SilcPrivateKey private_key,
1034                               char *remote_host, int port,
1035                               SilcClientConnectCallback callback,
1036                               void *context);
1037
1038 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1039  *
1040  * SYNOPSIS
1041  *
1042  *    SilcAsyncOperation
1043  *    silc_client_key_exchange(SilcClient client,
1044  *                             SilcClientConnectionParams *params,
1045  *                             SilcPublicKey public_key,
1046  *                             SilcPrivateKey private_key,
1047  *                             SilcStream stream,
1048  *                             SilcConnectionType conn_type,
1049  *                             SilcClientConnectCallback callback,
1050  *                             void *context);
1051  *
1052  * DESCRIPTION
1053  *
1054  *    Starts key exchange protocol and authentication protocol in the
1055  *    connection indicated by `stream'.  This function can be be used to
1056  *    start SILC session with remote host (usually server) when the caller
1057  *    has itself created the connection, instead of calling the function
1058  *    silc_client_connect_to_server or silc_client_connect_to_client.  If
1059  *    one of those functions was used this function must not be called as
1060  *    in that case the key exchange is performed automatically.
1061  *
1062  *    Use this function only if you have created the connection by yourself.
1063  *    After creating the connection the socket must be wrapped into a
1064  *    socket stream.  See silcsocketstream.h for more information.  Note that
1065  *    the `stream' must have valid remote IP address (and optionally also
1066  *    hostname) and port set.
1067  *
1068  *    The `params' may be provided to provide various connection parameters.
1069  *    The `public_key' and the `private_key' is your identity used in this
1070  *    session.  The `callback' with `context' will be called after the session
1071  *    has been set up.  It will also be called later when remote host
1072  *    disconnects.  The `conn_type' is the type of session this is going to
1073  *    be.
1074  *
1075  *    Returns SilcAsyncOperation which can be used to cancel the connecting,
1076  *    or NULL on error.  Note that the returned pointer becomes invalid
1077  *    after the `callback' is called.
1078  *
1079  * EXAMPLE
1080  *
1081  *    int sock;
1082  *
1083  *    // Create remote connection stream.  Resolve hostname and IP also.
1084  *    sock = create_connection(remote_host, port);
1085  *    silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1086  *                                  stream_create_cb, app);
1087  *
1088  *    // Stream callback delivers our new SilcStream context
1089  *    void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1090  *                          void *context)
1091  *    {
1092  *      ...
1093  *      if (status != SILC_SOCKET_OK)
1094  *        error(status);
1095  *
1096  *      // Start key exchange
1097  *      silc_client_key_exchange(client, NULL, public_key, private_key,
1098  *                               stream, SILC_CONN_SERVER, connection_cb, app);
1099  *      ...
1100  *    }
1101  *
1102  ***/
1103 SilcAsyncOperation
1104 silc_client_key_exchange(SilcClient client,
1105                          SilcClientConnectionParams *params,
1106                          SilcPublicKey public_key,
1107                          SilcPrivateKey private_key,
1108                          SilcStream stream,
1109                          SilcConnectionType conn_type,
1110                          SilcClientConnectCallback callback,
1111                          void *context);
1112
1113 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1114  *
1115  * SYNOPSIS
1116  *
1117  *    void silc_client_close_connection(SilcClient client,
1118  *                                      SilcClientConnection conn);
1119  *
1120  * DESCRIPTION
1121  *
1122  *    Closes the remote connection `conn'.  The `conn' will become invalid
1123  *    after this call.  Usually this function is called only when explicitly
1124  *    closing connection for example in case of error, or when the remote
1125  *    connection was created by the application or when the remote is client
1126  *    connection.  Server connections are usually closed by sending QUIT
1127  *    command to the server.  However, this call may also be used.
1128  *
1129  ***/
1130 void silc_client_close_connection(SilcClient client,
1131                                   SilcClientConnection conn);
1132
1133 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1134
1135 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1136  *
1137  * SYNOPSIS
1138  *
1139  *    SilcBool silc_client_send_channel_message(SilcClient client,
1140  *                                              SilcClientConnection conn,
1141  *                                              SilcChannelEntry channel,
1142  *                                              SilcChannelPrivateKey key,
1143  *                                              SilcMessageFlags flags,
1144  *                                              SilcHash hash,
1145  *                                              unsigned char *data,
1146  *                                              SilcUInt32 data_len);
1147  *
1148  * DESCRIPTION
1149  *
1150  *    Sends packet to the `channel'. Packet to channel is always encrypted
1151  *    differently from "normal" packets. SILC header of the packet is
1152  *    encrypted with the next receiver's key and the rest of the packet is
1153  *    encrypted with the channel specific key. Padding and HMAC is computed
1154  *    with the next receiver's key. The `data' is the channel message.
1155  *
1156  *    If `key' is provided then that private key is used to encrypt the
1157  *    channel message.  If it is not provided, private keys has not been
1158  *    set at all, the normal channel key is used automatically.  If private
1159  *    keys are set then the first key (the key that was added first as
1160  *    private key) is used.
1161  *
1162  *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1163  *    digitally signed with the SILC key pair.
1164  *
1165  *    Returns TRUE if the message was sent, and FALSE if error occurred or
1166  *    the sending is not allowed due to channel modes (like sending is
1167  *    blocked).  This function is thread safe and private messages can be
1168  *    sent from multiple threads.
1169  *
1170  ***/
1171 SilcBool silc_client_send_channel_message(SilcClient client,
1172                                           SilcClientConnection conn,
1173                                           SilcChannelEntry channel,
1174                                           SilcChannelPrivateKey key,
1175                                           SilcMessageFlags flags,
1176                                           SilcHash hash,
1177                                           unsigned char *data,
1178                                           SilcUInt32 data_len);
1179
1180 /* Block process until channel message from `channel' is received */
1181 SilcBool
1182 silc_client_receive_channel_message(SilcClient client,
1183                                     SilcClientConnection conn,
1184                                     SilcChannelEntry channel,
1185                                     SilcClientEntry *return_sender,
1186                                     SilcMessageFlags *return_flags,
1187                                     const unsigned char **return_message,
1188                                     SilcUInt32 *return_message_len);
1189
1190 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1191  *
1192  * SYNOPSIS
1193  *
1194  *    SilcBool silc_client_send_private_message(SilcClient client,
1195  *                                              SilcClientConnection conn,
1196  *                                              SilcClientEntry client_entry,
1197  *                                              SilcMessageFlags flags,
1198  *                                              SilcHash hash,
1199  *                                              unsigned char *data,
1200  *                                              SilcUInt32 data_len);
1201  *
1202  * DESCRIPTION
1203  *
1204  *    Sends private message to remote client. If private message key has
1205  *    not been set with this client then the message will be encrypted using
1206  *    normal session keys.  If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1207  *    the message will be digitally signed with the SILC key pair.  In this
1208  *    case the caller must also provide the `hash' pointer.  By default, the
1209  *    hash function must be SHA-1.
1210  *
1211  *    Returns TRUE if the message was sent, and FALSE if error occurred.
1212  *    This function is thread safe and private messages can be sent from
1213  *    multiple threads.
1214  *
1215  ***/
1216 SilcBool silc_client_send_private_message(SilcClient client,
1217                                           SilcClientConnection conn,
1218                                           SilcClientEntry client_entry,
1219                                           SilcMessageFlags flags,
1220                                           SilcHash hash,
1221                                           unsigned char *data,
1222                                           SilcUInt32 data_len);
1223
1224 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1225  *
1226  * SYNOPSIS
1227  *
1228  *    SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1229  *                                           SilcClientEntry client_entry);
1230  *
1231  * DESCRIPTION
1232  *
1233  *    Returns the SilcChannelUser entry if the `client_entry' is joined on the
1234  *    channel indicated by the `channel'. NULL if client is not joined on
1235  *    the channel.
1236  *
1237  ***/
1238 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1239                                        SilcClientEntry client_entry);
1240
1241
1242 /* Command management */
1243
1244 /****f* silcclient/SilcClientAPI/silc_client_command_call
1245  *
1246  * SYNOPSIS
1247  *
1248  *    SilcUInt16 silc_client_command_call(SilcClient client,
1249  *                                        SilcClientConnection conn,
1250  *                                        const char *command_line, ...);
1251  *
1252  * DESCRIPTION
1253  *
1254  *    Calls and executes the command indicated by the `command_name'.
1255  *    The `command_line' is a string which includes the command's name and
1256  *    its arguments separated with whitespaces (' ').  If `command_line'
1257  *    is non-NULL then all variable arguments are ignored by default.
1258  *
1259  *    If `command_line' is NULL, then the variable arguments define the
1260  *    command's name and its arguments.  The first variable argument must
1261  *    be the command name.  The variable argument list must be terminated
1262  *    with NULL.
1263  *
1264  *    Returns FALSE if the command is not known and TRUE after command.
1265  *    execution.  The "command" client operation is called when the
1266  *    command is executed to indicate whether the command executed
1267  *    successfully or not.
1268  *
1269  *    The "command_reply" client operation will be called when reply is
1270  *    received from the server to the command.  Application may also use
1271  *    the silc_client_command_pending to attach to the command reply.
1272  *    The command identifier for silc_client_command_pending function after
1273  *    this function call is conn->cmd_ident, which application may use.
1274  *
1275  * EXAMPLE
1276  *
1277  *    silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1278  *                             NULL);
1279  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1280  *
1281  * NOTES
1282  *
1283  *    This command executes the commands implemented inside the client
1284  *    library.  These commands are designed for command line applications,
1285  *    but GUI application may call them too if needed.  Alternatively
1286  *    application may override the library and use silc_client_command_send
1287  *    function instead.
1288  *
1289  ***/
1290 SilcUInt16 silc_client_command_call(SilcClient client,
1291                                     SilcClientConnection conn,
1292                                     const char *command_line, ...);
1293
1294 /* If FALSE is returned the callback will not be called again, even if there
1295    is more data coming in in the command reply.  If there are other pending
1296    commands waiting for the reply, they will receive it even if some other
1297    command reply has returned FALSE. */
1298 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1299                                            SilcClientConnection conn,
1300                                            SilcCommand command,
1301                                            SilcStatus status,
1302                                            SilcStatus error,
1303                                            void *context,
1304                                            va_list ap);
1305
1306 /****f* silcclient/SilcClientAPI/silc_client_command_send
1307  *
1308  * SYNOPSIS
1309  *
1310  *    SilcUInt16 silc_client_command_send(SilcClient client,
1311  *                                        SilcClientConnection conn,
1312  *                                        SilcCommand command,
1313  *                                        SilcClientCommandReply reply,
1314  *                                        void *reply_context,
1315  *                                        SilcUInt32 argc, ...);
1316  *
1317  * DESCRIPTION
1318  *
1319  *    Generic function to send any command.  The arguments must be given
1320  *    already encoded into correct format and in correct order. If application
1321  *    wants to perform the commands by itself, it can do so and send the data
1322  *    directly to the server using this function.  If application is using
1323  *    the silc_client_command_call, this function is usually not used.
1324  *    Programmer should get familiar with the SILC protocol commands
1325  *    specification when using this function, as the arguments needs to
1326  *    be encoded as specified in the protocol.
1327  *
1328  *    The variable arguments are a set of { type, data, data_length },
1329  *    and the `argc' is the number of these sets.
1330  *
1331  *    The `reply' callback must be provided, and it is called when the
1332  *    command reply is received from the server.  Note that, when using this
1333  *    function the default `command_reply' client operation will not be
1334  *    called, when reply is received.  Note however that, `reply' is almost
1335  *    identical with `command_reply' callback, and application may forward
1336  *    the reply from `reply' to `command_reply' callback, if desired.
1337  *
1338  *    Returns command identifier for this sent command.  It can be used
1339  *    to additionally attach to the command reply using the function
1340  *    silc_client_command_pending, if needed.  Returns 0 on error,
1341  *
1342  * EXAMPLE
1343  *
1344  *    silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1345  *                             my_whois_command_reply, cmd_ctx,
1346  *                             1, 1, nickname, strlen(nickname));
1347  *
1348  ***/
1349 SilcUInt16 silc_client_command_send(SilcClient client,
1350                                     SilcClientConnection conn,
1351                                     SilcCommand command,
1352                                     SilcClientCommandReply reply,
1353                                     void *reply_context,
1354                                     SilcUInt32 argc, ...);
1355
1356 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1357  *
1358  * SYNOPSIS
1359  *
1360  *    void silc_client_command_pending(SilcClientConnection conn,
1361  *                                     SilcCommand reply_cmd,
1362  *                                     SilcUInt16 cmd-ident,
1363  *                                     SilcCommandCb callback,
1364  *                                     void *context);
1365  *
1366  * DESCRIPTION
1367  *
1368  *    This function can be used to add pending command callback to be
1369  *    called when an command reply is received to an earlier sent command.
1370  *    The `reply_cmd' is the command that must be received in order for
1371  *    the pending command callback indicated by `callback' to be called.
1372  *    The `callback' will deliver the `context' and
1373  *    SilcClientCommandReplyContext which includes the internals of the
1374  *    command reply.
1375  *
1376  *    The `cmd_ident' is a command identifier which was set for the earlier
1377  *    sent command.  The command reply will include the same identifier
1378  *    and pending command callback will be called when the reply is
1379  *    received with the same command identifier.  It is possible to
1380  *    add multiple pending command callbacks for same command and for
1381  *    same identifier.
1382  *
1383  *    Application may use this function to add its own command reply
1384  *    handlers if it wishes not to use the standard `command_reply'
1385  *    client operation.  However, note that the pending command callback
1386  *    does not deliver parsed command reply, but application must parse
1387  *    it itself.
1388  *
1389  *    Note also that the application is notified about the received command
1390  *    reply through the `command_reply' client operation before calling
1391  *    the `callback` pending command callback.  That is the normal
1392  *    command reply handling, and is called regardless whether pending
1393  *    command callbacks are used or not.
1394  *
1395  *    Commands that application calls with silc_client_command_call
1396  *    will use a command identifier from conn->cmd_ident variable.  After
1397  *    calling the silc_client_command_call, the conn->cmd_ident includes
1398  *    the command identifier that was used for the command sending.
1399  *
1400  * EXAMPLE
1401  *
1402  *    silc_client_command_call(client, conn, "PING silc.silcnet.org");
1403  *    silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1404  *                                my_ping_handler, my_ping_context);
1405  *
1406  ***/
1407 SilcBool silc_client_command_pending(SilcClientConnection conn,
1408                                      SilcCommand command,
1409                                      SilcUInt16 cmd_ident,
1410                                      SilcClientCommandReply reply,
1411                                      void *context);
1412
1413
1414 /* Private Message key management (client_prvmsg.c) */
1415
1416 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1417  *
1418  * SYNOPSIS
1419  *
1420  *    SilcBool
1421  *    silc_client_add_private_message_key(SilcClient client,
1422  *                                        SilcClientConnection conn,
1423  *                                        SilcClientEntry client_entry,
1424  *                                        const char *cipher,
1425  *                                        const char *hmac,
1426  *                                        unsigned char *key,
1427  *                                        SilcUInt32 key_len);
1428  *
1429  * DESCRIPTION
1430  *
1431  *    Adds a static private message key to the client library.  The key
1432  *    will be used to encrypt all private message between the client and
1433  *    the remote client indicated by the `client_entry'.  The `key' can
1434  *    be for example a pre-shared-key, passphrase or similar shared secret
1435  *    string.  The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1436  *    to assure that the requirements of the SILC protocol are met. The
1437  *    API, however, allows to allocate any cipher and HMAC.
1438  *
1439  *    If the private message key is added to client without first receiving
1440  *    a request for it from the remote `client_entry' this function will
1441  *    send the request to `client_entry'.  Note that, the actual key is
1442  *    not sent to the network.
1443  *
1444  *    It is not necessary to set key for normal private message usage. If the
1445  *    key is not set then the private messages are encrypted using normal
1446  *    session keys.  Setting the private key, however, increases the security.
1447  *
1448  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1449  *    otherwise.
1450  *
1451  ***/
1452 SilcBool silc_client_add_private_message_key(SilcClient client,
1453                                              SilcClientConnection conn,
1454                                              SilcClientEntry client_entry,
1455                                              const char *cipher,
1456                                              const char *hmac,
1457                                              unsigned char *key,
1458                                              SilcUInt32 key_len);
1459
1460 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1461  *
1462  * SYNOPSIS
1463  *
1464  *    SilcBool
1465  *    silc_client_add_private_message_key_ske(SilcClient client,
1466  *                                            SilcClientConnection conn,
1467  *                                            SilcClientEntry client_entry,
1468  *                                            const char *cipher,
1469  *                                            const char *hmac,
1470  *                                            SilcSKEKeyMaterial key);
1471  *
1472  * DESCRIPTION
1473  *
1474  *    Same as silc_client_add_private_message_key but takes the key material
1475  *    from the SKE key material structure.  This structure is received if
1476  *    the application uses the silc_client_send_key_agreement to negotiate
1477  *    the key material.  The `cipher' and `hmac' SHOULD be provided as it is
1478  *    negotiated also in the SKE protocol.
1479  *
1480  ***/
1481 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1482                                                  SilcClientConnection conn,
1483                                                  SilcClientEntry client_entry,
1484                                                  const char *cipher,
1485                                                  const char *hmac,
1486                                                  SilcSKEKeyMaterial key);
1487
1488 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1489  *
1490  * SYNOPSIS
1491  *
1492  *    SilcBool silc_client_del_private_message_key(SilcClient client,
1493  *                                             SilcClientConnection conn,
1494  *                                             SilcClientEntry client_entry);
1495  *
1496  * DESCRIPTION
1497  *
1498  *    Removes the private message from the library. The key won't be used
1499  *    after this to protect the private messages with the remote `client_entry'
1500  *    client. Returns FALSE on error, TRUE otherwise.
1501  *
1502  ***/
1503 SilcBool silc_client_del_private_message_key(SilcClient client,
1504                                              SilcClientConnection conn,
1505                                              SilcClientEntry client_entry);
1506
1507 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1508  *
1509  * SYNOPSIS
1510  *
1511  *    SilcPrivateMessageKeys
1512  *    silc_client_list_private_message_keys(SilcClient client,
1513  *                                          SilcClientConnection conn,
1514  *                                          SilcUInt32 *key_count);
1515  *
1516  * DESCRIPTION
1517  *
1518  *    Returns array of set private message keys associated to the connection
1519  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1520  *    count to the `key_count' argument. The array must be freed by the caller
1521  *    by calling the silc_client_free_private_message_keys function. Note:
1522  *    the keys returned in the array is in raw format. It might not be desired
1523  *    to show the keys as is. The application might choose not to show the keys
1524  *    at all or to show the fingerprints of the keys.
1525  *
1526  ***/
1527 SilcPrivateMessageKeys
1528 silc_client_list_private_message_keys(SilcClient client,
1529                                       SilcClientConnection conn,
1530                                       SilcUInt32 *key_count);
1531
1532 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1533  *
1534  * SYNOPSIS
1535  *
1536  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1537  *                                               SilcUInt32 key_count);
1538  *
1539  * DESCRIPTION
1540  *
1541  *    Frees the SilcPrivateMessageKeys array returned by the function
1542  *    silc_client_list_private_message_keys.
1543  *
1544  ***/
1545 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1546                                            SilcUInt32 key_count);
1547
1548
1549 /* Channel private key management (client_channel.c,
1550    SilcChannelPrivateKey is defined in idlist.h) */
1551
1552 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1553  *
1554  * SYNOPSIS
1555  *
1556  *    SilcBool silc_client_add_channel_private_key(SilcClient client,
1557  *                                             SilcClientConnection conn,
1558  *                                             SilcChannelEntry channel,
1559  *                                             const char *name,
1560  *                                             char *cipher,
1561  *                                             char *hmac,
1562  *                                             unsigned char *key,
1563  *                                             SilcUInt32 key_len,
1564  *                                             SilcChannelPrivateKey *ret_key);
1565  *
1566  * DESCRIPTION
1567  *
1568  *    Adds private key for channel. When channel has private key then the
1569  *    messages are encrypted using that key. All clients on the channel
1570  *    must also know the key in order to decrypt the messages. However,
1571  *    it is possible to have several private keys per one channel. In this
1572  *    case only some of the clients on the channel may know the one key
1573  *    and only some the other key.  The `name' can be application given
1574  *    name for the key.  This returns the created key to the 'ret_key'
1575  *    pointer if it is non-NULL;
1576  *
1577  *    If `cipher' and/or `hmac' is NULL then default values will be used
1578  *    (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1579  *
1580  *    The private key for channel is optional. If it is not set then the
1581  *    channel messages are encrypted using the channel key generated by the
1582  *    server. However, setting the private key (or keys) for the channel
1583  *    significantly adds security. If more than one key is set the library
1584  *    will automatically try all keys at the message decryption phase. Note:
1585  *    setting many keys slows down the decryption phase as all keys has to
1586  *    be tried in order to find the correct decryption key. However, setting
1587  *    a few keys does not have big impact to the decryption performace.
1588  *
1589  * NOTES
1590  *
1591  *    NOTE: This is entirely local setting. The key set using this function
1592  *    is not sent to the network at any phase.
1593  *
1594  *    NOTE: If the key material was originated by the SKE protocol (using
1595  *    silc_client_send_key_agreement) then the `key' MUST be the
1596  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1597  *    currently it is not expected that the SKE key material would be used
1598  *    as channel private key. However, this API allows it.
1599  *
1600  ***/
1601 SilcBool silc_client_add_channel_private_key(SilcClient client,
1602                                              SilcClientConnection conn,
1603                                              SilcChannelEntry channel,
1604                                              const char *name,
1605                                              char *cipher,
1606                                              char *hmac,
1607                                              unsigned char *key,
1608                                              SilcUInt32 key_len,
1609                                              SilcChannelPrivateKey *ret_key);
1610
1611 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1612  *
1613  * SYNOPSIS
1614  *
1615  *    SilcBool silc_client_del_channel_private_keys(SilcClient client,
1616  *                                              SilcClientConnection conn,
1617  *                                              SilcChannelEntry channel);
1618  *
1619  * DESCRIPTION
1620  *
1621  *    Removes all private keys from the `channel'. The old channel key is used
1622  *    after calling this to protect the channel messages. Returns FALSE on
1623  *    on error, TRUE otherwise.
1624  *
1625  ***/
1626 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1627                                               SilcClientConnection conn,
1628                                               SilcChannelEntry channel);
1629
1630 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1631  *
1632  * SYNOPSIS
1633  *
1634  *    SilcBool silc_client_del_channel_private_key(SilcClient client,
1635  *                                            SilcClientConnection conn,
1636  *                                            SilcChannelEntry channel,
1637  *                                            SilcChannelPrivateKey key);
1638  *
1639  * DESCRIPTION
1640  *
1641  *    Removes and frees private key `key' from the channel `channel'.
1642  *    The `key' is retrieved by calling the function
1643  *    silc_client_list_channel_private_keys. The key is not used after
1644  *    this. If the key was last private key then the old channel key is
1645  *    used hereafter to protect the channel messages. This returns FALSE
1646  *    on error, TRUE otherwise.
1647  *
1648  ***/
1649 SilcBool silc_client_del_channel_private_key(SilcClient client,
1650                                              SilcClientConnection conn,
1651                                              SilcChannelEntry channel,
1652                                              SilcChannelPrivateKey key);
1653
1654 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1655  *
1656  * SYNOPSIS
1657  *
1658  *    SilcDList
1659  *    silc_client_list_channel_private_keys(SilcClient client,
1660  *                                          SilcClientConnection conn,
1661  *                                          SilcChannelEntry channel);
1662  *
1663  * DESCRIPTION
1664  *
1665  *    Returns list of private keys associated to the `channel'.  The caller
1666  *    must free the returned list.  The pointers in the list may be
1667  *    used to delete the specific key by giving the pointer as argument to the
1668  *    function silc_client_del_channel_private_key.  Each entry in the list
1669  *    is SilcChannelPrivateKey.
1670  *
1671  ***/
1672 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1673                                                 SilcClientConnection conn,
1674                                                 SilcChannelEntry channel);
1675
1676 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1677  *
1678  * SYNOPSIS
1679  *
1680  *    void silc_client_current_channel_private_key(SilcClient client,
1681  *                                                 SilcClientConnection conn,
1682  *                                                 SilcChannelEntry channel,
1683  *                                                 SilcChannelPrivateKey key);
1684  *
1685  * DESCRIPTION
1686  *
1687  *    Sets the `key' to be used as current channel private key on the
1688  *    `channel'.  Packet sent after calling this function will be secured
1689  *    with `key'.
1690  *
1691  ***/
1692 void silc_client_current_channel_private_key(SilcClient client,
1693                                              SilcClientConnection conn,
1694                                              SilcChannelEntry channel,
1695                                              SilcChannelPrivateKey key);
1696
1697
1698 /* Key Agreement routines */
1699
1700 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1701  *
1702  * SYNOPSIS
1703  *
1704  *    void silc_client_send_key_agreement(SilcClient client,
1705  *                                        SilcClientConnection conn,
1706  *                                        SilcClientEntry client_entry,
1707  *                                        SilcClientConnectionParams *params,
1708  *                                        SilcPublicKey public_key,
1709  *                                        SilcPrivateKey private_key,
1710  *                                        SilcKeyAgreementCallback completion,
1711  *                                        void *context);
1712  *
1713  * DESCRIPTION
1714  *
1715  *    Sends key agreement request to the remote client indicated by the
1716  *    `client_entry'.
1717  *
1718  *    If `params' is non-NULL and it has the `local_ip' and `local_port' set
1719  *    the caller will provide the connection endpoint for the key agreement
1720  *    connection.  The `bind_ip' can be used to bind to that IP instead of
1721  *    `local_ip'.  If the `udp' is set to TRUE the connection will be UDP
1722  *    instead of TCP.  Caller may also set the `repository', `verify_notfound'
1723  *    and `timeout_secs' fields in `params'.  Other fields are ignored.
1724  *    If `params' is NULL, then the `client_entry' is expected to provide
1725  *    the connection endpoint for us.  It is recommended the `timeout_secs'
1726  *    is specified in case the remote client does not reply anything to
1727  *    the request.
1728  *
1729  *    The `public_key' and `private_key' is our identity in the key agreement.
1730  *
1731  *    In case we do not provide the connection endpoint, we will receive
1732  *    the `key_agreement' client operation when the remote send its own
1733  *    key agreement request packet.  We may then there start the key
1734  *    agreement with silc_client_perform_key_agreement.  If we provided the
1735  *    the connection endpoint, the client operation will not be called.
1736  *
1737  *    There can be only one active key agreement for `client_entry'.  Old
1738  *    key agreement may be aborted by calling silc_client_abort_key_agreement.
1739  *
1740  ***/
1741 void silc_client_send_key_agreement(SilcClient client,
1742                                     SilcClientConnection conn,
1743                                     SilcClientEntry client_entry,
1744                                     SilcClientConnectionParams *params,
1745                                     SilcPublicKey public_key,
1746                                     SilcPrivateKey private_key,
1747                                     SilcKeyAgreementCallback completion,
1748                                     void *context);
1749
1750 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1751  *
1752  * SYNOPSIS
1753  *
1754  *    void
1755  *    silc_client_perform_key_agreement(SilcClient client,
1756  *                                      SilcClientConnection conn,
1757  *                                      SilcClientEntry client_entry,
1758  *                                      SilcClientConnectionParams *params,
1759  *                                      SilcPublicKey public_key,
1760  *                                      SilcPrivateKey private_key,
1761  *                                      char *hostname, int port,
1762  *                                      SilcKeyAgreementCallback completion,
1763  *                                      void *context);
1764  *
1765  * DESCRIPTION
1766  *
1767  *    Performs the key agreement protocol.  Application may use this to
1768  *    initiate the key agreement protocol.  Usually this is called after
1769  *    receiving the `key_agreement' client operation.
1770  *
1771  *    The `hostname' is the remote hostname (or IP address) and the `port'
1772  *    is the remote port.  The `completion' callback with the `context' will
1773  *    be called after the key agreement protocol.
1774  *
1775  *    The `params' is connection parameters and it may be used to define
1776  *    the key agreement connection related parameters.  It may be NULL.
1777  *
1778  ***/
1779 void silc_client_perform_key_agreement(SilcClient client,
1780                                        SilcClientConnection conn,
1781                                        SilcClientEntry client_entry,
1782                                        SilcClientConnectionParams *params,
1783                                        SilcPublicKey public_key,
1784                                        SilcPrivateKey private_key,
1785                                        char *hostname, int port,
1786                                        SilcKeyAgreementCallback completion,
1787                                        void *context);
1788
1789 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1790  *
1791  * SYNOPSIS
1792  *
1793  *    void
1794  *    silc_client_perform_key_agreement_stream(
1795  *                                      SilcClient client,
1796  *                                      SilcClientConnection conn,
1797  *                                      SilcClientEntry client_entry,
1798  *                                      SilcClientConnectionParams *params,
1799  *                                      SilcPublicKey public_key,
1800  *                                      SilcPrivateKey private_key,
1801  *                                      SilcStream stream,
1802  *                                      SilcKeyAgreementCallback completion,
1803  *                                      void *context);
1804  *
1805  * DESCRIPTION
1806  *
1807  *    Same as silc_client_perform_key_agreement but the caller has created
1808  *    the connection.  The `stream' is the created connection.
1809  *
1810  ***/
1811 void
1812 silc_client_perform_key_agreement_stream(SilcClient client,
1813                                          SilcClientConnection conn,
1814                                          SilcClientEntry client_entry,
1815                                          SilcClientConnectionParams *params,
1816                                          SilcPublicKey public_key,
1817                                          SilcPrivateKey private_key,
1818                                          SilcStream stream,
1819                                          SilcKeyAgreementCallback completion,
1820                                          void *context);
1821
1822 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1823  *
1824  * SYNOPSIS
1825  *
1826  *    void silc_client_abort_key_agreement(SilcClient client,
1827  *                                         SilcClientConnection conn,
1828  *                                         SilcClientEntry client_entry);
1829  *
1830  * DESCRIPTION
1831  *
1832  *    This function can be called to unbind the hostname and the port for
1833  *    the key agreement protocol. However, this function has effect only
1834  *    before the key agreement protocol has been performed. After it has
1835  *    been performed the library will automatically unbind the port. The
1836  *    `client_entry' is the client to which we sent the key agreement
1837  *    request.  The key agreement completion callback will be called
1838  *    with SILC_KEY_AGREEMENT_ABORTED status.
1839  *
1840  ***/
1841 void silc_client_abort_key_agreement(SilcClient client,
1842                                      SilcClientConnection conn,
1843                                      SilcClientEntry client_entry);
1844
1845
1846 /* Misc functions */
1847
1848 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1849  *
1850  * SYNOPSIS
1851  *
1852  *    void silc_client_set_away_message(SilcClient client,
1853  *                                      SilcClientConnection conn,
1854  *                                      char *message);
1855  *
1856  * DESCRIPTION
1857  *
1858  *    Sets away `message'.  The away message may be set when the client's
1859  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1860  *    to anyone who sends private message.  The `message' will be sent
1861  *    automatically back to the the client who send private message.  If
1862  *    away message is already set this replaces the old message with the
1863  *    new one.  If `message' is NULL the old away message is removed.
1864  *    The sender may freely free the memory of the `message'.
1865  *
1866  ***/
1867 void silc_client_set_away_message(SilcClient client,
1868                                   SilcClientConnection conn,
1869                                   char *message);
1870
1871 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1872  *
1873  * SYNOPSIS
1874  *
1875  *    typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1876  *                                              SilcClientConnection conn,
1877  *                                              SilcAuthMethod auth_meth,
1878  *                                              void *context);
1879  *
1880  * DESCRIPTION
1881  *
1882  *    Connection authentication method request callback. This is called
1883  *    by the client library after it has received the authentication method
1884  *    that the application requested by calling the function
1885  *    silc_client_request_authentication_method.
1886  *
1887  ***/
1888 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1889                                           SilcClientConnection conn,
1890                                           SilcAuthMethod auth_meth,
1891                                           void *context);
1892
1893 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1894  *
1895  * SYNOPSIS
1896  *
1897  *    void
1898  *    silc_client_request_authentication_method(SilcClient client,
1899  *                                              SilcClientConnection conn,
1900  *                                              SilcConnectionAuthRequest
1901  *                                                callback,
1902  *                                              void *context);
1903  *
1904  * DESCRIPTION
1905  *
1906  *    This function can be used to request the current authentication method
1907  *    from the server. This may be called when connecting to the server
1908  *    and the client library requests the authentication data from the
1909  *    application. If the application does not know the current authentication
1910  *    method it can request it from the server using this function.
1911  *    The `callback' with `context' will be called after the server has
1912  *    replied back with the current authentication method.
1913  *
1914  ***/
1915 void
1916 silc_client_request_authentication_method(SilcClient client,
1917                                           SilcClientConnection conn,
1918                                           SilcConnectionAuthRequest callback,
1919                                           void *context);
1920
1921 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1922  *
1923  * NAME
1924  *
1925  *    typedef enum { ... } SilcClientMonitorStatus;
1926  *
1927  * DESCRIPTION
1928  *
1929  *    File transmission session status types.  These will indicate
1930  *    the status of the file transmission session.
1931  *
1932  * SOURCE
1933  */
1934 typedef enum {
1935   SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT,    /* In key agreemenet phase */
1936   SILC_CLIENT_FILE_MONITOR_SEND,             /* Sending file */
1937   SILC_CLIENT_FILE_MONITOR_RECEIVE,          /* Receiving file */
1938   SILC_CLIENT_FILE_MONITOR_GET,
1939   SILC_CLIENT_FILE_MONITOR_PUT,
1940   SILC_CLIENT_FILE_MONITOR_CLOSED,           /* Session closed */
1941   SILC_CLIENT_FILE_MONITOR_ERROR,            /* Error during session */
1942 } SilcClientMonitorStatus;
1943 /***/
1944
1945 /****d* silcclient/SilcClientAPI/SilcClientFileError
1946  *
1947  * NAME
1948  *
1949  *    typedef enum { ... } SilcClientFileError;
1950  *
1951  * DESCRIPTION
1952  *
1953  *    File transmission error types.  These types are returned by
1954  *    some of the file transmission functions, and by the monitor
1955  *    callback to indicate error.
1956  *
1957  * SOURCE
1958  */
1959 typedef enum {
1960   SILC_CLIENT_FILE_OK,
1961   SILC_CLIENT_FILE_ERROR,
1962   SILC_CLIENT_FILE_UNKNOWN_SESSION,
1963   SILC_CLIENT_FILE_ALREADY_STARTED,
1964   SILC_CLIENT_FILE_NO_SUCH_FILE,
1965   SILC_CLIENT_FILE_PERMISSION_DENIED,
1966   SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1967 } SilcClientFileError;
1968 /***/
1969
1970 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1971  *
1972  * SYNOPSIS
1973  *
1974  *    typedef void (*SilcClientFileMonitor)(SilcClient client,
1975  *                                          SilcClientConnection conn,
1976  *                                          SilcClientMonitorStatus status,
1977  *                                          SilcClientFileError error,
1978  *                                          SilcUInt64 offset,
1979  *                                          SilcUInt64 filesize,
1980  *                                          SilcClientEntry client_entry,
1981  *                                          SilcUInt32 session_id,
1982  *                                          const char *filepath,
1983  *                                          void *context);
1984  *
1985  * DESCRIPTION
1986  *
1987  *    Monitor callback that is called during the file transmission to
1988  *    monitor the transmission process.  The `status' indicates the current
1989  *    monitoring process.  The `error' will indicate the error type
1990  *    if `status' is SILC_CLIENT_FILE_MONITOR_ERROR.  The `offset' is the
1991  *    currently transmitted amount of total `filesize'.  The `client_entry'
1992  *    indicates the remote client, and the transmission session ID is the
1993  *    `session_id'.  The filename being transmitted is indicated by the
1994  *    `filepath'.
1995  *
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 /****f* silcclient/SilcClientAPI/SilcClientFileName
2009  *
2010  * SYNOPSIS
2011  *
2012  *    typedef void (*SilcClientFileName)(const char *filepath,
2013  *                                       void *context);
2014  *
2015  * DESCRIPTION
2016  *
2017  *    Completion callback for the SilcClientFileAskName callback function.
2018  *    Application calls this to deliver the filepath and filename where
2019  *    the downloaded file is to be saved.
2020  *
2021  ***/
2022 typedef void (*SilcClientFileName)(const char *filepath,
2023                                    void *context);
2024
2025 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2026  *
2027  * SYNOPSIS
2028  *
2029  *    typedef void (*SilcClientFileAskName)(SilcClient client,
2030  *                                          SilcClientConnection conn,
2031  *                                          SilcUInt32 session_id,
2032  *                                          const char *remote_filename,
2033  *                                          SilcClientFileName completion,
2034  *                                          void *completion_context,
2035  *                                          void *context);
2036  *
2037  * DESCRIPTION
2038  *
2039  *    File name asking callback, that is called if it is given to the
2040  *    silc_client_file_receive and the path given to that as argument was
2041  *    NULL.  The library calls this to ask the filename and filepath to
2042  *    where the file is to be saved.  The 'remote_filename' is the file
2043  *    that is being downloaded.  Application must call the 'completion'
2044  *    with 'completion_context' to continue with the file downloading.
2045  *    It is not mandatory to provide this to the silc_client_file_receive.
2046  *
2047  ***/
2048 typedef void (*SilcClientFileAskName)(SilcClient client,
2049                                       SilcClientConnection conn,
2050                                       SilcUInt32 session_id,
2051                                       const char *remote_filename,
2052                                       SilcClientFileName completion,
2053                                       void *completion_context,
2054                                       void *context);
2055
2056 /****f* silcclient/SilcClientAPI/silc_client_file_send
2057  *
2058  * SYNOPSIS
2059  *
2060  *    SilcClientFileError
2061  *    silc_client_file_send(SilcClient client,
2062  *                          SilcClientConnection conn,
2063  *                          SilcClientFileMonitor monitor,
2064  *                          void *monitor_context,
2065  *                          const char *local_ip,
2066  *                          SilcUInt32 local_port,
2067  *                          SilcBool do_not_bind,
2068  *                          SilcClientEntry client_entry,
2069  *                          const char *filepath);
2070  *                          SilcUInt32 *session_id);
2071  *
2072  * DESCRIPTION
2073  *
2074  *    Sends a file indicated by the `filepath' to the remote client
2075  *    indicated by the `client_entry'.  This will negotiate a secret key
2076  *    with the remote client before actually starting the transmission of
2077  *    the file.  The `monitor' callback will be called to monitor the
2078  *    transmission of the file.
2079  *
2080  *    This returns a file session ID for the file transmission to the
2081  *    `session_id' pointer.  It can be used to close the session (and
2082  *    abort the file transmission) by calling the silc_client_file_close
2083  *    function.  The session ID is also returned in the `monitor' callback.
2084  *
2085  *    If the `local_ip' is provided then this will try to bind the
2086  *    listener for key exchange protocol to that IP.  If `local_port' is
2087  *    non-zero that port is used.  If `local_ip' is NULL then this will
2088  *    automatically attempt to bind it to local IP address of the machine.
2089  *    If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2090  *    ignored and it is expected that the receiver will provide the
2091  *    point of contact.  This is usefull if the sender is behind NAT.
2092  *
2093  *    If error will occur during the file transfer process the error
2094  *    status will be returned in the monitor callback.  In this case
2095  *    the application must call silc_client_file_close to close the
2096  *    session.
2097  *
2098  ***/
2099 SilcClientFileError
2100 silc_client_file_send(SilcClient client,
2101                       SilcClientConnection conn,
2102                       SilcClientFileMonitor monitor,
2103                       void *monitor_context,
2104                       const char *local_ip,
2105                       SilcUInt32 local_port,
2106                       SilcBool do_not_bind,
2107                       SilcClientEntry client_entry,
2108                       const char *filepath,
2109                       SilcUInt32 *session_id);
2110
2111 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2112  *
2113  * SYNOPSIS
2114  *
2115  *    SilcClientFileError
2116  *    silc_client_file_receive(SilcClient client,
2117  *                             SilcClientConnection conn,
2118  *                             SilcClientFileMonitor monitor,
2119  *                             void *monitor_context,
2120  *                             const char *path,
2121  *                             SilcUInt32 session_id,
2122  *                             SilcClientFileAskName ask_name,
2123  *                             void *ask_name_context);
2124  *
2125  * DESCRIPTION
2126  *
2127  *    Receives a file from a client indicated by the `client_entry'.  The
2128  *    `session_id' indicates the file transmission session and it has been
2129  *    received in the `ftp' client operation function.  This will actually
2130  *    perform the key agreement protocol with the remote client before
2131  *    actually starting the file transmission.  The `monitor' callback
2132  *    will be called to monitor the transmission.  If `path' is non-NULL
2133  *    the file will be saved into that directory.  If NULL the file is
2134  *    saved in the current working directory, unless the 'ask_name'
2135  *    callback is non-NULL.  In this case the callback is called to ask
2136  *    the path and filename from application.
2137  *
2138  *    If error will occur during the file transfer process the error
2139  *    status will be returned in the monitor callback.  In this case
2140  *    the application must call silc_client_file_close to close the
2141  *    session.
2142  *
2143  ***/
2144 SilcClientFileError
2145 silc_client_file_receive(SilcClient client,
2146                          SilcClientConnection conn,
2147                          SilcClientFileMonitor monitor,
2148                          void *monitor_context,
2149                          const char *path,
2150                          SilcUInt32 session_id,
2151                          SilcClientFileAskName ask_name,
2152                          void *ask_name_context);
2153
2154 /****f* silcclient/SilcClientAPI/silc_client_file_close
2155  *
2156  * SYNOPSIS
2157  *
2158  *    SilcClientFileError silc_client_file_close(SilcClient client,
2159  *                                               SilcClientConnection conn,
2160  *                                               SilcUInt32 session_id);
2161  *
2162  * DESCRIPTION
2163  *
2164  *    Closes file transmission session indicated by the `session_id'.
2165  *    If file transmission is being conducted it will be aborted
2166  *    automatically. This function is also used to close the session
2167  *    after successful file transmission. This function can be used
2168  *    also to reject incoming file transmission request.  If the
2169  *    session was already started and the monitor callback was set
2170  *    the monitor callback will be called with the monitor status
2171  *    SILC_CLIENT_FILE_MONITOR_CLOSED.
2172  *
2173  ***/
2174 SilcClientFileError silc_client_file_close(SilcClient client,
2175                                            SilcClientConnection conn,
2176                                            SilcUInt32 session_id);
2177
2178 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2179  *
2180  * SYNOPSIS
2181  *
2182  *    SilcAttributePayload
2183  *    silc_client_attribute_add(SilcClient client,
2184  *                              SilcClientConnection conn,
2185  *                              SilcAttribute attribute,
2186  *                              void *object,
2187  *                              SilcUInt32 object_size);
2188  *
2189  * DESCRIPTION
2190  *
2191  *    Add new Requsted Attribute for WHOIS command to the client library.
2192  *    The `attribute' object indicated by `object' is added and allocated
2193  *    SilcAttributePayload is returned.  The `object' must be of correct
2194  *    type and of correct size.  See the SilcAttribute for object types
2195  *    for different attributes.  You may also get all added attributes
2196  *    from the client with silc_client_attributes_get function.
2197  *
2198  *    Requested Attributes are different personal information about the
2199  *    user, status information and other information which other users
2200  *    may query with WHOIS command.  Application may set these so that
2201  *    if someone sends WHOIS query these attributes will be replied back
2202  *    to the sender.  The library always puts the public key to the
2203  *    Requested Attributes, but if application wishes to add additional
2204  *    public keys (or certificates) it can be done with this interface.
2205  *    Library also always computes digital signature of the attributes
2206  *    automatically, so application does not need to do that.
2207  *
2208  ***/
2209 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2210                                                SilcClientConnection conn,
2211                                                SilcAttribute attribute,
2212                                                void *object,
2213                                                SilcUInt32 object_size);
2214
2215 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2216  *
2217  * SYNOPSIS
2218  *
2219  *    SilcBool silc_client_attribute_del(SilcClient client,
2220  *                                   SilcClientConnection conn,
2221  *                                   SilcAttribute attribute,
2222  *                                   SilcAttributePayload attr);
2223  *
2224  * DESCRIPTION
2225  *
2226  *    Delete a Requested Attribute from the client.  If the `attribute'
2227  *    is non-zero then all attributes of that type are deleted and the
2228  *    `attr' is ignored.  If `attr' is non-NULL then that specific
2229  *    attribute is deleted and `attribute' is ignored.
2230  *
2231  *    You may get all added attributes with the function
2232  *    silc_client_attributes_get and to get the SilcAttributePayload.
2233  *    This function Returns TRUE if the attribute was found and deleted.
2234  *
2235  ***/
2236 SilcBool silc_client_attribute_del(SilcClient client,
2237                                    SilcClientConnection conn,
2238                                    SilcAttribute attribute,
2239                                    SilcAttributePayload attr);
2240
2241 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2242  *
2243  * SYNOPSIS
2244  *
2245  *    const SilcHashTable
2246  *    silc_client_attributes_get(SilcClient client,
2247  *                               SilcClientConnection conn);
2248  *
2249  * DESCRIPTION
2250  *
2251  *    Returns pointer to the SilcHashTable which includes all the added
2252  *    Requested Attributes.  The caller must not free the hash table.
2253  *    The caller may use SilcHashTableList and silc_hash_table_list to
2254  *    traverse the table.  Each entry in the hash table is one added
2255  *    SilcAttributePayload.  It is possible to delete a attribute
2256  *    payload while traversing the table.
2257  *
2258  ***/
2259 SilcHashTable silc_client_attributes_get(SilcClient client,
2260                                          SilcClientConnection conn);
2261
2262 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2263  *
2264  * SYNOPSIS
2265  *
2266  *    SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2267  *
2268  * DESCRIPTION
2269  *
2270  *    Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2271  *    then all attributes are requested.  Alternatively, `attribute' and
2272  *    all variable arguments can each be requested attribute.  In this case
2273  *    the last must be set to zero (0) to complete the variable list of
2274  *    requested attributes.  See SilcAttribute for all attributes.
2275  *    You can give the returned buffer as argument to for example
2276  *    silc_client_get_client_by_id_resolve function.
2277  *
2278  * EXAMPLE
2279  *
2280  *    Request all attributes
2281  *    buffer = silc_client_attributes_request(0);
2282  *
2283  *    Request only the following attributes
2284  *    buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2285  *                                            SILC_ATTRIBUTE_SERVICE,
2286  *                                            SILC_ATTRIBUTE_MOOD, 0);
2287  *
2288  ***/
2289 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2290
2291 #ifdef __cplusplus
2292 }
2293 #endif
2294
2295 #endif /* SILCCLIENT_H */