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)(const 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)(const 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)(SilcAuthMethod auth_meth,
441 * const 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 const 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.
503 typedef struct SilcClientOperationsStruct {
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). The `payload'
518 may be used to retrieve all the details of the message. */
519 void (*channel_message)(SilcClient client, SilcClientConnection conn,
520 SilcClientEntry sender, SilcChannelEntry channel,
521 SilcMessagePayload payload,
522 SilcChannelPrivateKey key, SilcMessageFlags flags,
523 const unsigned char *message,
524 SilcUInt32 message_len);
526 /* Private message to the client. The `sender' is the sender of the
527 message. The message is `message'and maybe NULL. The `flags'
528 indicates message flags and it is used to determine how the message
529 can be interpreted (like it may tell the message is multimedia
530 message). The `payload' may be used to retrieve all the details of
532 void (*private_message)(SilcClient client, SilcClientConnection conn,
533 SilcClientEntry sender, SilcMessagePayload payload,
534 SilcMessageFlags flags, const unsigned char *message,
535 SilcUInt32 message_len);
537 /* Notify message to the client. The arguments are notify `type' specific.
538 See separate documentation in the Toolkit Reference Manual for the notify
540 void (*notify)(SilcClient client, SilcClientConnection conn,
541 SilcNotifyType type, ...);
543 /* Command handler. This function is called always after application has
544 called a command. It will be called to indicate that the command
545 was processed. It will also be called if error occurs while processing
546 the command. The `success' indicates whether the command was sent
547 or if error occurred. The `status' indicates the actual error.
548 The `argc' and `argv' are the command line arguments sent to the
549 command by application. Note that, this is not reply to the command
550 from server, this is merely and indication to application that the
551 command was processed. */
552 void (*command)(SilcClient client, SilcClientConnection conn,
553 SilcBool success, SilcCommand command, SilcStatus status,
554 SilcUInt32 argc, unsigned char **argv);
556 /* Command reply handler. Delivers a reply to command that was sent
557 earlier. The `conn' is the associated client connection. The `command'
558 indicates the command reply type. If the `status' other than
559 SILC_STATUS_OK an error occurred. In this case the `error' will indicate
560 the error. It is possible to receive list of command replies and list
561 of errors. In this case the `status' will indicate it is an list entry
562 (the `status' is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM and/or
563 SILC_STATUS_LIST_END).
565 The arguments received in `ap' are command specific. See a separate
566 documentation in the Toolkit Reference Manual for the command reply
568 void (*command_reply)(SilcClient client, SilcClientConnection conn,
569 SilcCommand command, SilcStatus status,
570 SilcStatus error, va_list ap);
572 /* Find authentication method and authentication data by hostname and
573 port. The hostname may be IP address as well. The `auth_method' is
574 the authentication method the remote connection requires. It is
575 however possible that remote accepts also some other authentication
576 method. Application should use the method that may have been
577 configured for this connection. If none has been configured it should
578 use the required `auth_method'. If the `auth_method' is
579 SILC_AUTH_NONE, server does not require any authentication or the
580 required authentication method is not known. The `completion'
581 callback must be called to deliver the chosen authentication method
582 and data. The `conn' may be NULL. */
583 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
584 char *hostname, SilcUInt16 port,
585 SilcAuthMethod auth_method,
586 SilcGetAuthMeth completion, void *context);
588 /* Called to verify received public key. The `conn_type' indicates which
589 entity (server or client) has sent the public key. If user decides to
590 trust the key the application may save the key as trusted public key for
591 later use. The `completion' must be called after the public key has
593 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
594 SilcConnectionType conn_type,
595 SilcPublicKey public_key,
596 SilcVerifyPublicKey completion, void *context);
598 /* Ask from end user a passphrase or a password. The passphrase is
599 returned to the library by calling the `completion' callback with
600 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
601 if not then the library will attempt to encode. */
602 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
603 SilcAskPassphrase completion, void *context);
605 /* Called to indicate that incoming key agreement request has been
606 received. If the application wants to perform key agreement it may
607 call silc_client_perform_key_agreement to initiate key agreement or
608 silc_client_send_key_agreement to provide connection point to the
609 remote client in case the `hostname' is NULL. If key agreement is
610 not desired this request can be ignored. The `protocol' is either
611 value 0 for TCP or value 1 for UDP. */
612 void (*key_agreement)(SilcClient client, SilcClientConnection conn,
613 SilcClientEntry client_entry,
614 const char *hostname, SilcUInt16 protocol,
617 /* Notifies application that file transfer protocol session is being
618 requested by the remote client indicated by the `client_entry' from
619 the `hostname' and `port'. The `session_id' is the file transfer
620 session and it can be used to either accept or reject the file
621 transfer request, by calling the silc_client_file_receive or
622 silc_client_file_close, respectively. */
623 void (*ftp)(SilcClient client, SilcClientConnection conn,
624 SilcClientEntry client_entry, SilcUInt32 session_id,
625 const char *hostname, SilcUInt16 port);
626 } SilcClientOperations;
629 /****s* silcclient/SilcClientAPI/SilcClientParams
633 * typedef struct { ... } SilcClientParams;
637 * Client parameters. This can be filled with proper values and
638 * given as argument to the silc_client_alloc function. The structure
639 * hold various parameters which affects the function of the client.
643 typedef struct SilcClientParamsStruct {
644 /* If this boolean is set to TRUE then the client library will use
645 threads. Any of the callback functions in the SilcClientOperations
646 and other callbacks may be called at any time in a thread. The
647 application may need to employ appropriate concurrency control
648 in the callbacks to protect application specific data. */
651 /* Nickname format string. This can be used to order the client library
652 to save the nicknames in the library in a certain format. Since
653 nicknames are not unique in SILC it is possible to have multiple same
654 nicknames. Using this format string it is possible to order the library
655 to separate the multiple same nicknames from each other. If this is
656 empty then default format is used which is the default nickname
657 without anything else. The string MUST be NULL terminated.
659 Following format types are available:
661 %n nickname - the real nickname returned by the server (mandatory)
662 %a number - ascending number in case there are several
663 same nicknames (fe. nick#2 and nick#3)
664 %h hostname - the stripped hostname of the client
665 %H full hostname - the full hostname of the client
667 Example format strings: "%n#%a" (fe. nick#2, nick#3)
668 "%n@%h%a" (fe. nick@host, nick@host2)
669 "%a!%n@%h" (fe. nick@host, 2!nick@host)
671 Note that there must always be some separator characters around '%n'
672 format. It is not possible to put format characters before or after
673 '%n' without separators (such ash '#'). Also note that the separator
674 character should be a character that cannot be part of normal nickname.
676 char nickname_format[32];
678 /* If this is set to TRUE then the `nickname_format' is employed to all
679 saved nicknames even if there are no multiple same nicknames in the
680 cache. By default this is FALSE, which means that the `nickname_format'
681 is employed only if the library will receive a nickname that is
682 already saved in the cache. It is recommended to leave this to FALSE
684 SilcBool nickname_force_format;
686 /* If this is set to TRUE, the silcclient library will not register and
687 deregister the cipher, pkcs, hash and hmac algorithms. The application
688 itself will need to handle that. */
689 SilcBool dont_register_crypto_library;
695 /* Initialization functions (client.c) */
697 /****f* silcclient/SilcClientAPI/silc_client_alloc
701 * SilcClient silc_client_alloc(SilcClientOperations *ops,
702 * SilcClientParams *params,
704 * const char *silc_version);
708 * Allocates new client object. This has to be done before client may
709 * work. After calling this one must call silc_client_init to initialize
710 * the client. The `application' is application specific user data pointer
711 * and caller must free it. The `silc_version' is the application version
712 * that will be used to compare against remote host's (usually a server)
713 * version string. The `application' context is accessible by the
714 * application by client->application, client being SilcClient.
717 SilcClient silc_client_alloc(SilcClientOperations *ops,
718 SilcClientParams *params,
720 const char *version_string);
722 /****f* silcclient/SilcClientAPI/silc_client_free
726 * void silc_client_free(SilcClient client);
730 * Frees client object and its internals. The execution of the client
731 * should be stopped with silc_client_stop function before calling
735 void silc_client_free(SilcClient client);
737 /****f* silcclient/SilcClientAPI/silc_client_init
741 * SilcBool silc_client_init(SilcClient client, const char *username,
742 * const char *hostname, const char *realname,
743 * SilcClientRunning running, void *context);
747 * Initializes the client. This makes all the necessary steps to make
748 * the client ready to be run. One must call silc_client_run to run the
749 * client. Returns FALSE if error occurred, TRUE otherwise.
751 * The `username' and `hostname' strings must be given and they must be
752 * UTF-8 encoded. The `username' is the client's username in the
753 * operating system, `hostname' is the client's host name and the
754 * `realname' is the user's real name.
756 * The `running' callback with `context' is called after the client is
757 * running after silc_client_run or silc_client_run_one has been called.
758 * Application may start using the Client library API after that. Setting
759 * the callback is optional, but highly recommended.
762 SilcBool silc_client_init(SilcClient client, const char *username,
763 const char *hostname, const char *realname,
764 SilcClientRunning running, void *context);
766 /****f* silcclient/SilcClientAPI/silc_client_run
770 * void silc_client_run(SilcClient client);
774 * Runs the client. This starts the scheduler from the utility library.
775 * When this functions returns the execution of the application is over.
776 * The client must be initialized before calling this.
779 void silc_client_run(SilcClient client);
781 /****f* silcclient/SilcClientAPI/silc_client_run_one
785 * void silc_client_run_one(SilcClient client);
789 * Runs the client and returns immeadiately. This function is used when
790 * the SILC Client object indicated by the `client' is run under some
791 * other scheduler, or event loop or main loop. On GUI applications,
792 * for example this may be desired to used to run the client under the
793 * GUI application's main loop. Typically the GUI application would
794 * register an idle task that calls this function multiple times in
795 * a second to quickly process the SILC specific data.
798 void silc_client_run_one(SilcClient client);
800 /****f* silcclient/SilcClientAPI/silc_client_stop
804 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
809 * Stops the client. This is called to stop the client and thus to stop
810 * the program. The client context must be freed with the silc_client_free
811 * function. All connections that exist in this client must be closed
812 * before calling this function. Connections can be closed by calling
813 * silc_client_close_connection.
815 * The `stopped' will be called once the client and all connections have
816 * finished. The client may be freed after that. Note that the `stopped'
817 * won't be called before all connections have finished. Setting the
818 * callback is optional.
821 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
824 /* Connecting functions */
826 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
830 * typedef struct { ... } SilcClientConnectionParams;
834 * Client connection parameters. This can be filled by the application
835 * and given as argument to silc_client_connect_to_server,
836 * silc_client_connect_to_client, silc_client_key_exchange or
837 * silc_client_send_key_agreement.
841 typedef struct SilcClientConnectionParamsStruct {
842 /* If this is provided the user's nickname in the network will be the
843 string given here. If it is given, it must be UTF-8 encoded. If this
844 string is not given, the user's username by default is used as nickname.
845 The nickname may later be changed by using NICK command. The maximum
846 length for the nickname string is 128 bytes. */
849 /* If this key repository pointer is non-NULL then public key received in
850 the key exchange protocol will be verified from this repository. If
851 this is not provided then the `verify_public_key' client operation will
852 be called back to application. If the boolean `verify_notfound' is set
853 to TRUE then the `verify_public_key' client operation will be called
854 in case the public key is not found in `repository'. Only public keys
855 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
856 be checked, other keys will be ignored. */
858 SilcBool verify_notfound;
860 /* Authentication data. Application may set here the authentication data
861 and authentication method to be used in connecting. If `auth_set'
862 boolean is TRUE then authentication data is provided by application.
863 If the authentication method is public key authentication then the key
864 pair given as argument when connecting will be used and `auth' field
865 is NULL. If it is passphrase authentication, it can be provided in
866 `auth' and `auth_len' fields. If `auth_set' is FALSE
867 the `get_auth_method' client operation will be called to get the
868 authentication method and data from application. */
870 SilcAuthMethod auth_method;
874 /* If this boolean is set to TRUE then the connection will use UDP instead
875 of TCP. If UDP is set then also the next `local_ip' and `local_port'
879 /* The `local_ip' specifies the local IP address used with the connection.
880 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
881 non-zero it will be used as local port with UDP connection. The remote
882 host will also send packets to the specified address and port. If the
883 `bind_ip' is non-NULL a listener is bound to that address instead of
889 /* If this boolean is set to TRUE then the key exchange is done with
890 perfect forward secrecy. */
893 /* If this boolean is set to TRUE then connection authentication protocol
894 is not performed during connecting. Only key exchange protocol is
895 performed. This usually must be set to TRUE when connecting to another
896 client, but must be FALSE with server connections. */
897 SilcBool no_authentication;
899 /* The SILC session detachment data that was returned in the `command_reply'
900 client operation for SILC_COMMAND_DETACH command. If this is provided
901 here the client library will attempt to resume the session in the network.
902 After the connection is created and the session has been resumed the
903 client will receive SILC_COMMAND_NICK command_reply for the client's
904 nickname in the network and SILC_COMMAND_JOIN command reply for all the
905 channels that the client has joined in the network. It may also receive
906 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
907 unsigned char *detach_data;
908 SilcUInt32 detach_data_len;
910 /* Connection timeout. If non-zero, the connection will timeout unless
911 the SILC connection is completed in the specified amount of time. */
912 SilcUInt32 timeout_secs;
914 /* Rekey timeout in seconds. The client will perform rekey in this
915 time interval. If set to zero, the default value will be used
916 (3600 seconds, 1 hour). */
917 SilcUInt32 rekey_secs;
919 /* If this is set to TRUE then the client will ignore all incoming
920 Requested Attributes queries and does not reply anything back. This
921 usually leads into situation where server does not anymore send
922 the queries after seeing that client does not reply anything back.
923 If your application does not support Requested Attributes or you do
924 not want to use them set this to TRUE. See SilcAttribute and
925 silc_client_attribute_add for more information on attributes. */
926 SilcBool ignore_requested_attributes;
928 } SilcClientConnectionParams;
931 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
936 * silc_client_connect_to_server(SilcClient client,
937 * SilcClientConnectionParams *params,
938 * SilcPublicKey public_key,
939 * SilcPrivateKey private_key,
940 * char *remote_host, int port,
941 * SilcClientConnectCallback callback,
946 * Connects to remote server `remote_host' at port `port'. This function
947 * can be used to create connection to remote SILC server and start
948 * SILC session in the SILC network. The `params' may be provided
949 * to provide various connection parameters. The `public_key' and the
950 * `private_key' is your identity used in this connection. When
951 * authentication method is based on digital signatures, this key pair
952 * will be used. The `callback' with `context' will be called after the
953 * connection has been created. It will also be called later when remote
956 * If application wishes to create the network connection itself, use
957 * the silc_client_key_exchange after creating the connection to start
958 * key exchange and authentication with the server.
960 * Returns SilcAsyncOperation which can be used to cancel the connecting,
961 * or NULL on error. Note that the returned pointer becomes invalid
962 * after the `callback' is called.
966 silc_client_connect_to_server(SilcClient client,
967 SilcClientConnectionParams *params,
968 SilcPublicKey public_key,
969 SilcPrivateKey private_key,
970 char *remote_host, int port,
971 SilcClientConnectCallback callback,
974 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
979 * silc_client_connect_to_client(SilcClient client,
980 * SilcClientConnectionParams *params,
981 * SilcPublicKey public_key,
982 * SilcPrivateKey private_key,
983 * char *remote_host, int port,
984 * SilcClientConnectCallback callback,
989 * Connects to remote client `remote_host' at port `port'. This function
990 * can be used to create peer-to-peer connection to another SILC client,
991 * for example, for direct conferencing, or file transfer or for other
992 * purposes. The `params' may be provided to provide various connection
993 * parameters. The `public_key' and the `private_key' is your identity
994 * used in this connection. The `callback' with `context' will be called
995 * after the connection has been created. It will also be called later
996 * when remote host disconnects.
998 * If application wishes to create the network connection itself, use
999 * the silc_client_key_exchange after creating the connection to start
1000 * key exchange with the client.
1002 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1003 * or NULL on error. Note that the returned pointer becomes invalid
1004 * after the `callback' is called.
1008 silc_client_connect_to_client(SilcClient client,
1009 SilcClientConnectionParams *params,
1010 SilcPublicKey public_key,
1011 SilcPrivateKey private_key,
1012 char *remote_host, int port,
1013 SilcClientConnectCallback callback,
1016 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1020 * SilcAsyncOperation
1021 * silc_client_key_exchange(SilcClient client,
1022 * SilcClientConnectionParams *params,
1023 * SilcPublicKey public_key,
1024 * SilcPrivateKey private_key,
1025 * SilcStream stream,
1026 * SilcConnectionType conn_type,
1027 * SilcClientConnectCallback callback,
1032 * Starts key exchange protocol and authentication protocol in the
1033 * connection indicated by `stream'. This function can be be used to
1034 * start SILC session with remote host (usually server) when the caller
1035 * has itself created the connection, instead of calling the function
1036 * silc_client_connect_to_server or silc_client_connect_to_client. If
1037 * one of those functions was used this function must not be called as
1038 * in that case the key exchange is performed automatically.
1040 * Use this function only if you have created the connection by yourself.
1041 * After creating the connection the socket must be wrapped into a
1042 * socket stream. See silcsocketstream.h for more information. Note that
1043 * the `stream' must have valid remote IP address (and optionally also
1044 * hostname) and port set.
1046 * The `params' may be provided to provide various connection parameters.
1047 * The `public_key' and the `private_key' is your identity used in this
1048 * session. The `callback' with `context' will be called after the session
1049 * has been set up. It will also be called later when remote host
1050 * disconnects. The `conn_type' is the type of session this is going to
1051 * be. If the remote is SILC server it is SILC_CONN_SERVER or if it is
1052 * SILC client it is SILC_CONN_CLIENT.
1054 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1055 * or NULL on error. Note that the returned pointer becomes invalid
1056 * after the `callback' is called.
1062 * // Create remote connection stream. Resolve hostname and IP also.
1063 * sock = create_connection(remote_host, port);
1064 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1065 * stream_create_cb, app);
1067 * // Stream callback delivers our new SilcStream context
1068 * void stream_create_cb(SilcSocketStreamStatus status, SilcStream stream,
1072 * if (status != SILC_SOCKET_OK)
1075 * // Start key exchange
1076 * silc_client_key_exchange(client, NULL, public_key, private_key,
1077 * stream, SILC_CONN_SERVER, connection_cb, app);
1083 silc_client_key_exchange(SilcClient client,
1084 SilcClientConnectionParams *params,
1085 SilcPublicKey public_key,
1086 SilcPrivateKey private_key,
1088 SilcConnectionType conn_type,
1089 SilcClientConnectCallback callback,
1092 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1096 * void silc_client_close_connection(SilcClient client,
1097 * SilcClientConnection conn);
1101 * Closes the remote connection `conn'. The `conn' will become invalid
1102 * after this call. Usually this function is called only when explicitly
1103 * closing connection for example in case of error, or when the remote
1104 * connection was created by the application or when the remote is client
1105 * connection. Server connections are usually closed by sending QUIT
1106 * command to the server. However, this call may also be used.
1109 void silc_client_close_connection(SilcClient client,
1110 SilcClientConnection conn);
1112 /* Message sending functions */
1114 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1118 * SilcBool silc_client_send_channel_message(SilcClient client,
1119 * SilcClientConnection conn,
1120 * SilcChannelEntry channel,
1121 * SilcChannelPrivateKey key,
1122 * SilcMessageFlags flags,
1124 * unsigned char *data,
1125 * SilcUInt32 data_len);
1129 * Sends encrypted message to the `channel'. The plaintext message is
1130 * the `data' of `data_len' bytes in length.
1132 * If `key' is provided then that private channel message key is used to
1133 * encrypt the message. If it is not provided and the `channel' does not
1134 * have SILC_CHANNEL_MODE_PRIVKEY set, the curent channel key is used
1135 * instead. If the mode is set but `key' is NULL the key that was added
1136 * first as private channel message key will be used.
1138 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1139 * digitally signed with the SILC key pair associated with the `conn'.
1140 * In this case the `hash' pointer must be provided as well.
1142 * Returns TRUE if the message was sent, and FALSE if error occurred or
1143 * the sending is not allowed due to channel modes (like sending is
1144 * blocked). This function is thread safe and private messages can be
1145 * sent from multiple threads.
1148 SilcBool silc_client_send_channel_message(SilcClient client,
1149 SilcClientConnection conn,
1150 SilcChannelEntry channel,
1151 SilcChannelPrivateKey key,
1152 SilcMessageFlags flags,
1154 unsigned char *data,
1155 SilcUInt32 data_len);
1157 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1161 * SilcBool silc_client_send_private_message(SilcClient client,
1162 * SilcClientConnection conn,
1163 * SilcClientEntry client_entry,
1164 * SilcMessageFlags flags,
1166 * unsigned char *data,
1167 * SilcUInt32 data_len);
1171 * Sends private message to remote client. If private message key has
1172 * not been set with this client then the message will be encrypted using
1173 * the session keys used in `conn' connection. If the `flags' includes
1174 * SILC_MESSAGE_FLAG_SIGNED the message will be digitally signed with the
1175 * SILC key pair associated with `conn'. In this case the caller must also
1176 * provide the `hash' pointer.
1178 * Returns TRUE if the message was sent, and FALSE if error occurred.
1179 * This function is thread safe and private messages can be sent from
1183 SilcBool silc_client_send_private_message(SilcClient client,
1184 SilcClientConnection conn,
1185 SilcClientEntry client_entry,
1186 SilcMessageFlags flags,
1188 unsigned char *data,
1189 SilcUInt32 data_len);
1191 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init
1196 * silc_client_private_message_wait_init(SilcClient client,
1197 * SilcClientConnection conn,
1198 * SilcClientEntry client_entry);
1202 * Initializes private message waiting functionality for the client
1203 * indicated by `client_entry'. Once this is called private message
1204 * from remote connection indicated by `conn' for `client_entry' may
1205 * be waiter for, for example in a thread. The function
1206 * silc_client_private_message_wait is used to block the current thread
1207 * until a private message is received from a specified client entry.
1208 * Return FALSE in case an internal error occurred.
1211 SilcBool silc_client_private_message_wait_init(SilcClient client,
1212 SilcClientConnection conn,
1213 SilcClientEntry client_entry);
1215 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit
1220 * silc_client_private_message_wait_uninit(SilcClient client,
1221 * SilcClientConnection conn,
1222 * SilcClientEntry client_entry);
1226 * Unintializes private message waiting for client indicated by
1227 * `client_entry'. After this call private message cannot be waited
1228 * anymore and silc_client_private_message_wait will return with FALSE
1232 void silc_client_private_message_wait_uninit(SilcClient client,
1233 SilcClientConnection conn,
1234 SilcClientEntry client_entry);
1236 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait
1241 * silc_client_private_message_wait(SilcClient client,
1242 * SilcClientConnection conn,
1243 * SilcClientEntry client_entry,
1244 * SilcMessagePayload *payload);
1248 * Blocks current thread or process until a private message has been
1249 * received from the remote client indicated by `client_entry'. Before
1250 * private messages can be waited the silc_client_private_message_wait_init
1251 * must be called. This function can be used from a thread to wait for
1252 * private message from the specified client. Multiple threads can be
1253 * created to wait messages from multiple clients. Any other private
1254 * message received from the connection indicated by `conn' will be
1255 * forwarded to the normal `private_message' client operation callback.
1256 * The private messages from `client_entry' will not be delivered to the
1257 * `private_message' client operation callback.
1259 * Returns TRUE and the received private message into `payload'. The caller
1260 * must free the returned SilcMessagePayload. If this function returns
1261 * FALSE the private messages cannot be waited anymore. This happens
1262 * when some other thread calls silc_client_private_message_wait_uninit.
1263 * This returns FALSE also if silc_client_private_message_wait_init has
1267 SilcBool silc_client_private_message_wait(SilcClient client,
1268 SilcClientConnection conn,
1269 SilcClientEntry client_entry,
1270 SilcMessagePayload *payload);
1272 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1276 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1277 * SilcClientEntry client_entry);
1281 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1282 * channel indicated by the `channel'. NULL if client is not joined on
1286 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1287 SilcClientEntry client_entry);
1290 /* Command management */
1292 /****f* silcclient/SilcClientAPI/silc_client_command_call
1296 * SilcUInt16 silc_client_command_call(SilcClient client,
1297 * SilcClientConnection conn,
1298 * const char *command_line, ...);
1302 * Calls and executes the command indicated by the `command_name'.
1303 * The `command_line' is a string which includes the command's name and
1304 * its arguments separated with whitespaces (' '). If `command_line'
1305 * is non-NULL then all variable arguments are ignored by default.
1307 * If `command_line' is NULL, then the variable arguments define the
1308 * command's name and its arguments. The first variable argument must
1309 * be the command name. The variable argument list must be terminated
1312 * Returns command identifier for this sent command. It can be used
1313 * to additionally attach to the command reply using the function
1314 * silc_client_command_pending, if needed. Returns 0 on error.
1316 * The `command' client operation callback will be called when the
1317 * command is executed to indicate whether or not the command executed
1320 * The `command_reply' client operation callbak will be called when reply
1321 * is received from the server to the command. Application may also use
1322 * the silc_client_command_pending to attach to the command reply.
1323 * The command identifier for silc_client_command_pending function after
1324 * this function call is conn->cmd_ident, which application may use.
1328 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1330 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1334 * This command executes the commands implemented inside the client
1335 * library. These commands are designed for command line applications,
1336 * but GUI application may call them too if needed. Alternatively
1337 * application may override the library and use silc_client_command_send
1341 SilcUInt16 silc_client_command_call(SilcClient client,
1342 SilcClientConnection conn,
1343 const char *command_line, ...);
1345 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1349 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1350 * SilcClientConnection conn,
1351 * SilcCommand command,
1352 * SilcStatus status,
1359 * The command reply callback function given as argument to functions
1360 * silc_client_command_send and silc_client_command_pending. This is
1361 * called to deliver the command replies to the caller. Each command
1362 * reply received from the server to the `command' will be delivered
1363 * separately to the caller by calling this callback. The `status' will
1364 * indicate whether there is only one reply or multiple replies. The
1365 * `error' will indicate if an error occurred. The `ap' will include
1366 * command reply arguments. They are the same arguments as for
1367 * `command_reply' client operation callback in SilcClientOperations.
1369 * If `status' is SILC_STATUS_OK only one reply was received and error
1370 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1371 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1372 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1374 * If FALSE is returned in this function this callback will not be called
1375 * again for `command' even if there are more comand replies. By returning
1376 * FALSE the caller my stop the command reply handling when needed.
1379 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1380 SilcClientConnection conn,
1381 SilcCommand command,
1387 /****f* silcclient/SilcClientAPI/silc_client_command_send
1391 * SilcUInt16 silc_client_command_send(SilcClient client,
1392 * SilcClientConnection conn,
1393 * SilcCommand command,
1394 * SilcClientCommandReply reply,
1395 * void *reply_context,
1396 * SilcUInt32 argc, ...);
1400 * Generic function to send any command. The arguments must be given
1401 * already encoded into correct format and in correct order. If application
1402 * wants to perform the commands by itself, it can do so and send the data
1403 * directly to the server using this function. If application is using
1404 * the silc_client_command_call, this function is usually not used.
1405 * Programmer should get familiar with the SILC protocol commands
1406 * specification when using this function, as the arguments needs to
1407 * be encoded as specified in the protocol.
1409 * The variable arguments are a set of { type, data, data_length },
1410 * and the `argc' is the number of these sets.
1412 * The `reply' callback must be provided, and it is called when the
1413 * command reply is received from the server. Note that, when using this
1414 * function the default `command_reply' client operation callback will not
1415 * be called when reply is received.
1417 * Returns command identifier for this sent command. It can be used
1418 * to additionally attach to the command reply using the function
1419 * silc_client_command_pending, if needed. Returns 0 on error.
1423 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1424 * my_whois_command_reply, cmd_ctx,
1425 * 1, 1, nickname, strlen(nickname));
1428 SilcUInt16 silc_client_command_send(SilcClient client,
1429 SilcClientConnection conn,
1430 SilcCommand command,
1431 SilcClientCommandReply reply,
1432 void *reply_context,
1433 SilcUInt32 argc, ...);
1435 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1439 * void silc_client_command_pending(SilcClientConnection conn,
1440 * SilcCommand command,
1441 * SilcUInt16 cmd_ident,
1442 * SilcClientCommandReply reply,
1447 * This function can be used to add pending command callback to be
1448 * called when an command reply is received to an earlier sent command.
1449 * The `command' is the command that must be received in order for
1450 * the pending command callback indicated by `callback' to be called.
1452 * The `cmd_ident' is a command identifier which was set for the earlier
1453 * sent command. The command reply will include the same identifier
1454 * and pending command callback will be called when the reply is
1455 * received with the same command identifier. It is possible to
1456 * add multiple pending command callbacks for same command and for
1459 * Application may use this function to add its own command reply
1460 * handlers if it wishes not to use the standard `command_reply'
1463 * Note also that the application is notified about the received command
1464 * reply through the `command_reply' client operation before calling
1465 * the `callback` pending command callback. That is the normal
1466 * command reply handling, and is called regardless whether pending
1467 * command callbacks are used or not.
1471 * SilcUInt16 cmd_ident;
1472 * cmd_ident = silc_client_command_call(client, conn,
1473 * "PING silc.silcnet.org");
1474 * silc_client_command_pending(conn, SILC_COMMAND_PING, cmd_ident,
1475 * my_ping_handler, my_ping_context);
1478 SilcBool silc_client_command_pending(SilcClientConnection conn,
1479 SilcCommand command,
1480 SilcUInt16 cmd_ident,
1481 SilcClientCommandReply reply,
1485 /* Private Message key management */
1487 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1492 * silc_client_add_private_message_key(SilcClient client,
1493 * SilcClientConnection conn,
1494 * SilcClientEntry client_entry,
1495 * const char *cipher,
1497 * unsigned char *key,
1498 * SilcUInt32 key_len);
1502 * Adds a static private message key to the client library. The key
1503 * will be used to encrypt all private message between the client and
1504 * the remote client indicated by the `client_entry'. The `key' can
1505 * be for example a pre-shared-key, passphrase or similar shared secret
1506 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1507 * to assure that the requirements of the SILC protocol are met. The
1508 * API, however, allows to allocate any cipher and HMAC.
1510 * If the private message key is added to client without first receiving
1511 * a request for it from the remote `client_entry' this function will
1512 * send the request to `client_entry'. Note that, the actual key is
1513 * not sent to the network.
1515 * It is not necessary to set key for normal private message usage. If the
1516 * key is not set then the private messages are encrypted using normal
1517 * session keys. Setting the private key, however, increases security.
1519 * Returns FALSE if the key is already set for the `client_entry', TRUE
1523 SilcBool silc_client_add_private_message_key(SilcClient client,
1524 SilcClientConnection conn,
1525 SilcClientEntry client_entry,
1529 SilcUInt32 key_len);
1531 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1536 * silc_client_add_private_message_key_ske(SilcClient client,
1537 * SilcClientConnection conn,
1538 * SilcClientEntry client_entry,
1539 * const char *cipher,
1541 * SilcSKEKeyMaterial key);
1545 * Same as silc_client_add_private_message_key but takes the key material
1546 * from the SKE key material structure. This structure is received if
1547 * the application uses the silc_client_send_key_agreement to negotiate
1548 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1549 * negotiated also in the SKE protocol.
1552 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1553 SilcClientConnection conn,
1554 SilcClientEntry client_entry,
1557 SilcSKEKeyMaterial key);
1559 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1564 * silc_client_del_private_message_key(SilcClient client,
1565 * SilcClientConnection conn,
1566 * SilcClientEntry client_entry);
1570 * Removes the private message from the library. The key won't be used
1571 * after this to protect the private messages with the remote `client_entry'
1572 * client. Returns FALSE on error, TRUE otherwise.
1575 SilcBool silc_client_del_private_message_key(SilcClient client,
1576 SilcClientConnection conn,
1577 SilcClientEntry client_entry);
1579 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1583 * SilcPrivateMessageKeys
1584 * silc_client_list_private_message_keys(SilcClient client,
1585 * SilcClientConnection conn,
1586 * SilcUInt32 *key_count);
1590 * Returns array of set private message keys associated to the connection
1591 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1592 * count to the `key_count' argument. The array must be freed by the caller
1593 * by calling the silc_client_free_private_message_keys function. Note:
1594 * the keys returned in the array is in raw format. It might not be desired
1595 * to show the keys as is. The application might choose not to show the keys
1596 * at all or to show the fingerprints of the keys.
1599 SilcPrivateMessageKeys
1600 silc_client_list_private_message_keys(SilcClient client,
1601 SilcClientConnection conn,
1602 SilcUInt32 *key_count);
1604 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1608 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1609 * SilcUInt32 key_count);
1613 * Frees the SilcPrivateMessageKeys array returned by the function
1614 * silc_client_list_private_message_keys.
1617 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1618 SilcUInt32 key_count);
1620 /****f* silcclient/SilcClientAPI/silc_client_private_message_key_is_set
1625 * silc_client_private_message_key_is_set(SilcClient client,
1626 * SilcClientConnection conn,
1627 * SilcClientEntry client_entry);
1631 * Returns TRUE if the private message key has been set for the client
1632 * entry indicated by `client_entry'.
1636 silc_client_private_message_key_is_set(SilcClient client,
1637 SilcClientConnection conn,
1638 SilcClientEntry client_entry);
1641 /* Channel private key management */
1643 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1648 * silc_client_add_channel_private_key(SilcClient client,
1649 * SilcClientConnection conn,
1650 * SilcChannelEntry channel,
1654 * unsigned char *key,
1655 * SilcUInt32 key_len,
1656 * SilcChannelPrivateKey *ret_key);
1660 * Adds private key for channel. When channel has private key then the
1661 * messages are encrypted using that key. All clients on the channel
1662 * must also know the key in order to decrypt the messages. However,
1663 * it is possible to have several private keys per one channel. In this
1664 * case only some of the clients on the channel may know the one key
1665 * and only some the other key. The `name' can be application given
1666 * name for the key. This returns the created key to the 'ret_key'
1667 * pointer if it is non-NULL;
1669 * If `cipher' and/or `hmac' is NULL then default values will be used
1670 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1672 * The private key for channel is optional. If it is not set then the
1673 * channel messages are encrypted using the channel key generated by the
1674 * server. However, setting the private key (or keys) for the channel
1675 * significantly adds security. If more than one key is set the library
1676 * will automatically try all keys at the message decryption phase. Note:
1677 * setting many keys slows down the decryption phase as all keys has to
1678 * be tried in order to find the correct decryption key. However, setting
1679 * a few keys does not have big impact to the decryption performace.
1683 * NOTE: This is entirely local setting. The key set using this function
1684 * is not sent to the network at any phase.
1686 * NOTE: If the key material was originated by the SKE protocol (using
1687 * silc_client_send_key_agreement) then the `key' MUST be the
1688 * key->send_enc_key as this is dictated by the SILC protocol. However,
1689 * currently it is not expected that the SKE key material would be used
1690 * as channel private key. However, this API allows it.
1693 SilcBool silc_client_add_channel_private_key(SilcClient client,
1694 SilcClientConnection conn,
1695 SilcChannelEntry channel,
1701 SilcChannelPrivateKey *ret_key);
1703 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1707 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1708 * SilcClientConnection conn,
1709 * SilcChannelEntry channel);
1713 * Removes all private keys from the `channel'. The old channel key is used
1714 * after calling this to protect the channel messages. Returns FALSE on
1715 * on error, TRUE otherwise.
1718 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1719 SilcClientConnection conn,
1720 SilcChannelEntry channel);
1722 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1726 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1727 * SilcClientConnection conn,
1728 * SilcChannelEntry channel,
1729 * SilcChannelPrivateKey key);
1733 * Removes and frees private key `key' from the channel `channel'.
1734 * The `key' is retrieved by calling the function
1735 * silc_client_list_channel_private_keys. The key is not used after
1736 * this. If the key was last private key then the old channel key is
1737 * used hereafter to protect the channel messages. This returns FALSE
1738 * on error, TRUE otherwise.
1741 SilcBool silc_client_del_channel_private_key(SilcClient client,
1742 SilcClientConnection conn,
1743 SilcChannelEntry channel,
1744 SilcChannelPrivateKey key);
1746 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1751 * silc_client_list_channel_private_keys(SilcClient client,
1752 * SilcClientConnection conn,
1753 * SilcChannelEntry channel);
1757 * Returns list of private keys associated to the `channel'. The caller
1758 * must free the returned list with silc_dlist_uninit. The pointers in
1759 * the list may be used to delete the specific key by giving the pointer
1760 * as argument to the function silc_client_del_channel_private_key. Each
1761 * entry in the list is SilcChannelPrivateKey.
1764 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1765 SilcClientConnection conn,
1766 SilcChannelEntry channel);
1768 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1772 * void silc_client_current_channel_private_key(SilcClient client,
1773 * SilcClientConnection conn,
1774 * SilcChannelEntry channel,
1775 * SilcChannelPrivateKey key);
1779 * Sets the `key' to be used as current channel private key on the
1780 * `channel'. Packet sent after calling this function will be secured
1784 void silc_client_current_channel_private_key(SilcClient client,
1785 SilcClientConnection conn,
1786 SilcChannelEntry channel,
1787 SilcChannelPrivateKey key);
1790 /* Key Agreement routines */
1792 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1796 * void silc_client_send_key_agreement(SilcClient client,
1797 * SilcClientConnection conn,
1798 * SilcClientEntry client_entry,
1799 * SilcClientConnectionParams *params,
1800 * SilcPublicKey public_key,
1801 * SilcPrivateKey private_key,
1802 * SilcKeyAgreementCallback completion,
1807 * Sends key agreement request to the remote client indicated by the
1810 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1811 * the caller will provide the connection endpoint for the key agreement
1812 * connection. The `bind_ip' can be used to bind to that IP instead of
1813 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1814 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1815 * and `timeout_secs' fields in `params'. Other fields are ignored.
1816 * If `params' is NULL, then the `client_entry' is expected to provide
1817 * the connection endpoint for us. It is recommended the `timeout_secs'
1818 * is specified in case the remote client does not reply anything to
1821 * The `public_key' and `private_key' is our identity in the key agreement.
1823 * In case we do not provide the connection endpoint, we will receive
1824 * the `key_agreement' client operation when the remote send its own
1825 * key agreement request packet. We may then there start the key
1826 * agreement with silc_client_perform_key_agreement. If we provided the
1827 * the connection endpoint, the client operation will not be called.
1829 * There can be only one active key agreement for `client_entry'. Old
1830 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1834 * // Send key agreement request (we don't provide connection endpoint)
1835 * silc_client_send_key_agreement(client, conn, remote_client,
1836 * NULL, public_key, private_key,
1837 * my_keyagr_completion, my_context);
1839 * // Another example where we provide connection endpoint (TCP).
1840 * SilcClientConnectionParams params;
1841 * memset(¶ms, 0, sizeof(params));
1842 * params.local_ip = local_ip;
1843 * params.local_port = local_port;
1844 * params.timeout_secs = 60;
1845 * silc_client_send_key_agreement(client, conn, remote_client,
1846 * ¶ms, public_key, private_key,
1847 * my_keyagr_completion, my_context);
1850 void silc_client_send_key_agreement(SilcClient client,
1851 SilcClientConnection conn,
1852 SilcClientEntry client_entry,
1853 SilcClientConnectionParams *params,
1854 SilcPublicKey public_key,
1855 SilcPrivateKey private_key,
1856 SilcKeyAgreementCallback completion,
1859 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1864 * silc_client_perform_key_agreement(SilcClient client,
1865 * SilcClientConnection conn,
1866 * SilcClientEntry client_entry,
1867 * SilcClientConnectionParams *params,
1868 * SilcPublicKey public_key,
1869 * SilcPrivateKey private_key,
1870 * char *hostname, int port,
1871 * SilcKeyAgreementCallback completion,
1876 * Performs the key agreement protocol. Application may use this to
1877 * initiate the key agreement protocol. Usually this is called after
1878 * receiving the `key_agreement' client operation.
1880 * The `hostname' is the remote hostname (or IP address) and the `port'
1881 * is the remote port. The `completion' callback with the `context' will
1882 * be called after the key agreement protocol.
1884 * The `params' is connection parameters and it may be used to define
1885 * the key agreement connection related parameters. It may be NULL.
1888 void silc_client_perform_key_agreement(SilcClient client,
1889 SilcClientConnection conn,
1890 SilcClientEntry client_entry,
1891 SilcClientConnectionParams *params,
1892 SilcPublicKey public_key,
1893 SilcPrivateKey private_key,
1894 char *hostname, int port,
1895 SilcKeyAgreementCallback completion,
1898 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1903 * silc_client_perform_key_agreement_stream(
1904 * SilcClient client,
1905 * SilcClientConnection conn,
1906 * SilcClientEntry client_entry,
1907 * SilcClientConnectionParams *params,
1908 * SilcPublicKey public_key,
1909 * SilcPrivateKey private_key,
1910 * SilcStream stream,
1911 * SilcKeyAgreementCallback completion,
1916 * Same as silc_client_perform_key_agreement but the caller has created
1917 * the connection to remote client. The `stream' is the created
1922 silc_client_perform_key_agreement_stream(SilcClient client,
1923 SilcClientConnection conn,
1924 SilcClientEntry client_entry,
1925 SilcClientConnectionParams *params,
1926 SilcPublicKey public_key,
1927 SilcPrivateKey private_key,
1929 SilcKeyAgreementCallback completion,
1932 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1936 * void silc_client_abort_key_agreement(SilcClient client,
1937 * SilcClientConnection conn,
1938 * SilcClientEntry client_entry);
1942 * This function can be called to unbind the hostname and the port for
1943 * the key agreement protocol. However, this function has effect only
1944 * before the key agreement protocol has been performed. After it has
1945 * been performed the library will automatically unbind the port. The
1946 * `client_entry' is the client to which we sent the key agreement
1947 * request. The key agreement completion callback will be called
1948 * with SILC_KEY_AGREEMENT_ABORTED status.
1951 void silc_client_abort_key_agreement(SilcClient client,
1952 SilcClientConnection conn,
1953 SilcClientEntry client_entry);
1956 /* Misc functions */
1958 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1962 * SilcBool silc_client_set_away_message(SilcClient client,
1963 * SilcClientConnection conn,
1968 * Sets away `message'. The away message may be set when the client's
1969 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1970 * to anyone who sends private message. The `message' will be sent
1971 * automatically back to the the client who send private message. If
1972 * away message is already set this replaces the old message with the
1973 * new one. If `message' is NULL the old away message is removed.
1974 * The sender may freely free the memory of the `message'. Returns
1978 SilcBool silc_client_set_away_message(SilcClient client,
1979 SilcClientConnection conn,
1982 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1986 * typedef enum { ... } SilcClientMonitorStatus;
1990 * File transmission session status types. These will indicate
1991 * the status of the file transmission session.
1993 * The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session
1994 * is key exchange phase.
1996 * The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent
1999 * The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being
2000 * recieved from remote client.
2002 * The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user
2003 * issues silc_client_file_close. If needed, it may be ignored in the
2006 * The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote
2007 * disconnects the session connection. The silc_client_file_close must
2008 * be called when this status is received. The session is over when
2011 * The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error
2012 * occured. The SilcClientFileError will indicate more detailed error
2013 * condition. The silc_client_file_close must be called when this status
2014 * is received. The session is over when this is received.
2019 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2020 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2021 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2022 SILC_CLIENT_FILE_MONITOR_GET, /* Unsupported */
2023 SILC_CLIENT_FILE_MONITOR_PUT, /* Unsupported */
2024 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2025 SILC_CLIENT_FILE_MONITOR_DISCONNECT, /* Session disconnected */
2026 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2027 } SilcClientMonitorStatus;
2030 /****d* silcclient/SilcClientAPI/SilcClientFileError
2034 * typedef enum { ... } SilcClientFileError;
2038 * File transmission error types. These types are returned by
2039 * some of the file transmission functions, and by the monitor
2040 * callback to indicate error.
2045 SILC_CLIENT_FILE_OK,
2046 SILC_CLIENT_FILE_ERROR, /* Generic error */
2047 SILC_CLIENT_FILE_UNKNOWN_SESSION, /* Unknown session ID */
2048 SILC_CLIENT_FILE_ALREADY_STARTED, /* Session already started */
2049 SILC_CLIENT_FILE_NO_SUCH_FILE, /* No such file */
2050 SILC_CLIENT_FILE_PERMISSION_DENIED, /* Permission denied */
2051 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED, /* Key exchange failed */
2052 SILC_CLIENT_FILE_CONNECT_FAILED, /* Error during connecting */
2053 SILC_CLIENT_FILE_TIMEOUT, /* Connecting timedout */
2054 SILC_CLIENT_FILE_NO_MEMORY, /* System out of memory */
2055 } SilcClientFileError;
2058 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2062 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2063 * SilcClientConnection conn,
2064 * SilcClientMonitorStatus status,
2065 * SilcClientFileError error,
2066 * SilcUInt64 offset,
2067 * SilcUInt64 filesize,
2068 * SilcClientEntry client_entry,
2069 * SilcUInt32 session_id,
2070 * const char *filepath,
2075 * Monitor callback that is called during the file transmission to
2076 * monitor the transmission process. The `status' indicates the current
2077 * monitoring process. The `error' will indicate the error type
2078 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2079 * currently transmitted amount of total `filesize'. The `client_entry'
2080 * indicates the remote client, and the transmission session ID is the
2081 * `session_id'. The filename being transmitted is indicated by the
2082 * `filepath'. The `conn' is NULL if the connection to remote client
2083 * does not exist yet.
2086 typedef void (*SilcClientFileMonitor)(SilcClient client,
2087 SilcClientConnection conn,
2088 SilcClientMonitorStatus status,
2089 SilcClientFileError error,
2091 SilcUInt64 filesize,
2092 SilcClientEntry client_entry,
2093 SilcUInt32 session_id,
2094 const char *filepath,
2097 /****f* silcclient/SilcClientAPI/SilcClientFileName
2101 * typedef void (*SilcClientFileName)(const char *filepath,
2106 * Completion callback for the SilcClientFileAskName callback function.
2107 * Application calls this to deliver the filepath and filename where
2108 * the downloaded file is to be saved.
2111 typedef void (*SilcClientFileName)(const char *filepath,
2114 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2118 * typedef void (*SilcClientFileAskName)(SilcClient client,
2119 * SilcClientConnection conn,
2120 * SilcUInt32 session_id,
2121 * const char *remote_filename,
2122 * SilcClientFileName completion,
2123 * void *completion_context,
2128 * File name asking callback that is called if it is given to the
2129 * silc_client_file_receive and the path given to that as argument was
2130 * NULL. The library calls this to ask the filename and filepath to
2131 * where the file is to be saved. The 'remote_filename' is the file
2132 * that is being downloaded. Application must call the 'completion'
2133 * with 'completion_context' to continue with the file downloading.
2134 * It is not mandatory to provide this to the silc_client_file_receive.
2137 typedef void (*SilcClientFileAskName)(SilcClient client,
2138 SilcClientConnection conn,
2139 SilcUInt32 session_id,
2140 const char *remote_filename,
2141 SilcClientFileName completion,
2142 void *completion_context,
2145 /****f* silcclient/SilcClientAPI/silc_client_file_send
2149 * SilcClientFileError
2150 * silc_client_file_send(SilcClient client,
2151 * SilcClientConnection conn,
2152 * SilcClientEntry client_entry,
2153 * SilcClientConnectionParams *params,
2154 * SilcPublicKey public_key,
2155 * SilcPrivateKey private_key,
2156 * SilcClientFileMonitor monitor,
2157 * void *monitor_context,
2158 * const char *filepath,
2159 * SilcUInt32 *session_id);
2163 * Sends a file indicated by the `filepath' to the remote client
2164 * indicated by the `client_entry'. This will negotiate a secret key
2165 * with the remote client before actually starting the transmission of
2166 * the file. The `monitor' callback will be called to monitor the
2167 * transmission of the file.
2169 * This returns a file session ID for the file transmission to the
2170 * `session_id' pointer. It can be used to close the session (and
2171 * abort the file transmission) by calling the silc_client_file_close
2172 * function. The session ID is also returned in the `monitor' callback.
2174 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
2175 * the caller will provide the connection endpoint for the key agreement
2176 * connection. The `bind_ip' can be used to bind to that IP instead of
2177 * `local_ip'. Caller may also set the `repository', `verify_notfound'
2178 * and `timeout_secs' fields in `params'. Other fields are ignored.
2179 * If `params' is NULL, then the `client_entry' is expected to provide
2180 * the connection endpoint for us. It is recommended the `timeout_secs'
2181 * is specified in case the remote client does not reply anything to
2184 * The `public_key' and `private_key' is our identity in the key agreement.
2186 * If error will occur during the file transfer process the error status
2187 * will be returned in the monitor callback. In this case the application
2188 * must call silc_client_file_close to close the session.
2192 silc_client_file_send(SilcClient client,
2193 SilcClientConnection conn,
2194 SilcClientEntry client_entry,
2195 SilcClientConnectionParams *params,
2196 SilcPublicKey public_key,
2197 SilcPrivateKey private_key,
2198 SilcClientFileMonitor monitor,
2199 void *monitor_context,
2200 const char *filepath,
2201 SilcUInt32 *session_id);
2203 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2207 * SilcClientFileError
2208 * silc_client_file_receive(SilcClient client,
2209 * SilcClientConnection conn,
2210 * SilcClientConnectionParams *params,
2211 * SilcPublicKey public_key,
2212 * SilcPrivateKey private_key,
2213 * SilcClientFileMonitor monitor,
2214 * void *monitor_context,
2216 * SilcUInt32 session_id,
2217 * SilcClientFileAskName ask_name,
2218 * void *ask_name_context);
2222 * Receives a file from a client indicated by the `client_entry'. The
2223 * `session_id' indicates the file transmission session and it has been
2224 * received in the `ftp' client operation callback. This will actually
2225 * perform the key agreement protocol with the remote client before
2226 * actually starting the file transmission. The `monitor' callback
2227 * will be called to monitor the transmission. If `path' is non-NULL
2228 * the file will be saved into that directory. If NULL the file is
2229 * saved in the current working directory, unless the 'ask_name'
2230 * callback is non-NULL. In this case the callback is called to ask
2231 * the path and filename from application.
2233 * The `params' is the connection related parameters. If the remote client
2234 * provided connection point the `params' will be used when creating
2235 * connection to the remote client. If remote client did not provide
2236 * connection point the `params' is used to provide connection point
2237 * locally for the remote client. See silc_client_file_send for more
2238 * information on providing connection point for remote client.
2240 * The `public_key' and `private_key' is our identity in the key agreement.
2242 * If error will occur during the file transfer process the error status
2243 * will be returned in the monitor callback. In this case the application
2244 * must call silc_client_file_close to close the session.
2248 silc_client_file_receive(SilcClient client,
2249 SilcClientConnection conn,
2250 SilcClientConnectionParams *params,
2251 SilcPublicKey public_key,
2252 SilcPrivateKey private_key,
2253 SilcClientFileMonitor monitor,
2254 void *monitor_context,
2256 SilcUInt32 session_id,
2257 SilcClientFileAskName ask_name,
2258 void *ask_name_context);
2260 /****f* silcclient/SilcClientAPI/silc_client_file_close
2264 * SilcClientFileError silc_client_file_close(SilcClient client,
2265 * SilcClientConnection conn,
2266 * SilcUInt32 session_id);
2270 * Closes file transmission session indicated by the `session_id'.
2271 * If file transmission is being conducted it will be aborted
2272 * automatically. This function is also used to close the session
2273 * after successful file transmission. This function can be used
2274 * also to reject incoming file transmission request. If the
2275 * session was already started and the monitor callback was set
2276 * the monitor callback will be called with the monitor status
2277 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2280 SilcClientFileError silc_client_file_close(SilcClient client,
2281 SilcClientConnection conn,
2282 SilcUInt32 session_id);
2284 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2288 * SilcAttributePayload
2289 * silc_client_attribute_add(SilcClient client,
2290 * SilcClientConnection conn,
2291 * SilcAttribute attribute,
2293 * SilcUInt32 object_size);
2297 * Add new Requsted Attribute for WHOIS command to the client library.
2298 * The `attribute' object indicated by `object' is added and allocated
2299 * SilcAttributePayload is returned. The `object' must be of correct
2300 * type and of correct size. See the SilcAttribute for object types
2301 * for different attributes. You may also get all added attributes
2302 * from the client with silc_client_attributes_get function.
2304 * Requested Attributes are different personal information about the
2305 * user, status information and other information which other users
2306 * may query with WHOIS command. Application may set these so that
2307 * if someone sends WHOIS query these attributes will be replied back
2308 * to the sender. The library always puts the public key to the
2309 * Requested Attributes, but if application wishes to add additional
2310 * public keys (or certificates) it can be done with this interface.
2311 * Library also always computes digital signature of the attributes
2312 * automatically, so application does not need to do that.
2315 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2316 SilcClientConnection conn,
2317 SilcAttribute attribute,
2319 SilcUInt32 object_size);
2321 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2325 * SilcBool silc_client_attribute_del(SilcClient client,
2326 * SilcClientConnection conn,
2327 * SilcAttribute attribute,
2328 * SilcAttributePayload attr);
2332 * Delete a Requested Attribute from the client. If the `attribute'
2333 * is non-zero then all attributes of that type are deleted and the
2334 * `attr' is ignored. If `attr' is non-NULL then that specific
2335 * attribute is deleted and `attribute' is ignored.
2337 * You may get all added attributes with the function
2338 * silc_client_attributes_get and to get the SilcAttributePayload.
2339 * This function Returns TRUE if the attribute was found and deleted.
2342 SilcBool silc_client_attribute_del(SilcClient client,
2343 SilcClientConnection conn,
2344 SilcAttribute attribute,
2345 SilcAttributePayload attr);
2347 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2351 * const SilcHashTable
2352 * silc_client_attributes_get(SilcClient client,
2353 * SilcClientConnection conn);
2357 * Returns pointer to the SilcHashTable which includes all the added
2358 * Requested Attributes. The caller must not free the hash table.
2359 * The caller may use SilcHashTableList and silc_hash_table_list to
2360 * traverse the table. Each entry in the hash table is one added
2361 * SilcAttributePayload. It is possible to delete a attribute
2362 * payload while traversing the table.
2365 SilcHashTable silc_client_attributes_get(SilcClient client,
2366 SilcClientConnection conn);
2368 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2372 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2376 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2377 * then all attributes are requested. Alternatively, `attribute' and
2378 * all variable arguments can each be requested attribute. In this case
2379 * the last must be set to zero (0) to complete the variable list of
2380 * requested attributes. See SilcAttribute for all attributes.
2381 * You can give the returned buffer as argument to for example
2382 * silc_client_get_client_by_id_resolve function.
2386 * Request all attributes
2387 * buffer = silc_client_attributes_request(0);
2389 * Request only the following attributes
2390 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2391 * SILC_ATTRIBUTE_SERVICE,
2392 * SILC_ATTRIBUTE_MOOD, 0);
2395 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2397 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2402 * silc_client_nickname_format(SilcClient client,
2403 * SilcClientConnection conn,
2404 * SilcClientEntry client_entry,
2405 * SilcBool priority);
2409 * Formats the nickname of `client_entry' according to the nickname
2410 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2411 * then the `client_entry' will always get the unformatted nickname.
2412 * If FALSE and there are more than one same nicknames in the client
2413 * the nickname will be formatted.
2415 * This returns NULL on error. Otherwise, the client entry that was
2416 * formatted is returned. If `priority' is FALSE this always returns
2417 * the `client_entry'. If it is TRUE, this may return the client entry
2418 * that was formatted after giving the `client_entry' the unformatted
2421 * Usually application does not need to call this function, as the library
2422 * automatically formats nicknames. However, if application wants to
2423 * for example force the `client_entry' to always have the unformatted
2424 * nickname it may call this function to do so.
2427 SilcClientEntry silc_client_nickname_format(SilcClient client,
2428 SilcClientConnection conn,
2429 SilcClientEntry client_entry,
2432 /****f* silcclient/SilcClientAPI/silc_client_nickname_parse
2436 * SilcBool silc_client_nickname_parse(SilcClient client,
2437 * SilcClientConnection conn,
2443 * Parses the `nickname' according to the format string given in the
2444 * SilcClientParams. Returns the parsed nickname into the `ret_nick'.
2445 * The caller must free the returned pointer. Returns FALSE if error
2446 * occurred during parsing. Returns TRUE if the nickname was parsed,
2447 * it was not formatted or if the format string has not been specified
2448 * in SilcClientParams.
2451 SilcBool silc_client_nickname_parse(SilcClient client,
2452 SilcClientConnection conn,
2460 #endif /* SILCCLIENT_H */