moved winix directories to winixd subdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1027 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
340
winixd/core/request.cpp
Normal file
340
winixd/core/request.cpp
Normal file
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Request::Request()
|
||||
{
|
||||
id = 0;
|
||||
config = 0;
|
||||
}
|
||||
|
||||
|
||||
void Request::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Request::ClearOutputStreams()
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
out_main_stream.Clear();
|
||||
|
||||
if( config )
|
||||
len = config->ezc_out_streams_size;
|
||||
|
||||
/*
|
||||
* clearing buffers and setting 'escape' flag to true
|
||||
* for all streams which were used in the map
|
||||
*/
|
||||
out_streams.ClearMap();
|
||||
out_streams.ResizeTab(len);
|
||||
out_main_stream_use_html_filter = true;
|
||||
out_streams_use_html_filter = 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.clear();
|
||||
env_request_uri.clear();
|
||||
env_http_cookie.clear();
|
||||
env_remote_addr.clear();
|
||||
env_http_host.clear();
|
||||
env_http_user_agent.clear();
|
||||
env_http_accept_encoding.clear();
|
||||
env_fcgi_role.clear();
|
||||
env_content_type.clear();
|
||||
env_https.clear();
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user