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 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
96 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
97 } SilcKeyAgreementStatus;
100 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
104 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
105 * SilcClientConnection conn,
106 * SilcClientEntry client_entry,
107 * SilcKeyAgreementStatus status,
108 * SilcSKEKeyMaterial *key,
113 * Key agreement callback that is called after the key agreement protocol
114 * has been performed. This is called also if error occurred during the
115 * key agreement protocol. The `key' is the allocated key material and
116 * the caller is responsible of freeing it. The `key' is NULL if error
117 * has occurred. The application can freely use the `key' to whatever
118 * purpose it needs. See lib/silcske/silcske.h for the definition of
119 * the SilcSKEKeyMaterial structure.
122 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
123 SilcClientConnection conn,
124 SilcClientEntry client_entry,
125 SilcKeyAgreementStatus status,
126 SilcSKEKeyMaterial *key,
129 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
133 * typedef struct { ... } SilcPrivateMessageKeys;
137 * Structure to hold the list of private message keys. The array of this
138 * structure is returned by the silc_client_list_private_message_keys
144 SilcClientEntry client_entry; /* The remote client entry */
145 char *cipher; /* The cipher name */
146 unsigned char *key; /* The original key, If the appliation
147 provided it. This is NULL if the
148 library generated the key or if
149 the SKE key material was used. */
150 SilcUInt32 key_len; /* The key length */
151 } *SilcPrivateMessageKeys;
154 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
158 * typedef struct { ... } SilcChannelPrivateKey;
162 * Structure to hold one channel private key. The array of this structure
163 * is returned by silc_client_list_channel_private_keys function.
167 typedef struct SilcChannelPrivateKeyStruct {
168 char *name; /* Application given name */
169 SilcCipher cipher; /* The cipher and key */
170 SilcHmac hmac; /* The HMAC and hmac key */
171 unsigned char *key; /* The key data */
172 SilcUInt32 key_len; /* The key length */
173 } *SilcChannelPrivateKey;
176 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
180 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
181 * SilcUInt32 passphrase_len,
186 * Ask passphrase callback. This is called by the application when the
187 * library calls `ask_passphrase' client operation. The callback delivers
188 * the passphrase to the library. The passphrases in SILC protocol
189 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
190 * encoded, and if it is not then library will attempt to encode it.
193 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
194 SilcUInt32 passphrase_len,
197 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
201 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
205 * Public key (or certificate) verification callback. This is called
206 * by the application to indicate that the public key verification was
207 * either success or failure.
210 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
212 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
216 * typedef void (*SilcGetAuthMeth)(bool success,
217 * SilcProtocolAuthMeth auth_meth,
218 * const unsigned char *auth_data,
219 * SilcUInt32 auth_data_len, void *context);
223 * Authentication method resolving callback. This is called by the
224 * application to return the resolved authentication method. The client
225 * library has called the get_auth_method client operation and given
226 * this function pointer as argument. The `success' will indicate whether
227 * the authentication method could be resolved. The `auth_meth' is the
228 * resolved authentication method. The `auth_data' and the `auth_data_len'
229 * are the resolved authentication data. The `context' is the libary's
230 * context sent to the get_auth_method client operation.
233 typedef void (*SilcGetAuthMeth)(bool success,
234 SilcProtocolAuthMeth auth_meth,
235 const unsigned char *auth_data,
236 SilcUInt32 auth_data_len, void *context);
238 /****d* silcclient/SilcClientAPI/SilcClientMessageType
242 * typedef enum { ... } SilcClientMessageType;
246 * Different message types for `say' client operation. The application
247 * may filter the message sent by the library according this type.
252 SILC_CLIENT_MESSAGE_INFO, /* Informational */
253 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
254 SILC_CLIENT_MESSAGE_ERROR, /* Error */
255 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
256 } SilcClientMessageType;
259 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
263 * typedef enum { ... } SilcClientConnectionStatus
267 * This type is returned to the `connect' client operation to indicate
268 * the status of the created connection. It can indicated if it was
269 * successful or whether an error occurred.
274 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
275 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
276 resumed old detached session */
277 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
278 } SilcClientConnectionStatus;
281 /****s* silcclient/SilcClientAPI/SilcClientOperations
285 * typedef struct { ... } SilcClientOperations;
289 * SILC Client Operations. These must be implemented by the application.
290 * The Client library may call any of these routines at any time. The
291 * routines are used to deliver certain information to the application
292 * or from the application to the client library.
297 /* Message sent to the application by library. `conn' associates the
298 message to a specific connection. `conn', however, may be NULL.
299 The `type' indicates the type of the message sent by the library.
300 The applicationi can for example filter the message according the
302 void (*say)(SilcClient client, SilcClientConnection conn,
303 SilcClientMessageType type, char *msg, ...);
305 /* Message for a channel. The `sender' is the sender of the message
306 The `channel' is the channel. The `msg' is the message. Note that
308 void (*channel_message)(SilcClient client, SilcClientConnection conn,
309 SilcClientEntry sender, SilcChannelEntry channel,
310 SilcMessageFlags flags,
311 const unsigned char *message,
312 SilcUInt32 message_len);
314 /* Private message to the client. The `sender' is the sender of the
316 void (*private_message)(SilcClient client, SilcClientConnection conn,
317 SilcClientEntry sender, SilcMessageFlags flags,
318 const unsigned char *message,
319 SilcUInt32 message_len);
321 /* Notify message to the client. The notify arguments are sent in the
322 same order as servers sends them. The arguments are same as received
323 from the server except for ID's. If ID is received application receives
324 the corresponding entry to the ID. For example, if Client ID is received
325 application receives SilcClientEntry. Also, if the notify type is
326 for channel the channel entry is sent to application (even if server
327 does not send it because client library gets the channel entry from
328 the Channel ID in the packet's header). */
329 void (*notify)(SilcClient client, SilcClientConnection conn,
330 SilcNotifyType type, ...);
332 /* Command handler. This function is called always in the command function.
333 If error occurs it will be called as well. `conn' is the associated
334 client connection. `cmd_context' is the command context that was
335 originally sent to the command. `success' is FALSE if error occurred
336 during command. `command' is the command being processed. It must be
337 noted that this is not reply from server. This is merely called just
338 after application has called the command. Just to tell application
339 that the command really was processed. */
340 void (*command)(SilcClient client, SilcClientConnection conn,
341 SilcClientCommandContext cmd_context, bool success,
342 SilcCommand command, SilcStatus status);
344 /* Command reply handler. This function is called always in the command reply
345 function. If error occurs it will be called as well. Normal scenario
346 is that it will be called after the received command data has been parsed
347 and processed. The function is used to pass the received command data to
350 `conn' is the associated client connection. `cmd_payload' is the command
351 payload data received from server and it can be ignored. It is provided
352 if the application would like to re-parse the received command data,
353 however, it must be noted that the data is parsed already by the library
354 thus the payload can be ignored. `success' is FALSE if error occurred.
355 In this case arguments are not sent to the application. The `status' is
356 the command reply status server returned. The `command' is the command
357 reply being processed. The function has variable argument list and each
358 command defines the number and type of arguments it passes to the
359 application (on error they are not sent).
361 The arguments are sent in the same order as servers sends them. The
362 arguments are same as received from the server except for ID's. If
363 ID is received application receives the corresponding entry to the
364 ID. For example, if Client ID is receives application receives
366 void (*command_reply)(SilcClient client, SilcClientConnection conn,
367 SilcCommandPayload cmd_payload, bool success,
368 SilcCommand command, SilcStatus status, ...);
370 /* Called to indicate that connection was either successfully established
371 or connecting failed. This is also the first time application receives
372 the SilcClientConnection object which it should save somewhere.
373 The `status' indicated whether the connection were successful. If it
374 is error value the application must always call the function
375 silc_client_close_connection. */
376 void (*connect)(SilcClient client, SilcClientConnection conn,
377 SilcClientConnectionStatus status);
379 /* Called to indicate that connection was disconnected to the server.
380 The `status' may tell the reason of the disconnection, and if the
381 `message' is non-NULL it may include the disconnection message
382 received from server. */
383 void (*disconnect)(SilcClient client, SilcClientConnection conn,
384 SilcStatus status, const char *message);
386 /* Find authentication method and authentication data by hostname and
387 port. The hostname may be IP address as well. When the authentication
388 method has been resolved the `completion' callback with the found
389 authentication method and authentication data is called. The `conn'
391 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
392 char *hostname, SilcUInt16 port,
393 SilcGetAuthMeth completion, void *context);
395 /* Verifies received public key. The `conn_type' indicates which entity
396 (server, client etc.) has sent the public key. If user decides to trust
397 the key may be saved as trusted public key for later use. The
398 `completion' must be called after the public key has been verified. */
399 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
400 SilcSocketType conn_type, unsigned char *pk,
401 SilcUInt32 pk_len, SilcSKEPKType pk_type,
402 SilcVerifyPublicKey completion, void *context);
404 /* Ask (interact, that is) a passphrase from user. The passphrase is
405 returned to the library by calling the `completion' callback with
406 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
407 if not then the library will attempt to encode. */
408 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
409 SilcAskPassphrase completion, void *context);
411 /* Notifies application that failure packet was received. This is called
412 if there is some protocol active in the client. The `protocol' is the
413 protocol context. The `failure' is opaque pointer to the failure
414 indication. Note, that the `failure' is protocol dependant and
415 application must explicitly cast it to correct type. Usually `failure'
416 is 32 bit failure type (see protocol specs for all protocol failure
418 void (*failure)(SilcClient client, SilcClientConnection conn,
419 SilcProtocol protocol, void *failure);
421 /* Asks whether the user would like to perform the key agreement protocol.
422 This is called after we have received an key agreement packet or an
423 reply to our key agreement packet. This returns TRUE if the user wants
424 the library to perform the key agreement protocol and FALSE if it is not
425 desired (application may start it later by calling the function
426 silc_client_perform_key_agreement). If TRUE is returned also the
427 `completion' and `context' arguments must be set by the application. */
428 int (*key_agreement)(SilcClient client, SilcClientConnection conn,
429 SilcClientEntry client_entry, const char *hostname,
430 SilcUInt16 port, SilcKeyAgreementCallback *completion,
433 /* Notifies application that file transfer protocol session is being
434 requested by the remote client indicated by the `client_entry' from
435 the `hostname' and `port'. The `session_id' is the file transfer
436 session and it can be used to either accept or reject the file
437 transfer request, by calling the silc_client_file_receive or
438 silc_client_file_close, respectively. */
439 void (*ftp)(SilcClient client, SilcClientConnection conn,
440 SilcClientEntry client_entry, SilcUInt32 session_id,
441 const char *hostname, SilcUInt16 port);
443 /* Delivers SILC session detachment data indicated by `detach_data' to the
444 application. If application has issued SILC_COMMAND_DETACH command
445 the client session in the SILC network is not quit. The client remains
446 in the network but is detached. The detachment data may be used later
447 to resume the session in the SILC Network. The appliation is
448 responsible of saving the `detach_data', to for example in a file.
450 The detachment data can be given as argument to the functions
451 silc_client_connect_to_server, or silc_client_add_connection when
452 creating connection to remote server, inside SilcClientConnectionParams
453 structure. If it is provided the client library will attempt to resume
454 the session in the network. After the connection is created
455 successfully, the application is responsible of setting the user
456 interface for user into the same state it was before detaching (showing
457 same channels, channel modes, etc). It can do this by fetching the
458 information (like joined channels) from the client library. */
459 void (*detach)(SilcClient client, SilcClientConnection conn,
460 const unsigned char *detach_data,
461 SilcUInt32 detach_data_len);
462 } SilcClientOperations;
465 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
469 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
470 * char **ret_nickname);
474 * A callback function provided by the application for the library in
475 * SilcClientParams structure. This function parses the formatted
476 * nickname string `nickname' and returns the true nickname to the
477 * `ret_nickname' pointer. The library can call this function at
481 typedef void (*SilcNicknameFormatParse)(const char *nickname,
482 char **ret_nickname);
484 /****s* silcclient/SilcClientAPI/SilcClientParams
488 * typedef struct { ... } SilcClientParams;
492 * Client parameters. This can be filled with proper values and
493 * given as argument to the silc_client_alloc function. The structure
494 * hold various parameters which affects the function of the client.
499 /* Number of maximum tasks the client library's scheduler can handle.
500 If set to zero, the default value will be used (200). For WIN32
501 systems this should be set to 64 as it is the hard limit dictated
505 /* Rekey timeout in seconds. The client will perform rekey in this
506 time interval. If set to zero, the default value will be used. */
507 unsigned int rekey_secs;
509 /* Connection authentication method request timeout. If server does not
510 reply back the current authentication method when we've requested it
511 in this time interval we'll assume the reply will not come at all.
512 If set to zero, the default value (2 seconds) will be used. */
513 unsigned int connauth_request_secs;
515 /* Nickname format string. This can be used to order the client library
516 to save the nicknames in the library in a certain format. Since
517 nicknames are not unique in SILC it is possible to have multiple same
518 nicknames. Using this format string it is possible to order the library
519 to separate the multiple same nicknames from each other. The format
520 types are defined below and they can appear in any order in the format
521 string. If this is NULL then default format is used which is the
522 default nickname without anything else. The string MUST be NULL
525 Following format types are available:
527 %n nickname - the real nickname returned by the server (mandatory)
528 %h hostname - the stripped hostname of the client
529 %H full hostname - the full hostname of the client
530 %s server name - the server name the client is connected
531 %S full server - the full server name the client is connected
532 %a number - ascending number in case there are several
533 same nicknames (fe. nick@host and nick@host2)
535 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
536 "%a!%n@%s" (fe. nick@server, 2!nick@server)
537 "%n@%H" (fe. nick@host.domain.com)
539 By default this format is employed to the nicknames by the libary
540 only when there appears multiple same nicknames. If the library has
541 only one nickname cached the nickname is saved as is and without the
542 defined format. If you want always to save the nickname in the defined
543 format set the boolean field `nickname_force_format' to value TRUE.
545 char nickname_format[32];
547 /* If this is set to TRUE then the `nickname_format' is employed to all
548 saved nicknames even if there are no multiple same nicknames in the
549 cache. By default this is FALSE, which means that the `nickname_format'
550 is employed only if the library will receive a nickname that is
551 already saved in the cache. It is recommended to leave this to FALSE
553 bool nickname_force_format;
555 /* A callback function provided by the application for the library to
556 parse the nickname from the formatted nickname string. Even though
557 the libary formats the nicknames the application knows generally the
558 format better so this function should be provided for the library
559 if the application sets the `nickname_format' field. The library
560 will call this to get the true nickname from the provided formatted
561 nickname string whenever it needs the true nickname. */
562 SilcNicknameFormatParse nickname_parse;
568 /* Initialization functions (client.c) */
570 /****f* silcclient/SilcClientAPI/silc_client_alloc
574 * SilcClient silc_client_alloc(SilcClientOperations *ops,
575 * SilcClientParams *params,
577 * const char *silc_version);
581 * Allocates new client object. This has to be done before client may
582 * work. After calling this one must call silc_client_init to initialize
583 * the client. The `application' is application specific user data pointer
584 * and caller must free it. The `silc_version' is the application version
585 * that will be used to compare against remote host's (usually a server)
586 * version string. The `application' context is accessible by the
587 * application by client->application, client being SilcClient.
590 SilcClient silc_client_alloc(SilcClientOperations *ops,
591 SilcClientParams *params,
593 const char *silc_version);
595 /****f* silcclient/SilcClientAPI/silc_client_free
599 * void silc_client_free(SilcClient client);
603 * Frees client object and its internals. The execution of the client
604 * should be stopped with silc_client_stop function before calling
608 void silc_client_free(SilcClient client);
610 /****f* silcclient/SilcClientAPI/silc_client_init
614 * int silc_client_init(SilcClient client);
618 * Initializes the client. This makes all the necessary steps to make
619 * the client ready to be run. One must call silc_client_run to run the
620 * client. Returns FALSE if error occurred, TRUE otherwise.
623 int silc_client_init(SilcClient client);
625 /****f* silcclient/SilcClientAPI/silc_client_run
629 * void silc_client_run(SilcClient client);
633 * Runs the client. This starts the scheduler from the utility library.
634 * When this functions returns the execution of the appliation is over.
637 void silc_client_run(SilcClient client);
639 /****f* silcclient/SilcClientAPI/silc_client_run_one
643 * void silc_client_run_one(SilcClient client);
647 * Runs the client and returns immeadiately. This function is used when
648 * the SILC Client object indicated by the `client' is run under some
649 * other scheduler, or event loop or main loop. On GUI applications,
650 * for example this may be desired to used to run the client under the
651 * GUI application's main loop. Typically the GUI application would
652 * register an idle task that calls this function multiple times in
653 * a second to quickly process the SILC specific data.
656 void silc_client_run_one(SilcClient client);
658 /****f* silcclient/SilcClientAPI/silc_client_stop
662 * void silc_client_stop(SilcClient client);
666 * Stops the client. This is called to stop the client and thus to stop
667 * the program. The client context must be freed with the silc_client_free
671 void silc_client_stop(SilcClient client);
674 /* Connecting functions (client.c) */
676 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
680 * typedef struct { ... } SilcClientConnectionParams;
684 * Client connection parameters. This can be filled by the application
685 * and given as argument to silc_client_connect_to_server or to
686 * silc_client_add_connection.
691 /* The SILC session detachment data that was returned by `detach' client
692 operation when the application detached from the network. Application
693 is responsible of saving the data and giving it as argument here
694 for resuming the session in the SILC network.
696 If this is provided here the client library will attempt to resume
697 the session in the network. After the connection is created
698 successfully, the application is responsible of setting the user
699 interface for user into the same state it was before detaching (showing
700 same channels, channel modes, etc). It can do this by fetching the
701 information (like joined channels) from the client library. */
702 unsigned char *detach_data;
703 SilcUInt32 detach_data_len;
705 } SilcClientConnectionParams;
708 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
712 * int silc_client_connect_to_server(SilcClient client,
713 * SilcClientConnectionParams *params,
714 * int port, char *host, void *context);
718 * Connects to remote server. This is the main routine used to connect
719 * to SILC server. Returns -1 on error and the created socket otherwise.
720 * The `context' is user context that is saved into the SilcClientConnection
721 * that is created after the connection is created. Note that application
722 * may handle the connecting process outside the library. If this is the
723 * case then this function is not used at all. When the connecting is
724 * done the `connect' client operation is called, and the `context' is
725 * accessible with conn->context, conn being SilcClientConnection.
726 * If the `params' is provided they are used by the routine.
729 int silc_client_connect_to_server(SilcClient client,
730 SilcClientConnectionParams *params,
731 int port, char *host, void *context);
733 /****f* silcclient/SilcClientAPI/silc_client_add_connection
738 * SilcClientConnection
739 * silc_client_add_connection(SilcClient client,
740 * SilcClientConnectionParams *params,
741 * char *hostname, int port, void *context);
745 * Allocates and adds new connection to the client. This adds the allocated
746 * connection to the connection table and returns a pointer to it. A client
747 * can have multiple connections to multiple servers. Every connection must
748 * be added to the client using this function. User data `context' may
749 * be sent as argument. If the `params' is provided they are used by
754 * This function is normally used only if the application performed
755 * the connecting outside the library, and did not called the
756 * silc_client_connect_to_server function at all. The library
757 * however may use this internally.
761 silc_client_add_connection(SilcClient client,
762 SilcClientConnectionParams *params,
763 char *hostname, int port, void *context);
765 /****f* silcclient/SilcClientAPI/silc_client_del_connection
769 * void silc_client_del_connection(SilcClient client,
770 * SilcClientConnection conn);
774 * Removes connection from client. Frees all memory. The library
775 * call this function automatically for all connection contexts.
776 * The application however may free the connection contexts it has
780 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
782 /****f* silcclient/SilcClientAPI/silc_client_add_socket
786 * void silc_client_add_socket(SilcClient client,
787 * SilcSocketConnection sock);
791 * Adds listener socket to the listener sockets table. This function is
792 * used to add socket objects that are listeners to the client. This should
793 * not be used to add other connection objects.
796 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
798 /****f* silcclient/SilcClientAPI/silc_client_del_socket
802 * void silc_client_del_socket(SilcClient client,
803 * SilcSocketConnection sock);
807 * Deletes listener socket from the listener sockets table. If the
808 * application has added a socket with silc_client_add_socket it must
809 * also free it using this function.
812 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
814 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
818 * void silc_client_start_key_exchange(SilcClient client,
819 * SilcClientConnection conn,
824 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
825 * key material between client and server. This function can be called
826 * directly if application is performing its own connecting and does not
827 * use the connecting provided by this library. This function is normally
828 * used only if the application performed the connecting outside the
829 * library. The library however may use this internally. After the
830 * key exchange is performed the `connect' client operation is called.
833 void silc_client_start_key_exchange(SilcClient client,
834 SilcClientConnection conn,
837 /****f* silcclient/SilcClientAPI/silc_client_close_connection
841 * void silc_client_close_connection(SilcClient client,
842 * SilcClientConnection conn);
846 * Closes connection to remote end. Free's all allocated data except
847 * for some information such as nickname etc. that are valid at all time.
850 void silc_client_close_connection(SilcClient client,
851 SilcClientConnection conn);
854 /* Message sending functions (client_channel.c and client_prvmsg.c) */
856 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
860 * void silc_client_send_channel_message(SilcClient client,
861 * SilcClientConnection conn,
862 * SilcChannelEntry channel,
863 * SilcChannelPrivateKey key,
864 * SilcMessageFlags flags,
865 * unsigned char *data,
866 * SilcUInt32 data_len,
871 * Sends packet to the `channel'. Packet to channel is always encrypted
872 * differently from "normal" packets. SILC header of the packet is
873 * encrypted with the next receiver's key and the rest of the packet is
874 * encrypted with the channel specific key. Padding and HMAC is computed
875 * with the next receiver's key. The `data' is the channel message. If
876 * the `force_send' is TRUE then the packet is sent immediately.
878 * If `key' is provided then that private key is used to encrypt the
879 * channel message. If it is not provided, private keys has not been
880 * set at all, the normal channel key is used automatically. If private
881 * keys are set then the first key (the key that was added first as
882 * private key) is used.
885 void silc_client_send_channel_message(SilcClient client,
886 SilcClientConnection conn,
887 SilcChannelEntry channel,
888 SilcChannelPrivateKey key,
889 SilcMessageFlags flags,
894 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
898 * void silc_client_send_private_message(SilcClient client,
899 * SilcClientConnection conn,
900 * SilcClientEntry client_entry,
901 * SilcMessageFlags flags,
902 * unsigned char *data,
903 * SilcUInt32 data_len,
908 * Sends private message to remote client. If private message key has
909 * not been set with this client then the message will be encrypted using
910 * normal session keys. Private messages are special packets in SILC
911 * network hence we need this own function for them. This is similar
912 * to silc_client_packet_send_to_channel except that we send private
913 * message. The `data' is the private message. If the `force_send' is
914 * TRUE the packet is sent immediately.
917 void silc_client_send_private_message(SilcClient client,
918 SilcClientConnection conn,
919 SilcClientEntry client_entry,
920 SilcMessageFlags flags,
926 /* Client and Channel entry retrieval (idlist.c) */
928 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
932 * typedef void (*SilcGetClientCallback)(SilcClient client,
933 * SilcClientConnection conn,
934 * SilcClientEntry *clients,
935 * SilcUInt32 clients_count,
940 * Callback function given to the silc_client_get_client function. The
941 * found entries are allocated into the `clients' array. The array must
942 * not be freed by the receiver, the library will free it later. If the
943 * `clients' is NULL, no such clients exist in the SILC Network.
946 typedef void (*SilcGetClientCallback)(SilcClient client,
947 SilcClientConnection conn,
948 SilcClientEntry *clients,
949 SilcUInt32 clients_count,
952 /****f* silcclient/SilcClientAPI/silc_client_get_clients
956 * void silc_client_get_clients(SilcClient client,
957 * SilcClientConnection conn,
958 * const char *nickname,
959 * const char *server,
960 * SilcGetClientCallback completion,
965 * Finds client entry or entries by the `nickname' and `server'. The
966 * completion callback will be called when the client entries has been
967 * found. After the server returns the client information it is cached
968 * and can be accesses locally at a later time.
972 * NOTE: This function is always asynchronous and resolves the client
973 * information from the server. Thus, if you already know the client
974 * information then use the silc_client_get_client_by_id function to
975 * get the client entry since this function may be very slow and should
976 * be used only to initially get the client entries.
979 void silc_client_get_clients(SilcClient client,
980 SilcClientConnection conn,
981 const char *nickname,
983 SilcGetClientCallback completion,
986 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
990 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
991 * SilcClientConnection conn,
992 * const char *nickname,
993 * const char *format,
994 * SilcUInt32 *clients_count);
998 * Same as silc_client_get_clients function but does not resolve anything
999 * from the server. This checks local cache and returns all matching
1000 * clients from the local cache. If none was found this returns NULL.
1001 * The `nickname' is the real nickname of the client, and the `format'
1002 * is the formatted nickname to find exact match from multiple found
1003 * entries. The format must be same as given in the SilcClientParams
1004 * structure to the client library. If the `format' is NULL all found
1005 * clients by `nickname' are returned. The caller must return the
1009 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1010 SilcClientConnection conn,
1011 const char *nickname,
1013 SilcUInt32 *clients_count);
1015 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1019 * void silc_client_get_clients_by_list(SilcClient client,
1020 * SilcClientConnection conn,
1021 * SilcUInt32 list_count,
1022 * SilcBuffer client_id_list,
1023 * SilcGetClientCallback completion,
1028 * Gets client entries by the list of client ID's `client_id_list'. This
1029 * always resolves those client ID's it does not know yet from the server
1030 * so this function might take a while. The `client_id_list' is a list
1031 * of ID Payloads added one after other. JOIN command reply and USERS
1032 * command reply for example returns this sort of list. The `completion'
1033 * will be called after the entries are available. When server returns
1034 * the client information it will be cached and can be accessed locally
1038 void silc_client_get_clients_by_list(SilcClient client,
1039 SilcClientConnection conn,
1040 SilcUInt32 list_count,
1041 SilcBuffer client_id_list,
1042 SilcGetClientCallback completion,
1045 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1049 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1050 * SilcClientConnection conn,
1051 * SilcClientID *client_id);
1055 * Find entry for client by the client's ID. Returns the entry or NULL
1056 * if the entry was not found. This checks the local cache and does
1057 * not resolve anything from server.
1060 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1061 SilcClientConnection conn,
1062 SilcClientID *client_id);
1064 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1069 * silc_client_get_client_by_id_resolve(SilcClient client,
1070 * SilcClientConnection conn,
1071 * SilcClientID *client_id,
1072 * SilcGetClientCallback completion,
1077 * Same as silc_client_get_client_by_id but will always resolve the
1078 * information from the server. Use this only if you know that you
1079 * do not have the entry and the only thing you know about the client
1080 * is its ID. When server returns the client information it will be
1081 * cache and can be accessed locally at a later time.
1084 void silc_client_get_client_by_id_resolve(SilcClient client,
1085 SilcClientConnection conn,
1086 SilcClientID *client_id,
1087 SilcGetClientCallback completion,
1090 /****f* silcclient/SilcClientAPI/silc_client_del_client
1094 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1095 * SilcClientEntry client_entry)
1099 * Removes client from local cache by the client entry indicated by
1100 * the `client_entry'. Returns TRUE if the deletion were successful.
1103 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1104 SilcClientEntry client_entry);
1106 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1110 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1111 * SilcClientConnection conn,
1112 * SilcChannelEntry *channels,
1113 * SilcUInt32 channels_count,
1118 * Callback function given to the silc_client_get_channel_* functions.
1119 * The found entries are allocated into the `channels' array. The array
1120 * must not be freed by the receiver, the library will free it later.
1121 * If the `channel' is NULL, no such channel exist in the SILC Network.
1124 typedef void (*SilcGetChannelCallback)(SilcClient client,
1125 SilcClientConnection conn,
1126 SilcChannelEntry *channels,
1127 SilcUInt32 channels_count,
1130 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1134 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1135 * SilcClientConnection conn,
1140 * Finds entry for channel by the channel name. Returns the entry or NULL
1141 * if the entry was not found. It is found only if the client is joined
1145 SilcChannelEntry silc_client_get_channel(SilcClient client,
1146 SilcClientConnection conn,
1149 /****f* silcclient/SilcClientAPI/silc_client_get_channel_id_resolve
1154 * silc_client_get_channel_by_id_resolve(SilcClient client,
1155 * SilcClientConnection conn,
1156 * SilcChannelID *channel_id,
1157 * SilcGetClientCallback completion,
1162 * Finds channel entry by the channel name. Returns the entry or NULL
1163 * if it was not found.
1166 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1167 SilcClientConnection conn,
1168 SilcChannelID *channel_id);
1170 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1175 * silc_client_get_channel_by_id_resolve(SilcClient client,
1176 * SilcClientConnection conn,
1177 * SilcChannelID *channel_id,
1178 * SilcGetClientCallback completion,
1183 * Resolves the channel information (its name mainly) from the server
1184 * by the `channel_id'. Use this only if you know that you do not have
1185 * the entry cached locally.
1188 void silc_client_get_channel_by_id_resolve(SilcClient client,
1189 SilcClientConnection conn,
1190 SilcChannelID *channel_id,
1191 SilcGetChannelCallback completion,
1194 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1198 * bool silc_client_del_channel(SilcClient client,
1199 * SilcClientConnection conn,
1200 * SilcChannelEntry channel)
1204 * Removes channel from local cache by the channel entry indicated by
1205 * the `channel'. Returns TRUE if the deletion were successful.
1208 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1209 SilcChannelEntry channel);
1211 /****f* silcclient/SilcClientAPI/silc_client_get_server
1215 * SilcServerEntry silc_client_get_server(SilcClient client,
1216 * SilcClientConnection conn,
1217 * char *server_name)
1221 * Finds entry for server by the server name. Returns the entry or NULL
1222 * if the entry was not found.
1225 SilcServerEntry silc_client_get_server(SilcClient client,
1226 SilcClientConnection conn,
1229 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1233 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1234 * SilcClientConnection conn,
1235 * SilcServerID *server_id);
1239 * Finds entry for server by the server ID. Returns the entry or NULL
1240 * if the entry was not found.
1243 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1244 SilcClientConnection conn,
1245 SilcServerID *server_id);
1247 /****f* silcclient/SilcClientAPI/silc_client_del_server
1251 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1252 * SilcServerEntry server);
1256 * Removes server from local cache by the server entry indicated by
1257 * the `server'. Returns TRUE if the deletion were successful.
1260 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1261 SilcServerEntry server);
1263 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1267 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1268 * SilcClientEntry client_entry);
1272 * Returns the ChannelUser entry if the `client_entry' is joined on the
1273 * channel indicated by the `channel'. NULL if client is not joined on
1277 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1278 SilcClientEntry client_entry);
1280 /* Command management (command.c) */
1282 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1286 * SilcClientCommandContext silc_client_command_alloc(void);
1290 * Allocate Command Context. The context is defined in `command.h' file.
1291 * The context is used by the library commands and applications should use
1292 * it as well. However, application may choose to use some own context
1293 * for its local commands. All library commands, however, must use this
1297 SilcClientCommandContext silc_client_command_alloc(void);
1299 /****f* silcclient/SilcClientAPI/silc_client_command_free
1303 * void silc_client_command_free(SilcClientCommandContext ctx);
1307 * Free command context and its internals. If the contex was duplicated
1308 * with silc_client_command_dup this may not actually free the data,
1309 * instead it will decrease the reference counter of the context. The
1310 * context will be freed when the reference counter hits zero.
1313 void silc_client_command_free(SilcClientCommandContext ctx);
1315 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1319 * SilcClientCommandContext
1320 * silc_client_command_dup(SilcClientCommandContext ctx);
1324 * Duplicate Command Context by adding reference counter. The context won't
1325 * be free'd untill it hits zero.
1328 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1330 /****f* silcclient/SilcClientAPI/silc_client_command_find
1334 * SilcClientCommand silc_client_command_find(SilcClient client,
1335 * const char *name);
1339 * Finds and returns a pointer to the command list. Return NULL if the
1340 * command is not found. See the `command.[ch]' for the command list.
1341 * Command names are not case-sensitive.
1344 SilcClientCommand silc_client_command_find(SilcClient client,
1347 /****f* silcclient/SilcClientAPI/silc_client_command_call
1351 * void silc_client_command_call(SilcClientCommand command);
1355 * Calls the command (executes it). Application can call this after
1356 * it has allocated the SilcClientCommandContext with the function
1357 * silc_client_command_alloc and found the command from the client
1358 * library by calling silc_client_command_find. This will execute
1361 * Application can call the command function directly too if it
1362 * wishes to do so. See the command.h for details of the
1363 * SilcClientCommand structure.
1366 void silc_client_command_call(SilcClientCommand command,
1367 SilcClientCommandContext cmd);
1369 /****f* silcclient/SilcClientAPI/silc_client_command_send
1373 * void silc_client_command_send(SilcClient client,
1374 * SilcClientConnection conn,
1375 * SilcCommand command, SilcUInt16 ident,
1376 * SilcUInt32 argc, ...);
1380 * Generic function to send any command. The arguments must be sent already
1381 * encoded into correct form and in correct order. If application wants
1382 * to perform the commands by itself, it can do so and send the data
1383 * directly to the server using this function. If application is using
1384 * the silc_client_command_call, this function is usually not used.
1387 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1388 SilcCommand command, SilcUInt16 ident,
1389 SilcUInt32 argc, ...);
1391 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1395 * void silc_client_command_pending(SilcClientConnection conn,
1396 * SilcCommand reply_cmd,
1398 * SilcCommandCb callback,
1403 * Add new pending command to be executed when reply to a command has been
1404 * received. The `reply_cmd' is the command that will call the `callback'
1405 * with `context' when reply has been received. If `ident' is non-zero
1406 * the `callback' will be executed when received reply with command
1407 * identifier `ident'.
1409 * Note that the application is notified about the received command
1410 * reply through the `command_reply' client operation before calling
1411 * the `callback` pending command callback.
1414 void silc_client_command_pending(SilcClientConnection conn,
1415 SilcCommand reply_cmd,
1417 SilcCommandCb callback,
1421 /* Private Message key management (client_prvmsg.c) */
1423 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1427 * int silc_client_add_private_message_key(SilcClient client,
1428 * SilcClientConnection conn,
1429 * SilcClientEntry client_entry,
1431 * unsigned char *key,
1432 * SilcUInt32 key_len,
1433 * bool generate_key,
1438 * Adds private message key to the client library. The key will be used to
1439 * encrypt all private message between the client and the remote client
1440 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1441 * value `generate_key' is TRUE the library will generate random key.
1442 * The `key' maybe for example pre-shared-key, passphrase or similar.
1443 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1444 * requirements of the SILC protocol are met. The API, however, allows
1445 * to allocate any cipher.
1447 * If `responder' is TRUE then the sending and receiving keys will be
1448 * set according the client being the receiver of the private key. If
1449 * FALSE the client is being the sender (or negotiator) of the private
1452 * It is not necessary to set key for normal private message usage. If the
1453 * key is not set then the private messages are encrypted using normal
1454 * session keys. Setting the private key, however, increases the security.
1456 * Returns FALSE if the key is already set for the `client_entry', TRUE
1460 int silc_client_add_private_message_key(SilcClient client,
1461 SilcClientConnection conn,
1462 SilcClientEntry client_entry,
1469 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1473 * int silc_client_add_private_message_key_ske(SilcClient client,
1474 * SilcClientConnection conn,
1475 * SilcClientEntry client_entry,
1477 * SilcSKEKeyMaterial *key);
1481 * Same as silc_client_add_private_message_key but takes the key material
1482 * from the SKE key material structure. This structure is received if
1483 * the application uses the silc_client_send_key_agreement to negotiate
1484 * the key material. The `cipher' SHOULD be provided as it is negotiated
1485 * also in the SKE protocol.
1488 int silc_client_add_private_message_key_ske(SilcClient client,
1489 SilcClientConnection conn,
1490 SilcClientEntry client_entry,
1492 SilcSKEKeyMaterial *key,
1495 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key
1499 * int silc_client_send_private_message_key(SilcClient client,
1500 * SilcClientConnection conn,
1501 * SilcClientEntry client_entry,
1506 * Sends private message key payload to the remote client indicated by
1507 * the `client_entry'. If the `force_send' is TRUE the packet is sent
1508 * immediately. Returns FALSE if error occurs, TRUE otherwise. The
1509 * application should call this function after setting the key to the
1512 * Note that the key sent using this function is sent to the remote client
1513 * through the SILC network. The packet is protected using normal session
1517 int silc_client_send_private_message_key(SilcClient client,
1518 SilcClientConnection conn,
1519 SilcClientEntry client_entry,
1522 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1526 * int silc_client_del_private_message_key(SilcClient client,
1527 * SilcClientConnection conn,
1528 * SilcClientEntry client_entry);
1532 * Removes the private message from the library. The key won't be used
1533 * after this to protect the private messages with the remote `client_entry'
1534 * client. Returns FALSE on error, TRUE otherwise.
1537 int silc_client_del_private_message_key(SilcClient client,
1538 SilcClientConnection conn,
1539 SilcClientEntry client_entry);
1541 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1545 * SilcPrivateMessageKeys
1546 * silc_client_list_private_message_keys(SilcClient client,
1547 * SilcClientConnection conn,
1548 * SilcUInt32 *key_count);
1552 * Returns array of set private message keys associated to the connection
1553 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1554 * count to the `key_count' argument. The array must be freed by the caller
1555 * by calling the silc_client_free_private_message_keys function. Note:
1556 * the keys returned in the array is in raw format. It might not be desired
1557 * to show the keys as is. The application might choose not to show the keys
1558 * at all or to show the fingerprints of the keys.
1561 SilcPrivateMessageKeys
1562 silc_client_list_private_message_keys(SilcClient client,
1563 SilcClientConnection conn,
1564 SilcUInt32 *key_count);
1566 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1570 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1571 * SilcUInt32 key_count);
1575 * Frees the SilcPrivateMessageKeys array returned by the function
1576 * silc_client_list_private_message_keys.
1579 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1580 SilcUInt32 key_count);
1583 /* Channel private key management (client_channel.c,
1584 SilcChannelPrivateKey is defined in idlist.h) */
1586 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1590 * int silc_client_add_channel_private_key(SilcClient client,
1591 * SilcClientConnection conn,
1592 * SilcChannelEntry channel,
1596 * unsigned char *key,
1597 * SilcUInt32 key_len);
1601 * Adds private key for channel. This may be set only if the channel's mode
1602 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1603 * mode is not set. When channel has private key then the messages are
1604 * encrypted using that key. All clients on the channel must also know the
1605 * key in order to decrypt the messages. However, it is possible to have
1606 * several private keys per one channel. In this case only some of the
1607 * clients on the channel may know the one key and only some the other key.
1608 * The `name' can be application given name for the key.
1610 * The private key for channel is optional. If it is not set then the
1611 * channel messages are encrypted using the channel key generated by the
1612 * server. However, setting the private key (or keys) for the channel
1613 * significantly adds security. If more than one key is set the library
1614 * will automatically try all keys at the message decryption phase. Note:
1615 * setting many keys slows down the decryption phase as all keys has to
1616 * be tried in order to find the correct decryption key. However, setting
1617 * a few keys does not have big impact to the decryption performace.
1621 * NOTE: This is entirely local setting. The key set using this function
1622 * is not sent to the network at any phase.
1624 * NOTE: If the key material was originated by the SKE protocol (using
1625 * silc_client_send_key_agreement) then the `key' MUST be the
1626 * key->send_enc_key as this is dictated by the SILC protocol. However,
1627 * currently it is not expected that the SKE key material would be used
1628 * as channel private key. However, this API allows it.
1631 int silc_client_add_channel_private_key(SilcClient client,
1632 SilcClientConnection conn,
1633 SilcChannelEntry channel,
1638 SilcUInt32 key_len);
1640 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1644 * int silc_client_del_channel_private_keys(SilcClient client,
1645 * SilcClientConnection conn,
1646 * SilcChannelEntry channel);
1650 * Removes all private keys from the `channel'. The old channel key is used
1651 * after calling this to protect the channel messages. Returns FALSE on
1652 * on error, TRUE otherwise.
1655 int silc_client_del_channel_private_keys(SilcClient client,
1656 SilcClientConnection conn,
1657 SilcChannelEntry channel);
1659 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1663 * int silc_client_del_channel_private_key(SilcClient client,
1664 * SilcClientConnection conn,
1665 * SilcChannelEntry channel,
1666 * SilcChannelPrivateKey key);
1670 * Removes and frees private key `key' from the channel `channel'.
1671 * The `key' is retrieved by calling the function
1672 * silc_client_list_channel_private_keys. The key is not used after
1673 * this. If the key was last private key then the old channel key is
1674 * used hereafter to protect the channel messages. This returns FALSE
1675 * on error, TRUE otherwise.
1678 int silc_client_del_channel_private_key(SilcClient client,
1679 SilcClientConnection conn,
1680 SilcChannelEntry channel,
1681 SilcChannelPrivateKey key);
1683 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1687 * SilcChannelPrivateKey *
1688 * silc_client_list_channel_private_keys(SilcClient client,
1689 * SilcClientConnection conn,
1690 * SilcChannelEntry channel,
1691 * SilcUInt32 *key_count);
1695 * Returns array (pointers) of private keys associated to the `channel'.
1696 * The caller must free the array by calling the function
1697 * silc_client_free_channel_private_keys. The pointers in the array may be
1698 * used to delete the specific key by giving the pointer as argument to the
1699 * function silc_client_del_channel_private_key.
1702 SilcChannelPrivateKey *
1703 silc_client_list_channel_private_keys(SilcClient client,
1704 SilcClientConnection conn,
1705 SilcChannelEntry channel,
1706 SilcUInt32 *key_count);
1708 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1712 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1713 * SilcUInt32 key_count);
1717 * Frees the SilcChannelPrivateKey array.
1720 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1721 SilcUInt32 key_count);
1723 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1727 * void silc_client_current_channel_private_key(SilcClient client,
1728 * SilcClientConnection conn,
1729 * SilcChannelEntry channel,
1730 * SilcChannelPrivateKey key);
1734 * Sets the `key' to be used as current channel private key on the
1735 * `channel'. Packet sent after calling this function will be secured
1739 void silc_client_current_channel_private_key(SilcClient client,
1740 SilcClientConnection conn,
1741 SilcChannelEntry channel,
1742 SilcChannelPrivateKey key);
1745 /* Key Agreement routines (client_keyagr.c) */
1747 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1751 * void silc_client_send_key_agreement(SilcClient client,
1752 * SilcClientConnection conn,
1753 * SilcClientEntry client_entry,
1756 * SilcUInt32 timeout_secs,
1757 * SilcKeyAgreementCallback completion,
1762 * Sends key agreement request to the remote client indicated by the
1763 * `client_entry'. If the caller provides the `hostname' and the `port'
1764 * arguments then the library will bind the client to that hostname and
1765 * that port for the key agreement protocol. It also sends the `hostname'
1766 * and the `port' in the key agreement packet to the remote client. This
1767 * would indicate that the remote client may initiate the key agreement
1768 * protocol to the `hostname' on the `port'. If port is zero then the
1769 * bound port is undefined (the operating system defines it).
1771 * If the `hostname' and `port' is not provided then empty key agreement
1772 * packet is sent to the remote client. The remote client may reply with
1773 * the same packet including its hostname and port. If the library receives
1774 * the reply from the remote client the `key_agreement' client operation
1775 * callback will be called to verify whether the user wants to perform the
1776 * key agreement or not.
1780 * NOTE: If the application provided the `hostname' and the `port' and the
1781 * remote side initiates the key agreement protocol it is not verified
1782 * from the user anymore whether the protocol should be executed or not.
1783 * By setting the `hostname' and `port' the user gives permission to
1784 * perform the protocol (we are responder in this case).
1786 * NOTE: If the remote side decides not to initiate the key agreement
1787 * or decides not to reply with the key agreement packet then we cannot
1788 * perform the key agreement at all. If the key agreement protocol is
1789 * performed the `completion' callback with the `context' will be called.
1790 * If remote side decides to ignore the request the `completion' will be
1791 * called after the specified timeout, `timeout_secs'.
1793 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1794 * will not be called at all since this does nothing more than sending
1795 * a packet to the remote host.
1797 * NOTE: There can be only one active key agreement for one client entry.
1798 * Before setting new one, the old one must be finished (it is finished
1799 * after calling the completion callback) or the function
1800 * silc_client_abort_key_agreement must be called.
1803 void silc_client_send_key_agreement(SilcClient client,
1804 SilcClientConnection conn,
1805 SilcClientEntry client_entry,
1806 const char *hostname,
1807 const char *bindhost,
1809 SilcUInt32 timeout_secs,
1810 SilcKeyAgreementCallback completion,
1813 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1818 * silc_client_perform_key_agreement(SilcClient client,
1819 * SilcClientConnection conn,
1820 * SilcClientEntry client_entry,
1823 * SilcKeyAgreementCallback completion,
1828 * Performs the actual key agreement protocol. Application may use this
1829 * to initiate the key agreement protocol. This can be called for example
1830 * after the application has received the `key_agreement' client operation,
1831 * and did not return TRUE from it.
1833 * The `hostname' is the remote hostname (or IP address) and the `port'
1834 * is the remote port. The `completion' callback with the `context' will
1835 * be called after the key agreement protocol.
1839 * NOTE: If the application returns TRUE in the `key_agreement' client
1840 * operation the library will automatically start the key agreement. In this
1841 * case the application must not call this function. However, application
1842 * may choose to just ignore the `key_agreement' client operation (and
1843 * merely just print information about it on the screen) and call this
1844 * function when the user whishes to do so (by, for example, giving some
1845 * specific command). Thus, the API provides both, automatic and manual
1846 * initiation of the key agreement. Calling this function is the manual
1847 * initiation and returning TRUE in the `key_agreement' client operation
1848 * is the automatic initiation.
1851 void silc_client_perform_key_agreement(SilcClient client,
1852 SilcClientConnection conn,
1853 SilcClientEntry client_entry,
1856 SilcKeyAgreementCallback completion,
1859 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1864 * silc_client_perform_key_agreement_fd(SilcClient client,
1865 * SilcClientConnection conn,
1866 * SilcClientEntry client_entry,
1869 * SilcKeyAgreementCallback completion,
1874 * Same as above but application has created already the connection to
1875 * the remote host. The `sock' is the socket to the remote connection.
1876 * Application can use this function if it does not want the client library
1877 * to create the connection.
1880 void silc_client_perform_key_agreement_fd(SilcClient client,
1881 SilcClientConnection conn,
1882 SilcClientEntry client_entry,
1885 SilcKeyAgreementCallback completion,
1888 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1892 * void silc_client_abort_key_agreement(SilcClient client,
1893 * SilcClientConnection conn,
1894 * SilcClientEntry client_entry);
1898 * This function can be called to unbind the hostname and the port for
1899 * the key agreement protocol. However, this function has effect only
1900 * before the key agreement protocol has been performed. After it has
1901 * been performed the library will automatically unbind the port. The
1902 * `client_entry' is the client to which we sent the key agreement
1903 * request. The key agreement completion callback will be called
1904 * with SILC_KEY_AGREEMENT_ABORTED status.
1907 void silc_client_abort_key_agreement(SilcClient client,
1908 SilcClientConnection conn,
1909 SilcClientEntry client_entry);
1912 /* Misc functions */
1914 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1918 * void silc_client_set_away_message(SilcClient client,
1919 * SilcClientConnection conn,
1924 * Sets away `message'. The away message may be set when the client's
1925 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1926 * to anyone who sends private message. The `message' will be sent
1927 * automatically back to the the client who send private message. If
1928 * away message is already set this replaces the old message with the
1929 * new one. If `message' is NULL the old away message is removed.
1930 * The sender may freely free the memory of the `message'.
1933 void silc_client_set_away_message(SilcClient client,
1934 SilcClientConnection conn,
1938 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1942 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1943 * SilcClientConnection conn,
1944 * SilcAuthMethod auth_meth,
1949 * Connection authentication method request callback. This is called
1950 * by the client library after it has received the authentication method
1951 * that the application requested by calling the function
1952 * silc_client_request_authentication_method.
1955 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1956 SilcClientConnection conn,
1957 SilcAuthMethod auth_meth,
1960 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1965 * silc_client_request_authentication_method(SilcClient client,
1966 * SilcClientConnection conn,
1967 * SilcConnectionAuthRequest
1973 * This function can be used to request the current authentication method
1974 * from the server. This may be called when connecting to the server
1975 * and the client library requests the authentication data from the
1976 * application. If the application does not know the current authentication
1977 * method it can request it from the server using this function.
1978 * The `callback' with `context' will be called after the server has
1979 * replied back with the current authentication method.
1983 silc_client_request_authentication_method(SilcClient client,
1984 SilcClientConnection conn,
1985 SilcConnectionAuthRequest callback,
1988 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1992 * typedef enum { ... } SilcClientMonitorStatus;
1996 * File transmission session status types. These will indicate
1997 * the status of the file transmission session.
2002 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2003 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2004 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2005 SILC_CLIENT_FILE_MONITOR_GET,
2006 SILC_CLIENT_FILE_MONITOR_PUT,
2007 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2008 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2009 } SilcClientMonitorStatus;
2012 /****d* silcclient/SilcClientAPI/SilcClientFileError
2016 * typedef enum { ... } SilcClientFileError;
2020 * File transmission error types. These types are returned by
2021 * some of the file transmission functions, and by the monitor
2022 * callback to indicate error.
2027 SILC_CLIENT_FILE_OK,
2028 SILC_CLIENT_FILE_ERROR,
2029 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2030 SILC_CLIENT_FILE_ALREADY_STARTED,
2031 SILC_CLIENT_FILE_NO_SUCH_FILE,
2032 SILC_CLIENT_FILE_PERMISSION_DENIED,
2033 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2034 } SilcClientFileError;
2037 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2041 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2042 * SilcClientConnection conn,
2043 * SilcClientMonitorStatus status,
2044 * SilcClientFileError error,
2045 * SilcUInt64 offset,
2046 * SilcUInt64 filesize,
2047 * SilcClientEntry client_entry,
2048 * SilcUInt32 session_id,
2049 * const char *filepath,
2054 * Monitor callback that is called during the file transmission to
2055 * monitor the transmission process. The `status' indicates the current
2056 * monitoring process. The `error' will indicate the error type
2057 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2058 * currently transmitted amount of total `filesize'. The `client_entry'
2059 * indicates the remote client, and the transmission session ID is the
2060 * `session_id'. The filename being transmitted is indicated by the
2064 typedef void (*SilcClientFileMonitor)(SilcClient client,
2065 SilcClientConnection conn,
2066 SilcClientMonitorStatus status,
2067 SilcClientFileError error,
2069 SilcUInt64 filesize,
2070 SilcClientEntry client_entry,
2071 SilcUInt32 session_id,
2072 const char *filepath,
2075 /****f* silcclient/SilcClientAPI/silc_client_file_send
2079 * SilcClientFileError
2080 * silc_client_file_send(SilcClient client,
2081 * SilcClientConnection conn,
2082 * SilcClientFileMonitor monitor,
2083 * void *monitor_context,
2084 * const char *local_ip,
2085 * SilcUInt32 local_port,
2086 * SilcClientEntry client_entry,
2087 * const char *filepath);
2088 * SilcUInt32 *session_id);
2092 * Sends a file indicated by the `filepath' to the remote client
2093 * indicated by the `client_entry'. This will negotiate a secret key
2094 * with the remote client before actually starting the transmission of
2095 * the file. The `monitor' callback will be called to monitor the
2096 * transmission of the file.
2098 * This returns a file session ID for the file transmission to the
2099 * `session_id' pointer.. It can be used to close the session (and
2100 * abort the file transmission) by calling the silc_client_file_close
2101 * function. The session ID is also returned in the `monitor' callback.
2103 * If the `local_ip' is provided then this will try to bind the
2104 * listener for key exchange protocol to that IP. If `local_port' is
2105 * non-zero that port is used. If `local_ip' is NULL then this will
2106 * automatically attempt to bind it to local IP address of the machine.
2107 * If that fails then this does not bind to any address and port, and
2108 * assume that the remote client will provide the listener for the
2109 * key exchange protocol.
2111 * If error will occur during the file transfer process the error
2112 * status will be returned in the monitor callback. In this case
2113 * the application must call silc_client_file_close to close the
2118 silc_client_file_send(SilcClient client,
2119 SilcClientConnection conn,
2120 SilcClientFileMonitor monitor,
2121 void *monitor_context,
2122 const char *local_ip,
2123 SilcUInt32 local_port,
2124 SilcClientEntry client_entry,
2125 const char *filepath,
2126 SilcUInt32 *session_id);
2128 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2132 * SilcClientFileError
2133 * silc_client_file_receive(SilcClient client,
2134 * SilcClientConnection conn,
2135 * SilcClientFileMonitor monitor,
2136 * void *monitor_context,
2138 * SilcUInt32 session_id);
2142 * Receives a file from a client indicated by the `client_entry'. The
2143 * `session_id' indicates the file transmission session and it has been
2144 * received in the `ftp' client operation function. This will actually
2145 * perform the key agreement protocol with the remote client before
2146 * actually starting the file transmission. The `monitor' callback
2147 * will be called to monitor the transmission. If `path' is non NULL
2148 * the file will be saved into that directory. If NULL the file is
2149 * saved in the current working directory.
2151 * If error will occur during the file transfer process the error
2152 * status will be returned in the monitor callback. In this case
2153 * the application must call silc_client_file_close to close the
2158 silc_client_file_receive(SilcClient client,
2159 SilcClientConnection conn,
2160 SilcClientFileMonitor monitor,
2161 void *monitor_context,
2163 SilcUInt32 session_id);
2165 /****f* silcclient/SilcClientAPI/silc_client_file_close
2169 * SilcClientFileError silc_client_file_close(SilcClient client,
2170 * SilcClientConnection conn,
2171 * SilcUInt32 session_id);
2175 * Closes file transmission session indicated by the `session_id'.
2176 * If file transmission is being conducted it will be aborted
2177 * automatically. This function is also used to close the session
2178 * after successful file transmission. This function can be used
2179 * also to reject incoming file transmission request.
2182 SilcClientFileError silc_client_file_close(SilcClient client,
2183 SilcClientConnection conn,
2184 SilcUInt32 session_id);
2187 #include "command.h"
2188 #include "command_reply.h"
2190 #include "protocol.h"
2196 #endif /* SILCCLIENT_H */