winix/content/cp.cpp

106 lines
1.8 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <errno.h>
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include "../core/misc.h"
bool Content::CpCheckAccessFrom()
{
if( request.is_item )
{
if( !request.HasReadAccess(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
// dirs are checked in function parser
return true;
}
void Content::CpAuth(Item & item)
{
if( !request.MakePath(item, mv_new_path, true) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( CopyFile(item.auth_path, mv_new_path) )
{
log << log1 << "Content: copied static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
item.auth_path = mv_new_path;
request.status = db.EditAuthById(item, item.id);
}
else
{
log << log1 << "Content: can't copy a file from: " << item.auth_path << ", to: " << mv_new_path << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
void Content::CpItem(Item & item, bool redirect)
{
if( MoveIsTheSameFile(item) )
return;
if( !mv_file.empty() )
{
item.url = mv_file;
PrepareUrl(item);
}
item.parent_id = mv_dir_id;
PostFunEmacsAdd(item);
if( request.status == WINIX_ERR_OK )
{
if( item.auth != Item::auth_none )
CpAuth(item);
if( redirect )
RedirectTo(item);
}
}
void Content::PostFunCp()
{
if( CpCheckAccessFrom() &&
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
MoveCheckAccessTo(mv_dir_id) )
{
if( request.is_item )
{
CpItem(request.item);
}
else
{
/* not implemented yet */
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
}
void Content::FunCp()
{
CpCheckAccessFrom();
}