2010-01-06 20:17:53 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2010-01-06 20:17:53 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2011-06-24 22:53:21 +02:00
|
|
|
* Copyright (c) 2008-2011, Tomasz Sowa
|
2010-01-06 20:17:53 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_postmultiparser
|
|
|
|
#define headerfile_winix_core_postmultiparser
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fcgiapp.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include "error.h"
|
|
|
|
#include "requesttypes.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "config.h"
|
2011-06-24 22:53:21 +02:00
|
|
|
#include "misc.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
// 2 MB
|
2010-02-11 21:56:52 +01:00
|
|
|
#define WINIX_POSTMULTI_INPUT_BUFFER 2097152
|
|
|
|
#define WINIX_POSTMULTI_OUTPUT_BUFFER 2097152
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PostMultiParser
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
PostMultiParser();
|
|
|
|
PostMultiParser(const PostMultiParser &);
|
|
|
|
PostMultiParser & operator=(const PostMultiParser &);
|
|
|
|
~PostMultiParser();
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void SetConfig(Config * pconfig);
|
2010-08-10 22:43:38 +02:00
|
|
|
Error Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_);
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Config * config;
|
|
|
|
|
2010-01-06 20:17:53 +01:00
|
|
|
FCGX_Stream * in;
|
|
|
|
unsigned char * in_buffer;
|
|
|
|
std::ofstream tmp_file;
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring tmp_filename;
|
|
|
|
std::string atmp_filename;
|
2010-01-06 20:17:53 +01:00
|
|
|
int tmp_filename_postfix;
|
|
|
|
size_t in_buffer_ind;
|
|
|
|
size_t in_buffer_len;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
PostTab * post_tab;
|
|
|
|
PostFileTab * post_file_tab;
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
int last; // last read character
|
2011-06-24 22:53:21 +02:00
|
|
|
int var_index; // used as a postfix to the same name (is auto increment)
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
bool line_end_dos;
|
|
|
|
std::string boundary;
|
|
|
|
std::string content;
|
|
|
|
size_t content_len;
|
|
|
|
|
|
|
|
std::string header_name, header_value;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
std::string name, filename;
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring namew, contentw;
|
2010-01-06 20:17:53 +01:00
|
|
|
PostFile post_file_temp;
|
|
|
|
|
|
|
|
void LogFirst(const std::string & to_log, size_t len);
|
2011-06-24 22:53:21 +02:00
|
|
|
void ConvStr(const std::string & src, std::wstring & dst);
|
2010-01-06 20:17:53 +01:00
|
|
|
|
|
|
|
bool IsWhite(int c);
|
|
|
|
void SkipWhite();
|
|
|
|
|
|
|
|
void AddNormalPostVar();
|
|
|
|
void AddFilePostVar();
|
|
|
|
void AddPostVar();
|
|
|
|
|
|
|
|
void ReadBoundary();
|
|
|
|
|
|
|
|
bool IsHeader();
|
|
|
|
void ReadHeaderName();
|
|
|
|
void ReadHeaderValue();
|
|
|
|
void ReadPartHeader();
|
|
|
|
|
|
|
|
void CreateTmpFile();
|
|
|
|
bool HasBoundary();
|
|
|
|
void ReadContentSkipBoundary(bool has_boundary);
|
|
|
|
void ReadContentToFileLoop();
|
|
|
|
void ReadContentToFile();
|
|
|
|
void ReadContentLoop();
|
|
|
|
void ReadContent();
|
|
|
|
void CheckBoundaryEnd();
|
|
|
|
void ReadPart();
|
|
|
|
|
|
|
|
void ReadChar();
|
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
template<class Container, class Value>
|
|
|
|
bool InsertPostVar(Container & container, std::wstring & key, const Value & value);
|
|
|
|
|
2010-01-06 20:17:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
template<class Container, class Value>
|
|
|
|
bool PostMultiParser::InsertPostVar(Container & container, std::wstring & key, const Value & value)
|
|
|
|
{
|
|
|
|
bool added;
|
|
|
|
std::pair<typename Container::iterator, bool> res;
|
|
|
|
|
|
|
|
res = container.insert( std::make_pair(key, value) );
|
|
|
|
added = res.second;
|
|
|
|
|
|
|
|
if( !added )
|
|
|
|
{
|
|
|
|
key += L"_inc";
|
|
|
|
key += Toa(var_index);
|
|
|
|
res = container.insert( std::make_pair(key, value) );
|
|
|
|
added = res.second;
|
|
|
|
var_index += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return added;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-06 20:17:53 +01:00
|
|
|
#endif
|