1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org>
4 SPDX-FileCopyrightText: 2000 Waldo Bastain <bastain@kde.org>
5 SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org>
6 SPDX-FileCopyrightText: 2008 Jarosław Staniek <staniek@kde.org>
7 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-only
10*/
11
12#ifndef KPROTOCOLMANAGER_P_H
13#define KPROTOCOLMANAGER_P_H
14
15#include <kiocore_export.h>
16
17#include <QCache>
18#include <QHostAddress>
19#include <QMutex>
20#include <QString>
21#include <QUrl>
22
23#include <KSharedConfig>
24
25#include "kprotocolmanager.h"
26
27class KProxyData : public QObject
28{
29 Q_OBJECT
30public:
31 KProxyData(const QString &workerProtocol, const QStringList &proxyAddresses)
32 : protocol(workerProtocol)
33 , proxyList(proxyAddresses)
34 {
35 }
36
37 void removeAddress(const QString &address)
38 {
39 proxyList.removeAll(t: address);
40 }
41
42 QString protocol;
43 QStringList proxyList;
44};
45
46class KIOCORE_EXPORT KProtocolManagerPrivate
47{
48public:
49 using SubnetPair = QPair<QHostAddress, int>;
50
51 /**
52 * Types of proxy configuration
53 * @li NoProxy - No proxy is used
54 * @li ManualProxy - Proxies are manually configured
55 * @li PACProxy - A Proxy configuration URL has been given
56 * @li WPADProxy - A proxy should be automatically discovered
57 * @li EnvVarProxy - Use the proxy values set through environment variables.
58 */
59 enum ProxyType {
60 NoProxy,
61 ManualProxy,
62 PACProxy,
63 WPADProxy,
64 EnvVarProxy,
65 };
66
67 KProtocolManagerPrivate();
68 ~KProtocolManagerPrivate();
69 bool shouldIgnoreProxyFor(const QUrl &url);
70 void sync();
71 ProxyType proxyType();
72 bool useReverseProxy();
73 QString readNoProxyFor();
74 QString proxyFor(const QString &protocol);
75 QStringList getSystemProxyFor(const QUrl &url);
76
77 QMutex mutex; // protects all member vars
78 KSharedConfig::Ptr configPtr;
79 KSharedConfig::Ptr http_config;
80 QString modifiers;
81 QString useragent;
82 QString noProxyFor;
83 QList<SubnetPair> noProxySubnets;
84 QCache<QString, KProxyData> cachedProxyData;
85
86 QMap<QString /*mimetype*/, QString /*protocol*/> protocolForArchiveMimetypes;
87
88 /**
89 * Return the protocol to use in order to handle the given @p url
90 * It's usually the same, except that FTP, when handled by a proxy,
91 * needs an HTTP KIO worker.
92 *
93 * When a proxy is to be used, proxy contains the URL for the proxy.
94 * @param url the url to check
95 * @param proxy the URL of the proxy to use
96 * @return the worker protocol (e.g. 'http'), can be null if unknown
97 *
98 */
99 static QString workerProtocol(const QUrl &url, QStringList &proxy);
100
101 /**
102 * Returns all the possible proxy server addresses for @p url.
103 *
104 * If the selected proxy type is @ref PACProxy or @ref WPADProxy, then a
105 * helper kded module, proxyscout, is used to determine the proxy information.
106 * Otherwise, @ref proxyFor is used to find the proxy to use for the given url.
107 *
108 * If this function returns empty list, then the request is to a proxy server
109 * must be denied. For a direct connection, this function will return a single
110 * entry of "DIRECT".
111 *
112 *
113 * @param url the URL whose proxy info is needed
114 * @returns the proxy server address if one is available, otherwise an empty list .
115 */
116 static QStringList proxiesForUrl(const QUrl &url);
117
118 /**
119 * Returns the default user-agent value used for web browsing, for example
120 * "Mozilla/5.0 (compatible; Konqueror/4.0; Linux; X11; i686; en_US) KHTML/4.0.1 (like Gecko)"
121 *
122 * @param keys can be any of the following:
123 * @li 'o' Show OS
124 * @li 'v' Show OS Version
125 * @li 'p' Show platform (only for X11)
126 * @li 'm' Show machine architecture
127 * @li 'l' Show language
128 * @return the default user-agent value with the given @p keys
129 */
130 static QString defaultUserAgent(const QString &keys);
131
132 /**
133 * Returns system name, version and machine type, for example "Windows", "5.1", "i686".
134 * This information can be used for constructing custom user-agent strings.
135 *
136 * @param systemName system name
137 * @param systemVersion system version
138 * @param machine machine type
139
140 * @return true if system name, version and machine type has been provided
141 */
142 static bool getSystemNameVersionAndMachine(QString &systemName, QString &systemVersion, QString &machine);
143};
144
145#endif
146

source code of kio/src/core/kprotocolmanager_p.h