5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
57 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct
70 *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
73 /* General definitions */
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
79 * typedef enum { ... } SilcKeyAgreementStatus;
83 * Key agreement status types indicating the status of the key
84 * agreement protocol. These types are returned to the application
85 * in the SilcKeyAgreementCallback callback function.
90 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
91 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
92 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
93 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
94 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
95 } SilcKeyAgreementStatus;
98 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
102 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
103 * SilcClientConnection conn,
104 * SilcClientEntry client_entry,
105 * SilcKeyAgreementStatus status,
106 * SilcSKEKeyMaterial *key,
111 * Key agreement callback that is called after the key agreement protocol
112 * has been performed. This is called also if error occurred during the
113 * key agreement protocol. The `key' is the allocated key material and
114 * the caller is responsible of freeing it. The `key' is NULL if error
115 * has occurred. The application can freely use the `key' to whatever
116 * purpose it needs. See lib/silcske/silcske.h for the definition of
117 * the SilcSKEKeyMaterial structure.
120 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
121 SilcClientConnection conn,
122 SilcClientEntry client_entry,
123 SilcKeyAgreementStatus status,
124 SilcSKEKeyMaterial *key,
127 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
131 * typedef struct { ... } SilcPrivateMessageKeys;
135 * Structure to hold the list of private message keys. The array of this
136 * structure is returned by the silc_client_list_private_message_keys
142 SilcClientEntry client_entry; /* The remote client entry */
143 char *cipher; /* The cipher name */
144 unsigned char *key; /* The original key, If the appliation
145 provided it. This is NULL if the
146 library generated the key or if
147 the SKE key material was used. */
148 SilcUInt32 key_len; /* The key length */
149 } *SilcPrivateMessageKeys;
152 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
156 * typedef struct { ... } SilcChannelPrivateKey;
160 * Structure to hold one channel private key. The array of this structure
161 * is returned by silc_client_list_channel_private_keys function.
165 typedef struct SilcChannelPrivateKeyStruct {
166 char *name; /* Application given name */
167 SilcCipher cipher; /* The cipher and key */
168 SilcHmac hmac; /* The HMAC and hmac key */
169 unsigned char *key; /* The key data */
170 SilcUInt32 key_len; /* The key length */
171 } *SilcChannelPrivateKey;
174 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
178 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
179 * SilcUInt32 passphrase_len,
184 * Ask passphrase callback. This is called by the application when the
185 * library calls `ask_passphrase' client operation. The callback delivers
186 * the passphrase to the library. The passphrases in SILC protocol
187 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
188 * encoded, and if it is not then library will attempt to encode it.
191 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
192 SilcUInt32 passphrase_len,
195 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
199 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
203 * Public key (or certificate) verification callback. This is called
204 * by the application to indicate that the public key verification was
205 * either success or failure.
208 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
210 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
214 * typedef void (*SilcGetAuthMeth)(bool success,
215 * SilcProtocolAuthMeth auth_meth,
216 * const unsigned char *auth_data,
217 * SilcUInt32 auth_data_len, void *context);
221 * Authentication method resolving callback. This is called by the
222 * application to return the resolved authentication method. The client
223 * library has called the get_auth_method client operation and given
224 * this function pointer as argument. The `success' will indicate whether
225 * the authentication method could be resolved. The `auth_meth' is the
226 * resolved authentication method. The `auth_data' and the `auth_data_len'
227 * are the resolved authentication data. The `context' is the libary's
228 * context sent to the get_auth_method client operation.
231 typedef void (*SilcGetAuthMeth)(bool success,
232 SilcProtocolAuthMeth auth_meth,
233 const unsigned char *auth_data,
234 SilcUInt32 auth_data_len, void *context);
236 /****d* silcclient/SilcClientAPI/SilcClientMessageType
240 * typedef enum { ... } SilcClientMessageType;
244 * Different message types for `say' client operation. The application
245 * may filter the message sent by the library according this type.
250 SILC_CLIENT_MESSAGE_INFO, /* Informational */
251 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
252 SILC_CLIENT_MESSAGE_ERROR, /* Error */
253 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
254 } SilcClientMessageType;
257 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
261 * typedef enum { ... } SilcClientConnectionStatus
265 * This type is returned to the `connect' client operation to indicate
266 * the status of the created connection. It can indicated if it was
267 * successful or whether an error occurred.
272 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
273 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
274 resumed old detached session */
275 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
276 } SilcClientConnectionStatus;
279 /****s* silcclient/SilcClientAPI/SilcClientOperations
283 * typedef struct { ... } SilcClientOperations;
287 * SILC Client Operations. These must be implemented by the application.
288 * The Client library may call any of these routines at any time. The
289 * routines are used to deliver certain information to the application
290 * or from the application to the client library.
295 /* Message sent to the application by library. `conn' associates the
296 message to a specific connection. `conn', however, may be NULL.
297 The `type' indicates the type of the message sent by the library.
298 The applicationi can for example filter the message according the
300 void (*say)(SilcClient client, SilcClientConnection conn,
301 SilcClientMessageType type, char *msg, ...);
303 /* Message for a channel. The `sender' is the sender of the message
304 The `channel' is the channel. The `msg' is the message. Note that
306 void (*channel_message)(SilcClient client, SilcClientConnection conn,
307 SilcClientEntry sender, SilcChannelEntry channel,
308 SilcMessageFlags flags,
309 const unsigned char *message,
310 SilcUInt32 message_len);
312 /* Private message to the client. The `sender' is the sender of the
314 void (*private_message)(SilcClient client, SilcClientConnection conn,
315 SilcClientEntry sender, SilcMessageFlags flags,
316 const unsigned char *message,
317 SilcUInt32 message_len);
319 /* Notify message to the client. The notify arguments are sent in the
320 same order as servers sends them. The arguments are same as received
321 from the server except for ID's. If ID is received application receives
322 the corresponding entry to the ID. For example, if Client ID is received
323 application receives SilcClientEntry. Also, if the notify type is
324 for channel the channel entry is sent to application (even if server
325 does not send it because client library gets the channel entry from
326 the Channel ID in the packet's header). */
327 void (*notify)(SilcClient client, SilcClientConnection conn,
328 SilcNotifyType type, ...);
330 /* Command handler. This function is called always in the command function.
331 If error occurs it will be called as well. `conn' is the associated
332 client connection. `cmd_context' is the command context that was
333 originally sent to the command. `success' is FALSE if error occurred
334 during command. `command' is the command being processed. It must be
335 noted that this is not reply from server. This is merely called just
336 after application has called the command. Just to tell application
337 that the command really was processed. */
338 void (*command)(SilcClient client, SilcClientConnection conn,
339 SilcClientCommandContext cmd_context, bool success,
340 SilcCommand command, SilcStatus status);
342 /* Command reply handler. This function is called always in the command reply
343 function. If error occurs it will be called as well. Normal scenario
344 is that it will be called after the received command data has been parsed
345 and processed. The function is used to pass the received command data to
348 `conn' is the associated client connection. `cmd_payload' is the command
349 payload data received from server and it can be ignored. It is provided
350 if the application would like to re-parse the received command data,
351 however, it must be noted that the data is parsed already by the library
352 thus the payload can be ignored. `success' is FALSE if error occurred.
353 In this case arguments are not sent to the application. The `status' is
354 the command reply status server returned. The `command' is the command
355 reply being processed. The function has variable argument list and each
356 command defines the number and type of arguments it passes to the
357 application (on error they are not sent).
359 The arguments are sent in the same order as servers sends them. The
360 arguments are same as received from the server except for ID's. If
361 ID is received application receives the corresponding entry to the
362 ID. For example, if Client ID is receives application receives
364 void (*command_reply)(SilcClient client, SilcClientConnection conn,
365 SilcCommandPayload cmd_payload, bool success,
366 SilcCommand command, SilcStatus status, ...);
368 /* Called to indicate that connection was either successfully established
369 or connecting failed. This is also the first time application receives
370 the SilcClientConnection object which it should save somewhere.
371 The `status' indicated whether the connection were successful. If it
372 is error value the application must always call the function
373 silc_client_close_connection. */
374 void (*connect)(SilcClient client, SilcClientConnection conn,
375 SilcClientConnectionStatus status);
377 /* Called to indicate that connection was disconnected to the server. */
378 void (*disconnect)(SilcClient client, SilcClientConnection conn);
380 /* Find authentication method and authentication data by hostname and
381 port. The hostname may be IP address as well. When the authentication
382 method has been resolved the `completion' callback with the found
383 authentication method and authentication data is called. The `conn'
385 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
386 char *hostname, SilcUInt16 port,
387 SilcGetAuthMeth completion, void *context);
389 /* Verifies received public key. The `conn_type' indicates which entity
390 (server, client etc.) has sent the public key. If user decides to trust
391 the key may be saved as trusted public key for later use. The
392 `completion' must be called after the public key has been verified. */
393 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
394 SilcSocketType conn_type, unsigned char *pk,
395 SilcUInt32 pk_len, SilcSKEPKType pk_type,
396 SilcVerifyPublicKey completion, void *context);
398 /* Ask (interact, that is) a passphrase from user. The passphrase is
399 returned to the library by calling the `completion' callback with
400 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
401 if not then the library will attempt to encode. */
402 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
403 SilcAskPassphrase completion, void *context);
405 /* Notifies application that failure packet was received. This is called
406 if there is some protocol active in the client. The `protocol' is the
407 protocol context. The `failure' is opaque pointer to the failure
408 indication. Note, that the `failure' is protocol dependant and
409 application must explicitly cast it to correct type. Usually `failure'
410 is 32 bit failure type (see protocol specs for all protocol failure
412 void (*failure)(SilcClient client, SilcClientConnection conn,
413 SilcProtocol protocol, void *failure);
415 /* Asks whether the user would like to perform the key agreement protocol.
416 This is called after we have received an key agreement packet or an
417 reply to our key agreement packet. This returns TRUE if the user wants
418 the library to perform the key agreement protocol and FALSE if it is not
419 desired (application may start it later by calling the function
420 silc_client_perform_key_agreement). If TRUE is returned also the
421 `completion' and `context' arguments must be set by the application. */
422 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
423 SilcClientEntry client_entry, const char *hostname,
424 SilcUInt16 port, SilcKeyAgreementCallback *completion,
427 /* Notifies application that file transfer protocol session is being
428 requested by the remote client indicated by the `client_entry' from
429 the `hostname' and `port'. The `session_id' is the file transfer
430 session and it can be used to either accept or reject the file
431 transfer request, by calling the silc_client_file_receive or
432 silc_client_file_close, respectively. */
433 void (*ftp)(SilcClient client, SilcClientConnection conn,
434 SilcClientEntry client_entry, SilcUInt32 session_id,
435 const char *hostname, SilcUInt16 port);
437 /* Delivers SILC session detachment data indicated by `detach_data' to the
438 application. If application has issued SILC_COMMAND_DETACH command
439 the client session in the SILC network is not quit. The client remains
440 in the network but is detached. The detachment data may be used later
441 to resume the session in the SILC Network. The appliation is
442 responsible of saving the `detach_data', to for example in a file.
444 The detachment data can be given as argument to the functions
445 silc_client_connect_to_server, or silc_client_add_connection when
446 creating connection to remote server, inside SilcClientConnectionParams
447 structure. If it is provided the client library will attempt to resume
448 the session in the network. After the connection is created
449 successfully, the application is responsible of setting the user
450 interface for user into the same state it was before detaching (showing
451 same channels, channel modes, etc). It can do this by fetching the
452 information (like joined channels) from the client library. */
453 void (*detach)(SilcClient client, SilcClientConnection conn,
454 const unsigned char *detach_data,
455 SilcUInt32 detach_data_len);
456 } SilcClientOperations;
459 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
463 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
464 * char **ret_nickname);
468 * A callback function provided by the application for the library in
469 * SilcClientParams structure. This function parses the formatted
470 * nickname string `nickname' and returns the true nickname to the
471 * `ret_nickname' pointer. The library can call this function at
475 typedef void (*SilcNicknameFormatParse)(const char *nickname,
476 char **ret_nickname);
478 /****s* silcclient/SilcClientAPI/SilcClientParams
482 * typedef struct { ... } SilcClientParams;
486 * Client parameters. This can be filled with proper values and
487 * given as argument to the silc_client_alloc function. The structure
488 * hold various parameters which affects the function of the client.
493 /* Number of maximum tasks the client library's scheduler can handle.
494 If set to zero, the default value will be used (200). For WIN32
495 systems this should be set to 64 as it is the hard limit dictated
499 /* Rekey timeout in seconds. The client will perform rekey in this
500 time interval. If set to zero, the default value will be used. */
501 unsigned int rekey_secs;
503 /* Connection authentication method request timeout. If server does not
504 reply back the current authentication method when we've requested it
505 in this time interval we'll assume the reply will not come at all.
506 If set to zero, the default value (2 seconds) will be used. */
507 unsigned int connauth_request_secs;
509 /* Nickname format string. This can be used to order the client library
510 to save the nicknames in the library in a certain format. Since
511 nicknames are not unique in SILC it is possible to have multiple same
512 nicknames. Using this format string it is possible to order the library
513 to separate the multiple same nicknames from each other. The format
514 types are defined below and they can appear in any order in the format
515 string. If this is NULL then default format is used which is the
516 default nickname without anything else. The string MUST be NULL
519 Following format types are available:
521 %n nickname - the real nickname returned by the server (mandatory)
522 %h hostname - the stripped hostname of the client
523 %H full hostname - the full hostname of the client
524 %s server name - the server name the client is connected
525 %S full server - the full server name the client is connected
526 %a number - ascending number in case there are several
527 same nicknames (fe. nick@host and nick@host2)
529 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
530 "%a!%n@%s" (fe. nick@server, 2!nick@server)
531 "%n@%H" (fe. nick@host.domain.com)
533 By default this format is employed to the nicknames by the libary
534 only when there appears multiple same nicknames. If the library has
535 only one nickname cached the nickname is saved as is and without the
536 defined format. If you want always to save the nickname in the defined
537 format set the boolean field `nickname_force_format' to value TRUE.
539 char nickname_format[32];
541 /* If this is set to TRUE then the `nickname_format' is employed to all
542 saved nicknames even if there are no multiple same nicknames in the
543 cache. By default this is FALSE, which means that the `nickname_format'
544 is employed only if the library will receive a nickname that is
545 already saved in the cache. It is recommended to leave this to FALSE
547 bool nickname_force_format;
549 /* A callback function provided by the application for the library to
550 parse the nickname from the formatted nickname string. Even though
551 the libary formats the nicknames the application knows generally the
552 format better so this function should be provided for the library
553 if the application sets the `nickname_format' field. The library
554 will call this to get the true nickname from the provided formatted
555 nickname string whenever it needs the true nickname. */
556 SilcNicknameFormatParse nickname_parse;
562 /* Initialization functions (client.c) */
564 /****f* silcclient/SilcClientAPI/silc_client_alloc
568 * SilcClient silc_client_alloc(SilcClientOperations *ops,
569 * SilcClientParams *params,
571 * const char *silc_version);
575 * Allocates new client object. This has to be done before client may
576 * work. After calling this one must call silc_client_init to initialize
577 * the client. The `application' is application specific user data pointer
578 * and caller must free it. The `silc_version' is the application version
579 * that will be used to compare against remote host's (usually a server)
580 * version string. The `application' context is accessible by the
581 * application by client->application, client being SilcClient.
584 SilcClient silc_client_alloc(SilcClientOperations *ops,
585 SilcClientParams *params,
587 const char *silc_version);
589 /****f* silcclient/SilcClientAPI/silc_client_free
593 * void silc_client_free(SilcClient client);
597 * Frees client object and its internals. The execution of the client
598 * should be stopped with silc_client_stop function before calling
602 void silc_client_free(SilcClient client);
604 /****f* silcclient/SilcClientAPI/silc_client_init
608 * int silc_client_init(SilcClient client);
612 * Initializes the client. This makes all the necessary steps to make
613 * the client ready to be run. One must call silc_client_run to run the
614 * client. Returns FALSE if error occurred, TRUE otherwise.
617 int silc_client_init(SilcClient client);
619 /****f* silcclient/SilcClientAPI/silc_client_run
623 * void silc_client_run(SilcClient client);
627 * Runs the client. This starts the scheduler from the utility library.
628 * When this functions returns the execution of the appliation is over.
631 void silc_client_run(SilcClient client);
633 /****f* silcclient/SilcClientAPI/silc_client_run_one
637 * void silc_client_run_one(SilcClient client);
641 * Runs the client and returns immeadiately. This function is used when
642 * the SILC Client object indicated by the `client' is run under some
643 * other scheduler, or event loop or main loop. On GUI applications,
644 * for example this may be desired to used to run the client under the
645 * GUI application's main loop. Typically the GUI application would
646 * register an idle task that calls this function multiple times in
647 * a second to quickly process the SILC specific data.
650 void silc_client_run_one(SilcClient client);
652 /****f* silcclient/SilcClientAPI/silc_client_stop
656 * void silc_client_stop(SilcClient client);
660 * Stops the client. This is called to stop the client and thus to stop
661 * the program. The client context must be freed with the silc_client_free
665 void silc_client_stop(SilcClient client);
668 /* Connecting functions (client.c) */
670 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
674 * typedef struct { ... } SilcClientConnectionParams;
678 * Client connection parameters. This can be filled by the application
679 * and given as argument to silc_client_connect_to_server or to
680 * silc_client_add_connection.
685 /* The SILC session detachment data that was returned by `detach' client
686 operation when the application detached from the network. Application
687 is responsible of saving the data and giving it as argument here
688 for resuming the session in the SILC network.
690 If this is provided here the client library will attempt to resume
691 the session in the network. After the connection is created
692 successfully, the application is responsible of setting the user
693 interface for user into the same state it was before detaching (showing
694 same channels, channel modes, etc). It can do this by fetching the
695 information (like joined channels) from the client library. */
696 unsigned char *detach_data;
697 SilcUInt32 detach_data_len;
699 } SilcClientConnectionParams;
702 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
706 * int silc_client_connect_to_server(SilcClient client,
707 * SilcClientConnectionParams *params,
708 * int port, char *host, void *context);
712 * Connects to remote server. This is the main routine used to connect
713 * to SILC server. Returns -1 on error and the created socket otherwise.
714 * The `context' is user context that is saved into the SilcClientConnection
715 * that is created after the connection is created. Note that application
716 * may handle the connecting process outside the library. If this is the
717 * case then this function is not used at all. When the connecting is
718 * done the `connect' client operation is called, and the `context' is
719 * accessible with conn->context, conn being SilcClientConnection.
720 * If the `params' is provided they are used by the routine.
723 int silc_client_connect_to_server(SilcClient client,
724 SilcClientConnectionParams *params,
725 int port, char *host, void *context);
727 /****f* silcclient/SilcClientAPI/silc_client_add_connection
732 * SilcClientConnection
733 * silc_client_add_connection(SilcClient client,
734 * SilcClientConnectionParams *params,
735 * char *hostname, int port, void *context);
739 * Allocates and adds new connection to the client. This adds the allocated
740 * connection to the connection table and returns a pointer to it. A client
741 * can have multiple connections to multiple servers. Every connection must
742 * be added to the client using this function. User data `context' may
743 * be sent as argument. If the `params' is provided they are used by
748 * This function is normally used only if the application performed
749 * the connecting outside the library, and did not called the
750 * silc_client_connect_to_server function at all. The library
751 * however may use this internally.
755 silc_client_add_connection(SilcClient client,
756 SilcClientConnectionParams *params,
757 char *hostname, int port, void *context);
759 /****f* silcclient/SilcClientAPI/silc_client_del_connection
763 * void silc_client_del_connection(SilcClient client,
764 * SilcClientConnection conn);
768 * Removes connection from client. Frees all memory. The library
769 * call this function automatically for all connection contexts.
770 * The application however may free the connection contexts it has
774 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
776 /****f* silcclient/SilcClientAPI/silc_client_add_socket
780 * void silc_client_add_socket(SilcClient client,
781 * SilcSocketConnection sock);
785 * Adds listener socket to the listener sockets table. This function is
786 * used to add socket objects that are listeners to the client. This should
787 * not be used to add other connection objects.
790 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
792 /****f* silcclient/SilcClientAPI/silc_client_del_socket
796 * void silc_client_del_socket(SilcClient client,
797 * SilcSocketConnection sock);
801 * Deletes listener socket from the listener sockets table. If the
802 * application has added a socket with silc_client_add_socket it must
803 * also free it using this function.
806 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
808 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
812 * void silc_client_start_key_exchange(SilcClient client,
813 * SilcClientConnection conn,
818 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
819 * key material between client and server. This function can be called
820 * directly if application is performing its own connecting and does not
821 * use the connecting provided by this library. This function is normally
822 * used only if the application performed the connecting outside the
823 * library. The library however may use this internally. After the
824 * key exchange is performed the `connect' client operation is called.
827 void silc_client_start_key_exchange(SilcClient client,
828 SilcClientConnection conn,
831 /****f* silcclient/SilcClientAPI/silc_client_close_connection
835 * void silc_client_close_connection(SilcClient client,
836 * SilcClientConnection conn);
840 * Closes connection to remote end. Free's all allocated data except
841 * for some information such as nickname etc. that are valid at all time.
844 void silc_client_close_connection(SilcClient client,
845 SilcClientConnection conn);
848 /* Message sending functions (client_channel.c and client_prvmsg.c) */
850 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
854 * void silc_client_send_channel_message(SilcClient client,
855 * SilcClientConnection conn,
856 * SilcChannelEntry channel,
857 * SilcChannelPrivateKey key,
858 * SilcMessageFlags flags,
859 * unsigned char *data,
860 * SilcUInt32 data_len,
865 * Sends packet to the `channel'. Packet to channel is always encrypted
866 * differently from "normal" packets. SILC header of the packet is
867 * encrypted with the next receiver's key and the rest of the packet is
868 * encrypted with the channel specific key. Padding and HMAC is computed
869 * with the next receiver's key. The `data' is the channel message. If
870 * the `force_send' is TRUE then the packet is sent immediately.
872 * If `key' is provided then that private key is used to encrypt the
873 * channel message. If it is not provided, private keys has not been
874 * set at all, the normal channel key is used automatically. If private
875 * keys are set then the first key (the key that was added first as
876 * private key) is used.
879 void silc_client_send_channel_message(SilcClient client,
880 SilcClientConnection conn,
881 SilcChannelEntry channel,
882 SilcChannelPrivateKey key,
883 SilcMessageFlags flags,
888 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
892 * void silc_client_send_private_message(SilcClient client,
893 * SilcClientConnection conn,
894 * SilcClientEntry client_entry,
895 * SilcMessageFlags flags,
896 * unsigned char *data,
897 * SilcUInt32 data_len,
902 * Sends private message to remote client. If private message key has
903 * not been set with this client then the message will be encrypted using
904 * normal session keys. Private messages are special packets in SILC
905 * network hence we need this own function for them. This is similar
906 * to silc_client_packet_send_to_channel except that we send private
907 * message. The `data' is the private message. If the `force_send' is
908 * TRUE the packet is sent immediately.
911 void silc_client_send_private_message(SilcClient client,
912 SilcClientConnection conn,
913 SilcClientEntry client_entry,
914 SilcMessageFlags flags,
920 /* Client and Channel entry retrieval (idlist.c) */
922 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
926 * typedef void (*SilcGetClientCallback)(SilcClient client,
927 * SilcClientConnection conn,
928 * SilcClientEntry *clients,
929 * SilcUInt32 clients_count,
934 * Callback function given to the silc_client_get_client function. The
935 * found entries are allocated into the `clients' array. The array must
936 * not be freed by the receiver, the library will free it later. If the
937 * `clients' is NULL, no such clients exist in the SILC Network.
940 typedef void (*SilcGetClientCallback)(SilcClient client,
941 SilcClientConnection conn,
942 SilcClientEntry *clients,
943 SilcUInt32 clients_count,
946 /****f* silcclient/SilcClientAPI/silc_client_get_clients
950 * void silc_client_get_clients(SilcClient client,
951 * SilcClientConnection conn,
952 * const char *nickname,
953 * const char *server,
954 * SilcGetClientCallback completion,
959 * Finds client entry or entries by the `nickname' and `server'. The
960 * completion callback will be called when the client entries has been
961 * found. After the server returns the client information it is cached
962 * and can be accesses locally at a later time.
966 * NOTE: This function is always asynchronous and resolves the client
967 * information from the server. Thus, if you already know the client
968 * information then use the silc_client_get_client_by_id function to
969 * get the client entry since this function may be very slow and should
970 * be used only to initially get the client entries.
973 void silc_client_get_clients(SilcClient client,
974 SilcClientConnection conn,
975 const char *nickname,
977 SilcGetClientCallback completion,
980 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
984 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
985 * SilcClientConnection conn,
986 * const char *nickname,
987 * const char *format,
988 * SilcUInt32 *clients_count);
992 * Same as silc_client_get_clients function but does not resolve anything
993 * from the server. This checks local cache and returns all matching
994 * clients from the local cache. If none was found this returns NULL.
995 * The `nickname' is the real nickname of the client, and the `format'
996 * is the formatted nickname to find exact match from multiple found
997 * entries. The format must be same as given in the SilcClientParams
998 * structure to the client library. If the `format' is NULL all found
999 * clients by `nickname' are returned. The caller must return the
1003 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1004 SilcClientConnection conn,
1005 const char *nickname,
1007 SilcUInt32 *clients_count);
1009 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1013 * void silc_client_get_clients_by_list(SilcClient client,
1014 * SilcClientConnection conn,
1015 * SilcUInt32 list_count,
1016 * SilcBuffer client_id_list,
1017 * SilcGetClientCallback completion,
1022 * Gets client entries by the list of client ID's `client_id_list'. This
1023 * always resolves those client ID's it does not know yet from the server
1024 * so this function might take a while. The `client_id_list' is a list
1025 * of ID Payloads added one after other. JOIN command reply and USERS
1026 * command reply for example returns this sort of list. The `completion'
1027 * will be called after the entries are available. When server returns
1028 * the client information it will be cached and can be accessed locally
1032 void silc_client_get_clients_by_list(SilcClient client,
1033 SilcClientConnection conn,
1034 SilcUInt32 list_count,
1035 SilcBuffer client_id_list,
1036 SilcGetClientCallback completion,
1039 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1043 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1044 * SilcClientConnection conn,
1045 * SilcClientID *client_id);
1049 * Find entry for client by the client's ID. Returns the entry or NULL
1050 * if the entry was not found. This checks the local cache and does
1051 * not resolve anything from server.
1054 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1055 SilcClientConnection conn,
1056 SilcClientID *client_id);
1058 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1063 * silc_client_get_client_by_id_resolve(SilcClient client,
1064 * SilcClientConnection conn,
1065 * SilcClientID *client_id,
1066 * SilcGetClientCallback completion,
1071 * Same as silc_client_get_client_by_id but will always resolve the
1072 * information from the server. Use this only if you know that you
1073 * do not have the entry and the only thing you know about the client
1074 * is its ID. When server returns the client information it will be
1075 * cache and can be accessed locally at a later time.
1078 void silc_client_get_client_by_id_resolve(SilcClient client,
1079 SilcClientConnection conn,
1080 SilcClientID *client_id,
1081 SilcGetClientCallback completion,
1084 /****f* silcclient/SilcClientAPI/silc_client_del_client
1088 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1089 * SilcClientEntry client_entry)
1093 * Removes client from local cache by the client entry indicated by
1094 * the `client_entry'. Returns TRUE if the deletion were successful.
1097 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1098 SilcClientEntry client_entry);
1100 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1104 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1105 * SilcClientConnection conn,
1106 * SilcChannelEntry *channels,
1107 * SilcUInt32 channels_count,
1112 * Callback function given to the silc_client_get_channel_* functions.
1113 * The found entries are allocated into the `channels' array. The array
1114 * must not be freed by the receiver, the library will free it later.
1115 * If the `channel' is NULL, no such channel exist in the SILC Network.
1118 typedef void (*SilcGetChannelCallback)(SilcClient client,
1119 SilcClientConnection conn,
1120 SilcChannelEntry *channels,
1121 SilcUInt32 channels_count,
1124 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1128 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1129 * SilcClientConnection conn,
1134 * Finds entry for channel by the channel name. Returns the entry or NULL
1135 * if the entry was not found. It is found only if the client is joined
1139 SilcChannelEntry silc_client_get_channel(SilcClient client,
1140 SilcClientConnection conn,
1143 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1148 * silc_client_get_channel_by_id_resolve(SilcClient client,
1149 * SilcClientConnection conn,
1150 * SilcChannelID *channel_id,
1151 * SilcGetClientCallback completion,
1156 * Finds channel entry by the channel name. Returns the entry or NULL
1157 * if it was not found.
1160 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1161 SilcClientConnection conn,
1162 SilcChannelID *channel_id);
1164 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1169 * silc_client_get_channel_by_id_resolve(SilcClient client,
1170 * SilcClientConnection conn,
1171 * SilcChannelID *channel_id,
1172 * SilcGetClientCallback completion,
1177 * Resolves the channel information (its name mainly) from the server
1178 * by the `channel_id'. Use this only if you know that you do not have
1179 * the entry cached locally.
1182 void silc_client_get_channel_by_id_resolve(SilcClient client,
1183 SilcClientConnection conn,
1184 SilcChannelID *channel_id,
1185 SilcGetChannelCallback completion,
1188 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1192 * bool silc_client_del_channel(SilcClient client,
1193 * SilcClientConnection conn,
1194 * SilcChannelEntry channel)
1198 * Removes channel from local cache by the channel entry indicated by
1199 * the `channel'. Returns TRUE if the deletion were successful.
1202 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1203 SilcChannelEntry channel);
1205 /****f* silcclient/SilcClientAPI/silc_client_get_server
1209 * SilcServerEntry silc_client_get_server(SilcClient client,
1210 * SilcClientConnection conn,
1211 * char *server_name)
1215 * Finds entry for server by the server name. Returns the entry or NULL
1216 * if the entry was not found.
1219 SilcServerEntry silc_client_get_server(SilcClient client,
1220 SilcClientConnection conn,
1223 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1227 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1228 * SilcClientConnection conn,
1229 * SilcServerID *server_id);
1233 * Finds entry for server by the server ID. Returns the entry or NULL
1234 * if the entry was not found.
1237 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1238 SilcClientConnection conn,
1239 SilcServerID *server_id);
1241 /****f* silcclient/SilcClientAPI/silc_client_del_server
1245 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1246 * SilcServerEntry server);
1250 * Removes server from local cache by the server entry indicated by
1251 * the `server'. Returns TRUE if the deletion were successful.
1254 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1255 SilcServerEntry server);
1257 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1261 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1262 * SilcClientEntry client_entry);
1266 * Returns the ChannelUser entry if the `client_entry' is joined on the
1267 * channel indicated by the `channel'. NULL if client is not joined on
1271 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1272 SilcClientEntry client_entry);
1274 /* Command management (command.c) */
1276 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1280 * SilcClientCommandContext silc_client_command_alloc(void);
1284 * Allocate Command Context. The context is defined in `command.h' file.
1285 * The context is used by the library commands and applications should use
1286 * it as well. However, application may choose to use some own context
1287 * for its local commands. All library commands, however, must use this
1291 SilcClientCommandContext silc_client_command_alloc(void);
1293 /****f* silcclient/SilcClientAPI/silc_client_command_free
1297 * void silc_client_command_free(SilcClientCommandContext ctx);
1301 * Free command context and its internals. If the contex was duplicated
1302 * with silc_client_command_dup this may not actually free the data,
1303 * instead it will decrease the reference counter of the context. The
1304 * context will be freed when the reference counter hits zero.
1307 void silc_client_command_free(SilcClientCommandContext ctx);
1309 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1313 * SilcClientCommandContext
1314 * silc_client_command_dup(SilcClientCommandContext ctx);
1318 * Duplicate Command Context by adding reference counter. The context won't
1319 * be free'd untill it hits zero.
1322 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1324 /****f* silcclient/SilcClientAPI/silc_client_command_find
1328 * SilcClientCommand silc_client_command_find(SilcClient client,
1329 * const char *name);
1333 * Finds and returns a pointer to the command list. Return NULL if the
1334 * command is not found. See the `command.[ch]' for the command list.
1335 * Command names are not case-sensitive.
1338 SilcClientCommand silc_client_command_find(SilcClient client,
1341 /****f* silcclient/SilcClientAPI/silc_client_command_call
1345 * void silc_client_command_call(SilcClientCommand command);
1349 * Calls the command (executes it). Application can call this after
1350 * it has allocated the SilcClientCommandContext with the function
1351 * silc_client_command_alloc and found the command from the client
1352 * library by calling silc_client_command_find. This will execute
1355 * Application can call the command function directly too if it
1356 * wishes to do so. See the command.h for details of the
1357 * SilcClientCommand structure.
1360 void silc_client_command_call(SilcClientCommand command,
1361 SilcClientCommandContext cmd);
1363 /****f* silcclient/SilcClientAPI/silc_client_command_send
1367 * void silc_client_command_send(SilcClient client,
1368 * SilcClientConnection conn,
1369 * SilcCommand command, SilcUInt16 ident,
1370 * SilcUInt32 argc, ...);
1374 * Generic function to send any command. The arguments must be sent already
1375 * encoded into correct form and in correct order. If application wants
1376 * to perform the commands by itself, it can do so and send the data
1377 * directly to the server using this function. If application is using
1378 * the silc_client_command_call, this function is usually not used.
1381 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1382 SilcCommand command, SilcUInt16 ident,
1383 SilcUInt32 argc, ...);
1385 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1389 * void silc_client_command_pending(SilcClientConnection conn,
1390 * SilcCommand reply_cmd,
1392 * SilcCommandCb callback,
1397 * Add new pending command to be executed when reply to a command has been
1398 * received. The `reply_cmd' is the command that will call the `callback'
1399 * with `context' when reply has been received. If `ident' is non-zero
1400 * the `callback' will be executed when received reply with command
1401 * identifier `ident'.
1403 * Note that the application is notified about the received command
1404 * reply through the `command_reply' client operation before calling
1405 * the `callback` pending command callback.
1408 void silc_client_command_pending(SilcClientConnection conn,
1409 SilcCommand reply_cmd,
1411 SilcCommandCb callback,
1415 /* Private Message key management (client_prvmsg.c) */
1417 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1421 * int silc_client_add_private_message_key(SilcClient client,
1422 * SilcClientConnection conn,
1423 * SilcClientEntry client_entry,
1425 * unsigned char *key,
1426 * SilcUInt32 key_len,
1427 * bool generate_key,
1432 * Adds private message key to the client library. The key will be used to
1433 * encrypt all private message between the client and the remote client
1434 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1435 * value `generate_key' is TRUE the library will generate random key.
1436 * The `key' maybe for example pre-shared-key, passphrase or similar.
1437 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1438 * requirements of the SILC protocol are met. The API, however, allows
1439 * to allocate any cipher.
1441 * If `responder' is TRUE then the sending and receiving keys will be
1442 * set according the client being the receiver of the private key. If
1443 * FALSE the client is being the sender (or negotiator) of the private
1446 * It is not necessary to set key for normal private message usage. If the
1447 * key is not set then the private messages are encrypted using normal
1448 * session keys. Setting the private key, however, increases the security.
1450 * Returns FALSE if the key is already set for the `client_entry', TRUE
1454 int silc_client_add_private_message_key(SilcClient client,
1455 SilcClientConnection conn,
1456 SilcClientEntry client_entry,
1463 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1467 * int silc_client_add_private_message_key_ske(SilcClient client,
1468 * SilcClientConnection conn,
1469 * SilcClientEntry client_entry,
1471 * SilcSKEKeyMaterial *key);
1475 * Same as silc_client_add_private_message_key but takes the key material
1476 * from the SKE key material structure. This structure is received if
1477 * the application uses the silc_client_send_key_agreement to negotiate
1478 * the key material. The `cipher' SHOULD be provided as it is negotiated
1479 * also in the SKE protocol.
1482 int silc_client_add_private_message_key_ske(SilcClient client,
1483 SilcClientConnection conn,
1484 SilcClientEntry client_entry,
1486 SilcSKEKeyMaterial *key,
1489 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1493 * int silc_client_send_private_message_key(SilcClient client,
1494 * SilcClientConnection conn,
1495 * SilcClientEntry client_entry,
1500 * Sends private message key payload to the remote client indicated by
1501 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1502 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1503 * application should call this function after setting the key to the
1506 * Note that the key sent using this function is sent to the remote client
1507 * through the SILC network. The packet is protected using normal session
1511 int silc_client_send_private_message_key(SilcClient client,
1512 SilcClientConnection conn,
1513 SilcClientEntry client_entry,
1516 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1520 * int silc_client_del_private_message_key(SilcClient client,
1521 * SilcClientConnection conn,
1522 * SilcClientEntry client_entry);
1526 * Removes the private message from the library. The key won't be used
1527 * after this to protect the private messages with the remote `client_entry'
1528 * client. Returns FALSE on error, TRUE otherwise.
1531 int silc_client_del_private_message_key(SilcClient client,
1532 SilcClientConnection conn,
1533 SilcClientEntry client_entry);
1535 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1539 * SilcPrivateMessageKeys
1540 * silc_client_list_private_message_keys(SilcClient client,
1541 * SilcClientConnection conn,
1542 * SilcUInt32 *key_count);
1546 * Returns array of set private message keys associated to the connection
1547 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1548 * count to the `key_count' argument. The array must be freed by the caller
1549 * by calling the silc_client_free_private_message_keys function. Note:
1550 * the keys returned in the array is in raw format. It might not be desired
1551 * to show the keys as is. The application might choose not to show the keys
1552 * at all or to show the fingerprints of the keys.
1555 SilcPrivateMessageKeys
1556 silc_client_list_private_message_keys(SilcClient client,
1557 SilcClientConnection conn,
1558 SilcUInt32 *key_count);
1560 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1564 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1565 * SilcUInt32 key_count);
1569 * Frees the SilcPrivateMessageKeys array returned by the function
1570 * silc_client_list_private_message_keys.
1573 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1574 SilcUInt32 key_count);
1577 /* Channel private key management (client_channel.c,
1578 SilcChannelPrivateKey is defined in idlist.h) */
1580 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1584 * int silc_client_add_channel_private_key(SilcClient client,
1585 * SilcClientConnection conn,
1586 * SilcChannelEntry channel,
1590 * unsigned char *key,
1591 * SilcUInt32 key_len);
1595 * Adds private key for channel. This may be set only if the channel's mode
1596 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1597 * mode is not set. When channel has private key then the messages are
1598 * encrypted using that key. All clients on the channel must also know the
1599 * key in order to decrypt the messages. However, it is possible to have
1600 * several private keys per one channel. In this case only some of the
1601 * clients on the channel may know the one key and only some the other key.
1602 * The `name' can be application given name for the key.
1604 * The private key for channel is optional. If it is not set then the
1605 * channel messages are encrypted using the channel key generated by the
1606 * server. However, setting the private key (or keys) for the channel
1607 * significantly adds security. If more than one key is set the library
1608 * will automatically try all keys at the message decryption phase. Note:
1609 * setting many keys slows down the decryption phase as all keys has to
1610 * be tried in order to find the correct decryption key. However, setting
1611 * a few keys does not have big impact to the decryption performace.
1615 * NOTE: This is entirely local setting. The key set using this function
1616 * is not sent to the network at any phase.
1618 * NOTE: If the key material was originated by the SKE protocol (using
1619 * silc_client_send_key_agreement) then the `key' MUST be the
1620 * key->send_enc_key as this is dictated by the SILC protocol. However,
1621 * currently it is not expected that the SKE key material would be used
1622 * as channel private key. However, this API allows it.
1625 int silc_client_add_channel_private_key(SilcClient client,
1626 SilcClientConnection conn,
1627 SilcChannelEntry channel,
1632 SilcUInt32 key_len);
1634 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1638 * int silc_client_del_channel_private_keys(SilcClient client,
1639 * SilcClientConnection conn,
1640 * SilcChannelEntry channel);
1644 * Removes all private keys from the `channel'. The old channel key is used
1645 * after calling this to protect the channel messages. Returns FALSE on
1646 * on error, TRUE otherwise.
1649 int silc_client_del_channel_private_keys(SilcClient client,
1650 SilcClientConnection conn,
1651 SilcChannelEntry channel);
1653 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1657 * int silc_client_del_channel_private_key(SilcClient client,
1658 * SilcClientConnection conn,
1659 * SilcChannelEntry channel,
1660 * SilcChannelPrivateKey key);
1664 * Removes and frees private key `key' from the channel `channel'.
1665 * The `key' is retrieved by calling the function
1666 * silc_client_list_channel_private_keys. The key is not used after
1667 * this. If the key was last private key then the old channel key is
1668 * used hereafter to protect the channel messages. This returns FALSE
1669 * on error, TRUE otherwise.
1672 int silc_client_del_channel_private_key(SilcClient client,
1673 SilcClientConnection conn,
1674 SilcChannelEntry channel,
1675 SilcChannelPrivateKey key);
1677 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1681 * SilcChannelPrivateKey *
1682 * silc_client_list_channel_private_keys(SilcClient client,
1683 * SilcClientConnection conn,
1684 * SilcChannelEntry channel,
1685 * SilcUInt32 *key_count);
1689 * Returns array (pointers) of private keys associated to the `channel'.
1690 * The caller must free the array by calling the function
1691 * silc_client_free_channel_private_keys. The pointers in the array may be
1692 * used to delete the specific key by giving the pointer as argument to the
1693 * function silc_client_del_channel_private_key.
1696 SilcChannelPrivateKey *
1697 silc_client_list_channel_private_keys(SilcClient client,
1698 SilcClientConnection conn,
1699 SilcChannelEntry channel,
1700 SilcUInt32 *key_count);
1702 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1706 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1707 * SilcUInt32 key_count);
1711 * Frees the SilcChannelPrivateKey array.
1714 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1715 SilcUInt32 key_count);
1717 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1721 * void silc_client_current_channel_private_key(SilcClient client,
1722 * SilcClientConnection conn,
1723 * SilcChannelEntry channel,
1724 * SilcChannelPrivateKey key);
1728 * Sets the `key' to be used as current channel private key on the
1729 * `channel'. Packet sent after calling this function will be secured
1733 void silc_client_current_channel_private_key(SilcClient client,
1734 SilcClientConnection conn,
1735 SilcChannelEntry channel,
1736 SilcChannelPrivateKey key);
1739 /* Key Agreement routines (client_keyagr.c) */
1741 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1745 * void silc_client_send_key_agreement(SilcClient client,
1746 * SilcClientConnection conn,
1747 * SilcClientEntry client_entry,
1750 * SilcUInt32 timeout_secs,
1751 * SilcKeyAgreementCallback completion,
1756 * Sends key agreement request to the remote client indicated by the
1757 * `client_entry'. If the caller provides the `hostname' and the `port'
1758 * arguments then the library will bind the client to that hostname and
1759 * that port for the key agreement protocol. It also sends the `hostname'
1760 * and the `port' in the key agreement packet to the remote client. This
1761 * would indicate that the remote client may initiate the key agreement
1762 * protocol to the `hostname' on the `port'. If port is zero then the
1763 * bound port is undefined (the operating system defines it).
1765 * If the `hostname' and `port' is not provided then empty key agreement
1766 * packet is sent to the remote client. The remote client may reply with
1767 * the same packet including its hostname and port. If the library receives
1768 * the reply from the remote client the `key_agreement' client operation
1769 * callback will be called to verify whether the user wants to perform the
1770 * key agreement or not.
1774 * NOTE: If the application provided the `hostname' and the `port' and the
1775 * remote side initiates the key agreement protocol it is not verified
1776 * from the user anymore whether the protocol should be executed or not.
1777 * By setting the `hostname' and `port' the user gives permission to
1778 * perform the protocol (we are responder in this case).
1780 * NOTE: If the remote side decides not to initiate the key agreement
1781 * or decides not to reply with the key agreement packet then we cannot
1782 * perform the key agreement at all. If the key agreement protocol is
1783 * performed the `completion' callback with the `context' will be called.
1784 * If remote side decides to ignore the request the `completion' will be
1785 * called after the specified timeout, `timeout_secs'.
1787 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1788 * will not be called at all since this does nothing more than sending
1789 * a packet to the remote host.
1791 * NOTE: There can be only one active key agreement for one client entry.
1792 * Before setting new one, the old one must be finished (it is finished
1793 * after calling the completion callback) or the function
1794 * silc_client_abort_key_agreement must be called.
1797 void silc_client_send_key_agreement(SilcClient client,
1798 SilcClientConnection conn,
1799 SilcClientEntry client_entry,
1800 const char *hostname,
1801 const char *bindhost,
1803 SilcUInt32 timeout_secs,
1804 SilcKeyAgreementCallback completion,
1807 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1812 * silc_client_perform_key_agreement(SilcClient client,
1813 * SilcClientConnection conn,
1814 * SilcClientEntry client_entry,
1817 * SilcKeyAgreementCallback completion,
1822 * Performs the actual key agreement protocol. Application may use this
1823 * to initiate the key agreement protocol. This can be called for example
1824 * after the application has received the `key_agreement' client operation,
1825 * and did not return TRUE from it.
1827 * The `hostname' is the remote hostname (or IP address) and the `port'
1828 * is the remote port. The `completion' callback with the `context' will
1829 * be called after the key agreement protocol.
1833 * NOTE: If the application returns TRUE in the `key_agreement' client
1834 * operation the library will automatically start the key agreement. In this
1835 * case the application must not call this function. However, application
1836 * may choose to just ignore the `key_agreement' client operation (and
1837 * merely just print information about it on the screen) and call this
1838 * function when the user whishes to do so (by, for example, giving some
1839 * specific command). Thus, the API provides both, automatic and manual
1840 * initiation of the key agreement. Calling this function is the manual
1841 * initiation and returning TRUE in the `key_agreement' client operation
1842 * is the automatic initiation.
1845 void silc_client_perform_key_agreement(SilcClient client,
1846 SilcClientConnection conn,
1847 SilcClientEntry client_entry,
1850 SilcKeyAgreementCallback completion,
1853 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1858 * silc_client_perform_key_agreement_fd(SilcClient client,
1859 * SilcClientConnection conn,
1860 * SilcClientEntry client_entry,
1863 * SilcKeyAgreementCallback completion,
1868 * Same as above but application has created already the connection to
1869 * the remote host. The `sock' is the socket to the remote connection.
1870 * Application can use this function if it does not want the client library
1871 * to create the connection.
1874 void silc_client_perform_key_agreement_fd(SilcClient client,
1875 SilcClientConnection conn,
1876 SilcClientEntry client_entry,
1879 SilcKeyAgreementCallback completion,
1882 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1886 * void silc_client_abort_key_agreement(SilcClient client,
1887 * SilcClientConnection conn,
1888 * SilcClientEntry client_entry);
1892 * This function can be called to unbind the hostname and the port for
1893 * the key agreement protocol. However, this function has effect only
1894 * before the key agreement protocol has been performed. After it has
1895 * been performed the library will automatically unbind the port. The
1896 * `client_entry' is the client to which we sent the key agreement
1897 * request. The key agreement completion callback will be called
1898 * with SILC_KEY_AGREEMENT_ABORTED status.
1901 void silc_client_abort_key_agreement(SilcClient client,
1902 SilcClientConnection conn,
1903 SilcClientEntry client_entry);
1906 /* Misc functions */
1908 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1912 * void silc_client_set_away_message(SilcClient client,
1913 * SilcClientConnection conn,
1918 * Sets away `message'. The away message may be set when the client's
1919 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1920 * to anyone who sends private message. The `message' will be sent
1921 * automatically back to the the client who send private message. If
1922 * away message is already set this replaces the old message with the
1923 * new one. If `message' is NULL the old away message is removed.
1924 * The sender may freely free the memory of the `message'.
1927 void silc_client_set_away_message(SilcClient client,
1928 SilcClientConnection conn,
1932 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1936 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1937 * SilcClientConnection conn,
1938 * SilcAuthMethod auth_meth,
1943 * Connection authentication method request callback. This is called
1944 * by the client library after it has received the authentication method
1945 * that the application requested by calling the function
1946 * silc_client_request_authentication_method.
1949 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1950 SilcClientConnection conn,
1951 SilcAuthMethod auth_meth,
1954 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1959 * silc_client_request_authentication_method(SilcClient client,
1960 * SilcClientConnection conn,
1961 * SilcConnectionAuthRequest
1967 * This function can be used to request the current authentication method
1968 * from the server. This may be called when connecting to the server
1969 * and the client library requests the authentication data from the
1970 * application. If the application does not know the current authentication
1971 * method it can request it from the server using this function.
1972 * The `callback' with `context' will be called after the server has
1973 * replied back with the current authentication method.
1977 silc_client_request_authentication_method(SilcClient client,
1978 SilcClientConnection conn,
1979 SilcConnectionAuthRequest callback,
1982 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1986 * typedef enum { ... } SilcClientMonitorStatus;
1990 * File transmission session status types. These will indicate
1991 * the status of the file transmission session.
1996 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
1997 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
1998 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
1999 SILC_CLIENT_FILE_MONITOR_GET,
2000 SILC_CLIENT_FILE_MONITOR_PUT,
2001 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2002 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2003 } SilcClientMonitorStatus;
2006 /****d* silcclient/SilcClientAPI/SilcClientFileError
2010 * typedef enum { ... } SilcClientFileError;
2014 * File transmission error types. These types are returned by
2015 * some of the file transmission functions, and by the monitor
2016 * callback to indicate error.
2021 SILC_CLIENT_FILE_OK,
2022 SILC_CLIENT_FILE_ERROR,
2023 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2024 SILC_CLIENT_FILE_ALREADY_STARTED,
2025 SILC_CLIENT_FILE_NO_SUCH_FILE,
2026 SILC_CLIENT_FILE_PERMISSION_DENIED,
2027 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2028 } SilcClientFileError;
2031 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2035 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2036 * SilcClientConnection conn,
2037 * SilcClientMonitorStatus status,
2038 * SilcClientFileError error,
2039 * SilcUInt64 offset,
2040 * SilcUInt64 filesize,
2041 * SilcClientEntry client_entry,
2042 * SilcUInt32 session_id,
2043 * const char *filepath,
2048 * Monitor callback that is called during the file transmission to
2049 * monitor the transmission process. The `status' indicates the current
2050 * monitoring process. The `error' will indicate the error type
2051 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2052 * currently transmitted amount of total `filesize'. The `client_entry'
2053 * indicates the remote client, and the transmission session ID is the
2054 * `session_id'. The filename being transmitted is indicated by the
2058 typedef void (*SilcClientFileMonitor)(SilcClient client,
2059 SilcClientConnection conn,
2060 SilcClientMonitorStatus status,
2061 SilcClientFileError error,
2063 SilcUInt64 filesize,
2064 SilcClientEntry client_entry,
2065 SilcUInt32 session_id,
2066 const char *filepath,
2069 /****f* silcclient/SilcClientAPI/silc_client_file_send
2073 * SilcClientFileError
2074 * silc_client_file_send(SilcClient client,
2075 * SilcClientConnection conn,
2076 * SilcClientFileMonitor monitor,
2077 * void *monitor_context,
2078 * const char *local_ip,
2079 * SilcUInt32 local_port,
2080 * SilcClientEntry client_entry,
2081 * const char *filepath);
2082 * SilcUInt32 *session_id);
2086 * Sends a file indicated by the `filepath' to the remote client
2087 * indicated by the `client_entry'. This will negotiate a secret key
2088 * with the remote client before actually starting the transmission of
2089 * the file. The `monitor' callback will be called to monitor the
2090 * transmission of the file.
2092 * This returns a file session ID for the file transmission to the
2093 * `session_id' pointer.. It can be used to close the session (and
2094 * abort the file transmission) by calling the silc_client_file_close
2095 * function. The session ID is also returned in the `monitor' callback.
2097 * If the `local_ip' is provided then this will try to bind the
2098 * listener for key exchange protocol to that IP. If `local_port' is
2099 * non-zero that port is used. If `local_ip' is NULL then this will
2100 * automatically attempt to bind it to local IP address of the machine.
2101 * If that fails then this does not bind to any address and port, and
2102 * assume that the remote client will provide the listener for the
2103 * key exchange protocol.
2105 * If error will occur during the file transfer process the error
2106 * status will be returned in the monitor callback. In this case
2107 * the application must call silc_client_file_close to close the
2112 silc_client_file_send(SilcClient client,
2113 SilcClientConnection conn,
2114 SilcClientFileMonitor monitor,
2115 void *monitor_context,
2116 const char *local_ip,
2117 SilcUInt32 local_port,
2118 SilcClientEntry client_entry,
2119 const char *filepath,
2120 SilcUInt32 *session_id);
2122 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2126 * SilcClientFileError
2127 * silc_client_file_receive(SilcClient client,
2128 * SilcClientConnection conn,
2129 * SilcClientFileMonitor monitor,
2130 * void *monitor_context,
2131 * SilcUInt32 session_id);
2135 * Receives a file from a client indicated by the `client_entry'. The
2136 * `session_id' indicates the file transmission session and it has been
2137 * received in the `ftp' client operation function. This will actually
2138 * perform the key agreement protocol with the remote client before
2139 * actually starting the file transmission. The `monitor' callback
2140 * will be called to monitor the transmission.
2142 * If error will occur during the file transfer process the error
2143 * status will be returned in the monitor callback. In this case
2144 * the application must call silc_client_file_close to close the
2149 silc_client_file_receive(SilcClient client,
2150 SilcClientConnection conn,
2151 SilcClientFileMonitor monitor,
2152 void *monitor_context,
2153 SilcUInt32 session_id);
2155 /****f* silcclient/SilcClientAPI/silc_client_file_close
2159 * SilcClientFileError silc_client_file_close(SilcClient client,
2160 * SilcClientConnection conn,
2161 * SilcUInt32 session_id);
2165 * Closes file transmission session indicated by the `session_id'.
2166 * If file transmission is being conducted it will be aborted
2167 * automatically. This function is also used to close the session
2168 * after successful file transmission. This function can be used
2169 * also to reject incoming file transmission request.
2172 SilcClientFileError silc_client_file_close(SilcClient client,
2173 SilcClientConnection conn,
2174 SilcUInt32 session_id);
2177 #include "command.h"
2178 #include "command_reply.h"
2180 #include "protocol.h"
2186 #endif /* SILCCLIENT_H */