2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-10 05:42:49 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-05-19 17:14:35 +02:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2008-12-12 04:11:29 +01:00
|
|
|
Request::Request() : char_empty(0)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
id = 0;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
void Request::SetConfig(Config * pconfig)
|
|
|
|
{
|
|
|
|
config = pconfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
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
|
|
|
|
|
|
|
method = none;
|
2009-12-30 21:46:12 +01:00
|
|
|
role = responder;
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
headers.Clear();
|
|
|
|
page.Clear();
|
|
|
|
debug.Clear();
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
page_generated = false;
|
|
|
|
use_html_filter = true;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
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;
|
2009-10-08 19:59:10 +02:00
|
|
|
env_http_accept_encoding = &char_empty;
|
2011-09-07 00:46:15 +02:00
|
|
|
env_https = &char_empty;
|
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;
|
2011-01-20 19:37:51 +01:00
|
|
|
function = 0; // !! dodac jakas empty funkcje
|
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;
|
|
|
|
memset(&start_tm, 0, sizeof(start_tm));
|
2012-05-19 17:14:35 +02:00
|
|
|
start_date.Clear();
|
2012-04-22 20:23:44 +02:00
|
|
|
|
|
|
|
subdomain.clear();
|
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);
|
|
|
|
start_tm = Time(start_time);
|
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
|
|
|
|
|
|
|
// value can be null
|
2009-11-21 00:09:52 +01:00
|
|
|
void Request::SetCookie(const char * name, const char * value, tm * expires)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2009-11-21 00:09:52 +01:00
|
|
|
headers << "Set-Cookie: " << name << "=";
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
if( value && value[0]!=0 )
|
2009-11-21 00:09:52 +01:00
|
|
|
headers << value;
|
2008-12-10 05:42:49 +01:00
|
|
|
else
|
2009-11-21 00:09:52 +01:00
|
|
|
headers << "\"\"";
|
|
|
|
|
|
|
|
if( expires )
|
|
|
|
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2012-03-15 18:50:19 +01:00
|
|
|
headers << "; path=/; domain=" << config->base_url << "\r\n";
|
2012-03-15 11:43:29 +01:00
|
|
|
|
2012-03-15 18:50:19 +01:00
|
|
|
/*
|
|
|
|
don't use '; secure' flag if you are using both sites (with SSL
|
|
|
|
and without SSL) -- with secure flag the cookie is sent only through
|
|
|
|
SSL and if you accidentally open a new window without SSL (http://)
|
|
|
|
then winix will create a new session for you and the previous session (https://)
|
|
|
|
will be lost (cookie is overwritten on the client browser)
|
|
|
|
*/
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-21 00:09:52 +01:00
|
|
|
void Request::SetCookie(const char * name, long value, tm * expires)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2009-11-21 00:09:52 +01:00
|
|
|
headers << "Set-Cookie: " << name << "=" << value;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2009-11-21 00:09:52 +01:00
|
|
|
if( expires )
|
|
|
|
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2012-03-15 18:50:19 +01:00
|
|
|
headers << "; path=/; domain=" << config->base_url << "\r\n";
|
2009-11-21 00:09:52 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|