diff options
author | Robert Pösel <robyer@seznam.cz> | 2013-09-29 14:44:04 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2013-09-29 14:44:04 +0000 |
commit | d09782a435ae4a9229b853e53e603d4c621df3a3 (patch) | |
tree | 25acbd0e49c8d901bd00b9b9bf44a84e6c1257e1 | |
parent | b728069180bcea77894d344753a7fdfc4f30a061 (diff) |
Facebook: cleanup using ptrA, ptrT
git-svn-id: http://svn.miranda-ng.org/main/trunk@6270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 89 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 31 |
4 files changed, 49 insertions, 80 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index bd7ad7d553..cbb52248ac 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -24,34 +24,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void FacebookProto::UpdateChat(const char *chat_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 = mir_a2t(chat_id);
+ gcd.ptszID = tchat_id;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
- gce.ptszText = mir_a2t_cp(message,CP_UTF8);
+ gce.ptszText = ttext;
gce.time = timestamp ? timestamp : ::time(NULL);
gce.dwFlags = GC_TCHAR;
gcd.iType = GC_EVENT_MESSAGE;
gce.bIsMe = !strcmp(id,facy.self_.user_id.c_str());
gce.dwFlags |= GCEF_ADDTOLOG;
- gce.ptszNick = mir_a2t_cp(name,CP_UTF8);
- gce.ptszUID = mir_a2t(id);
+ gce.ptszNick = tnick;
+ gce.ptszUID = tid;
CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
-
- mir_free(const_cast<TCHAR*>(gce.ptszUID));
- mir_free(const_cast<TCHAR*>(gce.ptszNick));
- mir_free(const_cast<TCHAR*>(gce.ptszText));
- mir_free(const_cast<TCHAR*>(gcd.ptszID));
}
int FacebookProto::OnChatOutgoing(WPARAM wParam,LPARAM lParam)
{
GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
- char *text;
- char *id;
if (strcmp(hook->pDest->pszModule,m_szModuleName))
return 0;
@@ -60,17 +58,11 @@ int FacebookProto::OnChatOutgoing(WPARAM wParam,LPARAM lParam) {
case GC_USER_MESSAGE:
{
- text = mir_t2a_cp(hook->ptszText,CP_UTF8);
- std::string msg = text;
+ std::string msg = ptrA( mir_t2a_cp(hook->ptszText,CP_UTF8));
+ std::string chat_id = ptrA( mir_t2a_cp(hook->pDest->ptszID,CP_UTF8));
- id = mir_t2a_cp(hook->pDest->ptszID,CP_UTF8);
- std::string chat_id = id;
-
- mir_free(text);
- mir_free(id);
-
if (isOnline()) {
- LOG("**Chat - Outgoing message: %s", text);
+ LOG("**Chat - Outgoing message: %s", msg.c_str());
ForkThread(&FacebookProto::SendChatMsgWorker, new send_chat(chat_id, msg));
}
@@ -89,15 +81,19 @@ int FacebookProto::OnChatOutgoing(WPARAM wParam,LPARAM lParam) void FacebookProto::AddChatContact(const char *chat_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 = mir_a2t(chat_id);
+ gcd.ptszID = tchat_id;
gcd.iType = GC_EVENT_JOIN;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
- gce.ptszNick = mir_a2t_cp(name, CP_UTF8);
- gce.ptszUID = mir_a2t(id);
+ gce.ptszNick = tnick;
+ gce.ptszUID = tid;
gce.time = ::time(NULL);
gce.bIsMe = !strcmp(id, facy.self_.user_id.c_str());
@@ -107,10 +103,6 @@ void FacebookProto::AddChatContact(const char *chat_id, const char *id, const ch gce.ptszStatus = _T("Normal");
CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
-
- mir_free(const_cast<TCHAR*>(gce.ptszNick));
- mir_free(const_cast<TCHAR*>(gce.ptszUID));
- mir_free(const_cast<TCHAR*>(gcd.ptszID));
}
@@ -119,73 +111,66 @@ void FacebookProto::RemoveChatContact(const char *chat_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 = mir_a2t(chat_id);
+ gcd.ptszID = tchat_id;
gcd.iType = GC_EVENT_PART;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
//gce.ptszNick = mir_a2t_cp(name, CP_UTF8);
- gce.ptszUID = mir_a2t(id);
- gce.ptszNick = gce.ptszUID;
+ gce.ptszUID = tid;
+ gce.ptszNick = tid;
gce.time = ::time(NULL);
gce.bIsMe = false;//!strcmp(id, facy.self_.user_id.c_str());
CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
-
- mir_free(const_cast<TCHAR*>(gcd.ptszID));
- mir_free(const_cast<TCHAR*>(gce.ptszNick));
- mir_free(const_cast<TCHAR*>(gce.ptszUID));
}
+/** Caller must free result */
char *FacebookProto::GetChatUsers(const char *chat_id)
{
+ ptrT tid( mir_a2t(chat_id));
GC_INFO gci = {0};
gci.Flags = USERS;
gci.pszModule = m_szModuleName;
- gci.pszID = mir_a2t(chat_id);
+ gci.pszID = tid;
CallService(MS_GC_GETINFO, 0, (LPARAM)(GC_INFO *) &gci);
LOG("**Chat - Users in chat %s: %s", chat_id, gci.pszUsers);
- mir_free(gci.pszID);
-
// mir_free(gci.pszUsers);
return gci.pszUsers;
}
bool FacebookProto::IsChatContact(const char *chat_id, const char *id)
{
- char *users = GetChatUsers(chat_id);
- bool found = false;
-
- if (users != NULL && strstr(users, id) != NULL)
- found = true;
-
- mir_free(users);
- return found;
+ ptrA users( GetChatUsers(chat_id));
+ return (users != NULL && strstr(users, id) != NULL);
}
void FacebookProto::AddChat(const char *id, const char *name)
{
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;
gcw.pszModule = m_szModuleName;
- gcw.ptszName = mir_a2t_cp(name, CP_UTF8);
- gcw.ptszID = mir_a2t(id);
+ gcw.ptszName = tname;
+ gcw.ptszID = tid;
CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw);
- mir_free(const_cast<TCHAR*>(gcw.ptszName));
- mir_free(const_cast<TCHAR*>(gcw.ptszID));
-
// Send setting events
GCDEST gcd = { m_szModuleName };
- gcd.ptszID = mir_a2t(id);
+ gcd.ptszID = tid;
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
@@ -207,8 +192,6 @@ void FacebookProto::AddChat(const char *id, const char *name) AddChatContact(id, 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));
-
- mir_free(const_cast<TCHAR*>(gcd.ptszID));
}
/*void FacebookProto::SetTopic(const char *topic)
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 45e1bc0267..be1e6232ab 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -511,11 +511,9 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa proto->Log(" Got multichat message");
- TCHAR* szTitle = mir_utf8decodeT(title.c_str());
- TCHAR* szText = mir_utf8decodeT(popup_text.c_str());
+ ptrT szTitle( mir_utf8decodeT(title.c_str()));
+ ptrT szText( mir_utf8decodeT(popup_text.c_str()));
proto->NotifyEvent(szTitle, szText, NULL, FACEBOOK_EVENT_OTHER, &url);
- mir_free(szTitle);
- mir_free(szText);
} else if (t == "notification_json") {
// event notification
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 7c36767524..604ca2d2ee 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -210,7 +210,7 @@ void FacebookProto::ParseSmileys(std::string message, HANDLE hContact) } else {
facy.save_url(url, filename, nlc);
}
- TCHAR *path = _tcsdup(filename.c_str());
+ ptrT path( _tcsdup(filename.c_str()));
SMADD_CONT cont;
cont.cbSize = sizeof(SMADD_CONT);
@@ -219,7 +219,6 @@ void FacebookProto::ParseSmileys(std::string message, HANDLE hContact) cont.path = path;
CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
- mir_free(path);
}
Netlib_CloseHandle(nlc);
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 8b72f2e11d..74180a8358 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -116,9 +116,8 @@ void FacebookProto::ProcessBuddyList(void* data) std::string url = FACEBOOK_URL_PROFILE + fbu->user_id;
- TCHAR* szTitle = mir_utf8decodeT(fbu->real_name.c_str());
+ ptrT szTitle( mir_utf8decodeT(fbu->real_name.c_str()));
NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), fbu->handle, FACEBOOK_EVENT_OTHER, &url);
- mir_free(szTitle);
}
// Check avatar change
@@ -209,9 +208,8 @@ void FacebookProto::ProcessFriendList(void* data) std::string url = FACEBOOK_URL_PROFILE + fbu->user_id;
- TCHAR* szTitle = mir_utf8decodeT(fbu->real_name.c_str());
+ ptrT szTitle( mir_utf8decodeT(fbu->real_name.c_str()));
NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), hContact, FACEBOOK_EVENT_OTHER, &url);
- mir_free(szTitle);
}
// Check avatar change
@@ -235,9 +233,8 @@ void FacebookProto::ProcessFriendList(void* data) std::string url = FACEBOOK_URL_PROFILE + id;
- TCHAR* szTitle = mir_utf8decodeT(contactname.c_str());
+ ptrT szTitle( mir_utf8decodeT(contactname.c_str()));
NotifyEvent(szTitle, TranslateT("Contact is no longer on server-list."), hContact, FACEBOOK_EVENT_OTHER, &url);
- mir_free(szTitle);
}
}
}
@@ -481,12 +478,9 @@ void FacebookProto::ProcessMessages(void* data) for(std::vector<facebook_notification*>::size_type i=0; i<notifications.size(); i++)
{
LOG(" Got notification: %s", notifications[i]->text.c_str());
- TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName);
- TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str());
+ ptrT szTitle( mir_utf8decodeT(this->m_szModuleName));
+ ptrT szText( mir_utf8decodeT(notifications[i]->text.c_str()));
NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link, ¬ifications[i]->id);
- mir_free(szTitle);
- mir_free(szText);
-
delete notifications[i];
}
notifications.clear();
@@ -539,12 +533,9 @@ void FacebookProto::ProcessNotifications(void*) for(std::vector<facebook_notification*>::size_type i=0; i<notifications.size(); i++)
{
LOG(" Got notification: %s", notifications[i]->text.c_str());
- TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName);
- TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str());
+ ptrT szTitle( mir_utf8decodeT(this->m_szModuleName));
+ ptrT szText( mir_utf8decodeT(notifications[i]->text.c_str()));
NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link, ¬ifications[i]->id);
- mir_free(szTitle);
- mir_free(szText);
-
delete notifications[i];
}
notifications.clear();
@@ -733,11 +724,9 @@ void FacebookProto::ProcessFeeds(void* data) for(std::vector<facebook_newsfeed*>::size_type i=0; i<news.size(); i++)
{
LOG(" Got newsfeed: %s %s", news[i]->title.c_str(), news[i]->text.c_str());
- TCHAR* szTitle = mir_utf8decodeT(news[i]->title.c_str());
- TCHAR* szText = mir_utf8decodeT(news[i]->text.c_str());
+ ptrT szTitle( mir_utf8decodeT(news[i]->title.c_str()));
+ ptrT szText( mir_utf8decodeT(news[i]->text.c_str()));
NotifyEvent(szTitle,szText,this->ContactIDToHContact(news[i]->user_id),FACEBOOK_EVENT_NEWSFEED, &news[i]->link);
- mir_free(szTitle);
- mir_free(szText);
delete news[i];
}
news.clear();
@@ -886,7 +875,7 @@ void FacebookProto::SearchIdAckThread(void *targ) PROTOSEARCHRESULT isr = {0};
isr.cbSize = sizeof(isr);
isr.flags = PSR_TCHAR;
- isr.id = tid;
+ isr.id = tid;
isr.firstName = tname;
isr.lastName = tsurname;
|