5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2004 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
59 /* General definitions */
61 /****s* silcclient/SilcClientAPI/SilcClient
65 * typedef struct SilcClientStruct { ... } *SilcClient
69 * This is the actual SILC Client structure which represents one
70 * SILC Client. It is allocated with the silc_client_alloc function
71 * and given as argument to all SILC Client Library functions. It
72 * is initialized with silc_client_init function, and freed with
73 * silc_client_free function.
77 struct SilcClientStruct {
79 * The following fields are set by application
81 char *nickname; /* Nickname, MAY be set by application */
82 char *username; /* Username, MUST be set by application */
83 char *hostname; /* hostname, MUST be set by application */
84 char *realname; /* Real name, MUST be set be application */
86 SilcPublicKey public_key; /* Public key of user, set by application */
87 SilcPrivateKey private_key; /* Private key of user, set by application */
88 SilcPKCS pkcs; /* PKCS allocated by application */
91 * The following fields are set by the library
94 /* Scheduler, set by library. Application may use this pointer. */
95 SilcSchedule schedule;
97 /* Random Number Generator. Application should use this as its primary
98 random number generator. */
101 /* Application specific user data pointer. Client library does not
102 touch this. This the context sent as argument to silc_client_alloc.
103 Application can use it freely. */
106 /* Generic hash context for application usage */
110 /* Internal data for client library. Application cannot access this
112 SilcClientInternal internal;
116 /****s* silcclient/SilcClientAPI/SilcClientConnection
120 * typedef struct SilcClientConnectionStruct { ... }
121 * *SilcClientConnection
125 * This structure represents a connection. When connection is created
126 * to server this is context is returned to the application in the
127 * "connected" client operation. It includes all the important
128 * data for the session, such as nickname, local and remote IDs, and
133 struct SilcClientConnectionStruct {
137 char *nickname; /* Current nickname */
138 SilcClientEntry local_entry; /* Own Client Entry */
139 SilcClientID *local_id; /* Current Client ID */
140 unsigned char *local_id_data; /* Current Client ID decoded */
141 SilcUInt32 local_id_data_len;
146 char *remote_host; /* Remote host name */
147 int remote_port; /* Remote port */
148 SilcServerID *remote_id; /* Remote Server ID */
149 unsigned char *remote_id_data; /* Remote Server ID decoded */
150 SilcUInt32 remote_id_data_len;
156 /* Current command identifier for a command that was sent last.
157 Application may get the value from this variable to find out the
158 command identifier for last command. */
159 SilcUInt16 cmd_ident;
161 /* User data context. Library does not touch this. Application may
162 freely set and use this pointer for its needs. */
165 /* Pointer back to the SilcClient. Application may use this. */
168 /* Current channel. Application may use and set this pointer if needed. */
169 SilcChannelEntry current_channel;
171 /* Socket connection object for this connection. Application may
172 use this if needed. The sock->user_data is back pointer to this
174 SilcSocketConnection sock;
176 /* Internal data for client library. Application cannot access this
178 SilcClientConnectionInternal internal;
182 /****s* silcclient/SilcClientAPI/SilcClientEntry
186 * typedef struct SilcClientEntryStruct { ... } *SilcClientEntry
190 * This structure represents a client or a user in the SILC network.
191 * The local user has this structure also and it can be accessed from
192 * SilcClientConnection structure. All other users in the SILC network
193 * that are accessed using the Client Library routines will have their
194 * own SilcClientEntry structure. For example, when finding users by
195 * their nickname the Client Library returns this structure back to
200 struct SilcClientEntryStruct {
201 /* General information */
202 char *nickname; /* nickname */
203 char *username; /* username */
204 char *hostname; /* hostname */
205 char *server; /* SILC server name */
206 char *realname; /* Realname (userinfo) */
208 /* Mode, ID and other information */
209 SilcUInt32 mode; /* User mode in SILC, see SilcUserMode */
210 SilcClientID *id; /* The Client ID */
211 SilcDList attrs; /* Requested Attributes (maybe NULL) */
212 unsigned char *fingerprint; /* Fingerprint of client's public key */
213 SilcUInt32 fingerprint_len; /* Length of the fingerprint */
215 /* Private message keys */
216 SilcCipher send_key; /* Private message key for sending */
217 SilcCipher receive_key; /* Private message key for receiving */
218 SilcHmac hmac_send; /* Private mesage key HMAC for sending */
219 SilcHmac hmac_receive; /* Private mesage key HMAC for receiving */
220 unsigned char *key; /* Set only if application provided the
221 key material. NULL if the library
222 generated the key. */
223 SilcUInt32 key_len; /* Key length */
224 SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
226 /* SilcClientEntry status information */
227 SilcEntryStatus status; /* Status mask */
228 SilcHashTable channels; /* All channels client has joined */
229 SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
230 bool generated; /* TRUE if library generated `key' */
231 bool valid; /* FALSE if this entry is not valid */
233 /* Application specific data. Application may set here whatever it wants. */
238 /****s* silcclient/SilcClientAPI/SilcChannelEntry
242 * typedef struct SilcChannelEntryStruct { ... } *SilcChannelEntry
246 * This structure represents a channel in the SILC network. All
247 * channels that the client are aware of or have joined in will be
248 * represented as SilcChannelEntry. The structure includes information
253 struct SilcChannelEntryStruct {
254 /* General information */
255 char *channel_name; /* Channel name */
256 SilcChannelID *id; /* Channel ID */
257 SilcUInt32 mode; /* Channel mode, ChannelModes. */
259 /* All clients that has joined this channel. The key to the table is the
260 SilcClientEntry and the context is SilcChannelUser context. */
261 SilcHashTable user_list;
264 SilcCipher channel_key; /* The channel key */
265 unsigned char *key; /* Raw key data */
266 SilcUInt32 key_len; /* Raw key data length */
267 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
268 SilcHmac hmac; /* Current HMAC */
270 /* Channel private keys */
271 SilcDList private_keys; /* List of private keys or NULL */
272 SilcChannelPrivateKey curr_key; /* Current private key */
274 /* SilcChannelEntry status information */
275 SilcDList old_channel_keys;
277 SilcUInt16 resolve_cmd_ident; /* Command identifier when
278 resolving this entry */
280 /* Application specific data. Application may set here whatever it wants. */
285 /****s* silcclient/SilcClientAPI/SilcChannelUser
289 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
293 * This structure represents a client that has joined to a channel.
294 * It shows the client and the channel and the client's mode (channel
295 * user mode) on the channel.
299 struct SilcChannelUserStruct {
300 SilcClientEntry client; /* Client joined on channel */
301 SilcUInt32 mode; /* mode, ChannelUserModes */
302 SilcChannelEntry channel; /* The channel user has joined */
304 /* Application specific data. Application may set here whatever it wants. */
309 /****s* silcclient/SilcClientAPI/SilcServerEntry
313 * typedef struct SilcServerEntryStruct { ... } *SilcServerEntry
317 * This structure represents a server in the SILC network. All servers
318 * that the client is aware of and have for example resolved with
319 * SILC_COMMAND_INFO command have their on SilcServerEntry structure.
323 struct SilcServerEntryStruct {
324 /* General information */
325 char *server_name; /* Server name */
326 char *server_info; /* Server info */
327 SilcServerID *server_id; /* Server ID */
328 SilcUInt16 resolve_cmd_ident; /* Command identifier when
329 resolving this entry */
331 /* Application specific data. Application may set here whatever it wants. */
336 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
340 * typedef enum { ... } SilcKeyAgreementStatus;
344 * Key agreement status types indicating the status of the key
345 * agreement protocol. These types are returned to the application
346 * in the SilcKeyAgreementCallback callback function.
351 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
352 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
353 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
354 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
355 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
356 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
357 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
358 } SilcKeyAgreementStatus;
361 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
365 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
366 * SilcClientConnection conn,
367 * SilcClientEntry client_entry,
368 * SilcKeyAgreementStatus status,
369 * SilcSKEKeyMaterial *key,
374 * Key agreement callback that is called after the key agreement protocol
375 * has been performed. This is called also if error occurred during the
376 * key agreement protocol. The `key' is the allocated key material and
377 * the caller is responsible of freeing it. The `key' is NULL if error
378 * has occurred. The application can freely use the `key' to whatever
379 * purpose it needs. See lib/silcske/silcske.h for the definition of
380 * the SilcSKEKeyMaterial structure.
383 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
384 SilcClientConnection conn,
385 SilcClientEntry client_entry,
386 SilcKeyAgreementStatus status,
387 SilcSKEKeyMaterial *key,
390 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
394 * typedef struct { ... } SilcPrivateMessageKeys;
398 * Structure to hold the list of private message keys. The array of this
399 * structure is returned by the silc_client_list_private_message_keys
405 SilcClientEntry client_entry; /* The remote client entry */
406 char *cipher; /* The cipher name */
407 unsigned char *key; /* The original key, If the appliation
408 provided it. This is NULL if the
409 library generated the key or if
410 the SKE key material was used. */
411 SilcUInt32 key_len; /* The key length */
412 } *SilcPrivateMessageKeys;
415 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
419 * typedef struct SilcChannelPrivateKeyStruct { ... }
420 * *SilcChannelPrivateKey;
424 * Structure to hold one channel private key. The array of this structure
425 * is returned by silc_client_list_channel_private_keys function.
429 struct SilcChannelPrivateKeyStruct {
430 char *name; /* Application given name */
431 SilcCipher cipher; /* The cipher and key */
432 SilcHmac hmac; /* The HMAC and hmac key */
433 unsigned char *key; /* The key data */
434 SilcUInt32 key_len; /* The key length */
438 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
442 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
443 * SilcUInt32 passphrase_len,
448 * Ask passphrase callback. This is called by the application when the
449 * library calls `ask_passphrase' client operation. The callback delivers
450 * the passphrase to the library. The passphrases in SILC protocol
451 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
452 * encoded, and if it is not then library will attempt to encode it.
455 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
456 SilcUInt32 passphrase_len,
459 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
463 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
467 * Public key (or certificate) verification callback. This is called
468 * by the application to indicate that the public key verification was
469 * either success or failure.
472 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
474 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
478 * typedef void (*SilcGetAuthMeth)(bool success,
479 * SilcProtocolAuthMeth auth_meth,
480 * const unsigned char *auth_data,
481 * SilcUInt32 auth_data_len, void *context);
485 * Authentication method resolving callback. This is called by the
486 * application to return the resolved authentication method. The client
487 * library has called the get_auth_method client operation and given
488 * this function pointer as argument. The `success' will indicate whether
489 * the authentication method could be resolved. The `auth_meth' is the
490 * resolved authentication method. The `auth_data' and the `auth_data_len'
491 * are the resolved authentication data. The `context' is the libary's
492 * context sent to the get_auth_method client operation.
495 typedef void (*SilcGetAuthMeth)(bool success,
496 SilcProtocolAuthMeth auth_meth,
497 const unsigned char *auth_data,
498 SilcUInt32 auth_data_len, void *context);
500 /****d* silcclient/SilcClientAPI/SilcClientMessageType
504 * typedef enum { ... } SilcClientMessageType;
508 * Different message types for `say' client operation. The application
509 * may filter the message sent by the library according this type.
514 SILC_CLIENT_MESSAGE_INFO, /* Informational */
515 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
516 SILC_CLIENT_MESSAGE_ERROR, /* Error */
517 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
518 } SilcClientMessageType;
521 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
525 * typedef enum { ... } SilcClientConnectionStatus
529 * This type is returned to the `connect' client operation to indicate
530 * the status of the created connection. It can indicate if it was
531 * successful or whether an error occurred.
536 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
537 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
538 resumed old detached session */
539 SILC_CLIENT_CONN_ERROR, /* Unknown error occurred during
541 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
542 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
543 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
544 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
545 } SilcClientConnectionStatus;
548 /****s* silcclient/SilcClientAPI/SilcClientOperations
552 * typedef struct { ... } SilcClientOperations;
556 * SILC Client Operations. These must be implemented by the application.
557 * The Client library may call any of these routines at any time. The
558 * routines are used to deliver certain information to the application
559 * or from the application to the client library.
564 /* Message sent to the application by library. `conn' associates the
565 message to a specific connection. `conn', however, may be NULL.
566 The `type' indicates the type of the message sent by the library.
567 The application can for example filter the message according the
568 type. The variable argument list is arguments to the formatted
569 message that `msg' may be. */
570 void (*say)(SilcClient client, SilcClientConnection conn,
571 SilcClientMessageType type, char *msg, ...);
573 /* Message for a channel. The `sender' is the sender of the message
574 The `channel' is the channel. The `message' is the message. Note
575 that `message' maybe NULL. The `flags' indicates message flags
576 and it is used to determine how the message can be interpreted
577 (like it may tell the message is multimedia message). */
578 void (*channel_message)(SilcClient client, SilcClientConnection conn,
579 SilcClientEntry sender, SilcChannelEntry channel,
580 SilcMessagePayload payload, SilcMessageFlags flags,
581 const unsigned char *message,
582 SilcUInt32 message_len);
584 /* Private message to the client. The `sender' is the sender of the
585 message. The message is `message'and maybe NULL. The `flags'
586 indicates message flags and it is used to determine how the message
587 can be interpreted (like it may tell the message is multimedia
589 void (*private_message)(SilcClient client, SilcClientConnection conn,
590 SilcClientEntry sender, SilcMessagePayload payload,
591 SilcMessageFlags flags,
592 const unsigned char *message,
593 SilcUInt32 message_len);
595 /* Notify message to the client. The notify arguments are sent in the
596 same order as servers sends them. The arguments are same as received
597 from the server except for ID's. If ID is received application receives
598 the corresponding entry to the ID. For example, if Client ID is received
599 application receives SilcClientEntry. Also, if the notify type is
600 for channel the channel entry is sent to application (even if server
601 does not send it because client library gets the channel entry from
602 the Channel ID in the packet's header). */
603 void (*notify)(SilcClient client, SilcClientConnection conn,
604 SilcNotifyType type, ...);
606 /* Command handler. This function is called always in the command function.
607 If error occurs it will be called as well. `conn' is the associated
608 client connection. `cmd_context' is the command context that was
609 originally sent to the command. `success' is FALSE if error occurred
610 during command. `command' is the command being processed. It must be
611 noted that this is not reply from server. This is merely called just
612 after application has called the command. Just to tell application
613 that the command really was processed. */
614 void (*command)(SilcClient client, SilcClientConnection conn,
615 SilcClientCommandContext cmd_context, bool success,
616 SilcCommand command, SilcStatus status);
618 /* Command reply handler. This function is called always in the command reply
619 function. If error occurs it will be called as well. Normal scenario
620 is that it will be called after the received command data has been parsed
621 and processed. The function is used to pass the received command data to
624 `conn' is the associated client connection. `cmd_payload' is the command
625 payload data received from server and it can be ignored. It is provided
626 if the application would like to re-parse the received command data,
627 however, it must be noted that the data is parsed already by the library
628 thus the payload can be ignored. `success' is FALSE if error occurred.
629 In this case arguments are not sent to the application. The `status' is
630 the command reply status server returned. The `command' is the command
631 reply being processed. The function has variable argument list and each
632 command defines the number and type of arguments it passes to the
633 application (on error they are not sent).
635 The arguments are sent in the same order as servers sends them. The
636 arguments are same as received from the server except for ID's. If
637 ID is received application receives the corresponding entry to the
638 ID. For example, if Client ID is receives application receives
640 void (*command_reply)(SilcClient client, SilcClientConnection conn,
641 SilcCommandPayload cmd_payload, bool success,
642 SilcCommand command, SilcStatus status, ...);
644 /* Called to indicate that connection was either successfully established
645 or connecting failed. This is also the first time application receives
646 the SilcClientConnection object which it should save somewhere.
647 The `status' indicated whether the connection were successful. If it
648 is error value the application must always call the function
649 silc_client_close_connection. */
650 void (*connected)(SilcClient client, SilcClientConnection conn,
651 SilcClientConnectionStatus status);
653 /* Called to indicate that connection was disconnected to the server.
654 The `status' may tell the reason of the disconnection, and if the
655 `message' is non-NULL it may include the disconnection message
656 received from server. */
657 void (*disconnected)(SilcClient client, SilcClientConnection conn,
658 SilcStatus status, const char *message);
660 /* Find authentication method and authentication data by hostname and
661 port. The hostname may be IP address as well. When the authentication
662 method has been resolved the `completion' callback with the found
663 authentication method and authentication data is called. The `conn'
665 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
666 char *hostname, SilcUInt16 port,
667 SilcGetAuthMeth completion, void *context);
669 /* Verifies received public key. The `conn_type' indicates which entity
670 (server, client etc.) has sent the public key. If user decides to trust
671 the application may save the key as trusted public key for later
672 use. The `completion' must be called after the public key has been
674 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
675 SilcSocketType conn_type, unsigned char *pk,
676 SilcUInt32 pk_len, SilcSKEPKType pk_type,
677 SilcVerifyPublicKey completion, void *context);
679 /* Ask (interact, that is) a passphrase from user. The passphrase is
680 returned to the library by calling the `completion' callback with
681 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
682 if not then the library will attempt to encode. */
683 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
684 SilcAskPassphrase completion, void *context);
686 /* Notifies application that failure packet was received. This is called
687 if there is some protocol active in the client. The `protocol' is the
688 protocol context. The `failure' is opaque pointer to the failure
689 indication. Note, that the `failure' is protocol dependant and
690 application must explicitly cast it to correct type. Usually `failure'
691 is 32 bit failure type (see protocol specs for all protocol failure
693 void (*failure)(SilcClient client, SilcClientConnection conn,
694 SilcProtocol protocol, void *failure);
696 /* Asks whether the user would like to perform the key agreement protocol.
697 This is called after we have received an key agreement packet or an
698 reply to our key agreement packet. This returns TRUE if the user wants
699 the library to perform the key agreement protocol and FALSE if it is not
700 desired (application may start it later by calling the function
701 silc_client_perform_key_agreement). If TRUE is returned also the
702 `completion' and `context' arguments must be set by the application. */
703 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
704 SilcClientEntry client_entry, const char *hostname,
705 SilcUInt16 port, SilcKeyAgreementCallback *completion,
708 /* Notifies application that file transfer protocol session is being
709 requested by the remote client indicated by the `client_entry' from
710 the `hostname' and `port'. The `session_id' is the file transfer
711 session and it can be used to either accept or reject the file
712 transfer request, by calling the silc_client_file_receive or
713 silc_client_file_close, respectively. */
714 void (*ftp)(SilcClient client, SilcClientConnection conn,
715 SilcClientEntry client_entry, SilcUInt32 session_id,
716 const char *hostname, SilcUInt16 port);
718 /* Delivers SILC session detachment data indicated by `detach_data' to the
719 application. If application has issued SILC_COMMAND_DETACH command
720 the client session in the SILC network is not quit. The client remains
721 in the network but is detached. The detachment data may be used later
722 to resume the session in the SILC Network. The appliation is
723 responsible of saving the `detach_data', to for example in a file.
725 The detachment data can be given as argument to the functions
726 silc_client_connect_to_server, or silc_client_add_connection when
727 creating connection to remote server, inside SilcClientConnectionParams
728 structure. If it is provided the client library will attempt to resume
729 the session in the network. After the connection is created
730 successfully, the application is responsible of setting the user
731 interface for user into the same state it was before detaching (showing
732 same channels, channel modes, etc). It can do this by fetching the
733 information (like joined channels) from the client library. */
734 void (*detach)(SilcClient client, SilcClientConnection conn,
735 const unsigned char *detach_data,
736 SilcUInt32 detach_data_len);
737 } SilcClientOperations;
740 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
744 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
745 * char **ret_nickname);
749 * A callback function provided by the application for the library in
750 * SilcClientParams structure. This function parses the formatted
751 * nickname string `nickname' and returns the true nickname to the
752 * `ret_nickname' pointer. The library can call this function at
756 typedef void (*SilcNicknameFormatParse)(const char *nickname,
757 char **ret_nickname);
759 /****s* silcclient/SilcClientAPI/SilcClientParams
763 * typedef struct { ... } SilcClientParams;
767 * Client parameters. This can be filled with proper values and
768 * given as argument to the silc_client_alloc function. The structure
769 * hold various parameters which affects the function of the client.
774 /* Number of maximum tasks the client library's scheduler can handle.
775 If set to zero, the default value will be used (200). For WIN32
776 systems this should be set to 64 as it is the hard limit dictated
780 /* Rekey timeout in seconds. The client will perform rekey in this
781 time interval. If set to zero, the default value will be used. */
782 unsigned int rekey_secs;
784 /* Connection authentication method request timeout. If server does not
785 reply back the current authentication method when we've requested it
786 in this time interval we'll assume the reply will not come at all.
787 If set to zero, the default value (2 seconds) will be used. */
788 unsigned int connauth_request_secs;
790 /* Nickname format string. This can be used to order the client library
791 to save the nicknames in the library in a certain format. Since
792 nicknames are not unique in SILC it is possible to have multiple same
793 nicknames. Using this format string it is possible to order the library
794 to separate the multiple same nicknames from each other. The format
795 types are defined below and they can appear in any order in the format
796 string. If this is NULL then default format is used which is the
797 default nickname without anything else. The string MUST be NULL
800 Following format types are available:
802 %n nickname - the real nickname returned by the server (mandatory)
803 %h hostname - the stripped hostname of the client
804 %H full hostname - the full hostname of the client
805 %s server name - the server name the client is connected
806 %S full server - the full server name the client is connected
807 %a number - ascending number in case there are several
808 same nicknames (fe. nick@host and nick@host2)
810 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
811 "%a!%n@%s" (fe. nick@server, 2!nick@server)
812 "%n@%H" (fe. nick@host.domain.com)
814 By default this format is employed to the nicknames by the libary
815 only when there appears multiple same nicknames. If the library has
816 only one nickname cached the nickname is saved as is and without the
817 defined format. If you want always to save the nickname in the defined
818 format set the boolean field `nickname_force_format' to value TRUE.
820 char nickname_format[32];
822 /* If this is set to TRUE then the `nickname_format' is employed to all
823 saved nicknames even if there are no multiple same nicknames in the
824 cache. By default this is FALSE, which means that the `nickname_format'
825 is employed only if the library will receive a nickname that is
826 already saved in the cache. It is recommended to leave this to FALSE
828 bool nickname_force_format;
830 /* A callback function provided by the application for the library to
831 parse the nickname from the formatted nickname string. Even though
832 the libary formats the nicknames the application knows generally the
833 format better so this function should be provided for the library
834 if the application sets the `nickname_format' field. The library
835 will call this to get the true nickname from the provided formatted
836 nickname string whenever it needs the true nickname. */
837 SilcNicknameFormatParse nickname_parse;
839 /* If this is set to TRUE then the client will ignore all incoming
840 Requested Attributes queries and does not reply anything back. This
841 usually leads into situation where server does not anymore send
842 the queries after seeing that client does not reply anything back.
843 If your application does not support Requested Attributes or you do
844 not want to use them set this to TRUE. See SilcAttribute and
845 silc_client_attribute_add for more information on attributes. */
846 bool ignore_requested_attributes;
852 /* Initialization functions (client.c) */
854 /****f* silcclient/SilcClientAPI/silc_client_alloc
858 * SilcClient silc_client_alloc(SilcClientOperations *ops,
859 * SilcClientParams *params,
861 * const char *silc_version);
865 * Allocates new client object. This has to be done before client may
866 * work. After calling this one must call silc_client_init to initialize
867 * the client. The `application' is application specific user data pointer
868 * and caller must free it. The `silc_version' is the application version
869 * that will be used to compare against remote host's (usually a server)
870 * version string. The `application' context is accessible by the
871 * application by client->application, client being SilcClient.
874 SilcClient silc_client_alloc(SilcClientOperations *ops,
875 SilcClientParams *params,
877 const char *version_string);
879 /****f* silcclient/SilcClientAPI/silc_client_free
883 * void silc_client_free(SilcClient client);
887 * Frees client object and its internals. The execution of the client
888 * should be stopped with silc_client_stop function before calling
892 void silc_client_free(SilcClient client);
894 /****f* silcclient/SilcClientAPI/silc_client_init
898 * bool silc_client_init(SilcClient client);
902 * Initializes the client. This makes all the necessary steps to make
903 * the client ready to be run. One must call silc_client_run to run the
904 * client. Returns FALSE if error occurred, TRUE otherwise.
907 bool silc_client_init(SilcClient client);
909 /****f* silcclient/SilcClientAPI/silc_client_run
913 * void silc_client_run(SilcClient client);
917 * Runs the client. This starts the scheduler from the utility library.
918 * When this functions returns the execution of the appliation is over.
919 * The client must be initialized before calling this.
922 void silc_client_run(SilcClient client);
924 /****f* silcclient/SilcClientAPI/silc_client_run_one
928 * void silc_client_run_one(SilcClient client);
932 * Runs the client and returns immeadiately. This function is used when
933 * the SILC Client object indicated by the `client' is run under some
934 * other scheduler, or event loop or main loop. On GUI applications,
935 * for example this may be desired to used to run the client under the
936 * GUI application's main loop. Typically the GUI application would
937 * register an idle task that calls this function multiple times in
938 * a second to quickly process the SILC specific data.
941 void silc_client_run_one(SilcClient client);
943 /****f* silcclient/SilcClientAPI/silc_client_stop
947 * void silc_client_stop(SilcClient client);
951 * Stops the client. This is called to stop the client and thus to stop
952 * the program. The client context must be freed with the silc_client_free
956 void silc_client_stop(SilcClient client);
959 /* Connecting functions (client.c) */
961 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
965 * typedef struct { ... } SilcClientConnectionParams;
969 * Client connection parameters. This can be filled by the application
970 * and given as argument to silc_client_connect_to_server or to
971 * silc_client_add_connection.
976 /* The SILC session detachment data that was returned by `detach' client
977 operation when the application detached from the network. Application
978 is responsible of saving the data and giving it as argument here
979 for resuming the session in the SILC network.
981 If this is provided here the client library will attempt to resume
982 the session in the network. After the connection is created
983 successfully, the application is responsible of setting the user
984 interface for user into the same state it was before detaching (showing
985 same channels, channel modes, etc). It can do this by fetching the
986 information (like joined channels) from the client library. */
987 unsigned char *detach_data;
988 SilcUInt32 detach_data_len;
990 } SilcClientConnectionParams;
993 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
997 * int silc_client_connect_to_server(SilcClient client,
998 * SilcClientConnectionParams *params,
999 * int port, char *host, void *context);
1003 * Connects to remote server. This is the main routine used to connect
1004 * to SILC server. Returns -1 on error and the created socket otherwise.
1005 * The `context' is user context that is saved into the SilcClientConnection
1006 * that is created after the connection is created. Note that application
1007 * may handle the connecting process outside the library. If this is the
1008 * case then this function is not used at all. When the connecting is
1009 * done the `connect' client operation is called, and the `context' is
1010 * accessible with conn->context, conn being SilcClientConnection.
1011 * If the `params' is provided they are used by the routine.
1014 int silc_client_connect_to_server(SilcClient client,
1015 SilcClientConnectionParams *params,
1016 int port, char *host, void *context);
1018 /****f* silcclient/SilcClientAPI/silc_client_add_connection
1023 * SilcClientConnection
1024 * silc_client_add_connection(SilcClient client,
1025 * SilcClientConnectionParams *params,
1026 * char *hostname, int port, void *context);
1030 * Allocates and adds new connection to the client. This adds the allocated
1031 * connection to the connection table and returns a pointer to it. A client
1032 * can have multiple connections to multiple servers. Every connection must
1033 * be added to the client using this function. User data `context' may
1034 * be sent as argument. If the `params' is provided they are used by
1039 * This function is normally used only if the application performed
1040 * the connecting outside the library, and did not called the
1041 * silc_client_connect_to_server function at all. The library
1042 * however may use this internally.
1045 SilcClientConnection
1046 silc_client_add_connection(SilcClient client,
1047 SilcClientConnectionParams *params,
1048 char *hostname, int port, void *context);
1050 /****f* silcclient/SilcClientAPI/silc_client_del_connection
1054 * void silc_client_del_connection(SilcClient client,
1055 * SilcClientConnection conn);
1059 * Removes connection from client. Frees all memory. The library
1060 * call this function automatically for all connection contexts.
1061 * The application however may free the connection contexts it has
1065 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
1067 /****f* silcclient/SilcClientAPI/silc_client_add_socket
1071 * void silc_client_add_socket(SilcClient client,
1072 * SilcSocketConnection sock);
1076 * Adds listener socket to the listener sockets table. This function is
1077 * used to add socket objects that are listeners to the client. This should
1078 * not be used to add other connection objects.
1081 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
1083 /****f* silcclient/SilcClientAPI/silc_client_del_socket
1087 * void silc_client_del_socket(SilcClient client,
1088 * SilcSocketConnection sock);
1092 * Deletes listener socket from the listener sockets table. If the
1093 * application has added a socket with silc_client_add_socket it must
1094 * also free it using this function.
1097 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
1099 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
1103 * void silc_client_start_key_exchange(SilcClient client,
1104 * SilcClientConnection conn,
1109 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
1110 * key material between client and server. This function can be called
1111 * directly if application is performing its own connecting and does not
1112 * use the connecting provided by this library. This function is normally
1113 * used only if the application performed the connecting outside the
1114 * library. The library however may use this internally. After the
1115 * key exchange is performed the `connect' client operation is called.
1119 * The silc_client_add_connection must be called before calling this
1120 * function to create the SilcClientConnection context for this
1124 void silc_client_start_key_exchange(SilcClient client,
1125 SilcClientConnection conn,
1128 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1132 * void silc_client_close_connection(SilcClient client,
1133 * SilcClientConnection conn);
1137 * Closes connection to remote end. Free's all allocated data except
1138 * for some information such as nickname etc. that are valid at all time.
1139 * Usually application does not need to directly call this, except
1140 * when explicitly closing the connection, or if an error occurs
1141 * during connection to server (see 'connect' client operation for
1142 * more information).
1145 void silc_client_close_connection(SilcClient client,
1146 SilcClientConnection conn);
1149 /* Message sending functions (client_channel.c and client_prvmsg.c) */
1151 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1155 * bool silc_client_send_channel_message(SilcClient client,
1156 * SilcClientConnection conn,
1157 * SilcChannelEntry channel,
1158 * SilcChannelPrivateKey key,
1159 * SilcMessageFlags flags,
1160 * unsigned char *data,
1161 * SilcUInt32 data_len,
1166 * Sends packet to the `channel'. Packet to channel is always encrypted
1167 * differently from "normal" packets. SILC header of the packet is
1168 * encrypted with the next receiver's key and the rest of the packet is
1169 * encrypted with the channel specific key. Padding and HMAC is computed
1170 * with the next receiver's key. The `data' is the channel message. If
1171 * the `force_send' is TRUE then the packet is sent immediately.
1173 * If `key' is provided then that private key is used to encrypt the
1174 * channel message. If it is not provided, private keys has not been
1175 * set at all, the normal channel key is used automatically. If private
1176 * keys are set then the first key (the key that was added first as
1177 * private key) is used.
1179 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1180 * digitally signed with the SILC key pair.
1182 * Returns TRUE if the message was sent, and FALSE if error occurred or
1183 * the sending is not allowed due to channel modes (like sending is
1187 bool silc_client_send_channel_message(SilcClient client,
1188 SilcClientConnection conn,
1189 SilcChannelEntry channel,
1190 SilcChannelPrivateKey key,
1191 SilcMessageFlags flags,
1192 unsigned char *data,
1193 SilcUInt32 data_len,
1196 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1200 * bool silc_client_send_private_message(SilcClient client,
1201 * SilcClientConnection conn,
1202 * SilcClientEntry client_entry,
1203 * SilcMessageFlags flags,
1204 * unsigned char *data,
1205 * SilcUInt32 data_len,
1210 * Sends private message to remote client. If private message key has
1211 * not been set with this client then the message will be encrypted using
1212 * normal session keys. Private messages are special packets in SILC
1213 * network hence we need this own function for them. This is similar
1214 * to silc_client_packet_send_to_channel except that we send private
1215 * message. The `data' is the private message. If the `force_send' is
1216 * TRUE the packet is sent immediately.
1218 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1219 * digitally signed with the SILC key pair.
1221 * Returns TRUE if the message was sent, and FALSE if error occurred.
1224 bool silc_client_send_private_message(SilcClient client,
1225 SilcClientConnection conn,
1226 SilcClientEntry client_entry,
1227 SilcMessageFlags flags,
1228 unsigned char *data,
1229 SilcUInt32 data_len,
1233 /* Client and Channel entry retrieval (idlist.c) */
1235 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
1239 * typedef void (*SilcGetClientCallback)(SilcClient client,
1240 * SilcClientConnection conn,
1241 * SilcClientEntry *clients,
1242 * SilcUInt32 clients_count,
1247 * Callback function given to the silc_client_get_client function. The
1248 * found entries are allocated into the `clients' array. The array must
1249 * not be freed by the receiver, the library will free it later. If the
1250 * `clients' is NULL, no such clients exist in the SILC Network.
1253 typedef void (*SilcGetClientCallback)(SilcClient client,
1254 SilcClientConnection conn,
1255 SilcClientEntry *clients,
1256 SilcUInt32 clients_count,
1259 /****f* silcclient/SilcClientAPI/silc_client_get_clients
1263 * void silc_client_get_clients(SilcClient client,
1264 * SilcClientConnection conn,
1265 * const char *nickname,
1266 * const char *server,
1267 * SilcGetClientCallback completion,
1272 * Finds client entry or entries by the `nickname' and `server'. The
1273 * completion callback will be called when the client entries has been
1274 * found. After the server returns the client information it is cached
1275 * and can be accesses locally at a later time. The resolving is done
1276 * with IDENTIFY command. The `server' may be NULL.
1280 * NOTE: This function is always asynchronous and resolves the client
1281 * information from the server. Thus, if you already know the client
1282 * information then use the silc_client_get_client_by_id function to
1283 * get the client entry since this function may be very slow and should
1284 * be used only to initially get the client entries.
1286 * Since this routine resolves with IDENTIFY command only the relevant
1287 * information (user's nickname and username) is resolved. For example,
1288 * user's real name, channel list and others are not resolved. Caller
1289 * can/must resolve those separately if they are needed (for example,
1290 * with silc_client_get_client_by_id_resolve).
1293 void silc_client_get_clients(SilcClient client,
1294 SilcClientConnection conn,
1295 const char *nickname,
1297 SilcGetClientCallback completion,
1300 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1304 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1305 * SilcClientConnection conn,
1306 * const char *nickname,
1307 * const char *format,
1308 * SilcUInt32 *clients_count);
1312 * Same as silc_client_get_clients function but does not resolve anything
1313 * from the server. This checks local cache and returns all matching
1314 * clients from the local cache. If none was found this returns NULL.
1315 * The `nickname' is the real nickname of the client, and the `format'
1316 * is the formatted nickname to find exact match from multiple found
1317 * entries. The format must be same as given in the SilcClientParams
1318 * structure to the client library. If the `format' is NULL all found
1319 * clients by `nickname' are returned. The caller must return the
1323 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1324 SilcClientConnection conn,
1325 const char *nickname,
1327 SilcUInt32 *clients_count);
1329 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_channel
1333 * void silc_client_get_clients_by_channel(SilcClient client,
1334 * SilcClientConnection conn,
1335 * SilcChannelEntry channel,
1336 * SilcGetClientCallback completion,
1341 * Gets client entries by the channel indicated by `channel'. Thus,
1342 * it resovles the users currently on that channel. If all users are
1343 * already resolved this returns the users from the channel. If the
1344 * users are resolved only partially this resolves the complete user
1345 * information. If no users are resolved on this channel at all, this
1346 * calls USERS command to resolve all users on the channel. The `completion'
1347 * will be called after the entries are available. When server returns
1348 * the client information it will be cached and can be accessed locally
1351 * This function can be used for example in SILC_COMMAND_JOIN command
1352 * reply handling in application to resolve users on that channel. It
1353 * also can be used after calling silc_client_get_channel_resolve to
1354 * resolve users on that channel.
1358 * The resolving is done with WHOIS command. For this reason this
1359 * command may take a long time because it resolves detailed user
1363 void silc_client_get_clients_by_channel(SilcClient client,
1364 SilcClientConnection conn,
1365 SilcChannelEntry channel,
1366 SilcGetClientCallback completion,
1369 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1373 * void silc_client_get_clients_by_list(SilcClient client,
1374 * SilcClientConnection conn,
1375 * SilcUInt32 list_count,
1376 * SilcBuffer client_id_list,
1377 * SilcGetClientCallback completion,
1382 * Gets client entries by the list of client ID's `client_id_list'. This
1383 * always resolves those client ID's it does not know yet from the server
1384 * so this function might take a while. The `client_id_list' is a list
1385 * of ID Payloads added one after other. JOIN command reply and USERS
1386 * command reply for example returns this sort of list. The `completion'
1387 * will be called after the entries are available. When server returns
1388 * the client information it will be cached and can be accessed locally
1393 * The resolving is done with IDENTIFY command. This means that only
1394 * the relevant information of user (it's nickname and username) is
1395 * resolved. For example, user's real name, channel lists and others
1396 * are not resolved. Caller can/must resolve those separately if they
1397 * are needed (for example, with silc_client_get_client_by_id_resolve).
1400 void silc_client_get_clients_by_list(SilcClient client,
1401 SilcClientConnection conn,
1402 SilcUInt32 list_count,
1403 SilcBuffer client_id_list,
1404 SilcGetClientCallback completion,
1407 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1411 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1412 * SilcClientConnection conn,
1413 * SilcClientID *client_id);
1417 * Find entry for client by the client's ID. Returns the entry or NULL
1418 * if the entry was not found. This checks the local cache and does
1419 * not resolve anything from server.
1422 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1423 SilcClientConnection conn,
1424 SilcClientID *client_id);
1426 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1431 * silc_client_get_client_by_id_resolve(SilcClient client,
1432 * SilcClientConnection conn,
1433 * SilcClientID *client_id,
1434 * SilcBuffer attributes,
1435 * SilcGetClientCallback completion,
1440 * Same as silc_client_get_client_by_id but will always resolve the
1441 * information from the server. Use this only if you know that you
1442 * do not have the entry and the only thing you know about the client
1443 * is its ID. When server returns the client information it will be
1444 * cache and can be accessed locally at a later time. The resolving
1445 * is done by sending WHOIS command.
1447 * If the `attributes' is non-NULL then the buffer includes Requested
1448 * Attributes which can be used to fetch very detailed information
1449 * about the user. If it is NULL then only normal WHOIS query is
1450 * made (for more information about attributes see SilcAttribute).
1451 * Caller may create the `attributes' with silc_client_attributes_request
1455 void silc_client_get_client_by_id_resolve(SilcClient client,
1456 SilcClientConnection conn,
1457 SilcClientID *client_id,
1458 SilcBuffer attributes,
1459 SilcGetClientCallback completion,
1462 /****f* silcclient/SilcClientAPI/silc_client_del_client
1466 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1467 * SilcClientEntry client_entry)
1471 * Removes client from local cache by the client entry indicated by
1472 * the `client_entry'. Returns TRUE if the deletion were successful.
1475 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1476 SilcClientEntry client_entry);
1478 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1482 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1483 * SilcClientConnection conn,
1484 * SilcChannelEntry *channels,
1485 * SilcUInt32 channels_count,
1490 * Callback function given to the silc_client_get_channel_* functions.
1491 * The found entries are allocated into the `channels' array. The array
1492 * must not be freed by the receiver, the library will free it later.
1493 * If the `channel' is NULL, no such channel exist in the SILC Network.
1496 typedef void (*SilcGetChannelCallback)(SilcClient client,
1497 SilcClientConnection conn,
1498 SilcChannelEntry *channels,
1499 SilcUInt32 channels_count,
1502 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1506 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1507 * SilcClientConnection conn,
1508 * char *channel_name);
1512 * Finds entry for channel by the channel name. Returns the entry or NULL
1513 * if the entry was not found. It is found only if the client is joined
1514 * to the channel. Use silc_client_get_channel_resolve or
1515 * silc_client_get_channel_by_id_resolve to resolve channel that client
1519 SilcChannelEntry silc_client_get_channel(SilcClient client,
1520 SilcClientConnection conn,
1521 char *channel_name);
1523 /****f* silcclient/SilcClientAPI/silc_client_get_channel_resolve
1527 * void silc_client_get_channel_resolve(SilcClient client,
1528 * SilcClientConnection conn,
1529 * char *channel_name,
1530 * SilcGetChannelCallback completion,
1535 * Resolves entry for channel by the channel name from the server.
1536 * The resolving is done with IDENTIFY command. Note that users on
1537 * the channel are not resolved at the same time. Use for example
1538 * silc_client_get_clients_by_channel to resolve all users on a channel.
1541 void silc_client_get_channel_resolve(SilcClient client,
1542 SilcClientConnection conn,
1544 SilcGetChannelCallback completion,
1547 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1552 * silc_client_get_channel_by_id(SilcClient client,
1553 * SilcClientConnection conn,
1554 * SilcChannelID *channel_id);
1558 * Finds channel entry by the channel ID. Returns the entry or NULL
1559 * if the entry was not found. This checks the local cache and does
1560 * not resolve anything from server.
1563 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1564 SilcClientConnection conn,
1565 SilcChannelID *channel_id);
1567 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1572 * silc_client_get_channel_by_id_resolve(SilcClient client,
1573 * SilcClientConnection conn,
1574 * SilcChannelID *channel_id,
1575 * SilcGetClientCallback completion,
1580 * Resolves the channel information (its name mainly) from the server
1581 * by the `channel_id'. Use this only if you know that you do not have
1582 * the entry cached locally. The resolving is done with IDENTIFY command.
1584 * Note that users on the channel are not resolved at the same time.
1585 * Use for example silc_client_get_clients_by_channel to resolve all
1586 * users on a channel.
1589 void silc_client_get_channel_by_id_resolve(SilcClient client,
1590 SilcClientConnection conn,
1591 SilcChannelID *channel_id,
1592 SilcGetChannelCallback completion,
1595 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1599 * bool silc_client_del_channel(SilcClient client,
1600 * SilcClientConnection conn,
1601 * SilcChannelEntry channel)
1605 * Removes channel from local cache by the channel entry indicated by
1606 * the `channel'. Returns TRUE if the deletion were successful.
1609 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1610 SilcChannelEntry channel);
1612 /****f* silcclient/SilcClientAPI/silc_client_get_server
1616 * SilcServerEntry silc_client_get_server(SilcClient client,
1617 * SilcClientConnection conn,
1618 * char *server_name)
1622 * Finds entry for server by the server name. Returns the entry or NULL
1623 * if the entry was not found.
1626 SilcServerEntry silc_client_get_server(SilcClient client,
1627 SilcClientConnection conn,
1630 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1634 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1635 * SilcClientConnection conn,
1636 * SilcServerID *server_id);
1640 * Finds entry for server by the server ID. Returns the entry or NULL
1641 * if the entry was not found.
1644 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1645 SilcClientConnection conn,
1646 SilcServerID *server_id);
1648 /****f* silcclient/SilcClientAPI/silc_client_del_server
1652 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1653 * SilcServerEntry server);
1657 * Removes server from local cache by the server entry indicated by
1658 * the `server'. Returns TRUE if the deletion were successful.
1661 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1662 SilcServerEntry server);
1664 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1668 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1669 * SilcClientEntry client_entry);
1673 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1674 * channel indicated by the `channel'. NULL if client is not joined on
1678 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1679 SilcClientEntry client_entry);
1681 /* Command management (command.c) */
1683 /****f* silcclient/SilcClientAPI/silc_client_command_call
1687 * bool silc_client_command_call(SilcClient client,
1688 * SilcClientConnection conn,
1689 * const char *command_line, ...);
1693 * Calls and executes the command indicated by the `command_name'.
1694 * The `command_line' is a string which includes the command's name and
1695 * its arguments separated with whitespaces (' '). If `command_line'
1696 * is non-NULL then all variable arguments are ignored by default.
1698 * If `command_line' is NULL, then the variable arguments define the
1699 * command's name and its arguments. The first variable argument must
1700 * be the command name. The variable argument list must be terminated
1703 * Returns FALSE if the command is not known and TRUE after command.
1704 * execution. The "command" client operation is called when the
1705 * command is executed to indicate whether the command executed
1706 * successfully or not.
1708 * The "command_reply" client operation will be called when reply is
1709 * received from the server to the command. Application may also use
1710 * the silc_client_command_pending to attach to the command reply.
1711 * The command identifier for silc_client_command_pending function after
1712 * this function call is conn->cmd_ident, which application may use.
1716 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1718 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1722 * This command executes the commands implemented inside the client
1723 * library. These commands are designed for command line applications,
1724 * but GUI application may call them too if needed. Alternatively
1725 * application may override the library and use silc_client_command_send
1729 bool silc_client_command_call(SilcClient client,
1730 SilcClientConnection conn,
1731 const char *command_line, ...);
1733 /****f* silcclient/SilcClientAPI/silc_client_command_send
1737 * void silc_client_command_send(SilcClient client,
1738 * SilcClientConnection conn,
1739 * SilcCommand command, SilcUInt16 ident,
1740 * SilcUInt32 argc, ...);
1744 * Generic function to send any command. The arguments must be sent already
1745 * encoded into correct form and in correct order. If application wants
1746 * to perform the commands by itself, it can do so and send the data
1747 * directly to the server using this function. If application is using
1748 * the silc_client_command_call, this function is usually not used.
1749 * Note that this overriders the Client Librarys commands and sends
1750 * the command packet directly to server.
1752 * Programmer should get familiar with the SILC protocol commands
1753 * specification when using this function, as the arguments needs to
1754 * be encoded as specified in the protocol.
1756 * The variable arguments are a pair of { type, data, data_length },
1757 * and the `argc' is the number of these pairs.
1761 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1762 * 1, nickname, strlen(nickname));
1765 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1766 SilcCommand command, SilcUInt16 ident,
1767 SilcUInt32 argc, ...);
1769 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1773 * void silc_client_command_pending(SilcClientConnection conn,
1774 * SilcCommand reply_cmd,
1776 * SilcCommandCb callback,
1781 * This function can be used to add pending command callback to be
1782 * called when an command reply is received to an earlier sent command.
1783 * The `reply_cmd' is the command that must be received in order for
1784 * the pending command callback indicated by `callback' to be called.
1785 * The `callback' will deliver the `context' and
1786 * SilcClientCommandReplyContext which includes the internals of the
1789 * The `ident' is a command identifier which was set for the earlier
1790 * sent command. The command reply will include the same identifier
1791 * and pending command callback will be called when the reply is
1792 * received with the same command identifier. It is possible to
1793 * add multiple pending command callbacks for same command and for
1796 * Application may use this function to add its own command reply
1797 * handlers if it wishes not to use the standard `command_reply'
1798 * client operation. However, note that the pending command callback
1799 * does not deliver parsed command reply, but application must parse
1802 * Note also that the application is notified about the received command
1803 * reply through the `command_reply' client operation before calling
1804 * the `callback` pending command callback. That is the normal
1805 * command reply handling, and is called regardless whether pending
1806 * command callbacks are used or not.
1808 * Commands that application calls with silc_client_command_call
1809 * will use a command identifier from conn->cmd_ident variable. After
1810 * calling the silc_client_command_call, the conn->cmd_ident includes
1811 * the command identifier that was used for the command sending.
1815 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1816 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1817 * my_ping_handler, my_ping_context);
1820 void silc_client_command_pending(SilcClientConnection conn,
1821 SilcCommand reply_cmd,
1823 SilcCommandCb callback,
1827 /* Private Message key management (client_prvmsg.c) */
1829 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1833 * bool silc_client_add_private_message_key(SilcClient client,
1834 * SilcClientConnection conn,
1835 * SilcClientEntry client_entry,
1836 * const char *cipher,
1838 * unsigned char *key,
1839 * SilcUInt32 key_len,
1840 * bool generate_key,
1845 * Adds private message key to the client library. The key will be used to
1846 * encrypt all private message between the client and the remote client
1847 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1848 * value `generate_key' is TRUE the library will generate random key.
1849 * The `key' maybe for example pre-shared-key, passphrase or similar.
1850 * The `cipher' and `hmac' MAY be provided but SHOULD be NULL to assure
1851 * that the requirements of the SILC protocol are met. The API, however,
1852 * allows to allocate any cipher and HMAC.
1854 * If `responder' is TRUE then the sending and receiving keys will be
1855 * set according the client being the receiver of the private key. If
1856 * FALSE the client is being the sender (or negotiator) of the private
1859 * It is not necessary to set key for normal private message usage. If the
1860 * key is not set then the private messages are encrypted using normal
1861 * session keys. Setting the private key, however, increases the security.
1863 * Returns FALSE if the key is already set for the `client_entry', TRUE
1867 bool silc_client_add_private_message_key(SilcClient client,
1868 SilcClientConnection conn,
1869 SilcClientEntry client_entry,
1877 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1882 * silc_client_add_private_message_key_ske(SilcClient client,
1883 * SilcClientConnection conn,
1884 * SilcClientEntry client_entry,
1885 * const char *cipher,
1887 * SilcSKEKeyMaterial *key);
1891 * Same as silc_client_add_private_message_key but takes the key material
1892 * from the SKE key material structure. This structure is received if
1893 * the application uses the silc_client_send_key_agreement to negotiate
1894 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1895 * negotiated also in the SKE protocol.
1898 bool silc_client_add_private_message_key_ske(SilcClient client,
1899 SilcClientConnection conn,
1900 SilcClientEntry client_entry,
1903 SilcSKEKeyMaterial *key,
1906 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1910 * bool silc_client_del_private_message_key(SilcClient client,
1911 * SilcClientConnection conn,
1912 * SilcClientEntry client_entry);
1916 * Removes the private message from the library. The key won't be used
1917 * after this to protect the private messages with the remote `client_entry'
1918 * client. Returns FALSE on error, TRUE otherwise.
1921 bool silc_client_del_private_message_key(SilcClient client,
1922 SilcClientConnection conn,
1923 SilcClientEntry client_entry);
1925 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1929 * SilcPrivateMessageKeys
1930 * silc_client_list_private_message_keys(SilcClient client,
1931 * SilcClientConnection conn,
1932 * SilcUInt32 *key_count);
1936 * Returns array of set private message keys associated to the connection
1937 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1938 * count to the `key_count' argument. The array must be freed by the caller
1939 * by calling the silc_client_free_private_message_keys function. Note:
1940 * the keys returned in the array is in raw format. It might not be desired
1941 * to show the keys as is. The application might choose not to show the keys
1942 * at all or to show the fingerprints of the keys.
1945 SilcPrivateMessageKeys
1946 silc_client_list_private_message_keys(SilcClient client,
1947 SilcClientConnection conn,
1948 SilcUInt32 *key_count);
1950 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1954 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1955 * SilcUInt32 key_count);
1959 * Frees the SilcPrivateMessageKeys array returned by the function
1960 * silc_client_list_private_message_keys.
1963 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1964 SilcUInt32 key_count);
1967 /* Channel private key management (client_channel.c,
1968 SilcChannelPrivateKey is defined in idlist.h) */
1970 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1974 * bool silc_client_add_channel_private_key(SilcClient client,
1975 * SilcClientConnection conn,
1976 * SilcChannelEntry channel,
1980 * unsigned char *key,
1981 * SilcUInt32 key_len);
1985 * Adds private key for channel. This may be set only if the channel's mode
1986 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1987 * mode is not set. When channel has private key then the messages are
1988 * encrypted using that key. All clients on the channel must also know the
1989 * key in order to decrypt the messages. However, it is possible to have
1990 * several private keys per one channel. In this case only some of the
1991 * clients on the channel may know the one key and only some the other key.
1992 * The `name' can be application given name for the key.
1994 * The private key for channel is optional. If it is not set then the
1995 * channel messages are encrypted using the channel key generated by the
1996 * server. However, setting the private key (or keys) for the channel
1997 * significantly adds security. If more than one key is set the library
1998 * will automatically try all keys at the message decryption phase. Note:
1999 * setting many keys slows down the decryption phase as all keys has to
2000 * be tried in order to find the correct decryption key. However, setting
2001 * a few keys does not have big impact to the decryption performace.
2005 * NOTE: This is entirely local setting. The key set using this function
2006 * is not sent to the network at any phase.
2008 * NOTE: If the key material was originated by the SKE protocol (using
2009 * silc_client_send_key_agreement) then the `key' MUST be the
2010 * key->send_enc_key as this is dictated by the SILC protocol. However,
2011 * currently it is not expected that the SKE key material would be used
2012 * as channel private key. However, this API allows it.
2015 bool silc_client_add_channel_private_key(SilcClient client,
2016 SilcClientConnection conn,
2017 SilcChannelEntry channel,
2022 SilcUInt32 key_len);
2024 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
2028 * bool silc_client_del_channel_private_keys(SilcClient client,
2029 * SilcClientConnection conn,
2030 * SilcChannelEntry channel);
2034 * Removes all private keys from the `channel'. The old channel key is used
2035 * after calling this to protect the channel messages. Returns FALSE on
2036 * on error, TRUE otherwise.
2039 bool silc_client_del_channel_private_keys(SilcClient client,
2040 SilcClientConnection conn,
2041 SilcChannelEntry channel);
2043 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
2047 * bool silc_client_del_channel_private_key(SilcClient client,
2048 * SilcClientConnection conn,
2049 * SilcChannelEntry channel,
2050 * SilcChannelPrivateKey key);
2054 * Removes and frees private key `key' from the channel `channel'.
2055 * The `key' is retrieved by calling the function
2056 * silc_client_list_channel_private_keys. The key is not used after
2057 * this. If the key was last private key then the old channel key is
2058 * used hereafter to protect the channel messages. This returns FALSE
2059 * on error, TRUE otherwise.
2062 bool silc_client_del_channel_private_key(SilcClient client,
2063 SilcClientConnection conn,
2064 SilcChannelEntry channel,
2065 SilcChannelPrivateKey key);
2067 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
2071 * SilcChannelPrivateKey *
2072 * silc_client_list_channel_private_keys(SilcClient client,
2073 * SilcClientConnection conn,
2074 * SilcChannelEntry channel,
2075 * SilcUInt32 *key_count);
2079 * Returns array (pointers) of private keys associated to the `channel'.
2080 * The caller must free the array by calling the function
2081 * silc_client_free_channel_private_keys. The pointers in the array may be
2082 * used to delete the specific key by giving the pointer as argument to the
2083 * function silc_client_del_channel_private_key.
2086 SilcChannelPrivateKey *
2087 silc_client_list_channel_private_keys(SilcClient client,
2088 SilcClientConnection conn,
2089 SilcChannelEntry channel,
2090 SilcUInt32 *key_count);
2092 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
2096 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2097 * SilcUInt32 key_count);
2101 * Frees the SilcChannelPrivateKey array.
2104 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
2105 SilcUInt32 key_count);
2107 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
2111 * void silc_client_current_channel_private_key(SilcClient client,
2112 * SilcClientConnection conn,
2113 * SilcChannelEntry channel,
2114 * SilcChannelPrivateKey key);
2118 * Sets the `key' to be used as current channel private key on the
2119 * `channel'. Packet sent after calling this function will be secured
2123 void silc_client_current_channel_private_key(SilcClient client,
2124 SilcClientConnection conn,
2125 SilcChannelEntry channel,
2126 SilcChannelPrivateKey key);
2129 /* Key Agreement routines (client_keyagr.c) */
2131 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
2135 * void silc_client_send_key_agreement(SilcClient client,
2136 * SilcClientConnection conn,
2137 * SilcClientEntry client_entry,
2140 * SilcUInt32 timeout_secs,
2141 * SilcKeyAgreementCallback completion,
2146 * Sends key agreement request to the remote client indicated by the
2147 * `client_entry'. If the caller provides the `hostname' and the `port'
2148 * arguments then the library will bind the client to that hostname and
2149 * that port for the key agreement protocol. It also sends the `hostname'
2150 * and the `port' in the key agreement packet to the remote client. This
2151 * would indicate that the remote client may initiate the key agreement
2152 * protocol to the `hostname' on the `port'. If port is zero then the
2153 * bound port is undefined (the operating system defines it).
2155 * If the `hostname' and `port' is not provided then empty key agreement
2156 * packet is sent to the remote client. The remote client may reply with
2157 * the same packet including its hostname and port. If the library receives
2158 * the reply from the remote client the `key_agreement' client operation
2159 * callback will be called to verify whether the user wants to perform the
2160 * key agreement or not.
2164 * NOTE: If the application provided the `hostname' and the `port' and the
2165 * remote side initiates the key agreement protocol it is not verified
2166 * from the user anymore whether the protocol should be executed or not.
2167 * By setting the `hostname' and `port' the user gives permission to
2168 * perform the protocol (we are responder in this case).
2170 * NOTE: If the remote side decides not to initiate the key agreement
2171 * or decides not to reply with the key agreement packet then we cannot
2172 * perform the key agreement at all. If the key agreement protocol is
2173 * performed the `completion' callback with the `context' will be called.
2174 * If remote side decides to ignore the request the `completion' will be
2175 * called after the specified timeout, `timeout_secs'.
2177 * NOTE: If the `hostname' and the `port' was not provided the `completion'
2178 * will not be called at all since this does nothing more than sending
2179 * a packet to the remote host.
2181 * NOTE: There can be only one active key agreement for one client entry.
2182 * Before setting new one, the old one must be finished (it is finished
2183 * after calling the completion callback) or the function
2184 * silc_client_abort_key_agreement must be called.
2187 void silc_client_send_key_agreement(SilcClient client,
2188 SilcClientConnection conn,
2189 SilcClientEntry client_entry,
2190 const char *hostname,
2191 const char *bindhost,
2193 SilcUInt32 timeout_secs,
2194 SilcKeyAgreementCallback completion,
2197 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
2202 * silc_client_perform_key_agreement(SilcClient client,
2203 * SilcClientConnection conn,
2204 * SilcClientEntry client_entry,
2207 * SilcKeyAgreementCallback completion,
2212 * Performs the actual key agreement protocol. Application may use this
2213 * to initiate the key agreement protocol. This can be called for example
2214 * after the application has received the `key_agreement' client operation,
2215 * and did not return TRUE from it.
2217 * The `hostname' is the remote hostname (or IP address) and the `port'
2218 * is the remote port. The `completion' callback with the `context' will
2219 * be called after the key agreement protocol.
2223 * NOTE: If the application returns TRUE in the `key_agreement' client
2224 * operation the library will automatically start the key agreement. In this
2225 * case the application must not call this function. However, application
2226 * may choose to just ignore the `key_agreement' client operation (and
2227 * merely just print information about it on the screen) and call this
2228 * function when the user whishes to do so (by, for example, giving some
2229 * specific command). Thus, the API provides both, automatic and manual
2230 * initiation of the key agreement. Calling this function is the manual
2231 * initiation and returning TRUE in the `key_agreement' client operation
2232 * is the automatic initiation.
2235 void silc_client_perform_key_agreement(SilcClient client,
2236 SilcClientConnection conn,
2237 SilcClientEntry client_entry,
2240 SilcKeyAgreementCallback completion,
2243 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
2248 * silc_client_perform_key_agreement_fd(SilcClient client,
2249 * SilcClientConnection conn,
2250 * SilcClientEntry client_entry,
2253 * SilcKeyAgreementCallback completion,
2258 * Same as above but application has created already the connection to
2259 * the remote host. The `sock' is the socket to the remote connection.
2260 * Application can use this function if it does not want the client library
2261 * to create the connection.
2264 void silc_client_perform_key_agreement_fd(SilcClient client,
2265 SilcClientConnection conn,
2266 SilcClientEntry client_entry,
2269 SilcKeyAgreementCallback completion,
2272 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
2276 * void silc_client_abort_key_agreement(SilcClient client,
2277 * SilcClientConnection conn,
2278 * SilcClientEntry client_entry);
2282 * This function can be called to unbind the hostname and the port for
2283 * the key agreement protocol. However, this function has effect only
2284 * before the key agreement protocol has been performed. After it has
2285 * been performed the library will automatically unbind the port. The
2286 * `client_entry' is the client to which we sent the key agreement
2287 * request. The key agreement completion callback will be called
2288 * with SILC_KEY_AGREEMENT_ABORTED status.
2291 void silc_client_abort_key_agreement(SilcClient client,
2292 SilcClientConnection conn,
2293 SilcClientEntry client_entry);
2296 /* Misc functions */
2298 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
2302 * void silc_client_set_away_message(SilcClient client,
2303 * SilcClientConnection conn,
2308 * Sets away `message'. The away message may be set when the client's
2309 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
2310 * to anyone who sends private message. The `message' will be sent
2311 * automatically back to the the client who send private message. If
2312 * away message is already set this replaces the old message with the
2313 * new one. If `message' is NULL the old away message is removed.
2314 * The sender may freely free the memory of the `message'.
2317 void silc_client_set_away_message(SilcClient client,
2318 SilcClientConnection conn,
2321 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
2325 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2326 * SilcClientConnection conn,
2327 * SilcAuthMethod auth_meth,
2332 * Connection authentication method request callback. This is called
2333 * by the client library after it has received the authentication method
2334 * that the application requested by calling the function
2335 * silc_client_request_authentication_method.
2338 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
2339 SilcClientConnection conn,
2340 SilcAuthMethod auth_meth,
2343 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
2348 * silc_client_request_authentication_method(SilcClient client,
2349 * SilcClientConnection conn,
2350 * SilcConnectionAuthRequest
2356 * This function can be used to request the current authentication method
2357 * from the server. This may be called when connecting to the server
2358 * and the client library requests the authentication data from the
2359 * application. If the application does not know the current authentication
2360 * method it can request it from the server using this function.
2361 * The `callback' with `context' will be called after the server has
2362 * replied back with the current authentication method.
2366 silc_client_request_authentication_method(SilcClient client,
2367 SilcClientConnection conn,
2368 SilcConnectionAuthRequest callback,
2371 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2375 * typedef enum { ... } SilcClientMonitorStatus;
2379 * File transmission session status types. These will indicate
2380 * the status of the file transmission session.
2385 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2386 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2387 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2388 SILC_CLIENT_FILE_MONITOR_GET,
2389 SILC_CLIENT_FILE_MONITOR_PUT,
2390 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2391 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2392 } SilcClientMonitorStatus;
2395 /****d* silcclient/SilcClientAPI/SilcClientFileError
2399 * typedef enum { ... } SilcClientFileError;
2403 * File transmission error types. These types are returned by
2404 * some of the file transmission functions, and by the monitor
2405 * callback to indicate error.
2410 SILC_CLIENT_FILE_OK,
2411 SILC_CLIENT_FILE_ERROR,
2412 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2413 SILC_CLIENT_FILE_ALREADY_STARTED,
2414 SILC_CLIENT_FILE_NO_SUCH_FILE,
2415 SILC_CLIENT_FILE_PERMISSION_DENIED,
2416 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2417 } SilcClientFileError;
2420 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2424 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2425 * SilcClientConnection conn,
2426 * SilcClientMonitorStatus status,
2427 * SilcClientFileError error,
2428 * SilcUInt64 offset,
2429 * SilcUInt64 filesize,
2430 * SilcClientEntry client_entry,
2431 * SilcUInt32 session_id,
2432 * const char *filepath,
2437 * Monitor callback that is called during the file transmission to
2438 * monitor the transmission process. The `status' indicates the current
2439 * monitoring process. The `error' will indicate the error type
2440 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2441 * currently transmitted amount of total `filesize'. The `client_entry'
2442 * indicates the remote client, and the transmission session ID is the
2443 * `session_id'. The filename being transmitted is indicated by the
2447 typedef void (*SilcClientFileMonitor)(SilcClient client,
2448 SilcClientConnection conn,
2449 SilcClientMonitorStatus status,
2450 SilcClientFileError error,
2452 SilcUInt64 filesize,
2453 SilcClientEntry client_entry,
2454 SilcUInt32 session_id,
2455 const char *filepath,
2458 /****f* silcclient/SilcClientAPI/silc_client_file_send
2462 * SilcClientFileError
2463 * silc_client_file_send(SilcClient client,
2464 * SilcClientConnection conn,
2465 * SilcClientFileMonitor monitor,
2466 * void *monitor_context,
2467 * const char *local_ip,
2468 * SilcUInt32 local_port,
2470 * SilcClientEntry client_entry,
2471 * const char *filepath);
2472 * SilcUInt32 *session_id);
2476 * Sends a file indicated by the `filepath' to the remote client
2477 * indicated by the `client_entry'. This will negotiate a secret key
2478 * with the remote client before actually starting the transmission of
2479 * the file. The `monitor' callback will be called to monitor the
2480 * transmission of the file.
2482 * This returns a file session ID for the file transmission to the
2483 * `session_id' pointer. It can be used to close the session (and
2484 * abort the file transmission) by calling the silc_client_file_close
2485 * function. The session ID is also returned in the `monitor' callback.
2487 * If the `local_ip' is provided then this will try to bind the
2488 * listener for key exchange protocol to that IP. If `local_port' is
2489 * non-zero that port is used. If `local_ip' is NULL then this will
2490 * automatically attempt to bind it to local IP address of the machine.
2491 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2492 * ignored and it is expected that the receiver will provide the
2493 * point of contact. This is usefull if the sender is behind NAT.
2495 * If error will occur during the file transfer process the error
2496 * status will be returned in the monitor callback. In this case
2497 * the application must call silc_client_file_close to close the
2502 silc_client_file_send(SilcClient client,
2503 SilcClientConnection conn,
2504 SilcClientFileMonitor monitor,
2505 void *monitor_context,
2506 const char *local_ip,
2507 SilcUInt32 local_port,
2509 SilcClientEntry client_entry,
2510 const char *filepath,
2511 SilcUInt32 *session_id);
2513 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2517 * SilcClientFileError
2518 * silc_client_file_receive(SilcClient client,
2519 * SilcClientConnection conn,
2520 * SilcClientFileMonitor monitor,
2521 * void *monitor_context,
2523 * SilcUInt32 session_id);
2527 * Receives a file from a client indicated by the `client_entry'. The
2528 * `session_id' indicates the file transmission session and it has been
2529 * received in the `ftp' client operation function. This will actually
2530 * perform the key agreement protocol with the remote client before
2531 * actually starting the file transmission. The `monitor' callback
2532 * will be called to monitor the transmission. If `path' is non NULL
2533 * the file will be saved into that directory. If NULL the file is
2534 * saved in the current working directory.
2536 * If error will occur during the file transfer process the error
2537 * status will be returned in the monitor callback. In this case
2538 * the application must call silc_client_file_close to close the
2543 silc_client_file_receive(SilcClient client,
2544 SilcClientConnection conn,
2545 SilcClientFileMonitor monitor,
2546 void *monitor_context,
2548 SilcUInt32 session_id);
2550 /****f* silcclient/SilcClientAPI/silc_client_file_close
2554 * SilcClientFileError silc_client_file_close(SilcClient client,
2555 * SilcClientConnection conn,
2556 * SilcUInt32 session_id);
2560 * Closes file transmission session indicated by the `session_id'.
2561 * If file transmission is being conducted it will be aborted
2562 * automatically. This function is also used to close the session
2563 * after successful file transmission. This function can be used
2564 * also to reject incoming file transmission request.
2567 SilcClientFileError silc_client_file_close(SilcClient client,
2568 SilcClientConnection conn,
2569 SilcUInt32 session_id);
2571 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2575 * SilcAttributePayload
2576 * silc_client_attribute_add(SilcClient client,
2577 * SilcClientConnection conn,
2578 * SilcAttribute attribute,
2580 * SilcUInt32 object_size);
2584 * Add new Requsted Attribute for WHOIS command to the client library.
2585 * The `attribute' object indicated by `object' is added and allocated
2586 * SilcAttributePayload is returned. The `object' must be of correct
2587 * type and of correct size. See the SilcAttribute for object types
2588 * for different attributes. You may also get all added attributes
2589 * from the client with silc_client_attributes_get function.
2591 * Requested Attributes are different personal information about the
2592 * user, status information and other information which other users
2593 * may query with WHOIS command. Application may set these so that
2594 * if someone sends WHOIS query these attributes will be replied back
2595 * to the sender. The library always puts the public key to the
2596 * Requested Attributes, but if application wishes to add additional
2597 * public keys (or certificates) it can be done with this interface.
2598 * Library also always computes digital signature of the attributes
2599 * automatically, so application does not need to do that.
2602 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2603 SilcClientConnection conn,
2604 SilcAttribute attribute,
2606 SilcUInt32 object_size);
2608 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2612 * bool silc_client_attribute_del(SilcClient client,
2613 * SilcClientConnection conn,
2614 * SilcAttribute attribute,
2615 * SilcAttributePayload attr);
2619 * Delete a Requested Attribute from the client. If the `attribute'
2620 * is non-zero then all attributes of that type are deleted and the
2621 * `attr' is ignored. If `attr' is non-NULL then that specific
2622 * attribute is deleted and `attribute' is ignored.
2624 * You may get all added attributes with the function
2625 * silc_client_attributes_get and to get the SilcAttributePayload.
2626 * This function Returns TRUE if the attribute was found and deleted.
2629 bool silc_client_attribute_del(SilcClient client,
2630 SilcClientConnection conn,
2631 SilcAttribute attribute,
2632 SilcAttributePayload attr);
2634 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2638 * const SilcHashTable
2639 * silc_client_attributes_get(SilcClient client,
2640 * SilcClientConnection conn);
2644 * Returns pointer to the SilcHashTable which includes all the added
2645 * Requested Attributes. The caller must not free the hash table.
2646 * The caller may use SilcHashTableList and silc_hash_table_list to
2647 * traverse the table. Each entry in the hash table is one added
2648 * SilcAttributePayload. It is possible to delete a attribute
2649 * payload while traversing the table.
2652 const SilcHashTable silc_client_attributes_get(SilcClient client,
2653 SilcClientConnection conn);
2655 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2659 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2663 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2664 * then all attributes are requested. Alternatively, `attribute' and
2665 * all variable arguments can each be requested attribute. In this case
2666 * the last must be set to zero (0) to complete the variable list of
2667 * requested attributes. See SilcAttribute for all attributes.
2668 * You can give the returned buffer as argument to for example
2669 * silc_client_get_client_by_id_resolve function.
2673 * Request all attributes
2674 * buffer = silc_client_attributes_request(0);
2676 * Request only the following attributes
2677 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2678 * SILC_ATTRIBUTE_SERVICE,
2679 * SILC_ATTRIBUTE_MOOD, 0);
2682 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2684 /* Low level packet sending functions */
2686 /****f* silcclient/SilcClientAPI/silc_client_send_packet
2690 * bool silc_client_send_packet(SilcClient client,
2691 * SilcClientConnection conn,
2692 * SilcPacketType type,
2693 * const unsigned char *data,
2694 * SilcUInt32 data_len);
2698 * This routine can be used by application to send packets directly
2699 * to a connection indicated by `conn'. Usually application does not
2700 * need this routine since the Client Library handles the packet
2701 * sending. The `type' indicates the packet type. If `data' is
2702 * NULL then empty packet is sent. This returns FALSE if packet cannot
2706 bool silc_client_send_packet(SilcClient client,
2707 SilcClientConnection conn,
2708 SilcPacketType type,
2709 const unsigned char *data,
2710 SilcUInt32 data_len);
2712 #include "command.h"
2713 #include "command_reply.h"
2715 #include "protocol.h"
2721 #endif /* SILCCLIENT_H */