summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-04-10 18:26:49 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-04-10 18:26:49 +0000
commite372b5c98c28088a666e8f8050c0ec57e7b326de (patch)
tree5556e072c2b649f598c51404b184880f928af0f6
parent9cecda91ac7e563b14fdba9d9cd5feea3faccf69 (diff)
SkypeWeb: Fixed some bugs from coverity
git-svn-id: http://svn.miranda-ng.org/main/trunk@12751 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/SkypeWeb/src/http_request.h2
-rw-r--r--protocols/SkypeWeb/src/request_queue.cpp2
-rw-r--r--protocols/SkypeWeb/src/requests/messages.h10
-rw-r--r--protocols/SkypeWeb/src/requests/search.h2
-rw-r--r--protocols/SkypeWeb/src/skype_avatars.cpp21
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp44
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_options.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h5
-rw-r--r--protocols/SkypeWeb/src/skype_request.cpp4
-rw-r--r--protocols/SkypeWeb/src/skype_search.cpp7
11 files changed, 72 insertions, 29 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h
index d754524f55..e94eb200f3 100644
--- a/protocols/SkypeWeb/src/http_request.h
+++ b/protocols/SkypeWeb/src/http_request.h
@@ -231,7 +231,7 @@ public:
va_end(formatArgs);
}
- ~HttpRequest()
+ virtual ~HttpRequest()
{
for (int i = 0; i < headersCount; i++)
{
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp
index 258fc3d5d4..ac10e9c9c7 100644
--- a/protocols/SkypeWeb/src/request_queue.cpp
+++ b/protocols/SkypeWeb/src/request_queue.cpp
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
RequestQueue::RequestQueue(HANDLE hConnection) :
hConnection(hConnection), requests(1)
{
+ isTerminated = false;
hRequestQueueThread = NULL;
hRequestQueueEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
@@ -35,7 +36,6 @@ void RequestQueue::Start()
if (!isTerminated)
return;
- isTerminated = false;
if (hRequestQueueThread == NULL)
hRequestQueueThread = mir_forkthread((pThreadFunc)&RequestQueue::WorkerThread, this);
}
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h
index cde3abe84d..fe9361a29f 100644
--- a/protocols/SkypeWeb/src/requests/messages.h
+++ b/protocols/SkypeWeb/src/requests/messages.h
@@ -58,7 +58,7 @@ class SendTypingRequest : public HttpRequest
{
public:
SendTypingRequest(const char *regToken, const char *username, bool bstate, const char *server = SKYPE_ENDPOINTS_HOST) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, mir_urlEncode(username))
+ HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, ptrA(mir_urlEncode(username)))
{
Headers
<< CHAR_VALUE("Accept", "application/json, text/javascript")
@@ -78,7 +78,7 @@ class GetHistoryRequest : public HttpRequest
{
public:
GetHistoryRequest(const char *regToken, const char *username, LONGLONG timestamp = 0, const char *server = SKYPE_ENDPOINTS_HOST) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=%d&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, mir_urlEncode(username), timestamp)
+ HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=%d&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, ptrA(mir_urlEncode(username)), timestamp)
{
Headers
<< CHAR_VALUE("Accept", "application/json, text/javascript")
@@ -100,10 +100,4 @@ public:
}
};
-
-
-
-
-
-
#endif //_SKYPE_REQUEST_MESSAGES_H_
diff --git a/protocols/SkypeWeb/src/requests/search.h b/protocols/SkypeWeb/src/requests/search.h
index 3ef28b2b24..c31ceeec75 100644
--- a/protocols/SkypeWeb/src/requests/search.h
+++ b/protocols/SkypeWeb/src/requests/search.h
@@ -22,7 +22,7 @@ class GetSearchRequest : public HttpRequest
{
public:
GetSearchRequest(const char *token, const char *string) :
- HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/search/users/any?keyWord=%s&contactTypes[]=skype", mir_urlEncode(string))
+ HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/search/users/any?keyWord=%s&contactTypes[]=skype", ptrA(mir_urlEncode(string)))
{
Headers
<< CHAR_VALUE("Accept", "application/json")
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp
index d3282bb565..3f003b9a5e 100644
--- a/protocols/SkypeWeb/src/skype_avatars.cpp
+++ b/protocols/SkypeWeb/src/skype_avatars.cpp
@@ -172,8 +172,6 @@ INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM wParam, LPARAM lParam)
return -1;
}
- size_t length;
- char *data;
FILE *hFile = _tfopen(path, L"rb");
if (!hFile)
{
@@ -182,23 +180,30 @@ INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM wParam, LPARAM lParam)
}
fseek(hFile, 0, SEEK_END);
- length = ftell(hFile);
+ size_t length = ftell(hFile);
+ if (length == -1)
+ {
+ debugLogA("CSkypeProto::SvcSetMyAvatar: failed to get avatar file size");
+ fclose(hFile);
+ return -1;
+ }
rewind(hFile);
- data = (char*)mir_alloc(length);
- size_t read = fread(data, sizeof(char), length, hFile);
- if (read != length)
+ char *data = (char*)mir_alloc(length);
+ if (fread(data, sizeof(char), length, hFile) != length)
{
- fclose(hFile);
debugLogA("CSkypeProto::SvcSetMyAvatar: failed to read avatar file");
+ mir_free(data);
+ fclose(hFile);
return -1;
}
fclose(hFile);
-
ptrA token(getStringA("TokenSecret"));
ptrA skypename(getStringA(SKYPE_SETTINGS_ID));
PushRequest(new SetAvatarRequest(token, skypename, data, length), &CSkypeProto::OnSentAvatar);
+
+ mir_free(data);
}
else
{
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index 6662f9c786..b49dff041a 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -17,13 +17,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common.h"
-MCONTACT CSkypeProto::FindChatRoom(const char *skypename)
+void CSkypeProto::InitGroupChatModule()
+{
+ GCREGISTER gcr = { sizeof(gcr) };
+ gcr.iMaxText = 0;
+ gcr.ptszDispName = this->m_tszUserName;
+ gcr.pszModule = this->m_szModuleName;
+ CallServiceSync(MS_GC_REGISTER, 0, (LPARAM)&gcr);
+
+ //HookProtoEvent(ME_GC_EVENT, &CSkypeProto::OnGroupChatEventHook);
+ //HookProtoEvent(ME_GC_BUILDMENU, &CSkypeProto::OnGroupChatMenuHook);
+
+ //CreateProtoService(PS_JOINCHAT, &CSkypeProto::OnJoinChatRoom);
+ //CreateProtoService(PS_LEAVECHAT, &CSkypeProto::OnLeaveChatRoom);
+}
+
+void CSkypeProto::CloseAllChatChatSessions()
+{
+ GC_INFO gci = { 0 };
+ gci.Flags = GCF_BYINDEX | GCF_ID | GCF_DATA;
+ gci.pszModule = m_szModuleName;
+
+ int count = CallServiceSync(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)m_szModuleName);
+ for (int i = 0; i < count; i++)
+ {
+ gci.iItem = i;
+ if (!CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci))
+ {
+ GCDEST gcd = { m_szModuleName, gci.pszID, GC_EVENT_CONTROL };
+ GCEVENT gce = { sizeof(gce), &gcd };
+ CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, (LPARAM)&gce);
+ CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, (LPARAM)&gce);
+ }
+ }
+}
+
+MCONTACT CSkypeProto::FindChatRoom(const char *chatname)
{
MCONTACT hContact = NULL;
for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- ptrA cSkypename(getStringA(hContact, "ChatID"));
- if (mir_strcmpi(skypename, cSkypename) == 0)
+ if (!isChatRoom(hContact))
+ continue;
+
+ ptrA cChatname(getStringA(hContact, "ChatID"));
+ if (mir_strcmpi(chatname, cChatname) == 0)
break;
}
return hContact;
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index 183b390d52..15b9f1501e 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -147,7 +147,7 @@ void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
HANDLE hMessage = (HANDLE)param->hMessage;
delete param;
- if (response->resultCode != 200 && response->resultCode != 201)
+ if (response == NULL || (response->resultCode != 200 && response->resultCode != 201))
{
CMStringA error = "Unknown error";
if (response)
diff --git a/protocols/SkypeWeb/src/skype_options.cpp b/protocols/SkypeWeb/src/skype_options.cpp
index 538f914337..fdd6aff5ac 100644
--- a/protocols/SkypeWeb/src/skype_options.cpp
+++ b/protocols/SkypeWeb/src/skype_options.cpp
@@ -46,7 +46,7 @@ void CSkypeOptionsMain::OnApply()
{
m_proto->setString(SKYPE_SETTINGS_ID, m_skypename.GetTextA());
m_proto->setString("Password", m_password.GetTextA());
- TCHAR *group = m_group.GetText();
+ ptrT group(m_group.GetText());
if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group))
Clist_CreateGroup(0, group);
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index a5c8383fc6..07acb2ec1e 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -232,7 +232,10 @@ private:
void OnSyncHistory(const NETLIBHTTPREQUEST *response);
//chats
- MCONTACT FindChatRoom(const char *skypename);
+ void InitGroupChatModule();
+ void CloseAllChatChatSessions();
+
+ MCONTACT FindChatRoom(const char *chatname);
MCONTACT AddChatRoom(const char *chatname);
void SetChatStatus(MCONTACT hContact, int iStatus);
diff --git a/protocols/SkypeWeb/src/skype_request.cpp b/protocols/SkypeWeb/src/skype_request.cpp
index b9d5702f01..6f911d283e 100644
--- a/protocols/SkypeWeb/src/skype_request.cpp
+++ b/protocols/SkypeWeb/src/skype_request.cpp
@@ -29,10 +29,10 @@ private:
public:
SkypeResponseDelegate(CSkypeProto *proto, SkypeResponseCallback responseCallback)
- : proto(proto), responseCallback(responseCallback), arg(NULL), hasArg(false) {}
+ : proto(proto), responseCallback(responseCallback), responseWithArgCallback(NULL), arg(NULL), hasArg(false) {}
SkypeResponseDelegate(CSkypeProto *proto, SkypeResponseWithArgCallback responseCallback, void *arg)
- : proto(proto), responseWithArgCallback(responseCallback), arg(arg), hasArg(true) { }
+ : proto(proto), responseCallback(NULL), responseWithArgCallback(responseCallback), arg(arg), hasArg(true) { }
void Invoke(const NETLIBHTTPREQUEST *response)
{
diff --git a/protocols/SkypeWeb/src/skype_search.cpp b/protocols/SkypeWeb/src/skype_search.cpp
index 8709ab5515..9db84a6ca2 100644
--- a/protocols/SkypeWeb/src/skype_search.cpp
+++ b/protocols/SkypeWeb/src/skype_search.cpp
@@ -36,7 +36,8 @@ void CSkypeProto::SearchBasicThread(void* id)
void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response)
{
- if (response == NULL) {
+ if (response == NULL)
+ {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
@@ -48,7 +49,8 @@ void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response)
}
JSONROOT root(response->pData);
- if (root == NULL) {
+ if (root == NULL)
+ {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
@@ -69,6 +71,7 @@ void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response)
psr.nick = mir_wstrdup(sDisplayName);
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
}
+ json_free(items);
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
/*JSONROOT pRoot;