Exemplo n.º 1
0
int CYahooProto::Authorize( HANDLE hdbe )
{
	debugLogA("[YahooAuthAllow]");
	if ( !m_bLoggedIn ) {
		debugLogA("[YahooAuthAllow] Not Logged In!");
		return 1;
	}

	DBEVENTINFO dbei = { sizeof(dbei) };
	if (( dbei.cbBlob = db_event_getBlobSize(hdbe)) == -1 )
		return 1;

	dbei.pBlob = ( PBYTE )_alloca( dbei.cbBlob );
	if (db_event_get(hdbe, &dbei))
		return 1;

	if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
		return 1;

	if ( strcmp(dbei.szModule, m_szModuleName))
		return 1;

	/* Need to remove the buddy from our Miranda Lists */
	MCONTACT hContact = DbGetAuthEventContact(&dbei);
	if (hContact != NULL) {
		ptrA who( getStringA(hContact, YAHOO_LOGINID));
		if (who) {
			ptrA myid( getStringA(hContact, "MyIdentity"));
			debugLogA("Accepting buddy:%s", who);
			accept(myid, who, getWord(hContact, "yprotoid", 0));
		}
	}

	return 0;
}
Exemplo n.º 2
0
MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, hContact, hDbEvent)
{
	DBEVENTINFO dbei = { sizeof(dbei) };
	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	if (dbei.cbBlob == -1)
		return 0;

	dbei.pBlob = (BYTE*)alloca(dbei.cbBlob);
	db_event_get(hDbEvent, &dbei);

	// if event is in protocol that is not despammed
	if (!ProtoInList(dbei.szModule))
		return 0;

	// event is an auth request
	if (gbHandleAuthReq) {
		if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
			MCONTACT hcntct = DbGetAuthEventContact(&dbei);

			// if request is from unknown or not marked Answered contact
			int a = db_get_b(hcntct, "CList", "NotOnList", 0);
			int b = !db_get_b(hcntct, pluginName, "Answered", 0);

			if (a && b) {
				// ...send message

				if (gbHideContacts)
					db_set_b(hcntct, "CList", "Hidden", 1);
				if (gbSpecialGroup)
					db_set_ws(hcntct, "CList", "Group", gbSpammersGroup.c_str());
				BYTE msg = 1;
				if (gbIgnoreURL) {
					TCHAR* EventText = ReqGetText(&dbei); //else return NULL
					msg = !IsUrlContains(EventText);
					mir_free(EventText);
				}
				if (gbInvisDisable) {
					if (CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
						msg = 0;
					else if (db_get_w(hContact, dbei.szModule, "ApparentMode", 0) == ID_STATUS_OFFLINE)
						msg = 0; //is it useful ?
				}
				if (msg) {
					ptrA buff(mir_utf8encodeW(variables_parse(gbAuthRepl, hcntct).c_str()));
					CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM)buff);
				}
				return 1;
			}
		}
	}
	return 0;
}
Exemplo n.º 3
0
MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
{
	UNREFERENCED_PARAMETER(wParam);
	MEVENT hDbEvent = (MEVENT)lParam;

	DBEVENTINFO dbei = { 0 };
	dbei.cbSize = sizeof(dbei);
	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	if (-1 == dbei.cbBlob)
		return 0;

	mir_ptr<BYTE> blob((LPBYTE)mir_alloc(dbei.cbBlob));
	dbei.pBlob = blob;
	db_event_get(hDbEvent, &dbei);

	// if event is in protocol that is not despammed
	if (plSets->ProtoDisabled(dbei.szModule))
		return 0;

	// event is an auth request
	if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
		MCONTACT hcntct = DbGetAuthEventContact(&dbei);

		// if request is from unknown or not marked Answered contact
		//and if I don't sent message to this contact
		if (db_get_b(hcntct, "CList", "NotOnList", 0) && !db_get_b(hcntct, pluginName, answeredSetting, 0) && !IsExistMyMessage(hcntct)) {
			if (!plSets->HandleAuthReq.Get()) {
				char *buf = mir_utf8encodeW(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str());
				CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM)buf);
				mir_free(buf);
			}

			// ...send message
			char *AuthRepl = mir_u2a(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str());
			CallProtoService(dbei.szModule, PS_AUTHDENY, hDbEvent, (LPARAM)AuthRepl);
			mir_free(AuthRepl);

			db_set_b(hcntct, "CList", "NotOnList", 1);
			db_set_b(hcntct, "CList", "Hidden", 1);
			if (!plSets->HistLog.Get())
				db_event_delete(0, hDbEvent);
			return 1;
		}
	}
	return 0;
}
Exemplo n.º 4
0
MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent)
{
	DWORD body[3];
	DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
	dbei.cbBlob = sizeof(DWORD) * 2;
	dbei.pBlob = (PBYTE)&body;

	if (db_event_get(hEvent, &dbei))
		return INVALID_CONTACT_ID;

	if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
		return INVALID_CONTACT_ID;

	if (mir_strcmp(dbei.szModule, m_szModuleName) != 0)
		return INVALID_CONTACT_ID;
	return DbGetAuthEventContact(&dbei);
}
Exemplo n.º 5
0
MCONTACT FacebookProto::HContactFromAuthEvent(HANDLE hEvent)
{
	DWORD body[2];
	DBEVENTINFO dbei = { sizeof(dbei) };
	dbei.cbBlob = sizeof(DWORD)*2;
	dbei.pBlob = (PBYTE)&body;

	if (db_event_get(hEvent, &dbei))
		return INVALID_CONTACT_ID;

	if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
		return INVALID_CONTACT_ID;

	if (strcmp(dbei.szModule, m_szModuleName))
		return INVALID_CONTACT_ID;

	return DbGetAuthEventContact(&dbei);
}
Exemplo n.º 6
0
int CYahooProto::AuthDeny( HANDLE hdbe, const TCHAR* reason )
{
	debugLogA("[YahooAuthDeny]");
	if ( !m_bLoggedIn )
		return 1;

	DBEVENTINFO dbei = { sizeof( dbei ) };
	if (( dbei.cbBlob = db_event_getBlobSize(hdbe)) == -1 ) {
		debugLogA("[YahooAuthDeny] ERROR: Can't get blob size");
		return 1;
	}

	dbei.pBlob = ( PBYTE )alloca( dbei.cbBlob );
	if (db_event_get(hdbe, &dbei)) {
		debugLogA("YahooAuthDeny - Can't get db event!");
		return 1;
	}

	if (dbei.eventType != EVENTTYPE_AUTHREQUEST) {
		debugLogA("YahooAuthDeny - not Authorization event");
		return 1;
	}

	if (strcmp( dbei.szModule, m_szModuleName)) {
		debugLogA("YahooAuthDeny - wrong module?");
		return 1;
	}

	/* Need to remove the buddy from our Miranda Lists */
	MCONTACT hContact = DbGetAuthEventContact(&dbei);
	if (hContact != NULL) {
		ptrA who( getStringA(hContact, YAHOO_LOGINID));
		if (who) {
			ptrA myid( getStringA(hContact, "MyIdentity"));
			ptrA u_reason( mir_utf8encodeT(reason));

			debugLogA("Rejecting buddy:%s msg: %s", who, u_reason);
			reject(myid, who, getWord(hContact, "yprotoid", 0), u_reason);
			CallService(MS_DB_CONTACT_DELETE, hContact, 0);
		}
	}
	return 0;
}
Exemplo n.º 7
0
MCONTACT __cdecl CYahooProto::AddToListByEvent( int flags, int /*iContact*/, HANDLE hDbEvent )
{
	debugLogA("[YahooAddToListByEvent]");
	if (!m_bLoggedIn)
		return 0;

	DBEVENTINFO dbei = { sizeof( dbei ) };
	if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == -1 ) {
		debugLogA("[YahooAddToListByEvent] ERROR: Can't get blob size.");
		return 0;
	}

	debugLogA("[YahooAddToListByEvent] Got blob size: %lu", dbei.cbBlob);
	dbei.pBlob = ( PBYTE )_alloca( dbei.cbBlob );
	if (db_event_get(hDbEvent, &dbei)) {
		debugLogA("[YahooAddToListByEvent] ERROR: Can't get event.");
		return 0;
	}

	if (dbei.eventType != EVENTTYPE_AUTHREQUEST) {
		debugLogA("[YahooAddToListByEvent] ERROR: Not an authorization request.");
		return 0;
	}

	if ( strcmp(dbei.szModule, m_szModuleName)) {
		debugLogA("[YahooAddToListByEvent] ERROR: Not Yahoo protocol.");
		return 0;
	}

	MCONTACT hContact = DbGetAuthEventContact(&dbei);
	if (hContact != NULL)
		debugLogA("Temp Buddy found at: %p ", hContact);
	else
		debugLogA("hContact NULL???");

	return hContact;
}
Exemplo n.º 8
0
INT_PTR CALLBACK DlgProcAdded(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HANDLE hDbEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list"));

			hDbEvent = (HANDLE)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);

			//blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
			DBEVENTINFO dbei = { sizeof(dbei) };
			dbei.cbBlob = db_event_getBlobSize(hDbEvent);
			dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
			db_event_get(hDbEvent, &dbei);

			DWORD uin = *(PDWORD)dbei.pBlob;
			HANDLE hContact = DbGetAuthEventContact(&dbei);
			char* nick = (char*)dbei.pBlob + sizeof(DWORD)*2;
			char* first = nick  + strlen(nick)  + 1;
			char* last = first + strlen(first) + 1;
			char* email = last  + strlen(last)  + 1;

			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, CallProtoService(dbei.szModule, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0));
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, CallProtoService(dbei.szModule, PS_LOADICON, PLI_PROTOCOL | PLIF_LARGE, 0));

			PROTOACCOUNT* acc = ProtoGetAccount(dbei.szModule);

			TCHAR* lastT = dbei.flags & DBEF_UTF ? Utf8DecodeT(last) : mir_a2t(last);
			TCHAR* firstT = dbei.flags & DBEF_UTF ? Utf8DecodeT(first) : mir_a2t(first);
			TCHAR* nickT = dbei.flags & DBEF_UTF ? Utf8DecodeT(nick) : mir_a2t(nick);
			TCHAR* emailT = dbei.flags & DBEF_UTF ? Utf8DecodeT(email) : mir_a2t(email);

			TCHAR name[128] = _T("");
			int off = 0;
			if (firstT[0] && lastT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s %s"), firstT, lastT);
			else if (firstT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s"), firstT);
			else if (lastT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s"), lastT);
			if (nickT[0])
			{
				if (off)
					mir_sntprintf(name + off, SIZEOF(name) - off, _T(" (%s)"), nickT);
				else
					mir_sntprintf(name, SIZEOF(name), _T("%s"), nickT);
			}
			if ( !name[0])
				_tcscpy(name, TranslateT("<Unknown>"));

			TCHAR hdr[256];
			if (uin && emailT[0])
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s added you to the contact list\n%u (%s) on %s"), name, uin, emailT, acc->tszAccountName);
			else if (uin)
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s added you to the contact list\n%u on %s"), name, uin, acc->tszAccountName);
			else
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s added you to the contact list\n%s on %s"), name, emailT[0] ? emailT : TranslateT("(Unknown)"), acc->tszAccountName);

			SetDlgItemText(hwndDlg, IDC_HEADERBAR, hdr);

			mir_free(lastT);
			mir_free(firstT);
			mir_free(nickT);
			mir_free(emailT);

			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DETAILS), GWLP_USERDATA, (LONG_PTR)hContact);

			if (hContact == INVALID_HANDLE_VALUE || !db_get_b(hContact, "CList", "NotOnList", 0))
				ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_ADD:
		{
			ADDCONTACTSTRUCT acs = {0};
			acs.handle = hDbEvent;
			acs.handleType = HANDLE_EVENT;
			acs.szProto = "";
			CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);

			HANDLE hContact = (HANDLE)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DETAILS), GWLP_USERDATA);
               if ((hContact == INVALID_HANDLE_VALUE) || !db_get_b(hContact, "CList", "NotOnList", 0))
                  ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
			break;
		}
		case IDC_DETAILS:
		{
			HANDLE hContact = (HANDLE)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DETAILS), GWLP_USERDATA);
			CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
			break;
		}

		case IDOK:
		{
			ADDCONTACTSTRUCT acs = {0};
			acs.handle = hDbEvent;
			acs.handleType = HANDLE_EVENT;
			acs.szProto = "";
			CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
		}
			//fall through
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;
		}
		break;

	case WM_DESTROY:
		Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		break;
	}
	return FALSE;
}
Exemplo n.º 9
0
INT_PTR CALLBACK DlgProcAuthReq(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HANDLE hDbEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list"));
		{
			hDbEvent = (HANDLE)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);

			//blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
			DBEVENTINFO dbei = { sizeof(dbei) };
			dbei.cbBlob = db_event_getBlobSize(hDbEvent);
			dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
			db_event_get(hDbEvent, &dbei);

			DWORD uin = *(PDWORD)dbei.pBlob;
			HANDLE hContact = DbGetAuthEventContact(&dbei);
			char *nick = (char*)dbei.pBlob + sizeof(DWORD)*2;
			char *first = nick  + strlen(nick)  + 1;
			char *last = first + strlen(first) + 1;
			char *email = last  + strlen(last)  + 1;
			char *reason = email + strlen(email) + 1;

			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, CallProtoService(dbei.szModule, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0));
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, CallProtoService(dbei.szModule, PS_LOADICON, PLI_PROTOCOL | PLIF_LARGE, 0));

			PROTOACCOUNT* acc = ProtoGetAccount(dbei.szModule);

			ptrT lastT(dbei.flags & DBEF_UTF ? Utf8DecodeT(last) : mir_a2t(last));
			ptrT firstT(dbei.flags & DBEF_UTF ? Utf8DecodeT(first) : mir_a2t(first));
			ptrT nickT(dbei.flags & DBEF_UTF ? Utf8DecodeT(nick) : mir_a2t(nick));
			ptrT emailT(dbei.flags & DBEF_UTF ? Utf8DecodeT(email) : mir_a2t(email));
			ptrT reasonT(dbei.flags & DBEF_UTF ? Utf8DecodeT(reason) : mir_a2t(reason));

			TCHAR name[128] = _T("");
			int off = 0;
			if (firstT[0] && lastT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s %s"), (TCHAR*)firstT, (TCHAR*)lastT);
			else if (firstT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s"), (TCHAR*)firstT);
			else if (lastT[0])
				off = mir_sntprintf(name, SIZEOF(name), _T("%s"), (TCHAR*)lastT);
			if (nickT[0]) {
				if (off)
					mir_sntprintf(name + off, SIZEOF(name) - off, _T(" (%s)"), (TCHAR*)nickT);
				else
					mir_sntprintf(name, SIZEOF(name), _T("%s"), (TCHAR*)nickT);
			}
			if ( !name[0])
				_tcscpy(name, TranslateT("<Unknown>"));

			TCHAR hdr[256];
			if (uin && emailT[0])
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s requested authorization\n%u (%s) on %s"), name, uin, (TCHAR*)emailT, acc->tszAccountName);
			else if (uin)
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s requested authorization\n%u on %s"), name, uin, acc->tszAccountName);
			else
				mir_sntprintf(hdr, SIZEOF(hdr), TranslateT("%s requested authorization\n%s on %s"), name, emailT[0] ? (TCHAR*)emailT : TranslateT("(Unknown)"), acc->tszAccountName);

			SetDlgItemText(hwndDlg, IDC_HEADERBAR, hdr);
			SetDlgItemText(hwndDlg, IDC_REASON, reasonT);

			if (hContact == INVALID_HANDLE_VALUE || !db_get_b(hContact, "CList", "NotOnList", 0))
				ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);

			SendDlgItemMessage(hwndDlg, IDC_DENYREASON, EM_LIMITTEXT, 255, 0);
			if (CallProtoService(dbei.szModule, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_NOAUTHDENYREASON) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_DENYREASON), FALSE);
				SetDlgItemText(hwndDlg, IDC_DENYREASON, TranslateT("Feature is not supported by protocol"));
			}
			if ( !db_get_b(hContact, "CList", "NotOnList", 0)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_ADDCHECK), FALSE);
				CheckDlgButton(hwndDlg, IDC_ADDCHECK, BST_UNCHECKED);
			}
			else CheckDlgButton(hwndDlg, IDC_ADDCHECK, BST_CHECKED);

			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_DETAILS), GWLP_USERDATA, (LONG_PTR)hContact);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG, GetWindowLongPtr((HWND)lParam, GWLP_USERDATA), 0);
			break;

		case IDC_DECIDELATER:
			DestroyWindow(hwndDlg);
			break;

		case IDOK:
			{
				DBEVENTINFO dbei = { sizeof(dbei) };
				db_event_get(hDbEvent, &dbei);
				CallProtoService(dbei.szModule, PS_AUTHALLOW, (WPARAM)hDbEvent, 0);

				if (IsDlgButtonChecked(hwndDlg, IDC_ADDCHECK)) {
					ADDCONTACTSTRUCT acs = {0};
					acs.handle = hDbEvent;
					acs.handleType = HANDLE_EVENT;
					acs.szProto = "";
					CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
				}
			}
			DestroyWindow(hwndDlg);
			break;

		case IDCANCEL:
			{
				DBEVENTINFO dbei = { sizeof(dbei) };
				db_event_get(hDbEvent, &dbei);

				if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_DENYREASON)))
				{
					TCHAR szReason[256];
					GetDlgItemText(hwndDlg, IDC_DENYREASON, szReason, SIZEOF(szReason));
					CallProtoService(dbei.szModule, PS_AUTHDENYT, (WPARAM)hDbEvent, (LPARAM)szReason);
				}
				else
					CallProtoService(dbei.szModule, PS_AUTHDENYT, (WPARAM)hDbEvent, 0);
			}
			DestroyWindow(hwndDlg);
			break;
		}
		break;

	case WM_DESTROY:
		Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		break;
	}
	return FALSE;
}
Exemplo n.º 10
0
static int AuthEventAdded(WPARAM, LPARAM lParam)
{
	TCHAR szUid[128] = _T("");
	TCHAR szTooltip[256];
	const HANDLE hDbEvent = (HANDLE)lParam;

	DBEVENTINFO dbei = { sizeof(dbei) };
	db_event_get((HANDLE)lParam, &dbei);
	if (dbei.flags & (DBEF_SENT | DBEF_READ) || (dbei.eventType != EVENTTYPE_AUTHREQUEST && dbei.eventType != EVENTTYPE_ADDED))
		return 0;

	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
	db_event_get(hDbEvent, &dbei);

	HANDLE hContact = DbGetAuthEventContact(&dbei);

	CLISTEVENT cli = {0};
	cli.cbSize = sizeof(cli);
	cli.hContact = hContact;
	cli.ptszTooltip = szTooltip;
	cli.flags = CLEF_TCHAR;
	cli.lParam = lParam;
	cli.hDbEvent = hDbEvent;

	CONTACTINFO ci = {0};
	ci.cbSize = sizeof(ci);
	ci.hContact = hContact;
	ci.szProto = GetContactProto(hContact);
	ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
	if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
		switch (ci.type) {
		case CNFT_ASCIIZ:
			mir_sntprintf(szUid, SIZEOF(szUid), _T("%s"), ci.pszVal);
			mir_free(ci.pszVal);
			break;

		case CNFT_DWORD:
			mir_sntprintf(szUid, SIZEOF(szUid), _T("%u"), ci.dVal);
			break;
		}
	}

	if (dbei.eventType == EVENTTYPE_AUTHREQUEST) {
		SkinPlaySound("AuthRequest");
		if (szUid[0])
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%s requests authorization"), szUid);
		else
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%u requests authorization"), *(PDWORD)dbei.pBlob);

		cli.hIcon = LoadSkinIcon(SKINICON_AUTH_REQUEST);
		cli.pszService = MS_AUTH_SHOWREQUEST;
		CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cli);
	}
	else if (dbei.eventType == EVENTTYPE_ADDED) {
		SkinPlaySound("AddedEvent");
		if (szUid[0])
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%s added you to their contact list"), szUid);
		else
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%u added you to their contact list"), *(PDWORD)dbei.pBlob);

		cli.hIcon = LoadSkinIcon(SKINICON_AUTH_ADD);
		cli.pszService = MS_AUTH_SHOWADDED;
		CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cli);
	}
	return 0;
}
Exemplo n.º 11
0
int PopupShow(PLUGIN_OPTIONS* pluginOptions, MCONTACT hContact, MEVENT hEvent, UINT eventType)
{
	TCHAR* sampleEvent;
	long iSeconds;

	//there has to be a maximum number of popups shown at the same time
	if (PopupCount >= MAX_POPUPS)
		return 2;

	//check if we should report this kind of event
	//get the prefered icon as well
	//CHANGE: iSeconds is -1 because I use my timer to hide popup
	POPUPDATAW pudw;
	pudw.iSeconds = -1; 

	switch (eventType) {
	case EVENTTYPE_MESSAGE:
		if (!(pluginOptions->maskNotify & MASK_MESSAGE)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
		pudw.colorBack = pluginOptions->bDefaultColorMsg ? 0 : pluginOptions->colBackMsg;
		pudw.colorText = pluginOptions->bDefaultColorMsg ? 0 : pluginOptions->colTextMsg;
		iSeconds = pluginOptions->iDelayMsg;
		sampleEvent = TranslateT("This is a sample message event :-)");
		break;

	case EVENTTYPE_URL:
		if (!(pluginOptions->maskNotify & MASK_URL)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_URL);
		pudw.colorBack = pluginOptions->bDefaultColorUrl ? 0 : pluginOptions->colBackUrl;
		pudw.colorText = pluginOptions->bDefaultColorUrl ? 0 : pluginOptions->colTextUrl;
		iSeconds = pluginOptions->iDelayUrl;
		sampleEvent = TranslateT("This is a sample URL event ;-)");
		break;

	case EVENTTYPE_FILE:
		if (!(pluginOptions->maskNotify & MASK_FILE)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_FILE);
		pudw.colorBack = pluginOptions->bDefaultColorFile ? 0 : pluginOptions->colBackFile;
		pudw.colorText = pluginOptions->bDefaultColorFile ? 0 : pluginOptions->colTextFile;
		iSeconds = pluginOptions->iDelayFile;
		sampleEvent = TranslateT("This is a sample file event :-D");
		break;

	default:
		if (!(pluginOptions->maskNotify & MASK_OTHER)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
		pudw.colorBack = pluginOptions->bDefaultColorOthers ? 0 : pluginOptions->colBackOthers;
		pudw.colorText = pluginOptions->bDefaultColorOthers ? 0 : pluginOptions->colTextOthers;
		iSeconds = pluginOptions->iDelayOthers;
		sampleEvent = TranslateT("This is a sample other event ;-D");
		break;
	}

	//get DBEVENTINFO with pBlob if preview is needed (when is test then is off)
	DBEVENTINFO dbe = { sizeof(dbe) };
	if (hEvent) {
		if ((pluginOptions->bPreview || eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST)) {
			dbe.cbBlob = db_event_getBlobSize(hEvent);
			dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob);
		}
		db_event_get(hEvent, &dbe);
	}

	EVENT_DATA_EX *eventData = (EVENT_DATA_EX*)mir_alloc(sizeof(EVENT_DATA_EX));
	eventData->hEvent = hEvent;
	eventData->number = 1;
	eventData->next = NULL;
	eventData->prev = NULL;

	// retrieve correct hContact for AUTH events
	if (dbe.pBlob && (eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST))
		hContact = DbGetAuthEventContact(&dbe);

	// set plugin_data ... will be usable within PopupDlgProc
	PLUGIN_DATA *pdata = (PLUGIN_DATA*)mir_alloc(sizeof(PLUGIN_DATA));
	pdata->eventType = eventType;
	pdata->hContact = hContact;
	pdata->pluginOptions = pluginOptions;
	pdata->countEvent = 1;
	pdata->iLock = 0;
	pdata->iSeconds = (iSeconds > 0) ? iSeconds : pluginOptions->iDelayDefault;
	pdata->firstEventData = pdata->firstShowEventData = pdata->lastEventData = eventData;

	// finally create the popup
	pudw.lchContact = hContact;
	pudw.PluginWindowProc = PopupDlgProc;
	pudw.PluginData = pdata;

	// if hContact is NULL, && hEvent is NULL then popup is only Test
	if ((hContact == NULL) && (hEvent == NULL)) {
		_tcsncpy(pudw.lptzContactName, TranslateT("Plugin Test"), MAX_CONTACTNAME);
		_tcsncpy(pudw.lptzText, TranslateTS(sampleEvent), MAX_SECONDLINE);
	}
	else { // get the needed event data
		_tcsncpy(pudw.lptzContactName, (TCHAR*)pcli->pfnGetContactDisplayName(hContact, 0), MAX_CONTACTNAME);
		_tcsncpy(pudw.lptzText, ptrT(GetEventPreview(&dbe)), MAX_SECONDLINE);
	}

	PopupCount++;

	PopupList[NumberPopupData(NULL, -1)] = pdata;
	// send data to popup plugin

	if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
		// popup creation failed, release popupdata
		if (PUAddPopupW(&pudw) < 0) {
			FreePopupEventData(pdata);
			mir_free(pdata);
		}
	}

	if (dbe.pBlob)
		mir_free(dbe.pBlob);
	return 0;
}