2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
2010-08-10 18:12:50 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-08-10 18:12:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "createthread.h"
|
|
|
|
#include "functions.h"
|
2011-01-20 19:37:51 +01:00
|
|
|
#include "functions/functions.h"
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
namespace Thread
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
CreateThread::CreateThread()
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
fun.url = L"createthread";
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
void CreateThread::SetTDb(TDb * ptdb)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-20 19:37:51 +01:00
|
|
|
tdb = ptdb;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
void CreateThread::SetThreadInfo(ThreadInfo * pthread_info)
|
2010-08-18 00:32:47 +02:00
|
|
|
{
|
2011-01-20 19:37:51 +01:00
|
|
|
thread_info = pthread_info;
|
2010-08-18 00:32:47 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
// returning true if we can create a thread in the current directory
|
|
|
|
bool CreateThread::HasAccess()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item || !system->HasWriteAccess(*cur->request->dir_tab.back()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
if( system->mounts.pmount->type != thread_info->mount_type_thread )
|
|
|
|
return false;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 13:45:38 +01:00
|
|
|
void CreateThread::SendNotify(const Item & item)
|
|
|
|
{
|
|
|
|
// sending notification
|
|
|
|
notify_msg.code = WINIX_NOTIFY_CODE_ADD;
|
|
|
|
notify_msg.template_index = thread_info->template_index;
|
2011-08-18 01:09:47 +02:00
|
|
|
notify_msg.dir_link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
|
2011-01-26 13:45:38 +01:00
|
|
|
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
|
|
|
|
notify_msg.item_link = notify_msg.dir_link;
|
|
|
|
notify_msg.item_link += item.url;
|
|
|
|
|
|
|
|
system->notify.ItemChanged(notify_msg);
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
void CreateThread::MakePost()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->item.Clear();
|
|
|
|
functions->ReadItem(cur->request->item, Item::file);
|
|
|
|
functions->SetUser(cur->request->item);
|
|
|
|
functions->PrepareUrl(cur->request->item);
|
|
|
|
cur->request->item.parent_id = cur->request->dir_tab.back()->id;
|
2012-01-25 00:03:36 +01:00
|
|
|
cur->request->item.privileges = system->NewFilePrivileges();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
if( functions->CheckAbuse() )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = system->AddFile(cur->request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-20 19:37:51 +01:00
|
|
|
thread.Clear();
|
2011-01-24 00:23:24 +01:00
|
|
|
thread.file_id = cur->request->item.id;
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = tdb->AddThread(thread);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2011-01-20 19:37:51 +01:00
|
|
|
{
|
|
|
|
log << log2 << "CreateThread: added a new thread" << logend;
|
2012-09-14 09:14:54 +02:00
|
|
|
thread_info->MakeRedirectIfPossible(cur->request->item);
|
2011-01-26 13:45:38 +01:00
|
|
|
SendNotify(cur->request->item);
|
2011-01-20 19:37:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log1 << "CreateThread: problem with adding a new thread, error code: "
|
2011-01-23 15:15:30 +01:00
|
|
|
<< cur->request->status << logend;
|
2011-01-20 19:37:51 +01:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|