+screen. IRC is usually implemented this way, however it is not the
+necessary way to associate the client's connections. SilcClientConnection
+object is provided by the library (and is always passed to the application)
+that can be used in the application to associate the connection from the
+library. Application specific context can be saved to the
+SilcClientConnection object which then can be retrieved in the application,
+thus perhaps associate the connection with what ever object in
+application (window or something else).
+
+
+1.4.1 Using Own Connecting
+
+Application might not want to use silc_client_connect_to_server function
+if it wants to perform its own connecting for some reason. In this case
+application must call function silc_client_start_key_exchange after it
+has created the connection by itself. This function starts the key
+exhange protocol between the client and server and the library takes care
+of everything after that.
+
+After connection has been created application must call:
+
+ SilcClientConnection conn;
+
+ /* Add new connection to client */
+ conn = silc_client_add_connection(client, hostname, port, context);
+
+ /* Start key exchange and let the library handle everything
+ after this point on. */
+ silc_client_start_key_exchange(client, conn, sock);
+
+NOTE: These calls are performed only and only if application did not call
+silc_client_connect_to_server function, but performed the connecting
+process manually.
+
+
+1.5 Example Client
+
+This section includes an example SILC client implementation in pseudo-like
+C code. It creates and initializes the client and sets up an imaginary
+user interface. The user will use the user interface then to create
+the connections. The SilcClientOperations are expected to be implemented.
+
+#include "silcincludes.h"
+#include "silcapi.h"
+
+int main()
+{
+ SilcClientOperations ops = {
+ silc_say,
+ silc_channel_message,
+ silc_private_message,
+ silc_notify,
+ silc_command,
+ silc_command_reply,
+ silc_connect,
+ silc_disconnect,
+ silc_get_auth_method,
+ silc_verify_public_key,
+ silc_ask_passphrase,
+ silc_failure,
+ silc_key_agreement,
+ };
+
+ SilcClient client;
+
+ /* Allocate SILC client. The `silc_version_string' is defined
+ in includes/version.h file. */
+ client = silc_client_alloc(&ops, NULL, silc_version_string);
+
+ /* Register default ciphers, pkcs, hash funtions and hmacs. */
+ silc_cipher_register_default();
+ silc_pkcs_register_default();
+ silc_hash_register_default();
+ silc_hmac_register_default();
+
+ /* Set the mandatory pointers, read public and private key from
+ files (or somewhere) and return pointers and PKCS context. */
+ client->username = silc_get_username();
+ client->hostname = silc_net_localhost();
+ client->realname = silc_get_real_name();
+ client->pkcs = get_public_and_private_key(&client->public_key,
+ &client->private_key);
+
+ /* If the keys does not exist, create a key pair since we must
+ provide key pair to the library. */
+ if (!client->pkcs)
+ generate_key_new_key_pair(client);
+
+ /* Iinitialize client */
+ if (!silc_client_init(client))
+ fatal_error("Could not initialize client");
+
+ /* Initialize user interface. The user interface can be generally
+ initialized at any phase, including before actually allocating
+ and initializing the client, if wished. */
+ InitUserInterface();
+ DoCoolThings();
+
+ /* Start the client. This will start the scheduler. At this phase
+ the user might have the user interface in front of him already.
+ He will use the user interface to create the connection to the
+ server for example. When this function returns the program is
+ ended. */
+ silc_client_run(client);
+
+ /* Client is ended */
+ return 0;
+}