|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreHTTPClient.h 00004 00005 Qore Programming Language 00006 00007 Copyright (C) 2006 - 2011 QoreTechnologies 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef QORE_HTTP_CLIENT_H_ 00025 #define QORE_HTTP_CLIENT_H_ 00026 00027 #include <qore/common.h> 00028 #include <qore/AbstractPrivateData.h> 00029 #include <qore/QoreThreadLock.h> 00030 #include <qore/QoreSocket.h> 00031 00032 #define HTTPCLIENT_DEFAULT_PORT 80 //!< the default port number to use 00033 #define HTTPCLIENT_DEFAULT_HOST "localhost" //!< the default host name to use 00034 00035 #define HTTPCLIENT_DEFAULT_TIMEOUT 300000 //!< the default connection and response packet timeout to use (300,000 ms = 5m) 00036 00037 #define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5 //!< maximum number of HTTP redirects allowed 00038 00039 class Queue; 00040 00042 00044 class QoreHTTPClient : public AbstractPrivateData { 00045 private: 00047 struct qore_qtc_private *priv; 00048 00050 DLLLOCAL QoreHTTPClient(const QoreHTTPClient&); 00051 00053 DLLLOCAL QoreHTTPClient& operator=(const QoreHTTPClient&); 00054 00055 protected: 00056 DLLEXPORT void lock(); 00057 DLLEXPORT void unlock(); 00058 00059 public: 00061 DLLEXPORT QoreHTTPClient(); 00062 00064 DLLEXPORT virtual ~QoreHTTPClient(); 00065 00067 00084 DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink* xsink); 00085 00087 00089 DLLEXPORT void setDefaultPort(int prt); 00090 00092 00094 DLLEXPORT void setDefaultPath(const char *pth); 00095 00097 00099 DLLEXPORT void addProtocol(const char *prot, int port, bool ssl = false); 00100 00102 DLLEXPORT void setTimeout(int to); 00103 00105 DLLEXPORT int getTimeout() const; 00106 00108 DLLEXPORT void setEncoding(const QoreEncoding *qe); 00109 00111 DLLEXPORT const QoreEncoding *getEncoding() const; 00112 00114 00119 DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink); 00120 00122 00125 DLLEXPORT const char* getHTTPVersion() const; 00126 00128 00131 DLLEXPORT void setHTTP11(bool h11); 00132 00134 DLLEXPORT bool isHTTP11() const; 00135 00137 00141 DLLEXPORT int setURL(const char *url, ExceptionSink *xsink); 00142 00144 00147 DLLEXPORT QoreStringNode *getURL(); 00148 00150 00154 DLLEXPORT void setUserPassword(const char *user, const char *pass); 00155 00157 DLLEXPORT void clearUserPassword(); 00158 00160 00164 DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink); 00165 00167 00170 DLLEXPORT QoreStringNode *getProxyURL(); 00171 00173 DLLEXPORT void clearProxyURL(); 00174 00176 00180 DLLEXPORT void setProxyUserPassword(const char *user, const char *pass); 00181 00183 DLLEXPORT void clearProxyUserPassword(); 00184 00186 DLLEXPORT void setSecure(bool is_secure); 00187 00189 DLLEXPORT bool isSecure() const; 00190 00192 DLLEXPORT void setProxySecure(bool is_secure); 00193 00195 DLLEXPORT bool isProxySecure() const; 00196 00198 DLLEXPORT void setMaxRedirects(int max); 00199 00201 DLLEXPORT int getMaxRedirects() const; 00202 00204 DLLEXPORT long verifyPeerCertificate(); 00205 00207 00210 DLLEXPORT const char *getSSLCipherName(); 00211 00213 00216 DLLEXPORT const char *getSSLCipherVersion(); 00217 00219 00221 DLLEXPORT int connect(ExceptionSink *xsink); 00222 00224 DLLEXPORT void disconnect(); 00225 00227 00238 DLLEXPORT QoreHashNode *send(const char *meth, const char *path, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink); 00239 00241 00248 DLLEXPORT AbstractQoreNode *get(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink); 00249 00251 00257 DLLEXPORT QoreHashNode *head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink); 00258 00260 00269 DLLEXPORT AbstractQoreNode *post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink); 00270 00272 00276 DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val); 00277 00278 using AbstractPrivateData::deref; 00280 00283 DLLEXPORT virtual void deref(ExceptionSink *xsink); 00284 00286 00289 DLLEXPORT void setConnectTimeout(int ms); 00290 00292 00295 DLLEXPORT int getConnectTimeout() const; 00296 00298 00307 DLLEXPORT int setNoDelay(bool nodelay); 00308 00310 DLLEXPORT void setEventQueue(Queue *cbq, ExceptionSink *xsink); 00311 00313 DLLEXPORT bool getNoDelay() const; 00314 00316 DLLEXPORT bool isConnected() const; 00317 00318 DLLLOCAL static void static_init(); 00319 00320 DLLLOCAL void cleanup(ExceptionSink *xsink); 00321 }; 00322 00323 #endif 00324 00325 // EOF 00326