5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2001 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; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #ifndef CLIENT_INTERNAL_H
21 #define CLIENT_INTERNAL_H
23 /* Internal context for connection process. This is needed as we
24 doing asynchronous connecting. */
27 SilcClientConnection conn;
34 } SilcClientInternalConnectContext;
36 /* Structure to hold ping time information. Every PING command will
37 add entry of this structure and is removed after reply to the ping
39 struct SilcClientPingStruct {
45 /* Structure to hold away messages set by user. This is mainly created
46 for future extensions where away messages could be set according filters
47 such as nickname and hostname. For now only one away message can
48 be set in one connection. */
49 struct SilcClientAwayStruct {
51 struct SilcClientAwayStruct *next;
54 /* Internal context for the client->internal pointer in the SilcClient. */
55 struct SilcClientInternalStruct {
56 /* All client operations that are implemented by the application. */
57 SilcClientOperations *ops;
59 /* Client Parameters */
60 SilcClientParams *params;
62 /* Table of connections in client. All the connection data is saved here. */
63 SilcClientConnection *conns;
64 SilcUInt32 conns_count;
66 /* Table of listenning sockets in client. Client can have listeners
67 (like key agreement protocol server) and those sockets are saved here.
68 This table is checked always if the connection object cannot be found
69 from the `conns' table. */
70 SilcSocketConnection *sockets;
71 SilcUInt32 sockets_count;
73 /* Registered commands */
76 /* Generic cipher and hash objects. */
77 SilcCipher none_cipher;
81 /* Client version. Used to compare to remote host's version strings. */
82 char *silc_client_version;
85 /* Session resuming callback */
86 typedef void (*SilcClientResumeSessionCallback)(SilcClient client,
87 SilcClientConnection conn,
93 /* Registers generic task for file descriptor for reading from network and
94 writing to network. As being generic task the actual task is allocated
95 only once and after that the same task applies to all registered fd's. */
96 #define SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd) \
98 silc_schedule_task_add(client->schedule, (fd), \
99 silc_client_packet_process, \
102 SILC_TASK_PRI_NORMAL); \
105 #define SILC_CLIENT_SET_CONNECTION_FOR_INPUT(s, fd) \
107 silc_schedule_set_listen_fd((s), (fd), SILC_TASK_READ, FALSE); \
110 #define SILC_CLIENT_SET_CONNECTION_FOR_OUTPUT(s, fd) \
112 silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | \
113 SILC_TASK_WRITE), FALSE); \
116 /* Finds socket connection object by file descriptor */
117 #define SILC_CLIENT_GET_SOCK(__x, __fd, __sock) \
121 for (__i = 0; __i < (__x)->internal->conns_count; __i++) \
122 if ((__x)->internal->conns[__i] && \
123 (__x)->internal->conns[__i]->sock->sock == (__fd)) \
126 if (__i >= (__x)->internal->conns_count) { \
128 for (__i = 0; __i < (__x)->internal->sockets_count; __i++) \
129 if ((__x)->internal->sockets[__i] && \
130 (__x)->internal->sockets[__i]->sock == (__fd)) \
131 (__sock) = (__x)->internal->sockets[__i]; \
133 (__sock) = (__x)->internal->conns[__i]->sock; \
136 /* Check whether rekey protocol is active */
137 #define SILC_CLIENT_IS_REKEY(sock) \
138 (sock->protocol && sock->protocol->protocol && \
139 sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY)
143 SILC_TASK_CALLBACK_GLOBAL(silc_client_packet_process);
144 int silc_client_packet_send_real(SilcClient client,
145 SilcSocketConnection sock,
147 void silc_client_ftp_free_sessions(SilcClient client,
148 SilcClientConnection conn);
149 void silc_client_ftp_session_free(SilcClientFtpSession session);
150 void silc_client_ftp_session_free_client(SilcClientConnection conn,
151 SilcClientEntry client_entry);
152 void silc_client_packet_send(SilcClient client,
153 SilcSocketConnection sock,
156 SilcIdType dst_id_type,
162 void silc_client_close_connection_real(SilcClient client,
163 SilcSocketConnection sock,
164 SilcClientConnection conn);
165 void silc_client_disconnected_by_server(SilcClient client,
166 SilcSocketConnection sock,
168 void silc_client_error_by_server(SilcClient client,
169 SilcSocketConnection sock,
171 void silc_client_receive_new_id(SilcClient client,
172 SilcSocketConnection sock,
174 void silc_client_save_channel_key(SilcClient client,
175 SilcClientConnection conn,
176 SilcBuffer key_payload,
177 SilcChannelEntry channel);
178 void silc_client_receive_channel_key(SilcClient client,
179 SilcSocketConnection sock,
181 void silc_client_channel_message(SilcClient client,
182 SilcSocketConnection sock,
183 SilcPacketContext *packet);
184 void silc_client_remove_from_channels(SilcClient client,
185 SilcClientConnection conn,
186 SilcClientEntry client_entry);
187 void silc_client_replace_from_channels(SilcClient client,
188 SilcClientConnection conn,
190 SilcClientEntry newclient);
191 void silc_client_process_failure(SilcClient client,
192 SilcSocketConnection sock,
193 SilcPacketContext *packet);
194 void silc_client_key_agreement(SilcClient client,
195 SilcSocketConnection sock,
196 SilcPacketContext *packet);
197 void silc_client_notify_by_server(SilcClient client,
198 SilcSocketConnection sock,
199 SilcPacketContext *packet);
200 void silc_client_private_message(SilcClient client,
201 SilcSocketConnection sock,
202 SilcPacketContext *packet);
203 void silc_client_connection_auth_request(SilcClient client,
204 SilcSocketConnection sock,
205 SilcPacketContext *packet);
206 void silc_client_ftp(SilcClient client,
207 SilcSocketConnection sock,
208 SilcPacketContext *packet);
209 SilcBuffer silc_client_get_detach_data(SilcClient client,
210 SilcClientConnection conn);
211 bool silc_client_process_detach_data(SilcClient client,
212 SilcClientConnection conn,
213 unsigned char **old_id,
214 SilcUInt16 *old_id_len);
215 void silc_client_resume_session(SilcClient client,
216 SilcClientConnection conn,
217 SilcClientResumeSessionCallback callback,
219 SilcBuffer silc_client_attributes_process(SilcClient client,
220 SilcSocketConnection sock,