diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-09 15:13:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-09 15:13:13 +0300 |
commit | 017f8e72ac56a88ecaea40dd1c52b1da0ae46986 (patch) | |
tree | 63f9429a30caa5a96dc18431c225b8d8aa57d83c /src/mir_app | |
parent | 6bf18e4265c8a0938d12e98eef1562b1ee4bc97b (diff) |
common rtf management code moved to the core
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/mir_app.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/srmm_util.cpp | 74 |
3 files changed, 78 insertions, 0 deletions
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 58a81567f4..e725d21d0f 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -408,3 +408,5 @@ ProtoGetAvatarMimeType @401 ??2CSrmmBaseDialog@@SAPAXI@Z @409 NONAME
??3CSrmmBaseDialog@@SAXPAX@Z @410 NONAME
?isChat@CSrmmBaseDialog@@QBE_NXZ @411 NONAME
+Srmm_LogStreamCallback @412
+Srmm_MessageStreamCallback @413
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 4616073840..b23014f010 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -408,3 +408,5 @@ ProtoGetAvatarMimeType @401 ??2CSrmmBaseDialog@@SAPEAX_K@Z @409 NONAME
??3CSrmmBaseDialog@@SAXPEAX@Z @410 NONAME
?isChat@CSrmmBaseDialog@@QEBA_NXZ @411 NONAME
+Srmm_LogStreamCallback @412
+Srmm_MessageStreamCallback @413
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp new file mode 100644 index 0000000000..78ed59e436 --- /dev/null +++ b/src/mir_app/src/srmm_util.cpp @@ -0,0 +1,74 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-17 Miranda NG project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "chat.h" + +MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) +{ + LOGSTREAMDATA *lstrdat = (LOGSTREAMDATA*)dwCookie; + if (lstrdat) { + // create the RTF + if (lstrdat->buffer == nullptr) { + lstrdat->bufferOffset = 0; + lstrdat->buffer = chatApi.Log_CreateRTF(lstrdat); + lstrdat->bufferLen = (int)mir_strlen(lstrdat->buffer); + } + + // give the RTF to the RE control + *pcb = min(cb, LONG(lstrdat->bufferLen - lstrdat->bufferOffset)); + memcpy(pbBuff, lstrdat->buffer + lstrdat->bufferOffset, *pcb); + lstrdat->bufferOffset += *pcb; + + // free stuff if the streaming operation is complete + if (lstrdat->bufferOffset == lstrdat->bufferLen) { + mir_free(lstrdat->buffer); + lstrdat->buffer = nullptr; + } + } + + return 0; +} + +MIR_APP_DLL(DWORD) CALLBACK Srmm_MessageStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) +{ + static DWORD dwRead; + char **ppText = (char **)dwCookie; + + if (*ppText == nullptr) { + *ppText = (char *)mir_alloc(cb + 2); + memcpy(*ppText, pbBuff, cb); + *pcb = cb; + dwRead = cb; + *(*ppText + cb) = '\0'; + } + else { + char *p = (char *)mir_realloc(*ppText, dwRead + cb + 2); + memcpy(p + dwRead, pbBuff, cb); + *ppText = p; + *pcb = cb; + dwRead += cb; + *(*ppText + dwRead) = '\0'; + } + return 0; +} |