MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / curlcon

Function curlcon

samples/conntest.cpp:32–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31#ifdef EXV_USE_CURL
32void curlcon(const std::string& url, bool useHttp1_0 = false) {
33 CURL* curl = curl_easy_init();
34 if (!curl) {
35 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Unable to init libcurl.");
36 }
37
38 // get the timeout value
39 std::string timeoutStr = Exiv2::getEnv(Exiv2::envTIMEOUT);
40 long timeout = atol(timeoutStr.c_str());
41 if (timeout == 0) {
42 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer.");
43 }
44
45 std::string response;
46 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
47 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Exiv2::curlWriter);
48 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
49 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
50 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
51 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
52 // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // debug
53 if (useHttp1_0)
54 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
55 else
56 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
57
58 /* Perform the request, res will get the return code */
59 CURLcode res = curl_easy_perform(curl);
60 if (res != CURLE_OK) { // error happened
61 throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, curl_easy_strerror(res));
62 }
63
64 // get return code
65 long returnCode;
66 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &returnCode); // get code
67 curl_easy_cleanup(curl);
68
69 if (returnCode >= 400 || returnCode < 0) {
70 throw Exiv2::Error(Exiv2::ErrorCode::kerTiffDirectoryTooLarge, "Server", returnCode);
71 }
72}
73#endif
74
75int main(int argc, const char** argv) {

Callers 1

mainFunction · 0.85

Calls 3

ErrorFunction · 0.85
getEnvFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected