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). */
331 void (*command_reply)(SilcClient client, SilcClientConnection conn,
332 SilcCommandPayload cmd_payload, int success,
333 SilcCommand command, SilcCommandStatus status, ...);
335 /* Called to indicate that connection was either successfully established
336 or connecting failed. This is also the first time application receives
337 the SilcClientConnection objecet which it should save somewhere.
338 If the `success' is FALSE the application must always call the function
339 silc_client_close_connection. */
340 void (*connect)(SilcClient client, SilcClientConnection conn, int success);
342 /* Called to indicate that connection was disconnected to the server. */
343 void (*disconnect)(SilcClient client, SilcClientConnection conn);
345 /* Find authentication method and authentication data by hostname and
346 port. The hostname may be IP address as well. When the authentication
347 method has been resolved the `completion' callback with the found
348 authentication method and authentication data is called. The `conn'
350 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
351 char *hostname, SilcUInt16 port,
352 SilcGetAuthMeth completion, void *context);
354 /* Verifies received public key. The `conn_type' indicates which entity
355 (server, client etc.) has sent the public key. If user decides to trust
356 the key may be saved as trusted public key for later use. The
357 `completion' must be called after the public key has been verified. */
358 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
359 SilcSocketType conn_type, unsigned char *pk,
360 SilcUInt32 pk_len, SilcSKEPKType pk_type,
361 SilcVerifyPublicKey completion, void *context);
363 /* Ask (interact, that is) a passphrase from user. The passphrase is
364 returned to the library by calling the `completion' callback with
366 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
367 SilcAskPassphrase completion, void *context);
369 /* Notifies application that failure packet was received. This is called
370 if there is some protocol active in the client. The `protocol' is the
371 protocol context. The `failure' is opaque pointer to the failure
372 indication. Note, that the `failure' is protocol dependant and
373 application must explicitly cast it to correct type. Usually `failure'
374 is 32 bit failure type (see protocol specs for all protocol failure
376 void (*failure)(SilcClient client, SilcClientConnection conn,
377 SilcProtocol protocol, void *failure);
379 /* Asks whether the user would like to perform the key agreement protocol.
380 This is called after we have received an key agreement packet or an
381 reply to our key agreement packet. This returns TRUE if the user wants
382 the library to perform the key agreement protocol and FALSE if it is not
383 desired (application may start it later by calling the function
384 silc_client_perform_key_agreement). If TRUE is returned also the
385 `completion' and `context' arguments must be set by the application. */
386 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
387 SilcClientEntry client_entry, const char *hostname,
388 SilcUInt16 port, SilcKeyAgreementCallback *completion,
391 /* Notifies application that file transfer protocol session is being
392 requested by the remote client indicated by the `client_entry' from
393 the `hostname' and `port'. The `session_id' is the file transfer
394 session and it can be used to either accept or reject the file
395 transfer request, by calling the silc_client_file_receive or
396 silc_client_file_close, respectively. */
397 void (*ftp)(SilcClient client, SilcClientConnection conn,
398 SilcClientEntry client_entry, SilcUInt32 session_id,
399 const char *hostname, SilcUInt16 port);
400 } SilcClientOperations;
403 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
407 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
408 * char **ret_nickname);
412 * A callback function provided by the application for the library in
413 * SilcClientParams structure. This function parses the formatted
414 * nickname string `nickname' and returns the true nickname to the
415 * `ret_nickname' pointer. The library can call this function at
419 typedef void (*SilcNicknameFormatParse)(const char *nickname,
420 char **ret_nickname);
422 /****s* silcclient/SilcClientAPI/SilcClientParams
426 * typedef struct { ... } SilcClientParams;
430 * Client parameters. This can be filled with proper values and
431 * given as argument to the silc_client_alloc function. The structure
432 * hold various parameters which affects the function of the client.
437 /* Number of maximum tasks the client library's scheduler can handle.
438 If set to zero, the default value will be used (200). For WIN32
439 systems this should be set to 64 as it is the hard limit dictated
443 /* Rekey timeout in seconds. The client will perform rekey in this
444 time interval. If set to zero, the default value will be used. */
445 unsigned int rekey_secs;
447 /* Connection authentication method request timeout. If server does not
448 reply back the current authentication method when we've requested it
449 in this time interval we'll assume the reply will not come at all.
450 If set to zero, the default value (2 seconds) will be used. */
451 unsigned int connauth_request_secs;
453 /* Nickname format string. This can be used to order the client library
454 to save the nicknames in the library in a certain format. Since
455 nicknames are not unique in SILC it is possible to have multiple same
456 nicknames. Using this format string it is possible to order the library
457 to separate the multiple same nicknames from each other. The format
458 types are defined below and they can appear in any order in the format
459 string. If this is NULL then default format is used which is the
460 default nickname without anything else. The string MUST be NULL
463 Following format types are available:
465 %n nickname - the real nickname returned by the server (mandatory)
466 %h hostname - the stripped hostname of the client
467 %H full hostname - the full hostname of the client
468 %s server name - the server name the client is connected
469 %S full server - the full server name the client is connected
470 %a number - ascending number in case there are several
471 same nicknames (fe. nick@host and nick@host2)
473 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
474 "%a!%n@%s" (fe. nick@server, 2!nick@server)
475 "%n@%H" (fe. nick@host.domain.com)
477 By default this format is employed to the nicknames by the libary
478 only when there appears multiple same nicknames. If the library has
479 only one nickname cached the nickname is saved as is and without the
480 defined format. If you want always to save the nickname in the defined
481 format set the boolean field `nickname_force_format' to value TRUE.
483 char nickname_format[32];
485 /* If this is set to TRUE then the `nickname_format' is employed to all
486 saved nicknames even if there are no multiple same nicknames in the
487 cache. By default this is FALSE, which means that the `nickname_format'
488 is employed only if the library will receive a nickname that is
489 already saved in the cache. It is recommended to leave this to FALSE
491 bool nickname_force_format;
493 /* A callback function provided by the application for the library to
494 parse the nickname from the formatted nickname string. Even though
495 the libary formats the nicknames the application knows generally the
496 format better so this function should be provided for the library
497 if the application sets the `nickname_format' field. The library
498 will call this to get the true nickname from the provided formatted
499 nickname string whenever it needs the true nickname. */
500 SilcNicknameFormatParse nickname_parse;
506 /* Initialization functions (client.c) */
508 /****f* silcclient/SilcClientAPI/silc_client_alloc
512 * SilcClient silc_client_alloc(SilcClientOperations *ops,
513 * SilcClientParams *params,
515 * const char *silc_version);
519 * Allocates new client object. This has to be done before client may
520 * work. After calling this one must call silc_client_init to initialize
521 * the client. The `application' is application specific user data pointer
522 * and caller must free it. The `silc_version' is the application version
523 * that will be used to compare against remote host's (usually a server)
527 SilcClient silc_client_alloc(SilcClientOperations *ops,
528 SilcClientParams *params,
530 const char *silc_version);
532 /****f* silcclient/SilcClientAPI/silc_client_free
536 * void silc_client_free(SilcClient client);
540 * Frees client object and its internals. The execution of the client
541 * should be stopped with silc_client_stop function before calling
545 void silc_client_free(SilcClient client);
547 /****f* silcclient/SilcClientAPI/silc_client_init
551 * int silc_client_init(SilcClient client);
555 * Initializes the client. This makes all the necessary steps to make
556 * the client ready to be run. One must call silc_client_run to run the
557 * client. Returns FALSE if error occurred, TRUE otherwise.
560 int silc_client_init(SilcClient client);
562 /****f* silcclient/SilcClientAPI/silc_client_run
566 * void silc_client_run(SilcClient client);
570 * Runs the client. This starts the scheduler from the utility library.
571 * When this functions returns the execution of the appliation is over.
574 void silc_client_run(SilcClient client);
576 /****f* silcclient/SilcClientAPI/silc_client_run_one
580 * void silc_client_run_one(SilcClient client);
584 * Runs the client and returns immeadiately. This function is used when
585 * the SILC Client object indicated by the `client' is run under some
586 * other scheduler, or event loop or main loop. On GUI applications,
587 * for example this may be desired to used to run the client under the
588 * GUI application's main loop. Typically the GUI application would
589 * register an idle task that calls this function multiple times in
590 * a second to quickly process the SILC specific data.
593 void silc_client_run_one(SilcClient client);
595 /****f* silcclient/SilcClientAPI/silc_client_stop
599 * void silc_client_stop(SilcClient client);
603 * Stops the client. This is called to stop the client and thus to stop
604 * the program. The client context must be freed with the silc_client_free
608 void silc_client_stop(SilcClient client);
611 /* Connecting functions (client.c) */
613 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
617 * int silc_client_connect_to_server(SilcClient client, int port,
618 * char *host, void *context);
622 * Connects to remote server. This is the main routine used to connect
623 * to SILC server. Returns -1 on error and the created socket otherwise.
624 * The `context' is user context that is saved into the SilcClientConnection
625 * that is created after the connection is created. Note that application
626 * may handle the connecting process outside the library. If this is the
627 * case then this function is not used at all. When the connecting is
628 * done the `connect' client operation is called.
631 int silc_client_connect_to_server(SilcClient client, int port,
632 char *host, void *context);
634 /****f* silcclient/SilcClientAPI/silc_client_add_connection
638 * SilcClientConnection silc_client_add_connection(SilcClient client,
645 * Allocates and adds new connection to the client. This adds the allocated
646 * connection to the connection table and returns a pointer to it. A client
647 * can have multiple connections to multiple servers. Every connection must
648 * be added to the client using this function. User data `context' may
649 * be sent as argument. This function is normally used only if the
650 * application performed the connecting outside the library. The library
651 * however may use this internally.
654 SilcClientConnection silc_client_add_connection(SilcClient client,
659 /****f* silcclient/SilcClientAPI/silc_client_del_connection
663 * void silc_client_del_connection(SilcClient client,
664 * SilcClientConnection conn);
668 * Removes connection from client. Frees all memory. The library
669 * call this function automatically for all connection contexts.
670 * The application however may free the connection contexts it has
674 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
676 /****f* silcclient/SilcClientAPI/silc_client_add_socket
680 * void silc_client_add_socket(SilcClient client,
681 * SilcSocketConnection sock);
685 * Adds listener socket to the listener sockets table. This function is
686 * used to add socket objects that are listeners to the client. This should
687 * not be used to add other connection objects.
690 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
692 /****f* silcclient/SilcClientAPI/silc_client_del_socket
696 * void silc_client_del_socket(SilcClient client,
697 * SilcSocketConnection sock);
701 * Deletes listener socket from the listener sockets table. If the
702 * application has added a socket with silc_client_add_socket it must
703 * also free it using this function.
706 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
708 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
712 * void silc_client_start_key_exchange(SilcClient client,
713 * SilcClientConnection conn,
718 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
719 * key material between client and server. This function can be called
720 * directly if application is performing its own connecting and does not
721 * use the connecting provided by this library. This function is normally
722 * used only if the application performed the connecting outside the
723 * library. The library however may use this internally. After the
724 * key exchange is performed the `connect' client operation is called.
727 void silc_client_start_key_exchange(SilcClient client,
728 SilcClientConnection conn,
731 /****f* silcclient/SilcClientAPI/silc_client_close_connection
735 * void silc_client_close_connection(SilcClient client,
736 * SilcSocketConnection sock,
737 * SilcClientConnection conn);
741 * Closes connection to remote end. Free's all allocated data except
742 * for some information such as nickname etc. that are valid at all time.
743 * If the `sock' is NULL then the conn->sock will be used. If `sock' is
744 * provided it will be checked whether the sock and `conn->sock' are the
745 * same (they can be different, ie. a socket can use `conn' as its
746 * connection but `conn->sock' might be actually a different connection
750 void silc_client_close_connection(SilcClient client,
751 SilcSocketConnection sock,
752 SilcClientConnection conn);
755 /* Message sending functions (client_channel.c and client_prvmsg.c) */
757 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
761 * void silc_client_send_channel_message(SilcClient client,
762 * SilcClientConnection conn,
763 * SilcChannelEntry channel,
764 * SilcChannelPrivateKey key,
765 * SilcMessageFlags flags,
766 * unsigned char *data,
767 * SilcUInt32 data_len,
772 * Sends packet to the `channel'. Packet to channel is always encrypted
773 * differently from "normal" packets. SILC header of the packet is
774 * encrypted with the next receiver's key and the rest of the packet is
775 * encrypted with the channel specific key. Padding and HMAC is computed
776 * with the next receiver's key. The `data' is the channel message. If
777 * the `force_send' is TRUE then the packet is sent immediately.
779 * If `key' is provided then that private key is used to encrypt the
780 * channel message. If it is not provided, private keys has not been
781 * set at all, the normal channel key is used automatically. If private
782 * keys are set then the first key (the key that was added first as
783 * private key) is used.
786 void silc_client_send_channel_message(SilcClient client,
787 SilcClientConnection conn,
788 SilcChannelEntry channel,
789 SilcChannelPrivateKey key,
790 SilcMessageFlags flags,
795 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
799 * void silc_client_send_private_message(SilcClient client,
800 * SilcClientConnection conn,
801 * SilcClientEntry client_entry,
802 * SilcMessageFlags flags,
803 * unsigned char *data,
804 * SilcUInt32 data_len,
809 * Sends private message to remote client. If private message key has
810 * not been set with this client then the message will be encrypted using
811 * normal session keys. Private messages are special packets in SILC
812 * network hence we need this own function for them. This is similar
813 * to silc_client_packet_send_to_channel except that we send private
814 * message. The `data' is the private message. If the `force_send' is
815 * TRUE the packet is sent immediately.
818 void silc_client_send_private_message(SilcClient client,
819 SilcClientConnection conn,
820 SilcClientEntry client_entry,
821 SilcMessageFlags flags,
827 /* Client and Channel entry retrieval (idlist.c) */
829 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
833 * typedef void (*SilcGetClientCallback)(SilcClient client,
834 * SilcClientConnection conn,
835 * SilcClientEntry *clients,
836 * SilcUInt32 clients_count,
841 * Callback function given to the silc_client_get_client function. The
842 * found entries are allocated into the `clients' array. The array must
843 * not be freed by the receiver, the library will free it later. If the
844 * `clients' is NULL, no such clients exist in the SILC Network.
847 typedef void (*SilcGetClientCallback)(SilcClient client,
848 SilcClientConnection conn,
849 SilcClientEntry *clients,
850 SilcUInt32 clients_count,
853 /****f* silcclient/SilcClientAPI/silc_client_get_clients
857 * void silc_client_get_clients(SilcClient client,
858 * SilcClientConnection conn,
859 * const char *nickname,
860 * const char *server,
861 * SilcGetClientCallback completion,
866 * Finds client entry or entries by the `nickname' and `server'. The
867 * completion callback will be called when the client entries has been
868 * found. After the server returns the client information it is cached
869 * and can be accesses locally at a later time.
873 * NOTE: This function is always asynchronous and resolves the client
874 * information from the server. Thus, if you already know the client
875 * information then use the silc_client_get_client_by_id function to
876 * get the client entry since this function may be very slow and should
877 * be used only to initially get the client entries.
880 void silc_client_get_clients(SilcClient client,
881 SilcClientConnection conn,
882 const char *nickname,
884 SilcGetClientCallback completion,
887 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
891 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
892 * SilcClientConnection conn,
893 * const char *nickname,
894 * const char *format,
895 * SilcUInt32 *clients_count);
899 * Same as silc_client_get_clients function but does not resolve anything
900 * from the server. This checks local cache and returns all matching
901 * clients from the local cache. If none was found this returns NULL.
902 * The `nickname' is the real nickname of the client, and the `format'
903 * is the formatted nickname to find exact match from multiple found
904 * entries. The format must be same as given in the SilcClientParams
905 * structure to the client library. If the `format' is NULL all found
906 * clients by `nickname' are returned. The caller must return the
910 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
911 SilcClientConnection conn,
912 const char *nickname,
914 SilcUInt32 *clients_count);
916 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
920 * void silc_client_get_clients_by_list(SilcClient client,
921 * SilcClientConnection conn,
922 * SilcUInt32 list_count,
923 * SilcBuffer client_id_list,
924 * SilcGetClientCallback completion,
929 * Gets client entries by the list of client ID's `client_id_list'. This
930 * always resolves those client ID's it does not know yet from the server
931 * so this function might take a while. The `client_id_list' is a list
932 * of ID Payloads added one after other. JOIN command reply and USERS
933 * command reply for example returns this sort of list. The `completion'
934 * will be called after the entries are available. When server returns
935 * the client information it will be cached and can be accessed locally
939 void silc_client_get_clients_by_list(SilcClient client,
940 SilcClientConnection conn,
941 SilcUInt32 list_count,
942 SilcBuffer client_id_list,
943 SilcGetClientCallback completion,
946 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
950 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
951 * SilcClientConnection conn,
952 * SilcClientID *client_id);
956 * Find entry for client by the client's ID. Returns the entry or NULL
957 * if the entry was not found. This checks the local cache and does
958 * not resolve anything from server.
961 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
962 SilcClientConnection conn,
963 SilcClientID *client_id);
965 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
970 * silc_client_get_client_by_id_resolve(SilcClient client,
971 * SilcClientConnection conn,
972 * SilcClientID *client_id,
973 * SilcGetClientCallback completion,
978 * Same as silc_client_get_client_by_id but will always resolve the
979 * information from the server. Use this only if you know that you
980 * do not have the entry and the only thing you know about the client
981 * is its ID. When server returns the client information it will be
982 * cache and can be accessed locally at a later time.
985 void silc_client_get_client_by_id_resolve(SilcClient client,
986 SilcClientConnection conn,
987 SilcClientID *client_id,
988 SilcGetClientCallback completion,
991 /****f* silcclient/SilcClientAPI/silc_client_del_client
995 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
996 * SilcClientEntry client_entry)
1000 * Removes client from local cache by the client entry indicated by
1001 * the `client_entry'. Returns TRUE if the deletion were successful.
1004 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1005 SilcClientEntry client_entry);
1007 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1011 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1012 * SilcClientConnection conn,
1013 * SilcChannelEntry *channels,
1014 * SilcUInt32 channels_count,
1019 * Callback function given to the silc_client_get_channel_* functions.
1020 * The found entries are allocated into the `channels' array. The array
1021 * must not be freed by the receiver, the library will free it later.
1022 * If the `channel' is NULL, no such channel exist in the SILC Network.
1025 typedef void (*SilcGetChannelCallback)(SilcClient client,
1026 SilcClientConnection conn,
1027 SilcChannelEntry *channels,
1028 SilcUInt32 channels_count,
1031 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1035 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1036 * SilcClientConnection conn,
1041 * Finds entry for channel by the channel name. Returns the entry or NULL
1042 * if the entry was not found. It is found only if the client is joined
1046 SilcChannelEntry silc_client_get_channel(SilcClient client,
1047 SilcClientConnection conn,
1050 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1055 * silc_client_get_channel_by_id_resolve(SilcClient client,
1056 * SilcClientConnection conn,
1057 * SilcChannelID *channel_id,
1058 * SilcGetClientCallback completion,
1063 * Finds channel entry by the channel name. Returns the entry or NULL
1064 * if it was not found.
1067 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1068 SilcClientConnection conn,
1069 SilcChannelID *channel_id);
1071 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1076 * silc_client_get_channel_by_id_resolve(SilcClient client,
1077 * SilcClientConnection conn,
1078 * SilcChannelID *channel_id,
1079 * SilcGetClientCallback completion,
1084 * Resolves the channel information (its name mainly) from the server
1085 * by the `channel_id'. Use this only if you know that you do not have
1086 * the entry cached locally.
1089 void silc_client_get_channel_by_id_resolve(SilcClient client,
1090 SilcClientConnection conn,
1091 SilcChannelID *channel_id,
1092 SilcGetChannelCallback completion,
1095 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1099 * bool silc_client_del_channel(SilcClient client,
1100 * SilcClientConnection conn,
1101 * SilcChannelEntry channel)
1105 * Removes channel from local cache by the channel entry indicated by
1106 * the `channel'. Returns TRUE if the deletion were successful.
1109 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1110 SilcChannelEntry channel);
1112 /****f* silcclient/SilcClientAPI/silc_client_get_server
1116 * SilcServerEntry silc_client_get_server(SilcClient client,
1117 * SilcClientConnection conn,
1118 * char *server_name)
1122 * Finds entry for server by the server name. Returns the entry or NULL
1123 * if the entry was not found.
1126 SilcServerEntry silc_client_get_server(SilcClient client,
1127 SilcClientConnection conn,
1130 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1134 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1135 * SilcClientConnection conn,
1136 * SilcServerID *server_id);
1140 * Finds entry for server by the server ID. Returns the entry or NULL
1141 * if the entry was not found.
1144 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1145 SilcClientConnection conn,
1146 SilcServerID *server_id);
1148 /****f* silcclient/SilcClientAPI/silc_client_del_server
1152 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1153 * SilcServerEntry server);
1157 * Removes server from local cache by the server entry indicated by
1158 * the `server'. Returns TRUE if the deletion were successful.
1161 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1162 SilcServerEntry server);
1164 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1168 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1169 * SilcClientEntry client_entry);
1173 * Returns the ChannelUser entry if the `client_entry' is joined on the
1174 * channel indicated by the `channel'. NULL if client is not joined on
1178 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1179 SilcClientEntry client_entry);
1181 /* Command management (command.c) */
1183 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1187 * SilcClientCommandContext silc_client_command_alloc(void);
1191 * Allocate Command Context. The context is defined in `command.h' file.
1192 * The context is used by the library commands and applications should use
1193 * it as well. However, application may choose to use some own context
1194 * for its local commands. All library commands, however, must use this
1198 SilcClientCommandContext silc_client_command_alloc(void);
1200 /****f* silcclient/SilcClientAPI/silc_client_command_free
1204 * void silc_client_command_free(SilcClientCommandContext ctx);
1208 * Free command context and its internals. If the contex was duplicated
1209 * with silc_client_command_dup this may not actually free the data,
1210 * instead it will decrease the reference counter of the context. The
1211 * context will be freed when the reference counter hits zero.
1214 void silc_client_command_free(SilcClientCommandContext ctx);
1216 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1220 * SilcClientCommandContext
1221 * silc_client_command_dup(SilcClientCommandContext ctx);
1225 * Duplicate Command Context by adding reference counter. The context won't
1226 * be free'd untill it hits zero.
1229 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1231 /****f* silcclient/SilcClientAPI/silc_client_command_find
1235 * SilcClientCommand silc_client_command_find(SilcClient client,
1236 * const char *name);
1240 * Finds and returns a pointer to the command list. Return NULL if the
1241 * command is not found. See the `command.[ch]' for the command list.
1242 * Command names are not case-sensitive.
1245 SilcClientCommand silc_client_command_find(SilcClient client,
1248 /****f* silcclient/SilcClientAPI/silc_client_command_call
1252 * void silc_client_command_call(SilcClientCommand command);
1256 * Calls the command (executes it). Application can call this after
1257 * it has allocated the SilcClientCommandContext with the function
1258 * silc_client_command_alloc and found the command from the client
1259 * library by calling silc_client_command_find. This will execute
1262 * Application can call the command function directly too if it
1263 * wishes to do so. See the command.h for details of the
1264 * SilcClientCommand structure.
1267 void silc_client_command_call(SilcClientCommand command,
1268 SilcClientCommandContext cmd);
1270 /****f* silcclient/SilcClientAPI/silc_client_command_send
1274 * void silc_client_command_send(SilcClient client,
1275 * SilcClientConnection conn,
1276 * SilcCommand command, SilcUInt16 ident,
1277 * SilcUInt32 argc, ...);
1281 * Generic function to send any command. The arguments must be sent already
1282 * encoded into correct form and in correct order. If application wants
1283 * to perform the commands by itself, it can do so and send the data
1284 * directly to the server using this function. If application is using
1285 * the silc_client_command_call, this function is usually not used.
1288 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1289 SilcCommand command, SilcUInt16 ident,
1290 SilcUInt32 argc, ...);
1292 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1296 * void silc_client_command_pending(SilcClientConnection conn,
1297 * SilcCommand reply_cmd,
1299 * SilcCommandCb callback,
1304 * Add new pending command to be executed when reply to a command has been
1305 * received. The `reply_cmd' is the command that will call the `callback'
1306 * with `context' when reply has been received. If `ident' is non-zero
1307 * the `callback' will be executed when received reply with command
1308 * identifier `ident'.
1310 * Note that the application is notified about the received command
1311 * reply through the `command_reply' client operation before calling
1312 * the `callback` pending command callback.
1315 void silc_client_command_pending(SilcClientConnection conn,
1316 SilcCommand reply_cmd,
1318 SilcCommandCb callback,
1322 /* Private Message key management (client_prvmsg.c) */
1324 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1328 * int silc_client_add_private_message_key(SilcClient client,
1329 * SilcClientConnection conn,
1330 * SilcClientEntry client_entry,
1332 * unsigned char *key,
1333 * SilcUInt32 key_len,
1334 * bool generate_key,
1339 * Adds private message key to the client library. The key will be used to
1340 * encrypt all private message between the client and the remote client
1341 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1342 * value `generate_key' is TRUE the library will generate random key.
1343 * The `key' maybe for example pre-shared-key, passphrase or similar.
1344 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1345 * requirements of the SILC protocol are met. The API, however, allows
1346 * to allocate any cipher.
1348 * If `responder' is TRUE then the sending and receiving keys will be
1349 * set according the client being the receiver of the private key. If
1350 * FALSE the client is being the sender (or negotiator) of the private
1353 * It is not necessary to set key for normal private message usage. If the
1354 * key is not set then the private messages are encrypted using normal
1355 * session keys. Setting the private key, however, increases the security.
1357 * Returns FALSE if the key is already set for the `client_entry', TRUE
1361 int silc_client_add_private_message_key(SilcClient client,
1362 SilcClientConnection conn,
1363 SilcClientEntry client_entry,
1370 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1374 * int silc_client_add_private_message_key_ske(SilcClient client,
1375 * SilcClientConnection conn,
1376 * SilcClientEntry client_entry,
1378 * SilcSKEKeyMaterial *key);
1382 * Same as silc_client_add_private_message_key but takes the key material
1383 * from the SKE key material structure. This structure is received if
1384 * the application uses the silc_client_send_key_agreement to negotiate
1385 * the key material. The `cipher' SHOULD be provided as it is negotiated
1386 * also in the SKE protocol.
1389 int silc_client_add_private_message_key_ske(SilcClient client,
1390 SilcClientConnection conn,
1391 SilcClientEntry client_entry,
1393 SilcSKEKeyMaterial *key,
1396 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1400 * int silc_client_send_private_message_key(SilcClient client,
1401 * SilcClientConnection conn,
1402 * SilcClientEntry client_entry,
1407 * Sends private message key payload to the remote client indicated by
1408 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1409 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1410 * application should call this function after setting the key to the
1413 * Note that the key sent using this function is sent to the remote client
1414 * through the SILC network. The packet is protected using normal session
1418 int silc_client_send_private_message_key(SilcClient client,
1419 SilcClientConnection conn,
1420 SilcClientEntry client_entry,
1423 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1427 * int silc_client_del_private_message_key(SilcClient client,
1428 * SilcClientConnection conn,
1429 * SilcClientEntry client_entry);
1433 * Removes the private message from the library. The key won't be used
1434 * after this to protect the private messages with the remote `client_entry'
1435 * client. Returns FALSE on error, TRUE otherwise.
1438 int silc_client_del_private_message_key(SilcClient client,
1439 SilcClientConnection conn,
1440 SilcClientEntry client_entry);
1442 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1446 * SilcPrivateMessageKeys
1447 * silc_client_list_private_message_keys(SilcClient client,
1448 * SilcClientConnection conn,
1449 * SilcUInt32 *key_count);
1453 * Returns array of set private message keys associated to the connection
1454 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1455 * count to the `key_count' argument. The array must be freed by the caller
1456 * by calling the silc_client_free_private_message_keys function. Note:
1457 * the keys returned in the array is in raw format. It might not be desired
1458 * to show the keys as is. The application might choose not to show the keys
1459 * at all or to show the fingerprints of the keys.
1462 SilcPrivateMessageKeys
1463 silc_client_list_private_message_keys(SilcClient client,
1464 SilcClientConnection conn,
1465 SilcUInt32 *key_count);
1467 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1471 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1472 * SilcUInt32 key_count);
1476 * Frees the SilcPrivateMessageKeys array returned by the function
1477 * silc_client_list_private_message_keys.
1480 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1481 SilcUInt32 key_count);
1484 /* Channel private key management (client_channel.c,
1485 SilcChannelPrivateKey is defined in idlist.h) */
1487 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1491 * int silc_client_add_channel_private_key(SilcClient client,
1492 * SilcClientConnection conn,
1493 * SilcChannelEntry channel,
1497 * unsigned char *key,
1498 * SilcUInt32 key_len);
1502 * Adds private key for channel. This may be set only if the channel's mode
1503 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1504 * mode is not set. When channel has private key then the messages are
1505 * encrypted using that key. All clients on the channel must also know the
1506 * key in order to decrypt the messages. However, it is possible to have
1507 * several private keys per one channel. In this case only some of the
1508 * clients on the channel may know the one key and only some the other key.
1509 * The `name' can be application given name for the key.
1511 * The private key for channel is optional. If it is not set then the
1512 * channel messages are encrypted using the channel key generated by the
1513 * server. However, setting the private key (or keys) for the channel
1514 * significantly adds security. If more than one key is set the library
1515 * will automatically try all keys at the message decryption phase. Note:
1516 * setting many keys slows down the decryption phase as all keys has to
1517 * be tried in order to find the correct decryption key. However, setting
1518 * a few keys does not have big impact to the decryption performace.
1522 * NOTE: This is entirely local setting. The key set using this function
1523 * is not sent to the network at any phase.
1525 * NOTE: If the key material was originated by the SKE protocol (using
1526 * silc_client_send_key_agreement) then the `key' MUST be the
1527 * key->send_enc_key as this is dictated by the SILC protocol. However,
1528 * currently it is not expected that the SKE key material would be used
1529 * as channel private key. However, this API allows it.
1532 int silc_client_add_channel_private_key(SilcClient client,
1533 SilcClientConnection conn,
1534 SilcChannelEntry channel,
1539 SilcUInt32 key_len);
1541 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1545 * int silc_client_del_channel_private_keys(SilcClient client,
1546 * SilcClientConnection conn,
1547 * SilcChannelEntry channel);
1551 * Removes all private keys from the `channel'. The old channel key is used
1552 * after calling this to protect the channel messages. Returns FALSE on
1553 * on error, TRUE otherwise.
1556 int silc_client_del_channel_private_keys(SilcClient client,
1557 SilcClientConnection conn,
1558 SilcChannelEntry channel);
1560 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1564 * int silc_client_del_channel_private_key(SilcClient client,
1565 * SilcClientConnection conn,
1566 * SilcChannelEntry channel,
1567 * SilcChannelPrivateKey key);
1571 * Removes and frees private key `key' from the channel `channel'.
1572 * The `key' is retrieved by calling the function
1573 * silc_client_list_channel_private_keys. The key is not used after
1574 * this. If the key was last private key then the old channel key is
1575 * used hereafter to protect the channel messages. This returns FALSE
1576 * on error, TRUE otherwise.
1579 int silc_client_del_channel_private_key(SilcClient client,
1580 SilcClientConnection conn,
1581 SilcChannelEntry channel,
1582 SilcChannelPrivateKey key);
1584 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1588 * SilcChannelPrivateKey *
1589 * silc_client_list_channel_private_keys(SilcClient client,
1590 * SilcClientConnection conn,
1591 * SilcChannelEntry channel,
1592 * SilcUInt32 *key_count);
1596 * Returns array (pointers) of private keys associated to the `channel'.
1597 * The caller must free the array by calling the function
1598 * silc_client_free_channel_private_keys. The pointers in the array may be
1599 * used to delete the specific key by giving the pointer as argument to the
1600 * function silc_client_del_channel_private_key.
1603 SilcChannelPrivateKey *
1604 silc_client_list_channel_private_keys(SilcClient client,
1605 SilcClientConnection conn,
1606 SilcChannelEntry channel,
1607 SilcUInt32 *key_count);
1609 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1613 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1614 * SilcUInt32 key_count);
1618 * Frees the SilcChannelPrivateKey array.
1621 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1622 SilcUInt32 key_count);
1624 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1628 * void silc_client_current_channel_private_key(SilcClient client,
1629 * SilcClientConnection conn,
1630 * SilcChannelEntry channel,
1631 * SilcChannelPrivateKey key);
1635 * Sets the `key' to be used as current channel private key on the
1636 * `channel'. Packet sent after calling this function will be secured
1640 void silc_client_current_channel_private_key(SilcClient client,
1641 SilcClientConnection conn,
1642 SilcChannelEntry channel,
1643 SilcChannelPrivateKey key);
1646 /* Key Agreement routines (client_keyagr.c) */
1648 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1652 * void silc_client_send_key_agreement(SilcClient client,
1653 * SilcClientConnection conn,
1654 * SilcClientEntry client_entry,
1657 * SilcUInt32 timeout_secs,
1658 * SilcKeyAgreementCallback completion,
1663 * Sends key agreement request to the remote client indicated by the
1664 * `client_entry'. If the caller provides the `hostname' and the `port'
1665 * arguments then the library will bind the client to that hostname and
1666 * that port for the key agreement protocol. It also sends the `hostname'
1667 * and the `port' in the key agreement packet to the remote client. This
1668 * would indicate that the remote client may initiate the key agreement
1669 * protocol to the `hostname' on the `port'. If port is zero then the
1670 * bound port is undefined (the operating system defines it).
1672 * If the `hostname' and `port' is not provided then empty key agreement
1673 * packet is sent to the remote client. The remote client may reply with
1674 * the same packet including its hostname and port. If the library receives
1675 * the reply from the remote client the `key_agreement' client operation
1676 * callback will be called to verify whether the user wants to perform the
1677 * key agreement or not.
1681 * NOTE: If the application provided the `hostname' and the `port' and the
1682 * remote side initiates the key agreement protocol it is not verified
1683 * from the user anymore whether the protocol should be executed or not.
1684 * By setting the `hostname' and `port' the user gives permission to
1685 * perform the protocol (we are responder in this case).
1687 * NOTE: If the remote side decides not to initiate the key agreement
1688 * or decides not to reply with the key agreement packet then we cannot
1689 * perform the key agreement at all. If the key agreement protocol is
1690 * performed the `completion' callback with the `context' will be called.
1691 * If remote side decides to ignore the request the `completion' will be
1692 * called after the specified timeout, `timeout_secs'.
1694 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1695 * will not be called at all since this does nothing more than sending
1696 * a packet to the remote host.
1698 * NOTE: There can be only one active key agreement for one client entry.
1699 * Before setting new one, the old one must be finished (it is finished
1700 * after calling the completion callback) or the function
1701 * silc_client_abort_key_agreement must be called.
1704 void silc_client_send_key_agreement(SilcClient client,
1705 SilcClientConnection conn,
1706 SilcClientEntry client_entry,
1707 const char *hostname,
1708 const char *bindhost,
1710 SilcUInt32 timeout_secs,
1711 SilcKeyAgreementCallback completion,
1714 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1719 * silc_client_perform_key_agreement(SilcClient client,
1720 * SilcClientConnection conn,
1721 * SilcClientEntry client_entry,
1724 * SilcKeyAgreementCallback completion,
1729 * Performs the actual key agreement protocol. Application may use this
1730 * to initiate the key agreement protocol. This can be called for example
1731 * after the application has received the `key_agreement' client operation,
1732 * and did not return TRUE from it.
1734 * The `hostname' is the remote hostname (or IP address) and the `port'
1735 * is the remote port. The `completion' callback with the `context' will
1736 * be called after the key agreement protocol.
1740 * NOTE: If the application returns TRUE in the `key_agreement' client
1741 * operation the library will automatically start the key agreement. In this
1742 * case the application must not call this function. However, application
1743 * may choose to just ignore the `key_agreement' client operation (and
1744 * merely just print information about it on the screen) and call this
1745 * function when the user whishes to do so (by, for example, giving some
1746 * specific command). Thus, the API provides both, automatic and manual
1747 * initiation of the key agreement. Calling this function is the manual
1748 * initiation and returning TRUE in the `key_agreement' client operation
1749 * is the automatic initiation.
1752 void silc_client_perform_key_agreement(SilcClient client,
1753 SilcClientConnection conn,
1754 SilcClientEntry client_entry,
1757 SilcKeyAgreementCallback completion,
1760 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1765 * silc_client_perform_key_agreement_fd(SilcClient client,
1766 * SilcClientConnection conn,
1767 * SilcClientEntry client_entry,
1770 * SilcKeyAgreementCallback completion,
1775 * Same as above but application has created already the connection to
1776 * the remote host. The `sock' is the socket to the remote connection.
1777 * Application can use this function if it does not want the client library
1778 * to create the connection.
1781 void silc_client_perform_key_agreement_fd(SilcClient client,
1782 SilcClientConnection conn,
1783 SilcClientEntry client_entry,
1786 SilcKeyAgreementCallback completion,
1789 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1793 * void silc_client_abort_key_agreement(SilcClient client,
1794 * SilcClientConnection conn,
1795 * SilcClientEntry client_entry);
1799 * This function can be called to unbind the hostname and the port for
1800 * the key agreement protocol. However, this function has effect only
1801 * before the key agreement protocol has been performed. After it has
1802 * been performed the library will automatically unbind the port. The
1803 * `client_entry' is the client to which we sent the key agreement
1804 * request. The key agreement completion callback will be called
1805 * with SILC_KEY_AGREEMENT_ABORTED status.
1808 void silc_client_abort_key_agreement(SilcClient client,
1809 SilcClientConnection conn,
1810 SilcClientEntry client_entry);
1813 /* Misc functions */
1815 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1819 * void silc_client_set_away_message(SilcClient client,
1820 * SilcClientConnection conn,
1825 * Sets away `message'. The away message may be set when the client's
1826 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1827 * to anyone who sends private message. The `message' will be sent
1828 * automatically back to the the client who send private message. If
1829 * away message is already set this replaces the old message with the
1830 * new one. If `message' is NULL the old away message is removed.
1831 * The sender may freely free the memory of the `message'.
1834 void silc_client_set_away_message(SilcClient client,
1835 SilcClientConnection conn,
1839 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1843 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1844 * SilcClientConnection conn,
1845 * SilcAuthMethod auth_meth,
1850 * Connection authentication method request callback. This is called
1851 * by the client library after it has received the authentication method
1852 * that the application requested by calling the function
1853 * silc_client_request_authentication_method.
1856 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1857 SilcClientConnection conn,
1858 SilcAuthMethod auth_meth,
1861 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1866 * silc_client_request_authentication_method(SilcClient client,
1867 * SilcClientConnection conn,
1868 * SilcConnectionAuthRequest
1874 * This function can be used to request the current authentication method
1875 * from the server. This may be called when connecting to the server
1876 * and the client library requests the authentication data from the
1877 * application. If the application does not know the current authentication
1878 * method it can request it from the server using this function.
1879 * The `callback' with `context' will be called after the server has
1880 * replied back with the current authentication method.
1884 silc_client_request_authentication_method(SilcClient client,
1885 SilcClientConnection conn,
1886 SilcConnectionAuthRequest callback,
1889 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1893 * typedef enum { ... } SilcClientMonitorStatus;
1897 * File transmission session status types. These will indicate
1898 * the status of the file transmission session.
1903 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1904 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1905 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1906 SILC_CLIENT_FILE_MONITOR_GET,
1907 SILC_CLIENT_FILE_MONITOR_PUT,
1908 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
1909 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
1910 } SilcClientMonitorStatus;
1913 /****d* silcclient/SilcClientAPI/SilcClientFileError
1917 * typedef enum { ... } SilcClientFileError;
1921 * File transmission error types. These types are returned by
1922 * some of the file transmission functions, and by the monitor
1923 * callback to indicate error.
1928 SILC_CLIENT_FILE_OK,
1929 SILC_CLIENT_FILE_ERROR,
1930 SILC_CLIENT_FILE_UNKNOWN_SESSION,
1931 SILC_CLIENT_FILE_ALREADY_STARTED,
1932 SILC_CLIENT_FILE_NO_SUCH_FILE,
1933 SILC_CLIENT_FILE_PERMISSION_DENIED,
1934 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
1935 } SilcClientFileError;
1938 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
1942 * typedef void (*SilcClientFileMonitor)(SilcClient client,
1943 * SilcClientConnection conn,
1944 * SilcClientMonitorStatus status,
1945 * SilcClientFileError error,
1946 * SilcUInt64 offset,
1947 * SilcUInt64 filesize,
1948 * SilcClientEntry client_entry,
1949 * SilcUInt32 session_id,
1950 * const char *filepath,
1955 * Monitor callback that is called during the file transmission to
1956 * monitor the transmission process. The `status' indicates the current
1957 * monitoring process. The `error' will indicate the error type
1958 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
1959 * currently transmitted amount of total `filesize'. The `client_entry'
1960 * indicates the remote client, and the transmission session ID is the
1961 * `session_id'. The filename being transmitted is indicated by the
1965 typedef void (*SilcClientFileMonitor)(SilcClient client,
1966 SilcClientConnection conn,
1967 SilcClientMonitorStatus status,
1968 SilcClientFileError error,
1970 SilcUInt64 filesize,
1971 SilcClientEntry client_entry,
1972 SilcUInt32 session_id,
1973 const char *filepath,
1976 /****f* silcclient/SilcClientAPI/silc_client_file_send
1980 * SilcClientFileError
1981 * silc_client_file_send(SilcClient client,
1982 * SilcClientConnection conn,
1983 * SilcClientFileMonitor monitor,
1984 * void *monitor_context,
1985 * const char *local_ip,
1986 * SilcUInt32 local_port,
1987 * SilcClientEntry client_entry,
1988 * const char *filepath);
1989 * SilcUInt32 *session_id);
1993 * Sends a file indicated by the `filepath' to the remote client
1994 * indicated by the `client_entry'. This will negotiate a secret key
1995 * with the remote client before actually starting the transmission of
1996 * the file. The `monitor' callback will be called to monitor the
1997 * transmission of the file.
1999 * This returns a file session ID for the file transmission to the
2000 * `session_id' pointer.. It can be used to close the session (and
2001 * abort the file transmission) by calling the silc_client_file_close
2002 * function. The session ID is also returned in the `monitor' callback.
2004 * If the `local_ip' is provided then this will try to bind the
2005 * listener for key exchange protocol to that IP. If `local_port' is
2006 * non-zero that port is used. If `local_ip' is NULL then this will
2007 * automatically attempt to bind it to local IP address of the machine.
2008 * If that fails then this does not bind to any address and port, and
2009 * assume that the remote client will provide the listener for the
2010 * key exchange protocol.
2012 * If error will occur during the file transfer process the error
2013 * status will be returned in the monitor callback. In this case
2014 * the application must call silc_client_file_close to close the
2019 silc_client_file_send(SilcClient client,
2020 SilcClientConnection conn,
2021 SilcClientFileMonitor monitor,
2022 void *monitor_context,
2023 const char *local_ip,
2024 SilcUInt32 local_port,
2025 SilcClientEntry client_entry,
2026 const char *filepath,
2027 SilcUInt32 *session_id);
2029 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2033 * SilcClientFileError
2034 * silc_client_file_receive(SilcClient client,
2035 * SilcClientConnection conn,
2036 * SilcClientFileMonitor monitor,
2037 * void *monitor_context,
2038 * SilcUInt32 session_id);
2042 * Receives a file from a client indicated by the `client_entry'. The
2043 * `session_id' indicates the file transmission session and it has been
2044 * received in the `ftp' client operation function. This will actually
2045 * perform the key agreement protocol with the remote client before
2046 * actually starting the file transmission. The `monitor' callback
2047 * will be called to monitor the transmission.
2049 * If error will occur during the file transfer process the error
2050 * status will be returned in the monitor callback. In this case
2051 * the application must call silc_client_file_close to close the
2056 silc_client_file_receive(SilcClient client,
2057 SilcClientConnection conn,
2058 SilcClientFileMonitor monitor,
2059 void *monitor_context,
2060 SilcUInt32 session_id);
2062 /****f* silcclient/SilcClientAPI/silc_client_file_close
2066 * SilcClientFileError silc_client_file_close(SilcClient client,
2067 * SilcClientConnection conn,
2068 * SilcUInt32 session_id);
2072 * Closes file transmission session indicated by the `session_id'.
2073 * If file transmission is being conducted it will be aborted
2074 * automatically. This function is also used to close the session
2075 * after successful file transmission. This function can be used
2076 * also to reject incoming file transmission request.
2079 SilcClientFileError silc_client_file_close(SilcClient client,
2080 SilcClientConnection conn,
2081 SilcUInt32 session_id);
2084 #include "command.h"
2085 #include "command_reply.h"
2087 #include "protocol.h"
2093 #endif /* SILCCLIENT_H */