1 /*
2     SPDX-FileCopyrightText: 2003-2004 Frerich Raabe <raabe@kde.org>
3     SPDX-FileCopyrightText: 2003-2004 Tobias Koenig <tokoe@kde.org>
4     SPDX-FileCopyrightText: 2006 Narayan Newton <narayannewton@gmail.com>
5 
6     SPDX-License-Identifier: BSD-2-Clause
7 */
8 
9 #include "kxmlrpcclient_private_export.h"
10 #include "query.h"
11 #include <KIO/Job>
12 
13 #include <QDomDocument>
14 #include <QVariant>
15 
16 namespace KXmlRpc
17 {
18 /**
19   @brief
20   Result is an internal class that represents a response
21   from a XML-RPC server.
22 
23   This is an internal class and is only used by Query.
24   @internal
25  */
26 class KXMLRPCCLIENT_TESTS_EXPORT Result
27 {
28     friend class Query;
29     friend class QueryPrivate;
30 
31 public:
32     /**
33       Constructs a result.
34      */
35     Result();
36 
37     /**
38       Returns true if the method call succeeded, false
39       if there was an XML-RPC fault.
40 
41       @see errorCode(), errorString()
42      */
43     bool success() const;
44 
45     /**
46       Returns the error code of the fault.
47 
48       @see success(), errorString()
49      */
50     int errorCode() const;
51 
52     /**
53       Returns the error string that describes the fault.
54 
55       @see success, errorCode()
56      */
57     QString errorString() const;
58 
59     /**
60       Returns the data sent to us from the server.
61      */
62     QList<QVariant> data() const;
63 
64 private:
65     bool mSuccess;
66     int mErrorCode;
67     QString mErrorString;
68     QList<QVariant> mData;
69 };
70 
71 class KXMLRPCCLIENT_TESTS_EXPORT QueryPrivate
72 {
73 public:
QueryPrivate(Query * parent)74     QueryPrivate(Query *parent)
75         : mParent(parent)
76     {
77     }
78 
79     static bool isMessageResponse(const QDomDocument &doc);
80     static bool isFaultResponse(const QDomDocument &doc);
81 
82     static Result parseMessageResponse(const QDomDocument &doc);
83     static Result parseFaultResponse(const QDomDocument &doc);
84 
85     static QByteArray markupCall(const QString &method, const QList<QVariant> &args);
86     static QByteArray marshal(const QVariant &value);
87     static QVariant demarshal(const QDomElement &element);
88 
89     void slotData(KIO::Job *job, const QByteArray &data);
90     void slotResult(KJob *job);
91 
92     Query *mParent;
93     QByteArray mBuffer;
94     QVariant mId;
95     QList<KJob *> mPendingJobs;
96 };
97 
98 } // namespace KXmlRpcClient
99