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:
2010-01-06 19:17:53 +00:00
parent 60fccea703
commit 81faca041a
22 changed files with 1016 additions and 132 deletions

View File

@@ -6,20 +6,20 @@ cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
cat.o: ../core/error.h ../core/log.h ../core/user.h ../core/rebus.h
cat.o: ../core/function.h ../core/thread.h ../core/compress.h
cat.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
cat.o: ../core/htmlfilter.h ../core/error.h
cat.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/error.h
content.o: content.h ../core/item.h ../templates/templates.h
content.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
content.o: ../core/requesttypes.h ../core/session.h ../core/done.h
content.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
content.o: ../core/rebus.h ../core/function.h ../core/thread.h
content.o: ../core/compress.h ../core/acceptencodingparser.h
content.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
content.o: ../core/db.h ../core/group.h ../core/dircontainer.h
content.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h
content.o: ../core/users.h ../core/groups.h ../core/functions.h
content.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
content.o: ../core/misc.h ../core/plugin.h ../core/request.h ../core/data.h
content.o: ../core/pluginmsg.h
content.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
content.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
content.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
content.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
content.o: ../core/mount.h ../core/misc.h ../core/plugin.h ../core/request.h
content.o: ../core/data.h ../core/pluginmsg.h
createthread.o: content.h ../core/item.h ../templates/templates.h
createthread.o: ../templates/patterncacher.h ../core/thread.h
createthread.o: ../core/request.h ../core/requesttypes.h ../core/session.h
@@ -27,9 +27,10 @@ createthread.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
createthread.o: ../core/user.h ../core/rebus.h ../core/function.h
createthread.o: ../core/thread.h ../core/compress.h
createthread.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
createthread.o: ../core/htmlfilter.h ../core/error.h ../core/db.h
createthread.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
createthread.o: ../core/mount.h ../core/data.h ../core/dirs.h ../core/users.h
createthread.o: ../core/htmlfilter.h ../core/postmultiparser.h
createthread.o: ../core/error.h ../core/db.h ../core/group.h
createthread.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/mount.h
createthread.o: ../core/data.h ../core/dirs.h ../core/users.h
createthread.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
createthread.o: ../core/mounts.h ../core/mount.h
default.o: content.h ../core/item.h ../templates/templates.h
@@ -38,22 +39,24 @@ default.o: ../core/requesttypes.h ../core/session.h ../core/done.h
default.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
default.o: ../core/rebus.h ../core/function.h ../core/thread.h
default.o: ../core/compress.h ../core/acceptencodingparser.h
default.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
default.o: ../core/db.h ../core/group.h ../core/dircontainer.h
default.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h
default.o: ../core/users.h ../core/groups.h ../core/functions.h
default.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
default.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
default.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
default.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
default.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
default.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
default.o: ../core/mount.h
emacs.o: content.h ../core/item.h ../templates/templates.h
emacs.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
emacs.o: ../core/requesttypes.h ../core/session.h ../core/done.h
emacs.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
emacs.o: ../core/rebus.h ../core/function.h ../core/thread.h
emacs.o: ../core/compress.h ../core/acceptencodingparser.h
emacs.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
emacs.o: ../core/db.h ../core/group.h ../core/dircontainer.h
emacs.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
emacs.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
emacs.o: ../core/mounts.h ../core/mount.h ../core/notify.h
emacs.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
emacs.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
emacs.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
emacs.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
emacs.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
emacs.o: ../core/mount.h ../core/notify.h
emacs.o: ../templatesnotify/templatesnotify.h ../core/mount.h ../core/misc.h
last.o: content.h ../core/item.h ../templates/templates.h
last.o: ../templates/patterncacher.h ../core/thread.h
@@ -63,41 +66,43 @@ login.o: ../core/requesttypes.h ../core/session.h ../core/done.h
login.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
login.o: ../core/rebus.h ../core/function.h ../core/thread.h
login.o: ../core/compress.h ../core/acceptencodingparser.h
login.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
login.o: ../core/db.h ../core/group.h ../core/dircontainer.h
login.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
login.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
login.o: ../core/mounts.h ../core/mount.h
login.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
login.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
login.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
login.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
login.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
login.o: ../core/mount.h
logout.o: content.h ../core/item.h ../templates/templates.h
logout.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
logout.o: ../core/requesttypes.h ../core/session.h ../core/done.h
logout.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
logout.o: ../core/rebus.h ../core/function.h ../core/thread.h
logout.o: ../core/compress.h ../core/acceptencodingparser.h
logout.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/data.h
logout.o: ../core/dirs.h ../core/dircontainer.h ../core/users.h
logout.o: ../core/ugcontainer.h ../core/groups.h ../core/group.h
logout.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
logout.o: ../core/mount.h
logout.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
logout.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
logout.o: ../core/dircontainer.h ../core/users.h ../core/ugcontainer.h
logout.o: ../core/groups.h ../core/group.h ../core/functions.h
logout.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
ls.o: content.h ../core/item.h ../templates/templates.h
ls.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
ls.o: ../core/error.h ../core/log.h ../core/user.h ../core/rebus.h
ls.o: ../core/function.h ../core/thread.h ../core/compress.h
ls.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
ls.o: ../core/htmlfilter.h ../core/db.h ../core/group.h
ls.o: ../core/dircontainer.h ../core/ugcontainer.h
ls.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/db.h
ls.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
mkdir.o: content.h ../core/item.h ../templates/templates.h
mkdir.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
mkdir.o: ../core/requesttypes.h ../core/session.h ../core/done.h
mkdir.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
mkdir.o: ../core/rebus.h ../core/function.h ../core/thread.h
mkdir.o: ../core/compress.h ../core/acceptencodingparser.h
mkdir.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
mkdir.o: ../core/db.h ../core/group.h ../core/dircontainer.h
mkdir.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
mkdir.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
mkdir.o: ../core/mounts.h ../core/mount.h ../core/notify.h
mkdir.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
mkdir.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
mkdir.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
mkdir.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
mkdir.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
mkdir.o: ../core/mount.h ../core/notify.h
mkdir.o: ../templatesnotify/templatesnotify.h ../core/mount.h
node.o: content.h ../core/item.h ../templates/templates.h
node.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
@@ -106,51 +111,67 @@ node.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
node.o: ../core/rebus.h ../core/function.h ../core/thread.h
node.o: ../core/compress.h ../core/acceptencodingparser.h
node.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
node.o: ../core/postmultiparser.h
priv.o: content.h ../core/item.h ../templates/templates.h
priv.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
priv.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
priv.o: ../core/rebus.h ../core/function.h ../core/thread.h
priv.o: ../core/compress.h ../core/acceptencodingparser.h
priv.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
priv.o: ../core/db.h ../core/group.h ../core/dircontainer.h
priv.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
priv.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
priv.o: ../core/mounts.h ../core/mount.h
priv.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
priv.o: ../core/postmultiparser.h ../core/error.h ../core/db.h
priv.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
priv.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
priv.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
priv.o: ../core/mount.h
reload.o: content.h ../core/item.h ../templates/templates.h
reload.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
reload.o: ../core/requesttypes.h ../core/session.h ../core/done.h
reload.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
reload.o: ../core/rebus.h ../core/function.h ../core/thread.h
reload.o: ../core/compress.h ../core/acceptencodingparser.h
reload.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/error.h
reload.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
reload.o: ../core/postmultiparser.h ../core/error.h
rm.o: content.h ../core/item.h ../templates/templates.h
rm.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
rm.o: ../core/error.h ../core/log.h ../core/user.h ../core/rebus.h
rm.o: ../core/function.h ../core/thread.h ../core/compress.h
rm.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
rm.o: ../core/htmlfilter.h ../core/error.h ../core/db.h ../core/group.h
rm.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
rm.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
rm.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
rm.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/error.h
rm.o: ../core/db.h ../core/group.h ../core/dircontainer.h
rm.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
rm.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
rm.o: ../core/mounts.h ../core/mount.h
run.o: content.h ../core/item.h ../templates/templates.h
run.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
run.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
run.o: ../core/error.h ../core/log.h ../core/user.h ../core/rebus.h
run.o: ../core/function.h ../core/thread.h ../core/compress.h
run.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
run.o: ../core/htmlfilter.h ../core/error.h
run.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/error.h
thread.o: content.h ../core/item.h ../templates/templates.h
thread.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
thread.o: ../core/requesttypes.h ../core/session.h ../core/done.h
thread.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
thread.o: ../core/rebus.h ../core/function.h ../core/thread.h
thread.o: ../core/compress.h ../core/acceptencodingparser.h
thread.o: ../core/acceptbaseparser.h ../core/htmlfilter.h ../core/db.h
thread.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
thread.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
thread.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
thread.o: ../core/mount.h ../core/mount.h
thread.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
thread.o: ../core/postmultiparser.h ../core/db.h ../core/group.h
thread.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
thread.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
thread.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
thread.o: ../core/mount.h
upload.o: content.h ../core/item.h ../templates/templates.h
upload.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
upload.o: ../core/requesttypes.h ../core/session.h ../core/done.h
upload.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
upload.o: ../core/rebus.h ../core/function.h ../core/thread.h
upload.o: ../core/compress.h ../core/acceptencodingparser.h
upload.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
upload.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
upload.o: ../core/dircontainer.h ../core/users.h ../core/ugcontainer.h
upload.o: ../core/groups.h ../core/group.h ../core/functions.h
upload.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
who.o: content.h ../core/item.h ../templates/templates.h
who.o: ../templates/patterncacher.h ../core/thread.h

View File

@@ -1 +1 @@
o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o reload.o rm.o run.o thread.o who.o
o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o reload.o rm.o run.o thread.o upload.o who.o

View File

@@ -181,6 +181,9 @@ void Content::MakeStandardFunction()
else
if( request.pfunction->code == FUN_CREATETHREAD )
FunCreateThread();
else
if( request.pfunction->code == FUN_UPLOAD )
FunUpload();
else
request.status = Error::permision_denied;
@@ -238,6 +241,10 @@ void Content::MakePost()
PostFunCreateThread();
break;
case FUN_UPLOAD:
PostFunUpload();
break;
default:
log << log1 << "Content: unknown post function" << logend;
break;
@@ -464,3 +471,27 @@ void Content::CheckGetPostTimes(time_t difference)
log << log1 << "Content: spam +1: POST after GET sent too fast" << logend;
}
/*
bool Content::CreateFile(const std::string & path, const std::string & content)
{
std::ofstream file(path.c_str(), std::ios_base::binary | std::ios_base::out);
if( !file )
{
log << log1 << "Content: can't create file: " << path << logend;
return false;
}
file << content;
file.close();
// !! dodac sprawdzenie prawidlowosci zapisania pliku
return true;
}
*/

View File

@@ -65,7 +65,8 @@ class Content
static bool FunThreadSort(const Thread & t1, const Thread & t2);
void FunThread();
void FunCreateThread();
void FunUpload();
bool PostFunSetUrlSubject();
void PostFunLogin();
void PostFunEmacsAdd();
@@ -80,11 +81,13 @@ class Content
bool FunCreateThreadCheckAccess();
bool FunCreateThreadCheckAbuse();
void PostFunCreateThread();
void PostFunUpload();
void RedirectTo(const Item & item);
void RedirectTo(long item_id);
void CheckGetPostTimes(time_t difference = 10);
// bool CreateFile(const std::string & path, const std::string & content);
public:

View File

@@ -78,6 +78,7 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask)
void Content::FunMkdir()
{
// !! what about an item? (is_item)
if( !request.CanUseMkdir(*request.dir_table.back()) )
{
request.status = Error::permision_denied;

78
content/upload.cpp Executable file
View File

@@ -0,0 +1,78 @@
/*
* 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.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include <cstdio>
void Content::FunUpload()
{
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
{
request.status = Error::permision_denied;
return;
}
if( data.mounts.CurrentMountType() != Mount::cms )
{
request.status = Error::permision_denied;
return;
}
}
void Content::PostFunUpload()
{
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
{
request.status = Error::permision_denied;
return;
}
if( data.mounts.CurrentMountType() != Mount::cms )
{
request.status = Error::permision_denied;
return;
}
if( request.post_file_table.empty() )
{
request.status = Error::permision_denied;
return;
}
// !! tutaj w zaleznosci od rozszerzenia dobrac odpowiedni static_auth
request.item.static_auth = Item::static_other;
PostFunEmacs();
if( request.session->done_status == Error::ok )
{
std::string path;
if( request.MakeDirsOnFS(path) )
{
path += '/';
path += request.item.url;
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
if( rename(tmp_filename.c_str(), path.c_str()) < 0 )
{
// !! skasowac takze plik z bazy danych
log << log1 << "Content: can't move the tmp file from: " << tmp_filename;
log << log1 << ", to: " << path << logend;
request.status = Error::permision_denied;
}
}
}
}