5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
24 /* Forward declaration for client */
25 typedef struct SilcClientObject *SilcClient;
27 /* Forward declaration for client window */
28 typedef struct SilcClientWindowObject *SilcClientWindow;
32 /* Structure to hold ping time information. Every PING command will
33 add entry of this structure and is removed after reply to the ping
35 typedef struct SilcClientPingStruct {
41 /* Structure to hold away messages set by user. This is mainly created
42 for future extensions where away messages could be set according filters
43 such as nickname and hostname. For now only one away message can
44 be set in one connection. */
45 typedef struct SilcClientAwayStruct {
47 struct SilcClientAwayStruct *next;
50 /* Window structure used in client to associate all the important
51 connection (window) specific data to this structure. How the window
52 actually appears on the screen in handeled by the silc_screen*
53 routines in screen.c. */
54 struct SilcClientWindowObject {
60 /* Local client ID for this connection */
61 SilcClientID *local_id;
63 /* Decoded local ID so that the above defined ID would not have
64 to be decoded for every packet. */
65 unsigned char *local_id_data;
66 unsigned int local_id_data_len;
68 /* Own client entry. */
69 SilcClientEntry local_entry;
79 /* Remote client ID for this connection */
80 SilcClientID *remote_id;
82 /* Remote local ID so that the above defined ID would not have
83 to be decoded for every packet. */
84 unsigned char *remote_id_data;
85 unsigned int remote_id_data_len;
92 SilcCipher receive_key;
94 unsigned char *hmac_key;
95 unsigned int hmac_key_len;
97 /* Client ID and Channel ID cache. Messages transmitted in SILC network
98 are done using different unique ID's. These are the cache for
99 thoses ID's used in the communication. */
100 SilcIDCache client_cache;
101 SilcIDCache channel_cache;
102 SilcIDCache server_cache;
104 /* Current channel on window. All channel's are saved (allocated) into
105 the cache entries. */
106 SilcChannelEntry current_channel;
108 /* Socket connection object for this connection (window). This
109 object will have a back-pointer to this window object for fast
110 referencing (sock->user_data). */
111 SilcSocketConnection sock;
113 /* Requested pings. */
114 SilcClientPing *ping;
115 unsigned int ping_count;
117 /* Set away message */
118 SilcClientAway *away;
120 /* The actual physical screen. This data is handled by the
121 screen handling routines. */
125 struct SilcClientObject {
129 /* Private and public key */
131 SilcPublicKey public_key;
132 SilcPrivateKey private_key;
134 /* SILC client task queues */
135 SilcTaskQueue io_queue;
136 SilcTaskQueue timeout_queue;
137 SilcTaskQueue generic_queue;
139 /* Input buffer that holds the characters user types. This is
140 used only to store the typed chars for a while. */
141 SilcBuffer input_buffer;
143 /* Table of windows in client. All the data, including connection
144 specific data, is saved in here. */
145 SilcClientWindow *windows;
146 unsigned int windows_count;
148 /* Currently active window. This is pointer to the window table
149 defined above. This must never be free'd directly. */
150 SilcClientWindow current_win;
152 /* The SILC client screen object */
155 /* Generic cipher and hash objects */
156 SilcCipher none_cipher;
162 /* Configuration object */
163 SilcClientConfig config;
165 /* Random Number Generator */
169 /* SIM (SILC Module) table */
170 SilcSimContext **sim;
171 unsigned int sim_count;
178 #define CTRL(x) ((x) & 0x1f) /* Ctrl+x */
181 /* Registers generic task for file descriptor for reading from network and
182 writing to network. As being generic task the actual task is allocated
183 only once and after that the same task applies to all registered fd's. */
184 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
186 SilcTask tmptask = silc_task_register(client->generic_queue, (fd), \
187 silc_client_packet_process, \
190 SILC_TASK_PRI_NORMAL); \
191 silc_task_set_iotype(tmptask, SILC_TASK_WRITE); \
194 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(fd) \
196 silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ)); \
199 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(fd) \
201 silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) | \
202 (1L << SILC_TASK_WRITE))); \
205 /* Finds socket connection object by file descriptor */
206 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
210 for (__i = 0; __i < (__x)->windows_count; __i++) \
211 if ((__x)->windows[__i]->sock->sock == (__fd)) \
214 if (__i >= (__x)->windows_count) \
216 (__sock) = (__x)->windows[__i]->sock; \
219 /* Returns TRUE if windows is currently active window */
220 #define SILC_CLIENT_IS_CURRENT_WIN(__x, __win) ((__x)->current_win == (__win))
223 int silc_client_alloc(SilcClient *new_client);
224 void silc_client_free(SilcClient client);
225 int silc_client_init(SilcClient client);
226 void silc_client_stop(SilcClient client);
227 void silc_client_run(SilcClient client);
228 void silc_client_parse_command_line(unsigned char *buffer,
229 unsigned char ***parsed,
230 unsigned int **parsed_lens,
231 unsigned int **parsed_types,
232 unsigned int *parsed_num,
233 unsigned int max_args);
234 int silc_client_connect_to_server(SilcClient client, int port,
236 void silc_client_packet_send(SilcClient client,
237 SilcSocketConnection sock,
240 SilcIdType dst_id_type,
244 unsigned int data_len,
246 void silc_client_packet_send_to_channel(SilcClient client,
247 SilcSocketConnection sock,
248 SilcChannelEntry channel,
250 unsigned int data_len,
252 void silc_client_packet_send_private_message(SilcClient client,
253 SilcSocketConnection sock,
254 SilcClientEntry client_entry,
256 unsigned int data_len,
258 void silc_client_close_connection(SilcClient client,
259 SilcSocketConnection sock);
260 void silc_client_disconnected_by_server(SilcClient client,
261 SilcSocketConnection sock,
263 void silc_client_error_by_server(SilcClient client,
264 SilcSocketConnection sock,
266 void silc_client_notify_by_server(SilcClient client,
267 SilcSocketConnection sock,
269 void silc_client_receive_new_id(SilcClient client,
270 SilcSocketConnection sock,
271 unsigned char *id_string);
272 void silc_client_new_channel_id(SilcClient client,
273 SilcSocketConnection sock,
276 unsigned char *id_string);
277 void silc_client_receive_channel_key(SilcClient client,
278 SilcSocketConnection sock,
280 void silc_client_channel_message(SilcClient client,
281 SilcSocketConnection sock,
282 SilcPacketContext *packet);