working smstools3 with basic pairing
This commit is contained in:
parent
d8e60cea95
commit
57963cf18e
4 changed files with 59 additions and 13 deletions
|
@ -42,6 +42,8 @@ using namespace Transport;
|
|||
|
||||
using namespace log4cxx;
|
||||
|
||||
#define INTERNAL_USER "/sms@backend@internal@user"
|
||||
|
||||
class SMSNetworkPlugin;
|
||||
SMSNetworkPlugin * np = NULL;
|
||||
StorageBackend *storageBackend;
|
||||
|
@ -52,6 +54,7 @@ class SMSNetworkPlugin : public NetworkPlugin {
|
|||
Swift::BoostIOServiceThread m_boostIOServiceThread;
|
||||
boost::shared_ptr<Swift::Connection> m_conn;
|
||||
Swift::Timer::ref m_timer;
|
||||
int m_internalUser;
|
||||
|
||||
SMSNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
|
||||
this->config = config;
|
||||
|
@ -65,6 +68,13 @@ class SMSNetworkPlugin : public NetworkPlugin {
|
|||
m_timer = m_factories->getTimerFactory()->createTimer(5000);
|
||||
m_timer->onTick.connect(boost::bind(&SMSNetworkPlugin::handleSMSDir, this));
|
||||
m_timer->start();
|
||||
|
||||
UserInfo info;
|
||||
info.jid = INTERNAL_USER;
|
||||
info.password = "";
|
||||
storageBackend->setUser(info);
|
||||
storageBackend->getUser(INTERNAL_USER, info);
|
||||
m_internalUser = info.id;
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,21 +88,32 @@ class SMSNetworkPlugin : public NetworkPlugin {
|
|||
|
||||
str.assign((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
|
||||
|
||||
std::string to = "";
|
||||
std::string from = "";
|
||||
std::string msg = "";
|
||||
while(str.find("\n") != std::string::npos) {
|
||||
std::string line = str.substr(0, str.find("\n"));
|
||||
if (line.find("To: ") == 0) {
|
||||
to = line.substr(strlen("To: "));
|
||||
if (line.find("From: ") == 0) {
|
||||
from = line.substr(strlen("From: "));
|
||||
}
|
||||
else if (line.empty()) {
|
||||
msg = str;
|
||||
msg = str.substr(1);
|
||||
break;
|
||||
}
|
||||
str = str.substr(str.find("\n") + 1);
|
||||
}
|
||||
|
||||
std::cout << "INCOMING SMS '" << to << "' '" << msg << "'\n";
|
||||
std::list<BuddyInfo> roster;
|
||||
storageBackend->getBuddies(m_internalUser, roster);
|
||||
|
||||
std::string to;
|
||||
BOOST_FOREACH(BuddyInfo &b, roster) {
|
||||
if (b.legacyName == from) {
|
||||
to = b.alias;
|
||||
}
|
||||
}
|
||||
|
||||
handleMessage(to, from, msg);
|
||||
std::cout << "INCOMING SMS '" << from << "' '" << to << "' '" << msg << "'\n";
|
||||
|
||||
}
|
||||
|
||||
|
@ -104,7 +125,7 @@ class SMSNetworkPlugin : public NetworkPlugin {
|
|||
try {
|
||||
if (is_regular(itr->path())) {
|
||||
handleSMS(itr->path().string());
|
||||
// remove(itr->path());
|
||||
remove(itr->path());
|
||||
}
|
||||
}
|
||||
catch (const filesystem_error& ex) {
|
||||
|
@ -162,7 +183,20 @@ class SMSNetworkPlugin : public NetworkPlugin {
|
|||
}
|
||||
|
||||
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") {
|
||||
sendSMS(legacyName, message);
|
||||
std::string n = legacyName;
|
||||
if (n.find("+") == 0) {
|
||||
n = n.substr(1);
|
||||
}
|
||||
|
||||
BuddyInfo info;
|
||||
info.legacyName = n;
|
||||
info.alias = user;
|
||||
info.id = -1;
|
||||
info.subscription = "both";
|
||||
info.flags = 0;
|
||||
storageBackend->addBuddy(m_internalUser, info);
|
||||
|
||||
sendSMS(n, message);
|
||||
}
|
||||
|
||||
void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password) {
|
||||
|
|
|
@ -33,6 +33,12 @@ incoming_dir=/var/spool/sms/incoming
|
|||
#backend_config=/home/hanzz/code/libtransport/spectrum/src/backend-logging.cfg # log4cxx/log4j logging configuration file for backends
|
||||
|
||||
[database]
|
||||
type = sqlite3 # or "none" without database backend
|
||||
database = test.sql
|
||||
prefix=icq
|
||||
#type = sqlite3 # or "none" without database backend
|
||||
#database = test.sql
|
||||
#prefix=icq
|
||||
type = mysql # or "none" without database backend.......................................................................................................................
|
||||
database = test
|
||||
prefix=
|
||||
user=root
|
||||
password=yourrootsqlpassword
|
||||
#encryption_key=hanzzik
|
||||
|
|
|
@ -470,7 +470,7 @@ long MySQLBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
|
|||
long id = (long) mysql_insert_id(&m_conn);
|
||||
|
||||
// INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?)
|
||||
if (!buddyInfo.settings.find("icon_hash")->second.s.empty()) {
|
||||
if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end() && !buddyInfo.settings.find("icon_hash")->second.s.empty()) {
|
||||
*m_updateBuddySetting << userId << id << buddyInfo.settings.find("icon_hash")->first << (int) TYPE_STRING << buddyInfo.settings.find("icon_hash")->second.s << buddyInfo.settings.find("icon_hash")->second.s;
|
||||
EXEC(m_updateBuddySetting, addBuddy(userId, buddyInfo));
|
||||
}
|
||||
|
@ -597,6 +597,10 @@ void MySQLBackend::getUserSetting(long id, const std::string &variable, int &typ
|
|||
else {
|
||||
*m_getUserSetting >> type >> value;
|
||||
}
|
||||
|
||||
while (m_getUserSetting->fetch() == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MySQLBackend::updateUserSetting(long id, const std::string &variable, const std::string &value) {
|
||||
|
@ -606,11 +610,11 @@ void MySQLBackend::updateUserSetting(long id, const std::string &variable, const
|
|||
}
|
||||
|
||||
void MySQLBackend::beginTransaction() {
|
||||
exec("START TRANSACTION;");
|
||||
//exec("START TRANSACTION;");
|
||||
}
|
||||
|
||||
void MySQLBackend::commitTransaction() {
|
||||
exec("COMMIT;");
|
||||
//exec("COMMIT;");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,6 +111,8 @@ bool SQLite3Backend::connect() {
|
|||
return false;
|
||||
}
|
||||
|
||||
sqlite3_busy_timeout(m_db, 1500);
|
||||
|
||||
if (createDatabase() == false)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue