5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2007 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 Library is a full featured SILC client without user interface.
26 * A simple interface called SILC Client Operations (SilcClientOperations)
27 * is provided for applications to implmeent the necessary functions to use
28 * the client library. The silcclient.h header file includes client library
29 * API, such as command handling and message sending. The silcclient_entry.h
30 * header file includes entry handling, such as channel and user entry
33 * Practically all functions in the Client Library API accepts SilcClient
34 * and SilcClientConnection as their first two argument. The first argument
35 * is the actual SilcClient context and the second is the SilcClientConnection
36 * context of the connection in question. Application may create and handle
37 * multiple connections in one SilcClient. Connections can be created to
38 * servers and other clients.
40 * The Client Library support multiple threads and is threads safe if used
41 * correctly. Messages can be sent from multiple threads without any
42 * locking. Messages however are always received only in one thread unless
43 * message waiting (see silc_client_private_message_wait as an example) is
44 * used. The threads can be turned on and off by giving a parameter to the
45 * SilcClient. When turned on, each new connection to remote host is always
46 * executed in an own thread. All tasks related to that connection are then
47 * executed in that thread. This means that client operation callbacks for
48 * that connections may be called from threads and application will need to
49 * employ concurrency control if the callbacks need to access shared data
50 * in the application. Messages are also received in that thread.
62 #include "silcclient_entry.h"
64 /* General definitions */
66 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
70 * typedef enum { ... } SilcClientConnectionStatus
74 * This type is returned to the `connect' client operation to indicate
75 * the status of the created connection. It can indicate if it was
76 * successful or whether an error occurred.
81 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
82 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
83 resumed old detached session */
84 SILC_CLIENT_CONN_DISCONNECTED, /* Remote host disconnected */
85 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
86 SILC_CLIENT_CONN_ERROR_KE, /* Key Exchange failed */
87 SILC_CLIENT_CONN_ERROR_AUTH, /* Authentication failed */
88 SILC_CLIENT_CONN_ERROR_RESUME, /* Resuming failed */
89 SILC_CLIENT_CONN_ERROR_TIMEOUT, /* Timeout during connecting */
90 } SilcClientConnectionStatus;
93 /****f* silcclient/SilcClientAPI/SilcClientRunning
97 * typedef void (*SilcClientRunning)(SilcClient client, void *context);
101 * The callback given as argument to silc_client_init function. Once
102 * this is called the client library is running and application may
103 * start using the Client library API.
106 typedef void (*SilcClientRunning)(SilcClient client, void *context);
108 /****f* silcclient/SilcClientAPI/SilcClientStopped
112 * typedef void (*SilcClientStopped)(SilcClient client, void *context);
116 * The callback given as argument to silc_client_stop. Once this is
117 * called the client library has stopped and can be freed by calling
118 * silc_client_free. Note that this won't be called if there are
119 * active connections in the client. Connections must first be closed
120 * by calling silc_client_close_connection or by sending QUIT command to
121 * the server connection.
124 typedef void (*SilcClientStopped)(SilcClient client, void *context);
126 /****f* silcclient/SilcClientAPI/SilcClientConnectCallback
130 * void (*SilcClientConnectCallback)(SilcClient client,
131 * SilcClientConnection conn,
132 * SilcClientConnectionStatus status,
134 * const char *message,
139 * Connect callbak given as argument to silc_client_connect_to_server,
140 * silc_client_connect_to_client and silc_client_key_exchange functions.
141 * It is called to indicate the status of the connection, indicated
142 * by the `status'. It is called after the connection has been
143 * established to the remote host and when connection is disconnected
144 * by the remote host. The `context' is the context given as argument
145 * to the connecting function. If the `status' is an error the `error'
146 * may indicate more detailed error. If `error' is SILC_STATUS_OK no
147 * detailed error message is available.
149 * When the `status' is SILC_CLIENT_CONN_DISCONNECTED the `error' will
150 * indicate the reason for disconnection. If the `message' is non-NULL
151 * it delivers error or disconnection message.
153 * The `conn' is the connection to the remote host. In case error
154 * occurred the `conn' may be NULL, however, in some cases a valid `conn'
155 * is returned even in error. If `conn' is non-NULL the receiver is
156 * responsible of closing the connection with silc_client_close_connection
157 * function, except when SILC_CLINET_CONN_DISCONNECTED or some error
158 * was received. In these cases the library will close the connection.
161 typedef void (*SilcClientConnectCallback)(SilcClient client,
162 SilcClientConnection conn,
163 SilcClientConnectionStatus status,
168 /****s* silcclient/SilcClientAPI/SilcClient
172 * typedef struct SilcClientStruct { ... } *SilcClient
176 * This is the actual SILC Client structure which represents one
177 * SILC Client. It is allocated with the silc_client_alloc function
178 * and given as argument to all SILC Client Library functions. It
179 * is initialized with silc_client_init function, and freed with
180 * silc_client_free function.
182 * This context represents the client. Each connection to remote server
183 * is represented by SilcClientConnection context.
187 struct SilcClientStruct {
188 char *username; /* Username */
189 char *hostname; /* hostname */
190 char *realname; /* Real name */
191 SilcSchedule schedule; /* Client scheduler */
192 SilcRng rng; /* Random number generator */
193 void *application; /* Application specific context, set with
194 silc_client_alloc. */
196 /* Internal data for client library. Application cannot access this. */
197 SilcClientInternal internal;
201 /****s* silcclient/SilcClientAPI/SilcClientConnection
205 * typedef struct SilcClientConnectionStruct { ... }
206 * *SilcClientConnection
210 * This structure represents a connection. It is allocated and freed by
211 * the library. It is returned to application in SilcClientConnectCallback.
212 * It includes all the important data for the session such as local
213 * client entry (which includes current nickname), local and remote IDs,
214 * and other information. All strings in the structure are UTF-8 encoded.
218 struct SilcClientConnectionStruct {
219 SilcClientEntry local_entry; /* Our own Client Entry */
220 SilcClientID *local_id; /* Our current Client ID */
222 char *remote_host; /* Remote host name */
223 int remote_port; /* Remote port */
224 SilcID remote_id; /* Remote ID */
226 SilcChannelEntry current_channel; /* Current joined channel */
227 SilcPublicKey public_key; /* Public key used in this connection */
228 SilcPrivateKey private_key; /* Private key */
229 SilcPacketStream stream; /* Connection to remote host */
230 SilcConnectionType type; /* Connection type */
231 SilcClientConnectCallback callback; /* Connection callback */
232 void *callback_context; /* Connection context */
233 SilcClient client; /* Pointer back to SilcClient */
235 /* Application specific data. Application may set here whatever it wants. */
238 /* Internal data for client library. Application cannot access this. */
239 SilcClientConnectionInternal internal;
243 /****s* silcclient/SilcClientAPI/SilcChannelUser
247 * typedef struct SilcChannelUserStruct { ... } *SilcChannelUser
251 * This structure represents a client that has joined to a channel.
252 * It shows the client and the channel and the client's mode (channel
253 * user mode) on the channel.
257 struct SilcChannelUserStruct {
258 SilcClientEntry client; /* Client joined on channel */
259 SilcUInt32 mode; /* mode, ChannelUserModes */
260 SilcChannelEntry channel; /* The channel user has joined */
262 /* Application specific data. Application may set here whatever it wants. */
267 /****s* silcclient/SilcClientAPI/SilcClientStats
271 * typedef struct { ... } SilcClientStats;
275 * This structure holds SILC network statistics returned by the
276 * SILC_COMMAND_STATS command reply to the application.
280 typedef struct SilcClientStatsStruct {
281 SilcUInt32 starttime; /* SILC server start time */
282 SilcUInt32 uptime; /* SILC server uptime*/
283 SilcUInt32 my_clients; /* Number of clients in the server */
284 SilcUInt32 my_channels; /* Number of channel in the server */
285 SilcUInt32 my_server_ops; /* Number of server operators in the server */
286 SilcUInt32 my_router_ops; /* Number of router operators in the router */
287 SilcUInt32 cell_clients; /* Number of clients in the cell */
288 SilcUInt32 cell_channels; /* Number of channels in the cell */
289 SilcUInt32 cell_servers; /* Number of server in the cell */
290 SilcUInt32 clients; /* All clients in SILC network */
291 SilcUInt32 channels; /* All channels in SILC network */
292 SilcUInt32 servers; /* All servers in SILC network */
293 SilcUInt32 routers; /* All routers in SILC network */
294 SilcUInt32 server_ops; /* All server operators in SILC network */
295 SilcUInt32 router_ops; /* All router operators in SILC network */
299 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
303 * typedef enum { ... } SilcKeyAgreementStatus;
307 * Key agreement status types indicating the status of the key
308 * agreement protocol. These types are returned to the application
309 * in the SilcKeyAgreementCallback callback function.
314 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
315 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
316 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
317 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
318 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
319 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
320 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
321 SILC_KEY_AGREEMENT_NO_MEMORY, /* System out of memory */
322 } SilcKeyAgreementStatus;
325 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
329 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
330 * SilcClientConnection conn,
331 * SilcClientEntry client_entry,
332 * SilcKeyAgreementStatus status,
333 * SilcSKEKeyMaterial *key,
338 * Key agreement callback that is called after the key agreement protocol
339 * has been performed. This is called also if error occurred during the
340 * key agreement protocol. The `key' is the allocated key material and
341 * the caller is responsible of freeing it. The `key' is NULL if error
342 * has occurred. The application can freely use the `key' to whatever
343 * purpose it needs. See lib/silcske/silcske.h for the definition of
344 * the SilcSKEKeyMaterial structure.
347 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
348 SilcClientConnection conn,
349 SilcClientEntry client_entry,
350 SilcKeyAgreementStatus status,
351 SilcSKEKeyMaterial key,
354 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
358 * typedef struct { ... } SilcPrivateMessageKeys;
362 * Structure to hold the list of private message keys. The list of these
363 * structures is returned by the silc_client_list_private_message_keys
368 typedef struct SilcPrivateMessageKeysStruct {
369 SilcClientEntry client_entry; /* The remote client entry */
370 char *cipher; /* The cipher name */
371 unsigned char *key; /* The original key, If the appliation
372 provided it. This is NULL if
373 the SKE key material was used. */
374 SilcUInt32 key_len; /* The key length */
375 } *SilcPrivateMessageKeys;
378 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
382 * typedef struct SilcChannelPrivateKeyStruct { ... }
383 * *SilcChannelPrivateKey;
387 * Structure to hold one channel private key. The array of this structure
388 * is returned by silc_client_list_channel_private_keys function.
392 struct SilcChannelPrivateKeyStruct {
393 char *name; /* Application given name */
394 SilcCipher send_key; /* The cipher and key */
395 SilcCipher receive_key; /* The cipher and key */
396 SilcHmac hmac; /* The HMAC and hmac key */
400 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
404 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
405 * SilcUInt32 passphrase_len,
410 * Ask passphrase callback. This is called by the application when the
411 * library calls `ask_passphrase' client operation. The callback delivers
412 * the passphrase to the library. The passphrases in SILC protocol
413 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
414 * encoded, and if it is not then library will attempt to encode it.
417 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
418 SilcUInt32 passphrase_len,
421 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
425 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
429 * Public key (or certificate) verification callback. This is called
430 * by the application to indicate that the public key verification was
431 * either success or failure.
434 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
436 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
440 * typedef void (*SilcGetAuthMeth)(SilcBool success,
441 * SilcAuthMethod auth_meth,
442 * void *auth, SilcUInt32 auth_len,
447 * Authentication data resolving callback. This is called by the
448 * application to return the resolved authentication data. The client
449 * library has called the get_auth_method client operation and given
450 * this function pointer as argument. The `auth_meth' is the selected
451 * authentication method. The `auth_data' and the `auth_data_len'
452 * are the resolved authentication data. The `context' is the libary's
453 * context sent to the get_auth_method client operation.
455 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
456 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the
457 * `auth' must be NULL. The library will use the private key given as
458 * argument to silc_client_connect_to_server, silc_client_connect_to_client
459 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and
460 * `auth_len' are ignored.
463 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
464 void *auth, SilcUInt32 auth_len,
467 /****d* silcclient/SilcClientAPI/SilcClientMessageType
471 * typedef enum { ... } SilcClientMessageType;
475 * Different message types for `say' client operation. The application
476 * may filter the message sent by the library according this type.
481 SILC_CLIENT_MESSAGE_INFO, /* Informational */
482 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
483 SILC_CLIENT_MESSAGE_ERROR, /* Error */
484 SILC_CLIENT_MESSAGE_COMMAND_ERROR, /* Error during command */
485 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
486 } SilcClientMessageType;
489 /****s* silcclient/SilcClientAPI/SilcClientOperations
493 * typedef struct { ... } SilcClientOperations;
497 * SILC Client Operations. These must be implemented by the application.
498 * The Client library may call any of these routines at any time. The
499 * routines are used to deliver certain information to the application
500 * or from the application to the client library.
504 typedef struct SilcClientOperationsStruct {
505 /* Message sent to the application by library. `conn' associates the
506 message to a specific connection. `conn', however, may be NULL.
507 The `type' indicates the type of the message sent by the library.
508 The application can for example filter the message according the
509 type. The variable argument list is arguments to the formatted
510 message that `msg' may be. */
511 void (*say)(SilcClient client, SilcClientConnection conn,
512 SilcClientMessageType type, char *msg, ...);
514 /* Message for a channel. The `sender' is the sender of the message
515 The `channel' is the channel. The `message' is the message. Note
516 that `message' maybe NULL. The `flags' indicates message flags
517 and it is used to determine how the message can be interpreted
518 (like it may tell the message is multimedia message). The `payload'
519 may be used to retrieve all the details of the message. */
520 void (*channel_message)(SilcClient client, SilcClientConnection conn,
521 SilcClientEntry sender, SilcChannelEntry channel,
522 SilcMessagePayload payload,
523 SilcChannelPrivateKey key, SilcMessageFlags flags,
524 const unsigned char *message,
525 SilcUInt32 message_len);
527 /* Private message to the client. The `sender' is the sender of the
528 message. The message is `message'and maybe NULL. The `flags'
529 indicates message flags and it is used to determine how the message
530 can be interpreted (like it may tell the message is multimedia
531 message). The `payload' may be used to retrieve all the details of
533 void (*private_message)(SilcClient client, SilcClientConnection conn,
534 SilcClientEntry sender, SilcMessagePayload payload,
535 SilcMessageFlags flags, const unsigned char *message,
536 SilcUInt32 message_len);
538 /* Notify message to the client. The arguments are notify `type' specific.
539 See separate documentation in the Toolkit Reference Manual for the notify
541 void (*notify)(SilcClient client, SilcClientConnection conn,
542 SilcNotifyType type, ...);
544 /* Command handler. This function is called always after application has
545 called a command. It will be called to indicate that the command
546 was processed. It will also be called if error occurs while processing
547 the command. The `success' indicates whether the command was sent
548 or if error occurred. The `status' indicates the actual error.
549 The `argc' and `argv' are the command line arguments sent to the
550 command by application. Note that, this is not reply to the command
551 from server, this is merely and indication to application that the
552 command was processed. */
553 void (*command)(SilcClient client, SilcClientConnection conn,
554 SilcBool success, SilcCommand command, SilcStatus status,
555 SilcUInt32 argc, unsigned char **argv);
557 /* Command reply handler. Delivers a reply to command that was sent
558 earlier. The `conn' is the associated client connection. The `command'
559 indicates the command reply type. If the `status' other than
560 SILC_STATUS_OK an error occurred. In this case the `error' will indicate
561 the error. It is possible to receive list of command replies and list
562 of errors. In this case the `status' will indicate it is an list entry
563 (the `status' is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM and/or
564 SILC_STATUS_LIST_END).
566 The arguments received in `ap' are command specific. See a separate
567 documentation in the Toolkit Reference Manual for the command reply
569 void (*command_reply)(SilcClient client, SilcClientConnection conn,
570 SilcCommand command, SilcStatus status,
571 SilcStatus error, va_list ap);
573 /* Find authentication method and authentication data by hostname and
574 port. The hostname may be IP address as well. The `auth_method' is
575 the authentication method the remote connection requires. It is
576 however possible that remote accepts also some other authentication
577 method. Application should use the method that may have been
578 configured for this connection. If none has been configured it should
579 use the required `auth_method'. If the `auth_method' is
580 SILC_AUTH_NONE, server does not require any authentication or the
581 required authentication method is not known. The `completion'
582 callback must be called to deliver the chosen authentication method
583 and data. The `conn' may be NULL. */
584 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
585 char *hostname, SilcUInt16 port,
586 SilcAuthMethod auth_method,
587 SilcGetAuthMeth completion, void *context);
589 /* Called to verify received public key. The `conn_type' indicates which
590 entity (server or client) has sent the public key. If user decides to
591 trust the key the application may save the key as trusted public key for
592 later use. The `completion' must be called after the public key has
594 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
595 SilcConnectionType conn_type,
596 SilcPublicKey public_key,
597 SilcVerifyPublicKey completion, void *context);
599 /* Ask from end user a passphrase or a password. The passphrase is
600 returned to the library by calling the `completion' callback with
601 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
602 if not then the library will attempt to encode. */
603 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
604 SilcAskPassphrase completion, void *context);
606 /* Called to indicate that incoming key agreement request has been
607 received. If the application wants to perform key agreement it may
608 call silc_client_perform_key_agreement to initiate key agreement or
609 silc_client_send_key_agreement to provide connection point to the
610 remote client in case the `hostname' is NULL. If key agreement is
611 not desired this request can be ignored. The `protocol' is either
612 value 0 for TCP or value 1 for UDP. */
613 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
614 SilcClientEntry client_entry,
615 const char *hostname, SilcUInt16 protocol,
618 /* Notifies application that file transfer protocol session is being
619 requested by the remote client indicated by the `client_entry' from
620 the `hostname' and `port'. The `session_id' is the file transfer
621 session and it can be used to either accept or reject the file
622 transfer request, by calling the silc_client_file_receive or
623 silc_client_file_close, respectively. */
624 void (*ftp)(SilcClient client, SilcClientConnection conn,
625 SilcClientEntry client_entry, SilcUInt32 session_id,
626 const char *hostname, SilcUInt16 port);
627 } SilcClientOperations;
630 /****s* silcclient/SilcClientAPI/SilcClientParams
634 * typedef struct { ... } SilcClientParams;
638 * Client parameters. This can be filled with proper values and
639 * given as argument to the silc_client_alloc function. The structure
640 * hold various parameters which affects the function of the client.
644 typedef struct SilcClientParamsStruct {
645 /* If this boolean is set to TRUE then the client library will use
646 threads. Any of the callback functions in the SilcClientOperations
647 and other callbacks may be called at any time in a thread. The
648 application may need to employ appropriate concurrency control
649 in the callbacks to protect application specific data. */
652 /* Nickname format string. This can be used to order the client library
653 to save the nicknames in the library in a certain format. Since
654 nicknames are not unique in SILC it is possible to have multiple same
655 nicknames. Using this format string it is possible to order the library
656 to separate the multiple same nicknames from each other. If this is
657 empty then default format is used which is the default nickname
658 without anything else. The string MUST be NULL terminated.
660 Following format types are available:
662 %n nickname - the real nickname returned by the server (mandatory)
663 %a number - ascending number in case there are several
664 same nicknames (fe. nick#2 and nick#3)
665 %h hostname - the stripped hostname of the client
666 %H full hostname - the full hostname of the client
668 Example format strings: "%n#%a" (fe. nick#2, nick#3)
669 "%n@%h%a" (fe. nick@host, nick@host2)
670 "%a!%n@%h" (fe. nick@host, 2!nick@host)
672 Note that there must always be some separator characters around '%n'
673 format. It is not possible to put format characters before or after
674 '%n' without separators (such ash '#'). Also note that the separator
675 character should be a character that cannot be part of normal nickname.
677 char nickname_format[32];
679 /* If this is set to TRUE then the `nickname_format' is employed to all
680 saved nicknames even if there are no multiple same nicknames in the
681 cache. By default this is FALSE, which means that the `nickname_format'
682 is employed only if the library will receive a nickname that is
683 already saved in the cache. It is recommended to leave this to FALSE
685 SilcBool nickname_force_format;
687 /* If this is set to TRUE, the silcclient library will not register and
688 deregister the cipher, pkcs, hash and hmac algorithms. The application
689 itself will need to handle that. */
690 SilcBool dont_register_crypto_library;
696 /* Initialization functions (client.c) */
698 /****f* silcclient/SilcClientAPI/silc_client_alloc
702 * SilcClient silc_client_alloc(SilcClientOperations *ops,
703 * SilcClientParams *params,
705 * const char *silc_version);
709 * Allocates new client object. This has to be done before client may
710 * work. After calling this one must call silc_client_init to initialize
711 * the client. The `application' is application specific user data pointer
712 * and caller must free it. The `silc_version' is the application version
713 * that will be used to compare against remote host's (usually a server)
714 * version string. The `application' context is accessible by the
715 * application by client->application, client being SilcClient.
718 SilcClient silc_client_alloc(SilcClientOperations *ops,
719 SilcClientParams *params,
721 const char *version_string);
723 /****f* silcclient/SilcClientAPI/silc_client_free
727 * void silc_client_free(SilcClient client);
731 * Frees client object and its internals. The execution of the client
732 * should be stopped with silc_client_stop function before calling
736 void silc_client_free(SilcClient client);
738 /****f* silcclient/SilcClientAPI/silc_client_init
742 * SilcBool silc_client_init(SilcClient client, const char *username,
743 * const char *hostname, const char *realname,
744 * SilcClientRunning running, void *context);
748 * Initializes the client. This makes all the necessary steps to make
749 * the client ready to be run. One must call silc_client_run to run the
750 * client. Returns FALSE if error occurred, TRUE otherwise.
752 * The `username' and `hostname' strings must be given and they must be
753 * UTF-8 encoded. The `username' is the client's username in the
754 * operating system, `hostname' is the client's host name and the
755 * `realname' is the user's real name.
757 * The `running' callback with `context' is called after the client is
758 * running after silc_client_run or silc_client_run_one has been called.
759 * Application may start using the Client library API after that. Setting
760 * the callback is optional, but highly recommended.
763 SilcBool silc_client_init(SilcClient client, const char *username,
764 const char *hostname, const char *realname,
765 SilcClientRunning running, void *context);
767 /****f* silcclient/SilcClientAPI/silc_client_run
771 * void silc_client_run(SilcClient client);
775 * Runs the client. This starts the scheduler from the utility library.
776 * When this functions returns the execution of the application is over.
777 * The client must be initialized before calling this.
780 void silc_client_run(SilcClient client);
782 /****f* silcclient/SilcClientAPI/silc_client_run_one
786 * void silc_client_run_one(SilcClient client);
790 * Runs the client and returns immeadiately. This function is used when
791 * the SILC Client object indicated by the `client' is run under some
792 * other scheduler, or event loop or main loop. On GUI applications,
793 * for example this may be desired to used to run the client under the
794 * GUI application's main loop. Typically the GUI application would
795 * register an idle task that calls this function multiple times in
796 * a second to quickly process the SILC specific data.
799 void silc_client_run_one(SilcClient client);
801 /****f* silcclient/SilcClientAPI/silc_client_stop
805 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
810 * Stops the client. This is called to stop the client and thus to stop
811 * the program. The client context must be freed with the silc_client_free
812 * function. All connections that exist in this client must be closed
813 * before calling this function. Connections can be closed by calling
814 * silc_client_close_connection.
816 * The `stopped' will be called once the client and all connections have
817 * finished. The client may be freed after that. Note that the `stopped'
818 * won't be called before all connections have finished. Setting the
819 * callback is optional.
822 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
825 /* Connecting functions */
827 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
831 * typedef struct { ... } SilcClientConnectionParams;
835 * Client connection parameters. This can be filled by the application
836 * and given as argument to silc_client_connect_to_server,
837 * silc_client_connect_to_client, silc_client_key_exchange or
838 * silc_client_send_key_agreement.
842 typedef struct SilcClientConnectionParamsStruct {
843 /* If this is provided the user's nickname in the network will be the
844 string given here. If it is given, it must be UTF-8 encoded. If this
845 string is not given, the user's username by default is used as nickname.
846 The nickname may later be changed by using NICK command. The maximum
847 length for the nickname string is 128 bytes. */
850 /* If this key repository pointer is non-NULL then public key received in
851 the key exchange protocol will be verified from this repository. If
852 this is not provided then the `verify_public_key' client operation will
853 be called back to application. If the boolean `verify_notfound' is set
854 to TRUE then the `verify_public_key' client operation will be called
855 in case the public key is not found in `repository'. Only public keys
856 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
857 be checked, other keys will be ignored. */
859 SilcBool verify_notfound;
861 /* Authentication data. Application may set here the authentication data
862 and authentication method to be used in connecting. If `auth_set'
863 boolean is TRUE then authentication data is provided by application.
864 If the authentication method is public key authentication then the key
865 pair given as argument when connecting will be used and `auth' field
866 is NULL. If it is passphrase authentication, it can be provided in
867 `auth' and `auth_len' fields. If `auth_set' is FALSE
868 the `get_auth_method' client operation will be called to get the
869 authentication method and data from application. */
871 SilcAuthMethod auth_method;
875 /* If this boolean is set to TRUE then the connection will use UDP instead
876 of TCP. If UDP is set then also the next `local_ip' and `local_port'
880 /* The `local_ip' specifies the local IP address used with the connection.
881 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
882 non-zero it will be used as local port with UDP connection. The remote
883 host will also send packets to the specified address and port. If the
884 `bind_ip' is non-NULL a listener is bound to that address instead of
890 /* If this boolean is set to TRUE then the key exchange is done with
891 perfect forward secrecy. */
894 /* If this boolean is set to TRUE then connection authentication protocol
895 is not performed during connecting. Only key exchange protocol is
896 performed. This usually must be set to TRUE when connecting to another
897 client, but must be FALSE with server connections. */
898 SilcBool no_authentication;
900 /* The SILC session detachment data that was returned in the `command_reply'
901 client operation for SILC_COMMAND_DETACH command. If this is provided
902 here the client library will attempt to resume the session in the network.
903 After the connection is created and the session has been resumed the
904 client will receive SILC_COMMAND_NICK command_reply for the client's
905 nickname in the network and SILC_COMMAND_JOIN command reply for all the
906 channels that the client has joined in the network. It may also receive
907 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
908 unsigned char *detach_data;
909 SilcUInt32 detach_data_len;
911 /* Connection timeout. If non-zero, the connection will timeout unless
912 the SILC connection is completed in the specified amount of time. */
913 SilcUInt32 timeout_secs;
915 /* Rekey timeout in seconds. The client will perform rekey in this
916 time interval. If set to zero, the default value will be used
917 (3600 seconds, 1 hour). */
918 SilcUInt32 rekey_secs;
920 /* If this is set to TRUE then the client will ignore all incoming
921 Requested Attributes queries and does not reply anything back. This
922 usually leads into situation where server does not anymore send
923 the queries after seeing that client does not reply anything back.
924 If your application does not support Requested Attributes or you do
925 not want to use them set this to TRUE. See SilcAttribute and
926 silc_client_attribute_add for more information on attributes. */
927 SilcBool ignore_requested_attributes;
929 } SilcClientConnectionParams;
932 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
937 * silc_client_connect_to_server(SilcClient client,
938 * SilcClientConnectionParams *params,
939 * SilcPublicKey public_key,
940 * SilcPrivateKey private_key,
941 * char *remote_host, int port,
942 * SilcClientConnectCallback callback,
947 * Connects to remote server `remote_host' at port `port'. This function
948 * can be used to create connection to remote SILC server and start
949 * SILC session in the SILC network. The `params' may be provided
950 * to provide various connection parameters. The `public_key' and the
951 * `private_key' is your identity used in this connection. When
952 * authentication method is based on digital signatures, this key pair
953 * will be used. The `callback' with `context' will be called after the
954 * connection has been created. It will also be called later when remote
957 * If application wishes to create the network connection itself, use
958 * the silc_client_key_exchange after creating the connection to start
959 * key exchange and authentication with the server.
961 * Returns SilcAsyncOperation which can be used to cancel the connecting,
962 * or NULL on error. Note that the returned pointer becomes invalid
963 * after the `callback' is called.
967 silc_client_connect_to_server(SilcClient client,
968 SilcClientConnectionParams *params,
969 SilcPublicKey public_key,
970 SilcPrivateKey private_key,
971 char *remote_host, int port,
972 SilcClientConnectCallback callback,
975 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
980 * silc_client_connect_to_client(SilcClient client,
981 * SilcClientConnectionParams *params,
982 * SilcPublicKey public_key,
983 * SilcPrivateKey private_key,
984 * char *remote_host, int port,
985 * SilcClientConnectCallback callback,
990 * Connects to remote client `remote_host' at port `port'. This function
991 * can be used to create peer-to-peer connection to another SILC client,
992 * for example, for direct conferencing, or file transfer or for other
993 * purposes. The `params' may be provided to provide various connection
994 * parameters. The `public_key' and the `private_key' is your identity
995 * used in this connection. The `callback' with `context' will be called
996 * after the connection has been created. It will also be called later
997 * when remote host disconnects.
999 * If application wishes to create the network connection itself, use
1000 * the silc_client_key_exchange after creating the connection to start
1001 * key exchange with the client.
1003 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1004 * or NULL on error. Note that the returned pointer becomes invalid
1005 * after the `callback' is called.
1009 silc_client_connect_to_client(SilcClient client,
1010 SilcClientConnectionParams *params,
1011 SilcPublicKey public_key,
1012 SilcPrivateKey private_key,
1013 char *remote_host, int port,
1014 SilcClientConnectCallback callback,
1017 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1021 * SilcAsyncOperation
1022 * silc_client_key_exchange(SilcClient client,
1023 * SilcClientConnectionParams *params,
1024 * SilcPublicKey public_key,
1025 * SilcPrivateKey private_key,
1026 * SilcStream stream,
1027 * SilcConnectionType conn_type,
1028 * SilcClientConnectCallback callback,
1033 * Starts key exchange protocol and authentication protocol in the
1034 * connection indicated by `stream'. This function can be be used to
1035 * start SILC session with remote host (usually server) when the caller
1036 * has itself created the connection, instead of calling the function
1037 * silc_client_connect_to_server or silc_client_connect_to_client. If
1038 * one of those functions was used this function must not be called as
1039 * in that case the key exchange is performed automatically.
1041 * Use this function only if you have created the connection by yourself.
1042 * After creating the connection the socket must be wrapped into a
1043 * socket stream. See silcsocketstream.h for more information. Note that
1044 * the `stream' must have valid remote IP address (and optionally also
1045 * hostname) and port set.
1047 * The `params' may be provided to provide various connection parameters.
1048 * The `public_key' and the `private_key' is your identity used in this
1049 * session. The `callback' with `context' will be called after the session
1050 * has been set up. It will also be called later when remote host
1051 * disconnects. The `conn_type' is the type of session this is going to
1052 * be. If the remote is SILC server it is SILC_CONN_SERVER or if it is
1053 * SILC client it is SILC_CONN_CLIENT.
1055 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1056 * or NULL on error. Note that the returned pointer becomes invalid
1057 * after the `callback' is called.
1063 * // Create remote connection stream. Resolve hostname and IP also.
1064 * sock = create_connection(remote_host, port);
1065 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1066 * stream_create_cb, app);
1068 * // Stream callback delivers our new SilcStream context
1069 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1073 * if (status != SILC_SOCKET_OK)
1076 * // Start key exchange
1077 * silc_client_key_exchange(client, NULL, public_key, private_key,
1078 * stream, SILC_CONN_SERVER, connection_cb, app);
1084 silc_client_key_exchange(SilcClient client,
1085 SilcClientConnectionParams *params,
1086 SilcPublicKey public_key,
1087 SilcPrivateKey private_key,
1089 SilcConnectionType conn_type,
1090 SilcClientConnectCallback callback,
1093 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1097 * void silc_client_close_connection(SilcClient client,
1098 * SilcClientConnection conn);
1102 * Closes the remote connection `conn'. The `conn' will become invalid
1103 * after this call. Usually this function is called only when explicitly
1104 * closing connection for example in case of error, or when the remote
1105 * connection was created by the application or when the remote is client
1106 * connection. Server connections are usually closed by sending QUIT
1107 * command to the server. However, this call may also be used.
1110 void silc_client_close_connection(SilcClient client,
1111 SilcClientConnection conn);
1113 /* Message sending functions */
1115 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1119 * SilcBool silc_client_send_channel_message(SilcClient client,
1120 * SilcClientConnection conn,
1121 * SilcChannelEntry channel,
1122 * SilcChannelPrivateKey key,
1123 * SilcMessageFlags flags,
1125 * unsigned char *data,
1126 * SilcUInt32 data_len);
1130 * Sends encrypted message to the `channel'. The plaintext message is
1131 * the `data' of `data_len' bytes in length.
1133 * If `key' is provided then that private channel message key is used to
1134 * encrypt the message. If it is not provided and the `channel' does not
1135 * have SILC_CHANNEL_MODE_PRIVKEY set, the curent channel key is used
1136 * instead. If the mode is set but `key' is NULL the key that was added
1137 * first as private channel message key will be used.
1139 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1140 * digitally signed with the SILC key pair associated with the `conn'.
1141 * In this case the `hash' pointer must be provided as well.
1143 * Returns TRUE if the message was sent, and FALSE if error occurred or
1144 * the sending is not allowed due to channel modes (like sending is
1145 * blocked). This function is thread safe and private messages can be
1146 * sent from multiple threads.
1149 SilcBool silc_client_send_channel_message(SilcClient client,
1150 SilcClientConnection conn,
1151 SilcChannelEntry channel,
1152 SilcChannelPrivateKey key,
1153 SilcMessageFlags flags,
1155 unsigned char *data,
1156 SilcUInt32 data_len);
1158 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1162 * SilcBool silc_client_send_private_message(SilcClient client,
1163 * SilcClientConnection conn,
1164 * SilcClientEntry client_entry,
1165 * SilcMessageFlags flags,
1167 * unsigned char *data,
1168 * SilcUInt32 data_len);
1172 * Sends private message to remote client. If private message key has
1173 * not been set with this client then the message will be encrypted using
1174 * the session keys used in `conn' connection. If the `flags' includes
1175 * SILC_MESSAGE_FLAG_SIGNED the message will be digitally signed with the
1176 * SILC key pair associated with `conn'. In this case the caller must also
1177 * provide the `hash' pointer.
1179 * Returns TRUE if the message was sent, and FALSE if error occurred.
1180 * This function is thread safe and private messages can be sent from
1184 SilcBool silc_client_send_private_message(SilcClient client,
1185 SilcClientConnection conn,
1186 SilcClientEntry client_entry,
1187 SilcMessageFlags flags,
1189 unsigned char *data,
1190 SilcUInt32 data_len);
1192 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init
1197 * silc_client_private_message_wait_init(SilcClient client,
1198 * SilcClientConnection conn,
1199 * SilcClientEntry client_entry);
1203 * Initializes private message waiting functionality for the client
1204 * indicated by `client_entry'. Once this is called private message
1205 * from remote connection indicated by `conn' for `client_entry' may
1206 * be waiter for, for example in a thread. The function
1207 * silc_client_private_message_wait is used to block the current thread
1208 * until a private message is received from a specified client entry.
1209 * Return FALSE in case an internal error occurred.
1212 SilcBool silc_client_private_message_wait_init(SilcClient client,
1213 SilcClientConnection conn,
1214 SilcClientEntry client_entry);
1216 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit
1221 * silc_client_private_message_wait_uninit(SilcClient client,
1222 * SilcClientConnection conn,
1223 * SilcClientEntry client_entry);
1227 * Unintializes private message waiting for client indicated by
1228 * `client_entry'. After this call private message cannot be waited
1229 * anymore and silc_client_private_message_wait will return with FALSE
1233 void silc_client_private_message_wait_uninit(SilcClient client,
1234 SilcClientConnection conn,
1235 SilcClientEntry client_entry);
1237 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait
1242 * silc_client_private_message_wait(SilcClient client,
1243 * SilcClientConnection conn,
1244 * SilcClientEntry client_entry,
1245 * SilcMessagePayload *payload);
1249 * Blocks current thread or process until a private message has been
1250 * received from the remote client indicated by `client_entry'. Before
1251 * private messages can be waited the silc_client_private_message_wait_init
1252 * must be called. This function can be used from a thread to wait for
1253 * private message from the specified client. Multiple threads can be
1254 * created to wait messages from multiple clients. Any other private
1255 * message received from the connection indicated by `conn' will be
1256 * forwarded to the normal `private_message' client operation callback.
1257 * The private messages from `client_entry' will not be delivered to the
1258 * `private_message' client operation callback.
1260 * Returns TRUE and the received private message into `payload'. The caller
1261 * must free the returned SilcMessagePayload. If this function returns
1262 * FALSE the private messages cannot be waited anymore. This happens
1263 * when some other thread calls silc_client_private_message_wait_uninit.
1264 * This returns FALSE also if silc_client_private_message_wait_init has
1268 SilcBool silc_client_private_message_wait(SilcClient client,
1269 SilcClientConnection conn,
1270 SilcClientEntry client_entry,
1271 SilcMessagePayload *payload);
1273 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1277 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1278 * SilcClientEntry client_entry);
1282 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1283 * channel indicated by the `channel'. NULL if client is not joined on
1287 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1288 SilcClientEntry client_entry);
1291 /* Command management */
1293 /****f* silcclient/SilcClientAPI/silc_client_command_call
1297 * SilcUInt16 silc_client_command_call(SilcClient client,
1298 * SilcClientConnection conn,
1299 * const char *command_line, ...);
1303 * Calls and executes the command indicated by the `command_name'.
1304 * The `command_line' is a string which includes the command's name and
1305 * its arguments separated with whitespaces (' '). If `command_line'
1306 * is non-NULL then all variable arguments are ignored by default.
1308 * If `command_line' is NULL, then the variable arguments define the
1309 * command's name and its arguments. The first variable argument must
1310 * be the command name. The variable argument list must be terminated
1313 * Returns FALSE if the command is not known and TRUE after command.
1314 * execution. The `command' client operation callback will be called when
1315 * the command is executed to indicate whether or not the command executed
1318 * The `command_reply' client operation callbak will be called when reply
1319 * is received from the server to the command. Application may also use
1320 * the silc_client_command_pending to attach to the command reply.
1321 * The command identifier for silc_client_command_pending function after
1322 * this function call is conn->cmd_ident, which application may use.
1326 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1328 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1332 * This command executes the commands implemented inside the client
1333 * library. These commands are designed for command line applications,
1334 * but GUI application may call them too if needed. Alternatively
1335 * application may override the library and use silc_client_command_send
1339 SilcUInt16 silc_client_command_call(SilcClient client,
1340 SilcClientConnection conn,
1341 const char *command_line, ...);
1343 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1347 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1348 * SilcClientConnection conn,
1349 * SilcCommand command,
1350 * SilcStatus status,
1357 * The command reply callback function given as argument to functions
1358 * silc_client_command_send and silc_client_command_pending. This is
1359 * called to deliver the command replies to the caller. Each command
1360 * reply received from the server to the `command' will be delivered
1361 * separately to the caller by calling this callback. The `status' will
1362 * indicate whether there is only one reply or multiple replies. The
1363 * `error' will indicate if an error occurred. The `ap' will include
1364 * command reply arguments. They are the same arguments as for
1365 * `command_reply' client operation callback in SilcClientOperations.
1367 * If `status' is SILC_STATUS_OK only one reply was received and error
1368 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1369 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1370 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1372 * If FALSE is returned in this function this callback will not be called
1373 * again for `command' even if there are more comand replies. By returning
1374 * FALSE the caller my stop the command reply handling when needed.
1377 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1378 SilcClientConnection conn,
1379 SilcCommand command,
1385 /****f* silcclient/SilcClientAPI/silc_client_command_send
1389 * SilcUInt16 silc_client_command_send(SilcClient client,
1390 * SilcClientConnection conn,
1391 * SilcCommand command,
1392 * SilcClientCommandReply reply,
1393 * void *reply_context,
1394 * SilcUInt32 argc, ...);
1398 * Generic function to send any command. The arguments must be given
1399 * already encoded into correct format and in correct order. If application
1400 * wants to perform the commands by itself, it can do so and send the data
1401 * directly to the server using this function. If application is using
1402 * the silc_client_command_call, this function is usually not used.
1403 * Programmer should get familiar with the SILC protocol commands
1404 * specification when using this function, as the arguments needs to
1405 * be encoded as specified in the protocol.
1407 * The variable arguments are a set of { type, data, data_length },
1408 * and the `argc' is the number of these sets.
1410 * The `reply' callback must be provided, and it is called when the
1411 * command reply is received from the server. Note that, when using this
1412 * function the default `command_reply' client operation callback will not
1413 * be called when reply is received.
1415 * Returns command identifier for this sent command. It can be used
1416 * to additionally attach to the command reply using the function
1417 * silc_client_command_pending, if needed. Returns 0 on error.
1421 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1422 * my_whois_command_reply, cmd_ctx,
1423 * 1, 1, nickname, strlen(nickname));
1426 SilcUInt16 silc_client_command_send(SilcClient client,
1427 SilcClientConnection conn,
1428 SilcCommand command,
1429 SilcClientCommandReply reply,
1430 void *reply_context,
1431 SilcUInt32 argc, ...);
1433 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1437 * void silc_client_command_pending(SilcClientConnection conn,
1438 * SilcCommand command,
1439 * SilcUInt16 cmd_ident,
1440 * SilcClientCommandReply reply,
1445 * This function can be used to add pending command callback to be
1446 * called when an command reply is received to an earlier sent command.
1447 * The `command' is the command that must be received in order for
1448 * the pending command callback indicated by `callback' to be called.
1450 * The `cmd_ident' is a command identifier which was set for the earlier
1451 * sent command. The command reply will include the same identifier
1452 * and pending command callback will be called when the reply is
1453 * received with the same command identifier. It is possible to
1454 * add multiple pending command callbacks for same command and for
1457 * Application may use this function to add its own command reply
1458 * handlers if it wishes not to use the standard `command_reply'
1461 * Note also that the application is notified about the received command
1462 * reply through the `command_reply' client operation before calling
1463 * the `callback` pending command callback. That is the normal
1464 * command reply handling, and is called regardless whether pending
1465 * command callbacks are used or not.
1469 * SilcUInt16 cmd_ident;
1470 * cmd_ident = silc_client_command_call(client, conn,
1471 * "PING silc.silcnet.org");
1472 * silc_client_command_pending(conn, SILC_COMMAND_PING, cmd_ident,
1473 * my_ping_handler, my_ping_context);
1476 SilcBool silc_client_command_pending(SilcClientConnection conn,
1477 SilcCommand command,
1478 SilcUInt16 cmd_ident,
1479 SilcClientCommandReply reply,
1483 /* Private Message key management */
1485 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1490 * silc_client_add_private_message_key(SilcClient client,
1491 * SilcClientConnection conn,
1492 * SilcClientEntry client_entry,
1493 * const char *cipher,
1495 * unsigned char *key,
1496 * SilcUInt32 key_len);
1500 * Adds a static private message key to the client library. The key
1501 * will be used to encrypt all private message between the client and
1502 * the remote client indicated by the `client_entry'. The `key' can
1503 * be for example a pre-shared-key, passphrase or similar shared secret
1504 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1505 * to assure that the requirements of the SILC protocol are met. The
1506 * API, however, allows to allocate any cipher and HMAC.
1508 * If the private message key is added to client without first receiving
1509 * a request for it from the remote `client_entry' this function will
1510 * send the request to `client_entry'. Note that, the actual key is
1511 * not sent to the network.
1513 * It is not necessary to set key for normal private message usage. If the
1514 * key is not set then the private messages are encrypted using normal
1515 * session keys. Setting the private key, however, increases security.
1517 * Returns FALSE if the key is already set for the `client_entry', TRUE
1521 SilcBool silc_client_add_private_message_key(SilcClient client,
1522 SilcClientConnection conn,
1523 SilcClientEntry client_entry,
1527 SilcUInt32 key_len);
1529 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1534 * silc_client_add_private_message_key_ske(SilcClient client,
1535 * SilcClientConnection conn,
1536 * SilcClientEntry client_entry,
1537 * const char *cipher,
1539 * SilcSKEKeyMaterial key);
1543 * Same as silc_client_add_private_message_key but takes the key material
1544 * from the SKE key material structure. This structure is received if
1545 * the application uses the silc_client_send_key_agreement to negotiate
1546 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1547 * negotiated also in the SKE protocol.
1550 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1551 SilcClientConnection conn,
1552 SilcClientEntry client_entry,
1555 SilcSKEKeyMaterial key);
1557 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1562 * silc_client_del_private_message_key(SilcClient client,
1563 * SilcClientConnection conn,
1564 * SilcClientEntry client_entry);
1568 * Removes the private message from the library. The key won't be used
1569 * after this to protect the private messages with the remote `client_entry'
1570 * client. Returns FALSE on error, TRUE otherwise.
1573 SilcBool silc_client_del_private_message_key(SilcClient client,
1574 SilcClientConnection conn,
1575 SilcClientEntry client_entry);
1577 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1581 * SilcPrivateMessageKeys
1582 * silc_client_list_private_message_keys(SilcClient client,
1583 * SilcClientConnection conn,
1584 * SilcUInt32 *key_count);
1588 * Returns array of set private message keys associated to the connection
1589 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1590 * count to the `key_count' argument. The array must be freed by the caller
1591 * by calling the silc_client_free_private_message_keys function. Note:
1592 * the keys returned in the array is in raw format. It might not be desired
1593 * to show the keys as is. The application might choose not to show the keys
1594 * at all or to show the fingerprints of the keys.
1597 SilcPrivateMessageKeys
1598 silc_client_list_private_message_keys(SilcClient client,
1599 SilcClientConnection conn,
1600 SilcUInt32 *key_count);
1602 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1606 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1607 * SilcUInt32 key_count);
1611 * Frees the SilcPrivateMessageKeys array returned by the function
1612 * silc_client_list_private_message_keys.
1615 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1616 SilcUInt32 key_count);
1618 /****f* silcclient/SilcClientAPI/silc_client_private_message_key_is_set
1623 * silc_client_private_message_key_is_set(SilcClient client,
1624 * SilcClientConnection conn,
1625 * SilcClientEntry client_entry);
1629 * Returns TRUE if the private message key has been set for the client
1630 * entry indicated by `client_entry'.
1634 silc_client_private_message_key_is_set(SilcClient client,
1635 SilcClientConnection conn,
1636 SilcClientEntry client_entry);
1639 /* Channel private key management */
1641 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1646 * silc_client_add_channel_private_key(SilcClient client,
1647 * SilcClientConnection conn,
1648 * SilcChannelEntry channel,
1652 * unsigned char *key,
1653 * SilcUInt32 key_len,
1654 * SilcChannelPrivateKey *ret_key);
1658 * Adds private key for channel. When channel has private key then the
1659 * messages are encrypted using that key. All clients on the channel
1660 * must also know the key in order to decrypt the messages. However,
1661 * it is possible to have several private keys per one channel. In this
1662 * case only some of the clients on the channel may know the one key
1663 * and only some the other key. The `name' can be application given
1664 * name for the key. This returns the created key to the 'ret_key'
1665 * pointer if it is non-NULL;
1667 * If `cipher' and/or `hmac' is NULL then default values will be used
1668 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1670 * The private key for channel is optional. If it is not set then the
1671 * channel messages are encrypted using the channel key generated by the
1672 * server. However, setting the private key (or keys) for the channel
1673 * significantly adds security. If more than one key is set the library
1674 * will automatically try all keys at the message decryption phase. Note:
1675 * setting many keys slows down the decryption phase as all keys has to
1676 * be tried in order to find the correct decryption key. However, setting
1677 * a few keys does not have big impact to the decryption performace.
1681 * NOTE: This is entirely local setting. The key set using this function
1682 * is not sent to the network at any phase.
1684 * NOTE: If the key material was originated by the SKE protocol (using
1685 * silc_client_send_key_agreement) then the `key' MUST be the
1686 * key->send_enc_key as this is dictated by the SILC protocol. However,
1687 * currently it is not expected that the SKE key material would be used
1688 * as channel private key. However, this API allows it.
1691 SilcBool silc_client_add_channel_private_key(SilcClient client,
1692 SilcClientConnection conn,
1693 SilcChannelEntry channel,
1699 SilcChannelPrivateKey *ret_key);
1701 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1705 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1706 * SilcClientConnection conn,
1707 * SilcChannelEntry channel);
1711 * Removes all private keys from the `channel'. The old channel key is used
1712 * after calling this to protect the channel messages. Returns FALSE on
1713 * on error, TRUE otherwise.
1716 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1717 SilcClientConnection conn,
1718 SilcChannelEntry channel);
1720 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1724 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1725 * SilcClientConnection conn,
1726 * SilcChannelEntry channel,
1727 * SilcChannelPrivateKey key);
1731 * Removes and frees private key `key' from the channel `channel'.
1732 * The `key' is retrieved by calling the function
1733 * silc_client_list_channel_private_keys. The key is not used after
1734 * this. If the key was last private key then the old channel key is
1735 * used hereafter to protect the channel messages. This returns FALSE
1736 * on error, TRUE otherwise.
1739 SilcBool silc_client_del_channel_private_key(SilcClient client,
1740 SilcClientConnection conn,
1741 SilcChannelEntry channel,
1742 SilcChannelPrivateKey key);
1744 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1749 * silc_client_list_channel_private_keys(SilcClient client,
1750 * SilcClientConnection conn,
1751 * SilcChannelEntry channel);
1755 * Returns list of private keys associated to the `channel'. The caller
1756 * must free the returned list with silc_dlist_uninit. The pointers in
1757 * the list may be used to delete the specific key by giving the pointer
1758 * as argument to the function silc_client_del_channel_private_key. Each
1759 * entry in the list is SilcChannelPrivateKey.
1762 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1763 SilcClientConnection conn,
1764 SilcChannelEntry channel);
1766 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1770 * void silc_client_current_channel_private_key(SilcClient client,
1771 * SilcClientConnection conn,
1772 * SilcChannelEntry channel,
1773 * SilcChannelPrivateKey key);
1777 * Sets the `key' to be used as current channel private key on the
1778 * `channel'. Packet sent after calling this function will be secured
1782 void silc_client_current_channel_private_key(SilcClient client,
1783 SilcClientConnection conn,
1784 SilcChannelEntry channel,
1785 SilcChannelPrivateKey key);
1788 /* Key Agreement routines */
1790 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1794 * void silc_client_send_key_agreement(SilcClient client,
1795 * SilcClientConnection conn,
1796 * SilcClientEntry client_entry,
1797 * SilcClientConnectionParams *params,
1798 * SilcPublicKey public_key,
1799 * SilcPrivateKey private_key,
1800 * SilcKeyAgreementCallback completion,
1805 * Sends key agreement request to the remote client indicated by the
1808 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1809 * the caller will provide the connection endpoint for the key agreement
1810 * connection. The `bind_ip' can be used to bind to that IP instead of
1811 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1812 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1813 * and `timeout_secs' fields in `params'. Other fields are ignored.
1814 * If `params' is NULL, then the `client_entry' is expected to provide
1815 * the connection endpoint for us. It is recommended the `timeout_secs'
1816 * is specified in case the remote client does not reply anything to
1819 * The `public_key' and `private_key' is our identity in the key agreement.
1821 * In case we do not provide the connection endpoint, we will receive
1822 * the `key_agreement' client operation when the remote send its own
1823 * key agreement request packet. We may then there start the key
1824 * agreement with silc_client_perform_key_agreement. If we provided the
1825 * the connection endpoint, the client operation will not be called.
1827 * There can be only one active key agreement for `client_entry'. Old
1828 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1832 * // Send key agreement request (we don't provide connection endpoint)
1833 * silc_client_send_key_agreement(client, conn, remote_client,
1834 * NULL, public_key, private_key,
1835 * my_keyagr_completion, my_context);
1837 * // Another example where we provide connection endpoint (TCP).
1838 * SilcClientConnectionParams params;
1839 * memset(¶ms, 0, sizeof(params));
1840 * params.local_ip = local_ip;
1841 * params.local_port = local_port;
1842 * params.timeout_secs = 60;
1843 * silc_client_send_key_agreement(client, conn, remote_client,
1844 * ¶ms, public_key, private_key,
1845 * my_keyagr_completion, my_context);
1848 void silc_client_send_key_agreement(SilcClient client,
1849 SilcClientConnection conn,
1850 SilcClientEntry client_entry,
1851 SilcClientConnectionParams *params,
1852 SilcPublicKey public_key,
1853 SilcPrivateKey private_key,
1854 SilcKeyAgreementCallback completion,
1857 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1862 * silc_client_perform_key_agreement(SilcClient client,
1863 * SilcClientConnection conn,
1864 * SilcClientEntry client_entry,
1865 * SilcClientConnectionParams *params,
1866 * SilcPublicKey public_key,
1867 * SilcPrivateKey private_key,
1868 * char *hostname, int port,
1869 * SilcKeyAgreementCallback completion,
1874 * Performs the key agreement protocol. Application may use this to
1875 * initiate the key agreement protocol. Usually this is called after
1876 * receiving the `key_agreement' client operation.
1878 * The `hostname' is the remote hostname (or IP address) and the `port'
1879 * is the remote port. The `completion' callback with the `context' will
1880 * be called after the key agreement protocol.
1882 * The `params' is connection parameters and it may be used to define
1883 * the key agreement connection related parameters. It may be NULL.
1886 void silc_client_perform_key_agreement(SilcClient client,
1887 SilcClientConnection conn,
1888 SilcClientEntry client_entry,
1889 SilcClientConnectionParams *params,
1890 SilcPublicKey public_key,
1891 SilcPrivateKey private_key,
1892 char *hostname, int port,
1893 SilcKeyAgreementCallback completion,
1896 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1901 * silc_client_perform_key_agreement_stream(
1902 * SilcClient client,
1903 * SilcClientConnection conn,
1904 * SilcClientEntry client_entry,
1905 * SilcClientConnectionParams *params,
1906 * SilcPublicKey public_key,
1907 * SilcPrivateKey private_key,
1908 * SilcStream stream,
1909 * SilcKeyAgreementCallback completion,
1914 * Same as silc_client_perform_key_agreement but the caller has created
1915 * the connection to remote client. The `stream' is the created
1920 silc_client_perform_key_agreement_stream(SilcClient client,
1921 SilcClientConnection conn,
1922 SilcClientEntry client_entry,
1923 SilcClientConnectionParams *params,
1924 SilcPublicKey public_key,
1925 SilcPrivateKey private_key,
1927 SilcKeyAgreementCallback completion,
1930 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1934 * void silc_client_abort_key_agreement(SilcClient client,
1935 * SilcClientConnection conn,
1936 * SilcClientEntry client_entry);
1940 * This function can be called to unbind the hostname and the port for
1941 * the key agreement protocol. However, this function has effect only
1942 * before the key agreement protocol has been performed. After it has
1943 * been performed the library will automatically unbind the port. The
1944 * `client_entry' is the client to which we sent the key agreement
1945 * request. The key agreement completion callback will be called
1946 * with SILC_KEY_AGREEMENT_ABORTED status.
1949 void silc_client_abort_key_agreement(SilcClient client,
1950 SilcClientConnection conn,
1951 SilcClientEntry client_entry);
1954 /* Misc functions */
1956 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1960 * SilcBool silc_client_set_away_message(SilcClient client,
1961 * SilcClientConnection conn,
1966 * Sets away `message'. The away message may be set when the client's
1967 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1968 * to anyone who sends private message. The `message' will be sent
1969 * automatically back to the the client who send private message. If
1970 * away message is already set this replaces the old message with the
1971 * new one. If `message' is NULL the old away message is removed.
1972 * The sender may freely free the memory of the `message'. Returns
1976 SilcBool silc_client_set_away_message(SilcClient client,
1977 SilcClientConnection conn,
1980 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1984 * typedef enum { ... } SilcClientMonitorStatus;
1988 * File transmission session status types. These will indicate
1989 * the status of the file transmission session.
1991 * The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session
1992 * is key exchange phase.
1994 * The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent
1997 * The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being
1998 * recieved from remote client.
2000 * The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user
2001 * issues silc_client_file_close. If needed, it may be ignored in the
2004 * The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote
2005 * disconnects the session connection. The silc_client_file_close must
2006 * be called when this status is received. The session is over when
2009 * The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error
2010 * occured. The SilcClientFileError will indicate more detailed error
2011 * condition. The silc_client_file_close must be called when this status
2012 * is received. The session is over when this is received.
2017 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2018 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2019 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2020 SILC_CLIENT_FILE_MONITOR_GET, /* Unsupported */
2021 SILC_CLIENT_FILE_MONITOR_PUT, /* Unsupported */
2022 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2023 SILC_CLIENT_FILE_MONITOR_DISCONNECT, /* Session disconnected */
2024 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2025 } SilcClientMonitorStatus;
2028 /****d* silcclient/SilcClientAPI/SilcClientFileError
2032 * typedef enum { ... } SilcClientFileError;
2036 * File transmission error types. These types are returned by
2037 * some of the file transmission functions, and by the monitor
2038 * callback to indicate error.
2043 SILC_CLIENT_FILE_OK,
2044 SILC_CLIENT_FILE_ERROR, /* Generic error */
2045 SILC_CLIENT_FILE_UNKNOWN_SESSION, /* Unknown session ID */
2046 SILC_CLIENT_FILE_ALREADY_STARTED, /* Session already started */
2047 SILC_CLIENT_FILE_NO_SUCH_FILE, /* No such file */
2048 SILC_CLIENT_FILE_PERMISSION_DENIED, /* Permission denied */
2049 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED, /* Key exchange failed */
2050 SILC_CLIENT_FILE_CONNECT_FAILED, /* Error during connecting */
2051 SILC_CLIENT_FILE_TIMEOUT, /* Connecting timedout */
2052 SILC_CLIENT_FILE_NO_MEMORY, /* System out of memory */
2053 } SilcClientFileError;
2056 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2060 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2061 * SilcClientConnection conn,
2062 * SilcClientMonitorStatus status,
2063 * SilcClientFileError error,
2064 * SilcUInt64 offset,
2065 * SilcUInt64 filesize,
2066 * SilcClientEntry client_entry,
2067 * SilcUInt32 session_id,
2068 * const char *filepath,
2073 * Monitor callback that is called during the file transmission to
2074 * monitor the transmission process. The `status' indicates the current
2075 * monitoring process. The `error' will indicate the error type
2076 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2077 * currently transmitted amount of total `filesize'. The `client_entry'
2078 * indicates the remote client, and the transmission session ID is the
2079 * `session_id'. The filename being transmitted is indicated by the
2080 * `filepath'. The `conn' is NULL if the connection to remote client
2081 * does not exist yet.
2084 typedef void (*SilcClientFileMonitor)(SilcClient client,
2085 SilcClientConnection conn,
2086 SilcClientMonitorStatus status,
2087 SilcClientFileError error,
2089 SilcUInt64 filesize,
2090 SilcClientEntry client_entry,
2091 SilcUInt32 session_id,
2092 const char *filepath,
2095 /****f* silcclient/SilcClientAPI/SilcClientFileName
2099 * typedef void (*SilcClientFileName)(const char *filepath,
2104 * Completion callback for the SilcClientFileAskName callback function.
2105 * Application calls this to deliver the filepath and filename where
2106 * the downloaded file is to be saved.
2109 typedef void (*SilcClientFileName)(const char *filepath,
2112 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2116 * typedef void (*SilcClientFileAskName)(SilcClient client,
2117 * SilcClientConnection conn,
2118 * SilcUInt32 session_id,
2119 * const char *remote_filename,
2120 * SilcClientFileName completion,
2121 * void *completion_context,
2126 * File name asking callback that is called if it is given to the
2127 * silc_client_file_receive and the path given to that as argument was
2128 * NULL. The library calls this to ask the filename and filepath to
2129 * where the file is to be saved. The 'remote_filename' is the file
2130 * that is being downloaded. Application must call the 'completion'
2131 * with 'completion_context' to continue with the file downloading.
2132 * It is not mandatory to provide this to the silc_client_file_receive.
2135 typedef void (*SilcClientFileAskName)(SilcClient client,
2136 SilcClientConnection conn,
2137 SilcUInt32 session_id,
2138 const char *remote_filename,
2139 SilcClientFileName completion,
2140 void *completion_context,
2143 /****f* silcclient/SilcClientAPI/silc_client_file_send
2147 * SilcClientFileError
2148 * silc_client_file_send(SilcClient client,
2149 * SilcClientConnection conn,
2150 * SilcClientEntry client_entry,
2151 * SilcClientConnectionParams *params,
2152 * SilcPublicKey public_key,
2153 * SilcPrivateKey private_key,
2154 * SilcClientFileMonitor monitor,
2155 * void *monitor_context,
2156 * const char *filepath,
2157 * SilcUInt32 *session_id);
2161 * Sends a file indicated by the `filepath' to the remote client
2162 * indicated by the `client_entry'. This will negotiate a secret key
2163 * with the remote client before actually starting the transmission of
2164 * the file. The `monitor' callback will be called to monitor the
2165 * transmission of the file.
2167 * This returns a file session ID for the file transmission to the
2168 * `session_id' pointer. It can be used to close the session (and
2169 * abort the file transmission) by calling the silc_client_file_close
2170 * function. The session ID is also returned in the `monitor' callback.
2172 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
2173 * the caller will provide the connection endpoint for the key agreement
2174 * connection. The `bind_ip' can be used to bind to that IP instead of
2175 * `local_ip'. Caller may also set the `repository', `verify_notfound'
2176 * and `timeout_secs' fields in `params'. Other fields are ignored.
2177 * If `params' is NULL, then the `client_entry' is expected to provide
2178 * the connection endpoint for us. It is recommended the `timeout_secs'
2179 * is specified in case the remote client does not reply anything to
2182 * The `public_key' and `private_key' is our identity in the key agreement.
2184 * If error will occur during the file transfer process the error status
2185 * will be returned in the monitor callback. In this case the application
2186 * must call silc_client_file_close to close the session.
2190 silc_client_file_send(SilcClient client,
2191 SilcClientConnection conn,
2192 SilcClientEntry client_entry,
2193 SilcClientConnectionParams *params,
2194 SilcPublicKey public_key,
2195 SilcPrivateKey private_key,
2196 SilcClientFileMonitor monitor,
2197 void *monitor_context,
2198 const char *filepath,
2199 SilcUInt32 *session_id);
2201 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2205 * SilcClientFileError
2206 * silc_client_file_receive(SilcClient client,
2207 * SilcClientConnection conn,
2208 * SilcClientConnectionParams *params,
2209 * SilcPublicKey public_key,
2210 * SilcPrivateKey private_key,
2211 * SilcClientFileMonitor monitor,
2212 * void *monitor_context,
2214 * SilcUInt32 session_id,
2215 * SilcClientFileAskName ask_name,
2216 * void *ask_name_context);
2220 * Receives a file from a client indicated by the `client_entry'. The
2221 * `session_id' indicates the file transmission session and it has been
2222 * received in the `ftp' client operation callback. This will actually
2223 * perform the key agreement protocol with the remote client before
2224 * actually starting the file transmission. The `monitor' callback
2225 * will be called to monitor the transmission. If `path' is non-NULL
2226 * the file will be saved into that directory. If NULL the file is
2227 * saved in the current working directory, unless the 'ask_name'
2228 * callback is non-NULL. In this case the callback is called to ask
2229 * the path and filename from application.
2231 * The `params' is the connection related parameters. If the remote client
2232 * provided connection point the `params' will be used when creating
2233 * connection to the remote client. If remote client did not provide
2234 * connection point the `params' is used to provide connection point
2235 * locally for the remote client. See silc_client_file_send for more
2236 * information on providing connection point for remote client.
2238 * The `public_key' and `private_key' is our identity in the key agreement.
2240 * If error will occur during the file transfer process the error status
2241 * will be returned in the monitor callback. In this case the application
2242 * must call silc_client_file_close to close the session.
2246 silc_client_file_receive(SilcClient client,
2247 SilcClientConnection conn,
2248 SilcClientConnectionParams *params,
2249 SilcPublicKey public_key,
2250 SilcPrivateKey private_key,
2251 SilcClientFileMonitor monitor,
2252 void *monitor_context,
2254 SilcUInt32 session_id,
2255 SilcClientFileAskName ask_name,
2256 void *ask_name_context);
2258 /****f* silcclient/SilcClientAPI/silc_client_file_close
2262 * SilcClientFileError silc_client_file_close(SilcClient client,
2263 * SilcClientConnection conn,
2264 * SilcUInt32 session_id);
2268 * Closes file transmission session indicated by the `session_id'.
2269 * If file transmission is being conducted it will be aborted
2270 * automatically. This function is also used to close the session
2271 * after successful file transmission. This function can be used
2272 * also to reject incoming file transmission request. If the
2273 * session was already started and the monitor callback was set
2274 * the monitor callback will be called with the monitor status
2275 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2278 SilcClientFileError silc_client_file_close(SilcClient client,
2279 SilcClientConnection conn,
2280 SilcUInt32 session_id);
2282 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2286 * SilcAttributePayload
2287 * silc_client_attribute_add(SilcClient client,
2288 * SilcClientConnection conn,
2289 * SilcAttribute attribute,
2291 * SilcUInt32 object_size);
2295 * Add new Requsted Attribute for WHOIS command to the client library.
2296 * The `attribute' object indicated by `object' is added and allocated
2297 * SilcAttributePayload is returned. The `object' must be of correct
2298 * type and of correct size. See the SilcAttribute for object types
2299 * for different attributes. You may also get all added attributes
2300 * from the client with silc_client_attributes_get function.
2302 * Requested Attributes are different personal information about the
2303 * user, status information and other information which other users
2304 * may query with WHOIS command. Application may set these so that
2305 * if someone sends WHOIS query these attributes will be replied back
2306 * to the sender. The library always puts the public key to the
2307 * Requested Attributes, but if application wishes to add additional
2308 * public keys (or certificates) it can be done with this interface.
2309 * Library also always computes digital signature of the attributes
2310 * automatically, so application does not need to do that.
2313 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2314 SilcClientConnection conn,
2315 SilcAttribute attribute,
2317 SilcUInt32 object_size);
2319 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2323 * SilcBool silc_client_attribute_del(SilcClient client,
2324 * SilcClientConnection conn,
2325 * SilcAttribute attribute,
2326 * SilcAttributePayload attr);
2330 * Delete a Requested Attribute from the client. If the `attribute'
2331 * is non-zero then all attributes of that type are deleted and the
2332 * `attr' is ignored. If `attr' is non-NULL then that specific
2333 * attribute is deleted and `attribute' is ignored.
2335 * You may get all added attributes with the function
2336 * silc_client_attributes_get and to get the SilcAttributePayload.
2337 * This function Returns TRUE if the attribute was found and deleted.
2340 SilcBool silc_client_attribute_del(SilcClient client,
2341 SilcClientConnection conn,
2342 SilcAttribute attribute,
2343 SilcAttributePayload attr);
2345 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2349 * const SilcHashTable
2350 * silc_client_attributes_get(SilcClient client,
2351 * SilcClientConnection conn);
2355 * Returns pointer to the SilcHashTable which includes all the added
2356 * Requested Attributes. The caller must not free the hash table.
2357 * The caller may use SilcHashTableList and silc_hash_table_list to
2358 * traverse the table. Each entry in the hash table is one added
2359 * SilcAttributePayload. It is possible to delete a attribute
2360 * payload while traversing the table.
2363 SilcHashTable silc_client_attributes_get(SilcClient client,
2364 SilcClientConnection conn);
2366 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2370 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2374 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2375 * then all attributes are requested. Alternatively, `attribute' and
2376 * all variable arguments can each be requested attribute. In this case
2377 * the last must be set to zero (0) to complete the variable list of
2378 * requested attributes. See SilcAttribute for all attributes.
2379 * You can give the returned buffer as argument to for example
2380 * silc_client_get_client_by_id_resolve function.
2384 * Request all attributes
2385 * buffer = silc_client_attributes_request(0);
2387 * Request only the following attributes
2388 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2389 * SILC_ATTRIBUTE_SERVICE,
2390 * SILC_ATTRIBUTE_MOOD, 0);
2393 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2395 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2400 * silc_client_nickname_format(SilcClient client,
2401 * SilcClientConnection conn,
2402 * SilcClientEntry client_entry,
2403 * SilcBool priority);
2407 * Formats the nickname of `client_entry' according to the nickname
2408 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2409 * then the `client_entry' will always get the unformatted nickname.
2410 * If FALSE and there are more than one same nicknames in the client
2411 * the nickname will be formatted.
2413 * This returns NULL on error. Otherwise, the client entry that was
2414 * formatted is returned. If `priority' is FALSE this always returns
2415 * the `client_entry'. If it is TRUE, this may return the client entry
2416 * that was formatted after giving the `client_entry' the unformatted
2419 * Usually application does not need to call this function, as the library
2420 * automatically formats nicknames. However, if application wants to
2421 * for example force the `client_entry' to always have the unformatted
2422 * nickname it may call this function to do so.
2425 SilcClientEntry silc_client_nickname_format(SilcClient client,
2426 SilcClientConnection conn,
2427 SilcClientEntry client_entry,
2430 /****f* silcclient/SilcClientAPI/silc_client_nickname_parse
2434 * SilcBool silc_client_nickname_parse(SilcClient client,
2435 * SilcClientConnection conn,
2441 * Parses the `nickname' according to the format string given in the
2442 * SilcClientParams. Returns the parsed nickname into the `ret_nick'.
2443 * The caller must free the returned pointer. Returns FALSE if error
2444 * occurred during parsing. Returns TRUE if the nickname was parsed,
2445 * it was not formatted or if the format string has not been specified
2446 * in SilcClientParams.
2449 SilcBool silc_client_nickname_parse(SilcClient client,
2450 SilcClientConnection conn,
2458 #endif /* SILCCLIENT_H */