Esempio n. 1
0
int SaveSessionDate()
{
	if (session_list[0]!=0)
	{
		int TimeSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, NULL, 0);
		TCHAR *szTimeBuf = (TCHAR*)mir_alloc((TimeSize+1)*sizeof(TCHAR));

		GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, szTimeBuf, TimeSize);

		int DateSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0);
		TCHAR *szDateBuf = (TCHAR*)mir_alloc((DateSize+1)*sizeof(TCHAR));

		GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, szDateBuf, DateSize );
		int lenn = (DateSize+TimeSize+5);
		TCHAR *szSessionTime = (TCHAR*)mir_alloc(lenn*sizeof(TCHAR));
		mir_sntprintf(szSessionTime, lenn, _T("%s - %s"), szTimeBuf, szDateBuf);

		char szSessionDate[256];
		DBVARIANT  dbv = {0};
		mir_snprintf(szSessionDate, SIZEOF(szSessionDate), "%s_%d", "SessionDate", 0);
		db_get_ts(NULL, MODNAME, szSessionDate, &dbv);
		TCHAR *szSessionDateBuf_1 = mir_tstrdup(dbv.ptszVal);
		db_free(&dbv);

		db_set_ts(NULL, MODNAME, szSessionDate, szSessionTime);
		mir_free(szSessionTime);
		ResaveSettings("SessionDate", 1, ses_limit, szSessionDateBuf_1);

		if (szTimeBuf)
			mir_free(szTimeBuf);
		if (szDateBuf)
			mir_free(szDateBuf);
	}
	if (g_bCrashRecovery)
		db_set_b(NULL, MODNAME, "lastSaveCompleted", 1);
	return 0;
}
Esempio n. 2
0
int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam)
{
	DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;

	char *szProto = GetContactProto(hContact);
	if(hContact == NULL || mir_strcmp(cws->szSetting,"Status")) return 0;
	if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM)) {
		int newStatus = cws->value.wVal;
		int oldStatus = db_get_w(hContact,"UserOnline","OldStatus",ID_STATUS_OFFLINE);
		
		if (newStatus != oldStatus && hContact != NULL && newStatus != ID_STATUS_OFFLINE) {
			DBVARIANT dbv;
			if (!db_get_ts(hContact, modname, "PounceMsg", &dbv) && (dbv.ptszVal[0] != '\0')) {
				// check my status
				if (statusCheck(db_get_w(hContact, modname, "SendIfMyStatusIsFLAG", 0), CallProtoService(szProto, PS_GETSTATUS,0,0)) 
				// check the contacts status
				&& statusCheck(db_get_w(hContact, modname, "SendIfTheirStatusIsFLAG", 0), newStatus)) {
					// check if we r giving up after x days
					if (CheckDate(hContact)) {
						if (db_get_w(hContact, modname, "ConfirmTimeout", 0)) {
							SendPounceDlgProcStruct *spdps = (SendPounceDlgProcStruct *)mir_alloc(sizeof(SendPounceDlgProcStruct));
							TCHAR *message = mir_tstrdup(dbv.ptszVal); // will get free()ed in the send confirm window proc
							spdps->hContact = hContact;
							spdps->message = message;
							CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONFIRMSEND), 0, SendPounceDlgProc, (LPARAM)spdps);
							// set the confirmation window to send the msg when the timeout is done
							mir_free(message);
						}
						else SendPounce(dbv.ptszVal, hContact);
					}
				}
				db_free(&dbv);
			}
		}
	}
	return 0;
}
Esempio n. 3
0
static INT_PTR Service_Register(WPARAM, LPARAM lParam)
{
	GCREGISTER *gcr = (GCREGISTER *)lParam;
	if (gcr == NULL)
		return GC_REGISTER_ERROR;

	if (gcr->cbSize != sizeof(GCREGISTER))
		return GC_REGISTER_WRONGVER;

	mir_cslock lck(cs);
	MODULEINFO *mi = ci.MM_AddModule(gcr->pszModule);
	if (mi == NULL)
		return GC_REGISTER_ERROR;

	mi->ptszModDispName = mir_tstrdup(gcr->ptszDispName);
	mi->bBold = (gcr->dwFlags & GC_BOLD) != 0;
	mi->bUnderline = (gcr->dwFlags & GC_UNDERLINE) != 0;
	mi->bItalics = (gcr->dwFlags & GC_ITALICS) != 0;
	mi->bColor = (gcr->dwFlags & GC_COLOR) != 0;
	mi->bBkgColor = (gcr->dwFlags & GC_BKGCOLOR) != 0;
	mi->bAckMsg = (gcr->dwFlags & GC_ACKMSG) != 0;
	mi->bChanMgr = (gcr->dwFlags & GC_CHANMGR) != 0;
	mi->bSingleFormat = (gcr->dwFlags & GC_SINGLEFORMAT) != 0;
	mi->bFontSize = (gcr->dwFlags & GC_FONTSIZE) != 0;
	mi->iMaxText = gcr->iMaxText;
	mi->nColorCount = gcr->nColors;
	if (gcr->nColors > 0) {
		mi->crColors = (COLORREF *)mir_alloc(sizeof(COLORREF)* gcr->nColors);
		memcpy(mi->crColors, gcr->pColors, sizeof(COLORREF)* gcr->nColors);
	}

	mi->pszHeader = ci.Log_CreateRtfHeader(mi);

	CheckColorsInModule((char*)gcr->pszModule);
	ci.SetAllOffline(TRUE, gcr->pszModule);
	return 0;
}
Esempio n. 4
0
int __cdecl CAimProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename)
{
	file_transfer *ft = (file_transfer*)hTransfer;
	if (!ft_list.find_by_ft(ft)) return 0;

	switch (*action)
	{
	case FILERESUME_RESUME:
		{
			struct _stati64 statbuf;
			_tstati64(ft->pfts.tszCurrentFile, &statbuf);
			ft->pfts.currentFileProgress = statbuf.st_size;
		}
		break;

	case FILERESUME_RENAME:
		mir_free(ft->pfts.tszCurrentFile);
		ft->pfts.tszCurrentFile = mir_tstrdup(*szFilename);
		break;

	case FILERESUME_OVERWRITE:
		ft->pfts.currentFileProgress = 0;
		break;

	case FILERESUME_SKIP:
		mir_free(ft->pfts.tszCurrentFile);
		ft->pfts.tszCurrentFile = NULL;
		break;

	default:
		aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, true, ft->max_ver);
		break;
	}
	SetEvent(ft->hResumeEvent);

	return 0;
}
Esempio n. 5
0
BOOL CJabberProto::DBCheckIsTransportedContact(const TCHAR *jid, MCONTACT hContact)
{
	// check if transport is already set
	if (!jid || !hContact)
		return FALSE;

	// strip domain part from jid
	TCHAR *domain  = _tcschr((TCHAR*)jid, '@');
	BOOL   isAgent = (domain == NULL) ? TRUE : FALSE;
	BOOL   isTransported = FALSE;
	if (domain != NULL)
		domain = NEWTSTR_ALLOCA(domain+1);
	else
		domain = NEWTSTR_ALLOCA(jid);

	TCHAR *resourcepos = _tcschr(domain, '/');
	if (resourcepos != NULL)
		*resourcepos = '\0';

	for (int i=0; i < SIZEOF(TransportProtoTable); i++)
		if (MatchMask(domain, TransportProtoTable[i].mask)) {
			GetTransportStatusIconIndex(GetTransportProtoID(domain), ID_STATUS_OFFLINE);
			isTransported = TRUE;
			break;
		}

	if (m_lstTransports.getIndex(domain) == -1 && isAgent) {
		m_lstTransports.insert( mir_tstrdup(domain));
		setByte(hContact, "IsTransport", 1);
	}

	if (isTransported) {
		setTString(hContact, "Transport", domain);
		setByte(hContact, "IsTransported", 1);
	}
	return isTransported;
}
int JabberMenuRosterAdd( WPARAM wParam, LPARAM lParam )
{
	DBVARIANT dbv;
	if ( !wParam ) return 0; // we do not add ourself to the roster. (buggy situation - should not happen)
	if ( !JGetStringT( ( HANDLE ) wParam, "ChatRoomID", &dbv )) {
		TCHAR *roomID = mir_tstrdup(dbv.ptszVal);
		JFreeVariant( &dbv );
		if ( JabberListGetItemPtr( LIST_ROSTER, roomID ) == NULL ) {
			TCHAR *nick = 0;
			TCHAR *group = 0;
			if ( !DBGetContactSettingTString( ( HANDLE ) wParam, "CList", "Group", &dbv ) ) {
				group = mir_tstrdup(dbv.ptszVal);
				JFreeVariant( &dbv );
			}
			if ( !JGetStringT( ( HANDLE ) wParam, "Nick", &dbv ) ) {
				nick = mir_tstrdup(dbv.ptszVal);
				JFreeVariant( &dbv );
			}
			JabberAddContactToRoster(roomID, nick, group, SUB_NONE);
			if ( JGetByte( "AddRoster2Bookmarks", TRUE ) == TRUE ) {

				JABBER_LIST_ITEM* item = NULL;
				
				item = JabberListGetItemPtr(LIST_BOOKMARK, roomID);
				if (!item) {
					item = ( JABBER_LIST_ITEM* )mir_alloc( sizeof( JABBER_LIST_ITEM ));
					ZeroMemory( item, sizeof( JABBER_LIST_ITEM ));
					item->jid = mir_tstrdup(roomID);
					item->name = mir_tstrdup(nick);
					if ( !JGetStringT( ( HANDLE ) wParam, "MyNick", &dbv ) ) {
						item->nick = mir_tstrdup(dbv.ptszVal);
						JFreeVariant( &dbv );
					}
					JabberAddEditBookmark(NULL, (LPARAM) item);
					mir_free(item);
				}
			}
			if (nick) mir_free(nick);
			if (nick) mir_free(group);
		}
		mir_free(roomID);
	}
	return 0;
}
Esempio n. 7
0
// mir_free() the return value
TCHAR *MakeRunCommand(BOOL fMirExe,BOOL fFixedDbProfile)
{
	TCHAR szDbFile[MAX_PATH], szExe[MAX_PATH], *pszFmt;
	if (fFixedDbProfile) {
		if ( CallService(MS_DB_GETPROFILENAMET, _countof(szDbFile), (LPARAM)szDbFile))
			return NULL;
		TCHAR *p = _tcsrchr(szDbFile, '.');
		if (p)
			*p = 0;
	}
	else mir_tstrcpy(szDbFile, _T("%1")); /* buffer safe */

	if ( !GetModuleFileName(fMirExe ? NULL : hInst, szExe, _countof(szExe)))
		return NULL;

	if (fMirExe)
		/* run command for miranda32.exe */
			pszFmt = _T("\"%s\" \"/profile:%s\"");
	else {
		/* run command for rundll32.exe calling WaitForDDE */
		pszFmt = _T("rundll32.exe %s,WaitForDDE \"/profile:%s\"");
		/* ensure the command line is not too long */ 
		GetShortPathName(szExe, szExe, _countof(szExe));
		/* surround by quotes if failed */
		size_t len = mir_tstrlen(szExe);
		if ( _tcschr(szExe,_T(' ')) != NULL && (len+2) < _countof(szExe)) {
			memmove(szExe, szExe+1, (len+1)*sizeof(TCHAR));
			szExe[len+2] = szExe[0] = _T('\"');
			szExe[len+3] = 0;
		}
	}

	TCHAR tszBuffer[1024];
	mir_sntprintf(tszBuffer, pszFmt, szExe, szDbFile);
	return mir_tstrdup(tszBuffer);
}
Esempio n. 8
0
void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notification) {
	if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM))
		return;

	std::stringstream text;
	text << notification->text << "\n\n" << PrepareUrl(notification->link);

	std::string message = text.str();
	utils::text::replace_all(&message, "%", "%%");

	ptrT idT(mir_tstrdup(_T(FACEBOOK_NOTIFICATIONS_CHATROOM)));
	ptrT messageT(mir_a2t_cp(message.c_str(), CP_UTF8));

	GCDEST gcd = { m_szModuleName, _T(FACEBOOK_NOTIFICATIONS_CHATROOM), GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.ptszText = messageT;
	gce.time = notification->time ? notification->time : ::time(NULL);
	gce.bIsMe = false;
	gce.dwFlags |= GCEF_ADDTOLOG;
	gce.ptszNick = TranslateT("Notifications");
	gce.ptszUID = idT;

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
Esempio n. 9
0
int  SkinOptionList_AddSkin(OPTTREE_OPTION* &options, int *OptionsCount, int pos, DWORD *dwGlobalOptions) {
	const PopupSkin *skin = 0;
	if (skin = skins.getSkin(PopupOptions.SkinPack)) {
		for (int i = 1; i <= 10; i++) {
			if (!skin->getFlagName(i))
				continue;
			*OptionsCount += 1;
			options = (OPTTREE_OPTION*)mir_realloc(options, sizeof(OPTTREE_OPTION)*(*OptionsCount));
			options[pos].dwFlag = (DWORD)(1 << (i - 1));
			options[pos].groupId = OPTTREE_CHECK;
			options[pos].iconIndex = 0;
			options[pos].pszSettingName = mir_tstrdup(_T("Skin options"));
			options[pos].pszOptionName = (LPTSTR)mir_alloc(sizeof(TCHAR)*(
				mir_tstrlen(options[pos].pszSettingName) +
				mir_strlen(skin->getFlagName(i)) + 10));
			wsprintf(options[pos].pszOptionName, _T("%s/%hs"), options[pos].pszSettingName, skin->getFlagName(i)); // !!!!!!!!!!!!!
			options[pos].bState = skin->getFlag(i) ? TRUE : FALSE;
			options[pos].Data = i;	// skin flag index
			*dwGlobalOptions |= skin->getFlag(i) ? (1 << (i - 1)) : 0;
			pos++;
		}
	}
	return pos;
}
Esempio n. 10
0
/**
 * Returns the selected text within the active document
 **/
BSTR IEView::getSelection()
{
	BSTR text = NULL;
	IHTMLDocument2 *document = getDocument();
	if (document != NULL) {
		IHTMLSelectionObject *pSelection = NULL;
		if (SUCCEEDED(document->get_selection( &pSelection )) && pSelection != NULL) {
			IDispatch *pDisp = NULL;
			if (SUCCEEDED(pSelection->createRange( &pDisp )) &&  pDisp != NULL) {
				IHTMLTxtRange *pRange = NULL;
				if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLTxtRange, (void**)&pRange))) {
					if (SUCCEEDED(pRange->get_text(&text)))
						text = mir_tstrdup(text);

					pRange->Release();
				}
				pDisp->Release();
			}
			pSelection->Release();
		}
		document->Release();
	}
	return text;
}
Esempio n. 11
0
TCHAR * GetCachedAvatar(char *proto, TCHAR *hash)
{
	TCHAR *ret = NULL;
	TCHAR file[1024] = _T("");
	TCHAR search[1024] = _T("");
	if (opts.log_keep_same_folder)
		GetHistoryFolder(file);
	else
		GetProtocolFolder(file, proto);

	mir_sntprintf(search, MAX_REGS(search), _T("%s\\%s.*"), file, hash);

	WIN32_FIND_DATA finddata;
	HANDLE hFind = FindFirstFile(search, &finddata);
	if (hFind == INVALID_HANDLE_VALUE)
		return NULL;

	do
	{
		size_t len = lstrlen(finddata.cFileName);
		if (len > 4 
			&& (!lstrcmpi(&finddata.cFileName[len-4], _T(".png"))
				|| !lstrcmpi(&finddata.cFileName[len-4], _T(".bmp"))
				|| !lstrcmpi(&finddata.cFileName[len-4], _T(".gif"))
				|| !lstrcmpi(&finddata.cFileName[len-4], _T(".jpg"))
				|| !lstrcmpi(&finddata.cFileName[len-5], _T(".jpeg"))))
		{
			mir_sntprintf(file, MAX_REGS(file), _T("%s\\%s"), file, finddata.cFileName);
			ret = mir_tstrdup(file);
			break;
		}
	} while(FindNextFile(hFind, &finddata));
	FindClose(hFind);

	return ret;
}
Esempio n. 12
0
int fnTrayIconAdd(HWND hwnd, const char *szProto, const char *szIconProto, int status)
{
	initcheck 0;

	mir_cslock lck(trayLockCS);
	int i;
	for (i = 0; i < cli.trayIconCount; i++)
		if (cli.trayIcon[i].id == 0)
			break;

	cli.trayIcon[i].id = TRAYICON_ID_BASE + i;
	cli.trayIcon[i].szProto = (char*)szProto;
	cli.trayIcon[i].hBaseIcon = cli.pfnGetIconFromStatusMode(NULL, szIconProto ? szIconProto : cli.trayIcon[i].szProto, status);

	NOTIFYICONDATA nid = { SIZEOFNID };
	nid.hWnd = hwnd;
	nid.uID = cli.trayIcon[i].id;
	nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	nid.uCallbackMessage = TIM_CALLBACK;
	nid.hIcon = cli.trayIcon[i].hBaseIcon;

	if (cli.shellVersion >= 5)
		nid.uFlags |= NIF_INFO;

	cli.pfnTrayIconMakeTooltip(NULL, cli.trayIcon[i].szProto);
	if (!mToolTipTrayTips)
		mir_tstrncpy(nid.szTip, cli.szTip, SIZEOF(nid.szTip));
	cli.trayIcon[i].ptszToolTip = mir_tstrdup(cli.szTip);

	Shell_NotifyIcon(NIM_ADD, &nid);
	cli.trayIcon[i].isBase = 1;

	if (cli.trayIconCount == 1)
		SetTaskBarIcon(cli.trayIcon[0].hBaseIcon, cli.szTip);
	return i;
}
Esempio n. 13
0
int GGPROTO::gc_event(WPARAM, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK *)lParam;
	GGGC *chat = NULL;
	uin_t uin;

	// Check if we got our protocol, and fields are set
	if (!gch
		|| !gch->pDest
		|| !gch->pDest->ptszID
		|| !gch->pDest->pszModule
		|| mir_strcmpi(gch->pDest->pszModule, m_szModuleName)
		|| !(uin = getDword(GG_KEY_UIN, 0))
		|| !(chat = gc_lookup(gch->pDest->ptszID)))
		return 0;

	// Window terminated (Miranda exit)
	if (gch->pDest->iType == SESSION_TERMINATE)
	{
		debugLog(_T("gc_event(): Terminating chat %x, id %s from chat window..."), chat, gch->pDest->ptszID);
		// Destroy chat entry
		free(chat->recipients);
		list_remove(&chats, chat, 1);

		// Remove contact from contact list (duh!) should be done by chat.dll !!
		for (MCONTACT hContact = db_find_first(); hContact; ) {
			MCONTACT hNext = db_find_next(hContact);
			DBVARIANT dbv;
			if (!getTString(hContact, "ChatRoomID", &dbv)) {
				if (dbv.ptszVal && !mir_tstrcmp(gch->pDest->ptszID, dbv.ptszVal))
					CallService(MS_DB_CONTACT_DELETE, hContact, 0);
				db_free(&dbv);
			}
			hContact = hNext;
		}
		return 1;
	}

	// Message typed / send only if online
	if (isonline() && (gch->pDest->iType == GC_USER_MESSAGE) && gch->ptszText) {
		TCHAR id[32];
		UIN2IDT(uin, id);
		DBVARIANT dbv;

		GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE };
		GCEVENT gce = { sizeof(gce), &gcd };
		gce.ptszUID = id;
		gce.ptszText = gch->ptszText;
		TCHAR* nickT;
		if (!getTString(GG_KEY_NICK, &dbv)){
			nickT = mir_tstrdup(dbv.ptszVal);
			db_free(&dbv);
		}
		else nickT = mir_tstrdup(TranslateT("Me"));
		gce.ptszNick = nickT;

		// Get rid of CRLF at back
		int lc = (int)mir_tstrlen(gch->ptszText) - 1;
		while(lc >= 0 && (gch->ptszText[lc] == '\n' || gch->ptszText[lc] == '\r'))
			gch->ptszText[lc --] = 0;

		gce.time = time(NULL);
		gce.bIsMe = 1;
		gce.dwFlags = GCEF_ADDTOLOG;
		debugLog(_T("gc_event(): Sending conference message to room %s, \"%s\"."), gch->pDest->ptszID, gch->ptszText);
		CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
		mir_free(nickT);
		
		T2Utf pszText_utf8(gch->ptszText);
		gg_EnterCriticalSection(&sess_mutex, "gc_event", 57, "sess_mutex", 1);
		gg_send_message_confer(sess, GG_CLASS_CHAT, chat->recipients_count, chat->recipients, pszText_utf8);
		gg_LeaveCriticalSection(&sess_mutex, "gc_event", 57, 1, "sess_mutex", 1);
		return 1;
	}

	// Privmessage selected
	if (gch->pDest->iType == GC_USER_PRIVMESS)
	{
		MCONTACT hContact = NULL;
		if ((uin = _ttoi(gch->ptszUID)) && (hContact = getcontact(uin, 1, 0, NULL)))
			CallService(MS_MSG_SENDMESSAGE, hContact, 0);
	}
	debugLog(_T("gc_event(): Unhandled event %d, chat %x, uin %d, text \"%s\"."), gch->pDest->iType, chat, uin, gch->ptszText);

	return 0;
}
Esempio n. 14
0
//---------------------------------------------------------------------------
INT_PTR CALLBACK CSend::ResultDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN));
			CSend* self = (CSend*)lParam;
			TCHAR* tmp = mir_tstrdup(TranslateT("Resulting URL from\n"));
			mir_tstradd(tmp, self->m_pszSendTyp);
			SetDlgItemText(hwndDlg, IDC_HEADERBAR, tmp);
			mir_free(tmp);
			SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_BIG, (LPARAM)GetIconBtn(ICO_BTN_ARROWR));
			SetDlgItemTextA(hwndDlg, ID_edtURL, self->m_URL);
			if (self->m_URLthumb) {
				SetDlgItemTextA(hwndDlg, ID_edtURLthumb, self->m_URLthumb);
			}
			else {
				SetDlgItemTextA(hwndDlg, ID_edtURLthumb, "-");
				for (int i = ID_btnThumbCopy; i <= ID_edtURLthumb; ++i) {
					EnableWindow(GetDlgItem(hwndDlg, i), FALSE);
				}
			}
			if (!self->m_pszFileDesc)
				SetDlgItemText(hwndDlg, ID_bvlDesc, self->m_ErrorTitle);
			else
				SetDlgItemText(hwndDlg, ID_bvlDesc, self->m_pszFileDesc);
			SendDlgItemMessage(hwndDlg, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_COPY));
			SendDlgItemMessage(hwndDlg, IDOK, BUTTONTRANSLATE, 0, 0);
			SendDlgItemMessage(hwndDlg, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_CANCEL));
			SendDlgItemMessage(hwndDlg, IDCANCEL, BUTTONTRANSLATE, 0, 0);
			for (int i = ID_btnCopy; i <= ID_btnThumbBBC2; ++i) {
				SendDlgItemMessage(hwndDlg, i, BUTTONSETASTHEMEDBTN, 0, 0);
				SendDlgItemMessage(hwndDlg, i, BUTTONSETASFLATBTN, 1, 0);
				switch (i) {
				case ID_btnCopy:
				case ID_btnThumbCopy:
					SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_COPY));
					SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy"), BATF_TCHAR);
					break;
				case ID_btnBBC:
				case ID_btnThumbBBC:
					SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_BBC));
					SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy BBCode"), BATF_TCHAR);
					break;
				default:
					SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_BBCLNK));
					SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy BBCode w/ link"), BATF_TCHAR);
				}
			}
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			return TRUE;

		case IDOK:
		case ID_btnCopy:
		case ID_btnThumbCopy:
		case ID_btnBBC:
		case ID_btnThumbBBC:
		case ID_btnThumbBBC2:
			TCHAR tmp[2048];
			int edtID = ID_edtURL;
			int bbc = 0;
			switch (LOWORD(wParam)) {
			case ID_btnThumbBBC2: ++bbc;
			case ID_btnThumbBBC: ++bbc;
			case ID_btnThumbCopy:
				edtID = ID_edtURLthumb;
				break;
			case ID_btnBBC: ++bbc;
				break;
			}
			size_t len;
			if (bbc) {
				if (bbc == 1) {
					memcpy(tmp, _T("[img]"), 5 * sizeof(TCHAR)); len = 5;
					len += GetDlgItemText(hwndDlg, edtID, tmp + len, 2048 - 11);
					memcpy(tmp + len, _T("[/img]"), 7 * sizeof(TCHAR)); len += 7;
				}
				else {
					memcpy(tmp, _T("[url="), 5 * sizeof(TCHAR)); len = 5;
					len += GetDlgItemText(hwndDlg, ID_edtURL, tmp + len, 1024);
					memcpy(tmp + len, _T("][img]"), 6 * sizeof(TCHAR)); len += 6;
					len += GetDlgItemText(hwndDlg, edtID, tmp + len, 1024);
					memcpy(tmp + len, _T("[/img][/url]"), 13 * sizeof(TCHAR)); len += 12;
				}
			}
			else
				len = GetDlgItemText(hwndDlg, edtID, tmp, _countof(tmp));
			int retries = 3;
			do {
				if (!OpenClipboard(hwndDlg)) {
					Sleep(100);
					continue;
				}
				EmptyClipboard();
				HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE, len*sizeof(TCHAR) + sizeof(TCHAR));
				TCHAR* tmp2 = (TCHAR*)GlobalLock(clipbuffer);
				mir_tstrncpy(tmp2, tmp, len + 1); tmp2[len] = '\0';
				GlobalUnlock(clipbuffer);
				SetClipboardData(CF_UNICODETEXT, clipbuffer);
				CloseClipboard();
				break;
			} while (--retries);
			
			if (LOWORD(wParam) == IDOK)
				DestroyWindow(hwndDlg);
			return TRUE;
		}
	}
	return FALSE;
}
Esempio n. 15
0
INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
	FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));

	switch (message)
	{

	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwnd);

		proto = reinterpret_cast<FacebookProto*>(lparam);
		SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);

		ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
		if (login != NULL)
			SetDlgItemTextA(hwnd, IDC_UN, login);

		ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
		if (password != NULL)
			SetDlgItemTextA(hwnd, IDC_PW, password);

		if (!proto->isOffline()) {
			SendDlgItemMessage(hwnd, IDC_UN, EM_SETREADONLY, TRUE, 0);
			SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, TRUE, 0);
		}

		SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, FACEBOOK_GROUP_NAME_LIMIT, 0);

		if (proto->m_tszDefaultGroup != NULL)
			SetDlgItemText(hwnd, IDC_GROUP, proto->m_tszDefaultGroup);

		LoadDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, DEFAULT_DISABLE_STATUS_NOTIFY);
		LoadDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS);
		LoadDBCheckState(proto, hwnd, IDC_NAME_AS_NICK, FACEBOOK_KEY_NAME_AS_NICK, DEFAULT_NAME_AS_NICK);

	} return TRUE;

	case WM_COMMAND:
	{
		switch (LOWORD(wparam)) {
		case IDC_NEWACCOUNTLINK:
			proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
			return TRUE;
		case IDC_UN:
		case IDC_PW:
		case IDC_GROUP:
			if (HIWORD(wparam) == EN_CHANGE && (HWND)lparam == GetFocus())
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			break;
		default:
			SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
		}
	} break;

	case WM_NOTIFY:
		if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
		{
			char str[128]; TCHAR tstr[128];

			GetDlgItemTextA(hwnd, IDC_UN, str, _countof(str));
			db_set_s(0, proto->ModuleName(), FACEBOOK_KEY_LOGIN, str);

			GetDlgItemTextA(hwnd, IDC_PW, str, _countof(str));
			proto->setString(FACEBOOK_KEY_PASS, str);

			GetDlgItemText(hwnd, IDC_GROUP, tstr, _countof(tstr));
			if (tstr[0] != '\0')
			{
				proto->m_tszDefaultGroup = mir_tstrdup(tstr);
				proto->setTString(FACEBOOK_KEY_DEF_GROUP, tstr);
				Clist_CreateGroup(0, tstr);
			}
			else {
				proto->delSetting(FACEBOOK_KEY_DEF_GROUP);
				proto->m_tszDefaultGroup = NULL;
			}				

			StoreDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY);
			StoreDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS);
			StoreDBCheckState(proto, hwnd, IDC_NAME_AS_NICK, FACEBOOK_KEY_NAME_AS_NICK);

			return TRUE;
		}
		break;

	}

	return FALSE;
}
Esempio n. 16
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;
}
Esempio n. 17
0
BOOL CJabberProto::OnIqRequestOOB(HXML, CJabberIqInfo *pInfo)
{
	if (!pInfo->GetFrom() || !pInfo->GetHContact())
		return TRUE;

	HXML n = XmlGetChild(pInfo->GetChildNode(), "url");
	if (!n || !XmlGetText(n))
		return TRUE;

	if (m_options.BsOnlyIBB) {
		// reject
		XmlNodeIq iq(_T("error"), pInfo);
		HXML e = XmlAddChild(iq, _T("error"), _T("File transfer refused")); XmlAddAttr(e, _T("code"), 406);
		m_ThreadInfo->send(iq);
		return TRUE;
	}

	filetransfer *ft = new filetransfer(this);
	ft->std.totalFiles = 1;
	ft->jid = mir_tstrdup(pInfo->GetFrom());
	ft->std.hContact = pInfo->GetHContact();
	ft->type = FT_OOB;
	ft->httpHostName = NULL;
	ft->httpPort = 80;
	ft->httpPath = NULL;

	// Parse the URL
	TCHAR *str = (TCHAR*)XmlGetText(n);	// URL of the file to get
	if (!_tcsnicmp(str, _T("http://"), 7)) {
		TCHAR *p = str + 7, *q;
		if ((q = _tcschr(p, '/')) != NULL) {
			TCHAR text[1024];
			if (q - p < _countof(text)) {
				_tcsncpy_s(text, p, q - p);
				text[q - p] = '\0';
				if ((p = _tcschr(text, ':')) != NULL) {
					ft->httpPort = (WORD)_ttoi(p + 1);
					*p = '\0';
				}
				ft->httpHostName = mir_t2a(text);
			}
		}
	}

	if (pInfo->GetIdStr())
		ft->szId = JabberId2string(pInfo->GetIqId());

	if (ft->httpHostName && ft->httpPath) {
		TCHAR *desc = NULL;

		debugLogA("Host=%s Port=%d Path=%s", ft->httpHostName, ft->httpPort, ft->httpPath);
		if ((n = XmlGetChild(pInfo->GetChildNode(), "desc")) != NULL)
			desc = (TCHAR*)XmlGetText(n);

		TCHAR *str2;
		debugLog(_T("description = %s"), desc);
		if ((str2 = _tcsrchr(ft->httpPath, '/')) != NULL)
			str2++;
		else
			str2 = ft->httpPath;
		str2 = mir_tstrdup(str2);
		JabberHttpUrlDecode(str2);

		PROTORECVFILET pre;
		pre.dwFlags = PRFF_TCHAR;
		pre.timestamp = time(NULL);
		pre.descr.t = desc;
		pre.files.t = &str2;
		pre.fileCount = 1;
		pre.lParam = (LPARAM)ft;
		ProtoChainRecvFile(ft->std.hContact, &pre);
		mir_free(str2);
	}
	else {
		// reject
		XmlNodeIq iq(_T("error"), pInfo);
		HXML e = XmlAddChild(iq, _T("error"), _T("File transfer refused")); XmlAddAttr(e, _T("code"), 406);
		m_ThreadInfo->send(iq);
		delete ft;
	}
	return TRUE;
}
Esempio n. 18
0
CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) :
	contList(10, CompareLists),
	grpList(10, CompareId),
	sttThreads(10, PtrKeySortT),
	sessionList(10, PtrKeySortT),
	dcList(10, PtrKeySortT),
	msgQueueList(1),
	msgCache(5, CompareId)
{
	char path[MAX_PATH];

	m_iVersion = 2;
	m_tszUserName = mir_tstrdup(aUserName);
	m_szModuleName = mir_strdup(aProtoName);
	m_szProtoName = mir_strdup(aProtoName);
	_strlwr(m_szProtoName);
	m_szProtoName[0] = (char)toupper(m_szProtoName[0]);

	mir_snprintf(path, sizeof(path), "%s/Status", m_szModuleName);
	MSN_CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)path);

	mir_snprintf(path, sizeof(path), "%s/IdleTS", m_szModuleName);
	MSN_CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)path);

	mir_snprintf(path, sizeof(path), "%s/p2pMsgId", m_szModuleName);
	MSN_CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)path);

	mir_snprintf(path, sizeof(path), "%s/MobileEnabled", m_szModuleName);
	MSN_CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)path);

	mir_snprintf(path, sizeof(path), "%s/MobileAllowed", m_szModuleName);
	MSN_CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)path);

	// Protocol services and events...
	hMSNNudge = CreateProtoEvent("/Nudge");

	CreateProtoService(PS_CREATEACCMGRUI,        &CMsnProto::SvcCreateAccMgrUI);

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

	CreateProtoService(PS_LEAVECHAT,             &CMsnProto::OnLeaveChat);

	CreateProtoService(PS_GETMYAVATART,          &CMsnProto::GetAvatar);
	CreateProtoService(PS_SETMYAVATART,          &CMsnProto::SetAvatar);
	CreateProtoService(PS_GETAVATARCAPS,         &CMsnProto::GetAvatarCaps);

	CreateProtoService(PS_GET_LISTENINGTO,       &CMsnProto::GetCurrentMedia);
	CreateProtoService(PS_SET_LISTENINGTO,       &CMsnProto::SetCurrentMedia);

	CreateProtoService(PS_SETMYNICKNAME,         &CMsnProto::SetNickName);
	CreateProtoService(MSN_SEND_NUDGE,           &CMsnProto::SendNudge);

	CreateProtoService(MSN_GETUNREAD_EMAILCOUNT, &CMsnProto::GetUnreadEmailCount);

	// service to get from protocol chat buddy info
//	CreateProtoService(MS_GC_PROTO_GETTOOLTIPTEXT, &CMsnProto::GCGetToolTipText);

	HookProtoEvent(ME_MSG_WINDOWPOPUP,           &CMsnProto::OnWindowPopup);
//	HookProtoEvent(ME_MSG_WINDOWEVENT,           &CMsnProto::OnWindowEvent);
	HookProtoEvent(ME_CLIST_GROUPCHANGE,         &CMsnProto::OnGroupChange);
	HookProtoEvent(ME_OPT_INITIALISE,            &CMsnProto::OnOptionsInit);
	HookProtoEvent(ME_CLIST_DOUBLECLICKED,       &CMsnProto::OnContactDoubleClicked);
	
	LoadOptions();

	HANDLE hContact = (HANDLE)MSN_CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
	while (hContact != NULL) 
	{
		if (MSN_IsMyContact(hContact))
		{
			deleteSetting(hContact, "Status");
			deleteSetting(hContact, "IdleTS");
			deleteSetting(hContact, "p2pMsgId");
			deleteSetting(hContact, "AccList");
//			DBDeleteContactSetting(hContact, "CList", "StatusMsg");
		}
		hContact = (HANDLE)MSN_CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0);
	}
	deleteSetting(NULL, "MobileEnabled");
	deleteSetting(NULL, "MobileAllowed");

	if (getStaticString(NULL, "LoginServer", path, sizeof(path)) == 0 &&
		(strcmp(path, MSN_DEFAULT_LOGIN_SERVER) == 0 ||
		strcmp(path, MSN_DEFAULT_GATEWAY) == 0))
		deleteSetting(NULL, "LoginServer");

	if (MyOptions.SlowSend)
	{
		if (DBGetContactSettingDword(NULL, "SRMsg", "MessageTimeout", 10000) < 60000) 
			DBWriteContactSettingDword(NULL, "SRMsg", "MessageTimeout", 60000);
		if (DBGetContactSettingDword(NULL, "SRMM", "MessageTimeout", 10000) < 60000) 
			DBWriteContactSettingDword(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"));

	m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;

	MSN_InitThreads();
	Lists_Init();
	MsgQueue_Init();
	P2pSessions_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, sizeof(szDbsettings), "%s_HTTPS", m_szModuleName);
	mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s plugin HTTPS connections"), m_tszUserName);
	hNetlibUserHttps = (HANDLE)MSN_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, SIZEOF(szBuffer), TranslateT("%s plugin connections"), m_tszUserName);
	hNetlibUser = (HANDLE)MSN_CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
}
Esempio n. 19
0
void TreeList_AppendColumn(HTREELISTITEM hItem, TCHAR *text)
{
	hItem->text.insert(mir_tstrdup(text));
	hItem->flags |= TLIF_MODIFIED;
}
Esempio n. 20
0
HMENU BuildRecursiveMenu(HMENU hMenu,ListParam *param)
{
	int i,j;
	MENUITEMINFO mii;
	PMO_MenuItem mi;
	HMENU hSubMenu;
	ListParam localparam;
	TCheckProcParam CheckParam;
	//PIntMenuObject pimo=NULL;
	int pimoidx;

	PMO_IntMenuItem MenuItems=NULL;
	int rootlevel;
	//	int cntFlag;
	int MenuItemsCount;
	char *checkproc=NULL;
	char *onAddproc=NULL;
	char MenuNameItems[256];

	if (param==NULL) return(NULL);
	pimoidx=GetMenuObjbyId(param->MenuObjectHandle);
	if (pimoidx==-1){return(NULL);}
	//pimo=&MenuObjects[pimoidx];

	MenuItems=MenuObjects[pimoidx].MenuItems;
	MenuItemsCount=MenuObjects[pimoidx].MenuItemsCount;
	rootlevel=param->rootlevel;
	//cntFlag=param->cntFlag;
	checkproc=MenuObjects[pimoidx].CheckService;
	onAddproc=MenuObjects[pimoidx].onAddService;

	localparam=*param;
	wsprintfA(MenuNameItems, "%s_Items", MenuObjects[pimoidx].Name);
	/*
	while((rootlevel==-1)&&(GetMenuItemCount(hMenu)>(param->cntFlag==MENU_CUSTOMITEMMAIN?1:0)) )
	DeleteMenu(hMenu,0,MF_BYPOSITION);
	*/
	while((rootlevel==-1)&&GetMenuItemCount(hMenu)>0) DeleteMenu(hMenu,0,MF_BYPOSITION);

	for(j=0;j<MenuItemsCount;j++) {
		mi=&(MenuItems[j].mi);
		if (mi->cbSize!=sizeof(TMO_MenuItem)) continue;

		//
		//		RegisterOneIcon(pimoidx,j);

		if (checkproc!=NULL)	{
			CheckParam.lParam=param->lParam;
			CheckParam.wParam=param->wParam;
			CheckParam.MenuItemOwnerData=mi->ownerdata;
			CheckParam.MenuItemHandle=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);
			if (CallService(checkproc,(WPARAM)&CheckParam,(LPARAM)0)==FALSE)	continue;
		}

		/**************************************/
		if (rootlevel==-1&&mi->root==-1&&MenuObjects[pimoidx].bUseUserDefinedItems) {
			char menuItemName[256];
			char DBString[256];
			DBVARIANT dbv;
			memset(&dbv,0,sizeof(dbv));

			GetMenuItemName( &MenuItems[j], menuItemName, sizeof(menuItemName));

			// check if it visible
			wsprintfA(DBString, "%s_visible", menuItemName);
			if (DBGetContactSettingByte(NULL, MenuNameItems, DBString, -1)==-1)
				DBWriteContactSettingByte(NULL,MenuNameItems, DBString,1);

			MenuItems[j].OverrideShow=TRUE;
			if (!DBGetContactSettingByte(NULL, MenuNameItems, DBString, 1)) {
				MenuItems[j].OverrideShow=FALSE;
				continue;  // find out what value to return if not getting added
			}

			// mi.pszName
			wsprintfA(DBString, "%s_name", menuItemName);
			if (!DBGetContactSettingTString(NULL, MenuNameItems, DBString, &dbv)) {
				if (_tcslen(dbv.ptszVal)>0) {
					if (MenuItems[j].CustomName) mir_free(MenuItems[j].CustomName);
					MenuItems[j].CustomName=mir_tstrdup(dbv.ptszVal);
				}
				if (dbv.ptszVal)	mir_free(dbv.ptszVal);
			}

			wsprintfA(DBString, "%s_pos", menuItemName);
			if (DBGetContactSettingDword(NULL, MenuNameItems, DBString, -1)==-1)
				DBWriteContactSettingDword(NULL,MenuNameItems, DBString,mi->position);

			mi->position = DBGetContactSettingDword(NULL, MenuNameItems, DBString, mi->position);
		}

		/**************************************/

		ZeroMemory(&mii,sizeof(mii));
		i=0;
		//hMenu=hMainMenu;
		mii.cbSize=MENUITEMINFO_V4_SIZE;
		mii.fMask=MIIM_SUBMENU|MIIM_TYPE|MIIM_DATA;
		mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);
		hSubMenu=NULL;

		if (rootlevel!=(int)MenuItems[j].mi.root)
			continue;

		if ((MenuItems[j].mi.flags&CMIF_CHILDPOPUP)||(MenuItems[j].mi.flags&CMIF_ROOTPOPUP))	{
			if (rootlevel==(int)MenuItems[j].mi.root) {
				//our level
				if (MenuItems[j].mi.flags&CMIF_ROOTPOPUP) {
					i=WhereToPlace(hMenu,mi,&mii,&localparam);

					if (!IsWinVer98Plus()) {
						mii.cbSize=MENUITEMINFO_V4_SIZE;
						mii.fMask=MIIM_DATA|MIIM_TYPE|MIIM_ID|MIIM_SUBMENU;
					}
					else {
						mii.cbSize=sizeof(mii);
						mii.fMask=MIIM_DATA|MIIM_ID|MIIM_STRING|MIIM_SUBMENU;
						if (MenuItems[j].iconId!=-1) mii.fMask|=MIIM_BITMAP;
					}

					mii.fType=MFT_STRING;
					//mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);
					mii.dwItemData=MenuItems[j].globalid;

					hSubMenu=CreatePopupMenu();
					mii.hSubMenu=hSubMenu;
					mii.hbmpItem=HBMMENU_CALLBACK;
					mii.dwTypeData=(MenuItems[j].CustomName)?(MenuItems[j].CustomName):(mi->pszName);
#ifdef PUTPOSITIONSONMENU
					if (GetKeyState(VK_CONTROL)&0x8000) {
						TCHAR str[256];
						mir_sntprintf(str,SIZEOF(str),_T("%s (%d,id %x)"),mi->pszName,mi->position,mii.dwItemData);
						mii.dwTypeData=str;
					}
#endif
					InsertMenuItemWithSeparators(hMenu,i,TRUE,&mii,&localparam);
					localparam.rootlevel=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);//MenuItems[j].id|cntFlag;
					BuildRecursiveMenu(hSubMenu,&localparam);

					continue;
				}

				i=WhereToPlace(hMenu,mi,&mii,&localparam);

				if (!IsWinVer98Plus()) {
					mii.cbSize=MENUITEMINFO_V4_SIZE;
					mii.fMask=MIIM_DATA|MIIM_TYPE|MIIM_ID|MIIM_STATE;
				}
				else {
					mii.cbSize=sizeof(mii);
					mii.fMask=MIIM_DATA|MIIM_ID|MIIM_STRING|MIIM_STATE;
					if (MenuItems[j].iconId!=-1) mii.fMask|=MIIM_BITMAP;
				}
				mii.fState=((MenuItems[j].mi.flags&CMIF_GRAYED)?MFS_GRAYED:MFS_ENABLED);
				mii.fState|=((MenuItems[j].mi.flags&CMIF_CHECKED)?MFS_CHECKED:MFS_UNCHECKED);
				mii.fType=MFT_STRING;
				mii.wID=MenuItems[j].id;
				//mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);//MenuItems[j].id|cntFlag;
				mii.dwItemData=MenuItems[j].globalid;

				mii.hbmpItem=HBMMENU_CALLBACK;
				mii.dwTypeData=(MenuItems[j].CustomName)?(MenuItems[j].CustomName):(mi->pszName);
#ifdef PUTPOSITIONSONMENU
				if (GetKeyState(VK_CONTROL)&0x8000) {
					TCHAR str[256];
					mir_sntprintf( str, SIZEOF(str), _T("%s (%d,id %x)"),mi->pszName,mi->position,mii.dwItemData);
					mii.dwTypeData=str;
				}
#endif
				if (onAddproc!=NULL)
					if (CallService(onAddproc,(WPARAM)&mii,(LPARAM)MenuItems[j].globalid)==FALSE)	continue;

				InsertMenuItemWithSeparators(hMenu,i,TRUE,&mii,&localparam);
				continue;
			}
		}
		else {
			//old items - not needed
			if (rootlevel==-1) {
			}
		}
	}
	return hMenu;
}
Esempio n. 21
0
static INT_PTR CALLBACK AccFormDlgProc(HWND hwndDlg,UINT message, WPARAM wParam, LPARAM lParam)
{
	switch( message ) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			PROTOCOLDESCRIPTOR** proto;
			int protoCount, i, cnt = 0;
			Proto_EnumProtocols(( WPARAM )&protoCount, ( LPARAM )&proto );
			for ( i=0; i < protoCount; i++ ) {
				PROTOCOLDESCRIPTOR* pd = proto[i];
				if ( pd->type == PROTOTYPE_PROTOCOL && pd->cbSize == sizeof( *pd )) {
					SendDlgItemMessageA( hwndDlg, IDC_PROTOTYPECOMBO, CB_ADDSTRING, 0, (LPARAM)proto[i]->szName );
					++cnt;
				}
			}
			SendDlgItemMessage( hwndDlg, IDC_PROTOTYPECOMBO, CB_SETCURSEL, 0, 0 );
			EnableWindow( GetDlgItem( hwndDlg, IDOK ), cnt != 0 );

			SetWindowLongPtr( hwndDlg, GWLP_USERDATA, lParam );
			AccFormDlgParam* param = ( AccFormDlgParam* )lParam;

			if ( param->action == PRAC_ADDED ) // new account
				SetWindowText( hwndDlg, TranslateT( "Create new account" ));
			else {
				TCHAR str[200];
				if ( param->action == PRAC_CHANGED ) { // update
					EnableWindow( GetDlgItem( hwndDlg, IDC_PROTOTYPECOMBO ), FALSE );
					mir_sntprintf( str, SIZEOF(str), _T("%s: %s"), TranslateT( "Editing account" ), param->pa->tszAccountName );
				}
				else mir_sntprintf( str, SIZEOF(str), _T("%s: %s"), TranslateT( "Upgrading account" ), param->pa->tszAccountName );

				SetWindowText( hwndDlg, str );
				SetDlgItemText( hwndDlg, IDC_ACCNAME, param->pa->tszAccountName );
				SetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, param->pa->szModuleName );
				SendDlgItemMessageA( hwndDlg, IDC_PROTOTYPECOMBO, CB_SELECTSTRING, -1, (LPARAM)param->pa->szProtoName );

				EnableWindow( GetDlgItem( hwndDlg, IDC_ACCINTERNALNAME ), FALSE );
			}
			SendDlgItemMessage( hwndDlg, IDC_ACCINTERNALNAME, EM_LIMITTEXT, 40, 0 );
		}
		return TRUE;

	case WM_COMMAND:
		switch( LOWORD(wParam)) {
		case IDOK:
			{
				AccFormDlgParam* param = ( AccFormDlgParam* )GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
				PROTOACCOUNT* pa = param->pa;

				if ( param->action == PRAC_ADDED ) {
					char buf[200];
					GetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, buf, SIZEOF( buf ));
					rtrim( buf );
					if ( buf[0] ) {
						for (int i = 0; i < accounts.getCount(); ++i)
							if (_stricmp(buf, accounts[i]->szModuleName) == 0)
								return FALSE;
				}	}

				switch( param->action ) {
				case PRAC_UPGRADED:
					{
						int idx;
						BOOL oldProto = pa->bOldProto;
						TCHAR szPlugin[MAX_PATH];
						mir_sntprintf(szPlugin, SIZEOF(szPlugin), _T("%s.dll"), StrConvT(pa->szProtoName));
						idx = accounts.getIndex(pa);
						UnloadAccount(pa, false, false);
						accounts.remove(idx);
						if (oldProto && UnloadPlugin(szPlugin, SIZEOF(szPlugin))) 
						{
							TCHAR szNewName[MAX_PATH];
							mir_sntprintf(szNewName, SIZEOF(szNewName), _T("%s~"), szPlugin);
							MoveFile(szPlugin, szNewName);
						}
					}
					// fall through

				case PRAC_ADDED:
					pa = (PROTOACCOUNT*)mir_calloc( sizeof( PROTOACCOUNT ));
					pa->cbSize = sizeof( PROTOACCOUNT );
					pa->bIsEnabled = TRUE;
                    pa->bIsVisible = TRUE;
                    
					pa->iOrder = accounts.getCount();
					pa->type = PROTOTYPE_PROTOCOL;
					break;
				}
				{
					TCHAR buf[256];
					GetDlgItemText( hwndDlg, IDC_ACCNAME, buf, SIZEOF( buf ));
					mir_free(pa->tszAccountName);
					pa->tszAccountName = mir_tstrdup( buf );
				}
				if ( param->action == PRAC_ADDED || param->action == PRAC_UPGRADED ) 
                {
					char buf[200];
					GetDlgItemTextA( hwndDlg, IDC_PROTOTYPECOMBO, buf, SIZEOF( buf ));
					pa->szProtoName = mir_strdup( buf );
					GetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, buf, SIZEOF( buf ));
					rtrim( buf );
					if ( buf[0] == 0 ) {
						int count = 1;
						for( ;; ) {
							DBVARIANT dbv;
							mir_snprintf( buf, SIZEOF(buf), "%s_%d", pa->szProtoName, count++ );
							if ( DBGetContactSettingString( NULL, buf, "AM_BaseProto", &dbv ))
								break;
							DBFreeVariant( &dbv );
					}	}
					pa->szModuleName = mir_strdup( buf );

					if ( !pa->tszAccountName[0] ) {
						mir_free(pa->tszAccountName);
						pa->tszAccountName = mir_a2t(buf);
					}

					DBWriteContactSettingString( NULL, pa->szModuleName, "AM_BaseProto", pa->szProtoName );
					accounts.insert( pa );

					if ( ActivateAccount( pa )) {
						pa->ppro->OnEvent( EV_PROTO_ONLOAD, 0, 0 );
						if (!DBGetContactSettingByte(NULL, "CList", "MoveProtoMenus", FALSE))
							pa->ppro->OnEvent( EV_PROTO_ONMENU, 0, 0 );
					}
					else pa->type = PROTOTYPE_DISPROTO;
				}

				WriteDbAccounts();
				NotifyEventHooks( hAccListChanged, param->action, ( LPARAM )pa );

				SendMessage( GetParent(hwndDlg), WM_MY_REFRESH, 0, 0 );
			}

			EndDialog( hwndDlg, TRUE );
			break;

		case IDCANCEL:
			EndDialog( hwndDlg, FALSE );
			break;
		}
	}

	return FALSE;
}
Esempio n. 22
0
static TCHAR *parseTrue(ARGUMENTSINFO *ai)
{
	return (ai->argc != 1) ? NULL : mir_tstrdup(_T(""));
}
	JabberGcLogInviteDlgData(const TCHAR *room):
		newJids(1), room(mir_tstrdup(room)) {}
Esempio n. 24
0
void SetControlHelp(const char *pszDlgId, const char *pszModule, int ctrlId, TCHAR *pszTitle, char *pszText, int type)
{
	int i, j;
	int found = 0;
	void *buf;

	EnterCriticalSection(&csDialogCache);
	j = 0;
	for (i = 0; i < dialogCacheCount; i++) {
		if (lstrcmpA(pszDlgId, dialogCache[i].szId))
			continue;
		for (j = 0; j < dialogCache[i].controlCount; j++) {
			if (ctrlId == dialogCache[i].control[j].id) {
				mir_free(dialogCache[i].control[j].szTitle); // does NULL check
				mir_free(dialogCache[i].control[j].szText); // does NULL check
				dialogCache[i].control[j].szTitle = NULL;
				dialogCache[i].control[j].szText = NULL;
				found = 1;
				break;
			}
		}
		if (!found) {
			buf = (struct DlgControlData*)mir_realloc(dialogCache[i].control, sizeof(struct DlgControlData)*(dialogCache[i].controlCount + 1));
			if (buf == NULL) {
				LeaveCriticalSection(&csDialogCache);
				return;
			}
			dialogCache[i].control = (struct DlgControlData*)buf;
			j = dialogCache[i].controlCount++;
			found = 1;
		}
		break;
	}
	if (!found) {
		buf = (struct DialogData*)mir_realloc(dialogCache, sizeof(struct DialogData)*(dialogCacheCount + 1));
		if (buf == NULL) {
			LeaveCriticalSection(&csDialogCache);
			return;
		}
		dialogCache = (struct DialogData*)buf;
		dialogCache[i].control = (struct DlgControlData*)mir_alloc(sizeof(struct DlgControlData));
		if (dialogCache[i].control == NULL) {
			LeaveCriticalSection(&csDialogCache);
			return;
		}
		dialogCache[i].controlCount = 1;
		i = dialogCacheCount;
		j = 0;

		dialogCache[i].szId = mir_strdup(pszDlgId);
		dialogCache[i].szModule = mir_strdup(pszModule);
		if (dialogCache[i].szId == NULL || dialogCache[i].szModule == NULL) {
			mir_free(dialogCache[i].szId); // does NULL check
			mir_free(dialogCache[i].szModule); // does NULL check
			LeaveCriticalSection(&csDialogCache);
			return;
		}
		dialogCacheCount++;
		dialogCache[i].timeLoaded = 0;
	}
	dialogCache[i].control[j].szTitle = mir_tstrdup(pszTitle); // does NULL arg check
	dialogCache[i].control[j].szText = mir_strdup(pszText); // does NULL arg check
	dialogCache[i].control[j].type = type;
	dialogCache[i].control[j].id = ctrlId;
	dialogCache[i].timeLastUsed = GetTickCount();
	dialogCache[i].changes = 1;
	LeaveCriticalSection(&csDialogCache);
}
void JabberGcLogUpdateMemberStatus( JABBER_LIST_ITEM* item, TCHAR* nick, TCHAR* jid, int action, XmlNode* reason )
{
	int statusToSet = 0;
	TCHAR* szReason = NULL;
	if ( reason != NULL && reason->text != NULL )
		szReason = reason->text;

	TCHAR* myNick = (item->nick == NULL) ? NULL : mir_tstrdup( item->nick );
	if ( myNick == NULL )
		myNick = JabberNickFromJID( jabberJID );

	GCDEST gcd = { jabberProtoName, 0, 0 };
	gcd.ptszID = item->jid;
	GCEVENT gce = {0};
	gce.cbSize = sizeof(GCEVENT);
	gce.ptszNick = nick;
	gce.ptszUID = nick;
	if (jid != NULL)
		gce.ptszUserInfo = jid;
	gce.ptszText = szReason;
	gce.dwFlags = GC_TCHAR;
	gce.pDest = &gcd;
 	if ( item->bChatActive == 2 ) {
		gce.dwFlags |= GCEF_ADDTOLOG;
		gce.time = time(0);
	}

	switch( gcd.iType = action ) {
	case GC_EVENT_PART:  break;
	case GC_EVENT_KICK:  gce.ptszStatus = TranslateT( "Moderator" );  break;
	default:
		for ( int i=0; i < item->resourceCount; i++ ) {
			JABBER_RESOURCE_STATUS& JS = item->resource[i];
			if ( !lstrcmp( nick, JS.resourceName )) {
				if ( action != GC_EVENT_JOIN ) {
					switch( action ) {
					case 0:
						gcd.iType = GC_EVENT_ADDSTATUS;
					case GC_EVENT_REMOVESTATUS:
						gce.dwFlags &= ~GCEF_ADDTOLOG;
					}
					gce.ptszText = TranslateT( "Moderator" );
				}
				gce.ptszStatus = TranslateTS( sttRoles[ JS.role ] );
				gce.bIsMe = ( lstrcmp( nick, myNick ) == 0 );
				statusToSet = JS.status;
				break;
	}	}	}

	JCallService( MS_GC_EVENT, NULL, ( LPARAM )&gce );

	if ( statusToSet != 0 ) {
		gce.ptszText = nick;
		if ( statusToSet == ID_STATUS_AWAY || statusToSet == ID_STATUS_NA || statusToSet == ID_STATUS_DND )
			gce.dwItemData = 3;
		else
			gce.dwItemData = 1;
		gcd.iType = GC_EVENT_SETSTATUSEX;
		JCallService( MS_GC_EVENT, NULL, ( LPARAM )&gce );
	}

	mir_free( myNick );
}
Esempio n. 26
0
////////////////////////////////////////////////////////////////////////////////
// This is main groupchat initialization routine
//
TCHAR* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_count)
{
	list_t l;
	GGGC *chat;
	TCHAR id[32];
	uin_t uin;
	DBVARIANT dbv;
	GCDEST gcd = { m_szModuleName, 0, GC_EVENT_ADDGROUP };
	GCEVENT gce = { sizeof(gce), &gcd };

	debugLogA("gc_getchat(): Count %d.", recipients_count);
	if (!recipients) return NULL;

	// Look for existing chat
	for(l = chats; l; l = l->next)
	{
		chat = (GGGC *)l->data;
		if (!chat) continue;

		if (chat->recipients_count == recipients_count + (sender ? 1 : 0))
		{
			int i, j, found = 0, sok = (sender == 0);
			if (!sok) {
				for (i = 0; i < chat->recipients_count; i++) {
					if (sender == chat->recipients[i])
					{
						sok = 1;
						break;
					}
				}
			}
			if (sok)
				for(i = 0; i < chat->recipients_count; i++)
					for(j = 0; j < recipients_count; j++)
						if (recipients[j] == chat->recipients[i]) found++;
			// Found all recipients
			if (found == recipients_count)
			{
				if (chat->ignore)
					debugLog(_T("gc_getchat(): Ignoring existing id %s, size %d."), chat->id, chat->recipients_count);
				else
					debugLog(_T("gc_getchat(): Returning existing id %s, size %d."), chat->id, chat->recipients_count);
				return !(chat->ignore) ? chat->id : NULL;
			}
		}
	}

	// Make new uin list to chat mapping
	chat = (GGGC *)malloc(sizeof(GGGC));
	UIN2IDT(gc_id ++, chat->id);
	chat->ignore = FALSE;

	// Check groupchat policy (new) / only for incoming
	if (sender)
	{
		int unknown = (getcontact(sender, 0, 0, NULL) == NULL),
			unknownSender = unknown;
		for(int i = 0; i < recipients_count; i++)
			if (!getcontact(recipients[i], 0, 0, NULL))
				unknown ++;
		if ((getWord(GG_KEY_GC_POLICY_DEFAULT, GG_KEYDEF_GC_POLICY_DEFAULT) == 2) ||
		   (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 2 &&
			recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
		   (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 2 &&
			unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN)))
			chat->ignore = TRUE;
		if (!chat->ignore && ((getWord(GG_KEY_GC_POLICY_DEFAULT, GG_KEYDEF_GC_POLICY_DEFAULT) == 1) ||
		   (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 1 &&
			recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
		   (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 1 &&
			unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN))))
		{
			TCHAR *senderName = unknownSender ?
				TranslateT("Unknown") : pcli->pfnGetContactDisplayName(getcontact(sender, 0, 0, NULL), 0);
			TCHAR error[256];
			mir_sntprintf(error, TranslateT("%s has initiated conference with %d participants (%d unknowns).\nDo you want to participate?"),
				senderName, recipients_count + 1, unknown);
			chat->ignore = MessageBox(NULL, error, m_tszUserName, MB_OKCANCEL | MB_ICONEXCLAMATION) != IDOK;
		}
		if (chat->ignore)
		{
			// Copy recipient list
			chat->recipients_count = recipients_count + 1;
			chat->recipients = (uin_t *)calloc(chat->recipients_count, sizeof(uin_t));
			int i = 0;
			for(; i < recipients_count; i++)
				chat->recipients[i] = recipients[i];
			if (sender) chat->recipients[i] = sender;
			debugLog(_T("gc_getchat(): Ignoring new chat %s, count %d."), chat->id, chat->recipients_count);
			list_add(&chats, chat, 0);
			return NULL;
		}
	}

	// Create new chat window
	TCHAR status[256];
	TCHAR *senderName;
	if (sender)
	{
		senderName = pcli->pfnGetContactDisplayName(getcontact(sender, 1, 0, NULL), 0);
		mir_sntprintf(status, TranslateT("%s initiated the conference.") , senderName);
	}
	else
	{
		senderName = NULL;
		mir_sntprintf(status, TranslateT("This is my own conference."));
	}

	GCSESSION gcwindow = { sizeof(gcwindow) };
	gcwindow.iType = GCW_CHATROOM;
	gcwindow.pszModule = m_szModuleName;
	gcwindow.ptszName = sender ? senderName : TranslateT("Conference");
	gcwindow.ptszID = chat->id;
	gcwindow.dwItemData = (UINT_PTR)chat;
	gcwindow.ptszStatusbarText = status;

	// Here we put nice new hash sign
	TCHAR *name = (TCHAR*)calloc(mir_tstrlen(gcwindow.ptszName) + 2, sizeof(TCHAR));
	*name = '#'; mir_tstrcpy(name + 1, gcwindow.ptszName);
	gcwindow.ptszName = name;

	// Create new room
	if (CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM) &gcwindow)) {
		debugLog(_T("gc_getchat(): Cannot create new chat window %s."), chat->id);
		free(name);
		free(chat);
		return NULL;
	}
	free(name);

	gcd.ptszID = chat->id;
	gce.ptszUID = id;
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.time = 0;

	// Add normal group
	gce.ptszStatus = TranslateT("Participants");
	CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
	gcd.iType = GC_EVENT_JOIN;

	// Add myself
	if (uin = getDword(GG_KEY_UIN, 0))
	{
		UIN2IDT(uin, id);

		TCHAR* nickT;
		if (!getTString(GG_KEY_NICK, &dbv)) {
			nickT = mir_tstrdup(dbv.ptszVal);
			db_free(&dbv);
		} else {
			nickT = mir_tstrdup(TranslateT("Me"));
		}
		gce.ptszNick = nickT;

		gce.bIsMe = 1;
		CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
		mir_free(nickT);
		debugLog(_T("gc_getchat(): Myself %s: %s (%s) to the list..."), gce.ptszUID, gce.ptszNick, gce.ptszStatus);
	}
	else debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin);

	// Copy recipient list
	chat->recipients_count = recipients_count + (sender ? 1 : 0);
	chat->recipients = (uin_t *)calloc(chat->recipients_count, sizeof(uin_t));
	int i;
	for(i = 0; i < recipients_count; i++)
		chat->recipients[i] = recipients[i];
	if (sender) chat->recipients[i] = sender;

	// Add contacts
	for(i = 0; i < chat->recipients_count; i++) {
		MCONTACT hContact = getcontact(chat->recipients[i], 1, 0, NULL);
		UIN2IDT(chat->recipients[i], id);
		if (hContact && (name = pcli->pfnGetContactDisplayName(hContact, 0)) != NULL)
			gce.ptszNick = name;
		else
			gce.ptszNick = TranslateT("'Unknown'");
		gce.bIsMe = 0;
		gce.dwFlags = 0;
		debugLog(_T("gc_getchat(): Added %s: %s (%s) to the list..."), gce.ptszUID, gce.ptszNick, gce.ptszStatus);
		CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
	}
	gcd.iType = GC_EVENT_CONTROL;
	CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce);
	CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);

	debugLog(_T("gc_getchat(): Returning new chat window %s, count %d."), chat->id, chat->recipients_count);
	list_add(&chats, chat, 0);
	return chat->id;
}
static BOOL CALLBACK JabberGcLogInviteDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch ( msg ) {
	case WM_INITDIALOG:
		{
			RECT dlgRect, scrRect;
			GetWindowRect( hwndDlg, &dlgRect );
			SystemParametersInfo( SPI_GETWORKAREA, 0, &scrRect, 0 );
			SetWindowPos( hwndDlg, HWND_TOPMOST, (scrRect.right/2)-(dlgRect.right/2), (scrRect.bottom/2)-(dlgRect.bottom/2), 0, 0, SWP_NOSIZE );
			TranslateDialogDefault( hwndDlg );
			SendMessage( hwndDlg, WM_SETICON, ICON_BIG, ( LPARAM )iconBigList[0]);
			SetDlgItemText( hwndDlg, IDC_ROOM, ( TCHAR* )lParam );

			SetWindowLong(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE,
				GetWindowLong(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE)|CLS_HIDEOFFLINE|CLS_CHECKBOXES|CLS_HIDEEMPTYGROUPS|CLS_USEGROUPS|CLS_GREYALTERNATE|CLS_GROUPCHECKBOXES);
			SendMessage(GetDlgItem(hwndDlg, IDC_CLIST), CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP|CLS_EX_TRACKSELECT, 0);
			ResetListOptions(GetDlgItem(hwndDlg, IDC_CLIST));
			FilterList(GetDlgItem(hwndDlg, IDC_CLIST));

			SendDlgItemMessage(hwndDlg, IDC_ADDJID, BUTTONSETASFLATBTN, 0, 0);
			SendDlgItemMessage(hwndDlg, IDC_ADDJID, BM_SETIMAGE, IMAGE_ICON, (LPARAM)iconList[17]);//LoadIconEx("addroster"));

			// use new operator to properly construct LIST object
			JabberGcLogInviteDlgData *data = new JabberGcLogInviteDlgData((TCHAR *)lParam);
			data->room = mir_tstrdup((TCHAR *)lParam);
			SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)data);
		}
		return TRUE;

	case WM_COMMAND:
		switch ( LOWORD( wParam )) {
		case IDC_ADDJID:
			{
				TCHAR buf[JABBER_MAX_JID_LEN];
				GetWindowText(GetDlgItem(hwndDlg, IDC_NEWJID), buf, SIZEOF(buf));
				SetWindowText(GetDlgItem(hwndDlg, IDC_NEWJID), _T(""));

				if (JabberHContactFromJID(buf))
					break;

				JabberGcLogInviteDlgData *data = (JabberGcLogInviteDlgData *)GetWindowLong(hwndDlg, GWL_USERDATA);

				int i;
				for (i = 0; i < data->newJids.getCount(); ++i)
					if (!lstrcmp(data->newJids[i]->jid, buf))
						break;
				if (i != data->newJids.getCount())
					break;

				JabberGcLogInviteDlgJidData *jidData = (JabberGcLogInviteDlgJidData *)mir_alloc(sizeof(JabberGcLogInviteDlgJidData));
				lstrcpy(jidData->jid, buf);
				CLCINFOITEM cii = {0};
				cii.cbSize = sizeof(cii);
				cii.flags = CLCIIF_CHECKBOX;
				mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"), jidData->jid, TranslateT("not on roster"));
				cii.pszText = buf;
				jidData->hItem = SendDlgItemMessage(hwndDlg,IDC_CLIST,CLM_ADDINFOITEM,0,(LPARAM)&cii);
				SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, jidData->hItem, 1);
				data->newJids.insert(jidData);
			}
			break;

		case IDC_INVITE:
			{
				JabberGcLogInviteDlgData *data = (JabberGcLogInviteDlgData *)GetWindowLong(hwndDlg, GWL_USERDATA);
				TCHAR* room = data->room;
				if ( room != NULL ) {
					TCHAR text[256];
					GetDlgItemText( hwndDlg, IDC_REASON, text, SIZEOF( text ));
					HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST);

					// invite users from roster
					for	(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
							hContact;
							hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) {
						char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
						if ( !lstrcmpA(proto, jabberProtoName) && !DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) {
							if (int hItem = SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0)) {
								if ( SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0 )) {
									DBVARIANT dbv={0};
									JGetStringT(hContact, "jid", &dbv);
									if (dbv.ptszVal && ( dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_WCHAR ))
										InviteUser(room, dbv.ptszVal, text);
									JFreeVariant(&dbv);
					}	}	}	}

					// invite others
					for (int i = 0; i < data->newJids.getCount(); ++i)
						if (SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)data->newJids[i]->hItem, 0))
							InviteUser(room, data->newJids[i]->jid, text);
			}	}
			// Fall through
		case IDCANCEL:
		case IDCLOSE:
			DestroyWindow( hwndDlg );
			return TRUE;
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->idFrom == IDC_CLIST) {
			switch (((LPNMHDR)lParam)->code) {
			case CLN_NEWCONTACT:
				FilterList(GetDlgItem(hwndDlg,IDC_CLIST));
				break;
			case CLN_LISTREBUILT:
				FilterList(GetDlgItem(hwndDlg,IDC_CLIST));
				break;
			case CLN_OPTIONSCHANGED:
				ResetListOptions(GetDlgItem(hwndDlg,IDC_CLIST));
				break;
		}	}
		break;

	case WM_CLOSE:
		DestroyWindow( hwndDlg );
		break;

	case WM_DESTROY:
		JabberGcLogInviteDlgData *data = (JabberGcLogInviteDlgData *)GetWindowLong(hwndDlg, GWL_USERDATA);
		delete data;
		break;
	}

	return FALSE;
}
Esempio n. 28
0
int CJabberProto::FileReceiveParse(filetransfer *ft, char* buffer, int datalen)
{
	char* p, *q, *s, *eob;
	int num, code;

	eob = buffer + datalen;
	p = buffer;
	num = 0;
	while (true) {
		if (ft->state == FT_CONNECTING || ft->state == FT_INITIALIZING) {
			for (q = p; q + 1 < eob && (*q != '\r' || *(q + 1) != '\n'); q++);
			if (q + 1 >= eob)
				break;

			ptrA str(mir_strndup(p, size_t(q - p)));
			if (str == NULL) {
				ft->state = FT_ERROR;
				break;
			}

			debugLogA("FT Got: %s", str);
			if (ft->state == FT_CONNECTING) {
				// looking for "HTTP/1.1 200 OK"
				if (sscanf(str, "HTTP/%*d.%*d %d %*s", &code) == 1 && code == 200) {
					ft->state = FT_INITIALIZING;
					ft->std.currentFileSize = -1;
					debugLogA("Change to FT_INITIALIZING");
					ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
				}
			}
			else {	// FT_INITIALIZING
				if (str[0] == '\0') {
					TCHAR *s;
					if ((s = _tcsrchr(ft->httpPath, '/')) != NULL)
						s++;
					else
						s = ft->httpPath;
					ft->std.tszCurrentFile = mir_tstrdup(s);
					JabberHttpUrlDecode(ft->std.tszCurrentFile);
					if (ft->create() == -1) {
						ft->state = FT_ERROR;
						break;
					}
					ft->state = FT_RECEIVING;
					ft->std.currentFileProgress = 0;
					debugLogA("Change to FT_RECEIVING");
				}
				else if ((s = strchr(str, ':')) != NULL) {
					*s = '\0';
					if (!mir_strcmp(str, "Content-Length"))
						ft->std.totalBytes = ft->std.currentFileSize = _atoi64(s + 1);
				}
			}

			q += 2;
			num += (q - p);
			p = q;
		}
		else if (ft->state == FT_RECEIVING) {
			int bufferSize, writeSize;
			__int64 remainingBytes;

			if (ft->std.currentFileProgress < ft->std.currentFileSize) {
				bufferSize = eob - p;
				remainingBytes = ft->std.currentFileSize - ft->std.currentFileProgress;
				if (remainingBytes < bufferSize)
					writeSize = remainingBytes;
				else
					writeSize = bufferSize;
				if (_write(ft->fileId, p, writeSize) != writeSize) {
					debugLogA("_write() error");
					ft->state = FT_ERROR;
				}
				else {
					ft->std.currentFileProgress += writeSize;
					ft->std.totalProgress += writeSize;
					ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std);
					if (ft->std.currentFileProgress == ft->std.currentFileSize)
						ft->state = FT_DONE;
				}
			}
			num = datalen;
			break;
		}
		else break;
	}

	return num;
}
Esempio n. 29
0
int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent)
{
	logmsg("HookedNewEvent1");
	DBEVENTINFO dbe;
	dbe.cbSize = sizeof(dbe);
	dbe.cbBlob = db_event_getBlobSize(hDBEvent);
	if (dbe.cbBlob == -1)
		return 0;

	dbe.pBlob = (PBYTE) malloc(dbe.cbBlob);
	if(db_event_get(hDBEvent,&dbe))
		return 0;

	if (dbe.flags & DBEF_SENT)
	    return 0;

	if (db_get_b(NULL,THIS_MODULE, "messages", DEFAULT_ANNOUNCEMESSAGES)==0)
		return 0;

	if (!(db_get_dw(NULL,THIS_MODULE,"showWhen", DEFAULT_SHOWWHEN)&(1<<(db_get_w(NULL, "CList", "Status", ID_STATUS_OFFLINE)-ID_STATUS_OFFLINE))))
		return 0;
	
	logmsg("HookedNewEvent2");

	TCHAR buf[512];
	_tcsncpy(buf, DEFAULT_MESSAGEFORMAT,_countof(buf));

	DBVARIANT dbv;
	if(!db_get_ts(NULL,THIS_MODULE,"message_format",&dbv)) {
		mir_tstrcpy(buf, dbv.ptszVal);
		db_free(&dbv);
	}

	int i1=-1, i2=-1;
	TCHAR* pbuf = buf;
	while (*pbuf) {
		if (*pbuf=='%') {
			if (*(pbuf+1)=='n') {
				if (i1==-1)
					i1=1;
				else i2=1;
				*(pbuf+1)='s';
			} else if (*(pbuf+1)=='m') {
				if (i1==-1)
					i1=2;
				else i2=2;
				*(pbuf+1)='s';
			} else if (*(pbuf+1)=='l') {
				*pbuf=0x0d;
				*(pbuf+1)=0x0a;
			}
		}
		pbuf++;
	}

	TCHAR *c1 = 0, *c2 = 0;
	if ( i1 == 1 )
		c1 = mir_tstrdup(pcli->pfnGetContactDisplayName(wParam, 0));
	else if ( i1 == 2 )
		c1 = DbGetEventTextT( &dbe, 0 );

	if ( i2 == 1 )
		c2 = mir_tstrdup(pcli->pfnGetContactDisplayName(wParam, 0));
	else if ( i2 == 2 )
		c2 = DbGetEventTextT( &dbe, 0 );

	TCHAR buffer[512];
	mir_sntprintf(buffer, buf, c1, c2);
	ShowOSD(buffer, 0, db_get_dw(NULL,THIS_MODULE, "clr_msg", DEFAULT_CLRMSG), wParam);

	mir_free( c1 );
	mir_free( c2 );
	return 0;
}
Esempio n. 30
0
INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		SendDlgItemMessage(hwnd, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)TranslateT("Enter a string to search the database for"));
		CheckDlgButton(hwnd, IDC_MODNAME, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_SETTINGNAME, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_SETTINGVALUE, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_FOUND, BST_CHECKED);
		SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)));
		SetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA, 0);
		SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
		SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); // taskbar icon
		TranslateDialogDefault(hwnd);
		ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_LIST), 32 | LVS_EX_LABELTIP); // LVS_EX_GRIDLINES
		loadListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
		Utils_RestoreWindowPositionNoMove(hwnd, NULL, modname, "Search_");
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
		case IDC_SEARCH:
			if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA)) // stop the search
				SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
			else {
				TCHAR text[FLD_SIZE];
				TCHAR replace[FLD_SIZE] = {0};

				if (!GetDlgItemText(hwnd, IDC_TEXT, text, _countof(text)) && !IsDlgButtonChecked(hwnd, IDC_EXACT)) break;

                // empty replace is done only for exact match or entire replace
				if (LOWORD(wParam) == IDOK &&
					!GetDlgItemText(hwnd, IDC_REPLACE, replace, _countof(replace)) &&
					(!IsDlgButtonChecked(hwnd, IDC_ENTIRELY) && !IsDlgButtonChecked(hwnd, IDC_EXACT)))
					break;

				if (BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_MODNAME) &&
					BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) &&
					BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE))
					break;

				FindInfo *fi = (FindInfo*)mir_calloc(sizeof(FindInfo));
				if (!fi)
					break;

				fi->hwnd = GetDlgItem(hwnd, IDC_LIST);
				fi->options = (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE) ? F_CASE : 0) |
					(IsDlgButtonChecked(hwnd, IDC_EXACT) ? F_EXACT : 0) |
					(IsDlgButtonChecked(hwnd, IDC_MODNAME) ? F_MODNAME : 0) |
					(IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) ? F_SETNAME : 0) |
					(IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE) ? F_SETVAL : 0);

				if (LOWORD(wParam) == IDOK) {

					if (IsDlgButtonChecked(hwnd, IDC_ENTIRELY))
						fi->options |= F_ENTIRE;

					fi->replace = mir_tstrdup(replace);

					SetDlgItemText(hwnd, IDOK, TranslateT("Stop"));
					EnableWindow(GetDlgItem(hwnd, IDC_SEARCH), 0);

				}
				else {
					SetDlgItemText(hwnd, IDC_SEARCH, TranslateT("Stop"));
					EnableWindow(GetDlgItem(hwnd, IDOK), 0);
				}

				fi->search = mir_tstrdup(text);

				ListView_DeleteAllItems(fi->hwnd);
				SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 1);

				EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0);
				mir_forkthread(FindSettings, fi);
			}
			break;

		case IDCANCEL:
			DestroyWindow(hwnd);
			break;
		}
		break;
	case WM_GETMINMAXINFO:
		{
			MINMAXINFO *mmi = (MINMAXINFO*)lParam;
			mmi->ptMinTrackSize.x = 610;
			mmi->ptMinTrackSize.y = 300;
		}
		return 0;

	case WM_SIZE:
		Utils_ResizeDialog(hwnd, hInst, MAKEINTRESOURCEA(IDD_FIND), FindDialogResize);
		break;

	case WM_NOTIFY:
		if (LOWORD(wParam) != IDC_LIST) break;
	    switch (((NMHDR*)lParam)->code) {
	    case NM_DBLCLK:
			{
				LVHITTESTINFO hti;
				LVITEM lvi;
				HWND hwndResults = GetDlgItem(hwnd, IDC_LIST);
				hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
				if (ListView_SubItemHitTest(hwndResults, &hti) > -1) {
					if (hti.flags&LVHT_ONITEM)
					{
						lvi.mask = LVIF_PARAM;
						lvi.iItem = hti.iItem;
						lvi.iSubItem = 0;
						if (ListView_GetItem(hwndResults, &lvi))
						{
							ItemInfo ii = {0};
							ii.hContact = (MCONTACT)lvi.lParam;
							ListView_GetItemTextA(hwndResults, hti.iItem, 2, ii.module, _countof(ii.module));
							ListView_GetItemTextA(hwndResults, hti.iItem, 3, ii.setting, _countof(ii.setting));
							if (ii.setting[0])
								ii.type = FW_SETTINGNAME;
							else if (ii.module[0])
								ii.type = FW_MODULE;

							SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
						}
					}
				}
				break;
			}

		case LVN_COLUMNCLICK:
			{
				LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
				ColumnsSortParams params;
				params.hList = GetDlgItem(hwnd, IDC_LIST);
				params.column = lv->iSubItem;
				params.last = lastColumn;
				ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
				lastColumn = (params.column == lastColumn) ? -1 : params.column;
				break;
			}
		} // switch
		break;
	case WM_DESTROY:
		ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_LIST));
		saveListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
		Utils_SaveWindowPosition(hwnd, NULL, modname, "Search_");
		break;
	}
	return 0;
}