Browse Source

- log is now private

master
Andreas Romeyke 2 years ago
parent
commit
2f99414816
22 changed files with 74 additions and 83 deletions
  1. +1
    -3
      src/examples/test_bag.cpp
  2. +1
    -1
      src/include/bag.hpp
  3. +2
    -1
      src/include/bagmetadata.hpp
  4. +3
    -0
      src/include/checksum.hpp
  5. +4
    -2
      src/include/fetchfile.hpp
  6. +2
    -1
      src/include/manifest.hpp
  7. +3
    -0
      src/include/othertags.hpp
  8. +2
    -1
      src/include/payload.hpp
  9. +1
    -1
      src/include/payloadmanifest.hpp
  10. +18
    -2
      src/lib/bagmetadata.cpp
  11. +1
    -1
      src/lib/checksum.cpp
  12. +2
    -33
      src/lib/fetchfile.cpp
  13. +4
    -4
      src/lib/manifest.cpp
  14. +1
    -1
      src/lib/payload.cpp
  15. +3
    -3
      src/lib/payloadmanifest.cpp
  16. +14
    -14
      src/lib/validate_bag.cpp
  17. +7
    -3
      test/test_bagmetadata.cpp
  18. +1
    -2
      test/test_fetchfile.cpp
  19. +1
    -2
      test/test_payload.cpp
  20. +1
    -3
      test/test_payloadmanifest.cpp
  21. +1
    -3
      test/test_tagmanifest.cpp
  22. +1
    -2
      test/testbag.cpp

+ 1
- 3
src/examples/test_bag.cpp View File

@ -11,10 +11,8 @@ int main(int argc, const char *argv[]) {
}
const string dir = argv[1];
Bag bag( dir );
stringstream log;
bool is_valid = bag.validate(log);
bool is_valid = bag.validate();
cout << "The bag '"<< dir <<"' is " << (is_valid ? "valid" : "invalid") << endl;
std::cout << log.str() << endl;
return 0;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab


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

@ -31,7 +31,7 @@ class Bag {
Bag();
Bag(string dfname);
bool store( string dfname);
bool validate( stringstream & log );
bool validate();
};
#endif
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 2
- 1
src/include/bagmetadata.hpp View File

@ -27,12 +27,13 @@ class Bagmetadata{
private:
map<string,string> metadata;
bool exist_bagmetadata_file;
stringstream log;
public:
Bagmetadata( string basedir );
bool has_bagmetadata();
map<string,string> get_metadata();
bool validate( stringstream & log );
bool validate();
bool has_oxum();
oxum_t get_oxum();
bool store( string basedir);


+ 3
- 0
src/include/checksum.hpp View File

@ -1,5 +1,6 @@
#ifndef LIBCBAG_CHECKSUM
#define LIBCBAG_CHECKSUM
#include <sstream>
#include <list>
#include <string>
#include <openssl/md5.h>
@ -28,6 +29,8 @@ SequentialEnum(checksum_algorithms,
string string_of_algorithm( checksum_algorithms alg);
class Checksum {
private:
stringstream log;
public:
//Checksum();
bool is_algorithm_supported( checksum_algorithms alg );


+ 4
- 2
src/include/fetchfile.hpp View File

@ -2,6 +2,7 @@
#define LIBCBAG_FETCHFILE
#include <string>
#include <list>
#include <sstream>
using namespace std;
typedef string url_t;
typedef string filename_t;
@ -14,12 +15,13 @@ class Fetchfile{
private:
string basedir;
list<fetch_t> entries;
stringstream log;
public:
Fetchfile( string basedir );
list<fetch_t> get_entries();
bool fetch(list<string> &log, fetch_t);
bool fetch(fetch_t);
bool fetch_all_entries();
bool validate( list<string> &log );
bool validate();
bool store( string basedir);
};


+ 2
- 1
src/include/manifest.hpp View File

@ -11,11 +11,12 @@ typedef string checksum_string_t;
class Manifest{
protected:
string basedir;
stringstream log;
map<checksum_algorithms,filename_t> manifest_algorithm_files;
public:
virtual multimap<checksum_string_t,filename_t> get_checksum_file_pairs(checksum_algorithms algorithm);
list<filename_t> get_checksummed_files();
virtual bool validate( stringstream & log );
virtual bool validate();
void debug();
bool store( string basedir);
};


+ 3
- 0
src/include/othertags.hpp View File

@ -1,8 +1,11 @@
#ifndef LIBCBAG_OTHERTAGS
#define LIBCBAG_OTHERTAGS
#include <string>
#include <sstream>
using namespace std;
class Othertags{
private:
stringstream log;
public:
Othertags( string basedir);
bool store( string basedir);


+ 2
- 1
src/include/payload.hpp View File

@ -12,11 +12,12 @@ class Payload{
private:
string basedir;
void scan_dir_recursively( fs::path directory, list<fs::path> &paths );
stringstream log;
public:
Payload( string basedir );
list<string> get_all_relative_paths();
list<string> get_all_absolute_paths();
bool validate(stringstream & log);
bool validate();
bool store( string basedir);
};
#endif


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

@ -10,7 +10,7 @@ using namespace std;
class Payloadmanifest : public Manifest {
public:
Payloadmanifest( string basedir );
bool validate( stringstream & log);
bool validate();
};
#endif


+ 18
- 2
src/lib/bagmetadata.cpp View File

@ -88,7 +88,7 @@ map <string,string> Bagmetadata::get_metadata() {
return this->metadata;
}
bool Bagmetadata::validate(stringstream & log ) {
bool Bagmetadata::validate() {
bool is_valid = true;
return is_valid;
}
@ -123,6 +123,22 @@ oxum_t Bagmetadata::get_oxum() {
}
bool Bagmetadata::store( string basedir ) {
return false;
fs::path p{ basedir };
fs::file_status s = fs::status( p );
if (! fs::is_directory( s)) {
Bagmetadata::log << "directory '" << basedir << "' does not exist" << endl;
return false;
}
string filename = basedir + "bag-info.txt";
ofstream baginfo_txt_file;
baginfo_txt_file.open( filename );
if (baginfo_txt_file.is_open()) {
for (map<string, string>::iterator it=this->metadata.begin(); it!=this->metadata.end(); ++it) {
baginfo_txt_file << (it->first) << " : " << (it->second) << endl;
}
baginfo_txt_file.close();
}
return true;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 1
- 1
src/lib/checksum.cpp View File

@ -53,7 +53,7 @@ string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) {
}
}
delete memBlock[];
delete[] memBlock;
// cout << "# # CHECKSUM for filepath '" << filepath << "' " << hex_result.str() << endl;
}else {
cout << "could not alloc memory" << endl;


+ 2
- 33
src/lib/fetchfile.cpp View File

@ -1,21 +1,3 @@
//#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>
@ -28,20 +10,7 @@ Fetchfile::Fetchfile( string basedir ) {
Fetchfile::basedir = basedir;
}
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;
// }
bool Fetchfile::fetch( fetch_t fetch ) {
CURL *curl;
CURLcode result;
curl = curl_easy_init();
@ -62,7 +31,7 @@ bool Fetchfile::fetch( list<string> &log, fetch_t fetch ) {
return true;
}
bool Fetchfile::validate(list<string> &log) {
bool Fetchfile::validate() {
return true;
}


+ 4
- 4
src/lib/manifest.cpp View File

@ -33,7 +33,7 @@ multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksu
return checksum_file_pairs;
}
bool Manifest::validate( stringstream & log ) {
bool Manifest::validate() {
Checksum checksum;
bool is_valid = true;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
@ -45,18 +45,18 @@ bool Manifest::validate( stringstream & log ) {
string calc_checksum = checksum.checksum_of_file( file, it->first );
//cout << "\t" << "file="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
if (calc_checksum.empty()) {
log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but file was not found" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but file was not found" << endl;
is_valid = false;
}
else if (0 != expected_checksum.compare( calc_checksum)) {
// cout << ( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected, but found: '" + calc_checksum + "'") << endl;
log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but found: '" << calc_checksum << "'" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but found: '" << calc_checksum << "'" << endl;
is_valid = false;
}
fs::path p{ file };
fs::file_status s = fs::status( p );
if (! fs::is_regular_file( p )) {
log << "Bagit file '" << file << "' does not exists in '" << this->basedir << "'" << endl;
this->log << "Bagit file '" << file << "' does not exists in '" << this->basedir << "'" << endl;
}
}
}


+ 1
- 1
src/lib/payload.cpp View File

@ -55,7 +55,7 @@ list<string> Payload::get_all_absolute_paths() {
return strpaths;
}
bool Payload::validate( stringstream & log ) {
bool Payload::validate() {
return true;
}


+ 3
- 3
src/lib/payloadmanifest.cpp View File

@ -37,14 +37,14 @@ Payloadmanifest::Payloadmanifest( string basedir ) {
//cout << "PAYLOADMANIFEST constructor, finished" << endl;
}
bool Payloadmanifest::validate( stringstream & log ) {
bool Payloadmanifest::validate() {
bool is_valid = true;
bool tmp = Manifest::validate( log );
bool tmp = Manifest::validate();
if (false == tmp) { is_valid = false; }
// check if at least one payload file exist
//cout << "payload_manifest: " << this->manifest_algorithm_files.size() << endl;
if (0 == this->manifest_algorithm_files.size()) {
log << "Bagit payloadmanifest count greater zero expected, but " << to_string(this->manifest_algorithm_files.size()) << " found" << endl;
this->log << "Bagit payloadmanifest count greater zero expected, but " << to_string(this->manifest_algorithm_files.size()) << " found" << endl;
is_valid = false;
}
//cout << "PAYLOADMANIFEST validate, calling debug()" << endl;


+ 14
- 14
src/lib/validate_bag.cpp View File

@ -4,25 +4,25 @@
#include <sstream>
bool Bag::validate( stringstream & log ) {
bool Bag::validate() {
bool is_valid = true;
if (this->bagit_version_major != 0) {
log << "Bagit major version 0 is expected, but got: " << to_string(this->bagit_version_major) << endl;
this->log << "Bagit major version 0 is expected, but got: " << to_string(this->bagit_version_major) << endl;
is_valid = false;
}
if (this->bagit_version_minor != 97) {
log << "Bagit minor version 97 is expected, but got: " << to_string(this->bagit_version_minor) << endl;
this->log << "Bagit minor version 97 is expected, but got: " << to_string(this->bagit_version_minor) << endl;
is_valid = false;
}
if (0 != tag_file_character_encoding.compare( "UTF-8" )) {
log << "Bagit character encoding UTF-8 is expected, but got: " << this->tag_file_character_encoding << endl;
this->log << "Bagit character encoding UTF-8 is expected, but got: " << this->tag_file_character_encoding << endl;
is_valid = false;
}
if (NULL == this->payload_p) {
log << "Bagit payload directory 'data/' is expected, but could not found" << endl;
this->log << "Bagit payload directory 'data/' is expected, but could not found" << endl;
is_valid = false;
} else {
bool ret = this->payload_p->validate( log );
bool ret = this->payload_p->validate();
if (ret == false) {
is_valid = false;
}
@ -31,8 +31,8 @@ bool Bag::validate( stringstream & log ) {
is_valid = false;
} else {
// checksums check
log << "Bagit payload manifest" << endl;
bool ret = this->payloadmanifest_p->validate( log );
this->log << "Bagit payload manifest" << endl;
bool ret = this->payloadmanifest_p->validate();
if (ret == false) {
is_valid = false;
}
@ -62,7 +62,7 @@ bool Bag::validate( stringstream & log ) {
int cmp_res = (*it1).compare( *it2);
//cout << "COMP: "<<cmp_res<<" file='"<< (*it1) << "' checksummed file='" << (*it2) << "'" << endl;
if ( cmp_res < 0) {
log << "Bagit warning, file '" << (*it1) << "' in payload has no checksum entry in payload manifest" << endl;
this->log << "Bagit warning, file '" << (*it1) << "' in payload has no checksum entry in payload manifest" << endl;
it1++;
} else if ( cmp_res > 0) {
it2++;
@ -76,15 +76,15 @@ bool Bag::validate( stringstream & log ) {
// next elements are optional
if (NULL == this->tagmanifest_p) {
} else {
log << "Bagit tag manifest" << endl;
bool ret = this->tagmanifest_p->validate( log );
this->log << "Bagit tag manifest" << endl;
bool ret = this->tagmanifest_p->validate();
if (ret == false) {
is_valid = false;
}
}
if (NULL == this->bagmetadata_p) {
} else {
bool ret = this->bagmetadata_p->validate( log );
bool ret = this->bagmetadata_p->validate();
if (ret == false) {
is_valid = false;
}
@ -95,11 +95,11 @@ bool Bag::validate( stringstream & log ) {
oxum_t expected_oxum = this->bagmetadata_p->get_oxum();
oxum_t calculated_oxum = c.oxum_of_filelist( files );
if (expected_oxum.octetcount != calculated_oxum.octetcount) {
log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl;
this->log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl;
is_valid = false;
}
if (expected_oxum.streamcount != calculated_oxum.streamcount) {
log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl;
this->log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl;
is_valid = false;
}


+ 7
- 3
test/test_bagmetadata.cpp View File

@ -19,10 +19,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
stringstream log;
Bagmetadata p( dir );
bool res = p.validate( log);
cout << log.str() << endl;
bool res = p.validate();
return res;
}
@ -68,6 +66,11 @@ oxum_t check_get_oxum(string dir) {
return p.get_oxum();
}
bool check_store( string dir_load_from, string dir_store_to ) {
Bagmetadata p( dir_load_from );
bool result = p.store( dir_store_to );
return result;
}
BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
@ -85,6 +88,7 @@ BOOST_AUTO_TEST_CASE(check_oxum) {
BOOST_TEST( expected.streamcount == result.streamcount);
};
BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_store_ok) {BOOST_TEST(check_store("../testbags/bag_minimal_ok/", "/tmp/testbag/"));};


+ 1
- 2
test/test_fetchfile.cpp View File

@ -18,9 +18,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
Fetchfile p( dir );
return p.validate( log);
return p.validate();
}


+ 1
- 2
test/test_payload.cpp View File

@ -18,9 +18,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
stringstream log;
Payload p( dir );
return p.validate( log);
return p.validate();
}
bool check_relative_paths() {


+ 1
- 3
test/test_payloadmanifest.cpp View File

@ -20,10 +20,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
stringstream log;
Payloadmanifest p( dir );
bool res = p.validate( log);
cout << log.str() << endl;
bool res = p.validate();
return res;
}


+ 1
- 3
test/test_tagmanifest.cpp View File

@ -20,10 +20,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
stringstream log;
Tagmanifest p( dir );
bool res = p.validate( log);
cout << log.str() << endl;
bool res = p.validate();
return res;
}


+ 1
- 2
test/testbag.cpp View File

@ -16,9 +16,8 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
stringstream log;
Bag p( dir );
return p.validate( log);
return p.validate();
}
bool check_store( string dir_load_from, string dir_store_to ) {


Loading…
Cancel
Save