Browse Source

- added support for oxum validation of payload files if possible

master
parent
commit
17cd8c56f0
4 changed files with 52 additions and 4 deletions
  1. +3
    -0
      src/include/bagmetadata.hpp
  2. +33
    -3
      src/lib/bagmetadata.cpp
  3. +0
    -1
      src/lib/payload.cpp
  4. +16
    -0
      src/lib/validate_bag.cpp

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

@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <list>
#include "checksum.hpp"
using namespace std;
enum {
@ -32,6 +33,8 @@ class Bagmetadata{
bool has_bagmetadata();
map<string,string> get_metadata();
bool validate( list<string> & log );
bool has_oxum();
oxum_t get_oxum();
};
#endif


+ 33
- 3
src/lib/bagmetadata.cpp View File

@ -62,7 +62,8 @@ Bagmetadata::Bagmetadata( string basedir ) {
key = *(iter);
value = (*++iter);
Bagmetadata::metadata[ key ] = value;
// DEBUG: cout << "KEY="<<key<<" value="<<value<<endl;
// DEBUG:
cout << "KEY="<<key<<" value="<<value<<endl;
}
}
} else { // no file
@ -77,7 +78,36 @@ map <string,string> Bagmetadata::get_metadata() {
}
bool Bagmetadata::validate(list<string> & log ) {
// TODO
return true;
bool is_valid = true;
return is_valid;
}
bool Bagmetadata::has_oxum() {
map<string, string>::iterator it;
it = this->metadata.find("Payload-Oxum");
if (it != this->metadata.end()) {
cout << "Oxum is: " << it->second << endl;
return true;
}
return false;
}
oxum_t Bagmetadata::get_oxum() {
oxum_t oxum;
oxum.octetcount=0;
oxum.streamcount=0;
map<string, string>::iterator it;
it = this->metadata.find("Payload-Oxum");
if (it != this->metadata.end()) {
// split by .
stringstream oxumstring(it->second);
string soctets;
string sstreams;
getline(oxumstring, soctets, '.');
getline(oxumstring, sstreams, '.');
oxum.octetcount = stoi( soctets );
oxum.streamcount = stoi( sstreams );
}
return oxum;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

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

@ -50,7 +50,6 @@ list<string> Payload::get_all_absolute_paths() {
}
bool Payload::validate( list<string> & log ) {
// TODO
return true;
}
// vim: set tabstop=4

+ 16
- 0
src/lib/validate_bag.cpp View File

@ -50,6 +50,22 @@ bool Bag::validate( list<string> & log ) {
if (ret == false) {
is_valid = false;
}
if (this->bagmetadata_p->has_oxum()) {
// check oxum of payload
Checksum c;
list<string> files = this->payload_p->get_all_relative_paths();
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.push_back("Bagit payload oxum octectcount=" + to_string(expected_oxum.octetcount) + " expected, but " + to_string(calculated_oxum.octetcount) + " found");
is_valid = false;
}
if (expected_oxum.streamcount != calculated_oxum.streamcount) {
log.push_back("Bagit payload oxum streamcount=" + to_string(expected_oxum.streamcount) + " expected, but " + to_string(calculated_oxum.streamcount) + " found");
is_valid = false;
}
}
}
/*
if (NULL == this->fetchfile_p) {


Loading…
Cancel
Save