summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_message_handlers.cpp
blob: eb00c11636a75d508438cbb22ddf01d2039a1930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*

Jabber Protocol Plugin for Miranda NG

Copyright (c) 2002-04  Santithorn Bunchua
Copyright (c) 2005-08  George Hazan
Copyright (c) 2007     Maxim Mluhov
Copyright (c) 2008-09  Dmitriy Chervov
Copyright (C) 2012-20 Miranda NG team

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"

bool CJabberProto::OnMessageError(const TiXmlElement *node, ThreadData*, CJabberMessageInfo* pInfo)
{
	// we check if is message delivery failure
	int id = JabberGetPacketID(node);
	JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, pInfo->GetFrom());
	if (item == nullptr)
		item = ListGetItemPtr(LIST_CHATROOM, pInfo->GetFrom());
	if (item != nullptr) { // yes, it is
		CMStringW szErrText(JabberErrorMsg(pInfo->GetChildNode()));
		if (id != -1)
			ProtoBroadcastAck(pInfo->GetHContact(), ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)id, (LPARAM)szErrText.c_str());
		else {
			wchar_t buf[512];
			auto *body = XmlGetChildText(node, "body");
			if (body)
				mir_snwprintf(buf, L"%s:\n%s\n%s", pInfo->GetFrom(), body, szErrText.c_str());
			else
				mir_snwprintf(buf, L"%s:\n%s", pInfo->GetFrom(), szErrText.c_str());

			MsgPopup(0, buf, TranslateT("Error"));
		}
	}
	return true;
}

bool CJabberProto::OnMessageIbb(const TiXmlElement*, ThreadData*, CJabberMessageInfo* pInfo)
{
	bool bOk = false;
	const char *sid = XmlGetAttr(pInfo->GetChildNode(), "sid");
	const char *seq = XmlGetAttr(pInfo->GetChildNode(), "seq");
	if (sid && seq && pInfo->GetChildNode()->GetText())
		bOk = OnIbbRecvdData(pInfo->GetChildNode()->GetText(), sid, seq);

	return true;
}

bool CJabberProto::OnMessagePubsubEvent(const TiXmlElement *node, ThreadData*, CJabberMessageInfo*)
{
	OnProcessPubsubEvent(node);
	return true;
}

bool CJabberProto::OnMessageGroupchat(const TiXmlElement *node, ThreadData*, CJabberMessageInfo* pInfo)
{
	JABBER_LIST_ITEM *chatItem = ListGetItemPtr(LIST_CHATROOM, pInfo->GetFrom());
	if (chatItem) // process GC message
		GroupchatProcessMessage(node);
	
	// got message from unknown conference... let's leave it :)
	else { 
//			wchar_t *conference = NEWWSTR_ALLOCA(from);
//			if (wchar_t *s = wcschr(conference, '/')) *s = 0;
//			XmlNode p("presence"); XmlAddAttr(p, "to", conference); XmlAddAttr(p, "type", "unavailable");
//			info->send(p);
	}
	return true;
}