fixed: UGContainer<Type> used a std::vector<Type> and when a new item was inserted
then current iterators (and pointers) were invalidated
now we are using std::vector<Type*>
this caused some crashes when a new user was added by 'adduser' winix function
added: plugin 'export' is able to upload files on a remote server now
(not finished yet)
changed: Thumb class is now called: Image
and we are able to resize images too
(some new options in the config and in mount points)
added: some new plugin messages
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@764 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -1,49 +1,96 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
db.o: db.h ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
|
||||
db.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h
|
||||
db.o: ../../core/requesttypes.h ../../core/error.h export.h ../../core/dirs.h
|
||||
db.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
|
||||
db.o: ../../db/dbitemquery.h ../../core/item.h ../../db/dbitemcolumns.h
|
||||
db.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
|
||||
db.o: ../../core/ugcontainer.h ../../core/log.h ../../core/textstream.h
|
||||
db.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
|
||||
db.o: ../../core/request.h ../../core/error.h ../../core/config.h
|
||||
db.o: ../../core/confparser.h ../../core/htmlfilter.h
|
||||
db.o: ../../templates/htmltextstream.h ../../core/session.h ../../core/user.h
|
||||
db.o: ../../core/plugindata.h ../../core/rebus.h ../../core/mount.h
|
||||
db.o: ../../templates/locale.h ../../core/confparser.h ../../notify/notify.h
|
||||
db.o: ../../notify/notifypool.h ../../templates/patterns.h
|
||||
db.o: ../../templates/locale.h ../../templates/localefilter.h
|
||||
db.o: ../../../ezc/src/ezc.h ../../../ezc/src/utf8.h
|
||||
db.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
|
||||
db.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
|
||||
db.o: ../../../ezc/src/stringconv.h ../../notify/notifythread.h
|
||||
db.o: ../../core/basethread.h ../../core/synchro.h
|
||||
db.o: ../../notify/templatesnotify.h ../../core/config.h ../../core/users.h
|
||||
db.o: ../../core/ugcontainer.h ../../core/lastcontainer.h
|
||||
db.o: ../../templates/misc.h ../../templates/htmltextstream.h
|
||||
db.o: ../../core/log.h
|
||||
exportinfo.o: ../../core/log.h exportinfo.h ../../core/system.h
|
||||
exportinfo.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h
|
||||
exportinfo.o: ../../db/db.h ../../db/dbbase.h ../../db/dbitemquery.h
|
||||
exportinfo.o: ../../core/item.h ../../db/dbitemcolumns.h ../../core/user.h
|
||||
exportinfo.o: ../../core/group.h ../../core/dircontainer.h
|
||||
exportinfo.o: ../../core/ugcontainer.h ../../core/log.h
|
||||
exportinfo.o: ../../core/textstream.h ../../core/logmanipulators.h
|
||||
exportinfo.o: ../../core/slog.h ../../core/cur.h ../../core/request.h
|
||||
exportinfo.o: ../../core/requesttypes.h ../../core/error.h
|
||||
exportinfo.o: ../../core/config.h ../../core/confparser.h
|
||||
exportinfo.o: ../../core/htmlfilter.h ../../templates/htmltextstream.h
|
||||
exportinfo.o: ../../core/textstream.h ../../core/misc.h ../../core/session.h
|
||||
exportinfo.o: ../../core/user.h ../../core/plugindata.h ../../core/rebus.h
|
||||
exportinfo.o: ../../core/mount.h ../../templates/locale.h
|
||||
exportinfo.o: ../../core/confparser.h ../../notify/notify.h
|
||||
exportinfo.o: ../../notify/notifypool.h ../../templates/patterns.h
|
||||
exportinfo.o: ../../templates/locale.h ../../templates/localefilter.h
|
||||
exportinfo.o: ../../../ezc/src/ezc.h ../../../ezc/src/utf8.h
|
||||
exportinfo.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
|
||||
exportinfo.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
|
||||
exportinfo.o: ../../../ezc/src/stringconv.h ../../notify/notifythread.h
|
||||
exportinfo.o: ../../core/basethread.h ../../core/synchro.h
|
||||
exportinfo.o: ../../notify/templatesnotify.h ../../core/config.h
|
||||
exportinfo.o: ../../core/users.h ../../core/ugcontainer.h
|
||||
exportinfo.o: ../../core/lastcontainer.h ../../templates/misc.h
|
||||
exportinfo.o: ../../templates/htmltextstream.h ../../core/mounts.h
|
||||
exportinfo.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
|
||||
exportinfo.o: ../../core/users.h ../../core/groups.h ../../core/group.h
|
||||
exportinfo.o: ../../core/loadavg.h ../../core/image.h ../../core/basethread.h
|
||||
exportinfo.o: ../../core/threadmanager.h export.h db.h ../../db/dbbase.h
|
||||
exportinfo.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
|
||||
exportinfo.o: ../../core/dirs.h message.h exportthread.h
|
||||
exportthread.o: exportthread.h ../../core/basethread.h ../../core/synchro.h
|
||||
exportthread.o: message.h ../../core/log.h ../../core/textstream.h
|
||||
exportthread.o: ../../core/misc.h ../../core/item.h ../../core/requesttypes.h
|
||||
exportthread.o: ../../core/logmanipulators.h ../../core/slog.h
|
||||
exportthread.o: ../../core/cur.h ../../core/request.h ../../core/error.h
|
||||
exportthread.o: ../../core/config.h ../../core/confparser.h
|
||||
exportthread.o: ../../core/htmlfilter.h ../../templates/htmltextstream.h
|
||||
exportthread.o: ../../core/textstream.h ../../core/session.h
|
||||
exportthread.o: ../../core/user.h ../../core/plugindata.h ../../core/rebus.h
|
||||
exportthread.o: ../../core/mount.h ../../templates/locale.h
|
||||
exportthread.o: ../../core/confparser.h ../../core/misc.h
|
||||
exportthread.o: message.h ../../core/log.h ../../core/misc.h
|
||||
exportthread.o: ../../core/item.h ../../core/requesttypes.h
|
||||
exportthread.o: ../../../ezc/src/utf8.h
|
||||
init.o: ../../core/log.h ../../core/textstream.h ../../core/misc.h
|
||||
init.o: ../../core/item.h ../../core/requesttypes.h
|
||||
init.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
|
||||
init.o: ../../core/request.h ../../core/error.h ../../core/config.h
|
||||
init.o: ../../core/confparser.h ../../core/htmlfilter.h
|
||||
init.o: ../../core/log.h ../../core/plugin.h ../../core/pluginmsg.h
|
||||
init.o: ../../core/log.h ../../core/textstream.h ../../core/logmanipulators.h
|
||||
init.o: ../../core/slog.h ../../core/cur.h ../../core/request.h
|
||||
init.o: ../../core/requesttypes.h ../../core/item.h ../../core/error.h
|
||||
init.o: ../../core/config.h ../../core/confparser.h ../../core/htmlfilter.h
|
||||
init.o: ../../templates/htmltextstream.h ../../core/textstream.h
|
||||
init.o: ../../core/session.h ../../core/user.h ../../core/plugindata.h
|
||||
init.o: ../../core/rebus.h ../../core/mount.h ../../templates/locale.h
|
||||
init.o: ../../core/confparser.h ../../core/plugin.h ../../core/pluginmsg.h
|
||||
init.o: ../../core/log.h ../../core/system.h ../../core/dirs.h
|
||||
init.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
|
||||
init.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
|
||||
init.o: ../../db/dbitemquery.h ../../core/item.h ../../db/dbitemcolumns.h
|
||||
init.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
|
||||
init.o: ../../core/ugcontainer.h ../../notify/notify.h
|
||||
init.o: ../../notify/notifypool.h ../../templates/patterns.h
|
||||
init.o: ../../templates/locale.h ../../templates/localefilter.h
|
||||
init.o: ../../../ezc/src/ezc.h ../../../ezc/src/utf8.h
|
||||
init.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
|
||||
init.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
|
||||
init.o: ../../../ezc/src/stringconv.h ../../notify/notifythread.h
|
||||
init.o: ../../core/basethread.h ../../core/synchro.h
|
||||
init.o: ../../notify/templatesnotify.h ../../core/config.h ../../core/users.h
|
||||
init.o: ../../core/ugcontainer.h ../../core/lastcontainer.h
|
||||
init.o: ../../templates/misc.h ../../templates/htmltextstream.h
|
||||
init.o: ../../core/mounts.h ../../core/mountparser.h ../../core/crypt.h
|
||||
init.o: ../../core/run.h ../../core/users.h ../../core/groups.h
|
||||
init.o: ../../core/group.h ../../core/loadavg.h ../../core/thumb.h
|
||||
init.o: ../../core/basethread.h ../../core/threadmanager.h
|
||||
init.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
|
||||
init.o: ../../functions/functions.h ../../functions/functionbase.h
|
||||
init.o: ../../core/request.h ../../core/system.h ../../core/synchro.h
|
||||
init.o: ../../core/misc.h ../../core/session.h ../../core/user.h
|
||||
init.o: ../../core/plugindata.h ../../core/rebus.h ../../core/mount.h
|
||||
init.o: ../../templates/locale.h ../../core/confparser.h ../../core/system.h
|
||||
init.o: ../../core/dirs.h ../../core/dircontainer.h ../../db/db.h
|
||||
init.o: ../../db/dbbase.h ../../db/dbitemquery.h ../../core/item.h
|
||||
init.o: ../../db/dbitemcolumns.h ../../core/user.h ../../core/group.h
|
||||
init.o: ../../core/dircontainer.h ../../core/ugcontainer.h
|
||||
init.o: ../../notify/notify.h ../../notify/notifypool.h
|
||||
init.o: ../../templates/patterns.h ../../templates/locale.h
|
||||
init.o: ../../templates/localefilter.h ../../../ezc/src/ezc.h
|
||||
init.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
|
||||
init.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
|
||||
init.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
|
||||
init.o: ../../notify/notifythread.h ../../core/basethread.h
|
||||
init.o: ../../core/synchro.h ../../notify/templatesnotify.h
|
||||
init.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
|
||||
init.o: ../../core/lastcontainer.h ../../templates/misc.h
|
||||
init.o: ../../templates/htmltextstream.h ../../core/mounts.h
|
||||
init.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
|
||||
init.o: ../../core/users.h ../../core/groups.h ../../core/group.h
|
||||
init.o: ../../core/loadavg.h ../../core/image.h ../../core/basethread.h
|
||||
init.o: ../../core/threadmanager.h ../../core/sessionmanager.h
|
||||
init.o: ../../core/sessioncontainer.h ../../functions/functions.h
|
||||
init.o: ../../functions/functionbase.h ../../core/request.h
|
||||
init.o: ../../core/system.h ../../core/synchro.h
|
||||
init.o: ../../functions/functionparser.h ../../core/cur.h
|
||||
init.o: ../../functions/adduser.h ../../functions/cat.h
|
||||
init.o: ../../functions/chmod.h ../../functions/privchanger.h
|
||||
@@ -64,4 +111,6 @@ init.o: ../../functions/who.h ../../functions/vim.h ../../core/htmlfilter.h
|
||||
init.o: ../../templates/templates.h ../../templates/patterncacher.h
|
||||
init.o: ../../templates/indexpatterns.h ../../templates/patterns.h
|
||||
init.o: ../../templates/changepatterns.h ../../core/sessionmanager.h
|
||||
init.o: exportthread.h message.h
|
||||
init.o: exportthread.h message.h exportinfo.h export.h db.h ../../db/dbbase.h
|
||||
init.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
|
||||
init.o: ../../core/dirs.h
|
||||
|
||||
@@ -1 +1 @@
|
||||
o = exportthread.o init.o
|
||||
o = db.o exportinfo.o exportthread.o init.o
|
||||
|
||||
207
plugins/export/db.cpp
Executable file
207
plugins/export/db.cpp
Executable file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "db.h"
|
||||
#include "core/log.h"
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
void Db::SetDirs(Dirs * pdirs)
|
||||
{
|
||||
dirs = pdirs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Db::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 Db::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);
|
||||
AssertValueBin(r, row, cpass, exp.ftp_pass_bin);
|
||||
|
||||
exp.can_change_ftp_params = AssertValueBool(r, row, ccan_change_ftp_params);
|
||||
exp.can_change_dir = AssertValueBool(r, row, ccan_change_dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Db::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 Db::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 Db::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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
66
plugins/export/db.h
Executable file
66
plugins/export/db.h
Executable file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_plugins_export_db
|
||||
#define headerfile_winix_plugins_export_db
|
||||
|
||||
#include <vector>
|
||||
#include "db/dbbase.h"
|
||||
#include "export.h"
|
||||
#include "core/dirs.h"
|
||||
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
|
||||
|
||||
class Db : public DbBase
|
||||
{
|
||||
public:
|
||||
|
||||
void SetDirs(Dirs * pdirs);
|
||||
|
||||
bool GetExport(long user_id, std::vector<Export> & export_tab, bool clear_tab = true);
|
||||
bool GetExport(long id, Export & exp);
|
||||
bool GetExportDirs(std::vector<ExportDir> & export_tab, bool clear_tab = true);
|
||||
|
||||
private:
|
||||
|
||||
Dirs * dirs;
|
||||
|
||||
Export exp;
|
||||
ExportDir exp_dir;
|
||||
DbTextStream query;
|
||||
std::wstring dir_temp;
|
||||
|
||||
int cid;
|
||||
int cuser_id;
|
||||
int cdir;
|
||||
int cftp_id;
|
||||
int cftp_dir;
|
||||
int cname;
|
||||
int cserver;
|
||||
int clogin;
|
||||
int cpass;
|
||||
int cpass_type;
|
||||
int ccan_change_ftp_params;
|
||||
int ccan_change_dir;
|
||||
int chttp_server;
|
||||
|
||||
void SetExportCols(PGresult * r);
|
||||
void SetExportValues(PGresult * r, int row, Export & exp);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
80
plugins/export/export.h
Executable file
80
plugins/export/export.h
Executable file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_plugins_export_export
|
||||
#define headerfile_winix_plugins_export_export
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
struct ExportDir
|
||||
{
|
||||
long id;
|
||||
long dir_id;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Export
|
||||
{
|
||||
long id;
|
||||
long user_id;
|
||||
std::wstring dir;
|
||||
|
||||
long ftp_id;
|
||||
std::wstring ftp_dir;
|
||||
|
||||
std::wstring ftp_name;
|
||||
std::wstring ftp_server;
|
||||
std::wstring ftp_login;
|
||||
std::wstring ftp_pass;
|
||||
std::string ftp_pass_bin;
|
||||
int ftp_pass_type;
|
||||
|
||||
bool can_change_ftp_params;
|
||||
bool can_change_dir;
|
||||
|
||||
std::wstring http_server;
|
||||
|
||||
|
||||
|
||||
Export()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = user_id = ftp_id = -1;
|
||||
ftp_pass_type = 0;
|
||||
|
||||
dir.clear();
|
||||
ftp_dir.clear();
|
||||
ftp_name.clear();
|
||||
ftp_server.clear();
|
||||
ftp_login.clear();
|
||||
ftp_pass.clear();
|
||||
ftp_pass_bin.clear();
|
||||
|
||||
can_change_ftp_params = false;
|
||||
can_change_dir = false;
|
||||
|
||||
http_server.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
234
plugins/export/exportinfo.cpp
Executable file
234
plugins/export/exportinfo.cpp
Executable file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/log.h"
|
||||
#include "exportinfo.h"
|
||||
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
|
||||
ExportInfo::ExportInfo()
|
||||
{
|
||||
use_rsa = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportInfo::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
}
|
||||
|
||||
|
||||
void ExportInfo::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void ExportInfo::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void ExportInfo::SetExportThread(ExportThread * pexport_thread)
|
||||
{
|
||||
export_thread = pexport_thread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportInfo::ReadExportDirs()
|
||||
{
|
||||
db->GetExportDirs(export_dirs);
|
||||
}
|
||||
|
||||
|
||||
void ExportInfo::ReadConfigVars()
|
||||
{
|
||||
use_rsa = config->Bool(L"export_rsa", false);
|
||||
rsa_key = config->Text(L"export_rsa_key");
|
||||
}
|
||||
|
||||
|
||||
ExportDir * ExportInfo::FindDir(long dir_id)
|
||||
{
|
||||
for(size_t i=0 ; i<export_dirs.size() ; ++i)
|
||||
{
|
||||
if( dir_id == export_dirs[i].dir_id || system->dirs.HasParent(dir_id, export_dirs[i].dir_id) )
|
||||
return &export_dirs[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ExportInfo::DecodePass(Export & exp)
|
||||
{
|
||||
if( exp.ftp_pass_type == 0 )
|
||||
{
|
||||
Ezc::UTF8ToWide(exp.ftp_pass_bin, exp.ftp_pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( system->crypt.RSA(false, rsa_key, exp.ftp_pass_bin, pass_decrypted) )
|
||||
{
|
||||
Ezc::UTF8ToWide(pass_decrypted, exp.ftp_pass);
|
||||
system->crypt.ClearString(pass_decrypted);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Export: I cannot decrypt a password (RSA failed)" << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ExportInfo::SkipDir(long dir_id, std::wstring & dir)
|
||||
{
|
||||
if( system->dirs.MakePath(dir_id, tmp_dir) )
|
||||
{
|
||||
if( !tmp_dir.empty() && IsSubString(tmp_dir, dir) )
|
||||
{
|
||||
// tmp_dir has a slash at the end
|
||||
// we want the slash at the beginning
|
||||
dir.erase(0, tmp_dir.size()-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportInfo::SendFile(const Item & item, bool thumb)
|
||||
{
|
||||
ExportDir * exp_dir = FindDir(item.parent_id);
|
||||
|
||||
if( !exp_dir )
|
||||
return;
|
||||
|
||||
msg.Clear();
|
||||
system->dirs.MakePath(item.parent_id, msg.path);
|
||||
msg.path += item.url;
|
||||
|
||||
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
{
|
||||
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC;
|
||||
|
||||
if( !system->MakeFilePath(item, msg.url, thumb) )
|
||||
{
|
||||
log << log1 << "Export: I cannot create a path to a static file, item id: " << item.id << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
|
||||
msg.url = config->url_proto;
|
||||
msg.url += config->base_url;
|
||||
system->dirs.MakePath(item.parent_id, msg.url, false);
|
||||
msg.url += item.url;
|
||||
msg.path += L".php"; // !! do konfiga
|
||||
}
|
||||
|
||||
msg.errors = 0;
|
||||
|
||||
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
|
||||
{
|
||||
if( DecodePass(exp) )
|
||||
{
|
||||
msg.ftp_login = exp.ftp_login;
|
||||
msg.ftp_pass = exp.ftp_pass;
|
||||
msg.ftp_server = exp.ftp_server;
|
||||
msg.http_server = exp.http_server;
|
||||
system->dirs.MakePath(exp_dir->dir_id, msg.src_dir);
|
||||
|
||||
if( !item.file_path.empty() && thumb ) // !! uzyc file_type
|
||||
msg.path.insert(0, L"/download"); // !! do konfiga
|
||||
|
||||
if( !exp.ftp_dir.empty() )
|
||||
msg.path.insert(0, exp.ftp_dir);
|
||||
|
||||
if( !msg.path.empty() && msg.path[0] != '/' )
|
||||
msg.path.insert(0, L"/");
|
||||
|
||||
export_thread->AddMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportInfo::SendDir(const Item & item)
|
||||
{
|
||||
ExportDir * exp_dir = FindDir(item.id);
|
||||
|
||||
if( !exp_dir )
|
||||
return;
|
||||
|
||||
msg.Clear();
|
||||
system->dirs.MakePath(item.id, msg.path);
|
||||
|
||||
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
|
||||
msg.url = config->url_proto;
|
||||
msg.url += config->base_url;
|
||||
system->dirs.MakePath(item.id, msg.url, false);
|
||||
msg.path += L"index.html"; // !! do konfiga
|
||||
|
||||
msg.errors = 0;
|
||||
|
||||
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
|
||||
{
|
||||
if( DecodePass(exp) )
|
||||
{
|
||||
msg.ftp_login = exp.ftp_login;
|
||||
msg.ftp_pass = exp.ftp_pass;
|
||||
msg.ftp_server = exp.ftp_server;
|
||||
msg.http_server = exp.http_server;
|
||||
system->dirs.MakePath(exp_dir->dir_id, msg.src_dir);
|
||||
|
||||
if( !exp.ftp_dir.empty() )
|
||||
msg.path.insert(0, exp.ftp_dir);
|
||||
|
||||
if( !msg.path.empty() && msg.path[0] != '/' )
|
||||
msg.path.insert(0, L"/");
|
||||
|
||||
export_thread->AddMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExportInfo::SendDir(long dir_id)
|
||||
{
|
||||
Item * dir = system->dirs.GetDir(dir_id);
|
||||
|
||||
if( !dir )
|
||||
return;
|
||||
|
||||
SendDir(*dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
69
plugins/export/exportinfo.h
Executable file
69
plugins/export/exportinfo.h
Executable file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_plugins_export_exportinfo
|
||||
#define headerfile_winix_plugins_export_exportinfo
|
||||
|
||||
#include "core/system.h"
|
||||
#include "export.h"
|
||||
#include "db.h"
|
||||
#include "message.h"
|
||||
#include "exportthread.h"
|
||||
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
|
||||
class ExportInfo
|
||||
{
|
||||
public:
|
||||
|
||||
ExportInfo();
|
||||
|
||||
void SetSystem(System * psystem);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetDb(Db * pdb);
|
||||
void SetExportThread(ExportThread * pexport_thread);
|
||||
|
||||
void ReadExportDirs();
|
||||
void ReadConfigVars();
|
||||
|
||||
ExportDir * FindDir(long dir_id);
|
||||
|
||||
bool DecodePass(Export & exp);
|
||||
|
||||
void SendFile(const Item & item, bool thumb = false);
|
||||
void SendDir(const Item & item);
|
||||
void SendDir(long dir_id);
|
||||
|
||||
private:
|
||||
|
||||
System * system;
|
||||
Config * config;
|
||||
Db * db;
|
||||
ExportThread * export_thread;
|
||||
|
||||
bool use_rsa;
|
||||
std::wstring rsa_key;
|
||||
std::string pass_decrypted;
|
||||
Message msg;
|
||||
Export exp;
|
||||
std::wstring tmp_dir;
|
||||
std::vector<ExportDir> export_dirs;
|
||||
|
||||
bool SkipDir(long dir_id, std::wstring & dir);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <curl/curl.h>
|
||||
#include <string.h>
|
||||
#include "exportthread.h"
|
||||
#include "core/log.h"
|
||||
@@ -28,6 +27,9 @@ ExportThread::ExportThread()
|
||||
{
|
||||
exp_thread = 0;
|
||||
utf8 = false;
|
||||
browser_name = "Winix Export";
|
||||
conn_timeout = 5;
|
||||
conn_max_errors = 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +40,15 @@ void ExportThread::SetUTF8(bool use_utf8)
|
||||
}
|
||||
|
||||
|
||||
void ExportThread::SetBaseUrl(const std::wstring & url)
|
||||
{
|
||||
base_url = url;
|
||||
}
|
||||
|
||||
void ExportThread::AddMessage(const Message & message)
|
||||
{
|
||||
message_tab.insert(message_tab.end(), message);
|
||||
WakeUpThread();
|
||||
|
||||
log << log1 << "yes ser" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,8 +69,6 @@ void ExportThread::AddMessage(int type, const std::wstring & url, const std::wst
|
||||
// objects are locked
|
||||
bool ExportThread::SignalReceived()
|
||||
{
|
||||
log << log1 << "------------- a ---------------" << logend;
|
||||
|
||||
return !message_tab.empty();
|
||||
}
|
||||
|
||||
@@ -79,7 +82,6 @@ MessageTab::iterator i;
|
||||
bool end;
|
||||
|
||||
Lock();
|
||||
log << log1 << "------------- swinka ---------------" << logend;
|
||||
i = message_tab.begin();
|
||||
Unlock();
|
||||
|
||||
@@ -90,7 +92,19 @@ bool end;
|
||||
if( i != message_tab.end() )
|
||||
{
|
||||
message_work = *i;
|
||||
message_tab.erase(i++);
|
||||
|
||||
Unlock();
|
||||
DoMessage();
|
||||
Lock();
|
||||
|
||||
// although there was Unlock() used we can use the same iterator 'i' here
|
||||
// it will *not* be invalidated (MessageTab is a std::list)
|
||||
// and we are deleting only here
|
||||
i->errors = message_work.errors;
|
||||
|
||||
if( message_work.can_remove )
|
||||
message_tab.erase(i++);
|
||||
|
||||
end = false;
|
||||
}
|
||||
else
|
||||
@@ -98,11 +112,8 @@ bool end;
|
||||
end = true;
|
||||
}
|
||||
|
||||
WaitForSignalSleep(5);
|
||||
Unlock();
|
||||
|
||||
if( !end )
|
||||
DoMessage();
|
||||
|
||||
}
|
||||
while( !end && !IsExitSignal() );
|
||||
}
|
||||
@@ -113,24 +124,45 @@ bool end;
|
||||
// current message we have in 'message_work'
|
||||
void ExportThread::DoMessage()
|
||||
{
|
||||
Lock();
|
||||
bool sent_ok = false;
|
||||
|
||||
if( utf8 )
|
||||
Ezc::WideToUTF8(message_work.url, url_a);
|
||||
Convert(message_work.url, url_a);
|
||||
|
||||
if( message_work.type == WINIX_PL_EXPORT_TYPE_CREATE_FILE )
|
||||
{
|
||||
if( Fetch(url_a.c_str()) )
|
||||
{
|
||||
ChangeAdresses(buffer);
|
||||
|
||||
if( Put() )
|
||||
sent_ok = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
AssignString(message_work.url, url_a);
|
||||
{
|
||||
if( Put() )
|
||||
sent_ok = true;
|
||||
}
|
||||
|
||||
Unlock();
|
||||
|
||||
Fetch(url_a.c_str());
|
||||
if( sent_ok )
|
||||
{
|
||||
message_work.can_remove = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
message_work.errors += 1;
|
||||
message_work.can_remove = false;
|
||||
|
||||
Lock();
|
||||
log << log1 << "sciagnalem takie cos ---------------------------------------------------" << logend;
|
||||
if( message_work.errors > conn_max_errors )
|
||||
{
|
||||
message_work.can_remove = true;
|
||||
|
||||
log << "rozmiar: " << buffer.size() << logend;
|
||||
|
||||
log << log1 << "koniec takiego cosia ---------------------------------------------------" << logend << logsave;
|
||||
Unlock();
|
||||
Lock();
|
||||
log << log1 << "Export: too many errors for uploading " << message_work.path << " (skipping)" << logend << logsave;
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,11 +174,7 @@ void ExportThread::DoMessage()
|
||||
// objects are not locked
|
||||
bool ExportThread::Fetch(const char * url)
|
||||
{
|
||||
CURL * curl;
|
||||
CURLcode res;
|
||||
long code;
|
||||
|
||||
curl = curl_easy_init();
|
||||
CURL * curl = curl_easy_init();
|
||||
|
||||
if( !curl )
|
||||
{
|
||||
@@ -156,26 +184,29 @@ long code;
|
||||
return false;
|
||||
}
|
||||
|
||||
exp_thread = this;
|
||||
error_buf[0] = 0;
|
||||
exp_thread = this;
|
||||
buffer.clear();
|
||||
|
||||
/*
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); // the http code will be from the last request
|
||||
*/
|
||||
//curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, StaticSaveFunction);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Winix");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, StaticSaveFunction);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, browser_name.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, conn_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buf);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 20);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
|
||||
//long code; // http code
|
||||
//curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if( res!=0 || code!=200 )
|
||||
if( res != 0 )
|
||||
{
|
||||
Lock();
|
||||
log << log1 << "Ezport: error: operation result: " << (int)res << ", http code: " << code << logend;
|
||||
log << log1 << "Export: download failed: " << error_buf << logend << logsave;
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
@@ -201,14 +232,274 @@ size_t ExportThread::SaveFunction(char * ptr, size_t size, size_t nmemb, void *u
|
||||
if( len > 0 )
|
||||
buffer.append(ptr, len);
|
||||
|
||||
Lock();
|
||||
log << log1 << "odebralem cosik: size: " << size << ", nmemb: " << nmemb << logend;
|
||||
Unlock();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects are not locked
|
||||
void ExportThread::Convert(const std::wstring & in, std::string & out, bool clear)
|
||||
{
|
||||
Lock();
|
||||
|
||||
if( utf8 )
|
||||
Ezc::WideToUTF8(in, out, clear);
|
||||
else
|
||||
AssignString(in, out, clear);
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
// objects are not locked
|
||||
bool ExportThread::Put()
|
||||
{
|
||||
FILE * file = 0;
|
||||
|
||||
if( message_work.type == WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC )
|
||||
{
|
||||
Convert(message_work.url, local_path);
|
||||
file = fopen(local_path.c_str(), "r");
|
||||
|
||||
if( !file )
|
||||
{
|
||||
Lock();
|
||||
log << log1 << "Export: I cannot open the file: " << local_path << logend;
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log3 << "Export: sending a static file: " << local_path << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CURL * curl = curl_easy_init();
|
||||
|
||||
|
||||
if( !curl )
|
||||
{
|
||||
Lock();
|
||||
log << log1 << "Export: I can't use curl (sending)" << logend;
|
||||
Unlock();
|
||||
|
||||
if( file )
|
||||
fclose(file);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
exp_thread = this;
|
||||
error_buf[0] = 0;
|
||||
buffer_read_index = 0;
|
||||
|
||||
ftp_server = "ftp://";
|
||||
Convert(message_work.ftp_server, ftp_server, false);
|
||||
Convert(message_work.path, ftp_server, false);
|
||||
Convert(message_work.ftp_login, ftp_login);
|
||||
Convert(message_work.ftp_pass, ftp_pass);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, ftp_server.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, ftp_login.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, ftp_pass.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, browser_name.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_FTP_RESPONSE_TIMEOUT, conn_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buf);
|
||||
|
||||
if( file )
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, StaticReadFunction);
|
||||
curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer.size());
|
||||
}
|
||||
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if( file )
|
||||
fclose(file);
|
||||
|
||||
if( res != 0 )
|
||||
{
|
||||
Lock();
|
||||
log << log1 << "Export: upload failed: " << error_buf << " (" << ftp_server << ")" << logend << logsave;
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
log << log2 << "Export: uploaded: " << ftp_server << logend << logsave;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
size_t ExportThread::StaticReadFunction(char * ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
if( exp_thread )
|
||||
return exp_thread->ReadFunction(ptr, size, nmemb, userdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t ExportThread::ReadFunction(char * ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
size_t max_len = size * nmemb;
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<max_len && buffer_read_index < buffer.size() ; ++i, ++buffer_read_index )
|
||||
{
|
||||
ptr[i] = buffer[buffer_read_index];
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
void ExportThread::CreateBaseUrl(std::string & buf)
|
||||
{
|
||||
buf = "http://";
|
||||
Convert(base_url, buf, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExportThread::ChangeAdresses(std::string & buf)
|
||||
{
|
||||
// !! mozna lock skasowac jesli loger nie bedzie uzywany
|
||||
Lock();
|
||||
|
||||
ChangeAdressesThumb(buf);
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
look_for_url += "/static";
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/static/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
/*
|
||||
CreateBaseUrl(look_for_url);
|
||||
look_for_url += "/common/";
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/common/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
*/
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
repl_url += "/";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
NoLastSlash(look_for_url);
|
||||
Convert(message_work.http_server, repl_url);
|
||||
look_for_url += '\"';
|
||||
repl_url += '\"';
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
|
||||
Convert(message_work.src_dir, look_for_url);
|
||||
repl_url = '/';
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
NoLastSlash(look_for_url);
|
||||
look_for_url += '\"';
|
||||
repl_url = "/\"";
|
||||
log << log1 << "zamiana: |" << look_for_url << "|, na: |" << repl_url << "|" << logend << logsave;
|
||||
ReplaceString(buf, look_for_url, repl_url);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExportThread::ChangeAdressesThumb(std::string & buf)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
CreateBaseUrl(look_for_url);
|
||||
Convert(message_work.src_dir, look_for_url, false);
|
||||
|
||||
for(i=0 ; i<buf.size() ; ++i)
|
||||
{
|
||||
if( IsSubStringp(look_for_url.c_str(), &buf[i]) )
|
||||
{
|
||||
i += look_for_url.size() - 1; // without skipping the last slash
|
||||
|
||||
if( HasThumbInAdress(buf, i) )
|
||||
{
|
||||
if( i <= buf.size() )
|
||||
buf.insert(i, "/download"); //!! do konfiga
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ExportThread::HasThumbInAdress(std::string & buf, size_t i)
|
||||
{
|
||||
const char * thumb1 = "/-/thumb";
|
||||
const char * thumb2 = "/download/thumb";
|
||||
|
||||
size_t len1 = strlen(thumb1);
|
||||
size_t len2 = strlen(thumb2);
|
||||
|
||||
for( ; i<buf.size() ; ++i)
|
||||
{
|
||||
if( IsSubStringp(thumb1, &buf[i]) )
|
||||
{
|
||||
buf.erase(i, len1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if( IsSubStringp(thumb2, &buf[i]) )
|
||||
{
|
||||
buf.erase(i, len2);
|
||||
return true;
|
||||
}
|
||||
|
||||
if( buf[i] == 10 || buf[i] == '"' || buf[i] == ' ' || buf[i] == '\t' ||
|
||||
buf[i] == '>' ||buf[i] == '<' )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
#ifndef headerfile_winix_plugins_export_exportthread
|
||||
#define headerfile_winix_plugins_export_exportthread
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <curl/curl.h>
|
||||
#include "core/basethread.h"
|
||||
#include "message.h"
|
||||
|
||||
@@ -27,6 +29,7 @@ public:
|
||||
ExportThread();
|
||||
|
||||
void SetUTF8(bool use_utf8);
|
||||
void SetBaseUrl(const std::wstring & url);
|
||||
|
||||
void AddMessage(const Message & message);
|
||||
void AddMessage(int type, const std::wstring & url, const std::wstring & path);
|
||||
@@ -41,15 +44,38 @@ private:
|
||||
static ExportThread * exp_thread;
|
||||
std::string url_a;
|
||||
std::string buffer;
|
||||
size_t buffer_read_index;
|
||||
bool utf8;
|
||||
std::wstring base_url;
|
||||
|
||||
std::string browser_name;
|
||||
std::string ftp_server;
|
||||
std::string ftp_login;
|
||||
std::string ftp_pass;
|
||||
char error_buf[CURL_ERROR_SIZE];
|
||||
|
||||
int conn_timeout; // timeout in seconds
|
||||
int conn_max_errors; // maximum errors (if there are more then a message is treated as undeliverable)
|
||||
|
||||
std::string look_for_url;
|
||||
std::string repl_url;
|
||||
std::string local_path;
|
||||
|
||||
virtual bool SignalReceived();
|
||||
virtual void Do();
|
||||
void DoMessage();
|
||||
bool Fetch(const char * url);
|
||||
bool Put();
|
||||
static size_t StaticSaveFunction(char * ptr, size_t size, size_t nmemb, void *userdata);
|
||||
size_t SaveFunction(char * ptr, size_t size, size_t nmemb, void *userdata);
|
||||
|
||||
static size_t StaticReadFunction(char * ptr, size_t size, size_t nmemb, void *userdata);
|
||||
size_t ReadFunction(char * ptr, size_t size, size_t nmemb, void *userdata);
|
||||
void Convert(const std::wstring & in, std::string & out, bool clear = true);
|
||||
void ChangeAdresses(std::string & buf);
|
||||
void ChangeAdressesThumb(std::string & buf);
|
||||
bool HasThumbInAdress(std::string & buf, size_t i);
|
||||
void CreateBaseUrl(std::string & buf);
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "core/log.h"
|
||||
#include "core/plugin.h"
|
||||
#include "exportthread.h"
|
||||
#include "exportinfo.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
extern "C" void Init(PluginInfo &);
|
||||
@@ -25,10 +28,8 @@ namespace Export
|
||||
const wchar_t plugin_name[] = L"export";
|
||||
int mount_par_export_conf = -1;
|
||||
ExportThread export_thread;
|
||||
Message msg;
|
||||
|
||||
|
||||
|
||||
Db db;
|
||||
ExportInfo export_info;
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +51,20 @@ void FstabChanged(PluginInfo & info)
|
||||
void InitPlugin(PluginInfo & info)
|
||||
{
|
||||
export_thread.SetUTF8(info.config->utf8);
|
||||
export_thread.SetBaseUrl(info.config->base_url);
|
||||
|
||||
info.system->thread_manager.Add(&export_thread);
|
||||
|
||||
export_info.ReadExportDirs();
|
||||
}
|
||||
|
||||
|
||||
void SendDir(PluginInfo & info)
|
||||
{
|
||||
const Item * dir = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( dir )
|
||||
export_info.SendDir(*dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,23 +73,84 @@ void SendFile(PluginInfo & info)
|
||||
{
|
||||
const Item * item = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( !item )
|
||||
return;
|
||||
|
||||
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
|
||||
msg.url = info.config->url_proto;
|
||||
msg.url += info.config->base_url;
|
||||
info.system->dirs.MakePath(item->parent_id, msg.url, false);
|
||||
msg.url += item->url;
|
||||
|
||||
msg.path.clear();
|
||||
|
||||
log << log1 << "Export: bede sciagal takiego swiniaka: " << msg.url << logend;
|
||||
|
||||
export_thread.AddMessage(msg);
|
||||
if( item )
|
||||
{
|
||||
if( item->file_type == WINIX_ITEM_FILETYPE_IMAGE && info.config->image_resize )
|
||||
{
|
||||
// there'll be a next message WINIX_IMAGE_RESIZED
|
||||
log << log4 << "Export: image will be resized, waiting..." << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
export_info.SendFile(*item);
|
||||
export_info.SendDir(item->parent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SendFileCopied(PluginInfo & info)
|
||||
{
|
||||
const Item * item = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( item )
|
||||
{
|
||||
export_info.SendFile(*item);
|
||||
|
||||
if( item->file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
export_info.SendFile(*item, true);
|
||||
|
||||
export_info.SendDir(item->parent_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SendFileResized(PluginInfo & info)
|
||||
{
|
||||
const Item * item = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( item )
|
||||
{
|
||||
export_info.SendFile(*item);
|
||||
export_info.SendDir(item->parent_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SendFileThumb(PluginInfo & info)
|
||||
{
|
||||
const Item * item = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( item )
|
||||
{
|
||||
export_info.SendFile(*item, true);
|
||||
export_info.SendDir(item->parent_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileRemoved(PluginInfo & info)
|
||||
{
|
||||
const Item * item = reinterpret_cast<Item*>(info.p1);
|
||||
|
||||
if( item )
|
||||
{
|
||||
export_info.SendDir(item->parent_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ProcessRequest(PluginInfo & info)
|
||||
{
|
||||
if( info.cur->request->function == &info.functions->fun_reload )
|
||||
{
|
||||
if( info.cur->request->IsParam(L"export") )
|
||||
export_info.ReadExportDirs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AddEzcFunctions(PluginInfo & info);
|
||||
|
||||
@@ -89,16 +164,37 @@ void Init(PluginInfo & info)
|
||||
{
|
||||
using namespace Export;
|
||||
|
||||
db.SetConn(info.db->GetConn());
|
||||
db.LogQueries(info.config->log_db_query);
|
||||
db.SetDirs(&info.system->dirs);
|
||||
export_info.SetSystem(info.system);
|
||||
export_info.SetConfig(info.config);
|
||||
export_info.SetDb(&db);
|
||||
export_info.SetExportThread(&export_thread);
|
||||
|
||||
|
||||
// plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
|
||||
plugin.Assign(WINIX_ADD_MOUNTS, AddMountParams);
|
||||
// plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
|
||||
|
||||
|
||||
plugin.Assign(WINIX_FILE_ADDED, SendFile);
|
||||
plugin.Assign(WINIX_FILE_CHANGED, SendFile);
|
||||
plugin.Assign(WINIX_FILE_CHANGED, SendFileResized);
|
||||
plugin.Assign(WINIX_CREATED_THUMB, SendFileThumb);
|
||||
plugin.Assign(WINIX_IMAGE_RESIZED, SendFileResized);
|
||||
plugin.Assign(WINIX_FILE_MOVED, SendFileCopied);
|
||||
plugin.Assign(WINIX_FILE_COPIED, SendFileCopied);
|
||||
|
||||
plugin.Assign(WINIX_DIR_CONTENT_SORTED, SendDir);
|
||||
plugin.Assign(5000, FileRemoved);
|
||||
|
||||
plugin.Assign(WINIX_PROCESS_REQUEST, ProcessRequest);
|
||||
|
||||
plugin.Assign(WINIX_PLUGIN_INIT, InitPlugin);
|
||||
|
||||
|
||||
|
||||
|
||||
info.p1 = (void*)(plugin_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
|
||||
|
||||
// message types
|
||||
#define WINIX_PL_EXPORT_TYPE_CREATE_FILE 1
|
||||
#define WINIX_PL_EXPORT_TYPE_CREATE_DIR 2
|
||||
#define WINIX_PL_EXPORT_TYPE_CREATE_FILE 1
|
||||
#define WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC 2
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,13 +26,47 @@ struct Message
|
||||
// message type
|
||||
int type;
|
||||
|
||||
// original (source) url
|
||||
// original (source) url (if message is WINIX_PL_EXPORT_TYPE_CREATE_FILE)
|
||||
// or a file path (WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC)
|
||||
std::wstring url;
|
||||
|
||||
// source directory
|
||||
std::wstring src_dir;
|
||||
|
||||
// output file (directory) name
|
||||
// relative path
|
||||
// with a slash at the beginning (and at the end if it is a directory)
|
||||
std::wstring path;
|
||||
|
||||
std::wstring ftp_server;
|
||||
std::wstring ftp_login;
|
||||
std::wstring ftp_pass;
|
||||
|
||||
// server on which the site will be visible
|
||||
std::wstring http_server;
|
||||
|
||||
// how many errors were with this message
|
||||
int errors;
|
||||
|
||||
// shoud be removed
|
||||
bool can_remove;
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
type = 0;
|
||||
errors = 0;
|
||||
can_remove = true;
|
||||
|
||||
url.clear();
|
||||
src_dir.clear();
|
||||
path.clear();
|
||||
ftp_server.clear();
|
||||
ftp_login.clear();
|
||||
ftp_pass.clear();
|
||||
http_server.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user