[Cmake-commits] [cmake-commits] zach.mullen committed cmSystemTools.cxx 1.422 1.423 cmSystemTools.h 1.165 1.166
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Dec 21 15:20:00 EST 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv4540
Modified Files:
cmSystemTools.cxx cmSystemTools.h
Log Message:
Added functionality to allow CTest to easily access web APIs. This will be used for better communication with CDash.
Index: cmSystemTools.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.h,v
retrieving revision 1.165
retrieving revision 1.166
diff -C 2 -d -r1.165 -r1.166
*** cmSystemTools.h 21 Dec 2009 17:27:04 -0000 1.165
--- cmSystemTools.h 21 Dec 2009 20:19:57 -0000 1.166
***************
*** 47,50 ****
--- 47,62 ----
KeyWOW64 view = KeyWOW64_Default);
+ enum HTTPMethod {
+ HTTP_GET,
+ HTTP_POST
+ };
+
+ /**
+ * Perform an HTTP request.
+ */
+ static int HTTPRequest(std::string url, HTTPMethod method,
+ std::string& response,
+ std::string fields = "", int timeout = 10);
+
/**
* Platform independent escape spaces, unix uses backslash,
Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.422
retrieving revision 1.423
diff -C 2 -d -r1.422 -r1.423
*** cmSystemTools.cxx 21 Dec 2009 17:27:04 -0000 1.422
--- cmSystemTools.cxx 21 Dec 2009 20:19:57 -0000 1.423
***************
*** 39,42 ****
--- 39,44 ----
#endif
+ #include "cm_curl.h"
+
#include <sys/stat.h>
***************
*** 2926,2927 ****
--- 2928,2979 ----
#endif
}
+
+ //----------------------------------------------------------------------------
+ static size_t
+ HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data)
+ {
+ register int realsize = (int)(size * nmemb);
+
+ std::string *response
+ = static_cast<std::string*>(data);
+ const char* chPtr = static_cast<char*>(ptr);
+ *response += chPtr;
+
+ return realsize;
+ }
+
+ //----------------------------------------------------------------------------
+ int cmSystemTools::HTTPRequest(std::string url, HTTPMethod method,
+ std::string& response,
+ std::string fields, int timeout)
+ {
+ CURL* curl;
+ ::curl_global_init(CURL_GLOBAL_ALL);
+ curl = ::curl_easy_init();
+
+ //set request options
+ if(method == cmSystemTools::HTTP_GET && fields.size())
+ {
+ url += "?" + fields;
+ }
+ else
+ {
+ ::curl_easy_setopt(curl, CURLOPT_POST, 1);
+ ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
+ }
+ ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+ ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+
+ //set response options
+ ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback);
+ ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&response);
+ ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+
+ CURLcode res = ::curl_easy_perform(curl);
+
+ ::curl_easy_cleanup(curl);
+ ::curl_global_cleanup();
+
+ return static_cast<int>(res);
+ }
More information about the Cmake-commits
mailing list