2 SILC Client Library Manual
8 SILC Client library is a full featured SILC Client protocolimplementation.
9 The library has been designed to be complete SILC client without actual
10 user interface. The library provides the API for the appliation which
11 it can use to implement generally whatever user interface it wants. The
12 SILC Client Library recides in the lib/silcclient/ directory. It uses
13 common and core compomnent of SILC protocol from the lib/silccore, SKE
14 from lib/silcske and general utility routines from lib/silcutil.
16 The `silcapi.h' file defines the function prototypes that application
17 must implement in order to be able to create the user interface with the
18 library. The idea is that the application can implement whatever user
19 interface routines in the functions and display the data whatever way
20 it wants. The library is entirely transparent to the user interface and
21 it does not include any user interface specific issues such as window
22 handling or item handling on the screen etc. These does not interest
23 the library. The `silcapi.h' also defines the client libary interface
24 the application can call. The interface includes for example functions
25 for sending channel and private messages, client and channel retrieval
26 and other utility functions.
31 The client is context or entity based, so several client entitites can
32 be created in the application if needed. However, it should be noted
33 that they are completely independent from each other and can be seen
34 as different applications. Usually only one client entity is needed
37 The client object is SilcClient which is usually allocated in following
40 SilcClient client = silc_client_alloc(&ops, context, version);
42 `ops' is the static structure of client operations that library will call.
43 `context' can be some application specific context that will be saved into
44 the SilcClient object. It is up to the caller to free this context.
45 SilcClient is always passed to the application thus the application
46 specific context can be retrieved from the SilcClient object. See
47 `client.h' file for detailed definition of SilcClient object.
49 `ops' can be defined for example as follows:
51 SilcClientOperations ops = {
61 silc_verify_public_key,
68 1.2 Initializing the Client
70 The client must be initialized before running. However, there are also
71 some other tasks that must be done before initializing the client.
72 The following pointers must be set by the application before calling
73 the initializing function:
82 After setting the pointers one must call:
84 silc_client_init(client);
86 which then initializes the client library for the `client'. If the
87 pointers mentioned above are not initialized the silc_client_init will
88 fail. The application should check the return value of the silc_client_init
92 1.3 Running the Client
94 The client is run by calling silc_client_run. The function will call
95 the scheduler from utility library that will be run until the program is
96 ended. When silc_client_run returns the application is ended. Thus,
97 to run the client, call:
99 silc_client_run(client);
101 Usually application may do some other initializations before calling
102 this function. For example before calling this function application
103 should initialize the user interface.
106 1.4 Creating Connection to Server
108 Connection to remote SILC server is done by calling:
110 silc_client_connect_to_server(client, port, hostname, context);
112 The function will create the connection asynchronously to the server, ie.
113 the function will return before the actual connection is created. After
114 the connection is created the client->ops->connect operation is called.
116 Generally speaking the connections are associated with windows' on the
117 screen. IRC is usually implemented this way, however it is not the
118 necessary way to associate the client's connections. SilcClientConnection
119 object is provided by the library (and is always passed to the application)
120 that can be used in the application to associate the connection from the
121 library. Application specific context can be saved to the
122 SilcClientConnection object which then can be retrieved in the application,
123 thus perhaps associate the connection with what ever object in
124 application (window or something else).
127 1.4.1 Using Own Connecting
129 Application might not want to use silc_client_connect_to_server function
130 if it wants to perform its own connecting for some reason. In this case
131 application must call function silc_client_start_key_exchange after it
132 has created the connection by itself. This function starts the key
133 exhange protocol between the client and server and the library takes care
134 of everything after that.
136 After connection has been created application must call:
138 SilcClientConnection conn;
140 /* Add new connection to client */
141 conn = silc_client_add_connection(client, hostname, port, context);
143 /* Start key exchange and let the library handle everything
144 after this point on. */
145 silc_client_start_key_exchange(client, conn, sock);
147 NOTE: These calls are performed only and only if application did not call
148 silc_client_connect_to_server function, but performed the connecting
154 This section includes an example SILC client implementation in pseudo-like
155 C code. It creates and initializes the client and sets up an imaginary
156 user interface. The user will use the user interface then to create
157 the connections. The SilcClientOperations are expected to be implemented.
159 #include "silcincludes.h"
164 SilcClientOperations ops = {
166 silc_channel_message,
167 silc_private_message,
173 silc_get_auth_method,
174 silc_verify_public_key,
182 /* Allocate SILC client. The `silc_version_string' is defined
183 in includes/version.h file. */
184 client = silc_client_alloc(&ops, NULL, silc_version_string);
186 /* Register default ciphers, pkcs, hash funtions and hmacs. */
187 silc_cipher_register_default();
188 silc_pkcs_register_default();
189 silc_hash_register_default();
190 silc_hmac_register_default();
192 /* Set the mandatory pointers, read public and private key from
193 files (or somewhere) and return pointers and PKCS context. */
194 client->username = silc_get_username();
195 client->hostname = silc_net_localhost();
196 client->realname = silc_get_real_name();
197 client->pkcs = get_public_and_private_key(&client->public_key,
198 &client->private_key);
200 /* If the keys does not exist, create a key pair since we must
201 provide key pair to the library. */
203 generate_key_new_key_pair(client);
205 /* Iinitialize client */
206 if (!silc_client_init(client))
207 fatal_error("Could not initialize client");
209 /* Initialize user interface. The user interface can be generally
210 initialized at any phase, including before actually allocating
211 and initializing the client, if wished. */
215 /* Start the client. This will start the scheduler. At this phase
216 the user might have the user interface in front of him already.
217 He will use the user interface to create the connection to the
218 server for example. When this function returns the program is
220 silc_client_run(client);
222 /* Client is ended */