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;
61 /* Remote client ID for this connection */
62 SilcClientID *remote_id;
64 /* Remote local ID so that the above defined ID would not have
65 to be decoded for every packet. */
66 unsigned char *remote_id_data;
67 unsigned int remote_id_data_len;
74 SilcCipher receive_key;
76 unsigned char *hmac_key;
77 unsigned int hmac_key_len;
79 /* Client ID and Channel ID cache. Messages transmitted in SILC network
80 are done using different unique ID's. These are the cache for
81 thoses ID's used in the communication. */
82 SilcIDCache *client_id_cache[96];
83 unsigned int client_id_cache_count[96];
84 SilcIDCache *channel_id_cache[96];
85 unsigned int channel_id_cache_count[96];
86 SilcIDCache *server_id_cache;
87 unsigned int server_id_cache_count;
89 /* Current channel on window. All channel's are saved (allocated) into
91 SilcChannelEntry current_channel;
93 /* Socket connection object for this connection (window). This
94 object will have a back-pointer to this window object for fast
95 referencing (sock->user_data). */
96 SilcSocketConnection sock;
98 /* Requested pings. */
100 unsigned int ping_count;
102 /* The actual physical screen. This data is handled by the
103 screen handling routines. */
111 /* Private and public key */
113 SilcPublicKey public_key;
114 SilcPrivateKey private_key;
116 /* SILC client task queues */
117 SilcTaskQueue io_queue;
118 SilcTaskQueue timeout_queue;
119 SilcTaskQueue generic_queue;
121 /* Input buffer that holds the characters user types. This is
122 used only to store the typed chars for a while. */
123 SilcBuffer input_buffer;
125 /* Table of windows in client. All the data, including connection
126 specific data, is saved in here. */
127 SilcClientWindow *windows;
128 unsigned int windows_count;
130 /* Currently active window. This is pointer to the window table
131 defined above. This must never be free'd directly. */
132 SilcClientWindow current_win;
134 /* The SILC client screen object */
137 /* Generic cipher and hash objects */
138 SilcCipher none_cipher;
144 /* Configuration object */
145 SilcClientConfig config;
147 /* Random Number Generator */
151 /* SIM (SILC Module) table */
152 SilcSimContext **sim;
153 unsigned int sim_count;
157 typedef SilcClientObject *SilcClient;
162 #define CTRL(x) ((x) & 0x1f) /* Ctrl+x */
165 /* Registers generic task for file descriptor for reading from network and
166 writing to network. As being generic task the actual task is allocated
167 only once and after that the same task applies to all registered fd's. */
168 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
170 SilcTask tmptask = silc_task_register(client->generic_queue, (fd), \
171 silc_client_packet_process, \
174 SILC_TASK_PRI_NORMAL); \
175 silc_task_set_iotype(tmptask, SILC_TASK_WRITE); \
178 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(fd) \
180 silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ)); \
183 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(fd) \
185 silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) | \
186 (1L << SILC_TASK_WRITE))); \
189 /* Finds socket connection object by file descriptor */
190 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
194 for (__i = 0; __i < (__x)->windows_count; __i++) \
195 if ((__x)->windows[__i]->sock->sock == (__fd)) \
198 if (__i >= (__x)->windows_count) \
200 (__sock) = (__x)->windows[__i]->sock; \
203 /* Returns TRUE if windows is currently active window */
204 #define SILC_CLIENT_IS_CURRENT_WIN(__x, __win) ((__x)->current_win == (__win))
207 int silc_client_alloc(SilcClient *new_client);
208 void silc_client_free(SilcClient client);
209 int silc_client_init(SilcClient client);
210 void silc_client_stop(SilcClient client);
211 void silc_client_run(SilcClient client);
212 void silc_client_parse_command_line(unsigned char *buffer,
213 unsigned char ***parsed,
214 unsigned int **parsed_lens,
215 unsigned int **parsed_types,
216 unsigned int *parsed_num,
217 unsigned int max_args);
218 int silc_client_connect_to_server(SilcClient client, int port,
220 void silc_client_packet_send(SilcClient client,
221 SilcSocketConnection sock,
224 SilcIdType dst_id_type,
228 unsigned int data_len,
230 void silc_client_packet_send_to_channel(SilcClient client,
231 SilcSocketConnection sock,
232 SilcChannelEntry channel,
234 unsigned int data_len,
236 void silc_client_packet_send_private_message(SilcClient client,
237 SilcSocketConnection sock,
238 SilcClientEntry client_entry,
240 unsigned int data_len,
242 void silc_client_close_connection(SilcClient client,
243 SilcSocketConnection sock);
244 void silc_client_disconnected_by_server(SilcClient client,
245 SilcSocketConnection sock,
247 void silc_client_error_by_server(SilcClient client,
248 SilcSocketConnection sock,
250 void silc_client_notify_by_server(SilcClient client,
251 SilcSocketConnection sock,
253 void silc_client_receive_new_id(SilcClient client,
254 SilcSocketConnection sock,
255 unsigned char *id_string);
256 void silc_client_new_channel_id(SilcClient client,
257 SilcSocketConnection sock,
260 unsigned char *id_string);
261 void silc_client_receive_channel_key(SilcClient client,
262 SilcSocketConnection sock,
264 void silc_client_channel_message(SilcClient client,
265 SilcSocketConnection sock,
266 SilcPacketContext *packet);