Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (93 sloc) 3.81 kb
0bdffd8 finally import the source ;)
wiedi authored
1 /*
2 * libMaia - maiaXmlRpcClient.cpp
3 * Copyright (c) 2007 Sebastian Wiedenroth <wiedi@frubar.net>
4 * and Karl Glatz
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "maiaXmlRpcClient.h"
29 #include "maiaFault.h"
30
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
31 MaiaXmlRpcClient::MaiaXmlRpcClient(QObject* parent) : QObject(parent),
32 manager(this), request()
33 {
450222c allow changing the user-agent header.
wiedi authored
34 init();
0bdffd8 finally import the source ;)
wiedi authored
35 }
36
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
37 MaiaXmlRpcClient::MaiaXmlRpcClient(QUrl url, QObject* parent) : QObject(parent),
38 manager(this), request(url)
39 {
450222c allow changing the user-agent header.
wiedi authored
40 init();
41 setUrl(url);
42 }
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
43
450222c allow changing the user-agent header.
wiedi authored
44 MaiaXmlRpcClient::MaiaXmlRpcClient(QUrl url, QString userAgent, QObject *parent) : QObject(parent) {
45 // userAgent should adhere to RFC 1945 http://tools.ietf.org/html/rfc1945
46 init();
47 request.setRawHeader("User-Agent", userAgent.toAscii());
0bdffd8 finally import the source ;)
wiedi authored
48 setUrl(url);
49 }
50
450222c allow changing the user-agent header.
wiedi authored
51 void MaiaXmlRpcClient::init() {
52 request.setRawHeader("User-Agent", "libmaia/0.2");
53 request.setHeader(QNetworkRequest::ContentTypeHeader, "text/xml");
809a2fb expose ssl configuration methods and forward sslerrors
wiedi authored
54
450222c allow changing the user-agent header.
wiedi authored
55 connect(&manager, SIGNAL(finished(QNetworkReply*)),
56 this, SLOT(replyFinished(QNetworkReply*)));
809a2fb expose ssl configuration methods and forward sslerrors
wiedi authored
57 connect(&manager, SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)),
58 this, SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)));
450222c allow changing the user-agent header.
wiedi authored
59 }
60
0bdffd8 finally import the source ;)
wiedi authored
61 void MaiaXmlRpcClient::setUrl(QUrl url) {
62 if(!url.isValid())
63 return;
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
64
65 request.setUrl(url);
0bdffd8 finally import the source ;)
wiedi authored
66 }
67
26abf12 add setUserAgent() also by Søren Boll Overgaard
wiedi authored
68 void MaiaXmlRpcClient::setUserAgent(QString userAgent) {
69 request.setRawHeader("User-Agent", userAgent.toAscii());
70 }
71
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
72 QNetworkReply* MaiaXmlRpcClient::call(QString method, QList<QVariant> args,
0bdffd8 finally import the source ;)
wiedi authored
73 QObject* responseObject, const char* responseSlot,
74 QObject* faultObject, const char* faultSlot) {
75 MaiaObject* call = new MaiaObject(this);
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
76 connect(call, SIGNAL(aresponse(QVariant &, QNetworkReply *)), responseObject, responseSlot);
77 connect(call, SIGNAL(fault(int, const QString &, QNetworkReply *)), faultObject, faultSlot);
0bdffd8 finally import the source ;)
wiedi authored
78
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
79 QNetworkReply* reply = manager.post( request,
80 call->prepareCall(method, args).toUtf8() );
81
82 callmap[reply] = call;
83 return reply;
0bdffd8 finally import the source ;)
wiedi authored
84 }
85
809a2fb expose ssl configuration methods and forward sslerrors
wiedi authored
86 void MaiaXmlRpcClient::setSslConfiguration(const QSslConfiguration &config) {
87 request.setSslConfiguration(config);
88 }
89
90 QSslConfiguration MaiaXmlRpcClient::sslConfiguration () const {
91 return request.sslConfiguration();
92 }
93
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
94 void MaiaXmlRpcClient::replyFinished(QNetworkReply* reply) {
0bdffd8 finally import the source ;)
wiedi authored
95 QString response;
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
96 if(!callmap.contains(reply))
0bdffd8 finally import the source ;)
wiedi authored
97 return;
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
98 if(reply->error() != QNetworkReply::NoError) {
99 MaiaFault fault(-32300, reply->errorString());
0bdffd8 finally import the source ;)
wiedi authored
100 response = fault.toString();
101 } else {
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
102 response = QString::fromUtf8(reply->readAll());
0bdffd8 finally import the source ;)
wiedi authored
103 }
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
104
105 // parseResponse deletes the MaiaObject
106 callmap[reply]->parseResponse(response, reply);
76aa4e2 bugfix: use deleteLater() for the reply
wiedi authored
107 reply->deleteLater();
fd386f7 integrate a patch by Lennart Goedhart
wiedi authored
108 callmap.remove(reply);
426613e cookie support by Søren Boll Overgaard, thanks!
wiedi authored
109 }
Something went wrong with that request. Please try again.