5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcclient/Client Library Interface
24 * This interface defines the SILC Client Library API for the application.
25 * The client operations are defined first. These are callback functions that
26 * the application MUST implement since the library may call the functions
27 * at any time. At the end of file is the API for the application that
28 * it can use from the library. This is the only file that the application
29 * may include from the SIlC Client Library.
31 * o SILC Client Operations
33 * These functions must be implemented by the application calling the SILC
34 * client library. The client library can call these functions at any time.
36 * To use this structure: define a static SilcClientOperations variable,
37 * fill it and pass its pointer to silc_client_alloc function.
39 * o SILC Client Library API
41 * This is the API that is published by the SILC Client Library for the
42 * applications. These functions are implemented in the SILC Client Library.
43 * Application may freely call these functions from the library.
45 * Please, refer to the README file in this directory for the directions
46 * of how to use the SILC Client Library.
57 /* Forward declarations */
58 typedef struct SilcClientStruct *SilcClient;
59 typedef struct SilcClientConnectionStruct *SilcClientConnection;
60 typedef struct SilcClientPingStruct SilcClientPing;
61 typedef struct SilcClientAwayStruct SilcClientAway;
62 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
63 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
64 typedef struct SilcClientEntryStruct *SilcClientEntry;
65 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
66 typedef struct SilcServerEntryStruct *SilcServerEntry;
67 typedef struct SilcClientCommandStruct *SilcClientCommand;
68 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
69 typedef struct SilcClientCommandReplyContextStruct
70 *SilcClientCommandReplyContext;
71 typedef struct SilcChannelUserStruct *SilcChannelUser;
73 /* General definitions */
75 /****d* silcclient/SilcClientAPI/SilcKeyAgreementStatus
79 * typedef enum { ... } SilcKeyAgreementStatus;
83 * Key agreement status types indicating the status of the key
84 * agreement protocol. These types are returned to the application
85 * in the SilcKeyAgreementCallback callback function.
90 SILC_KEY_AGREEMENT_OK, /* Everything is Ok */
91 SILC_KEY_AGREEMENT_ERROR, /* Unknown error occurred */
92 SILC_KEY_AGREEMENT_FAILURE, /* The protocol failed */
93 SILC_KEY_AGREEMENT_TIMEOUT, /* The protocol timeout */
94 SILC_KEY_AGREEMENT_ABORTED, /* The protocol aborted */
95 SILC_KEY_AGREEMENT_ALREADY_STARTED, /* Already started */
96 SILC_KEY_AGREEMENT_SELF_DENIED, /* Negotiationg with itself denied */
97 } SilcKeyAgreementStatus;
100 /****f* silcclient/SilcClientAPI/SilcKeyAgreementCallback
104 * typedef void (*SilcKeyAgreementCallback)(SilcClient client,
105 * SilcClientConnection conn,
106 * SilcClientEntry client_entry,
107 * SilcKeyAgreementStatus status,
108 * SilcSKEKeyMaterial *key,
113 * Key agreement callback that is called after the key agreement protocol
114 * has been performed. This is called also if error occurred during the
115 * key agreement protocol. The `key' is the allocated key material and
116 * the caller is responsible of freeing it. The `key' is NULL if error
117 * has occurred. The application can freely use the `key' to whatever
118 * purpose it needs. See lib/silcske/silcske.h for the definition of
119 * the SilcSKEKeyMaterial structure.
122 typedef void (*SilcKeyAgreementCallback)(SilcClient client,
123 SilcClientConnection conn,
124 SilcClientEntry client_entry,
125 SilcKeyAgreementStatus status,
126 SilcSKEKeyMaterial *key,
129 /****s* silcclient/SilcClientAPI/SilcPrivateMessageKeys
133 * typedef struct { ... } SilcPrivateMessageKeys;
137 * Structure to hold the list of private message keys. The array of this
138 * structure is returned by the silc_client_list_private_message_keys
144 SilcClientEntry client_entry; /* The remote client entry */
145 char *cipher; /* The cipher name */
146 unsigned char *key; /* The original key, If the appliation
147 provided it. This is NULL if the
148 library generated the key or if
149 the SKE key material was used. */
150 SilcUInt32 key_len; /* The key length */
151 } *SilcPrivateMessageKeys;
154 /****s* silcclient/SilcClientAPI/SilcChannelPrivateKey
158 * typedef struct { ... } SilcChannelPrivateKey;
162 * Structure to hold one channel private key. The array of this structure
163 * is returned by silc_client_list_channel_private_keys function.
167 typedef struct SilcChannelPrivateKeyStruct {
168 char *name; /* Application given name */
169 SilcCipher cipher; /* The cipher and key */
170 SilcHmac hmac; /* The HMAC and hmac key */
171 unsigned char *key; /* The key data */
172 SilcUInt32 key_len; /* The key length */
173 } *SilcChannelPrivateKey;
176 /****f* silcclient/SilcClientAPI/SilcAskPassphrase
180 * typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
181 * SilcUInt32 passphrase_len,
186 * Ask passphrase callback. This is called by the application when the
187 * library calls `ask_passphrase' client operation. The callback delivers
188 * the passphrase to the library. The passphrases in SILC protocol
189 * MUST be in UTF-8 encoding, therefore the `passphrase' SHOULD be UTF-8
190 * encoded, and if it is not then library will attempt to encode it.
193 typedef void (*SilcAskPassphrase)(unsigned char *passphrase,
194 SilcUInt32 passphrase_len,
197 /****f* silcclient/SilcClientAPI/SilcVerifyPublicKey
201 * typedef void (*SilcVerifyPublicKey)(bool success, void *context);
205 * Public key (or certificate) verification callback. This is called
206 * by the application to indicate that the public key verification was
207 * either success or failure.
210 typedef void (*SilcVerifyPublicKey)(bool success, void *context);
212 /****f* silcclient/SilcClientAPI/SilcGetAuthMeth
216 * typedef void (*SilcGetAuthMeth)(bool success,
217 * SilcProtocolAuthMeth auth_meth,
218 * const unsigned char *auth_data,
219 * SilcUInt32 auth_data_len, void *context);
223 * Authentication method resolving callback. This is called by the
224 * application to return the resolved authentication method. The client
225 * library has called the get_auth_method client operation and given
226 * this function pointer as argument. The `success' will indicate whether
227 * the authentication method could be resolved. The `auth_meth' is the
228 * resolved authentication method. The `auth_data' and the `auth_data_len'
229 * are the resolved authentication data. The `context' is the libary's
230 * context sent to the get_auth_method client operation.
233 typedef void (*SilcGetAuthMeth)(bool success,
234 SilcProtocolAuthMeth auth_meth,
235 const unsigned char *auth_data,
236 SilcUInt32 auth_data_len, void *context);
238 /****d* silcclient/SilcClientAPI/SilcClientMessageType
242 * typedef enum { ... } SilcClientMessageType;
246 * Different message types for `say' client operation. The application
247 * may filter the message sent by the library according this type.
252 SILC_CLIENT_MESSAGE_INFO, /* Informational */
253 SILC_CLIENT_MESSAGE_WARNING, /* Warning */
254 SILC_CLIENT_MESSAGE_ERROR, /* Error */
255 SILC_CLIENT_MESSAGE_AUDIT, /* Auditable */
256 } SilcClientMessageType;
259 /****d* silcclient/SilcClientAPI/SilcClientConnectionStatus
263 * typedef enum { ... } SilcClientConnectionStatus
267 * This type is returned to the `connect' client operation to indicate
268 * the status of the created connection. It can indicated if it was
269 * successful or whether an error occurred.
274 SILC_CLIENT_CONN_SUCCESS, /* Successfully connected */
275 SILC_CLIENT_CONN_SUCCESS_RESUME, /* Successfully connected and
276 resumed old detached session */
277 SILC_CLIENT_CONN_ERROR, /* Error occurred during connecting */
278 } SilcClientConnectionStatus;
281 /****s* silcclient/SilcClientAPI/SilcClientOperations
285 * typedef struct { ... } SilcClientOperations;
289 * SILC Client Operations. These must be implemented by the application.
290 * The Client library may call any of these routines at any time. The
291 * routines are used to deliver certain information to the application
292 * or from the application to the client library.
297 /* Message sent to the application by library. `conn' associates the
298 message to a specific connection. `conn', however, may be NULL.
299 The `type' indicates the type of the message sent by the library.
300 The application can for example filter the message according the
302 void (*say)(SilcClient client, SilcClientConnection conn,
303 SilcClientMessageType type, char *msg, ...);
305 /* Message for a channel. The `sender' is the sender of the message
306 The `channel' is the channel. The `message' is the message. Note
307 that `message' maybe NULL. The `flags' indicates message flags
308 and it is used to determine how the message can be interpreted
309 (like it may tell the message is multimedia message). */
310 void (*channel_message)(SilcClient client, SilcClientConnection conn,
311 SilcClientEntry sender, SilcChannelEntry channel,
312 SilcMessageFlags flags,
313 const unsigned char *message,
314 SilcUInt32 message_len);
316 /* Private message to the client. The `sender' is the sender of the
317 message. The message is `message'and maybe NULL. The `flags'
318 indicates message flags and it is used to determine how the message
319 can be interpreted (like it may tell the message is multimedia
321 void (*private_message)(SilcClient client, SilcClientConnection conn,
322 SilcClientEntry sender, SilcMessageFlags flags,
323 const unsigned char *message,
324 SilcUInt32 message_len);
326 /* Notify message to the client. The notify arguments are sent in the
327 same order as servers sends them. The arguments are same as received
328 from the server except for ID's. If ID is received application receives
329 the corresponding entry to the ID. For example, if Client ID is received
330 application receives SilcClientEntry. Also, if the notify type is
331 for channel the channel entry is sent to application (even if server
332 does not send it because client library gets the channel entry from
333 the Channel ID in the packet's header). */
334 void (*notify)(SilcClient client, SilcClientConnection conn,
335 SilcNotifyType type, ...);
337 /* Command handler. This function is called always in the command function.
338 If error occurs it will be called as well. `conn' is the associated
339 client connection. `cmd_context' is the command context that was
340 originally sent to the command. `success' is FALSE if error occurred
341 during command. `command' is the command being processed. It must be
342 noted that this is not reply from server. This is merely called just
343 after application has called the command. Just to tell application
344 that the command really was processed. */
345 void (*command)(SilcClient client, SilcClientConnection conn,
346 SilcClientCommandContext cmd_context, bool success,
347 SilcCommand command, SilcStatus status);
349 /* Command reply handler. This function is called always in the command reply
350 function. If error occurs it will be called as well. Normal scenario
351 is that it will be called after the received command data has been parsed
352 and processed. The function is used to pass the received command data to
355 `conn' is the associated client connection. `cmd_payload' is the command
356 payload data received from server and it can be ignored. It is provided
357 if the application would like to re-parse the received command data,
358 however, it must be noted that the data is parsed already by the library
359 thus the payload can be ignored. `success' is FALSE if error occurred.
360 In this case arguments are not sent to the application. The `status' is
361 the command reply status server returned. The `command' is the command
362 reply being processed. The function has variable argument list and each
363 command defines the number and type of arguments it passes to the
364 application (on error they are not sent).
366 The arguments are sent in the same order as servers sends them. The
367 arguments are same as received from the server except for ID's. If
368 ID is received application receives the corresponding entry to the
369 ID. For example, if Client ID is receives application receives
371 void (*command_reply)(SilcClient client, SilcClientConnection conn,
372 SilcCommandPayload cmd_payload, bool success,
373 SilcCommand command, SilcStatus status, ...);
375 /* Called to indicate that connection was either successfully established
376 or connecting failed. This is also the first time application receives
377 the SilcClientConnection object which it should save somewhere.
378 The `status' indicated whether the connection were successful. If it
379 is error value the application must always call the function
380 silc_client_close_connection. */
381 void (*connected)(SilcClient client, SilcClientConnection conn,
382 SilcClientConnectionStatus status);
384 /* Called to indicate that connection was disconnected to the server.
385 The `status' may tell the reason of the disconnection, and if the
386 `message' is non-NULL it may include the disconnection message
387 received from server. */
388 void (*disconnected)(SilcClient client, SilcClientConnection conn,
389 SilcStatus status, const char *message);
391 /* Find authentication method and authentication data by hostname and
392 port. The hostname may be IP address as well. When the authentication
393 method has been resolved the `completion' callback with the found
394 authentication method and authentication data is called. The `conn'
396 void (*get_auth_method)(SilcClient client, SilcClientConnection conn,
397 char *hostname, SilcUInt16 port,
398 SilcGetAuthMeth completion, void *context);
400 /* Verifies received public key. The `conn_type' indicates which entity
401 (server, client etc.) has sent the public key. If user decides to trust
402 the application may save the key as trusted public key for later
403 use. The `completion' must be called after the public key has been
405 void (*verify_public_key)(SilcClient client, SilcClientConnection conn,
406 SilcSocketType conn_type, unsigned char *pk,
407 SilcUInt32 pk_len, SilcSKEPKType pk_type,
408 SilcVerifyPublicKey completion, void *context);
410 /* Ask (interact, that is) a passphrase from user. The passphrase is
411 returned to the library by calling the `completion' callback with
412 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
413 if not then the library will attempt to encode. */
414 void (*ask_passphrase)(SilcClient client, SilcClientConnection conn,
415 SilcAskPassphrase completion, void *context);
417 /* Notifies application that failure packet was received. This is called
418 if there is some protocol active in the client. The `protocol' is the
419 protocol context. The `failure' is opaque pointer to the failure
420 indication. Note, that the `failure' is protocol dependant and
421 application must explicitly cast it to correct type. Usually `failure'
422 is 32 bit failure type (see protocol specs for all protocol failure
424 void (*failure)(SilcClient client, SilcClientConnection conn,
425 SilcProtocol protocol, void *failure);
427 /* Asks whether the user would like to perform the key agreement protocol.
428 This is called after we have received an key agreement packet or an
429 reply to our key agreement packet. This returns TRUE if the user wants
430 the library to perform the key agreement protocol and FALSE if it is not
431 desired (application may start it later by calling the function
432 silc_client_perform_key_agreement). If TRUE is returned also the
433 `completion' and `context' arguments must be set by the application. */
434 bool (*key_agreement)(SilcClient client, SilcClientConnection conn,
435 SilcClientEntry client_entry, const char *hostname,
436 SilcUInt16 port, SilcKeyAgreementCallback *completion,
439 /* Notifies application that file transfer protocol session is being
440 requested by the remote client indicated by the `client_entry' from
441 the `hostname' and `port'. The `session_id' is the file transfer
442 session and it can be used to either accept or reject the file
443 transfer request, by calling the silc_client_file_receive or
444 silc_client_file_close, respectively. */
445 void (*ftp)(SilcClient client, SilcClientConnection conn,
446 SilcClientEntry client_entry, SilcUInt32 session_id,
447 const char *hostname, SilcUInt16 port);
449 /* Delivers SILC session detachment data indicated by `detach_data' to the
450 application. If application has issued SILC_COMMAND_DETACH command
451 the client session in the SILC network is not quit. The client remains
452 in the network but is detached. The detachment data may be used later
453 to resume the session in the SILC Network. The appliation is
454 responsible of saving the `detach_data', to for example in a file.
456 The detachment data can be given as argument to the functions
457 silc_client_connect_to_server, or silc_client_add_connection when
458 creating connection to remote server, inside SilcClientConnectionParams
459 structure. If it is provided the client library will attempt to resume
460 the session in the network. After the connection is created
461 successfully, the application is responsible of setting the user
462 interface for user into the same state it was before detaching (showing
463 same channels, channel modes, etc). It can do this by fetching the
464 information (like joined channels) from the client library. */
465 void (*detach)(SilcClient client, SilcClientConnection conn,
466 const unsigned char *detach_data,
467 SilcUInt32 detach_data_len);
468 } SilcClientOperations;
471 /****f* silcclient/SilcClientAPI/SilcNicknameFormatParse
475 * typedef void (*SilcNicknameFormatParse)(const char *nickname,
476 * char **ret_nickname);
480 * A callback function provided by the application for the library in
481 * SilcClientParams structure. This function parses the formatted
482 * nickname string `nickname' and returns the true nickname to the
483 * `ret_nickname' pointer. The library can call this function at
487 typedef void (*SilcNicknameFormatParse)(const char *nickname,
488 char **ret_nickname);
490 /****s* silcclient/SilcClientAPI/SilcClientParams
494 * typedef struct { ... } SilcClientParams;
498 * Client parameters. This can be filled with proper values and
499 * given as argument to the silc_client_alloc function. The structure
500 * hold various parameters which affects the function of the client.
505 /* Number of maximum tasks the client library's scheduler can handle.
506 If set to zero, the default value will be used (200). For WIN32
507 systems this should be set to 64 as it is the hard limit dictated
511 /* Rekey timeout in seconds. The client will perform rekey in this
512 time interval. If set to zero, the default value will be used. */
513 unsigned int rekey_secs;
515 /* Connection authentication method request timeout. If server does not
516 reply back the current authentication method when we've requested it
517 in this time interval we'll assume the reply will not come at all.
518 If set to zero, the default value (2 seconds) will be used. */
519 unsigned int connauth_request_secs;
521 /* Nickname format string. This can be used to order the client library
522 to save the nicknames in the library in a certain format. Since
523 nicknames are not unique in SILC it is possible to have multiple same
524 nicknames. Using this format string it is possible to order the library
525 to separate the multiple same nicknames from each other. The format
526 types are defined below and they can appear in any order in the format
527 string. If this is NULL then default format is used which is the
528 default nickname without anything else. The string MUST be NULL
531 Following format types are available:
533 %n nickname - the real nickname returned by the server (mandatory)
534 %h hostname - the stripped hostname of the client
535 %H full hostname - the full hostname of the client
536 %s server name - the server name the client is connected
537 %S full server - the full server name the client is connected
538 %a number - ascending number in case there are several
539 same nicknames (fe. nick@host and nick@host2)
541 Example format strings: "%n@%h%a" (fe. nick@host, nick@host2)
542 "%a!%n@%s" (fe. nick@server, 2!nick@server)
543 "%n@%H" (fe. nick@host.domain.com)
545 By default this format is employed to the nicknames by the libary
546 only when there appears multiple same nicknames. If the library has
547 only one nickname cached the nickname is saved as is and without the
548 defined format. If you want always to save the nickname in the defined
549 format set the boolean field `nickname_force_format' to value TRUE.
551 char nickname_format[32];
553 /* If this is set to TRUE then the `nickname_format' is employed to all
554 saved nicknames even if there are no multiple same nicknames in the
555 cache. By default this is FALSE, which means that the `nickname_format'
556 is employed only if the library will receive a nickname that is
557 already saved in the cache. It is recommended to leave this to FALSE
559 bool nickname_force_format;
561 /* A callback function provided by the application for the library to
562 parse the nickname from the formatted nickname string. Even though
563 the libary formats the nicknames the application knows generally the
564 format better so this function should be provided for the library
565 if the application sets the `nickname_format' field. The library
566 will call this to get the true nickname from the provided formatted
567 nickname string whenever it needs the true nickname. */
568 SilcNicknameFormatParse nickname_parse;
570 /* If this is set to TRUE then the client will ignore all incoming
571 Requested Attributes queries and does not reply anything back. This
572 usually leads into situation where server does not anymore send
573 the queries after seeing that client does not reply anything back.
574 If your application does not support Requested Attributes or you do
575 not want to use them set this to TRUE. See SilcAttribute and
576 silc_client_attribute_add for more information on attributes. */
577 bool ignore_requested_attributes;
583 /* Initialization functions (client.c) */
585 /****f* silcclient/SilcClientAPI/silc_client_alloc
589 * SilcClient silc_client_alloc(SilcClientOperations *ops,
590 * SilcClientParams *params,
592 * const char *silc_version);
596 * Allocates new client object. This has to be done before client may
597 * work. After calling this one must call silc_client_init to initialize
598 * the client. The `application' is application specific user data pointer
599 * and caller must free it. The `silc_version' is the application version
600 * that will be used to compare against remote host's (usually a server)
601 * version string. The `application' context is accessible by the
602 * application by client->application, client being SilcClient.
605 SilcClient silc_client_alloc(SilcClientOperations *ops,
606 SilcClientParams *params,
608 const char *version_string);
610 /****f* silcclient/SilcClientAPI/silc_client_free
614 * void silc_client_free(SilcClient client);
618 * Frees client object and its internals. The execution of the client
619 * should be stopped with silc_client_stop function before calling
623 void silc_client_free(SilcClient client);
625 /****f* silcclient/SilcClientAPI/silc_client_init
629 * int silc_client_init(SilcClient client);
633 * Initializes the client. This makes all the necessary steps to make
634 * the client ready to be run. One must call silc_client_run to run the
635 * client. Returns FALSE if error occurred, TRUE otherwise.
638 int silc_client_init(SilcClient client);
640 /****f* silcclient/SilcClientAPI/silc_client_run
644 * void silc_client_run(SilcClient client);
648 * Runs the client. This starts the scheduler from the utility library.
649 * When this functions returns the execution of the appliation is over.
650 * The client must be initialized before calling this.
653 void silc_client_run(SilcClient client);
655 /****f* silcclient/SilcClientAPI/silc_client_run_one
659 * void silc_client_run_one(SilcClient client);
663 * Runs the client and returns immeadiately. This function is used when
664 * the SILC Client object indicated by the `client' is run under some
665 * other scheduler, or event loop or main loop. On GUI applications,
666 * for example this may be desired to used to run the client under the
667 * GUI application's main loop. Typically the GUI application would
668 * register an idle task that calls this function multiple times in
669 * a second to quickly process the SILC specific data.
672 void silc_client_run_one(SilcClient client);
674 /****f* silcclient/SilcClientAPI/silc_client_stop
678 * void silc_client_stop(SilcClient client);
682 * Stops the client. This is called to stop the client and thus to stop
683 * the program. The client context must be freed with the silc_client_free
687 void silc_client_stop(SilcClient client);
690 /* Connecting functions (client.c) */
692 /****s* silcclient/SilcClientAPI/SilcClientConnectionParams
696 * typedef struct { ... } SilcClientConnectionParams;
700 * Client connection parameters. This can be filled by the application
701 * and given as argument to silc_client_connect_to_server or to
702 * silc_client_add_connection.
707 /* The SILC session detachment data that was returned by `detach' client
708 operation when the application detached from the network. Application
709 is responsible of saving the data and giving it as argument here
710 for resuming the session in the SILC network.
712 If this is provided here the client library will attempt to resume
713 the session in the network. After the connection is created
714 successfully, the application is responsible of setting the user
715 interface for user into the same state it was before detaching (showing
716 same channels, channel modes, etc). It can do this by fetching the
717 information (like joined channels) from the client library. */
718 unsigned char *detach_data;
719 SilcUInt32 detach_data_len;
721 } SilcClientConnectionParams;
724 /****f* silcclient/SilcClientAPI/silc_client_connect_to_server
728 * int silc_client_connect_to_server(SilcClient client,
729 * SilcClientConnectionParams *params,
730 * int port, char *host, void *context);
734 * Connects to remote server. This is the main routine used to connect
735 * to SILC server. Returns -1 on error and the created socket otherwise.
736 * The `context' is user context that is saved into the SilcClientConnection
737 * that is created after the connection is created. Note that application
738 * may handle the connecting process outside the library. If this is the
739 * case then this function is not used at all. When the connecting is
740 * done the `connect' client operation is called, and the `context' is
741 * accessible with conn->context, conn being SilcClientConnection.
742 * If the `params' is provided they are used by the routine.
745 int silc_client_connect_to_server(SilcClient client,
746 SilcClientConnectionParams *params,
747 int port, char *host, void *context);
749 /****f* silcclient/SilcClientAPI/silc_client_add_connection
754 * SilcClientConnection
755 * silc_client_add_connection(SilcClient client,
756 * SilcClientConnectionParams *params,
757 * char *hostname, int port, void *context);
761 * Allocates and adds new connection to the client. This adds the allocated
762 * connection to the connection table and returns a pointer to it. A client
763 * can have multiple connections to multiple servers. Every connection must
764 * be added to the client using this function. User data `context' may
765 * be sent as argument. If the `params' is provided they are used by
770 * This function is normally used only if the application performed
771 * the connecting outside the library, and did not called the
772 * silc_client_connect_to_server function at all. The library
773 * however may use this internally.
777 silc_client_add_connection(SilcClient client,
778 SilcClientConnectionParams *params,
779 char *hostname, int port, void *context);
781 /****f* silcclient/SilcClientAPI/silc_client_del_connection
785 * void silc_client_del_connection(SilcClient client,
786 * SilcClientConnection conn);
790 * Removes connection from client. Frees all memory. The library
791 * call this function automatically for all connection contexts.
792 * The application however may free the connection contexts it has
796 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
798 /****f* silcclient/SilcClientAPI/silc_client_add_socket
802 * void silc_client_add_socket(SilcClient client,
803 * SilcSocketConnection sock);
807 * Adds listener socket to the listener sockets table. This function is
808 * used to add socket objects that are listeners to the client. This should
809 * not be used to add other connection objects.
812 void silc_client_add_socket(SilcClient client, SilcSocketConnection sock);
814 /****f* silcclient/SilcClientAPI/silc_client_del_socket
818 * void silc_client_del_socket(SilcClient client,
819 * SilcSocketConnection sock);
823 * Deletes listener socket from the listener sockets table. If the
824 * application has added a socket with silc_client_add_socket it must
825 * also free it using this function.
828 void silc_client_del_socket(SilcClient client, SilcSocketConnection sock);
830 /****f* silcclient/SilcClientAPI/silc_client_start_key_exchange
834 * void silc_client_start_key_exchange(SilcClient client,
835 * SilcClientConnection conn,
840 * Start SILC Key Exchange (SKE) protocol to negotiate shared secret
841 * key material between client and server. This function can be called
842 * directly if application is performing its own connecting and does not
843 * use the connecting provided by this library. This function is normally
844 * used only if the application performed the connecting outside the
845 * library. The library however may use this internally. After the
846 * key exchange is performed the `connect' client operation is called.
849 void silc_client_start_key_exchange(SilcClient client,
850 SilcClientConnection conn,
853 /****f* silcclient/SilcClientAPI/silc_client_close_connection
857 * void silc_client_close_connection(SilcClient client,
858 * SilcClientConnection conn);
862 * Closes connection to remote end. Free's all allocated data except
863 * for some information such as nickname etc. that are valid at all time.
866 void silc_client_close_connection(SilcClient client,
867 SilcClientConnection conn);
870 /* Message sending functions (client_channel.c and client_prvmsg.c) */
872 /****f* silcclient/SilcClientAPI/silc_client_send_channel_message
876 * void silc_client_send_channel_message(SilcClient client,
877 * SilcClientConnection conn,
878 * SilcChannelEntry channel,
879 * SilcChannelPrivateKey key,
880 * SilcMessageFlags flags,
881 * unsigned char *data,
882 * SilcUInt32 data_len,
887 * Sends packet to the `channel'. Packet to channel is always encrypted
888 * differently from "normal" packets. SILC header of the packet is
889 * encrypted with the next receiver's key and the rest of the packet is
890 * encrypted with the channel specific key. Padding and HMAC is computed
891 * with the next receiver's key. The `data' is the channel message. If
892 * the `force_send' is TRUE then the packet is sent immediately.
894 * If `key' is provided then that private key is used to encrypt the
895 * channel message. If it is not provided, private keys has not been
896 * set at all, the normal channel key is used automatically. If private
897 * keys are set then the first key (the key that was added first as
898 * private key) is used.
901 void silc_client_send_channel_message(SilcClient client,
902 SilcClientConnection conn,
903 SilcChannelEntry channel,
904 SilcChannelPrivateKey key,
905 SilcMessageFlags flags,
910 /****f* silcclient/SilcClientAPI/silc_client_send_private_message
914 * void silc_client_send_private_message(SilcClient client,
915 * SilcClientConnection conn,
916 * SilcClientEntry client_entry,
917 * SilcMessageFlags flags,
918 * unsigned char *data,
919 * SilcUInt32 data_len,
924 * Sends private message to remote client. If private message key has
925 * not been set with this client then the message will be encrypted using
926 * normal session keys. Private messages are special packets in SILC
927 * network hence we need this own function for them. This is similar
928 * to silc_client_packet_send_to_channel except that we send private
929 * message. The `data' is the private message. If the `force_send' is
930 * TRUE the packet is sent immediately.
933 void silc_client_send_private_message(SilcClient client,
934 SilcClientConnection conn,
935 SilcClientEntry client_entry,
936 SilcMessageFlags flags,
942 /* Client and Channel entry retrieval (idlist.c) */
944 /****f* silcclient/SilcClientAPI/SilcGetClientCallback
948 * typedef void (*SilcGetClientCallback)(SilcClient client,
949 * SilcClientConnection conn,
950 * SilcClientEntry *clients,
951 * SilcUInt32 clients_count,
956 * Callback function given to the silc_client_get_client function. The
957 * found entries are allocated into the `clients' array. The array must
958 * not be freed by the receiver, the library will free it later. If the
959 * `clients' is NULL, no such clients exist in the SILC Network.
962 typedef void (*SilcGetClientCallback)(SilcClient client,
963 SilcClientConnection conn,
964 SilcClientEntry *clients,
965 SilcUInt32 clients_count,
968 /****f* silcclient/SilcClientAPI/silc_client_get_clients
972 * void silc_client_get_clients(SilcClient client,
973 * SilcClientConnection conn,
974 * const char *nickname,
975 * const char *server,
976 * SilcGetClientCallback completion,
981 * Finds client entry or entries by the `nickname' and `server'. The
982 * completion callback will be called when the client entries has been
983 * found. After the server returns the client information it is cached
984 * and can be accesses locally at a later time.
988 * NOTE: This function is always asynchronous and resolves the client
989 * information from the server. Thus, if you already know the client
990 * information then use the silc_client_get_client_by_id function to
991 * get the client entry since this function may be very slow and should
992 * be used only to initially get the client entries.
995 void silc_client_get_clients(SilcClient client,
996 SilcClientConnection conn,
997 const char *nickname,
999 SilcGetClientCallback completion,
1002 /****f* silcclient/SilcClientAPI/silc_client_get_clients_local
1006 * SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1007 * SilcClientConnection conn,
1008 * const char *nickname,
1009 * const char *format,
1010 * SilcUInt32 *clients_count);
1014 * Same as silc_client_get_clients function but does not resolve anything
1015 * from the server. This checks local cache and returns all matching
1016 * clients from the local cache. If none was found this returns NULL.
1017 * The `nickname' is the real nickname of the client, and the `format'
1018 * is the formatted nickname to find exact match from multiple found
1019 * entries. The format must be same as given in the SilcClientParams
1020 * structure to the client library. If the `format' is NULL all found
1021 * clients by `nickname' are returned. The caller must return the
1025 SilcClientEntry *silc_client_get_clients_local(SilcClient client,
1026 SilcClientConnection conn,
1027 const char *nickname,
1029 SilcUInt32 *clients_count);
1031 /****f* silcclient/SilcClientAPI/silc_client_get_clients_by_list
1035 * void silc_client_get_clients_by_list(SilcClient client,
1036 * SilcClientConnection conn,
1037 * SilcUInt32 list_count,
1038 * SilcBuffer client_id_list,
1039 * SilcGetClientCallback completion,
1044 * Gets client entries by the list of client ID's `client_id_list'. This
1045 * always resolves those client ID's it does not know yet from the server
1046 * so this function might take a while. The `client_id_list' is a list
1047 * of ID Payloads added one after other. JOIN command reply and USERS
1048 * command reply for example returns this sort of list. The `completion'
1049 * will be called after the entries are available. When server returns
1050 * the client information it will be cached and can be accessed locally
1054 void silc_client_get_clients_by_list(SilcClient client,
1055 SilcClientConnection conn,
1056 SilcUInt32 list_count,
1057 SilcBuffer client_id_list,
1058 SilcGetClientCallback completion,
1061 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id
1065 * SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1066 * SilcClientConnection conn,
1067 * SilcClientID *client_id);
1071 * Find entry for client by the client's ID. Returns the entry or NULL
1072 * if the entry was not found. This checks the local cache and does
1073 * not resolve anything from server.
1076 SilcClientEntry silc_client_get_client_by_id(SilcClient client,
1077 SilcClientConnection conn,
1078 SilcClientID *client_id);
1080 /****f* silcclient/SilcClientAPI/silc_client_get_client_by_id_resolve
1085 * silc_client_get_client_by_id_resolve(SilcClient client,
1086 * SilcClientConnection conn,
1087 * SilcClientID *client_id,
1088 * SilcBuffer attributes,
1089 * SilcGetClientCallback completion,
1094 * Same as silc_client_get_client_by_id but will always resolve the
1095 * information from the server. Use this only if you know that you
1096 * do not have the entry and the only thing you know about the client
1097 * is its ID. When server returns the client information it will be
1098 * cache and can be accessed locally at a later time.
1100 * If the `attributes' is non-NULL then the buffer includes Requested
1101 * Attributes which can be used to fetch very detailed information
1102 * about the user. If it is NULL then only normal WHOIS query is
1103 * made (for more information about attributes see SilcAttribute).
1104 * Caller may create the `attributes' with silc_client_attributes_request
1108 void silc_client_get_client_by_id_resolve(SilcClient client,
1109 SilcClientConnection conn,
1110 SilcClientID *client_id,
1111 SilcBuffer attributes,
1112 SilcGetClientCallback completion,
1115 /****f* silcclient/SilcClientAPI/silc_client_del_client
1119 * bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1120 * SilcClientEntry client_entry)
1124 * Removes client from local cache by the client entry indicated by
1125 * the `client_entry'. Returns TRUE if the deletion were successful.
1128 bool silc_client_del_client(SilcClient client, SilcClientConnection conn,
1129 SilcClientEntry client_entry);
1131 /****f* silcclient/SilcClientAPI/SilcGetChannelCallback
1135 * typedef void (*SilcGetChannelCallback)(SilcClient client,
1136 * SilcClientConnection conn,
1137 * SilcChannelEntry *channels,
1138 * SilcUInt32 channels_count,
1143 * Callback function given to the silc_client_get_channel_* functions.
1144 * The found entries are allocated into the `channels' array. The array
1145 * must not be freed by the receiver, the library will free it later.
1146 * If the `channel' is NULL, no such channel exist in the SILC Network.
1149 typedef void (*SilcGetChannelCallback)(SilcClient client,
1150 SilcClientConnection conn,
1151 SilcChannelEntry *channels,
1152 SilcUInt32 channels_count,
1155 /****f* silcclient/SilcClientAPI/silc_client_get_channel
1159 * SilcChannelEntry silc_client_get_channel(SilcClient client,
1160 * SilcClientConnection conn,
1165 * Finds entry for channel by the channel name. Returns the entry or NULL
1166 * if the entry was not found. It is found only if the client is joined
1170 SilcChannelEntry silc_client_get_channel(SilcClient client,
1171 SilcClientConnection conn,
1174 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id
1179 * silc_client_get_channel_by_id(SilcClient client,
1180 * SilcClientConnection conn,
1181 * SilcChannelID *channel_id);
1185 * Finds channel entry by the channel name. Returns the entry or NULL
1186 * if it was not found.
1189 SilcChannelEntry silc_client_get_channel_by_id(SilcClient client,
1190 SilcClientConnection conn,
1191 SilcChannelID *channel_id);
1193 /****f* silcclient/SilcClientAPI/silc_client_get_channel_by_id_resolve
1198 * silc_client_get_channel_by_id_resolve(SilcClient client,
1199 * SilcClientConnection conn,
1200 * SilcChannelID *channel_id,
1201 * SilcGetClientCallback completion,
1206 * Resolves the channel information (its name mainly) from the server
1207 * by the `channel_id'. Use this only if you know that you do not have
1208 * the entry cached locally.
1211 void silc_client_get_channel_by_id_resolve(SilcClient client,
1212 SilcClientConnection conn,
1213 SilcChannelID *channel_id,
1214 SilcGetChannelCallback completion,
1217 /****f* silcclient/SilcClientAPI/silc_client_del_channel
1221 * bool silc_client_del_channel(SilcClient client,
1222 * SilcClientConnection conn,
1223 * SilcChannelEntry channel)
1227 * Removes channel from local cache by the channel entry indicated by
1228 * the `channel'. Returns TRUE if the deletion were successful.
1231 bool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
1232 SilcChannelEntry channel);
1234 /****f* silcclient/SilcClientAPI/silc_client_get_server
1238 * SilcServerEntry silc_client_get_server(SilcClient client,
1239 * SilcClientConnection conn,
1240 * char *server_name)
1244 * Finds entry for server by the server name. Returns the entry or NULL
1245 * if the entry was not found.
1248 SilcServerEntry silc_client_get_server(SilcClient client,
1249 SilcClientConnection conn,
1252 /****f* silcclient/SilcClientAPI/silc_client_get_server_by_id
1256 * SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1257 * SilcClientConnection conn,
1258 * SilcServerID *server_id);
1262 * Finds entry for server by the server ID. Returns the entry or NULL
1263 * if the entry was not found.
1266 SilcServerEntry silc_client_get_server_by_id(SilcClient client,
1267 SilcClientConnection conn,
1268 SilcServerID *server_id);
1270 /****f* silcclient/SilcClientAPI/silc_client_del_server
1274 * bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1275 * SilcServerEntry server);
1279 * Removes server from local cache by the server entry indicated by
1280 * the `server'. Returns TRUE if the deletion were successful.
1283 bool silc_client_del_server(SilcClient client, SilcClientConnection conn,
1284 SilcServerEntry server);
1286 /****f* silcclient/SilcClientAPI/silc_client_on_channel
1290 * SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1291 * SilcClientEntry client_entry);
1295 * Returns the ChannelUser entry if the `client_entry' is joined on the
1296 * channel indicated by the `channel'. NULL if client is not joined on
1300 SilcChannelUser silc_client_on_channel(SilcChannelEntry channel,
1301 SilcClientEntry client_entry);
1303 /* Command management (command.c) */
1305 /****f* silcclient/SilcClientAPI/silc_client_command_alloc
1309 * SilcClientCommandContext silc_client_command_alloc(void);
1313 * Allocate Command Context. The context is defined in `command.h' file.
1314 * The context is used by the library commands and applications should use
1315 * it as well. However, application may choose to use some own context
1316 * for its local commands. All library commands, however, must use this
1320 SilcClientCommandContext silc_client_command_alloc(void);
1322 /****f* silcclient/SilcClientAPI/silc_client_command_free
1326 * void silc_client_command_free(SilcClientCommandContext ctx);
1330 * Free command context and its internals. If the contex was duplicated
1331 * with silc_client_command_dup this may not actually free the data,
1332 * instead it will decrease the reference counter of the context. The
1333 * context will be freed when the reference counter hits zero.
1336 void silc_client_command_free(SilcClientCommandContext ctx);
1338 /****f* silcclient/SilcClientAPI/silc_client_command_dup
1342 * SilcClientCommandContext
1343 * silc_client_command_dup(SilcClientCommandContext ctx);
1347 * Duplicate Command Context by adding reference counter. The context won't
1348 * be free'd untill it hits zero.
1351 SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
1353 /****f* silcclient/SilcClientAPI/silc_client_command_find
1357 * SilcClientCommand silc_client_command_find(SilcClient client,
1358 * const char *name);
1362 * Finds and returns a pointer to the command list. Return NULL if the
1363 * command is not found. See the `command.[ch]' for the command list.
1364 * Command names are not case-sensitive.
1367 SilcClientCommand silc_client_command_find(SilcClient client,
1370 /****f* silcclient/SilcClientAPI/silc_client_command_call
1374 * void silc_client_command_call(SilcClientCommand command);
1378 * Calls the command (executes it). Application can call this after
1379 * it has allocated the SilcClientCommandContext with the function
1380 * silc_client_command_alloc and found the command from the client
1381 * library by calling silc_client_command_find. This will execute
1384 * Application can call the command function directly too if it
1385 * wishes to do so. See the command.h for details of the
1386 * SilcClientCommand structure.
1389 void silc_client_command_call(SilcClientCommand command,
1390 SilcClientCommandContext cmd);
1392 /****f* silcclient/SilcClientAPI/silc_client_command_send
1396 * void silc_client_command_send(SilcClient client,
1397 * SilcClientConnection conn,
1398 * SilcCommand command, SilcUInt16 ident,
1399 * SilcUInt32 argc, ...);
1403 * Generic function to send any command. The arguments must be sent already
1404 * encoded into correct form and in correct order. If application wants
1405 * to perform the commands by itself, it can do so and send the data
1406 * directly to the server using this function. If application is using
1407 * the silc_client_command_call, this function is usually not used.
1409 * The variable arguments are a pair of { type, data, data_length },
1410 * and the `argc' is the number of these pairs.
1414 * silc_client_command_send(client, conn, SILC_COMMAND_WHOIS, 0, 1,
1415 * 1, nickname, strlen(nickname));
1418 void silc_client_command_send(SilcClient client, SilcClientConnection conn,
1419 SilcCommand command, SilcUInt16 ident,
1420 SilcUInt32 argc, ...);
1422 /****f* silcclient/SilcClientAPI/silc_client_command_pending
1426 * void silc_client_command_pending(SilcClientConnection conn,
1427 * SilcCommand reply_cmd,
1429 * SilcCommandCb callback,
1434 * Add new pending command to be executed when reply to a command has been
1435 * received. The `reply_cmd' is the command that will call the `callback'
1436 * with `context' when reply has been received. If `ident' is non-zero
1437 * the `callback' will be executed when received reply with command
1438 * identifier `ident'.
1440 * Note that the application is notified about the received command
1441 * reply through the `command_reply' client operation before calling
1442 * the `callback` pending command callback.
1445 void silc_client_command_pending(SilcClientConnection conn,
1446 SilcCommand reply_cmd,
1448 SilcCommandCb callback,
1452 /* Private Message key management (client_prvmsg.c) */
1454 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key
1458 * int silc_client_add_private_message_key(SilcClient client,
1459 * SilcClientConnection conn,
1460 * SilcClientEntry client_entry,
1462 * unsigned char *key,
1463 * SilcUInt32 key_len,
1464 * bool generate_key,
1469 * Adds private message key to the client library. The key will be used to
1470 * encrypt all private message between the client and the remote client
1471 * indicated by the `client_entry'. If the `key' is NULL and the boolean
1472 * value `generate_key' is TRUE the library will generate random key.
1473 * The `key' maybe for example pre-shared-key, passphrase or similar.
1474 * The `cipher' MAY be provided but SHOULD be NULL to assure that the
1475 * requirements of the SILC protocol are met. The API, however, allows
1476 * to allocate any cipher.
1478 * If `responder' is TRUE then the sending and receiving keys will be
1479 * set according the client being the receiver of the private key. If
1480 * FALSE the client is being the sender (or negotiator) of the private
1483 * It is not necessary to set key for normal private message usage. If the
1484 * key is not set then the private messages are encrypted using normal
1485 * session keys. Setting the private key, however, increases the security.
1487 * Returns FALSE if the key is already set for the `client_entry', TRUE
1491 int silc_client_add_private_message_key(SilcClient client,
1492 SilcClientConnection conn,
1493 SilcClientEntry client_entry,
1500 /****f* silcclient/SilcClientAPI/silc_client_add_private_message_key_ske
1504 * int silc_client_add_private_message_key_ske(SilcClient client,
1505 * SilcClientConnection conn,
1506 * SilcClientEntry client_entry,
1508 * SilcSKEKeyMaterial *key);
1512 * Same as silc_client_add_private_message_key but takes the key material
1513 * from the SKE key material structure. This structure is received if
1514 * the application uses the silc_client_send_key_agreement to negotiate
1515 * the key material. The `cipher' SHOULD be provided as it is negotiated
1516 * also in the SKE protocol.
1519 int silc_client_add_private_message_key_ske(SilcClient client,
1520 SilcClientConnection conn,
1521 SilcClientEntry client_entry,
1523 SilcSKEKeyMaterial *key,
1526 /****f* silcclient/SilcClientAPI/silc_client_del_private_message_key
1530 * int silc_client_del_private_message_key(SilcClient client,
1531 * SilcClientConnection conn,
1532 * SilcClientEntry client_entry);
1536 * Removes the private message from the library. The key won't be used
1537 * after this to protect the private messages with the remote `client_entry'
1538 * client. Returns FALSE on error, TRUE otherwise.
1541 int silc_client_del_private_message_key(SilcClient client,
1542 SilcClientConnection conn,
1543 SilcClientEntry client_entry);
1545 /****f* silcclient/SilcClientAPI/silc_client_list_private_message_keys
1549 * SilcPrivateMessageKeys
1550 * silc_client_list_private_message_keys(SilcClient client,
1551 * SilcClientConnection conn,
1552 * SilcUInt32 *key_count);
1556 * Returns array of set private message keys associated to the connection
1557 * `conn'. Returns allocated SilcPrivateMessageKeys array and the array
1558 * count to the `key_count' argument. The array must be freed by the caller
1559 * by calling the silc_client_free_private_message_keys function. Note:
1560 * the keys returned in the array is in raw format. It might not be desired
1561 * to show the keys as is. The application might choose not to show the keys
1562 * at all or to show the fingerprints of the keys.
1565 SilcPrivateMessageKeys
1566 silc_client_list_private_message_keys(SilcClient client,
1567 SilcClientConnection conn,
1568 SilcUInt32 *key_count);
1570 /****f* silcclient/SilcClientAPI/silc_client_free_private_message_keys
1574 * void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1575 * SilcUInt32 key_count);
1579 * Frees the SilcPrivateMessageKeys array returned by the function
1580 * silc_client_list_private_message_keys.
1583 void silc_client_free_private_message_keys(SilcPrivateMessageKeys keys,
1584 SilcUInt32 key_count);
1587 /* Channel private key management (client_channel.c,
1588 SilcChannelPrivateKey is defined in idlist.h) */
1590 /****f* silcclient/SilcClientAPI/silc_client_add_channel_private_key
1594 * int silc_client_add_channel_private_key(SilcClient client,
1595 * SilcClientConnection conn,
1596 * SilcChannelEntry channel,
1600 * unsigned char *key,
1601 * SilcUInt32 key_len);
1605 * Adds private key for channel. This may be set only if the channel's mode
1606 * mask includes the SILC_CHANNEL_MODE_PRIVKEY. This returns FALSE if the
1607 * mode is not set. When channel has private key then the messages are
1608 * encrypted using that key. All clients on the channel must also know the
1609 * key in order to decrypt the messages. However, it is possible to have
1610 * several private keys per one channel. In this case only some of the
1611 * clients on the channel may know the one key and only some the other key.
1612 * The `name' can be application given name for the key.
1614 * The private key for channel is optional. If it is not set then the
1615 * channel messages are encrypted using the channel key generated by the
1616 * server. However, setting the private key (or keys) for the channel
1617 * significantly adds security. If more than one key is set the library
1618 * will automatically try all keys at the message decryption phase. Note:
1619 * setting many keys slows down the decryption phase as all keys has to
1620 * be tried in order to find the correct decryption key. However, setting
1621 * a few keys does not have big impact to the decryption performace.
1625 * NOTE: This is entirely local setting. The key set using this function
1626 * is not sent to the network at any phase.
1628 * NOTE: If the key material was originated by the SKE protocol (using
1629 * silc_client_send_key_agreement) then the `key' MUST be the
1630 * key->send_enc_key as this is dictated by the SILC protocol. However,
1631 * currently it is not expected that the SKE key material would be used
1632 * as channel private key. However, this API allows it.
1635 int silc_client_add_channel_private_key(SilcClient client,
1636 SilcClientConnection conn,
1637 SilcChannelEntry channel,
1642 SilcUInt32 key_len);
1644 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_keys
1648 * int silc_client_del_channel_private_keys(SilcClient client,
1649 * SilcClientConnection conn,
1650 * SilcChannelEntry channel);
1654 * Removes all private keys from the `channel'. The old channel key is used
1655 * after calling this to protect the channel messages. Returns FALSE on
1656 * on error, TRUE otherwise.
1659 int silc_client_del_channel_private_keys(SilcClient client,
1660 SilcClientConnection conn,
1661 SilcChannelEntry channel);
1663 /****f* silcclient/SilcClientAPI/silc_client_del_channel_private_key
1667 * int silc_client_del_channel_private_key(SilcClient client,
1668 * SilcClientConnection conn,
1669 * SilcChannelEntry channel,
1670 * SilcChannelPrivateKey key);
1674 * Removes and frees private key `key' from the channel `channel'.
1675 * The `key' is retrieved by calling the function
1676 * silc_client_list_channel_private_keys. The key is not used after
1677 * this. If the key was last private key then the old channel key is
1678 * used hereafter to protect the channel messages. This returns FALSE
1679 * on error, TRUE otherwise.
1682 int silc_client_del_channel_private_key(SilcClient client,
1683 SilcClientConnection conn,
1684 SilcChannelEntry channel,
1685 SilcChannelPrivateKey key);
1687 /****f* silcclient/SilcClientAPI/silc_client_list_channel_private_keys
1691 * SilcChannelPrivateKey *
1692 * silc_client_list_channel_private_keys(SilcClient client,
1693 * SilcClientConnection conn,
1694 * SilcChannelEntry channel,
1695 * SilcUInt32 *key_count);
1699 * Returns array (pointers) of private keys associated to the `channel'.
1700 * The caller must free the array by calling the function
1701 * silc_client_free_channel_private_keys. The pointers in the array may be
1702 * used to delete the specific key by giving the pointer as argument to the
1703 * function silc_client_del_channel_private_key.
1706 SilcChannelPrivateKey *
1707 silc_client_list_channel_private_keys(SilcClient client,
1708 SilcClientConnection conn,
1709 SilcChannelEntry channel,
1710 SilcUInt32 *key_count);
1712 /****f* silcclient/SilcClientAPI/silc_client_free_channel_private_keys
1716 * void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1717 * SilcUInt32 key_count);
1721 * Frees the SilcChannelPrivateKey array.
1724 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
1725 SilcUInt32 key_count);
1727 /****f* silcclient/SilcClientAPI/silc_client_current_channel_private_key
1731 * void silc_client_current_channel_private_key(SilcClient client,
1732 * SilcClientConnection conn,
1733 * SilcChannelEntry channel,
1734 * SilcChannelPrivateKey key);
1738 * Sets the `key' to be used as current channel private key on the
1739 * `channel'. Packet sent after calling this function will be secured
1743 void silc_client_current_channel_private_key(SilcClient client,
1744 SilcClientConnection conn,
1745 SilcChannelEntry channel,
1746 SilcChannelPrivateKey key);
1749 /* Key Agreement routines (client_keyagr.c) */
1751 /****f* silcclient/SilcClientAPI/silc_client_send_key_agreement
1755 * void silc_client_send_key_agreement(SilcClient client,
1756 * SilcClientConnection conn,
1757 * SilcClientEntry client_entry,
1760 * SilcUInt32 timeout_secs,
1761 * SilcKeyAgreementCallback completion,
1766 * Sends key agreement request to the remote client indicated by the
1767 * `client_entry'. If the caller provides the `hostname' and the `port'
1768 * arguments then the library will bind the client to that hostname and
1769 * that port for the key agreement protocol. It also sends the `hostname'
1770 * and the `port' in the key agreement packet to the remote client. This
1771 * would indicate that the remote client may initiate the key agreement
1772 * protocol to the `hostname' on the `port'. If port is zero then the
1773 * bound port is undefined (the operating system defines it).
1775 * If the `hostname' and `port' is not provided then empty key agreement
1776 * packet is sent to the remote client. The remote client may reply with
1777 * the same packet including its hostname and port. If the library receives
1778 * the reply from the remote client the `key_agreement' client operation
1779 * callback will be called to verify whether the user wants to perform the
1780 * key agreement or not.
1784 * NOTE: If the application provided the `hostname' and the `port' and the
1785 * remote side initiates the key agreement protocol it is not verified
1786 * from the user anymore whether the protocol should be executed or not.
1787 * By setting the `hostname' and `port' the user gives permission to
1788 * perform the protocol (we are responder in this case).
1790 * NOTE: If the remote side decides not to initiate the key agreement
1791 * or decides not to reply with the key agreement packet then we cannot
1792 * perform the key agreement at all. If the key agreement protocol is
1793 * performed the `completion' callback with the `context' will be called.
1794 * If remote side decides to ignore the request the `completion' will be
1795 * called after the specified timeout, `timeout_secs'.
1797 * NOTE: If the `hostname' and the `port' was not provided the `completion'
1798 * will not be called at all since this does nothing more than sending
1799 * a packet to the remote host.
1801 * NOTE: There can be only one active key agreement for one client entry.
1802 * Before setting new one, the old one must be finished (it is finished
1803 * after calling the completion callback) or the function
1804 * silc_client_abort_key_agreement must be called.
1807 void silc_client_send_key_agreement(SilcClient client,
1808 SilcClientConnection conn,
1809 SilcClientEntry client_entry,
1810 const char *hostname,
1811 const char *bindhost,
1813 SilcUInt32 timeout_secs,
1814 SilcKeyAgreementCallback completion,
1817 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement
1822 * silc_client_perform_key_agreement(SilcClient client,
1823 * SilcClientConnection conn,
1824 * SilcClientEntry client_entry,
1827 * SilcKeyAgreementCallback completion,
1832 * Performs the actual key agreement protocol. Application may use this
1833 * to initiate the key agreement protocol. This can be called for example
1834 * after the application has received the `key_agreement' client operation,
1835 * and did not return TRUE from it.
1837 * The `hostname' is the remote hostname (or IP address) and the `port'
1838 * is the remote port. The `completion' callback with the `context' will
1839 * be called after the key agreement protocol.
1843 * NOTE: If the application returns TRUE in the `key_agreement' client
1844 * operation the library will automatically start the key agreement. In this
1845 * case the application must not call this function. However, application
1846 * may choose to just ignore the `key_agreement' client operation (and
1847 * merely just print information about it on the screen) and call this
1848 * function when the user whishes to do so (by, for example, giving some
1849 * specific command). Thus, the API provides both, automatic and manual
1850 * initiation of the key agreement. Calling this function is the manual
1851 * initiation and returning TRUE in the `key_agreement' client operation
1852 * is the automatic initiation.
1855 void silc_client_perform_key_agreement(SilcClient client,
1856 SilcClientConnection conn,
1857 SilcClientEntry client_entry,
1860 SilcKeyAgreementCallback completion,
1863 /****f* silcclient/SilcClientAPI/silc_client_perform_key_agreement_fd
1868 * silc_client_perform_key_agreement_fd(SilcClient client,
1869 * SilcClientConnection conn,
1870 * SilcClientEntry client_entry,
1873 * SilcKeyAgreementCallback completion,
1878 * Same as above but application has created already the connection to
1879 * the remote host. The `sock' is the socket to the remote connection.
1880 * Application can use this function if it does not want the client library
1881 * to create the connection.
1884 void silc_client_perform_key_agreement_fd(SilcClient client,
1885 SilcClientConnection conn,
1886 SilcClientEntry client_entry,
1889 SilcKeyAgreementCallback completion,
1892 /****f* silcclient/SilcClientAPI/silc_client_abort_key_agreement
1896 * void silc_client_abort_key_agreement(SilcClient client,
1897 * SilcClientConnection conn,
1898 * SilcClientEntry client_entry);
1902 * This function can be called to unbind the hostname and the port for
1903 * the key agreement protocol. However, this function has effect only
1904 * before the key agreement protocol has been performed. After it has
1905 * been performed the library will automatically unbind the port. The
1906 * `client_entry' is the client to which we sent the key agreement
1907 * request. The key agreement completion callback will be called
1908 * with SILC_KEY_AGREEMENT_ABORTED status.
1911 void silc_client_abort_key_agreement(SilcClient client,
1912 SilcClientConnection conn,
1913 SilcClientEntry client_entry);
1916 /* Misc functions */
1918 /****f* silcclient/SilcClientAPI/silc_client_set_away_message
1922 * void silc_client_set_away_message(SilcClient client,
1923 * SilcClientConnection conn,
1928 * Sets away `message'. The away message may be set when the client's
1929 * mode is changed to SILC_UMODE_GONE and the client whishes to reply
1930 * to anyone who sends private message. The `message' will be sent
1931 * automatically back to the the client who send private message. If
1932 * away message is already set this replaces the old message with the
1933 * new one. If `message' is NULL the old away message is removed.
1934 * The sender may freely free the memory of the `message'.
1937 void silc_client_set_away_message(SilcClient client,
1938 SilcClientConnection conn,
1942 /****f* silcclient/SilcClientAPI/SilcConnectionAuthRequest
1946 * typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1947 * SilcClientConnection conn,
1948 * SilcAuthMethod auth_meth,
1953 * Connection authentication method request callback. This is called
1954 * by the client library after it has received the authentication method
1955 * that the application requested by calling the function
1956 * silc_client_request_authentication_method.
1959 typedef void (*SilcConnectionAuthRequest)(SilcClient client,
1960 SilcClientConnection conn,
1961 SilcAuthMethod auth_meth,
1964 /****f* silcclient/SilcClientAPI/silc_client_request_authentication_method
1969 * silc_client_request_authentication_method(SilcClient client,
1970 * SilcClientConnection conn,
1971 * SilcConnectionAuthRequest
1977 * This function can be used to request the current authentication method
1978 * from the server. This may be called when connecting to the server
1979 * and the client library requests the authentication data from the
1980 * application. If the application does not know the current authentication
1981 * method it can request it from the server using this function.
1982 * The `callback' with `context' will be called after the server has
1983 * replied back with the current authentication method.
1987 silc_client_request_authentication_method(SilcClient client,
1988 SilcClientConnection conn,
1989 SilcConnectionAuthRequest callback,
1992 /****d* silcclient/SilcClientAPI/SilcClientMonitorStatus
1996 * typedef enum { ... } SilcClientMonitorStatus;
2000 * File transmission session status types. These will indicate
2001 * the status of the file transmission session.
2006 SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT, /* In key agreemenet phase */
2007 SILC_CLIENT_FILE_MONITOR_SEND, /* Sending file */
2008 SILC_CLIENT_FILE_MONITOR_RECEIVE, /* Receiving file */
2009 SILC_CLIENT_FILE_MONITOR_GET,
2010 SILC_CLIENT_FILE_MONITOR_PUT,
2011 SILC_CLIENT_FILE_MONITOR_CLOSED, /* Session closed */
2012 SILC_CLIENT_FILE_MONITOR_ERROR, /* Error during session */
2013 } SilcClientMonitorStatus;
2016 /****d* silcclient/SilcClientAPI/SilcClientFileError
2020 * typedef enum { ... } SilcClientFileError;
2024 * File transmission error types. These types are returned by
2025 * some of the file transmission functions, and by the monitor
2026 * callback to indicate error.
2031 SILC_CLIENT_FILE_OK,
2032 SILC_CLIENT_FILE_ERROR,
2033 SILC_CLIENT_FILE_UNKNOWN_SESSION,
2034 SILC_CLIENT_FILE_ALREADY_STARTED,
2035 SILC_CLIENT_FILE_NO_SUCH_FILE,
2036 SILC_CLIENT_FILE_PERMISSION_DENIED,
2037 SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED,
2038 } SilcClientFileError;
2041 /****f* silcclient/SilcClientAPI/SilcClientFileMonitor
2045 * typedef void (*SilcClientFileMonitor)(SilcClient client,
2046 * SilcClientConnection conn,
2047 * SilcClientMonitorStatus status,
2048 * SilcClientFileError error,
2049 * SilcUInt64 offset,
2050 * SilcUInt64 filesize,
2051 * SilcClientEntry client_entry,
2052 * SilcUInt32 session_id,
2053 * const char *filepath,
2058 * Monitor callback that is called during the file transmission to
2059 * monitor the transmission process. The `status' indicates the current
2060 * monitoring process. The `error' will indicate the error type
2061 * if `status' is SILC_CLIENT_FILE_MONITOR_ERROR. The `offset' is the
2062 * currently transmitted amount of total `filesize'. The `client_entry'
2063 * indicates the remote client, and the transmission session ID is the
2064 * `session_id'. The filename being transmitted is indicated by the
2068 typedef void (*SilcClientFileMonitor)(SilcClient client,
2069 SilcClientConnection conn,
2070 SilcClientMonitorStatus status,
2071 SilcClientFileError error,
2073 SilcUInt64 filesize,
2074 SilcClientEntry client_entry,
2075 SilcUInt32 session_id,
2076 const char *filepath,
2079 /****f* silcclient/SilcClientAPI/silc_client_file_send
2083 * SilcClientFileError
2084 * silc_client_file_send(SilcClient client,
2085 * SilcClientConnection conn,
2086 * SilcClientFileMonitor monitor,
2087 * void *monitor_context,
2088 * const char *local_ip,
2089 * SilcUInt32 local_port,
2090 * SilcClientEntry client_entry,
2091 * const char *filepath);
2092 * SilcUInt32 *session_id);
2096 * Sends a file indicated by the `filepath' to the remote client
2097 * indicated by the `client_entry'. This will negotiate a secret key
2098 * with the remote client before actually starting the transmission of
2099 * the file. The `monitor' callback will be called to monitor the
2100 * transmission of the file.
2102 * This returns a file session ID for the file transmission to the
2103 * `session_id' pointer.. It can be used to close the session (and
2104 * abort the file transmission) by calling the silc_client_file_close
2105 * function. The session ID is also returned in the `monitor' callback.
2107 * If the `local_ip' is provided then this will try to bind the
2108 * listener for key exchange protocol to that IP. If `local_port' is
2109 * non-zero that port is used. If `local_ip' is NULL then this will
2110 * automatically attempt to bind it to local IP address of the machine.
2111 * If that fails then this does not bind to any address and port, and
2112 * assume that the remote client will provide the listener for the
2113 * key exchange protocol.
2115 * If error will occur during the file transfer process the error
2116 * status will be returned in the monitor callback. In this case
2117 * the application must call silc_client_file_close to close the
2122 silc_client_file_send(SilcClient client,
2123 SilcClientConnection conn,
2124 SilcClientFileMonitor monitor,
2125 void *monitor_context,
2126 const char *local_ip,
2127 SilcUInt32 local_port,
2128 SilcClientEntry client_entry,
2129 const char *filepath,
2130 SilcUInt32 *session_id);
2132 /****f* silcclient/SilcClientAPI/silc_client_file_receive
2136 * SilcClientFileError
2137 * silc_client_file_receive(SilcClient client,
2138 * SilcClientConnection conn,
2139 * SilcClientFileMonitor monitor,
2140 * void *monitor_context,
2142 * SilcUInt32 session_id);
2146 * Receives a file from a client indicated by the `client_entry'. The
2147 * `session_id' indicates the file transmission session and it has been
2148 * received in the `ftp' client operation function. This will actually
2149 * perform the key agreement protocol with the remote client before
2150 * actually starting the file transmission. The `monitor' callback
2151 * will be called to monitor the transmission. If `path' is non NULL
2152 * the file will be saved into that directory. If NULL the file is
2153 * saved in the current working directory.
2155 * If error will occur during the file transfer process the error
2156 * status will be returned in the monitor callback. In this case
2157 * the application must call silc_client_file_close to close the
2162 silc_client_file_receive(SilcClient client,
2163 SilcClientConnection conn,
2164 SilcClientFileMonitor monitor,
2165 void *monitor_context,
2167 SilcUInt32 session_id);
2169 /****f* silcclient/SilcClientAPI/silc_client_file_close
2173 * SilcClientFileError silc_client_file_close(SilcClient client,
2174 * SilcClientConnection conn,
2175 * SilcUInt32 session_id);
2179 * Closes file transmission session indicated by the `session_id'.
2180 * If file transmission is being conducted it will be aborted
2181 * automatically. This function is also used to close the session
2182 * after successful file transmission. This function can be used
2183 * also to reject incoming file transmission request.
2186 SilcClientFileError silc_client_file_close(SilcClient client,
2187 SilcClientConnection conn,
2188 SilcUInt32 session_id);
2190 /****f* silcclient/SilcClientAPI/silc_client_attribute_add
2194 * SilcAttributePayload
2195 * silc_client_attribute_add(SilcClient client,
2196 * SilcClientConnection conn,
2197 * SilcAttribute attribute,
2199 * SilcUInt32 object_size);
2203 * Add new Requsted Attribute for WHOIS command to the client library.
2204 * The `attribute' object indicated by `object' is added and allocated
2205 * SilcAttributePayload is returned. The `object' must be of correct
2206 * type and of correct size. See the SilcAttribute for object types
2207 * for different attributes. You may also get all added attributes
2208 * from the client with silc_client_attributes_get function.
2210 * Requested Attributes are different personal information about the
2211 * user, status information and other information which other users
2212 * may query with WHOIS command. Application may set these so that
2213 * if someone sends WHOIS query these attributes will be replied back
2214 * to the sender. The library always puts the public key to the
2215 * Requested Attributes, but if application wishes to add additional
2216 * public keys (or certificates) it can be done with this interface.
2217 * Library also always computes digital signature of the attributes
2218 * automatically, so application does not need to do that.
2221 SilcAttributePayload silc_client_attribute_add(SilcClient client,
2222 SilcClientConnection conn,
2223 SilcAttribute attribute,
2225 SilcUInt32 object_size);
2227 /****f* silcclient/SilcClientAPI/silc_client_attribute_del
2231 * bool silc_client_attribute_del(SilcClient client,
2232 * SilcClientConnection conn,
2233 * SilcAttribute attribute,
2234 * SilcAttributePayload attr);
2238 * Delete a Requested Attribute from the client. If the `attribute'
2239 * is non-zero then all attributes of that type are deleted and the
2240 * `attr' is ignored. If `attr' is non-NULL then that specific
2241 * attribute is deleted and `attribute' is ignored.
2243 * You may get all added attributes with the function
2244 * silc_client_attributes_get and to get the SilcAttributePayload.
2245 * This function Returns TRUE if the attribute was found and deleted.
2248 bool silc_client_attribute_del(SilcClient client,
2249 SilcClientConnection conn,
2250 SilcAttribute attribute,
2251 SilcAttributePayload attr);
2253 /****f* silcclient/SilcClientAPI/silc_client_attributes_get
2257 * const SilcHashTable
2258 * silc_client_attributes_get(SilcClient client,
2259 * SilcClientConnection conn);
2263 * Returns pointer to the SilcHashTable which includes all the added
2264 * Requested Attributes. The caller must not free the hash table.
2265 * The caller may use SilcHashTableList and silc_hash_table_list to
2266 * traverse the table. Each entry in the hash table is one added
2267 * SilcAttributePayload. It is possible to delete a attribute
2268 * payload while traversing the table.
2271 const SilcHashTable silc_client_attributes_get(SilcClient client,
2272 SilcClientConnection conn);
2274 /****f* silcclient/SilcClientAPI/silc_client_attributes_request
2278 * SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2282 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2283 * then all attributes are requested. Alternatively, `attribute' and
2284 * all variable arguments can each be requested attribute. In this case
2285 * the last must be set to zero (0) to complete the variable list of
2286 * requested attributes. See SilcAttribute for all attributes.
2287 * You can give the returned buffer as argument to for example
2288 * silc_client_get_client_by_id_resolve function.
2291 SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...);
2293 /* Low level packet sending functions */
2295 /****f* silcclient/SilcClientAPI/silc_client_packet_send
2299 * void silc_client_packet_send(SilcClient client,
2300 * SilcSocketConnection sock,
2301 * SilcPacketType type,
2303 * SilcIdType dst_id_type,
2304 * SilcCipher cipher,
2306 * unsigned char *data,
2307 * SilcUInt32 data_len,
2312 * Constructs a Requested Attributes buffer. If the `attribute' is zero (0)
2313 * then all attributes are requested. Alternatively, `attribute' and
2314 * all variable arguments can each be requested attribute. In this case
2315 * the last must be set to zero (0) to complete the variable list of
2316 * requested attributes. See SilcAttribute for all attributes.
2317 * You can give the returned buffer as argument to for example
2318 * silc_client_get_client_by_id_resolve function.
2321 void silc_client_packet_send(SilcClient client,
2322 SilcSocketConnection sock,
2323 SilcPacketType type,
2325 SilcIdType dst_id_type,
2328 unsigned char *data,
2329 SilcUInt32 data_len,
2333 #include "command.h"
2334 #include "command_reply.h"
2336 #include "protocol.h"
2342 #endif /* SILCCLIENT_H */