- now the mess with threads has gone away
- we have a class BaseThread -- this is a base class -- we can inherit from it when creating a new thread - others treads are correctly stopped (when signal comes) -- pthread_join - we have a special thread only for signals git-svn-id: svn://ttmath.org/publicrep/winix/trunk@685 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -1,34 +1,56 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
notify.o: templatesnotify.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
|
||||
notify.o: notify.h notifypool.h ../templates/locale.h ../core/confparser.h
|
||||
notify.o: ../templates/misc.h ../templates/localefilter.h
|
||||
notify.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
|
||||
notify.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
notify.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
|
||||
notify.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h
|
||||
notify.o: ../core/mount.h ../core/config.h ../core/confparser.h
|
||||
notify.o: ../core/htmlfilter.h ../core/textstream.h ../core/misc.h
|
||||
notify.o: ../templates/misc.h ../templates/localefilter.h
|
||||
notify.o: ../templates/locale.h ../core/confparser.h
|
||||
notify.o: ../templates/htmltextstream.h ../core/user.h ../core/log.h
|
||||
notify.o: ../core/textstream.h ../core/notify.h
|
||||
notify.o: ../templatesnotify/templatesnotify.h ../core/request.h
|
||||
notify.o: ../templates/htmltextstream.h ../core/textstream.h ../core/misc.h
|
||||
notify.o: ../core/user.h notifythread.h ../core/basethread.h
|
||||
notify.o: ../core/synchro.h templatesnotify.h ../core/config.h
|
||||
notify.o: ../core/confparser.h ../core/htmlfilter.h ../core/users.h
|
||||
notify.o: ../core/user.h ../core/ugcontainer.h ../core/log.h
|
||||
notify.o: ../core/textstream.h ../core/lastcontainer.h ../core/request.h
|
||||
notify.o: ../core/requesttypes.h ../core/session.h ../core/error.h
|
||||
notify.o: ../core/log.h ../core/user.h ../core/plugindata.h ../core/rebus.h
|
||||
notify.o: ../core/config.h ../templates/htmltextstream.h ../core/system.h
|
||||
notify.o: ../core/dirs.h ../core/dircontainer.h ../db/db.h ../db/dbbase.h
|
||||
notify.o: ../core/plugindata.h ../core/rebus.h ../core/config.h
|
||||
notify.o: ../templates/htmltextstream.h ../db/db.h ../db/dbbase.h
|
||||
notify.o: ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
|
||||
notify.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
|
||||
notify.o: ../core/group.h ../core/thread.h ../core/dircontainer.h
|
||||
notify.o: ../core/ugcontainer.h ../core/mounts.h ../core/mount.h
|
||||
notify.o: ../core/mountparser.h ../core/users.h ../core/ugcontainer.h
|
||||
notify.o: ../core/lastcontainer.h ../core/groups.h ../core/group.h
|
||||
notify.o: ../core/loadavg.h
|
||||
notify.o: ../core/ugcontainer.h ../templates/templates.h
|
||||
notify.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
|
||||
notify.o: ../core/httpsimpleparser.h ../core/log.h
|
||||
notify.o: ../templates/indexpatterns.h ../core/request.h ../core/system.h
|
||||
notify.o: ../core/dirs.h ../core/dircontainer.h ../templatesnotify/notify.h
|
||||
notify.o: ../core/mounts.h ../core/mount.h ../core/mountparser.h
|
||||
notify.o: ../core/users.h ../core/groups.h ../core/group.h ../core/loadavg.h
|
||||
notify.o: ../core/sessionmanager.h ../core/sessioncontainer.h
|
||||
notify.o: ../core/system.h ../core/dirs.h ../core/synchro.h
|
||||
notifypool.o: notifypool.h ../templates/locale.h ../core/confparser.h
|
||||
notifythread.o: notifythread.h ../core/basethread.h ../core/synchro.h
|
||||
notifythread.o: templatesnotify.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
|
||||
notifythread.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
notifythread.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
|
||||
notifythread.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h
|
||||
notifythread.o: ../core/textstream.h ../core/misc.h notifypool.h
|
||||
notifythread.o: ../templates/locale.h ../core/confparser.h
|
||||
notifythread.o: ../templates/misc.h ../templates/localefilter.h
|
||||
notifythread.o: ../templates/locale.h ../templates/htmltextstream.h
|
||||
notifythread.o: ../core/user.h ../core/config.h ../core/confparser.h
|
||||
notifythread.o: ../core/htmlfilter.h ../core/users.h ../core/user.h
|
||||
notifythread.o: ../core/ugcontainer.h ../core/log.h ../core/textstream.h
|
||||
notifythread.o: ../core/lastcontainer.h ../core/request.h
|
||||
notifythread.o: ../core/requesttypes.h ../core/session.h ../core/error.h
|
||||
notifythread.o: ../core/plugindata.h ../core/rebus.h ../core/config.h
|
||||
notifythread.o: ../templates/htmltextstream.h ../db/db.h ../db/dbbase.h
|
||||
notifythread.o: ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
|
||||
notifythread.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
|
||||
notifythread.o: ../core/group.h ../core/thread.h ../core/dircontainer.h
|
||||
notifythread.o: ../core/ugcontainer.h
|
||||
templatesnotify.o: templatesnotify.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
|
||||
templatesnotify.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
templatesnotify.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
|
||||
templatesnotify.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h
|
||||
templatesnotify.o: ../core/mount.h ../core/config.h ../core/confparser.h
|
||||
templatesnotify.o: ../core/htmlfilter.h ../core/textstream.h ../core/misc.h
|
||||
templatesnotify.o: ../templates/misc.h ../templates/localefilter.h
|
||||
templatesnotify.o: ../core/textstream.h ../core/misc.h notifypool.h
|
||||
templatesnotify.o: ../templates/locale.h ../core/confparser.h
|
||||
templatesnotify.o: ../templates/htmltextstream.h ../core/user.h ../core/log.h
|
||||
templatesnotify.o: ../core/textstream.h ../core/misc.h ../templates/locale.h
|
||||
|
@@ -1 +1 @@
|
||||
o = notify.o templatesnotify.o
|
||||
o = notify.o notifypool.o notifythread.o templatesnotify.o
|
||||
|
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templatesnotify.h"
|
||||
#include "core/notify.h"
|
||||
|
||||
|
||||
|
||||
namespace TemplatesNotifyFunctions
|
||||
{
|
||||
|
||||
|
||||
void notify_item_added(Info & i)
|
||||
{
|
||||
i.res = (notify_msg->notify_code & WINIX_NOTIFY_ITEM_ADD) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_item_edited(Info & i)
|
||||
{
|
||||
i.res = (notify_msg->notify_code & WINIX_NOTIFY_ITEM_EDIT) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_item_deleted(Info & i)
|
||||
{
|
||||
i.res = (notify_msg->notify_code & WINIX_NOTIFY_ITEM_DELETE) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_dir_added(Info & i)
|
||||
{
|
||||
i.res = (notify_msg->notify_code & WINIX_NOTIFY_DIR_ADD) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_to(Info & i)
|
||||
{
|
||||
i.out << notify_msg->email;
|
||||
}
|
||||
|
||||
|
||||
void notify_mount_type_is_thread(Info & i)
|
||||
{
|
||||
i.res = notify_msg->current_mount_type == mount_type_thread;
|
||||
}
|
||||
|
||||
|
||||
void notify_mount_type_is_ticket(Info & i)
|
||||
{
|
||||
i.res = notify_msg->current_mount_type == mount_type_ticket;
|
||||
}
|
||||
|
||||
|
||||
void notify_mount_type_is_cms(Info & i)
|
||||
{
|
||||
i.res = notify_msg->current_mount_type == mount_type_cms;
|
||||
}
|
||||
|
||||
|
||||
void notify_doc_base_url(Info & i)
|
||||
{
|
||||
i.out << notify_msg->doc_base_url;
|
||||
}
|
||||
|
||||
|
||||
void notify_item_dir(Info & i)
|
||||
{
|
||||
i.out << notify_msg->item_dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_item_link(Info & i)
|
||||
{
|
||||
i.out << notify_msg->item_link;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesNotifyFunctions
|
||||
|
||||
|
||||
|
81
templatesnotify/notify.h
Executable file
81
templatesnotify/notify.h
Executable file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslunotify
|
||||
#define headerfilecmslunotify
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "notifypool.h"
|
||||
#include "templates/misc.h"
|
||||
#include "notifythread.h"
|
||||
|
||||
|
||||
class Request;
|
||||
class Config;
|
||||
class Users;
|
||||
class Dirs;
|
||||
class Synchro;
|
||||
|
||||
|
||||
class Notify
|
||||
{
|
||||
public:
|
||||
|
||||
Notify();
|
||||
|
||||
void SetSynchro(Synchro * psynchro);
|
||||
void SetRequest(Request * prequest);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetUsers(Users * pusers);
|
||||
void SetDirs(Dirs * pdirs);
|
||||
|
||||
void Init();
|
||||
|
||||
void StartThread();
|
||||
void SendSignalToThread(); // use it in lock/unlock
|
||||
void WaitForThread();
|
||||
|
||||
size_t AddTemplate(const std::wstring & file_name);
|
||||
void ReadTemplates();
|
||||
|
||||
void ItemChanged(int notify_code, const Item & item);
|
||||
|
||||
private:
|
||||
|
||||
Request * request;
|
||||
Config * config;
|
||||
Dirs * dirs;
|
||||
Users * users;
|
||||
Synchro * synchro;
|
||||
|
||||
NotifyThread notify_thread;
|
||||
NotifyMsg msg;
|
||||
NotifyPool notify_pool;
|
||||
|
||||
// conditional variable
|
||||
pthread_cond_t thread_signal;
|
||||
|
||||
size_t notify_template_cms;
|
||||
size_t notify_template_thread;
|
||||
|
||||
// templates file names
|
||||
std::vector<std::wstring> templates_names;
|
||||
|
||||
// vector table [language][file]
|
||||
TemplatesFunctions::Patterns patterns;
|
||||
|
||||
void CreateItemLink(const Item & item, std::wstring & link, std::wstring & dir_link);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
59
templatesnotify/notifypool.cpp
Executable file
59
templatesnotify/notifypool.cpp
Executable file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "notifypool.h"
|
||||
|
||||
|
||||
|
||||
bool NotifyPool::Empty() const
|
||||
{
|
||||
return notify_pool.empty();
|
||||
}
|
||||
|
||||
|
||||
size_t NotifyPool::Size() const
|
||||
{
|
||||
return notify_pool.size(); // it has O(n)
|
||||
}
|
||||
|
||||
|
||||
NotifyMsg & NotifyPool::GetFirst()
|
||||
{
|
||||
return *notify_pool.begin();
|
||||
}
|
||||
|
||||
|
||||
void NotifyPool::DeleteFirst()
|
||||
{
|
||||
if( notify_pool.empty() )
|
||||
return;
|
||||
|
||||
notify_pool.erase(notify_pool.begin());
|
||||
}
|
||||
|
||||
|
||||
void NotifyPool::Add(const NotifyMsg & msg)
|
||||
{
|
||||
notify_pool.insert(notify_pool.end(), msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
82
templatesnotify/notifypool.h
Executable file
82
templatesnotify/notifypool.h
Executable file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslunotifypool
|
||||
#define headerfilecmslunotifypool
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "templates/locale.h"
|
||||
|
||||
|
||||
|
||||
#define WINIX_NOTIFY_CODE_DIR_ADD 1
|
||||
#define WINIX_NOTIFY_CODE_DIR_EDIT 2
|
||||
#define WINIX_NOTIFY_CODE_DIR_DELETE 4
|
||||
|
||||
#define WINIX_NOTIFY_CODE_FILE_ADD 8
|
||||
#define WINIX_NOTIFY_CODE_FILE_EDIT 16
|
||||
#define WINIX_NOTIFY_CODE_FILE_DELETE 32
|
||||
|
||||
// new thread has been starded
|
||||
#define WINIX_NOTIFY_CODE_THREAD_ADD 64
|
||||
|
||||
// someone replayed in a thread
|
||||
#define WINIX_NOTIFY_CODE_THREAD_REPLAYED 128
|
||||
|
||||
// someone edited its post
|
||||
#define WINIX_NOTIFY_CODE_THREAD_POST_CHANGED 256
|
||||
|
||||
|
||||
#define WINIX_NOTIFY_CODE_THREAD_DELETE 512
|
||||
|
||||
|
||||
|
||||
|
||||
struct NotifyMsg
|
||||
{
|
||||
int code;
|
||||
std::wstring item_link; // link to a file or a dir (can be the same as dir_link if the item is a directory)
|
||||
std::wstring dir_link; // link to a dir
|
||||
size_t template_index;
|
||||
};
|
||||
|
||||
|
||||
// used by the second thread (and its templates)
|
||||
struct NotifyUserMsg
|
||||
{
|
||||
std::wstring name;
|
||||
std::wstring email;
|
||||
Locale::Lang lang;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class NotifyPool
|
||||
{
|
||||
public:
|
||||
|
||||
bool Empty() const;
|
||||
size_t Size() const;
|
||||
|
||||
NotifyMsg & GetFirst();
|
||||
void DeleteFirst();
|
||||
void Add(const NotifyMsg & msg);
|
||||
|
||||
private:
|
||||
|
||||
std::list<NotifyMsg> notify_pool;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
246
templatesnotify/notifythread.cpp
Executable file
246
templatesnotify/notifythread.cpp
Executable file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "notifythread.h"
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
NotifyThread::NotifyThread()
|
||||
{
|
||||
patterns_changed = true;
|
||||
}
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
void NotifyThread::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
void NotifyThread::SetUsers(Users * pusers)
|
||||
{
|
||||
users = pusers;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
void NotifyThread::SetNotifyPool(NotifyPool * pool)
|
||||
{
|
||||
notify_pool = pool;
|
||||
}
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
void NotifyThread::SetPatterns(TemplatesFunctions::Patterns * pat)
|
||||
{
|
||||
pat_global = pat;
|
||||
}
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
void NotifyThread::PatternsChanged()
|
||||
{
|
||||
patterns_changed = true;
|
||||
}
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
bool NotifyThread::Init()
|
||||
{
|
||||
TemplatesNotifyFunctions::CreateFunctions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// first thread (objects are locked)
|
||||
bool NotifyThread::SignalReceived()
|
||||
{
|
||||
if( patterns_changed )
|
||||
{
|
||||
// !! usunac
|
||||
log << log3 << "NotifyThread: copying global patterns to local ones" << logend;
|
||||
patterns = *pat_global;
|
||||
patterns_changed = false;
|
||||
}
|
||||
|
||||
return !notify_pool->Empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// second thread (objects are not locked)
|
||||
// return true if there is something to send from the first queue (notify_pool)
|
||||
bool NotifyThread::AddNextNotify()
|
||||
{
|
||||
Users::Iterator i;
|
||||
bool res = false;
|
||||
|
||||
Lock();
|
||||
|
||||
if( !notify_pool->Empty() )
|
||||
{
|
||||
TemplatesNotifyFunctions::notify_msg = notify_pool->GetFirst();
|
||||
notify_pool->DeleteFirst();
|
||||
|
||||
for(i=users->Begin() ; i != users->End() ; ++i)
|
||||
{
|
||||
if( (i->cms_notify & TemplatesNotifyFunctions::notify_msg.code) != 0 ) // !! bedzie jedno pole i->notify
|
||||
{
|
||||
msg.name = i->name;
|
||||
msg.email = i->email;
|
||||
msg.lang = Locale::StrToLang(config->locale_str); // !! bedzie osobno dla kazdego uzytkownika
|
||||
|
||||
if( msg.lang == Locale::lang_unknown )
|
||||
msg.lang = Locale::lang_en;
|
||||
|
||||
notify_user.insert(notify_user.end(), msg);
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Unlock();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread -- here we must use Lock() and Unlock() explicitly
|
||||
void NotifyThread::Do()
|
||||
{
|
||||
NotifyUser::iterator i;
|
||||
bool queue_end;
|
||||
|
||||
while( AddNextNotify() )
|
||||
{
|
||||
Lock();
|
||||
i = notify_user.begin();
|
||||
queue_end = notify_user.empty();
|
||||
Unlock();
|
||||
|
||||
while( !queue_end )
|
||||
{
|
||||
Lock();
|
||||
TemplatesNotifyFunctions::notify_user_msg = *i;
|
||||
log << log3 << "NotifyThread: sending notification to: " << i->name << ", email: " << i->email << logend;
|
||||
Unlock();
|
||||
|
||||
SendMail();
|
||||
|
||||
Lock();
|
||||
WaitForSignalSleep(2); // automatically unlock and lock again when returns
|
||||
bool stop = synchro->was_stop_signal;
|
||||
Unlock();
|
||||
|
||||
if( stop )
|
||||
return;
|
||||
|
||||
Lock();
|
||||
notify_user.erase(i++);
|
||||
queue_end = (i == notify_user.end());
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second thread
|
||||
void NotifyThread::SendMail()
|
||||
{
|
||||
notify_stream.Clear();
|
||||
|
||||
size_t lang_index = static_cast<size_t>(TemplatesNotifyFunctions::notify_user_msg.lang);
|
||||
size_t template_index = TemplatesNotifyFunctions::notify_msg.template_index;
|
||||
|
||||
if( lang_index >= patterns.size() ||
|
||||
template_index >= patterns[lang_index].size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
return;
|
||||
}
|
||||
|
||||
generator.RecognizeSpecialChars(true);
|
||||
generator.TrimWhite(true);
|
||||
generator.SkipNewLine(true);
|
||||
generator.Generate(notify_stream, patterns[lang_index][template_index],
|
||||
TemplatesNotifyFunctions::ezc_functions);
|
||||
|
||||
SendMail(TemplatesNotifyFunctions::notify_user_msg.email, notify_stream.Str());
|
||||
}
|
||||
|
||||
|
||||
// second thread
|
||||
void NotifyThread::SendMail(const std::wstring & email, const std::wstring & message)
|
||||
{
|
||||
nlog.PutDate(log1);
|
||||
|
||||
if( !ValidateEmail(email) )
|
||||
{
|
||||
nlog << log1 << "NotifyThread: email adress: " << email << " is not correct" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
sendmail_command = "sendmail ";
|
||||
Ezc::WideToUTF8(email, sendmail_command, false);
|
||||
FILE * sendmail = popen(sendmail_command.c_str(), "w");
|
||||
|
||||
if( !sendmail )
|
||||
{
|
||||
nlog << log1 << "NotifyThread: can't run sendmail" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
SendMail(sendmail, message);
|
||||
pclose(sendmail);
|
||||
|
||||
nlog << log1 << "NotifyThread: email to: " << email << " has been sent" << logend;
|
||||
nlog << logsave;
|
||||
}
|
||||
|
||||
|
||||
// second thread
|
||||
void NotifyThread::SendMail(FILE * sendmail, const std::wstring & message)
|
||||
{
|
||||
char buf[10];
|
||||
size_t len;
|
||||
|
||||
for(size_t i=0 ; i<message.length() ; ++i)
|
||||
{
|
||||
if( message[i] == '\n' )
|
||||
{
|
||||
fprintf(sendmail, "\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
len = Ezc::IntToUTF8(int(message[i]), buf, sizeof(buf) / sizeof(char));
|
||||
|
||||
for(size_t a=0 ; a<len ; ++a)
|
||||
fputc(buf[a], sendmail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
66
templatesnotify/notifythread.h
Executable file
66
templatesnotify/notifythread.h
Executable file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslunotifythread
|
||||
#define headerfilecmslunotifythread
|
||||
|
||||
#include "core/basethread.h"
|
||||
#include "templatesnotify.h"
|
||||
#include "ezc.h"
|
||||
#include "templates/misc.h"
|
||||
#include "core/config.h"
|
||||
#include "core/users.h"
|
||||
|
||||
|
||||
|
||||
// we have set following pointers: request, config, system (from BaseThread)
|
||||
|
||||
class NotifyThread : public BaseThread
|
||||
{
|
||||
public:
|
||||
|
||||
NotifyThread();
|
||||
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetUsers(Users * pusers);
|
||||
void SetNotifyPool(NotifyPool * pool);
|
||||
void SetPatterns(TemplatesFunctions::Patterns * pat);
|
||||
void PatternsChanged();
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
Users * users;
|
||||
NotifyPool * notify_pool;
|
||||
TemplatesFunctions::Patterns * pat_global;
|
||||
|
||||
NotifyUserMsg msg;
|
||||
typedef std::list<NotifyUserMsg> NotifyUser;
|
||||
NotifyUser notify_user;
|
||||
std::string sendmail_command;
|
||||
bool patterns_changed;
|
||||
TemplatesFunctions::Patterns patterns;
|
||||
TemplatesNotifyFunctions::NotifyStream notify_stream;
|
||||
Ezc::Generator<TemplatesNotifyFunctions::NotifyStream> generator;
|
||||
|
||||
virtual bool Init();
|
||||
virtual bool SignalReceived();
|
||||
bool AddNextNotify();
|
||||
virtual void Do();
|
||||
void SendMail();
|
||||
void SendMail(const std::wstring & email, const std::wstring & message);
|
||||
void SendMail(FILE * sendmail, const std::wstring & message);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@@ -8,33 +8,117 @@
|
||||
*/
|
||||
|
||||
#include "templatesnotify.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/log.h"
|
||||
#include "core/textstream.h"
|
||||
#include "templates/locale.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesNotifyFunctions
|
||||
{
|
||||
Ezc::Functions<NotifyStream> ezc_functions;
|
||||
|
||||
// id of mount points types
|
||||
int mount_type_cms;
|
||||
int mount_type_thread;
|
||||
int mount_type_ticket;
|
||||
|
||||
|
||||
Patterns patterns;
|
||||
Ezc::Functions<TextStream<std::wstring> > ezc_functions;
|
||||
Locale locale;
|
||||
LocaleFilter locale_filter;
|
||||
|
||||
Config * config;
|
||||
|
||||
|
||||
// you can use this pointer in template functions (will be always valid)
|
||||
NotifyMsg * notify_msg;
|
||||
NotifyUserMsg notify_user_msg;
|
||||
NotifyMsg notify_msg;
|
||||
|
||||
|
||||
|
||||
|
||||
void notify_file_added(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_FILE_ADD) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_file_edited(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_FILE_EDIT) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_file_deleted(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_FILE_DELETE) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_dir_added(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_DIR_ADD) != 0;
|
||||
}
|
||||
|
||||
|
||||
void notify_thread_added(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_THREAD_ADD) != 0;
|
||||
}
|
||||
|
||||
|
||||
void notify_thread_replayed(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_THREAD_REPLAYED) != 0;
|
||||
}
|
||||
|
||||
|
||||
void notify_thread_post_changed(Info & i)
|
||||
{
|
||||
i.res = (notify_msg.code & WINIX_NOTIFY_CODE_THREAD_POST_CHANGED) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void notify_to(Info & i)
|
||||
{
|
||||
i.out << notify_user_msg.email;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void notify_doc_base_url(Info & i)
|
||||
{
|
||||
i.out << notify_user_msg.doc_base_url;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void notify_item_link(Info & i)
|
||||
{
|
||||
i.out << notify_msg.item_link;
|
||||
}
|
||||
|
||||
|
||||
void notify_dir_link(Info & i)
|
||||
{
|
||||
i.out << notify_msg.dir_link;
|
||||
}
|
||||
|
||||
|
||||
void CreateFunctions()
|
||||
{
|
||||
ezc_functions.Clear();
|
||||
|
||||
ezc_functions.Insert("notify_file_added", notify_file_added);
|
||||
ezc_functions.Insert("notify_file_edited", notify_file_edited);
|
||||
ezc_functions.Insert("notify_file_deleted", notify_file_deleted);
|
||||
ezc_functions.Insert("notify_dir_added", notify_dir_added);
|
||||
|
||||
ezc_functions.Insert("notify_thread_added", notify_thread_added);
|
||||
ezc_functions.Insert("notify_thread_replayed", notify_thread_replayed);
|
||||
ezc_functions.Insert("notify_thread_post_changed", notify_thread_post_changed);
|
||||
|
||||
ezc_functions.Insert("notify_to", notify_to);
|
||||
//ezc_functions.Insert("notify_doc_base_url", notify_doc_base_url);
|
||||
ezc_functions.Insert("notify_item_link", notify_item_link);
|
||||
ezc_functions.Insert("notify_dir_link", notify_dir_link);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesNotifyFunctions
|
||||
@@ -42,112 +126,6 @@ NotifyMsg * notify_msg;
|
||||
|
||||
|
||||
|
||||
void TemplatesNotify::SetConfig(Config * pconfig)
|
||||
{
|
||||
TemplatesNotifyFunctions::config = pconfig;
|
||||
}
|
||||
|
||||
void TemplatesNotify::SetMountTypes(int mcms, int mthread, int mticket)
|
||||
{
|
||||
using namespace TemplatesNotifyFunctions;
|
||||
|
||||
mount_type_cms = mcms;
|
||||
mount_type_thread = mthread;
|
||||
mount_type_ticket = mticket;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TemplatesNotify::CreateFunctions()
|
||||
{
|
||||
using namespace TemplatesNotifyFunctions;
|
||||
|
||||
ezc_functions.Clear();
|
||||
|
||||
ezc_functions.Insert("notify_item_added", notify_item_added);
|
||||
ezc_functions.Insert("notify_item_edited", notify_item_edited);
|
||||
ezc_functions.Insert("notify_item_deleted", notify_item_deleted);
|
||||
ezc_functions.Insert("notify_dir_added", notify_dir_added);
|
||||
ezc_functions.Insert("notify_to", notify_to);
|
||||
ezc_functions.Insert("notify_mount_type_is_thread", notify_mount_type_is_thread);
|
||||
ezc_functions.Insert("notify_mount_type_is_ticket", notify_mount_type_is_ticket);
|
||||
ezc_functions.Insert("notify_mount_type_is_cms", notify_mount_type_is_cms);
|
||||
ezc_functions.Insert("notify_doc_base_url", notify_doc_base_url);
|
||||
ezc_functions.Insert("notify_item_dir", notify_item_dir);
|
||||
ezc_functions.Insert("notify_item_link", notify_item_link);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TemplatesNotify::ClearPatterns()
|
||||
{
|
||||
using namespace TemplatesNotifyFunctions;
|
||||
|
||||
|
||||
TemplatesFunctions::ClearPatterns(patterns, pat_last);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// templates are read in the main thread
|
||||
// (before creating the second thread)
|
||||
void TemplatesNotify::Read()
|
||||
{
|
||||
using namespace TemplatesNotifyFunctions;
|
||||
|
||||
Locale::Lang lang = Locale::StrToLang(config->locale_str);
|
||||
|
||||
if( lang != Locale::lang_unknown )
|
||||
locale.SetLang(lang);
|
||||
else
|
||||
locale.SetLang(Locale::lang_en);
|
||||
|
||||
ClearPatterns();
|
||||
locale.UTF8(config->utf8);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
// !! nazwe pliku do konfiga
|
||||
TemplatesFunctions::Read(patterns, pat_email_notify, locale, locale_filter, ezc_functions,
|
||||
L"notify_email.txt", config->utf8,
|
||||
config->templates_dir, config->templates_dir_default, true);
|
||||
|
||||
notify_msg = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TemplatesNotify::Generate(Locale::Lang lang)
|
||||
{
|
||||
using namespace TemplatesNotifyFunctions;
|
||||
|
||||
notify_str.Clear();
|
||||
|
||||
if( !notify_msg )
|
||||
return;
|
||||
|
||||
if( static_cast<size_t>(lang) >= patterns.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
return;
|
||||
}
|
||||
|
||||
Ezc::Generator<TextStream<std::wstring> > generator;
|
||||
generator.RecognizeSpecialChars(true);
|
||||
generator.TrimWhite(true);
|
||||
generator.SkipNewLine(true);
|
||||
generator.Generate(notify_str, patterns[lang][pat_email_notify]);
|
||||
}
|
||||
|
||||
|
||||
TemplatesNotify::TemplatesNotify()
|
||||
{
|
||||
ClearPatterns();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -7,94 +7,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslutemplatestemplatesnotify
|
||||
#define headerfilecmslutemplatestemplatesnotify
|
||||
#ifndef headerfile_winix_notify_templatesnotify
|
||||
#define headerfile_winix_notify_templatesnotify
|
||||
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "ezc.h"
|
||||
#include "core/mount.h"
|
||||
#include "core/config.h"
|
||||
#include "core/textstream.h"
|
||||
#include "templates/misc.h"
|
||||
#include "notifypool.h"
|
||||
|
||||
|
||||
|
||||
struct NotifyMsg
|
||||
{
|
||||
std::wstring email;
|
||||
int notify_code;
|
||||
int current_mount_type;
|
||||
Locale::Lang lang;
|
||||
std::wstring doc_base_url;
|
||||
std::wstring item_dir;
|
||||
std::wstring item_link;
|
||||
};
|
||||
|
||||
|
||||
namespace TemplatesNotifyFunctions
|
||||
{
|
||||
extern int mount_type_cms;
|
||||
extern int mount_type_thread;
|
||||
extern int mount_type_ticket;
|
||||
typedef TextStream<std::wstring> NotifyStream;
|
||||
typedef Ezc::FunInfo<NotifyStream> Info;
|
||||
|
||||
typedef Ezc::FunInfo<TextStream<std::wstring> > Info;
|
||||
|
||||
enum Pat {
|
||||
pat_email_notify = 0, // first should be zero
|
||||
extern NotifyUserMsg notify_user_msg;
|
||||
extern NotifyMsg notify_msg;
|
||||
|
||||
pat_last // should be last
|
||||
};
|
||||
|
||||
typedef std::vector<std::vector<Ezc::Pattern> > Patterns;
|
||||
|
||||
extern Patterns patterns;
|
||||
extern NotifyMsg * notify_msg;
|
||||
|
||||
extern Config * config;
|
||||
|
||||
void notify_item_added(Info & i);
|
||||
void notify_item_edited(Info & i);
|
||||
void notify_item_deleted(Info & i);
|
||||
void notify_dir_added(Info & i);
|
||||
void notify_to(Info & i);
|
||||
void notify_mount_type_is_thread(Info & i);
|
||||
void notify_mount_type_is_ticket(Info & i);
|
||||
void notify_mount_type_is_cms(Info & i);
|
||||
void notify_doc_base_url(Info & i);
|
||||
void notify_item_dir(Info & i);
|
||||
void notify_item_link(Info & i);
|
||||
|
||||
} // namespace TemplatesNotifyFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
class TemplatesNotify
|
||||
{
|
||||
public:
|
||||
|
||||
TemplatesNotify();
|
||||
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetMountTypes(int mcms, int mthread, int mticket);
|
||||
|
||||
void Read();
|
||||
extern Ezc::Functions<NotifyStream> ezc_functions;
|
||||
void CreateFunctions();
|
||||
void Generate(Locale::Lang lang);
|
||||
|
||||
TextStream<std::wstring> notify_str;
|
||||
|
||||
private:
|
||||
|
||||
void Read(TemplatesNotifyFunctions::Pat pat, const std::string & dir, const char * file);
|
||||
void Read(TemplatesNotifyFunctions::Pat pat, const char * file);
|
||||
void ClearPatterns();
|
||||
|
||||
std::wstring temp;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user