1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2000-2001 Dawit Alemayehu <adawit@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #include "authinfo.h" |
9 | |
10 | #ifndef KIO_ANDROID_STUB |
11 | #include <QDBusArgument> |
12 | #include <QDBusMetaType> |
13 | #endif |
14 | #include <QDataStream> |
15 | #include <QDir> |
16 | #include <QFile> |
17 | #include <QTextStream> |
18 | |
19 | #include <QStandardPaths> |
20 | |
21 | using namespace KIO; |
22 | |
23 | ////// |
24 | |
25 | class |
26 | { |
27 | public: |
28 | () |
29 | : flags(AuthInfo::ExtraFieldNoFlags) |
30 | { |
31 | } |
32 | |
33 | (const ExtraField &other) |
34 | : customTitle(other.customTitle) |
35 | , flags(other.flags) |
36 | , value(other.value) |
37 | { |
38 | } |
39 | |
40 | ExtraField &(const ExtraField &other) |
41 | { |
42 | customTitle = other.customTitle; |
43 | flags = other.flags; |
44 | value = other.value; |
45 | return *this; |
46 | } |
47 | |
48 | QString ; // reserved for future use |
49 | AuthInfo::FieldFlags ; |
50 | QVariant ; |
51 | }; |
52 | Q_DECLARE_METATYPE(ExtraField) |
53 | |
54 | static QDataStream &(QDataStream &s, const ExtraField &) |
55 | { |
56 | s << extraField.customTitle; |
57 | s << static_cast<int>(extraField.flags); |
58 | s << extraField.value; |
59 | return s; |
60 | } |
61 | |
62 | static QDataStream &(QDataStream &s, ExtraField &) |
63 | { |
64 | s >> extraField.customTitle; |
65 | int i; |
66 | s >> i; |
67 | extraField.flags = AuthInfo::FieldFlags(i); |
68 | s >> extraField.value; |
69 | return s; |
70 | } |
71 | |
72 | #ifndef KIO_ANDROID_STUB |
73 | static QDBusArgument &(QDBusArgument &argument, const ExtraField &) |
74 | { |
75 | argument.beginStructure(); |
76 | argument << extraField.customTitle << static_cast<int>(extraField.flags) << QDBusVariant(extraField.value); |
77 | argument.endStructure(); |
78 | return argument; |
79 | } |
80 | |
81 | static const QDBusArgument &(const QDBusArgument &argument, ExtraField &) |
82 | { |
83 | QDBusVariant value; |
84 | int flag; |
85 | |
86 | argument.beginStructure(); |
87 | argument >> extraField.customTitle >> flag >> value; |
88 | argument.endStructure(); |
89 | |
90 | extraField.value = value.variant(); |
91 | extraField.flags = KIO::AuthInfo::FieldFlags(flag); |
92 | return argument; |
93 | } |
94 | #endif |
95 | |
96 | class KIO::AuthInfoPrivate |
97 | { |
98 | public: |
99 | QMap<QString, ExtraField> ; |
100 | }; |
101 | |
102 | ////// |
103 | |
104 | AuthInfo::AuthInfo() |
105 | : d(new AuthInfoPrivate()) |
106 | { |
107 | modified = false; |
108 | readOnly = false; |
109 | verifyPath = false; |
110 | keepPassword = false; |
111 | AuthInfo::registerMetaTypes(); |
112 | } |
113 | |
114 | AuthInfo::AuthInfo(const AuthInfo &info) |
115 | : d(new AuthInfoPrivate()) |
116 | { |
117 | (*this) = info; |
118 | AuthInfo::registerMetaTypes(); |
119 | } |
120 | |
121 | AuthInfo::~AuthInfo() = default; |
122 | |
123 | AuthInfo &AuthInfo::operator=(const AuthInfo &info) |
124 | { |
125 | url = info.url; |
126 | username = info.username; |
127 | password = info.password; |
128 | prompt = info.prompt; |
129 | caption = info.caption; |
130 | comment = info.comment; |
131 | commentLabel = info.commentLabel; |
132 | realmValue = info.realmValue; |
133 | digestInfo = info.digestInfo; |
134 | verifyPath = info.verifyPath; |
135 | readOnly = info.readOnly; |
136 | keepPassword = info.keepPassword; |
137 | modified = info.modified; |
138 | d->extraFields = info.d->extraFields; |
139 | return *this; |
140 | } |
141 | |
142 | bool AuthInfo::isModified() const |
143 | { |
144 | return modified; |
145 | } |
146 | |
147 | void AuthInfo::setModified(bool flag) |
148 | { |
149 | modified = flag; |
150 | } |
151 | |
152 | ///// |
153 | |
154 | void AuthInfo::(const QString &fieldName, const QVariant &value) |
155 | { |
156 | d->extraFields[fieldName].value = value; |
157 | } |
158 | |
159 | void AuthInfo::(const QString &fieldName, const FieldFlags flags) |
160 | { |
161 | d->extraFields[fieldName].flags = flags; |
162 | } |
163 | |
164 | QVariant AuthInfo::(const QString &fieldName) const |
165 | { |
166 | const auto it = d->extraFields.constFind(key: fieldName); |
167 | if (it == d->extraFields.constEnd()) { |
168 | return QVariant(); |
169 | } |
170 | return it->value; |
171 | } |
172 | |
173 | AuthInfo::FieldFlags AuthInfo::(const QString &fieldName) const |
174 | { |
175 | const auto it = d->extraFields.constFind(key: fieldName); |
176 | if (it == d->extraFields.constEnd()) { |
177 | return AuthInfo::ExtraFieldNoFlags; |
178 | } |
179 | return it->flags; |
180 | } |
181 | |
182 | void AuthInfo::registerMetaTypes() |
183 | { |
184 | qRegisterMetaType<ExtraField>(); |
185 | qRegisterMetaType<KIO::AuthInfo>(); |
186 | #ifndef KIO_ANDROID_STUB |
187 | qDBusRegisterMetaType<ExtraField>(); |
188 | qDBusRegisterMetaType<KIO::AuthInfo>(); |
189 | #endif |
190 | } |
191 | |
192 | ///// |
193 | |
194 | QDataStream &KIO::operator<<(QDataStream &s, const AuthInfo &a) |
195 | { |
196 | s << quint8(1) << a.url << a.username << a.password << a.prompt << a.caption << a.comment << a.commentLabel << a.realmValue << a.digestInfo << a.verifyPath |
197 | << a.readOnly << a.keepPassword << a.modified << a.d->extraFields; |
198 | return s; |
199 | } |
200 | |
201 | QDataStream &KIO::operator>>(QDataStream &s, AuthInfo &a) |
202 | { |
203 | quint8 version; |
204 | s >> version >> a.url >> a.username >> a.password >> a.prompt >> a.caption >> a.comment >> a.commentLabel >> a.realmValue >> a.digestInfo >> a.verifyPath |
205 | >> a.readOnly >> a.keepPassword >> a.modified >> a.d->extraFields; |
206 | return s; |
207 | } |
208 | |
209 | #ifndef KIO_ANDROID_STUB |
210 | QDBusArgument &KIO::operator<<(QDBusArgument &argument, const AuthInfo &a) |
211 | { |
212 | argument.beginStructure(); |
213 | argument << quint8(1) << a.url.toString() << a.username << a.password << a.prompt << a.caption << a.comment << a.commentLabel << a.realmValue |
214 | << a.digestInfo << a.verifyPath << a.readOnly << a.keepPassword << a.modified << a.d->extraFields; |
215 | argument.endStructure(); |
216 | return argument; |
217 | } |
218 | |
219 | const QDBusArgument &KIO::operator>>(const QDBusArgument &argument, AuthInfo &a) |
220 | { |
221 | QString url; |
222 | quint8 version; |
223 | |
224 | argument.beginStructure(); |
225 | argument >> version >> url >> a.username >> a.password >> a.prompt >> a.caption >> a.comment >> a.commentLabel >> a.realmValue >> a.digestInfo |
226 | >> a.verifyPath >> a.readOnly >> a.keepPassword >> a.modified >> a.d->extraFields; |
227 | argument.endStructure(); |
228 | |
229 | a.url = QUrl(url); |
230 | return argument; |
231 | } |
232 | #endif |
233 | |