Use JID escaping by default + keep compatibility with spectrum1 database when using JID escaping
This commit is contained in:
parent
6db78c58d2
commit
90aacd41d9
10 changed files with 52 additions and 51 deletions
|
@ -162,6 +162,7 @@ class Buddy {
|
|||
/// \param jid Jabber ID.
|
||||
/// \return legacy name of buddy from JID.
|
||||
static std::string JIDToLegacyName(const Swift::JID &jid);
|
||||
static BuddyFlag buddFlagsFromJID(const Swift::JID &jid);
|
||||
|
||||
private:
|
||||
void generateJID();
|
||||
|
|
|
@ -28,6 +28,6 @@ protocol=any
|
|||
#backend_config=backend_logging.cfg # log4cxx/log4j logging configuration file for backends
|
||||
|
||||
[database]
|
||||
#type = mysql # or "none" without database backend
|
||||
type = none # or "none" without database backend
|
||||
database = test.sql
|
||||
prefix=icq
|
||||
|
|
|
@ -50,7 +50,7 @@ long Buddy::getID() {
|
|||
void Buddy::setFlags(BuddyFlag flags) {
|
||||
m_flags = flags;
|
||||
|
||||
generateJID();
|
||||
// generateJID();
|
||||
}
|
||||
|
||||
BuddyFlag Buddy::getFlags() {
|
||||
|
@ -125,10 +125,11 @@ std::string Buddy::getSafeName() {
|
|||
// Transport::instance()->protocol()->prepareUsername(name, purple_buddy_get_account(m_buddy));
|
||||
if (getFlags() & BUDDY_JID_ESCAPING) {
|
||||
name = Swift::JID::getEscapedNode(name);
|
||||
std::cout << "OUT '" << getName() << "' '" << name << "'\n";
|
||||
}
|
||||
else {
|
||||
if (name.find_last_of("@") != std::string::npos) {
|
||||
name.replace(name.find_last_of("@"), 1, "%");
|
||||
name.replace(name.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
}
|
||||
// if (name.empty()) {
|
||||
|
@ -155,17 +156,24 @@ std::string Buddy::JIDToLegacyName(const Swift::JID &jid) {
|
|||
if (jid.getUnescapedNode() == jid.getNode()) {
|
||||
name = jid.getNode();
|
||||
if (name.find_last_of("%") != std::string::npos) {
|
||||
name.replace(name.find_last_of("%"), 1, "@");
|
||||
name.replace(name.find_last_of("%"), 1, "@"); // OK
|
||||
}
|
||||
}
|
||||
else {
|
||||
name = jid.getUnescapedNode();
|
||||
// Psi sucks...
|
||||
if (name.find_last_of("\\40") != std::string::npos) {
|
||||
name.replace(name.find_last_of("\\40"), 1, "@");
|
||||
name.replace(name.find_last_of("\\40"), 1, "@"); // OK
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
BuddyFlag Buddy::buddFlagsFromJID(const Swift::JID &jid) {
|
||||
if (jid.getUnescapedNode() == jid.getNode()) {
|
||||
return BUDDY_NO_FLAG;
|
||||
}
|
||||
return BUDDY_JID_ESCAPING;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,11 +59,7 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
|
|||
message->setFrom(buddy->getJID());
|
||||
}
|
||||
else {
|
||||
std::string name = nickname;
|
||||
if (name.find_last_of("@") != std::string::npos) {
|
||||
name.replace(name.find_last_of("@"), 1, "%");
|
||||
}
|
||||
message->setFrom(name);
|
||||
message->setFrom(Swift::JID(Swift::JID::getEscapedNode(nickname), m_conversationManager->getComponent()->getJID().toBare()));
|
||||
}
|
||||
}
|
||||
// PM message
|
||||
|
|
|
@ -63,10 +63,11 @@ void ConversationManager::removeConversation(Conversation *conv) {
|
|||
}
|
||||
|
||||
void ConversationManager::handleMessageReceived(Swift::Message::ref message) {
|
||||
std::string name = message->getTo().getUnescapedNode();
|
||||
if (name.find_last_of("%") != std::string::npos) {
|
||||
name.replace(name.find_last_of("%"), 1, "@");
|
||||
}
|
||||
// std::string name = message->getTo().getUnescapedNode();
|
||||
// if (name.find_last_of("%") != std::string::npos) { // OK when commented
|
||||
// name.replace(name.find_last_of("%"), 1, "@"); // OK when commented
|
||||
// }
|
||||
std::string name = Buddy::JIDToLegacyName(message->getTo());
|
||||
|
||||
// create conversation if it does not exist.
|
||||
if (!m_convs[name]) {
|
||||
|
|
|
@ -90,7 +90,7 @@ class NetworkFactory : public Factory {
|
|||
buddy->setName(buddyInfo.legacyName);
|
||||
buddy->setSubscription(buddyInfo.subscription);
|
||||
buddy->setGroups(buddyInfo.groups);
|
||||
buddy->setFlags((BuddyFlag) buddyInfo.flags);
|
||||
buddy->setFlags((BuddyFlag) (buddyInfo.flags));
|
||||
if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end())
|
||||
buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s);
|
||||
return buddy;
|
||||
|
@ -396,12 +396,11 @@ void NetworkPluginServer::handleAuthorizationPayload(const std::string &data) {
|
|||
response->setTo(user->getJID());
|
||||
std::string name = payload.buddyname();
|
||||
|
||||
// TODO:
|
||||
// name = Swift::JID::getEscapedNode(name)
|
||||
name = Swift::JID::getEscapedNode(name);
|
||||
|
||||
if (name.find_last_of("@") != std::string::npos) {
|
||||
name.replace(name.find_last_of("@"), 1, "%");
|
||||
}
|
||||
// if (name.find_last_of("@") != std::string::npos) { // OK when commented
|
||||
// name.replace(name.find_last_of("@"), 1, "%"); // OK when commented
|
||||
// }
|
||||
|
||||
response->setFrom(Swift::JID(name, m_component->getJID().toString()));
|
||||
response->setType(Swift::Presence::Subscribe);
|
||||
|
@ -451,6 +450,7 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) {
|
|||
}
|
||||
else {
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1);
|
||||
buddy->setFlags(BUDDY_JID_ESCAPING);
|
||||
handleBuddyPayload(buddy, payload);
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
}
|
||||
|
@ -669,33 +669,31 @@ void NetworkPluginServer::pingTimeout() {
|
|||
// Some users are connected for weeks and they are blocking backend to be destroyed and its memory
|
||||
// to be freed. We are finding users who are inactive for more than "idle_reconnect_time" seconds and
|
||||
// reconnect them to long-running backend, where they can idle hapilly till the end of ages.
|
||||
time_t now = time(NULL);
|
||||
std::vector<User *> usersToMove;
|
||||
unsigned long diff = CONFIG_INT(m_config, "service.idle_reconnect_time");
|
||||
if (diff != 0) {
|
||||
time_t now = time(NULL);
|
||||
std::vector<User *> usersToMove;
|
||||
|
||||
for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
|
||||
// Users from long-running backends can't be moved
|
||||
if ((*it)->longRun) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find users which are inactive for more than 'diff'
|
||||
BOOST_FOREACH(User *u, (*it)->users) {
|
||||
if (now - u->getLastActivity() > diff) {
|
||||
usersToMove.push_back(u);
|
||||
}
|
||||
}
|
||||
for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
|
||||
// Users from long-running backends can't be moved
|
||||
if ((*it)->longRun) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move inactive users to long-running backend.
|
||||
BOOST_FOREACH(User *u, usersToMove) {
|
||||
LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend");
|
||||
if (!moveToLongRunBackend(u))
|
||||
break;
|
||||
// Find users which are inactive for more than 'diff'
|
||||
BOOST_FOREACH(User *u, (*it)->users) {
|
||||
if (now - u->getLastActivity() > diff) {
|
||||
usersToMove.push_back(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move inactive users to long-running backend.
|
||||
BOOST_FOREACH(User *u, usersToMove) {
|
||||
LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend");
|
||||
if (!moveToLongRunBackend(u))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// check ping responses
|
||||
std::vector<Backend *> toRemove;
|
||||
|
|
|
@ -211,7 +211,7 @@ void RosterManager::handleRemoteRosterResponse(boost::shared_ptr<Swift::RosterPa
|
|||
buddyInfo.alias = item.getName();
|
||||
buddyInfo.legacyName = legacyName;
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = 0;
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID());
|
||||
|
||||
Buddy *buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
setBuddy(buddy);
|
||||
|
@ -299,7 +299,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
|
|||
buddyInfo.alias = "";
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = 0;
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo());
|
||||
LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Subscription received for new buddy " << buddyInfo.legacyName << " => adding to legacy network");
|
||||
|
||||
buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
|
@ -361,7 +361,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
|
|||
buddyInfo.alias = "";
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = 0;
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo());
|
||||
|
||||
buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
setBuddy(buddy);
|
||||
|
|
|
@ -94,7 +94,7 @@ bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID&
|
|||
buddyInfo.alias = item.getName();
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(item.getJID());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = 0;
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID());
|
||||
LOG4CXX_INFO(logger, from.toBare().toString() << ": Adding buddy " << buddyInfo.legacyName);
|
||||
|
||||
buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo);
|
||||
|
|
|
@ -164,8 +164,8 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
|
|||
res.password = "";
|
||||
res.uin = presence->getFrom().getNode();
|
||||
res.jid = userkey;
|
||||
if (res.uin.find_last_of("%") != std::string::npos) {
|
||||
res.uin.replace(res.uin.find_last_of("%"), 1, "@");
|
||||
if (res.uin.find_last_of("%") != std::string::npos) { // OK
|
||||
res.uin.replace(res.uin.find_last_of("%"), 1, "@"); // OK
|
||||
}
|
||||
if (m_storageBackend) {
|
||||
// store user and getUser again to get user ID.
|
||||
|
|
|
@ -96,12 +96,9 @@ bool VCardResponder::handleGetRequest(const Swift::JID& from, const Swift::JID&
|
|||
std::string name = to_.getUnescapedNode();
|
||||
if (name.empty()) {
|
||||
to_ = user->getJID();
|
||||
name = to_.getUnescapedNode();
|
||||
}
|
||||
|
||||
if (name.find_last_of("%") != std::string::npos) {
|
||||
name.replace(name.find_last_of("%"), 1, "@");
|
||||
}
|
||||
name = Buddy::JIDToLegacyName(to_);
|
||||
|
||||
LOG4CXX_INFO(logger, from.toBare().toString() << ": Requested VCard of " << name);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue