summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2013-11-17 23:23:53 +0000
committerRobert Pösel <robyer@seznam.cz>2013-11-17 23:23:53 +0000
commitb31c85fadafb41df147ff0c27baa04a23a48a27e (patch)
treed12d7cd770e1d193ed1ed683e36963cfb4abf7e0 /protocols/FacebookRM/src
parent96d149d7437f2a8dafcb5fb9fd535f0b2af47c69 (diff)
Facebook: use TCHAR* instead of char* on many places (chat related)
git-svn-id: http://svn.miranda-ng.org/main/trunk@6932 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/chat.cpp47
-rw-r--r--protocols/FacebookRM/src/client.h2
-rw-r--r--protocols/FacebookRM/src/contacts.cpp6
-rw-r--r--protocols/FacebookRM/src/entities.h4
-rw-r--r--protocols/FacebookRM/src/json.cpp29
-rw-r--r--protocols/FacebookRM/src/messages.cpp6
-rw-r--r--protocols/FacebookRM/src/process.cpp6
-rw-r--r--protocols/FacebookRM/src/proto.h14
8 files changed, 54 insertions, 60 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index 6519f1c96b..395a6ce507 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -24,15 +24,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_history.h>
#include <m_userinfo.h>
-void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp)
+void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char *name, const char *message, DWORD timestamp)
{
- ptrT tchat_id( mir_a2t(chat_id));
ptrT tid( mir_a2t(id));
ptrT tnick( mir_a2t_cp(name,CP_UTF8));
ptrT ttext( mir_a2t_cp(message,CP_UTF8));
GCDEST gcd = { m_szModuleName };
- gcd.ptszID = tchat_id;
+ gcd.ptszID = (TCHAR *)tchat_id;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
@@ -49,7 +48,7 @@ void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *
CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
- std::map<std::string, facebook_chatroom>::iterator chatroom = facy.chat_rooms.find(chat_id);
+ std::map<std::tstring, facebook_chatroom>::iterator chatroom = facy.chat_rooms.find(tchat_id);
chatroom->second.message_readers = "";
//HANDLE hChatContact = ChatIDToHContact(chat_id);
@@ -155,14 +154,13 @@ int FacebookProto::OnGCEvent(WPARAM wParam,LPARAM lParam)
return 0;
}
-void FacebookProto::AddChatContact(const char *chat_id, const char *id, const char *name)
+void FacebookProto::AddChatContact(const TCHAR *tchat_id, const char *id, const char *name)
{
- ptrT tchat_id( mir_a2t(chat_id));
ptrT tnick( mir_a2t_cp(name, CP_UTF8));
ptrT tid( mir_a2t(id));
GCDEST gcd = { m_szModuleName };
- gcd.ptszID = tchat_id;
+ gcd.ptszID = (TCHAR *)tchat_id;
gcd.iType = GC_EVENT_JOIN;
GCEVENT gce = {sizeof(gce)};
@@ -178,7 +176,7 @@ void FacebookProto::AddChatContact(const char *chat_id, const char *id, const ch
else
gce.ptszStatus = _T("Normal");
- std::map<std::string, facebook_chatroom>::iterator room = facy.chat_rooms.find(chat_id);
+ std::map<std::tstring, facebook_chatroom>::iterator room = facy.chat_rooms.find(tchat_id);
if(room != facy.chat_rooms.end())
room->second.participants.insert(std::make_pair(id, name));
@@ -186,17 +184,16 @@ void FacebookProto::AddChatContact(const char *chat_id, const char *id, const ch
}
-void FacebookProto::RemoveChatContact(const char *chat_id, const char *id)
+void FacebookProto::RemoveChatContact(const TCHAR *tchat_id, const char *id)
{
// We dont want to remove our self-contact from chat. Ever.
if (!strcmp(id, facy.self_.user_id.c_str()))
return;
- ptrT tchat_id( mir_a2t(chat_id));
ptrT tid( mir_a2t(id));
GCDEST gcd = { m_szModuleName };
- gcd.ptszID = tchat_id;
+ gcd.ptszID = (TCHAR *)tchat_id;
gcd.iType = GC_EVENT_PART;
GCEVENT gce = {sizeof(gce)};
@@ -208,7 +205,7 @@ void FacebookProto::RemoveChatContact(const char *chat_id, const char *id)
gce.time = ::time(NULL);
gce.bIsMe = false;//!strcmp(id, facy.self_.user_id.c_str());
- std::map<std::string, facebook_chatroom>::iterator room = facy.chat_rooms.find(chat_id);
+ std::map<std::tstring, facebook_chatroom>::iterator room = facy.chat_rooms.find(tchat_id);
if (room != facy.chat_rooms.end())
room->second.participants.erase(id);
@@ -216,13 +213,12 @@ void FacebookProto::RemoveChatContact(const char *chat_id, const char *id)
}
/** Caller must free result */
-char *FacebookProto::GetChatUsers(const char *chat_id)
+char *FacebookProto::GetChatUsers(const TCHAR *chat_id)
{
- ptrT tid( mir_a2t(chat_id));
GC_INFO gci = {0};
gci.Flags = USERS;
gci.pszModule = m_szModuleName;
- gci.pszID = tid;
+ gci.pszID = (TCHAR *)chat_id;
CallService(MS_GC_GETINFO, 0, (LPARAM)(GC_INFO *) &gci);
debugLogA("**Chat - Users in chat %s: %s", chat_id, gci.pszUsers);
@@ -231,19 +227,16 @@ char *FacebookProto::GetChatUsers(const char *chat_id)
return gci.pszUsers;
}
-bool FacebookProto::IsChatContact(const char *chat_id, const char *id)
+bool FacebookProto::IsChatContact(const TCHAR *chat_id, const char *id)
{
ptrA users( GetChatUsers(chat_id));
return (users != NULL && strstr(users, id) != NULL);
}
-void FacebookProto::AddChat(const char *id, const char *name)
+void FacebookProto::AddChat(const TCHAR *tid, const TCHAR *tname)
{
GCSESSION gcw = {sizeof(gcw)};
- ptrT tname( mir_a2t_cp(name, CP_UTF8));
- ptrT tid( mir_a2t(id));
-
// Create the group chat session
gcw.dwFlags = GC_TCHAR;
gcw.iType = GCW_CHATROOM;
@@ -254,7 +247,7 @@ void FacebookProto::AddChat(const char *id, const char *name)
// Send setting events
GCDEST gcd = { m_szModuleName };
- gcd.ptszID = tid;
+ gcd.ptszID = (TCHAR *)tid;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
@@ -273,11 +266,11 @@ void FacebookProto::AddChat(const char *id, const char *name)
gce.pDest = &gcd;
facebook_chatroom chatroom;
- chatroom.chat_name = name;
- facy.chat_rooms.insert(std::make_pair(id, chatroom));
+ chatroom.chat_name = tname;
+ facy.chat_rooms.insert(std::make_pair(tid, chatroom));
// Add self contact
- AddChatContact(id, facy.self_.user_id.c_str(), facy.self_.real_name.c_str());
+ AddChatContact(tid, facy.self_.user_id.c_str(), facy.self_.real_name.c_str());
CallServiceSync(MS_GC_EVENT,SESSION_INITDONE,reinterpret_cast<LPARAM>(&gce));
CallServiceSync(MS_GC_EVENT,SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
}
@@ -305,10 +298,10 @@ INT_PTR FacebookProto::OnJoinChat(WPARAM wParam,LPARAM suppress)
// TODO: load info from server + old history,...
- ptrA id( getStringA(hContact, "ChatRoomID"));
- ptrA name( getStringA(hContact, "Nick"));
+ ptrT idT( getTStringA(hContact, "ChatRoomID"));
+ ptrT nameT( getTStringA(hContact, "Nick"));
- AddChat(id, name);
+ AddChat(idT, nameT);
/* GCSESSION gcw = {sizeof(gcw)};
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 57a503d748..798d17843c 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -95,7 +95,7 @@ public:
std::map<std::string, std::string> cookies;
std::map<std::string, std::string> pages;
- std::map<std::string, facebook_chatroom> chat_rooms;
+ std::map<std::tstring, facebook_chatroom> chat_rooms;
std::string get_newsfeed_type();
std::string get_server_type();
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index a2950c07f5..432c00187f 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -66,14 +66,14 @@ bool FacebookProto::IsMyContact(HANDLE hContact, bool include_chat)
return false;
}
-HANDLE FacebookProto::ChatIDToHContact(std::string chat_id)
+HANDLE FacebookProto::ChatIDToHContact(std::tstring chat_id)
{
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (!IsMyContact(hContact, true))
continue;
- ptrA id(getStringA(hContact, "ChatRoomID"));
- if (id && !strcmp(id, chat_id.c_str()))
+ ptrT id(getTStringA(hContact, "ChatRoomID"));
+ if (id && !_tcscmp(id, chat_id.c_str()))
return hContact;
}
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 4eb4405f83..f1fc57055e 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -63,8 +63,8 @@ struct facebook_chatroom
{
HANDLE handle;
- std::string chat_name;
- std::string thread_id;
+ std::tstring chat_name;
+ std::tstring thread_id;
std::map<std::string, std::string> participants;
std::string message_readers;
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 14bcc64c25..e73320cfcf 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -361,14 +361,15 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
JSONNODE *threadid = json_get(it, "tid");
if (threadid != NULL) { // multi user chat
- std::string tid = json_as_pstring(threadid);
+ std::tstring tid = json_as_string(threadid);
std::string reader_id = json_as_pstring(reader);
- std::map<std::string, facebook_chatroom>::iterator chatroom = proto->facy.chat_rooms.find(tid);
+ std::map<std::tstring, facebook_chatroom>::iterator chatroom = proto->facy.chat_rooms.find(tid);
if (chatroom != proto->facy.chat_rooms.end()) {
std::map<std::string, std::string>::const_iterator participant = chatroom->second.participants.find(reader_id);
if (participant == chatroom->second.participants.end()) {
- std::string search = utils::url::encode(tid) + "?";
+ std::string tidA = _T2A(tid.c_str());
+ std::string search = utils::url::encode(tidA) + "?";
http::response resp = proto->facy.flap(REQUEST_USER_INFO, NULL, &search);
if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) {
@@ -454,14 +455,14 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
// Multi-user
JSONNODE *gthreadinfo = json_get(msg, "group_thread_info");
if (gthreadinfo != NULL) {
- std::string thread_id = json_as_pstring(tid);
+ std::tstring thread_id = json_as_string(tid);
// This is a recent 5 person listing of participants.
JSONNODE *participants_ids = json_get(gthreadinfo, "participant_ids");
JSONNODE *participants_names = json_get(gthreadinfo, "participant_names");
JSONNODE *thread_name_ = json_get(gthreadinfo, "name");
- std::string name = json_as_pstring(thread_name_);
+ std::tstring name = json_as_string(thread_name_);
// if there is no name for this room, set own name
if (name.empty()) {
@@ -471,16 +472,16 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
JSONNODE *nameItr = json_at(participants_names, n);
if (!name.empty())
- name += ", ";
+ name += _T(", ");
- name += json_as_pstring(nameItr);
+ name += json_as_string(nameItr);
}
JSONNODE *count_ = json_get(gthreadinfo, "participant_total_count");
unsigned int count = json_as_int(count_);
if (count > namesCount) {
- char more[200];
- mir_snprintf(more, SIZEOF(more), Translate("%s and more (%d)"), name.c_str(), count - namesCount);
+ TCHAR more[200];
+ mir_sntprintf(more, SIZEOF(more), TranslateT("%s and more (%d)"), name.c_str(), count - namesCount);
name = more;
}
}
@@ -493,7 +494,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
// Set thread id (TID) for later.
proto->AddChat(thread_id.c_str(), name.c_str());
hChatContact = proto->ChatIDToHContact(thread_id);
- proto->setString(hChatContact, FACEBOOK_KEY_TID, thread_id.c_str());
+ proto->setTString(hChatContact, FACEBOOK_KEY_TID, thread_id.c_str());
}
if (!hChatContact)
@@ -664,7 +665,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
JSONNODE *name_ = json_get(log_data_, "name");
std::string name = json_as_pstring(name_);
- std::string thread_id = json_as_pstring(thread_id_);
+ std::tstring thread_id = json_as_string(thread_id_);
std::string message = json_as_pstring(log_body_);
// proto->RenameChat(thread_id.c_str(), name.c_str()); // this don't work, why?
@@ -760,7 +761,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
JSONNODE *it = json_at(roger, i);
facebook_chatroom *room = new facebook_chatroom();
- room->thread_id = json_name(it);
+ room->thread_id = _A2T(json_name(it));
for (unsigned int j = 0; j < json_size(it); j++) {
JSONNODE *jt = json_at(it, j);
@@ -768,7 +769,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
room->participants.insert(std::make_pair(user_id, user_id)); // TODO: get name somehow
}
- chatrooms->insert(std::make_pair(room->thread_id, room));
+ chatrooms->insert(std::make_pair(_T2A(room->thread_id.c_str()), room));
}
}
@@ -782,7 +783,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
std::map<std::string, facebook_chatroom*>::iterator iter = chatrooms->find(json_as_pstring(thread_id));
if (iter != chatrooms->end()) {
- iter->second->chat_name = json_as_pstring(name); // TODO: create name from users if there is no name...
+ iter->second->chat_name = json_as_string(name); // TODO: create name from users if there is no name...
}
if (canonical == NULL || thread_id == NULL)
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index cb5abc57cb..cc75d048dd 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -76,7 +76,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
send_chat *data = static_cast<send_chat*>(p);
std::string err_message = "";
- HANDLE hContact = ChatIDToHContact(data->chat_id);
+ HANDLE hContact = ChatIDToHContact(std::tstring(_A2T(data->chat_id.c_str())));
if (hContact) {
std::string tid;
DBVARIANT dbv;
@@ -98,9 +98,9 @@ void FacebookProto::SendChatMsgWorker(void *p)
if (!tid.empty()) {
if (facy.send_message(tid, data->msg, &err_message, MESSAGE_TID))
- UpdateChat(data->chat_id.c_str(), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str());
+ UpdateChat(_A2T(data->chat_id.c_str()), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str());
else
- UpdateChat(data->chat_id.c_str(), NULL, NULL, err_message.c_str());
+ UpdateChat(_A2T(data->chat_id.c_str()), NULL, NULL, err_message.c_str());
}
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 3837a73f94..5a9ffb26f5 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -362,7 +362,7 @@ void FacebookProto::ProcessUnreadMessage(void *p)
// Set thread id (TID) for later.
AddChat(room->thread_id.c_str(), room->chat_name.c_str());
hChatContact = ChatIDToHContact(room->thread_id);
- setString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
+ setTString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end(); ) {
AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str());
@@ -373,7 +373,7 @@ void FacebookProto::ProcessUnreadMessage(void *p)
if (!hChatContact)
hChatContact = ChatIDToHContact(room->thread_id);
- setString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, room->thread_id.c_str());
+ setTString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, room->thread_id.c_str());
ForkThread(&FacebookProto::ReadMessageWorker, hChatContact);
delete it->second;
@@ -385,7 +385,7 @@ void FacebookProto::ProcessUnreadMessage(void *p)
for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) {
if (messages[i]->isChat) {
debugLogA(" Got chat message: %s", messages[i]->message_text.c_str());
- UpdateChat(messages[i]->thread_id.c_str(), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time);
+ UpdateChat(_A2T(messages[i]->thread_id.c_str()), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time);
} else if (messages[i]->user_id != facy.self_.user_id) {
debugLogA(" Got message: %s", messages[i]->message_text.c_str());
facebook_user fbu;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index a6f56fa50c..3ab2c867c0 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -187,20 +187,20 @@ public:
// Contacts handling
bool IsMyContact(HANDLE, bool include_chat = false);
HANDLE ContactIDToHContact(std::string);
- HANDLE ChatIDToHContact(std::string);
+ HANDLE ChatIDToHContact(std::tstring);
HANDLE AddToContactList(facebook_user*, ContactType type, bool dont_check = false);
void SetAllContactStatuses(int status, bool reset_client = false);
HANDLE HContactFromAuthEvent(HANDLE hEvent);
// Chats handling
- void AddChat(const char *id, const char *name);
- void UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp = 0);
+ void AddChat(const TCHAR *id, const TCHAR *name);
+ void UpdateChat(const TCHAR *chat_id, const char *id, const char *name, const char *message, DWORD timestamp = 0);
void RenameChat(const char *chat_id, const char *name);
- bool IsChatContact(const char *chat_id, const char *id);
- void AddChatContact(const char *chat_id, const char *id, const char *name);
- void RemoveChatContact(const char *chat_id, const char *id);
+ bool IsChatContact(const TCHAR *chat_id, const char *id);
+ void AddChatContact(const TCHAR *chat_id, const char *id, const char *name);
+ void RemoveChatContact(const TCHAR *chat_id, const char *id);
void SetChatStatus(const char *chat_id, int status);
- char *GetChatUsers(const char *chat_id);
+ char *GetChatUsers(const TCHAR *chat_id);
// Connection client
facebook_client facy; // TODO: Refactor to "client" and make dynamic