updates.
[silc.git] / lib / silcclient / client.h
1 /*
2
3   client.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2001 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 #ifndef CLIENT_H
21 #define CLIENT_H
22
23 /* Forward declarations */
24 typedef struct SilcClientStruct *SilcClient;
25 typedef struct SilcClientInternalStruct *SilcClientInternal;
26 typedef struct SilcClientConnectionStruct *SilcClientConnection;
27 typedef struct SilcClientPingStruct SilcClientPing;
28 typedef struct SilcClientAwayStruct SilcClientAway;
29 typedef struct SilcClientKeyAgreementStruct *SilcClientKeyAgreement;
30 typedef struct SilcClientFtpSessionStruct *SilcClientFtpSession;
31
32 #include "idlist.h"
33 #include "command.h"
34 #include "silcapi.h"
35
36 /* Generic rekey context for connections */
37 typedef struct {
38   /* Current sending encryption key, provided for re-key. The `pfs'
39      is TRUE if the Perfect Forward Secrecy is performed in re-key. */
40   unsigned char *send_enc_key;
41   uint32 enc_key_len;
42   int ske_group;
43   bool pfs;
44   uint32 timeout;
45   void *context;
46 } *SilcClientRekey;
47
48 /* Context to hold the connection authentication request callbacks that
49    will be called when the server has replied back to our request about
50    current authentication method in the session. */
51 typedef struct {
52   SilcConnectionAuthRequest callback;
53   void *context;
54   SilcTask timeout;
55 } *SilcClientConnAuthRequest;
56
57 /* Connection structure used in client to associate all the important
58    connection specific data to this structure. */
59 struct SilcClientConnectionStruct {
60   /*
61    * Local data 
62    */
63   char *nickname;
64
65   /* Local client ID for this connection */
66   SilcClientID *local_id;
67
68   /* Decoded local ID so that the above defined ID would not have
69      to be decoded for every packet. */
70   unsigned char *local_id_data;
71   uint32 local_id_data_len;
72
73   /* Own client entry. */
74   SilcClientEntry local_entry;
75
76   /*
77    * Remote data 
78    */
79   char *remote_host;
80   int remote_port;
81   int remote_type;
82   char *remote_info;
83
84   /* Remote server ID for this connection */
85   SilcServerID *remote_id;
86
87   /* Decoded remote ID so that the above defined ID would not have
88      to be decoded for every packet. */
89   unsigned char *remote_id_data;
90   uint32 remote_id_data_len;
91
92   /*
93    * Common data 
94    */
95   /* Keys and stuff negotiated in the SKE protocol */
96   SilcCipher send_key;
97   SilcCipher receive_key;
98   SilcHmac hmac_send;
99   SilcHmac hmac_receive;
100   SilcHash hash;
101   uint32 psn_send;
102   uint32 psn_receive;
103
104   /* Client ID and Channel ID cache. Messages transmitted in SILC network
105      are done using different unique ID's. These are the cache for
106      thoses ID's used in the communication. */
107   SilcIDCache client_cache;
108   SilcIDCache channel_cache;
109   SilcIDCache server_cache;
110
111   /* Current channel on window. All channels are saved (allocated) into
112      the cache entries. */
113   SilcChannelEntry current_channel;
114
115   /* Socket connection object for this connection (window). This
116      object will have a back-pointer to this window object for fast
117      referencing (sock->user_data). */
118   SilcSocketConnection sock;
119
120   /* Pending command queue for this connection */
121   SilcDList pending_commands;
122
123   /* Current command identifier, 0 not used */
124   uint16 cmd_ident;
125
126   /* Requested pings. */
127   SilcClientPing *ping;
128   uint32 ping_count;
129
130   /* Set away message */
131   SilcClientAway *away;
132
133   /* Re-key context */
134   SilcClientRekey rekey;
135
136   /* Authentication request context. */
137   SilcClientConnAuthRequest connauth;
138
139   /* File transmission sessions */
140   SilcDList ftp_sessions;
141   uint32 next_session_id;
142   SilcClientFtpSession active_session;
143
144   /* Pointer back to the SilcClient. This object is passed to the application
145      and the actual client object is accesible through this pointer. */
146   SilcClient client;
147
148   /* User data context. Library does not touch this. */
149   void *context;
150 };
151
152 /* Main client structure. */
153 struct SilcClientStruct {
154   char *username;               /* Username, must be set by application */
155   char *hostname;               /* hostname, must be set by application */
156   char *realname;               /* Real name, must be set be application */
157
158   SilcPublicKey public_key;     /* Public key of user, set by application */
159   SilcPrivateKey private_key;   /* Private key of user, set by application */
160   SilcPKCS pkcs;                /* PKCS allocated by application */
161
162   SilcSchedule schedule;        /* Scheduler, automatically allocated by
163                                    the client library. */
164
165   /* Random Number Generator. Application should use this as its primary
166      random number generator. */
167   SilcRng rng;
168
169   /* Application specific user data pointer. Client library does not
170      touch this. This the context sent as argument to silc_client_alloc. */
171   void *application;
172
173   /* Internal data for client library. Application cannot access this
174      data at all. */
175   SilcClientInternal internal;
176 };
177
178 #endif