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 /* Window structure used in client to associate all the important
42 connection (window) specific data to this structure. How the window
43 actually appears on the screen in handeled by the silc_screen*
44 routines in screen.c. */
45 struct SilcClientWindowObject {
51 /* Local client ID for this connection */
52 SilcClientID *local_id;
54 /* Decoded local ID so that the above defined ID would not have
55 to be decoded for every packet. */
56 unsigned char *local_id_data;
57 unsigned int local_id_data_len;
59 /* Own client entry. */
60 SilcClientEntry local_entry;
70 /* Remote client ID for this connection */
71 SilcClientID *remote_id;
73 /* Remote local ID so that the above defined ID would not have
74 to be decoded for every packet. */
75 unsigned char *remote_id_data;
76 unsigned int remote_id_data_len;
83 SilcCipher receive_key;
85 unsigned char *hmac_key;
86 unsigned int hmac_key_len;
88 /* Client ID and Channel ID cache. Messages transmitted in SILC network
89 are done using different unique ID's. These are the cache for
90 thoses ID's used in the communication. */
91 SilcIDCache client_cache;
92 SilcIDCache channel_cache;
93 SilcIDCache server_cache;
95 /* Current channel on window. All channel's are saved (allocated) into
97 SilcChannelEntry current_channel;
99 /* Socket connection object for this connection (window). This
100 object will have a back-pointer to this window object for fast
101 referencing (sock->user_data). */
102 SilcSocketConnection sock;
104 /* Requested pings. */
105 SilcClientPing *ping;
106 unsigned int ping_count;
108 /* The actual physical screen. This data is handled by the
109 screen handling routines. */
113 struct SilcClientObject {
117 /* Private and public key */
119 SilcPublicKey public_key;
120 SilcPrivateKey private_key;
122 /* SILC client task queues */
123 SilcTaskQueue io_queue;
124 SilcTaskQueue timeout_queue;
125 SilcTaskQueue generic_queue;
127 /* Input buffer that holds the characters user types. This is
128 used only to store the typed chars for a while. */
129 SilcBuffer input_buffer;
131 /* Table of windows in client. All the data, including connection
132 specific data, is saved in here. */
133 SilcClientWindow *windows;
134 unsigned int windows_count;
136 /* Currently active window. This is pointer to the window table
137 defined above. This must never be free'd directly. */
138 SilcClientWindow current_win;
140 /* The SILC client screen object */
143 /* Generic cipher and hash objects */
144 SilcCipher none_cipher;
150 /* Configuration object */
151 SilcClientConfig config;
153 /* Random Number Generator */
157 /* SIM (SILC Module) table */
158 SilcSimContext **sim;
159 unsigned int sim_count;
166 #define CTRL(x) ((x) & 0x1f) /* Ctrl+x */
169 /* Registers generic task for file descriptor for reading from network and
170 writing to network. As being generic task the actual task is allocated
171 only once and after that the same task applies to all registered fd's. */
172 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
174 SilcTask tmptask = silc_task_register(client->generic_queue, (fd), \
175 silc_client_packet_process, \
178 SILC_TASK_PRI_NORMAL); \
179 silc_task_set_iotype(tmptask, SILC_TASK_WRITE); \
182 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(fd) \
184 silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ)); \
187 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(fd) \
189 silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) | \
190 (1L << SILC_TASK_WRITE))); \
193 /* Finds socket connection object by file descriptor */
194 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
198 for (__i = 0; __i < (__x)->windows_count; __i++) \
199 if ((__x)->windows[__i]->sock->sock == (__fd)) \
202 if (__i >= (__x)->windows_count) \
204 (__sock) = (__x)->windows[__i]->sock; \
207 /* Returns TRUE if windows is currently active window */
208 #define SILC_CLIENT_IS_CURRENT_WIN(__x, __win) ((__x)->current_win == (__win))
211 int silc_client_alloc(SilcClient *new_client);
212 void silc_client_free(SilcClient client);
213 int silc_client_init(SilcClient client);
214 void silc_client_stop(SilcClient client);
215 void silc_client_run(SilcClient client);
216 void silc_client_parse_command_line(unsigned char *buffer,
217 unsigned char ***parsed,
218 unsigned int **parsed_lens,
219 unsigned int **parsed_types,
220 unsigned int *parsed_num,
221 unsigned int max_args);
222 int silc_client_connect_to_server(SilcClient client, int port,
224 void silc_client_packet_send(SilcClient client,
225 SilcSocketConnection sock,
228 SilcIdType dst_id_type,
232 unsigned int data_len,
234 void silc_client_packet_send_to_channel(SilcClient client,
235 SilcSocketConnection sock,
236 SilcChannelEntry channel,
238 unsigned int data_len,
240 void silc_client_packet_send_private_message(SilcClient client,
241 SilcSocketConnection sock,
242 SilcClientEntry client_entry,
244 unsigned int data_len,
246 void silc_client_close_connection(SilcClient client,
247 SilcSocketConnection sock);
248 void silc_client_disconnected_by_server(SilcClient client,
249 SilcSocketConnection sock,
251 void silc_client_error_by_server(SilcClient client,
252 SilcSocketConnection sock,
254 void silc_client_notify_by_server(SilcClient client,
255 SilcSocketConnection sock,
257 void silc_client_receive_new_id(SilcClient client,
258 SilcSocketConnection sock,
259 unsigned char *id_string);
260 void silc_client_new_channel_id(SilcClient client,
261 SilcSocketConnection sock,
264 unsigned char *id_string);
265 void silc_client_receive_channel_key(SilcClient client,
266 SilcSocketConnection sock,
268 void silc_client_channel_message(SilcClient client,
269 SilcSocketConnection sock,
270 SilcPacketContext *packet);