added: parser for multipart forms, files: postmultiparser.h postmultiparser.cpp
added: function: upload git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@543 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "request.h"
|
||||
#include "getparser.h"
|
||||
#include "postparser.h"
|
||||
@@ -31,6 +33,21 @@ void Request::Init()
|
||||
}
|
||||
|
||||
|
||||
void Request::ClearPostFileTmp()
|
||||
{
|
||||
// deleting temporary files (if exists)
|
||||
|
||||
while( !post_file_table.empty() )
|
||||
{
|
||||
const std::string & tmp_filename = post_file_table.begin()->second.tmp_filename;
|
||||
|
||||
if( unlink(tmp_filename.c_str()) == 0 )
|
||||
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
|
||||
|
||||
post_file_table.erase(post_file_table.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Request::Clear()
|
||||
{
|
||||
@@ -39,9 +56,10 @@ void Request::Clear()
|
||||
// id is never 0
|
||||
if( ++id == 0 )
|
||||
++id;
|
||||
|
||||
|
||||
get_table.clear();
|
||||
post_table.clear();
|
||||
post_file_table.clear();
|
||||
cookie_table.clear();
|
||||
|
||||
method = none;
|
||||
@@ -60,7 +78,9 @@ void Request::Clear()
|
||||
env_http_user_agent = &char_empty;
|
||||
env_http_accept_encoding = &char_empty;
|
||||
env_fcgi_role = &char_empty;
|
||||
|
||||
env_content_type = &char_empty;
|
||||
|
||||
|
||||
session = 0;
|
||||
|
||||
item_table.clear();
|
||||
@@ -241,6 +261,7 @@ void Request::ReadEnvVariables()
|
||||
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
|
||||
env_http_accept_encoding = SetEnvVar("HTTP_ACCEPT_ENCODING");
|
||||
env_fcgi_role = SetEnvVar("FCGI_ROLE");
|
||||
env_content_type = SetEnvVar("CONTENT_TYPE");
|
||||
}
|
||||
|
||||
|
||||
@@ -255,6 +276,8 @@ void Request::CheckIE()
|
||||
browser_msie = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::CheckKonqueror()
|
||||
{
|
||||
char * kon = strstr(env_http_user_agent, "Konqueror");
|
||||
@@ -300,13 +323,24 @@ return true;
|
||||
|
||||
void Request::ReadParameters()
|
||||
{
|
||||
// !! wrzucic jako skladowa klasy
|
||||
GetParser get_parser(env_request_uri, get_table);
|
||||
get_parser.Parse();
|
||||
|
||||
if( method == post )
|
||||
{
|
||||
PostParser post_parser(in, post_table);
|
||||
post_parser.Parse();
|
||||
if( IsSubStringNoCase("multipart/form-data", env_content_type) )
|
||||
{
|
||||
log << log3 << "Request: post content type: multipart/form-data" << logend;
|
||||
|
||||
post_multi_parser.Parse(in, post_table, post_file_table);
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! wrzucic jako skladowa klasy
|
||||
PostParser post_parser(in, post_table);
|
||||
post_parser.Parse();
|
||||
}
|
||||
}
|
||||
|
||||
CookieParser cookie_parser(env_http_cookie, cookie_table);
|
||||
@@ -739,6 +773,23 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseUpload(const Item & item, bool check_root)
|
||||
{
|
||||
// you can use 'upload' only in a directory
|
||||
if( item.type != Item::dir )
|
||||
return false;
|
||||
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use mkdir everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseHtml(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
@@ -787,3 +838,24 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
bool Request::MakeDirsOnFS(std::string & path)
|
||||
{
|
||||
size_t i;
|
||||
path = "/home/tomek/roboczy/slimaczek.pl/static_auth"; // !! dodac do konfiga
|
||||
|
||||
// skipping the first - the first is root
|
||||
for(i=1 ; i<dir_table.size() ; ++i)
|
||||
{
|
||||
path += '/';
|
||||
path += dir_table[i]->url;
|
||||
|
||||
if( mkdir(path.c_str(), 0750) < 0 )
|
||||
{
|
||||
// oops
|
||||
log << log1 << "Request: can't create the directory on fs: " << path << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user