Browse Source

- changed to use libcurl

master
Andreas Romeyke 2 years ago
parent
commit
57100a1724
5 changed files with 80 additions and 38 deletions
  1. +7
    -0
      README.compile
  2. +7
    -3
      src/CMakeLists.txt
  3. +1
    -1
      src/include/fetchfile.hpp
  4. +49
    -27
      src/lib/fetchfile.cpp
  5. +16
    -7
      test/CMakeLists.txt

+ 7
- 0
README.compile View File

@ -0,0 +1,7 @@
HINTs
=====
Sometimes you got a linker error: usr/bin/ld: warning: libssl.so.1.0.2, needed by /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libcurl.so, may conflict with libssl.so.1.1
then you must set the OPENSSL_PACKAGE_VERSION to right version number.
You could try "cmake -DCMAKE_FIND_PACKAGE_SORT_DIRECTION=ASC"

+ 7
- 3
src/CMakeLists.txt View File

@ -25,13 +25,16 @@ link_directories(${OPENSSL_LIBRARIES})
#message("POCO libraries: ${POCO_LIBRARIES}")
#include_directories(${POCO_INCLUDE_DIR})
#link_directories(${POCO_LIBRARIES})
find_library(POCO_FOUNDATION PocoFoundation)
find_library(POCO_NET PocoNet)
file( GLOB libcbag_SOURCES_LIB
"lib/*.cpp"
)
find_package(CURL REQUIRED)
message("Curl include dir: ${CURL_INCLUDE_DIR}")
message("Curl libraries: ${CURL_LIBRARIES}")
include_directories(${CURL_INCLUDE_DIR})
link_directories(${CURL_LIBRARIES})
#file( GLOB libcbag_SOURCES_LIB
# "${PROJECT_SOURCE_DIR}/lib/*.cpp"
@ -48,4 +51,5 @@ add_executable(test_payload examples/test_payload.cpp ${libcbag_SOURCES_lib})
TARGET_LINK_LIBRARIES(test_payload ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cbag)
#add_executable(test_bag ${PROJECT_SOURCE_DIR}/examples/test_bag.cpp ${libcbag_SOURCES_lib})
add_executable(test_bag examples/test_bag.cpp ${libcbag_SOURCES_lib})
TARGET_LINK_LIBRARIES(test_bag ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${POCO_NET_LIBRARIES} cbag)
#TARGET_LINK_LIBRARIES(test_bag ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${POCO_NET_LIBRARIES} cbag)
TARGET_LINK_LIBRARIES(test_bag ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} cbag)

+ 1
- 1
src/include/fetchfile.hpp View File

@ -17,7 +17,7 @@ class Fetchfile{
public:
Fetchfile( string basedir );
list<fetch_t> get_entries();
bool fetch(list<string> &log, url_t);
bool fetch(list<string> &log, fetch_t);
bool fetch_all_entries();
bool validate( list<string> &log );
};


+ 49
- 27
src/lib/fetchfile.cpp View File

@ -1,24 +1,25 @@
//#include <urdl/istream.hpp>
// using Poco::Net
#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/Net/FTPStreamFactory.h"
using Poco::URIStreamOpener;
using Poco::StreamCopier;
using Poco::Path;
using Poco::URI;
using Poco::Exception;
using Poco::Net::HTTPStreamFactory;
using Poco::Net::FTPStreamFactory;
//#include "Poco/URIStreamOpener.h"
//#include "Poco/StreamCopier.h"
//#include "Poco/Path.h"
//#include "Poco/URI.h"
//#include "Poco/Exception.h"
//#include "Poco/Net/HTTPStreamFactory.h"
//#include "Poco/Net/FTPStreamFactory.h"
//using Poco::URIStreamOpener;
//using Poco::StreamCopier;
//using Poco::Path;
//using Poco::URI;
//using Poco::Exception;
//using Poco::Net::HTTPStreamFactory;
//using Poco::Net::FTPStreamFactory;
#include <string>
#include <iostream>
#include <memory>
#include <curl/curl.h>
#include "fetchfile.hpp"
using namespace std;
@ -27,21 +28,42 @@ Fetchfile::Fetchfile( string basedir ) {
Fetchfile::basedir = basedir;
}
bool Fetchfile::fetch( list<string> &log, url_t url ) {
bool Fetchfile::fetch( list<string> &log, fetch_t fetch ) {
//urdl::istream filestream (url);
// using Poco::Net
HTTPStreamFactory::registerFactory();
FTPStreamFactory::registerFactory();
try {
URI uri(url);
unique_ptr<istream> pStr(URIStreamOpener::defaultOpener().open(uri));
StreamCopier::copyStream(*pStr.get(), std::cout);
} catch (Exception &e) {
log.push_back( "Unable to open URL '" + url + "', because '" + e.displayText() + "'" );
return false;
}
return true;
// HTTPStreamFactory::registerFactory();
// FTPStreamFactory::registerFactory();
// try {
// URI uri(url);
// unique_ptr<istream> pStr(URIStreamOpener::defaultOpener().open(uri));
// StreamCopier::copyStream(*pStr.get(), std::cout);
// } catch (Exception &e) {
// log.push_back( "Unable to open URL '" + url + "', because '" + e.displayText() + "'" );
// return false;
// }
CURL *curl;
FILE *fp;
CURLcode result;
curl = curl_easy_init();
if (curl) {
fp = fopen( fetch.filename.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_URL, fetch.url.c_str());
// FIXME: curl needs a write function if WIN32,
// see https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html#DESCRIPTION
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
} else {
return false;
}
return true;
}
bool Fetchfile::validate(list<string> &log) {
return true;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 16
- 7
test/CMakeLists.txt View File

@ -20,12 +20,20 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
#message("POCO libraries: ${POCO_LIBRARIES}")
#include_directories(${POCO_INCLUDE_DIR})
#link_directories(${POCO_LIBRARIES})
find_library(POCO_FOUNDATION PocoFoundation)
find_library(POCO_NET PocoNet)
set(POCO_NET_INCLUDE_DIR /usr/include)
set(POCO_NET_LIBRARIES ${POCO_NET_FILEPATH})
message("POCO include dir: ${POCO_NET_INCLUDE_DIR}")
message("POCO libraries: ${POCO_NET_LIBRARIES}")
#find_library(POCO PocoNet)
#find_path(POCO_NET_INCLUDE_DIR "Poco/URI.h")
#set(POCO_NET_INCLUDE_DIR "/usr/include")
#set(POCO_NET_LIBRARIES "libPocoNet.so")
#find_path(POCO_NET_LIBRARY "libPocoNet.so")
#message("POCO found: ${POCO_FOUND}")
#message("POCO include dir: ${POCO_INCLUDE_DIR}")
#message("POCO library: ${POCO_LIBRARY}")
#message("POCO libraries: ${POCO_LIBRARIES}")
find_package(CURL REQUIRED)
message("Curl include dir: ${CURL_INCLUDE_DIR}")
message("Curl libraries: ${CURL_LIBRARIES}")
include_directories(${CURL_INCLUDE_DIR})
link_directories(${CURL_LIBRARIES})
add_executable(TestBag testbag.cpp)
add_executable(TestPayload test_payload.cpp)
@ -38,6 +46,7 @@ target_link_libraries(TestPayload ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES
target_link_libraries(TestPayloadManifest ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cbag)
target_link_libraries(TestTagManifest ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cbag)
target_link_libraries(TestBagMetadata ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cbag)
target_link_libraries(TestFetchFile ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${POCO_NET_LIBRARIES} cbag)
#target_link_libraries(TestFetchFile ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${POCO_NET_LIBRARY} cbag)
target_link_libraries(TestFetchFile ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARY} cbag)

Loading…
Cancel
Save