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