From 2bf60b8c681e1a72fddfc1490b154b8ffd4389c9 Mon Sep 17 00:00:00 2001
From: MikalaiR <nikolay.romanovich@narod.ru>
Date: Sat, 8 Aug 2015 08:43:36 +0000
Subject: SkypeWeb: cslock for append message; optimization

git-svn-id: http://svn.miranda-ng.org/main/trunk@14858 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 protocols/SkypeWeb/src/skype_contacts.cpp | 19 ++-------
 protocols/SkypeWeb/src/skype_db.cpp       |  1 +
 protocols/SkypeWeb/src/skype_proto.h      |  1 +
 protocols/SkypeWeb/src/skype_utils.h      | 68 +++++++++++++++++++++++++++++++
 protocols/SkypeWeb/src/stdafx.h           |  1 +
 5 files changed, 75 insertions(+), 15 deletions(-)
 create mode 100644 protocols/SkypeWeb/src/skype_utils.h

(limited to 'protocols')

diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp
index 56e0ef62d9..05df715501 100644
--- a/protocols/SkypeWeb/src/skype_contacts.cpp
+++ b/protocols/SkypeWeb/src/skype_contacts.cpp
@@ -140,23 +140,12 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response)
 				db_set_dw(hContact, m_szModuleName, "LastAuthRequestTime", eventTime);
 				delSetting(hContact, "Auth");
 
+				DB_AUTH_BLOB blob(hContact, NULL, NULL, NULL, skypename.c_str(), reason.c_str());
+
 				PROTORECVEVENT pre = { 0 };
 				pre.timestamp = time(NULL);
-				pre.lParam = (DWORD)(sizeof(DWORD) * 2 + skypename.size() + reason.size() + 5);
-
-				/*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
-				PBYTE pBlob, pCurBlob;
-				pCurBlob = pBlob = (PBYTE)mir_calloc(pre.lParam);
-
-				*((PDWORD)pCurBlob) = 0;
-				pCurBlob += sizeof(DWORD);
-				*((PDWORD)pCurBlob) = (DWORD)hContact;
-				pCurBlob += sizeof(DWORD);
-				pCurBlob += 3;
-				mir_strcpy((char*)pCurBlob, skypename.c_str());
-				pCurBlob += skypename.size() + 1;
-				mir_strcpy((char*)pCurBlob, reason.c_str());
-				pre.szMessage = (char*)pBlob;
+				pre.lParam = blob.size();
+				pre.szMessage = blob;
 
 				ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
 			}
diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp
index 9e0f04a25a..bc5a6d138c 100644
--- a/protocols/SkypeWeb/src/skype_db.cpp
+++ b/protocols/SkypeWeb/src/skype_db.cpp
@@ -65,6 +65,7 @@ MEVENT CSkypeProto::AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DW
 
 MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time)
 {
+	mir_cslock lck(m_AppendMessageLock);
 	DBEVENTINFO dbei = { sizeof(dbei) };
 	dbei.cbBlob = db_event_getBlobSize(hEvent);	
 	dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 9b28810db1..ac07cb4eea 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -118,6 +118,7 @@ private:
 	mir_cs m_GCCreateDialogsLock;
 	mir_cs messageSyncLock;
 	mir_cs m_StatusLock;
+	mir_cs m_AppendMessageLock;
 	static mir_cs accountsLock;
 	static mir_cs timerLock;
 	
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h
new file mode 100644
index 0000000000..6f79be2655
--- /dev/null
+++ b/protocols/SkypeWeb/src/skype_utils.h
@@ -0,0 +1,68 @@
+/*
+Copyright (c) 2015 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _UTILS_H_
+#define _UTILS_H_
+
+class DB_AUTH_BLOB
+{
+	MCONTACT hContact;
+	ptrA szNick, szFirstName, szLastName, szId, szReason;
+
+	PBYTE makeBlob()
+	{
+		size_t size = this->size();
+
+		/*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
+		PBYTE pBlob, pCurBlob;
+		pCurBlob = pBlob = (PBYTE)mir_calloc(size);
+
+		*((PDWORD)pCurBlob) = 0;
+		pCurBlob += sizeof(DWORD);
+		*((PDWORD)pCurBlob) = (DWORD)hContact;
+		pCurBlob += sizeof(DWORD);
+		
+		if (szNick){ mir_strcpy((char*)pCurBlob, szNick); pCurBlob += mir_strlen(szNick); }
+		pCurBlob += 1;
+		
+		if (szFirstName){ mir_strcpy((char*)pCurBlob, szFirstName); pCurBlob += mir_strlen(szFirstName); }
+		pCurBlob += 1;
+		
+		if (szLastName){ mir_strcpy((char*)pCurBlob, szLastName); pCurBlob += mir_strlen(szLastName); }
+		pCurBlob += 1;
+		
+		if (szId){ mir_strcpy((char*)pCurBlob, szId); pCurBlob += mir_strlen(szId); }
+		pCurBlob += 1;
+		
+		if (szReason){ mir_strcpy((char*)pCurBlob, szReason); pCurBlob += mir_strlen(szReason); }
+		pCurBlob += 1;
+		
+		return pBlob;
+	}
+
+public:
+	__inline explicit DB_AUTH_BLOB(MCONTACT _hContact, LPCSTR nick, LPCSTR fname, LPCSTR lname, LPCSTR id, LPCSTR reason) 
+		: hContact(_hContact), szNick(mir_strdup(nick)), szFirstName(mir_strdup(fname)), szLastName(mir_strdup(lname)), szId(mir_strdup(id)), szReason(mir_strdup(reason)) {}
+
+	__inline size_t size(){ return ((sizeof(DWORD) * 2) + (mir_strlen(szNick) + 1) + (mir_strlen(szFirstName) + 1) + (mir_strlen(szLastName) + 1) + (mir_strlen(szId) + 1) + (mir_strlen(szReason) + 1)); }
+
+	__inline operator char*(){ return (char*)makeBlob(); };
+	__inline operator BYTE*(){ return makeBlob(); };
+};
+
+
+#endif //_UTILS_H_
\ No newline at end of file
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index 1cfea038db..0e8440203b 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -68,6 +68,7 @@ extern char g_szMirVer[];
 #include "skype_options.h"
 #include "skype_trouter.h"
 #include "skype_db.h"
+#include "skype_utils.h"
 #include "http_request.h"
 #include "requests\login.h"
 #include "requests\profile.h"
-- 
cgit v1.2.3