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 /* Structure to hold ping time information. Every PING command will
25 add entry of this structure and is removed after reply to the ping
27 typedef struct SilcClientPingStruct {
33 /* Window structure used in client to associate all the important
34 connection (window) specific data to this structure. How the window
35 actually appears on the screen in handeled by the silc_screen*
36 routines in screen.c. */
43 /* Local client ID for this connection */
44 SilcClientID *local_id;
46 /* Decoded local ID so that the above defined ID would not have
47 to be decoded for every packet. */
48 unsigned char *local_id_data;
49 unsigned int local_id_data_len;
51 /* Own client entry. */
52 SilcClientEntry local_entry;
62 /* Remote client ID for this connection */
63 SilcClientID *remote_id;
65 /* Remote local ID so that the above defined ID would not have
66 to be decoded for every packet. */
67 unsigned char *remote_id_data;
68 unsigned int remote_id_data_len;
75 SilcCipher receive_key;
77 unsigned char *hmac_key;
78 unsigned int hmac_key_len;
80 /* Client ID and Channel ID cache. Messages transmitted in SILC network
81 are done using different unique ID's. These are the cache for
82 thoses ID's used in the communication. */
83 SilcIDCache *client_id_cache[96];
84 unsigned int client_id_cache_count[96];
85 SilcIDCache *channel_id_cache[96];
86 unsigned int channel_id_cache_count[96];
87 SilcIDCache *server_id_cache;
88 unsigned int server_id_cache_count;
90 /* Current channel on window. All channel's are saved (allocated) into
92 SilcChannelEntry current_channel;
94 /* Socket connection object for this connection (window). This
95 object will have a back-pointer to this window object for fast
96 referencing (sock->user_data). */
97 SilcSocketConnection sock;
99 /* Requested pings. */
100 SilcClientPing *ping;
101 unsigned int ping_count;
103 /* The actual physical screen. This data is handled by the
104 screen handling routines. */
112 /* Private and public key */
114 SilcPublicKey public_key;
115 SilcPrivateKey private_key;
117 /* SILC client task queues */
118 SilcTaskQueue io_queue;
119 SilcTaskQueue timeout_queue;
120 SilcTaskQueue generic_queue;
122 /* Input buffer that holds the characters user types. This is
123 used only to store the typed chars for a while. */
124 SilcBuffer input_buffer;
126 /* Table of windows in client. All the data, including connection
127 specific data, is saved in here. */
128 SilcClientWindow *windows;
129 unsigned int windows_count;
131 /* Currently active window. This is pointer to the window table
132 defined above. This must never be free'd directly. */
133 SilcClientWindow current_win;
135 /* The SILC client screen object */
138 /* Generic cipher and hash objects */
139 SilcCipher none_cipher;
145 /* Configuration object */
146 SilcClientConfig config;
148 /* Random Number Generator */
152 /* SIM (SILC Module) table */
153 SilcSimContext **sim;
154 unsigned int sim_count;
158 typedef SilcClientObject *SilcClient;
163 #define CTRL(x) ((x) & 0x1f) /* Ctrl+x */
166 /* Registers generic task for file descriptor for reading from network and
167 writing to network. As being generic task the actual task is allocated
168 only once and after that the same task applies to all registered fd's. */
169 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
171 SilcTask tmptask = silc_task_register(client->generic_queue, (fd), \
172 silc_client_packet_process, \
175 SILC_TASK_PRI_NORMAL); \
176 silc_task_set_iotype(tmptask, SILC_TASK_WRITE); \
179 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(fd) \
181 silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ)); \
184 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(fd) \
186 silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) | \
187 (1L << SILC_TASK_WRITE))); \
190 /* Finds socket connection object by file descriptor */
191 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
195 for (__i = 0; __i < (__x)->windows_count; __i++) \
196 if ((__x)->windows[__i]->sock->sock == (__fd)) \
199 if (__i >= (__x)->windows_count) \
201 (__sock) = (__x)->windows[__i]->sock; \
204 /* Returns TRUE if windows is currently active window */
205 #define SILC_CLIENT_IS_CURRENT_WIN(__x, __win) ((__x)->current_win == (__win))
208 int silc_client_alloc(SilcClient *new_client);
209 void silc_client_free(SilcClient client);
210 int silc_client_init(SilcClient client);
211 void silc_client_stop(SilcClient client);
212 void silc_client_run(SilcClient client);
213 void silc_client_parse_command_line(unsigned char *buffer,
214 unsigned char ***parsed,
215 unsigned int **parsed_lens,
216 unsigned int **parsed_types,
217 unsigned int *parsed_num,
218 unsigned int max_args);
219 int silc_client_connect_to_server(SilcClient client, int port,
221 void silc_client_packet_send(SilcClient client,
222 SilcSocketConnection sock,
225 SilcIdType dst_id_type,
229 unsigned int data_len,
231 void silc_client_packet_send_to_channel(SilcClient client,
232 SilcSocketConnection sock,
233 SilcChannelEntry channel,
235 unsigned int data_len,
237 void silc_client_packet_send_private_message(SilcClient client,
238 SilcSocketConnection sock,
239 SilcClientEntry client_entry,
241 unsigned int data_len,
243 void silc_client_close_connection(SilcClient client,
244 SilcSocketConnection sock);
245 void silc_client_disconnected_by_server(SilcClient client,
246 SilcSocketConnection sock,
248 void silc_client_error_by_server(SilcClient client,
249 SilcSocketConnection sock,
251 void silc_client_notify_by_server(SilcClient client,
252 SilcSocketConnection sock,
254 void silc_client_receive_new_id(SilcClient client,
255 SilcSocketConnection sock,
256 unsigned char *id_string);
257 void silc_client_new_channel_id(SilcClient client,
258 SilcSocketConnection sock,
261 unsigned char *id_string);
262 void silc_client_receive_channel_key(SilcClient client,
263 SilcSocketConnection sock,
265 void silc_client_channel_message(SilcClient client,
266 SilcSocketConnection sock,
267 SilcPacketContext *packet);