208 lines
3.9 KiB
C++
Executable File
208 lines
3.9 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "edb.h"
|
|
#include "core/log.h"
|
|
|
|
|
|
namespace Export
|
|
{
|
|
|
|
void EDb::SetDirs(Dirs * pdirs)
|
|
{
|
|
dirs = pdirs;
|
|
}
|
|
|
|
|
|
|
|
void EDb::SetExportCols(PGresult * r)
|
|
{
|
|
cid = AssertColumn(r, "id");
|
|
cuser_id = AssertColumn(r, "user_id");
|
|
cdir = AssertColumn(r, "dir");
|
|
cftp_id = AssertColumn(r, "ftp_id");
|
|
cftp_dir = AssertColumn(r, "ftp_dir");
|
|
cname = AssertColumn(r, "name");
|
|
cserver = AssertColumn(r, "server");
|
|
clogin = AssertColumn(r, "login");
|
|
cpass = AssertColumn(r, "pass");
|
|
cpass_type = AssertColumn(r, "pass_type");
|
|
|
|
ccan_change_ftp_params = AssertColumn(r, "can_change_ftp_params");
|
|
ccan_change_dir = AssertColumn(r, "can_change_dir");
|
|
chttp_server = AssertColumn(r, "http_server");
|
|
}
|
|
|
|
|
|
void EDb::SetExportValues(PGresult * r, int row, Export & exp)
|
|
{
|
|
exp.Clear();
|
|
|
|
exp.id = AssertValueLong(r, row, cid);
|
|
exp.user_id = AssertValueLong(r, row, cuser_id);
|
|
exp.ftp_id = AssertValueLong(r, row, cftp_id);
|
|
exp.ftp_pass_type = AssertValueInt(r, row, cpass_type);
|
|
|
|
AssertValueWide(r, row, cdir, exp.dir);
|
|
AssertValueWide(r, row, cftp_dir, exp.ftp_dir);
|
|
AssertValueWide(r, row, cname, exp.ftp_name);
|
|
AssertValueWide(r, row, cserver, exp.ftp_server);
|
|
AssertValueWide(r, row, clogin, exp.ftp_login);
|
|
AssertValueWide(r, row, chttp_server, exp.http_server);
|
|
AssertValueWide(r, row, cpass, exp.ftp_pass);
|
|
|
|
exp.can_change_ftp_params = AssertValueBool(r, row, ccan_change_ftp_params);
|
|
exp.can_change_dir = AssertValueBool(r, row, ccan_change_dir);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDb::GetExport(long user_id, std::vector<Export> & export_tab, bool clear_tab)
|
|
{
|
|
if( clear_tab )
|
|
export_tab.clear();
|
|
|
|
PGresult * r = 0;
|
|
bool result = true;
|
|
|
|
try
|
|
{
|
|
query.Clear();
|
|
query << R( "select export.id, user_id, dir, ftp_id, ftp_dir, can_change_ftp_params, can_change_dir, "
|
|
"http_server, name, server, login, pass, pass_type from plugins.export "
|
|
"left join plugins.export_ftp on ftp_id = export_ftp.id where user_id = ")
|
|
<< user_id
|
|
<< R(";");
|
|
|
|
r = AssertQuery(query);
|
|
AssertResult(r, PGRES_TUPLES_OK);
|
|
|
|
SetExportCols(r);
|
|
int rows = Rows(r);
|
|
|
|
for(int i=0 ; i<rows ; ++i)
|
|
{
|
|
SetExportValues(r, i, exp);
|
|
export_tab.push_back(exp);
|
|
}
|
|
}
|
|
catch(const Error &)
|
|
{
|
|
result = false;
|
|
}
|
|
|
|
ClearResult(r);
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
bool EDb::GetExport(long id, Export & exp)
|
|
{
|
|
exp.Clear();
|
|
PGresult * r = 0;
|
|
bool result = false;
|
|
|
|
try
|
|
{
|
|
query.Clear();
|
|
query << R( "select export.id, user_id, dir, ftp_id, ftp_dir, can_change_ftp_params, can_change_dir, "
|
|
"http_server, name, server, login, pass, pass_type from plugins.export "
|
|
"left join plugins.export_ftp on ftp_id = export_ftp.id where export.id = ")
|
|
<< id
|
|
<< R(";");
|
|
|
|
r = AssertQuery(query);
|
|
AssertResult(r, PGRES_TUPLES_OK);
|
|
SetExportCols(r);
|
|
|
|
if( Rows(r) == 1 )
|
|
{
|
|
SetExportValues(r, 0, exp);
|
|
result = true;
|
|
}
|
|
}
|
|
catch(const Error &)
|
|
{
|
|
}
|
|
|
|
ClearResult(r);
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
bool EDb::GetExportDirs(std::vector<ExportDir> & export_tab, bool clear_tab)
|
|
{
|
|
if( clear_tab )
|
|
export_tab.clear();
|
|
|
|
PGresult * r = 0;
|
|
bool result = true;
|
|
|
|
try
|
|
{
|
|
query.Clear();
|
|
query << R( "select export.id, dir from plugins.export;");
|
|
|
|
r = AssertQuery(query);
|
|
AssertResult(r, PGRES_TUPLES_OK);
|
|
|
|
int rows = Rows(r);
|
|
cid = AssertColumn(r, "id");
|
|
cdir = AssertColumn(r, "dir");
|
|
|
|
for(int i=0 ; i<rows ; ++i)
|
|
{
|
|
exp_dir.id = AssertValueLong(r, i, cid);
|
|
AssertValueWide(r, i, cdir, dir_temp);
|
|
|
|
Item * pdir = dirs->GetDir(dir_temp);
|
|
|
|
if( pdir )
|
|
{
|
|
exp_dir.dir_id = pdir->id;
|
|
export_tab.push_back(exp_dir);
|
|
}
|
|
else
|
|
{
|
|
slog << "There is not such a directory: " << dir_temp << " (skipping)" << logend;
|
|
}
|
|
}
|
|
}
|
|
catch(const Error &)
|
|
{
|
|
result = false;
|
|
}
|
|
|
|
ClearResult(r);
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|