servlib/bundling/BPQResponse.cc
changeset 15 65e62bd13efd
parent 10 84c85b6450de
child 21 ea3d443fb6bc
--- a/servlib/bundling/BPQResponse.cc	Wed Jun 22 15:06:06 2011 +0100
+++ b/servlib/bundling/BPQResponse.cc	Thu Jun 23 18:40:30 2011 +0100
@@ -69,102 +69,51 @@
         BlockProcessor* new_bp = BundleProtocol::find_processor(
                                     current_bi.owner()->block_type());
 
+        // take a pointer to the data in the buffer
+        // making sure the buffer is big enough
+        const u_char* data = current_bi.writable_contents()->
+                             buf(current_bi.full_length())
+                           + current_bi.data_offset();
+
         BlockInfo* new_bi = new_response->api_blocks()->append_block(new_bp);
         new_bp->init_block( new_bi,
                             new_response->api_blocks(),
                             current_bi.type(),
                             current_bi.flags(),
-                            (const u_char*)current_bi.data(),
+                            data,
                             current_bi.full_length() );
-/*
-        BlockInfo* new_bi = new BlockInfo(current);
-        new_bi->set_flag(current.flags());
-
-        new_response->api_blocks()->append_block(current.owner(), new_bi);
-*/
     }
 
     // copy RECV blocks
     BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks();
 
+    int n=0;
     for (BlockInfoVec::iterator iter = recv_blocks->begin();
          iter != recv_blocks->end();
          ++iter)
     {
         BlockInfo current_bi = *iter;       
+        log_debug_p(LOG, "RECV Block[%d] is of type: %d", 
+                    n++, current_bi.owner()->block_type());
+
         BlockProcessor* new_bp = BundleProtocol::find_processor(
                                     current_bi.owner()->block_type());
 
+        // take a pointer to the data in the buffer
+        // making sure the buffer is big enough
+        const u_char* data = current_bi.writable_contents()->
+                             buf(current_bi.full_length())
+                           + current_bi.data_offset();
+
         BlockInfo* new_bi = new_response->mutable_recv_blocks()->append_block(new_bp);
         new_bp->init_block( new_bi,
                             new_response->mutable_recv_blocks(),
                             current_bi.type(),
                             current_bi.flags(),
-                            (const u_char*)current_bi.data(),
+                            data,
                             current_bi.data_length() );
-
-
-/*
-        BlockInfo* new_bi = new BlockInfo(current);
-        new_bi->set_flag(current.flags());
-
-        new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
-        if (new_bi->type() == 200) {
-            BPQBlock bpq(new_bi);
-            log_debug_p(LOG, "_COPY_  kind(%d) query_len(%d) query(%s)",
-                     bpq.kind(), bpq.query_len(), bpq.query_val());
-        }
-*/
     }
     
-//   new_response->xmit_blocks()
-   return true;
-}
-
-bool
-BPQResponse::copy_bpq_response(Bundle*     new_response,
-                               Bundle*     response)
-{
-    log_debug_p(LOG, "BPQResponse::copy_bpq_response");
-
-    // init metadata
-    response->copy_metadata(new_response);
-    
-    // set payload
-    log_debug_p(LOG, "Copy response payload");
-    new_response->mutable_payload()->
-        replace_with_file(response->payload().filename().c_str());
-
-    // copy API blocks
-    BlockInfoVec* api_blocks = response->api_blocks();
-
-    for (BlockInfoVec::iterator iter = api_blocks->begin();
-         iter != api_blocks->end();
-         ++iter)
-    {
-        BlockInfo current = *iter;
-
-        BlockInfo* new_bi = new BlockInfo(current);
-        new_bi->set_flag(current.flags());
-
-        new_response->api_blocks()->append_block(current.owner(), new_bi);
-    }
-
-    // copy RECV blocks
-    BlockInfoVec* recv_blocks = response->mutable_recv_blocks();
-
-    for (BlockInfoVec::iterator iter = recv_blocks->begin();
-         iter != recv_blocks->end();
-         ++iter)
-    {
-        BlockInfo current = *iter;
-
-        BlockInfo* new_bi = new BlockInfo(current);
-        new_bi->set_flag(current.flags());
-
-        new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
-    }
-
    return true;
 }