152 lines
2.7 KiB
C++
Executable File
152 lines
2.7 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"
|
|
#include "plugin.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;
|
|
bool has_winix_post_params_msg;
|
|
bool has_winix_raw_post_msg;
|
|
std::string raw_post;
|
|
|
|
|
|
protected:
|
|
|
|
|
|
virtual int GetChar()
|
|
{
|
|
int c = FCGX_GetChar(in);
|
|
|
|
if( c != -1 && has_winix_raw_post_msg )
|
|
raw_post += c;
|
|
|
|
return c;
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
if( has_winix_post_params_msg )
|
|
plugin.Call(0, WINIX_POST_PARAMS, &name, &value);
|
|
|
|
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;
|
|
raw_post.clear();
|
|
|
|
has_winix_post_params_msg = plugin.HasMessage(WINIX_POST_PARAMS);
|
|
has_winix_raw_post_msg = plugin.HasMessage(WINIX_RAW_POST_STRING);
|
|
|
|
HttpSimpleParser::Parse();
|
|
|
|
if( has_winix_raw_post_msg )
|
|
plugin.Call(0, WINIX_RAW_POST_STRING, &raw_post);
|
|
|
|
raw_post.clear();
|
|
}
|
|
|
|
};
|
|
|
|
|
|
#endif
|