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.
189 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
190 SilcUInt32 passphrase_len,
193 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
197 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
201 * Public key (or certificate) verification callback. This is called
202 * by the application to indicate that the public key verification was
203 * either success or failure.
206 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
208 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
212 * typedef void (*SilcGetAuthMeth)(bool success,
213 * SilcProtocolAuthMeth auth_meth,
214 * const unsigned char *auth_data,
215 * SilcUInt32 auth_data_len, void *context);
219 * Authentication method resolving callback. This is called by the
220 * application to return the resolved authentication method. The client
221 * library has called the get_auth_method client operation and given
222 * this function pointer as argument. The `success' will indicate whether
223 * the authentication method could be resolved. The `auth_meth' is the
224 * resolved authentication method. The `auth_data' and the `auth_data_len'
225 * are the resolved authentication data. The `context' is the libary's
226 * context sent to the get_auth_method client operation.
229 typedef void (*SilcGetAuthMeth)(bool success,
230 SilcProtocolAuthMeth auth_meth,
231 const unsigned char *auth_data,
232 SilcUInt32 auth_data_len, void *context);
234 /****d* silcclient/SilcClientAPI/SilcClientMessageType
238 * typedef enum { ... } SilcClientMessageType;
242 * Different message types for `say' client operation. The application
243 * may filter the message sent by the library according this type.
248 SILC_CLIENT_MESSAGE_INFO, /* Informational */
249 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
250 SILC_CLIENT_MESSAGE_ERROR, /* Error */
251 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
252 } SilcClientMessageType;
255 /****s* silcclient/SilcClientAPI/SilcClientOperations
259 * typedef struct { ... } SilcClientOperations;
263 * SILC Client Operations. These must be implemented by the application.
264 * The Client library may call any of these routines at any time. The
265 * routines are used to deliver certain information to the application
266 * or from the application to the client library.
271 /* Message sent to the application by library. `conn' associates the
272 message to a specific connection. `conn', however, may be NULL.
273 The `type' indicates the type of the message sent by the library.
274 The applicationi can for example filter the message according the
276 void (*say)(SilcClient client, SilcClientConnection conn,
277 SilcClientMessageType type, char *msg, ...);
279 /* Message for a channel. The `sender' is the sender of the message
280 The `channel' is the channel. The `msg' is the message. Note that
282 void (*channel_message)(SilcClient client, SilcClientConnection conn,
283 SilcClientEntry sender, SilcChannelEntry channel,
284 SilcMessageFlags flags, char *msg);
286 /* Private message to the client. The `sender' is the sender of the
288 void (*private_message)(SilcClient client, SilcClientConnection conn,
289 SilcClientEntry sender, SilcMessageFlags flags,
292 /* Notify message to the client. The notify arguments are sent in the
293 same order as servers sends them. The arguments are same as received
294 from the server except for ID's. If ID is received application receives
295 the corresponding entry to the ID. For example, if Client ID is received
296 application receives SilcClientEntry. Also, if the notify type is
297 for channel the channel entry is sent to application (even if server
298 does not send it because client library gets the channel entry from
299 the Channel ID in the packet's header). */
300 void (*notify)(SilcClient client, SilcClientConnection conn,
301 SilcNotifyType type, ...);
303 /* Command handler. This function is called always in the command function.
304 If error occurs it will be called as well. `conn' is the associated
305 client connection. `cmd_context' is the command context that was
306 originally sent to the command. `success' is FALSE if error occurred
307 during command. `command' is the command being processed. It must be
308 noted that this is not reply from server. This is merely called just
309 after application has called the command. Just to tell application
310 that the command really was processed. */
311 void (*command)(SilcClient client, SilcClientConnection conn,
312 SilcClientCommandContext cmd_context, int success,
313 SilcCommand command);
315 /* Command reply handler. This function is called always in the command reply
316 function. If error occurs it will be called as well. Normal scenario
317 is that it will be called after the received command data has been parsed
318 and processed. The function is used to pass the received command data to
321 `conn' is the associated client connection. `cmd_payload' is the command
322 payload data received from server and it can be ignored. It is provided
323 if the application would like to re-parse the received command data,
324 however, it must be noted that the data is parsed already by the library
325 thus the payload can be ignored. `success' is FALSE if error occurred.
326 In this case arguments are not sent to the application. The `status' is
327 the command reply status server returned. The `command' is the command
328 reply being processed. The function has variable argument list and each
329 command defines the number and type of arguments it passes to the
330 application (on error they are not sent).
332 The arguments are sent in the same order as servers sends them. The
333 arguments are same as received from the server except for ID's. If
334 ID is received application receives the corresponding entry to the
335 ID. For example, if Client ID is receives application receives
337 void (*command_reply)(SilcClient client, SilcClientConnection conn,
338 SilcCommandPayload cmd_payload, int success,
339 SilcCommand command, SilcCommandStatus status, ...);
341 /* Called to indicate that connection was either successfully established
342 or connecting failed. This is also the first time application receives
343 the SilcClientConnection objecet which it should save somewhere.
344 If the `success' is FALSE the application must always call the function
345 silc_client_close_connection. */
346 void (*connect)(SilcClient client, SilcClientConnection conn, int success);
348 /* Called to indicate that connection was disconnected to the server. */
349 void (*disconnect)(SilcClient client, SilcClientConnection conn);
351 /* Find authentication method and authentication data by hostname and
352 port. The hostname may be IP address as well. When the authentication
353 method has been resolved the `completion' callback with the found
354 authentication method and authentication data is called. The `conn'
356 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
357 char *hostname, SilcUInt16 port,
358 SilcGetAuthMeth completion, void *context);
360 /* Verifies received public key. The `conn_type' indicates which entity
361 (server, client etc.) has sent the public key. If user decides to trust
362 the key may be saved as trusted public key for later use. The
363 `completion' must be called after the public key has been verified. */
364 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
365 SilcSocketType conn_type, unsigned char *pk,
366 SilcUInt32 pk_len, SilcSKEPKType pk_type,
367 SilcVerifyPublicKey completion, void *context);
369 /* Ask (interact, that is) a passphrase from user. The passphrase is
370 returned to the library by calling the `completion' callback with
372 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
373 SilcAskPassphrase completion, void *context);
375 /* Notifies application that failure packet was received. This is called
376 if there is some protocol active in the client. The `protocol' is the
377 protocol context. The `failure' is opaque pointer to the failure
378 indication. Note, that the `failure' is protocol dependant and
379 application must explicitly cast it to correct type. Usually `failure'
380 is 32 bit failure type (see protocol specs for all protocol failure
382 void (*failure)(SilcClient client, SilcClientConnection conn,
383 SilcProtocol protocol, void *failure);
385 /* Asks whether the user would like to perform the key agreement protocol.
386 This is called after we have received an key agreement packet or an
387 reply to our key agreement packet. This returns TRUE if the user wants
388 the library to perform the key agreement protocol and FALSE if it is not
389 desired (application may start it later by calling the function
390 silc_client_perform_key_agreement). If TRUE is returned also the
391 `completion' and `context' arguments must be set by the application. */
392 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
393 SilcClientEntry client_entry, const char *hostname,
394 SilcUInt16 port, SilcKeyAgreementCallback *completion,
397 /* Notifies application that file transfer protocol session is being
398 requested by the remote client indicated by the `client_entry' from
399 the `hostname' and `port'. The `session_id' is the file transfer
400 session and it can be used to either accept or reject the file
401 transfer request, by calling the silc_client_file_receive or
402 silc_client_file_close, respectively. */
403 void (*ftp)(SilcClient client, SilcClientConnection conn,
404 SilcClientEntry client_entry, SilcUInt32 session_id,
405 const char *hostname, SilcUInt16 port);
406 } SilcClientOperations;
409 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
413 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
414 * char **ret_nickname);
418 * A callback function provided by the application for the library in
419 * SilcClientParams structure. This function parses the formatted
420 * nickname string `nickname' and returns the true nickname to the
421 * `ret_nickname' pointer. The library can call this function at
425 typedef void (*SilcNicknameFormatParse)(const char *nickname,
426 char **ret_nickname);
428 /****s* silcclient/SilcClientAPI/SilcClientParams
432 * typedef struct { ... } SilcClientParams;
436 * Client parameters. This can be filled with proper values and
437 * given as argument to the silc_client_alloc function. The structure
438 * hold various parameters which affects the function of the client.
443 /* Number of maximum tasks the client library's scheduler can handle.
444 If set to zero, the default value will be used (200). For WIN32
445 systems this should be set to 64 as it is the hard limit dictated
449 /* Rekey timeout in seconds. The client will perform rekey in this
450 time interval. If set to zero, the default value will be used. */
451 unsigned int rekey_secs;
453 /* Connection authentication method request timeout. If server does not
454 reply back the current authentication method when we've requested it
455 in this time interval we'll assume the reply will not come at all.
456 If set to zero, the default value (2 seconds) will be used. */
457 unsigned int connauth_request_secs;
459 /* Nickname format string. This can be used to order the client library
460 to save the nicknames in the library in a certain format. Since
461 nicknames are not unique in SILC it is possible to have multiple same
462 nicknames. Using this format string it is possible to order the library
463 to separate the multiple same nicknames from each other. The format
464 types are defined below and they can appear in any order in the format
465 string. If this is NULL then default format is used which is the
466 default nickname without anything else. The string MUST be NULL
469 Following format types are available:
471 %n nickname - the real nickname returned by the server (mandatory)
472 %h hostname - the stripped hostname of the client
473 %H full hostname - the full hostname of the client
474 %s server name - the server name the client is connected
475 %S full server - the full server name the client is connected
476 %a number - ascending number in case there are several
477 same nicknames (fe. nick@host and nick@host2)
479 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
480 "%a!%n@%s" (fe. nick@server, 2!nick@server)
481 "%n@%H" (fe. nick@host.domain.com)
483 By default this format is employed to the nicknames by the libary
484 only when there appears multiple same nicknames. If the library has
485 only one nickname cached the nickname is saved as is and without the
486 defined format. If you want always to save the nickname in the defined
487 format set the boolean field `nickname_force_format' to value TRUE.
489 char nickname_format[32];
491 /* If this is set to TRUE then the `nickname_format' is employed to all
492 saved nicknames even if there are no multiple same nicknames in the
493 cache. By default this is FALSE, which means that the `nickname_format'
494 is employed only if the library will receive a nickname that is
495 already saved in the cache. It is recommended to leave this to FALSE
497 bool nickname_force_format;
499 /* A callback function provided by the application for the library to
500 parse the nickname from the formatted nickname string. Even though
501 the libary formats the nicknames the application knows generally the
502 format better so this function should be provided for the library
503 if the application sets the `nickname_format' field. The library
504 will call this to get the true nickname from the provided formatted
505 nickname string whenever it needs the true nickname. */
506 SilcNicknameFormatParse nickname_parse;
512 /* Initialization functions (client.c) */
514 /****f* silcclient/SilcClientAPI/silc_client_alloc
518 * SilcClient silc_client_alloc(SilcClientOperations *ops,
519 * SilcClientParams *params,
521 * const char *silc_version);
525 * Allocates new client object. This has to be done before client may
526 * work. After calling this one must call silc_client_init to initialize
527 * the client. The `application' is application specific user data pointer
528 * and caller must free it. The `silc_version' is the application version
529 * that will be used to compare against remote host's (usually a server)
533 SilcClient silc_client_alloc(SilcClientOperations *ops,
534 SilcClientParams *params,
536 const char *silc_version);
538 /****f* silcclient/SilcClientAPI/silc_client_free
542 * void silc_client_free(SilcClient client);
546 * Frees client object and its internals. The execution of the client
547 * should be stopped with silc_client_stop function before calling
551 void silc_client_free(SilcClient client);
553 /****f* silcclient/SilcClientAPI/silc_client_init
557 * int silc_client_init(SilcClient client);
561 * Initializes the client. This makes all the necessary steps to make
562 * the client ready to be run. One must call silc_client_run to run the
563 * client. Returns FALSE if error occurred, TRUE otherwise.
566 int silc_client_init(SilcClient client);
568 /****f* silcclient/SilcClientAPI/silc_client_run
572 * void silc_client_run(SilcClient client);
576 * Runs the client. This starts the scheduler from the utility library.
577 * When this functions returns the execution of the appliation is over.
580 void silc_client_run(SilcClient client);
582 /****f* silcclient/SilcClientAPI/silc_client_run_one
586 * void silc_client_run_one(SilcClient client);
590 * Runs the client and returns immeadiately. This function is used when
591 * the SILC Client object indicated by the `client' is run under some
592 * other scheduler, or event loop or main loop. On GUI applications,
593 * for example this may be desired to used to run the client under the
594 * GUI application's main loop. Typically the GUI application would
595 * register an idle task that calls this function multiple times in
596 * a second to quickly process the SILC specific data.
599 void silc_client_run_one(SilcClient client);
601 /****f* silcclient/SilcClientAPI/silc_client_stop
605 * void silc_client_stop(SilcClient client);
609 * Stops the client. This is called to stop the client and thus to stop
610 * the program. The client context must be freed with the silc_client_free
614 void silc_client_stop(SilcClient client);
617 /* Connecting functions (client.c) */
619 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
623 * int silc_client_connect_to_server(SilcClient client, int port,
624 * char *host, void *context);
628 * Connects to remote server. This is the main routine used to connect
629 * to SILC server. Returns -1 on error and the created socket otherwise.
630 * The `context' is user context that is saved into the SilcClientConnection
631 * that is created after the connection is created. Note that application
632 * may handle the connecting process outside the library. If this is the
633 * case then this function is not used at all. When the connecting is
634 * done the `connect' client operation is called.
637 int silc_client_connect_to_server(SilcClient client, int port,
638 char *host, void *context);
640 /****f* silcclient/SilcClientAPI/silc_client_add_connection
644 * SilcClientConnection silc_client_add_connection(SilcClient client,
651 * Allocates and adds new connection to the client. This adds the allocated
652 * connection to the connection table and returns a pointer to it. A client
653 * can have multiple connections to multiple servers. Every connection must
654 * be added to the client using this function. User data `context' may
655 * be sent as argument. This function is normally used only if the
656 * application performed the connecting outside the library. The library
657 * however may use this internally.
660 SilcClientConnection silc_client_add_connection(SilcClient client,
665 /****f* silcclient/SilcClientAPI/silc_client_del_connection
669 * void silc_client_del_connection(SilcClient client,
670 * SilcClientConnection conn);
674 * Removes connection from client. Frees all memory. The library
675 * call this function automatically for all connection contexts.
676 * The application however may free the connection contexts it has
680 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
682 /****f* silcclient/SilcClientAPI/silc_client_add_socket
686 * void silc_client_add_socket(SilcClient client,
687 * SilcSocketConnection sock);
691 * Adds listener socket to the listener sockets table. This function is
692 * used to add socket objects that are listeners to the client. This should
693 * not be used to add other connection objects.
696 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
698 /****f* silcclient/SilcClientAPI/silc_client_del_socket
702 * void silc_client_del_socket(SilcClient client,
703 * SilcSocketConnection sock);
707 * Deletes listener socket from the listener sockets table. If the
708 * application has added a socket with silc_client_add_socket it must
709 * also free it using this function.
712 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
714 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
718 * void silc_client_start_key_exchange(SilcClient client,
719 * SilcClientConnection conn,
724 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
725 * key material between client and server. This function can be called
726 * directly if application is performing its own connecting and does not
727 * use the connecting provided by this library. This function is normally
728 * used only if the application performed the connecting outside the
729 * library. The library however may use this internally. After the
730 * key exchange is performed the `connect' client operation is called.
733 void silc_client_start_key_exchange(SilcClient client,
734 SilcClientConnection conn,
737 /****f* silcclient/SilcClientAPI/silc_client_close_connection
741 * void silc_client_close_connection(SilcClient client,
742 * SilcSocketConnection sock,
743 * SilcClientConnection conn);
747 * Closes connection to remote end. Free's all allocated data except
748 * for some information such as nickname etc. that are valid at all time.
749 * If the `sock' is NULL then the conn->sock will be used. If `sock' is
750 * provided it will be checked whether the sock and `conn->sock' are the
751 * same (they can be different, ie. a socket can use `conn' as its
752 * connection but `conn->sock' might be actually a different connection
756 void silc_client_close_connection(SilcClient client,
757 SilcSocketConnection sock,
758 SilcClientConnection conn);
761 /* Message sending functions (client_channel.c and client_prvmsg.c) */
763 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
767 * void silc_client_send_channel_message(SilcClient client,
768 * SilcClientConnection conn,
769 * SilcChannelEntry channel,
770 * SilcChannelPrivateKey key,
771 * SilcMessageFlags flags,
772 * unsigned char *data,
773 * SilcUInt32 data_len,
778 * Sends packet to the `channel'. Packet to channel is always encrypted
779 * differently from "normal" packets. SILC header of the packet is
780 * encrypted with the next receiver's key and the rest of the packet is
781 * encrypted with the channel specific key. Padding and HMAC is computed
782 * with the next receiver's key. The `data' is the channel message. If
783 * the `force_send' is TRUE then the packet is sent immediately.
785 * If `key' is provided then that private key is used to encrypt the
786 * channel message. If it is not provided, private keys has not been
787 * set at all, the normal channel key is used automatically. If private
788 * keys are set then the first key (the key that was added first as
789 * private key) is used.
792 void silc_client_send_channel_message(SilcClient client,
793 SilcClientConnection conn,
794 SilcChannelEntry channel,
795 SilcChannelPrivateKey key,
796 SilcMessageFlags flags,
801 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
805 * void silc_client_send_private_message(SilcClient client,
806 * SilcClientConnection conn,
807 * SilcClientEntry client_entry,
808 * SilcMessageFlags flags,
809 * unsigned char *data,
810 * SilcUInt32 data_len,
815 * Sends private message to remote client. If private message key has
816 * not been set with this client then the message will be encrypted using
817 * normal session keys. Private messages are special packets in SILC
818 * network hence we need this own function for them. This is similar
819 * to silc_client_packet_send_to_channel except that we send private
820 * message. The `data' is the private message. If the `force_send' is
821 * TRUE the packet is sent immediately.
824 void silc_client_send_private_message(SilcClient client,
825 SilcClientConnection conn,
826 SilcClientEntry client_entry,
827 SilcMessageFlags flags,
833 /* Client and Channel entry retrieval (idlist.c) */
835 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
839 * typedef void (*SilcGetClientCallback)(SilcClient client,
840 * SilcClientConnection conn,
841 * SilcClientEntry *clients,
842 * SilcUInt32 clients_count,
847 * Callback function given to the silc_client_get_client function. The
848 * found entries are allocated into the `clients' array. The array must
849 * not be freed by the receiver, the library will free it later. If the
850 * `clients' is NULL, no such clients exist in the SILC Network.
853 typedef void (*SilcGetClientCallback)(SilcClient client,
854 SilcClientConnection conn,
855 SilcClientEntry *clients,
856 SilcUInt32 clients_count,
859 /****f* silcclient/SilcClientAPI/silc_client_get_clients
863 * void silc_client_get_clients(SilcClient client,
864 * SilcClientConnection conn,
865 * const char *nickname,
866 * const char *server,
867 * SilcGetClientCallback completion,
872 * Finds client entry or entries by the `nickname' and `server'. The
873 * completion callback will be called when the client entries has been
874 * found. After the server returns the client information it is cached
875 * and can be accesses locally at a later time.
879 * NOTE: This function is always asynchronous and resolves the client
880 * information from the server. Thus, if you already know the client
881 * information then use the silc_client_get_client_by_id function to
882 * get the client entry since this function may be very slow and should
883 * be used only to initially get the client entries.
886 void silc_client_get_clients(SilcClient client,
887 SilcClientConnection conn,
888 const char *nickname,
890 SilcGetClientCallback completion,
893 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
897 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
898 * SilcClientConnection conn,
899 * const char *nickname,
900 * const char *format,
901 * SilcUInt32 *clients_count);
905 * Same as silc_client_get_clients function but does not resolve anything
906 * from the server. This checks local cache and returns all matching
907 * clients from the local cache. If none was found this returns NULL.
908 * The `nickname' is the real nickname of the client, and the `format'
909 * is the formatted nickname to find exact match from multiple found
910 * entries. The format must be same as given in the SilcClientParams
911 * structure to the client library. If the `format' is NULL all found
912 * clients by `nickname' are returned. The caller must return the
916 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
917 SilcClientConnection conn,
918 const char *nickname,
920 SilcUInt32 *clients_count);
922 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
926 * void silc_client_get_clients_by_list(SilcClient client,
927 * SilcClientConnection conn,
928 * SilcUInt32 list_count,
929 * SilcBuffer client_id_list,
930 * SilcGetClientCallback completion,
935 * Gets client entries by the list of client ID's `client_id_list'. This
936 * always resolves those client ID's it does not know yet from the server
937 * so this function might take a while. The `client_id_list' is a list
938 * of ID Payloads added one after other. JOIN command reply and USERS
939 * command reply for example returns this sort of list. The `completion'
940 * will be called after the entries are available. When server returns
941 * the client information it will be cached and can be accessed locally
945 void silc_client_get_clients_by_list(SilcClient client,
946 SilcClientConnection conn,
947 SilcUInt32 list_count,
948 SilcBuffer client_id_list,
949 SilcGetClientCallback completion,
952 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
956 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
957 * SilcClientConnection conn,
958 * SilcClientID *client_id);
962 * Find entry for client by the client's ID. Returns the entry or NULL
963 * if the entry was not found. This checks the local cache and does
964 * not resolve anything from server.
967 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
968 SilcClientConnection conn,
969 SilcClientID *client_id);
971 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
976 * silc_client_get_client_by_id_resolve(SilcClient client,
977 * SilcClientConnection conn,
978 * SilcClientID *client_id,
979 * SilcGetClientCallback completion,
984 * Same as silc_client_get_client_by_id but will always resolve the
985 * information from the server. Use this only if you know that you
986 * do not have the entry and the only thing you know about the client
987 * is its ID. When server returns the client information it will be
988 * cache and can be accessed locally at a later time.
991 void silc_client_get_client_by_id_resolve(SilcClient client,
992 SilcClientConnection conn,
993 SilcClientID *client_id,
994 SilcGetClientCallback completion,
997 /****f* silcclient/SilcClientAPI/silc_client_del_client
1001 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1002 * SilcClientEntry client_entry)
1006 * Removes client from local cache by the client entry indicated by
1007 * the `client_entry'. Returns TRUE if the deletion were successful.
1010 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1011 SilcClientEntry client_entry);
1013 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1017 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1018 * SilcClientConnection conn,
1019 * SilcChannelEntry *channels,
1020 * SilcUInt32 channels_count,
1025 * Callback function given to the silc_client_get_channel_* functions.
1026 * The found entries are allocated into the `channels' array. The array
1027 * must not be freed by the receiver, the library will free it later.
1028 * If the `channel' is NULL, no such channel exist in the SILC Network.
1031 typedef void (*SilcGetChannelCallback)(SilcClient client,
1032 SilcClientConnection conn,
1033 SilcChannelEntry *channels,
1034 SilcUInt32 channels_count,
1037 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1041 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1042 * SilcClientConnection conn,
1047 * Finds entry for channel by the channel name. Returns the entry or NULL
1048 * if the entry was not found. It is found only if the client is joined
1052 SilcChannelEntry silc_client_get_channel(SilcClient client,
1053 SilcClientConnection conn,
1056 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1061 * silc_client_get_channel_by_id_resolve(SilcClient client,
1062 * SilcClientConnection conn,
1063 * SilcChannelID *channel_id,
1064 * SilcGetClientCallback completion,
1069 * Finds channel entry by the channel name. Returns the entry or NULL
1070 * if it was not found.
1073 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1074 SilcClientConnection conn,
1075 SilcChannelID *channel_id);
1077 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1082 * silc_client_get_channel_by_id_resolve(SilcClient client,
1083 * SilcClientConnection conn,
1084 * SilcChannelID *channel_id,
1085 * SilcGetClientCallback completion,
1090 * Resolves the channel information (its name mainly) from the server
1091 * by the `channel_id'. Use this only if you know that you do not have
1092 * the entry cached locally.
1095 void silc_client_get_channel_by_id_resolve(SilcClient client,
1096 SilcClientConnection conn,
1097 SilcChannelID *channel_id,
1098 SilcGetChannelCallback completion,
1101 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1105 * bool silc_client_del_channel(SilcClient client,
1106 * SilcClientConnection conn,
1107 * SilcChannelEntry channel)
1111 * Removes channel from local cache by the channel entry indicated by
1112 * the `channel'. Returns TRUE if the deletion were successful.
1115 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1116 SilcChannelEntry channel);
1118 /****f* silcclient/SilcClientAPI/silc_client_get_server
1122 * SilcServerEntry silc_client_get_server(SilcClient client,
1123 * SilcClientConnection conn,
1124 * char *server_name)
1128 * Finds entry for server by the server name. Returns the entry or NULL
1129 * if the entry was not found.
1132 SilcServerEntry silc_client_get_server(SilcClient client,
1133 SilcClientConnection conn,
1136 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1140 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1141 * SilcClientConnection conn,
1142 * SilcServerID *server_id);
1146 * Finds entry for server by the server ID. Returns the entry or NULL
1147 * if the entry was not found.
1150 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1151 SilcClientConnection conn,
1152 SilcServerID *server_id);
1154 /****f* silcclient/SilcClientAPI/silc_client_del_server
1158 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1159 * SilcServerEntry server);
1163 * Removes server from local cache by the server entry indicated by
1164 * the `server'. Returns TRUE if the deletion were successful.
1167 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1168 SilcServerEntry server);
1170 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1174 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1175 * SilcClientEntry client_entry);
1179 * Returns the ChannelUser entry if the `client_entry' is joined on the
1180 * channel indicated by the `channel'. NULL if client is not joined on
1184 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1185 SilcClientEntry client_entry);
1187 /* Command management (command.c) */
1189 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1193 * SilcClientCommandContext silc_client_command_alloc(void);
1197 * Allocate Command Context. The context is defined in `command.h' file.
1198 * The context is used by the library commands and applications should use
1199 * it as well. However, application may choose to use some own context
1200 * for its local commands. All library commands, however, must use this
1204 SilcClientCommandContext silc_client_command_alloc(void);
1206 /****f* silcclient/SilcClientAPI/silc_client_command_free
1210 * void silc_client_command_free(SilcClientCommandContext ctx);
1214 * Free command context and its internals. If the contex was duplicated
1215 * with silc_client_command_dup this may not actually free the data,
1216 * instead it will decrease the reference counter of the context. The
1217 * context will be freed when the reference counter hits zero.
1220 void silc_client_command_free(SilcClientCommandContext ctx);
1222 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1226 * SilcClientCommandContext
1227 * silc_client_command_dup(SilcClientCommandContext ctx);
1231 * Duplicate Command Context by adding reference counter. The context won't
1232 * be free'd untill it hits zero.
1235 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1237 /****f* silcclient/SilcClientAPI/silc_client_command_find
1241 * SilcClientCommand silc_client_command_find(SilcClient client,
1242 * const char *name);
1246 * Finds and returns a pointer to the command list. Return NULL if the
1247 * command is not found. See the `command.[ch]' for the command list.
1248 * Command names are not case-sensitive.
1251 SilcClientCommand silc_client_command_find(SilcClient client,
1254 /****f* silcclient/SilcClientAPI/silc_client_command_call
1258 * void silc_client_command_call(SilcClientCommand command);
1262 * Calls the command (executes it). Application can call this after
1263 * it has allocated the SilcClientCommandContext with the function
1264 * silc_client_command_alloc and found the command from the client
1265 * library by calling silc_client_command_find. This will execute
1268 * Application can call the command function directly too if it
1269 * wishes to do so. See the command.h for details of the
1270 * SilcClientCommand structure.
1273 void silc_client_command_call(SilcClientCommand command,
1274 SilcClientCommandContext cmd);
1276 /****f* silcclient/SilcClientAPI/silc_client_command_send
1280 * void silc_client_command_send(SilcClient client,
1281 * SilcClientConnection conn,
1282 * SilcCommand command, SilcUInt16 ident,
1283 * SilcUInt32 argc, ...);
1287 * Generic function to send any command. The arguments must be sent already
1288 * encoded into correct form and in correct order. If application wants
1289 * to perform the commands by itself, it can do so and send the data
1290 * directly to the server using this function. If application is using
1291 * the silc_client_command_call, this function is usually not used.
1294 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1295 SilcCommand command, SilcUInt16 ident,
1296 SilcUInt32 argc, ...);
1298 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1302 * void silc_client_command_pending(SilcClientConnection conn,
1303 * SilcCommand reply_cmd,
1305 * SilcCommandCb callback,
1310 * Add new pending command to be executed when reply to a command has been
1311 * received. The `reply_cmd' is the command that will call the `callback'
1312 * with `context' when reply has been received. If `ident' is non-zero
1313 * the `callback' will be executed when received reply with command
1314 * identifier `ident'.
1316 * Note that the application is notified about the received command
1317 * reply through the `command_reply' client operation before calling
1318 * the `callback` pending command callback.
1321 void silc_client_command_pending(SilcClientConnection conn,
1322 SilcCommand reply_cmd,
1324 SilcCommandCb callback,
1328 /* Private Message key management (client_prvmsg.c) */
1330 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1334 * int silc_client_add_private_message_key(SilcClient client,
1335 * SilcClientConnection conn,
1336 * SilcClientEntry client_entry,
1338 * unsigned char *key,
1339 * SilcUInt32 key_len,
1340 * bool generate_key,
1345 * Adds private message key to the client library. The key will be used to
1346 * encrypt all private message between the client and the remote client
1347 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1348 * value `generate_key' is TRUE the library will generate random key.
1349 * The `key' maybe for example pre-shared-key, passphrase or similar.
1350 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1351 * requirements of the SILC protocol are met. The API, however, allows
1352 * to allocate any cipher.
1354 * If `responder' is TRUE then the sending and receiving keys will be
1355 * set according the client being the receiver of the private key. If
1356 * FALSE the client is being the sender (or negotiator) of the private
1359 * It is not necessary to set key for normal private message usage. If the
1360 * key is not set then the private messages are encrypted using normal
1361 * session keys. Setting the private key, however, increases the security.
1363 * Returns FALSE if the key is already set for the `client_entry', TRUE
1367 int silc_client_add_private_message_key(SilcClient client,
1368 SilcClientConnection conn,
1369 SilcClientEntry client_entry,
1376 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1380 * int silc_client_add_private_message_key_ske(SilcClient client,
1381 * SilcClientConnection conn,
1382 * SilcClientEntry client_entry,
1384 * SilcSKEKeyMaterial *key);
1388 * Same as silc_client_add_private_message_key but takes the key material
1389 * from the SKE key material structure. This structure is received if
1390 * the application uses the silc_client_send_key_agreement to negotiate
1391 * the key material. The `cipher' SHOULD be provided as it is negotiated
1392 * also in the SKE protocol.
1395 int silc_client_add_private_message_key_ske(SilcClient client,
1396 SilcClientConnection conn,
1397 SilcClientEntry client_entry,
1399 SilcSKEKeyMaterial *key,
1402 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1406 * int silc_client_send_private_message_key(SilcClient client,
1407 * SilcClientConnection conn,
1408 * SilcClientEntry client_entry,
1413 * Sends private message key payload to the remote client indicated by
1414 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1415 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1416 * application should call this function after setting the key to the
1419 * Note that the key sent using this function is sent to the remote client
1420 * through the SILC network. The packet is protected using normal session
1424 int silc_client_send_private_message_key(SilcClient client,
1425 SilcClientConnection conn,
1426 SilcClientEntry client_entry,
1429 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1433 * int silc_client_del_private_message_key(SilcClient client,
1434 * SilcClientConnection conn,
1435 * SilcClientEntry client_entry);
1439 * Removes the private message from the library. The key won't be used
1440 * after this to protect the private messages with the remote `client_entry'
1441 * client. Returns FALSE on error, TRUE otherwise.
1444 int silc_client_del_private_message_key(SilcClient client,
1445 SilcClientConnection conn,
1446 SilcClientEntry client_entry);
1448 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1452 * SilcPrivateMessageKeys
1453 * silc_client_list_private_message_keys(SilcClient client,
1454 * SilcClientConnection conn,
1455 * SilcUInt32 *key_count);
1459 * Returns array of set private message keys associated to the connection
1460 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1461 * count to the `key_count' argument. The array must be freed by the caller
1462 * by calling the silc_client_free_private_message_keys function. Note:
1463 * the keys returned in the array is in raw format. It might not be desired
1464 * to show the keys as is. The application might choose not to show the keys
1465 * at all or to show the fingerprints of the keys.
1468 SilcPrivateMessageKeys
1469 silc_client_list_private_message_keys(SilcClient client,
1470 SilcClientConnection conn,
1471 SilcUInt32 *key_count);
1473 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1477 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1478 * SilcUInt32 key_count);
1482 * Frees the SilcPrivateMessageKeys array returned by the function
1483 * silc_client_list_private_message_keys.
1486 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1487 SilcUInt32 key_count);
1490 /* Channel private key management (client_channel.c,
1491 SilcChannelPrivateKey is defined in idlist.h) */
1493 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1497 * int silc_client_add_channel_private_key(SilcClient client,
1498 * SilcClientConnection conn,
1499 * SilcChannelEntry channel,
1503 * unsigned char *key,
1504 * SilcUInt32 key_len);
1508 * Adds private key for channel. This may be set only if the channel's mode
1509 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1510 * mode is not set. When channel has private key then the messages are
1511 * encrypted using that key. All clients on the channel must also know the
1512 * key in order to decrypt the messages. However, it is possible to have
1513 * several private keys per one channel. In this case only some of the
1514 * clients on the channel may know the one key and only some the other key.
1515 * The `name' can be application given name for the key.
1517 * The private key for channel is optional. If it is not set then the
1518 * channel messages are encrypted using the channel key generated by the
1519 * server. However, setting the private key (or keys) for the channel
1520 * significantly adds security. If more than one key is set the library
1521 * will automatically try all keys at the message decryption phase. Note:
1522 * setting many keys slows down the decryption phase as all keys has to
1523 * be tried in order to find the correct decryption key. However, setting
1524 * a few keys does not have big impact to the decryption performace.
1528 * NOTE: This is entirely local setting. The key set using this function
1529 * is not sent to the network at any phase.
1531 * NOTE: If the key material was originated by the SKE protocol (using
1532 * silc_client_send_key_agreement) then the `key' MUST be the
1533 * key->send_enc_key as this is dictated by the SILC protocol. However,
1534 * currently it is not expected that the SKE key material would be used
1535 * as channel private key. However, this API allows it.
1538 int silc_client_add_channel_private_key(SilcClient client,
1539 SilcClientConnection conn,
1540 SilcChannelEntry channel,
1545 SilcUInt32 key_len);
1547 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1551 * int silc_client_del_channel_private_keys(SilcClient client,
1552 * SilcClientConnection conn,
1553 * SilcChannelEntry channel);
1557 * Removes all private keys from the `channel'. The old channel key is used
1558 * after calling this to protect the channel messages. Returns FALSE on
1559 * on error, TRUE otherwise.
1562 int silc_client_del_channel_private_keys(SilcClient client,
1563 SilcClientConnection conn,
1564 SilcChannelEntry channel);
1566 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1570 * int silc_client_del_channel_private_key(SilcClient client,
1571 * SilcClientConnection conn,
1572 * SilcChannelEntry channel,
1573 * SilcChannelPrivateKey key);
1577 * Removes and frees private key `key' from the channel `channel'.
1578 * The `key' is retrieved by calling the function
1579 * silc_client_list_channel_private_keys. The key is not used after
1580 * this. If the key was last private key then the old channel key is
1581 * used hereafter to protect the channel messages. This returns FALSE
1582 * on error, TRUE otherwise.
1585 int silc_client_del_channel_private_key(SilcClient client,
1586 SilcClientConnection conn,
1587 SilcChannelEntry channel,
1588 SilcChannelPrivateKey key);
1590 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1594 * SilcChannelPrivateKey *
1595 * silc_client_list_channel_private_keys(SilcClient client,
1596 * SilcClientConnection conn,
1597 * SilcChannelEntry channel,
1598 * SilcUInt32 *key_count);
1602 * Returns array (pointers) of private keys associated to the `channel'.
1603 * The caller must free the array by calling the function
1604 * silc_client_free_channel_private_keys. The pointers in the array may be
1605 * used to delete the specific key by giving the pointer as argument to the
1606 * function silc_client_del_channel_private_key.
1609 SilcChannelPrivateKey *
1610 silc_client_list_channel_private_keys(SilcClient client,
1611 SilcClientConnection conn,
1612 SilcChannelEntry channel,
1613 SilcUInt32 *key_count);
1615 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1619 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1620 * SilcUInt32 key_count);
1624 * Frees the SilcChannelPrivateKey array.
1627 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1628 SilcUInt32 key_count);
1630 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1634 * void silc_client_current_channel_private_key(SilcClient client,
1635 * SilcClientConnection conn,
1636 * SilcChannelEntry channel,
1637 * SilcChannelPrivateKey key);
1641 * Sets the `key' to be used as current channel private key on the
1642 * `channel'. Packet sent after calling this function will be secured
1646 void silc_client_current_channel_private_key(SilcClient client,
1647 SilcClientConnection conn,
1648 SilcChannelEntry channel,
1649 SilcChannelPrivateKey key);
1652 /* Key Agreement routines (client_keyagr.c) */
1654 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1658 * void silc_client_send_key_agreement(SilcClient client,
1659 * SilcClientConnection conn,
1660 * SilcClientEntry client_entry,
1663 * SilcUInt32 timeout_secs,
1664 * SilcKeyAgreementCallback completion,
1669 * Sends key agreement request to the remote client indicated by the
1670 * `client_entry'. If the caller provides the `hostname' and the `port'
1671 * arguments then the library will bind the client to that hostname and
1672 * that port for the key agreement protocol. It also sends the `hostname'
1673 * and the `port' in the key agreement packet to the remote client. This
1674 * would indicate that the remote client may initiate the key agreement
1675 * protocol to the `hostname' on the `port'. If port is zero then the
1676 * bound port is undefined (the operating system defines it).
1678 * If the `hostname' and `port' is not provided then empty key agreement
1679 * packet is sent to the remote client. The remote client may reply with
1680 * the same packet including its hostname and port. If the library receives
1681 * the reply from the remote client the `key_agreement' client operation
1682 * callback will be called to verify whether the user wants to perform the
1683 * key agreement or not.
1687 * NOTE: If the application provided the `hostname' and the `port' and the
1688 * remote side initiates the key agreement protocol it is not verified
1689 * from the user anymore whether the protocol should be executed or not.
1690 * By setting the `hostname' and `port' the user gives permission to
1691 * perform the protocol (we are responder in this case).
1693 * NOTE: If the remote side decides not to initiate the key agreement
1694 * or decides not to reply with the key agreement packet then we cannot
1695 * perform the key agreement at all. If the key agreement protocol is
1696 * performed the `completion' callback with the `context' will be called.
1697 * If remote side decides to ignore the request the `completion' will be
1698 * called after the specified timeout, `timeout_secs'.
1700 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1701 * will not be called at all since this does nothing more than sending
1702 * a packet to the remote host.
1704 * NOTE: There can be only one active key agreement for one client entry.
1705 * Before setting new one, the old one must be finished (it is finished
1706 * after calling the completion callback) or the function
1707 * silc_client_abort_key_agreement must be called.
1710 void silc_client_send_key_agreement(SilcClient client,
1711 SilcClientConnection conn,
1712 SilcClientEntry client_entry,
1713 const char *hostname,
1714 const char *bindhost,
1716 SilcUInt32 timeout_secs,
1717 SilcKeyAgreementCallback completion,
1720 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1725 * silc_client_perform_key_agreement(SilcClient client,
1726 * SilcClientConnection conn,
1727 * SilcClientEntry client_entry,
1730 * SilcKeyAgreementCallback completion,
1735 * Performs the actual key agreement protocol. Application may use this
1736 * to initiate the key agreement protocol. This can be called for example
1737 * after the application has received the `key_agreement' client operation,
1738 * and did not return TRUE from it.
1740 * The `hostname' is the remote hostname (or IP address) and the `port'
1741 * is the remote port. The `completion' callback with the `context' will
1742 * be called after the key agreement protocol.
1746 * NOTE: If the application returns TRUE in the `key_agreement' client
1747 * operation the library will automatically start the key agreement. In this
1748 * case the application must not call this function. However, application
1749 * may choose to just ignore the `key_agreement' client operation (and
1750 * merely just print information about it on the screen) and call this
1751 * function when the user whishes to do so (by, for example, giving some
1752 * specific command). Thus, the API provides both, automatic and manual
1753 * initiation of the key agreement. Calling this function is the manual
1754 * initiation and returning TRUE in the `key_agreement' client operation
1755 * is the automatic initiation.
1758 void silc_client_perform_key_agreement(SilcClient client,
1759 SilcClientConnection conn,
1760 SilcClientEntry client_entry,
1763 SilcKeyAgreementCallback completion,
1766 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1771 * silc_client_perform_key_agreement_fd(SilcClient client,
1772 * SilcClientConnection conn,
1773 * SilcClientEntry client_entry,
1776 * SilcKeyAgreementCallback completion,
1781 * Same as above but application has created already the connection to
1782 * the remote host. The `sock' is the socket to the remote connection.
1783 * Application can use this function if it does not want the client library
1784 * to create the connection.
1787 void silc_client_perform_key_agreement_fd(SilcClient client,
1788 SilcClientConnection conn,
1789 SilcClientEntry client_entry,
1792 SilcKeyAgreementCallback completion,
1795 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1799 * void silc_client_abort_key_agreement(SilcClient client,
1800 * SilcClientConnection conn,
1801 * SilcClientEntry client_entry);
1805 * This function can be called to unbind the hostname and the port for
1806 * the key agreement protocol. However, this function has effect only
1807 * before the key agreement protocol has been performed. After it has
1808 * been performed the library will automatically unbind the port. The
1809 * `client_entry' is the client to which we sent the key agreement
1810 * request. The key agreement completion callback will be called
1811 * with SILC_KEY_AGREEMENT_ABORTED status.
1814 void silc_client_abort_key_agreement(SilcClient client,
1815 SilcClientConnection conn,
1816 SilcClientEntry client_entry);
1819 /* Misc functions */
1821 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1825 * void silc_client_set_away_message(SilcClient client,
1826 * SilcClientConnection conn,
1831 * Sets away `message'. The away message may be set when the client's
1832 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1833 * to anyone who sends private message. The `message' will be sent
1834 * automatically back to the the client who send private message. If
1835 * away message is already set this replaces the old message with the
1836 * new one. If `message' is NULL the old away message is removed.
1837 * The sender may freely free the memory of the `message'.
1840 void silc_client_set_away_message(SilcClient client,
1841 SilcClientConnection conn,
1845 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1849 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1850 * SilcClientConnection conn,
1851 * SilcAuthMethod auth_meth,
1856 * Connection authentication method request callback. This is called
1857 * by the client library after it has received the authentication method
1858 * that the application requested by calling the function
1859 * silc_client_request_authentication_method.
1862 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1863 SilcClientConnection conn,
1864 SilcAuthMethod auth_meth,
1867 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1872 * silc_client_request_authentication_method(SilcClient client,
1873 * SilcClientConnection conn,
1874 * SilcConnectionAuthRequest
1880 * This function can be used to request the current authentication method
1881 * from the server. This may be called when connecting to the server
1882 * and the client library requests the authentication data from the
1883 * application. If the application does not know the current authentication
1884 * method it can request it from the server using this function.
1885 * The `callback' with `context' will be called after the server has
1886 * replied back with the current authentication method.
1890 silc_client_request_authentication_method(SilcClient client,
1891 SilcClientConnection conn,
1892 SilcConnectionAuthRequest callback,
1895 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1899 * typedef enum { ... } SilcClientMonitorStatus;
1903 * File transmission session status types. These will indicate
1904 * the status of the file transmission session.
1909 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1910 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1911 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1912 SILC_CLIENT_FILE_MONITOR_GET,
1913 SILC_CLIENT_FILE_MONITOR_PUT,
1914 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1915 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1916 } SilcClientMonitorStatus;
1919 /****d* silcclient/SilcClientAPI/SilcClientFileError
1923 * typedef enum { ... } SilcClientFileError;
1927 * File transmission error types. These types are returned by
1928 * some of the file transmission functions, and by the monitor
1929 * callback to indicate error.
1934 SILC_CLIENT_FILE_OK,
1935 SILC_CLIENT_FILE_ERROR,
1936 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1937 SILC_CLIENT_FILE_ALREADY_STARTED,
1938 SILC_CLIENT_FILE_NO_SUCH_FILE,
1939 SILC_CLIENT_FILE_PERMISSION_DENIED,
1940 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1941 } SilcClientFileError;
1944 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1948 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1949 * SilcClientConnection conn,
1950 * SilcClientMonitorStatus status,
1951 * SilcClientFileError error,
1952 * SilcUInt64 offset,
1953 * SilcUInt64 filesize,
1954 * SilcClientEntry client_entry,
1955 * SilcUInt32 session_id,
1956 * const char *filepath,
1961 * Monitor callback that is called during the file transmission to
1962 * monitor the transmission process. The `status' indicates the current
1963 * monitoring process. The `error' will indicate the error type
1964 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1965 * currently transmitted amount of total `filesize'. The `client_entry'
1966 * indicates the remote client, and the transmission session ID is the
1967 * `session_id'. The filename being transmitted is indicated by the
1971 typedef void (*SilcClientFileMonitor)(SilcClient client,
1972 SilcClientConnection conn,
1973 SilcClientMonitorStatus status,
1974 SilcClientFileError error,
1976 SilcUInt64 filesize,
1977 SilcClientEntry client_entry,
1978 SilcUInt32 session_id,
1979 const char *filepath,
1982 /****f* silcclient/SilcClientAPI/silc_client_file_send
1986 * SilcClientFileError
1987 * silc_client_file_send(SilcClient client,
1988 * SilcClientConnection conn,
1989 * SilcClientFileMonitor monitor,
1990 * void *monitor_context,
1991 * const char *local_ip,
1992 * SilcUInt32 local_port,
1993 * SilcClientEntry client_entry,
1994 * const char *filepath);
1995 * SilcUInt32 *session_id);
1999 * Sends a file indicated by the `filepath' to the remote client
2000 * indicated by the `client_entry'. This will negotiate a secret key
2001 * with the remote client before actually starting the transmission of
2002 * the file. The `monitor' callback will be called to monitor the
2003 * transmission of the file.
2005 * This returns a file session ID for the file transmission to the
2006 * `session_id' pointer.. It can be used to close the session (and
2007 * abort the file transmission) by calling the silc_client_file_close
2008 * function. The session ID is also returned in the `monitor' callback.
2010 * If the `local_ip' is provided then this will try to bind the
2011 * listener for key exchange protocol to that IP. If `local_port' is
2012 * non-zero that port is used. If `local_ip' is NULL then this will
2013 * automatically attempt to bind it to local IP address of the machine.
2014 * If that fails then this does not bind to any address and port, and
2015 * assume that the remote client will provide the listener for the
2016 * key exchange protocol.
2018 * If error will occur during the file transfer process the error
2019 * status will be returned in the monitor callback. In this case
2020 * the application must call silc_client_file_close to close the
2025 silc_client_file_send(SilcClient client,
2026 SilcClientConnection conn,
2027 SilcClientFileMonitor monitor,
2028 void *monitor_context,
2029 const char *local_ip,
2030 SilcUInt32 local_port,
2031 SilcClientEntry client_entry,
2032 const char *filepath,
2033 SilcUInt32 *session_id);
2035 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2039 * SilcClientFileError
2040 * silc_client_file_receive(SilcClient client,
2041 * SilcClientConnection conn,
2042 * SilcClientFileMonitor monitor,
2043 * void *monitor_context,
2044 * SilcUInt32 session_id);
2048 * Receives a file from a client indicated by the `client_entry'. The
2049 * `session_id' indicates the file transmission session and it has been
2050 * received in the `ftp' client operation function. This will actually
2051 * perform the key agreement protocol with the remote client before
2052 * actually starting the file transmission. The `monitor' callback
2053 * will be called to monitor the transmission.
2055 * If error will occur during the file transfer process the error
2056 * status will be returned in the monitor callback. In this case
2057 * the application must call silc_client_file_close to close the
2062 silc_client_file_receive(SilcClient client,
2063 SilcClientConnection conn,
2064 SilcClientFileMonitor monitor,
2065 void *monitor_context,
2066 SilcUInt32 session_id);
2068 /****f* silcclient/SilcClientAPI/silc_client_file_close
2072 * SilcClientFileError silc_client_file_close(SilcClient client,
2073 * SilcClientConnection conn,
2074 * SilcUInt32 session_id);
2078 * Closes file transmission session indicated by the `session_id'.
2079 * If file transmission is being conducted it will be aborted
2080 * automatically. This function is also used to close the session
2081 * after successful file transmission. This function can be used
2082 * also to reject incoming file transmission request.
2085 SilcClientFileError silc_client_file_close(SilcClient client,
2086 SilcClientConnection conn,
2087 SilcUInt32 session_id);
2090 #include "command.h"
2091 #include "command_reply.h"
2093 #include "protocol.h"
2099 #endif /* SILCCLIENT_H */