Browse Source

- prepared fetchfile, needs further work

master
parent
commit
90d276e4ad
3 changed files with 73 additions and 3 deletions
  1. +8
    -0
      src/CMakeLists.txt
  2. +18
    -3
      src/include/fetchfile.hpp
  3. +47
    -0
      src/lib/fetchfile.cpp

+ 8
- 0
src/CMakeLists.txt View File

@ -20,6 +20,14 @@ message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR})
link_directories(${OPENSSL_LIBRARIES})
#find_package(Poco COMPONENTS net)
#message("POCO include dir: ${POCO_INCLUDE_DIR}")
#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"
)


+ 18
- 3
src/include/fetchfile.hpp View File

@ -1,11 +1,26 @@
#ifndef LIBCBAG_FETCHFILE
#define LIBCBAG_FETCHFILE
#include <string>
#include <list>
using namespace std;
class fetchfile{
typedef string url_t;
typedef string filename_t;
typedef struct {
url_t url;
size_t size;
filename_t filename;
} fetch_t;
class Fetchfile{
private:
string basedir;
list<fetch_t> entries;
public:
fetchfile();
Fetchfile( string basedir );
list<fetch_t> get_entries();
bool fetch(list<string> &log, url_t);
bool fetch_all_entries();
bool validate();
};
#endif
// vim: set tabstop=4
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 47
- 0
src/lib/fetchfile.cpp View File

@ -0,0 +1,47 @@
//#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 <string>
#include <iostream>
#include <memory>
#include "fetchfile.hpp"
using namespace std;
Fetchfile::Fetchfile( string basedir ) {
Fetchfile::basedir = basedir;
}
bool Fetchfile::fetch( list<string> &log, url_t url ) {
//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;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

Loading…
Cancel
Save