317 lines
4.5 KiB
C++
Executable File
317 lines
4.5 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "request.h"
|
|
#include "log.h"
|
|
#include "plugin.h"
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
namespace Winix
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request() : char_empty(0)
|
|
{
|
|
id = 0;
|
|
config = 0;
|
|
}
|
|
|
|
|
|
void Request::SetConfig(Config * pconfig)
|
|
{
|
|
config = pconfig;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Request::ClearOutputStreams()
|
|
{
|
|
size_t len = 16;
|
|
|
|
if( config )
|
|
len = config->ezc_out_streams_size;
|
|
|
|
if( len < 1 || len > 64 )
|
|
len = 16;
|
|
|
|
out_streams.resize(len);
|
|
use_html_filter.resize(len);
|
|
|
|
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
|
{
|
|
out_streams[i].Clear();
|
|
use_html_filter[i] = true;
|
|
}
|
|
}
|
|
|
|
|
|
void Request::Clear()
|
|
{
|
|
// id is never 0
|
|
if( ++id == 0 )
|
|
++id;
|
|
|
|
RemovePostFileTmp(post_file_tab);
|
|
ClearOutputStreams();
|
|
|
|
post_tab.clear();
|
|
post_file_tab.clear();
|
|
cookie_tab.clear();
|
|
|
|
method = unknown_method;
|
|
|
|
out_headers.Clear();
|
|
out_cookies.Clear();
|
|
|
|
page_generated = false;
|
|
|
|
env_request_method = &char_empty;
|
|
env_request_uri = &char_empty;
|
|
env_http_cookie = &char_empty;
|
|
env_remote_addr = &char_empty;
|
|
env_http_host = &char_empty;
|
|
env_http_user_agent = &char_empty;
|
|
env_fcgi_role = &char_empty;
|
|
env_content_type = &char_empty;
|
|
env_http_accept_encoding = &char_empty;
|
|
env_https = &char_empty;
|
|
|
|
item_tab.clear();
|
|
item.Clear();
|
|
dir_tab.clear();
|
|
last_item = &item;
|
|
is_item = false;
|
|
function = 0;
|
|
param_tab.clear();
|
|
anchor.clear();
|
|
|
|
status = WINIX_ERR_OK;
|
|
|
|
browser_msie = false;
|
|
redirect_to.clear();
|
|
redirect_type = 303;
|
|
x_sendfile.clear();
|
|
send_as_attachment = false;
|
|
|
|
using_ssl = false;
|
|
|
|
start_time = 0;
|
|
start_date.Clear();
|
|
|
|
subdomain.clear();
|
|
return_info_only = false;
|
|
info.Clear();
|
|
info_serializer = 0;
|
|
return_json = false;
|
|
|
|
out_bin_stream.clear();
|
|
send_bin_stream = false;
|
|
|
|
gen_trim_white = false;
|
|
gen_skip_new_line = false;
|
|
gen_use_special_chars = false;
|
|
|
|
ip = 0;
|
|
use_200_status_for_not_found_and_permission_denied = false;
|
|
}
|
|
|
|
|
|
|
|
void Request::RequestStarts()
|
|
{
|
|
// clearing it is better to use at the end of a request
|
|
// so starting is much faster
|
|
|
|
start_time = std::time(0);
|
|
start_date = start_time;
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Request::IsPostVar(const wchar_t * var)
|
|
{
|
|
PostTab::iterator p;
|
|
|
|
p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool Request::IsPostVar(const std::wstring & var)
|
|
{
|
|
PostTab::iterator p;
|
|
|
|
p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
const std::wstring & Request::PostVar(const wchar_t * var)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return str_empty;
|
|
|
|
return p->second;
|
|
}
|
|
|
|
|
|
const std::wstring & Request::PostVar(const std::wstring & var)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return str_empty;
|
|
|
|
return p->second;
|
|
}
|
|
|
|
|
|
|
|
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
{
|
|
result.clear();
|
|
return false;
|
|
}
|
|
|
|
result = p->second;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool Request::PostVar(const std::wstring & var, std::wstring & result)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
{
|
|
result.clear();
|
|
return false;
|
|
}
|
|
|
|
result = p->second;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
std::wstring * Request::PostVarp(const wchar_t * var)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return 0;
|
|
|
|
return &p->second;
|
|
}
|
|
|
|
|
|
std::wstring * Request::PostVarp(const std::wstring & var)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return 0;
|
|
|
|
return &p->second;
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Request::AllPostVarEmpty()
|
|
{
|
|
PostTab::iterator i;
|
|
|
|
for(i=post_tab.begin() ; i!=post_tab.end() ; ++i)
|
|
if( !i->second.empty() )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
bool Request::IsParam(const wchar_t * param_name)
|
|
{
|
|
ParamTab::iterator i;
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
{
|
|
if( i->name == param_name )
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
bool Request::IsParam(const std::wstring & param_name)
|
|
{
|
|
ParamTab::iterator i;
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
{
|
|
if( i->name == param_name )
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
const std::wstring & Request::ParamValue(const wchar_t * param_name)
|
|
{
|
|
ParamTab::iterator i;
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
{
|
|
if( i->name == param_name )
|
|
return i->value;
|
|
}
|
|
|
|
return str_empty;
|
|
}
|
|
|
|
|
|
const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
|
{
|
|
return ParamValue(param_name.c_str());
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|
|
|