updates.
[silc.git] / lib / silcclient / silcapi.h
1 /****h* silcclient/silcapi.h
2  *
3  * NAME
4  *
5  * silcapi.h
6  *
7  * COPYRIGHT
8  *
9  * Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
10  *
11  * Copyright (C) 2000 - 2001 Pekka Riikonen
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * DESCRIPTION
24  *
25  * This file defines the SILC Client Library API for the application.  The
26  * client operations are defined first.  These are callback functions that
27  * the application MUST implement since the library may call the functions
28  * at any time.  At the end of file is the API for the application that
29  * it can use from the library.  This is the only file that the application
30  * may include from the SIlC Client Library.
31  *
32  * o SILC Client Operations
33  *
34  *   These functions must be implemented by the application calling the SILC
35  *   client library. The client library can call these functions at any time.
36  *
37  *   To use this structure: define a static SilcClientOperations variable,
38  *   fill it and pass its pointer to silc_client_alloc function.
39  *
40  * o SILC Client Library API
41  *
42  *   This is the API that is published by the SILC Client Library for the
43  *   applications.  These functions are implemented in the SILC Client Library.
44  *   Application may freely call these functions from the library.
45  *
46  * Please, refer to the README file in this directory for the directions
47  * of how to use the SILC Client Library.
48  *
49  ***/
50
51 #ifndef SILCAPI_H
52 #define SILCAPI_H
53
54 #include "clientlibincludes.h"
55
56 /* General definitions */
57
58 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
59  *
60  * NAME
61  *
62  *    typedef enum { ... } SilcKeyAgreementStatus;
63  *
64  * DESCRIPTION
65  *
66  *    Key agreement status types indicating the status of the key
67  *    agreement protocol.  These types are returned to the application 
68  *    in the SilcKeyAgreementCallback callback function.
69  *
70  * SOURCE
71  */
72 typedef enum {
73   SILC_KEY_AGREEMENT_OK,               /* Everything is Ok */
74   SILC_KEY_AGREEMENT_ERROR,            /* Unknown error occurred */
75   SILC_KEY_AGREEMENT_FAILURE,          /* The protocol failed */
76   SILC_KEY_AGREEMENT_TIMEOUT,          /* The protocol timeout */
77 } SilcKeyAgreementStatus;
78 /***/
79
80 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
81  *
82  * SYNOPSIS
83  *
84  *    typedef void (*SilcKeyAgreementCallback)(SilcClient client,
85  *                                             SilcClientConnection conn,
86  *                                             SilcClientEntry client_entry,
87  *                                             SilcKeyAgreementStatus status,
88  *                                             SilcSKEKeyMaterial *key,
89  *                                             void *context);
90  *
91  * DESCRIPTION
92  *
93  *    Key agreement callback that is called after the key agreement protocol
94  *    has been performed. This is called also if error occurred during the
95  *    key agreement protocol. The `key' is the allocated key material and
96  *    the caller is responsible of freeing it. The `key' is NULL if error
97  *    has occurred. The application can freely use the `key' to whatever
98  *    purpose it needs. See lib/silcske/silcske.h for the definition of
99  *    the SilcSKEKeyMaterial structure.
100  *
101  ***/
102 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103                                          SilcClientConnection conn,
104                                          SilcClientEntry client_entry,
105                                          SilcKeyAgreementStatus status,
106                                          SilcSKEKeyMaterial *key,
107                                          void *context);
108
109 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
110  *
111  * NAME
112  *
113  *    typedef struct { ... } SilcPrivateMessageKeys;
114  *
115  * DESCRIPTION
116  *
117  *    Structure to hold the list of private message keys. The array of this
118  *    structure is returned by the silc_client_list_private_message_keys
119  *    function.
120  *
121  * SOURCE
122  */
123 typedef struct {
124   SilcClientEntry client_entry;       /* The remote client entry */
125   char *cipher;                       /* The cipher name */
126   unsigned char *key;                 /* The original key, If the appliation
127                                          provided it. This is NULL if the
128                                          library generated the key or if
129                                          the SKE key material was used. */
130   uint32 key_len;                     /* The key length */
131 } *SilcPrivateMessageKeys;
132 /***/
133
134
135 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
136  *
137  * SYNOPSIS
138  *
139  *    typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
140  *                                      uint32 passphrase_len,
141  *                                      void *context);
142  *
143  * DESCRIPTION
144  *
145  *    Ask passphrase callback. This is called by the application when the
146  *    library calls `ask_passphrase' client operation.  The callback delivers
147  *    the passphrase to the library.
148  *
149  ***/
150 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
151                                   uint32 passphrase_len,
152                                   void *context);
153
154 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
155  *
156  * SYNOPSIS
157  *
158  *    typedef void (*SilcVerifyPublicKey)(bool success, void *context);
159  *
160  * DESCRIPTION
161  *
162  *    Public key (or certificate) verification callback. This is called
163  *    by the application to indicate that the public key verification was
164  *    either success or failure.
165  *
166  ***/
167 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
168
169 /****d* silcclient/SilcClientAPI/SilcClientMessageType
170  *
171  * NAME
172  *
173  *    typedef enum { ... } SilcClientMessageType;
174  *
175  * DESCRIPTION
176  *
177  *    Different message types for `say' client operation.  The application
178  *    may filter the message sent by the library according this type.
179  *
180  * SOURCE
181  */
182 typedef enum {
183   SILC_CLIENT_MESSAGE_INFO,            /* Informational */
184   SILC_CLIENT_MESSAGE_WARNING,         /* Warning */
185   SILC_CLIENT_MESSAGE_ERROR,           /* Error */
186   SILC_CLIENT_MESSAGE_AUDIT,           /* Auditable */
187 } SilcClientMessageType;
188 /***/
189
190 /****s* silcclient/SilcClientAPI/SilcClientOperations
191  *
192  * NAME
193  *
194  *    typedef struct { ... } SilcClientOperations;
195  *
196  * DESCRIPTION
197  *
198  *    SILC Client Operations. These must be implemented by the application.
199  *    The Client library may call any of these routines at any time.  The
200  *    routines are used to deliver certain information to the application
201  *    or from the application to the client library.
202  *
203  * SOURCE
204  */
205 typedef struct {
206   /* Message sent to the application by library. `conn' associates the
207      message to a specific connection.  `conn', however, may be NULL. 
208      The `type' indicates the type of the message sent by the library.
209      The applicationi can for example filter the message according the
210      type. */
211   void (*say)(SilcClient client, SilcClientConnection conn, 
212               SilcClientMessageType type, char *msg, ...);
213
214   /* Message for a channel. The `sender' is the sender of the message 
215      The `channel' is the channel. */
216   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
217                           SilcClientEntry sender, SilcChannelEntry channel, 
218                           SilcMessageFlags flags, char *msg);
219
220   /* Private message to the client. The `sender' is the sender of the
221      message. */
222   void (*private_message)(SilcClient client, SilcClientConnection conn,
223                           SilcClientEntry sender, SilcMessageFlags flags,
224                           char *msg);
225
226   /* Notify message to the client. The notify arguments are sent in the
227      same order as servers sends them. The arguments are same as received
228      from the server except for ID's.  If ID is received application receives
229      the corresponding entry to the ID. For example, if Client ID is received
230      application receives SilcClientEntry.  Also, if the notify type is
231      for channel the channel entry is sent to application (even if server
232      does not send it because client library gets the channel entry from
233      the Channel ID in the packet's header). */
234   void (*notify)(SilcClient client, SilcClientConnection conn, 
235                  SilcNotifyType type, ...);
236
237   /* Command handler. This function is called always in the command function.
238      If error occurs it will be called as well. `conn' is the associated
239      client connection. `cmd_context' is the command context that was
240      originally sent to the command. `success' is FALSE if error occurred
241      during command. `command' is the command being processed. It must be
242      noted that this is not reply from server. This is merely called just
243      after application has called the command. Just to tell application
244      that the command really was processed. */
245   void (*command)(SilcClient client, SilcClientConnection conn, 
246                   SilcClientCommandContext cmd_context, int success,
247                   SilcCommand command);
248
249   /* Command reply handler. This function is called always in the command reply
250      function. If error occurs it will be called as well. Normal scenario
251      is that it will be called after the received command data has been parsed
252      and processed. The function is used to pass the received command data to
253      the application. 
254      
255      `conn' is the associated client connection. `cmd_payload' is the command
256      payload data received from server and it can be ignored. It is provided
257      if the application would like to re-parse the received command data,
258      however, it must be noted that the data is parsed already by the library
259      thus the payload can be ignored. `success' is FALSE if error occurred.
260      In this case arguments are not sent to the application. The `status' is
261      the command reply status server returned. The `command' is the command
262      reply being processed. The function has variable argument list and each
263      command defines the number and type of arguments it passes to the
264      application (on error they are not sent). */
265   void (*command_reply)(SilcClient client, SilcClientConnection conn,
266                         SilcCommandPayload cmd_payload, int success,
267                         SilcCommand command, SilcCommandStatus status, ...);
268
269   /* Called to indicate that connection was either successfully established
270      or connecting failed.  This is also the first time application receives
271      the SilcClientConnection objecet which it should save somewhere.
272      If the `success' is FALSE the application must always call the function
273      silc_client_close_connection. */
274   void (*connect)(SilcClient client, SilcClientConnection conn, int success);
275
276   /* Called to indicate that connection was disconnected to the server. */
277   void (*disconnect)(SilcClient client, SilcClientConnection conn);
278
279   /* Find authentication method and authentication data by hostname and
280      port. The hostname may be IP address as well. The found authentication
281      method and authentication data is returned to `auth_meth', `auth_data'
282      and `auth_data_len'. The function returns TRUE if authentication method
283      is found and FALSE if not. `conn' may be NULL. */
284   int (*get_auth_method)(SilcClient client, SilcClientConnection conn,
285                          char *hostname, uint16 port,
286                          SilcProtocolAuthMeth *auth_meth,
287                          unsigned char **auth_data,
288                          uint32 *auth_data_len);
289
290   /* Verifies received public key. The `conn_type' indicates which entity
291      (server, client etc.) has sent the public key. If user decides to trust
292      the key may be saved as trusted public key for later use. The 
293      `completion' must be called after the public key has been verified. */
294   void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
295                             SilcSocketType conn_type, unsigned char *pk, 
296                             uint32 pk_len, SilcSKEPKType pk_type,
297                             SilcVerifyPublicKey completion, void *context);
298
299   /* Ask (interact, that is) a passphrase from user. The passphrase is
300      returned to the library by calling the `completion' callback with
301      the `context'. */
302   void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
303                          SilcAskPassphrase completion, void *context);
304
305   /* Notifies application that failure packet was received.  This is called
306      if there is some protocol active in the client.  The `protocol' is the
307      protocol context.  The `failure' is opaque pointer to the failure
308      indication.  Note, that the `failure' is protocol dependant and
309      application must explicitly cast it to correct type.  Usually `failure'
310      is 32 bit failure type (see protocol specs for all protocol failure
311      types). */
312   void (*failure)(SilcClient client, SilcClientConnection conn, 
313                   SilcProtocol protocol, void *failure);
314
315   /* Asks whether the user would like to perform the key agreement protocol.
316      This is called after we have received an key agreement packet or an
317      reply to our key agreement packet. This returns TRUE if the user wants
318      the library to perform the key agreement protocol and FALSE if it is not
319      desired (application may start it later by calling the function
320      silc_client_perform_key_agreement). If TRUE is returned also the
321      `completion' and `context' arguments must be set by the application. */
322   int (*key_agreement)(SilcClient client, SilcClientConnection conn,
323                        SilcClientEntry client_entry, char *hostname,
324                        int port,
325                        SilcKeyAgreementCallback *completion,
326                        void **context);
327 } SilcClientOperations;
328 /***/
329
330 /****s* silcclient/SilcClientAPI/SilcClientParams
331  *
332  * NAME
333  *
334  *    typedef struct { ... } SilcClientParams;
335  *
336  * DESCRIPTION
337  *
338  *    Client parameters. This can be filled with proper values and
339  *    given as argument to the silc_client_alloc function. The structure
340  *    hold various parameters which affects the function of the client.
341  *
342  * SOURCE
343  */
344 typedef struct {
345   /* Number of maximum tasks the client library's scheduler can handle.
346      If set to zero, the default value will be used (200). For WIN32
347      systems this should be set to 64 as it is the hard limit dictated
348      by the WIN32. */
349   int task_max;
350
351   /* Rekey timeout in seconds. The client will perform rekey in this
352      time interval. If set to zero, the default value will be used. */
353   unsigned int rekey_secs;
354 } SilcClientParams;
355 /***/
356
357
358 /* Initialization functions (client.c) */
359
360 /****f* silcclient/SilcClientAPI/silc_client_alloc
361  *
362  * SYNOPSIS
363  *
364  *    SilcClient silc_client_alloc(SilcClientOperations *ops, 
365  *                                 SilcClientParams *params,
366  *                                 void *application,
367  *                                 const char *silc_version);
368  *
369  * DESCRIPTION
370  *
371  *    Allocates new client object. This has to be done before client may
372  *    work. After calling this one must call silc_client_init to initialize
373  *    the client. The `application' is application specific user data pointer
374  *    and caller must free it. The `silc_version' is the application version
375  *    that will be used to compare against remote host's (usually a server)
376  *    version string.
377  *
378  ***/
379 SilcClient silc_client_alloc(SilcClientOperations *ops, 
380                              SilcClientParams *params,
381                              void *application,
382                              const char *silc_version);
383
384 /****f* silcclient/SilcClientAPI/silc_client_free
385  *
386  * SYNOPSIS
387  *
388  *    void silc_client_free(SilcClient client);
389  *
390  * DESCRIPTION
391  *
392  *    Frees client object and its internals.  The execution of the client
393  *    should be stopped with silc_client_stop function before calling
394  *    this function.
395  *
396  ***/
397 void silc_client_free(SilcClient client);
398
399 /****f* silcclient/SilcClientAPI/silc_client_init
400  *
401  * SYNOPSIS
402  *
403  *    int silc_client_init(SilcClient client);
404  *
405  * DESCRIPTION
406  *
407  *    Initializes the client. This makes all the necessary steps to make
408  *    the client ready to be run. One must call silc_client_run to run the
409  *    client. Returns FALSE if error occurred, TRUE otherwise.
410  *
411  ***/
412 int silc_client_init(SilcClient client);
413
414 /****f* silcclient/SilcClientAPI/silc_client_run
415  *
416  * SYNOPSIS
417  *
418  *    void silc_client_run(SilcClient client);
419  *
420  * DESCRIPTION
421  *
422  *    Runs the client. This starts the scheduler from the utility library.
423  *    When this functions returns the execution of the appliation is over.
424  *
425  ***/
426 void silc_client_run(SilcClient client);
427
428 /****f* silcclient/SilcClientAPI/silc_client_stop
429  *
430  * SYNOPSIS
431  *
432  *    void silc_client_stop(SilcClient client);
433  *
434  * DESCRIPTION
435  *
436  *    Stops the client. This is called to stop the client and thus to stop
437  *    the program.  The client context must be freed with the silc_client_free
438  *    function.
439  *
440  ***/
441 void silc_client_stop(SilcClient client);
442
443
444 /* Connecting functions (client.c) */
445
446 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
447  *
448  * SYNOPSIS
449  *
450  *    int silc_client_connect_to_server(SilcClient client, int port,
451  *                                      char *host, void *context);
452  *
453  * DESCRIPTION
454  *
455  *    Connects to remote server. This is the main routine used to connect
456  *    to SILC server. Returns -1 on error and the created socket otherwise. 
457  *    The `context' is user context that is saved into the SilcClientConnection
458  *    that is created after the connection is created. Note that application
459  *    may handle the connecting process outside the library. If this is the
460  *    case then this function is not used at all. When the connecting is
461  *    done the `connect' client operation is called.
462  *
463  ***/
464 int silc_client_connect_to_server(SilcClient client, int port,
465                                   char *host, void *context);
466
467 /****f* silcclient/SilcClientAPI/silc_client_add_connection
468  *
469  * SYNOPSIS
470  *
471  *    SilcClientConnection silc_client_add_connection(SilcClient client,
472  *                                                    char *hostname,
473  *                                                    int port,
474  *                                                    void *context);
475  *
476  * DESCRIPTION
477  *
478  *    Allocates and adds new connection to the client. This adds the allocated
479  *    connection to the connection table and returns a pointer to it. A client
480  *    can have multiple connections to multiple servers. Every connection must
481  *    be added to the client using this function. User data `context' may
482  *    be sent as argument. This function is normally used only if the 
483  *    application performed the connecting outside the library. The library
484  *    however may use this internally.
485  *
486  ***/
487 SilcClientConnection silc_client_add_connection(SilcClient client,
488                                                 char *hostname,
489                                                 int port,
490                                                 void *context);
491
492 /****f* silcclient/SilcClientAPI/silc_client_del_connection
493  *
494  * SYNOPSIS
495  *
496  *    void silc_client_del_connection(SilcClient client, 
497  *                                    SilcClientConnection conn);
498  *
499  * DESCRIPTION
500  *
501  *    Removes connection from client. Frees all memory. The library
502  *    call this function automatically for all connection contexts.
503  *    The application however may free the connection contexts it has
504  *    allocated.
505  *
506  ***/
507 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
508
509 /****f* silcclient/SilcClientAPI/silc_client_add_socket
510  *
511  * SYNOPSIS
512  *
513  *    void silc_client_add_socket(SilcClient client, 
514  *                                SilcSocketConnection sock);
515  *
516  * DESCRIPTION
517  *
518  *    Adds listener socket to the listener sockets table. This function is
519  *    used to add socket objects that are listeners to the client.  This should
520  *    not be used to add other connection objects.
521  *
522  ***/
523 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
524
525 /****f* silcclient/SilcClientAPI/silc_client_del_socket
526  *
527  * SYNOPSIS
528  *
529  *    void silc_client_del_socket(SilcClient client, 
530  *                                SilcSocketConnection sock);
531  *
532  * DESCRIPTION
533  *
534  *    Deletes listener socket from the listener sockets table.  If the
535  *    application has added a socket with silc_client_add_socket it must
536  *    also free it using this function.
537  *
538  ***/
539 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
540
541 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
542  *
543  * SYNOPSIS
544  *
545  *    int silc_client_start_key_exchange(SilcClient client,
546  *                                       SilcClientConnection conn,
547  *                                       int fd);
548  *
549  * DESCRIPTION
550  *
551  *    Start SILC Key Exchange (SKE) protocol to negotiate shared secret
552  *    key material between client and server.  This function can be called
553  *    directly if application is performing its own connecting and does not
554  *    use the connecting provided by this library. This function is normally
555  *    used only if the application performed the connecting outside the
556  *    library. The library however may use this internally.
557  *
558  ***/
559 int silc_client_start_key_exchange(SilcClient client,
560                                    SilcClientConnection conn,
561                                    int fd);
562
563 /****f* silcclient/SilcClientAPI/silc_client_close_connection
564  *
565  * SYNOPSIS
566  *
567  *    void silc_client_close_connection(SilcClient client,
568  *                                      SilcSocketConnection sock,
569  *                                      SilcClientConnection conn);
570  *
571  * DESCRIPTION
572  *
573  *    Closes connection to remote end. Free's all allocated data except
574  *    for some information such as nickname etc. that are valid at all time. 
575  *    If the `sock' is NULL then the conn->sock will be used.  If `sock' is
576  *    provided it will be checked whether the sock and `conn->sock' are the
577  *    same (they can be different, ie. a socket can use `conn' as its
578  *    connection but `conn->sock' might be actually a different connection
579  *    than the `sock'). 
580  *
581  ***/
582 void silc_client_close_connection(SilcClient client,
583                                   SilcSocketConnection sock,
584                                   SilcClientConnection conn);
585
586
587 /* Message sending functions (client_channel.c and client_prvmsg.c) */
588
589 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
590  *
591  * SYNOPSIS
592  *
593  *    void silc_client_send_channel_message(SilcClient client, 
594  *                                          SilcClientConnection conn,
595  *                                          SilcChannelEntry channel,
596  *                                          SilcChannelPrivateKey key,
597  *                                          SilcMessageFlags flags,
598  *                                          unsigned char *data, 
599  *                                          uint32 data_len, 
600  *                                          int force_send);
601  *
602  * DESCRIPTION
603  *
604  *    Sends packet to the `channel'. Packet to channel is always encrypted
605  *    differently from "normal" packets. SILC header of the packet is 
606  *    encrypted with the next receiver's key and the rest of the packet is
607  *    encrypted with the channel specific key. Padding and HMAC is computed
608  *    with the next receiver's key. The `data' is the channel message. If
609  *    the `force_send' is TRUE then the packet is sent immediately. 
610  *
611  *    If `key' is provided then that private key is used to encrypt the
612  *    channel message.  If it is not provided, private keys has not been
613  *    set at all, the normal channel key is used automatically.  If private
614  *    keys are set then the first key (the key that was added first as
615  *    private key) is used. 
616  *
617  ***/
618 void silc_client_send_channel_message(SilcClient client, 
619                                       SilcClientConnection conn,
620                                       SilcChannelEntry channel,
621                                       SilcChannelPrivateKey key,
622                                       SilcMessageFlags flags,
623                                       unsigned char *data, 
624                                       uint32 data_len, 
625                                       int force_send);
626
627 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
628  *
629  * SYNOPSIS
630  *
631  *    void silc_client_send_private_message(SilcClient client,
632  *                                          SilcClientConnection conn,
633  *                                          SilcClientEntry client_entry,
634  *                                          SilcMessageFlags flags,
635  *                                          unsigned char *data, 
636  *                                          uint32 data_len, 
637  *                                          int force_send);
638  *
639  * DESCRIPTION
640  *
641  *    Sends private message to remote client. If private message key has
642  *    not been set with this client then the message will be encrypted using
643  *    normal session keys. Private messages are special packets in SILC
644  *    network hence we need this own function for them. This is similar
645  *    to silc_client_packet_send_to_channel except that we send private
646  *    message. The `data' is the private message. If the `force_send' is
647  *    TRUE the packet is sent immediately. 
648  *
649  ***/
650 void silc_client_send_private_message(SilcClient client,
651                                       SilcClientConnection conn,
652                                       SilcClientEntry client_entry,
653                                       SilcMessageFlags flags,
654                                       unsigned char *data, 
655                                       uint32 data_len, 
656                                       int force_send);
657
658
659 /* Client and Channel entry retrieval (idlist.c) */
660
661 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
662  *
663  * SYNOPSIS
664  *
665  *    typedef void (*SilcGetClientCallback)(SilcClient client,
666  *                                          SilcClientConnection conn,
667  *                                          SilcClientEntry *clients,
668  *                                          uint32 clients_count,
669  *                                          void *context);
670  *
671  * DESCRIPTION
672  *
673  *    Callback function given to the silc_client_get_client function. The
674  *    found entries are allocated into the `clients' array. The array must
675  *    not be freed by the receiver, the library will free it later. If the
676  *    `clients' is NULL, no such clients exist in the SILC Network.
677  *
678  ***/
679 typedef void (*SilcGetClientCallback)(SilcClient client,
680                                       SilcClientConnection conn,
681                                       SilcClientEntry *clients,
682                                       uint32 clients_count,
683                                       void *context);
684
685 /****f* silcclient/SilcClientAPI/silc_client_get_clients
686  *
687  * SYNOPSIS
688  *
689  *    void silc_client_get_clients(SilcClient client,
690  *                                 SilcClientConnection conn,
691  *                                 char *nickname,
692  *                                 char *server,
693  *                                 SilcGetClientCallback completion,
694  *                                 void *context);
695  *
696  * DESCRIPTION
697  *
698  *    Finds client entry or entries by the `nickname' and `server'. The 
699  *    completion callback will be called when the client entries has been
700  *    found.
701  *
702  * NOTES
703  *
704  *    NOTE: This function is always asynchronous and resolves the client
705  *    information from the server. Thus, if you already know the client
706  *    information then use the silc_client_get_client_by_id function to
707  *    get the client entry since this function may be very slow and should
708  *    be used only to initially get the client entries. 
709  *
710  ***/
711 void silc_client_get_clients(SilcClient client,
712                              SilcClientConnection conn,
713                              char *nickname,
714                              char *server,
715                              SilcGetClientCallback completion,
716                              void *context);
717
718 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
719  *
720  * SYNOPSIS
721  *
722  *    SilcClientEntry *silc_client_get_clients_local(SilcClient client,
723  *                                                   SilcClientConnection conn,
724  *                                                   char *nickname,
725  *                                                   char *server,
726  *                                                   uint32 *clients_count);
727  *
728  * DESCRIPTION
729  *
730  *    Same as silc_client_get_clients function but does not resolve anything
731  *    from the server.  This checks local cache and returns all clients from
732  *    the local cache. 
733  *
734  ***/
735 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
736                                                SilcClientConnection conn,
737                                                char *nickname,
738                                                char *server,
739                                                uint32 *clients_count);
740
741 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
742  *
743  * SYNOPSIS
744  *
745  *    void silc_client_get_clients_by_list(SilcClient client,
746  *                                         SilcClientConnection conn,
747  *                                         uint32 list_count,
748  *                                         SilcBuffer client_id_list,
749  *                                         SilcGetClientCallback completion,
750  *                                         void *context);
751  *
752  * DESCRIPTION
753  *
754  *    Gets client entries by the list of client ID's `client_id_list'. This
755  *    always resolves those client ID's it does not know yet from the server
756  *    so this function might take a while. The `client_id_list' is a list
757  *    of ID Payloads added one after other.  JOIN command reply and USERS
758  *    command reply for example returns this sort of list. The `completion'
759  *    will be called after the entries are available. 
760  *
761  ***/
762 void silc_client_get_clients_by_list(SilcClient client,
763                                      SilcClientConnection conn,
764                                      uint32 list_count,
765                                      SilcBuffer client_id_list,
766                                      SilcGetClientCallback completion,
767                                      void *context);
768
769 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
770  *
771  * SYNOPSIS
772  *
773  *    SilcClientEntry silc_client_get_client_by_id(SilcClient client,
774  *                                                 SilcClientConnection conn,
775  *                                                 SilcClientID *client_id);
776  *
777  * DESCRIPTION
778  *
779  *    Find entry for client by the client's ID. Returns the entry or NULL
780  *    if the entry was not found. 
781  *
782  ***/
783 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
784                                              SilcClientConnection conn,
785                                              SilcClientID *client_id);
786
787 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
788  *
789  * SYNOPSIS
790  *
791  *    void 
792  *    silc_client_get_client_by_id_resolve(SilcClient client,
793  *                                         SilcClientConnection conn,
794  *                                         SilcClientID *client_id,
795  *                                         SilcGetClientCallback completion,
796  *                                         void *context);
797  *
798  * DESCRIPTION
799  *
800  *    Same as silc_client_get_client_by_id but will always resolve the
801  *    information from the server. Use this only if you know that you
802  *    do not have the entry and the only thing you know about the client
803  *    is its ID. 
804  *
805  ***/
806 void silc_client_get_client_by_id_resolve(SilcClient client,
807                                           SilcClientConnection conn,
808                                           SilcClientID *client_id,
809                                           SilcGetClientCallback completion,
810                                           void *context);
811
812 /****f* silcclient/SilcClientAPI/silc_client_del_client
813  *
814  * SYNOPSIS
815  *
816  *    bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
817  *                                SilcClientEntry client_entry)
818  *
819  * DESCRIPTION
820  *
821  *    Removes client from local cache by the client entry indicated by
822  *    the `client_entry'.  Returns TRUE if the deletion were successful.
823  *
824  ***/
825 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
826                             SilcClientEntry client_entry);
827
828 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
829  *
830  * SYNOPSIS
831  *
832  *    typedef void (*SilcGetClientCallback)(SilcClient client,
833  *                                          SilcClientConnection conn,
834  *                                          SilcClientEntry *clients,
835  *                                          uint32 clients_count,
836  *                                          void *context);
837  *
838  * DESCRIPTION
839  *
840  *    Callback function given to the silc_client_get_channel_* functions.
841  *    The found entries are allocated into the `channels' array. The array
842  *    must not be freed by the receiver, the library will free it later.
843  *    If the `channel' is NULL, no such channel exist in the SILC Network.
844  *
845  ***/
846 typedef void (*SilcGetChannelCallback)(SilcClient client,
847                                        SilcClientConnection conn,
848                                        SilcChannelEntry *channels,
849                                        uint32 channels_count,
850                                        void *context);
851
852 /****f* silcclient/SilcClientAPI/silc_client_get_channel
853  *
854  * SYNOPSIS
855  *
856  *    SilcChannelEntry silc_client_get_channel(SilcClient client,
857  *                                             SilcClientConnection conn,
858  *                                             char *channel);
859  *
860  * DESCRIPTION
861  *
862  *    Finds entry for channel by the channel name. Returns the entry or NULL
863  *    if the entry was not found. It is found only if the client is joined
864  *    to the channel. 
865  *
866  ***/
867 SilcChannelEntry silc_client_get_channel(SilcClient client,
868                                          SilcClientConnection conn,
869                                          char *channel);
870
871 /****f* silcclient/SilcClientAPI/silc_client_get_channel
872  *
873  * SYNOPSIS
874  *
875  *    void 
876  *    silc_client_get_channel_by_id_resolve(SilcClient client,
877  *                                          SilcClientConnection conn,
878  *                                          SilcChannelID *channel_id,
879  *                                          SilcGetClientCallback completion,
880  *                                          void *context);
881  *
882  * DESCRIPTION
883  *
884  *    Finds channel entry by the channel name. Returns the entry or NULL
885  *    if it was not found.
886  *
887  ***/
888 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
889                                                SilcClientConnection conn,
890                                                SilcChannelID *channel_id);
891
892 /****f* silcclient/SilcClientAPI/silc_client_get_channel
893  *
894  * SYNOPSIS
895  *
896  *    void 
897  *    silc_client_get_channel_by_id_resolve(SilcClient client,
898  *                                          SilcClientConnection conn,
899  *                                          SilcChannelID *channel_id,
900  *                                          SilcGetClientCallback completion,
901  *                                          void *context);
902  *
903  * DESCRIPTION
904  *
905  *    Resolves the channel information (its name mainly) from the server
906  *    by the `channel_id'. Use this only if you know that you do not have
907  *    the entry cached locally.
908  *
909  ***/
910 void silc_client_get_channel_by_id_resolve(SilcClient client,
911                                            SilcClientConnection conn,
912                                            SilcChannelID *channel_id,
913                                            SilcGetChannelCallback completion,
914                                            void *context);
915
916 /****f* silcclient/SilcClientAPI/silc_client_del_channel
917  *
918  * SYNOPSIS
919  *
920  *    bool silc_client_del_channel(SilcClient client, 
921  *                                 SilcClientConnection conn,
922  *                                 SilcChannelEntry channel)
923  *
924  * DESCRIPTION
925  *
926  *    Removes channel from local cache by the channel entry indicated by
927  *    the `channel'.  Returns TRUE if the deletion were successful.
928  *
929  ***/
930 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
931                              SilcChannelEntry channel);
932
933 /****f* silcclient/SilcClientAPI/silc_client_get_server
934  *
935  * SYNOPSIS
936  *
937  *    SilcServerEntry silc_client_get_server(SilcClient client,
938  *                                           SilcClientConnection conn,
939  *                                           char *server_name)
940  *
941  * DESCRIPTION
942  *
943  *    Finds entry for server by the server name. Returns the entry or NULL
944  *    if the entry was not found.
945  *
946  ***/
947 SilcServerEntry silc_client_get_server(SilcClient client,
948                                        SilcClientConnection conn,
949                                        char *server_name);
950
951 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
952  *
953  * SYNOPSIS
954  *
955  *    SilcServerEntry silc_client_get_server_by_id(SilcClient client,
956  *                                                 SilcClientConnection conn,
957  *                                                 SilcServerID *server_id);
958  *
959  * DESCRIPTION
960  *
961  *    Finds entry for server by the server ID. Returns the entry or NULL
962  *    if the entry was not found.
963  *
964  ***/
965 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
966                                              SilcClientConnection conn,
967                                              SilcServerID *server_id);
968
969 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
970  *
971  * SYNOPSIS
972  *
973  *    bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
974  *                                SilcServerEntry server);
975  *
976  * DESCRIPTION
977  *
978  *    Removes server from local cache by the server entry indicated by
979  *    the `server'.  Returns TRUE if the deletion were successful.
980  *
981  ***/
982 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
983                             SilcServerEntry server);
984
985 /* Command management (command.c) */
986
987 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
988  *
989  * SYNOPSIS
990  *
991  *    SilcClientCommandContext silc_client_command_alloc();
992  *
993  * DESCRIPTION
994  *
995  *    Allocate Command Context. The context is defined in `command.h' file.
996  *    The context is used by the library commands and applications should use
997  *    it as well. However, application may choose to use some own context
998  *    for its local commands. All library commands, however, must use this
999  *    context. 
1000  *
1001  ***/
1002 SilcClientCommandContext silc_client_command_alloc();
1003
1004 /****f* silcclient/SilcClientAPI/silc_client_command_free
1005  *
1006  * SYNOPSIS
1007  *
1008  *    void silc_client_command_free(SilcClientCommandContext ctx);
1009  *
1010  * DESCRIPTION
1011  *
1012  *    Free command context and its internals.  If the contex was duplicated
1013  *    with silc_client_command_dup this may not actually free the data, 
1014  *    instead it will decrease the reference counter of the context.  The
1015  *    context will be freed when the reference counter hits zero.
1016  *
1017  ***/
1018 void silc_client_command_free(SilcClientCommandContext ctx);
1019
1020 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1021  *
1022  * SYNOPSIS
1023  *
1024  *    SilcClientCommandContext 
1025  *    silc_client_command_dup(SilcClientCommandContext ctx);
1026  *
1027  * DESCRIPTION
1028  *
1029  *    Duplicate Command Context by adding reference counter. The context won't
1030  *    be free'd untill it hits zero. 
1031  *
1032  ***/
1033 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1034
1035 /****f* silcclient/SilcClientAPI/silc_client_command_find
1036  *
1037  * SYNOPSIS
1038  *
1039  *    SilcClientCommand *silc_client_command_find(const char *name);
1040  *
1041  * DESCRIPTION
1042  *
1043  *    Finds and returns a pointer to the command list. Return NULL if the
1044  *    command is not found. See the `command.[ch]' for the command list. 
1045  *
1046  ***/
1047 SilcClientCommand *silc_client_command_find(const char *name);
1048
1049 /****f* silcclient/SilcClientAPI/silc_client_send_command
1050  *
1051  * SYNOPSIS
1052  *
1053  *    void silc_client_send_command(SilcClient client, 
1054  *                                  SilcClientConnection conn,
1055  *                                  SilcCommand command, uint16 ident,
1056  *                                  uint32 argc, ...);
1057  *
1058  * DESCRIPTION
1059  *
1060  *    Generic function to send any command. The arguments must be sent already
1061  *    encoded into correct form and in correct order. 
1062  *
1063  ***/
1064 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
1065                               SilcCommand command, uint16 ident,
1066                               uint32 argc, ...);
1067
1068 /****f* silcclient/SilcClientAPI/SilcClientPendingDestructor
1069  *
1070  * SYNOPSIS
1071  *
1072  *    typedef void (*SilcClientPendingDestructor)(void *context);
1073  *
1074  * DESCRIPTION
1075  *
1076  *    Pending Command callback destructor. This is called after calling the
1077  *    pending callback or if error occurs while processing the pending command.
1078  *    If error occurs then the callback won't be called at all, and only this
1079  *    destructor is called. The `context' is the context given for the function
1080  *    silc_client_command_pending. 
1081  *
1082  ***/
1083 typedef void (*SilcClientPendingDestructor)(void *context);
1084
1085 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1086  *
1087  * SYNOPSIS
1088  *
1089  *    void silc_client_command_pending(SilcClientConnection conn,
1090  *                                     SilcCommand reply_cmd,
1091  *                                     uint16 ident,
1092  *                                     SilcClientPendingDestructor destructor,
1093  *                                     SilcCommandCb callback,
1094  *                                     void *context);
1095  *
1096  * DESCRIPTION
1097  *
1098  *    Add new pending command to be executed when reply to a command has been
1099  *    received.  The `reply_cmd' is the command that will call the `callback'
1100  *    with `context' when reply has been received.  If `ident is non-zero
1101  *    the `callback' will be executed when received reply with command 
1102  *    identifier `ident'. 
1103  *
1104  ***/
1105 void silc_client_command_pending(SilcClientConnection conn,
1106                                  SilcCommand reply_cmd,
1107                                  uint16 ident,
1108                                  SilcClientPendingDestructor destructor,
1109                                  SilcCommandCb callback,
1110                                  void *context);
1111
1112
1113 /* Private Message key management (client_prvmsg.c) */
1114
1115 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1116  *
1117  * SYNOPSIS
1118  *
1119  *    int silc_client_add_private_message_key(SilcClient client,
1120  *                                            SilcClientConnection conn,
1121  *                                            SilcClientEntry client_entry,
1122  *                                            char *cipher,
1123  *                                            unsigned char *key,
1124  *                                            uint32 key_len,
1125  *                                            bool generate_key,
1126  *                                            bool responder);
1127  *
1128  * DESCRIPTION
1129  *
1130  *    Adds private message key to the client library. The key will be used to
1131  *    encrypt all private message between the client and the remote client
1132  *    indicated by the `client_entry'. If the `key' is NULL and the boolean
1133  *    value `generate_key' is TRUE the library will generate random key.
1134  *    The `key' maybe for example pre-shared-key, passphrase or similar.
1135  *    The `cipher' MAY be provided but SHOULD be NULL to assure that the
1136  *    requirements of the SILC protocol are met. The API, however, allows
1137  *    to allocate any cipher.
1138  *
1139  *    If `responder' is TRUE then the sending and receiving keys will be
1140  *    set according the client being the receiver of the private key.  If
1141  *    FALSE the client is being the sender (or negotiator) of the private
1142  *    key.
1143  *
1144  *    It is not necessary to set key for normal private message usage. If the
1145  *    key is not set then the private messages are encrypted using normal
1146  *    session keys. Setting the private key, however, increases the security. 
1147  *
1148  *    Returns FALSE if the key is already set for the `client_entry', TRUE
1149  *    otherwise. 
1150  *
1151  ***/
1152 int silc_client_add_private_message_key(SilcClient client,
1153                                         SilcClientConnection conn,
1154                                         SilcClientEntry client_entry,
1155                                         char *cipher,
1156                                         unsigned char *key,
1157                                         uint32 key_len,
1158                                         bool generate_key,
1159                                         bool responder);
1160
1161 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1162  *
1163  * SYNOPSIS
1164  *
1165  *    int silc_client_add_private_message_key_ske(SilcClient client,
1166  *                                                SilcClientConnection conn,
1167  *                                                SilcClientEntry client_entry,
1168  *                                                char *cipher,
1169  *                                                SilcSKEKeyMaterial *key);
1170  *
1171  * DESCRIPTION
1172  *
1173  *    Same as silc_client_add_private_message_key but takes the key material
1174  *    from the SKE key material structure. This structure is received if
1175  *    the application uses the silc_client_send_key_agreement to negotiate
1176  *    the key material. The `cipher' SHOULD be provided as it is negotiated
1177  *    also in the SKE protocol. 
1178  *
1179  ***/
1180 int silc_client_add_private_message_key_ske(SilcClient client,
1181                                             SilcClientConnection conn,
1182                                             SilcClientEntry client_entry,
1183                                             char *cipher,
1184                                             SilcSKEKeyMaterial *key,
1185                                             bool responder);
1186
1187 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1188  *
1189  * SYNOPSIS
1190  *
1191  *    int silc_client_send_private_message_key(SilcClient client,
1192  *                                             SilcClientConnection conn,
1193  *                                             SilcClientEntry client_entry,
1194  *                                             int force_send);
1195  *
1196  * DESCRIPTION
1197  *
1198  *    Sends private message key payload to the remote client indicated by
1199  *    the `client_entry'. If the `force_send' is TRUE the packet is sent
1200  *    immediately. Returns FALSE if error occurs, TRUE otherwise. The
1201  *    application should call this function after setting the key to the
1202  *    client.
1203  *
1204  *    Note that the key sent using this function is sent to the remote client
1205  *    through the SILC network. The packet is protected using normal session
1206  *    keys. 
1207  *
1208  ***/
1209 int silc_client_send_private_message_key(SilcClient client,
1210                                          SilcClientConnection conn,
1211                                          SilcClientEntry client_entry,
1212                                          int force_send);
1213
1214 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1215  *
1216  * SYNOPSIS
1217  *
1218  *    int silc_client_del_private_message_key(SilcClient client,
1219  *                                            SilcClientConnection conn,
1220  *                                            SilcClientEntry client_entry);
1221  *
1222  * DESCRIPTION
1223  *
1224  *    Removes the private message from the library. The key won't be used
1225  *    after this to protect the private messages with the remote `client_entry'
1226  *    client. Returns FALSE on error, TRUE otherwise. 
1227  *
1228  ***/
1229 int silc_client_del_private_message_key(SilcClient client,
1230                                         SilcClientConnection conn,
1231                                         SilcClientEntry client_entry);
1232
1233 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1234  *
1235  * SYNOPSIS
1236  *
1237  *    SilcPrivateMessageKeys
1238  *    silc_client_list_private_message_keys(SilcClient client,
1239  *                                          SilcClientConnection conn,
1240  *                                          uint32 *key_count);
1241  * 
1242  * DESCRIPTION
1243  *
1244  *    Returns array of set private message keys associated to the connection
1245  *    `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1246  *    count to the `key_count' argument. The array must be freed by the caller
1247  *    by calling the silc_client_free_private_message_keys function. Note: 
1248  *    the keys returned in the array is in raw format. It might not be desired
1249  *    to show the keys as is. The application might choose not to show the keys
1250  *    at all or to show the fingerprints of the keys. 
1251  *
1252  ***/
1253 SilcPrivateMessageKeys
1254 silc_client_list_private_message_keys(SilcClient client,
1255                                       SilcClientConnection conn,
1256                                       uint32 *key_count);
1257
1258 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1259  *
1260  * SYNOPSIS
1261  *
1262  *    void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1263  *                                               uint32 key_count);
1264  * 
1265  * DESCRIPTION
1266  *
1267  *    Frees the SilcPrivateMessageKeys array returned by the function
1268  *    silc_client_list_private_message_keys. 
1269  *
1270  ***/
1271 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1272                                            uint32 key_count);
1273
1274
1275 /* Channel private key management (client_channel.c, 
1276    SilcChannelPrivateKey is defined in idlist.h) */
1277
1278 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1279  *
1280  * SYNOPSIS
1281  *
1282  *    int silc_client_add_channel_private_key(SilcClient client,
1283  *                                            SilcClientConnection conn,
1284  *                                            SilcChannelEntry channel,
1285  *                                            char *cipher,
1286  *                                            char *hmac,
1287  *                                            unsigned char *key,
1288  *                                            uint32 key_len);
1289  * 
1290  * DESCRIPTION
1291  *
1292  *    Adds private key for channel. This may be set only if the channel's mode
1293  *    mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1294  *    mode is not set. When channel has private key then the messages are
1295  *    encrypted using that key. All clients on the channel must also know the
1296  *    key in order to decrypt the messages. However, it is possible to have
1297  *    several private keys per one channel. In this case only some of the
1298  *    clients on the channel may know the one key and only some the other key.
1299  *
1300  *    The private key for channel is optional. If it is not set then the
1301  *    channel messages are encrypted using the channel key generated by the
1302  *    server. However, setting the private key (or keys) for the channel 
1303  *    significantly adds security. If more than one key is set the library
1304  *    will automatically try all keys at the message decryption phase. Note:
1305  *    setting many keys slows down the decryption phase as all keys has to
1306  *    be tried in order to find the correct decryption key. However, setting
1307  *    a few keys does not have big impact to the decryption performace. 
1308  *
1309  * NOTES
1310  *
1311  *    NOTE: This is entirely local setting. The key set using this function
1312  *    is not sent to the network at any phase.
1313  *
1314  *    NOTE: If the key material was originated by the SKE protocol (using
1315  *    silc_client_send_key_agreement) then the `key' MUST be the
1316  *    key->send_enc_key as this is dictated by the SILC protocol. However,
1317  *    currently it is not expected that the SKE key material would be used
1318  *    as channel private key. However, this API allows it. 
1319  *
1320  ***/
1321 int silc_client_add_channel_private_key(SilcClient client,
1322                                         SilcClientConnection conn,
1323                                         SilcChannelEntry channel,
1324                                         char *cipher,
1325                                         char *hmac,
1326                                         unsigned char *key,
1327                                         uint32 key_len);
1328
1329 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1330  *
1331  * SYNOPSIS
1332  *
1333  *    int silc_client_del_channel_private_keys(SilcClient client,
1334  *                                             SilcClientConnection conn,
1335  *                                             SilcChannelEntry channel);
1336  * 
1337  * DESCRIPTION
1338  *
1339  *    Removes all private keys from the `channel'. The old channel key is used
1340  *    after calling this to protect the channel messages. Returns FALSE on
1341  *    on error, TRUE otherwise. 
1342  *
1343  ***/
1344 int silc_client_del_channel_private_keys(SilcClient client,
1345                                          SilcClientConnection conn,
1346                                          SilcChannelEntry channel);
1347
1348 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1349  *
1350  * SYNOPSIS
1351  *
1352  *    int silc_client_del_channel_private_key(SilcClient client,
1353  *                                            SilcClientConnection conn,
1354  *                                            SilcChannelEntry channel,
1355  *                                            SilcChannelPrivateKey key);
1356  * 
1357  * DESCRIPTION
1358  *
1359  *    Removes and frees private key `key' from the channel `channel'. 
1360  *    The `key' is retrieved by calling the function 
1361  *    silc_client_list_channel_private_keys. The key is not used after
1362  *    this. If the key was last private key then the old channel key is
1363  *    used hereafter to protect the channel messages. This returns FALSE
1364  *    on error, TRUE otherwise. 
1365  *
1366  ***/
1367 int silc_client_del_channel_private_key(SilcClient client,
1368                                         SilcClientConnection conn,
1369                                         SilcChannelEntry channel,
1370                                         SilcChannelPrivateKey key);
1371
1372 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1373  *
1374  * SYNOPSIS
1375  *
1376  *    SilcChannelPrivateKey *
1377  *    silc_client_list_channel_private_keys(SilcClient client,
1378  *                                          SilcClientConnection conn,
1379  *                                          SilcChannelEntry channel,
1380  *                                          uint32 *key_count);
1381  *
1382  * DESCRIPTION
1383  *
1384  *    Returns array (pointers) of private keys associated to the `channel'.
1385  *    The caller must free the array by calling the function
1386  *    silc_client_free_channel_private_keys. The pointers in the array may be
1387  *    used to delete the specific key by giving the pointer as argument to the
1388  *    function silc_client_del_channel_private_key. 
1389  *
1390  ***/
1391 SilcChannelPrivateKey *
1392 silc_client_list_channel_private_keys(SilcClient client,
1393                                       SilcClientConnection conn,
1394                                       SilcChannelEntry channel,
1395                                       uint32 *key_count);
1396
1397 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1398  *
1399  * SYNOPSIS
1400  *
1401  *    void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1402  *                                               uint32 key_count);
1403  *
1404  * DESCRIPTION
1405  *
1406  *    Frees the SilcChannelPrivateKey array.
1407  *
1408  ***/
1409 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1410                                            uint32 key_count);
1411
1412
1413 /* Key Agreement routines (client_keyagr.c) */
1414
1415 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1416  *
1417  * SYNOPSIS
1418  *
1419  *    void silc_client_send_key_agreement(SilcClient client,
1420  *                                        SilcClientConnection conn,
1421  *                                        SilcClientEntry client_entry,
1422  *                                        char *hostname,
1423  *                                        int port,
1424  *                                        uint32 timeout_secs,
1425  *                                        SilcKeyAgreementCallback completion,
1426  *                                        void *context);
1427  *
1428  * DESCRIPTION
1429  *
1430  *    Sends key agreement request to the remote client indicated by the
1431  *    `client_entry'. If the caller provides the `hostname' and the `port'
1432  *    arguments then the library will bind the client to that hostname and
1433  *    that port for the key agreement protocol. It also sends the `hostname'
1434  *    and the `port' in the key agreement packet to the remote client. This
1435  *    would indicate that the remote client may initiate the key agreement
1436  *    protocol to the `hostname' on the `port'.  If port is zero then the
1437  *    bound port is undefined (the operating system defines it).
1438  *
1439  *    If the `hostname' and `port' is not provided then empty key agreement
1440  *    packet is sent to the remote client. The remote client may reply with
1441  *    the same packet including its hostname and port. If the library receives
1442  *    the reply from the remote client the `key_agreement' client operation
1443  *    callback will be called to verify whether the user wants to perform the
1444  *    key agreement or not. 
1445  *
1446  * NOTES
1447  *
1448  *    NOTE: If the application provided the `hostname' and the `port' and the 
1449  *    remote side initiates the key agreement protocol it is not verified
1450  *    from the user anymore whether the protocol should be executed or not.
1451  *    By setting the `hostname' and `port' the user gives permission to
1452  *    perform the protocol (we are responder in this case).
1453  *
1454  *    NOTE: If the remote side decides not to initiate the key agreement
1455  *    or decides not to reply with the key agreement packet then we cannot
1456  *    perform the key agreement at all. If the key agreement protocol is
1457  *    performed the `completion' callback with the `context' will be called.
1458  *    If remote side decides to ignore the request the `completion' will be
1459  *    called after the specified timeout, `timeout_secs'. 
1460  *
1461  *    NOTE: If the `hostname' and the `port' was not provided the `completion'
1462  *    will not be called at all since this does nothing more than sending
1463  *    a packet to the remote host.
1464  *
1465  *    NOTE: There can be only one active key agreement for one client entry.
1466  *    Before setting new one, the old one must be finished (it is finished
1467  *    after calling the completion callback) or the function 
1468  *    silc_client_abort_key_agreement must be called. 
1469  *
1470  ***/
1471 void silc_client_send_key_agreement(SilcClient client,
1472                                     SilcClientConnection conn,
1473                                     SilcClientEntry client_entry,
1474                                     char *hostname,
1475                                     int port,
1476                                     uint32 timeout_secs,
1477                                     SilcKeyAgreementCallback completion,
1478                                     void *context);
1479
1480 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1481  *
1482  * SYNOPSIS
1483  *
1484  *    void 
1485  *    silc_client_perform_key_agreement(SilcClient client,
1486  *                                      SilcClientConnection conn,
1487  *                                      SilcClientEntry client_entry,
1488  *                                      char *hostname,
1489  *                                      int port,
1490  *                                      SilcKeyAgreementCallback completion,
1491  *                                      void *context);
1492  *
1493  * DESCRIPTION
1494  *
1495  *    Performs the actual key agreement protocol. Application may use this
1496  *    to initiate the key agreement protocol. This can be called for example
1497  *    after the application has received the `key_agreement' client operation,
1498  *    and did not return TRUE from it.
1499  *
1500  *    The `hostname' is the remote hostname (or IP address) and the `port'
1501  *    is the remote port. The `completion' callback with the `context' will
1502  *    be called after the key agreement protocol.
1503  *
1504  * NOTES
1505  * 
1506  *    NOTE: If the application returns TRUE in the `key_agreement' client
1507  *    operation the library will automatically start the key agreement. In this
1508  *    case the application must not call this function. However, application
1509  *    may choose to just ignore the `key_agreement' client operation (and
1510  *    merely just print information about it on the screen) and call this
1511  *    function when the user whishes to do so (by, for example, giving some
1512  *    specific command). Thus, the API provides both, automatic and manual
1513  *    initiation of the key agreement. Calling this function is the manual
1514  *    initiation and returning TRUE in the `key_agreement' client operation
1515  *    is the automatic initiation. 
1516  *
1517  ***/
1518 void silc_client_perform_key_agreement(SilcClient client,
1519                                        SilcClientConnection conn,
1520                                        SilcClientEntry client_entry,
1521                                        char *hostname,
1522                                        int port,
1523                                        SilcKeyAgreementCallback completion,
1524                                        void *context);
1525
1526 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1527  *
1528  * SYNOPSIS
1529  *
1530  *    void
1531  *    silc_client_perform_key_agreement_fd(SilcClient client,
1532  *                                         SilcClientConnection conn,
1533  *                                         SilcClientEntry client_entry,
1534  *                                         int sock,
1535  *                                         char *hostname,
1536  *                                         SilcKeyAgreementCallback completion,
1537  *                                         void *context);
1538  *
1539  * DESCRIPTION
1540  *
1541  *    Same as above but application has created already the connection to 
1542  *    the remote host. The `sock' is the socket to the remote connection. 
1543  *    Application can use this function if it does not want the client library
1544  *    to create the connection. 
1545  *
1546  ***/
1547 void silc_client_perform_key_agreement_fd(SilcClient client,
1548                                           SilcClientConnection conn,
1549                                           SilcClientEntry client_entry,
1550                                           int sock,
1551                                           char *hostname,
1552                                           SilcKeyAgreementCallback completion,
1553                                           void *context);
1554
1555 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1556  *
1557  * SYNOPSIS
1558  *
1559  *    void silc_client_abort_key_agreement(SilcClient client,
1560  *                                         SilcClientConnection conn,
1561  *                                         SilcClientEntry client_entry);
1562  *
1563  * DESCRIPTION
1564  *
1565  *    This function can be called to unbind the hostname and the port for
1566  *    the key agreement protocol. However, this function has effect only 
1567  *    before the key agreement protocol has been performed. After it has
1568  *    been performed the library will automatically unbind the port. The 
1569  *    `client_entry' is the client to which we sent the key agreement 
1570  *    request. 
1571  *
1572  ***/
1573 void silc_client_abort_key_agreement(SilcClient client,
1574                                      SilcClientConnection conn,
1575                                      SilcClientEntry client_entry);
1576
1577
1578 /* Misc functions */
1579
1580 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1581  *
1582  * SYNOPSIS
1583  *
1584  *    void silc_client_set_away_message(SilcClient client,
1585  *                                      SilcClientConnection conn,
1586  *                                      char *message);
1587  *
1588  * DESCRIPTION
1589  *
1590  *    Sets away `message'.  The away message may be set when the client's
1591  *    mode is changed to SILC_UMODE_GONE and the client whishes to reply
1592  *    to anyone who sends private message.  The `message' will be sent
1593  *    automatically back to the the client who send private message.  If
1594  *    away message is already set this replaces the old message with the
1595  *    new one.  If `message' is NULL the old away message is removed. 
1596  *    The sender may freely free the memory of the `message'. 
1597  *
1598  ***/
1599 void silc_client_set_away_message(SilcClient client,
1600                                   SilcClientConnection conn,
1601                                   char *message);
1602
1603 #endif