2008-12-10 05:42:49 +01:00
/*
* This file is a part of CMSLU - - Content Management System like Unix
* and is not publicly distributed
*
2009-04-21 22:50:55 +02:00
* Copyright ( c ) 2008 - 2009 , Tomasz Sowa
2008-12-10 05:42:49 +01:00
* All rights reserved .
*
*/
2009-04-21 22:50:55 +02:00
# ifndef headerfilecmslucorerequest
# define headerfilecmslucorerequest
2008-12-10 05:42:49 +01:00
# include <fcgiapp.h>
# include <sstream>
# include <vector>
2008-12-30 02:05:03 +01:00
# include <ctime>
# include <iomanip>
2009-04-21 22:50:55 +02:00
2008-12-10 05:42:49 +01:00
# include "requesttypes.h"
# include "session.h"
# include "item.h"
# include "error.h"
2008-12-30 02:05:03 +01:00
# include "function.h"
2009-04-21 01:49:28 +02:00
# include "thread.h"
2009-09-22 01:05:05 +02:00
# include "compress.h"
2008-12-10 05:42:49 +01:00
2009-04-21 22:50:55 +02:00
2008-12-10 05:42:49 +01:00
struct Request
{
2008-12-30 02:05:03 +01:00
// 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 ;
2008-12-10 05:42:49 +01:00
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 ;
2008-12-12 04:11:29 +01:00
// 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'
2008-12-10 05:42:49 +01:00
const char * env_request_method ;
const char * env_request_uri ;
const char * env_http_cookie ;
2008-12-11 03:46:16 +01:00
const char * env_remote_addr ;
2008-12-12 04:11:29 +01:00
const char * env_http_host ;
2008-12-30 02:05:03 +01:00
const char * env_http_user_agent ;
2008-12-10 05:42:49 +01:00
// current session
// is set after calling session_manager.SetSession()
Session * session ;
// 'done_status' is set if 'done' is different than 'nothing'
2008-12-30 02:05:03 +01:00
Error done_status ; // !! wywalic - jest przeciez w session
2008-12-10 05:42:49 +01:00
// what to do
2009-01-26 21:49:28 +01:00
// !! wywalic?
2008-12-21 22:17:09 +01:00
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
2008-12-14 06:28:28 +01:00
2008-12-30 02:05:03 +01:00
// !! nowe skladowe
2008-12-10 05:42:49 +01:00
2008-12-30 02:05:03 +01:00
// current directory
// !! zapewnic aby byl minimum jeden katalog (root)
2008-12-10 05:42:49 +01:00
2008-12-30 02:05:03 +01:00
// !! moze nazwac to poprostu dir?
std : : vector < Item * > dir_table ;
2008-12-10 05:42:49 +01:00
2008-12-30 02:05:03 +01:00
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 ;
2008-12-10 05:42:49 +01:00
2008-12-30 02:05:03 +01:00
Error status ;
// ------------------
// !! stare skladowe
// current directory e.g. /foo/bar
//std::vector<Item> cur_dir_table;
2008-12-10 05:42:49 +01:00
// id of the last directory (bar) or -1
2008-12-30 02:05:03 +01:00
//long dir;
// ------------------
2008-12-10 05:42:49 +01:00
// items in the current directory
// maybe without contents?
std : : vector < Item > item_table ;
// directories in the current directory
2008-12-30 02:05:03 +01:00
//std::vector<Item> dir_table2;
2008-12-10 05:42:49 +01:00
2009-04-21 01:49:28 +02:00
// current thread (if exists)
2009-06-05 22:29:06 +02:00
bool is_thread ;
2009-04-21 01:49:28 +02:00
Thread thread ;
2008-12-10 05:42:49 +01:00
2009-06-05 22:29:06 +02:00
std : : vector < Thread > thread_tab ;
2008-12-10 05:42:49 +01:00
// this string is used for many purposes such as redirecting
std : : string str ;
// for debugging
void PrintGetTable ( ) ;
void PrintEnv ( ) ;
void PrintIn ( ) ;
Request ( ) ;
void Clear ( ) ;
2009-09-22 01:05:05 +02:00
void Init ( ) ;
2008-12-10 05:42:49 +01:00
2008-12-30 02:05:03 +01:00
bool IsParam ( const char * s ) ;
2008-12-10 05:42:49 +01:00
void SetCookie ( const char * name , const char * value ) ;
void SetCookie ( const char * name , long value ) ;
bool IsPostVar ( const char * var ) ;
2009-05-21 21:27:16 +02:00
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
2008-12-30 02:05:03 +01:00
//bool PostVar(const char * var, std::string & result);
2008-12-10 05:42:49 +01:00
// item_table[0] -> item
2008-12-30 02:05:03 +01:00
// !! to tez nie bedzie potrzebne
2008-12-10 05:42:49 +01:00
void CopyFirstItem ( ) ;
void ReadEnvVariables ( ) ;
void CheckMethod ( ) ;
void ReadParameters ( ) ;
void Read ( ) ;
void SendAll ( ) ;
2008-12-21 22:17:09 +01:00
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 ) ;
2008-12-22 17:03:03 +01:00
bool HasReadExecAccess ( const Item & item ) ;
2009-01-26 21:49:28 +01:00
2009-06-05 22:29:06 +02:00
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 ) ;
2009-01-26 21:49:28 +01:00
2009-06-05 22:29:06 +02:00
bool CanUseHtml ( long user_id ) ;
bool CanUseBBCode ( long user_id ) ;
2008-12-21 22:17:09 +01:00
2008-12-12 04:11:29 +01:00
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 ) ;
2008-12-30 02:05:03 +01:00
void StandardLog ( ) ;
2009-09-22 01:05:05 +02:00
Compress compress ;
2009-01-26 21:49:28 +01:00
2008-12-10 05:42:49 +01:00
} ;
extern Request request ;
# endif