# HG changeset patch # User aidan # Date 1308850830 -3600 # Node ID 65e62bd13efd31a51aa5e11da972db45478d0c75 # Parent 06512deddac4e22d36cb163789aa07c5efb5957d segfault fix in BPQResponse.cc diff -r 06512deddac4 -r 65e62bd13efd servlib/bundling/BPQResponse.cc --- 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; } diff -r 06512deddac4 -r 65e62bd13efd servlib/bundling/BundleDaemon.cc --- a/servlib/bundling/BundleDaemon.cc Wed Jun 22 15:06:06 2011 +0100 +++ b/servlib/bundling/BundleDaemon.cc Thu Jun 23 18:40:30 2011 +0100 @@ -457,6 +457,30 @@ // add bundle to cache and store bundle->set_in_bpq_cache(true); + + /********************************************** + // DEBUG Code - remove + + if (bundle->recv_blocks().has_block(1)) { + BlockInfo* payload = const_cast + (bundle->recv_blocks().find_block(1)); + + size_t length = payload->data_length(); + size_t offset = payload->data_offset(); + size_t buf_len = payload->writable_contents()->buf_len(); + + log_info("payload->data_length(): %d", payload->data_length()); + log_info("payload->data_offset(): %d", payload->data_offset()); + log_info("payload->full_length(): %d", payload->full_length()); + log_info("payload->writable_contents()->buf_len(): %d", + payload->writable_contents()->buf_len()); + + ASSERT (buf_len >= length + offset); + + memset(payload->writable_contents()->buf() + offset, + 0, length); + } + **********************************************/ bpq_bundles_->push_back(bundle); if (add_to_store) {