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