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