Ejemplo n.º 1
0
inline std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, uuid& id)
{
    typedef typename std::basic_istream<CharT,Traits>::sentry sentry_t;
    sentry_t ok(is);
    if (ok)
    {
        CharT c;
        if (!is.get(c))
            return is;

        is.unget();

        if (c == is.widen('{'))
        {
            CharT buf[38+1];
            if (!is.read(buf, 38))
                return is;
            buf[38] = CharT();
            id = uuid(buf);
        }
        else
        {
            CharT buf[36+1];
            if (!is.read(buf, 36))
                return is;
            buf[36] = CharT();
            id = uuid(buf);
        }
    }
    return is;
}
Ejemplo n.º 2
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || nLen > (int)MAX_SIZE)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        vector<char> vch(nLen);
        stream.read(&vch[0], nLen);
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
Ejemplo n.º 3
0
 void read_next()
 {
     parser_.begin_parse();
     while (!eof_ && !parser_.done())
     {
         if (!(index_ < buffer_length_))
         {
             if (!is_->eof())
             {
                 is_->read(buffer_.data(), buffer_capacity_);
                 buffer_length_ = static_cast<size_t>(is_->gcount());
                 if (buffer_length_ == 0)
                 {
                     eof_ = true;
                 }
                 index_ = 0;
             }
             else
             {
                 eof_ = true;
             }
         }
         if (!eof_)
         {
             parser_.parse(buffer_.data(),index_,buffer_length_);
             index_ = parser_.index();
         }
     }
     parser_.end_parse();
 }
Ejemplo n.º 4
0
 void check_done()
 {
     while (!eof_)
     {
         if (!(index_ < buffer_length_))
         {
             if (!is_->eof())
             {
                 is_->read(buffer_.data(), buffer_capacity_);
                 buffer_length_ = static_cast<size_t>(is_->gcount());
                 if (buffer_length_ == 0)
                 {
                     eof_ = true;
                 }
                 index_ = 0;
             }
             else
             {
                 eof_ = true;
             }
         }
         if (!eof_)
         {
             parser_.check_done(buffer_.data(),index_,buffer_length_);
             index_ = parser_.index();
         }
     }
 }
Ejemplo n.º 5
0
 inline std::basic_istream<Char>&
 operator >>(std::basic_istream<Char>& in, header_type& header) {
     in.read(
             util::cast::pointer_cast<char*>(&header),
             sizeof(header_type));
     return in;
 }
Ejemplo n.º 6
0
int ReadHTTP (std::basic_istream<char>& stream, std::map<std::string, std::string>& mapHeadersRet,
              std::string& strMessageRet)
{
    mapHeadersRet.clear ();
    strMessageRet = "";

    // Read status
    int nStatus = ReadHTTPStatus (stream);

    // Read header
    int nLen = ReadHTTPHeader (stream, mapHeadersRet);

    if (nLen < 0 || nLen > gMaxHTTPHeaderSize)
        return 500;

    // Read message
    if (nLen > 0)
    {
        std::vector<char> vch (nLen);
        stream.read (&vch[0], nLen);
        strMessageRet = std::string (vch.begin (), vch.end ());
    }

    return nStatus;
}
Ejemplo n.º 7
0
std::basic_istream<charT,traits> & operator >> (std::basic_istream<charT,traits> & iStream, BE<INT>& benum)
{
  INT val;
  iStream.read(reinterpret_cast<charT*>(&val), sizeof val);
  benum.value = endian::ntoh(val);
  return iStream ;
}
Ejemplo n.º 8
0
std::basic_istream<charT,traits> & operator >> (std::basic_istream<charT,traits> & iStream, Bytes & str)
{
  BE<int32_t> sz; 
  iStream >> sz;
  str.bytes.resize(sz.value);
  iStream.read(reinterpret_cast<charT*>(str.bytes.data()), sz.value);
  return iStream ;
}
Ejemplo n.º 9
0
Archivo: main.cpp Proyecto: CCJY/coliru
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e(&sliteral)[N]) {
        e buffer[N-1] = {}; //get buffer
        in >> buffer[0]; //skips whitespace
        if (N>2)
                in.read(buffer+1, N-2); //read the rest
        if (strncmp(buffer, sliteral, N-1)) //if it failed
                in.setstate(in.rdstate() | std::ios::badbit); //set the state
        return in;
}
Ejemplo n.º 10
0
inline void ReadBSTRFromStream( std::basic_istream< CharT, CharTraitsT > &Istream, ATL::CComBSTR &Str )
{ 
   Str.Empty();

   CharT Buff[256];

   do 
   {
      Istream.read( Buff, APL_ARRSIZE(Buff) );
      ATL::CComBSTR TmpStr(Istream.gcount(), Buff);
      Str.Append(TmpStr);   

   } while(Istream.gcount() == APL_ARRSIZE(Buff));
}
Ejemplo n.º 11
0
std::basic_istream<CharT>& operator>>(std::basic_istream<CharT>& is, RMap<StrType>& param){
	size_t bufferSize = is.rdbuf()->in_avail();
	char* buffer = new CharT[bufferSize+1];
	is.read(buffer, bufferSize);
	buffer[bufferSize] = '\0';

	StrType str(buffer);
	typename StrType::iterator it = str.begin();
	parseMap<StrType>(param, it);

	delete[] buffer;

	return is;
}
Ejemplo n.º 12
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto, size_t max_size)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || (size_t)nLen > max_size)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        //vector<char> vch(nLen);
        //stream.read(&vch[0], nLen);

        //RPC Bug Fix:
        //Prevent easy memory exhaustion attack
        //Allocate memory for POST message data only as bytes come in, instead of
        //all at once at the beginning.
        vector<char> vch;
        size_t ptr = 0;
        while (ptr < (size_t)nLen)
        {
            size_t bytes_to_read = std::min((size_t)nLen - ptr, POST_READ_SIZE);
            vch.resize(ptr + bytes_to_read);
            stream.read(&vch[ptr], bytes_to_read);
            if (!stream) // Connection lost while reading
                return HTTP_INTERNAL_SERVER_ERROR;
            ptr += bytes_to_read;
        }
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
Ejemplo n.º 13
0
inline void ReadBSTRFromStream( std::basic_istream< WCHAR, CharTraitsT > &Istream, ATL::CComBSTR &Str )
{ 
   //Оптимизация исключающая временные объекты
   Str.Empty();

   WCHAR Buff[256];

   do 
   {
      Istream.read( Buff, APL_ARRSIZE(Buff) );
      Str.Append(Buff, Istream.gcount());   

   }
   while(Istream.gcount() == APL_ARRSIZE(Buff));

}
Ejemplo n.º 14
0
int Buffer::pushBytesFromStream(std::basic_istream<char>& istr, int cnt)
{
    if (writeAvailable() < cnt)
        cnt = writeAvailable();

    istr.read((char*)_tail, cnt);
    if (istr.eof())
    {
        cnt = istr.gcount();
    }
    else if (istr.fail())
    {
        return -1;
    }
    _tail += cnt;
    return cnt;
}
Ejemplo n.º 15
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto, size_t max_size)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || (size_t)nLen > max_size)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        vector<char> vch;
        size_t ptr = 0;
        while (ptr < (size_t)nLen)
        {
            size_t bytes_to_read = std::min((size_t)nLen - ptr, POST_READ_SIZE);
            vch.resize(ptr + bytes_to_read);
            stream.read(&vch[ptr], bytes_to_read);
            if (!stream) // Connection lost while reading
                return HTTP_INTERNAL_SERVER_ERROR;
            ptr += bytes_to_read;
        }
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
Ejemplo n.º 16
0
		friend std::basic_istream<charT, traits> & operator >> (
			std::basic_istream<charT, traits> &stream, const mytype &value)
		{
			return stream.read((char *)&value.value, sizeof(valueT));
		}