servlib/bundling/BPQResponse.cc
changeset 15 65e62bd13efd
parent 10 84c85b6450de
child 21 ea3d443fb6bc
equal deleted inserted replaced
14:06512deddac4 15:65e62bd13efd
    67     {
    67     {
    68         BlockInfo current_bi = *iter;    
    68         BlockInfo current_bi = *iter;    
    69         BlockProcessor* new_bp = BundleProtocol::find_processor(
    69         BlockProcessor* new_bp = BundleProtocol::find_processor(
    70                                     current_bi.owner()->block_type());
    70                                     current_bi.owner()->block_type());
    71 
    71 
       
    72         // take a pointer to the data in the buffer
       
    73         // making sure the buffer is big enough
       
    74         const u_char* data = current_bi.writable_contents()->
       
    75                              buf(current_bi.full_length())
       
    76                            + current_bi.data_offset();
       
    77 
    72         BlockInfo* new_bi = new_response->api_blocks()->append_block(new_bp);
    78         BlockInfo* new_bi = new_response->api_blocks()->append_block(new_bp);
    73         new_bp->init_block( new_bi,
    79         new_bp->init_block( new_bi,
    74                             new_response->api_blocks(),
    80                             new_response->api_blocks(),
    75                             current_bi.type(),
    81                             current_bi.type(),
    76                             current_bi.flags(),
    82                             current_bi.flags(),
    77                             (const u_char*)current_bi.data(),
    83                             data,
    78                             current_bi.full_length() );
    84                             current_bi.full_length() );
    79 /*
       
    80         BlockInfo* new_bi = new BlockInfo(current);
       
    81         new_bi->set_flag(current.flags());
       
    82 
       
    83         new_response->api_blocks()->append_block(current.owner(), new_bi);
       
    84 */
       
    85     }
    85     }
    86 
    86 
    87     // copy RECV blocks
    87     // copy RECV blocks
    88     BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks();
    88     BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks();
    89 
    89 
       
    90     int n=0;
    90     for (BlockInfoVec::iterator iter = recv_blocks->begin();
    91     for (BlockInfoVec::iterator iter = recv_blocks->begin();
    91          iter != recv_blocks->end();
    92          iter != recv_blocks->end();
    92          ++iter)
    93          ++iter)
    93     {
    94     {
    94         BlockInfo current_bi = *iter;       
    95         BlockInfo current_bi = *iter;       
       
    96         log_debug_p(LOG, "RECV Block[%d] is of type: %d", 
       
    97                     n++, current_bi.owner()->block_type());
       
    98 
    95         BlockProcessor* new_bp = BundleProtocol::find_processor(
    99         BlockProcessor* new_bp = BundleProtocol::find_processor(
    96                                     current_bi.owner()->block_type());
   100                                     current_bi.owner()->block_type());
       
   101 
       
   102         // take a pointer to the data in the buffer
       
   103         // making sure the buffer is big enough
       
   104         const u_char* data = current_bi.writable_contents()->
       
   105                              buf(current_bi.full_length())
       
   106                            + current_bi.data_offset();
    97 
   107 
    98         BlockInfo* new_bi = new_response->mutable_recv_blocks()->append_block(new_bp);
   108         BlockInfo* new_bi = new_response->mutable_recv_blocks()->append_block(new_bp);
    99         new_bp->init_block( new_bi,
   109         new_bp->init_block( new_bi,
   100                             new_response->mutable_recv_blocks(),
   110                             new_response->mutable_recv_blocks(),
   101                             current_bi.type(),
   111                             current_bi.type(),
   102                             current_bi.flags(),
   112                             current_bi.flags(),
   103                             (const u_char*)current_bi.data(),
   113                             data,
   104                             current_bi.data_length() );
   114                             current_bi.data_length() );
   105 
       
   106 
       
   107 /*
       
   108         BlockInfo* new_bi = new BlockInfo(current);
       
   109         new_bi->set_flag(current.flags());
       
   110 
       
   111         new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
       
   112         if (new_bi->type() == 200) {
       
   113             BPQBlock bpq(new_bi);
       
   114             log_debug_p(LOG, "_COPY_  kind(%d) query_len(%d) query(%s)",
       
   115                      bpq.kind(), bpq.query_len(), bpq.query_val());
       
   116         }
       
   117 */
       
   118     }
   115     }
   119     
   116     
   120 //   new_response->xmit_blocks()
       
   121    return true;
       
   122 }
       
   123 
       
   124 bool
       
   125 BPQResponse::copy_bpq_response(Bundle*     new_response,
       
   126                                Bundle*     response)
       
   127 {
       
   128     log_debug_p(LOG, "BPQResponse::copy_bpq_response");
       
   129 
       
   130     // init metadata
       
   131     response->copy_metadata(new_response);
       
   132     
       
   133     // set payload
       
   134     log_debug_p(LOG, "Copy response payload");
       
   135     new_response->mutable_payload()->
       
   136         replace_with_file(response->payload().filename().c_str());
       
   137 
       
   138     // copy API blocks
       
   139     BlockInfoVec* api_blocks = response->api_blocks();
       
   140 
       
   141     for (BlockInfoVec::iterator iter = api_blocks->begin();
       
   142          iter != api_blocks->end();
       
   143          ++iter)
       
   144     {
       
   145         BlockInfo current = *iter;
       
   146 
       
   147         BlockInfo* new_bi = new BlockInfo(current);
       
   148         new_bi->set_flag(current.flags());
       
   149 
       
   150         new_response->api_blocks()->append_block(current.owner(), new_bi);
       
   151     }
       
   152 
       
   153     // copy RECV blocks
       
   154     BlockInfoVec* recv_blocks = response->mutable_recv_blocks();
       
   155 
       
   156     for (BlockInfoVec::iterator iter = recv_blocks->begin();
       
   157          iter != recv_blocks->end();
       
   158          ++iter)
       
   159     {
       
   160         BlockInfo current = *iter;
       
   161 
       
   162         BlockInfo* new_bi = new BlockInfo(current);
       
   163         new_bi->set_flag(current.flags());
       
   164 
       
   165         new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
       
   166     }
       
   167 
       
   168    return true;
   117    return true;
   169 }
   118 }
   170 
   119 
   171 } // namespace dtn
   120 } // namespace dtn