1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <libtest/common.h>
24 #if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
25 #include <curl/curl.h>
33 #define YATL_USERAGENT "YATL/1.0"
36 http_get_result_callback(void *ptr
, size_t size
, size_t nmemb
, void *data
)
38 size_t body_size
= size
* nmemb
;
40 vchar_t
*_body
= (vchar_t
*)data
;
42 _body
->resize(size
* nmemb
);
43 memcpy(&_body
[0], ptr
, _body
->size());
49 static void init(CURL
*curl
, const std::string
& url
)
53 #if defined(HAVE_LIBCURL) && HAVE_LIBCURL
55 curl_easy_setopt(curl
, CURLOPT_URL
, url
.c_str());
56 curl_easy_setopt(curl
, CURLOPT_USERAGENT
, YATL_USERAGENT
);
65 #if defined(HAVE_LIBCURL) && HAVE_LIBCURL
66 CURL
*curl
= curl_easy_init();
70 curl_easy_setopt(curl
, CURLOPT_WRITEFUNCTION
, http_get_result_callback
);
71 curl_easy_setopt(curl
, CURLOPT_WRITEDATA
, (void *)&_body
);
73 CURLcode retref
= curl_easy_perform(curl
);
74 curl_easy_getinfo(curl
, CURLINFO_RESPONSE_CODE
, _response
);
76 curl_easy_cleanup(curl
);
78 return retref
== CURLE_OK
;
89 #if defined(HAVE_LIBCURL) && HAVE_LIBCURL
90 CURL
*curl
= curl_easy_init();;
94 curl_easy_setopt(curl
, CURLOPT_POSTFIELDSIZE
, _body
.size());
95 curl_easy_setopt(curl
, CURLOPT_POSTFIELDS
, (void *)&_body
[0]);
97 CURLcode retref
= curl_easy_perform(curl
);
98 curl_easy_getinfo(curl
, CURLINFO_RESPONSE_CODE
, _response
);
100 curl_easy_cleanup(curl
);
107 bool TRACE::execute()
111 #if defined(HAVE_LIBCURL) && HAVE_LIBCURL
112 CURL
*curl
= curl_easy_init();;
116 curl_easy_setopt(curl
, CURLOPT_CUSTOMREQUEST
, "TRACE");
117 curl_easy_setopt(curl
, CURLOPT_WRITEFUNCTION
, http_get_result_callback
);
118 curl_easy_setopt(curl
, CURLOPT_WRITEDATA
, (void *)&_body
[0]);
120 CURLcode retref
= curl_easy_perform(curl
);
121 curl_easy_getinfo(curl
, CURLINFO_RESPONSE_CODE
, _response
);
123 curl_easy_cleanup(curl
);
125 return retref
== CURLE_OK
;
136 #if defined(HAVE_LIBCURL) && HAVE_LIBCURL
137 CURL
*curl
= curl_easy_init();;
141 curl_easy_setopt(curl
, CURLOPT_CUSTOMREQUEST
, "HEAD");
142 curl_easy_setopt(curl
, CURLOPT_WRITEFUNCTION
, http_get_result_callback
);
144 CURLcode retref
= curl_easy_perform(curl
);
145 curl_easy_getinfo(curl
, CURLINFO_RESPONSE_CODE
, _response
);
147 curl_easy_cleanup(curl
);
149 return retref
== CURLE_OK
;
157 } // namespace libtest