Example #1
0
void CMsnProto::LoadOptions(void)
{
    memset(&MyOptions, 0, sizeof(MyOptions));

    //Popup Options
    MyOptions.ManageServer = getByte("ManageServer", TRUE) != 0;
    MyOptions.ShowErrorsAsPopups = getByte("ShowErrorsAsPopups", TRUE) != 0;
    MyOptions.SlowSend = getByte("SlowSend", FALSE) != 0;
    if (db_get_static(NULL, m_szModuleName, "wlid", MyOptions.szEmail, sizeof(MyOptions.szEmail)))
    {
        if (db_get_static(NULL, m_szModuleName, "e-mail", MyOptions.szEmail, sizeof(MyOptions.szEmail)))
            MyOptions.szEmail[0] = 0;
        else setString("wlid", MyOptions.szEmail);
    }
    _strlwr(MyOptions.szEmail);
    MyOptions.netId = getDword("netId", GetMyNetID());

    if (db_get_static(NULL, m_szModuleName, "MachineGuid", MyOptions.szMachineGuid, sizeof(MyOptions.szMachineGuid))) {
        char* uuid = getNewUuid();
        mir_strcpy(MyOptions.szMachineGuid, uuid);
        setString("MachineGuid", MyOptions.szMachineGuid);
        mir_free(uuid);
    }
    mir_strcpy(MyOptions.szMachineGuidP2P, MyOptions.szMachineGuid);
    _strlwr(MyOptions.szMachineGuidP2P);
}
Example #2
0
INT_PTR CALLBACK DlgDeleteContactUI(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        TranslateDialogDefault(hwndDlg);
        SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
        return TRUE;

    case WM_CLOSE:
        EndDialog(hwndDlg, 0);
        break;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK) {
            int isBlock = IsDlgButtonChecked(hwndDlg, IDC_REMOVEBLOCK);
            int isHot = IsDlgButtonChecked(hwndDlg, IDC_REMOVEHOT);

            DeleteParam *param = (DeleteParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

            char szEmail[MSN_MAX_EMAIL_LEN];
            if (!db_get_static(param->hContact, param->proto->m_szModuleName, "wlid", szEmail, sizeof(szEmail)) ||
                    !db_get_static(param->hContact, param->proto->m_szModuleName, "e-mail", szEmail, sizeof(szEmail))) {
                param->proto->MSN_AddUser(param->hContact, szEmail, 0, LIST_FL | (isHot ? LIST_REMOVE : LIST_REMOVENH));
                if (isBlock) {
                    param->proto->MSN_AddUser(param->hContact, szEmail, 0, LIST_AL | LIST_REMOVE);
                    param->proto->MSN_AddUser(param->hContact, szEmail, 0, LIST_BL);
                }
            }
            EndDialog(hwndDlg, 1);
        }
        break;
    }

    return FALSE;
}
Example #3
0
INT_PTR CALLBACK DlgProcContactInfo(HWND hwnd, UINT msg, WPARAM, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwnd);
		{
			MCONTACT hContact = (MCONTACT)((PROPSHEETPAGE*)lParam)->lParam;
			char name[2048];
			SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)hContact);

			if (db_get_static(hContact, MODNAME, "Name", name, _countof(name)))
				break;
			SetDlgItemTextA(hwnd, IDC_DISPLAY_NAME, name);
			if (db_get_static(hContact, MODNAME, "ToolTip", name, _countof(name)))
				break;
			SetDlgItemTextA(hwnd, IDC_TOOLTIP, name);
		}
		return TRUE;

	case WM_COMMAND:
		SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
				MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
				if (GetWindowTextLength(GetDlgItem(hwnd, IDC_DISPLAY_NAME))) {
					char text[512];
					GetDlgItemTextA(hwnd, IDC_DISPLAY_NAME, text, _countof(text));
					db_set_s(hContact, MODNAME, "Name", text);
					WriteSetting(hContact, MODNAME, "Name", MODNAME, "Nick");
				}
				else {
					db_unset(hContact, MODNAME, "Name");
					db_unset(hContact, MODNAME, "Nick");
				}

				if (GetWindowTextLength(GetDlgItem(hwnd, IDC_TOOLTIP))) {
					char text[2048];
					GetDlgItemTextA(hwnd, IDC_TOOLTIP, text, _countof(text));
					db_set_s(hContact, MODNAME, "ToolTip", text);
					WriteSetting(hContact, MODNAME, "ToolTip", "UserInfo", "MyNotes");
				}
				else {
					db_unset(hContact, MODNAME, "ToolTip");
					db_unset(hContact, "UserInfo", "MyNotes");
				}
			}
			return TRUE;
		}
		break;
	}
	return FALSE;
}
Example #4
0
int CMsnProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam)
{
	DBCONTACTWRITESETTING* cws = (DBCONTACTWRITESETTING*)lParam;

	if (!msnLoggedIn || MyOptions.netId != NETID_MSN)
		return 0;

	if (hContact == NULL) {
		if (MyOptions.SlowSend && strcmp(cws->szSetting, "MessageTimeout") == 0 &&
			(strcmp(cws->szModule, "SRMM") == 0 || strcmp(cws->szModule, "SRMsg") == 0)) {
			if (cws->value.dVal < 60000)
				MessageBox(NULL, TranslateT("MSN requires message send timeout in your Message window plugin to be not less then 60 sec. Please correct the timeout value."),
				TranslateT("MSN Protocol"), MB_OK | MB_ICONINFORMATION);
		}
		return 0;
	}

	if (!strcmp(cws->szSetting, "ApparentMode")) {
		char tEmail[MSN_MAX_EMAIL_LEN];
		if (!db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)) ||
			!db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) {
			bool isBlocked = Lists_IsInList(LIST_BL, tEmail);

			if (isBlocked && (cws->value.type == DBVT_DELETED || cws->value.wVal == 0)) {
				MSN_AddUser(hContact, tEmail, 0, LIST_BL + LIST_REMOVE);
				MSN_AddUser(hContact, tEmail, 0, LIST_AL);
			}
			else if (!isBlocked && cws->value.wVal == ID_STATUS_OFFLINE) {
				MSN_AddUser(hContact, tEmail, 0, LIST_AL + LIST_REMOVE);
				MSN_AddUser(hContact, tEmail, 0, LIST_BL);
			}
		}
	}

	if (!strcmp(cws->szSetting, "MyHandle") && !strcmp(cws->szModule, "CList")) {
		bool isMe = MSN_IsMeByContact(hContact);
		if (!isMe || !nickChg) {
			char szContactID[100];
			if (!db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID))) {
				if (cws->value.type != DBVT_DELETED) {
					if (cws->value.type == DBVT_UTF8)
						MSN_ABUpdateNick(cws->value.pszVal, szContactID);
					else
						MSN_ABUpdateNick(UTF8(cws->value.pszVal), szContactID);
				}
				else MSN_ABUpdateNick(NULL, szContactID);
			}

			if (isMe)
				displayEmailCount(hContact);
		}
	}
	return 0;
}
Example #5
0
int __cdecl CMsnProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
{
	char tEmail[MSN_MAX_EMAIL_LEN];
	if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)))
	    db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail));

	if (Lists_IsInList(LIST_FL, tEmail))
		db_unset(hContact, "CList", "Hidden");

	return Proto_RecvMessage(hContact, pre);
}
Example #6
0
int CMsnProto::GetInfo(MCONTACT hContact, int)
{
	if (MyOptions.netId == NETID_SKYPE) {
		char tEmail[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)))
			db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail));

		MSN_SKYABGetProfile(tEmail);
		return 1;
	}
	return 0;
}
Example #7
0
static void SaveSettings(MCONTACT hItem, HWND hwndList, CMsnProto* proto)
{
	if (hItem == NULL)
		hItem = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0);

	while (hItem) {
		if (IsHContactGroup(hItem)) {
			MCONTACT hItemT = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);
			if (hItemT)
				SaveSettings(hItemT, hwndList, proto);
		}
		else {
			char szEmail[MSN_MAX_EMAIL_LEN];

			if (IsHContactContact(hItem)) {
				if (db_get_static(hItem, proto->m_szModuleName, "wlid", szEmail, sizeof(szEmail)) &&
					db_get_static(hItem, proto->m_szModuleName, "e-mail", szEmail, sizeof(szEmail)))
					continue;
			}
			else if (IsHContactInfo(hItem)) {
				TCHAR buf[MSN_MAX_EMAIL_LEN];
				SendMessage(hwndList, CLM_GETITEMTEXT, (WPARAM)hItem, (LPARAM)buf);
				WideCharToMultiByte(CP_ACP, 0, buf, -1, szEmail, sizeof(szEmail), 0, 0);

			}

			int dwMask = proto->Lists_GetMask(szEmail);
			SaveListItem(hItem, szEmail, LIST_LL, (dwMask & LIST_LL) ? 1 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, 0)), proto);
			SaveListItem(hItem, szEmail, LIST_FL, (dwMask & LIST_FL) ? 2 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, 0)), proto);
			SaveListItem(hItem, szEmail, LIST_AL, (dwMask & LIST_AL) ? 3 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2, 0)), proto);
			SaveListItem(hItem, szEmail, LIST_BL, (dwMask & LIST_BL) ? 4 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3, 0)), proto);

			int newMask = proto->Lists_GetMask(szEmail);
			int xorMask = newMask ^ dwMask;

			if (xorMask && newMask & (LIST_FL | LIST_LL)) {
				MCONTACT hContact = IsHContactInfo(hItem) ? proto->MSN_HContactFromEmail(szEmail, szEmail, true, false) : hItem;
				proto->MSN_SetContactDb(hContact, szEmail);
			}

			if (xorMask & (LIST_FL | LIST_LL) && !(newMask & (LIST_FL | LIST_LL))) {
				if (!IsHContactInfo(hItem)) {
					CallService(MS_DB_CONTACT_DELETE, (WPARAM)hItem, 0);
					MsnContact* msc = proto->Lists_Get(szEmail);
					if (msc) msc->hContact = NULL;
				}
			}
		}
		hItem = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXT, (LPARAM)hItem);
	}
}
Example #8
0
INT_PTR CMsnProto::MsnBlockCommand(WPARAM hContact, LPARAM)
{
	if (msnLoggedIn) {
		char tEmail[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)))
		db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail));

		if (Lists_IsInList(LIST_BL, tEmail))
			delSetting(hContact, "ApparentMode");
		else
			setWord(hContact, "ApparentMode", ID_STATUS_OFFLINE);
	}
	return 0;
}
Example #9
0
int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
	if (msnLoggedIn)
	{
		char email[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "e-mail", email, sizeof(email)))
			return 1;

		char* szMsg = mir_utf8encodeT(szMessage);

//			int netId = Lists_GetNetId(email);
//			if (netId == NETID_UNKNOWN)
		int netId = strncmp(email, "tel:", 4) == 0 ? NETID_MOB : NETID_MSN;
		if (MSN_AddUser(hContact, email, netId, LIST_FL, szMsg))
		{
			MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_AL);
		}
		MSN_SetContactDb(hContact, email);
		mir_free(szMsg);

		if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		return 0;
	}
	return 1;
}
Example #10
0
void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url)
{
	char* hippy = NULL;
	if (!url)
		url = ismail ? "http://mail.live.com?rru=inbox" : "http://profile.live.com";

	const char *postdata = ismail ? postdataM : postdataS;

	char passport[256];
	if (db_get_static(NULL, m_szModuleName, "MsnPassportHost", passport, 256))
		strcpy(passport, "https://login.live.com/");

	char *p = strchr(passport, '/');
	if (p && p[1] == '/') p = strchr(p + 2, '/');
	if (p)
		*p = 0;

	CMStringA post = HotmailLogin(CMStringA().Format(postdata, (unsigned)time(NULL), ptrA(mir_urlEncode(url))));
	if (!post.IsEmpty()) {
		CMStringA hippy(passport);
		hippy.AppendFormat("/ppsecure/sha1auth.srf?lc=%d&token=%s", itoa(langpref, passport, 10), ptrA(mir_urlEncode(post)));

		debugLogA("Starting URL: '%s'", hippy);
		CallService(MS_UTILS_OPENURL, 1, (LPARAM)hippy.GetString());
	}
}
Example #11
0
void replaceAllStrings(MCONTACT hContact)
{
	char tmp1[256], tmp2[256], tmp3[256];
	WriteSetting(hContact, MODNAME, "Name", MODNAME, "Nick");
	WriteSetting(hContact, MODNAME, "ProgramString", MODNAME, "Program");
	WriteSetting(hContact, MODNAME, "ProgramParamsString", MODNAME, "ProgramParams");
	/* tooltips*/
	WriteSetting(hContact, MODNAME, "ToolTip", "UserInfo", "MyNotes");
	if (db_get_static(hContact, MODNAME, "Program", tmp1, _countof(tmp1)) && db_get_static(hContact, MODNAME, "ProgramParams", tmp2, _countof(tmp2))) {
		mir_snprintf(tmp3, _countof(tmp3), "%s %s", tmp1, tmp2);
		db_set_s(hContact, "UserInfo", "FirstName", tmp3);
	}
	else if (db_get_static(hContact, MODNAME, "Program", tmp1, _countof(tmp1))) {
		db_set_s(hContact, "UserInfo", "FirstName", tmp1);
	}
	else db_set_s(hContact, "UserInfo", "FirstName", "");
}
Example #12
0
bool CMsnProto::MSN_IsMeByContact(MCONTACT hContact, char* szEmail)
{
	char tEmail[MSN_MAX_EMAIL_LEN];
	char *emailPtr = szEmail ? szEmail : tEmail;

	*emailPtr = 0;
	if (db_get_static(hContact, m_szModuleName, "e-mail", emailPtr, sizeof(tEmail)))
		return false;

	return _stricmp(emailPtr, MyOptions.szEmail) == 0;
}
Example #13
0
char* CMsnProto::GetStoreHost(const char* service)
{
    char hostname[128];
    mir_snprintf(hostname, sizeof(hostname), "StoreHost-%s", service);

    char* host = (char*)mir_alloc(256);
    if (db_get_static(NULL, m_szModuleName, hostname, host, 256))
        strcpy(host, "https://tkrdr.storage.msn.com/storageservice/SchematizedStore.asmx");

    return host;
}
Example #14
0
static void SetContactIcons(MCONTACT hItem, HWND hwndList, CMsnProto* proto)
{
	if (!proto->MSN_IsMyContact(hItem)) {
		SendMessage(hwndList, CLM_DELETEITEM, (WPARAM)hItem, 0);
		return;
	}

	char szEmail[MSN_MAX_EMAIL_LEN];
	if (db_get_static(hItem, proto->m_szModuleName, "wlid", szEmail, sizeof(szEmail)) && 
		db_get_static(hItem, proto->m_szModuleName, "e-mail", szEmail, sizeof(szEmail))) {
		SendMessage(hwndList, CLM_DELETEITEM, (WPARAM)hItem, 0);
		return;
	}

	DWORD dwMask = proto->Lists_GetMask(szEmail);
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, (dwMask & LIST_LL) ? 1 : 0));
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, (dwMask & LIST_FL) ? 2 : 0));
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2, (dwMask & LIST_AL) ? 3 : 0));
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3, (dwMask & LIST_BL) ? 4 : 0));
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(4, (dwMask & LIST_RL) ? 5 : 0));
}
Example #15
0
// PSS_AUTHREQUEST
int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
	if (msnLoggedIn) {
		char email[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "wlid", email, sizeof(email)) &&
			db_get_static(hContact, m_szModuleName, "e-mail", email, sizeof(email)))
			return 1;

		int netId = strncmp(email, "tel:", 4) == 0 ? NETID_MOB : (strncmp(email, "live:", 5) == 0 ? NETID_SKYPE : NETID_MSN);
		if (MSN_AddUser(hContact, email, netId, LIST_FL, T2Utf(szMessage))) {
			MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_AL);
		}
		MSN_SetContactDb(hContact, email);

		if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		return 0;
	}
	return 1;
}
Example #16
0
void CMsnProto::Lists_Populate(void)
{
	MCONTACT hContact = db_find_first(m_szModuleName);
	while (hContact) {
		MCONTACT hNext = db_find_next(hContact, m_szModuleName);
		char szEmail[MSN_MAX_EMAIL_LEN] = "";
		if (db_get_static(hContact, m_szModuleName, "wlid", szEmail, sizeof(szEmail))) {
			if (db_get_static(hContact, m_szModuleName, "e-mail", szEmail, sizeof(szEmail)) == 0)
				setString(hContact, "wlid", szEmail);
		}
		if (szEmail[0]) {
			bool localList = getByte(hContact, "LocalList", 0) != 0;
			int netId = getWord(hContact, "netId", localList?NETID_MSN:NETID_UNKNOWN);
			if (localList)
				Lists_Add(LIST_LL, netId, szEmail, hContact);
			else
				Lists_Add(0, netId, szEmail, hContact);
		}
		else if (!isChatRoom(hContact)) CallService(MS_DB_CONTACT_DELETE, hContact, 0);
		hContact = hNext;
	}
}
Example #17
0
INT_PTR addContact(WPARAM, LPARAM)
{
	char tmp[256];
	MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
	Proto_AddToContact(hContact, MODNAME);
	CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE);
	db_set_ts(hContact, MODNAME, "Nick", TranslateT("New Non-IM Contact"));
	DoPropertySheet(hContact);
	if (!db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp)))
		CallService(MS_DB_CONTACT_DELETE, hContact, 0);
	replaceAllStrings(hContact);
	return 0;
}
Example #18
0
int __cdecl CMsnProto::SetStatus(int iNewStatus)
{
	if (m_iDesiredStatus == iNewStatus) return 0;

	m_iDesiredStatus = iNewStatus;
	debugLogA("PS_SETSTATUS(%d,0)", iNewStatus);

	if (m_iDesiredStatus == ID_STATUS_OFFLINE)
	{
		if (msnNsThread)
			msnNsThread->sendTerminate();
	}
	else if (!msnLoggedIn && m_iStatus == ID_STATUS_OFFLINE)
	{
		char szPassword[100];
		int ps = db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword));
		if (ps != 0  || *szPassword == 0)
		{
			ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
			m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
			return 0;
		}

		if (*MyOptions.szEmail == 0)
		{
			ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID);
			m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
			return 0;
		}

		sessionList.destroy();
		dcList.destroy();

		usingGateway = false;

		int oldMode = m_iStatus;
		m_iStatus = ID_STATUS_CONNECTING;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldMode, m_iStatus);

		ThreadData* newThread = new ThreadData;

		newThread->mType = SERVER_NOTIFICATION;
		newThread->mIsMainThread = true;

		newThread->startThread(&CMsnProto::MSNServerThread, this);
	}
	else
		if (m_iStatus > ID_STATUS_OFFLINE) MSN_SetServerStatus(m_iDesiredStatus);

	return 0;
}
Example #19
0
void timerFunc(void*)
{
	char text[512], fn[16], szFileName[MAX_PATH], temp[MAX_PATH];

	int timerCount = db_get_w(NULL, MODNAME, "timerCount", 1) + 1;

	if (LCStatus == ID_STATUS_OFFLINE) {
		killTimer();
		return;
	}
	db_set_w(NULL, MODNAME, "timerCount", (WORD)timerCount);

	/* update the web pages*/
	for (int i = 0;; i++) {
		mir_snprintf(fn, "fn%d", i);
		if (!db_get_static(NULL, MODNAME, fn, text, _countof(text)))
			break;

		if (!strncmp("http://", text, mir_strlen("http://")) || !strncmp("https://", text, mir_strlen("https://"))) {
			mir_snprintf(fn, "fn%d_timer", i);
			int timer = db_get_w(NULL, MODNAME, fn, 60);
			if (timer && !(timerCount % timer)) {
				if (!InternetDownloadFile(text)) {
					mir_snprintf(szFileName, "%s\\plugins\\fn%d.html", getMimDir(temp), i);
					savehtml(szFileName);
				}
			}
		}
	}

	/* update all the contacts */
	for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) {
		int timer = db_get_w(hContact, MODNAME, "Timer", 15);
		if (timer && !(timerCount % timer))
			if (db_get_static(hContact, MODNAME, "Name", text, _countof(text)))
				replaceAllStrings(hContact);
	}
}
Example #20
0
void ExportContact(MCONTACT hContact)
{
	char szFileName[MAX_PATH];
	char DBVar[1024];
	int tmp;

	if (Openfile(szFileName, 0)) {
		//	if (tmp = MessageBox(0, "Do you want to overwrite the contents of the file?\r\n\r\nPressing No will append this contact to the end of the file.",modFullname, MB_YESNO) == IDYES)
		//		file = fopen(szFileName, "w");
		//	else 
		FILE *file = fopen(szFileName, "a");
		if (file) {
			if (!db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) {
				fprintf(file, "\r\n[Non-IM Contact]\r\nName=%s\r\n", DBVar);
				if (!db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar)))
					fprintf(file, "ProgramString=%s\r\n", DBVar);
				if (!db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar)))
					fprintf(file, "ProgramParamString=%s\r\n", DBVar);
				if (!db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar)))
					fprintf(file, "ToolTip=%s</tooltip>\r\n", DBVar);
				if (!db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar)))
					fprintf(file, "Group=%s\r\n", DBVar);
				if (tmp = db_get_w(hContact, MODNAME, "Icon", 40072))
					fprintf(file, "Icon=%d\r\n", tmp);
				if (tmp = db_get_b(hContact, MODNAME, "UseTimer", 0))
					fprintf(file, "UseTimer=%d\r\n", tmp);
				if (tmp = db_get_b(hContact, MODNAME, "Minutes", 1))
					fprintf(file, "Minutes=%d\r\n", tmp);
				if (tmp = db_get_w(hContact, MODNAME, "Timer", 0))
					fprintf(file, "Timer=%d\r\n", tmp);
				fprintf(file, "[/Non-IM Contact]\r\n");
			}
			else ("Contact is invalid", modFullname);
			fclose(file);
		}
	}
}
Example #21
0
int ApplyProtoFilter(MCONTACT hContact)
{
	if (g_Mode == MODE_ALL)	return 0;

	int loaded = 0;
	char szProto[FLD_SIZE];

	if (!db_get_static(hContact, "Protocol", "p", szProto, _countof(szProto)))
		loaded = Proto_GetAccount(szProto) ? 1 : 0;

	if ((loaded && g_Mode == MODE_UNLOADED) || (!loaded && g_Mode == MODE_LOADED))
		return 1;

	return 0;
}
Example #22
0
int GetMailboxPwd(LPCSTR acc, LPSTR *pwd, int buffSize)
{
	char buff[256];
	if (db_get_static(NULL, acc, LOGIN_PASS_SETTING_NAME, buff, sizeof(buff)))
		return 0;

	int result = (int)mir_strlen(buff);

	if (pwd) {
		if (buffSize < result + 1)
			result = buffSize - 1;
		memcpy(*pwd, &buff, result + 1);
	}

	return result;
}
Example #23
0
INT_PTR CMsnProto::MsnViewProfile(WPARAM hContact, LPARAM)
{
	char buf[64], *cid;

	if (hContact == NULL)
		cid = mycid;
	else {
		cid = buf;
		if (db_get_static(hContact, m_szModuleName, "CID", buf, 30))
			return 0;
	}

	char tUrl[256];
	mir_snprintf(tUrl, _countof(tUrl), "http://cid-%I64X.profiles.live.com", _atoi64(cid));
	MsnInvokeMyURL(false, tUrl);
	return 0;
}
Example #24
0
void WriteSetting(MCONTACT hContact, char* module1, char* setting1, char* module2, char* setting2)
{
	CMStringA newString;
	char text[MAX_STRING_LENGTH];
	int error = 0, status = GetLCStatus(0, 0);
	if (db_get_static(hContact, module1, setting1, text, _countof(text))) {
		switch (stringReplacer(text, newString, hContact)) {
		case ERROR_NO_LINE_AFTER_VAR_F:
			newString.Format(Translate("%s - ERROR: no line specified or line not found (in %s)"), text, setting1);
			error = 1;
			break;
		case ERROR_LINE_NOT_READ:
			newString.Format(Translate("%s - ERROR: file couldn't be opened (in %s)"), text, setting1);
			error = 1;
			break;
		case ERROR_NO_FILE:
			newString.Format(Translate("%s - ERROR: no file specified in settings (in %s)"), text, setting1);
			error = 1;
			break;
		default:
			error = 0;
			break;
		}
		// strip the tab and new lines from all except the tooltip
		if (!error && mir_strcmp(setting1, "ToolTip"))
			newString.TrimRight();
		db_set_s(hContact, module2, setting2, newString);
	}
	else db_set_s(hContact, module2, setting2, "");
	
	if (!error) {
		if ((status == ID_STATUS_ONLINE) || (status == ID_STATUS_AWAY) ||
			 (status == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)) ||
			 db_get_b(hContact, MODNAME, "AlwaysVisible", 0))
			db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
		else
			db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE);
	}
	else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE);
}
Example #25
0
void DoPropertySheet(MCONTACT hContact)
{
	char title[256], nick[256];
	PROPSHEETPAGEA psp[4] = { 0 };

	/* contact info */
	psp[0].dwSize = sizeof(PROPSHEETPAGE);
	psp[0].dwFlags = PSP_USEICONID | PSP_USETITLE;
	psp[0].hInstance = g_hInst;
	psp[0].pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_INFO);
	psp[0].pszIcon = NULL;
	psp[0].pfnDlgProc = DlgProcContactInfo;
	psp[0].pszTitle = Translate("Contacts Display Info");
	psp[0].lParam = hContact;
	psp[0].pfnCallback = NULL;

	/* other settings */
	psp[1].dwSize = sizeof(PROPSHEETPAGE);
	psp[1].dwFlags = PSP_USEICONID | PSP_USETITLE;
	psp[1].hInstance = g_hInst;
	psp[1].pszTemplate = MAKEINTRESOURCEA(IDD_OTHER_STUFF);
	psp[1].pszIcon = NULL;
	psp[1].pfnDlgProc = DlgProcOtherStuff;
	psp[1].pszTitle = Translate("Link and Contact list Settings");
	psp[1].lParam = hContact;
	psp[1].pfnCallback = NULL;

	/* copy contact */
	psp[2].dwSize = sizeof(PROPSHEETPAGE);
	psp[2].dwFlags = PSP_USEICONID | PSP_USETITLE;
	psp[2].hInstance = g_hInst;
	psp[2].pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_COPYEXPORT);
	psp[2].pszIcon = NULL;
	psp[2].pfnDlgProc = DlgProcCopy;
	psp[2].pszTitle = Translate("Copy Contact");
	psp[2].lParam = hContact;
	psp[2].pfnCallback = NULL;

	/* files */
	psp[3].dwSize = sizeof(PROPSHEETPAGE);
	psp[3].dwFlags = PSP_USEICONID | PSP_USETITLE;
	psp[3].hInstance = g_hInst;
	psp[3].pszTemplate = MAKEINTRESOURCEA(IDD_ADD_FILE);
	psp[3].pszIcon = NULL;
	psp[3].pfnDlgProc = DlgProcFiles;
	psp[3].pszTitle = Translate("Files");
	psp[3].lParam = 0;
	psp[3].pfnCallback = NULL;

	/* propery sheet header.. dont touch !!!! */
	PROPSHEETHEADERA psh = { sizeof(psh) };
	psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_USECALLBACK;
	psh.hInstance = g_hInst;
	psh.pszIcon = MAKEINTRESOURCEA(IDI_MAIN);
	db_get_static(hContact, MODNAME, "Nick", nick, _countof(nick));
	mir_snprintf(title, Translate("Edit Non-IM Contact \"%s\""), nick);
	psh.pszCaption = title;
	psh.nPages = _countof(psp);
	psh.ppsp = (LPCPROPSHEETPAGEA)&psp;
	psh.pfnCallback = PropSheetProc;

	// Now do it and return
	PropertySheetA(&psh);
}
Example #26
0
CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) :
	PROTO<CMsnProto>(aProtoName, aUserName),
	m_arContacts(10, CompareLists),
	m_arGroups(10, CompareId),
	m_arThreads(10, PtrKeySortT),
	m_arGCThreads(10, PtrKeySortT),
#ifdef OBSOLETE
	m_arSessions(10, PtrKeySortT),
	m_arDirect(10, PtrKeySortT),
#endif
	lsMessageQueue(1),
	lsAvatarQueue(1),
	msgCache(5, CompareId),
	authContactToken("authContact", "service::contacts.msn.com::MBI_SSL"),
	authStorageToken("authStorage", "service::storage.msn.com::MBI_SSL"),
	authSSLToken("authSSL", "service::ssl.live.com::MBI_SSL"),
	authSkypeComToken("authSkypeCom", "service::skype.com::MBI_SSL"),
	authStrToken("authStr", "service::chatservice.live.com::MBI_SSL", true),
	authSkypeToken("authSkype")
{
	db_set_resident(m_szModuleName, "IdleTS");
	db_set_resident(m_szModuleName, "p2pMsgId");
	db_set_resident(m_szModuleName, "MobileEnabled");
	db_set_resident(m_szModuleName, "MobileAllowed");

	// Initialize tokens
	authContactToken.Init(this);
	authStorageToken.Init(this);
	authSSLToken.Init(this);
	authSkypeComToken.Init(this);
	authStrToken.Init(this);
	authSkypeToken.Init(this);
	LoadAuthTokensDB();

	// Protocol services and events...

	CreateProtoService(PS_CREATEACCMGRUI, &CMsnProto::SvcCreateAccMgrUI);

	CreateProtoService(PS_GETAVATARINFO, &CMsnProto::GetAvatarInfo);
	CreateProtoService(PS_GETMYAWAYMSG, &CMsnProto::GetMyAwayMsg);

	CreateProtoService(PS_LEAVECHAT, &CMsnProto::OnLeaveChat);

	CreateProtoService(PS_GETMYAVATAR, &CMsnProto::GetAvatar);
	CreateProtoService(PS_SETMYAVATAR, &CMsnProto::SetAvatar);
	CreateProtoService(PS_GETAVATARCAPS, &CMsnProto::GetAvatarCaps);

	CreateProtoService(PS_SETMYNICKNAME, &CMsnProto::SetNickName);
#ifdef OBSOLETE
	CreateProtoService(PS_GET_LISTENINGTO, &CMsnProto::GetCurrentMedia);
	CreateProtoService(PS_SET_LISTENINGTO, &CMsnProto::SetCurrentMedia);

	MsgQueue_Init();
#endif

	hMSNNudge = CreateProtoEvent("/Nudge");
	CreateProtoService(PS_SEND_NUDGE, &CMsnProto::SendNudge);

	CreateProtoService(PS_GETUNREADEMAILCOUNT, &CMsnProto::GetUnreadEmailCount);

	// event hooks
	HookProtoEvent(ME_MSG_WINDOWPOPUP, &CMsnProto::OnWindowPopup);
	HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMsnProto::OnGroupChange);
	HookProtoEvent(ME_OPT_INITIALISE, &CMsnProto::OnOptionsInit);
	HookProtoEvent(ME_CLIST_DOUBLECLICKED, &CMsnProto::OnContactDoubleClicked);

	LoadOptions();

	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		delSetting(hContact, "Status");
		delSetting(hContact, "IdleTS");
		delSetting(hContact, "p2pMsgId");
		delSetting(hContact, "AccList");
	}
	delSetting("MobileEnabled");
	delSetting("MobileAllowed");

	char path[MAX_PATH];
	if (db_get_static(NULL, m_szModuleName, "LoginServer", path, sizeof(path)) == 0 &&
		(mir_strcmp(path, MSN_DEFAULT_LOGIN_SERVER) == 0 ||
		mir_strcmp(path, MSN_DEFAULT_GATEWAY) == 0))
		delSetting("LoginServer");

	if (MyOptions.SlowSend) {
		if (db_get_dw(NULL, "SRMsg", "MessageTimeout", 10000) < 60000)
			db_set_dw(NULL, "SRMsg", "MessageTimeout", 60000);
		if (db_get_dw(NULL, "SRMM", "MessageTimeout", 10000) < 60000)
			db_set_dw(NULL, "SRMM", "MessageTimeout", 60000);
	}

	mailsoundname = (char*)mir_alloc(64);
	mir_snprintf(mailsoundname, 64, "%s:Hotmail", m_szModuleName);
	SkinAddNewSoundExT(mailsoundname, m_tszUserName, LPGENT("Live Mail"));

	alertsoundname = (char*)mir_alloc(64);
	mir_snprintf(alertsoundname, 64, "%s:Alerts", m_szModuleName);
	SkinAddNewSoundExT(alertsoundname, m_tszUserName, LPGENT("Live Alert"));

	AvatarQueue_Init();
	InitCustomFolders();

	TCHAR szBuffer[MAX_PATH];
	char  szDbsettings[64];

	NETLIBUSER nlu1 = { 0 };
	nlu1.cbSize = sizeof(nlu1);
	nlu1.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
	nlu1.szSettingsModule = szDbsettings;
	nlu1.ptszDescriptiveName = szBuffer;

	mir_snprintf(szDbsettings, "%s_HTTPS", m_szModuleName);
	mir_sntprintf(szBuffer, TranslateT("%s plugin HTTPS connections"), m_tszUserName);
	hNetlibUserHttps = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu1);

	NETLIBUSER nlu = { 0 };
	nlu.cbSize = sizeof(nlu);
	nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
	nlu.szSettingsModule = m_szModuleName;
	nlu.ptszDescriptiveName = szBuffer;

	nlu.szHttpGatewayUserAgent = (char*)MSN_USER_AGENT;
	nlu.pfnHttpGatewayInit = msn_httpGatewayInit;
	nlu.pfnHttpGatewayWrapSend = msn_httpGatewayWrapSend;
	nlu.pfnHttpGatewayUnwrapRecv = msn_httpGatewayUnwrapRecv;

	mir_sntprintf(szBuffer, TranslateT("%s plugin connections"), m_tszUserName);
	m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);

	m_DisplayNameCache = NULL;
}
Example #27
0
static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    DBVARIANT dbv;

    switch (msg) {
    case WM_INITDIALOG:
        TranslateDialogDefault(hwndDlg);
        {
            SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
            CMsnProto* proto = (CMsnProto*)lParam;

            if (!proto->getString("DirectServer", &dbv)) {
                SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, dbv.pszVal);
                db_free(&dbv);
            }
            else SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, MSN_DEFAULT_LOGIN_SERVER);

            if (!proto->getString("GatewayServer", &dbv)) {
                SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, dbv.pszVal);
                db_free(&dbv);
            }
            else SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, MSN_DEFAULT_GATEWAY);

            CheckDlgButton(hwndDlg, IDC_SLOWSEND, proto->getByte("SlowSend", 0) ? BST_CHECKED : BST_UNCHECKED);

            SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Automatically obtain host/port"));
            SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Manually specify host/port"));
            SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Disable"));

            unsigned gethst = proto->getByte("AutoGetHost", 1);
            if (gethst < 2) gethst = !gethst;

            char ipaddr[256] = "";
            if (gethst == 1)
                if (db_get_static(NULL, proto->m_szModuleName, "YourHost", ipaddr, sizeof(ipaddr)))
                    gethst = 0;

            if (gethst == 0)
                strncpy_s(ipaddr, (proto->msnLoggedIn ? proto->MyConnection.GetMyExtIPStr() : ""), _TRUNCATE);

            SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_SETCURSEL, gethst, 0);
            if (ipaddr[0])
                SetDlgItemTextA(hwndDlg, IDC_YOURHOST, ipaddr);
            else
                SetDlgItemText(hwndDlg, IDC_YOURHOST, TranslateT("IP info available only after login"));
            EnableWindow(GetDlgItem(hwndDlg, IDC_YOURHOST), gethst == 1);
        }
        return TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDC_RESETSERVER:
            SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, MSN_DEFAULT_LOGIN_SERVER);
            SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, MSN_DEFAULT_GATEWAY);
            SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            break;
        }

        if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus())
            switch (LOWORD(wParam)) {
            case IDC_DIRECTSERVER:
            case IDC_GATEWAYSERVER:
            case IDC_YOURHOST:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }

        if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_HOSTOPT) {
            unsigned gethst = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);
            EnableWindow(GetDlgItem(hwndDlg, IDC_YOURHOST), gethst == 1);
            SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
        }

        if (HIWORD(wParam) == BN_CLICKED) {
            switch (LOWORD(wParam)) {
            case IDC_SLOWSEND:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;
            }
        }
        break;

    case WM_NOTIFY:
        if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
            char str[MAX_PATH];

            CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

            GetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, str, _countof(str));
            if (mir_strcmp(str, MSN_DEFAULT_LOGIN_SERVER))
                proto->setString("DirectServer", str);
            else
                proto->delSetting("DirectServer");

            GetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, str, _countof(str));
            if (mir_strcmp(str, MSN_DEFAULT_GATEWAY))
                proto->setString("GatewayServer", str);
            else
                proto->delSetting("GatewayServer");

            proto->setByte("SlowSend", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SLOWSEND));
            if (proto->getByte("SlowSend", FALSE)) {
                if (db_get_dw(NULL, "SRMsg", "MessageTimeout", 60000) < 60000 ||
                        db_get_dw(NULL, "SRMM", "MessageTimeout", 60000) < 60000) {
                    MessageBox(NULL, TranslateT("MSN Protocol requires message timeout to be not less then 60 sec. Correct the timeout value."),
                               TranslateT("MSN Protocol"), MB_OK | MB_ICONINFORMATION);
                }
            }

#ifdef OBSOLETE
            unsigned gethst2 = proto->getByte("AutoGetHost", 1);

#endif
            unsigned gethst = SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_GETCURSEL, 0, 0);
            if (gethst < 2) gethst = !gethst;
            proto->setByte("AutoGetHost", (BYTE)gethst);

            if (gethst == 0) {
                GetDlgItemTextA(hwndDlg, IDC_YOURHOST, str, _countof(str));
                proto->setString("YourHost", str);
            }
            else proto->delSetting("YourHost");

#ifdef OBSOLETE
            if (gethst != gethst2)
                proto->ForkThread(&CMsnProto::MSNConnDetectThread, NULL);
#endif

            proto->LoadOptions();
            return TRUE;
        }
    }

    return FALSE;
}
Example #28
0
static INT_PTR CALLBACK DlgProcAccMgrUI(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        TranslateDialogDefault(hwndDlg);
        {
            SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);

            CMsnProto* proto = (CMsnProto*)lParam;
            SetDlgItemTextA(hwndDlg, IDC_HANDLE, proto->MyOptions.szEmail);

            char tBuffer[MAX_PATH];
            if (!db_get_static(NULL, proto->m_szModuleName, "Password", tBuffer, sizeof(tBuffer))) {
                tBuffer[16] = 0;
                SetDlgItemTextA(hwndDlg, IDC_PASSWORD, tBuffer);
            }
            SendDlgItemMessage(hwndDlg, IDC_PASSWORD, EM_SETLIMITTEXT, 16, 0);

            DBVARIANT dbv;
            if (!proto->getTString("Place", &dbv)) {
                SetDlgItemText(hwndDlg, IDC_PLACE, dbv.ptszVal);
                db_free(&dbv);
            }
        }
        return TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDC_NEWMSNACCOUNTLINK) {
            Utils_OpenUrl("https://signup.live.com");
            return TRUE;
        }

        if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
            switch (LOWORD(wParam)) {
            case IDC_HANDLE:
            case IDC_PASSWORD:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
        }
        break;

    case WM_NOTIFY:
        if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
            char  password[100], szEmail[MSN_MAX_EMAIL_LEN];
            DBVARIANT dbv;

            CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

            GetDlgItemTextA(hwndDlg, IDC_HANDLE, szEmail, _countof(szEmail));
            if (mir_strcmp(szEmail, proto->MyOptions.szEmail)) {
                mir_strcpy(proto->MyOptions.szEmail, szEmail);
                proto->setString("e-mail", szEmail);
                proto->setString("wlid", szEmail);
                proto->setDword("netId", (proto->MyOptions.netId = proto->GetMyNetID()));
            }

            GetDlgItemTextA(hwndDlg, IDC_PASSWORD, password, _countof(password));
            if (!proto->getString("Password", &dbv)) {
                if (mir_strcmp(password, dbv.pszVal))
                    proto->setString("Password", password);
                db_free(&dbv);
            }
            else proto->setString("Password", password);

            TCHAR szPlace[64];
            GetDlgItemText(hwndDlg, IDC_PLACE, szPlace, _countof(szPlace));
            if (szPlace[0])
                proto->setTString("Place", szPlace);
            else
                proto->delSetting("Place");

            return TRUE;
        }
        break;
    }

    return FALSE;
}
Example #29
0
void __cdecl CMsnProto::MSNServerThread(void* arg)
{
	ThreadData* info = (ThreadData*)arg;
	if (info->mIsMainThread)
		isConnectSuccess = false;

	int tPortNumber = -1;
	{
		char* tPortDelim = strrchr(info->mServer, ':');
		if (tPortDelim != NULL) {
			*tPortDelim = '\0';
			if ((tPortNumber = atoi(tPortDelim + 1)) == 0)
				tPortNumber = -1;
			else if (usingGateway && !(tPortNumber == 80 || tPortNumber == 443))
				usingGateway = false;
		}
	}

	if (usingGateway) {
		if (info->mServer[0] == 0)
			mir_strcpy(info->mServer, MSN_DEFAULT_LOGIN_SERVER);
		else if (info->mIsMainThread)
			mir_strcpy(info->mGatewayIP, info->mServer);

		if (info->gatewayType)
			mir_strcpy(info->mGatewayIP, info->mServer);
		else {
			if (info->mGatewayIP[0] == 0 && db_get_static(NULL, m_szModuleName, "GatewayServer", info->mGatewayIP, sizeof(info->mGatewayIP)))
				mir_strcpy(info->mGatewayIP, MSN_DEFAULT_GATEWAY);
		}
	}
	else {
		if (info->mServer[0] == 0 && db_get_static(NULL, m_szModuleName, "DirectServer", info->mServer, sizeof(info->mServer)))
			mir_strcpy(info->mServer, MSN_DEFAULT_LOGIN_SERVER);
	}

	NETLIBOPENCONNECTION tConn = { 0 };
	tConn.cbSize = sizeof(tConn);
	tConn.flags = NLOCF_V2;
	tConn.timeout = 5;

	if (usingGateway) {
		tConn.flags |= NLOCF_HTTPGATEWAY;
		tConn.szHost = info->mGatewayIP;
		tConn.wPort = MSN_DEFAULT_GATEWAY_PORT;
	}
	else {
		tConn.flags = NLOCF_SSL;
		tConn.szHost = info->mServer;
		tConn.wPort = MSN_DEFAULT_PORT;
	}
	if (tPortNumber != -1)
		tConn.wPort = (WORD)tPortNumber;

	debugLogA("Thread started: server='%s:%d', type=%d", tConn.szHost, tConn.wPort, info->mType);

	info->s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&tConn);
	if (info->s == NULL) {
		debugLogA("Connection Failed (%d) server='%s:%d'", WSAGetLastError(), tConn.szHost, tConn.wPort);

		switch (info->mType) {
		case SERVER_NOTIFICATION:
			goto LBL_Exit;
			break;

		case SERVER_SWITCHBOARD:
			if (info->mCaller) msnNsThread->sendPacket("XFR", "SB");
			break;
		}
		return;
	}

	if (usingGateway)
		CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(info->s), info->mGatewayTimeout);

	debugLogA("Connected with handle=%08X", info->s);

	if (info->mType == SERVER_NOTIFICATION) 
		info->sendPacketPayload("CNT", "CON", "<connect>%s%s%s<ver>2</ver><agent><os>winnt</os><osVer>5.2</osVer><proc>x86</proc><lcid>en-us</lcid></agent></connect>\r\n",
		*info->mState?"<xfr><state>":"", *info->mState?info->mState:"", *info->mState?"</state></xfr>":"");
	else if (info->mType == SERVER_SWITCHBOARD) {
		info->sendPacket(info->mCaller ? "USR" : "ANS", "%s;%s %s", MyOptions.szEmail, MyOptions.szMachineGuid, info->mCookie);
	}
	else if (info->mType == SERVER_FILETRANS && info->mCaller == 0) {
		info->send("VER MSNFTP\r\n", 12);
	}

	if (info->mIsMainThread) {
		msnNsThread = info;
	}

	debugLogA("Entering main recv loop");
	info->mBytesInData = 0;
	for (;;) {
		int recvResult = info->recv(info->mData + info->mBytesInData, info->mDataSize - info->mBytesInData);
		if (recvResult == SOCKET_ERROR) {
			debugLogA("Connection %08p [%08X] was abortively closed", info->s, GetCurrentThreadId());
			break;
		}

		if (!recvResult) {
			debugLogA("Connection %08p [%08X] was gracefully closed", info->s, GetCurrentThreadId());
			break;
		}

		info->mBytesInData += recvResult;

#ifdef OBSOLETE
		if (info->mCaller == 1 && info->mType == SERVER_FILETRANS) {
			if (MSN_HandleMSNFTP(info, info->mData))
				break;
		}
		else 
#endif
		{
			for (;;) {
				char* peol = strchr(info->mData, '\r');
				if (peol == NULL)
					break;

				int msgLen = (int)(peol - info->mData);
				if (info->mBytesInData < msgLen + 2)
					break;  //wait for full line end

				char msg[1024];
				strncpy_s(msg, info->mData, msgLen);

				if (*++peol != '\n')
					debugLogA("Dodgy line ending to command: ignoring");
				else
					peol++;

				info->mBytesInData -= peol - info->mData;
				memmove(info->mData, peol, info->mBytesInData);
				debugLogA("RECV: %s", msg);

				if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) {
					debugLogA("Invalid command name");
					continue;
				}

				if (info->mType != SERVER_FILETRANS) {
					int handlerResult;
					if (isdigit(msg[0]) && isdigit(msg[1]) && isdigit(msg[2]))   //all error messages
						handlerResult = MSN_HandleErrors(info, msg);
					else
						handlerResult = MSN_HandleCommands(info, msg);

					if (handlerResult) {
						if (info->sessionClosed) goto LBL_Exit;
						info->sendTerminate();
					}
				}
#ifdef OBSOLETE
				else
					if (MSN_HandleMSNFTP(info, msg))
						goto LBL_Exit;
#endif
			}
		}

		if (info->mBytesInData == info->mDataSize) {
			if (!ReallocInfoBuffer(info, info->mDataSize*2)) {
				debugLogA("sizeof(data) is too small: the longest line won't fit");
				break;
			}
		}
	}

LBL_Exit:
	if (info->mIsMainThread) {
		/*
		if (!isConnectSuccess && !usingGateway && m_iDesiredStatus != ID_STATUS_OFFLINE) {
			msnNsThread = NULL;
			usingGateway = true;

			ThreadData* newThread = new ThreadData;
			newThread->mType = SERVER_NOTIFICATION;
			newThread->mIsMainThread = true;

			newThread->startThread(&CMsnProto::MSNServerThread, this);
		}
		else*/ {
			if (hKeepAliveThreadEvt) {
				msnPingTimeout *= -1;
				SetEvent(hKeepAliveThreadEvt);
			}

			if (info->s == NULL)
				ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
			else {
#ifdef OBSOLETE
				p2p_cancelAllSessions();
#endif
				MSN_CloseConnections();
			}

			if (hHttpsConnection) {
				Netlib_CloseHandle(hHttpsConnection);
				hHttpsConnection = NULL;
			}

			MSN_GoOffline();
			msnNsThread = NULL;
		}
	}

	debugLogA("Thread [%08X] ending now", GetCurrentThreadId());
}
Example #30
0
static INT_PTR CALLBACK DlgProcMsnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        TranslateDialogDefault(hwndDlg);
        {
            SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
            CMsnProto* proto = (CMsnProto*)lParam;

            SetDlgItemTextA(hwndDlg, IDC_HANDLE, proto->MyOptions.szEmail);

            char tBuffer[MAX_PATH];
            if (!db_get_static(NULL, proto->m_szModuleName, "Password", tBuffer, sizeof(tBuffer))) {
                tBuffer[16] = 0;
                SetDlgItemTextA(hwndDlg, IDC_PASSWORD, tBuffer);
            }
            SendDlgItemMessage(hwndDlg, IDC_PASSWORD, EM_SETLIMITTEXT, 16, 0);

            HWND wnd = GetDlgItem(hwndDlg, IDC_HANDLE2);
            DBVARIANT dbv;
            if (!proto->getTString("Nick", &dbv)) {
                SetWindowText(wnd, dbv.ptszVal);
                db_free(&dbv);
            }
            EnableWindow(wnd, proto->msnLoggedIn);
            EnableWindow(GetDlgItem(hwndDlg, IDC_MOBILESEND), proto->msnLoggedIn &&
                         proto->getByte("MobileEnabled", 0) && proto->getByte("MobileAllowed", 0));

            CheckDlgButton(hwndDlg, IDC_MOBILESEND, proto->getByte("MobileAllowed", 0) ? BST_CHECKED : BST_UNCHECKED);
            CheckDlgButton(hwndDlg, IDC_SENDFONTINFO, proto->getByte("SendFontInfo", 1) ? BST_CHECKED : BST_UNCHECKED);
            CheckDlgButton(hwndDlg, IDC_MANAGEGROUPS, proto->getByte("ManageServer", 1) ? BST_CHECKED : BST_UNCHECKED);

            int tValue = proto->getByte("RunMailerOnHotmail", 0);
            CheckDlgButton(hwndDlg, IDC_RUN_APP_ON_HOTMAIL, tValue ? BST_CHECKED : BST_UNCHECKED);
            EnableWindow(GetDlgItem(hwndDlg, IDC_MAILER_APP), tValue);
            EnableWindow(GetDlgItem(hwndDlg, IDC_ENTER_MAILER_APP), tValue);

            if (!db_get_static(NULL, proto->m_szModuleName, "MailerPath", tBuffer, sizeof(tBuffer)))
                SetDlgItemTextA(hwndDlg, IDC_MAILER_APP, tBuffer);

            if (!proto->msnLoggedIn) {
                EnableWindow(GetDlgItem(hwndDlg, IDC_MANAGEGROUPS), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS), FALSE);
            }
            else CheckDlgButton(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS, proto->msnOtherContactsBlocked ? BST_CHECKED : BST_UNCHECKED);
        }
        return TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDC_NEWMSNACCOUNTLINK) {
            Utils_OpenUrl("https://signup.live.com");
            return TRUE;
        }

        if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
            switch (LOWORD(wParam)) {
            case IDC_HANDLE:
            case IDC_PASSWORD:
            case IDC_HANDLE2:
            case IDC_GATEWAYSERVER:
            case IDC_YOURHOST:
            case IDC_DIRECTSERVER:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
        }

        if (HIWORD(wParam) == BN_CLICKED) {
            switch (LOWORD(wParam)) {
            case IDC_SENDFONTINFO:
            case IDC_DISABLE_ANOTHER_CONTACTS:
            case IDC_MOBILESEND:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;

            case IDC_MANAGEGROUPS:
                if (IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS)) {
                    if (IDYES == MessageBox(hwndDlg,
                                            TranslateT("Server groups import may change your contact list layout after next login. Do you want to upload your groups to the server?"),
                                            TranslateT("MSN Protocol"), MB_YESNOCANCEL)) {
                        CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
                        proto->MSN_UploadServerGroups(NULL);
                    }
                }
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;

            case IDC_RUN_APP_ON_HOTMAIL:
            {
                BOOL tIsChosen = IsDlgButtonChecked(hwndDlg, IDC_RUN_APP_ON_HOTMAIL);
                EnableWindow(GetDlgItem(hwndDlg, IDC_MAILER_APP), tIsChosen);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENTER_MAILER_APP), tIsChosen);
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
            break;

            case IDC_ENTER_MAILER_APP:
                char szFile[MAX_PATH + 2];
                {
                    HWND tEditField = GetDlgItem(hwndDlg, IDC_MAILER_APP);

                    GetWindowTextA(tEditField, szFile, _countof(szFile));

                    size_t tSelectLen = 0;

                    if (szFile[0] == '\"') {
                        char* p = strchr(szFile + 1, '\"');
                        if (p != NULL) {
                            *p = '\0';
                            memmove(szFile, szFile + 1, mir_strlen(szFile));
                            tSelectLen += 2;
                            goto LBL_Continue;
                        }
                    }

                    char* p = strchr(szFile, ' ');
                    if (p != NULL) *p = '\0';
LBL_Continue:
                    tSelectLen += mir_strlen(szFile);

                    OPENFILENAMEA ofn = { 0 };
                    ofn.lStructSize = sizeof(ofn);
                    ofn.hwndOwner = hwndDlg;
                    ofn.nMaxFile = _countof(szFile);
                    ofn.lpstrFile = szFile;
                    ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
                    if (GetOpenFileNameA(&ofn) != TRUE)
                        break;

                    if (strchr(szFile, ' ') != NULL) {
                        char tmpBuf[MAX_PATH + 2];
                        mir_snprintf(tmpBuf, _countof(tmpBuf), "\"%s\"", szFile);
                        mir_strcpy(szFile, tmpBuf);
                    }

                    SendMessage(tEditField, EM_SETSEL, 0, tSelectLen);
                    SendMessageA(tEditField, EM_REPLACESEL, TRUE, LPARAM(szFile));
                    SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                }
            }
        }
        break;

    case WM_NOTIFY:
        if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
            bool reconnectRequired = false;
            TCHAR screenStr[MAX_PATH];
            char  password[100], szEmail[MSN_MAX_EMAIL_LEN];
            DBVARIANT dbv;

            CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

            GetDlgItemTextA(hwndDlg, IDC_HANDLE, szEmail, _countof(szEmail));
            if (mir_strcmp(_strlwr(szEmail), proto->MyOptions.szEmail)) {
                reconnectRequired = true;
                mir_strcpy(proto->MyOptions.szEmail, szEmail);
                proto->setString("e-mail", szEmail);
                proto->setString("wlid", szEmail);
                proto->setDword("netId", (proto->MyOptions.netId = proto->GetMyNetID()));
            }

            GetDlgItemTextA(hwndDlg, IDC_PASSWORD, password, _countof(password));
            if (!proto->getString("Password", &dbv)) {
                if (mir_strcmp(password, dbv.pszVal)) {
                    reconnectRequired = true;
                    proto->setString("Password", password);
                }
                db_free(&dbv);
            }
            else {
                reconnectRequired = true;
                proto->setString("Password", password);
            }

#ifdef OBSOLETE
            GetDlgItemText(hwndDlg, IDC_HANDLE2, screenStr, _countof(screenStr));
            if (!proto->getTString("Nick", &dbv)) {
                if (mir_tstrcmp(dbv.ptszVal, screenStr))
                    proto->MSN_SendNickname(screenStr);
                db_free(&dbv);
            }
            else proto->MSN_SendNickname(screenStr);

            BYTE mblsnd = IsDlgButtonChecked(hwndDlg, IDC_MOBILESEND) == BST_CHECKED;
            if (mblsnd != proto->getByte("MobileAllowed", 0)) {
                proto->msnNsThread->sendPacket("PRP", "MOB %c", mblsnd ? 'Y' : 'N');
                proto->MSN_SetServerStatus(proto->m_iStatus);
            }

            unsigned tValue = IsDlgButtonChecked(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS);
            if (tValue != proto->msnOtherContactsBlocked && proto->msnLoggedIn) {
                proto->msnOtherContactsBlocked = tValue;
                proto->msnNsThread->sendPacket("BLP", tValue ? "BL" : "AL");
                proto->MSN_ABUpdateAttr(NULL, "MSN.IM.BLP", tValue ? "0" : "1");
                break;
            }
#endif

            proto->setByte("SendFontInfo", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SENDFONTINFO));
            proto->setByte("RunMailerOnHotmail", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_RUN_APP_ON_HOTMAIL));
            proto->setByte("ManageServer", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS));

            GetDlgItemText(hwndDlg, IDC_MAILER_APP, screenStr, _countof(screenStr));
            proto->setTString("MailerPath", screenStr);

            if (reconnectRequired && proto->msnLoggedIn)
                MessageBox(hwndDlg,
                           TranslateT("The changes you have made require you to reconnect to the MSN Messenger network before they take effect"),
                           TranslateT("MSN Options"), MB_OK);

            proto->LoadOptions();
            return TRUE;
        }
        break;
    }

    return FALSE;
}