253 lines
3.8 KiB
C++
Executable File
253 lines
3.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "request.h"
|
|
#include "log.h"
|
|
#include "plugin.h"
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request() : char_empty(0)
|
|
{
|
|
id = 0;
|
|
}
|
|
|
|
|
|
void Request::SetConfig(Config * pconfig)
|
|
{
|
|
config = pconfig;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Request::ClearPostFileTmp()
|
|
{
|
|
// deleting temporary files (if exists)
|
|
|
|
while( !post_file_tab.empty() )
|
|
{
|
|
const std::string & tmp_filename = post_file_tab.begin()->second.tmp_filename;
|
|
|
|
if( unlink(tmp_filename.c_str()) == 0 )
|
|
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
|
|
|
|
post_file_tab.erase(post_file_tab.begin());
|
|
}
|
|
}
|
|
|
|
|
|
void Request::Clear()
|
|
{
|
|
// warning: don't clear: in, out, err, env
|
|
|
|
// id is never 0
|
|
if( ++id == 0 )
|
|
++id;
|
|
|
|
ClearPostFileTmp();
|
|
|
|
get_tab.clear();
|
|
post_tab.clear();
|
|
post_file_tab.clear();
|
|
cookie_tab.clear();
|
|
|
|
method = none;
|
|
role = responder;
|
|
|
|
headers.str("");
|
|
page.str("");
|
|
debug.str("");
|
|
|
|
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;
|
|
|
|
|
|
session = 0;
|
|
|
|
item_tab.clear();
|
|
item.Clear();
|
|
dir_tab.clear();
|
|
last_item = 0;
|
|
is_item = false;
|
|
function = 0;
|
|
param_tab.clear();
|
|
|
|
status = WINIX_ERR_OK;
|
|
|
|
notify_code = 0;
|
|
browser_msie = false;
|
|
redirect_to.clear();
|
|
x_sendfile.clear();
|
|
send_as_attachment = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
// value can be null
|
|
void Request::SetCookie(const char * name, const char * value, tm * expires)
|
|
{
|
|
headers << "Set-Cookie: " << name << "=";
|
|
|
|
if( value && value[0]!=0 )
|
|
headers << value;
|
|
else
|
|
headers << "\"\"";
|
|
|
|
if( expires )
|
|
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
|
|
|
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
|
}
|
|
|
|
|
|
|
|
void Request::SetCookie(const char * name, long value, tm * expires)
|
|
{
|
|
headers << "Set-Cookie: " << name << "=" << value;
|
|
|
|
if( expires )
|
|
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
|
|
|
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
|
}
|
|
|
|
|
|
|
|
bool Request::IsPostVar(const char * var)
|
|
{
|
|
PostTab::iterator p;
|
|
|
|
p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
const std::string & Request::PostVar(const char * var)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
return str_empty;
|
|
|
|
return p->second;
|
|
}
|
|
|
|
|
|
|
|
bool Request::PostVar(const char * var, std::string & result)
|
|
{
|
|
PostTab::iterator p = post_tab.find(var);
|
|
|
|
if( p == post_tab.end() )
|
|
{
|
|
result.clear();
|
|
return false;
|
|
}
|
|
|
|
result = p->second;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void Request::PrintGetTab()
|
|
{
|
|
debug << "get_tab: " << get_tab.size() << "\n";
|
|
|
|
for(GetTab::iterator i = get_tab.begin() ; i != get_tab.end() ; ++i)
|
|
debug << " \"" << *i << "\"\n";
|
|
|
|
debug << std::endl;
|
|
}
|
|
|
|
|
|
void Request::PrintEnv()
|
|
{
|
|
char ** e;
|
|
|
|
debug << "environment variables:\n";
|
|
|
|
for( e = env ; *e ; ++e )
|
|
debug << ' ' << *e << "\n";
|
|
|
|
debug << std::endl;
|
|
}
|
|
|
|
|
|
|
|
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 char * param_name)
|
|
{
|
|
ParamTab::iterator i;
|
|
|
|
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
{
|
|
// !! make sure that exists std::string::operator==(const char*)
|
|
// (optimization)
|
|
if( i->name == param_name )
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
const std::string & Request::ParamValue(const char * 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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|