1 /****h* silcclient/silcapi.h
9 * Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
11 * Copyright (C) 2000 - 2001 Pekka Riikonen
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.
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.
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.
32 * o SILC Client Operations
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.
37 * To use this structure: define a static SilcClientOperations variable,
38 * fill it and pass its pointer to silc_client_alloc function.
40 * o SILC Client Library API
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.
46 * Please, refer to the README file in this directory for the directions
47 * of how to use the SILC Client Library.
54 #include "clientlibincludes.h"
56 /* General definitions */
58 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
62 * typedef enum { ... } SilcKeyAgreementStatus;
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.
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;
80 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
84 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
85 * SilcClientConnection conn,
86 * SilcClientEntry client_entry,
87 * SilcKeyAgreementStatus status,
88 * SilcSKEKeyMaterial *key,
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.
102 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103 SilcClientConnection conn,
104 SilcClientEntry client_entry,
105 SilcKeyAgreementStatus status,
106 SilcSKEKeyMaterial *key,
109 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
113 * typedef struct { ... } SilcPrivateMessageKeys;
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
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;
135 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
139 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
140 * uint32 passphrase_len,
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.
150 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
151 uint32 passphrase_len,
154 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
158 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
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.
167 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
169 /****d* silcclient/SilcClientAPI/SilcClientMessageType
173 * typedef enum { ... } SilcClientMessageType;
177 * Different message types for `say' client operation. The application
178 * may filter the message sent by the library according this type.
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;
190 /****s* silcclient/SilcClientAPI/SilcClientOperations
194 * typedef struct { ... } SilcClientOperations;
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.
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
211 void (*say)(SilcClient client, SilcClientConnection conn,
212 SilcClientMessageType type, char *msg, ...);
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);
220 /* Private message to the client. The `sender' is the sender of the
222 void (*private_message)(SilcClient client, SilcClientConnection conn,
223 SilcClientEntry sender, SilcMessageFlags flags,
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, ...);
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);
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
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, ...);
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 void (*connect)(SilcClient client, SilcClientConnection conn, int success);
274 /* Called to indicate that connection was disconnected to the server. */
275 void (*disconnect)(SilcClient client, SilcClientConnection conn);
277 /* Find authentication method and authentication data by hostname and
278 port. The hostname may be IP address as well. The found authentication
279 method and authentication data is returned to `auth_meth', `auth_data'
280 and `auth_data_len'. The function returns TRUE if authentication method
281 is found and FALSE if not. `conn' may be NULL. */
282 int (*get_auth_method)(SilcClient client, SilcClientConnection conn,
283 char *hostname, uint16 port,
284 SilcProtocolAuthMeth *auth_meth,
285 unsigned char **auth_data,
286 uint32 *auth_data_len);
288 /* Verifies received public key. The `conn_type' indicates which entity
289 (server, client etc.) has sent the public key. If user decides to trust
290 the key may be saved as trusted public key for later use. The
291 `completion' must be called after the public key has been verified. */
292 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
293 SilcSocketType conn_type, unsigned char *pk,
294 uint32 pk_len, SilcSKEPKType pk_type,
295 SilcVerifyPublicKey completion, void *context);
297 /* Ask (interact, that is) a passphrase from user. The passphrase is
298 returned to the library by calling the `completion' callback with
300 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
301 SilcAskPassphrase completion, void *context);
303 /* Notifies application that failure packet was received. This is called
304 if there is some protocol active in the client. The `protocol' is the
305 protocol context. The `failure' is opaque pointer to the failure
306 indication. Note, that the `failure' is protocol dependant and
307 application must explicitly cast it to correct type. Usually `failure'
308 is 32 bit failure type (see protocol specs for all protocol failure
310 void (*failure)(SilcClient client, SilcClientConnection conn,
311 SilcProtocol protocol, void *failure);
313 /* Asks whether the user would like to perform the key agreement protocol.
314 This is called after we have received an key agreement packet or an
315 reply to our key agreement packet. This returns TRUE if the user wants
316 the library to perform the key agreement protocol and FALSE if it is not
317 desired (application may start it later by calling the function
318 silc_client_perform_key_agreement). If TRUE is returned also the
319 `completion' and `context' arguments must be set by the application. */
320 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
321 SilcClientEntry client_entry, char *hostname,
323 SilcKeyAgreementCallback *completion,
325 } SilcClientOperations;
328 /****s* silcclient/SilcClientAPI/SilcClientParams
332 * typedef struct { ... } SilcClientParams;
336 * Client parameters. This can be filled with proper values and
337 * given as argument to the silc_client_alloc function. The structure
338 * hold various parameters which affects the function of the client.
343 /* Rekey timeout in seconds. The client will perform rekey in this
344 time interval. If set to zero, default value will be used. */
345 unsigned int rekey_secs;
350 /* Initialization functions (client.c) */
352 /****f* silcclient/SilcClientAPI/silc_client_alloc
356 * SilcClient silc_client_alloc(SilcClientOperations *ops,
357 * SilcClientParams *params,
359 * const char *silc_version);
363 * Allocates new client object. This has to be done before client may
364 * work. After calling this one must call silc_client_init to initialize
365 * the client. The `application' is application specific user data pointer
366 * and caller must free it. The `silc_version' is the application version
367 * that will be used to compare against remote host's (usually a server)
371 SilcClient silc_client_alloc(SilcClientOperations *ops,
372 SilcClientParams *params,
374 const char *silc_version);
376 /****f* silcclient/SilcClientAPI/silc_client_free
380 * void silc_client_free(SilcClient client);
384 * Frees client object and its internals. The execution of the client
385 * should be stopped with silc_client_stop function before calling
389 void silc_client_free(SilcClient client);
391 /****f* silcclient/SilcClientAPI/silc_client_init
395 * int silc_client_init(SilcClient client);
399 * Initializes the client. This makes all the necessary steps to make
400 * the client ready to be run. One must call silc_client_run to run the
401 * client. Returns FALSE if error occurred, TRUE otherwise.
404 int silc_client_init(SilcClient client);
406 /****f* silcclient/SilcClientAPI/silc_client_run
410 * void silc_client_run(SilcClient client);
414 * Runs the client. This starts the scheduler from the utility library.
415 * When this functions returns the execution of the appliation is over.
418 void silc_client_run(SilcClient client);
420 /****f* silcclient/SilcClientAPI/silc_client_stop
424 * void silc_client_stop(SilcClient client);
428 * Stops the client. This is called to stop the client and thus to stop
429 * the program. The client context must be freed with the silc_client_free
433 void silc_client_stop(SilcClient client);
436 /* Connecting functions (client.c) */
438 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
442 * int silc_client_connect_to_server(SilcClient client, int port,
443 * char *host, void *context);
447 * Connects to remote server. This is the main routine used to connect
448 * to SILC server. Returns -1 on error and the created socket otherwise.
449 * The `context' is user context that is saved into the SilcClientConnection
450 * that is created after the connection is created. Note that application
451 * may handle the connecting process outside the library. If this is the
452 * case then this function is not used at all. When the connecting is
453 * done the `connect' client operation is called.
456 int silc_client_connect_to_server(SilcClient client, int port,
457 char *host, void *context);
459 /****f* silcclient/SilcClientAPI/silc_client_add_connection
463 * SilcClientConnection silc_client_add_connection(SilcClient client,
470 * Allocates and adds new connection to the client. This adds the allocated
471 * connection to the connection table and returns a pointer to it. A client
472 * can have multiple connections to multiple servers. Every connection must
473 * be added to the client using this function. User data `context' may
474 * be sent as argument. This function is normally used only if the
475 * application performed the connecting outside the library. The library
476 * however may use this internally.
479 SilcClientConnection silc_client_add_connection(SilcClient client,
484 /****f* silcclient/SilcClientAPI/silc_client_del_connection
488 * void silc_client_del_connection(SilcClient client,
489 * SilcClientConnection conn);
493 * Removes connection from client. Frees all memory. The library
494 * call this function automatically for all connection contexts.
495 * The application however may free the connection contexts it has
499 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
501 /****f* silcclient/SilcClientAPI/silc_client_add_socket
505 * void silc_client_add_socket(SilcClient client,
506 * SilcSocketConnection sock);
510 * Adds listener socket to the listener sockets table. This function is
511 * used to add socket objects that are listeners to the client. This should
512 * not be used to add other connection objects.
515 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
517 /****f* silcclient/SilcClientAPI/silc_client_del_socket
521 * void silc_client_del_socket(SilcClient client,
522 * SilcSocketConnection sock);
526 * Deletes listener socket from the listener sockets table. If the
527 * application has added a socket with silc_client_add_socket it must
528 * also free it using this function.
531 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
533 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
537 * int silc_client_start_key_exchange(SilcClient client,
538 * SilcClientConnection conn,
543 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
544 * key material between client and server. This function can be called
545 * directly if application is performing its own connecting and does not
546 * use the connecting provided by this library. This function is normally
547 * used only if the application performed the connecting outside the
548 * library. The library however may use this internally.
551 int silc_client_start_key_exchange(SilcClient client,
552 SilcClientConnection conn,
555 /****f* silcclient/SilcClientAPI/silc_client_close_connection
559 * void silc_client_close_connection(SilcClient client,
560 * SilcSocketConnection sock,
561 * SilcClientConnection conn);
565 * Closes connection to remote end. Free's all allocated data except
566 * for some information such as nickname etc. that are valid at all time.
567 * If the `sock' is NULL then the conn->sock will be used. If `sock' is
568 * provided it will be checked whether the sock and `conn->sock' are the
569 * same (they can be different, ie. a socket can use `conn' as its
570 * connection but `conn->sock' might be actually a different connection
574 void silc_client_close_connection(SilcClient client,
575 SilcSocketConnection sock,
576 SilcClientConnection conn);
579 /* Message sending functions (client_channel.c and client_prvmsg.c) */
581 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
585 * void silc_client_send_channel_message(SilcClient client,
586 * SilcClientConnection conn,
587 * SilcChannelEntry channel,
588 * SilcChannelPrivateKey key,
589 * SilcMessageFlags flags,
590 * unsigned char *data,
596 * Sends packet to the `channel'. Packet to channel is always encrypted
597 * differently from "normal" packets. SILC header of the packet is
598 * encrypted with the next receiver's key and the rest of the packet is
599 * encrypted with the channel specific key. Padding and HMAC is computed
600 * with the next receiver's key. The `data' is the channel message. If
601 * the `force_send' is TRUE then the packet is sent immediately.
603 * If `key' is provided then that private key is used to encrypt the
604 * channel message. If it is not provided, private keys has not been
605 * set at all, the normal channel key is used automatically. If private
606 * keys are set then the first key (the key that was added first as
607 * private key) is used.
610 void silc_client_send_channel_message(SilcClient client,
611 SilcClientConnection conn,
612 SilcChannelEntry channel,
613 SilcChannelPrivateKey key,
614 SilcMessageFlags flags,
619 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
623 * void silc_client_send_private_message(SilcClient client,
624 * SilcClientConnection conn,
625 * SilcClientEntry client_entry,
626 * SilcMessageFlags flags,
627 * unsigned char *data,
633 * Sends private message to remote client. If private message key has
634 * not been set with this client then the message will be encrypted using
635 * normal session keys. Private messages are special packets in SILC
636 * network hence we need this own function for them. This is similar
637 * to silc_client_packet_send_to_channel except that we send private
638 * message. The `data' is the private message. If the `force_send' is
639 * TRUE the packet is sent immediately.
642 void silc_client_send_private_message(SilcClient client,
643 SilcClientConnection conn,
644 SilcClientEntry client_entry,
645 SilcMessageFlags flags,
651 /* Client and Channel entry retrieval (idlist.c) */
653 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
657 * typedef void (*SilcGetClientCallback)(SilcClient client,
658 * SilcClientConnection conn,
659 * SilcClientEntry *clients,
660 * uint32 clients_count,
665 * Callback function given to the silc_client_get_client function. The
666 * found entries are allocated into the `clients' array. The array must
667 * not be freed by the receiver, the library will free it later. If the
668 * `clients' is NULL, no such clients exist in the SILC Network.
671 typedef void (*SilcGetClientCallback)(SilcClient client,
672 SilcClientConnection conn,
673 SilcClientEntry *clients,
674 uint32 clients_count,
677 /****f* silcclient/SilcClientAPI/silc_client_get_clients
681 * void silc_client_get_clients(SilcClient client,
682 * SilcClientConnection conn,
685 * SilcGetClientCallback completion,
690 * Finds client entry or entries by the `nickname' and `server'. The
691 * completion callback will be called when the client entries has been
696 * NOTE: This function is always asynchronous and resolves the client
697 * information from the server. Thus, if you already know the client
698 * information then use the silc_client_get_client_by_id function to
699 * get the client entry since this function may be very slow and should
700 * be used only to initially get the client entries.
703 void silc_client_get_clients(SilcClient client,
704 SilcClientConnection conn,
707 SilcGetClientCallback completion,
710 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
714 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
715 * SilcClientConnection conn,
718 * uint32 *clients_count);
722 * Same as silc_client_get_clients function but does not resolve anything
723 * from the server. This checks local cache and returns all clients from
727 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
728 SilcClientConnection conn,
731 uint32 *clients_count);
733 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
737 * void silc_client_get_clients_by_list(SilcClient client,
738 * SilcClientConnection conn,
740 * SilcBuffer client_id_list,
741 * SilcGetClientCallback completion,
746 * Gets client entries by the list of client ID's `client_id_list'. This
747 * always resolves those client ID's it does not know yet from the server
748 * so this function might take a while. The `client_id_list' is a list
749 * of ID Payloads added one after other. JOIN command reply and USERS
750 * command reply for example returns this sort of list. The `completion'
751 * will be called after the entries are available.
754 void silc_client_get_clients_by_list(SilcClient client,
755 SilcClientConnection conn,
757 SilcBuffer client_id_list,
758 SilcGetClientCallback completion,
761 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
765 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
766 * SilcClientConnection conn,
767 * SilcClientID *client_id);
771 * Find entry for client by the client's ID. Returns the entry or NULL
772 * if the entry was not found.
775 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
776 SilcClientConnection conn,
777 SilcClientID *client_id);
779 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
784 * silc_client_get_client_by_id_resolve(SilcClient client,
785 * SilcClientConnection conn,
786 * SilcClientID *client_id,
787 * SilcGetClientCallback completion,
792 * Same as silc_client_get_client_by_id but will always resolve the
793 * information from the server. Use this only if you know that you
794 * do not have the entry and the only thing you know about the client
798 void silc_client_get_client_by_id_resolve(SilcClient client,
799 SilcClientConnection conn,
800 SilcClientID *client_id,
801 SilcGetClientCallback completion,
804 /****f* silcclient/SilcClientAPI/silc_client_del_client
808 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
809 * SilcClientEntry client_entry)
813 * Removes client from local cache by the client entry indicated by
814 * the `client_entry'. Returns TRUE if the deletion were successful.
817 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
818 SilcClientEntry client_entry);
820 /****f* silcclient/SilcClientAPI/silc_client_del_client_by_id
824 * bool silc_client_del_client_by_id(SilcClient client,
825 * SilcClientConnection conn,
826 * SilcClientID *client_id);
830 * Removes client from local cache by the Client ID indicated by
831 * the `Client ID'. Returns TRUE if the deletion were successful.
834 bool silc_client_del_client_by_id(SilcClient client,
835 SilcClientConnection conn,
836 SilcClientID *client_id);
838 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
842 * typedef void (*SilcGetClientCallback)(SilcClient client,
843 * SilcClientConnection conn,
844 * SilcClientEntry *clients,
845 * uint32 clients_count,
850 * Callback function given to the silc_client_get_channel_* functions.
851 * The found entries are allocated into the `channels' array. The array
852 * must not be freed by the receiver, the library will free it later.
853 * If the `channel' is NULL, no such channel exist in the SILC Network.
856 typedef void (*SilcGetChannelCallback)(SilcClient client,
857 SilcClientConnection conn,
858 SilcChannelEntry *channels,
859 uint32 channels_count,
862 /****f* silcclient/SilcClientAPI/silc_client_get_channel
866 * SilcChannelEntry silc_client_get_channel(SilcClient client,
867 * SilcClientConnection conn,
872 * Finds entry for channel by the channel name. Returns the entry or NULL
873 * if the entry was not found. It is found only if the client is joined
877 SilcChannelEntry silc_client_get_channel(SilcClient client,
878 SilcClientConnection conn,
881 /****f* silcclient/SilcClientAPI/silc_client_get_channel
886 * silc_client_get_channel_by_id_resolve(SilcClient client,
887 * SilcClientConnection conn,
888 * SilcChannelID *channel_id,
889 * SilcGetClientCallback completion,
894 * Finds channel entry by the channel name. Returns the entry or NULL
895 * if it was not found.
898 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
899 SilcClientConnection conn,
900 SilcChannelID *channel_id);
902 /****f* silcclient/SilcClientAPI/silc_client_get_channel
907 * silc_client_get_channel_by_id_resolve(SilcClient client,
908 * SilcClientConnection conn,
909 * SilcChannelID *channel_id,
910 * SilcGetClientCallback completion,
915 * Resolves the channel information (its name mainly) from the server
916 * by the `channel_id'. Use this only if you know that you do not have
917 * the entry cached locally.
920 void silc_client_get_channel_by_id_resolve(SilcClient client,
921 SilcClientConnection conn,
922 SilcChannelID *channel_id,
923 SilcGetChannelCallback completion,
926 /****f* silcclient/SilcClientAPI/silc_client_get_server
930 * SilcServerEntry silc_client_get_server(SilcClient client,
931 * SilcClientConnection conn,
936 * Finds entry for server by the server name. Returns the entry or NULL
937 * if the entry was not found.
940 SilcServerEntry silc_client_get_server(SilcClient client,
941 SilcClientConnection conn,
944 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
948 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
949 * SilcClientConnection conn,
950 * SilcServerID *server_id);
954 * Finds entry for server by the server ID. Returns the entry or NULL
955 * if the entry was not found.
958 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
959 SilcClientConnection conn,
960 SilcServerID *server_id);
963 /* Command management (command.c) */
965 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
969 * SilcClientCommandContext silc_client_command_alloc();
973 * Allocate Command Context. The context is defined in `command.h' file.
974 * The context is used by the library commands and applications should use
975 * it as well. However, application may choose to use some own context
976 * for its local commands. All library commands, however, must use this
980 SilcClientCommandContext silc_client_command_alloc();
982 /****f* silcclient/SilcClientAPI/silc_client_command_free
986 * void silc_client_command_free(SilcClientCommandContext ctx);
990 * Free command context and its internals. If the contex was duplicated
991 * with silc_client_command_dup this may not actually free the data,
992 * instead it will decrease the reference counter of the context. The
993 * context will be freed when the reference counter hits zero.
996 void silc_client_command_free(SilcClientCommandContext ctx);
998 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1002 * SilcClientCommandContext
1003 * silc_client_command_dup(SilcClientCommandContext ctx);
1007 * Duplicate Command Context by adding reference counter. The context won't
1008 * be free'd untill it hits zero.
1011 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1013 /****f* silcclient/SilcClientAPI/silc_client_command_find
1017 * SilcClientCommand *silc_client_command_find(const char *name);
1021 * Finds and returns a pointer to the command list. Return NULL if the
1022 * command is not found. See the `command.[ch]' for the command list.
1025 SilcClientCommand *silc_client_command_find(const char *name);
1027 /****f* silcclient/SilcClientAPI/silc_client_send_command
1031 * void silc_client_send_command(SilcClient client,
1032 * SilcClientConnection conn,
1033 * SilcCommand command, uint16 ident,
1034 * uint32 argc, ...);
1038 * Generic function to send any command. The arguments must be sent already
1039 * encoded into correct form and in correct order.
1042 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
1043 SilcCommand command, uint16 ident,
1046 /****f* silcclient/SilcClientAPI/SilcClientPendingDestructor
1050 * typedef void (*SilcClientPendingDestructor)(void *context);
1054 * Pending Command callback destructor. This is called after calling the
1055 * pending callback or if error occurs while processing the pending command.
1056 * If error occurs then the callback won't be called at all, and only this
1057 * destructor is called. The `context' is the context given for the function
1058 * silc_client_command_pending.
1061 typedef void (*SilcClientPendingDestructor)(void *context);
1063 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1067 * void silc_client_command_pending(SilcClientConnection conn,
1068 * SilcCommand reply_cmd,
1070 * SilcClientPendingDestructor destructor,
1071 * SilcCommandCb callback,
1076 * Add new pending command to be executed when reply to a command has been
1077 * received. The `reply_cmd' is the command that will call the `callback'
1078 * with `context' when reply has been received. If `ident is non-zero
1079 * the `callback' will be executed when received reply with command
1080 * identifier `ident'.
1083 void silc_client_command_pending(SilcClientConnection conn,
1084 SilcCommand reply_cmd,
1086 SilcClientPendingDestructor destructor,
1087 SilcCommandCb callback,
1091 /* Private Message key management (client_prvmsg.c) */
1093 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1097 * int silc_client_add_private_message_key(SilcClient client,
1098 * SilcClientConnection conn,
1099 * SilcClientEntry client_entry,
1101 * unsigned char *key,
1103 * bool generate_key,
1108 * Adds private message key to the client library. The key will be used to
1109 * encrypt all private message between the client and the remote client
1110 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1111 * value `generate_key' is TRUE the library will generate random key.
1112 * The `key' maybe for example pre-shared-key, passphrase or similar.
1113 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1114 * requirements of the SILC protocol are met. The API, however, allows
1115 * to allocate any cipher.
1117 * If `responder' is TRUE then the sending and receiving keys will be
1118 * set according the client being the receiver of the private key. If
1119 * FALSE the client is being the sender (or negotiator) of the private
1122 * It is not necessary to set key for normal private message usage. If the
1123 * key is not set then the private messages are encrypted using normal
1124 * session keys. Setting the private key, however, increases the security.
1126 * Returns FALSE if the key is already set for the `client_entry', TRUE
1130 int silc_client_add_private_message_key(SilcClient client,
1131 SilcClientConnection conn,
1132 SilcClientEntry client_entry,
1139 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1143 * int silc_client_add_private_message_key_ske(SilcClient client,
1144 * SilcClientConnection conn,
1145 * SilcClientEntry client_entry,
1147 * SilcSKEKeyMaterial *key);
1151 * Same as silc_client_add_private_message_key but takes the key material
1152 * from the SKE key material structure. This structure is received if
1153 * the application uses the silc_client_send_key_agreement to negotiate
1154 * the key material. The `cipher' SHOULD be provided as it is negotiated
1155 * also in the SKE protocol.
1158 int silc_client_add_private_message_key_ske(SilcClient client,
1159 SilcClientConnection conn,
1160 SilcClientEntry client_entry,
1162 SilcSKEKeyMaterial *key,
1165 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1169 * int silc_client_send_private_message_key(SilcClient client,
1170 * SilcClientConnection conn,
1171 * SilcClientEntry client_entry,
1176 * Sends private message key payload to the remote client indicated by
1177 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1178 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1179 * application should call this function after setting the key to the
1182 * Note that the key sent using this function is sent to the remote client
1183 * through the SILC network. The packet is protected using normal session
1187 int silc_client_send_private_message_key(SilcClient client,
1188 SilcClientConnection conn,
1189 SilcClientEntry client_entry,
1192 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1196 * int silc_client_del_private_message_key(SilcClient client,
1197 * SilcClientConnection conn,
1198 * SilcClientEntry client_entry);
1202 * Removes the private message from the library. The key won't be used
1203 * after this to protect the private messages with the remote `client_entry'
1204 * client. Returns FALSE on error, TRUE otherwise.
1207 int silc_client_del_private_message_key(SilcClient client,
1208 SilcClientConnection conn,
1209 SilcClientEntry client_entry);
1211 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1215 * SilcPrivateMessageKeys
1216 * silc_client_list_private_message_keys(SilcClient client,
1217 * SilcClientConnection conn,
1218 * uint32 *key_count);
1222 * Returns array of set private message keys associated to the connection
1223 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1224 * count to the `key_count' argument. The array must be freed by the caller
1225 * by calling the silc_client_free_private_message_keys function. Note:
1226 * the keys returned in the array is in raw format. It might not be desired
1227 * to show the keys as is. The application might choose not to show the keys
1228 * at all or to show the fingerprints of the keys.
1231 SilcPrivateMessageKeys
1232 silc_client_list_private_message_keys(SilcClient client,
1233 SilcClientConnection conn,
1236 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1240 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1241 * uint32 key_count);
1245 * Frees the SilcPrivateMessageKeys array returned by the function
1246 * silc_client_list_private_message_keys.
1249 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1253 /* Channel private key management (client_channel.c,
1254 SilcChannelPrivateKey is defined in idlist.h) */
1256 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1260 * int silc_client_add_channel_private_key(SilcClient client,
1261 * SilcClientConnection conn,
1262 * SilcChannelEntry channel,
1265 * unsigned char *key,
1270 * Adds private key for channel. This may be set only if the channel's mode
1271 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1272 * mode is not set. When channel has private key then the messages are
1273 * encrypted using that key. All clients on the channel must also know the
1274 * key in order to decrypt the messages. However, it is possible to have
1275 * several private keys per one channel. In this case only some of the
1276 * clients on the channel may know the one key and only some the other key.
1278 * The private key for channel is optional. If it is not set then the
1279 * channel messages are encrypted using the channel key generated by the
1280 * server. However, setting the private key (or keys) for the channel
1281 * significantly adds security. If more than one key is set the library
1282 * will automatically try all keys at the message decryption phase. Note:
1283 * setting many keys slows down the decryption phase as all keys has to
1284 * be tried in order to find the correct decryption key. However, setting
1285 * a few keys does not have big impact to the decryption performace.
1289 * NOTE: This is entirely local setting. The key set using this function
1290 * is not sent to the network at any phase.
1292 * NOTE: If the key material was originated by the SKE protocol (using
1293 * silc_client_send_key_agreement) then the `key' MUST be the
1294 * key->send_enc_key as this is dictated by the SILC protocol. However,
1295 * currently it is not expected that the SKE key material would be used
1296 * as channel private key. However, this API allows it.
1299 int silc_client_add_channel_private_key(SilcClient client,
1300 SilcClientConnection conn,
1301 SilcChannelEntry channel,
1307 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1311 * int silc_client_del_channel_private_keys(SilcClient client,
1312 * SilcClientConnection conn,
1313 * SilcChannelEntry channel);
1317 * Removes all private keys from the `channel'. The old channel key is used
1318 * after calling this to protect the channel messages. Returns FALSE on
1319 * on error, TRUE otherwise.
1322 int silc_client_del_channel_private_keys(SilcClient client,
1323 SilcClientConnection conn,
1324 SilcChannelEntry channel);
1326 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1330 * int silc_client_del_channel_private_key(SilcClient client,
1331 * SilcClientConnection conn,
1332 * SilcChannelEntry channel,
1333 * SilcChannelPrivateKey key);
1337 * Removes and frees private key `key' from the channel `channel'.
1338 * The `key' is retrieved by calling the function
1339 * silc_client_list_channel_private_keys. The key is not used after
1340 * this. If the key was last private key then the old channel key is
1341 * used hereafter to protect the channel messages. This returns FALSE
1342 * on error, TRUE otherwise.
1345 int silc_client_del_channel_private_key(SilcClient client,
1346 SilcClientConnection conn,
1347 SilcChannelEntry channel,
1348 SilcChannelPrivateKey key);
1350 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1354 * SilcChannelPrivateKey *
1355 * silc_client_list_channel_private_keys(SilcClient client,
1356 * SilcClientConnection conn,
1357 * SilcChannelEntry channel,
1358 * uint32 *key_count);
1362 * Returns array (pointers) of private keys associated to the `channel'.
1363 * The caller must free the array by calling the function
1364 * silc_client_free_channel_private_keys. The pointers in the array may be
1365 * used to delete the specific key by giving the pointer as argument to the
1366 * function silc_client_del_channel_private_key.
1369 SilcChannelPrivateKey *
1370 silc_client_list_channel_private_keys(SilcClient client,
1371 SilcClientConnection conn,
1372 SilcChannelEntry channel,
1375 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1379 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1380 * uint32 key_count);
1384 * Frees the SilcChannelPrivateKey array.
1387 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1391 /* Key Agreement routines (client_keyagr.c) */
1393 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1397 * void silc_client_send_key_agreement(SilcClient client,
1398 * SilcClientConnection conn,
1399 * SilcClientEntry client_entry,
1402 * uint32 timeout_secs,
1403 * SilcKeyAgreementCallback completion,
1408 * Sends key agreement request to the remote client indicated by the
1409 * `client_entry'. If the caller provides the `hostname' and the `port'
1410 * arguments then the library will bind the client to that hostname and
1411 * that port for the key agreement protocol. It also sends the `hostname'
1412 * and the `port' in the key agreement packet to the remote client. This
1413 * would indicate that the remote client may initiate the key agreement
1414 * protocol to the `hostname' on the `port'. If port is zero then the
1415 * bound port is undefined (the operating system defines it).
1417 * If the `hostname' and `port' is not provided then empty key agreement
1418 * packet is sent to the remote client. The remote client may reply with
1419 * the same packet including its hostname and port. If the library receives
1420 * the reply from the remote client the `key_agreement' client operation
1421 * callback will be called to verify whether the user wants to perform the
1422 * key agreement or not.
1426 * NOTE: If the application provided the `hostname' and the `port' and the
1427 * remote side initiates the key agreement protocol it is not verified
1428 * from the user anymore whether the protocol should be executed or not.
1429 * By setting the `hostname' and `port' the user gives permission to
1430 * perform the protocol (we are responder in this case).
1432 * NOTE: If the remote side decides not to initiate the key agreement
1433 * or decides not to reply with the key agreement packet then we cannot
1434 * perform the key agreement at all. If the key agreement protocol is
1435 * performed the `completion' callback with the `context' will be called.
1436 * If remote side decides to ignore the request the `completion' will be
1437 * called after the specified timeout, `timeout_secs'.
1439 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1440 * will not be called at all since this does nothing more than sending
1441 * a packet to the remote host.
1443 * NOTE: There can be only one active key agreement for one client entry.
1444 * Before setting new one, the old one must be finished (it is finished
1445 * after calling the completion callback) or the function
1446 * silc_client_abort_key_agreement must be called.
1449 void silc_client_send_key_agreement(SilcClient client,
1450 SilcClientConnection conn,
1451 SilcClientEntry client_entry,
1454 uint32 timeout_secs,
1455 SilcKeyAgreementCallback completion,
1458 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1463 * silc_client_perform_key_agreement(SilcClient client,
1464 * SilcClientConnection conn,
1465 * SilcClientEntry client_entry,
1468 * SilcKeyAgreementCallback completion,
1473 * Performs the actual key agreement protocol. Application may use this
1474 * to initiate the key agreement protocol. This can be called for example
1475 * after the application has received the `key_agreement' client operation,
1476 * and did not return TRUE from it.
1478 * The `hostname' is the remote hostname (or IP address) and the `port'
1479 * is the remote port. The `completion' callback with the `context' will
1480 * be called after the key agreement protocol.
1484 * NOTE: If the application returns TRUE in the `key_agreement' client
1485 * operation the library will automatically start the key agreement. In this
1486 * case the application must not call this function. However, application
1487 * may choose to just ignore the `key_agreement' client operation (and
1488 * merely just print information about it on the screen) and call this
1489 * function when the user whishes to do so (by, for example, giving some
1490 * specific command). Thus, the API provides both, automatic and manual
1491 * initiation of the key agreement. Calling this function is the manual
1492 * initiation and returning TRUE in the `key_agreement' client operation
1493 * is the automatic initiation.
1496 void silc_client_perform_key_agreement(SilcClient client,
1497 SilcClientConnection conn,
1498 SilcClientEntry client_entry,
1501 SilcKeyAgreementCallback completion,
1504 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1509 * silc_client_perform_key_agreement_fd(SilcClient client,
1510 * SilcClientConnection conn,
1511 * SilcClientEntry client_entry,
1514 * SilcKeyAgreementCallback completion,
1519 * Same as above but application has created already the connection to
1520 * the remote host. The `sock' is the socket to the remote connection.
1521 * Application can use this function if it does not want the client library
1522 * to create the connection.
1525 void silc_client_perform_key_agreement_fd(SilcClient client,
1526 SilcClientConnection conn,
1527 SilcClientEntry client_entry,
1530 SilcKeyAgreementCallback completion,
1533 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1537 * void silc_client_abort_key_agreement(SilcClient client,
1538 * SilcClientConnection conn,
1539 * SilcClientEntry client_entry);
1543 * This function can be called to unbind the hostname and the port for
1544 * the key agreement protocol. However, this function has effect only
1545 * before the key agreement protocol has been performed. After it has
1546 * been performed the library will automatically unbind the port. The
1547 * `client_entry' is the client to which we sent the key agreement
1551 void silc_client_abort_key_agreement(SilcClient client,
1552 SilcClientConnection conn,
1553 SilcClientEntry client_entry);
1556 /* Misc functions */
1558 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1562 * void silc_client_set_away_message(SilcClient client,
1563 * SilcClientConnection conn,
1568 * Sets away `message'. The away message may be set when the client's
1569 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1570 * to anyone who sends private message. The `message' will be sent
1571 * automatically back to the the client who send private message. If
1572 * away message is already set this replaces the old message with the
1573 * new one. If `message' is NULL the old away message is removed.
1574 * The sender may freely free the memory of the `message'.
1577 void silc_client_set_away_message(SilcClient client,
1578 SilcClientConnection conn,