Qore Programming Language  0.8.9
 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 
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 
234 
241  DLLEXPORT AbstractQoreNode *get(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
242 
244 
250  DLLEXPORT QoreHashNode *head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
251 
253 
262  DLLEXPORT AbstractQoreNode *post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink);
263 
265 
269  DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val);
270 
273 
276  DLLEXPORT virtual void deref(ExceptionSink *xsink);
277 
279 
282  DLLEXPORT void setConnectTimeout(int ms);
283 
285 
288  DLLEXPORT int getConnectTimeout() const;
289 
291 
300  DLLEXPORT int setNoDelay(bool nodelay);
301 
303  DLLEXPORT void setEventQueue(Queue *cbq, ExceptionSink *xsink);
304 
306  DLLEXPORT bool getNoDelay() const;
307 
309  DLLEXPORT bool isConnected() const;
310 
311  DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
312  DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, class Queue* wq, AbstractQoreNode* arg, int64 min_ms = 1000);
313  DLLEXPORT QoreHashNode* getUsageInfo() const;
314  DLLEXPORT void clearStats();
315 
316  DLLLOCAL static void static_init();
317 
318  DLLLOCAL void cleanup(ExceptionSink *xsink);
319 };
320 
321 #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:72
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 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:41
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:47
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:40
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:57
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
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
provides a way to communicate with HTTP servers using Qore data structures
Definition: QoreHttpClientObject.h:42
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
DLLEXPORT int getConnectTimeout() const
returns the connect timeout in ms, negative numbers mean no timeout
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