Qore Programming Language: include/qore/QoreHttpClientObject.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreHttpClientObject.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreHttpClientObject.h
4
5 Qore Programming Language
6
7 Copyright (C) 2006 - 2014 QoreTechnologies
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef QORE_HTTP_CLIENT_OBJECT_H_
25 #define QORE_HTTP_CLIENT_OBJECT_H_
26
27 #include <qore/common.h>
28 #include <qore/QoreSocketObject.h>
29
30 #define HTTPCLIENT_DEFAULT_PORT 80
31 #define HTTPCLIENT_DEFAULT_HOST "localhost"
32
33 #define HTTPCLIENT_DEFAULT_TIMEOUT 300000
34
35 #define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5
36
37 class Queue;
38
40
42 class QoreHttpClientObject : public QoreSocketObject {
43 private:
45 struct qore_httpclient_priv* http_priv;
46
48 DLLLOCAL QoreHttpClientObject(const QoreHttpClientObject&);
49
51 DLLLOCAL QoreHttpClientObject& operator=(const QoreHttpClientObject&);
52
53 protected:
54 DLLEXPORT void lock();
55 DLLEXPORT void unlock();
56
57 public:
59 DLLEXPORT QoreHttpClientObject();
60
62 DLLEXPORT virtual ~QoreHttpClientObject();
63
65
82 DLLEXPORT int setOptions(const QoreHashNode* opts, ExceptionSink* xsink);
83
85
87 DLLEXPORT void setDefaultPort(int prt);
88
90
92 DLLEXPORT void setDefaultPath(const char* pth);
93
95
97 DLLEXPORT const char* getDefaultPath() const;
98
100
102 DLLEXPORT const char* getConnectionPath() const;
103
105
107 DLLEXPORT void addProtocol(const char* prot, int port, bool ssl = false);
108
110 DLLEXPORT void setTimeout(int to);
111
113 DLLEXPORT int getTimeout() const;
114
116 DLLEXPORT void setEncoding(const QoreEncoding* qe);
117
119 DLLEXPORT const QoreEncoding* getEncoding() const;
120
122
127 DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink);
128
130
133 DLLEXPORT const char* getHTTPVersion() const;
134
136
139 DLLEXPORT void setHTTP11(bool h11);
140
142 DLLEXPORT bool isHTTP11() const;
143
145
149 DLLEXPORT int setURL(const char* url, ExceptionSink* xsink);
150
152
155 DLLEXPORT QoreStringNode* getURL();
156
158
162 DLLEXPORT void setUserPassword(const char* user, const char* pass);
163
165 DLLEXPORT void clearUserPassword();
166
168
172 DLLEXPORT int setProxyURL(const char* proxy, ExceptionSink* xsink);
173
175
178 DLLEXPORT QoreStringNode* getProxyURL();
179
181 DLLEXPORT void clearProxyURL();
182
184
188 DLLEXPORT void setProxyUserPassword(const char* user, const char* pass);
189
191 DLLEXPORT void clearProxyUserPassword();
192
194 DLLEXPORT void setSecure(bool is_secure);
195
197 DLLEXPORT bool isSecure() const;
198
200 DLLEXPORT void setProxySecure(bool is_secure);
201
203 DLLEXPORT bool isProxySecure() const;
204
206 DLLEXPORT void setMaxRedirects(int max);
207
209 DLLEXPORT int getMaxRedirects() const;
210
212
214 DLLEXPORT int connect(ExceptionSink* xsink);
215
217 DLLEXPORT void disconnect();
218
220
231 DLLEXPORT QoreHashNode* send(const char* meth, const char* path, const QoreHashNode* headers, const void* data, unsigned size, bool getbody, QoreHashNode* info, ExceptionSink* xsink);
232
233 DLLEXPORT QoreHashNode* sendWithSendCallback(const char* meth, const char* mpath, const QoreHashNode* headers, const ResolvedCallReferenceNode* send_callback, bool getbody, QoreHashNode* info, int timeout_ms, ExceptionSink* xsink);
234
235 DLLEXPORT void sendWithRecvCallback(const char* meth, const char* mpath, const QoreHashNode* headers, const void* data, unsigned size, bool getbody, QoreHashNode* info, int timeout_ms, const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, ExceptionSink* xsink);
236
237 DLLEXPORT void sendWithCallbacks(const char* meth, const char* mpath, const QoreHashNode* headers, const ResolvedCallReferenceNode* send_callback, bool getbody, QoreHashNode* info, int timeout_ms, const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, ExceptionSink* xsink);
238
240
247 DLLEXPORT AbstractQoreNode* get(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
248
250
256 DLLEXPORT QoreHashNode* head(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
257
259
268 DLLEXPORT AbstractQoreNode* post(const char* path, const QoreHashNode* headers, const void* data, unsigned size, QoreHashNode* info, ExceptionSink* xsink);
269
271
275 DLLEXPORT void setDefaultHeaderValue(const char* header, const char* val);
276
277 using AbstractPrivateData::deref;
279
282 DLLEXPORT virtual void deref(ExceptionSink* xsink);
283
285
288 DLLEXPORT void setConnectTimeout(int ms);
289
291
294 DLLEXPORT int getConnectTimeout() const;
295
297
306 DLLEXPORT int setNoDelay(bool nodelay);
307
309 DLLEXPORT void setEventQueue(Queue* cbq, ExceptionSink* xsink);
310
312 DLLEXPORT bool getNoDelay() const;
313
315 DLLEXPORT bool isConnected() const;
316
318 DLLEXPORT void setPersistent(ExceptionSink* xsink);
319
320 DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
321 DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, AbstractQoreNode* arg, int64 min_ms = 1000);
322 DLLEXPORT QoreHashNode* getUsageInfo() const;
323 DLLEXPORT void clearStats();
324
325 DLLLOCAL static void static_init();
326
327 DLLLOCAL void cleanup(ExceptionSink* xsink);
328 };
329
330 #endif
QoreHttpClientObject::clearProxyUserPassword
DLLEXPORT void clearProxyUserPassword()
clears the username and password for the proxy connection
QoreHttpClientObject::head
DLLEXPORT QoreHashNode * head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP "HEAD" method and returns the headers returned, the caller owns the QoreHashNode refere...
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:72
QoreHttpClientObject::isProxySecure
DLLEXPORT bool isProxySecure() const
returns the SSL proxy connection parameter flag
QoreHttpClientObject::getURL
DLLEXPORT QoreStringNode * getURL()
returns the connection parameters as a URL, caller owns the reference count returned ...
QoreHttpClientObject::setPersistent
DLLEXPORT void setPersistent(ExceptionSink *xsink)
temporarily disables implicit reconnections; must be called when the server is already connected ...
QoreHttpClientObject::connect
DLLEXPORT int connect(ExceptionSink *xsink)
opens a connection and returns a code giving the result
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:41
QoreHttpClientObject::isSecure
DLLEXPORT bool isSecure() const
returns the SSL connection parameter flag
QoreHttpClientObject::setOptions
DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink *xsink)
set options with a hash, returns -1 if an exception was thrown, 0 for OK
QoreHttpClientObject::QoreHttpClientObject
DLLEXPORT QoreHttpClientObject()
creates the QoreHttpClientObject object
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
QoreHttpClientObject::setTimeout
DLLEXPORT void setTimeout(int to)
sets the connection and response packet timeout value in milliseconds
QoreHttpClientObject::getMaxRedirects
DLLEXPORT int getMaxRedirects() const
returns the value of the max_redirects option
QoreHttpClientObject::setDefaultPath
DLLEXPORT void setDefaultPath(const char *pth)
sets the default path
QoreHttpClientObject::setProxyURL
DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink)
sets the proxy URL
QoreHttpClientObject::addProtocol
DLLEXPORT void addProtocol(const char *prot, int port, bool ssl=false)
adds a protocol
QoreHttpClientObject::~QoreHttpClientObject
virtual DLLEXPORT ~QoreHttpClientObject()
destroys the object and frees all associated memory
QoreHttpClientObject::setURL
DLLEXPORT int setURL(const char *url, ExceptionSink *xsink)
sets the connection URL
QoreHttpClientObject::setDefaultPort
DLLEXPORT void setDefaultPort(int prt)
sets the default port
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
QoreHttpClientObject::setHTTP11
DLLEXPORT void setHTTP11(bool h11)
sets or clears HTTP 1.1 protocol compliance
QoreHttpClientObject::setConnectTimeout
DLLEXPORT void setConnectTimeout(int ms)
sets the connect timeout in ms
QoreHttpClientObject::post
DLLEXPORT AbstractQoreNode * post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP "POST" message to the remote server and returns the message body of the response...
QoreHttpClientObject::getNoDelay
DLLEXPORT bool getNoDelay() const
returns the value of the TCP_NODELAY flag on the object
QoreHttpClientObject::setDefaultHeaderValue
DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val)
sets the value of a default header to send with every outgoing message
QoreHttpClientObject::setUserPassword
DLLEXPORT void setUserPassword(const char *user, const char *pass)
sets the username and password for the connection
AbstractPrivateData::deref
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:57
QoreHttpClientObject::setHTTPVersion
DLLEXPORT int setHTTPVersion(const char *version, ExceptionSink *xsink)
sets the http version from a string
QoreHttpClientObject::setMaxRedirects
DLLEXPORT void setMaxRedirects(int max)
sets the max_redirects option
QoreHttpClientObject::isConnected
DLLEXPORT bool isConnected() const
returns the connection status of the object
QoreHttpClientObject::getHTTPVersion
DLLEXPORT const char * getHTTPVersion() const
returns the http version as a string (either "1.0" or "1.1")
QoreHttpClientObject::setEncoding
DLLEXPORT void setEncoding(const QoreEncoding *qe)
sets the default encoding for the object
QoreHttpClientObject::disconnect
DLLEXPORT void disconnect()
disconnects from the remote server
QoreHttpClientObject::getTimeout
DLLEXPORT int getTimeout() const
returns the connection and response packet timeout value in milliseconds
QoreObject
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
QoreHttpClientObject
provides a way to communicate with HTTP servers using Qore data structures
Definition: QoreHttpClientObject.h:42
QoreHttpClientObject::setProxySecure
DLLEXPORT void setProxySecure(bool is_secure)
sets the SSL flag for use in the next connection to the proxy
QoreHttpClientObject::getProxyURL
DLLEXPORT QoreStringNode * getProxyURL()
returns the proxy connection parameters as a URL (or 0 if there is none), caller owns the reference c...
QoreHttpClientObject::setNoDelay
DLLEXPORT int setNoDelay(bool nodelay)
sets the TCP_NODELAY flag on the object
QoreHttpClientObject::getConnectionPath
DLLEXPORT const char * getConnectionPath() const
returns the current connection path or 0 if none is set
QoreHttpClientObject::getDefaultPath
DLLEXPORT const char * getDefaultPath() const
returns the default path or 0 if none is set
QoreHttpClientObject::getConnectTimeout
DLLEXPORT int getConnectTimeout() const
returns the connect timeout in ms, negative numbers mean no timeout
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:120
QoreHttpClientObject::getEncoding
DLLEXPORT const QoreEncoding * getEncoding() const
returns the default encoding for the object
QoreHttpClientObject::isHTTP11
DLLEXPORT bool isHTTP11() const
returns true if HTTP 1.1 protocol compliance has been set
QoreHttpClientObject::setSecure
DLLEXPORT void setSecure(bool is_secure)
sets the SSL flag for use in the next connection
common.h
QoreHttpClientObject::clearUserPassword
DLLEXPORT void clearUserPassword()
clears the username and password for the connection
QoreHttpClientObject::setEventQueue
DLLEXPORT void setEventQueue(Queue *cbq, ExceptionSink *xsink)
sets the event queue, must be already referenced before call
QoreHttpClientObject::setProxyUserPassword
DLLEXPORT void setProxyUserPassword(const char *user, const char *pass)
sets the username and password for the proxy connection
QoreHttpClientObject::send
DLLEXPORT QoreHashNode * send(const char *meth, const char *path, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink)
sends a message to the remote server and returns the entire response as a hash, caller owns the QoreH...
QoreHttpClientObject::clearProxyURL
DLLEXPORT void clearProxyURL()
clears the proxy URL