20 #ifndef URL_H_9DAEGSMV
21 #define URL_H_9DAEGSMV
32 #include <condition_variable>
40 virtual void downloadStarted(
const URL& url) {};
41 virtual void downloadCompleted(
const URL& url) {};
42 virtual void downloadFailed(
const URL& url,
int errorCode) {};
43 virtual void headerChunkReceived(
const URL& url,
const std::string& headerChunk) {};
44 virtual void contentChunkReceived(
const URL& url,
const std::string& contentChunk) {};
52 class USCXML_API
URLImpl :
public std::enable_shared_from_this<URLImpl> {
54 URLImpl(
const std::string& url);
57 bool isAbsolute()
const;
58 std::string scheme()
const;
59 std::string userInfo()
const;
60 std::string host()
const;
61 std::string port()
const;
62 std::string fragment()
const;
63 std::map<std::string, std::string> query()
const;
64 std::string path()
const;
65 std::list<std::string> pathComponents()
const;
70 static URL resolveWithCWD(
URLImpl* relativeURL);
74 _monitors.insert(monitor);
77 _monitors.erase(monitor);
81 void addOutHeader(
const std::string& key,
const std::string& value);
82 void setOutContent(
const std::string& content);
83 void setRequestType(URLRequestType requestType);
84 const std::map<std::string, std::string> getInHeaderFields();
85 const std::string getInHeaderField(
const std::string& key);
87 const std::string getStatusCode()
const;
88 const std::string getStatusMessage()
const;
89 const std::string getInContent(
bool forceReload =
false);
90 const void download(
bool blocking =
false);
92 operator Data()
const;
93 operator std::string()
const;
100 void* getCurlHandle();
101 static size_t writeHandler(
void *ptr,
size_t size,
size_t nmemb,
void *userdata);
102 static size_t headerHandler(
void *ptr,
size_t size,
size_t nmemb,
void *userdata);
104 void downloadStarted();
105 void downloadCompleted();
106 void downloadFailed(
int errorCode);
108 static void prepareException(
ErrorEvent& exception,
int errorCode,
const std::string& origUri,
void* parser);
110 void* _handle = NULL;
111 std::stringstream _rawInContent;
112 std::stringstream _rawInHeader;
113 std::map<std::string, std::string> _inHeaders;
115 std::string _outContent;
116 std::map<std::string, std::string> _outHeader;
117 URLRequestType _requestType;
119 std::string _statusCode;
120 std::string _statusMsg;
121 bool _isDownloaded =
false;
122 bool _hasFailed =
false;
125 std::condition_variable_any _condVar;
126 std::recursive_mutex _mutex;
128 std::set<URLMonitor*> _monitors;
137 URL(
const std::string url) : _impl(
new URLImpl(url)) {}
143 static std::string getResourceDir();
150 static std::string getTempDir(
bool shared =
true);
153 return _impl->isAbsolute();
156 std::string scheme() {
157 return _impl->scheme();
160 std::string userInfo() {
161 return _impl->userInfo();
165 return _impl->host();
169 return _impl->port();
172 std::string fragment() {
173 return _impl->fragment();
176 std::map<std::string, std::string> query() {
177 return _impl->query();
181 return _impl->path();
184 std::list<std::string> pathComponents() {
185 return _impl->pathComponents();
189 return _impl->normalize();
192 static URL resolve(
URL relativeURL,
URL absoluteURL) {
193 return URLImpl::resolve(relativeURL._impl.get(), absoluteURL._impl.get());
196 static URL resolveWithCWD(
URL relativeURL) {
197 return URLImpl::resolveWithCWD(relativeURL._impl.get());
200 static URL refer(
URL absoluteSource,
URL absoluteBase) {
201 return URLImpl::refer(absoluteSource._impl.get(), absoluteBase._impl.get());
204 void addOutHeader(
const std::string& key,
const std::string& value) {
205 return _impl->addOutHeader(key, value);
208 void setOutContent(
const std::string& content) {
209 return _impl->setOutContent(content);
211 void setRequestType(URLRequestType requestType) {
212 return _impl->setRequestType(requestType);
215 const std::map<std::string, std::string> getInHeaderFields() {
216 return _impl->getInHeaderFields();
219 const std::string getInHeaderField(
const std::string& key) {
220 return _impl->getInHeaderField(key);
223 const std::string getStatusCode()
const {
224 return _impl->getStatusCode();
227 const std::string getStatusMessage()
const {
228 return _impl->getStatusMessage();
231 const std::string getInContent(
bool forceReload =
false) {
232 return _impl->getInContent(forceReload);
235 const void download(
bool blocking =
false)
const {
236 return _impl->download(blocking);
240 return _impl->addMonitor(monitor);
243 return _impl->removeMonitor(monitor);
246 operator Data()
const {
247 return _impl->operator
Data();
250 operator std::string() {
251 return (*_impl.get());
255 std::shared_ptr<URLImpl> _impl;
257 static std::string currTmpDir;
263 static void fetchURL(
URL& url);
264 static void breakURL(
URL& url);
276 static void run(
void* instance);
279 std::thread* _thread;
280 std::condition_variable_any _condVar;
281 std::recursive_mutex _mutex;
284 std::map<void*, URL> _handlesToURLs;
285 std::map<void*, void*> _handlesToHeaders;
286 void* _multiHandle = NULL;
287 char* _envProxy = NULL;
Definition: Breakpoint.cpp:26
#define PIMPL_OPERATORS(type)
The usual operators as required for the PIMPL pattern.
Definition: Common.h:68