예제 #1
0
    std::shared_ptr<Response> request(const std::string& request_type, const std::string& path, std::iostream& content,
      const std::map<std::string, std::string>& header = std::map<std::string, std::string>()) {
      std::string corrected_path = path;
      if (corrected_path == "")
        corrected_path = "/";

      content.seekp(0, std::ios::end);
      auto content_length = content.tellp();
      content.seekp(0, std::ios::beg);

      boost::asio::streambuf write_buffer;
      std::ostream write_stream(&write_buffer);
      write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n";
      write_stream << "Host: " << host << "\r\n";
      for (auto& h : header) {
        write_stream << h.first << ": " << h.second << "\r\n";
      }
      if (content_length>0)
        write_stream << "Content-Length: " << content_length << "\r\n";
      write_stream << "\r\n";
      if (content_length>0)
        write_stream << content.rdbuf();

      try {
        connect();

        boost::asio::write(*socket, write_buffer);
      }
      catch (const std::exception& e) {
        socket_error = true;
        throw std::invalid_argument(e.what());
      }

      return request_read();
    }
예제 #2
0
파일: Client.cpp 프로젝트: Damax/zia
void	Client::setResponseContentLength(Transaction& trans, std::iostream& os)
{
  os.seekg(0, std::ios::end);
  int os_length = os.tellg();
  os_length--;
  os.seekg(0, std::ios::beg);
  trans.getResponse().getHeaders().setValue("CONTENT-LENGTH", inttostr(os_length));
}
예제 #3
0
void SkillLevelEvent::save( std::iostream& ios )
{

    Event::save(ios);

    // Save bonus
    ios.write( (char*) &bonus, sizeof( bonus ) );

    // Save skill
    ios.write( (char*) &skill, sizeof( skill ) );
}
예제 #4
0
SkillLevelEvent::SkillLevelEvent( std::iostream& ios )
    :   Event(ios)
{

    // Read bonus
    ios.read( (char*) &bonus, sizeof( bonus ) );

    // Read skill
    ios.read( (char*) &skill, sizeof( skill ) );


}
예제 #5
0
파일: ammo.cpp 프로젝트: anylonen/abura-tan
void Ammo::toFile( std::iostream& outFile )
{

    // Write Item base information:
    Item::toFile( outFile );

    // Write char form
    outFile.write( (char*) &form, sizeof(form) );

    // Write bool fired
    outFile.write( (char*) &fired, sizeof(fired) );

}
예제 #6
0
파일: ammo.cpp 프로젝트: anylonen/abura-tan
Ammo::Ammo( std::iostream& inFile, TargetValue* TVP )
// Read Item base information:
    : Item (inFile, TVP)
{

    // Read char form
    inFile.read( (char*) &form, sizeof(form) );

    // Read bool fired
    inFile.read( (char*) &fired, sizeof(fired) );


}
예제 #7
0
void FillStream(std::iostream& strm, RawData& expression)
{
	static const std::string s_smallExpression("0123456789abcdefghijklmnopqrstuvwxyz");
	static const int iterationsCount = 10;

	for (int i = 0; i < iterationsCount; ++i)
	{
		strm << s_smallExpression;
	}
	size_t expressionSize = iterationsCount * s_smallExpression.size();
	expression.resize(expressionSize);
	strm.read(reinterpret_cast<char*>(&expression[0]), expressionSize);
	strm.seekg(0);
}
예제 #8
0
gzstream::gzstream( std::iostream & strm,
                    unsigned int buffer_size )
    : std::iostream( static_cast< std::streambuf * >( 0 ) )
    , M_gzstreambuf( *(strm.rdbuf()), buffer_size )
{
    this->init( &M_gzstreambuf );
}
예제 #9
0
Event::Event( std::iostream& ios )
{

    ios.read( (char*) &time, sizeof(time) );

    Timeline::add( this );
}
예제 #10
0
 void _serialize(std::iostream &fs, serialization_context &context) {
   assert(target > 0);
   assert(context.ss.objects.count(target) > 0);
   fs << target << " ";
   target = 0;
   assert(fs.good());
   context.is_leaf = false;
 }
예제 #11
0
파일: dag_reader.cpp 프로젝트: baharev/asol
void grab_content(const char* file_name, std::iostream& in) {

	parser p(file_name);

	interpreter_DAG ipt(p.get_problem_representation(), in);

	if (!in.good())
		error("unexpected error");
}
예제 #12
0
Fluid::Fluid( std::iostream& inFile, TargetValue* TVP )
// Read Item base information:
    : Item (inFile, TVP)
{

    // Read materialClass f_material
    inFile.read( (char*) &f_material, sizeof(f_material) );


}
예제 #13
0
void readExactly(size_t toread, std::iostream& result)
{
  size_t hasread = 0;
  while(toread > hasread && std::cin.good()) {
    char a[1];
    std::cin.read(a,1);
    result.write(a,1);
    hasread++;
  }
}
예제 #14
0
void Fluid::toFile( std::iostream& outFile )
{

    // Write Item base information:
    Item::toFile( outFile );

    // Write materialClass f_material
    outFile.write( (char*) &f_material, sizeof(f_material) );

}
예제 #15
0
/*!

*/
gzfilterstream::gzfilterstream( std::iostream & strm,
                                int level,
                                std::size_t buf_size )
    : std::iostream( static_cast< std::streambuf* >( 0 ) )
    , M_filter_buf( *(strm.rdbuf()), level, buf_size )

{
    // std::basic_ios::init( basic_streambuf<charT,traits>* sb );
    this->init( &M_filter_buf );
}
예제 #16
0
 void _deserialize(std::iostream &fs, serialization_context &context) {
   assert(target == 0);
   ss = &context.ss;
   fs >> target;
   assert(fs.good());
   assert(context.ss.objects.count(target) > 0);
   // We just created a new reference to this object and
   // invalidated the on-disk reference, so the total refcount
   // stays the same.
 }
예제 #17
0
void ActionEvent::save( std::iostream& ios )
{

    Event::save(ios);

    // Save target
    ios << target;

    // Save actor
    ios.write( (char*) &action, sizeof( action ) );
}
예제 #18
0
ActionEvent::ActionEvent( std::iostream& ios )
    :   Event(ios)
{

    // Read target
    ios >> target;

    // Read actor
    ios.read( (char*) &action, sizeof( action ) );


}
예제 #19
0
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
{
    out.clear(std::ios::goodbit);
    if(m_hasSearchPath) {
        std::string fullPath = resolvePath(fileName);
        PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
        if(!file) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fullPath.c_str(), PHYSFS_getLastError()));
        } else {
            int fileSize = PHYSFS_fileLength(file);
            if(fileSize > 0) {
                std::vector<char> buffer(fileSize);
                PHYSFS_read(file, (void*)&buffer[0], 1, fileSize);
                out.write(&buffer[0], fileSize);
            } else
                out.clear(std::ios::eofbit);
            PHYSFS_close(file);
            out.seekg(0, std::ios::beg);
        }
    } else {
        std::ifstream fin(fileName);
        if(!fin) {
            out.clear(std::ios::failbit);
            stdext::throw_exception(stdext::format("failed to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError()));
        } else {
            out << fin.rdbuf();
        }
    }
}
예제 #20
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void MLRLookUpLight::Save(std::iostream stream)
{
	// Check_Object(this);
	Check_Object(stream);
	MLRInfiniteLight::Save(stream);
	*stream << mapOrigin;
	*stream << mapZoneCountX << mapZoneCountZ;
	*stream << zoneSizeX << zoneSizeZ;
	*stream << mapName;
	for (size_t i = 0; i < mapZoneCountX * mapZoneCountZ; i++)
	{
		stream->WriteBytes(maps[i], 256 * 256);
	}
}
예제 #21
0
std::string StringUtilities::GetAsString(std::iostream& i_stream)
{
	int length;
	char* p_buffer;
	
	// get length of file:
	i_stream.seekg (0, std::iostream::end);
	length = static_cast<int>(i_stream.tellg());
	i_stream.seekg (0, std::iostream::beg);

	// allocate memory:
	p_buffer = new char [length];
	//write file
	int pos = 0;
	while(i_stream.good())
	{
		p_buffer[pos] = i_stream.get();
		++pos;
	}

	std::string out(p_buffer, pos);
	delete[] p_buffer;
	return out;
}
예제 #22
0
template<class Key, class Value> void serialize(std::iostream &fs,
						serialization_context &context,
						std::map<Key, Value> &mp)
{
  fs << "map " << mp.size() << " {" << std::endl;
  assert(fs.good());
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    fs << "  ";
    serialize(fs, context, it->first);
    fs << " -> ";
    serialize(fs, context, it->second);
    fs << std::endl;
  }
  fs << "}" << std::endl;
}
예제 #23
0
void FilePiece::print(int64_t from, int64_t to, std::iostream &outStream)
{
	if (fileData)
	{
		const int64_t BUFFSIZE = 8192;
		int64_t targetLength;
		uint8_t buffer[BUFFSIZE];
		for (int64_t i = from; i <= to; i += targetLength)
		{
			targetLength = MIN(BUFFSIZE, to - i + 1);
			cs.read(buffer, i, targetLength);
			outStream.write((const char *)buffer, targetLength);
		}
	}
	else
	{
		if (signature == SIG_CDFH || signature == SIG_DD)
		{
			FilePiece* fileDataPiece = (FilePiece*)extraBuffer;

			if (fileDataPiece->cs.reachedOffset < (fileDataPiece->length - 1))
			{
				uint8_t tmp;
				fileDataPiece->cs.read(&tmp, fileDataPiece->length - 1, 1);
			}

			if (fileDataPiece->cs.reachedOffset < (int64_t)(fileDataPiece->length - 1)) //safety measure: insufficient crc
				abort();
			if (signature == SIG_CDFH)
				((CDFH*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
			else if (signature == SIG_DD)
				((DD*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
		}
		outStream.write((const char *)buffer + from, to - from + 1);
	}
}
예제 #24
0
bool ResourceManager::saveFile(const std::string& fileName, std::iostream& in)
{
    std::streampos oldPos = in.tellg();
    in.seekg(0, std::ios::end);
    std::streampos size = in.tellg();
    in.seekg(0, std::ios::beg);
    std::vector<char> buffer(size);
    in.read(&buffer[0], size);
    bool ret = saveFile(fileName, (const uchar*)&buffer[0], size);
    in.seekg(oldPos, std::ios::beg);
    return ret;
}
예제 #25
0
template<class Key, class Value> void deserialize(std::iostream &fs,
						  serialization_context &context,
						  std::map<Key, Value> &mp)
{
  std::string dummy;
  int size = 0;
  fs >> dummy >> size >> dummy;
  assert(fs.good());
  for (int i = 0; i < size; i++) {
    Key k;
    Value v;
    deserialize(fs, context, k);
    fs >> dummy;
    deserialize(fs, context, v);
    mp[k] = v;
  }
  fs >> dummy;
}
예제 #26
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLRLookUpLight::MLRLookUpLight(std::iostream stream, uint32_t version)
	: MLRInfiniteLight(DefaultData, stream, version)
{
	Check_Object(stream);
	// _ASSERT(gos_GetCurrentHeap() == Heap);
	*stream >> mapOrigin;
	*stream >> mapZoneCountX >> mapZoneCountZ;
	*stream >> zoneSizeX >> zoneSizeZ;
	*stream >> mapName;
	one_Over_zoneSizeX = 1.0f / zoneSizeX;
	one_Over_zoneSizeZ = 1.0f / zoneSizeZ;
	maps			   = new puint8_t[mapZoneCountX * mapZoneCountZ];
	Check_Pointer(maps);
	for (size_t i = 0; i < mapZoneCountX * mapZoneCountZ; i++)
	{
		maps[i] = new uint8_t[256 * 256];
		Check_Pointer(maps[i]);
		stream->ReadBytes(maps[i], 256 * 256);
	}
}
예제 #27
0
		void on_connected(socket& /*socket*/, std::iostream& stream)
		{
			for (std::size_t keep_alive_count = config_.maximum_keep_alive_requests; keep_alive_count != 0; --keep_alive_count)
			{
				stream.exceptions(std::ios_base::badbit);

				if (stream.peek() == EOF)
				{
					stream.clear();
					break;
				}

				stream.exceptions(std::ios_base::eofbit | std::ios_base::failbit | std::ios_base::badbit);

				http_server_context context(stream, config_);
				http_request& req = context.request();
				http_response& res = context.response();

				bool head = false;
				bool keep_alive = false;

				try
				{
					context.read_headers();

					switch (req.get_method())
					{
					case http_method::head:
						head = true;
						break;
					case http_method::get:
					case http_method::post:
						break;
					default:
						BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
					}

					if (req.is_connection_keep_alive())
					{
						res.set_keep_alive_requests(keep_alive_count);
						keep_alive = true;
					}

					context.validate_headers();

					if (config_.logger)
						config_.logger->http_server_request(req);

					try
					{
						switch (req.get_method())
						{
						case http_method::head:
						case http_method::get:
							derived().on_get(context, head);
							break;
						case http_method::post:
							derived().on_post(context);
							break;
						default:
							BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
						}
					}
					catch(http_exception&)
					{
						throw;
					}
					catch (interrupted_exception&)
					{
						throw;
					}
					catch (std::exception&)
					{
						BOOST_THROW_EXCEPTION(http_exception(http_status_code::internal_service_error));
					}
				}
				catch (http_exception& e)
				{
					if (config_.logger)
						config_.logger->exception();

					res.set_status_code(e.status_code());

					try
					{
						auto it = config_.error_document.find(e.status_code());
						if (it != config_.error_document.end())
							BOOST_THROW_EXCEPTION(http_exception(http_status_code::not_found));

						req.set_path(it->second);

						derived().on_get(context, head);
					}
					catch (http_exception&)
					{
						null_content().on_get(context, head);
					}
				}

				context.finish_write();

				if (!keep_alive)
					break;
			}
		}
예제 #28
0
void Event::save( std::iostream& ios )
{

    ios.write( (char*) &time, sizeof(time) );
}
예제 #29
0
bool test_seekable_in_chars(std::iostream& io)
{
    int i;  // old 'for' scope workaround.

    // Test seeking with ios::cur
    for (i = 0; i < data_reps; ++i) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-chunk_size, BOOST_IOS::cur);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(-chunk_size, BOOST_IOS::cur);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }

    // Test seeking with ios::beg
    std::streamoff off = 0;
    io.seekp(0, BOOST_IOS::beg);
    for (i = 0; i < data_reps; ++i, off += chunk_size) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(off, BOOST_IOS::beg);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(off, BOOST_IOS::beg);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }

    // Test seeking with ios::end
    io.seekp(0, BOOST_IOS::end);
    off = io.tellp();
    io.seekp(-off, BOOST_IOS::end);
    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-off, BOOST_IOS::end);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(-off, BOOST_IOS::end);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }
    return true;
}
예제 #30
0
bool test_seekable_in_chunks(std::iostream& io)
{
    int i;  // old 'for' scope workaround.

    // Test seeking with ios::cur
    for (i = 0; i < data_reps; ++i) {
        io.write(narrow_data(), chunk_size);
        io.seekp(-chunk_size, BOOST_IOS::cur);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(-chunk_size, BOOST_IOS::cur);
        io.write(narrow_data(), chunk_size);
    }

    // Test seeking with ios::beg
    std::streamoff off = 0;
    io.seekp(0, BOOST_IOS::beg);
    for (i = 0; i < data_reps; ++i, off += chunk_size) {
        io.write(narrow_data(), chunk_size);
        io.seekp(off, BOOST_IOS::beg);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(off, BOOST_IOS::beg);
        io.write(narrow_data(), chunk_size);
    }
    
    // Test seeking with ios::end
    io.seekp(0, BOOST_IOS::end);
    off = io.tellp();
    io.seekp(-off, BOOST_IOS::end);
    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
        io.write(narrow_data(), chunk_size);
        io.seekp(-off, BOOST_IOS::end);
        char buf[chunk_size];
        io.read(buf, chunk_size);
        if (strncmp(buf, narrow_data(), chunk_size) != 0)
            return false;
        io.seekp(-off, BOOST_IOS::end);
        io.write(narrow_data(), chunk_size);
    }
    return true;
}