Qore Programming Language - C/C++ Library  0.8.12.2
 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 - 2015 Qore Technologies, sro
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef QORE_HTTP_CLIENT_OBJECT_H_
33 #define QORE_HTTP_CLIENT_OBJECT_H_
34 
35 #include <qore/common.h>
36 #include <qore/QoreSocketObject.h>
37 
38 #define HTTPCLIENT_DEFAULT_PORT 80
39 #define HTTPCLIENT_DEFAULT_HOST "localhost"
40 
41 #define HTTPCLIENT_DEFAULT_TIMEOUT 300000
42 
43 #define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5
44 
45 class Queue;
46 
48 
50 class QoreHttpClientObject : public QoreSocketObject {
51 private:
53  struct qore_httpclient_priv* http_priv;
54 
57 
59  DLLLOCAL QoreHttpClientObject& operator=(const QoreHttpClientObject&);
60 
61 protected:
62  DLLEXPORT void lock();
63  DLLEXPORT void unlock();
64 
65 public:
67  DLLEXPORT QoreHttpClientObject();
68 
70  DLLEXPORT virtual ~QoreHttpClientObject();
71 
73 
90  DLLEXPORT int setOptions(const QoreHashNode* opts, ExceptionSink* xsink);
91 
93 
95  DLLEXPORT void setDefaultPort(int prt);
96 
98 
100  DLLEXPORT void setDefaultPath(const char* pth);
101 
103 
105  DLLEXPORT const char* getDefaultPath() const;
106 
108 
110  DLLEXPORT const char* getConnectionPath() const;
111 
113 
115  DLLEXPORT void addProtocol(const char* prot, int port, bool ssl = false);
116 
118  DLLEXPORT void setTimeout(int to);
119 
121  DLLEXPORT int getTimeout() const;
122 
124  DLLEXPORT void setEncoding(const QoreEncoding* qe);
125 
127  DLLEXPORT const QoreEncoding* getEncoding() const;
128 
130 
135  DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink);
136 
138 
141  DLLEXPORT const char* getHTTPVersion() const;
142 
144 
147  DLLEXPORT void setHTTP11(bool h11);
148 
150  DLLEXPORT bool isHTTP11() const;
151 
153 
157  DLLEXPORT int setURL(const char* url, ExceptionSink* xsink);
158 
160 
163  DLLEXPORT QoreStringNode* getURL();
164 
166 
170  DLLEXPORT void setUserPassword(const char* user, const char* pass);
171 
173  DLLEXPORT void clearUserPassword();
174 
176 
180  DLLEXPORT int setProxyURL(const char* proxy, ExceptionSink* xsink);
181 
183 
186  DLLEXPORT QoreStringNode* getProxyURL();
187 
189  DLLEXPORT void clearProxyURL();
190 
192 
196  DLLEXPORT void setProxyUserPassword(const char* user, const char* pass);
197 
199  DLLEXPORT void clearProxyUserPassword();
200 
202  DLLEXPORT void setSecure(bool is_secure);
203 
205  DLLEXPORT bool isSecure() const;
206 
208  DLLEXPORT void setProxySecure(bool is_secure);
209 
211  DLLEXPORT bool isProxySecure() const;
212 
214  DLLEXPORT void setMaxRedirects(int max);
215 
217  DLLEXPORT int getMaxRedirects() const;
218 
220 
222  DLLEXPORT int connect(ExceptionSink* xsink);
223 
225  DLLEXPORT void disconnect();
226 
228 
239  DLLEXPORT QoreHashNode* send(const char* meth, const char* path, const QoreHashNode* headers, const void* data, unsigned size, bool getbody, QoreHashNode* info, ExceptionSink* xsink);
240 
241  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);
242 
243  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);
244 
245  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);
246 
248 
255  DLLEXPORT AbstractQoreNode* get(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
256 
258 
264  DLLEXPORT QoreHashNode* head(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
265 
267 
276  DLLEXPORT AbstractQoreNode* post(const char* path, const QoreHashNode* headers, const void* data, unsigned size, QoreHashNode* info, ExceptionSink* xsink);
277 
279 
283  DLLEXPORT void setDefaultHeaderValue(const char* header, const char* val);
284 
287 
290  DLLEXPORT virtual void deref(ExceptionSink* xsink);
291 
293 
296  DLLEXPORT void setConnectTimeout(int ms);
297 
299 
302  DLLEXPORT int getConnectTimeout() const;
303 
305 
314  DLLEXPORT int setNoDelay(bool nodelay);
315 
317  DLLEXPORT void setEventQueue(Queue* cbq, ExceptionSink* xsink);
318 
320  DLLEXPORT bool getNoDelay() const;
321 
323  DLLEXPORT bool isConnected() const;
324 
326  DLLEXPORT void setPersistent(ExceptionSink* xsink);
327 
328  DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
329  DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, AbstractQoreNode* arg, int64 min_ms = 1000);
330  DLLEXPORT QoreHashNode* getUsageInfo() const;
331  DLLEXPORT void clearStats();
332 
333  DLLLOCAL static void static_init();
334 
335  DLLLOCAL void cleanup(ExceptionSink* xsink);
336 };
337 
338 #endif
DLLEXPORT void clearProxyUserPassword()
clears the username and password for the proxy connection
DLLEXPORT QoreHashNode * head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP &quot;HEAD&quot; method and returns the headers returned, the caller owns the QoreHashNode refere...
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
DLLEXPORT bool isProxySecure() const
returns the SSL proxy connection parameter flag
DLLEXPORT QoreStringNode * getURL()
returns the connection parameters as a URL, caller owns the reference count returned ...
DLLEXPORT void setPersistent(ExceptionSink *xsink)
temporarily disables implicit reconnections; must be called when the server is already connected ...
DLLEXPORT int connect(ExceptionSink *xsink)
opens a connection and returns a code giving the result
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
DLLEXPORT bool isSecure() const
returns the SSL connection parameter flag
DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink *xsink)
set options with a hash, returns -1 if an exception was thrown, 0 for OK
DLLEXPORT QoreHttpClientObject()
creates the QoreHttpClientObject object
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
DLLEXPORT void setTimeout(int to)
sets the connection and response packet timeout value in milliseconds
DLLEXPORT int getMaxRedirects() const
returns the value of the max_redirects option
DLLEXPORT void setDefaultPath(const char *pth)
sets the default path
DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink)
sets the proxy URL
DLLEXPORT void addProtocol(const char *prot, int port, bool ssl=false)
adds a protocol
virtual DLLEXPORT ~QoreHttpClientObject()
destroys the object and frees all associated memory
DLLEXPORT int setURL(const char *url, ExceptionSink *xsink)
sets the connection URL
DLLEXPORT void setDefaultPort(int prt)
sets the default port
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT void setHTTP11(bool h11)
sets or clears HTTP 1.1 protocol compliance
DLLEXPORT void setConnectTimeout(int ms)
sets the connect timeout in ms
DLLEXPORT AbstractQoreNode * post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP &quot;POST&quot; message to the remote server and returns the message body of the response...
DLLEXPORT bool getNoDelay() const
returns the value of the TCP_NODELAY flag on the object
DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val)
sets the value of a default header to send with every outgoing message
DLLEXPORT void setUserPassword(const char *user, const char *pass)
sets the username and password for the connection
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:67
DLLEXPORT int setHTTPVersion(const char *version, ExceptionSink *xsink)
sets the http version from a string
DLLEXPORT void setMaxRedirects(int max)
sets the max_redirects option
DLLEXPORT bool isConnected() const
returns the connection status of the object
DLLEXPORT const char * getHTTPVersion() const
returns the http version as a string (either &quot;1.0&quot; or &quot;1.1&quot;)
DLLEXPORT void setEncoding(const QoreEncoding *qe)
sets the default encoding for the object
DLLEXPORT void disconnect()
disconnects from the remote server
DLLEXPORT int getTimeout() const
returns the connection and response packet timeout value in milliseconds
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
provides a way to communicate with HTTP servers using Qore data structures
Definition: QoreHttpClientObject.h:50
DLLEXPORT void setProxySecure(bool is_secure)
sets the SSL flag for use in the next connection to the proxy
DLLEXPORT QoreStringNode * getProxyURL()
returns the proxy connection parameters as a URL (or 0 if there is none), caller owns the reference c...
DLLEXPORT int setNoDelay(bool nodelay)
sets the TCP_NODELAY flag on the object
DLLEXPORT const char * getConnectionPath() const
returns the current connection path or 0 if none is set
DLLEXPORT const char * getDefaultPath() const
returns the default path or 0 if none is set
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:228
DLLEXPORT int getConnectTimeout() const
returns the connect timeout in ms, negative numbers mean no timeout
base class for resolved call references
Definition: CallReferenceNode.h:130
DLLEXPORT const QoreEncoding * getEncoding() const
returns the default encoding for the object
DLLEXPORT bool isHTTP11() const
returns true if HTTP 1.1 protocol compliance has been set
DLLEXPORT void setSecure(bool is_secure)
sets the SSL flag for use in the next connection
DLLEXPORT void clearUserPassword()
clears the username and password for the connection
DLLEXPORT void setEventQueue(Queue *cbq, ExceptionSink *xsink)
sets the event queue, must be already referenced before call
DLLEXPORT void setProxyUserPassword(const char *user, const char *pass)
sets the username and password for the proxy connection
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...
DLLEXPORT void clearProxyURL()
clears the proxy URL