5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
57 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct
70 *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
73 /* General definitions */
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
79 * typedef enum { ... } SilcKeyAgreementStatus;
83 * Key agreement status types indicating the status of the key
84 * agreement protocol. These types are returned to the application
85 * in the SilcKeyAgreementCallback callback function.
90 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
91 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
92 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
93 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
94 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
95 } SilcKeyAgreementStatus;
98 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
102 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103 * SilcClientConnection conn,
104 * SilcClientEntry client_entry,
105 * SilcKeyAgreementStatus status,
106 * SilcSKEKeyMaterial *key,
111 * Key agreement callback that is called after the key agreement protocol
112 * has been performed. This is called also if error occurred during the
113 * key agreement protocol. The `key' is the allocated key material and
114 * the caller is responsible of freeing it. The `key' is NULL if error
115 * has occurred. The application can freely use the `key' to whatever
116 * purpose it needs. See lib/silcske/silcske.h for the definition of
117 * the SilcSKEKeyMaterial structure.
120 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
121 SilcClientConnection conn,
122 SilcClientEntry client_entry,
123 SilcKeyAgreementStatus status,
124 SilcSKEKeyMaterial *key,
127 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
131 * typedef struct { ... } SilcPrivateMessageKeys;
135 * Structure to hold the list of private message keys. The array of this
136 * structure is returned by the silc_client_list_private_message_keys
142 SilcClientEntry client_entry; /* The remote client entry */
143 char *cipher; /* The cipher name */
144 unsigned char *key; /* The original key, If the appliation
145 provided it. This is NULL if the
146 library generated the key or if
147 the SKE key material was used. */
148 SilcUInt32 key_len; /* The key length */
149 } *SilcPrivateMessageKeys;
152 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
156 * typedef struct { ... } SilcChannelPrivateKey;
160 * Structure to hold one channel private key. The array of this structure
161 * is returned by silc_client_list_channel_private_keys function.
165 typedef struct SilcChannelPrivateKeyStruct {
166 char *name; /* Application given name */
167 SilcCipher cipher; /* The cipher and key */
168 SilcHmac hmac; /* The HMAC and hmac key */
169 unsigned char *key; /* The key data */
170 SilcUInt32 key_len; /* The key length */
171 } *SilcChannelPrivateKey;
174 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
178 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
179 * SilcUInt32 passphrase_len,
184 * Ask passphrase callback. This is called by the application when the
185 * library calls `ask_passphrase' client operation. The callback delivers
186 * the passphrase to the library. The passphrases in SILC protocol
187 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
188 * encoded, and if it is not then library will attempt to encode it.
191 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
192 SilcUInt32 passphrase_len,
195 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
199 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
203 * Public key (or certificate) verification callback. This is called
204 * by the application to indicate that the public key verification was
205 * either success or failure.
208 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
210 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
214 * typedef void (*SilcGetAuthMeth)(bool success,
215 * SilcProtocolAuthMeth auth_meth,
216 * const unsigned char *auth_data,
217 * SilcUInt32 auth_data_len, void *context);
221 * Authentication method resolving callback. This is called by the
222 * application to return the resolved authentication method. The client
223 * library has called the get_auth_method client operation and given
224 * this function pointer as argument. The `success' will indicate whether
225 * the authentication method could be resolved. The `auth_meth' is the
226 * resolved authentication method. The `auth_data' and the `auth_data_len'
227 * are the resolved authentication data. The `context' is the libary's
228 * context sent to the get_auth_method client operation.
231 typedef void (*SilcGetAuthMeth)(bool success,
232 SilcProtocolAuthMeth auth_meth,
233 const unsigned char *auth_data,
234 SilcUInt32 auth_data_len, void *context);
236 /****d* silcclient/SilcClientAPI/SilcClientMessageType
240 * typedef enum { ... } SilcClientMessageType;
244 * Different message types for `say' client operation. The application
245 * may filter the message sent by the library according this type.
250 SILC_CLIENT_MESSAGE_INFO, /* Informational */
251 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
252 SILC_CLIENT_MESSAGE_ERROR, /* Error */
253 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
254 } SilcClientMessageType;
257 /****s* silcclient/SilcClientAPI/SilcClientOperations
261 * typedef struct { ... } SilcClientOperations;
265 * SILC Client Operations. These must be implemented by the application.
266 * The Client library may call any of these routines at any time. The
267 * routines are used to deliver certain information to the application
268 * or from the application to the client library.
273 /* Message sent to the application by library. `conn' associates the
274 message to a specific connection. `conn', however, may be NULL.
275 The `type' indicates the type of the message sent by the library.
276 The applicationi can for example filter the message according the
278 void (*say)(SilcClient client, SilcClientConnection conn,
279 SilcClientMessageType type, char *msg, ...);
281 /* Message for a channel. The `sender' is the sender of the message
282 The `channel' is the channel. The `msg' is the message. Note that
284 void (*channel_message)(SilcClient client, SilcClientConnection conn,
285 SilcClientEntry sender, SilcChannelEntry channel,
286 SilcMessageFlags flags,
287 const unsigned char *message,
288 SilcUInt32 message_len);
290 /* Private message to the client. The `sender' is the sender of the
292 void (*private_message)(SilcClient client, SilcClientConnection conn,
293 SilcClientEntry sender, SilcMessageFlags flags,
294 const unsigned char *message,
295 SilcUInt32 message_len);
297 /* Notify message to the client. The notify arguments are sent in the
298 same order as servers sends them. The arguments are same as received
299 from the server except for ID's. If ID is received application receives
300 the corresponding entry to the ID. For example, if Client ID is received
301 application receives SilcClientEntry. Also, if the notify type is
302 for channel the channel entry is sent to application (even if server
303 does not send it because client library gets the channel entry from
304 the Channel ID in the packet's header). */
305 void (*notify)(SilcClient client, SilcClientConnection conn,
306 SilcNotifyType type, ...);
308 /* Command handler. This function is called always in the command function.
309 If error occurs it will be called as well. `conn' is the associated
310 client connection. `cmd_context' is the command context that was
311 originally sent to the command. `success' is FALSE if error occurred
312 during command. `command' is the command being processed. It must be
313 noted that this is not reply from server. This is merely called just
314 after application has called the command. Just to tell application
315 that the command really was processed. */
316 void (*command)(SilcClient client, SilcClientConnection conn,
317 SilcClientCommandContext cmd_context, int success,
318 SilcCommand command);
320 /* Command reply handler. This function is called always in the command reply
321 function. If error occurs it will be called as well. Normal scenario
322 is that it will be called after the received command data has been parsed
323 and processed. The function is used to pass the received command data to
326 `conn' is the associated client connection. `cmd_payload' is the command
327 payload data received from server and it can be ignored. It is provided
328 if the application would like to re-parse the received command data,
329 however, it must be noted that the data is parsed already by the library
330 thus the payload can be ignored. `success' is FALSE if error occurred.
331 In this case arguments are not sent to the application. The `status' is
332 the command reply status server returned. The `command' is the command
333 reply being processed. The function has variable argument list and each
334 command defines the number and type of arguments it passes to the
335 application (on error they are not sent).
337 The arguments are sent in the same order as servers sends them. The
338 arguments are same as received from the server except for ID's. If
339 ID is received application receives the corresponding entry to the
340 ID. For example, if Client ID is receives application receives
342 void (*command_reply)(SilcClient client, SilcClientConnection conn,
343 SilcCommandPayload cmd_payload, int success,
344 SilcCommand command, SilcCommandStatus status, ...);
346 /* Called to indicate that connection was either successfully established
347 or connecting failed. This is also the first time application receives
348 the SilcClientConnection object which it should save somewhere.
349 If the `success' is FALSE the application must always call the function
350 silc_client_close_connection. */
351 void (*connect)(SilcClient client, SilcClientConnection conn, int success);
353 /* Called to indicate that connection was disconnected to the server. */
354 void (*disconnect)(SilcClient client, SilcClientConnection conn);
356 /* Find authentication method and authentication data by hostname and
357 port. The hostname may be IP address as well. When the authentication
358 method has been resolved the `completion' callback with the found
359 authentication method and authentication data is called. The `conn'
361 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
362 char *hostname, SilcUInt16 port,
363 SilcGetAuthMeth completion, void *context);
365 /* Verifies received public key. The `conn_type' indicates which entity
366 (server, client etc.) has sent the public key. If user decides to trust
367 the key may be saved as trusted public key for later use. The
368 `completion' must be called after the public key has been verified. */
369 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
370 SilcSocketType conn_type, unsigned char *pk,
371 SilcUInt32 pk_len, SilcSKEPKType pk_type,
372 SilcVerifyPublicKey completion, void *context);
374 /* Ask (interact, that is) a passphrase from user. The passphrase is
375 returned to the library by calling the `completion' callback with
376 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
377 if not then the library will attempt to encode. */
378 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
379 SilcAskPassphrase completion, void *context);
381 /* Notifies application that failure packet was received. This is called
382 if there is some protocol active in the client. The `protocol' is the
383 protocol context. The `failure' is opaque pointer to the failure
384 indication. Note, that the `failure' is protocol dependant and
385 application must explicitly cast it to correct type. Usually `failure'
386 is 32 bit failure type (see protocol specs for all protocol failure
388 void (*failure)(SilcClient client, SilcClientConnection conn,
389 SilcProtocol protocol, void *failure);
391 /* Asks whether the user would like to perform the key agreement protocol.
392 This is called after we have received an key agreement packet or an
393 reply to our key agreement packet. This returns TRUE if the user wants
394 the library to perform the key agreement protocol and FALSE if it is not
395 desired (application may start it later by calling the function
396 silc_client_perform_key_agreement). If TRUE is returned also the
397 `completion' and `context' arguments must be set by the application. */
398 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
399 SilcClientEntry client_entry, const char *hostname,
400 SilcUInt16 port, SilcKeyAgreementCallback *completion,
403 /* Notifies application that file transfer protocol session is being
404 requested by the remote client indicated by the `client_entry' from
405 the `hostname' and `port'. The `session_id' is the file transfer
406 session and it can be used to either accept or reject the file
407 transfer request, by calling the silc_client_file_receive or
408 silc_client_file_close, respectively. */
409 void (*ftp)(SilcClient client, SilcClientConnection conn,
410 SilcClientEntry client_entry, SilcUInt32 session_id,
411 const char *hostname, SilcUInt16 port);
412 } SilcClientOperations;
415 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
419 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
420 * char **ret_nickname);
424 * A callback function provided by the application for the library in
425 * SilcClientParams structure. This function parses the formatted
426 * nickname string `nickname' and returns the true nickname to the
427 * `ret_nickname' pointer. The library can call this function at
431 typedef void (*SilcNicknameFormatParse)(const char *nickname,
432 char **ret_nickname);
434 /****s* silcclient/SilcClientAPI/SilcClientParams
438 * typedef struct { ... } SilcClientParams;
442 * Client parameters. This can be filled with proper values and
443 * given as argument to the silc_client_alloc function. The structure
444 * hold various parameters which affects the function of the client.
449 /* Number of maximum tasks the client library's scheduler can handle.
450 If set to zero, the default value will be used (200). For WIN32
451 systems this should be set to 64 as it is the hard limit dictated
455 /* Rekey timeout in seconds. The client will perform rekey in this
456 time interval. If set to zero, the default value will be used. */
457 unsigned int rekey_secs;
459 /* Connection authentication method request timeout. If server does not
460 reply back the current authentication method when we've requested it
461 in this time interval we'll assume the reply will not come at all.
462 If set to zero, the default value (2 seconds) will be used. */
463 unsigned int connauth_request_secs;
465 /* Nickname format string. This can be used to order the client library
466 to save the nicknames in the library in a certain format. Since
467 nicknames are not unique in SILC it is possible to have multiple same
468 nicknames. Using this format string it is possible to order the library
469 to separate the multiple same nicknames from each other. The format
470 types are defined below and they can appear in any order in the format
471 string. If this is NULL then default format is used which is the
472 default nickname without anything else. The string MUST be NULL
475 Following format types are available:
477 %n nickname - the real nickname returned by the server (mandatory)
478 %h hostname - the stripped hostname of the client
479 %H full hostname - the full hostname of the client
480 %s server name - the server name the client is connected
481 %S full server - the full server name the client is connected
482 %a number - ascending number in case there are several
483 same nicknames (fe. nick@host and nick@host2)
485 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
486 "%a!%n@%s" (fe. nick@server, 2!nick@server)
487 "%n@%H" (fe. nick@host.domain.com)
489 By default this format is employed to the nicknames by the libary
490 only when there appears multiple same nicknames. If the library has
491 only one nickname cached the nickname is saved as is and without the
492 defined format. If you want always to save the nickname in the defined
493 format set the boolean field `nickname_force_format' to value TRUE.
495 char nickname_format[32];
497 /* If this is set to TRUE then the `nickname_format' is employed to all
498 saved nicknames even if there are no multiple same nicknames in the
499 cache. By default this is FALSE, which means that the `nickname_format'
500 is employed only if the library will receive a nickname that is
501 already saved in the cache. It is recommended to leave this to FALSE
503 bool nickname_force_format;
505 /* A callback function provided by the application for the library to
506 parse the nickname from the formatted nickname string. Even though
507 the libary formats the nicknames the application knows generally the
508 format better so this function should be provided for the library
509 if the application sets the `nickname_format' field. The library
510 will call this to get the true nickname from the provided formatted
511 nickname string whenever it needs the true nickname. */
512 SilcNicknameFormatParse nickname_parse;
518 /* Initialization functions (client.c) */
520 /****f* silcclient/SilcClientAPI/silc_client_alloc
524 * SilcClient silc_client_alloc(SilcClientOperations *ops,
525 * SilcClientParams *params,
527 * const char *silc_version);
531 * Allocates new client object. This has to be done before client may
532 * work. After calling this one must call silc_client_init to initialize
533 * the client. The `application' is application specific user data pointer
534 * and caller must free it. The `silc_version' is the application version
535 * that will be used to compare against remote host's (usually a server)
539 SilcClient silc_client_alloc(SilcClientOperations *ops,
540 SilcClientParams *params,
542 const char *silc_version);
544 /****f* silcclient/SilcClientAPI/silc_client_free
548 * void silc_client_free(SilcClient client);
552 * Frees client object and its internals. The execution of the client
553 * should be stopped with silc_client_stop function before calling
557 void silc_client_free(SilcClient client);
559 /****f* silcclient/SilcClientAPI/silc_client_init
563 * int silc_client_init(SilcClient client);
567 * Initializes the client. This makes all the necessary steps to make
568 * the client ready to be run. One must call silc_client_run to run the
569 * client. Returns FALSE if error occurred, TRUE otherwise.
572 int silc_client_init(SilcClient client);
574 /****f* silcclient/SilcClientAPI/silc_client_run
578 * void silc_client_run(SilcClient client);
582 * Runs the client. This starts the scheduler from the utility library.
583 * When this functions returns the execution of the appliation is over.
586 void silc_client_run(SilcClient client);
588 /****f* silcclient/SilcClientAPI/silc_client_run_one
592 * void silc_client_run_one(SilcClient client);
596 * Runs the client and returns immeadiately. This function is used when
597 * the SILC Client object indicated by the `client' is run under some
598 * other scheduler, or event loop or main loop. On GUI applications,
599 * for example this may be desired to used to run the client under the
600 * GUI application's main loop. Typically the GUI application would
601 * register an idle task that calls this function multiple times in
602 * a second to quickly process the SILC specific data.
605 void silc_client_run_one(SilcClient client);
607 /****f* silcclient/SilcClientAPI/silc_client_stop
611 * void silc_client_stop(SilcClient client);
615 * Stops the client. This is called to stop the client and thus to stop
616 * the program. The client context must be freed with the silc_client_free
620 void silc_client_stop(SilcClient client);
623 /* Connecting functions (client.c) */
625 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
629 * typedef struct { ... } SilcClientConnectionParams;
633 * Client connection parameters. This can be filled by the application
634 * and given as argument to silc_client_connect_to_server or to
635 * silc_client_add_connection.
640 /* The SILC session detachment data that was returned by `detach' client
641 operation when the application detached from the network. Application
642 is responsible of saving the data and giving it as argument here
643 for resuming the session in the SILC network. */
644 unsigned char *detach_data;
645 SilcUInt32 detach_data_len;
647 } SilcClientConnectionParams;
650 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
654 * int silc_client_connect_to_server(SilcClient client,
655 * SilcClientConnectionParams *params,
656 * int port, char *host, void *context);
660 * Connects to remote server. This is the main routine used to connect
661 * to SILC server. Returns -1 on error and the created socket otherwise.
662 * The `context' is user context that is saved into the SilcClientConnection
663 * that is created after the connection is created. Note that application
664 * may handle the connecting process outside the library. If this is the
665 * case then this function is not used at all. When the connecting is
666 * done the `connect' client operation is called, and the `context' is
667 * accessible with conn->context, conn being SilcClientConnection.
668 * If the `params' is provided they are used by the routine.
671 int silc_client_connect_to_server(SilcClient client,
672 SilcClientConnectionParams *params,
673 int port, char *host, void *context);
675 /****f* silcclient/SilcClientAPI/silc_client_add_connection
680 * SilcClientConnection
681 * silc_client_add_connection(SilcClient client,
682 * SilcClientConnectionParams *params,
683 * char *hostname, int port, void *context);
687 * Allocates and adds new connection to the client. This adds the allocated
688 * connection to the connection table and returns a pointer to it. A client
689 * can have multiple connections to multiple servers. Every connection must
690 * be added to the client using this function. User data `context' may
691 * be sent as argument. If the `params' is provided they are used by
696 * This function is normally used only if the application performed
697 * the connecting outside the library, and did not called the
698 * silc_client_connect_to_server function at all. The library
699 * however may use this internally.
703 silc_client_add_connection(SilcClient client,
704 SilcClientConnectionParams *params,
705 char *hostname, int port, void *context);
707 /****f* silcclient/SilcClientAPI/silc_client_del_connection
711 * void silc_client_del_connection(SilcClient client,
712 * SilcClientConnection conn);
716 * Removes connection from client. Frees all memory. The library
717 * call this function automatically for all connection contexts.
718 * The application however may free the connection contexts it has
722 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
724 /****f* silcclient/SilcClientAPI/silc_client_add_socket
728 * void silc_client_add_socket(SilcClient client,
729 * SilcSocketConnection sock);
733 * Adds listener socket to the listener sockets table. This function is
734 * used to add socket objects that are listeners to the client. This should
735 * not be used to add other connection objects.
738 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
740 /****f* silcclient/SilcClientAPI/silc_client_del_socket
744 * void silc_client_del_socket(SilcClient client,
745 * SilcSocketConnection sock);
749 * Deletes listener socket from the listener sockets table. If the
750 * application has added a socket with silc_client_add_socket it must
751 * also free it using this function.
754 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
756 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
760 * void silc_client_start_key_exchange(SilcClient client,
761 * SilcClientConnection conn,
766 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
767 * key material between client and server. This function can be called
768 * directly if application is performing its own connecting and does not
769 * use the connecting provided by this library. This function is normally
770 * used only if the application performed the connecting outside the
771 * library. The library however may use this internally. After the
772 * key exchange is performed the `connect' client operation is called.
775 void silc_client_start_key_exchange(SilcClient client,
776 SilcClientConnection conn,
779 /****f* silcclient/SilcClientAPI/silc_client_close_connection
783 * void silc_client_close_connection(SilcClient client,
784 * SilcClientConnection conn);
788 * Closes connection to remote end. Free's all allocated data except
789 * for some information such as nickname etc. that are valid at all time.
792 void silc_client_close_connection(SilcClient client,
793 SilcClientConnection conn);
796 /* Message sending functions (client_channel.c and client_prvmsg.c) */
798 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
802 * void silc_client_send_channel_message(SilcClient client,
803 * SilcClientConnection conn,
804 * SilcChannelEntry channel,
805 * SilcChannelPrivateKey key,
806 * SilcMessageFlags flags,
807 * unsigned char *data,
808 * SilcUInt32 data_len,
813 * Sends packet to the `channel'. Packet to channel is always encrypted
814 * differently from "normal" packets. SILC header of the packet is
815 * encrypted with the next receiver's key and the rest of the packet is
816 * encrypted with the channel specific key. Padding and HMAC is computed
817 * with the next receiver's key. The `data' is the channel message. If
818 * the `force_send' is TRUE then the packet is sent immediately.
820 * If `key' is provided then that private key is used to encrypt the
821 * channel message. If it is not provided, private keys has not been
822 * set at all, the normal channel key is used automatically. If private
823 * keys are set then the first key (the key that was added first as
824 * private key) is used.
827 void silc_client_send_channel_message(SilcClient client,
828 SilcClientConnection conn,
829 SilcChannelEntry channel,
830 SilcChannelPrivateKey key,
831 SilcMessageFlags flags,
836 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
840 * void silc_client_send_private_message(SilcClient client,
841 * SilcClientConnection conn,
842 * SilcClientEntry client_entry,
843 * SilcMessageFlags flags,
844 * unsigned char *data,
845 * SilcUInt32 data_len,
850 * Sends private message to remote client. If private message key has
851 * not been set with this client then the message will be encrypted using
852 * normal session keys. Private messages are special packets in SILC
853 * network hence we need this own function for them. This is similar
854 * to silc_client_packet_send_to_channel except that we send private
855 * message. The `data' is the private message. If the `force_send' is
856 * TRUE the packet is sent immediately.
859 void silc_client_send_private_message(SilcClient client,
860 SilcClientConnection conn,
861 SilcClientEntry client_entry,
862 SilcMessageFlags flags,
868 /* Client and Channel entry retrieval (idlist.c) */
870 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
874 * typedef void (*SilcGetClientCallback)(SilcClient client,
875 * SilcClientConnection conn,
876 * SilcClientEntry *clients,
877 * SilcUInt32 clients_count,
882 * Callback function given to the silc_client_get_client function. The
883 * found entries are allocated into the `clients' array. The array must
884 * not be freed by the receiver, the library will free it later. If the
885 * `clients' is NULL, no such clients exist in the SILC Network.
888 typedef void (*SilcGetClientCallback)(SilcClient client,
889 SilcClientConnection conn,
890 SilcClientEntry *clients,
891 SilcUInt32 clients_count,
894 /****f* silcclient/SilcClientAPI/silc_client_get_clients
898 * void silc_client_get_clients(SilcClient client,
899 * SilcClientConnection conn,
900 * const char *nickname,
901 * const char *server,
902 * SilcGetClientCallback completion,
907 * Finds client entry or entries by the `nickname' and `server'. The
908 * completion callback will be called when the client entries has been
909 * found. After the server returns the client information it is cached
910 * and can be accesses locally at a later time.
914 * NOTE: This function is always asynchronous and resolves the client
915 * information from the server. Thus, if you already know the client
916 * information then use the silc_client_get_client_by_id function to
917 * get the client entry since this function may be very slow and should
918 * be used only to initially get the client entries.
921 void silc_client_get_clients(SilcClient client,
922 SilcClientConnection conn,
923 const char *nickname,
925 SilcGetClientCallback completion,
928 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
932 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
933 * SilcClientConnection conn,
934 * const char *nickname,
935 * const char *format,
936 * SilcUInt32 *clients_count);
940 * Same as silc_client_get_clients function but does not resolve anything
941 * from the server. This checks local cache and returns all matching
942 * clients from the local cache. If none was found this returns NULL.
943 * The `nickname' is the real nickname of the client, and the `format'
944 * is the formatted nickname to find exact match from multiple found
945 * entries. The format must be same as given in the SilcClientParams
946 * structure to the client library. If the `format' is NULL all found
947 * clients by `nickname' are returned. The caller must return the
951 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
952 SilcClientConnection conn,
953 const char *nickname,
955 SilcUInt32 *clients_count);
957 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
961 * void silc_client_get_clients_by_list(SilcClient client,
962 * SilcClientConnection conn,
963 * SilcUInt32 list_count,
964 * SilcBuffer client_id_list,
965 * SilcGetClientCallback completion,
970 * Gets client entries by the list of client ID's `client_id_list'. This
971 * always resolves those client ID's it does not know yet from the server
972 * so this function might take a while. The `client_id_list' is a list
973 * of ID Payloads added one after other. JOIN command reply and USERS
974 * command reply for example returns this sort of list. The `completion'
975 * will be called after the entries are available. When server returns
976 * the client information it will be cached and can be accessed locally
980 void silc_client_get_clients_by_list(SilcClient client,
981 SilcClientConnection conn,
982 SilcUInt32 list_count,
983 SilcBuffer client_id_list,
984 SilcGetClientCallback completion,
987 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
991 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
992 * SilcClientConnection conn,
993 * SilcClientID *client_id);
997 * Find entry for client by the client's ID. Returns the entry or NULL
998 * if the entry was not found. This checks the local cache and does
999 * not resolve anything from server.
1002 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1003 SilcClientConnection conn,
1004 SilcClientID *client_id);
1006 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1011 * silc_client_get_client_by_id_resolve(SilcClient client,
1012 * SilcClientConnection conn,
1013 * SilcClientID *client_id,
1014 * SilcGetClientCallback completion,
1019 * Same as silc_client_get_client_by_id but will always resolve the
1020 * information from the server. Use this only if you know that you
1021 * do not have the entry and the only thing you know about the client
1022 * is its ID. When server returns the client information it will be
1023 * cache and can be accessed locally at a later time.
1026 void silc_client_get_client_by_id_resolve(SilcClient client,
1027 SilcClientConnection conn,
1028 SilcClientID *client_id,
1029 SilcGetClientCallback completion,
1032 /****f* silcclient/SilcClientAPI/silc_client_del_client
1036 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1037 * SilcClientEntry client_entry)
1041 * Removes client from local cache by the client entry indicated by
1042 * the `client_entry'. Returns TRUE if the deletion were successful.
1045 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1046 SilcClientEntry client_entry);
1048 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1052 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1053 * SilcClientConnection conn,
1054 * SilcChannelEntry *channels,
1055 * SilcUInt32 channels_count,
1060 * Callback function given to the silc_client_get_channel_* functions.
1061 * The found entries are allocated into the `channels' array. The array
1062 * must not be freed by the receiver, the library will free it later.
1063 * If the `channel' is NULL, no such channel exist in the SILC Network.
1066 typedef void (*SilcGetChannelCallback)(SilcClient client,
1067 SilcClientConnection conn,
1068 SilcChannelEntry *channels,
1069 SilcUInt32 channels_count,
1072 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1076 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1077 * SilcClientConnection conn,
1082 * Finds entry for channel by the channel name. Returns the entry or NULL
1083 * if the entry was not found. It is found only if the client is joined
1087 SilcChannelEntry silc_client_get_channel(SilcClient client,
1088 SilcClientConnection conn,
1091 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1096 * silc_client_get_channel_by_id_resolve(SilcClient client,
1097 * SilcClientConnection conn,
1098 * SilcChannelID *channel_id,
1099 * SilcGetClientCallback completion,
1104 * Finds channel entry by the channel name. Returns the entry or NULL
1105 * if it was not found.
1108 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1109 SilcClientConnection conn,
1110 SilcChannelID *channel_id);
1112 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1117 * silc_client_get_channel_by_id_resolve(SilcClient client,
1118 * SilcClientConnection conn,
1119 * SilcChannelID *channel_id,
1120 * SilcGetClientCallback completion,
1125 * Resolves the channel information (its name mainly) from the server
1126 * by the `channel_id'. Use this only if you know that you do not have
1127 * the entry cached locally.
1130 void silc_client_get_channel_by_id_resolve(SilcClient client,
1131 SilcClientConnection conn,
1132 SilcChannelID *channel_id,
1133 SilcGetChannelCallback completion,
1136 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1140 * bool silc_client_del_channel(SilcClient client,
1141 * SilcClientConnection conn,
1142 * SilcChannelEntry channel)
1146 * Removes channel from local cache by the channel entry indicated by
1147 * the `channel'. Returns TRUE if the deletion were successful.
1150 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1151 SilcChannelEntry channel);
1153 /****f* silcclient/SilcClientAPI/silc_client_get_server
1157 * SilcServerEntry silc_client_get_server(SilcClient client,
1158 * SilcClientConnection conn,
1159 * char *server_name)
1163 * Finds entry for server by the server name. Returns the entry or NULL
1164 * if the entry was not found.
1167 SilcServerEntry silc_client_get_server(SilcClient client,
1168 SilcClientConnection conn,
1171 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1175 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1176 * SilcClientConnection conn,
1177 * SilcServerID *server_id);
1181 * Finds entry for server by the server ID. Returns the entry or NULL
1182 * if the entry was not found.
1185 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1186 SilcClientConnection conn,
1187 SilcServerID *server_id);
1189 /****f* silcclient/SilcClientAPI/silc_client_del_server
1193 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1194 * SilcServerEntry server);
1198 * Removes server from local cache by the server entry indicated by
1199 * the `server'. Returns TRUE if the deletion were successful.
1202 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1203 SilcServerEntry server);
1205 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1209 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1210 * SilcClientEntry client_entry);
1214 * Returns the ChannelUser entry if the `client_entry' is joined on the
1215 * channel indicated by the `channel'. NULL if client is not joined on
1219 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1220 SilcClientEntry client_entry);
1222 /* Command management (command.c) */
1224 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1228 * SilcClientCommandContext silc_client_command_alloc(void);
1232 * Allocate Command Context. The context is defined in `command.h' file.
1233 * The context is used by the library commands and applications should use
1234 * it as well. However, application may choose to use some own context
1235 * for its local commands. All library commands, however, must use this
1239 SilcClientCommandContext silc_client_command_alloc(void);
1241 /****f* silcclient/SilcClientAPI/silc_client_command_free
1245 * void silc_client_command_free(SilcClientCommandContext ctx);
1249 * Free command context and its internals. If the contex was duplicated
1250 * with silc_client_command_dup this may not actually free the data,
1251 * instead it will decrease the reference counter of the context. The
1252 * context will be freed when the reference counter hits zero.
1255 void silc_client_command_free(SilcClientCommandContext ctx);
1257 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1261 * SilcClientCommandContext
1262 * silc_client_command_dup(SilcClientCommandContext ctx);
1266 * Duplicate Command Context by adding reference counter. The context won't
1267 * be free'd untill it hits zero.
1270 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1272 /****f* silcclient/SilcClientAPI/silc_client_command_find
1276 * SilcClientCommand silc_client_command_find(SilcClient client,
1277 * const char *name);
1281 * Finds and returns a pointer to the command list. Return NULL if the
1282 * command is not found. See the `command.[ch]' for the command list.
1283 * Command names are not case-sensitive.
1286 SilcClientCommand silc_client_command_find(SilcClient client,
1289 /****f* silcclient/SilcClientAPI/silc_client_command_call
1293 * void silc_client_command_call(SilcClientCommand command);
1297 * Calls the command (executes it). Application can call this after
1298 * it has allocated the SilcClientCommandContext with the function
1299 * silc_client_command_alloc and found the command from the client
1300 * library by calling silc_client_command_find. This will execute
1303 * Application can call the command function directly too if it
1304 * wishes to do so. See the command.h for details of the
1305 * SilcClientCommand structure.
1308 void silc_client_command_call(SilcClientCommand command,
1309 SilcClientCommandContext cmd);
1311 /****f* silcclient/SilcClientAPI/silc_client_command_send
1315 * void silc_client_command_send(SilcClient client,
1316 * SilcClientConnection conn,
1317 * SilcCommand command, SilcUInt16 ident,
1318 * SilcUInt32 argc, ...);
1322 * Generic function to send any command. The arguments must be sent already
1323 * encoded into correct form and in correct order. If application wants
1324 * to perform the commands by itself, it can do so and send the data
1325 * directly to the server using this function. If application is using
1326 * the silc_client_command_call, this function is usually not used.
1329 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1330 SilcCommand command, SilcUInt16 ident,
1331 SilcUInt32 argc, ...);
1333 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1337 * void silc_client_command_pending(SilcClientConnection conn,
1338 * SilcCommand reply_cmd,
1340 * SilcCommandCb callback,
1345 * Add new pending command to be executed when reply to a command has been
1346 * received. The `reply_cmd' is the command that will call the `callback'
1347 * with `context' when reply has been received. If `ident' is non-zero
1348 * the `callback' will be executed when received reply with command
1349 * identifier `ident'.
1351 * Note that the application is notified about the received command
1352 * reply through the `command_reply' client operation before calling
1353 * the `callback` pending command callback.
1356 void silc_client_command_pending(SilcClientConnection conn,
1357 SilcCommand reply_cmd,
1359 SilcCommandCb callback,
1363 /* Private Message key management (client_prvmsg.c) */
1365 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1369 * int silc_client_add_private_message_key(SilcClient client,
1370 * SilcClientConnection conn,
1371 * SilcClientEntry client_entry,
1373 * unsigned char *key,
1374 * SilcUInt32 key_len,
1375 * bool generate_key,
1380 * Adds private message key to the client library. The key will be used to
1381 * encrypt all private message between the client and the remote client
1382 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1383 * value `generate_key' is TRUE the library will generate random key.
1384 * The `key' maybe for example pre-shared-key, passphrase or similar.
1385 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1386 * requirements of the SILC protocol are met. The API, however, allows
1387 * to allocate any cipher.
1389 * If `responder' is TRUE then the sending and receiving keys will be
1390 * set according the client being the receiver of the private key. If
1391 * FALSE the client is being the sender (or negotiator) of the private
1394 * It is not necessary to set key for normal private message usage. If the
1395 * key is not set then the private messages are encrypted using normal
1396 * session keys. Setting the private key, however, increases the security.
1398 * Returns FALSE if the key is already set for the `client_entry', TRUE
1402 int silc_client_add_private_message_key(SilcClient client,
1403 SilcClientConnection conn,
1404 SilcClientEntry client_entry,
1411 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1415 * int silc_client_add_private_message_key_ske(SilcClient client,
1416 * SilcClientConnection conn,
1417 * SilcClientEntry client_entry,
1419 * SilcSKEKeyMaterial *key);
1423 * Same as silc_client_add_private_message_key but takes the key material
1424 * from the SKE key material structure. This structure is received if
1425 * the application uses the silc_client_send_key_agreement to negotiate
1426 * the key material. The `cipher' SHOULD be provided as it is negotiated
1427 * also in the SKE protocol.
1430 int silc_client_add_private_message_key_ske(SilcClient client,
1431 SilcClientConnection conn,
1432 SilcClientEntry client_entry,
1434 SilcSKEKeyMaterial *key,
1437 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1441 * int silc_client_send_private_message_key(SilcClient client,
1442 * SilcClientConnection conn,
1443 * SilcClientEntry client_entry,
1448 * Sends private message key payload to the remote client indicated by
1449 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1450 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1451 * application should call this function after setting the key to the
1454 * Note that the key sent using this function is sent to the remote client
1455 * through the SILC network. The packet is protected using normal session
1459 int silc_client_send_private_message_key(SilcClient client,
1460 SilcClientConnection conn,
1461 SilcClientEntry client_entry,
1464 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1468 * int silc_client_del_private_message_key(SilcClient client,
1469 * SilcClientConnection conn,
1470 * SilcClientEntry client_entry);
1474 * Removes the private message from the library. The key won't be used
1475 * after this to protect the private messages with the remote `client_entry'
1476 * client. Returns FALSE on error, TRUE otherwise.
1479 int silc_client_del_private_message_key(SilcClient client,
1480 SilcClientConnection conn,
1481 SilcClientEntry client_entry);
1483 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1487 * SilcPrivateMessageKeys
1488 * silc_client_list_private_message_keys(SilcClient client,
1489 * SilcClientConnection conn,
1490 * SilcUInt32 *key_count);
1494 * Returns array of set private message keys associated to the connection
1495 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1496 * count to the `key_count' argument. The array must be freed by the caller
1497 * by calling the silc_client_free_private_message_keys function. Note:
1498 * the keys returned in the array is in raw format. It might not be desired
1499 * to show the keys as is. The application might choose not to show the keys
1500 * at all or to show the fingerprints of the keys.
1503 SilcPrivateMessageKeys
1504 silc_client_list_private_message_keys(SilcClient client,
1505 SilcClientConnection conn,
1506 SilcUInt32 *key_count);
1508 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1512 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1513 * SilcUInt32 key_count);
1517 * Frees the SilcPrivateMessageKeys array returned by the function
1518 * silc_client_list_private_message_keys.
1521 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1522 SilcUInt32 key_count);
1525 /* Channel private key management (client_channel.c,
1526 SilcChannelPrivateKey is defined in idlist.h) */
1528 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1532 * int silc_client_add_channel_private_key(SilcClient client,
1533 * SilcClientConnection conn,
1534 * SilcChannelEntry channel,
1538 * unsigned char *key,
1539 * SilcUInt32 key_len);
1543 * Adds private key for channel. This may be set only if the channel's mode
1544 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1545 * mode is not set. When channel has private key then the messages are
1546 * encrypted using that key. All clients on the channel must also know the
1547 * key in order to decrypt the messages. However, it is possible to have
1548 * several private keys per one channel. In this case only some of the
1549 * clients on the channel may know the one key and only some the other key.
1550 * The `name' can be application given name for the key.
1552 * The private key for channel is optional. If it is not set then the
1553 * channel messages are encrypted using the channel key generated by the
1554 * server. However, setting the private key (or keys) for the channel
1555 * significantly adds security. If more than one key is set the library
1556 * will automatically try all keys at the message decryption phase. Note:
1557 * setting many keys slows down the decryption phase as all keys has to
1558 * be tried in order to find the correct decryption key. However, setting
1559 * a few keys does not have big impact to the decryption performace.
1563 * NOTE: This is entirely local setting. The key set using this function
1564 * is not sent to the network at any phase.
1566 * NOTE: If the key material was originated by the SKE protocol (using
1567 * silc_client_send_key_agreement) then the `key' MUST be the
1568 * key->send_enc_key as this is dictated by the SILC protocol. However,
1569 * currently it is not expected that the SKE key material would be used
1570 * as channel private key. However, this API allows it.
1573 int silc_client_add_channel_private_key(SilcClient client,
1574 SilcClientConnection conn,
1575 SilcChannelEntry channel,
1580 SilcUInt32 key_len);
1582 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1586 * int silc_client_del_channel_private_keys(SilcClient client,
1587 * SilcClientConnection conn,
1588 * SilcChannelEntry channel);
1592 * Removes all private keys from the `channel'. The old channel key is used
1593 * after calling this to protect the channel messages. Returns FALSE on
1594 * on error, TRUE otherwise.
1597 int silc_client_del_channel_private_keys(SilcClient client,
1598 SilcClientConnection conn,
1599 SilcChannelEntry channel);
1601 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1605 * int silc_client_del_channel_private_key(SilcClient client,
1606 * SilcClientConnection conn,
1607 * SilcChannelEntry channel,
1608 * SilcChannelPrivateKey key);
1612 * Removes and frees private key `key' from the channel `channel'.
1613 * The `key' is retrieved by calling the function
1614 * silc_client_list_channel_private_keys. The key is not used after
1615 * this. If the key was last private key then the old channel key is
1616 * used hereafter to protect the channel messages. This returns FALSE
1617 * on error, TRUE otherwise.
1620 int silc_client_del_channel_private_key(SilcClient client,
1621 SilcClientConnection conn,
1622 SilcChannelEntry channel,
1623 SilcChannelPrivateKey key);
1625 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1629 * SilcChannelPrivateKey *
1630 * silc_client_list_channel_private_keys(SilcClient client,
1631 * SilcClientConnection conn,
1632 * SilcChannelEntry channel,
1633 * SilcUInt32 *key_count);
1637 * Returns array (pointers) of private keys associated to the `channel'.
1638 * The caller must free the array by calling the function
1639 * silc_client_free_channel_private_keys. The pointers in the array may be
1640 * used to delete the specific key by giving the pointer as argument to the
1641 * function silc_client_del_channel_private_key.
1644 SilcChannelPrivateKey *
1645 silc_client_list_channel_private_keys(SilcClient client,
1646 SilcClientConnection conn,
1647 SilcChannelEntry channel,
1648 SilcUInt32 *key_count);
1650 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1654 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1655 * SilcUInt32 key_count);
1659 * Frees the SilcChannelPrivateKey array.
1662 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1663 SilcUInt32 key_count);
1665 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1669 * void silc_client_current_channel_private_key(SilcClient client,
1670 * SilcClientConnection conn,
1671 * SilcChannelEntry channel,
1672 * SilcChannelPrivateKey key);
1676 * Sets the `key' to be used as current channel private key on the
1677 * `channel'. Packet sent after calling this function will be secured
1681 void silc_client_current_channel_private_key(SilcClient client,
1682 SilcClientConnection conn,
1683 SilcChannelEntry channel,
1684 SilcChannelPrivateKey key);
1687 /* Key Agreement routines (client_keyagr.c) */
1689 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1693 * void silc_client_send_key_agreement(SilcClient client,
1694 * SilcClientConnection conn,
1695 * SilcClientEntry client_entry,
1698 * SilcUInt32 timeout_secs,
1699 * SilcKeyAgreementCallback completion,
1704 * Sends key agreement request to the remote client indicated by the
1705 * `client_entry'. If the caller provides the `hostname' and the `port'
1706 * arguments then the library will bind the client to that hostname and
1707 * that port for the key agreement protocol. It also sends the `hostname'
1708 * and the `port' in the key agreement packet to the remote client. This
1709 * would indicate that the remote client may initiate the key agreement
1710 * protocol to the `hostname' on the `port'. If port is zero then the
1711 * bound port is undefined (the operating system defines it).
1713 * If the `hostname' and `port' is not provided then empty key agreement
1714 * packet is sent to the remote client. The remote client may reply with
1715 * the same packet including its hostname and port. If the library receives
1716 * the reply from the remote client the `key_agreement' client operation
1717 * callback will be called to verify whether the user wants to perform the
1718 * key agreement or not.
1722 * NOTE: If the application provided the `hostname' and the `port' and the
1723 * remote side initiates the key agreement protocol it is not verified
1724 * from the user anymore whether the protocol should be executed or not.
1725 * By setting the `hostname' and `port' the user gives permission to
1726 * perform the protocol (we are responder in this case).
1728 * NOTE: If the remote side decides not to initiate the key agreement
1729 * or decides not to reply with the key agreement packet then we cannot
1730 * perform the key agreement at all. If the key agreement protocol is
1731 * performed the `completion' callback with the `context' will be called.
1732 * If remote side decides to ignore the request the `completion' will be
1733 * called after the specified timeout, `timeout_secs'.
1735 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1736 * will not be called at all since this does nothing more than sending
1737 * a packet to the remote host.
1739 * NOTE: There can be only one active key agreement for one client entry.
1740 * Before setting new one, the old one must be finished (it is finished
1741 * after calling the completion callback) or the function
1742 * silc_client_abort_key_agreement must be called.
1745 void silc_client_send_key_agreement(SilcClient client,
1746 SilcClientConnection conn,
1747 SilcClientEntry client_entry,
1748 const char *hostname,
1749 const char *bindhost,
1751 SilcUInt32 timeout_secs,
1752 SilcKeyAgreementCallback completion,
1755 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1760 * silc_client_perform_key_agreement(SilcClient client,
1761 * SilcClientConnection conn,
1762 * SilcClientEntry client_entry,
1765 * SilcKeyAgreementCallback completion,
1770 * Performs the actual key agreement protocol. Application may use this
1771 * to initiate the key agreement protocol. This can be called for example
1772 * after the application has received the `key_agreement' client operation,
1773 * and did not return TRUE from it.
1775 * The `hostname' is the remote hostname (or IP address) and the `port'
1776 * is the remote port. The `completion' callback with the `context' will
1777 * be called after the key agreement protocol.
1781 * NOTE: If the application returns TRUE in the `key_agreement' client
1782 * operation the library will automatically start the key agreement. In this
1783 * case the application must not call this function. However, application
1784 * may choose to just ignore the `key_agreement' client operation (and
1785 * merely just print information about it on the screen) and call this
1786 * function when the user whishes to do so (by, for example, giving some
1787 * specific command). Thus, the API provides both, automatic and manual
1788 * initiation of the key agreement. Calling this function is the manual
1789 * initiation and returning TRUE in the `key_agreement' client operation
1790 * is the automatic initiation.
1793 void silc_client_perform_key_agreement(SilcClient client,
1794 SilcClientConnection conn,
1795 SilcClientEntry client_entry,
1798 SilcKeyAgreementCallback completion,
1801 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1806 * silc_client_perform_key_agreement_fd(SilcClient client,
1807 * SilcClientConnection conn,
1808 * SilcClientEntry client_entry,
1811 * SilcKeyAgreementCallback completion,
1816 * Same as above but application has created already the connection to
1817 * the remote host. The `sock' is the socket to the remote connection.
1818 * Application can use this function if it does not want the client library
1819 * to create the connection.
1822 void silc_client_perform_key_agreement_fd(SilcClient client,
1823 SilcClientConnection conn,
1824 SilcClientEntry client_entry,
1827 SilcKeyAgreementCallback completion,
1830 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1834 * void silc_client_abort_key_agreement(SilcClient client,
1835 * SilcClientConnection conn,
1836 * SilcClientEntry client_entry);
1840 * This function can be called to unbind the hostname and the port for
1841 * the key agreement protocol. However, this function has effect only
1842 * before the key agreement protocol has been performed. After it has
1843 * been performed the library will automatically unbind the port. The
1844 * `client_entry' is the client to which we sent the key agreement
1845 * request. The key agreement completion callback will be called
1846 * with SILC_KEY_AGREEMENT_ABORTED status.
1849 void silc_client_abort_key_agreement(SilcClient client,
1850 SilcClientConnection conn,
1851 SilcClientEntry client_entry);
1854 /* Misc functions */
1856 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1860 * void silc_client_set_away_message(SilcClient client,
1861 * SilcClientConnection conn,
1866 * Sets away `message'. The away message may be set when the client's
1867 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1868 * to anyone who sends private message. The `message' will be sent
1869 * automatically back to the the client who send private message. If
1870 * away message is already set this replaces the old message with the
1871 * new one. If `message' is NULL the old away message is removed.
1872 * The sender may freely free the memory of the `message'.
1875 void silc_client_set_away_message(SilcClient client,
1876 SilcClientConnection conn,
1880 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1884 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1885 * SilcClientConnection conn,
1886 * SilcAuthMethod auth_meth,
1891 * Connection authentication method request callback. This is called
1892 * by the client library after it has received the authentication method
1893 * that the application requested by calling the function
1894 * silc_client_request_authentication_method.
1897 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1898 SilcClientConnection conn,
1899 SilcAuthMethod auth_meth,
1902 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1907 * silc_client_request_authentication_method(SilcClient client,
1908 * SilcClientConnection conn,
1909 * SilcConnectionAuthRequest
1915 * This function can be used to request the current authentication method
1916 * from the server. This may be called when connecting to the server
1917 * and the client library requests the authentication data from the
1918 * application. If the application does not know the current authentication
1919 * method it can request it from the server using this function.
1920 * The `callback' with `context' will be called after the server has
1921 * replied back with the current authentication method.
1925 silc_client_request_authentication_method(SilcClient client,
1926 SilcClientConnection conn,
1927 SilcConnectionAuthRequest callback,
1930 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1934 * typedef enum { ... } SilcClientMonitorStatus;
1938 * File transmission session status types. These will indicate
1939 * the status of the file transmission session.
1944 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1945 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1946 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1947 SILC_CLIENT_FILE_MONITOR_GET,
1948 SILC_CLIENT_FILE_MONITOR_PUT,
1949 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1950 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1951 } SilcClientMonitorStatus;
1954 /****d* silcclient/SilcClientAPI/SilcClientFileError
1958 * typedef enum { ... } SilcClientFileError;
1962 * File transmission error types. These types are returned by
1963 * some of the file transmission functions, and by the monitor
1964 * callback to indicate error.
1969 SILC_CLIENT_FILE_OK,
1970 SILC_CLIENT_FILE_ERROR,
1971 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1972 SILC_CLIENT_FILE_ALREADY_STARTED,
1973 SILC_CLIENT_FILE_NO_SUCH_FILE,
1974 SILC_CLIENT_FILE_PERMISSION_DENIED,
1975 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1976 } SilcClientFileError;
1979 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1983 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1984 * SilcClientConnection conn,
1985 * SilcClientMonitorStatus status,
1986 * SilcClientFileError error,
1987 * SilcUInt64 offset,
1988 * SilcUInt64 filesize,
1989 * SilcClientEntry client_entry,
1990 * SilcUInt32 session_id,
1991 * const char *filepath,
1996 * Monitor callback that is called during the file transmission to
1997 * monitor the transmission process. The `status' indicates the current
1998 * monitoring process. The `error' will indicate the error type
1999 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2000 * currently transmitted amount of total `filesize'. The `client_entry'
2001 * indicates the remote client, and the transmission session ID is the
2002 * `session_id'. The filename being transmitted is indicated by the
2006 typedef void (*SilcClientFileMonitor)(SilcClient client,
2007 SilcClientConnection conn,
2008 SilcClientMonitorStatus status,
2009 SilcClientFileError error,
2011 SilcUInt64 filesize,
2012 SilcClientEntry client_entry,
2013 SilcUInt32 session_id,
2014 const char *filepath,
2017 /****f* silcclient/SilcClientAPI/silc_client_file_send
2021 * SilcClientFileError
2022 * silc_client_file_send(SilcClient client,
2023 * SilcClientConnection conn,
2024 * SilcClientFileMonitor monitor,
2025 * void *monitor_context,
2026 * const char *local_ip,
2027 * SilcUInt32 local_port,
2028 * SilcClientEntry client_entry,
2029 * const char *filepath);
2030 * SilcUInt32 *session_id);
2034 * Sends a file indicated by the `filepath' to the remote client
2035 * indicated by the `client_entry'. This will negotiate a secret key
2036 * with the remote client before actually starting the transmission of
2037 * the file. The `monitor' callback will be called to monitor the
2038 * transmission of the file.
2040 * This returns a file session ID for the file transmission to the
2041 * `session_id' pointer.. It can be used to close the session (and
2042 * abort the file transmission) by calling the silc_client_file_close
2043 * function. The session ID is also returned in the `monitor' callback.
2045 * If the `local_ip' is provided then this will try to bind the
2046 * listener for key exchange protocol to that IP. If `local_port' is
2047 * non-zero that port is used. If `local_ip' is NULL then this will
2048 * automatically attempt to bind it to local IP address of the machine.
2049 * If that fails then this does not bind to any address and port, and
2050 * assume that the remote client will provide the listener for the
2051 * key exchange protocol.
2053 * If error will occur during the file transfer process the error
2054 * status will be returned in the monitor callback. In this case
2055 * the application must call silc_client_file_close to close the
2060 silc_client_file_send(SilcClient client,
2061 SilcClientConnection conn,
2062 SilcClientFileMonitor monitor,
2063 void *monitor_context,
2064 const char *local_ip,
2065 SilcUInt32 local_port,
2066 SilcClientEntry client_entry,
2067 const char *filepath,
2068 SilcUInt32 *session_id);
2070 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2074 * SilcClientFileError
2075 * silc_client_file_receive(SilcClient client,
2076 * SilcClientConnection conn,
2077 * SilcClientFileMonitor monitor,
2078 * void *monitor_context,
2079 * SilcUInt32 session_id);
2083 * Receives a file from a client indicated by the `client_entry'. The
2084 * `session_id' indicates the file transmission session and it has been
2085 * received in the `ftp' client operation function. This will actually
2086 * perform the key agreement protocol with the remote client before
2087 * actually starting the file transmission. The `monitor' callback
2088 * will be called to monitor the transmission.
2090 * If error will occur during the file transfer process the error
2091 * status will be returned in the monitor callback. In this case
2092 * the application must call silc_client_file_close to close the
2097 silc_client_file_receive(SilcClient client,
2098 SilcClientConnection conn,
2099 SilcClientFileMonitor monitor,
2100 void *monitor_context,
2101 SilcUInt32 session_id);
2103 /****f* silcclient/SilcClientAPI/silc_client_file_close
2107 * SilcClientFileError silc_client_file_close(SilcClient client,
2108 * SilcClientConnection conn,
2109 * SilcUInt32 session_id);
2113 * Closes file transmission session indicated by the `session_id'.
2114 * If file transmission is being conducted it will be aborted
2115 * automatically. This function is also used to close the session
2116 * after successful file transmission. This function can be used
2117 * also to reject incoming file transmission request.
2120 SilcClientFileError silc_client_file_close(SilcClient client,
2121 SilcClientConnection conn,
2122 SilcUInt32 session_id);
2125 #include "command.h"
2126 #include "command_reply.h"
2128 #include "protocol.h"
2134 #endif /* SILCCLIENT_H */