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.
675 Note that, using '@' as a separator is not recommended as the nickname
676 string may contain it to separate a server name from the nickname (eg.
677 nickname@silcnet.org).
679 char nickname_format[32];
681 /* If this is set to TRUE then the `nickname_format' is employed to all
682 saved nicknames even if there are no multiple same nicknames in the
683 cache. By default this is FALSE, which means that the `nickname_format'
684 is employed only if the library will receive a nickname that is
685 already saved in the cache. It is recommended to leave this to FALSE
687 SilcBool nickname_force_format;
689 /* If this is set to TRUE then all nickname strings returned by the library
690 and stored by the library are in the format of 'nickname@server', eg.
691 nickname@silcnet.org. If this is FALSE then the server name of the
692 nickname is available only from the SilcClientEntry structure. When this
693 is TRUE the server name is still parsed to SilcClientEntry. */
694 SilcBool full_nicknames;
696 /* If this is set to TRUE then all channel name strings returned by the
697 library and stored by the library are in the format of 'channel@server',
698 eg. silc@silcnet.org. If this is FALSE then the server name of the
699 channel is available only from the SilcChannelEntry structure. When this
700 is TRUE the server name is still parsed to SilcChannelEntry. Note that,
701 not all SILC server versions return such channel name strings. */
702 SilcBool full_channel_names;
704 /* If this is set to TRUE, the silcclient library will not initialize
705 or uninitialize the SILC Crypto Toolkit. The application will have
706 to do that itself by calling silc_crypto_init and silc_crypto_uninit. */
707 SilcBool dont_register_crypto_library;
713 /* Initialization functions (client.c) */
715 /****f* silcclient/SilcClientAPI/silc_client_alloc
719 * SilcClient silc_client_alloc(SilcClientOperations *ops,
720 * SilcClientParams *params,
722 * const char *silc_version);
726 * Allocates new client object. This has to be done before client may
727 * work. After calling this one must call silc_client_init to initialize
728 * the client. The `application' is application specific user data pointer
729 * and caller must free it. The `silc_version' is the application version
730 * that will be used to compare against remote host's (usually a server)
731 * version string. The `application' context is accessible by the
732 * application by client->application, client being SilcClient.
735 SilcClient silc_client_alloc(SilcClientOperations *ops,
736 SilcClientParams *params,
738 const char *version_string);
740 /****f* silcclient/SilcClientAPI/silc_client_free
744 * void silc_client_free(SilcClient client);
748 * Frees client object and its internals. The execution of the client
749 * should be stopped with silc_client_stop function before calling
753 void silc_client_free(SilcClient client);
755 /****f* silcclient/SilcClientAPI/silc_client_init
759 * SilcBool silc_client_init(SilcClient client, const char *username,
760 * const char *hostname, const char *realname,
761 * SilcClientRunning running, void *context);
765 * Initializes the client. This makes all the necessary steps to make
766 * the client ready to be run. One must call silc_client_run to run the
767 * client. Returns FALSE if error occurred, TRUE otherwise.
769 * The `username' and `hostname' strings must be given and they must be
770 * UTF-8 encoded. The `username' is the client's username in the
771 * operating system, `hostname' is the client's host name and the
772 * `realname' is the user's real name.
774 * The `running' callback with `context' is called after the client is
775 * running after silc_client_run or silc_client_run_one has been called.
776 * Application may start using the Client library API after that. Setting
777 * the callback is optional, but highly recommended.
780 SilcBool silc_client_init(SilcClient client, const char *username,
781 const char *hostname, const char *realname,
782 SilcClientRunning running, void *context);
784 /****f* silcclient/SilcClientAPI/silc_client_run
788 * void silc_client_run(SilcClient client);
792 * Runs the client. This starts the scheduler from the utility library.
793 * When this functions returns the execution of the application is over.
794 * The client must be initialized before calling this.
797 void silc_client_run(SilcClient client);
799 /****f* silcclient/SilcClientAPI/silc_client_run_one
803 * void silc_client_run_one(SilcClient client);
807 * Runs the client and returns immeadiately. This function is used when
808 * the SILC Client object indicated by the `client' is run under some
809 * other scheduler, or event loop or main loop. On GUI applications,
810 * for example this may be desired to used to run the client under the
811 * GUI application's main loop. Typically the GUI application would
812 * register an idle task that calls this function multiple times in
813 * a second to quickly process the SILC specific data.
816 void silc_client_run_one(SilcClient client);
818 /****f* silcclient/SilcClientAPI/silc_client_stop
822 * void silc_client_stop(SilcClient client, SilcClientStopped stopped,
827 * Stops the client. This is called to stop the client and thus to stop
828 * the program. The client context must be freed with the silc_client_free
829 * function. All connections that exist in this client must be closed
830 * before calling this function. Connections can be closed by calling
831 * silc_client_close_connection.
833 * The `stopped' will be called once the client and all connections have
834 * finished. The client may be freed after that. Note that the `stopped'
835 * won't be called before all connections have finished. Setting the
836 * callback is optional.
839 void silc_client_stop(SilcClient client, SilcClientStopped stopped,
842 /* Connecting functions */
844 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
848 * typedef struct { ... } SilcClientConnectionParams;
852 * Client connection parameters. This can be filled by the application
853 * and given as argument to silc_client_connect_to_server,
854 * silc_client_connect_to_client, silc_client_key_exchange or
855 * silc_client_send_key_agreement.
859 typedef struct SilcClientConnectionParamsStruct {
860 /* If this is provided the user's nickname in the network will be the
861 string given here. If it is given, it must be UTF-8 encoded. If this
862 string is not given, the user's username by default is used as nickname.
863 The nickname may later be changed by using NICK command. The maximum
864 length for the nickname string is 128 bytes. */
867 /* If this key repository pointer is non-NULL then public key received in
868 the key exchange protocol will be verified from this repository. If
869 this is not provided then the `verify_public_key' client operation will
870 be called back to application. If the boolean `verify_notfound' is set
871 to TRUE then the `verify_public_key' client operation will be called
872 in case the public key is not found in `repository'. Only public keys
873 added with at least SILC_SKR_USAGE_KEY_AGREEMENT in the repository will
874 be checked, other keys will be ignored. */
876 SilcBool verify_notfound;
878 /* Authentication data. Application may set here the authentication data
879 and authentication method to be used in connecting. If `auth_set'
880 boolean is TRUE then authentication data is provided by application.
881 If the authentication method is public key authentication then the key
882 pair given as argument when connecting will be used and `auth' field
883 is NULL. If it is passphrase authentication, it can be provided in
884 `auth' and `auth_len' fields. If `auth_set' is FALSE
885 the `get_auth_method' client operation will be called to get the
886 authentication method and data from application. */
888 SilcAuthMethod auth_method;
892 /* If this boolean is set to TRUE then the connection will use UDP instead
893 of TCP. If UDP is set then also the next `local_ip' and `local_port'
897 /* The `local_ip' specifies the local IP address used with the connection.
898 It must be non-NULL if `udp' boolean is TRUE. If the `local_port' is
899 non-zero it will be used as local port with UDP connection. The remote
900 host will also send packets to the specified address and port. If the
901 `bind_ip' is non-NULL a listener is bound to that address instead of
907 /* If this boolean is set to TRUE then the key exchange is done with
908 perfect forward secrecy. */
911 /* If this boolean is set to TRUE then connection authentication protocol
912 is not performed during connecting. Only key exchange protocol is
913 performed. This usually must be set to TRUE when connecting to another
914 client, but must be FALSE with server connections. */
915 SilcBool no_authentication;
917 /* The SILC session detachment data that was returned in the `command_reply'
918 client operation for SILC_COMMAND_DETACH command. If this is provided
919 here the client library will attempt to resume the session in the network.
920 After the connection is created and the session has been resumed the
921 client will receive SILC_COMMAND_NICK command_reply for the client's
922 nickname in the network and SILC_COMMAND_JOIN command reply for all the
923 channels that the client has joined in the network. It may also receive
924 SILC_COMMAND_UMODE command reply to set user's mode on the network. */
925 unsigned char *detach_data;
926 SilcUInt32 detach_data_len;
928 /* Connection timeout. If non-zero, the connection will timeout unless
929 the SILC connection is completed in the specified amount of time. */
930 SilcUInt32 timeout_secs;
932 /* Rekey timeout in seconds. The client will perform rekey in this
933 time interval. If set to zero, the default value will be used
934 (3600 seconds, 1 hour). */
935 SilcUInt32 rekey_secs;
937 /* If this is set to TRUE then the client will ignore all incoming
938 Requested Attributes queries and does not reply anything back. This
939 usually leads into situation where server does not anymore send
940 the queries after seeing that client does not reply anything back.
941 If your application does not support Requested Attributes or you do
942 not want to use them set this to TRUE. See SilcAttribute and
943 silc_client_attribute_add for more information on attributes. */
944 SilcBool ignore_requested_attributes;
946 } SilcClientConnectionParams;
949 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
954 * silc_client_connect_to_server(SilcClient client,
955 * SilcClientConnectionParams *params,
956 * SilcPublicKey public_key,
957 * SilcPrivateKey private_key,
958 * char *remote_host, int port,
959 * SilcClientConnectCallback callback,
964 * Connects to remote server `remote_host' at port `port'. This function
965 * can be used to create connection to remote SILC server and start
966 * SILC session in the SILC network. The `params' may be provided
967 * to provide various connection parameters. The `public_key' and the
968 * `private_key' is your identity used in this connection. When
969 * authentication method is based on digital signatures, this key pair
970 * will be used. The `callback' with `context' will be called after the
971 * connection has been created. It will also be called later when remote
974 * If application wishes to create the network connection itself, use
975 * the silc_client_key_exchange after creating the connection to start
976 * key exchange and authentication with the server.
978 * Returns SilcAsyncOperation which can be used to cancel the connecting,
979 * or NULL on error. Note that the returned pointer becomes invalid
980 * after the `callback' is called.
984 silc_client_connect_to_server(SilcClient client,
985 SilcClientConnectionParams *params,
986 SilcPublicKey public_key,
987 SilcPrivateKey private_key,
988 char *remote_host, int port,
989 SilcClientConnectCallback callback,
992 /****f* silcclient/SilcClientAPI/silc_client_connect_to_client
997 * silc_client_connect_to_client(SilcClient client,
998 * SilcClientConnectionParams *params,
999 * SilcPublicKey public_key,
1000 * SilcPrivateKey private_key,
1001 * char *remote_host, int port,
1002 * SilcClientConnectCallback callback,
1007 * Connects to remote client `remote_host' at port `port'. This function
1008 * can be used to create peer-to-peer connection to another SILC client,
1009 * for example, for direct conferencing, or file transfer or for other
1010 * purposes. The `params' may be provided to provide various connection
1011 * parameters. The `public_key' and the `private_key' is your identity
1012 * used in this connection. The `callback' with `context' will be called
1013 * after the connection has been created. It will also be called later
1014 * when remote host disconnects.
1016 * If application wishes to create the network connection itself, use
1017 * the silc_client_key_exchange after creating the connection to start
1018 * key exchange with the client.
1020 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1021 * or NULL on error. Note that the returned pointer becomes invalid
1022 * after the `callback' is called.
1026 silc_client_connect_to_client(SilcClient client,
1027 SilcClientConnectionParams *params,
1028 SilcPublicKey public_key,
1029 SilcPrivateKey private_key,
1030 char *remote_host, int port,
1031 SilcClientConnectCallback callback,
1034 /****f* silcclient/SilcClientAPI/silc_client_key_exchange
1038 * SilcAsyncOperation
1039 * silc_client_key_exchange(SilcClient client,
1040 * SilcClientConnectionParams *params,
1041 * SilcPublicKey public_key,
1042 * SilcPrivateKey private_key,
1043 * SilcStream stream,
1044 * SilcConnectionType conn_type,
1045 * SilcClientConnectCallback callback,
1050 * Starts key exchange protocol and authentication protocol in the
1051 * connection indicated by `stream'. This function can be be used to
1052 * start SILC session with remote host (usually server) when the caller
1053 * has itself created the connection, instead of calling the function
1054 * silc_client_connect_to_server or silc_client_connect_to_client. If
1055 * one of those functions was used this function must not be called as
1056 * in that case the key exchange is performed automatically.
1058 * Use this function only if you have created the connection by yourself.
1059 * After creating the connection the socket must be wrapped into a
1060 * socket stream. See silcsocketstream.h for more information. Note that
1061 * the `stream' must have valid remote IP address (and optionally also
1062 * hostname) and port set.
1064 * The `params' may be provided to provide various connection parameters.
1065 * The `public_key' and the `private_key' is your identity used in this
1066 * session. The `callback' with `context' will be called after the session
1067 * has been set up. It will also be called later when remote host
1068 * disconnects. The `conn_type' is the type of session this is going to
1069 * be. If the remote is SILC server it is SILC_CONN_SERVER or if it is
1070 * SILC client it is SILC_CONN_CLIENT.
1072 * Returns SilcAsyncOperation which can be used to cancel the connecting,
1073 * or NULL on error. Note that the returned pointer becomes invalid
1074 * after the `callback' is called.
1080 * // Create remote connection stream. Resolve hostname and IP also.
1081 * sock = create_connection(remote_host, port);
1082 * silc_socket_tcp_stream_create(sock, TRUE, FALSE, schedule,
1083 * stream_create_cb, app);
1085 * // Stream callback delivers our new SilcStream context
1086 * void stream_create_cb(SilcResult status, SilcStream stream,
1090 * if (status != SILC_OK)
1093 * // Start key exchange
1094 * silc_client_key_exchange(client, NULL, public_key, private_key,
1095 * stream, SILC_CONN_SERVER, connection_cb, app);
1101 silc_client_key_exchange(SilcClient client,
1102 SilcClientConnectionParams *params,
1103 SilcPublicKey public_key,
1104 SilcPrivateKey private_key,
1106 SilcConnectionType conn_type,
1107 SilcClientConnectCallback callback,
1110 /****f* silcclient/SilcClientAPI/silc_client_close_connection
1114 * void silc_client_close_connection(SilcClient client,
1115 * SilcClientConnection conn);
1119 * Closes the remote connection `conn'. The `conn' will become invalid
1120 * after this call. Usually this function is called only when explicitly
1121 * closing connection for example in case of error, or when the remote
1122 * connection was created by the application or when the remote is client
1123 * connection. Server connections are usually closed by sending QUIT
1124 * command to the server. However, this call may also be used.
1127 void silc_client_close_connection(SilcClient client,
1128 SilcClientConnection conn);
1130 /* Message sending functions */
1132 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
1136 * SilcBool silc_client_send_channel_message(SilcClient client,
1137 * SilcClientConnection conn,
1138 * SilcChannelEntry channel,
1139 * SilcChannelPrivateKey key,
1140 * SilcMessageFlags flags,
1142 * unsigned char *data,
1143 * SilcUInt32 data_len);
1147 * Sends encrypted message to the `channel'. The plaintext message is
1148 * the `data' of `data_len' bytes in length.
1150 * If `key' is provided then that private channel message key is used to
1151 * encrypt the message. If it is not provided and the `channel' does not
1152 * have SILC_CHANNEL_MODE_PRIVKEY set, the curent channel key is used
1153 * instead. If the mode is set but `key' is NULL the key that was added
1154 * first as private channel message key will be used.
1156 * If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
1157 * digitally signed with the SILC key pair associated with the `conn'.
1158 * In this case the `hash' pointer must be provided as well.
1160 * Returns TRUE if the message was sent, and FALSE if error occurred or
1161 * the sending is not allowed due to channel modes (like sending is
1162 * blocked). This function is thread safe and private messages can be
1163 * sent from multiple threads.
1166 SilcBool silc_client_send_channel_message(SilcClient client,
1167 SilcClientConnection conn,
1168 SilcChannelEntry channel,
1169 SilcChannelPrivateKey key,
1170 SilcMessageFlags flags,
1172 unsigned char *data,
1173 SilcUInt32 data_len);
1175 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
1179 * SilcBool silc_client_send_private_message(SilcClient client,
1180 * SilcClientConnection conn,
1181 * SilcClientEntry client_entry,
1182 * SilcMessageFlags flags,
1184 * unsigned char *data,
1185 * SilcUInt32 data_len);
1189 * Sends private message to remote client. If private message key has
1190 * not been set with this client then the message will be encrypted using
1191 * the session keys used in `conn' connection. If the `flags' includes
1192 * SILC_MESSAGE_FLAG_SIGNED the message will be digitally signed with the
1193 * SILC key pair associated with `conn'. In this case the caller must also
1194 * provide the `hash' pointer.
1196 * Returns TRUE if the message was sent, and FALSE if error occurred.
1197 * This function is thread safe and private messages can be sent from
1201 SilcBool silc_client_send_private_message(SilcClient client,
1202 SilcClientConnection conn,
1203 SilcClientEntry client_entry,
1204 SilcMessageFlags flags,
1206 unsigned char *data,
1207 SilcUInt32 data_len);
1209 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_init
1214 * silc_client_private_message_wait_init(SilcClient client,
1215 * SilcClientConnection conn,
1216 * SilcClientEntry client_entry);
1220 * Initializes private message waiting functionality for the client
1221 * indicated by `client_entry'. Once this is called private message
1222 * from remote connection indicated by `conn' for `client_entry' may
1223 * be waiter for, for example in a thread. The function
1224 * silc_client_private_message_wait is used to block the current thread
1225 * until a private message is received from a specified client entry.
1226 * Return FALSE in case an internal error occurred.
1229 SilcBool silc_client_private_message_wait_init(SilcClient client,
1230 SilcClientConnection conn,
1231 SilcClientEntry client_entry);
1233 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait_uninit
1238 * silc_client_private_message_wait_uninit(SilcClient client,
1239 * SilcClientConnection conn,
1240 * SilcClientEntry client_entry);
1244 * Unintializes private message waiting for client indicated by
1245 * `client_entry'. After this call private message cannot be waited
1246 * anymore and silc_client_private_message_wait will return with FALSE
1250 void silc_client_private_message_wait_uninit(SilcClient client,
1251 SilcClientConnection conn,
1252 SilcClientEntry client_entry);
1254 /****f* silcclient/SilcClientAPI/silc_client_private_message_wait
1259 * silc_client_private_message_wait(SilcClient client,
1260 * SilcClientConnection conn,
1261 * SilcClientEntry client_entry,
1262 * SilcMessagePayload *payload);
1266 * Blocks current thread or process until a private message has been
1267 * received from the remote client indicated by `client_entry'. Before
1268 * private messages can be waited the silc_client_private_message_wait_init
1269 * must be called. This function can be used from a thread to wait for
1270 * private message from the specified client. Multiple threads can be
1271 * created to wait messages from multiple clients. Any other private
1272 * message received from the connection indicated by `conn' will be
1273 * forwarded to the normal `private_message' client operation callback.
1274 * The private messages from `client_entry' will not be delivered to the
1275 * `private_message' client operation callback.
1277 * Returns TRUE and the received private message into `payload'. The caller
1278 * must free the returned SilcMessagePayload. If this function returns
1279 * FALSE the private messages cannot be waited anymore. This happens
1280 * when some other thread calls silc_client_private_message_wait_uninit.
1281 * This returns FALSE also if silc_client_private_message_wait_init has
1285 SilcBool silc_client_private_message_wait(SilcClient client,
1286 SilcClientConnection conn,
1287 SilcClientEntry client_entry,
1288 SilcMessagePayload *payload);
1290 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1294 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1295 * SilcClientEntry client_entry);
1299 * Returns the SilcChannelUser entry if the `client_entry' is joined on the
1300 * channel indicated by the `channel'. NULL if client is not joined on
1304 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1305 SilcClientEntry client_entry);
1308 /* Command management */
1310 /****f* silcclient/SilcClientAPI/silc_client_command_call
1314 * SilcUInt16 silc_client_command_call(SilcClient client,
1315 * SilcClientConnection conn,
1316 * const char *command_line, ...);
1320 * Calls and executes the command indicated by the `command_name'.
1321 * The `command_line' is a string which includes the command's name and
1322 * its arguments separated with whitespaces (' '). If `command_line'
1323 * is non-NULL then all variable arguments are ignored by default.
1325 * If `command_line' is NULL, then the variable arguments define the
1326 * command's name and its arguments. The first variable argument must
1327 * be the command name. The variable argument list must be terminated
1330 * Returns command identifier for this sent command. It can be used
1331 * to additionally attach to the command reply using the function
1332 * silc_client_command_pending, if needed. Returns 0 on error.
1334 * The `command' client operation callback will be called when the
1335 * command is executed to indicate whether or not the command executed
1338 * The `command_reply' client operation callbak will be called when reply
1339 * is received from the server to the command. Application may also use
1340 * the silc_client_command_pending to attach to the command reply.
1341 * The command identifier for silc_client_command_pending function after
1342 * this function call is conn->cmd_ident, which application may use.
1346 * silc_client_command_call(client, conn, NULL, "PING", "silc.silcnet.org",
1348 * silc_client_command_call(client, conn, "PING silc.silcnet.org");
1352 * This command executes the commands implemented inside the client
1353 * library. These commands are designed for command line applications,
1354 * but GUI application may call them too if needed. Alternatively
1355 * application may override the library and use silc_client_command_send
1359 SilcUInt16 silc_client_command_call(SilcClient client,
1360 SilcClientConnection conn,
1361 const char *command_line, ...);
1363 /****f* silcclient/SilcClientAPI/SilcClientCommandReply
1367 * typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1368 * SilcClientConnection conn,
1369 * SilcCommand command,
1370 * SilcStatus status,
1377 * The command reply callback function given as argument to functions
1378 * silc_client_command_send and silc_client_command_pending. This is
1379 * called to deliver the command replies to the caller. Each command
1380 * reply received from the server to the `command' will be delivered
1381 * separately to the caller by calling this callback. The `status' will
1382 * indicate whether there is only one reply or multiple replies. The
1383 * `error' will indicate if an error occurred. The `ap' will include
1384 * command reply arguments. They are the same arguments as for
1385 * `command_reply' client operation callback in SilcClientOperations.
1387 * If `status' is SILC_STATUS_OK only one reply was received and error
1388 * did not occur. If it is SILC_STATUS_LIST_START, SILC_STATUS_LIST_ITEM
1389 * or SILC_STATUS_LIST_END, there are will be two or more replies. The
1390 * first reply is SILC_STATUS_LIST_START and last one SILC_STATUS_LIST_END.
1392 * If FALSE is returned in this function this callback will not be called
1393 * again for `command' even if there are more comand replies. By returning
1394 * FALSE the caller may stop the command reply handling when needed.
1397 typedef SilcBool (*SilcClientCommandReply)(SilcClient client,
1398 SilcClientConnection conn,
1399 SilcCommand command,
1405 /****f* silcclient/SilcClientAPI/silc_client_command_send
1409 * SilcUInt16 silc_client_command_send(SilcClient client,
1410 * SilcClientConnection conn,
1411 * SilcCommand command,
1412 * SilcClientCommandReply reply,
1413 * void *reply_context,
1414 * SilcUInt32 argc, ...);
1418 * Generic function to send any command. The arguments must be given
1419 * already encoded into correct format and in correct order. If application
1420 * wants to perform the commands by itself, it can do so and send the data
1421 * directly to the server using this function. If application is using
1422 * the silc_client_command_call, this function is usually not used.
1423 * Programmer should get familiar with the SILC protocol commands
1424 * specification when using this function, as the arguments needs to
1425 * be encoded as specified in the protocol.
1427 * The variable arguments are a set of { type, data, data_length },
1428 * and the `argc' is the number of these sets.
1430 * The `reply' callback must be provided, and it is called when the
1431 * command reply is received from the server. Note that, when using this
1432 * function the default `command_reply' client operation callback will not
1433 * be called when reply is received.
1435 * Returns command identifier for this sent command. It can be used
1436 * to additionally attach to the command reply using the function
1437 * silc_client_command_pending, if needed. Returns 0 on error.
1441 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS,
1442 * my_whois_command_reply, cmd_ctx,
1443 * 1, 1, nickname, strlen(nickname));
1446 SilcUInt16 silc_client_command_send(SilcClient client,
1447 SilcClientConnection conn,
1448 SilcCommand command,
1449 SilcClientCommandReply reply,
1450 void *reply_context,
1451 SilcUInt32 argc, ...);
1453 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1457 * void silc_client_command_pending(SilcClientConnection conn,
1458 * SilcCommand command,
1459 * SilcUInt16 cmd_ident,
1460 * SilcClientCommandReply reply,
1465 * This function can be used to add pending command callback to be
1466 * called when an command reply is received to an earlier sent command.
1467 * The `command' is the command that must be received in order for
1468 * the pending command callback indicated by `callback' to be called.
1470 * The `cmd_ident' is a command identifier which was set for the earlier
1471 * sent command. The command reply will include the same identifier
1472 * and pending command callback will be called when the reply is
1473 * received with the same command identifier. It is possible to
1474 * add multiple pending command callbacks for same command and for
1477 * Application may use this function to add its own command reply
1478 * handlers if it wishes not to use the standard `command_reply'
1481 * Note also that the application is notified about the received command
1482 * reply through the `command_reply' client operation before calling
1483 * the `callback` pending command callback. That is the normal
1484 * command reply handling, and is called regardless whether pending
1485 * command callbacks are used or not.
1489 * SilcUInt16 cmd_ident;
1490 * cmd_ident = silc_client_command_call(client, conn,
1491 * "PING silc.silcnet.org");
1492 * silc_client_command_pending(conn, SILC_COMMAND_PING, cmd_ident,
1493 * my_ping_handler, my_ping_context);
1496 SilcBool silc_client_command_pending(SilcClientConnection conn,
1497 SilcCommand command,
1498 SilcUInt16 cmd_ident,
1499 SilcClientCommandReply reply,
1503 /* Private Message key management */
1505 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1510 * silc_client_add_private_message_key(SilcClient client,
1511 * SilcClientConnection conn,
1512 * SilcClientEntry client_entry,
1513 * const char *cipher,
1515 * unsigned char *key,
1516 * SilcUInt32 key_len);
1520 * Adds a static private message key to the client library. The key
1521 * will be used to encrypt all private message between the client and
1522 * the remote client indicated by the `client_entry'. The `key' can
1523 * be for example a pre-shared-key, passphrase or similar shared secret
1524 * string. The `cipher' and `hmac' MAY be provided but SHOULD be NULL
1525 * to assure that the requirements of the SILC protocol are met. The
1526 * API, however, allows to allocate any cipher and HMAC.
1528 * If the private message key is added to client without first receiving
1529 * a request for it from the remote `client_entry' this function will
1530 * send the request to `client_entry'. Note that, the actual key is
1531 * not sent to the network.
1533 * It is not necessary to set key for normal private message usage. If the
1534 * key is not set then the private messages are encrypted using normal
1535 * session keys. Setting the private key, however, increases security.
1537 * Returns FALSE if the key is already set for the `client_entry', TRUE
1541 SilcBool silc_client_add_private_message_key(SilcClient client,
1542 SilcClientConnection conn,
1543 SilcClientEntry client_entry,
1547 SilcUInt32 key_len);
1549 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1554 * silc_client_add_private_message_key_ske(SilcClient client,
1555 * SilcClientConnection conn,
1556 * SilcClientEntry client_entry,
1557 * const char *cipher,
1559 * SilcSKEKeyMaterial key);
1563 * Same as silc_client_add_private_message_key but takes the key material
1564 * from the SKE key material structure. This structure is received if
1565 * the application uses the silc_client_send_key_agreement to negotiate
1566 * the key material. The `cipher' and `hmac' SHOULD be provided as it is
1567 * negotiated also in the SKE protocol.
1570 SilcBool silc_client_add_private_message_key_ske(SilcClient client,
1571 SilcClientConnection conn,
1572 SilcClientEntry client_entry,
1575 SilcSKEKeyMaterial key);
1577 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1582 * silc_client_del_private_message_key(SilcClient client,
1583 * SilcClientConnection conn,
1584 * SilcClientEntry client_entry);
1588 * Removes the private message from the library. The key won't be used
1589 * after this to protect the private messages with the remote `client_entry'
1590 * client. Returns FALSE on error, TRUE otherwise.
1593 SilcBool silc_client_del_private_message_key(SilcClient client,
1594 SilcClientConnection conn,
1595 SilcClientEntry client_entry);
1597 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1601 * SilcPrivateMessageKeys
1602 * silc_client_list_private_message_keys(SilcClient client,
1603 * SilcClientConnection conn,
1604 * SilcUInt32 *key_count);
1608 * Returns array of set private message keys associated to the connection
1609 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1610 * count to the `key_count' argument. The array must be freed by the caller
1611 * by calling the silc_client_free_private_message_keys function. Note:
1612 * the keys returned in the array is in raw format. It might not be desired
1613 * to show the keys as is. The application might choose not to show the keys
1614 * at all or to show the fingerprints of the keys.
1617 SilcPrivateMessageKeys
1618 silc_client_list_private_message_keys(SilcClient client,
1619 SilcClientConnection conn,
1620 SilcUInt32 *key_count);
1622 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1626 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1627 * SilcUInt32 key_count);
1631 * Frees the SilcPrivateMessageKeys array returned by the function
1632 * silc_client_list_private_message_keys.
1635 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1636 SilcUInt32 key_count);
1638 /****f* silcclient/SilcClientAPI/silc_client_private_message_key_is_set
1643 * silc_client_private_message_key_is_set(SilcClient client,
1644 * SilcClientConnection conn,
1645 * SilcClientEntry client_entry);
1649 * Returns TRUE if the private message key has been set for the client
1650 * entry indicated by `client_entry'.
1654 silc_client_private_message_key_is_set(SilcClient client,
1655 SilcClientConnection conn,
1656 SilcClientEntry client_entry);
1659 /* Channel private key management */
1661 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1666 * silc_client_add_channel_private_key(SilcClient client,
1667 * SilcClientConnection conn,
1668 * SilcChannelEntry channel,
1672 * unsigned char *key,
1673 * SilcUInt32 key_len,
1674 * SilcChannelPrivateKey *ret_key);
1678 * Adds private key for channel. When channel has private key then the
1679 * messages are encrypted using that key. All clients on the channel
1680 * must also know the key in order to decrypt the messages. However,
1681 * it is possible to have several private keys per one channel. In this
1682 * case only some of the clients on the channel may know the one key
1683 * and only some the other key. The `name' can be application given
1684 * name for the key. This returns the created key to the 'ret_key'
1685 * pointer if it is non-NULL;
1687 * If `cipher' and/or `hmac' is NULL then default values will be used
1688 * (aes-256-cbc for cipher and hmac-sha1-96 for hmac).
1690 * The private key for channel is optional. If it is not set then the
1691 * channel messages are encrypted using the channel key generated by the
1692 * server. However, setting the private key (or keys) for the channel
1693 * significantly adds security. If more than one key is set the library
1694 * will automatically try all keys at the message decryption phase. Note:
1695 * setting many keys slows down the decryption phase as all keys has to
1696 * be tried in order to find the correct decryption key. However, setting
1697 * a few keys does not have big impact to the decryption performace.
1701 * NOTE: This is entirely local setting. The key set using this function
1702 * is not sent to the network at any phase.
1704 * NOTE: If the key material was originated by the SKE protocol (using
1705 * silc_client_send_key_agreement) then the `key' MUST be the
1706 * key->send_enc_key as this is dictated by the SILC protocol. However,
1707 * currently it is not expected that the SKE key material would be used
1708 * as channel private key. However, this API allows it.
1711 SilcBool silc_client_add_channel_private_key(SilcClient client,
1712 SilcClientConnection conn,
1713 SilcChannelEntry channel,
1719 SilcChannelPrivateKey *ret_key);
1721 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1725 * SilcBool silc_client_del_channel_private_keys(SilcClient client,
1726 * SilcClientConnection conn,
1727 * SilcChannelEntry channel);
1731 * Removes all private keys from the `channel'. The old channel key is used
1732 * after calling this to protect the channel messages. Returns FALSE on
1733 * on error, TRUE otherwise.
1736 SilcBool silc_client_del_channel_private_keys(SilcClient client,
1737 SilcClientConnection conn,
1738 SilcChannelEntry channel);
1740 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1744 * SilcBool silc_client_del_channel_private_key(SilcClient client,
1745 * SilcClientConnection conn,
1746 * SilcChannelEntry channel,
1747 * SilcChannelPrivateKey key);
1751 * Removes and frees private key `key' from the channel `channel'.
1752 * The `key' is retrieved by calling the function
1753 * silc_client_list_channel_private_keys. The key is not used after
1754 * this. If the key was last private key then the old channel key is
1755 * used hereafter to protect the channel messages. This returns FALSE
1756 * on error, TRUE otherwise.
1759 SilcBool silc_client_del_channel_private_key(SilcClient client,
1760 SilcClientConnection conn,
1761 SilcChannelEntry channel,
1762 SilcChannelPrivateKey key);
1764 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1769 * silc_client_list_channel_private_keys(SilcClient client,
1770 * SilcClientConnection conn,
1771 * SilcChannelEntry channel);
1775 * Returns list of private keys associated to the `channel'. The caller
1776 * must free the returned list with silc_dlist_uninit. The pointers in
1777 * the list may be used to delete the specific key by giving the pointer
1778 * as argument to the function silc_client_del_channel_private_key. Each
1779 * entry in the list is SilcChannelPrivateKey.
1782 SilcDList silc_client_list_channel_private_keys(SilcClient client,
1783 SilcClientConnection conn,
1784 SilcChannelEntry channel);
1786 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1790 * void silc_client_current_channel_private_key(SilcClient client,
1791 * SilcClientConnection conn,
1792 * SilcChannelEntry channel,
1793 * SilcChannelPrivateKey key);
1797 * Sets the `key' to be used as current channel private key on the
1798 * `channel'. Packet sent after calling this function will be secured
1802 void silc_client_current_channel_private_key(SilcClient client,
1803 SilcClientConnection conn,
1804 SilcChannelEntry channel,
1805 SilcChannelPrivateKey key);
1808 /* Key Agreement routines */
1810 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1814 * void silc_client_send_key_agreement(SilcClient client,
1815 * SilcClientConnection conn,
1816 * SilcClientEntry client_entry,
1817 * SilcClientConnectionParams *params,
1818 * SilcPublicKey public_key,
1819 * SilcPrivateKey private_key,
1820 * SilcKeyAgreementCallback completion,
1825 * Sends key agreement request to the remote client indicated by the
1828 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
1829 * the caller will provide the connection endpoint for the key agreement
1830 * connection. The `bind_ip' can be used to bind to that IP instead of
1831 * `local_ip'. If the `udp' is set to TRUE the connection will be UDP
1832 * instead of TCP. Caller may also set the `repository', `verify_notfound'
1833 * and `timeout_secs' fields in `params'. Other fields are ignored.
1834 * If `params' is NULL, then the `client_entry' is expected to provide
1835 * the connection endpoint for us. It is recommended the `timeout_secs'
1836 * is specified in case the remote client does not reply anything to
1839 * The `public_key' and `private_key' is our identity in the key agreement.
1841 * In case we do not provide the connection endpoint, we will receive
1842 * the `key_agreement' client operation when the remote send its own
1843 * key agreement request packet. We may then there start the key
1844 * agreement with silc_client_perform_key_agreement. If we provided the
1845 * the connection endpoint, the client operation will not be called.
1847 * There can be only one active key agreement for `client_entry'. Old
1848 * key agreement may be aborted by calling silc_client_abort_key_agreement.
1852 * // Send key agreement request (we don't provide connection endpoint)
1853 * silc_client_send_key_agreement(client, conn, remote_client,
1854 * NULL, public_key, private_key,
1855 * my_keyagr_completion, my_context);
1857 * // Another example where we provide connection endpoint (TCP).
1858 * SilcClientConnectionParams params;
1859 * memset(¶ms, 0, sizeof(params));
1860 * params.local_ip = local_ip;
1861 * params.local_port = local_port;
1862 * params.timeout_secs = 60;
1863 * silc_client_send_key_agreement(client, conn, remote_client,
1864 * ¶ms, public_key, private_key,
1865 * my_keyagr_completion, my_context);
1868 void silc_client_send_key_agreement(SilcClient client,
1869 SilcClientConnection conn,
1870 SilcClientEntry client_entry,
1871 SilcClientConnectionParams *params,
1872 SilcPublicKey public_key,
1873 SilcPrivateKey private_key,
1874 SilcKeyAgreementCallback completion,
1877 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1882 * silc_client_perform_key_agreement(SilcClient client,
1883 * SilcClientConnection conn,
1884 * SilcClientEntry client_entry,
1885 * SilcClientConnectionParams *params,
1886 * SilcPublicKey public_key,
1887 * SilcPrivateKey private_key,
1888 * char *hostname, int port,
1889 * SilcKeyAgreementCallback completion,
1894 * Performs the key agreement protocol. Application may use this to
1895 * initiate the key agreement protocol. Usually this is called after
1896 * receiving the `key_agreement' client operation.
1898 * The `hostname' is the remote hostname (or IP address) and the `port'
1899 * is the remote port. The `completion' callback with the `context' will
1900 * be called after the key agreement protocol.
1902 * The `params' is connection parameters and it may be used to define
1903 * the key agreement connection related parameters. It may be NULL.
1906 void silc_client_perform_key_agreement(SilcClient client,
1907 SilcClientConnection conn,
1908 SilcClientEntry client_entry,
1909 SilcClientConnectionParams *params,
1910 SilcPublicKey public_key,
1911 SilcPrivateKey private_key,
1912 char *hostname, int port,
1913 SilcKeyAgreementCallback completion,
1916 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_stream
1921 * silc_client_perform_key_agreement_stream(
1922 * SilcClient client,
1923 * SilcClientConnection conn,
1924 * SilcClientEntry client_entry,
1925 * SilcClientConnectionParams *params,
1926 * SilcPublicKey public_key,
1927 * SilcPrivateKey private_key,
1928 * SilcStream stream,
1929 * SilcKeyAgreementCallback completion,
1934 * Same as silc_client_perform_key_agreement but the caller has created
1935 * the connection to remote client. The `stream' is the created
1940 silc_client_perform_key_agreement_stream(SilcClient client,
1941 SilcClientConnection conn,
1942 SilcClientEntry client_entry,
1943 SilcClientConnectionParams *params,
1944 SilcPublicKey public_key,
1945 SilcPrivateKey private_key,
1947 SilcKeyAgreementCallback completion,
1950 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1954 * void silc_client_abort_key_agreement(SilcClient client,
1955 * SilcClientConnection conn,
1956 * SilcClientEntry client_entry);
1960 * This function can be called to unbind the hostname and the port for
1961 * the key agreement protocol. However, this function has effect only
1962 * before the key agreement protocol has been performed. After it has
1963 * been performed the library will automatically unbind the port. The
1964 * `client_entry' is the client to which we sent the key agreement
1965 * request. The key agreement completion callback will be called
1966 * with SILC_KEY_AGREEMENT_ABORTED status.
1969 void silc_client_abort_key_agreement(SilcClient client,
1970 SilcClientConnection conn,
1971 SilcClientEntry client_entry);
1974 /* Misc functions */
1976 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1980 * SilcBool silc_client_set_away_message(SilcClient client,
1981 * SilcClientConnection conn,
1986 * Sets away `message'. The away message may be set when the client's
1987 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1988 * to anyone who sends private message. The `message' will be sent
1989 * automatically back to the the client who send private message. If
1990 * away message is already set this replaces the old message with the
1991 * new one. If `message' is NULL the old away message is removed.
1992 * The sender may freely free the memory of the `message'. Returns
1996 SilcBool silc_client_set_away_message(SilcClient client,
1997 SilcClientConnection conn,
2000 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
2004 * typedef enum { ... } SilcClientMonitorStatus;
2008 * File transmission session status types. These will indicate
2009 * the status of the file transmission session.
2011 * The SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT is called when session
2012 * is key exchange phase.
2014 * The SILC_CLIENT_FILE_MONITOR_SEND is called when data is being sent
2017 * The SILC_CLIENT_FILE_MONITOR_RECEIVE is called when data is being
2018 * recieved from remote client.
2020 * The SILC_CLIENT_FILE_MONITOR_CLOSED will be called when the user
2021 * issues silc_client_file_close. If needed, it may be ignored in the
2024 * The SILC_CLIENT_FILE_MONITOR_DISCONNECT will be called if remote
2025 * disconnects the session connection. The silc_client_file_close must
2026 * be called when this status is received. The session is over when
2029 * The SILC_CLIENLT_FILE_MONITOR_ERROR is called in case some error
2030 * occured. The SilcClientFileError will indicate more detailed error
2031 * condition. The silc_client_file_close must be called when this status
2032 * is received. The session is over when this is received.
2037 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2038 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2039 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2040 SILC_CLIENT_FILE_MONITOR_GET, /* Unsupported */
2041 SILC_CLIENT_FILE_MONITOR_PUT, /* Unsupported */
2042 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2043 SILC_CLIENT_FILE_MONITOR_DISCONNECT, /* Session disconnected */
2044 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2045 } SilcClientMonitorStatus;
2048 /****d* silcclient/SilcClientAPI/SilcClientFileError
2052 * typedef enum { ... } SilcClientFileError;
2056 * File transmission error types. These types are returned by
2057 * some of the file transmission functions, and by the monitor
2058 * callback to indicate error.
2063 SILC_CLIENT_FILE_OK,
2064 SILC_CLIENT_FILE_ERROR, /* Generic error */
2065 SILC_CLIENT_FILE_UNKNOWN_SESSION, /* Unknown session ID */
2066 SILC_CLIENT_FILE_ALREADY_STARTED, /* Session already started */
2067 SILC_CLIENT_FILE_NO_SUCH_FILE, /* No such file */
2068 SILC_CLIENT_FILE_PERMISSION_DENIED, /* Permission denied */
2069 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED, /* Key exchange failed */
2070 SILC_CLIENT_FILE_CONNECT_FAILED, /* Error during connecting */
2071 SILC_CLIENT_FILE_TIMEOUT, /* Connecting timedout */
2072 SILC_CLIENT_FILE_NO_MEMORY, /* System out of memory */
2073 } SilcClientFileError;
2076 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2080 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2081 * SilcClientConnection conn,
2082 * SilcClientMonitorStatus status,
2083 * SilcClientFileError error,
2084 * SilcUInt64 offset,
2085 * SilcUInt64 filesize,
2086 * SilcClientEntry client_entry,
2087 * SilcUInt32 session_id,
2088 * const char *filepath,
2093 * Monitor callback that is called during the file transmission to
2094 * monitor the transmission process. The `status' indicates the current
2095 * monitoring process. The `error' will indicate the error type
2096 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2097 * currently transmitted amount of total `filesize'. The `client_entry'
2098 * indicates the remote client, and the transmission session ID is the
2099 * `session_id'. The filename being transmitted is indicated by the
2100 * `filepath'. The `conn' is NULL if the connection to remote client
2101 * does not exist yet.
2104 typedef void (*SilcClientFileMonitor)(SilcClient client,
2105 SilcClientConnection conn,
2106 SilcClientMonitorStatus status,
2107 SilcClientFileError error,
2109 SilcUInt64 filesize,
2110 SilcClientEntry client_entry,
2111 SilcUInt32 session_id,
2112 const char *filepath,
2115 /****f* silcclient/SilcClientAPI/SilcClientFileName
2119 * typedef void (*SilcClientFileName)(const char *filepath,
2124 * Completion callback for the SilcClientFileAskName callback function.
2125 * Application calls this to deliver the filepath and filename where
2126 * the downloaded file is to be saved.
2129 typedef void (*SilcClientFileName)(const char *filepath,
2132 /****f* silcclient/SilcClientAPI/SilcClientFileAskName
2136 * typedef void (*SilcClientFileAskName)(SilcClient client,
2137 * SilcClientConnection conn,
2138 * SilcUInt32 session_id,
2139 * const char *remote_filename,
2140 * SilcClientFileName completion,
2141 * void *completion_context,
2146 * File name asking callback that is called if it is given to the
2147 * silc_client_file_receive and the path given to that as argument was
2148 * NULL. The library calls this to ask the filename and filepath to
2149 * where the file is to be saved. The 'remote_filename' is the file
2150 * that is being downloaded. Application must call the 'completion'
2151 * with 'completion_context' to continue with the file downloading.
2152 * It is not mandatory to provide this to the silc_client_file_receive.
2155 typedef void (*SilcClientFileAskName)(SilcClient client,
2156 SilcClientConnection conn,
2157 SilcUInt32 session_id,
2158 const char *remote_filename,
2159 SilcClientFileName completion,
2160 void *completion_context,
2163 /****f* silcclient/SilcClientAPI/silc_client_file_send
2167 * SilcClientFileError
2168 * silc_client_file_send(SilcClient client,
2169 * SilcClientConnection conn,
2170 * SilcClientEntry client_entry,
2171 * SilcClientConnectionParams *params,
2172 * SilcPublicKey public_key,
2173 * SilcPrivateKey private_key,
2174 * SilcClientFileMonitor monitor,
2175 * void *monitor_context,
2176 * const char *filepath,
2177 * SilcUInt32 *session_id);
2181 * Sends a file indicated by the `filepath' to the remote client
2182 * indicated by the `client_entry'. This will negotiate a secret key
2183 * with the remote client before actually starting the transmission of
2184 * the file. The `monitor' callback will be called to monitor the
2185 * transmission of the file.
2187 * This returns a file session ID for the file transmission to the
2188 * `session_id' pointer. It can be used to close the session (and
2189 * abort the file transmission) by calling the silc_client_file_close
2190 * function. The session ID is also returned in the `monitor' callback.
2192 * If `params' is non-NULL and it has the `local_ip' and `local_port' set
2193 * the caller will provide the connection endpoint for the key agreement
2194 * connection. The `bind_ip' can be used to bind to that IP instead of
2195 * `local_ip'. Caller may also set the `repository', `verify_notfound'
2196 * and `timeout_secs' fields in `params'. Other fields are ignored.
2197 * If `params' is NULL, then the `client_entry' is expected to provide
2198 * the connection endpoint for us. It is recommended the `timeout_secs'
2199 * is specified in case the remote client does not reply anything to
2202 * The `public_key' and `private_key' is our identity in the key agreement.
2204 * If error will occur during the file transfer process the error status
2205 * will be returned in the monitor callback. In this case the application
2206 * must call silc_client_file_close to close the session.
2210 silc_client_file_send(SilcClient client,
2211 SilcClientConnection conn,
2212 SilcClientEntry client_entry,
2213 SilcClientConnectionParams *params,
2214 SilcPublicKey public_key,
2215 SilcPrivateKey private_key,
2216 SilcClientFileMonitor monitor,
2217 void *monitor_context,
2218 const char *filepath,
2219 SilcUInt32 *session_id);
2221 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2225 * SilcClientFileError
2226 * silc_client_file_receive(SilcClient client,
2227 * SilcClientConnection conn,
2228 * SilcClientConnectionParams *params,
2229 * SilcPublicKey public_key,
2230 * SilcPrivateKey private_key,
2231 * SilcClientFileMonitor monitor,
2232 * void *monitor_context,
2234 * SilcUInt32 session_id,
2235 * SilcClientFileAskName ask_name,
2236 * void *ask_name_context);
2240 * Receives a file from a client indicated by the `client_entry'. The
2241 * `session_id' indicates the file transmission session and it has been
2242 * received in the `ftp' client operation callback. This will actually
2243 * perform the key agreement protocol with the remote client before
2244 * actually starting the file transmission. The `monitor' callback
2245 * will be called to monitor the transmission. If `path' is non-NULL
2246 * the file will be saved into that directory. If NULL the file is
2247 * saved in the current working directory, unless the 'ask_name'
2248 * callback is non-NULL. In this case the callback is called to ask
2249 * the path and filename from application.
2251 * The `params' is the connection related parameters. If the remote client
2252 * provided connection point the `params' will be used when creating
2253 * connection to the remote client. If remote client did not provide
2254 * connection point the `params' is used to provide connection point
2255 * locally for the remote client. See silc_client_file_send for more
2256 * information on providing connection point for remote client.
2258 * The `public_key' and `private_key' is our identity in the key agreement.
2260 * If error will occur during the file transfer process the error status
2261 * will be returned in the monitor callback. In this case the application
2262 * must call silc_client_file_close to close the session.
2266 silc_client_file_receive(SilcClient client,
2267 SilcClientConnection conn,
2268 SilcClientConnectionParams *params,
2269 SilcPublicKey public_key,
2270 SilcPrivateKey private_key,
2271 SilcClientFileMonitor monitor,
2272 void *monitor_context,
2274 SilcUInt32 session_id,
2275 SilcClientFileAskName ask_name,
2276 void *ask_name_context);
2278 /****f* silcclient/SilcClientAPI/silc_client_file_close
2282 * SilcClientFileError silc_client_file_close(SilcClient client,
2283 * SilcClientConnection conn,
2284 * SilcUInt32 session_id);
2288 * Closes file transmission session indicated by the `session_id'.
2289 * If file transmission is being conducted it will be aborted
2290 * automatically. This function is also used to close the session
2291 * after successful file transmission. This function can be used
2292 * also to reject incoming file transmission request. If the
2293 * session was already started and the monitor callback was set
2294 * the monitor callback will be called with the monitor status
2295 * SILC_CLIENT_FILE_MONITOR_CLOSED.
2298 SilcClientFileError silc_client_file_close(SilcClient client,
2299 SilcClientConnection conn,
2300 SilcUInt32 session_id);
2302 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2306 * SilcAttributePayload
2307 * silc_client_attribute_add(SilcClient client,
2308 * SilcClientConnection conn,
2309 * SilcAttribute attribute,
2311 * SilcUInt32 object_size);
2315 * Add new Requsted Attribute for WHOIS command to the client library.
2316 * The `attribute' object indicated by `object' is added and allocated
2317 * SilcAttributePayload is returned. The `object' must be of correct
2318 * type and of correct size. See the SilcAttribute for object types
2319 * for different attributes. You may also get all added attributes
2320 * from the client with silc_client_attributes_get function.
2322 * Requested Attributes are different personal information about the
2323 * user, status information and other information which other users
2324 * may query with WHOIS command. Application may set these so that
2325 * if someone sends WHOIS query these attributes will be replied back
2326 * to the sender. The library always puts the public key to the
2327 * Requested Attributes, but if application wishes to add additional
2328 * public keys (or certificates) it can be done with this interface.
2329 * Library also always computes digital signature of the attributes
2330 * automatically, so application does not need to do that.
2333 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2334 SilcClientConnection conn,
2335 SilcAttribute attribute,
2337 SilcUInt32 object_size);
2339 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2343 * SilcBool silc_client_attribute_del(SilcClient client,
2344 * SilcClientConnection conn,
2345 * SilcAttribute attribute,
2346 * SilcAttributePayload attr);
2350 * Delete a Requested Attribute from the client. If the `attribute'
2351 * is non-zero then all attributes of that type are deleted and the
2352 * `attr' is ignored. If `attr' is non-NULL then that specific
2353 * attribute is deleted and `attribute' is ignored.
2355 * You may get all added attributes with the function
2356 * silc_client_attributes_get and to get the SilcAttributePayload.
2357 * This function Returns TRUE if the attribute was found and deleted.
2360 SilcBool silc_client_attribute_del(SilcClient client,
2361 SilcClientConnection conn,
2362 SilcAttribute attribute,
2363 SilcAttributePayload attr);
2365 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2369 * const SilcHashTable
2370 * silc_client_attributes_get(SilcClient client,
2371 * SilcClientConnection conn);
2375 * Returns pointer to the SilcHashTable which includes all the added
2376 * Requested Attributes. The caller must not free the hash table.
2377 * The caller may use SilcHashTableList and silc_hash_table_list to
2378 * traverse the table. Each entry in the hash table is one added
2379 * SilcAttributePayload. It is possible to delete a attribute
2380 * payload while traversing the table.
2383 SilcHashTable silc_client_attributes_get(SilcClient client,
2384 SilcClientConnection conn);
2386 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2390 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2394 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2395 * then all attributes are requested. Alternatively, `attribute' and
2396 * all variable arguments can each be requested attribute. In this case
2397 * the last must be set to zero (0) to complete the variable list of
2398 * requested attributes. See SilcAttribute for all attributes.
2399 * You can give the returned buffer as argument to for example
2400 * silc_client_get_client_by_id_resolve function.
2404 * Request all attributes
2405 * buffer = silc_client_attributes_request(0);
2407 * Request only the following attributes
2408 * buffer = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO,
2409 * SILC_ATTRIBUTE_SERVICE,
2410 * SILC_ATTRIBUTE_MOOD, 0);
2413 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2415 /****f* silcclient/SilcClientAPI/silc_client_nickname_format
2420 * silc_client_nickname_format(SilcClient client,
2421 * SilcClientConnection conn,
2422 * SilcClientEntry client_entry,
2423 * SilcBool priority);
2427 * Formats the nickname of `client_entry' according to the nickname
2428 * formatting rules set in SilcClientParams. If the `priority' is TRUE
2429 * then the `client_entry' will always get the unformatted nickname.
2430 * If FALSE and there are more than one same nicknames in the client
2431 * the nickname will be formatted.
2433 * This returns NULL on error. Otherwise, the client entry that was
2434 * formatted is returned. If `priority' is FALSE this always returns
2435 * the `client_entry'. If it is TRUE, this may return the client entry
2436 * that was formatted after giving the `client_entry' the unformatted
2439 * Usually application does not need to call this function, as the library
2440 * automatically formats nicknames. However, if application wants to
2441 * for example force the `client_entry' to always have the unformatted
2442 * nickname it may call this function to do so.
2445 SilcClientEntry silc_client_nickname_format(SilcClient client,
2446 SilcClientConnection conn,
2447 SilcClientEntry client_entry,
2450 /****f* silcclient/SilcClientAPI/silc_client_nickname_parse
2454 * SilcBool silc_client_nickname_parse(SilcClient client,
2455 * SilcClientConnection conn,
2461 * Parses the `nickname' according to the format string given in the
2462 * SilcClientParams. Returns the parsed nickname into the `ret_nick'.
2463 * The caller must free the returned pointer. Returns FALSE if error
2464 * occurred during parsing. Returns TRUE if the nickname was parsed,
2465 * it was not formatted or if the format string has not been specified
2466 * in SilcClientParams.
2469 SilcBool silc_client_nickname_parse(SilcClient client,
2470 SilcClientConnection conn,
2478 #endif /* SILCCLIENT_H */