5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2007 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"
32 #include "client_ftp.h"
33 #include "client_listener.h"
35 /****************************** Definitions *********************************/
37 /* Packet retry counter and timer defines, for exponential backoff algorithm.
38 Meaningful with UDP transport when packets may get lost. */
39 #define SILC_CLIENT_RETRY_COUNT 4 /* Max packet retry count */
40 #define SILC_CLIENT_RETRY_MUL 2 /* Retry timer interval growth */
41 #define SILC_CLIENT_RETRY_RAND 2 /* Randomizer, timeout += rnd % 2 */
42 #define SILC_CLIENT_RETRY_MIN 1 /* Min retry timeout, seconds */
43 #define SLIC_CLIENT_RETRY_MAX 16 /* Max retry timeout, seconds */
45 /********************************** Types ***********************************/
47 /* Public key verification context */
50 SilcSKEVerifyCbCompletion completion;
51 void *completion_context;
52 } *SilcVerifyKeyContext;
54 /* Command and command reply context used to hold registered commands
55 in the SILC client. */
56 typedef struct SilcClientCommandStruct {
57 struct SilcClientCommandStruct *next;
58 SilcCommand cmd; /* Command type */
59 SilcFSMStateCallback command; /* Command function */
60 SilcFSMStateCallback reply; /* Command reply callback */
61 char *name; /* Name of the command (optional) */
62 SilcUInt8 max_args; /* Maximum arguments (optional) */
65 /* Command reply callback structure */
66 typedef struct SilcClientCommandReplyCallbackStruct {
67 struct SilcClientCommandReplyCallbackStruct *next;
68 SilcClientCommandReply reply; /* Command reply callback */
69 void *context; /* Command reply context */
70 unsigned int do_not_call : 1; /* Set to not call the callback */
71 } *SilcClientCommandReplyCallback;
73 /* Command context given as argument to command state functions. This same
74 context is used when calling, sending and procesing command and command
76 typedef struct SilcClientCommandContextStruct {
77 struct SilcClientCommandContextStruct *next;
78 SilcClientConnection conn; /* Connection */
79 SilcFSMThreadStruct thread; /* FSM thread for command call */
81 SilcCommand cmd; /* Command */
82 SilcUInt16 cmd_ident; /* Command identifier */
83 SilcUInt32 argc; /* Number of arguments */
84 unsigned char **argv; /* Arguments, may be NULL */
85 SilcUInt32 *argv_lens; /* Argument lengths, may be NULL */
86 SilcUInt32 *argv_types; /* Argument types, may be NULL */
88 SilcList reply_callbacks; /* Command reply callbacks */
89 SilcStatus status; /* Current command reply status */
90 SilcStatus error; /* Current command reply error */
92 void *context; /* Context for free use */
93 unsigned int called : 1; /* Set when called by application */
94 unsigned int verbose : 1; /* Verbose with 'say' client operation */
95 unsigned int resolved : 1; /* Set when resolving something */
96 } *SilcClientCommandContext;
98 /* Internal context for the client->internal pointer in the SilcClient. */
99 struct SilcClientInternalStruct {
100 SilcFSMStruct fsm; /* Client's FSM */
101 SilcFSMEventStruct wait_event; /* Event signaller */
102 SilcClientOperations *ops; /* Client operations */
103 SilcClientParams *params; /* Client parameters */
104 SilcPacketEngine packet_engine; /* Packet engine */
105 SilcMutex lock; /* Client lock */
106 SilcList commands; /* Registered commands */
107 SilcDList ftp_sessions; /* FTP sessions */
108 char *silc_client_version; /* Version set by application */
109 SilcClientRunning running; /* Running/Stopped callback */
110 void *running_context; /* Context for runnign callback */
111 SilcAtomic16 conns; /* Number of connections in client */
112 SilcUInt16 next_session_id; /* Next FTP session ID */
115 unsigned int stop : 1; /* Stop client */
116 unsigned int run_callback : 1; /* Call running/stopped callback */
117 unsigned int connection_closed : 1; /* A connection closed */
120 /* Internal context for conn->internal in SilcClientConnection. */
121 struct SilcClientConnectionInternalStruct {
122 SilcClientConnectionParams params; /* Connection parameters */
123 SilcFSMStruct fsm; /* Connection FSM */
124 SilcFSMThreadStruct event_thread; /* FSM thread for events */
125 SilcFSMEventStruct wait_event; /* Event signaller */
126 SilcSchedule schedule; /* Connection's scheduler */
127 SilcMutex lock; /* Connection lock */
128 SilcSKE ske; /* Key exchange protocol */
129 SilcSKERekeyMaterial rekey; /* Rekey material */
130 SilcList thread_pool; /* Packet thread pool */
131 SilcList pending_commands; /* Pending commands list */
132 SilcHash hash; /* Negotiated hash function */
133 SilcHash sha1hash; /* SHA-1 default hash context */
134 SilcBuffer local_idp; /* Local ID Payload */
135 SilcBuffer remote_idp; /* Remote ID Payload */
136 SilcAsyncOperation op; /* Protocols async operation */
137 SilcAsyncOperation cop; /* Async operation for application */
138 SilcHashTable attrs; /* Configured user attributes */
139 SilcStream user_stream; /* Low level stream in connecting */
140 char *disconnect_message; /* Disconnection message */
141 char *away_message; /* Away message */
142 void *prv_waiter; /* Private message packet waiter */
144 SilcIDCache client_cache; /* Client entry cache */
145 SilcIDCache channel_cache; /* Channel entry cache */
146 SilcIDCache server_cache; /* Server entry cache */
148 SilcUInt32 remote_version; /* Remote SILC protocol version */
149 SilcAtomic16 cmd_ident; /* Current command identifier */
150 SilcUInt8 retry_count; /* Packet retry counter */
151 SilcUInt8 retry_timer; /* Packet retry timer */
152 SilcClientConnectionStatus status; /* Connection callback status */
153 SilcStatus error; /* Connection callback error */
156 unsigned int connect : 1; /* Connect remote host */
157 unsigned int disconnected : 1; /* Disconnect remote connection */
158 unsigned int key_exchange : 1; /* Start key exchange */
159 unsigned int rekeying : 1; /* Start rekey */
162 unsigned int verbose : 1; /* Notify application */
163 unsigned int registering : 1; /* Set when registering to network */
164 unsigned int rekey_responder : 1; /* Set when rekeying as responder */
165 unsigned int auth_request : 1; /* Set when requesting auth method */
168 SILC_FSM_STATE(silc_client_connection_st_run);
169 SILC_FSM_STATE(silc_client_connection_st_packet);
170 SILC_FSM_STATE(silc_client_connection_st_close);
171 SILC_FSM_STATE(silc_client_error);
172 SILC_FSM_STATE(silc_client_disconnect);
173 SILC_FSM_STATE(silc_client_st_stop);
175 void silc_client_del_connection(SilcClient client, SilcClientConnection conn);
176 void silc_client_fsm_destructor(SilcFSM fsm, void *fsm_context,
177 void *destructor_context);
178 void silc_client_command_free(SilcClientCommandContext cmd);
180 silc_client_add_connection(SilcClient client,
181 SilcConnectionType conn_type,
183 SilcClientConnectionParams *params,
184 SilcPublicKey public_key,
185 SilcPrivateKey private_key,
186 char *remote_host, int port,
187 SilcClientConnectCallback callback,
189 SilcBuffer silc_client_attributes_process(SilcClient client,
190 SilcClientConnection conn,
193 #endif /* CLIENT_INTERNAL_H */