Exemplo n.º 1
0
void WhatsAppProto::onGroupMessageReceived(const FMessage &msg)
{
	WAChatInfo *pInfo = SafeGetChat(msg.key.remote_jid);
	if (pInfo == NULL)
		return;
	
	auto p = pInfo->m_unsentMsgs.find(msg.key.id);
	if (p == pInfo->m_unsentMsgs.end())
		return;

	ptrT tszUID(str2t(m_szJid));
	ptrT tszNick(str2t(m_szNick));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = time(NULL);
	gce.ptszText = p->second.c_str();
	gce.bIsMe = m_szJid == msg.remote_resource;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);

	pInfo->m_unsentMsgs.erase(p);
}
Exemplo n.º 2
0
void __cdecl CJabberProto::OnRenameGroup(DBCONTACTWRITESETTING *cws, HANDLE hContact)
{
	JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, ptrT(getTStringA(hContact, "jid")));
	if (item == NULL)
		return;

	ptrT tszNick(db_get_tsa(hContact, "CList", "MyHandle"));
	if (tszNick == NULL)
		tszNick = getTStringA(hContact, "Nick");
	if (tszNick == NULL)
		tszNick = JabberNickFromJID(item->jid);
	if (tszNick == NULL)
		return;

	if (cws->value.type == DBVT_DELETED) {
		if (item->group != NULL) {
			debugLogA("Group set to nothing");
			AddContactToRoster(item->jid, tszNick, NULL);
		}
	}
	else {
		TCHAR *p = sttSettingToTchar(cws);
		if (cws->value.pszVal != NULL && lstrcmp(p, item->group)) {
			debugLogA("Group set to %S", p);
			if (p)
				AddContactToRoster(item->jid, tszNick, p);
		}
		mir_free(p);
	}
}
Exemplo n.º 3
0
void WhatsAppProto::onGroupNewSubject(const std::string &gjid, const std::string &author, const std::string &newSubject, int ts)
{
	WAChatInfo *pInfo = SafeGetChat(gjid);
	if (pInfo == NULL)
		return;

	ptrT tszText(str2t(newSubject));
	ptrT tszTextDb(getTStringA(pInfo->hContact, WHATSAPP_KEY_NICK));
	if (!mir_tstrcmp(tszText, tszTextDb)) // notify about subject change only if differs from the stored one
		return;

	ptrT tszUID(str2t(author));
	ptrT tszNick(GetChatUserNick(author));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_TOPIC };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG + ((ts == 0) ? GCEF_NOTNOTIFY : 0);
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = ts;
	gce.ptszText = tszText;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);

	setTString(pInfo->hContact, WHATSAPP_KEY_NICK, tszText);
}
Exemplo n.º 4
0
void ProtocolArray::GetDefaultNick()
{
	ptrT tszNick(db_get_tsa(0, MODULE_NAME, SETTING_DEFAULT_NICK));
	if (tszNick)
		mir_tstrncpy(default_nick, tszNick, _countof(default_nick));
	else
		default_nick[0] = '\0';
}
Exemplo n.º 5
0
void ProtocolArray::GetDefaultNick()
{
	ptrT tszNick(db_get_tsa(0, MODULE_NAME, SETTING_DEFAULT_NICK));
	if (tszNick)
		_tcsncpy_s(default_nick, SIZEOF(default_nick), tszNick, _TRUNCATE);
	else
		default_nick[0] = '\0';
}
Exemplo n.º 6
0
void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNode &jnResponse)
{
	debugLogA("CVkProto::CreateVkUserInfoList");
	if (!jnResponse)
		return;
	
	const JSONNode &jnProfiles = jnResponse["profiles"];
	
	if (!jnProfiles.isnull())
		for (auto it = jnProfiles.begin(); it != jnProfiles.end(); ++it) {
			const JSONNode &jnProfile = (*it);
			if (!jnProfile["id"])
				continue;
			LONG UserId =  jnProfile["id"].as_int();		

			CMString tszNick(jnProfile["first_name"].as_mstring());
			tszNick.AppendChar(' ');
			tszNick += jnProfile["last_name"].as_mstring();
			CMString tszLink = _T("https://vk.com/");
			CMString tszScreenName(jnProfile["screen_name"].as_mstring());
			if (tszScreenName.IsEmpty())
				tszScreenName.AppendFormat(_T("id%d"), UserId);
			tszLink += tszScreenName;
			CVkUserInfo * vkUser = new CVkUserInfo(UserId, false, tszNick, tszLink, FindUser(UserId));
			vkUsers.insert(vkUser);
		}
	
	const JSONNode &jnGroups = jnResponse["groups"];
	if (!jnGroups.isnull())		
		for (auto it = jnGroups.begin(); it != jnGroups.end(); ++it) {
			const JSONNode &jnProfile = (*it);
			if (!jnProfile["id"])
				continue;
			LONG UserId = - jnProfile["id"].as_int();

			CMString tszNick(jnProfile["name"].as_mstring());
			CMString tszLink = _T("https://vk.com/");
			tszLink += jnProfile["screen_name"].as_mstring();
			CVkUserInfo * vkUser = new CVkUserInfo(UserId, true, tszNick, tszLink);
			vkUsers.insert(vkUser);
		}
}
Exemplo n.º 7
0
void WhatsAppProto::onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts)
{
	WAChatInfo *pInfo = SafeGetChat(gjid);
	if (pInfo == NULL)
		return;

	ptrT tszUID(str2t(ujid));
	ptrT tszNick(GetChatUserNick(ujid));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_PART };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = ts;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
}
Exemplo n.º 8
0
INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
{
	debugLogA("CVkProto::SvcReportAbuse");
	LONG userID = getDword(hContact, "ID", -1);
	if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
		return 1;

	CMString tszNick(ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"))),
		ptszMsg(FORMAT, TranslateT("Are you sure to report abuse on %s?"), tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
	if (IDNO == MessageBox(NULL, ptszMsg, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
		return 1;

	Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.report.json", true, &CVkProto::OnReceiveSmth)
		<< INT_PARAM("user_id", userID)
		<< CHAR_PARAM("type", "spam")
		<< VER_API);

	return 0;
}
Exemplo n.º 9
0
void CVkProto::OnReceiveDeleteFriend(NETLIBHTTPREQUEST* reply, AsyncHttpRequest* pReq)
{
	debugLogA("CVkProto::OnReceiveDeleteFriend %d", reply->resultCode);
	CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
	if (reply->resultCode == 200 && param) {
		JSONNode jnRoot;
		const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
		if (jnResponse) {
			CMString tszNick(ptrT(db_get_tsa(param->hContact, m_szModuleName, "Nick")));
			if (tszNick.IsEmpty())
				tszNick = TranslateT("(Unknown contact)");
			CMString msgformat, msg;

			if (jnResponse["success"].as_bool()) {
				if (jnResponse["friend_deleted"].as_bool())
					msgformat = TranslateT("User %s was deleted from your friend list");
				else if (jnResponse["out_request_deleted"].as_bool())
					msgformat = TranslateT("Your request to the user %s was deleted");
				else if (jnResponse["in_request_deleted"].as_bool())
					msgformat = TranslateT("Friend request from the user %s declined");
				else if (jnResponse["suggestion_deleted"].as_bool())
					msgformat = TranslateT("Friend request suggestion for the user %s deleted");

				msg.AppendFormat(msgformat, tszNick);
				MsgPopup(param->hContact, msg, tszNick);
				setByte(param->hContact, "Auth", 1);
			}
			else {
				msg = TranslateT("User or request was not deleted");
				MsgPopup(param->hContact, msg, tszNick);
			}
		}
	}

	if (param && (!pReq->bNeedsRestart || m_bTerminated)) {
		delete param;
		pReq->pUserInfo = NULL;
	}
}
Exemplo n.º 10
0
void CVkProto::OnReceiveAuthRequest(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveAuthRequest %d", reply->resultCode);
	CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
	if (reply->resultCode == 200 && param) {
		JSONNode jnRoot;
		const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
		if (jnResponse) {
			int iRet = jnResponse.as_int();
			setByte(param->hContact, "Auth", 0);
			if (iRet == 2) {
				CMString msg,			
					tszNick(ptrT(db_get_tsa(param->hContact, m_szModuleName, "Nick")));
				if (tszNick.IsEmpty())
					tszNick = TranslateT("(Unknown contact)");
				msg.AppendFormat(TranslateT("User %s added as friend"), tszNick);
				MsgPopup(param->hContact, msg, tszNick);
			}
		} 
		else {
			switch (pReq->m_iErrorCode) {
			case VKERR_HIMSELF_AS_FRIEND:
				MsgPopup(param->hContact, TranslateT("You cannot add yourself as friend"), TranslateT("Error"), true);
				break;
			case VKERR_YOU_ON_BLACKLIST:
				MsgPopup(param->hContact, TranslateT("Cannot add this user to friends as they have put you on their blacklist"), TranslateT("Error"), true);
				break;
			case VKERR_USER_ON_BLACKLIST:
				MsgPopup(param->hContact, TranslateT("Cannot add this user to friends as you put him on blacklist"), TranslateT("Error"), true);
				break;
			}
		}
	}

	if (param && (!pReq->bNeedsRestart || m_bTerminated)) {
		delete param;
		pReq->pUserInfo = NULL;
	}
}
Exemplo n.º 11
0
void WhatsAppProto::onGroupMessage(const FMessage &pMsg)
{
	// we need to add a contact, so there's no difference at all
	if (pMsg.media_wa_type == FMessage::WA_TYPE_CONTACT) {
		onMessageForMe(pMsg);
		return;
	}

	WAChatInfo *pInfo = SafeGetChat(pMsg.key.remote_jid);
	if (pInfo == NULL) {
		pInfo = InitChat(pMsg.key.remote_jid, "");
		pInfo->bActive = true;
	}

	std::string msg(pMsg.data);
	if (!pMsg.media_url.empty()) {
		if (!msg.empty())
			msg.append("\n");
		msg += pMsg.media_url;
	}

	ptrT tszText(str2t(msg));
	ptrT tszUID(str2t(pMsg.remote_resource));
	ptrT tszNick(GetChatUserNick(pMsg.remote_resource));

	GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE };

	GCEVENT gce = { sizeof(gce), &gcd };
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = tszUID;
	gce.ptszNick = tszNick;
	gce.time = pMsg.timestamp;
	gce.ptszText = tszText;
	gce.bIsMe = m_szJid == pMsg.remote_resource;
	CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);

	if (isOnline())
		m_pConnection->sendMessageReceived(pMsg);
}
Exemplo n.º 12
0
BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo)
{
	HXML queryNode = pInfo->GetChildNode();

	// RFC 3921 #7.2 Business Rules
	if (pInfo->GetFrom()) {
		TCHAR *szFrom = JabberPrepareJid(pInfo->GetFrom());
		if (!szFrom)
			return TRUE;

		TCHAR *szTo = JabberPrepareJid(m_ThreadInfo->fullJID);
		if (!szTo) {
			mir_free(szFrom);
			return TRUE;
		}

		TCHAR *pDelimiter = _tcschr(szFrom, _T('/'));
		if (pDelimiter) *pDelimiter = 0;

		pDelimiter = _tcschr(szTo, _T('/'));
		if (pDelimiter) *pDelimiter = 0;

		BOOL bRetVal = mir_tstrcmp(szFrom, szTo) == 0;

		mir_free(szFrom);
		mir_free(szTo);

		// invalid JID
		if (!bRetVal) {
			debugLog(_T("<iq/> attempt to hack via roster push from %s"), pInfo->GetFrom());
			return TRUE;
		}
	}

	JABBER_LIST_ITEM *item;
	MCONTACT hContact = NULL;
	const TCHAR *jid, *str;

	debugLogA("<iq/> Got roster push, query has %d children", XmlGetChildCount(queryNode));
	for (int i = 0;; i++) {
		HXML itemNode = XmlGetChild(queryNode, i);
		if (!itemNode)
			break;

		if (mir_tstrcmp(XmlGetName(itemNode), _T("item")) != 0)
			continue;
		if ((jid = XmlGetAttrValue(itemNode, _T("jid"))) == NULL)
			continue;
		if ((str = XmlGetAttrValue(itemNode, _T("subscription"))) == NULL)
			continue;

		// we will not add new account when subscription=remove
		if (!mir_tstrcmp(str, _T("to")) || !mir_tstrcmp(str, _T("both")) || !mir_tstrcmp(str, _T("from")) || !mir_tstrcmp(str, _T("none"))) {
			const TCHAR *name = XmlGetAttrValue(itemNode, _T("name"));
			ptrT nick((name != NULL) ? mir_tstrdup(name) : JabberNickFromJID(jid));
			if (nick != NULL) {
				if ((item = ListAdd(LIST_ROSTER, jid)) != NULL) {
					replaceStrT(item->nick, nick);

					HXML groupNode = XmlGetChild(itemNode, "group");
					replaceStrT(item->group, XmlGetText(groupNode));

					if ((hContact = HContactFromJID(jid, 0)) == NULL) {
						// Received roster has a new JID.
						// Add the jid (with empty resource) to Miranda contact list.
						hContact = DBCreateContact(jid, nick, FALSE, FALSE);
					}
					else setTString(hContact, "jid", jid);

					if (name != NULL) {
						ptrT tszNick(getTStringA(hContact, "Nick"));
						if (tszNick != NULL) {
							if (mir_tstrcmp(nick, tszNick) != 0)
								db_set_ts(hContact, "CList", "MyHandle", nick);
							else
								db_unset(hContact, "CList", "MyHandle");
						}
						else db_set_ts(hContact, "CList", "MyHandle", nick);
					}
					else db_unset(hContact, "CList", "MyHandle");

					if (!m_options.IgnoreRosterGroups) {
						if (item->group != NULL) {
							Clist_CreateGroup(0, item->group);
							db_set_ts(hContact, "CList", "Group", item->group);
						}
						else db_unset(hContact, "CList", "Group");
					}
				}
			}
		}

		if ((item = ListGetItemPtr(LIST_ROSTER, jid)) != NULL) {
			if (!mir_tstrcmp(str, _T("both"))) item->subscription = SUB_BOTH;
			else if (!mir_tstrcmp(str, _T("to"))) item->subscription = SUB_TO;
			else if (!mir_tstrcmp(str, _T("from"))) item->subscription = SUB_FROM;
			else item->subscription = SUB_NONE;
			debugLog(_T("Roster push for jid=%s, set subscription to %s"), jid, str);
			// subscription = remove is to remove from roster list
			// but we will just set the contact to offline and not actually
			// remove, so that history will be retained.
			if (!mir_tstrcmp(str, _T("remove"))) {
				if ((hContact = HContactFromJID(jid)) != NULL) {
					SetContactOfflineStatus(hContact);
					ListRemove(LIST_ROSTER, jid);
				}
			}
			else if (isChatRoom(hContact))
				db_unset(hContact, "CList", "Hidden");
			else
				UpdateSubscriptionInfo(hContact, item);
		}
	}

	UI_SAFE_NOTIFY(m_pDlgServiceDiscovery, WM_JABBER_TRANSPORT_REFRESH);
	RebuildInfoFrame();
	return TRUE;
}
Exemplo n.º 13
0
void CJabberDlgGcJoin::OnInitDialog()
{
	CSuper::OnInitDialog();

	Window_SetIcon_IcoLib(m_hwnd, g_GetIconHandle(IDI_GROUP));

	JabberGcRecentInfo *pInfo = NULL;
	if (m_jid)
		pInfo = new JabberGcRecentInfo(m_proto, m_jid);
	else if (OpenClipboard(m_hwnd)) {
		HANDLE hData = GetClipboardData(CF_UNICODETEXT);

		if (hData) {
			TCHAR *buf = (TCHAR *)GlobalLock(hData);
			if (buf && _tcschr(buf, _T('@')) && !_tcschr(buf, _T(' ')))
				pInfo = new JabberGcRecentInfo(m_proto, buf);
			GlobalUnlock(hData);
		}
		CloseClipboard();
	}

	if (pInfo) {
		pInfo->fillForm(m_hwnd);
		delete pInfo;
	}

	ptrT tszNick(m_proto->getTStringA("Nick"));
	if (tszNick == NULL)
		tszNick = JabberNickFromJID(m_proto->m_szJabberJID);
	SetDlgItemText(m_hwnd, IDC_NICK, tszNick);

	TEXTMETRIC tm = { 0 };
	HDC hdc = GetDC(m_hwnd);
	GetTextMetrics(hdc, &tm);
	ReleaseDC(m_hwnd, hdc);
	sttTextLineHeight = tm.tmHeight;
	SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_SETITEMHEIGHT, -1, sttTextLineHeight - 1);

	LOGFONT lf = { 0 };
	HFONT hfnt = (HFONT)SendDlgItemMessage(m_hwnd, IDC_TXT_RECENT, WM_GETFONT, 0, 0);
	GetObject(hfnt, sizeof(lf), &lf);
	lf.lfWeight = FW_BOLD;
	SendDlgItemMessage(m_hwnd, IDC_TXT_RECENT, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), TRUE);

	SendDlgItemMessage(m_hwnd, IDC_BOOKMARKS, BM_SETIMAGE, IMAGE_ICON, (LPARAM)m_proto->LoadIconEx("bookmarks"));
	SendDlgItemMessage(m_hwnd, IDC_BOOKMARKS, BUTTONSETASFLATBTN, TRUE, 0);
	SendDlgItemMessage(m_hwnd, IDC_BOOKMARKS, BUTTONADDTOOLTIP, (WPARAM)"Bookmarks", 0);
	SendDlgItemMessage(m_hwnd, IDC_BOOKMARKS, BUTTONSETASPUSHBTN, TRUE, 0);

	m_proto->ComboLoadRecentStrings(m_hwnd, IDC_SERVER, "joinWnd_rcSvr");

	int i;
	for (i = 0; i < 5; i++) {
		TCHAR jid[JABBER_MAX_JID_LEN];
		JabberGcRecentInfo info(m_proto);
		if (!info.loadRecent(i))
			break;

		mir_sntprintf(jid, _T("%s@%s (%s)"), info.m_room, info.m_server, info.m_nick ? info.m_nick : TranslateT("<no nick>"));
		SetDlgItemText(m_hwnd, IDC_RECENT1 + i, jid);
	}
	sttJoinDlgShowRecentItems(m_hwnd, i);
}
Exemplo n.º 14
0
static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
{
	DBEVENTGETTEXT* egt = (DBEVENTGETTEXT*)lParam;
	if (egt == NULL)
		return 0;

	DBEVENTINFO *dbei = egt->dbei;

	DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType);
	if (et && ServiceExists(et->textService))
		return CallService(et->textService, wParam, lParam);

	if (!dbei->pBlob)
		return 0;

	if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) {
		// EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
		// EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
		DWORD  uin = *(DWORD*)dbei->pBlob;
		HANDLE hContact = (HANDLE)*(DWORD*)(dbei->pBlob + sizeof(DWORD));
		char  *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2;
		ptrT tszNick(getEventString(dbei, buf));
		ptrT tszFirst(getEventString(dbei, buf));
		ptrT tszLast(getEventString(dbei, buf));
		ptrT tszEmail(getEventString(dbei, buf));

		CMString nick, text;
		if (tszFirst || tszLast) {
			nick.AppendFormat(_T("%s %s"), tszFirst, tszLast);
			nick.Trim();
		}
		if (tszEmail) {
			if (!nick.IsEmpty())
				nick.Append(_T(", "));
			nick.Append(tszEmail);
		}
		if (uin != 0) {
			if (!nick.IsEmpty())
				nick.Append(_T(", "));
			nick.AppendFormat(_T("%d"), uin);
		}
		if (!nick.IsEmpty())
			nick = _T("(") + nick + _T(")");

		if (dbei->eventType == EVENTTYPE_AUTHREQUEST) {
			ptrT tszReason(getEventString(dbei, buf));
			text.Format(TranslateT("Authorization request from %s%s: %s"),
				(*tszNick == 0) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason);
		}
		else text.Format(TranslateT("You were added by %s%s"),
			(*tszNick == 0) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick);
		return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text);
	}

	if (dbei->eventType == EVENTTYPE_CONTACTS) {
		CMString text(TranslateT("Contacts: "));
		// blob is: [uin(ASCIIZ), nick(ASCIIZ)]*
		char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob;
		while (buf < limit) {
			ptrT tszUin(getEventString(dbei, buf));
			ptrT tszNick(getEventString(dbei, buf));
			if (tszNick && *tszNick)
				text.AppendFormat(_T("\"%s\" "), tszNick);
			if (tszUin && *tszUin)
				text.AppendFormat(_T("<%s>; "), tszUin);
		}
		return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text);
	}

	if (dbei->eventType == EVENTTYPE_FILE) {
		char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD);
		ptrT tszFileName(getEventString(dbei, buf));
		ptrT tszDescription(getEventString(dbei, buf));
		ptrT &ptszText = (lstrlen(tszDescription) == 0) ? tszFileName : tszDescription;
		switch (egt->datatype) {
		case DBVT_WCHAR:
			return (INT_PTR)ptszText.detouch();
		case DBVT_ASCIIZ:
			return (INT_PTR)mir_t2a(ptszText);
		}
		return 0;
	}

	// by default treat an event's blob as a string
	if (egt->datatype == DBVT_WCHAR) {
		char *str = (char*)alloca(dbei->cbBlob + 1);
		memcpy(str, dbei->pBlob, dbei->cbBlob);
		str[dbei->cbBlob] = 0;

		if (dbei->flags & DBEF_UTF) {
			WCHAR *msg = NULL;
			Utf8DecodeCP(str, egt->codepage, &msg);
			if (msg)
				return (INT_PTR)msg;
		}

		return (INT_PTR)mir_a2t_cp(str, egt->codepage);
	}

	if (egt->datatype == DBVT_ASCIIZ) {
		char *msg = mir_strdup((char*)dbei->pBlob);
		if (dbei->flags & DBEF_UTF)
			Utf8DecodeCP(msg, egt->codepage, NULL);

		return (INT_PTR)msg;
	}
	return 0;
}
Exemplo n.º 15
0
int Cache_GetLineText(ClcCacheEntry *pdnce, int type, LPTSTR text, int text_size, ClcLineInfo &line)
{
	if (text == nullptr)
		return TEXT_EMPTY;
	text[0] = '\0';

	switch (type) {
	case TEXT_STATUS:
LBL_Status:
		if (GetStatusName(text, text_size, pdnce, line.xstatus_has_priority) == -1 && line.use_name_and_message_for_xstatus) {
			// Try to get XStatusMsg
			ptrW tszXStatusMsg(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusMsg"));
			if (tszXStatusMsg != nullptr && tszXStatusMsg[0] != 0) {
				wchar_t *tmp = NEWWSTR_ALLOCA(text);
				mir_snwprintf(text, text_size, L"%s: %s", tmp, tszXStatusMsg);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		return TEXT_STATUS;

	case TEXT_NICKNAME:
		if (pdnce->hContact && pdnce->szProto) {
			ptrW tszNick(db_get_wsa(pdnce->hContact, pdnce->szProto, "Nick"));
			if (tszNick != nullptr) {
				mir_wstrncpy(text, tszNick, text_size);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		return TEXT_NICKNAME;

	case TEXT_STATUS_MESSAGE:
		if (GetStatusMessage(text, text_size, pdnce, line.xstatus_has_priority) == -1 && line.use_name_and_message_for_xstatus) {
			// Try to get XStatusName
			ptrW tszXStatusName(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusName"));
			if (tszXStatusName != nullptr && tszXStatusName[0] != 0) {
				wchar_t *tmp = NEWWSTR_ALLOCA(text);
				mir_snwprintf(text, text_size, L"%s: %s", tszXStatusName, tmp);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		else if (line.use_name_and_message_for_xstatus && line.xstatus_has_priority) {
			// Try to get XStatusName
			ptrW tszXStatusName(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusName"));
			if (tszXStatusName != nullptr && tszXStatusName[0] != 0) {
				mir_wstrncpy(text, tszXStatusName, text_size);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}

		if (text[0] == '\0') {
			if (line.show_listening_if_no_away) {
				GetListeningTo(text, text_size, pdnce);
				if (text[0] != '\0')
					return TEXT_LISTENING_TO;
			}

			if (line.show_status_if_no_away) // re-request status if no away
				goto LBL_Status;
		}
		return TEXT_STATUS_MESSAGE;

	case TEXT_LISTENING_TO:
		GetListeningTo(text, text_size, pdnce);
		return TEXT_LISTENING_TO;

	case TEXT_TEXT:
		{
			ptrW tmp(variables_parsedup(line.text, pdnce->tszName, pdnce->hContact));
			mir_wstrncpy(text, tmp, text_size);
			CopySkipUnprintableChars(text, text, text_size - 1);
		}
		return TEXT_TEXT;

	case TEXT_CONTACT_TIME:
		if (pdnce->hTimeZone) {
			// Get pdnce time
			text[0] = 0;
			TimeZone_PrintDateTime(pdnce->hTimeZone, L"t", text, text_size, 0);
		}
		return TEXT_CONTACT_TIME;
	}

	return TEXT_EMPTY;
}