storage path configurable etc

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@785 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 19 years ago
parent d3f3f7e6ff
commit e8f722adef

@ -1,7 +1,7 @@
plug_in_name = msg_storage
module_ldflags =
module_cflags =
module_cflags = -DMOD_NAME=\"$(plug_in_name)\"
COREPATH ?=../../core
include $(COREPATH)/plug-in/Makefile.app_module

@ -5,6 +5,8 @@
#include "MsgStorageAPI.h"
#include "MsgStorage.h"
#include "AmConfigReader.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <utime.h>
@ -12,11 +14,11 @@
#include <dirent.h>
#include <unistd.h>
#define MSG_DIR "/var/lib/voicebox/" // TODO: configurabel...
#define MSG_DIR "/var/spool/voicebox/" // default
MsgStorage* MsgStorage::_instance = 0;
EXPORT_PLUGIN_CLASS_FACTORY(MsgStorage,"msg_storage");
EXPORT_PLUGIN_CLASS_FACTORY(MsgStorage, MOD_NAME);
MsgStorage::MsgStorage(const string& name)
: AmDynInvokeFactory(name) {
@ -26,6 +28,27 @@ MsgStorage::MsgStorage(const string& name)
MsgStorage::~MsgStorage() { }
int MsgStorage::onLoad() {
msg_dir = MSG_DIR;
AmConfigReader cfg;
if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) {
DBG("no configuration could be loaded, assuming defaults.\n");
} else {
msg_dir = cfg.getParameter("storage_dir",MSG_DIR);
DBG("storage_dir set to '%s'.\n", msg_dir.c_str());
}
string path = msg_dir + "/_test_dir_";
int status = mkdir(path.c_str(),
S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (status && (errno != EEXIST)) {
ERROR("creating test path in storage '%s': %s\n",
path.c_str(),strerror(errno));
return -1;
}
rmdir(path.c_str());
DBG("MsgStorage loaded.\n");
return 0;
}
@ -82,9 +105,9 @@ void MsgStorage::invoke(const string& method,
int MsgStorage::msg_new(string domain, string user,
string msg_name, FILE* data) {
string msg_name, FILE* data) {
string path = MSG_DIR "/" + domain + "/" + user + "/";
string path = msg_dir+ "/" + domain + "/" + user + "/";
int status = mkdir(path.c_str(),
S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (status && (errno != EEXIST)) {
@ -108,7 +131,7 @@ int MsgStorage::msg_new(string domain, string user,
void MsgStorage::msg_get(string domain, string user,
string msg_name, AmArg& ret) {
string fname = MSG_DIR "/" + domain + "/" + user + "/"+ msg_name;
string fname = msg_dir + "/" + domain + "/" + user + "/"+ msg_name;
FILE* fp = fopen(fname.c_str(), "r");
if (!fp)
ret.push(MSG_EMSGNOTFOUND);
@ -121,7 +144,7 @@ void MsgStorage::msg_get(string domain, string user,
}
int MsgStorage::msg_markread(string domain, string user, string msg_name) {
string path = MSG_DIR "/" + domain + "/" + user + "/" + msg_name;
string path = msg_dir + "/" + domain + "/" + user + "/" + msg_name;
struct stat e_stat;
if (stat(path.c_str(), &e_stat)) {
@ -144,7 +167,8 @@ int MsgStorage::msg_markread(string domain, string user, string msg_name) {
}
int MsgStorage::msg_delete(string domain, string user, string msg_name) {
string path = MSG_DIR "/" + domain + "/" + user + "/" + msg_name;
// TODO: check the directory lock
string path = msg_dir + "/" + domain + "/" + user + "/" + msg_name;
if (unlink(path.c_str())) {
ERROR("cannot unlink '%s': %s\n",
path.c_str(),strerror(errno));
@ -154,12 +178,13 @@ int MsgStorage::msg_delete(string domain, string user, string msg_name) {
}
void MsgStorage::userdir_open(string domain, string user, AmArg& ret) {
string path = MSG_DIR "/" + domain + "/" + user + "/";
// TODO: block the directory from delete (increase lock)
string path = msg_dir + "/" + domain + "/" + user + "/";
DBG("trying to list '%s'\n", path.c_str());
DIR* dir = opendir(path.c_str());
if (!dir) {
ret.push(MSG_EUSRNOTFOUND);
ret.push(AmArg()); // empty lis
ret.push(AmArg()); // empty list
return;
}
@ -199,7 +224,11 @@ void MsgStorage::userdir_open(string domain, string user, AmArg& ret) {
ret.push(msglist);
}
int MsgStorage::userdir_close(string domain, string user) { return 0; }
int MsgStorage::userdir_close(string domain, string user) {
// TODO: unblock the directory from delete (decrease lock)
return 0;
}
void MsgStorage::userdir_getcount(string domain, string user, AmArg& ret) { }
// copies ifp to ofp, blockwise

@ -9,6 +9,8 @@ class MsgStorage : public AmDynInvokeFactory,
static MsgStorage* _instance;
string msg_dir;
int msg_new(string domain, string user, string msg_name, FILE* data);
void msg_get(string domain, string user, string msg_name, AmArg& ret);
int msg_markread(string domain, string user, string msg_name);

@ -0,0 +1,12 @@
This is an example module for file system based storage for
messages. It uses the file atime vs. mtime to determine whether a
messagee is new.
This module lacks delete-locking of an open message
directory, which means that its possible to delete a message in
one call and on a parallel call not be able to listen to that
deleted message any more (even if it was in the list before). This
should be very rare usage though.

@ -0,0 +1,8 @@
#
# storage_dir is where messages are saved on disk. this
# folder must be writable.
#
# default: /var/spool/voicebox/
#
#storage_dir=/var/spool/voicebox/
Loading…
Cancel
Save