winix/core/request.h

193 lines
4.3 KiB
C++
Executable File

/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008-2009, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorerequest
#define headerfilecmslucorerequest
#include <fcgiapp.h>
#include <sstream>
#include <vector>
#include <ctime>
#include <iomanip>
#include "requesttypes.h"
#include "session.h"
#include "item.h"
#include "error.h"
#include "function.h"
#include "thread.h"
#include "compress.h"
struct Request
{
// request id
// is incremented for each request and is never 0
// (from -1 will be incremented twice)
// it's used for some optimalization e.g. in templates
size_t id;
FCGX_Stream * in, * out, * err;
FCGX_ParamArray env; // defined as 'char **'
enum Method { get, post, none } method;
// headers, page and debug
std::ostringstream headers, page, debug;
GetTable get_table;
PostTable post_table;
CookieTable cookie_table;
// environment variables
// they are not null -- when the server doesn't have such a variable it will be pointing into 'char_empty' which is default '\0'
const char * env_request_method;
const char * env_request_uri;
const char * env_http_cookie;
const char * env_remote_addr;
const char * env_http_host;
const char * env_http_user_agent;
// current session
// is set after calling session_manager.SetSession()
Session * session;
// 'done_status' is set if 'done' is different than 'nothing'
Error done_status; // !! wywalic - jest przeciez w session
// what to do
// !! wywalic?
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
// !! nowe skladowe
// current directory
// !! zapewnic aby byl minimum jeden katalog (root)
// !! moze nazwac to poprostu dir?
std::vector<Item*> dir_table;
bool is_item;
// this item is used for many purposes such as editing, adding an item etc.
Item item;
// null if there is no a function
Function * pfunction;
// !! moze nazwac to poprostu param?
std::vector<std::string*> param_table;
Error status;
// ------------------
// !! stare skladowe
// current directory e.g. /foo/bar
//std::vector<Item> cur_dir_table;
// id of the last directory (bar) or -1
//long dir;
// ------------------
// items in the current directory
// maybe without contents?
std::vector<Item> item_table;
// directories in the current directory
//std::vector<Item> dir_table2;
// current thread (if exists)
bool is_thread;
Thread thread;
std::vector<Thread> thread_tab;
// this string is used for many purposes such as redirecting
std::string str;
// for debugging
void PrintGetTable();
void PrintEnv();
void PrintIn();
Request();
void Clear();
void Init();
bool IsParam(const char * s);
void SetCookie(const char * name, const char * value);
void SetCookie(const char * name, long value);
bool IsPostVar(const char * var);
std::string & PostVar(const char * var); // with a throw !!! wywalic te wyjatki ztad, niech zwraca pusty string jak nie znajdzie nic, albo referencje na jakis statyczny pusty string
//bool PostVar(const char * var, std::string & result);
// item_table[0] -> item
// !! to tez nie bedzie potrzebne
void CopyFirstItem();
void ReadEnvVariables();
void CheckMethod();
void ReadParameters();
void Read();
void SendAll();
bool CanChangeUser(const Item & item, long new_user_id);
bool CanChangeGroup(const Item & item, long new_group_id);
bool CanChangePrivileges(const Item & item, int new_priv);
bool HasAccess(const Item & item, int mask);
bool HasReadAccess(const Item & item);
bool HasWriteAccess(const Item & item);
bool HasReadWriteAccess(const Item & item);
bool HasReadExecAccess(const Item & item);
bool CanCreateThread(bool check_root = false);
bool CanRemove(const Item & item);
bool CanUseEmacs(const Item & item, bool check_root = false);
bool CanUseMkdir(const Item & item, bool check_root = false);
bool CanUseHtml(long user_id);
bool CanUseBBCode(long user_id);
private:
// used to set some env_* variables into it, when the server didn't set that variable
// it contains '\0'
const char char_empty;
const char * SetEnvVar(const char * var);
void StandardLog();
Compress compress;
};
extern Request request;
#endif