summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-20 10:41:27 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-20 10:41:27 +0000
commit2ffa7047ec0475856481b9e813eecb99b268d2d0 (patch)
tree0fda1b8c11a018c049b07e20059e38e1c693e266 /protocols
parent5560fccb85a89bb668a79eed3d4cd0e668278331 (diff)
protocols must return unique ids on SendMsg
git-svn-id: http://svn.miranda-ng.org/main/trunk@4481 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.cpp38
-rw-r--r--protocols/IRCG/src/ircproto.cpp114
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp127
-rw-r--r--protocols/MSN/src/msn_proto.cpp3
-rw-r--r--protocols/Tlen/src/jabber_misc.cpp3
-rw-r--r--protocols/Tlen/src/jabber_svc.cpp77
-rw-r--r--protocols/Tlen/src/jabber_thread.cpp1
-rw-r--r--protocols/Twitter/src/http.cpp2
-rw-r--r--protocols/Twitter/src/proto.cpp15
9 files changed, 192 insertions, 188 deletions
diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp
index f52f97b76c..50c1a59dee 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.cpp
+++ b/protocols/Gadu-Gadu/src/gg_proto.cpp
@@ -606,9 +606,11 @@ void __cdecl GGPROTO::sendackthread(void *ack)
int GGPROTO::SendMsg(HANDLE hContact, int flags, const char *msg)
{
- uin_t uin;
- char* msg_utf8;
+ uin_t uin = (uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0);
+ if (!isonline() || !uin)
+ return 0;
+ char* msg_utf8;
if ( flags & PREF_TCHAR )
msg_utf8 = mir_utf8encodeT( ( wchar_t* )&msg[ strlen( msg )+1 ] );
else if ( flags & PREF_UTF )
@@ -616,32 +618,28 @@ int GGPROTO::SendMsg(HANDLE hContact, int flags, const char *msg)
else
msg_utf8 = mir_utf8encode(msg);
+ if (!msg_utf8)
+ return 0;
- if (msg_utf8 && isonline() && (uin = (uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0)))
+ gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1);
+ int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg_utf8);
+ gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1);
+ if (!db_get_b(NULL, m_szModuleName, GG_KEY_MSGACK, GG_KEYDEF_MSGACK))
{
- int seq;
- gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1);
- seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg_utf8);
- gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1);
- if (!db_get_b(NULL, m_szModuleName, GG_KEY_MSGACK, GG_KEYDEF_MSGACK))
+ // Auto-ack message without waiting for server ack
+ GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK));
+ if (ack)
{
- // Auto-ack message without waiting for server ack
- GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK));
- if (ack)
- {
- ack->seq = seq;
- ack->hContact = hContact;
+ ack->seq = seq;
+ ack->hContact = hContact;
#ifdef DEBUGMODE
- netlog("SendMsg(): forkthread 16 GGPROTO::sendackthread");
+ netlog("SendMsg(): forkthread 16 GGPROTO::sendackthread");
#endif
- forkthread(&GGPROTO::sendackthread, ack);
- }
+ forkthread(&GGPROTO::sendackthread, ack);
}
- mir_free(msg_utf8);
- return seq;
}
mir_free(msg_utf8);
- return 0;
+ return seq;
}
//////////////////////////////////////////////////////////
diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp
index 7c25fbc036..10b60b0194 100644
--- a/protocols/IRCG/src/ircproto.cpp
+++ b/protocols/IRCG/src/ircproto.cpp
@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_genmenu.h>
+static volatile LONG g_msgid = 1;
+
static int CompareSessions( const CDccSession* p1, const CDccSession* p2 )
{
return INT_PTR( p1->di->hContact ) - INT_PTR( p2->di->hContact );
@@ -186,7 +188,8 @@ static int sttCheckPerform( const char *szSetting, LPARAM lParam )
if ( s != szSetting ) {
OBJLIST<String>* p = ( OBJLIST<String>* )lParam;
p->insert( new String( szSetting ));
- } }
+ }
+ }
return 0;
}
@@ -224,10 +227,8 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM )
}
if ( ServiceExists( MS_GC_REGISTER )) {
- GCREGISTER gcr = {0};
- gcr.cbSize = sizeof(GCREGISTER);
+ GCREGISTER gcr = { sizeof(GCREGISTER) };
gcr.dwFlags = GC_CHANMGR | GC_BOLD | GC_ITALICS | GC_UNDERLINE | GC_COLOR | GC_BKGCOLOR | GC_TCHAR;
- gcr.iMaxText = 0;
gcr.nColors = 16;
gcr.pColors = colors;
gcr.ptszModuleDispName = m_tszUserName;
@@ -236,11 +237,7 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM )
IrcHookEvent( ME_GC_EVENT, &CIrcProto::GCEventHook );
IrcHookEvent( ME_GC_BUILDMENU, &CIrcProto::GCMenuHook );
- GCSESSION gcw = {0};
- GCDEST gcd = {0};
- GCEVENT gce = {0};
-
- gcw.cbSize = sizeof(GCSESSION);
+ GCSESSION gcw = { sizeof(GCSESSION) };
gcw.dwFlags = GC_TCHAR;
gcw.iType = GCW_SERVER;
gcw.ptszID = SERVERWINDOW;
@@ -248,14 +245,15 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM )
gcw.ptszName = NEWTSTR_ALLOCA(( TCHAR* )_A2T( m_network ));
CallServiceSync( MS_GC_NEWSESSION, 0, (LPARAM)&gcw );
- gce.cbSize = sizeof(GCEVENT);
- gce.dwFlags = GC_TCHAR;
- gce.pDest = &gcd;
+ GCDEST gcd = { 0 };
gcd.ptszID = SERVERWINDOW;
gcd.pszModule = m_szModuleName;
gcd.iType = GC_EVENT_CONTROL;
+ GCEVENT gce = { sizeof(GCEVENT) };
+ gce.dwFlags = GC_TCHAR;
gce.pDest = &gcd;
+
if ( m_useServer && !m_hideServerWindow )
CallChatEvent( WINDOW_VISIBLE, (LPARAM)&gce);
else
@@ -294,14 +292,14 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM )
mir_free( szLoadFileName );
if ( !getByte( "PerformConversionDone", 0 )) {
- OBJLIST<String> performToConvert( 10 );
+ OBJLIST<String> performToConvert(10);
DBCONTACTENUMSETTINGS dbces;
dbces.pfnEnumProc = sttCheckPerform;
dbces.lParam = ( LPARAM )&performToConvert;
dbces.szModule = m_szModuleName;
- CallService( MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbces );
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbces);
- for ( int i = 0; i < performToConvert.getCount(); i++ ) {
+ for (int i = 0; i < performToConvert.getCount(); i++) {
String s = performToConvert[i];
DBVARIANT dbv;
if ( !getTString( s, &dbv )) {
@@ -319,7 +317,7 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM )
IrcHookEvent( ME_USERINFO_INITIALISE, &CIrcProto::OnInitUserInfo );
IrcHookEvent( ME_OPT_INITIALISE, &CIrcProto::OnInitOptionsPages );
- if ( m_nick[0] ) {
+ if (m_nick[0]) {
TCHAR szBuf[ 40 ];
if ( lstrlen( m_alternativeNick ) == 0 ) {
mir_sntprintf( szBuf, SIZEOF(szBuf), _T("%s%u"), m_nick, rand()%9999);
@@ -798,55 +796,69 @@ HANDLE __cdecl CIrcProto::SendFile( HANDLE hContact, const TCHAR*, TCHAR** ppszF
////////////////////////////////////////////////////////////////////////////////////////
// SendMessage - sends a message
-void __cdecl CIrcProto::AckMessageFail( void* info )
+struct TFakeAckParam
{
- ProtoBroadcastAck( m_szModuleName, info, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE) 1, (LPARAM)Translate("The protocol is not online"));
+ __inline TFakeAckParam(HANDLE _hContact, int _msgid) :
+ hContact(_hContact), msgid(_msgid)
+ {}
+
+ HANDLE hContact;
+ int msgid;
+};
+
+void __cdecl CIrcProto::AckMessageFail(void *info)
+{
+ ProtoBroadcastAck(m_szModuleName, info, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("The protocol is not online"));
}
-void __cdecl CIrcProto::AckMessageFailDcc( void* info )
+void __cdecl CIrcProto::AckMessageFailDcc(void *info)
{
- ProtoBroadcastAck( m_szModuleName, info, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE) 1, (LPARAM)Translate("The dcc chat connection is not active"));
+ ProtoBroadcastAck(m_szModuleName, info, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("The dcc chat connection is not active"));
}
-void __cdecl CIrcProto::AckMessageSuccess( void* info )
+void __cdecl CIrcProto::AckMessageSuccess(void *info)
{
- ProtoBroadcastAck( m_szModuleName, info, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE) 1, 0);
+ TFakeAckParam *param = (TFakeAckParam*)info;
+ ProtoBroadcastAck(m_szModuleName, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)param->msgid, 0);
+ delete param;
}
-int __cdecl CIrcProto::SendMsg( HANDLE hContact, int flags, const char* pszSrc )
+int __cdecl CIrcProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc)
{
- BYTE bDcc = getByte( hContact, "DCC", 0) ;
- WORD wStatus = getWord( hContact, "Status", ID_STATUS_OFFLINE) ;
- if ( m_iStatus != ID_STATUS_OFFLINE && m_iStatus != ID_STATUS_CONNECTING && !bDcc || bDcc && wStatus == ID_STATUS_ONLINE ) {
- int codepage = getCodepage();
-
- TCHAR* result;
- if ( flags & PREF_UNICODE ) {
- const char* p = strchr( pszSrc, '\0' );
- if ( p != pszSrc ) {
- while ( *(++p) == '\0' )
- ;
- result = mir_u2t_cp(( wchar_t* )p, codepage );
- }
- else result = mir_a2t_cp( pszSrc, codepage );
- }
- else if ( flags & PREF_UTF ) {
- mir_utf8decode( NEWSTR_ALLOCA(pszSrc), &result );
+ BYTE bDcc = getByte(hContact, "DCC", 0);
+ WORD wStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE);
+ if (bDcc && wStatus != ID_STATUS_ONLINE) {
+ ircFork(&CIrcProto::AckMessageFailDcc, hContact);
+ return 0;
+ }
+ if (!bDcc && (m_iStatus == ID_STATUS_OFFLINE || m_iStatus == ID_STATUS_CONNECTING)) {
+ ircFork(&CIrcProto::AckMessageFail, hContact);
+ return 0;
+ }
+
+ int codepage = getCodepage();
+
+ TCHAR *result;
+ if ( flags & PREF_UNICODE ) {
+ const char* p = strchr( pszSrc, '\0' );
+ if ( p != pszSrc ) {
+ while ( *(++p) == '\0' )
+ ;
+ result = mir_u2t_cp((wchar_t*)p, codepage );
}
else result = mir_a2t_cp( pszSrc, codepage );
-
- PostIrcMessageWnd(NULL, hContact, result );
- mir_free( result );
- ircFork( &CIrcProto::AckMessageSuccess, hContact );
- }
- else {
- if ( bDcc )
- ircFork( &CIrcProto::AckMessageFailDcc, hContact );
- else
- ircFork( &CIrcProto::AckMessageFail, hContact );
}
+ else if (flags & PREF_UTF)
+ mir_utf8decode(NEWSTR_ALLOCA(pszSrc), &result);
+ else
+ result = mir_a2t_cp( pszSrc, codepage );
- return 1;
+ PostIrcMessageWnd(NULL, hContact, result);
+ mir_free(result);
+
+ int seq = InterlockedIncrement(&g_msgid);
+ ircFork(&CIrcProto::AckMessageSuccess, new TFakeAckParam(hContact, seq));
+ return seq;
}
////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index b4b1e2537f..9e7f84c48d 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -1127,11 +1127,12 @@ HANDLE __cdecl CJabberProto::SendFile(HANDLE hContact, const TCHAR *szDescriptio
struct TFakeAckParams
{
- inline TFakeAckParams(HANDLE p1, const char* p2)
- : hContact(p1), msg(p2) {}
+ inline TFakeAckParams(HANDLE _hContact, const char* _msg, int _msgid = 0)
+ : hContact(_hContact), msg(_msg), msgid(_msgid) {}
HANDLE hContact;
const char *msg;
+ int msgid;
};
void __cdecl CJabberProto::SendMessageAckThread(void* param)
@@ -1141,7 +1142,7 @@ void __cdecl CJabberProto::SendMessageAckThread(void* param)
Log("Broadcast ACK");
JSendBroadcast(par->hContact, ACKTYPE_MESSAGE,
par->msg ? ACKRESULT_FAILED : ACKRESULT_SUCCESS,
- (HANDLE)1, (LPARAM) par->msg);
+ (HANDLE)par->msgid, (LPARAM) par->msg);
Log("Returning from thread");
delete par;
}
@@ -1151,17 +1152,15 @@ static char PGP_EPILOG[] = "\r\n-----END PGP MESSAGE-----\r\n";
int __cdecl CJabberProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc)
{
- int id;
-
- DBVARIANT dbv;
- if ( !m_bJabberOnline || JGetStringT(hContact, "jid", &dbv)) {
+ mir_ptr<TCHAR> ptszJid( db_get_tsa(hContact, m_szModuleName, "jid"));
+ if ( !m_bJabberOnline || ptszJid == NULL) {
TFakeAckParams *param = new TFakeAckParams(hContact, Translate("Protocol is offline or no jid"));
JForkThread(&CJabberProto::SendMessageAckThread, param);
return 1;
}
TCHAR *msg;
- int isEncrypted;
+ int isEncrypted, id = SerialNext();
if ( !strncmp(pszSrc, PGP_PROLOG, strlen(PGP_PROLOG))) {
const char* szEnd = strstr(pszSrc, PGP_EPILOG);
@@ -1182,79 +1181,73 @@ int __cdecl CJabberProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc
else
msg = mir_a2t(pszSrc);
- int nSentMsgId = 0;
-
- if (msg != NULL) {
- TCHAR *msgType;
- if (ListExist(LIST_CHATROOM, dbv.ptszVal) && _tcschr(dbv.ptszVal, '/') == NULL)
- msgType = _T("groupchat");
- else
- msgType = _T("chat");
+ if (msg == NULL)
+ return 0;
- XmlNode m(_T("message")); xmlAddAttr(m, _T("type"), msgType);
- if ( !isEncrypted)
- m << XCHILD(_T("body"), msg);
- else {
- m << XCHILD(_T("body"), _T("[This message is encrypted.]"));
- m << XCHILD(_T("x"), msg) << XATTR(_T("xmlns"), _T("jabber:x:encrypted"));
- }
- mir_free(msg);
+ TCHAR *msgType;
+ if (ListExist(LIST_CHATROOM, ptszJid) && _tcschr(ptszJid, '/') == NULL)
+ msgType = _T("groupchat");
+ else
+ msgType = _T("chat");
- TCHAR szClientJid[ JABBER_MAX_JID_LEN ];
- GetClientJID(dbv.ptszVal, szClientJid, SIZEOF(szClientJid));
+ XmlNode m(_T("message")); xmlAddAttr(m, _T("type"), msgType);
+ if ( !isEncrypted)
+ m << XCHILD(_T("body"), msg);
+ else {
+ m << XCHILD(_T("body"), _T("[This message is encrypted.]"));
+ m << XCHILD(_T("x"), msg) << XATTR(_T("xmlns"), _T("jabber:x:encrypted"));
+ }
+ mir_free(msg);
- JABBER_RESOURCE_STATUS *r = ResourceInfoFromJID(szClientJid);
- if (r)
- r->bMessageSessionActive = TRUE;
+ TCHAR szClientJid[ JABBER_MAX_JID_LEN ];
+ GetClientJID(ptszJid, szClientJid, SIZEOF(szClientJid));
- JabberCapsBits jcb = GetResourceCapabilites(szClientJid, TRUE);
+ JABBER_RESOURCE_STATUS *r = ResourceInfoFromJID(szClientJid);
+ if (r)
+ r->bMessageSessionActive = TRUE;
- if (jcb & JABBER_RESOURCE_CAPS_ERROR)
- jcb = JABBER_RESOURCE_CAPS_NONE;
+ JabberCapsBits jcb = GetResourceCapabilites(szClientJid, TRUE);
- if (jcb & JABBER_CAPS_CHATSTATES)
- m << XCHILDNS(_T("active"), _T(JABBER_FEAT_CHATSTATES));
-
- if (
- // if message delivery check disabled by entity caps manager
- (jcb & JABBER_CAPS_MESSAGE_EVENTS_NO_DELIVERY) ||
- // if client knows nothing about delivery
- !(jcb & (JABBER_CAPS_MESSAGE_EVENTS | JABBER_CAPS_MESSAGE_RECEIPTS)) ||
- // if message sent to groupchat
- !lstrcmp(msgType, _T("groupchat")) ||
- // if message delivery check disabled in settings
- !m_options.MsgAck || !JGetByte(hContact, "MsgAck", TRUE)) {
- if ( !lstrcmp(msgType, _T("groupchat")))
- xmlAddAttr(m, _T("to"), dbv.ptszVal);
- else {
- id = SerialNext();
- xmlAddAttr(m, _T("to"), szClientJid); xmlAddAttrID(m, id);
- }
- m_ThreadInfo->send(m);
+ if (jcb & JABBER_RESOURCE_CAPS_ERROR)
+ jcb = JABBER_RESOURCE_CAPS_NONE;
- JForkThread(&CJabberProto::SendMessageAckThread, new TFakeAckParams(hContact, 0));
+ if (jcb & JABBER_CAPS_CHATSTATES)
+ m << XCHILDNS(_T("active"), _T(JABBER_FEAT_CHATSTATES));
- nSentMsgId = 1;
- }
+ if (
+ // if message delivery check disabled by entity caps manager
+ (jcb & JABBER_CAPS_MESSAGE_EVENTS_NO_DELIVERY) ||
+ // if client knows nothing about delivery
+ !(jcb & (JABBER_CAPS_MESSAGE_EVENTS | JABBER_CAPS_MESSAGE_RECEIPTS)) ||
+ // if message sent to groupchat
+ !lstrcmp(msgType, _T("groupchat")) ||
+ // if message delivery check disabled in settings
+ !m_options.MsgAck || !JGetByte(hContact, "MsgAck", TRUE))
+ {
+ if ( !lstrcmp(msgType, _T("groupchat")))
+ xmlAddAttr(m, _T("to"), (TCHAR*)ptszJid);
else {
id = SerialNext();
xmlAddAttr(m, _T("to"), szClientJid); xmlAddAttrID(m, id);
+ }
+ m_ThreadInfo->send(m);
- // message receipts XEP priority
- if (jcb & JABBER_CAPS_MESSAGE_RECEIPTS)
- m << XCHILDNS(_T("request"), _T(JABBER_FEAT_MESSAGE_RECEIPTS));
- else if (jcb & JABBER_CAPS_MESSAGE_EVENTS) {
- HXML x = m << XCHILDNS(_T("x"), _T(JABBER_FEAT_MESSAGE_EVENTS));
- x << XCHILD(_T("delivered")); x << XCHILD(_T("offline"));
- }
- else id = 1;
+ JForkThread(&CJabberProto::SendMessageAckThread, new TFakeAckParams(hContact, 0, id));
+ }
+ else {
+ xmlAddAttr(m, _T("to"), szClientJid); xmlAddAttrID(m, id);
- m_ThreadInfo->send(m);
- nSentMsgId = id;
- } }
+ // message receipts XEP priority
+ if (jcb & JABBER_CAPS_MESSAGE_RECEIPTS)
+ m << XCHILDNS(_T("request"), _T(JABBER_FEAT_MESSAGE_RECEIPTS));
+ else if (jcb & JABBER_CAPS_MESSAGE_EVENTS) {
+ HXML x = m << XCHILDNS(_T("x"), _T(JABBER_FEAT_MESSAGE_EVENTS));
+ x << XCHILD(_T("delivered")); x << XCHILD(_T("offline"));
+ }
- db_free(&dbv);
- return nSentMsgId;
+ m_ThreadInfo->send(m);
+ }
+ return id;
}
////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp
index e2b1cf2763..509084481d 100644
--- a/protocols/MSN/src/msn_proto.cpp
+++ b/protocols/MSN/src/msn_proto.cpp
@@ -907,8 +907,7 @@ int __cdecl CMsnProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc)
int seq = 0;
int netId = Lists_GetNetId(tEmail);
- switch (netId)
- {
+ switch (netId) {
case NETID_MOB:
if (strlen(msg) > 133)
{
diff --git a/protocols/Tlen/src/jabber_misc.cpp b/protocols/Tlen/src/jabber_misc.cpp
index 73ac847836..631a6d7e99 100644
--- a/protocols/Tlen/src/jabber_misc.cpp
+++ b/protocols/Tlen/src/jabber_misc.cpp
@@ -86,13 +86,12 @@ char *JabberJIDFromHContact(TlenProtocol *proto, HANDLE hContact)
HANDLE JabberHContactFromJID(TlenProtocol *proto, const char *jid)
{
DBVARIANT dbv;
- char *szProto;
char *p;
if (jid == NULL)
return NULL;
for (HANDLE hContact = db_find_first(proto->m_szModuleName); hContact; hContact = db_find_next(hContact, proto->m_szModuleName)) {
- if ( db_get(hContact, proto->m_szModuleName, "jid", &dbv))
+ if ( db_get_s(hContact, proto->m_szModuleName, "jid", &dbv))
continue;
if ((p=dbv.pszVal) != NULL) {
diff --git a/protocols/Tlen/src/jabber_svc.cpp b/protocols/Tlen/src/jabber_svc.cpp
index 8a505ac471..79a804cf52 100644
--- a/protocols/Tlen/src/jabber_svc.cpp
+++ b/protocols/Tlen/src/jabber_svc.cpp
@@ -39,7 +39,6 @@ extern int TlenPreShutdown(void *ptr, WPARAM wParam, LPARAM lParam);
extern int TlenSystemModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam);
extern int TlenPrebuildContactMenu(void *ptr, WPARAM wParam, LPARAM lParam);
-
DWORD_PTR __cdecl TlenProtocol::GetCaps(int type, HANDLE hContact)
{
if (type == PFLAGNUM_1)
@@ -545,25 +544,33 @@ int __cdecl TlenProtocol::SetApparentMode(HANDLE hContact, int mode)
return 0;
}
-typedef struct{
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct SENDACKTHREADDATA
+{
+ __inline SENDACKTHREADDATA(TlenProtocol *_ppro, HANDLE _hContact, int _msgid=0) :
+ proto(_ppro), hContact(_hContact), msgid(_msgid)
+ {}
+
TlenProtocol *proto;
HANDLE hContact;
-} SENDACKTHREADDATA;
+ int msgid;
+};
static void __cdecl JabberSendMessageAckThread(void *ptr)
{
SENDACKTHREADDATA *data = (SENDACKTHREADDATA *)ptr;
SleepEx(10, TRUE);
- ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE) 1, 0);
- mir_free(data);
+ ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0);
+ delete data;
}
static void __cdecl TlenSendMessageFailedThread(void *ptr)
{
SENDACKTHREADDATA *data = (SENDACKTHREADDATA *)ptr;
SleepEx(10, TRUE);
- ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE) 2, 0);
- mir_free(data);
+ ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, 0);
+ delete data;
}
static void __cdecl TlenGetAwayMsgThread(void *ptr)
@@ -575,16 +582,14 @@ static void __cdecl TlenGetAwayMsgThread(void *ptr)
if ((item=JabberListGetItemPtr(data->proto, LIST_ROSTER, dbv.pszVal)) != NULL) {
db_free(&dbv);
if (item->statusMessage != NULL) {
- ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE) 1, (LPARAM) item->statusMessage);
+ ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)data->msgid, (LPARAM) item->statusMessage);
return;
}
}
- else {
- db_free(&dbv);
- }
+ else db_free(&dbv);
}
ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE) 1, (LPARAM) "");
- mir_free(data);
+ delete data;
}
INT_PTR TlenSendAlert(void *ptr, LPARAM wParam, LPARAM lParam)
@@ -605,54 +610,46 @@ int __cdecl TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msg)
DBVARIANT dbv;
char *msgEnc;
JABBER_LIST_ITEM *item;
- int id;
char msgType[16];
if (!isOnline || db_get(hContact, m_szModuleName, "jid", &dbv)) {
- SENDACKTHREADDATA *tdata = (SENDACKTHREADDATA*) mir_alloc(sizeof(SENDACKTHREADDATA));
- tdata->proto = this;
- tdata->hContact = hContact;
- JabberForkThread(TlenSendMessageFailedThread, 0, (void *) tdata);
+ JabberForkThread(TlenSendMessageFailedThread, 0, new SENDACKTHREADDATA(this, hContact, 2));
return 2;
}
+
+ int id = JabberSerialNext(this);
+
if (!strcmp(msg, "<alert>")) {
- SENDACKTHREADDATA *tdata = (SENDACKTHREADDATA*) mir_alloc(sizeof(SENDACKTHREADDATA));
- tdata->proto = this;
- tdata->hContact = hContact;
JabberSend(this, "<m tp='a' to='%s'/>", dbv.pszVal);
- JabberForkThread(JabberSendMessageAckThread, 0, (void *) tdata);
- } else if (!strcmp(msg, "<image>")) {
- SENDACKTHREADDATA *tdata = (SENDACKTHREADDATA*) mir_alloc(sizeof(SENDACKTHREADDATA));
- tdata->proto = this;
- tdata->hContact = hContact;
- id = JabberSerialNext(this);
+ JabberForkThread(JabberSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
+ }
+ else if (!strcmp(msg, "<image>")) {
JabberSend(this, "<message to='%s' type='%s' crc='%x' idt='%d'/>", dbv.pszVal, "pic", 0x757f044, id);
- JabberForkThread(JabberSendMessageAckThread, 0, (void *) tdata);
- } else {
+ JabberForkThread(JabberSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
+ }
+ else {
if ((msgEnc=JabberTextEncode(msg)) != NULL) {
- if (JabberListExist(this, LIST_CHATROOM, dbv.pszVal) && strchr(dbv.pszVal, '/') == NULL) {
+ if (JabberListExist(this, LIST_CHATROOM, dbv.pszVal) && strchr(dbv.pszVal, '/') == NULL)
strcpy(msgType, "groupchat");
- } else if (db_get_b(hContact, m_szModuleName, "bChat", FALSE)) {
+ else if (db_get_b(hContact, m_szModuleName, "bChat", FALSE))
strcpy(msgType, "privchat");
- } else {
+ else
strcpy(msgType, "chat");
- }
+
if (!strcmp(msgType, "groupchat") || db_get_b(NULL, m_szModuleName, "MsgAck", FALSE) == FALSE) {
SENDACKTHREADDATA *tdata = (SENDACKTHREADDATA*) mir_alloc(sizeof(SENDACKTHREADDATA));
tdata->proto = this;
tdata->hContact = hContact;
- if (!strcmp(msgType, "groupchat")) {
+ if (!strcmp(msgType, "groupchat"))
JabberSend(this, "<message to='%s' type='%s'><body>%s</body></message>", dbv.pszVal, msgType, msgEnc);
- } else if (!strcmp(msgType, "privchat")) {
+ else if (!strcmp(msgType, "privchat"))
JabberSend(this, "<m to='%s'><b n='6' s='10' f='0' c='000000'>%s</b></m>", dbv.pszVal, msgEnc);
- } else {
- id = JabberSerialNext(this);
+ else
JabberSend(this, "<message to='%s' type='%s' id='"JABBER_IQID"%d'><body>%s</body><x xmlns='jabber:x:event'><composing/></x></message>", dbv.pszVal, msgType, id, msgEnc);
- }
- JabberForkThread(JabberSendMessageAckThread, 0, (void *) tdata);
+
+ JabberForkThread(JabberSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
}
else {
- id = JabberSerialNext(this);
if ((item=JabberListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL)
item->idMsgAckPending = id;
JabberSend(this, "<message to='%s' type='%s' id='"JABBER_IQID"%d'><body>%s</body><x xmlns='jabber:x:event'><offline/><delivered/><composing/></x></message>", dbv.pszVal, msgType, id, msgEnc);
@@ -661,7 +658,7 @@ int __cdecl TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msg)
mir_free(msgEnc);
}
db_free(&dbv);
- return 1;
+ return id;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Tlen/src/jabber_thread.cpp b/protocols/Tlen/src/jabber_thread.cpp
index 0cc09e86c4..fa3022279a 100644
--- a/protocols/Tlen/src/jabber_thread.cpp
+++ b/protocols/Tlen/src/jabber_thread.cpp
@@ -112,7 +112,6 @@ void __cdecl JabberServerThread(ThreadData *info)
int reconnectMaxTime;
int numRetry;
int reconnectTime;
- char *str;
int loginErr = 0;
JabberLog(info->proto, "Thread started");
diff --git a/protocols/Twitter/src/http.cpp b/protocols/Twitter/src/http.cpp
index 912219dfaf..71069d08a4 100644
--- a/protocols/Twitter/src/http.cpp
+++ b/protocols/Twitter/src/http.cpp
@@ -23,5 +23,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string http::url_encode(const std::string &s)
{
- return mir_ptr<char>( mir_urlEncode( s.c_str()));
+ return (char*)mir_ptr<char>( mir_urlEncode( s.c_str()));
}
diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp
index 03b2538910..5a1aa801f6 100644
--- a/protocols/Twitter/src/proto.cpp
+++ b/protocols/Twitter/src/proto.cpp
@@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <ctime>
#include <direct.h>
+static volatile LONG g_msgid = 1;
+
TwitterProto::TwitterProto(const char *proto_name,const TCHAR *username)
{
ProtoConstructor(this, proto_name, username);
@@ -129,9 +131,13 @@ int TwitterProto::RecvMsg(HANDLE hContact,PROTORECVEVENT *pre)
struct send_direct
{
- send_direct(HANDLE hContact,const std::string &msg) : hContact(hContact),msg(msg) {}
+ __inline send_direct(HANDLE _hContact, const std::string &_msg, int _msgid) :
+ hContact(_hContact), msg(_msg), msgid(_msgid)
+ {}
+
HANDLE hContact;
std::string msg;
+ int msgid;
};
void TwitterProto::SendSuccess(void *p)
@@ -146,7 +152,7 @@ void TwitterProto::SendSuccess(void *p)
ScopedLock s(twitter_lock_);
twit_.send_direct(dbv.pszVal,data->msg);
- ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_SUCCESS,(HANDLE)1,0);
+ ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_SUCCESS,(HANDLE)data->msgid,0);
db_free(&dbv);
}
@@ -166,8 +172,9 @@ int TwitterProto::SendMsg(HANDLE hContact,int flags,const char *msg)
else
tszMsg = mir_a2t( msg );
- ForkThread(&TwitterProto::SendSuccess, this,new send_direct(hContact,msg));
- return 1;
+ int seq = InterlockedIncrement(&g_msgid);
+ ForkThread(&TwitterProto::SendSuccess, this,new send_direct(hContact, msg, seq));
+ return seq;
}
// *************************