changed: upload function

select file type by the extension
         param: multi
fixed:   uptime function
         it showed incorrect uptime time (minuts were badly calculated)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@575 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-02-12 23:16:13 +00:00
parent 796985472a
commit 3c5a7cd664
16 changed files with 275 additions and 81 deletions

View File

@@ -14,6 +14,7 @@
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include "../core/misc.h"
@@ -38,37 +39,35 @@ return true;
void Content::UploadSaveFile()
bool Content::UploadCreatePath(std::string & path)
{
static std::string path;
struct stat sb;
path.clear();
request.MakePath(path);
if( stat(path.c_str(), &sb) < 0 )
if( !request.MakeDirsOnFS() )
{
if( !request.MakeDirsOnFS() )
{
request.status = Error::permission_denied;
return;
}
request.status = Error::permission_denied;
return false;
}
return true;
}
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 )
void Content::UploadSaveFile(const std::string & tmp_filename, const std::string & destination)
{
if( rename(tmp_filename.c_str(), destination.c_str()) == 0 )
{
log << log1 << "Content: uploaded a new file: " << path << logend;
log << log1 << "Content: uploaded a new file: " << destination << logend;
}
else
{
int err = errno;
// !! skasowac takze plik z bazy danych
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << path << ", ";
// !! skasowac takze plik z bazy danych?
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << destination << ", ";
log.SystemErr(err);
log << logend;
@@ -78,7 +77,120 @@ struct stat sb;
bool Content::FunUploadCheckAbuse()
{
if( !CheckRebus() )
{
request.status = Error::incorrect_rebus;
request.session->done = Done::added_thread;
request.session->done_status = Error::incorrect_rebus;
return false;
}
CheckGetPostTimes(4);
if( request.session->spam_score > 0 )
{
request.status = Error::spam;
request.session->done = Done::added_thread;
request.session->done_status = Error::spam;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Content::UploadMulti()
{
request.item.Clear(); // clearing and setting date
request.item.parent_id = request.dir_table.back()->id;
request.item.type = Item::file;
request.item.privileges = 0644; // !! tymczasowo
SetUser(request.item);
if( !UploadCreatePath(tmp_path) )
return;
tmp_path2 = tmp_path; // remember the path
PostFileTable::iterator i = request.post_file_table.begin();
for( ; i != request.post_file_table.end() ; ++i)
{
const char * file_name = i->second.filename.c_str();
request.item.subject = file_name;
request.item.url = file_name;
request.item.static_auth = SelectFileType(file_name);
PrepareUrl(request.item);
PostFunEmacsAdd(); // always adding a new item
if( request.session->done_status == Error::ok )
{
tmp_path += '/';
tmp_path += request.item.url; // item.url could have been changed
UploadSaveFile(i->second.tmp_filename, tmp_path);
tmp_path = tmp_path2; // restoring the oryginal path
}
}
RedirectToLastDir();
}
void Content::UploadSingle()
{
std::string * new_subject = request.PostVar("subject");
std::string * new_url = request.PostVar("url");
bool has_subject = (new_subject && (*new_subject)[0] != 0 );
bool has_url = (new_url && (*new_url)[0] != 0 );
ReadItem(request.item, Item::file); // ReadItem() changes the url if it is empty
request.item.privileges = 0644; // !! tymczasowo
const char * file_name = request.post_file_table.begin()->second.filename.c_str();
request.item.static_auth = SelectFileType(file_name);
if( !has_subject )
request.item.subject = file_name;
if( !has_url )
{
request.item.url = file_name;
PrepareUrl(request.item);
}
PostFunEmacsAdd(); // always adding a new item
if( request.session->done_status == Error::ok )
{
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
if( !UploadCreatePath(tmp_path) )
return;
tmp_path += '/';
tmp_path += request.item.url; // item.url could have been changed
UploadSaveFile(tmp_filename, tmp_path);
}
if( request.session->done_status == Error::ok )
RedirectTo(request.item);
}
// !! dodac usuwanie plikow statycznych przez rm
void Content::PostFunUpload()
{
if( !FunUploadCheckAccess() )
@@ -89,23 +201,14 @@ void Content::PostFunUpload()
request.status = Error::permission_denied;
return;
}
// !! moze request.session->done_status trzeba ustawic na Error::ok na poczatku? (i podobnie w innych metodach, mkdir, emacs ...)
ReadItem(request.item, Item::file);
// !! sprawdzanie rebusa?
if( !FunUploadCheckAbuse() )
return;
// !! tutaj w zaleznosci od rozszerzenia dobrac odpowiedni static_auth
request.item.static_auth = Item::static_other;
PostFunEmacsAdd(); // always adding a new item
if( request.session->done_status == Error::ok )
UploadSaveFile();
if( request.session->done_status == Error::ok )
RedirectTo(request.item);
if( request.post_file_table.size() > 1 )
UploadMulti();
else
UploadSingle();
}