diff options
Diffstat (limited to 'plugins/Scriver')
-rw-r--r-- | plugins/Scriver/src/msgdialog.cpp | 46 | ||||
-rw-r--r-- | plugins/Scriver/src/sendqueue.cpp | 169 |
2 files changed, 99 insertions, 116 deletions
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 0149cbd1a5..084a91145f 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -1579,13 +1579,12 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP item->flags = msi->flags;
item->codepage = dat->windowData.codePage;
if ( IsUtfSendAvailable( dat->windowData.hContact )) {
- char* szMsgUtf;
- szMsgUtf = mir_utf8encodeW( (TCHAR *)&msi->sendBuffer[strlen(msi->sendBuffer) + 1] );
+ char *szMsgUtf = mir_utf8encodeW( (TCHAR *)&msi->sendBuffer[strlen(msi->sendBuffer) + 1] );
item->flags &= ~PREF_UNICODE;
if (!szMsgUtf) {
break;
}
- if (*szMsgUtf == 0) {
+ if (*szMsgUtf == 0) {
mir_free(szMsgUtf);
break;
}
@@ -1726,24 +1725,23 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break;
if (dat->windowData.hContact != NULL) {
- GETTEXTEX gt = {0};
- PARAFORMAT2 pf2;
- MessageSendQueueItem msi = { 0 };
- int bufSize;
int ansiBufSize = GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), dat->windowData.codePage, TRUE) + 1;
- bufSize = ansiBufSize;
+ int bufSize = ansiBufSize + GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, TRUE) + 2;
+
+ PARAFORMAT2 pf2;
ZeroMemory((void *)&pf2, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_RTLPARA;
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETPARAFORMAT, 0, (LPARAM)&pf2);
+
+ MessageSendQueueItem msi = { 0 };
+ msi.flags = PREF_TCHAR;
if (pf2.wEffects & PFE_RTLPARA)
msi.flags |= PREF_RTL;
- bufSize += GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, TRUE) + 2;
-
msi.sendBufferSize = bufSize;
msi.sendBuffer = (char *) mir_alloc(msi.sendBufferSize);
- msi.flags |= PREF_TCHAR;
+ GETTEXTEX gt = {0};
gt.flags = GT_USECRLF;
gt.cb = ansiBufSize;
gt.codepage = dat->windowData.codePage;
@@ -1758,20 +1756,20 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP mir_free (msi.sendBuffer);
break;
}
- {
- /* Store messaging history */
- char *msgText = GetRichTextEncoded(GetDlgItem(hwndDlg, IDC_MESSAGE), dat->windowData.codePage);
- TCmdList *cmdListNew = tcmdlist_last(dat->windowData.cmdList);
- while (cmdListNew != NULL && cmdListNew->temporary) {
- dat->windowData.cmdList = tcmdlist_remove(dat->windowData.cmdList, cmdListNew);
- cmdListNew = tcmdlist_last(dat->windowData.cmdList);
- }
- if (msgText != NULL) {
- dat->windowData.cmdList = tcmdlist_append(dat->windowData.cmdList, msgText, 20, FALSE);
- mir_free(msgText);
- }
- dat->windowData.cmdListCurrent = NULL;
+
+ /* Store messaging history */
+ char *msgText = GetRichTextEncoded(GetDlgItem(hwndDlg, IDC_MESSAGE), dat->windowData.codePage);
+ TCmdList *cmdListNew = tcmdlist_last(dat->windowData.cmdList);
+ while (cmdListNew != NULL && cmdListNew->temporary) {
+ dat->windowData.cmdList = tcmdlist_remove(dat->windowData.cmdList, cmdListNew);
+ cmdListNew = tcmdlist_last(dat->windowData.cmdList);
}
+ if (msgText != NULL) {
+ dat->windowData.cmdList = tcmdlist_append(dat->windowData.cmdList, msgText, 20, FALSE);
+ mir_free(msgText);
+ }
+ dat->windowData.cmdListCurrent = NULL;
+
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
diff --git a/plugins/Scriver/src/sendqueue.cpp b/plugins/Scriver/src/sendqueue.cpp index fda0384591..0022478912 100644 --- a/plugins/Scriver/src/sendqueue.cpp +++ b/plugins/Scriver/src/sendqueue.cpp @@ -25,44 +25,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static MessageSendQueueItem *global_sendQueue = NULL;
static CRITICAL_SECTION queueMutex;
-static char *MsgServiceName(HANDLE hContact)
-{
-
- char szServiceName[100];
- char *szProto = GetContactProto(hContact);
- if (szProto == NULL)
- return PSS_MESSAGE;
-
- mir_snprintf(szServiceName, sizeof(szServiceName), "%s%sW", szProto, PSS_MESSAGE);
- if (ServiceExists(szServiceName))
- return PSS_MESSAGE "W";
-
- return PSS_MESSAGE;
-}
-TCHAR * GetSendBufferMsg(MessageSendQueueItem *item) {
- TCHAR *szMsg = NULL;
- size_t len = strlen(item->sendBuffer);
-
- if (item->flags & PREF_UTF) {
- szMsg = mir_utf8decodeW(item->sendBuffer);
- } else {
- szMsg = (TCHAR *)mir_alloc(item->sendBufferSize - len - 1);
- memcpy(szMsg, item->sendBuffer + len + 1, item->sendBufferSize - len - 1);
- }
+TCHAR * GetSendBufferMsg(MessageSendQueueItem *item)
+{
+ TCHAR *szMsg = NULL;
+ size_t len = strlen(item->sendBuffer);
+
+ if (item->flags & PREF_UTF)
+ szMsg = mir_utf8decodeW(item->sendBuffer);
+ else {
+ szMsg = (TCHAR *)mir_alloc(item->sendBufferSize - len - 1);
+ memcpy(szMsg, item->sendBuffer + len + 1, item->sendBufferSize - len - 1);
+ }
- return szMsg;
+ return szMsg;
}
-void InitSendQueue() {
+void InitSendQueue()
+{
InitializeCriticalSection(&queueMutex);
}
-void DestroySendQueue() {
+void DestroySendQueue()
+{
DeleteCriticalSection(&queueMutex);
}
-MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender) {
+MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender)
+{
MessageSendQueueItem *item = (MessageSendQueueItem *) mir_alloc(sizeof(MessageSendQueueItem));
EnterCriticalSection(&queueMutex);
ZeroMemory(item, sizeof(MessageSendQueueItem));
@@ -76,7 +66,8 @@ MessageSendQueueItem* CreateSendQueueItem(HWND hwndSender) { return item;
}
-MessageSendQueueItem* FindOldestPendingSendQueueItem(HWND hwndSender, HANDLE hContact) {
+MessageSendQueueItem* FindOldestPendingSendQueueItem(HWND hwndSender, HANDLE hContact)
+{
MessageSendQueueItem *item, *found = NULL;
EnterCriticalSection(&queueMutex);
for (item = global_sendQueue; item != NULL; item = item->next) {
@@ -88,54 +79,49 @@ MessageSendQueueItem* FindOldestPendingSendQueueItem(HWND hwndSender, HANDLE hCo return found;
}
-MessageSendQueueItem* FindSendQueueItem(HANDLE hContact, HANDLE hSendId) {
- MessageSendQueueItem *item;
- EnterCriticalSection(&queueMutex);
- for (item = global_sendQueue; item != NULL; item = item->next) {
- if (item->hContact == hContact && item->hSendId == hSendId) {
- break;
- }
- }
- LeaveCriticalSection(&queueMutex);
- return item;
+MessageSendQueueItem* FindSendQueueItem(HANDLE hContact, HANDLE hSendId)
+{
+ mir_cslock lock(queueMutex);
+ for (MessageSendQueueItem *item = global_sendQueue; item != NULL; item = item->next)
+ if (item->hContact == hContact && item->hSendId == hSendId)
+ return item;
+
+ return NULL;
}
-BOOL RemoveSendQueueItem(MessageSendQueueItem* item) {
- BOOL result = TRUE;
+BOOL RemoveSendQueueItem(MessageSendQueueItem* item)
+{
HWND hwndSender = item->hwndSender;
-// logInfo(" removing [%s] next: [%s] prev: [%s]", item->sendBuffer, item->next != NULL ? item->next->sendBuffer : "", item->prev != NULL ? item->prev->sendBuffer : "");
- EnterCriticalSection(&queueMutex);
- if (item->prev != NULL) {
+
+ mir_cslock lock(queueMutex);
+ if (item->prev != NULL)
item->prev->next = item->next;
- } else {
+ else
global_sendQueue = item->next;
- }
- if (item->next != NULL) {
+
+ if (item->next != NULL)
item->next->prev = item->prev;
- }
- if (item->sendBuffer) {
- mir_free(item->sendBuffer);
- }
- if (item->proto) {
- mir_free(item->proto);
- }
+
+ mir_free(item->sendBuffer);
+ mir_free(item->proto);
mir_free(item);
- for (item = global_sendQueue; item != NULL; item = item->next) {
- if (item->hwndSender == hwndSender) {
- result = FALSE;
- }
- }
- LeaveCriticalSection(&queueMutex);
- return result;
+
+ for (item = global_sendQueue; item != NULL; item = item->next)
+ if (item->hwndSender == hwndSender)
+ return FALSE;
+
+ return TRUE;
}
-void ReportSendQueueTimeouts(HWND hwndSender) {
+void ReportSendQueueTimeouts(HWND hwndSender)
+{
MessageSendQueueItem *item, *item2;
int timeout = db_get_dw(NULL, SRMMMOD, SRMSGSET_MSGTIMEOUT, SRMSGDEFSET_MSGTIMEOUT);
- EnterCriticalSection(&queueMutex);
+
+ mir_cslock lock(queueMutex);
+
for (item = global_sendQueue; item != NULL; item = item2) {
item2 = item->next;
-// logInfo(" item in the queue [%s] next: [%s] prev: [%s]", item->sendBuffer, item->next != NULL ? item->next->sendBuffer : "", item->prev != NULL ? item->prev->sendBuffer : "");
if (item->timeout < timeout) {
item->timeout += 1000;
if (item->timeout >= timeout) {
@@ -156,68 +142,67 @@ void ReportSendQueueTimeouts(HWND hwndSender) { }
}
}
- LeaveCriticalSection(&queueMutex);
}
-void ReleaseSendQueueItems(HWND hwndSender) {
- MessageSendQueueItem *item;
- EnterCriticalSection(&queueMutex);
- for (item = global_sendQueue; item != NULL; item = item->next) {
+void ReleaseSendQueueItems(HWND hwndSender)
+{
+ mir_cslock lock(queueMutex);
+
+ for (MessageSendQueueItem *item = global_sendQueue; item != NULL; item = item->next) {
if (item->hwndSender == hwndSender) {
item->hwndSender = NULL;
- if (item->hwndErrorDlg != NULL) {
+ if (item->hwndErrorDlg != NULL)
DestroyWindow(item->hwndErrorDlg);
- }
+
item->hwndErrorDlg = NULL;
}
}
- LeaveCriticalSection(&queueMutex);
}
-int ReattachSendQueueItems(HWND hwndSender, HANDLE hContact) {
+int ReattachSendQueueItems(HWND hwndSender, HANDLE hContact)
+{
int count = 0;
- MessageSendQueueItem *item;
- EnterCriticalSection(&queueMutex);
- for (item = global_sendQueue; item != NULL; item = item->next) {
+
+ mir_cslock lock(queueMutex);
+
+ for (MessageSendQueueItem *item = global_sendQueue; item != NULL; item = item->next) {
if (item->hContact == hContact && item->hwndSender == NULL) {
item->hwndSender = hwndSender;
item->timeout = 0;
count++;
-// logInfo(" reattaching [%s]", item->sendBuffer);
}
}
- LeaveCriticalSection(&queueMutex);
return count;
}
-
-void RemoveAllSendQueueItems() {
+void RemoveAllSendQueueItems()
+{
MessageSendQueueItem *item, *item2;
- EnterCriticalSection(&queueMutex);
+ mir_cslock lock(queueMutex);
for (item = global_sendQueue; item != NULL; item = item2) {
item2 = item->next;
RemoveSendQueueItem(item);
}
- LeaveCriticalSection(&queueMutex);
}
-void SendSendQueueItem(MessageSendQueueItem* item) {
- EnterCriticalSection(&queueMutex);
+void SendSendQueueItem(MessageSendQueueItem* item)
+{
+ mir_cslockfull lock(queueMutex);
item->timeout = 0;
-// logInfo(" sending item [%s] next: [%s] prev: [%s]", item->sendBuffer, item->next != NULL ? item->next->sendBuffer : "", item->prev != NULL ? item->prev->sendBuffer : "");
+
if (item->prev != NULL) {
item->prev->next = item->next;
- if (item->next != NULL) {
+ if (item->next != NULL)
item->next->prev = item->prev;
- }
+
item->next = global_sendQueue;
item->prev = NULL;
- if (global_sendQueue != NULL) {
+ if (global_sendQueue != NULL)
global_sendQueue->prev = item;
- }
+
global_sendQueue = item;
}
-// logInfo(" item sent [%s] next: [%s] prev: [%s]", item->sendBuffer, item->next != NULL ? item->next->sendBuffer : "", item->prev != NULL ? item->prev->sendBuffer : "");
- LeaveCriticalSection(&queueMutex);
- item->hSendId = (HANDLE)CallContactService(item->hContact, MsgServiceName(item->hContact), item->flags, (LPARAM)item->sendBuffer);
+ lock.unlock();
+
+ item->hSendId = (HANDLE)CallContactService(item->hContact, PSS_MESSAGE, item->flags, (LPARAM)item->sendBuffer);
}
|