diff --git a/src/include/bagmetadata.hpp b/src/include/bagmetadata.hpp index 09d227d..9b55cbc 100644 --- a/src/include/bagmetadata.hpp +++ b/src/include/bagmetadata.hpp @@ -3,6 +3,7 @@ #include #include #include +#include "checksum.hpp" using namespace std; enum { @@ -32,6 +33,8 @@ class Bagmetadata{ bool has_bagmetadata(); map get_metadata(); bool validate( list & log ); + bool has_oxum(); + oxum_t get_oxum(); }; #endif diff --git a/src/lib/bagmetadata.cpp b/src/lib/bagmetadata.cpp index 3161fde..63c6ac7 100644 --- a/src/lib/bagmetadata.cpp +++ b/src/lib/bagmetadata.cpp @@ -62,7 +62,8 @@ Bagmetadata::Bagmetadata( string basedir ) { key = *(iter); value = (*++iter); Bagmetadata::metadata[ key ] = value; - // DEBUG: cout << "KEY="<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::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 diff --git a/src/lib/payload.cpp b/src/lib/payload.cpp index e217851..81c06cf 100644 --- a/src/lib/payload.cpp +++ b/src/lib/payload.cpp @@ -50,7 +50,6 @@ list Payload::get_all_absolute_paths() { } bool Payload::validate( list & log ) { - // TODO return true; } // vim: set tabstop=4 diff --git a/src/lib/validate_bag.cpp b/src/lib/validate_bag.cpp index 981bdcb..4ba62d4 100644 --- a/src/lib/validate_bag.cpp +++ b/src/lib/validate_bag.cpp @@ -50,6 +50,22 @@ bool Bag::validate( list & log ) { if (ret == false) { is_valid = false; } + if (this->bagmetadata_p->has_oxum()) { + // check oxum of payload + Checksum c; + list 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) {