35 #include <curl/curl.h> 46 CURLcode ret = curl_global_init(CURL_GLOBAL_ALL);
49 ROS_ERROR(
"Error initializing libcurl! retcode = %d", ret);
61 curl_global_cleanup();
71 curl_handle_ = curl_easy_init();
78 curl_easy_cleanup(curl_handle_);
84 std::vector<uint8_t>
v;
87 size_t curlWriteFunc(
void* buffer,
size_t size,
size_t nmemb,
void* userp)
91 size_t prev_size = membuf->
v.size();
92 membuf->
v.resize(prev_size + size * nmemb);
93 memcpy(&membuf->
v[prev_size], buffer, size * nmemb);
100 std::string mod_url = url;
101 if (url.find(
"package://") == 0)
103 mod_url.erase(0, strlen(
"package://"));
104 size_t pos = mod_url.find(
"/");
105 if (pos == std::string::npos)
107 throw Exception(url,
"Could not parse package:// format into file:// format");
110 std::string
package = mod_url.substr(0, pos);
111 mod_url.erase(0, pos);
114 if (package_path.empty())
119 mod_url =
"file://" + package_path + mod_url;
122 curl_easy_setopt(curl_handle_, CURLOPT_URL, mod_url.c_str());
123 curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION,
curlWriteFunc);
125 char error_buffer[CURL_ERROR_SIZE];
126 curl_easy_setopt(curl_handle_, CURLOPT_ERRORBUFFER , error_buffer);
130 curl_easy_setopt(curl_handle_, CURLOPT_WRITEDATA, &buf);
132 CURLcode ret = curl_easy_perform(curl_handle_);
137 else if (!buf.
v.empty())
139 res.
size = buf.
v.size();
140 res.
data.reset(
new uint8_t[res.
size+1]);
141 memcpy(res.
data.get(), &buf.
v[0], res.
size);
size_t curlWriteFunc(void *buffer, size_t size, size_t nmemb, void *userp)
static CURLStaticInit g_curl_init
boost::shared_array< uint8_t > data
A combination of a pointer to data in memory along with the data's size.
ROSLIB_DECL std::string getPath(const std::string &package_name)
MemoryResource get(const std::string &url)
Get a file and store it in memory.