File indexing completed on 2024-04-28 15:32:50
0001 /* 0002 SPDX-FileCopyrightText: 2003-2004 Frerich Raabe <raabe@kde.org> 0003 SPDX-FileCopyrightText: 2003-2004 Tobias Koenig <tokoe@kde.org> 0004 SPDX-FileCopyrightText: 2006 Narayan Newton <narayannewton@gmail.com> 0005 0006 SPDX-License-Identifier: BSD-2-Clause 0007 */ 0008 0009 #include "kxmlrpcclient_private_export.h" 0010 #include "query.h" 0011 #include <KIO/Job> 0012 0013 #include <QDomDocument> 0014 #include <QVariant> 0015 0016 namespace KXmlRpc 0017 { 0018 /** 0019 @brief 0020 Result is an internal class that represents a response 0021 from a XML-RPC server. 0022 0023 This is an internal class and is only used by Query. 0024 @internal 0025 */ 0026 class KXMLRPCCLIENT_TESTS_EXPORT Result 0027 { 0028 friend class Query; 0029 friend class QueryPrivate; 0030 0031 public: 0032 /** 0033 Constructs a result. 0034 */ 0035 Result(); 0036 0037 /** 0038 Returns true if the method call succeeded, false 0039 if there was an XML-RPC fault. 0040 0041 @see errorCode(), errorString() 0042 */ 0043 bool success() const; 0044 0045 /** 0046 Returns the error code of the fault. 0047 0048 @see success(), errorString() 0049 */ 0050 int errorCode() const; 0051 0052 /** 0053 Returns the error string that describes the fault. 0054 0055 @see success, errorCode() 0056 */ 0057 QString errorString() const; 0058 0059 /** 0060 Returns the data sent to us from the server. 0061 */ 0062 QList<QVariant> data() const; 0063 0064 private: 0065 bool mSuccess; 0066 int mErrorCode; 0067 QString mErrorString; 0068 QList<QVariant> mData; 0069 }; 0070 0071 class KXMLRPCCLIENT_TESTS_EXPORT QueryPrivate 0072 { 0073 public: 0074 QueryPrivate(Query *parent) 0075 : mParent(parent) 0076 { 0077 } 0078 0079 static bool isMessageResponse(const QDomDocument &doc); 0080 static bool isFaultResponse(const QDomDocument &doc); 0081 0082 static Result parseMessageResponse(const QDomDocument &doc); 0083 static Result parseFaultResponse(const QDomDocument &doc); 0084 0085 static QByteArray markupCall(const QString &method, const QList<QVariant> &args); 0086 static QByteArray marshal(const QVariant &value); 0087 static QVariant demarshal(const QDomElement &element); 0088 0089 void slotData(KIO::Job *job, const QByteArray &data); 0090 void slotResult(KJob *job); 0091 0092 Query *mParent; 0093 QByteArray mBuffer; 0094 QVariant mId; 0095 QList<KJob *> mPendingJobs; 0096 }; 0097 0098 } // namespace KXmlRpcClient