diff options
Diffstat (limited to 'linden/indra/newview/hippoRestRequest.cpp')
-rw-r--r-- | linden/indra/newview/hippoRestRequest.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/linden/indra/newview/hippoRestRequest.cpp b/linden/indra/newview/hippoRestRequest.cpp new file mode 100644 index 0000000..ab8a557 --- /dev/null +++ b/linden/indra/newview/hippoRestRequest.cpp | |||
@@ -0,0 +1,54 @@ | |||
1 | |||
2 | |||
3 | #include "hippoRestRequest.h" | ||
4 | |||
5 | #ifndef CURL_STATICLIB | ||
6 | #define CURL_STATICLIB 1 | ||
7 | #endif | ||
8 | #include <curl/curl.h> | ||
9 | |||
10 | #include <stdtypes.h> | ||
11 | #include <llerror.h> | ||
12 | |||
13 | |||
14 | static size_t curlWrite(void *ptr, size_t size, size_t nmemb, void *userData) | ||
15 | { | ||
16 | std::string *result = (std::string*)userData; | ||
17 | size_t bytes = (size * nmemb); | ||
18 | result->append((char*)ptr, bytes); | ||
19 | return nmemb; | ||
20 | } | ||
21 | |||
22 | |||
23 | //static | ||
24 | int HippoRestRequest::getBlocking(const std::string &url, std::string *result) | ||
25 | { | ||
26 | llinfos << "Requesting: " << url << llendl; | ||
27 | |||
28 | char curlErrorBuffer[CURL_ERROR_SIZE]; | ||
29 | CURL* curlp = curl_easy_init(); | ||
30 | |||
31 | curl_easy_setopt(curlp, CURLOPT_NOSIGNAL, 1); // don't use SIGALRM for timeouts | ||
32 | curl_easy_setopt(curlp, CURLOPT_TIMEOUT, 5); // seconds | ||
33 | |||
34 | curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, curlWrite); | ||
35 | curl_easy_setopt(curlp, CURLOPT_WRITEDATA, result); | ||
36 | curl_easy_setopt(curlp, CURLOPT_URL, url.c_str()); | ||
37 | curl_easy_setopt(curlp, CURLOPT_ERRORBUFFER, curlErrorBuffer); | ||
38 | curl_easy_setopt(curlp, CURLOPT_FAILONERROR, 1); | ||
39 | |||
40 | *result = ""; | ||
41 | S32 curlSuccess = curl_easy_perform(curlp); | ||
42 | S32 httpStatus = 499; | ||
43 | curl_easy_getinfo(curlp, CURLINFO_RESPONSE_CODE, &httpStatus); | ||
44 | |||
45 | if (curlSuccess != 0) { | ||
46 | llwarns << "CURL ERROR (HTTP Status " << httpStatus << "): " << curlErrorBuffer << llendl; | ||
47 | } else if (httpStatus != 200) { | ||
48 | llwarns << "HTTP Error " << httpStatus << ", but no Curl error." << llendl; | ||
49 | } | ||
50 | |||
51 | curl_easy_cleanup(curlp); | ||
52 | return httpStatus; | ||
53 | } | ||
54 | |||