Exemplo n.º 1
0
bool ProxySession::Transfer(FileDesc& src, FileDesc& dest, IParser& parser, std::error_code &ec)
{
    // until we're using an actual plugin, just read and write to a local buffer
    auto inBuff = parser.GetWriteSlice();
    auto numRead = read(src, inBuff, inBuff.Size());

    if(numRead < 0) {
            ec = std::error_code(errno, std::system_category());
            return false;
    }

    if(numRead == 0) {
            ec = Error::END_OF_FILE;
            return false;
    }


    if(m_config.observeOnly)
    {
        // in observe only mode we just write the data we read immediately
        // there is no guarantee that the parser doesn't modify the buffer

        this->WriteAll(dest, RSlice(inBuff, numRead), ec);

        // regardless of if there is any error or not, we feed the parser
        // but ignore whatever it outputs
        parser.Parse(numRead);
    }
    else
    {
        // now notify the parser that we wrote some data into its input buffer
        if(parser.Parse(numRead))
        {
            // if the parser didn't reject it, pass output anything the parser kicked back
            this->WriteOutputTo(dest, ec);
        }
        else
        {
            ec = Error::PARSER_REJECT;
        }
    }

    // always clear any unwritten slices due to error or explicit parser rejection
    this->m_output_vec.clear();

    return ec.value();
}
Exemplo n.º 2
0
void LinkLayerParser::TransferUserData()
{
	uint32_t len = header.GetLength() - LPDU_MIN_LENGTH;
	LinkFrame::ReadUserData(buffer.ReadBuffer() + LPDU_HEADER_SIZE, rxBuffer, len);
	userData = RSlice(rxBuffer, len);
}