5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2006 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
24 #include "command_reply.h"
25 #include "client_connect.h"
26 #include "client_register.h"
27 #include "client_entry.h"
28 #include "client_prvmsg.h"
29 #include "client_channel.h"
30 #include "client_notify.h"
31 #include "client_keyagr.h"
33 /****************************** Definitions *********************************/
35 /* Packet retry counter and timer defines, for exponential backoff algorithm.
36 Meaningful with UDP transport when packets may get lost. */
37 #define SILC_CLIENT_RETRY_COUNT 4 /* Max packet retry count */
38 #define SILC_CLIENT_RETRY_MUL 2 /* Retry timer interval growth */
39 #define SILC_CLIENT_RETRY_RAND 2 /* Randomizer, timeout += rnd % 2 */
40 #define SILC_CLIENT_RETRY_MIN 1 /* Min retry timeout, seconds */
41 #define SLIC_CLIENT_RETRY_MAX 16 /* Max retry timeout, seconds */
43 /********************************** Types ***********************************/
45 /* Public key verification context */
48 SilcSKEVerifyCbCompletion completion;
49 void *completion_context;
52 /* Context to hold the connection authentication request callbacks that
53 will be called when the server has replied back to our request about
54 current authentication method in the session. */
56 SilcConnectionAuthRequest callback;
59 } *SilcClientConnAuthRequest;
61 /* Generic rekey context for connections */
63 /* Current sending encryption key, provided for re-key. The `pfs'
64 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
65 unsigned char *send_enc_key;
66 SilcUInt32 enc_key_len;
73 /* Internal context for connection process. This is needed as we
74 doing asynchronous connecting. */
77 SilcClientConnection conn;
83 } SilcClientInternalConnectContext;
85 /* Structure to hold away messages set by user. This is mainly created
86 for future extensions where away messages could be set according filters
87 such as nickname and hostname. For now only one away message can
88 be set in one connection. */
89 struct SilcClientAwayStruct {
91 struct SilcClientAwayStruct *next;
94 /* Command and command reply context used to hold registered commands
95 in the SILC client. */
96 typedef struct SilcClientCommandStruct {
97 struct SilcClientCommandStruct *next;
98 SilcCommand cmd; /* Command type */
99 SilcFSMStateCallback command; /* Command function */
100 SilcFSMStateCallback reply; /* Command reply callback */
101 char *name; /* Name of the command (optional) */
102 SilcUInt8 max_args; /* Maximum arguments (optional) */
103 } *SilcClientCommand;
105 /* Command reply callback structure */
106 typedef struct SilcClientCommandReplyCallbackStruct {
107 struct SilcClientCommandReplyCallbackStruct *next;
108 SilcClientCommandReply reply; /* Command reply callback */
109 void *context; /* Command reply context */
110 unsigned int do_not_call : 1; /* Set to not call the callback */
111 } *SilcClientCommandReplyCallback;
113 /* Command context given as argument to command state functions. This same
114 context is used when calling, sending and procesing command and command
116 typedef struct SilcClientCommandContextStruct {
117 struct SilcClientCommandContextStruct *next;
118 SilcClientConnection conn; /* Connection */
119 SilcFSMThreadStruct thread; /* FSM thread for command call */
121 SilcCommand cmd; /* Command */
122 SilcUInt16 cmd_ident; /* Command identifier */
123 SilcUInt32 argc; /* Number of arguments */
124 unsigned char **argv; /* Arguments, may be NULL */
125 SilcUInt32 *argv_lens; /* Argument lengths, may be NULL */
126 SilcUInt32 *argv_types; /* Argument types, may be NULL */
128 SilcList reply_callbacks; /* Command reply callbacks */
129 SilcStatus status; /* Current command reply status */
130 SilcStatus error; /* Current command reply error */
132 void *context; /* Context for free use */
133 unsigned int called : 1; /* Set when called by application */
134 unsigned int verbose : 1; /* Verbose with 'say' client operation */
135 unsigned int resolved : 1; /* Set when resolving something */
136 } *SilcClientCommandContext;
138 /* Internal context for the client->internal pointer in the SilcClient. */
139 struct SilcClientInternalStruct {
140 SilcFSMStruct fsm; /* Client's FSM */
141 SilcFSMSemaStruct wait_event; /* Event signaller */
142 SilcClientOperations *ops; /* Client operations */
143 SilcClientParams *params; /* Client parameters */
144 SilcPacketEngine packet_engine; /* Packet engine */
145 SilcMutex lock; /* Client lock */
146 SilcList commands; /* Registered commands */
147 char *silc_client_version; /* Version set by application */
150 unsigned int run_callback : 1; /* Call running callback */
153 /* Internal context for conn->internal in SilcClientConnection. */
154 struct SilcClientConnectionInternalStruct {
155 SilcIDCacheEntry local_entry; /* Local client cache entry */
156 SilcClientConnectionParams params; /* Connection parameters */
158 SilcFSMStruct fsm; /* Connection FSM */
159 SilcFSMThreadStruct event_thread; /* FSM thread for events */
160 SilcFSMSemaStruct wait_event; /* Event signaller */
161 SilcSchedule schedule; /* Connection's scheduler */
162 SilcMutex lock; /* Connection lock */
163 SilcSKE ske; /* Key exchange protocol */
164 SilcSKERekeyMaterial rekey; /* Rekey material */
165 SilcList thread_pool; /* Packet thread pool */
166 SilcList pending_commands; /* Pending commands list */
167 SilcHash hash; /* Negotiated hash function */
168 SilcHash sha1hash; /* SHA-1 default hash context */
169 SilcBuffer local_idp; /* Local ID Payload */
170 SilcBuffer remote_idp; /* Remote ID Payload */
171 SilcAsyncOperation op; /* Protocols async operation */
173 SilcIDCache client_cache; /* Client entry cache */
174 SilcIDCache channel_cache; /* Channel entry cache */
175 SilcIDCache server_cache; /* Server entry cache */
177 SilcAtomic16 cmd_ident; /* Current command identifier */
178 SilcUInt8 retry_count; /* Packet retry counter */
179 SilcUInt8 retry_timer; /* Packet retry timer */
182 unsigned int connect : 1; /* Connect remote host */
183 unsigned int disconnected : 1; /* Disconnected by remote host */
184 unsigned int key_exchange : 1; /* Start key exchange */
187 unsigned int verbose : 1; /* Notify application */
188 unsigned int registering : 1; /* Set when registering to network */
190 SilcClientAway *away;
191 SilcClientConnAuthRequest connauth;
192 SilcDList ftp_sessions;
193 SilcUInt32 next_session_id;
194 SilcClientFtpSession active_session;
196 SilcHashTable privmsg_wait; /* Waited private messages */
199 SILC_FSM_STATE(silc_client_connection_st_run);
200 SILC_FSM_STATE(silc_client_connection_st_packet);
201 SILC_FSM_STATE(silc_client_connection_st_close);
202 SILC_FSM_STATE(silc_client_error);
203 SILC_FSM_STATE(silc_client_disconnect);
205 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
206 SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn,
207 SilcClientEntry client_entry);
208 SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
209 SilcChannelEntry channel);
210 SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
211 SilcServerEntry server);
212 SilcUInt16 silc_client_command_send_argv(SilcClient client,
213 SilcClientConnection conn,
215 SilcClientCommandReply reply,
218 unsigned char **argv,
219 SilcUInt32 *argv_lens,
220 SilcUInt32 *argv_types);
221 void silc_client_command_free(SilcClientCommandContext cmd);
223 void silc_client_ftp(SilcClient client, SilcClientConnection conn,
225 void silc_client_connection_auth_request(SilcClient client,
226 SilcClientConnection conn,