Exemple #1
0
 //! assuming the packet has been properly initialized,
 //! this will fill bytes from @buffer into this packets buffer,
 //! then return the number of bytes written
 uint32_t fill(const std::string& buffer)
 {
   uint32_t rem   = buffer_end() - data_end();
   uint32_t total = (buffer.size() < rem) ? buffer.size() : rem;
   // copy from buffer to packet buffer
   memcpy(data_end(), buffer.data(), total);
   // set new packet length
   set_length(length() + total);
   return total;
 }
Exemple #2
0
bool smtp_client::send(const mail_message& message,
	const char* email /* = NULL */)
{
	// 发送 SMTP 邮件信封过程
	if (send_envelope(message) == false)
		return false;

	// 优先使用参数给出的邮件文件,然后才是 message 中自动生成的邮件文件
	if (email == NULL)
		email = message.get_email();

	// 如果没有可发送的邮件文件,则认为调用者想通过 write 等接口直接发送数据
	if (email == NULL)
		return true;

	// 发送 DATA 命令
	if (data_begin() == false)
		return false;

	// 发送邮件
	if (send_email(email) == false)
		return false;

	// 发送 DATA 结束符
	return data_end();
}
Exemple #3
0
/* ---------------------------------------------------------------- */ 
void data_save(icmProcessorP proc, const char *name, int adr, int size)
{
    int i, data, failed = 0;
    struct data_context ctx;
    
    /* align to 4 */
    size += (adr & 3);
    adr = adr & ~3;
    
    data_init(&ctx, proc, name);
    
    
    if(data_open_write(&ctx, adr, size)) {
        for(i = 0; i < size ; i += 4) {
            if(!data_read_memory(&ctx, adr, &data))
                failed = 1;
            data_write_file(&ctx, &data);
            adr += 4;
        }
        data_end(&ctx);
        
        if(failed) {
            printf("NOTE: there were memory access errors. Saved data is invalid\n");
        }        
    }  else printf( "Unable to create '%s' data file\n", name);        
}
Exemple #4
0
bool SimpleTableDump::dumpCidVectors(std::string name, atable_ptr_t table) {
  verify(table);
  prepare(name);
  auto store = std::dynamic_pointer_cast<Store>(table);

  std::string fullPath_begin = _baseDirectory + "/" + name + "/begin.cid.dat";
  std::string fullPath_end = _baseDirectory + "/" + name + "/end.cid.dat";
  std::ofstream data_begin(fullPath_begin, std::ios::out | std::ios::binary);
  std::ofstream data_end(fullPath_end, std::ios::out | std::ios::binary);

  // note: The cid vectors are different for NV built and normal, so we better copy it once, instead of accessing the
  // memory underneath directly.
  std::vector<tx::transaction_cid_t> beginCid;
  std::vector<tx::transaction_cid_t> endCid;
  size_t store_size = store->checkpointSize();

  // copy everything to our std::vectors & write out to file
  beginCid.resize(store_size);
  auto cid_start_begin = store->cidBeginIteratorForRecovery();
  std::copy(cid_start_begin, cid_start_begin + store_size, beginCid.begin());
  data_begin.write((char*)&beginCid[0], store_size * sizeof(tx::transaction_cid_t));
  data_begin.close();

  endCid.resize(store_size);
  auto cid_end_begin = store->cidEndIteratorForRecovery();
  std::copy(cid_end_begin, cid_end_begin + store_size, endCid.begin());
  data_end.write((char*)&endCid[0], store_size * sizeof(tx::transaction_cid_t));
  data_end.close();

  return true;
}
Exemple #5
0
void data_load(icmProcessorP proc, const char *name, int adr, int has_adr)
{    
    int i, data, failed = 0;
    struct data_context ctx;    
    
    data_init(&ctx, proc, name);        
    if(data_open_read(&ctx)) {
        
        printf("Loaded %s %08lx %08lx\n", ctx.header.name, ctx.header.start, ctx.header.size);        
        if(!has_adr) adr = ctx.header.start;
        
        for(i = 0; i < ctx.header.size ; i += 4) {
            data_read_file(&ctx, &data);
            if(!data_write_memory(&ctx, adr, &data))
                failed = 1;
            
            adr += 4;
        }
        data_end(&ctx);
        
        if(failed) {
            printf("NOTE: there were memory access errors. Memory may be invalid\n");
        }        
    }  else printf( "Unable to open '%s' data file\n", name);     
}
Exemple #6
0
//
//
//
/// @brief Checks if all the elements are zero.
//
/// @return @c true if all the elements are zero or if the current array
/// was not previously initialized by construction or the array::create()
/// member funtion. And returns @c false otherwise.
//
bool is_null() const
{
	auto check = [](int iter)
	{
		return (iter == 0.0);
	};
	return std::all_of(data, data_end(), check);
};
Exemple #7
0
const t_aud_chunk_header* Caud_file::get_chunk_header(int i)
{
	assert(is_open());
	if (!data())
		read();
	const byte* r = data() + sizeof(t_aud_header);
	while (i--)
	{
		if (r + sizeof(t_aud_chunk_header) > data_end())
			return NULL;
		const t_aud_chunk_header* header = reinterpret_cast<const t_aud_chunk_header*>(r);
		r += sizeof(t_aud_chunk_header) + header->size_in;
	}
	if (r + sizeof(t_aud_chunk_header) > data_end() || r + sizeof(t_aud_chunk_header) + reinterpret_cast<const t_aud_chunk_header*>(r)->size_in > data_end())
		return NULL;
	return reinterpret_cast<const t_aud_chunk_header*>(r);
}
Exemple #8
0
    void init(uint16_t l_port, uint16_t d_port)
    {
      Expects(data_end() == layer_begin() + ip_header_length());

      // Initialize UDP packet header
      // source and destination ports
      set_src_port(l_port);
      set_dst_port(d_port);
      // set zero length
      set_length(sizeof(UDP::header));
      // zero the optional checksum
      header().checksum = 0;
      set_protocol(Protocol::UDP);
    }
Exemple #9
0
//
//
//
/// @brief Checks if all the elements are negative. Only if the current array
/// was previously initialized either by construction or the array::create().
//
/// @return @c true if all the elements are negative, and @c false otherwise.
//
bool is_negative() const
{
	if(is_ready())
	{
		auto check = [](int iter)
		{
			return (iter < 0.0);
		};
		return std::all_of(data, data_end(), check);
	}
	else
	{
		return false;
	}
};
Exemple #10
0
void data_compare(icmProcessorP proc, const char *name, int adr, int has_adr)
{
    int i, data1, data2, cnt = 0, failed = 0;
    struct data_context ctx;    
    char *symbol;
    
    data_init(&ctx, proc, name);        
    if(data_open_read(&ctx)) {        
        if(!has_adr) adr = ctx.header.start;
        
        for(i = 0; i < ctx.header.size ; i += 4) {
            data_read_file(&ctx, &data1);
            if(!data_read_memory(&ctx, adr, &data2))
                failed = 1;
            else if(data1 != data2 && cnt < 8) {
                printf("Data changed at 0x%08lx:  OLD=0x%08lx  NEW=0x%08lx", adr, data1, data2);                    
                symbol = getSymbolFromAddress(adr);
                if(symbol) printf(" (%s)", symbol);                
                printf("\n");
                    
                cnt ++;                
                if(cnt == 8) printf("... (additional changes not reported)\n");                
            }
            adr += 4;
        }
        data_end(&ctx);
        
        if(cnt > 0) {
            printf(" *** DATA COMPARISION: There were %d changes.\n", cnt);
        } else {
            printf(" *** DATA COMPARISION: Saved data was identical to memory.\n");
        }
    
        if(failed) {
            printf("NOTE: there were memory access errors. Comparision my be incorrect.\n");
        }
    }  else printf( "Unable to open '%s' data file\n", name);     
            
}
Exemple #11
0
void data_show(const char *name)
{
    int i, data;
    unsigned int adr;
    struct data_context ctx;    
    
    data_init(&ctx, 0, name);        
    if(data_open_read(&ctx)) {
                
        adr = ctx.header.start;
        for(i = 0; i < ctx.header.size ; i += 4) {
            data_read_file(&ctx, &data);
            if(i == 0 || (adr & 31) == 0) {
                printf("\n%08lx: ", adr);
            }
            printf("%08lx ", data);            
            adr += 4;
        }
        data_end(&ctx);
        printf("\n");
        
    }  else printf( "Unable to open '%s' data file\n", name);         
}
Exemple #12
0
char * huffman_decode(data *buffer)
{
    int result_size = 200;
    char *decode = malloc(result_size);
    int index = 0;
    huffman_tree *curr = TREE;
    while (!data_end(buffer)) {
        while (curr->c == '\0') {
            uint32_t i = bits_read(buffer, 1);
            if (i == 0)
                curr = curr->zero;
            else
                curr = curr->one;
        }
        decode[index++] = curr->c;
        if (index >= result_size) {
            result_size *= 2;
            decode = realloc(decode, result_size);
        }
        curr = TREE;
    }
    decode[index] = '\0';
    return decode;
}
Exemple #13
0
typename fcppt::container::raw_vector<T, A>::iterator
fcppt::container::raw_vector<T, A>::insert(
    iterator const _position,
    T const &_value
)
{
    size_type const new_size(
        size() + 1u
    );

    if(
        new_size > this->capacity()
    )
    {
        difference_type const insert_sz(
            _position - this->begin()
        );

        size_type const new_cap(
            this->new_capacity(
                new_size
            )
        );

        pointer const new_memory(
            impl_.alloc_.allocate(
                new_cap
            )
        );

        if(
            !this->empty()
        )
            std::uninitialized_copy(
                this->begin(),
                _position,
                new_memory
            );

        *(new_memory + insert_sz) = _value;

        if(
            !this->empty()
        )
            std::uninitialized_copy(
                _position,
                this->end(),
                new_memory + insert_sz + 1u
            );

        this->deallocate();

        this->set_pointers(
            new_memory,
            new_size,
            new_cap
        );

        return this->begin() + insert_sz;
    }
    else
    {
        if(
            !this->empty()
        )
            std::copy_backward(
                _position,
                this->end(),
                data_end() + 1u
            );

        *_position = _value;

        ++impl_.last_;

        return _position;
    }
}
int main(int argc, char *argv[])
{
	g_test_init(&argc, &argv, NULL);

	define_test("/hfp/test_init", test_init, NULL, data_end());
	define_test("/hfp/test_cmd_handler_1", test_command_handler, NULL,
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F'),
			data_end());
	define_test("/hfp/test_cmd_handler_2", test_command_handler, NULL,
			raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '\r'),
			raw_pdu('A', 'T', 'D', '1', '2', '3', '4'),
			data_end());
	define_test("/hfp/test_register_1", test_register, prefix_handler,
			raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_COMMAND, 0),
			data_end());
	define_test("/hfp/test_register_2", test_register, prefix_handler,
			raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '=', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_register_3", test_register, prefix_handler,
			raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '?', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_READ, 0),
			data_end());
	define_test("/hfp/test_register_4", test_register, prefix_handler,
			raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
			raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '=', '?',
									'\r'),
			type_pdu(HFP_GW_CMD_TYPE_TEST, 0),
			data_end());
	define_test("/hfp/test_register_5", test_register, prefix_handler,
			raw_pdu('D', '\0'),
			raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '5', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_fragmented_1", test_fragmented, NULL,
			frg_pdu('A'), frg_pdu('T'), frg_pdu('+'), frg_pdu('B'),
			frg_pdu('R'), frg_pdu('S'), frg_pdu('F'), frg_pdu('\r'),
			data_end());
	define_test("/hfp/test_ustring_1", test_register, check_ustring_1,
			raw_pdu('D', '\0'),
			raw_pdu('A', 'T', 'D', '0', '1', '2', '3', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_ustring_2", test_register, check_ustring_2,
			raw_pdu('D', '\0'),
			raw_pdu('A', 'T', 'D', '0', '1', '2', '3', '\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_string_1", test_register, check_string_1,
			raw_pdu('D', '\0'),
			raw_pdu('A', 'T', 'D', '\"', '0', '1', '2', '3', '\"',
									'\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_string_2", test_register, check_string_2,
			raw_pdu('D', '\0'),
			raw_pdu('A', 'T', 'D', '\"', '0', '1', '2', '3', '\"',
									'\r'),
			type_pdu(HFP_GW_CMD_TYPE_SET, 0),
			data_end());
	define_test("/hfp/test_empty", test_fragmented, NULL,
			raw_pdu('\r'),
			data_end());

	return g_test_run();
}
void cyclic_read_session::handle_read_tail(
    const boost::system::error_code& error,
    const std::size_t bytes_transferred)
{
  port_read_in_progress_ = false;

  // Check for pending session do_start_extern_stop operation
  if (extern_state::stop == extern_state_)
  {
    if (may_complete_stop())
    {
      complete_stop();
      post_extern_stop_handler();
    }
    return;
  }

  if (error)
  {
    // Check for pending session read operation
    if (extern_read_handler_.has_target())
    {
      extern_read_handler_.post(read_result_type(error, 0));
      return;
    }

    // Store error for the next outer read operation.
    read_error_ = error;
    return;
  }

  typedef boost::asio::streambuf::const_buffers_type        const_buffers_type;
  typedef boost::asio::buffers_iterator<const_buffers_type> buffers_iterator;
  // Extract frame from buffer to distinct memory area
  const_buffers_type committed_buffers(read_buffer_.data());
  buffers_iterator data_begin(buffers_iterator::begin(committed_buffers));
  buffers_iterator data_end(
      data_begin + bytes_transferred - frame_tail_.length());

  frame_ptr new_frame;
  if (frame_buffer_.full())
  {
    new_frame = frame_buffer_.front();
    new_frame->assign(data_begin, data_end);
  }
  else
  {
    new_frame = boost::make_shared<frame>(data_begin, data_end);
  }

  // Consume processed data
  read_buffer_.consume(bytes_transferred);

  // Continue inner operations loop.
  read_until_head();

  // Save ready frame into the cyclic read buffer
  frame_buffer_.push_back(new_frame);

  // If there is waiting read operation - complete it
  if (extern_read_handler_base* handler = extern_read_handler_.target())
  {
    read_result_type copy_result = handler->copy(frame_buffer_);
    frame_buffer_.erase_begin(copy_result.get<1>());
    extern_read_handler_.post(copy_result);
  }
}
Exemple #16
0
	const T* cend( ) const {
		return data_end( );
	}
Exemple #17
0
	T* end( ) {
		return data_end( );
	}