libpurple: case-sensitive room names mapping
This commit is contained in:
parent
dd1695b530
commit
91ceb49e04
1 changed files with 53 additions and 23 deletions
|
@ -21,9 +21,11 @@
|
||||||
#if !defined(__FreeBSD__) && !defined(__APPLE__)
|
#if !defined(__FreeBSD__) && !defined(__APPLE__)
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#endif
|
#endif
|
||||||
#include <algorithm>
|
|
||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/locale.hpp>
|
||||||
|
#include <boost/locale/conversion.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
#ifdef WITH_LIBEVENT
|
#ifdef WITH_LIBEVENT
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
|
@ -515,7 +517,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
PurpleAccount *account = m_sessions[user];
|
PurpleAccount *account = m_sessions[user];
|
||||||
if (account) {
|
if (account) {
|
||||||
LOG4CXX_INFO(logger, "Sending message to '" << legacyName << "'");
|
LOG4CXX_INFO(logger, "Sending message to '" << legacyName << "'");
|
||||||
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, legacyName.c_str(), account);
|
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, LegacyNameToName(account, legacyName).c_str(), account);
|
||||||
if (legacyName == adminLegacyName) {
|
if (legacyName == adminLegacyName) {
|
||||||
// expect OAuth code
|
// expect OAuth code
|
||||||
if (m_inputRequests.find(user) != m_inputRequests.end()) {
|
if (m_inputRequests.find(user) != m_inputRequests.end()) {
|
||||||
|
@ -527,9 +529,9 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conv) {
|
if (!conv) {
|
||||||
conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_IM, legacyName.c_str(), account);
|
conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_IM, LegacyNameToName(account, legacyName).c_str(), account);
|
||||||
if (!conv) {
|
if (!conv) {
|
||||||
conv = purple_conversation_new_wrapped(PURPLE_CONV_TYPE_IM, account, legacyName.c_str());
|
conv = purple_conversation_new_wrapped(PURPLE_CONV_TYPE_IM, account, LegacyNameToName(account, legacyName).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xhtml.empty()) {
|
if (xhtml.empty()) {
|
||||||
|
@ -556,7 +558,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
void handleRoomSubjectChangedRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
|
void handleRoomSubjectChangedRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
|
||||||
PurpleAccount *account = m_sessions[user];
|
PurpleAccount *account = m_sessions[user];
|
||||||
if (account) {
|
if (account) {
|
||||||
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, legacyName.c_str(), account);
|
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, LegacyNameToName(account, legacyName).c_str(), account);
|
||||||
if (!conv) {
|
if (!conv) {
|
||||||
LOG4CXX_ERROR(logger, user << ": Cannot set room subject. There is now conversation " << legacyName);
|
LOG4CXX_ERROR(logger, user << ": Cannot set room subject. There is now conversation " << legacyName);
|
||||||
return;
|
return;
|
||||||
|
@ -727,6 +729,29 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LegacyNameToName(PurpleAccount *account, const std::string &legacyName) {
|
||||||
|
std::string conversationName = legacyName;
|
||||||
|
BOOST_FOREACH(std::string _room, m_rooms[np->m_accounts[account]]) {
|
||||||
|
std::string lowercased_room = boost::locale::to_lower(_room);
|
||||||
|
if (lowercased_room.compare(conversationName) == 0) {
|
||||||
|
conversationName = _room;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return conversationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NameToLegacyName(PurpleAccount *account, const std::string &legacyName) {
|
||||||
|
std::string conversationName = legacyName;
|
||||||
|
BOOST_FOREACH(std::string _room, m_rooms[np->m_accounts[account]]) {
|
||||||
|
if (_room.compare(conversationName) == 0) {
|
||||||
|
conversationName = boost::locale::to_lower(legacyName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return conversationName;
|
||||||
|
}
|
||||||
|
|
||||||
void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &pasword) {
|
void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &pasword) {
|
||||||
PurpleAccount *account = m_sessions[user];
|
PurpleAccount *account = m_sessions[user];
|
||||||
if (!account) {
|
if (!account) {
|
||||||
|
@ -735,17 +760,17 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
|
|
||||||
PurpleConnection *gc = purple_account_get_connection_wrapped(account);
|
PurpleConnection *gc = purple_account_get_connection_wrapped(account);
|
||||||
GHashTable *comps = NULL;
|
GHashTable *comps = NULL;
|
||||||
|
std::string roomName = LegacyNameToName(account, room);
|
||||||
// Check if the PurpleChat is not stored in buddy list
|
// Check if the PurpleChat is not stored in buddy list
|
||||||
PurpleChat *chat = purple_blist_find_chat_wrapped(account, room.c_str());
|
PurpleChat *chat = purple_blist_find_chat_wrapped(account, roomName.c_str());
|
||||||
if (chat) {
|
if (chat) {
|
||||||
comps = purple_chat_get_components_wrapped(chat);
|
comps = purple_chat_get_components_wrapped(chat);
|
||||||
}
|
}
|
||||||
else if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) {
|
else if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) {
|
||||||
if (CONFIG_STRING(config, "service.protocol") == "prpl-jabber") {
|
if (CONFIG_STRING(config, "service.protocol") == "prpl-jabber") {
|
||||||
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, (room + "/" + nickname).c_str());
|
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, (roomName + "/" + nickname).c_str());
|
||||||
} else {
|
} else {
|
||||||
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, room.c_str());
|
comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, roomName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,7 +788,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG4CXX_INFO(logger, user << ": Joining the room " << room);
|
LOG4CXX_INFO(logger, user << ": Joining the room " << roomName);
|
||||||
if (comps) {
|
if (comps) {
|
||||||
serv_join_chat_wrapped(gc, comps);
|
serv_join_chat_wrapped(gc, comps);
|
||||||
g_hash_table_destroy(comps);
|
g_hash_table_destroy(comps);
|
||||||
|
@ -776,7 +801,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, room.c_str(), account);
|
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, LegacyNameToName(account, room).c_str(), account);
|
||||||
purple_conversation_destroy_wrapped(conv);
|
purple_conversation_destroy_wrapped(conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,6 +873,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||||
std::map<std::string, unsigned int> m_vcards;
|
std::map<std::string, unsigned int> m_vcards;
|
||||||
std::map<std::string, authRequest *> m_authRequests;
|
std::map<std::string, authRequest *> m_authRequests;
|
||||||
std::map<std::string, inputRequest *> m_inputRequests;
|
std::map<std::string, inputRequest *> m_inputRequests;
|
||||||
|
std::map<std::string, std::list<std::string> > m_rooms;
|
||||||
std::map<unsigned long, PurpleXfer *> m_xfers;
|
std::map<unsigned long, PurpleXfer *> m_xfers;
|
||||||
std::map<std::string, PurpleXfer *> m_unhandledXfers;
|
std::map<std::string, PurpleXfer *> m_unhandledXfers;
|
||||||
std::vector<PurpleXfer *> m_waitingXfers;
|
std::vector<PurpleXfer *> m_waitingXfers;
|
||||||
|
@ -1157,9 +1183,10 @@ static void conv_write(PurpleConversation *conv, const char *who, const char *al
|
||||||
np->handleMessage(np->m_accounts[account], w, message_, "", xhtml_, timestamp);
|
np->handleMessage(np->m_accounts[account], w, message_, "", xhtml_, timestamp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << purple_conversation_get_name_wrapped(conv) << "' " << who);
|
std::string conversationName = purple_conversation_get_name_wrapped(conv);
|
||||||
np->handleMessage(np->m_accounts[account], purple_conversation_get_name_wrapped(conv), message_, who, xhtml_, timestamp);
|
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << conversationName << "' " << who);
|
||||||
}
|
np->handleMessage(np->m_accounts[account], np->NameToLegacyName(account, conversationName), message_, who, xhtml_, timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,8 +1333,9 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char
|
||||||
np->handleMessage(np->m_accounts[account], w, message_, n, xhtml_, timestamp);
|
np->handleMessage(np->m_accounts[account], w, message_, n, xhtml_, timestamp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' xhtml='" << xhtml_ << "' name='" << purple_conversation_get_name_wrapped(conv) << "' " << who);
|
std::string conversationName = purple_conversation_get_name_wrapped(conv);
|
||||||
np->handleMessage(np->m_accounts[account], purple_conversation_get_name_wrapped(conv), message_, who, xhtml_, timestamp);
|
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' xhtml='" << xhtml_ << "' name='" << conversationName << "' " << who);
|
||||||
|
np->handleMessage(np->m_accounts[account], np->NameToLegacyName(account, conversationName), message_, who, xhtml_, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,8 +1363,8 @@ static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gbool
|
||||||
// item->addAttribute("affiliation", "member");
|
// item->addAttribute("affiliation", "member");
|
||||||
// item->addAttribute("role", "participant");
|
// item->addAttribute("role", "participant");
|
||||||
}
|
}
|
||||||
|
std::string conversationName = purple_conversation_get_name_wrapped(conv);
|
||||||
np->handleParticipantChanged(np->m_accounts[account], name, purple_conversation_get_name_wrapped(conv), (int) flags, pbnetwork::STATUS_ONLINE, "", "", alias);
|
np->handleParticipantChanged(np->m_accounts[account], name, np->NameToLegacyName(account, conversationName), (int) flags, pbnetwork::STATUS_ONLINE, "", "", alias);
|
||||||
|
|
||||||
l = l->next;
|
l = l->next;
|
||||||
}
|
}
|
||||||
|
@ -1348,7 +1376,8 @@ static void conv_chat_remove_users(PurpleConversation *conv, GList *users) {
|
||||||
GList *l = users;
|
GList *l = users;
|
||||||
while (l != NULL) {
|
while (l != NULL) {
|
||||||
std::string name((char *) l->data);
|
std::string name((char *) l->data);
|
||||||
np->handleParticipantChanged(np->m_accounts[account], name, purple_conversation_get_name_wrapped(conv), 0, pbnetwork::STATUS_NONE);
|
std::string conversationName = purple_conversation_get_name_wrapped(conv);
|
||||||
|
np->handleParticipantChanged(np->m_accounts[account], name, np->NameToLegacyName(account, conversationName), 0, pbnetwork::STATUS_NONE);
|
||||||
|
|
||||||
l = l->next;
|
l = l->next;
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1390,7 @@ static gboolean conv_has_focus(PurpleConversation *conv) {
|
||||||
static void conv_chat_topic_changed(PurpleConversation *conv, const char *who, const char *topic) {
|
static void conv_chat_topic_changed(PurpleConversation *conv, const char *who, const char *topic) {
|
||||||
LOG4CXX_INFO(logger, "Conversation topic changed");
|
LOG4CXX_INFO(logger, "Conversation topic changed");
|
||||||
PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
|
PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
|
||||||
np->handleSubject(np->m_accounts[account], purple_conversation_get_name_wrapped(conv), topic ? topic : "", who ? who : "Spectrum 2");
|
np->handleSubject(np->m_accounts[account], np->NameToLegacyName(account, purple_conversation_get_name_wrapped(conv)), topic ? topic : "", who ? who : "Spectrum 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void conv_present(PurpleConversation *conv) {
|
static void conv_present(PurpleConversation *conv) {
|
||||||
|
@ -1833,11 +1862,10 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
GList *rooms;
|
GList *rooms;
|
||||||
std::list<std::string> m_rooms;
|
|
||||||
std::list<std::string> m_topics;
|
std::list<std::string> m_topics;
|
||||||
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
|
for (rooms = list->rooms; rooms != NULL; rooms = rooms->next) {
|
||||||
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
|
PurpleRoomlistRoom *room = (PurpleRoomlistRoom *)rooms->data;
|
||||||
m_rooms.push_back(room->name);
|
np->m_rooms[np->m_accounts[list->account]].push_back(room->name);
|
||||||
|
|
||||||
if (topicId == -1) {
|
if (topicId == -1) {
|
||||||
m_topics.push_back(room->name);
|
m_topics.push_back(room->name);
|
||||||
|
@ -1872,7 +1900,7 @@ static void RoomlistProgress(PurpleRoomlist *list, gboolean in_progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG4CXX_INFO(logger, "RoomList is fetched for user " << user);
|
LOG4CXX_INFO(logger, "RoomList is fetched for user " << user);
|
||||||
np->handleRoomList(user, m_rooms, m_topics);
|
np->handleRoomList(user, np->m_rooms[user], m_topics);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG4CXX_INFO(logger, "RoomList is still in progress");
|
LOG4CXX_INFO(logger, "RoomList is still in progress");
|
||||||
|
@ -2209,6 +2237,8 @@ static void transportDataReceived(gpointer data, gint source, PurpleInputConditi
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
boost::locale::generator gen;
|
||||||
|
std::locale::global(gen(""));
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#if !defined(__FreeBSD__) && !defined(__APPLE__)
|
#if !defined(__FreeBSD__) && !defined(__APPLE__)
|
||||||
mallopt(M_CHECK_ACTION, 2);
|
mallopt(M_CHECK_ACTION, 2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue