1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
/* This file is part of the KDE libraries
Copyright (C) 1999 Torben Weis <weis@kde.org>
Copyright (C) 2000- Waldo Bastain <bastain@kde.org>
Copyright (C) 2000- Dawit Alemayehu <adawit@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __kprotocolmanager_h__
#define __kprotocolmanager_h__
#include <tqstringlist.h>
#include <tdeapplication.h>
#include <tdeio/global.h>
/** @deprecated Use KProtocolManager::defaultUserAgent() instead. */
#define DEFAULT_USERAGENT_STRING ""
class TDEConfig;
/**
* Provides information about I/O (Internet, etc.) settings chosen/set
* by the end user.
*
* KProtocolManager has a heap of static functions that allows only read
* access to KDE's IO related settings. These include proxy, cache, file
* transfer resumption, timeout and user-agent related settings.
*
* The information provided by this class is generic enough to be applicable
* to any application that makes use of KDE's IO sub-system. Note that this
* mean the proxy, timeout etc. settings are saved in a separate user-specific
* config file and not in the config file of the application.
*
* Original author:
* @author Torben Weis <weis@kde.org>
*
* Revised by:
* @author Waldo Bastain <bastain@kde.org>
* @author Dawit Alemayehu <adawit@kde.org>
* @see KPAC
*/
class TDEIO_EXPORT KProtocolManager
{
public:
/*=========================== USER-AGENT SETTINGS ===========================*/
/**
* Returns the default user-agent string.
*
* @return the default user-agent string
*/
static TQString defaultUserAgent();
/**
* Returns the default user-agent value.
*
* @param keys can be any of the following:
* @li 'o' Show OS
* @li 'v' Show OS Version
* @li 'p' Show platform
* @li 'm' Show machine architecture
* @li 'l' Show language
* @return the default user-agent value with the given @p keys
*/
static TQString defaultUserAgent(const TQString &keys);
/**
* Returns the userAgent string configured for the
* specified host.
*
* If hostname is not found or is empty (i.e. "" or
* TQString::null) this function will return the default
* user agent.
*
* @param hostname name of the host
* @return specified userAgent string
*/
static TQString userAgentForHost( const TQString &hostname );
/*=========================== TIMEOUT CONFIG ================================*/
/**
* Returns the preferred timeout value for reading from
* remote connections in seconds.
*
* @return timeout value for remote connection in secs.
*/
static int readTimeout();
/**
* Returns the preferred timeout value for remote connections
* in seconds.
*
* @return timeout value for remote connection in secs.
*/
static int connectTimeout();
/**
* Returns the preferred timeout value for proxy connections
* in seconds.
*
* @return timeout value for proxy connection in secs.
*/
static int proxyConnectTimeout();
/**
* Returns the preferred response timeout value for
* remote connecting in seconds.
*
* @return timeout value for remote connection in seconds.
*/
static int responseTimeout();
/*=============================== PROXY CONFIG ==============================*/
/**
* Returns true if the user specified a proxy server to make connections.
*
* @see slaveProtocol, proxyForURL, proxyFor
*/
static bool useProxy();
/**
* Returns true if the proxy settings should apply to the list
* returned by @ref noProxyFor.
*
* Normally addresses listed in the noProxyFor list are not routed
* through a proxy server. However, if this function returns true,
* then all addresses listed in the noProxyFor list are to be routed
* through a proxy server where as those that are not should bypass it.
*
* This function as well as @ref noProxyFor only apply when @ref proxyType
* is @p ManualProxy.
*
* @see proxyForURL, proxyFor, slaveProtocol
*/
static bool useReverseProxy();
/**
* Types of proxy configuration
* @li NoProxy - No proxy is used
* @li ManualProxy - Proxies are manually configured
* @li PACProxy - A Proxy configuration URL has been given
* @li WPADProxy - A proxy should be automatically discovered
* @li EnvVarProxy - Use the proxy values set through environment variables.
*/
enum ProxyType
{
NoProxy,
ManualProxy,
PACProxy,
WPADProxy,
EnvVarProxy
};
/**
* Returns the type of proxy configuration that is used.
*
* @see ProxyType
*/
static ProxyType proxyType();
/**
* Proxy authorization modes.
*
* @li Prompt - Ask for authorization as needed
* @li Automatic - Use auto login as defined in .kionetrc files.
*
* NOTE: .kionetrc files have the same format as ftp .netrc files.
* Please note the use of .kionetrc files is highly discouraged since
* password is stored in clear text. For future releases the ability
* to store preset password for proxy servers will probably be supported
* through KWallet integration.
*/
enum ProxyAuthMode
{
Prompt,
Automatic
};
/**
* Returns the way proxy authorization should be handled.
*
* @see ProxyAuthMode
*/
static ProxyAuthMode proxyAuthMode();
/**
* Returns a comma-separated list of hostnames or partial
* host-names that should bypass any proxy settings.
*
* This function as well as @ref useReverseProxy only apply
* when @ref proxyType is @p ManualProxy.
*
* @see useReverseProxy, proxyFor, proxyForURL, slaveProtocol
*/
static TQString noProxyFor();
/**
* Same as above except the environment variable name
* is returned instead of the variable value when
* @ref proxyType is @p EnvVarProxy.
*
* @see noProxyFor
* @since 3.5.x
*/
static TQString noProxyForRaw();
/**
* Returns the proxy server address for a given protocol.
*
* NOTE: This function does not take the @ref useReverseProxy()
* settings into account.
*
* @see useReverseProxy, slaveProtocol
* @param protocol the protocol whose proxy info is needed
* @returns the proxy server address if one is available,
* or TQString::null if not available
*/
static TQString proxyFor( const TQString& protocol );
/**
* Returns the proxy server address for a given URL.
*
* If @ref proxyType returns Automatic, an external service
* called KPAC (a kded module) is used to determine the proxy
* server. Otherwise, @ref proxyFor is invoked to determine
* whether the URL needs to be routed through a proxy server.
*
* NOTE: This function does not take the @ref useReverseProxy()
* or the @ref noProxyFor() settings into account.
*
* @see useReverseProxy, slaveProtocol, noProxyFor
* @param url the URL whose proxy info is needed
* @returns the proxy server address or the text "DIRECT"
* if no proxying is needed for the given address.
*/
static TQString proxyForURL( const KURL& url );
/**
* Marks this proxy as bad (down). It will not be used for the
* next 30 minutes. (The script may supply an alternate proxy)
* @param proxy the proxy to mark as bad (as URL)
*/
static void badProxy( const TQString & proxy );
/**
* Returns the URL of the script for automatic proxy configuration.
* @return the proxy configuration script
*/
static TQString proxyConfigScript();
/*========================== CACHE CONFIG ===================================*/
/**
* Returns true/false to indicate whether a cache
* should be used
*
* @return true to use the cache, false otherwisea
*/
static bool useCache();
/**
* Returns the maximum age in seconds cached files should be
* kept before they are deleted as necessary.
*
* @return the maximum cache age in seconds
*/
static int maxCacheAge();
/**
* Returns the maximum size that can be used for caching.
*
* By default this function returns the DEFAULT_MAX_CACHE_SIZE
* value as defined in http_slave_defaults.h. Not that the
* value returned is in bytes, hence a value of 5120 would mean
* 5 Kb.
*
* @return the maximum cache size in bytes
*/
static int maxCacheSize(); // Maximum cache size in Kb.
/**
* The directory which contains the cache files.
* @return the directory that contains the cache files
*/
static TQString cacheDir();
/**
* Returns the Cache control directive to be used.
* @return the cache control value
*/
static TDEIO::CacheControl cacheControl();
/*============================ DOWNLOAD CONFIG ==============================*/
/**
* Returns true if partial downloads should be
* automatically resumed.
* @return true to resume partial downloads
*/
static bool autoResume();
/**
* Returns true if partial downloads should be marked
* with a ".part" extension.
* @return true if partial downloads should get an ".part" extension
*/
static bool markPartial();
/**
* Returns the minimum file size for keeping aborted
* downloads.
*
* Any data downloaded that does not meet this minimum
* requirement will simply be discarded. The default size
* is 5 KB.
*
* @return the minimum keep size for aborted downloads in bytes
*/
static int minimumKeepSize();
/*============================ NETWORK CONNECTIONS ==========================*/
/**
* Returns true if proxy connections should be persistent.
* @return true if proxy connections should be persistent
* @since 3.1
*/
static bool persistentProxyConnection();
/**
* Returns true if connections should be persistent
* @return true if the connections should be persistent
*/
static bool persistentConnections();
/*=============================== OTHERS ====================================*/
/**
* Force a reload of the general config file of
* io-slaves ( tdeioslaverc).
*/
static void reparseConfiguration();
/**
* Return the protocol to use in order to handle the given @p url
* It's usually the same, except that FTP, when handled by a proxy,
* needs an HTTP ioslave.
*
* When a proxy is to be used, proxy contains the URL for the proxy.
* @param url the url to check
* @param proxy the URL of the proxy to use
* @return the slave protocol (e.g. 'http'), can be null if unknown
*/
static TQString slaveProtocol(const KURL &url, TQString &proxy);
/**
* @internal
* (Shared with SlaveConfig)
*/
static TDEConfig *config();
private:
static TDEConfig *http_config();
};
#endif
|