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.
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
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 cipher; /* The cipher and key */
395 SilcHmac hmac; /* The HMAC and hmac key */
399 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
403 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
404 * SilcUInt32 passphrase_len,
409 * Ask passphrase callback. This is called by the application when the
410 * library calls `ask_passphrase' client operation. The callback delivers
411 * the passphrase to the library. The passphrases in SILC protocol
412 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
413 * encoded, and if it is not then library will attempt to encode it.
416 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
417 SilcUInt32 passphrase_len,
420 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
424 * typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
428 * Public key (or certificate) verification callback. This is called
429 * by the application to indicate that the public key verification was
430 * either success or failure.
433 typedef void (*SilcVerifyPublicKey)(SilcBool success, void *context);
435 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
439 * typedef void (*SilcGetAuthMeth)(SilcBool success,
440 * SilcAuthMethod auth_meth,
441 * void *auth, SilcUInt32 auth_len,
446 * Authentication data resolving callback. This is called by the
447 * application to return the resolved authentication data. The client
448 * library has called the get_auth_method client operation and given
449 * this function pointer as argument. The `auth_meth' is the selected
450 * authentication method. The `auth_data' and the `auth_data_len'
451 * are the resolved authentication data. The `context' is the libary's
452 * context sent to the get_auth_method client operation.
454 * If the `auth_method' is SILC_AUTH_PASSWORD then `auth' and `auth_len'
455 * is the passphrase and its length. If it is SILC_AUTH_PUBLIC_KEY the
456 * `auth' must be NULL. The library will use the private key given as
457 * argument to silc_client_connect_to_server, silc_client_connect_to_client
458 * or silc_client_key_exchange. If it is SILC_AUTH_NONE, both `auth' and
459 * `auth_len' are ignored.
462 typedef void (*SilcGetAuthMeth)(SilcAuthMethod auth_meth,
463 void *auth, SilcUInt32 auth_len,
466 /****d* silcclient/SilcClientAPI/SilcClientMessageType
470 * typedef enum { ... } SilcClientMessageType;
474 * Different message types for `say' client operation. The application
475 * may filter the message sent by the library according this type.
480 SILC_CLIENT_MESSAGE_INFO, /* Informational */
481 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
482 SILC_CLIENT_MESSAGE_ERROR, /* Error */
483 SILC_CLIENT_MESSAGE_COMMAND_ERROR, /* Error during command */
484 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
485 } SilcClientMessageType;
488 /****s* silcclient/SilcClientAPI/SilcClientOperations
492 * typedef struct { ... } SilcClientOperations;
496 * SILC Client Operations. These must be implemented by the application.
497 * The Client library may call any of these routines at any time. The
498 * routines are used to deliver certain information to the application
499 * or from the application to the client library.
504 /* Message sent to the application by library. `conn' associates the
505 message to a specific connection. `conn', however, may be NULL.
506 The `type' indicates the type of the message sent by the library.
507 The application can for example filter the message according the
508 type. The variable argument list is arguments to the formatted
509 message that `msg' may be. */
510 void (*say)(SilcClient client, SilcClientConnection conn,
511 SilcClientMessageType type, char *msg, ...);
513 /* Message for a channel. The `sender' is the sender of the message
514 The `channel' is the channel. The `message' is the message. Note
515 that `message' maybe NULL. The `flags' indicates message flags
516 and it is used to determine how the message can be interpreted
517 (like it may tell the message is multimedia message). */
518 void (*channel_message)(SilcClient client, SilcClientConnection conn,
519 SilcClientEntry sender, SilcChannelEntry channel,
520 SilcMessagePayload payload,
521 SilcChannelPrivateKey key, SilcMessageFlags flags,
522 const unsigned char *message,
523 SilcUInt32 message_len);
525 /* Private message to the client. The `sender' is the sender of the
526 message. The message is `message'and maybe NULL. The `flags'
527 indicates message flags and it is used to determine how the message
528 can be interpreted (like it may tell the message is multimedia
530 void (*private_message)(SilcClient client, SilcClientConnection conn,
531 SilcClientEntry sender, SilcMessagePayload payload,
532 SilcMessageFlags flags, const unsigned char *message,
533 SilcUInt32 message_len);
535 /* Notify message to the client. The notify arguments are sent in the
536 same order as servers sends them. The arguments are same as received
537 from the server except for ID's. If ID is received application receives
538 the corresponding entry to the ID. For example, if Client ID is received
539 application receives SilcClientEntry. Also, if the notify type is
540 for channel the channel entry is sent to application (even if server
541 does not send it because client library gets the channel entry from
542 the Channel ID in the packet's header). */
543 void (*notify)(SilcClient client, SilcClientConnection conn,
544 SilcNotifyType type, ...);
546 /* Command handler. This function is called always after application has
547 called a command. It will be called to indicate that the command
548 was processed. It will also be called if error occurs while processing
549 the command. The `success' indicates whether the command was sent
550 or if error occurred. The `status' indicates the actual error.
551 The `argc' and `argv' are the command line arguments sent to the
552 command by application. Note that, this is not reply to the command
553 from server, this is merely and indication to application that the
554 command was processed. */
555 void (*command)(SilcClient client, SilcClientConnection conn,
556 SilcBool success, SilcCommand command, SilcStatus status,
557 SilcUInt32 argc, unsigned char **argv);
559 /* Command reply handler. This function is called always in the command reply
560 function. If error occurs it will be called as well. Normal scenario
561 is that it will be called after the received command data has been parsed
562 and processed. The function is used to pass the received command data to
565 `conn' is the associated client connection. `cmd_payload' is the command
566 payload data received from server and it can be ignored. It is provided
567 if the application would like to re-parse the received command data,
568 however, it must be noted that the data is parsed already by the library
569 thus the payload can be ignored. `success' is FALSE if error occurred.
570 In this case arguments are not sent to the application. The `status' is
571 the command reply status server returned. The `command' is the command
572 reply being processed. The function has variable argument list and each
573 command defines the number and type of arguments it passes to the
574 application (on error they are not sent).
576 The arguments are sent in the same order as servers sends them. The
577 arguments are same as received from the server except for ID's. If
578 ID is received application receives the corresponding entry to the
579 ID. For example, if Client ID is receives application receives
581 void (*command_reply)(SilcClient client, SilcClientConnection conn,
582 SilcCommand command, SilcStatus status,
583 SilcStatus error, va_list ap);
585 /* Find authentication method and authentication data by hostname and
586 port. The hostname may be IP address as well. The `auth_method' is
587 the authentication method the remote connection requires. It is
588 however possible that remote accepts also some other authentication
589 method. Application should use the method that may have been
590 configured for this connection. If none has been configured it should
591 use the required `auth_method'. If the `auth_method' is
592 SILC_AUTH_NONE, server does not require any authentication or the
593 required authentication method is not known. The `completion'
594 callback must be called to deliver the chosen authentication method
595 and data. The `conn' may be NULL. */
596 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
597 char *hostname, SilcUInt16 port,
598 SilcAuthMethod auth_method,
599 SilcGetAuthMeth completion, void *context);
601 /* Verifies received public key. The `conn_type' indicates which entity
602 (server or client) has sent the public key. If user decides to trust
603 the key the application may save the key as trusted public key for
604 later use. The `completion' must be called after the public key has
606 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
607 SilcConnectionType conn_type,
608 SilcPublicKey public_key,
609 SilcVerifyPublicKey completion, void *context);
611 /* Ask (interact, that is) a passphrase from user. The passphrase is
612 returned to the library by calling the `completion' callback with
613 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
614 if not then the library will attempt to encode. */
615 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
616 SilcAskPassphrase completion, void *context);
618 /* Called to indicate that incoming key agreement request has been
619 received. If the application wants to perform key agreement it may
620 call silc_client_perform_key_agreement to initiate key agreementn or
621 silc_client_send_key_agreement to provide connection point to the
622 remote client in case the `hostname' is NULL. If key agreement is
623 not desired this request can be ignored. The `protocol' is either
624 value 0 for TCP or value 1 for UDP. */
625 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
626 SilcClientEntry client_entry,
627 const char *hostname, SilcUInt16 protocol,
630 /* Notifies application that file transfer protocol session is being
631 requested by the remote client indicated by the `client_entry' from
632 the `hostname' and `port'. The `session_id' is the file transfer
633 session and it can be used to either accept or reject the file
634 transfer request, by calling the silc_client_file_receive or
635 silc_client_file_close, respectively. */
636 void (*ftp)(SilcClient client, SilcClientConnection conn,
637 SilcClientEntry client_entry, SilcUInt32 session_id,
638 const char *hostname, SilcUInt16 port);
639 } SilcClientOperations;
642 /****s* silcclient/SilcClientAPI/SilcClientParams
646 * typedef struct { ... } SilcClientParams;
650 * Client parameters. This can be filled with proper values and
651 * given as argument to the silc_client_alloc function. The structure
652 * hold various parameters which affects the function of the client.
657 /* If this boolean is set to TRUE then the client library will use
658 threads. Any of the callback functions in the SilcClientOperations
659 and other callbacks may be called at any time in a thread. The
660 application may need to employ appropriate concurrency control
661 in the callbacks to protect application specific data. */
664 /* Nickname format string. This can be used to order the client library
665 to save the nicknames in the library in a certain format. Since
666 nicknames are not unique in SILC it is possible to have multiple same
667 nicknames. Using this format string it is possible to order the library
668 to separate the multiple same nicknames from each other. If this is
669 empty then default format is used which is the default nickname
670 without anything else. The string MUST be NULL terminated.
672 Following format types are available:
674 %n nickname - the real nickname returned by the server (mandatory)
675 %h hostname - the stripped hostname of the client
676 %H full hostname - the full hostname of the client
677 %s server name - the server name the client is connected
678 %S full server - the full server name the client is connected
679 %a number - ascending number in case there are several
680 same nicknames (fe. nick@host and nick@host2)
682 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
683 "%a!%n@%s" (fe. nick@server, 2!nick@server)
684 "%n@%H" (fe. nick@host.domain.com)
686 Note that there must always be some separator characters around '%n'
687 format. It is not possible to put format characters before or after
688 '%n' without separators (such ash '@'). Also note that the separator
689 character should be a character that cannot be part of normal nickname.
691 char nickname_format[32];
693 /* If this is set to TRUE then the `nickname_format' is employed to all
694 saved nicknames even if there are no multiple same nicknames in the
695 cache. By default this is FALSE, which means that the `nickname_format'
696 is employed only if the library will receive a nickname that is
697 already saved in the cache. It is recommended to leave this to FALSE
699 SilcBool nickname_force_format;
701 /* If this is set to TRUE, the silcclient library will not register and
702 deregister the cipher, pkcs, hash and hmac algorithms. The application
703 itself will need to handle that. */
704 SilcBool dont_register_crypto_library;
710 /* Initialization functions (client.c) */
712 /****f* silcclient/SilcClientAPI/silc_client_alloc
716 * SilcClient silc_client_alloc(SilcClientOperations *ops,
717 * SilcClientParams *params,
719 * const char *silc_version);
723 * Allocates new client object. This has to be done before client may
724 * work. After calling this one must call silc_client_init to initialize
725 * the client. The `application' is application specific user data pointer
726 * and caller must free it. The `silc_version' is the application version
727 * that will be used to compare against remote host's (usually a server)
728 * version string. The `application' context is accessible by the
729 * application by client->application, client being SilcClient.
732 SilcClient silc_client_alloc(SilcClientOperations *ops,
733 SilcClientParams *params,
735 const char *version_string);
737 /****f* silcclient/SilcClientAPI/silc_client_free
741 * void silc_client_free(SilcClient client);
745 * Frees client object and its internals. The execution of the client
746 * should be stopped with silc_client_stop function before calling
750 void silc_client_free(SilcClient client);
752 /****f* silcclient/SilcClientAPI/silc_client_init
756 * SilcBool silc_client_init(SilcClient client, const char *username,
757 * const char *hostname, const char *realname,
758 * SilcClientRunning running, void *context);
762 * Initializes the client. This makes all the necessary steps to make
763 * the client ready to be run. One must call silc_client_run to run the
764 * client. Returns FALSE if error occurred, TRUE otherwise.
766 * The `username' and `hostname' strings must be given and they must be
767 * UTF-8 encoded. The `username' is the client's username in the
768 * operating system, `hostname' is the client's host name and the
769 * `realname' is the user's real name.
771 * The `running' callback is called after the client is running after
772 * silc_client_run or silc_client_run_one has been called. Application
773 * may start using the Client library API after that. Setting the
774 * callback is optional, but recommended.
777 SilcBool silc_client_init(SilcClient client, const char *username,
778 const char *hostname, const char *realname,
779 SilcClientRunning running, void *context);
781 /****f* silcclient/SilcClientAPI/silc_client_run
785 * void silc_client_run(SilcClient client);
789 * Runs the client. This starts the scheduler from the utility library.
790 * When this functions returns the execution of the application is over.
791 * The client must be initialized before calling this.
794 void silc_client_run(SilcClient client);
796 /****f* silcclient/SilcClientAPI/silc_client_run_one
800 * void silc_client_run_one(SilcClient client);
804 * Runs the client and returns immeadiately. This function is used when
805 * the SILC Client object indicated by the `client' is run under some
806 * other scheduler, or event loop or main loop. On GUI applications,
807 * for example this may be desired to used to run the client under the
808 * GUI application's main loop. Typically the GUI application would
809 * register an idle task that calls this function multiple times in
810 * a second to quickly process the SILC specific data.
813 void silc_client_run_one(SilcClient client);
815 /****f* silcclient/SilcClientAPI/silc_client_stop
819 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
824 * Stops the client. This is called to stop the client and thus to stop
825 * the program. The client context must be freed with the silc_client_free
826 * function. All connections that exist in this client must be closed
827 * before calling this function. Connections can be closed by calling
828 * silc_client_close_connection.
830 * The `stopped' will be called once the client and all connections have
831 * finished. The client may be freed after that. Note that the `stopped'
832 * won't be called before all connections have finished. Setting the
833 * callback is optional.
836 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
839 /* Connecting functions */
841 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
845 * typedef struct { ... } SilcClientConnectionParams;
849 * Client connection parameters. This can be filled by the application
850 * and given as argument to silc_client_connect_to_server,
851 * silc_client_connect_to_client, silc_client_key_exchange or
852 * silc_client_send_key_agreement.
857 /* If this is provided the user's nickname in the network will be the
858 string given here. If it is given, it must be UTF-8 encoded. If this
859 string is not given, the user's username by default is used as nickname.
860 The nickname may later be changed by using NICK command. The maximum
861 length for the nickname string is 128 bytes. */
864 /* If this key repository pointer is non-NULL then public key received in
865 the key exchange protocol will be verified from this repository. If
866 this is not provided then the `verify_public_key' client operation will
867 be called back to application. If the boolean `verify_notfound' is set
868 to TRUE then the `verify_public_key' client operation will be called
869 in case the public key is not found in `repository'. Only public keys
870 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
871 be checked, other keys will be ignored. */
873 SilcBool verify_notfound;
875 /* Authentication data. Application may set here the authentication data
876 and authentication method to be used in connecting. If `auth_set'
877 boolean is TRUE then authentication data is provided by application.
878 If the authentication method is public key authentication then the key
879 pair given as argument when connecting will be used and `auth' field
880 is NULL. If it is passphrase authentication, it can be provided in
881 `auth' and `auth_len' fields. If `auth_set' is FALSE
882 the `get_auth_method' client operation will be called to get the
883 authentication method and data from application. */
885 SilcAuthMethod auth_method;
889 /* If this boolean is set to TRUE then the connection will use UDP instead
890 of TCP. If UDP is set then also the next `local_ip' and `local_port'
894 /* The `local_ip' specifies the local IP address used with the connection.
895 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
896 non-zero it will be used as local port with UDP connection. The remote
897 host will also send packets to the specified address and port. If the
898 `bind_ip' is non-NULL a listener is bound to that address instead of
904 /* If this boolean is set to TRUE then the key exchange is done with
905 perfect forward secrecy. */
908 /* If this boolean is set to TRUE then connection authentication protocol
909 is not performed during connecting. Only key exchange protocol is
910 performed. This usually must be set to TRUE when connecting to another
911 client, but must be FALSE with server connections. */
912 SilcBool no_authentication;
914 /* The SILC session detachment data that was returned in the `command_reply'
915 client operation for SILC_COMMAND_DETACH command. If this is provided
916 here the client library will attempt to resume the session in the network.
917 After the connection is created and the session has been resumed the
918 client will receive SILC_COMMAND_NICK command_reply for the client's
919 nickname in the network and SILC_COMMAND_JOIN command reply for all the
920 channels that the client has joined in the network. It may also receive
921 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
922 unsigned char *detach_data;
923 SilcUInt32 detach_data_len;
925 /* Connection timeout. If non-zero, the connection will timeout unless
926 the SILC connection is completed in the specified amount of time. */
927 SilcUInt32 timeout_secs;
929 /* Rekey timeout in seconds. The client will perform rekey in this
930 time interval. If set to zero, the default value will be used
931 (3600 seconds, 1 hour). */
932 SilcUInt32 rekey_secs;
934 /* If this is set to TRUE then the client will ignore all incoming
935 Requested Attributes queries and does not reply anything back. This
936 usually leads into situation where server does not anymore send
937 the queries after seeing that client does not reply anything back.
938 If your application does not support Requested Attributes or you do
939 not want to use them set this to TRUE. See SilcAttribute and
940 silc_client_attribute_add for more information on attributes. */
941 SilcBool ignore_requested_attributes;
943 } SilcClientConnectionParams;
946 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
951 * silc_client_connect_to_server(SilcClient client,
952 * SilcClientConnectionParams *params,
953 * SilcPublicKey public_key,
954 * SilcPrivateKey private_key,
955 * char *remote_host, int port,
956 * SilcClientConnectCallback callback,
961 * Connects to remote server `remote_host' at port `port'. This function
962 * can be used to create connection to remote SILC server and start
963 * SILC session in the SILC network. The `params' may be provided
964 * to provide various connection parameters. The `public_key' and the
965 * `private_key' is your identity used in this connection. When
966 * authentication method is based on digital signatures, this key pair
967 * will be used. The `callback' with `context' will be called after the
968 * connection has been created. It will also be called later when remote
971 * If application wishes to create the network connection itself, use
972 * the silc_client_key_exchange after creating the connection to start
973 * key exchange and authentication with the server.
975 * Returns SilcAsyncOperation which can be used to cancel the connecting,
976 * or NULL on error. Note that the returned pointer becomes invalid
977 * after the `callback' is called.
981 silc_client_connect_to_server(SilcClient client,
982 SilcClientConnectionParams *params,
983 SilcPublicKey public_key,
984 SilcPrivateKey private_key,
985 char *remote_host, int port,
986 SilcClientConnectCallback callback,
989 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
994 * silc_client_connect_to_client(SilcClient client,
995 * SilcClientConnectionParams *params,
996 * SilcPublicKey public_key,
997 * SilcPrivateKey private_key,
998 * char *remote_host, int port,
999 * SilcClientConnectCallback callback,
1004 * Connects to remote client `remote_host' at port `port'. This function
1005 * can be used to create peer-to-peer connection to another SILC client,
1006 * for example, for direct conferencing, or file transfer or for other
1007 * purposes. The `params' may be provided to provide various connection
1008 * parameters. The `public_key' and the `private_key' is your identity
1009 * used in this connection. The `callback' with `context' will be called
1010 * after the connection has been created. It will also be called later
1011 * when remote host disconnects.
1013 * If application wishes to create the network connection itself, use
1014 * the silc_client_key_exchange after creating the connection to start
1015 * key exchange with the client.
1017 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1018 * or NULL on error. Note that the returned pointer becomes invalid
1019 * after the `callback' is called.
1023 silc_client_connect_to_client(SilcClient client,
1024 SilcClientConnectionParams *params,
1025 SilcPublicKey public_key,
1026 SilcPrivateKey private_key,
1027 char *remote_host, int port,
1028 SilcClientConnectCallback callback,
1031 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1035 * SilcAsyncOperation
1036 * silc_client_key_exchange(SilcClient client,
1037 * SilcClientConnectionParams *params,
1038 * SilcPublicKey public_key,
1039 * SilcPrivateKey private_key,
1040 * SilcStream stream,
1041 * SilcConnectionType conn_type,
1042 * SilcClientConnectCallback callback,
1047 * Starts key exchange protocol and authentication protocol in the
1048 * connection indicated by `stream'. This function can be be used to
1049 * start SILC session with remote host (usually server) when the caller
1050 * has itself created the connection, instead of calling the function
1051 * silc_client_connect_to_server or silc_client_connect_to_client. If
1052 * one of those functions was used this function must not be called as
1053 * in that case the key exchange is performed automatically.
1055 * Use this function only if you have created the connection by yourself.
1056 * After creating the connection the socket must be wrapped into a
1057 * socket stream. See silcsocketstream.h for more information. Note that
1058 * the `stream' must have valid remote IP address (and optionally also
1059 * hostname) and port set.
1061 * The `params' may be provided to provide various connection parameters.
1062 * The `public_key' and the `private_key' is your identity used in this
1063 * session. The `callback' with `context' will be called after the session
1064 * has been set up. It will also be called later when remote host
1065 * disconnects. The `conn_type' is the type of session this is going to
1068 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1069 * or NULL on error. Note that the returned pointer becomes invalid
1070 * after the `callback' is called.
1076 * // Create remote connection stream. Resolve hostname and IP also.
1077 * sock = create_connection(remote_host, port);
1078 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1079 * stream_create_cb, app);
1081 * // Stream callback delivers our new SilcStream context
1082 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1086 * if (status != SILC_SOCKET_OK)
1089 * // Start key exchange
1090 * silc_client_key_exchange(client, NULL, public_key, private_key,
1091 * stream, SILC_CONN_SERVER, connection_cb, app);
1097 silc_client_key_exchange(SilcClient client,
1098 SilcClientConnectionParams *params,
1099 SilcPublicKey public_key,
1100 SilcPrivateKey private_key,
1102 SilcConnectionType conn_type,
1103 SilcClientConnectCallback callback,
1106 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1110 * void silc_client_close_connection(SilcClient client,
1111 * SilcClientConnection conn);
1115 * Closes the remote connection `conn'. The `conn' will become invalid
1116 * after this call. Usually this function is called only when explicitly
1117 * closing connection for example in case of error, or when the remote
1118 * connection was created by the application or when the remote is client
1119 * connection. Server connections are usually closed by sending QUIT
1120 * command to the server. However, this call may also be used.
1123 void silc_client_close_connection(SilcClient client,
1124 SilcClientConnection conn);
1126 /* Message sending functions */
1128 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1132 * SilcBool silc_client_send_channel_message(SilcClient client,
1133 * SilcClientConnection conn,
1134 * SilcChannelEntry channel,
1135 * SilcChannelPrivateKey key,
1136 * SilcMessageFlags flags,
1138 * unsigned char *data,
1139 * SilcUInt32 data_len);
1143 * Sends packet to the `channel'. Packet to channel is always encrypted
1144 * differently from "normal" packets. SILC header of the packet is
1145 * encrypted with the next receiver's key and the rest of the packet is
1146 * encrypted with the channel specific key. Padding and HMAC is computed
1147 * with the next receiver's key. The `data' is the channel message.
1149 * If `key' is provided then that private key is used to encrypt the
1150 * channel message. If it is not provided, private keys has not been
1151 * set at all, the normal channel key is used automatically. If private
1152 * keys are set then the first key (the key that was added first as
1153 * private key) is used.
1155 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1156 * digitally signed with the SILC key pair. In this case the `hash'
1157 * pointer must be provided as well.
1159 * Returns TRUE if the message was sent, and FALSE if error occurred or
1160 * the sending is not allowed due to channel modes (like sending is
1161 * blocked). This function is thread safe and private messages can be
1162 * sent from multiple threads.
1165 SilcBool silc_client_send_channel_message(SilcClient client,
1166 SilcClientConnection conn,
1167 SilcChannelEntry channel,
1168 SilcChannelPrivateKey key,
1169 SilcMessageFlags flags,
1171 unsigned char *data,
1172 SilcUInt32 data_len);
1174 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1178 * SilcBool silc_client_send_private_message(SilcClient client,
1179 * SilcClientConnection conn,
1180 * SilcClientEntry client_entry,
1181 * SilcMessageFlags flags,
1183 * unsigned char *data,
1184 * SilcUInt32 data_len);
1188 * Sends private message to remote client. If private message key has
1189 * not been set with this client then the message will be encrypted using
1190 * normal session keys. If the `flags' includes SILC_MESSAGE_FLAG_SIGNED
1191 * the message will be digitally signed with the SILC key pair. In this
1192 * case the caller must also provide the `hash' pointer.
1194 * Returns TRUE if the message was sent, and FALSE if error occurred.
1195 * This function is thread safe and private messages can be sent from
1199 SilcBool silc_client_send_private_message(SilcClient client,
1200 SilcClientConnection conn,
1201 SilcClientEntry client_entry,
1202 SilcMessageFlags flags,
1204 unsigned char *data,
1205 SilcUInt32 data_len);
1207 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init
1212 * silc_client_private_message_wait_init(SilcClient client,
1213 * SilcClientConnection conn);
1217 * Initializes private message waiting functionality for the connection
1218 * indicated by `conn'. Once this is called private message from remote
1219 * connection indicated by `conn' for any client entry beloning to that
1220 * connection may be waited for, for example in an thread. The function
1221 * silc_client_private_message_wait is used to block the current thread
1222 * until a private message is received from a specified client entry.
1223 * Return FALSE on error.
1226 SilcBool silc_client_private_message_wait_init(SilcClient client,
1227 SilcClientConnection conn);
1229 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit
1234 * silc_client_private_message_wait_uninit(SilcClient client,
1235 * SilcClientConnection conn);
1239 * Unintializes private message waiting for connection indicated by
1240 * `conn'. After this call private message cannot be waited anymore.
1241 * This call may be called from any thread. This call will signal all
1242 * private message waiting threads to stop waiting.
1245 void silc_client_private_message_wait_uninit(SilcClient client,
1246 SilcClientConnection conn);
1248 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait
1253 * silc_client_private_message_wait(SilcClient client,
1254 * SilcClientConnection conn,
1255 * SilcClientEntry client_entry,
1256 * SilcMessagePayload *payload);
1260 * Blocks current thread or process until a private message has been
1261 * received from the remote client indicated by `client_entry'. Before
1262 * private messages can be waited the silc_client_private_message_wait_init
1263 * must be called. This function can be used from a thread to wait for
1264 * private message from the specified client. Multiple threads can be
1265 * created to wait messages from multiple clients. Any other private
1266 * message received from the connection indicated by `conn' will be
1267 * forwarded to the normal `private_message' client operation. The
1268 * private messages from `client_entry' will not be delivered to the
1269 * `private_message' client operation.
1271 * Returns TRUE and the received private message into `payload'. The caller
1272 * must free the returned SilcMessagePayload. If this function returns
1273 * FALSE the private messages cannot be waited anymore. This happens
1274 * when some other thread calls silc_client_private_message_wait_uninit.
1275 * This returns FALSE also if silc_client_private_message_wait_init has
1279 SilcBool silc_client_private_message_wait(SilcClient client,
1280 SilcClientConnection conn,
1281 SilcClientEntry client_entry,
1282 SilcMessagePayload *payload);
1284 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1288 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1289 * SilcClientEntry client_entry);
1293 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1294 * channel indicated by the `channel'. NULL if client is not joined on
1298 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1299 SilcClientEntry client_entry);
1302 /* Command management */
1304 /****f* silcclient/SilcClientAPI/silc_client_command_call
1308 * SilcUInt16 silc_client_command_call(SilcClient client,
1309 * SilcClientConnection conn,
1310 * const char *command_line, ...);
1314 * Calls and executes the command indicated by the `command_name'.
1315 * The `command_line' is a string which includes the command's name and
1316 * its arguments separated with whitespaces (' '). If `command_line'
1317 * is non-NULL then all variable arguments are ignored by default.
1319 * If `command_line' is NULL, then the variable arguments define the
1320 * command's name and its arguments. The first variable argument must
1321 * be the command name. The variable argument list must be terminated
1324 * Returns FALSE if the command is not known and TRUE after command.
1325 * execution. The "command" client operation is called when the
1326 * command is executed to indicate whether the command executed
1327 * successfully or not.
1329 * The "command_reply" client operation will be called when reply is
1330 * received from the server to the command. Application may also use
1331 * the silc_client_command_pending to attach to the command reply.
1332 * The command identifier for silc_client_command_pending function after
1333 * this function call is conn->cmd_ident, which application may use.
1337 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1339 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1343 * This command executes the commands implemented inside the client
1344 * library. These commands are designed for command line applications,
1345 * but GUI application may call them too if needed. Alternatively
1346 * application may override the library and use silc_client_command_send
1350 SilcUInt16 silc_client_command_call(SilcClient client,
1351 SilcClientConnection conn,
1352 const char *command_line, ...);
1354 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1358 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1359 * SilcClientConnection conn,
1360 * SilcCommand command,
1361 * SilcStatus status,
1368 * The command reply callback function given as argument to functions
1369 * silc_client_command_send and silc_client_command_pending. This is
1370 * called to deliver the command replies to the caller. Each command
1371 * reply received from the server to the `command' will be delivered
1372 * separately to the caller by calling this callback. The `status' will
1373 * indicate whether there is only one reply or multiple replies. The
1374 * `error' will indicate if an error occurred. The `ap' will include
1375 * command reply arguments. They are the same arguments as for
1376 * `command_reply' client operation in SilcClientOperations.
1378 * If `status' is SILC_STATUS_OK only one reply was received and error
1379 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1380 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1381 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1383 * If FALSE is returned in this function this callback will not be called
1384 * again for `command' even if there are more comand replies. By returning
1385 * FALSE the caller my stop the command reply handling when needed.
1388 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1389 SilcClientConnection conn,
1390 SilcCommand command,
1396 /****f* silcclient/SilcClientAPI/silc_client_command_send
1400 * SilcUInt16 silc_client_command_send(SilcClient client,
1401 * SilcClientConnection conn,
1402 * SilcCommand command,
1403 * SilcClientCommandReply reply,
1404 * void *reply_context,
1405 * SilcUInt32 argc, ...);
1409 * Generic function to send any command. The arguments must be given
1410 * already encoded into correct format and in correct order. If application
1411 * wants to perform the commands by itself, it can do so and send the data
1412 * directly to the server using this function. If application is using
1413 * the silc_client_command_call, this function is usually not used.
1414 * Programmer should get familiar with the SILC protocol commands
1415 * specification when using this function, as the arguments needs to
1416 * be encoded as specified in the protocol.
1418 * The variable arguments are a set of { type, data, data_length },
1419 * and the `argc' is the number of these sets.
1421 * The `reply' callback must be provided, and it is called when the
1422 * command reply is received from the server. Note that, when using this
1423 * function the default `command_reply' client operation will not be
1424 * called, when reply is received.
1426 * Returns command identifier for this sent command. It can be used
1427 * to additionally attach to the command reply using the function
1428 * silc_client_command_pending, if needed. Returns 0 on error,
1432 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1433 * my_whois_command_reply, cmd_ctx,
1434 * 1, 1, nickname, strlen(nickname));
1437 SilcUInt16 silc_client_command_send(SilcClient client,
1438 SilcClientConnection conn,
1439 SilcCommand command,
1440 SilcClientCommandReply reply,
1441 void *reply_context,
1442 SilcUInt32 argc, ...);
1444 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1448 * void silc_client_command_pending(SilcClientConnection conn,
1449 * SilcCommand reply_cmd,
1450 * SilcUInt16 cmd-ident,
1451 * SilcCommandCb callback,
1456 * This function can be used to add pending command callback to be
1457 * called when an command reply is received to an earlier sent command.
1458 * The `reply_cmd' is the command that must be received in order for
1459 * the pending command callback indicated by `callback' to be called.
1460 * The `callback' will deliver the `context' and
1461 * SilcClientCommandReplyContext which includes the internals of the
1464 * The `cmd_ident' is a command identifier which was set for the earlier
1465 * sent command. The command reply will include the same identifier
1466 * and pending command callback will be called when the reply is
1467 * received with the same command identifier. It is possible to
1468 * add multiple pending command callbacks for same command and for
1471 * Application may use this function to add its own command reply
1472 * handlers if it wishes not to use the standard `command_reply'
1473 * client operation. However, note that the pending command callback
1474 * does not deliver parsed command reply, but application must parse
1477 * Note also that the application is notified about the received command
1478 * reply through the `command_reply' client operation before calling
1479 * the `callback` pending command callback. That is the normal
1480 * command reply handling, and is called regardless whether pending
1481 * command callbacks are used or not.
1483 * Commands that application calls with silc_client_command_call
1484 * will use a command identifier from conn->cmd_ident variable. After
1485 * calling the silc_client_command_call, the conn->cmd_ident includes
1486 * the command identifier that was used for the command sending.
1490 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1491 * silc_client_command_pending(conn, SILC_COMMAND_PING, conn->cmd_ident,
1492 * my_ping_handler, my_ping_context);
1495 SilcBool silc_client_command_pending(SilcClientConnection conn,
1496 SilcCommand command,
1497 SilcUInt16 cmd_ident,
1498 SilcClientCommandReply reply,
1502 /* Private Message key management */
1504 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1509 * silc_client_add_private_message_key(SilcClient client,
1510 * SilcClientConnection conn,
1511 * SilcClientEntry client_entry,
1512 * const char *cipher,
1514 * unsigned char *key,
1515 * SilcUInt32 key_len);
1519 * Adds a static private message key to the client library. The key
1520 * will be used to encrypt all private message between the client and
1521 * the remote client indicated by the `client_entry'. The `key' can
1522 * be for example a pre-shared-key, passphrase or similar shared secret
1523 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1524 * to assure that the requirements of the SILC protocol are met. The
1525 * API, however, allows to allocate any cipher and HMAC.
1527 * If the private message key is added to client without first receiving
1528 * a request for it from the remote `client_entry' this function will
1529 * send the request to `client_entry'. Note that, the actual key is
1530 * not sent to the network.
1532 * It is not necessary to set key for normal private message usage. If the
1533 * key is not set then the private messages are encrypted using normal
1534 * session keys. Setting the private key, however, increases the security.
1536 * Returns FALSE if the key is already set for the `client_entry', TRUE
1540 SilcBool silc_client_add_private_message_key(SilcClient client,
1541 SilcClientConnection conn,
1542 SilcClientEntry client_entry,
1546 SilcUInt32 key_len);
1548 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1553 * silc_client_add_private_message_key_ske(SilcClient client,
1554 * SilcClientConnection conn,
1555 * SilcClientEntry client_entry,
1556 * const char *cipher,
1558 * SilcSKEKeyMaterial key);
1562 * Same as silc_client_add_private_message_key but takes the key material
1563 * from the SKE key material structure. This structure is received if
1564 * the application uses the silc_client_send_key_agreement to negotiate
1565 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1566 * negotiated also in the SKE protocol.
1569 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1570 SilcClientConnection conn,
1571 SilcClientEntry client_entry,
1574 SilcSKEKeyMaterial key);
1576 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1580 * SilcBool silc_client_del_private_message_key(SilcClient client,
1581 * SilcClientConnection conn,
1582 * SilcClientEntry client_entry);
1586 * Removes the private message from the library. The key won't be used
1587 * after this to protect the private messages with the remote `client_entry'
1588 * client. Returns FALSE on error, TRUE otherwise.
1591 SilcBool silc_client_del_private_message_key(SilcClient client,
1592 SilcClientConnection conn,
1593 SilcClientEntry client_entry);
1595 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1599 * SilcPrivateMessageKeys
1600 * silc_client_list_private_message_keys(SilcClient client,
1601 * SilcClientConnection conn,
1602 * SilcUInt32 *key_count);
1606 * Returns array of set private message keys associated to the connection
1607 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1608 * count to the `key_count' argument. The array must be freed by the caller
1609 * by calling the silc_client_free_private_message_keys function. Note:
1610 * the keys returned in the array is in raw format. It might not be desired
1611 * to show the keys as is. The application might choose not to show the keys
1612 * at all or to show the fingerprints of the keys.
1615 SilcPrivateMessageKeys
1616 silc_client_list_private_message_keys(SilcClient client,
1617 SilcClientConnection conn,
1618 SilcUInt32 *key_count);
1620 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1624 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1625 * SilcUInt32 key_count);
1629 * Frees the SilcPrivateMessageKeys array returned by the function
1630 * silc_client_list_private_message_keys.
1633 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1634 SilcUInt32 key_count);
1637 /* Channel private key management */
1639 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1643 * SilcBool silc_client_add_channel_private_key(SilcClient client,
1644 * SilcClientConnection conn,
1645 * SilcChannelEntry channel,
1649 * unsigned char *key,
1650 * SilcUInt32 key_len,
1651 * SilcChannelPrivateKey *ret_key);
1655 * Adds private key for channel. When channel has private key then the
1656 * messages are encrypted using that key. All clients on the channel
1657 * must also know the key in order to decrypt the messages. However,
1658 * it is possible to have several private keys per one channel. In this
1659 * case only some of the clients on the channel may know the one key
1660 * and only some the other key. The `name' can be application given
1661 * name for the key. This returns the created key to the 'ret_key'
1662 * pointer if it is non-NULL;
1664 * If `cipher' and/or `hmac' is NULL then default values will be used
1665 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1667 * The private key for channel is optional. If it is not set then the
1668 * channel messages are encrypted using the channel key generated by the
1669 * server. However, setting the private key (or keys) for the channel
1670 * significantly adds security. If more than one key is set the library
1671 * will automatically try all keys at the message decryption phase. Note:
1672 * setting many keys slows down the decryption phase as all keys has to
1673 * be tried in order to find the correct decryption key. However, setting
1674 * a few keys does not have big impact to the decryption performace.
1678 * NOTE: This is entirely local setting. The key set using this function
1679 * is not sent to the network at any phase.
1681 * NOTE: If the key material was originated by the SKE protocol (using
1682 * silc_client_send_key_agreement) then the `key' MUST be the
1683 * key->send_enc_key as this is dictated by the SILC protocol. However,
1684 * currently it is not expected that the SKE key material would be used
1685 * as channel private key. However, this API allows it.
1688 SilcBool silc_client_add_channel_private_key(SilcClient client,
1689 SilcClientConnection conn,
1690 SilcChannelEntry channel,
1696 SilcChannelPrivateKey *ret_key);
1698 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1702 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1703 * SilcClientConnection conn,
1704 * SilcChannelEntry channel);
1708 * Removes all private keys from the `channel'. The old channel key is used
1709 * after calling this to protect the channel messages. Returns FALSE on
1710 * on error, TRUE otherwise.
1713 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1714 SilcClientConnection conn,
1715 SilcChannelEntry channel);
1717 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1721 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1722 * SilcClientConnection conn,
1723 * SilcChannelEntry channel,
1724 * SilcChannelPrivateKey key);
1728 * Removes and frees private key `key' from the channel `channel'.
1729 * The `key' is retrieved by calling the function
1730 * silc_client_list_channel_private_keys. The key is not used after
1731 * this. If the key was last private key then the old channel key is
1732 * used hereafter to protect the channel messages. This returns FALSE
1733 * on error, TRUE otherwise.
1736 SilcBool silc_client_del_channel_private_key(SilcClient client,
1737 SilcClientConnection conn,
1738 SilcChannelEntry channel,
1739 SilcChannelPrivateKey key);
1741 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1746 * silc_client_list_channel_private_keys(SilcClient client,
1747 * SilcClientConnection conn,
1748 * SilcChannelEntry channel);
1752 * Returns list of private keys associated to the `channel'. The caller
1753 * must free the returned list with silc_dlist_uninit. The pointers in
1754 * the list may be used to delete the specific key by giving the pointer
1755 * as argument to the function silc_client_del_channel_private_key. Each
1756 * entry in the list is SilcChannelPrivateKey.
1759 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1760 SilcClientConnection conn,
1761 SilcChannelEntry channel);
1763 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1767 * void silc_client_current_channel_private_key(SilcClient client,
1768 * SilcClientConnection conn,
1769 * SilcChannelEntry channel,
1770 * SilcChannelPrivateKey key);
1774 * Sets the `key' to be used as current channel private key on the
1775 * `channel'. Packet sent after calling this function will be secured
1779 void silc_client_current_channel_private_key(SilcClient client,
1780 SilcClientConnection conn,
1781 SilcChannelEntry channel,
1782 SilcChannelPrivateKey key);
1785 /* Key Agreement routines */
1787 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1791 * void silc_client_send_key_agreement(SilcClient client,
1792 * SilcClientConnection conn,
1793 * SilcClientEntry client_entry,
1794 * SilcClientConnectionParams *params,
1795 * SilcPublicKey public_key,
1796 * SilcPrivateKey private_key,
1797 * SilcKeyAgreementCallback completion,
1802 * Sends key agreement request to the remote client indicated by the
1805 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1806 * the caller will provide the connection endpoint for the key agreement
1807 * connection. The `bind_ip' can be used to bind to that IP instead of
1808 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1809 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1810 * and `timeout_secs' fields in `params'. Other fields are ignored.
1811 * If `params' is NULL, then the `client_entry' is expected to provide
1812 * the connection endpoint for us. It is recommended the `timeout_secs'
1813 * is specified in case the remote client does not reply anything to
1816 * The `public_key' and `private_key' is our identity in the key agreement.
1818 * In case we do not provide the connection endpoint, we will receive
1819 * the `key_agreement' client operation when the remote send its own
1820 * key agreement request packet. We may then there start the key
1821 * agreement with silc_client_perform_key_agreement. If we provided the
1822 * the connection endpoint, the client operation will not be called.
1824 * There can be only one active key agreement for `client_entry'. Old
1825 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1829 * // Send key agreement request (we don't provide connection endpoint)
1830 * silc_client_send_key_agreement(client, conn, remote_client,
1831 * NULL, public_key, private_key,
1832 * my_keyagr_completion, my_context);
1834 * // Another example where we provide connection endpoint (TCP).
1835 * SilcClientConnectionParams params;
1836 * memset(¶ms, 0, sizeof(params));
1837 * params.local_ip = local_ip;
1838 * params.local_port = local_port;
1839 * params.timeout_secs = 60;
1840 * silc_client_send_key_agreement(client, conn, remote_client,
1841 * ¶ms, public_key, private_key,
1842 * my_keyagr_completion, my_context);
1845 void silc_client_send_key_agreement(SilcClient client,
1846 SilcClientConnection conn,
1847 SilcClientEntry client_entry,
1848 SilcClientConnectionParams *params,
1849 SilcPublicKey public_key,
1850 SilcPrivateKey private_key,
1851 SilcKeyAgreementCallback completion,
1854 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1859 * silc_client_perform_key_agreement(SilcClient client,
1860 * SilcClientConnection conn,
1861 * SilcClientEntry client_entry,
1862 * SilcClientConnectionParams *params,
1863 * SilcPublicKey public_key,
1864 * SilcPrivateKey private_key,
1865 * char *hostname, int port,
1866 * SilcKeyAgreementCallback completion,
1871 * Performs the key agreement protocol. Application may use this to
1872 * initiate the key agreement protocol. Usually this is called after
1873 * receiving the `key_agreement' client operation.
1875 * The `hostname' is the remote hostname (or IP address) and the `port'
1876 * is the remote port. The `completion' callback with the `context' will
1877 * be called after the key agreement protocol.
1879 * The `params' is connection parameters and it may be used to define
1880 * the key agreement connection related parameters. It may be NULL.
1883 void silc_client_perform_key_agreement(SilcClient client,
1884 SilcClientConnection conn,
1885 SilcClientEntry client_entry,
1886 SilcClientConnectionParams *params,
1887 SilcPublicKey public_key,
1888 SilcPrivateKey private_key,
1889 char *hostname, int port,
1890 SilcKeyAgreementCallback completion,
1893 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1898 * silc_client_perform_key_agreement_stream(
1899 * SilcClient client,
1900 * SilcClientConnection conn,
1901 * SilcClientEntry client_entry,
1902 * SilcClientConnectionParams *params,
1903 * SilcPublicKey public_key,
1904 * SilcPrivateKey private_key,
1905 * SilcStream stream,
1906 * SilcKeyAgreementCallback completion,
1911 * Same as silc_client_perform_key_agreement but the caller has created
1912 * the connection. The `stream' is the created connection.
1916 silc_client_perform_key_agreement_stream(SilcClient client,
1917 SilcClientConnection conn,
1918 SilcClientEntry client_entry,
1919 SilcClientConnectionParams *params,
1920 SilcPublicKey public_key,
1921 SilcPrivateKey private_key,
1923 SilcKeyAgreementCallback completion,
1926 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1930 * void silc_client_abort_key_agreement(SilcClient client,
1931 * SilcClientConnection conn,
1932 * SilcClientEntry client_entry);
1936 * This function can be called to unbind the hostname and the port for
1937 * the key agreement protocol. However, this function has effect only
1938 * before the key agreement protocol has been performed. After it has
1939 * been performed the library will automatically unbind the port. The
1940 * `client_entry' is the client to which we sent the key agreement
1941 * request. The key agreement completion callback will be called
1942 * with SILC_KEY_AGREEMENT_ABORTED status.
1945 void silc_client_abort_key_agreement(SilcClient client,
1946 SilcClientConnection conn,
1947 SilcClientEntry client_entry);
1950 /* Misc functions */
1952 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1956 * SilcBool silc_client_set_away_message(SilcClient client,
1957 * SilcClientConnection conn,
1962 * Sets away `message'. The away message may be set when the client's
1963 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1964 * to anyone who sends private message. The `message' will be sent
1965 * automatically back to the the client who send private message. If
1966 * away message is already set this replaces the old message with the
1967 * new one. If `message' is NULL the old away message is removed.
1968 * The sender may freely free the memory of the `message'. Returns
1972 SilcBool silc_client_set_away_message(SilcClient client,
1973 SilcClientConnection conn,
1976 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1980 * typedef enum { ... } SilcClientMonitorStatus;
1984 * File transmission session status types. These will indicate
1985 * the status of the file transmission session.
1987 * The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session
1988 * is key exchange phase.
1990 * The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent
1993 * The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being
1994 * recieved from remote client.
1996 * The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user
1997 * issues silc_client_file_close. If needed, it may be ignored in the
2000 * The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote
2001 * disconnects the session connection. The silc_client_file_close must
2002 * be called when this status is received. The session is over when
2005 * The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error
2006 * occured. The SilcClientFileError will indicate more detailed error
2007 * condition. The silc_client_file_close must be called when this status
2008 * is received. The session is over when this is received.
2013 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2014 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2015 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2016 SILC_CLIENT_FILE_MONITOR_GET, /* Unsupported */
2017 SILC_CLIENT_FILE_MONITOR_PUT, /* Unsupported */
2018 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2019 SILC_CLIENT_FILE_MONITOR_DISCONNECT, /* Session disconnected */
2020 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2021 } SilcClientMonitorStatus;
2024 /****d* silcclient/SilcClientAPI/SilcClientFileError
2028 * typedef enum { ... } SilcClientFileError;
2032 * File transmission error types. These types are returned by
2033 * some of the file transmission functions, and by the monitor
2034 * callback to indicate error.
2039 SILC_CLIENT_FILE_OK,
2040 SILC_CLIENT_FILE_ERROR, /* Generic error */
2041 SILC_CLIENT_FILE_UNKNOWN_SESSION, /* Unknown session ID */
2042 SILC_CLIENT_FILE_ALREADY_STARTED, /* Session already started */
2043 SILC_CLIENT_FILE_NO_SUCH_FILE, /* No such file */
2044 SILC_CLIENT_FILE_PERMISSION_DENIED, /* Permission denied */
2045 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED, /* Key exchange failed */
2046 SILC_CLIENT_FILE_CONNECT_FAILED, /* Error during connecting */
2047 SILC_CLIENT_FILE_TIMEOUT, /* Connecting timedout */
2048 SILC_CLIENT_FILE_NO_MEMORY, /* System out of memory */
2049 } SilcClientFileError;
2052 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2056 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2057 * SilcClientConnection conn,
2058 * SilcClientMonitorStatus status,
2059 * SilcClientFileError error,
2060 * SilcUInt64 offset,
2061 * SilcUInt64 filesize,
2062 * SilcClientEntry client_entry,
2063 * SilcUInt32 session_id,
2064 * const char *filepath,
2069 * Monitor callback that is called during the file transmission to
2070 * monitor the transmission process. The `status' indicates the current
2071 * monitoring process. The `error' will indicate the error type
2072 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2073 * currently transmitted amount of total `filesize'. The `client_entry'
2074 * indicates the remote client, and the transmission session ID is the
2075 * `session_id'. The filename being transmitted is indicated by the
2076 * `filepath'. The `conn' is NULL if the connection to remote client
2077 * does not exist yet.
2080 typedef void (*SilcClientFileMonitor)(SilcClient client,
2081 SilcClientConnection conn,
2082 SilcClientMonitorStatus status,
2083 SilcClientFileError error,
2085 SilcUInt64 filesize,
2086 SilcClientEntry client_entry,
2087 SilcUInt32 session_id,
2088 const char *filepath,
2091 /****f* silcclient/SilcClientAPI/SilcClientFileName
2095 * typedef void (*SilcClientFileName)(const char *filepath,
2100 * Completion callback for the SilcClientFileAskName callback function.
2101 * Application calls this to deliver the filepath and filename where
2102 * the downloaded file is to be saved.
2105 typedef void (*SilcClientFileName)(const char *filepath,
2108 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2112 * typedef void (*SilcClientFileAskName)(SilcClient client,
2113 * SilcClientConnection conn,
2114 * SilcUInt32 session_id,
2115 * const char *remote_filename,
2116 * SilcClientFileName completion,
2117 * void *completion_context,
2122 * File name asking callback, that is called if it is given to the
2123 * silc_client_file_receive and the path given to that as argument was
2124 * NULL. The library calls this to ask the filename and filepath to
2125 * where the file is to be saved. The 'remote_filename' is the file
2126 * that is being downloaded. Application must call the 'completion'
2127 * with 'completion_context' to continue with the file downloading.
2128 * It is not mandatory to provide this to the silc_client_file_receive.
2131 typedef void (*SilcClientFileAskName)(SilcClient client,
2132 SilcClientConnection conn,
2133 SilcUInt32 session_id,
2134 const char *remote_filename,
2135 SilcClientFileName completion,
2136 void *completion_context,
2139 /****f* silcclient/SilcClientAPI/silc_client_file_send
2143 * SilcClientFileError
2144 * silc_client_file_send(SilcClient client,
2145 * SilcClientConnection conn,
2146 * SilcClientFileMonitor monitor,
2147 * void *monitor_context,
2148 * const char *local_ip,
2149 * SilcUInt32 local_port,
2150 * SilcBool do_not_bind,
2151 * SilcClientEntry client_entry,
2152 * const char *filepath);
2153 * SilcUInt32 *session_id);
2157 * Sends a file indicated by the `filepath' to the remote client
2158 * indicated by the `client_entry'. This will negotiate a secret key
2159 * with the remote client before actually starting the transmission of
2160 * the file. The `monitor' callback will be called to monitor the
2161 * transmission of the file.
2163 * This returns a file session ID for the file transmission to the
2164 * `session_id' pointer. It can be used to close the session (and
2165 * abort the file transmission) by calling the silc_client_file_close
2166 * function. The session ID is also returned in the `monitor' callback.
2168 * If the `local_ip' is provided then this will try to bind the
2169 * listener for key exchange protocol to that IP. If `local_port' is
2170 * non-zero that port is used. If `local_ip' is NULL then this will
2171 * automatically attempt to bind it to local IP address of the machine.
2172 * If `do_not_bind' is TRUE then the `local_ip' and `local_port' are
2173 * ignored and it is expected that the receiver will provide the
2174 * point of contact. This is usefull if the sender is behind NAT.
2176 * If error will occur during the file transfer process the error
2177 * status will be returned in the monitor callback. In this case
2178 * the application must call silc_client_file_close to close the
2183 silc_client_file_send(SilcClient client,
2184 SilcClientConnection conn,
2185 SilcClientEntry client_entry,
2186 SilcClientConnectionParams *params,
2187 SilcPublicKey public_key,
2188 SilcPrivateKey private_key,
2189 SilcClientFileMonitor monitor,
2190 void *monitor_context,
2191 const char *filepath,
2192 SilcUInt32 *session_id);
2194 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2198 * SilcClientFileError
2199 * silc_client_file_receive(SilcClient client,
2200 * SilcClientConnection conn,
2201 * SilcClientFileMonitor monitor,
2202 * void *monitor_context,
2204 * SilcUInt32 session_id,
2205 * SilcClientFileAskName ask_name,
2206 * void *ask_name_context);
2210 * Receives a file from a client indicated by the `client_entry'. The
2211 * `session_id' indicates the file transmission session and it has been
2212 * received in the `ftp' client operation function. This will actually
2213 * perform the key agreement protocol with the remote client before
2214 * actually starting the file transmission. The `monitor' callback
2215 * will be called to monitor the transmission. If `path' is non-NULL
2216 * the file will be saved into that directory. If NULL the file is
2217 * saved in the current working directory, unless the 'ask_name'
2218 * callback is non-NULL. In this case the callback is called to ask
2219 * the path and filename from application.
2221 * If error will occur during the file transfer process the error
2222 * status will be returned in the monitor callback. In this case
2223 * the application must call silc_client_file_close to close the
2228 silc_client_file_receive(SilcClient client,
2229 SilcClientConnection conn,
2230 SilcClientConnectionParams *params,
2231 SilcPublicKey public_key,
2232 SilcPrivateKey private_key,
2233 SilcClientFileMonitor monitor,
2234 void *monitor_context,
2236 SilcUInt32 session_id,
2237 SilcClientFileAskName ask_name,
2238 void *ask_name_context);
2240 /****f* silcclient/SilcClientAPI/silc_client_file_close
2244 * SilcClientFileError silc_client_file_close(SilcClient client,
2245 * SilcClientConnection conn,
2246 * SilcUInt32 session_id);
2250 * Closes file transmission session indicated by the `session_id'.
2251 * If file transmission is being conducted it will be aborted
2252 * automatically. This function is also used to close the session
2253 * after successful file transmission. This function can be used
2254 * also to reject incoming file transmission request. If the
2255 * session was already started and the monitor callback was set
2256 * the monitor callback will be called with the monitor status
2257 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2260 SilcClientFileError silc_client_file_close(SilcClient client,
2261 SilcClientConnection conn,
2262 SilcUInt32 session_id);
2264 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2268 * SilcAttributePayload
2269 * silc_client_attribute_add(SilcClient client,
2270 * SilcClientConnection conn,
2271 * SilcAttribute attribute,
2273 * SilcUInt32 object_size);
2277 * Add new Requsted Attribute for WHOIS command to the client library.
2278 * The `attribute' object indicated by `object' is added and allocated
2279 * SilcAttributePayload is returned. The `object' must be of correct
2280 * type and of correct size. See the SilcAttribute for object types
2281 * for different attributes. You may also get all added attributes
2282 * from the client with silc_client_attributes_get function.
2284 * Requested Attributes are different personal information about the
2285 * user, status information and other information which other users
2286 * may query with WHOIS command. Application may set these so that
2287 * if someone sends WHOIS query these attributes will be replied back
2288 * to the sender. The library always puts the public key to the
2289 * Requested Attributes, but if application wishes to add additional
2290 * public keys (or certificates) it can be done with this interface.
2291 * Library also always computes digital signature of the attributes
2292 * automatically, so application does not need to do that.
2295 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2296 SilcClientConnection conn,
2297 SilcAttribute attribute,
2299 SilcUInt32 object_size);
2301 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2305 * SilcBool silc_client_attribute_del(SilcClient client,
2306 * SilcClientConnection conn,
2307 * SilcAttribute attribute,
2308 * SilcAttributePayload attr);
2312 * Delete a Requested Attribute from the client. If the `attribute'
2313 * is non-zero then all attributes of that type are deleted and the
2314 * `attr' is ignored. If `attr' is non-NULL then that specific
2315 * attribute is deleted and `attribute' is ignored.
2317 * You may get all added attributes with the function
2318 * silc_client_attributes_get and to get the SilcAttributePayload.
2319 * This function Returns TRUE if the attribute was found and deleted.
2322 SilcBool silc_client_attribute_del(SilcClient client,
2323 SilcClientConnection conn,
2324 SilcAttribute attribute,
2325 SilcAttributePayload attr);
2327 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2331 * const SilcHashTable
2332 * silc_client_attributes_get(SilcClient client,
2333 * SilcClientConnection conn);
2337 * Returns pointer to the SilcHashTable which includes all the added
2338 * Requested Attributes. The caller must not free the hash table.
2339 * The caller may use SilcHashTableList and silc_hash_table_list to
2340 * traverse the table. Each entry in the hash table is one added
2341 * SilcAttributePayload. It is possible to delete a attribute
2342 * payload while traversing the table.
2345 SilcHashTable silc_client_attributes_get(SilcClient client,
2346 SilcClientConnection conn);
2348 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2352 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2356 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2357 * then all attributes are requested. Alternatively, `attribute' and
2358 * all variable arguments can each be requested attribute. In this case
2359 * the last must be set to zero (0) to complete the variable list of
2360 * requested attributes. See SilcAttribute for all attributes.
2361 * You can give the returned buffer as argument to for example
2362 * silc_client_get_client_by_id_resolve function.
2366 * Request all attributes
2367 * buffer = silc_client_attributes_request(0);
2369 * Request only the following attributes
2370 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2371 * SILC_ATTRIBUTE_SERVICE,
2372 * SILC_ATTRIBUTE_MOOD, 0);
2375 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2377 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2382 * silc_client_nickname_format(SilcClient client,
2383 * SilcClientConnection conn,
2384 * SilcClientEntry client_entry,
2385 * SilcBool priority);
2389 * Formats the nickname of `client_entry' according to the nickname
2390 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2391 * then the `client_entry' will always get the unformatted nickname.
2392 * If FALSE and there are more than one same nicknames in the client
2393 * the nickname will be formatted.
2395 * This returns NULL on error. Otherwise, the client entry that was
2396 * formatted is returned. If `priority' is FALSE this always returns
2397 * the `client_entry'. If it is TRUE, this may return the client entry
2398 * that was formatted after giving the `client_entry' the unformatted
2401 * Usually application does not need to call this function, as the library
2402 * automatically formats nicknames. However, if application wants to
2403 * for example force the `client_entry' to always have the unformatted
2404 * nickname it may call this function to do so.
2407 SilcClientEntry silc_client_nickname_format(SilcClient client,
2408 SilcClientConnection conn,
2409 SilcClientEntry client_entry,
2416 #endif /* SILCCLIENT_H */