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 /* Window structure used in client to associate all the important
25 connection (window) specific data to this structure. How the window
26 actually appears on the screen in handeled by the silc_screen*
27 routines in screen.c. */
34 /* Local client ID for this connection */
35 SilcClientID *local_id;
37 /* Decoded local ID so that the above defined ID would not have
38 to be decoded for every packet. */
39 unsigned char *local_id_data;
40 unsigned int local_id_data_len;
42 /* Own client entry. */
43 SilcClientEntry local_entry;
52 /* Remote client ID for this connection */
53 SilcClientID *remote_id;
55 /* Remote local ID so that the above defined ID would not have
56 to be decoded for every packet. */
57 unsigned char *remote_id_data;
58 unsigned int remote_id_data_len;
65 SilcCipher receive_key;
68 unsigned char *hmac_key;
69 unsigned int hmac_key_len;
71 /* Client ID and Channel ID cache. Messages transmitted in SILC network
72 are done using different unique ID's. These are the cache for
73 thoses ID's used in the communication. */
74 SilcIDCache *client_id_cache[96];
75 unsigned int client_id_cache_count[96];
76 SilcIDCache *channel_id_cache[96];
77 unsigned int channel_id_cache_count[96];
78 SilcIDCache *server_id_cache;
79 unsigned int server_id_cache_count;
81 /* Current channel on window. All channel's are saved (allocated) into
83 SilcChannelEntry current_channel;
85 /* Socket connection object for this connection (window). This
86 object will have a back-pointer to this window object for fast
87 referencing (sock->user_data). */
88 SilcSocketConnection sock;
90 /* The actual physical screen. This data is handled by the
91 screen handling routines. */
99 /* SILC client task queues */
100 SilcTaskQueue io_queue;
101 SilcTaskQueue timeout_queue;
102 SilcTaskQueue generic_queue;
104 /* Input buffer that holds the characters user types. This is
105 used only to store the typed chars for a while. */
106 SilcBuffer input_buffer;
108 /* Table of windows in client. All the data, including connection
109 specific data, is saved in here. */
110 SilcClientWindow *windows;
111 unsigned int windows_count;
113 /* Currently active window. This is pointer to the window table
114 defined above. This must never be free'd directly. */
115 SilcClientWindow current_win;
117 /* The SILC client screen object */
120 /* Generic cipher and hash objects */
121 SilcCipher none_cipher;
127 /* Configuration object */
128 SilcClientConfig config;
130 /* Random Number Generator */
134 /* SIM (SILC Module) table */
135 SilcSimContext **sim;
136 unsigned int sim_count;
140 typedef SilcClientObject *SilcClient;
145 #define CTRL(x) ((x) & 0x1f) /* Ctrl+x */
148 /* Registers generic task for file descriptor for reading from network and
149 writing to network. As being generic task the actual task is allocated
150 only once and after that the same task applies to all registered fd's. */
151 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
153 SilcTask tmptask = silc_task_register(client->generic_queue, (fd), \
154 silc_client_packet_process, \
157 SILC_TASK_PRI_NORMAL); \
158 silc_task_set_iotype(tmptask, SILC_TASK_WRITE); \
161 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(fd) \
163 silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ)); \
166 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(fd) \
168 silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) | \
169 (1L << SILC_TASK_WRITE))); \
172 /* Finds socket connection object by file descriptor */
173 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
177 for (__i = 0; __i < (__x)->windows_count; __i++) \
178 if ((__x)->windows[__i]->sock->sock == (__fd)) \
181 if (__i >= (__x)->windows_count) \
183 (__sock) = (__x)->windows[__i]->sock; \
186 /* Returns TRUE if windows is currently active window */
187 #define SILC_CLIENT_IS_CURRENT_WIN(__x, __win) ((__x)->current_win == (__win))
190 int silc_client_alloc(SilcClient *new_client);
191 void silc_client_free(SilcClient client);
192 int silc_client_init(SilcClient client);
193 void silc_client_stop(SilcClient client);
194 void silc_client_run(SilcClient client);
195 void silc_client_parse_command_line(unsigned char *buffer,
196 unsigned char ***parsed,
197 unsigned int **parsed_lens,
198 unsigned int **parsed_types,
199 unsigned int *parsed_num,
200 unsigned int max_args);
201 int silc_client_connect_to_server(SilcClient client, int port,
203 void silc_client_packet_send(SilcClient client,
204 SilcSocketConnection sock,
207 SilcIdType dst_id_type,
211 unsigned int data_len,
213 void silc_client_packet_send_to_channel(SilcClient client,
214 SilcSocketConnection sock,
215 SilcChannelEntry channel,
217 unsigned int data_len,
219 void silc_client_packet_send_private_message(SilcClient client,
220 SilcSocketConnection sock,
221 SilcClientEntry client_entry,
223 unsigned int data_len,
225 void silc_client_close_connection(SilcClient client,
226 SilcSocketConnection sock);
227 void silc_client_disconnected_by_server(SilcClient client,
228 SilcSocketConnection sock,
230 void silc_client_error_by_server(SilcClient client,
231 SilcSocketConnection sock,
233 void silc_client_notify_by_server(SilcClient client,
234 SilcSocketConnection sock,
236 void silc_client_receive_new_id(SilcClient client,
237 SilcSocketConnection sock,
238 unsigned char *id_string);
239 void silc_client_new_channel_id(SilcClient client,
240 SilcSocketConnection sock,
242 unsigned char *id_string);
243 void silc_client_receive_channel_key(SilcClient client,
244 SilcSocketConnection sock,
246 void silc_client_channel_message(SilcClient client,
247 SilcSocketConnection sock,
248 SilcPacketContext *packet);