1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
Copyright (©) 2003-2025 Teus Benschop.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <webserver/request.h>
Webserver_Request::Webserver_Request ()
{
secure = false;
get = "/index";
is_post = false;
user_agent.assign ("Browser/1.0");
accept_language = "en-US";
content_length = 0;
response_code = 200;
resend_cookie = false;
}
Webserver_Request::~Webserver_Request ()
{
if (session_logic_instance)
delete session_logic_instance;
if (database_config_user_instance)
delete database_config_user_instance;
if (database_users_instance)
delete database_users_instance;
if (database_ipc_instance)
delete database_ipc_instance;
}
int Webserver_Request::post_count(const std::string& key) const
{
int count {0};
for (const auto& element : post) {
if (element.first == key)
count++;
}
return count;
}
std::string Webserver_Request::post_get(const std::string& key) const
{
for (const auto& element : post)
if (element.first == key)
return element.second;
return std::string();
}
// Returns a pointer to a live Session_Logic object.
Session_Logic * Webserver_Request::session_logic ()
{
// Single live object during the entire web request.
if (!session_logic_instance)
session_logic_instance = new Session_Logic (*this);
return session_logic_instance;
}
// Returns a pointer to a live Database_Config_User object.
Database_Config_User * Webserver_Request::database_config_user ()
{
// Single live object during the entire web request.
if (!database_config_user_instance)
database_config_user_instance = new Database_Config_User (*this);
return database_config_user_instance;
}
// Returns a pointer to a live Database_Users object.
Database_Users * Webserver_Request::database_users ()
{
// Single live object during the entire web request.
if (!database_users_instance)
database_users_instance = new Database_Users ();
return database_users_instance;
}
Database_Ipc * Webserver_Request::database_ipc ()
{
if (!database_ipc_instance)
database_ipc_instance = new Database_Ipc (*this);
return database_ipc_instance;
}
|