2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2008-12-10 05:42:49 +01:00
|
|
|
*/
|
2009-11-21 00:09:52 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
#include "request.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
2009-11-13 21:40:11 +01:00
|
|
|
#include "plugin.h"
|
2009-11-21 00:09:52 +01:00
|
|
|
#include "misc.h"
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
Request::Request()
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
id = 0;
|
2013-12-23 04:29:33 +01:00
|
|
|
config = 0;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
void Request::SetConfig(Config * pconfig)
|
|
|
|
{
|
|
|
|
config = pconfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Request::ClearOutputStreams()
|
2012-08-08 18:04:48 +02:00
|
|
|
{
|
2013-12-23 04:29:33 +01:00
|
|
|
size_t len = 16;
|
|
|
|
|
|
|
|
if( config )
|
|
|
|
len = config->ezc_out_streams_size;
|
2013-11-29 22:39:23 +01:00
|
|
|
|
|
|
|
if( len < 1 || len > 64 )
|
|
|
|
len = 16;
|
|
|
|
|
2014-11-06 22:17:41 +01:00
|
|
|
if( out_streams.size() != len )
|
|
|
|
out_streams.resize(len);
|
|
|
|
|
|
|
|
if( use_html_filter.size() != len )
|
|
|
|
use_html_filter.resize(len);
|
2012-08-08 18:04:48 +02:00
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
2013-12-04 02:21:57 +01:00
|
|
|
{
|
2013-11-14 21:59:23 +01:00
|
|
|
out_streams[i].Clear();
|
2014-11-06 22:17:41 +01:00
|
|
|
out_streams[i].Escape(true);
|
2013-12-04 02:21:57 +01:00
|
|
|
use_html_filter[i] = true;
|
|
|
|
}
|
2013-11-14 21:59:23 +01:00
|
|
|
}
|
2009-09-22 01:05:05 +02:00
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
void Request::Clear()
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
// id is never 0
|
|
|
|
if( ++id == 0 )
|
|
|
|
++id;
|
2010-01-06 20:17:53 +01:00
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
RemovePostFileTmp(post_file_tab);
|
2013-11-14 21:59:23 +01:00
|
|
|
ClearOutputStreams();
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
post_tab.clear();
|
|
|
|
post_file_tab.clear();
|
|
|
|
cookie_tab.clear();
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
method = unknown_method;
|
2013-11-14 21:59:23 +01:00
|
|
|
|
2013-11-29 22:39:23 +01:00
|
|
|
out_headers.Clear();
|
|
|
|
out_cookies.Clear();
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
page_generated = false;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
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();
|
2010-01-06 20:17:53 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
item_tab.clear();
|
2008-12-10 05:42:49 +01:00
|
|
|
item.Clear();
|
2010-08-10 22:43:38 +02:00
|
|
|
dir_tab.clear();
|
2011-01-20 19:37:51 +01:00
|
|
|
last_item = &item;
|
2008-12-30 02:05:03 +01:00
|
|
|
is_item = false;
|
2013-11-29 22:39:23 +01:00
|
|
|
function = 0;
|
2010-08-10 22:43:38 +02:00
|
|
|
param_tab.clear();
|
2011-07-29 00:18:10 +02:00
|
|
|
anchor.clear();
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
status = WINIX_ERR_OK;
|
2010-01-25 05:52:17 +01:00
|
|
|
|
2009-10-08 19:59:10 +02:00
|
|
|
browser_msie = false;
|
2009-11-17 02:04:01 +01:00
|
|
|
redirect_to.clear();
|
2011-07-07 19:02:14 +02:00
|
|
|
redirect_type = 303;
|
2010-02-19 00:30:22 +01:00
|
|
|
x_sendfile.clear();
|
|
|
|
send_as_attachment = false;
|
2011-09-07 00:46:15 +02:00
|
|
|
|
|
|
|
using_ssl = false;
|
2012-02-17 06:19:24 +01:00
|
|
|
|
|
|
|
start_time = 0;
|
2012-05-19 17:14:35 +02:00
|
|
|
start_date.Clear();
|
2012-04-22 20:23:44 +02:00
|
|
|
|
|
|
|
subdomain.clear();
|
2013-11-14 21:59:23 +01:00
|
|
|
return_info_only = false;
|
|
|
|
info.Clear();
|
|
|
|
info_serializer = 0;
|
|
|
|
return_json = false;
|
2012-08-26 21:53:47 +02:00
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
out_bin_stream.clear();
|
|
|
|
send_bin_stream = false;
|
2012-09-11 07:19:45 +02:00
|
|
|
|
2012-08-26 21:53:47 +02:00
|
|
|
gen_trim_white = false;
|
|
|
|
gen_skip_new_line = false;
|
|
|
|
gen_use_special_chars = false;
|
2012-10-27 09:44:26 +02:00
|
|
|
|
|
|
|
ip = 0;
|
2013-03-26 01:04:01 +01:00
|
|
|
use_200_status_for_not_found_and_permission_denied = false;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-17 06:19:24 +01:00
|
|
|
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);
|
2012-05-19 17:14:35 +02:00
|
|
|
start_date = start_time;
|
2012-02-17 06:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Request::IsPostVar(const wchar_t * var)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
PostTab::iterator p;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
p = post_tab.find(var);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( p == post_tab.end() )
|
2008-12-10 05:42:49 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
bool Request::IsPostVar(const std::wstring & var)
|
|
|
|
{
|
|
|
|
PostTab::iterator p;
|
|
|
|
|
|
|
|
p = post_tab.find(var);
|
|
|
|
|
|
|
|
if( p == post_tab.end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & Request::PostVar(const wchar_t * var)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
PostTab::iterator p = post_tab.find(var);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( p == post_tab.end() )
|
2010-08-12 21:10:12 +02:00
|
|
|
return str_empty;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
return p->second;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
PostTab::iterator p = post_tab.find(var);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( p == post_tab.end() )
|
2009-11-17 00:36:38 +01:00
|
|
|
{
|
|
|
|
result.clear();
|
2008-12-30 02:05:03 +01:00
|
|
|
return false;
|
2009-11-17 00:36:38 +01:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
result = p->second;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-17 02:04:01 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring * Request::PostVarp(const wchar_t * var)
|
2010-09-30 22:58:20 +02:00
|
|
|
{
|
|
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
|
|
|
|
if( p == post_tab.end() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &p->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-04 19:51:43 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-09 01:42:40 +01:00
|
|
|
bool Request::AllPostVarEmpty()
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
PostTab::iterator i;
|
2009-12-09 01:42:40 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(i=post_tab.begin() ; i!=post_tab.end() ; ++i)
|
2009-12-09 01:42:40 +01:00
|
|
|
if( !i->second.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool Request::IsParam(const wchar_t * param_name)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-11-23 22:52:25 +01:00
|
|
|
ParamTab::iterator i;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->name == param_name )
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Request::IsParam(const std::wstring & param_name)
|
|
|
|
{
|
2010-11-23 22:52:25 +01:00
|
|
|
ParamTab::iterator i;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-07-04 22:27:14 +02:00
|
|
|
if( i->name == param_name )
|
2008-12-30 02:05:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & Request::ParamValue(const wchar_t * param_name)
|
2010-07-04 22:27:14 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
ParamTab::iterator i;
|
2010-07-04 22:27:14 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
2010-07-04 22:27:14 +02:00
|
|
|
{
|
|
|
|
if( i->name == param_name )
|
|
|
|
return i->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str_empty;
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2011-02-11 22:37:28 +01:00
|
|
|
const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
|
|
|
{
|
|
|
|
return ParamValue(param_name.c_str());
|
|
|
|
}
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|