winix/core/postparser.h

131 lines
2.1 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2012, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_postparser
#define headerfile_winix_core_postparser
#include <fcgiapp.h>
#include <string>
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "misc.h"
#include "utf8/utf8.h"
#include "log.h"
#include "config.h"
class PostParser : public HttpSimpleParser
{
FCGX_Stream * in;
PostTab * post_tab;
std::wstring temp_name, temp_value;
bool input_as_utf8;
size_t log_value_size;
int var_index;
protected:
virtual int GetChar()
{
return FCGX_GetChar(in);
}
void CreateLog(bool param_added)
{
log << log2 << "Method POST, name: \"" << temp_name << "\"";
if( log_value_size > 0 && !IsSubStringNoCase(L"pass", temp_name.c_str()) )
{
log << ", value: ";
if( temp_value.size() > log_value_size )
log << "(first " << log_value_size << " characters) ";
log << "\"";
log.LogString(temp_value, log_value_size);
log << "\" (size: " << temp_value.size() << ")";
}
if( param_added == false )
log << log2 << " (skipped)";
log << log2 << logend;
}
void ConvStr(const std::string & src, std::wstring & dst)
{
if( input_as_utf8 )
PT::UTF8ToWide(src, dst);
else
AssignString(src, dst);
}
virtual void Parameter(std::string & name, std::string & value)
{
bool added;
std::pair<PostTab::iterator, bool> res;
ConvStr(name, temp_name);
ConvStr(value, temp_value);
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
added = res.second;
if( !added )
{
temp_name += L"_inc";
temp_name += Toa(var_index);
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
added = res.second;
var_index += 1;
}
CreateLog(added);
}
public:
PostParser()
{
input_as_utf8 = false;
log_value_size = 0;
}
void UTF8(bool utf)
{
input_as_utf8 = utf;
}
void LogValueSize(size_t s)
{
log_value_size = s;
}
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
{
in = in_;
post_tab = &post_tab_;
var_index = 1;
HttpSimpleParser::Parse();
}
};
#endif