# HG changeset patch # User aidan # Date 1313505826 -3600 # Node ID 208a44ac3a5e8fff923d75b5f1eda4d9b25f7a68 # Parent c4b3e13a1a90ce1f16e3627acef01528554b5a0f adding block validation diff -r c4b3e13a1a90 -r 208a44ac3a5e servlib/bundling/BPQBlockProcessor.cc --- a/servlib/bundling/BPQBlockProcessor.cc Mon Aug 15 18:28:00 2011 +0100 +++ b/servlib/bundling/BPQBlockProcessor.cc Tue Aug 16 15:43:46 2011 +0100 @@ -184,6 +184,48 @@ log_info_p(LOG, "BPQBlockProcessor::generate() ending"); return BP_SUCCESS; } +//---------------------------------------------------------------------- +bool +BPQBlockProcessor::validate(const Bundle* bundle, + BlockInfoVec* block_list, + BlockInfo* block, + status_report_reason_t* reception_reason, + status_report_reason_t* deletion_reason) +{ + if ( ! BlockProcessor::validate(bundle, + block_list, + block,reception_reason, + deletion_reason) ) { + log_err_p(LOG, "BlockProcessor validation failed"); + return false; + } + + if ( block->data_offset() + block->data_length() != block->full_length() ) { + + log_err_p(LOG, "offset (%lu) + data len (%lu) is not equal to the full len (%lu)", + block->data_offset(), block->data_length(), block->full_length() ); + *deletion_reason = BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE; + return false; + } + + if ( block->contents().buf_len() < block->full_length() ) { + + log_err_p(LOG, "block buffer len (%lu) is less than the full len (%lu)", + block->contents().buf_len(), block->full_length() ); + *deletion_reason = BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE; + return false; + } + + if ( *(block->data()) != 0 && *(block->data()) != 1 ) { + + log_err_p(LOG, "invalid kind - should be query (0) or response (1) but is: %u", + (u_int) *block->data() ); + *deletion_reason = BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE; + return false; + } + + return true; +} //---------------------------------------------------------------------- /* diff -r c4b3e13a1a90 -r 208a44ac3a5e servlib/bundling/BPQBlockProcessor.h --- a/servlib/bundling/BPQBlockProcessor.h Mon Aug 15 18:28:00 2011 +0100 +++ b/servlib/bundling/BPQBlockProcessor.h Tue Aug 16 15:43:46 2011 +0100 @@ -40,6 +40,13 @@ BlockInfo* block, const LinkRef& link, bool last); + + bool validate(const Bundle* bundle, + BlockInfoVec* block_list, + BlockInfo* block, + status_report_reason_t* reception_reason, + status_report_reason_t* deletion_reason); + /* int finalize(const Bundle* bundle, BlockInfoVec* xmit_blocks, diff -r c4b3e13a1a90 -r 208a44ac3a5e servlib/bundling/BundleProtocol.cc --- a/servlib/bundling/BundleProtocol.cc Mon Aug 15 18:28:00 2011 +0100 +++ b/servlib/bundling/BundleProtocol.cc Tue Aug 16 15:43:46 2011 +0100 @@ -169,6 +169,8 @@ } if (! xmit_blocks->has_block(i)) { + if (i == BundleProtocol::QUERY_EXTENSION_BLOCK) + log_debug_p(LOG, "adding extra BPQ block!!!"); bp->prepare(bundle, xmit_blocks, NULL, link, BlockInfo::LIST_NONE); } }