5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2005 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.
56 /* General definitions */
58 /****s* silcclient/SilcClientAPI/SilcClient
62 * typedef struct SilcClientStruct { ... } *SilcClient
66 * This is the actual SILC Client structure which represents one
67 * SILC Client. It is allocated with the silc_client_alloc function
68 * and given as argument to all SILC Client Library functions. It
69 * is initialized with silc_client_init function, and freed with
70 * silc_client_free function.
74 struct SilcClientStruct {
76 * The following fields are set by application. Strings MUST be UTF-8
79 char *nickname; /* Nickname, MAY be set by application */
80 char *username; /* Username, MUST be set by application */
81 char *hostname; /* hostname, MUST be set by application */
82 char *realname; /* Real name, MUST be set be application */
84 SilcPublicKey public_key; /* Public key of user, set by application */
85 SilcPrivateKey private_key; /* Private key of user, set by application */
86 SilcPKCS pkcs; /* PKCS allocated by application */
89 * The following fields are set by the library
92 /* Scheduler, set by library. Application may use this pointer. */
93 SilcSchedule schedule;
95 /* Random Number Generator. Application should use this as its primary
96 random number generator. */
99 /* Application specific user data pointer. Client library does not
100 touch this. This the context sent as argument to silc_client_alloc.
101 Application can use it freely. */
104 /* Generic hash context for application usage */
108 /* Internal data for client library. Application cannot access this
110 SilcClientInternal internal;
114 /****s* silcclient/SilcClientAPI/SilcClientConnection
118 * typedef struct SilcClientConnectionStruct { ... }
119 * *SilcClientConnection
123 * This structure represents a connection. When connection is created
124 * to server this is context is returned to the application in the
125 * "connected" client operation. It includes all the important
126 * data for the session, such as nickname, local and remote IDs, and
127 * other information. All strings in the structure are UTF-8 encoded.
131 struct SilcClientConnectionStruct {
135 char *nickname; /* Current nickname */
136 SilcClientEntry local_entry; /* Own Client Entry */
137 SilcClientID *local_id; /* Current Client ID */
138 unsigned char *local_id_data; /* Current Client ID decoded */
139 SilcUInt32 local_id_data_len;
144 char *remote_host; /* Remote host name, UTF-8 encoded */
145 int remote_port; /* Remote port */
146 SilcServerID *remote_id; /* Remote Server ID */
147 unsigned char *remote_id_data; /* Remote Server ID decoded */
148 SilcUInt32 remote_id_data_len;
154 /* Current command identifier for a command that was sent last.
155 Application may get the value from this variable to find out the
156 command identifier for last command. */
157 SilcUInt16 cmd_ident;
159 /* User data context. Library does not touch this. Application may
160 freely set and use this pointer for its needs. */
163 /* Pointer back to the SilcClient. Application may use this. */
166 /* Current channel. Application may use and set this pointer if needed. */
167 SilcChannelEntry current_channel;
169 /* Socket connection object for this connection. Application may
170 use this if needed. The sock->user_data is back pointer to this
172 SilcSocketConnection sock;
174 /* Internal data for client library. Application cannot access this
176 SilcClientConnectionInternal internal;
180 /****s* silcclient/SilcClientAPI/SilcClientEntry
184 * typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
188 * This structure represents a client or a user in the SILC network.
189 * The local user has this structure also and it can be accessed from
190 * SilcClientConnection structure. All other users in the SILC network
191 * that are accessed using the Client Library routines will have their
192 * own SilcClientEntry structure. For example, when finding users by
193 * their nickname the Client Library returns this structure back to
194 * the application. All strings in the structure are UTF-8 encoded.
198 struct SilcClientEntryStruct {
199 /* General information */
200 char *nickname; /* nickname */
201 char *username; /* username */
202 char *hostname; /* hostname */
203 char *server; /* SILC server name */
204 char *realname; /* Realname (userinfo) */
206 /* Mode, ID and other information */
207 SilcUInt32 mode; /* User mode in SILC, see SilcUserMode */
208 SilcClientID *id; /* The Client ID */
209 SilcDList attrs; /* Requested Attributes (maybe NULL) */
210 unsigned char *fingerprint; /* Fingerprint of client's public key */
211 SilcUInt32 fingerprint_len; /* Length of the fingerprint */
212 SilcPublicKey public_key; /* User's public key, may be NULL */
214 /* Private message keys */
215 SilcCipher send_key; /* Private message key for sending */
216 SilcCipher receive_key; /* Private message key for receiving */
217 SilcHmac hmac_send; /* Private mesage key HMAC for sending */
218 SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
219 unsigned char *key; /* Set only if application provided the
220 key material. NULL if the library
221 generated the key. */
222 SilcUInt32 key_len; /* Key length */
223 SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
225 /* SilcClientEntry status information */
226 SilcEntryStatus status; /* Status mask */
227 SilcHashTable channels; /* All channels client has joined */
228 SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
229 unsigned int generated : 1; /* TRUE if library generated `key' */
230 unsigned int valid : 1; /* FALSE if this entry is not valid */
231 unsigned int prv_resp : 1; /* TRUE if private message key indicator
232 has been received (responder). */
234 /* Application specific data. Application may set here whatever it wants. */
239 /****s* silcclient/SilcClientAPI/SilcChannelEntry
243 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
247 * This structure represents a channel in the SILC network. All
248 * channels that the client are aware of or have joined in will be
249 * represented as SilcChannelEntry. The structure includes information
250 * about the channel. All strings in the structure are UTF-8 encoded.
254 struct SilcChannelEntryStruct {
255 /* General information */
256 char *channel_name; /* Channel name */
257 SilcChannelID *id; /* Channel ID */
258 SilcUInt32 mode; /* Channel mode, ChannelModes. */
259 char *topic; /* Current topic, may be NULL */
260 SilcPublicKey founder_key; /* Founder key, may be NULL */
261 SilcUInt32 user_limit; /* User limit on channel */
263 /* All clients that has joined this channel. The key to the table is the
264 SilcClientEntry and the context is SilcChannelUser context. */
265 SilcHashTable user_list;
268 SilcCipher channel_key; /* The channel key */
269 unsigned char *key; /* Raw key data */
270 SilcUInt32 key_len; /* Raw key data length */
271 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
272 SilcHmac hmac; /* Current HMAC */
274 /* Channel private keys */
275 SilcDList private_keys; /* List of private keys or NULL */
276 SilcChannelPrivateKey curr_key; /* Current private key */
278 /* SilcChannelEntry status information */
279 SilcDList old_channel_keys;
281 SilcUInt16 resolve_cmd_ident; /* Command identifier when
282 resolving this entry */
284 /* Application specific data. Application may set here whatever it wants. */
289 /****s* silcclient/SilcClientAPI/SilcChannelUser
293 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
297 * This structure represents a client that has joined to a channel.
298 * It shows the client and the channel and the client's mode (channel
299 * user mode) on the channel.
303 struct SilcChannelUserStruct {
304 SilcClientEntry client; /* Client joined on channel */
305 SilcUInt32 mode; /* mode, ChannelUserModes */
306 SilcChannelEntry channel; /* The channel user has joined */
308 /* Application specific data. Application may set here whatever it wants. */
313 /****s* silcclient/SilcClientAPI/SilcServerEntry
317 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
321 * This structure represents a server in the SILC network. All servers
322 * that the client is aware of and have for example resolved with
323 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
324 * All strings in the structure are UTF-8 encoded.
328 struct SilcServerEntryStruct {
329 /* General information */
330 char *server_name; /* Server name */
331 char *server_info; /* Server info */
332 SilcServerID *server_id; /* Server ID */
333 SilcUInt16 resolve_cmd_ident; /* Command identifier when
334 resolving this entry */
336 /* Application specific data. Application may set here whatever it wants. */
341 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
345 * typedef enum { ... } SilcKeyAgreementStatus;
349 * Key agreement status types indicating the status of the key
350 * agreement protocol. These types are returned to the application
351 * in the SilcKeyAgreementCallback callback function.
356 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
357 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
358 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
359 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
360 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
361 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
362 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
363 } SilcKeyAgreementStatus;
366 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
370 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
371 * SilcClientConnection conn,
372 * SilcClientEntry client_entry,
373 * SilcKeyAgreementStatus status,
374 * SilcSKEKeyMaterial *key,
379 * Key agreement callback that is called after the key agreement protocol
380 * has been performed. This is called also if error occurred during the
381 * key agreement protocol. The `key' is the allocated key material and
382 * the caller is responsible of freeing it. The `key' is NULL if error
383 * has occurred. The application can freely use the `key' to whatever
384 * purpose it needs. See lib/silcske/silcske.h for the definition of
385 * the SilcSKEKeyMaterial structure.
388 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
389 SilcClientConnection conn,
390 SilcClientEntry client_entry,
391 SilcKeyAgreementStatus status,
392 SilcSKEKeyMaterial *key,
395 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
399 * typedef struct { ... } SilcPrivateMessageKeys;
403 * Structure to hold the list of private message keys. The array of this
404 * structure is returned by the silc_client_list_private_message_keys
410 SilcClientEntry client_entry; /* The remote client entry */
411 char *cipher; /* The cipher name */
412 unsigned char *key; /* The original key, If the appliation
413 provided it. This is NULL if the
414 library generated the key or if
415 the SKE key material was used. */
416 SilcUInt32 key_len; /* The key length */
417 } *SilcPrivateMessageKeys;
420 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
424 * typedef struct SilcChannelPrivateKeyStruct { ... }
425 * *SilcChannelPrivateKey;
429 * Structure to hold one channel private key. The array of this structure
430 * is returned by silc_client_list_channel_private_keys function.
434 struct SilcChannelPrivateKeyStruct {
435 char *name; /* Application given name */
436 SilcCipher cipher; /* The cipher and key */
437 SilcHmac hmac; /* The HMAC and hmac key */
438 unsigned char *key; /* The key data */
439 SilcUInt32 key_len; /* The key length */
443 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
447 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
448 * SilcUInt32 passphrase_len,
453 * Ask passphrase callback. This is called by the application when the
454 * library calls `ask_passphrase' client operation. The callback delivers
455 * the passphrase to the library. The passphrases in SILC protocol
456 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
457 * encoded, and if it is not then library will attempt to encode it.
460 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
461 SilcUInt32 passphrase_len,
464 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
468 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
472 * Public key (or certificate) verification callback. This is called
473 * by the application to indicate that the public key verification was
474 * either success or failure.
477 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
479 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
483 * typedef void (*SilcGetAuthMeth)(bool success,
484 * SilcProtocolAuthMeth auth_meth,
485 * const unsigned char *auth_data,
486 * SilcUInt32 auth_data_len, void *context);
490 * Authentication method resolving callback. This is called by the
491 * application to return the resolved authentication method. The client
492 * library has called the get_auth_method client operation and given
493 * this function pointer as argument. The `success' will indicate whether
494 * the authentication method could be resolved. The `auth_meth' is the
495 * resolved authentication method. The `auth_data' and the `auth_data_len'
496 * are the resolved authentication data. The `context' is the libary's
497 * context sent to the get_auth_method client operation.
500 typedef void (*SilcGetAuthMeth)(bool success,
501 SilcProtocolAuthMeth auth_meth,
502 const unsigned char *auth_data,
503 SilcUInt32 auth_data_len, void *context);
505 /****d* silcclient/SilcClientAPI/SilcClientMessageType
509 * typedef enum { ... } SilcClientMessageType;
513 * Different message types for `say' client operation. The application
514 * may filter the message sent by the library according this type.
519 SILC_CLIENT_MESSAGE_INFO, /* Informational */
520 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
521 SILC_CLIENT_MESSAGE_ERROR, /* Error */
522 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
523 } SilcClientMessageType;
526 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
530 * typedef enum { ... } SilcClientConnectionStatus
534 * This type is returned to the `connect' client operation to indicate
535 * the status of the created connection. It can indicate if it was
536 * successful or whether an error occurred.
541 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
542 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
543 resumed old detached session */
544 SILC_CLIENT_CONN_ERROR, /* Unknown error occurred during
546 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
547 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
548 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
549 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
550 } SilcClientConnectionStatus;
553 /****s* silcclient/SilcClientAPI/SilcClientOperations
557 * typedef struct { ... } SilcClientOperations;
561 * SILC Client Operations. These must be implemented by the application.
562 * The Client library may call any of these routines at any time. The
563 * routines are used to deliver certain information to the application
564 * or from the application to the client library.
569 /* Message sent to the application by library. `conn' associates the
570 message to a specific connection. `conn', however, may be NULL.
571 The `type' indicates the type of the message sent by the library.
572 The application can for example filter the message according the
573 type. The variable argument list is arguments to the formatted
574 message that `msg' may be. */
575 void (*say)(SilcClient client, SilcClientConnection conn,
576 SilcClientMessageType type, char *msg, ...);
578 /* Message for a channel. The `sender' is the sender of the message
579 The `channel' is the channel. The `message' is the message. Note
580 that `message' maybe NULL. The `flags' indicates message flags
581 and it is used to determine how the message can be interpreted
582 (like it may tell the message is multimedia message). */
583 void (*channel_message)(SilcClient client, SilcClientConnection conn,
584 SilcClientEntry sender, SilcChannelEntry channel,
585 SilcMessagePayload payload,
586 SilcChannelPrivateKey key, SilcMessageFlags flags,
587 const unsigned char *message,
588 SilcUInt32 message_len);
590 /* Private message to the client. The `sender' is the sender of the
591 message. The message is `message'and maybe NULL. The `flags'
592 indicates message flags and it is used to determine how the message
593 can be interpreted (like it may tell the message is multimedia
595 void (*private_message)(SilcClient client, SilcClientConnection conn,
596 SilcClientEntry sender, SilcMessagePayload payload,
597 SilcMessageFlags flags,
598 const unsigned char *message,
599 SilcUInt32 message_len);
601 /* Notify message to the client. The notify arguments are sent in the
602 same order as servers sends them. The arguments are same as received
603 from the server except for ID's. If ID is received application receives
604 the corresponding entry to the ID. For example, if Client ID is received
605 application receives SilcClientEntry. Also, if the notify type is
606 for channel the channel entry is sent to application (even if server
607 does not send it because client library gets the channel entry from
608 the Channel ID in the packet's header). */
609 void (*notify)(SilcClient client, SilcClientConnection conn,
610 SilcNotifyType type, ...);
612 /* Command handler. This function is called always in the command function.
613 If error occurs it will be called as well. `conn' is the associated
614 client connection. `cmd_context' is the command context that was
615 originally sent to the command. `success' is FALSE if error occurred
616 during command. `command' is the command being processed. It must be
617 noted that this is not reply from server. This is merely called just
618 after application has called the command. Just to tell application
619 that the command really was processed. */
620 void (*command)(SilcClient client, SilcClientConnection conn,
621 SilcClientCommandContext cmd_context, bool success,
622 SilcCommand command, SilcStatus status);
624 /* Command reply handler. This function is called always in the command reply
625 function. If error occurs it will be called as well. Normal scenario
626 is that it will be called after the received command data has been parsed
627 and processed. The function is used to pass the received command data to
630 `conn' is the associated client connection. `cmd_payload' is the command
631 payload data received from server and it can be ignored. It is provided
632 if the application would like to re-parse the received command data,
633 however, it must be noted that the data is parsed already by the library
634 thus the payload can be ignored. `success' is FALSE if error occurred.
635 In this case arguments are not sent to the application. The `status' is
636 the command reply status server returned. The `command' is the command
637 reply being processed. The function has variable argument list and each
638 command defines the number and type of arguments it passes to the
639 application (on error they are not sent).
641 The arguments are sent in the same order as servers sends them. The
642 arguments are same as received from the server except for ID's. If
643 ID is received application receives the corresponding entry to the
644 ID. For example, if Client ID is receives application receives
646 void (*command_reply)(SilcClient client, SilcClientConnection conn,
647 SilcCommandPayload cmd_payload, bool success,
648 SilcCommand command, SilcStatus status, ...);
650 /* Called to indicate that connection was either successfully established
651 or connecting failed. This is also the first time application receives
652 the SilcClientConnection object which it should save somewhere.
653 The `status' indicated whether the connection were successful. If it
654 is error value the application must always call the function
655 silc_client_close_connection. */
656 void (*connected)(SilcClient client, SilcClientConnection conn,
657 SilcClientConnectionStatus status);
659 /* Called to indicate that connection was disconnected to the server.
660 The `status' may tell the reason of the disconnection, and if the
661 `message' is non-NULL it may include the disconnection message
662 received from server. Application must not call the
663 silc_client_close_connection in this callback. The 'conn' is also
664 invalid after this function returns back to library. */
665 void (*disconnected)(SilcClient client, SilcClientConnection conn,
666 SilcStatus status, const char *message);
668 /* Find authentication method and authentication data by hostname and
669 port. The hostname may be IP address as well. When the authentication
670 method has been resolved the `completion' callback with the found
671 authentication method and authentication data is called. The `conn'
673 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
674 char *hostname, SilcUInt16 port,
675 SilcGetAuthMeth completion, void *context);
677 /* Verifies received public key. The `conn_type' indicates which entity
678 (server, client etc.) has sent the public key. If user decides to trust
679 the application may save the key as trusted public key for later
680 use. The `completion' must be called after the public key has been
682 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
683 SilcSocketType conn_type, unsigned char *pk,
684 SilcUInt32 pk_len, SilcSKEPKType pk_type,
685 SilcVerifyPublicKey completion, void *context);
687 /* Ask (interact, that is) a passphrase from user. The passphrase is
688 returned to the library by calling the `completion' callback with
689 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
690 if not then the library will attempt to encode. */
691 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
692 SilcAskPassphrase completion, void *context);
694 /* Notifies application that failure packet was received. This is called
695 if there is some protocol active in the client. The `protocol' is the
696 protocol context. The `failure' is opaque pointer to the failure
697 indication. Note, that the `failure' is protocol dependant and
698 application must explicitly cast it to correct type. Usually `failure'
699 is 32 bit failure type (see protocol specs for all protocol failure
701 void (*failure)(SilcClient client, SilcClientConnection conn,
702 SilcProtocol protocol, void *failure);
704 /* Asks whether the user would like to perform the key agreement protocol.
705 This is called after we have received an key agreement packet or an
706 reply to our key agreement packet. This returns TRUE if the user wants
707 the library to perform the key agreement protocol and FALSE if it is not
708 desired (application may start it later by calling the function
709 silc_client_perform_key_agreement). If TRUE is returned also the
710 `completion' and `context' arguments must be set by the application. */
711 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
712 SilcClientEntry client_entry, const char *hostname,
713 SilcUInt16 port, SilcKeyAgreementCallback *completion,
716 /* Notifies application that file transfer protocol session is being
717 requested by the remote client indicated by the `client_entry' from
718 the `hostname' and `port'. The `session_id' is the file transfer
719 session and it can be used to either accept or reject the file
720 transfer request, by calling the silc_client_file_receive or
721 silc_client_file_close, respectively. */
722 void (*ftp)(SilcClient client, SilcClientConnection conn,
723 SilcClientEntry client_entry, SilcUInt32 session_id,
724 const char *hostname, SilcUInt16 port);
726 /* Delivers SILC session detachment data indicated by `detach_data' to the
727 application. If application has issued SILC_COMMAND_DETACH command
728 the client session in the SILC network is not quit. The client remains
729 in the network but is detached. The detachment data may be used later
730 to resume the session in the SILC Network. The appliation is
731 responsible of saving the `detach_data', to for example in a file.
733 The detachment data can be given as argument to the functions
734 silc_client_connect_to_server, or silc_client_add_connection when
735 creating connection to remote server, inside SilcClientConnectionParams
736 structure. If it is provided the client library will attempt to resume
737 the session in the network. After the connection is created
738 successfully, the application is responsible of setting the user
739 interface for user into the same state it was before detaching (showing
740 same channels, channel modes, etc). It can do this by fetching the
741 information (like joined channels) from the client library. */
742 void (*detach)(SilcClient client, SilcClientConnection conn,
743 const unsigned char *detach_data,
744 SilcUInt32 detach_data_len);
745 } SilcClientOperations;
748 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
752 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
753 * char **ret_nickname);
757 * A callback function provided by the application for the library in
758 * SilcClientParams structure. This function parses the formatted
759 * nickname string `nickname' and returns the true nickname to the
760 * `ret_nickname' pointer. The library can call this function at
764 typedef void (*SilcNicknameFormatParse)(const char *nickname,
765 char **ret_nickname);
767 /****s* silcclient/SilcClientAPI/SilcClientParams
771 * typedef struct { ... } SilcClientParams;
775 * Client parameters. This can be filled with proper values and
776 * given as argument to the silc_client_alloc function. The structure
777 * hold various parameters which affects the function of the client.
782 /* Number of maximum tasks the client library's scheduler can handle.
783 If set to zero, the default value will be used (200). For WIN32
784 systems this should be set to 64 as it is the hard limit dictated
788 /* Rekey timeout in seconds. The client will perform rekey in this
789 time interval. If set to zero, the default value will be used. */
790 unsigned int rekey_secs;
792 /* Connection authentication method request timeout. If server does not
793 reply back the current authentication method when we've requested it
794 in this time interval we'll assume the reply will not come at all.
795 If set to zero, the default value (2 seconds) will be used. */
796 unsigned int connauth_request_secs;
798 /* Nickname format string. This can be used to order the client library
799 to save the nicknames in the library in a certain format. Since
800 nicknames are not unique in SILC it is possible to have multiple same
801 nicknames. Using this format string it is possible to order the library
802 to separate the multiple same nicknames from each other. The format
803 types are defined below and they can appear in any order in the format
804 string. If this is NULL then default format is used which is the
805 default nickname without anything else. The string MUST be NULL
808 Following format types are available:
810 %n nickname - the real nickname returned by the server (mandatory)
811 %h hostname - the stripped hostname of the client
812 %H full hostname - the full hostname of the client
813 %s server name - the server name the client is connected
814 %S full server - the full server name the client is connected
815 %a number - ascending number in case there are several
816 same nicknames (fe. nick@host and nick@host2)
818 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
819 "%a!%n@%s" (fe. nick@server, 2!nick@server)
820 "%n@%H" (fe. nick@host.domain.com)
822 By default this format is employed to the nicknames by the libary
823 only when there appears multiple same nicknames. If the library has
824 only one nickname cached the nickname is saved as is and without the
825 defined format. If you want always to save the nickname in the defined
826 format set the boolean field `nickname_force_format' to value TRUE.
828 char nickname_format[32];
830 /* If this is set to TRUE then the `nickname_format' is employed to all
831 saved nicknames even if there are no multiple same nicknames in the
832 cache. By default this is FALSE, which means that the `nickname_format'
833 is employed only if the library will receive a nickname that is
834 already saved in the cache. It is recommended to leave this to FALSE
836 bool nickname_force_format;
838 /* A callback function provided by the application for the library to
839 parse the nickname from the formatted nickname string. Even though
840 the libary formats the nicknames the application knows generally the
841 format better so this function should be provided for the library
842 if the application sets the `nickname_format' field. The library
843 will call this to get the true nickname from the provided formatted
844 nickname string whenever it needs the true nickname. */
845 SilcNicknameFormatParse nickname_parse;
847 /* If this is set to TRUE then the client will ignore all incoming
848 Requested Attributes queries and does not reply anything back. This
849 usually leads into situation where server does not anymore send
850 the queries after seeing that client does not reply anything back.
851 If your application does not support Requested Attributes or you do
852 not want to use them set this to TRUE. See SilcAttribute and
853 silc_client_attribute_add for more information on attributes. */
854 bool ignore_requested_attributes;
856 /* If this is set to TRUE, the silcclient library will not register and
857 deregister the cipher, pkcs, hash and hmac algorithms. The application
858 itself will need to handle that. */
859 bool dont_register_crypto_library;
865 /* Initialization functions (client.c) */
867 /****f* silcclient/SilcClientAPI/silc_client_alloc
871 * SilcClient silc_client_alloc(SilcClientOperations *ops,
872 * SilcClientParams *params,
874 * const char *silc_version);
878 * Allocates new client object. This has to be done before client may
879 * work. After calling this one must call silc_client_init to initialize
880 * the client. The `application' is application specific user data pointer
881 * and caller must free it. The `silc_version' is the application version
882 * that will be used to compare against remote host's (usually a server)
883 * version string. The `application' context is accessible by the
884 * application by client->application, client being SilcClient.
887 SilcClient silc_client_alloc(SilcClientOperations *ops,
888 SilcClientParams *params,
890 const char *version_string);
892 /****f* silcclient/SilcClientAPI/silc_client_free
896 * void silc_client_free(SilcClient client);
900 * Frees client object and its internals. The execution of the client
901 * should be stopped with silc_client_stop function before calling
905 void silc_client_free(SilcClient client);
907 /****f* silcclient/SilcClientAPI/silc_client_init
911 * bool silc_client_init(SilcClient client);
915 * Initializes the client. This makes all the necessary steps to make
916 * the client ready to be run. One must call silc_client_run to run the
917 * client. Returns FALSE if error occurred, TRUE otherwise.
920 bool silc_client_init(SilcClient client);
922 /****f* silcclient/SilcClientAPI/silc_client_run
926 * void silc_client_run(SilcClient client);
930 * Runs the client. This starts the scheduler from the utility library.
931 * When this functions returns the execution of the appliation is over.
932 * The client must be initialized before calling this.
935 void silc_client_run(SilcClient client);
937 /****f* silcclient/SilcClientAPI/silc_client_run_one
941 * void silc_client_run_one(SilcClient client);
945 * Runs the client and returns immeadiately. This function is used when
946 * the SILC Client object indicated by the `client' is run under some
947 * other scheduler, or event loop or main loop. On GUI applications,
948 * for example this may be desired to used to run the client under the
949 * GUI application's main loop. Typically the GUI application would
950 * register an idle task that calls this function multiple times in
951 * a second to quickly process the SILC specific data.
954 void silc_client_run_one(SilcClient client);
956 /****f* silcclient/SilcClientAPI/silc_client_stop
960 * void silc_client_stop(SilcClient client);
964 * Stops the client. This is called to stop the client and thus to stop
965 * the program. The client context must be freed with the silc_client_free
969 void silc_client_stop(SilcClient client);
972 /* Connecting functions (client.c) */
974 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
978 * typedef struct { ... } SilcClientConnectionParams;
982 * Client connection parameters. This can be filled by the application
983 * and given as argument to silc_client_connect_to_server or to
984 * silc_client_add_connection.
989 /* The SILC session detachment data that was returned by `detach' client
990 operation when the application detached from the network. Application
991 is responsible of saving the data and giving it as argument here
992 for resuming the session in the SILC network.
994 If this is provided here the client library will attempt to resume
995 the session in the network. After the connection is created
996 successfully, the application is responsible of setting the user
997 interface for user into the same state it was before detaching (showing
998 same channels, channel modes, etc). It can do this by fetching the
999 information (like joined channels) from the client library. */
1000 unsigned char *detach_data;
1001 SilcUInt32 detach_data_len;
1003 } SilcClientConnectionParams;
1006 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
1010 * int silc_client_connect_to_server(SilcClient client,
1011 * SilcClientConnectionParams *params,
1012 * int port, char *host, void *context);
1016 * Connects to remote server. This is the main routine used to connect
1017 * to SILC server. Returns -1 on error and the created socket otherwise.
1018 * The `context' is user context that is saved into the SilcClientConnection
1019 * that is created after the connection is created. Note that application
1020 * may handle the connecting process outside the library. If this is the
1021 * case then this function is not used at all. When the connecting is
1022 * done the `connect' client operation is called, and the `context' is
1023 * accessible with conn->context, conn being SilcClientConnection.
1024 * If the `params' is provided they are used by the routine.
1027 int silc_client_connect_to_server(SilcClient client,
1028 SilcClientConnectionParams *params,
1029 int port, char *host, void *context);
1031 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1036 * SilcClientConnection
1037 * silc_client_add_connection(SilcClient client,
1038 * SilcClientConnectionParams *params,
1039 * char *hostname, int port, void *context);
1043 * Allocates and adds new connection to the client. This adds the allocated
1044 * connection to the connection table and returns a pointer to it. A client
1045 * can have multiple connections to multiple servers. Every connection must
1046 * be added to the client using this function. User data `context' may
1047 * be sent as argument. If the `params' is provided they are used by
1052 * This function is normally used only if the application performed
1053 * the connecting outside the library, and did not called the
1054 * silc_client_connect_to_server function at all. The library
1055 * however may use this internally.
1058 SilcClientConnection
1059 silc_client_add_connection(SilcClient client,
1060 SilcClientConnectionParams *params,
1061 char *hostname, int port, void *context);
1063 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1067 * void silc_client_del_connection(SilcClient client,
1068 * SilcClientConnection conn);
1072 * Removes connection from client. Frees all memory. The library
1073 * call this function automatically for all connection contexts.
1074 * The application however may free the connection contexts it has
1078 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1080 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1084 * void silc_client_add_socket(SilcClient client,
1085 * SilcSocketConnection sock);
1089 * Adds listener socket to the listener sockets table. This function is
1090 * used to add socket objects that are listeners to the client. This should
1091 * not be used to add other connection objects.
1094 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1096 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1100 * void silc_client_del_socket(SilcClient client,
1101 * SilcSocketConnection sock);
1105 * Deletes listener socket from the listener sockets table. If the
1106 * application has added a socket with silc_client_add_socket it must
1107 * also free it using this function.
1110 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1112 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1116 * void silc_client_start_key_exchange(SilcClient client,
1117 * SilcClientConnection conn,
1122 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1123 * key material between client and server. This function can be called
1124 * directly if application is performing its own connecting and does not
1125 * use the connecting provided by this library. This function is normally
1126 * used only if the application performed the connecting outside the
1127 * library. The library however may use this internally. After the
1128 * key exchange is performed the `connect' client operation is called.
1132 * The silc_client_add_connection must be called before calling this
1133 * function to create the SilcClientConnection context for this
1137 void silc_client_start_key_exchange(SilcClient client,
1138 SilcClientConnection conn,
1141 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1145 * void silc_client_close_connection(SilcClient client,
1146 * SilcClientConnection conn);
1150 * Closes connection to remote end. Free's all allocated data except
1151 * for some information such as nickname etc. that are valid at all time.
1152 * Usually application does not need to directly call this, except
1153 * when explicitly closing the connection, or if an error occurs
1154 * during connection to server (see 'connect' client operation for
1155 * more information).
1158 void silc_client_close_connection(SilcClient client,
1159 SilcClientConnection conn);
1162 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1164 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1168 * bool silc_client_send_channel_message(SilcClient client,
1169 * SilcClientConnection conn,
1170 * SilcChannelEntry channel,
1171 * SilcChannelPrivateKey key,
1172 * SilcMessageFlags flags,
1173 * unsigned char *data,
1174 * SilcUInt32 data_len,
1179 * Sends packet to the `channel'. Packet to channel is always encrypted
1180 * differently from "normal" packets. SILC header of the packet is
1181 * encrypted with the next receiver's key and the rest of the packet is
1182 * encrypted with the channel specific key. Padding and HMAC is computed
1183 * with the next receiver's key. The `data' is the channel message. If
1184 * the `force_send' is TRUE then the packet is sent immediately.
1186 * If `key' is provided then that private key is used to encrypt the
1187 * channel message. If it is not provided, private keys has not been
1188 * set at all, the normal channel key is used automatically. If private
1189 * keys are set then the first key (the key that was added first as
1190 * private key) is used.
1192 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1193 * digitally signed with the SILC key pair.
1195 * Returns TRUE if the message was sent, and FALSE if error occurred or
1196 * the sending is not allowed due to channel modes (like sending is
1200 bool silc_client_send_channel_message(SilcClient client,
1201 SilcClientConnection conn,
1202 SilcChannelEntry channel,
1203 SilcChannelPrivateKey key,
1204 SilcMessageFlags flags,
1205 unsigned char *data,
1206 SilcUInt32 data_len,
1209 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1213 * bool silc_client_send_private_message(SilcClient client,
1214 * SilcClientConnection conn,
1215 * SilcClientEntry client_entry,
1216 * SilcMessageFlags flags,
1217 * unsigned char *data,
1218 * SilcUInt32 data_len,
1223 * Sends private message to remote client. If private message key has
1224 * not been set with this client then the message will be encrypted using
1225 * normal session keys. Private messages are special packets in SILC
1226 * network hence we need this own function for them. This is similar
1227 * to silc_client_packet_send_to_channel except that we send private
1228 * message. The `data' is the private message. If the `force_send' is
1229 * TRUE the packet is sent immediately.
1231 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1232 * digitally signed with the SILC key pair.
1234 * Returns TRUE if the message was sent, and FALSE if error occurred.
1237 bool silc_client_send_private_message(SilcClient client,
1238 SilcClientConnection conn,
1239 SilcClientEntry client_entry,
1240 SilcMessageFlags flags,
1241 unsigned char *data,
1242 SilcUInt32 data_len,
1246 /* Client and Channel entry retrieval (idlist.c) */
1248 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1252 * typedef void (*SilcGetClientCallback)(SilcClient client,
1253 * SilcClientConnection conn,
1254 * SilcClientEntry *clients,
1255 * SilcUInt32 clients_count,
1260 * Callback function given to the silc_client_get_client function. The
1261 * found entries are allocated into the `clients' array. The array must
1262 * not be freed by the receiver, the library will free it later. If the
1263 * `clients' is NULL, no such clients exist in the SILC Network.
1266 typedef void (*SilcGetClientCallback)(SilcClient client,
1267 SilcClientConnection conn,
1268 SilcClientEntry *clients,
1269 SilcUInt32 clients_count,
1272 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1276 * void silc_client_get_clients(SilcClient client,
1277 * SilcClientConnection conn,
1278 * const char *nickname,
1279 * const char *server,
1280 * SilcGetClientCallback completion,
1285 * Finds client entry or entries by the `nickname' and `server'. The
1286 * completion callback will be called when the client entries has been
1287 * found. After the server returns the client information it is cached
1288 * and can be accesses locally at a later time. The resolving is done
1289 * with IDENTIFY command. The `server' may be NULL.
1293 * NOTE: This function is always asynchronous and resolves the client
1294 * information from the server. Thus, if you already know the client
1295 * information then use the silc_client_get_client_by_id function to
1296 * get the client entry since this function may be very slow and should
1297 * be used only to initially get the client entries.
1299 * Since this routine resolves with IDENTIFY command only the relevant
1300 * information (user's nickname and username) is resolved. For example,
1301 * user's real name, channel list and others are not resolved. Caller
1302 * can/must resolve those separately if they are needed (for example,
1303 * with silc_client_get_client_by_id_resolve).
1306 void silc_client_get_clients(SilcClient client,
1307 SilcClientConnection conn,
1308 const char *nickname,
1310 SilcGetClientCallback completion,
1313 /****f* silcclient/SilcClientAPI/silc_client_get_clients_whois
1317 * void silc_client_get_clients_whois(SilcClient client,
1318 * SilcClientConnection conn,
1319 * const char *nickname,
1320 * const char *server,
1321 * SilcBuffer attributes,
1322 * SilcGetClientCallback completion,
1327 * Finds client entry or entries by the `nickname' and `server'. The
1328 * completion callback will be called when the client entries has been
1329 * found. After the server returns the client information it is cached
1330 * and can be accesses locally at a later time. The resolving is done
1331 * with WHOIS command. The `server' may be NULL.
1333 * If the `attributes' is non-NULL then the buffer includes Requested
1334 * Attributes which can be used to fetch very detailed information
1335 * about the user. If it is NULL then only normal WHOIS query is
1336 * made (for more information about attributes see SilcAttribute).
1337 * Caller may create the `attributes' with silc_client_attributes_request
1342 * The resolving is done with WHOIS command. For this reason this
1343 * command may take a long time because it resolves detailed user
1347 void silc_client_get_clients_whois(SilcClient client,
1348 SilcClientConnection conn,
1349 const char *nickname,
1351 SilcBuffer attributes,
1352 SilcGetClientCallback completion,
1355 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1359 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1360 * SilcClientConnection conn,
1361 * const char *nickname,
1362 * const char *format,
1363 * SilcUInt32 *clients_count);
1367 * Same as silc_client_get_clients function but does not resolve anything
1368 * from the server. This checks local cache and returns all matching
1369 * clients from the local cache. If none was found this returns NULL.
1370 * The `nickname' is the real nickname of the client, and the `format'
1371 * is the formatted nickname to find exact match from multiple found
1372 * entries. The format must be same as given in the SilcClientParams
1373 * structure to the client library. If the `format' is NULL all found
1374 * clients by `nickname' are returned. The caller must return the
1378 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1379 SilcClientConnection conn,
1380 const char *nickname,
1382 SilcUInt32 *clients_count);
1384 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1388 * void silc_client_get_clients_by_channel(SilcClient client,
1389 * SilcClientConnection conn,
1390 * SilcChannelEntry channel,
1391 * SilcGetClientCallback completion,
1396 * Gets client entries by the channel indicated by `channel'. Thus,
1397 * it resovles the users currently on that channel. If all users are
1398 * already resolved this returns the users from the channel. If the
1399 * users are resolved only partially this resolves the complete user
1400 * information. If no users are resolved on this channel at all, this
1401 * calls USERS command to resolve all users on the channel. The `completion'
1402 * will be called after the entries are available. When server returns
1403 * the client information it will be cached and can be accessed locally
1406 * This function can be used for example in SILC_COMMAND_JOIN command
1407 * reply handling in application to resolve users on that channel. It
1408 * also can be used after calling silc_client_get_channel_resolve to
1409 * resolve users on that channel.
1413 * The resolving is done with WHOIS command. For this reason this
1414 * command may take a long time because it resolves detailed user
1418 void silc_client_get_clients_by_channel(SilcClient client,
1419 SilcClientConnection conn,
1420 SilcChannelEntry channel,
1421 SilcGetClientCallback completion,
1424 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1428 * void silc_client_get_clients_by_list(SilcClient client,
1429 * SilcClientConnection conn,
1430 * SilcUInt32 list_count,
1431 * SilcBuffer client_id_list,
1432 * SilcGetClientCallback completion,
1437 * Gets client entries by the list of client ID's `client_id_list'. This
1438 * always resolves those client ID's it does not know yet from the server
1439 * so this function might take a while. The `client_id_list' is a list
1440 * of ID Payloads added one after other. JOIN command reply and USERS
1441 * command reply for example returns this sort of list. The `completion'
1442 * will be called after the entries are available. When server returns
1443 * the client information it will be cached and can be accessed locally
1448 * The resolving is done with IDENTIFY command. This means that only
1449 * the relevant information of user (it's nickname and username) is
1450 * resolved. For example, user's real name, channel lists and others
1451 * are not resolved. Caller can/must resolve those separately if they
1452 * are needed (for example, with silc_client_get_client_by_id_resolve).
1455 void silc_client_get_clients_by_list(SilcClient client,
1456 SilcClientConnection conn,
1457 SilcUInt32 list_count,
1458 SilcBuffer client_id_list,
1459 SilcGetClientCallback completion,
1462 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1466 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1467 * SilcClientConnection conn,
1468 * SilcClientID *client_id);
1472 * Find entry for client by the client's ID. Returns the entry or NULL
1473 * if the entry was not found. This checks the local cache and does
1474 * not resolve anything from server.
1477 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1478 SilcClientConnection conn,
1479 SilcClientID *client_id);
1481 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1486 * silc_client_get_client_by_id_resolve(SilcClient client,
1487 * SilcClientConnection conn,
1488 * SilcClientID *client_id,
1489 * SilcBuffer attributes,
1490 * SilcGetClientCallback completion,
1495 * Same as silc_client_get_client_by_id but will always resolve the
1496 * information from the server. Use this only if you know that you
1497 * do not have the entry and the only thing you know about the client
1498 * is its ID. When server returns the client information it will be
1499 * cache and can be accessed locally at a later time. The resolving
1500 * is done by sending WHOIS command.
1502 * If the `attributes' is non-NULL then the buffer includes Requested
1503 * Attributes which can be used to fetch very detailed information
1504 * about the user. If it is NULL then only normal WHOIS query is
1505 * made (for more information about attributes see SilcAttribute).
1506 * Caller may create the `attributes' with silc_client_attributes_request
1510 void silc_client_get_client_by_id_resolve(SilcClient client,
1511 SilcClientConnection conn,
1512 SilcClientID *client_id,
1513 SilcBuffer attributes,
1514 SilcGetClientCallback completion,
1517 /****f* silcclient/SilcClientAPI/silc_client_del_client
1521 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1522 * SilcClientEntry client_entry)
1526 * Removes client from local cache by the client entry indicated by
1527 * the `client_entry'. Returns TRUE if the deletion were successful.
1530 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1531 SilcClientEntry client_entry);
1533 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1537 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1538 * SilcClientConnection conn,
1539 * SilcChannelEntry *channels,
1540 * SilcUInt32 channels_count,
1545 * Callback function given to the silc_client_get_channel_* functions.
1546 * The found entries are allocated into the `channels' array. The array
1547 * must not be freed by the receiver, the library will free it later.
1548 * If the `channel' is NULL, no such channel exist in the SILC Network.
1551 typedef void (*SilcGetChannelCallback)(SilcClient client,
1552 SilcClientConnection conn,
1553 SilcChannelEntry *channels,
1554 SilcUInt32 channels_count,
1557 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1561 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1562 * SilcClientConnection conn,
1563 * char *channel_name);
1567 * Finds entry for channel by the channel name. Returns the entry or NULL
1568 * if the entry was not found. It is found only if the client is joined
1569 * to the channel. Use silc_client_get_channel_resolve or
1570 * silc_client_get_channel_by_id_resolve to resolve channel that client
1574 SilcChannelEntry silc_client_get_channel(SilcClient client,
1575 SilcClientConnection conn,
1576 char *channel_name);
1578 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1582 * void silc_client_get_channel_resolve(SilcClient client,
1583 * SilcClientConnection conn,
1584 * char *channel_name,
1585 * SilcGetChannelCallback completion,
1590 * Resolves entry for channel by the channel name from the server.
1591 * The resolving is done with IDENTIFY command. Note that users on
1592 * the channel are not resolved at the same time. Use for example
1593 * silc_client_get_clients_by_channel to resolve all users on a channel.
1596 void silc_client_get_channel_resolve(SilcClient client,
1597 SilcClientConnection conn,
1599 SilcGetChannelCallback completion,
1602 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1607 * silc_client_get_channel_by_id(SilcClient client,
1608 * SilcClientConnection conn,
1609 * SilcChannelID *channel_id);
1613 * Finds channel entry by the channel ID. Returns the entry or NULL
1614 * if the entry was not found. This checks the local cache and does
1615 * not resolve anything from server.
1618 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1619 SilcClientConnection conn,
1620 SilcChannelID *channel_id);
1622 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1627 * silc_client_get_channel_by_id_resolve(SilcClient client,
1628 * SilcClientConnection conn,
1629 * SilcChannelID *channel_id,
1630 * SilcGetClientCallback completion,
1635 * Resolves the channel information (its name mainly) from the server
1636 * by the `channel_id'. Use this only if you know that you do not have
1637 * the entry cached locally. The resolving is done with IDENTIFY command.
1639 * Note that users on the channel are not resolved at the same time.
1640 * Use for example silc_client_get_clients_by_channel to resolve all
1641 * users on a channel.
1644 void silc_client_get_channel_by_id_resolve(SilcClient client,
1645 SilcClientConnection conn,
1646 SilcChannelID *channel_id,
1647 SilcGetChannelCallback completion,
1650 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1654 * bool silc_client_del_channel(SilcClient client,
1655 * SilcClientConnection conn,
1656 * SilcChannelEntry channel)
1660 * Removes channel from local cache by the channel entry indicated by
1661 * the `channel'. Returns TRUE if the deletion were successful.
1664 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1665 SilcChannelEntry channel);
1667 /****f* silcclient/SilcClientAPI/silc_client_get_server
1671 * SilcServerEntry silc_client_get_server(SilcClient client,
1672 * SilcClientConnection conn,
1673 * char *server_name)
1677 * Finds entry for server by the server name. Returns the entry or NULL
1678 * if the entry was not found.
1681 SilcServerEntry silc_client_get_server(SilcClient client,
1682 SilcClientConnection conn,
1685 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1689 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1690 * SilcClientConnection conn,
1691 * SilcServerID *server_id);
1695 * Finds entry for server by the server ID. Returns the entry or NULL
1696 * if the entry was not found.
1699 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1700 SilcClientConnection conn,
1701 SilcServerID *server_id);
1703 /****f* silcclient/SilcClientAPI/silc_client_del_server
1707 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1708 * SilcServerEntry server);
1712 * Removes server from local cache by the server entry indicated by
1713 * the `server'. Returns TRUE if the deletion were successful.
1716 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1717 SilcServerEntry server);
1719 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1723 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1724 * SilcClientEntry client_entry);
1728 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1729 * channel indicated by the `channel'. NULL if client is not joined on
1733 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1734 SilcClientEntry client_entry);
1736 /* Command management (command.c) */
1738 /****f* silcclient/SilcClientAPI/silc_client_command_call
1742 * bool silc_client_command_call(SilcClient client,
1743 * SilcClientConnection conn,
1744 * const char *command_line, ...);
1748 * Calls and executes the command indicated by the `command_name'.
1749 * The `command_line' is a string which includes the command's name and
1750 * its arguments separated with whitespaces (' '). If `command_line'
1751 * is non-NULL then all variable arguments are ignored by default.
1753 * If `command_line' is NULL, then the variable arguments define the
1754 * command's name and its arguments. The first variable argument must
1755 * be the command name. The variable argument list must be terminated
1758 * Returns FALSE if the command is not known and TRUE after command.
1759 * execution. The "command" client operation is called when the
1760 * command is executed to indicate whether the command executed
1761 * successfully or not.
1763 * The "command_reply" client operation will be called when reply is
1764 * received from the server to the command. Application may also use
1765 * the silc_client_command_pending to attach to the command reply.
1766 * The command identifier for silc_client_command_pending function after
1767 * this function call is conn->cmd_ident, which application may use.
1771 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1773 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1777 * This command executes the commands implemented inside the client
1778 * library. These commands are designed for command line applications,
1779 * but GUI application may call them too if needed. Alternatively
1780 * application may override the library and use silc_client_command_send
1784 bool silc_client_command_call(SilcClient client,
1785 SilcClientConnection conn,
1786 const char *command_line, ...);
1788 /****f* silcclient/SilcClientAPI/silc_client_command_send
1792 * void silc_client_command_send(SilcClient client,
1793 * SilcClientConnection conn,
1794 * SilcCommand command, SilcUInt16 ident,
1795 * SilcUInt32 argc, ...);
1799 * Generic function to send any command. The arguments must be sent already
1800 * encoded into correct form and in correct order. If application wants
1801 * to perform the commands by itself, it can do so and send the data
1802 * directly to the server using this function. If application is using
1803 * the silc_client_command_call, this function is usually not used.
1804 * Note that this overriders the Client Librarys commands and sends
1805 * the command packet directly to server.
1807 * Programmer should get familiar with the SILC protocol commands
1808 * specification when using this function, as the arguments needs to
1809 * be encoded as specified in the protocol.
1811 * The variable arguments are a pair of { type, data, data_length },
1812 * and the `argc' is the number of these pairs.
1816 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1817 * 1, nickname, strlen(nickname));
1820 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1821 SilcCommand command, SilcUInt16 ident,
1822 SilcUInt32 argc, ...);
1824 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1828 * void silc_client_command_pending(SilcClientConnection conn,
1829 * SilcCommand reply_cmd,
1831 * SilcCommandCb callback,
1836 * This function can be used to add pending command callback to be
1837 * called when an command reply is received to an earlier sent command.
1838 * The `reply_cmd' is the command that must be received in order for
1839 * the pending command callback indicated by `callback' to be called.
1840 * The `callback' will deliver the `context' and
1841 * SilcClientCommandReplyContext which includes the internals of the
1844 * The `ident' is a command identifier which was set for the earlier
1845 * sent command. The command reply will include the same identifier
1846 * and pending command callback will be called when the reply is
1847 * received with the same command identifier. It is possible to
1848 * add multiple pending command callbacks for same command and for
1851 * Application may use this function to add its own command reply
1852 * handlers if it wishes not to use the standard `command_reply'
1853 * client operation. However, note that the pending command callback
1854 * does not deliver parsed command reply, but application must parse
1857 * Note also that the application is notified about the received command
1858 * reply through the `command_reply' client operation before calling
1859 * the `callback` pending command callback. That is the normal
1860 * command reply handling, and is called regardless whether pending
1861 * command callbacks are used or not.
1863 * Commands that application calls with silc_client_command_call
1864 * will use a command identifier from conn->cmd_ident variable. After
1865 * calling the silc_client_command_call, the conn->cmd_ident includes
1866 * the command identifier that was used for the command sending.
1870 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1871 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1872 * my_ping_handler, my_ping_context);
1875 void silc_client_command_pending(SilcClientConnection conn,
1876 SilcCommand reply_cmd,
1878 SilcCommandCb callback,
1882 /* Private Message key management (client_prvmsg.c) */
1884 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1888 * bool silc_client_add_private_message_key(SilcClient client,
1889 * SilcClientConnection conn,
1890 * SilcClientEntry client_entry,
1891 * const char *cipher,
1893 * unsigned char *key,
1894 * SilcUInt32 key_len,
1895 * bool generate_key,
1900 * Adds private message key to the client library. The key will be used to
1901 * encrypt all private message between the client and the remote client
1902 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1903 * value `generate_key' is TRUE the library will generate random key.
1904 * The `key' maybe for example pre-shared-key, passphrase or similar.
1905 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1906 * that the requirements of the SILC protocol are met. The API, however,
1907 * allows to allocate any cipher and HMAC.
1909 * If `responder' is TRUE then the sending and receiving keys will be
1910 * set according the client being the receiver of the private key. If
1911 * FALSE the client is being the sender (or negotiator) of the private
1914 * It is not necessary to set key for normal private message usage. If the
1915 * key is not set then the private messages are encrypted using normal
1916 * session keys. Setting the private key, however, increases the security.
1918 * Returns FALSE if the key is already set for the `client_entry', TRUE
1922 bool silc_client_add_private_message_key(SilcClient client,
1923 SilcClientConnection conn,
1924 SilcClientEntry client_entry,
1932 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1937 * silc_client_add_private_message_key_ske(SilcClient client,
1938 * SilcClientConnection conn,
1939 * SilcClientEntry client_entry,
1940 * const char *cipher,
1942 * SilcSKEKeyMaterial *key);
1946 * Same as silc_client_add_private_message_key but takes the key material
1947 * from the SKE key material structure. This structure is received if
1948 * the application uses the silc_client_send_key_agreement to negotiate
1949 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1950 * negotiated also in the SKE protocol.
1953 bool silc_client_add_private_message_key_ske(SilcClient client,
1954 SilcClientConnection conn,
1955 SilcClientEntry client_entry,
1958 SilcSKEKeyMaterial *key,
1961 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1965 * bool silc_client_del_private_message_key(SilcClient client,
1966 * SilcClientConnection conn,
1967 * SilcClientEntry client_entry);
1971 * Removes the private message from the library. The key won't be used
1972 * after this to protect the private messages with the remote `client_entry'
1973 * client. Returns FALSE on error, TRUE otherwise.
1976 bool silc_client_del_private_message_key(SilcClient client,
1977 SilcClientConnection conn,
1978 SilcClientEntry client_entry);
1980 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1984 * SilcPrivateMessageKeys
1985 * silc_client_list_private_message_keys(SilcClient client,
1986 * SilcClientConnection conn,
1987 * SilcUInt32 *key_count);
1991 * Returns array of set private message keys associated to the connection
1992 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1993 * count to the `key_count' argument. The array must be freed by the caller
1994 * by calling the silc_client_free_private_message_keys function. Note:
1995 * the keys returned in the array is in raw format. It might not be desired
1996 * to show the keys as is. The application might choose not to show the keys
1997 * at all or to show the fingerprints of the keys.
2000 SilcPrivateMessageKeys
2001 silc_client_list_private_message_keys(SilcClient client,
2002 SilcClientConnection conn,
2003 SilcUInt32 *key_count);
2005 /****f* silcclient/SilcClientAPI/silc_client_send_private_message_key_request
2010 * silc_client_send_private_message_key_request(SilcClient client,
2011 * SilcClientConnection conn,
2012 * SilcClientEntry client_entry);
2016 * This function can be used to send an private message key indicator
2017 * request to the remote client indicated by 'client_entry'. This can
2018 * be used when setting a static or pre-shared private message key.
2019 * The sender of this packet is the initiator and must set the 'responder'
2020 * argument in silc_client_add_private_message_key function to FALSE.
2021 * The receiver of this indicator request must set it to TRUE, if the
2022 * receiver decides to set a private message key. By using this
2023 * function applications may automate initiator/responder setting in
2024 * private message key functions, without asking from user which one is
2025 * the initiator and which one is responder.
2029 * The sender of this packet must set the private message key for
2030 * 'client_entry' before calling this function. The 'responder'
2031 * argument MUST be set to FALSE when setting the key.
2035 silc_client_send_private_message_key_request(SilcClient client,
2036 SilcClientConnection conn,
2037 SilcClientEntry client_entry);
2039 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
2043 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2044 * SilcUInt32 key_count);
2048 * Frees the SilcPrivateMessageKeys array returned by the function
2049 * silc_client_list_private_message_keys.
2052 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
2053 SilcUInt32 key_count);
2056 /* Channel private key management (client_channel.c,
2057 SilcChannelPrivateKey is defined in idlist.h) */
2059 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
2063 * bool silc_client_add_channel_private_key(SilcClient client,
2064 * SilcClientConnection conn,
2065 * SilcChannelEntry channel,
2069 * unsigned char *key,
2070 * SilcUInt32 key_len,
2071 * SilcChannelPrivateKey *ret_key);
2075 * Adds private key for channel. When channel has private key then the
2076 * messages are encrypted using that key. All clients on the channel
2077 * must also know the key in order to decrypt the messages. However,
2078 * it is possible to have several private keys per one channel. In this
2079 * case only some of the clients on the channel may know the one key
2080 * and only some the other key. The `name' can be application given
2081 * name for the key. This returns the created key to the 'ret_key'
2082 * pointer if it is non-NULL;
2084 * If `cipher' and/or `hmac' is NULL then default values will be used
2085 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
2087 * The private key for channel is optional. If it is not set then the
2088 * channel messages are encrypted using the channel key generated by the
2089 * server. However, setting the private key (or keys) for the channel
2090 * significantly adds security. If more than one key is set the library
2091 * will automatically try all keys at the message decryption phase. Note:
2092 * setting many keys slows down the decryption phase as all keys has to
2093 * be tried in order to find the correct decryption key. However, setting
2094 * a few keys does not have big impact to the decryption performace.
2098 * NOTE: This is entirely local setting. The key set using this function
2099 * is not sent to the network at any phase.
2101 * NOTE: If the key material was originated by the SKE protocol (using
2102 * silc_client_send_key_agreement) then the `key' MUST be the
2103 * key->send_enc_key as this is dictated by the SILC protocol. However,
2104 * currently it is not expected that the SKE key material would be used
2105 * as channel private key. However, this API allows it.
2108 bool silc_client_add_channel_private_key(SilcClient client,
2109 SilcClientConnection conn,
2110 SilcChannelEntry channel,
2116 SilcChannelPrivateKey *ret_key);
2118 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2122 * bool silc_client_del_channel_private_keys(SilcClient client,
2123 * SilcClientConnection conn,
2124 * SilcChannelEntry channel);
2128 * Removes all private keys from the `channel'. The old channel key is used
2129 * after calling this to protect the channel messages. Returns FALSE on
2130 * on error, TRUE otherwise.
2133 bool silc_client_del_channel_private_keys(SilcClient client,
2134 SilcClientConnection conn,
2135 SilcChannelEntry channel);
2137 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2141 * bool silc_client_del_channel_private_key(SilcClient client,
2142 * SilcClientConnection conn,
2143 * SilcChannelEntry channel,
2144 * SilcChannelPrivateKey key);
2148 * Removes and frees private key `key' from the channel `channel'.
2149 * The `key' is retrieved by calling the function
2150 * silc_client_list_channel_private_keys. The key is not used after
2151 * this. If the key was last private key then the old channel key is
2152 * used hereafter to protect the channel messages. This returns FALSE
2153 * on error, TRUE otherwise.
2156 bool silc_client_del_channel_private_key(SilcClient client,
2157 SilcClientConnection conn,
2158 SilcChannelEntry channel,
2159 SilcChannelPrivateKey key);
2161 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2165 * SilcChannelPrivateKey *
2166 * silc_client_list_channel_private_keys(SilcClient client,
2167 * SilcClientConnection conn,
2168 * SilcChannelEntry channel,
2169 * SilcUInt32 *key_count);
2173 * Returns array (pointers) of private keys associated to the `channel'.
2174 * The caller must free the array by calling the function
2175 * silc_client_free_channel_private_keys. The pointers in the array may be
2176 * used to delete the specific key by giving the pointer as argument to the
2177 * function silc_client_del_channel_private_key.
2180 SilcChannelPrivateKey *
2181 silc_client_list_channel_private_keys(SilcClient client,
2182 SilcClientConnection conn,
2183 SilcChannelEntry channel,
2184 SilcUInt32 *key_count);
2186 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2190 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2191 * SilcUInt32 key_count);
2195 * Frees the SilcChannelPrivateKey array.
2198 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2199 SilcUInt32 key_count);
2201 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2205 * void silc_client_current_channel_private_key(SilcClient client,
2206 * SilcClientConnection conn,
2207 * SilcChannelEntry channel,
2208 * SilcChannelPrivateKey key);
2212 * Sets the `key' to be used as current channel private key on the
2213 * `channel'. Packet sent after calling this function will be secured
2217 void silc_client_current_channel_private_key(SilcClient client,
2218 SilcClientConnection conn,
2219 SilcChannelEntry channel,
2220 SilcChannelPrivateKey key);
2223 /* Key Agreement routines (client_keyagr.c) */
2225 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2229 * void silc_client_send_key_agreement(SilcClient client,
2230 * SilcClientConnection conn,
2231 * SilcClientEntry client_entry,
2234 * SilcUInt32 timeout_secs,
2235 * SilcKeyAgreementCallback completion,
2240 * Sends key agreement request to the remote client indicated by the
2241 * `client_entry'. If the caller provides the `hostname' and the `port'
2242 * arguments then the library will bind the client to that hostname and
2243 * that port for the key agreement protocol. It also sends the `hostname'
2244 * and the `port' in the key agreement packet to the remote client. This
2245 * would indicate that the remote client may initiate the key agreement
2246 * protocol to the `hostname' on the `port'. If port is zero then the
2247 * bound port is undefined (the operating system defines it).
2249 * If the `hostname' and `port' is not provided then empty key agreement
2250 * packet is sent to the remote client. The remote client may reply with
2251 * the same packet including its hostname and port. If the library receives
2252 * the reply from the remote client the `key_agreement' client operation
2253 * callback will be called to verify whether the user wants to perform the
2254 * key agreement or not.
2258 * NOTE: If the application provided the `hostname' and the `port' and the
2259 * remote side initiates the key agreement protocol it is not verified
2260 * from the user anymore whether the protocol should be executed or not.
2261 * By setting the `hostname' and `port' the user gives permission to
2262 * perform the protocol (we are responder in this case).
2264 * NOTE: If the remote side decides not to initiate the key agreement
2265 * or decides not to reply with the key agreement packet then we cannot
2266 * perform the key agreement at all. If the key agreement protocol is
2267 * performed the `completion' callback with the `context' will be called.
2268 * If remote side decides to ignore the request the `completion' will be
2269 * called after the specified timeout, `timeout_secs'.
2271 * NOTE: If the `hostname' and the `port' was not provided the `completion'
2272 * will not be called at all since this does nothing more than sending
2273 * a packet to the remote host.
2275 * NOTE: There can be only one active key agreement for one client entry.
2276 * Before setting new one, the old one must be finished (it is finished
2277 * after calling the completion callback) or the function
2278 * silc_client_abort_key_agreement must be called.
2281 void silc_client_send_key_agreement(SilcClient client,
2282 SilcClientConnection conn,
2283 SilcClientEntry client_entry,
2284 const char *hostname,
2285 const char *bindhost,
2287 SilcUInt32 timeout_secs,
2288 SilcKeyAgreementCallback completion,
2291 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2296 * silc_client_perform_key_agreement(SilcClient client,
2297 * SilcClientConnection conn,
2298 * SilcClientEntry client_entry,
2301 * SilcKeyAgreementCallback completion,
2306 * Performs the actual key agreement protocol. Application may use this
2307 * to initiate the key agreement protocol. This can be called for example
2308 * after the application has received the `key_agreement' client operation,
2309 * and did not return TRUE from it.
2311 * The `hostname' is the remote hostname (or IP address) and the `port'
2312 * is the remote port. The `completion' callback with the `context' will
2313 * be called after the key agreement protocol.
2317 * NOTE: If the application returns TRUE in the `key_agreement' client
2318 * operation the library will automatically start the key agreement. In this
2319 * case the application must not call this function. However, application
2320 * may choose to just ignore the `key_agreement' client operation (and
2321 * merely just print information about it on the screen) and call this
2322 * function when the user whishes to do so (by, for example, giving some
2323 * specific command). Thus, the API provides both, automatic and manual
2324 * initiation of the key agreement. Calling this function is the manual
2325 * initiation and returning TRUE in the `key_agreement' client operation
2326 * is the automatic initiation.
2329 void silc_client_perform_key_agreement(SilcClient client,
2330 SilcClientConnection conn,
2331 SilcClientEntry client_entry,
2334 SilcKeyAgreementCallback completion,
2337 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2342 * silc_client_perform_key_agreement_fd(SilcClient client,
2343 * SilcClientConnection conn,
2344 * SilcClientEntry client_entry,
2347 * SilcKeyAgreementCallback completion,
2352 * Same as above but application has created already the connection to
2353 * the remote host. The `sock' is the socket to the remote connection.
2354 * Application can use this function if it does not want the client library
2355 * to create the connection.
2358 void silc_client_perform_key_agreement_fd(SilcClient client,
2359 SilcClientConnection conn,
2360 SilcClientEntry client_entry,
2363 SilcKeyAgreementCallback completion,
2366 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2370 * void silc_client_abort_key_agreement(SilcClient client,
2371 * SilcClientConnection conn,
2372 * SilcClientEntry client_entry);
2376 * This function can be called to unbind the hostname and the port for
2377 * the key agreement protocol. However, this function has effect only
2378 * before the key agreement protocol has been performed. After it has
2379 * been performed the library will automatically unbind the port. The
2380 * `client_entry' is the client to which we sent the key agreement
2381 * request. The key agreement completion callback will be called
2382 * with SILC_KEY_AGREEMENT_ABORTED status.
2385 void silc_client_abort_key_agreement(SilcClient client,
2386 SilcClientConnection conn,
2387 SilcClientEntry client_entry);
2390 /* Misc functions */
2392 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2396 * void silc_client_set_away_message(SilcClient client,
2397 * SilcClientConnection conn,
2402 * Sets away `message'. The away message may be set when the client's
2403 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2404 * to anyone who sends private message. The `message' will be sent
2405 * automatically back to the the client who send private message. If
2406 * away message is already set this replaces the old message with the
2407 * new one. If `message' is NULL the old away message is removed.
2408 * The sender may freely free the memory of the `message'.
2411 void silc_client_set_away_message(SilcClient client,
2412 SilcClientConnection conn,
2415 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2419 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2420 * SilcClientConnection conn,
2421 * SilcAuthMethod auth_meth,
2426 * Connection authentication method request callback. This is called
2427 * by the client library after it has received the authentication method
2428 * that the application requested by calling the function
2429 * silc_client_request_authentication_method.
2432 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2433 SilcClientConnection conn,
2434 SilcAuthMethod auth_meth,
2437 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2442 * silc_client_request_authentication_method(SilcClient client,
2443 * SilcClientConnection conn,
2444 * SilcConnectionAuthRequest
2450 * This function can be used to request the current authentication method
2451 * from the server. This may be called when connecting to the server
2452 * and the client library requests the authentication data from the
2453 * application. If the application does not know the current authentication
2454 * method it can request it from the server using this function.
2455 * The `callback' with `context' will be called after the server has
2456 * replied back with the current authentication method.
2460 silc_client_request_authentication_method(SilcClient client,
2461 SilcClientConnection conn,
2462 SilcConnectionAuthRequest callback,
2465 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2469 * typedef enum { ... } SilcClientMonitorStatus;
2473 * File transmission session status types. These will indicate
2474 * the status of the file transmission session.
2479 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2480 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2481 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2482 SILC_CLIENT_FILE_MONITOR_GET,
2483 SILC_CLIENT_FILE_MONITOR_PUT,
2484 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2485 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2486 } SilcClientMonitorStatus;
2489 /****d* silcclient/SilcClientAPI/SilcClientFileError
2493 * typedef enum { ... } SilcClientFileError;
2497 * File transmission error types. These types are returned by
2498 * some of the file transmission functions, and by the monitor
2499 * callback to indicate error.
2504 SILC_CLIENT_FILE_OK,
2505 SILC_CLIENT_FILE_ERROR,
2506 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2507 SILC_CLIENT_FILE_ALREADY_STARTED,
2508 SILC_CLIENT_FILE_NO_SUCH_FILE,
2509 SILC_CLIENT_FILE_PERMISSION_DENIED,
2510 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2511 } SilcClientFileError;
2514 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2518 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2519 * SilcClientConnection conn,
2520 * SilcClientMonitorStatus status,
2521 * SilcClientFileError error,
2522 * SilcUInt64 offset,
2523 * SilcUInt64 filesize,
2524 * SilcClientEntry client_entry,
2525 * SilcUInt32 session_id,
2526 * const char *filepath,
2531 * Monitor callback that is called during the file transmission to
2532 * monitor the transmission process. The `status' indicates the current
2533 * monitoring process. The `error' will indicate the error type
2534 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2535 * currently transmitted amount of total `filesize'. The `client_entry'
2536 * indicates the remote client, and the transmission session ID is the
2537 * `session_id'. The filename being transmitted is indicated by the
2541 typedef void (*SilcClientFileMonitor)(SilcClient client,
2542 SilcClientConnection conn,
2543 SilcClientMonitorStatus status,
2544 SilcClientFileError error,
2546 SilcUInt64 filesize,
2547 SilcClientEntry client_entry,
2548 SilcUInt32 session_id,
2549 const char *filepath,
2552 /****f* silcclient/SilcClientAPI/SilcClientFileName
2556 * typedef void (*SilcClientFileName)(const char *filepath,
2561 * Completion callback for the SilcClientFileAskName callback function.
2562 * Application calls this to deliver the filepath and filename where
2563 * the downloaded file is to be saved.
2566 typedef void (*SilcClientFileName)(const char *filepath,
2569 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2573 * typedef void (*SilcClientFileAskName)(SilcClient client,
2574 * SilcClientConnection conn,
2575 * SilcUInt32 session_id,
2576 * const char *remote_filename,
2577 * SilcClientFileName completion,
2578 * void *completion_context,
2583 * File name asking callback, that is called if it is given to the
2584 * silc_client_file_receive and the path given to that as argument was
2585 * NULL. The library calls this to ask the filename and filepath to
2586 * where the file is to be saved. The 'remote_filename' is the file
2587 * that is being downloaded. Application must call the 'completion'
2588 * with 'completion_context' to continue with the file downloading.
2589 * It is not mandatory to provide this to the silc_client_file_receive.
2592 typedef void (*SilcClientFileAskName)(SilcClient client,
2593 SilcClientConnection conn,
2594 SilcUInt32 session_id,
2595 const char *remote_filename,
2596 SilcClientFileName completion,
2597 void *completion_context,
2600 /****f* silcclient/SilcClientAPI/silc_client_file_send
2604 * SilcClientFileError
2605 * silc_client_file_send(SilcClient client,
2606 * SilcClientConnection conn,
2607 * SilcClientFileMonitor monitor,
2608 * void *monitor_context,
2609 * const char *local_ip,
2610 * SilcUInt32 local_port,
2612 * SilcClientEntry client_entry,
2613 * const char *filepath);
2614 * SilcUInt32 *session_id);
2618 * Sends a file indicated by the `filepath' to the remote client
2619 * indicated by the `client_entry'. This will negotiate a secret key
2620 * with the remote client before actually starting the transmission of
2621 * the file. The `monitor' callback will be called to monitor the
2622 * transmission of the file.
2624 * This returns a file session ID for the file transmission to the
2625 * `session_id' pointer. It can be used to close the session (and
2626 * abort the file transmission) by calling the silc_client_file_close
2627 * function. The session ID is also returned in the `monitor' callback.
2629 * If the `local_ip' is provided then this will try to bind the
2630 * listener for key exchange protocol to that IP. If `local_port' is
2631 * non-zero that port is used. If `local_ip' is NULL then this will
2632 * automatically attempt to bind it to local IP address of the machine.
2633 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2634 * ignored and it is expected that the receiver will provide the
2635 * point of contact. This is usefull if the sender is behind NAT.
2637 * If error will occur during the file transfer process the error
2638 * status will be returned in the monitor callback. In this case
2639 * the application must call silc_client_file_close to close the
2644 silc_client_file_send(SilcClient client,
2645 SilcClientConnection conn,
2646 SilcClientFileMonitor monitor,
2647 void *monitor_context,
2648 const char *local_ip,
2649 SilcUInt32 local_port,
2651 SilcClientEntry client_entry,
2652 const char *filepath,
2653 SilcUInt32 *session_id);
2655 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2659 * SilcClientFileError
2660 * silc_client_file_receive(SilcClient client,
2661 * SilcClientConnection conn,
2662 * SilcClientFileMonitor monitor,
2663 * void *monitor_context,
2665 * SilcUInt32 session_id,
2666 * SilcClientFileAskName ask_name,
2667 * void *ask_name_context);
2671 * Receives a file from a client indicated by the `client_entry'. The
2672 * `session_id' indicates the file transmission session and it has been
2673 * received in the `ftp' client operation function. This will actually
2674 * perform the key agreement protocol with the remote client before
2675 * actually starting the file transmission. The `monitor' callback
2676 * will be called to monitor the transmission. If `path' is non-NULL
2677 * the file will be saved into that directory. If NULL the file is
2678 * saved in the current working directory, unless the 'ask_name'
2679 * callback is non-NULL. In this case the callback is called to ask
2680 * the path and filename from application.
2682 * If error will occur during the file transfer process the error
2683 * status will be returned in the monitor callback. In this case
2684 * the application must call silc_client_file_close to close the
2689 silc_client_file_receive(SilcClient client,
2690 SilcClientConnection conn,
2691 SilcClientFileMonitor monitor,
2692 void *monitor_context,
2694 SilcUInt32 session_id,
2695 SilcClientFileAskName ask_name,
2696 void *ask_name_context);
2698 /****f* silcclient/SilcClientAPI/silc_client_file_close
2702 * SilcClientFileError silc_client_file_close(SilcClient client,
2703 * SilcClientConnection conn,
2704 * SilcUInt32 session_id);
2708 * Closes file transmission session indicated by the `session_id'.
2709 * If file transmission is being conducted it will be aborted
2710 * automatically. This function is also used to close the session
2711 * after successful file transmission. This function can be used
2712 * also to reject incoming file transmission request. If the
2713 * session was already started and the monitor callback was set
2714 * the monitor callback will be called with the monitor status
2715 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2718 SilcClientFileError silc_client_file_close(SilcClient client,
2719 SilcClientConnection conn,
2720 SilcUInt32 session_id);
2722 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2726 * SilcAttributePayload
2727 * silc_client_attribute_add(SilcClient client,
2728 * SilcClientConnection conn,
2729 * SilcAttribute attribute,
2731 * SilcUInt32 object_size);
2735 * Add new Requsted Attribute for WHOIS command to the client library.
2736 * The `attribute' object indicated by `object' is added and allocated
2737 * SilcAttributePayload is returned. The `object' must be of correct
2738 * type and of correct size. See the SilcAttribute for object types
2739 * for different attributes. You may also get all added attributes
2740 * from the client with silc_client_attributes_get function.
2742 * Requested Attributes are different personal information about the
2743 * user, status information and other information which other users
2744 * may query with WHOIS command. Application may set these so that
2745 * if someone sends WHOIS query these attributes will be replied back
2746 * to the sender. The library always puts the public key to the
2747 * Requested Attributes, but if application wishes to add additional
2748 * public keys (or certificates) it can be done with this interface.
2749 * Library also always computes digital signature of the attributes
2750 * automatically, so application does not need to do that.
2753 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2754 SilcClientConnection conn,
2755 SilcAttribute attribute,
2757 SilcUInt32 object_size);
2759 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2763 * bool silc_client_attribute_del(SilcClient client,
2764 * SilcClientConnection conn,
2765 * SilcAttribute attribute,
2766 * SilcAttributePayload attr);
2770 * Delete a Requested Attribute from the client. If the `attribute'
2771 * is non-zero then all attributes of that type are deleted and the
2772 * `attr' is ignored. If `attr' is non-NULL then that specific
2773 * attribute is deleted and `attribute' is ignored.
2775 * You may get all added attributes with the function
2776 * silc_client_attributes_get and to get the SilcAttributePayload.
2777 * This function Returns TRUE if the attribute was found and deleted.
2780 bool silc_client_attribute_del(SilcClient client,
2781 SilcClientConnection conn,
2782 SilcAttribute attribute,
2783 SilcAttributePayload attr);
2785 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2789 * const SilcHashTable
2790 * silc_client_attributes_get(SilcClient client,
2791 * SilcClientConnection conn);
2795 * Returns pointer to the SilcHashTable which includes all the added
2796 * Requested Attributes. The caller must not free the hash table.
2797 * The caller may use SilcHashTableList and silc_hash_table_list to
2798 * traverse the table. Each entry in the hash table is one added
2799 * SilcAttributePayload. It is possible to delete a attribute
2800 * payload while traversing the table.
2803 const SilcHashTable silc_client_attributes_get(SilcClient client,
2804 SilcClientConnection conn);
2806 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2810 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2814 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2815 * then all attributes are requested. Alternatively, `attribute' and
2816 * all variable arguments can each be requested attribute. In this case
2817 * the last must be set to zero (0) to complete the variable list of
2818 * requested attributes. See SilcAttribute for all attributes.
2819 * You can give the returned buffer as argument to for example
2820 * silc_client_get_client_by_id_resolve function.
2824 * Request all attributes
2825 * buffer = silc_client_attributes_request(0);
2827 * Request only the following attributes
2828 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2829 * SILC_ATTRIBUTE_SERVICE,
2830 * SILC_ATTRIBUTE_MOOD, 0);
2833 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2835 /* Low level packet sending functions */
2837 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2841 * bool silc_client_send_packet(SilcClient client,
2842 * SilcClientConnection conn,
2843 * SilcPacketType type,
2844 * const unsigned char *data,
2845 * SilcUInt32 data_len);
2849 * This routine can be used by application to send packets directly
2850 * to a connection indicated by `conn'. Usually application does not
2851 * need this routine since the Client Library handles the packet
2852 * sending. The `type' indicates the packet type. If `data' is
2853 * NULL then empty packet is sent. This returns FALSE if packet cannot
2857 bool silc_client_send_packet(SilcClient client,
2858 SilcClientConnection conn,
2859 SilcPacketType type,
2860 const unsigned char *data,
2861 SilcUInt32 data_len);
2863 #include "command.h"
2864 #include "command_reply.h"
2866 #include "protocol.h"
2872 #endif /* SILCCLIENT_H */