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