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 /* Context to hold the connection authentication request callbacks that
33 will be called when the server has replied back to our request about
34 current authentication method in the session. */
36 SilcConnectionAuthRequest callback;
39 } *SilcClientConnAuthRequest;
41 /* Generic rekey context for connections */
43 /* Current sending encryption key, provided for re-key. The `pfs'
44 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
45 unsigned char *send_enc_key;
46 SilcUInt32 enc_key_len;
53 /* Internal context for connection process. This is needed as we
54 doing asynchronous connecting. */
57 SilcClientConnection conn;
63 } SilcClientInternalConnectContext;
65 /* Structure to hold away messages set by user. This is mainly created
66 for future extensions where away messages could be set according filters
67 such as nickname and hostname. For now only one away message can
68 be set in one connection. */
69 struct SilcClientAwayStruct {
71 struct SilcClientAwayStruct *next;
74 /* Command and command reply context used to hold registered commands
75 in the SILC client. */
76 typedef struct SilcClientCommandStruct {
77 struct SilcClientCommandStruct *next;
78 SilcCommand cmd; /* Command type */
79 SilcFSMStateCallback command; /* Command function */
80 SilcFSMStateCallback reply; /* Command reply callback */
81 char *name; /* Name of the command (optional) */
82 SilcUInt8 max_args; /* Maximum arguments (optional) */
85 /* Command reply callback structure */
86 typedef struct SilcClientCommandReplyCallbackStruct {
87 struct SilcClientCommandReplyCallbackStruct *next;
88 SilcClientCommandReply reply; /* Command reply callback */
89 void *context; /* Command reply context */
90 unsigned int do_not_call : 1; /* Set to not call the callback */
91 } *SilcClientCommandReplyCallback;
93 /* Command context given as argument to command state functions. This same
94 context is used when calling, sending and procesing command and command
96 typedef struct SilcClientCommandContextStruct {
97 struct SilcClientCommandContextStruct *next;
98 SilcClientConnection conn; /* Connection */
99 SilcFSMThreadStruct thread; /* FSM thread for command call */
101 SilcCommand cmd; /* Command */
102 SilcUInt16 cmd_ident; /* Command identifier */
103 SilcUInt32 argc; /* Number of arguments */
104 unsigned char **argv; /* Arguments, may be NULL */
105 SilcUInt32 *argv_lens; /* Argument lengths, may be NULL */
106 SilcUInt32 *argv_types; /* Argument types, may be NULL */
108 SilcList reply_callbacks; /* Command reply callbacks */
109 SilcStatus status; /* Current command reply status */
110 SilcStatus error; /* Current command reply error */
112 void *context; /* Context for free use */
113 unsigned int called : 1; /* Set when called by application */
114 unsigned int verbose : 1; /* Verbose with 'say' client operation */
115 unsigned int resolved : 1; /* Set when resolving something */
116 } *SilcClientCommandContext;
118 /* Internal context for the client->internal pointer in the SilcClient. */
119 struct SilcClientInternalStruct {
120 SilcFSMStruct fsm; /* Client's FSM */
121 SilcFSMSemaStruct wait_event; /* Event signaller */
122 SilcClientOperations *ops; /* Client operations */
123 SilcClientParams *params; /* Client parameters */
124 SilcPacketEngine packet_engine; /* Packet engine */
125 SilcMutex lock; /* Client lock */
127 /* List of connections in client. All the connection data is saved here. */
130 /* Registered commands */
133 /* Client version. Used to compare to remote host's version strings. */
134 char *silc_client_version;
137 unsigned int run_callback : 1; /* Call running callback */
140 /* Internal context for conn->internal in SilcClientConnection. */
141 struct SilcClientConnectionInternalStruct {
142 SilcIDCacheEntry local_entry; /* Local client cache entry */
143 SilcClientConnectionParams params; /* Connection parameters */
145 SilcFSMStruct fsm; /* Connection FSM */
146 SilcFSMThreadStruct event_thread; /* FSM thread for events */
147 SilcFSMSemaStruct wait_event; /* Event signaller */
148 SilcSchedule schedule; /* Connection's scheduler */
149 SilcMutex lock; /* Connection lock */
150 SilcSKE ske; /* Key exchange protocol */
151 SilcSKERekeyMaterial rekey; /* Rekey material */
152 SilcList thread_pool; /* Packet thread pool */
153 SilcList pending_commands; /* Pending commands list */
154 SilcHash hash; /* Negotiated hash function */
155 SilcHash sha1hash; /* SHA-1 default hash context */
157 SilcIDCache client_cache; /* Client entry cache */
158 SilcIDCache channel_cache; /* Channel entry cache */
159 SilcIDCache server_cache; /* Server entry cache */
161 SilcBuffer local_idp; /* Local ID Payload */
162 SilcBuffer remote_idp; /* Remote ID Payload */
164 SilcAtomic16 cmd_ident; /* Current command identifier */
167 unsigned int connect : 1; /* Connect remote host */
168 unsigned int disconnected : 1; /* Disconnected by remote host */
169 unsigned int key_exchange : 1; /* Start key exchange */
172 unsigned int verbose : 1; /* Notify application */
173 unsigned int registering : 1; /* Set when registering to network */
175 SilcClientAway *away;
176 SilcClientConnAuthRequest connauth;
177 SilcDList ftp_sessions;
178 SilcUInt32 next_session_id;
179 SilcClientFtpSession active_session;
181 SilcHashTable privmsg_wait; /* Waited private messages */
184 SILC_FSM_STATE(silc_client_connection_st_run);
185 SILC_FSM_STATE(silc_client_connection_st_packet);
186 SILC_FSM_STATE(silc_client_connection_st_close);
187 SILC_FSM_STATE(silc_client_error);
188 SILC_FSM_STATE(silc_client_disconnect);
190 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
191 SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn,
192 SilcClientEntry client_entry);
193 SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
194 SilcChannelEntry channel);
195 SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
196 SilcServerEntry server);
197 SilcUInt16 silc_client_command_send_argv(SilcClient client,
198 SilcClientConnection conn,
200 SilcClientCommandReply reply,
203 unsigned char **argv,
204 SilcUInt32 *argv_lens,
205 SilcUInt32 *argv_types);
207 void silc_client_ftp(SilcClient client, SilcClientConnection conn,
209 void silc_client_key_agreement(SilcClient client,
210 SilcClientConnection conn,
212 void silc_client_connection_auth_request(SilcClient client,
213 SilcClientConnection conn,