1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "putjob.h"
10
11#include <QDebug>
12#include <QXmlStreamReader>
13
14#include <QNetworkAccessManager>
15
16#include "platformdependent_v2.h"
17
18using namespace Attica;
19
20PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, QIODevice *iodevice)
21 : BaseJob(internals)
22 , m_ioDevice(iodevice)
23 , m_request(request)
24{
25}
26
27Attica::PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const QByteArray &byteArray)
28 : BaseJob(internals)
29 , m_ioDevice(nullptr)
30 , m_byteArray(byteArray)
31 , m_request(request)
32{
33}
34
35PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap &parameters)
36 : BaseJob(internals)
37 , m_ioDevice(nullptr)
38 , m_request(request)
39{
40 // Create put data
41 int j = 0;
42 for (StringMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
43 if (j++ > 0) {
44 m_byteArray.append(c: '&');
45 }
46 m_byteArray.append(a: QUrl::toPercentEncoding(i.key()));
47 m_byteArray.append(c: '=');
48 m_byteArray.append(a: QUrl::toPercentEncoding(i.value()));
49 }
50}
51
52QNetworkReply *PutJob::executeRequest()
53{
54 Attica::PlatformDependentV2 *platformDependentV2 = dynamic_cast<Attica::PlatformDependentV2 *>(internals());
55 if (!platformDependentV2) {
56 return nullptr;
57 }
58
59 if (m_ioDevice) {
60 return platformDependentV2->put(request: m_request, data: m_ioDevice);
61 } else {
62 return platformDependentV2->put(request: m_request, data: m_byteArray);
63 }
64}
65
66void PutJob::parse(const QString &xmlString)
67{
68 // qCDebug(ATTICA) << "PutJob::parse" << xmlString;
69 QXmlStreamReader xml(xmlString);
70 Metadata data;
71 while (!xml.atEnd()) {
72 xml.readNext();
73
74 if (xml.isStartElement()) {
75 if (xml.name() == QLatin1String("meta")) {
76 while (!xml.atEnd()) {
77 xml.readNext();
78 if (xml.isEndElement() && xml.name() == QLatin1String("meta")) {
79 break;
80 } else if (xml.isStartElement()) {
81 if (xml.name() == QLatin1String("status")) {
82 data.setStatusString(xml.readElementText());
83 } else if (xml.name() == QLatin1String("statuscode")) {
84 data.setStatusCode(xml.readElementText().toInt());
85 } else if (xml.name() == QLatin1String("message")) {
86 data.setMessage(xml.readElementText());
87 } else if (xml.name() == QLatin1String("totalitems")) {
88 data.setTotalItems(xml.readElementText().toInt());
89 } else if (xml.name() == QLatin1String("itemsperpage")) {
90 data.setItemsPerPage(xml.readElementText().toInt());
91 }
92 }
93 }
94 } else if (xml.name() == QLatin1String("data")) {
95 while (!xml.atEnd()) {
96 xml.readNext();
97 if (xml.isEndElement() && xml.name() == QLatin1String("data")) {
98 break;
99 } else if (xml.isStartElement()) {
100 if (xml.name() == QLatin1String("projectid")) {
101 data.setResultingId(xml.readElementText());
102 }
103 if (xml.name() == QLatin1String("buildjobid")) {
104 data.setResultingId(xml.readElementText());
105 }
106 }
107 }
108 }
109 }
110 }
111 setMetadata(data);
112}
113
114#include "moc_putjob.cpp"
115

source code of attica/src/putjob.cpp