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 @file 0010 This file is part of the API for accessing XML-RPC Servers 0011 and defines the Client class. 0012 0013 @brief 0014 Defines the Client class. 0015 0016 @author Frerich Raabe <raabe@kde.org> 0017 @author Tobias Koenig <tokoe@kde.org> 0018 @author Narayan Newton <narayannewton@gmail.com> 0019 */ 0020 0021 #ifndef KXML_RPC_CLIENT_H 0022 #define KXML_RPC_CLIENT_H 0023 0024 #include "kxmlrpcclient_export.h" 0025 0026 #include <QList> 0027 #include <QObject> 0028 #include <QUrl> 0029 #include <QVariant> 0030 class ClientPrivate; 0031 0032 /** Names for XmlRpc related classes */ 0033 namespace KXmlRpc 0034 { 0035 /** 0036 @class Client client.h <KXmlRpcClient/Client> 0037 0038 @brief 0039 A class that represents a connection to a XML-RPC server. 0040 This is the main interface to the XML-RPC client library. 0041 0042 @code 0043 KXmlRpc::Client *c = new Client(QUrl( "http://localhost" ), this); 0044 c->setUserAgent( "Test/1.0" ); 0045 c->call( "xmlrpc.command1", "Hi!", 0046 this, SLOT( gotData( const QList<QVariant>&, const QVariant ) ), 0047 this, SLOT( gotError( const QString&, const QVariant& ) ) ); 0048 @endcode 0049 0050 @author Narayan Newton <narayannewton@gmail.com> 0051 0052 @since 5.8 0053 */ 0054 class KXMLRPCCLIENT_EXPORT Client : public QObject 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 /** 0060 Constructs a XML-RPC Client. 0061 0062 @param parent the parent of this object, defaults to NULL. 0063 */ 0064 explicit Client(QObject *parent = nullptr); 0065 0066 /** 0067 Constructs a XML-RPC Client, which will connect to @p url. 0068 0069 @param url the url of the xml-rpc server. 0070 @param parent the parent of this object, defaults to NULL. 0071 */ 0072 explicit Client(const QUrl &url, QObject *parent = nullptr); 0073 0074 /** 0075 Destroys the XML-RPC Client. 0076 */ 0077 ~Client() override; 0078 0079 /** 0080 Returns the current url the XML-RPC Client will connect to. 0081 0082 @see setUrl() 0083 */ 0084 QUrl url() const; 0085 0086 /** 0087 Sets the url the Client will connect to. 0088 0089 @param url the url for the xml-rpc server we will be connecting to. 0090 0091 @see url() 0092 */ 0093 void setUrl(const QUrl &url); 0094 0095 /** 0096 Returns the user agent string currently used by the Client. 0097 0098 @see setUserAgent() 0099 */ 0100 QString userAgent() const; 0101 0102 /** 0103 Sets the userAgent string the Client will use to identify itself. 0104 0105 @param userAgent the user agent string to use. 0106 0107 @see userAgent() 0108 */ 0109 void setUserAgent(const QString &userAgent); 0110 0111 /** 0112 Returns true if HTTP-Digest authentication is enabled, false 0113 if not. 0114 0115 @see setDigestAuthEnabled() 0116 */ 0117 bool isDigestAuthEnabled() const; 0118 0119 /** 0120 Enables/disables HTTP-Digest authentication 0121 0122 @see isDigestAuthEnabled() 0123 */ 0124 0125 void setDigestAuthEnabled(bool enabled); 0126 0127 public Q_SLOTS: 0128 /** 0129 Calls the given method on a XML-RPC server, with the given 0130 argument list. 0131 0132 @param method the method on the server we are going to be calling 0133 @param args the argument list to pass to the server 0134 @param msgObj the object containing the data slot 0135 @param messageSlot the data slot itself 0136 @param faultObj the object containing the error slot 0137 @param faultSlot the error slot itself 0138 @param id the id for our #Client object, defaults to empty 0139 */ 0140 void call(const QString &method, 0141 const QList<QVariant> &args, 0142 QObject *msgObj, 0143 const char *messageSlot, 0144 QObject *faultObj, 0145 const char *faultSlot, 0146 const QVariant &id = QVariant()); 0147 0148 /** 0149 Calls the given method on a XML-RPC server, with the given 0150 argument. 0151 0152 @param method the method on the server we are going to be calling 0153 @param arg the argument to pass to the server 0154 @param msgObj the object containing the data slot 0155 @param messageSlot the data slot itself 0156 @param faultObj the object containing the error slot 0157 @param faultSlot the error slot itself 0158 @param id the id for our Client object, defaults to empty 0159 */ 0160 void call(const QString &method, 0161 const QVariant &arg, 0162 QObject *msgObj, 0163 const char *messageSlot, 0164 QObject *faultObj, 0165 const char *faultSlot, 0166 const QVariant &id = QVariant()); 0167 0168 /** 0169 Calls the given method on a XML-RPC server, with the given 0170 int as the argument. 0171 0172 @param method the method on the server we are going to be calling 0173 @param arg the int to pass to the server 0174 @param msgObj the object containing the data slot 0175 @param messageSlot the data slot itself 0176 @param faultObj the object containing the error slot 0177 @param faultSlot the error slot itself 0178 @param id the id for our Client object, defaults to empty 0179 */ 0180 void 0181 call(const QString &method, int arg, QObject *msgObj, const char *messageSlot, QObject *faultObj, const char *faultSlot, const QVariant &id = QVariant()); 0182 0183 /** 0184 Calls the given method on a XML-RPC server, with the given 0185 bool as the argument. 0186 0187 @param method the method on the server we are going to be calling 0188 @param arg the bool to pass to the server 0189 @param msgObj the object containing the data slot 0190 @param messageSlot the data slot itself 0191 @param faultObj the object containing the error slot 0192 @param faultSlot the error slot itself 0193 @param id the id for our Client object, defaults to empty 0194 */ 0195 void 0196 call(const QString &method, bool arg, QObject *msgObj, const char *messageSlot, QObject *faultObj, const char *faultSlot, const QVariant &id = QVariant()); 0197 0198 /** 0199 Calls the given method on a XML-RPC server, with the given 0200 double as the argument. 0201 0202 @param method the method on the server we are going to be calling 0203 @param arg the double to pass to the server 0204 @param msgObj the object containing the data slot 0205 @param messageSlot the data slot itself 0206 @param faultObj the object containing the error slot 0207 @param faultSlot the error slot itself 0208 @param id the id for our Client object, defaults to empty 0209 */ 0210 void call(const QString &method, 0211 double arg, 0212 QObject *msgObj, 0213 const char *messageSlot, 0214 QObject *faultObj, 0215 const char *faultSlot, 0216 const QVariant &id = QVariant()); 0217 0218 /** 0219 Calls the given method on a XML-RPC server, with the given 0220 string as the argument. 0221 0222 @param method the method on the server we are going to be calling 0223 @param arg the string to pass to the server 0224 @param msgObj the object containing the data slot 0225 @param messageSlot the data slot itself 0226 @param faultObj the object containing the error slot 0227 @param faultSlot the error slot itself 0228 @param id the id for our Client object, defaults to empty 0229 */ 0230 void call(const QString &method, 0231 const QString &arg, 0232 QObject *msgObj, 0233 const char *messageSlot, 0234 QObject *faultObj, 0235 const char *faultSlot, 0236 const QVariant &id = QVariant()); 0237 0238 /** 0239 Calls the given method on a XML-RPC server, with the given 0240 byte array as the argument. 0241 0242 @param method the method on the server we are going to be calling 0243 @param arg the array to pass to the server 0244 @param msgObj the object containing the data slot 0245 @param messageSlot the data slot itself 0246 @param faultObj the object containing the error slot 0247 @param faultSlot the error slot itself 0248 @param id the id for our Client object, defaults to empty 0249 */ 0250 void call(const QString &method, 0251 const QByteArray &arg, 0252 QObject *msgObj, 0253 const char *messageSlot, 0254 QObject *faultObj, 0255 const char *faultSlot, 0256 const QVariant &id = QVariant()); 0257 0258 /** 0259 Calls the given method on a XML-RPC server, with the given 0260 date as the argument 0261 0262 @param method the method on the server we are going to be calling 0263 @param arg the date and/or time to pass to the server 0264 @param msgObj the object containing the data slot 0265 @param messageSlot the data slot itself 0266 @param faultObj the object containing the error slot 0267 @param faultSlot the error slot itself 0268 @param id the id for our Client object, defaults to empty 0269 */ 0270 void call(const QString &method, 0271 const QDateTime &arg, 0272 QObject *msgObj, 0273 const char *messageSlot, 0274 QObject *faultObj, 0275 const char *faultSlot, 0276 const QVariant &id = QVariant()); 0277 0278 /** 0279 Calls the given method on a XML-RPC server, with the given 0280 string list as the argument 0281 0282 @param method the method on the server we are going to be calling 0283 @param arg the list of strings to pass to the server 0284 @param msgObj the object containing the data slot 0285 @param messageSlot the data slot itself 0286 @param faultObj the object containing the error slot 0287 @param faultSlot the error slot itself 0288 @param id the id for our Client object, defaults to empty 0289 */ 0290 void call(const QString &method, 0291 const QStringList &arg, 0292 QObject *msgObj, 0293 const char *messageSlot, 0294 QObject *faultObj, 0295 const char *faultSlot, 0296 const QVariant &id = QVariant()); 0297 0298 private: 0299 ClientPrivate *const d; 0300 0301 template<typename T> 0302 void call(const QString &method, 0303 const QList<T> &arg, 0304 QObject *obj1, 0305 const char *messageSlot, 0306 QObject *obj2, 0307 const char *faultSlot, 0308 const QVariant &id = QVariant()); 0309 0310 Q_PRIVATE_SLOT(d, void queryFinished(Query *)) 0311 }; 0312 0313 /** 0314 Calls the given method on a XML-RPC server with the given 0315 list of type T arguments. 0316 0317 @param method the method on the server we are going to be calling 0318 @param arg the list of type T to pass to the server 0319 @param msgObj the object containing the data slot 0320 @param messageSlot the data slot itself 0321 @param faultObj the object containing the error slot 0322 @param faultSlot the error slot itself 0323 @param id the id for our Client object, defaults to empty 0324 */ 0325 template<typename T> 0326 void Client::call(const QString &method, 0327 const QList<T> &arg, 0328 QObject *msgObj, 0329 const char *messageSlot, 0330 QObject *faultObj, 0331 const char *faultSlot, 0332 const QVariant &id) 0333 { 0334 QList<QVariant> args; 0335 const int numArgs = arg.count(); 0336 args.reserve(numArgs); 0337 for (int i = 0; i < numArgs; ++i) { 0338 args << QVariant(arg[i]); 0339 } 0340 0341 return call(method, args, faultObj, faultSlot, msgObj, messageSlot, id); 0342 } 0343 0344 } 0345 0346 #endif