Files
@ 7a63ea9e0e6a
Branch filter:
Location: libtransport.git/libtransport/StorageBackend.cpp - annotation
7a63ea9e0e6a
2.8 KiB
text/x-c++hdr
libtransport: set active chat state on conversation message
Not setting it violated XEP-0085 and sometimes tricked other clients
into thinking that Spectrum does not understand chat states.
Closes #282
Not setting it violated XEP-0085 and sometimes tricked other clients
into thinking that Spectrum does not understand chat states.
Closes #282
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 78e71f9345c7 78e71f9345c7 a06a47ed110e 78e71f9345c7 78e71f9345c7 78e71f9345c7 cc64a76c8be5 a06a47ed110e 372ee69043f1 a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e da196682876c a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e a06a47ed110e b326bca552d7 a06a47ed110e a06a47ed110e a06a47ed110e 372ee69043f1 372ee69043f1 372ee69043f1 e63427c2da8a 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 e63427c2da8a 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 372ee69043f1 a06a47ed110e | #include "transport/StorageBackend.h"
#include "transport/Config.h"
#include "transport/SQLite3Backend.h"
#include "transport/MySQLBackend.h"
#include "transport/PQXXBackend.h"
#include "Swiften/StringCodecs/Base64.h"
namespace Transport {
StorageBackend *StorageBackend::createBackend(Config *config, std::string &error) {
StorageBackend *storageBackend = NULL;
#ifdef WITH_SQLITE
if (CONFIG_STRING(config, "database.type") == "sqlite3") {
storageBackend = new SQLite3Backend(config);
}
#else
if (CONFIG_STRING(config, "database.type") == "sqlite3") {
error = "Libtransport is not compiled with sqlite3 backend support.";
}
#endif
#ifdef WITH_MYSQL
if (CONFIG_STRING(config, "database.type") == "mysql") {
storageBackend = new MySQLBackend(config);
}
#else
if (CONFIG_STRING(config, "database.type") == "mysql") {
error = "Spectrum2 is not compiled with mysql backend support.";
}
#endif
#ifdef WITH_PQXX
if (CONFIG_STRING(config, "database.type") == "pqxx") {
storageBackend = new PQXXBackend(config);
}
#else
if (CONFIG_STRING(config, "database.type") == "pqxx") {
error = "Spectrum2 is not compiled with pqxx backend support.";
}
#endif
if (CONFIG_STRING(config, "database.type") != "mysql" && CONFIG_STRING(config, "database.type") != "sqlite3"
&& CONFIG_STRING(config, "database.type") != "pqxx" && CONFIG_STRING(config, "database.type") != "none") {
error = "Unknown storage backend " + CONFIG_STRING(config, "database.type");
}
return storageBackend;
}
std::string StorageBackend::encryptPassword(const std::string &password, const std::string &key) {
std::string encrypted;
encrypted.resize(password.size());
for (unsigned i = 0; i < password.size(); i++) {
char c = password[i];
char keychar = key[i % key.size()];
c += keychar;
encrypted[i] = c;
}
encrypted = Swift::Base64::encode(Swift::createByteArray(encrypted));
return encrypted;
}
std::string StorageBackend::decryptPassword(std::string &encrypted, const std::string &key) {
encrypted = Swift::byteArrayToString(Swift::Base64::decode(encrypted));
std::string password;
password.resize(encrypted.size());
for (unsigned i = 0; i < encrypted.size(); i++) {
char c = encrypted[i];
char keychar = key[i % key.size()];
c -= keychar;
password[i] = c;
}
return password;
}
std::string StorageBackend::serializeGroups(const std::vector<std::string> &groups) {
std::string ret;
BOOST_FOREACH(const std::string &group, groups) {
ret += group + "\n";
}
if (!ret.empty()) {
ret.erase(ret.end() - 1);
}
return ret;
}
std::vector<std::string> StorageBackend::deserializeGroups(std::string &groups) {
std::vector<std::string> ret;
if (groups.empty()) {
return ret;
}
boost::split(ret, groups, boost::is_any_of("\n"));
if (ret.back().empty()) {
ret.erase(ret.end() - 1);
}
return ret;
}
}
|