servlib/bundling/BPQBlockProcessor.cc
changeset 45 208a44ac3a5e
parent 35 2bc8cc69d2a5
child 47 f1d80668861b
--- 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;
+}
 
 //----------------------------------------------------------------------
 /*