updates.
[silc.git] / lib / silcclient / README
1
2                       SILC Client Library Manual
3
4                              Version 0.7
5
6 1.0 Introduction
7
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.
15
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.
27
28
29 1.1 Creating Client
30
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
35 per application.
36
37 The client object is SilcClient which is usually allocated in following
38 manner:
39
40         SilcClient client = silc_client_alloc(&ops, context, version);
41
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.
48
49 `ops' can be defined for example as follows:
50
51 SilcClientOperations ops = {
52   silc_say,
53   silc_channel_message,
54   silc_private_message,
55   silc_notify,
56   silc_command,
57   silc_command_reply,
58   silc_connect,
59   silc_disconnect,
60   silc_get_auth_method,
61   silc_verify_public_key,
62   silc_ask_passphrase,
63   silc_failure,
64   silc_key_agreement,
65 };
66
67
68 1.2 Initializing the Client
69
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:
74
75         client->username
76         client->hostname
77         client->realname
78         client->pkcs
79         client->public_key
80         client->private_key
81
82 You may also set client->nickname if you want.  If it is set then the
83 library will change the nickname to that one after the client is connected
84 to the server.  If not set, then server will initially give the nickname
85 which is same as the username.
86
87 After setting the pointers one must call:
88
89         silc_client_init(client);
90
91 which then initializes the client library for the `client'.  If the
92 pointers mentioned above are not initialized the silc_client_init will
93 fail.  The application should check the return value of the silc_client_init
94 function.
95
96
97 1.3 Running the Client
98
99 The client is run by calling silc_client_run.  The function will call
100 the scheduler from utility library that will be run until the program is
101 ended.  When silc_client_run returns the application is ended.  Thus,
102 to run the client, call:
103
104         silc_client_run(client);
105
106 Usually application may do some other initializations before calling
107 this function.  For example before calling this function application
108 should initialize the user interface.
109
110
111 1.4 Creating Connection to Server
112
113 Connection to remote SILC server is done by calling:
114
115         silc_client_connect_to_server(client, port, hostname, context);
116
117 The function will create the connection asynchronously to the server, ie.
118 the function will return before the actual connection is created.  After
119 the connection is created the client->ops->connect operation is called.
120
121 Generally speaking the connections are associated with windows' on the
122 screen.  IRC is usually implemented this way, however it is not the
123 necessary way to associate the client's connections.  SilcClientConnection
124 object is provided by the library (and is always passed to the application)
125 that can be used in the application to associate the connection from the
126 library.  Application specific context can be saved to the 
127 SilcClientConnection object which then can be retrieved in the application,
128 thus perhaps associate the connection with what ever object in 
129 application (window or something else).
130
131
132 1.4.1 Using Own Connecting
133
134 Application might not want to use silc_client_connect_to_server function
135 if it wants to perform its own connecting for some reason.  In this case
136 application must call function silc_client_start_key_exchange after it
137 has created the connection by itself.  This function starts the key
138 exhange protocol between the client and server and the library takes care
139 of everything after that.
140
141 After connection has been created application must call:
142
143         SilcClientConnection conn;
144
145         /* Add new connection to client */
146         conn = silc_client_add_connection(client, hostname, port, context);
147
148         /* Start key exchange and let the library handle everything
149            after this point on. */
150         silc_client_start_key_exchange(client, conn, sock);
151
152 NOTE: These calls are performed only and only if application did not call
153 silc_client_connect_to_server function, but performed the connecting 
154 process manually.
155
156
157 1.5 Example Client
158
159 This section includes an example SILC client implementation in pseudo-like
160 C code.  It creates and initializes the client and sets up an imaginary
161 user interface.  The user will use the user interface then to create
162 the connections.  The SilcClientOperations are expected to be implemented.
163
164 #include "silcincludes.h"
165 #include "silcapi.h"
166
167 int main()
168 {
169         SilcClientOperations ops = {
170           silc_say,
171           silc_channel_message,
172           silc_private_message,
173           silc_notify,
174           silc_command,
175           silc_command_reply,
176           silc_connect,
177           silc_disconnect,
178           silc_get_auth_method,
179           silc_verify_public_key,
180           silc_ask_passphrase,
181           silc_failure,
182           silc_key_agreement,
183         };
184
185         SilcClient client;
186
187         /* Allocate SILC client. The `silc_version_string' is defined
188            in includes/version.h file. */
189         client = silc_client_alloc(&ops, NULL, silc_version_string);
190
191         /* Register default ciphers, pkcs, hash funtions and hmacs. */
192         silc_cipher_register_default();
193         silc_pkcs_register_default();
194         silc_hash_register_default();
195         silc_hmac_register_default();
196
197         /* Set the mandatory pointers, read public and private key from
198            files (or somewhere) and return pointers and PKCS context. */
199         client->username = silc_get_username();
200         client->hostname = silc_net_localhost();
201         client->realname = silc_get_real_name();
202         client->pkcs = get_public_and_private_key(&client->public_key,
203                                                   &client->private_key);
204
205         /* If the keys does not exist, create a key pair since we must
206            provide key pair to the library. */
207         if (!client->pkcs)
208           generate_key_new_key_pair(client);
209
210         /* Iinitialize client */
211         if (!silc_client_init(client))
212           fatal_error("Could not initialize client");
213
214         /* Initialize user interface. The user interface can be generally
215            initialized at any phase, including before actually allocating
216            and initializing the client, if wished. */
217         InitUserInterface();
218         DoCoolThings();
219
220         /* Start the client. This will start the scheduler. At this phase
221            the user might have the user interface in front of him already.
222            He will use the user interface to create the connection to the
223            server for example. When this function returns the program is 
224           ended. */
225         silc_client_run(client);
226
227         /* Client is ended */
228         return 0;
229 }