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 /* Generic cipher and hash objects. */
137 /* Client version. Used to compare to remote host's version strings. */
138 char *silc_client_version;
141 unsigned int run_callback : 1; /* Call running callback */
144 /* Internal context for conn->internal in SilcClientConnection. */
145 struct SilcClientConnectionInternalStruct {
146 /* Client ID and Channel ID cache. Messages transmitted in SILC network
147 are done using different unique ID's. These are the cache for
148 thoses ID's used in the communication. */
149 SilcIDCache client_cache;
150 SilcIDCache channel_cache;
151 SilcIDCache server_cache;
153 /* Pending command queue for this connection */
154 SilcList pending_commands;
156 /* Set away message */
157 SilcClientAway *away;
159 /* Authentication request context. */
160 SilcClientConnAuthRequest connauth;
162 /* File transmission sessions */
163 SilcDList ftp_sessions;
164 SilcUInt32 next_session_id;
165 SilcClientFtpSession active_session;
167 /* Requested Attributes */
170 SilcFSMStruct fsm; /* Connection FSM */
171 SilcFSMThreadStruct event_thread; /* FSM thread for events */
172 SilcFSMSemaStruct wait_event; /* Event signaller */
173 SilcMutex lock; /* Connection lock */
174 SilcSchedule schedule; /* Connection's scheduler */
175 SilcSKE ske; /* Key exchange protocol */
176 SilcSKERekeyMaterial rekey; /* Rekey material */
177 SilcHash hash; /* Negotiated hash function */
178 SilcClientConnectionParams params; /* Connection parameters */
179 SilcAtomic16 cmd_ident; /* Current command identifier */
180 SilcIDCacheEntry local_entry; /* Local client cache entry */
181 SilcList thread_pool; /* Packet thread pool */
183 SilcHashTable privmsg_wait; /* Waited private messages */
186 unsigned int connect : 1; /* Connect remote host */
187 unsigned int disconnected : 1; /* Disconnected by remote host */
188 unsigned int key_exchange : 1; /* Start key exchange */
191 unsigned int verbose : 1; /* Notify application */
192 unsigned int registering : 1; /* Set when registering to network */
195 SILC_FSM_STATE(silc_client_connection_st_run);
196 SILC_FSM_STATE(silc_client_connection_st_packet);
197 SILC_FSM_STATE(silc_client_connection_st_close);
198 SILC_FSM_STATE(silc_client_error);
199 SILC_FSM_STATE(silc_client_disconnect);
201 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
202 SilcBool silc_client_del_client(SilcClient client, SilcClientConnection conn,
203 SilcClientEntry client_entry);
204 SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
205 SilcChannelEntry channel);
206 SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
207 SilcServerEntry server);
208 SilcUInt16 silc_client_command_send_argv(SilcClient client,
209 SilcClientConnection conn,
211 SilcClientCommandReply reply,
214 unsigned char **argv,
215 SilcUInt32 *argv_lens,
216 SilcUInt32 *argv_types);
218 void silc_client_ftp(SilcClient client, SilcClientConnection conn,
220 void silc_client_key_agreement(SilcClient client,
221 SilcClientConnection conn,
223 void silc_client_connection_auth_request(SilcClient client,
224 SilcClientConnection conn,