6a0af1c90aef10526bc0e8b9651c0791479fddbf
[profile/ivi/qtbase.git] / src / corelib / io / qurl_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QURL_P_H
43 #define QURL_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience of
50 // qurl*.cpp This header file may change from version to version without
51 // notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qurl.h"
57
58 QT_BEGIN_NAMESPACE
59
60 struct QUrlErrorInfo {
61     inline QUrlErrorInfo() : _source(0), _message(0), _expected(0), _found(0)
62     { }
63
64     const char *_source;
65     const char *_message;
66     char _expected;
67     char _found;
68
69     inline void setParams(const char *source, const char *message, char expected, char found)
70     {
71         _source = source;
72         _message = message;
73         _expected = expected;
74         _found = found;
75     }
76 };
77
78 class QUrlPrivate
79 {
80 public:
81     enum Section {
82         Scheme = 0x01,
83         UserName = 0x02,
84         Password = 0x04,
85         UserInfo = UserName | Password,
86         Host = 0x08,
87         Port = 0x10,
88         Authority = UserInfo | Host | Port,
89         Path = 0x20,
90         Hierarchy = Authority | Path,
91         Query = 0x40,
92         Fragment = 0x80
93     };
94
95     QUrlPrivate();
96     QUrlPrivate(const QUrlPrivate &copy);
97
98     void parse(const QString &url);
99     void clear();
100
101     // no QString scheme() const;
102     void appendAuthority(QString &appendTo, QUrl::FormattingOptions options) const;
103     void appendUserInfo(QString &appendTo, QUrl::FormattingOptions options) const;
104     void appendUserName(QString &appendTo, QUrl::FormattingOptions options) const;
105     void appendPassword(QString &appendTo, QUrl::FormattingOptions options) const;
106     void appendHost(QString &appendTo, QUrl::FormattingOptions options) const;
107     void appendPath(QString &appendTo, QUrl::FormattingOptions options) const;
108     void appendQuery(QString &appendTo, QUrl::FormattingOptions options) const;
109     void appendFragment(QString &appendTo, QUrl::FormattingOptions options) const;
110
111     // the "end" parameters are like STL iterators: they point to one past the last valid element
112     bool setScheme(const QString &value, int len, bool decoded = false);
113     bool setAuthority(const QString &auth, int from, int end);
114     void setUserInfo(const QString &userInfo, int from, int end);
115     void setUserName(const QString &value, int from, int end);
116     void setPassword(const QString &value, int from, int end);
117     bool setHost(const QString &value, int from, int end, bool maybePercentEncoded = true);
118     void setPath(const QString &value, int from, int end);
119     void setQuery(const QString &value, int from, int end);
120     void setFragment(const QString &value, int from, int end);
121
122     inline bool hasScheme() const { return sectionIsPresent & Scheme; }
123     inline bool hasAuthority() const { return sectionIsPresent & Authority; }
124     inline bool hasUserInfo() const { return sectionIsPresent & UserInfo; }
125     inline bool hasUserName() const { return sectionIsPresent & UserName; }
126     inline bool hasPassword() const { return sectionIsPresent & Password; }
127     inline bool hasHost() const { return sectionIsPresent & Host; }
128     inline bool hasPort() const { return port != -1; }
129     inline bool hasPath() const { return !path.isEmpty(); }
130     inline bool hasQuery() const { return sectionIsPresent & Query; }
131     inline bool hasFragment() const { return sectionIsPresent & Fragment; }
132
133     QString mergePaths(const QString &relativePath) const;
134
135     QAtomicInt ref;
136     int port;
137
138     QString scheme;
139     QString userName;
140     QString password;
141     QString host;
142     QString path;
143     QString query;
144     QString fragment;
145
146     // not used for:
147     //  - Port (port == -1 means absence)
148     //  - Path (there's no path delimiter, so we optimize its use out of existence)
149     // Schemes are never supposed to be empty, but we keep the flag anyway
150     uchar sectionIsPresent;
151
152     // UserName, Password, Path, Query, and Fragment never contain errors in TolerantMode.
153     // Those flags are set only by the strict parser.
154     uchar sectionHasError;
155
156     mutable QUrlErrorInfo errorInfo;
157     QString createErrorString();
158 };
159
160
161 // in qurlrecode.cpp
162 extern Q_AUTOTEST_EXPORT int qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end,
163                                           QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications);
164
165 // in qurlidna.cpp
166 enum AceOperation { ToAceOnly, NormalizeAce };
167 extern QString qt_ACE_do(const QString &domain, AceOperation op);
168 extern Q_AUTOTEST_EXPORT void qt_nameprep(QString *source, int from);
169 extern Q_AUTOTEST_EXPORT bool qt_check_std3rules(const QChar *uc, int len);
170 extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output);
171 extern Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc);
172
173 QT_END_NAMESPACE
174
175 #endif // QURL_P_H