pax_global_header00006660000000000000000000000064125602307720014516gustar00rootroot0000000000000052 comment=60c44397066d8be31c99d694b815d1976d3d6f1f ros-resource-retriever-1.11.6/000077500000000000000000000000001256023077200162415ustar00rootroot00000000000000ros-resource-retriever-1.11.6/CHANGELOG.rst000066400000000000000000000012621256023077200202630ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package resource_retriever ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.11.6 (2014-11-30) ------------------- 1.11.5 (2014-07-24) ------------------- 1.11.4 (2014-07-07) ------------------- 1.11.3 (2014-06-24) ------------------- 1.11.2 (2014-03-22) ------------------- 1.11.1 (2014-03-20) ------------------- 1.11.0 (2014-02-21) ------------------- 1.10.18 (2013-12-04) -------------------- * add DEPENDS for kdl_parser * Contributors: Ioan Sucan 1.10.16 (2013-11-18) -------------------- * check for CATKIN_ENABLE_TESTING 1.10.15 (2013-08-17) -------------------- * resource_retriever: install python package using setup.py ros-resource-retriever-1.11.6/CMakeLists.txt000066400000000000000000000016401256023077200210020ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(resource_retriever) find_package(catkin REQUIRED COMPONENTS rosconsole roslib) catkin_python_setup() catkin_package( LIBRARIES ${PROJECT_NAME} INCLUDE_DIRS include) include_directories(include) find_package(catkin REQUIRED COMPONENTS rosconsole roslib) include_directories(${catkin_INCLUDE_DIRS}) link_directories(${catkin_LIBRARY_DIRS}) include(FindCURL) if(NOT CURL_FOUND) message("CURL not found! Aborting...") fail() endif(NOT CURL_FOUND) include_directories(${CURL_INCLUDE_DIRS}) add_library(${PROJECT_NAME} src/retriever.cpp) target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES} ${catkin_LIBRARIES}) if(CATKIN_ENABLE_TESTING) add_subdirectory(test EXCLUDE_FROM_ALL) endif() install(TARGETS ${PROJECT_NAME} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) ros-resource-retriever-1.11.6/include/000077500000000000000000000000001256023077200176645ustar00rootroot00000000000000ros-resource-retriever-1.11.6/include/resource_retriever/000077500000000000000000000000001256023077200236025ustar00rootroot00000000000000ros-resource-retriever-1.11.6/include/resource_retriever/retriever.h000066400000000000000000000054631256023077200257720ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef RESOURCE_RETRIEVER_RETRIEVER_H #define RESOURCE_RETRIEVER_RETRIEVER_H #include #include #include #include typedef void CURL; namespace resource_retriever { class Exception : public std::runtime_error { public: Exception(const std::string& file, const std::string& error_msg) : std::runtime_error("Error retrieving file [" + file + "]: " + error_msg) {} }; /** * \brief A combination of a pointer to data in memory along with the data's size. */ struct MemoryResource { MemoryResource() : size(0) {} boost::shared_array data; uint32_t size; }; /** * \brief Retrieves files from from a url. Caches a CURL handle so multiple accesses to a single url * will keep connections open. */ class Retriever { public: Retriever(); ~Retriever(); /** * \brief Get a file and store it in memory * \param url The url to retrieve. package://package/file will be turned into the correct file:// invocation * \return The file, loaded into memory * \throws resource_retriever::Exception if anything goes wrong. */ MemoryResource get(const std::string& url); private: CURL* curl_handle_; }; } // namespace resource_retriever #endif // RESOURCE_RETRIEVER_RETRIEVER_H ros-resource-retriever-1.11.6/mainpage.dox000066400000000000000000000005301256023077200205340ustar00rootroot00000000000000/** \mainpage \htmlinclude manifest.html \b resource_retriever is a package used for downloading files from a url. It also provides special handling of the package:// prefix, allowing things to be referenced by path relative to a package. \section codeapi Code API - resource_retriever::Retriever -- Use this class to download files. */ros-resource-retriever-1.11.6/package.xml000066400000000000000000000022251256023077200203570ustar00rootroot00000000000000 resource_retriever 1.11.6 This package retrieves data from url-format files such as http://, ftp://, package:// file://, etc., and loads the data into memory. The package:// url for ros packages is translated into a local file:// url. The resourse retriever was initially designed to load mesh files into memory, but it can be used for any type of data. The resource retriever is based on the the libcurl library. Josh Faust Ioan Sucan BSD http://ros.org/wiki/resource_retriever https://github.com/ros/robot_model https://github.com/ros/robot_model/issues catkin curl rosconsole roslib curl rosconsole roslib ros-resource-retriever-1.11.6/setup.py000066400000000000000000000003421256023077200177520ustar00rootroot00000000000000from distutils.core import setup from catkin_pkg.python_setup import generate_distutils_setup d = generate_distutils_setup() d['packages'] = ['resource_retriever'] d['scripts'] = [] d['package_dir'] = {'': 'src'} setup(**d) ros-resource-retriever-1.11.6/src/000077500000000000000000000000001256023077200170305ustar00rootroot00000000000000ros-resource-retriever-1.11.6/src/resource_retriever/000077500000000000000000000000001256023077200227465ustar00rootroot00000000000000ros-resource-retriever-1.11.6/src/resource_retriever/__init__.py000066400000000000000000000051621256023077200250630ustar00rootroot00000000000000# Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of the Willow Garage nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # import roslib; roslib.load_manifest('resource_retriever') import subprocess import urlgrabber, string PACKAGE_PREFIX = 'package://' def rospack_find(package): process = subprocess.Popen(['rospack', 'find', package], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = process.communicate() if len(stderr) > 0: raise Exception(stderr) else: return string.strip(stdout) def get_filename(url, use_protocol=True ): mod_url = url if url.find(PACKAGE_PREFIX) == 0: mod_url = url[len(PACKAGE_PREFIX):] pos = mod_url.find('/') if pos == -1: raise Exception("Could not parse package:// format into file:// format for "+url) package = mod_url[0:pos] mod_url = mod_url[pos:] package_path = rospack_find(package) if use_protocol: protocol = "file://" else: protocol = "" mod_url = protocol + package_path + mod_url; return mod_url def get(url): return urlgrabber.urlopen(get_filename(url)) ros-resource-retriever-1.11.6/src/retriever.cpp000066400000000000000000000076171256023077200215560ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "resource_retriever/retriever.h" #include #include #include #include namespace resource_retriever { class CURLStaticInit { public: CURLStaticInit() : initialized_(false) { CURLcode ret = curl_global_init(CURL_GLOBAL_ALL); if (ret != 0) { ROS_ERROR("Error initializing libcurl! retcode = %d", ret); } else { initialized_ = true; } } ~CURLStaticInit() { if (initialized_) { curl_global_cleanup(); } } bool initialized_; }; static CURLStaticInit g_curl_init; Retriever::Retriever() { curl_handle_ = curl_easy_init(); } Retriever::~Retriever() { if (curl_handle_) { curl_easy_cleanup(curl_handle_); } } struct MemoryBuffer { std::vector v; }; size_t curlWriteFunc(void* buffer, size_t size, size_t nmemb, void* userp) { MemoryBuffer* membuf = (MemoryBuffer*)userp; size_t prev_size = membuf->v.size(); membuf->v.resize(prev_size + size * nmemb); memcpy(&membuf->v[prev_size], buffer, size * nmemb); return size * nmemb; } MemoryResource Retriever::get(const std::string& url) { std::string mod_url = url; if (url.find("package://") == 0) { mod_url.erase(0, strlen("package://")); size_t pos = mod_url.find("/"); if (pos == std::string::npos) { throw Exception(url, "Could not parse package:// format into file:// format"); } std::string package = mod_url.substr(0, pos); mod_url.erase(0, pos); std::string package_path = ros::package::getPath(package); if (package_path.empty()) { throw Exception(url, "Package [" + package + "] does not exist"); } mod_url = "file://" + package_path + mod_url; } curl_easy_setopt(curl_handle_, CURLOPT_URL, mod_url.c_str()); curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION, curlWriteFunc); char error_buffer[CURL_ERROR_SIZE]; curl_easy_setopt(curl_handle_, CURLOPT_ERRORBUFFER , error_buffer); MemoryResource res; MemoryBuffer buf; curl_easy_setopt(curl_handle_, CURLOPT_WRITEDATA, &buf); CURLcode ret = curl_easy_perform(curl_handle_); if (ret != 0) { throw Exception(mod_url, error_buffer); } else if (!buf.v.empty()) { res.size = buf.v.size(); res.data.reset(new uint8_t[res.size]); memcpy(res.data.get(), &buf.v[0], res.size); } return res; } } ros-resource-retriever-1.11.6/test/000077500000000000000000000000001256023077200172205ustar00rootroot00000000000000ros-resource-retriever-1.11.6/test/CMakeLists.txt000066400000000000000000000002411256023077200217550ustar00rootroot00000000000000set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) catkin_add_gtest(${PROJECT_NAME}_utest test.cpp) target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME}) ros-resource-retriever-1.11.6/test/test.cpp000066400000000000000000000065011256023077200207050ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2008, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include #include #include #include using namespace resource_retriever; TEST(Retriever, getByPackage) { try { Retriever r; MemoryResource res = r.get("package://"ROS_PACKAGE_NAME"/test/test.txt"); ASSERT_EQ(res.size, 1); ASSERT_EQ(res.data[0], 'A'); } catch (Exception& e) { FAIL(); } } TEST(Retriever, largeFile) { try { std::string path = ros::package::getPath(ROS_PACKAGE_NAME) + "/test/large_file.dat"; FILE* f = fopen(path.c_str(), "w"); ASSERT_TRUE(f); for (int i = 0; i < 1024*1024*50; ++i) { fprintf(f, "A"); } fclose(f); Retriever r; MemoryResource res = r.get("package://"ROS_PACKAGE_NAME"/test/large_file.dat"); ASSERT_EQ(res.size, 1024*1024*50); } catch (Exception& e) { FAIL(); } } TEST(Retriever, http) { try { Retriever r; MemoryResource res = r.get("http://pr.willowgarage.com/downloads/svnmerge.py"); ASSERT_GT(res.size, 0); } catch (Exception& e) { FAIL(); } } TEST(Retriever, invalidFiles) { Retriever r; try { r.get("file://fail"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } try { r.get("package://roscpp"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } try { r.get("package://invalid_package_blah/test.xml"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } } int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ros-resource-retriever-1.11.6/test/test.txt000066400000000000000000000000011256023077200207270ustar00rootroot00000000000000A