Esempio n. 1
0
INT_PTR AddContactDialog(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		return 1;
	
	ADDCONTACTSTRUCT *acs = (ADDCONTACTSTRUCT*)mir_alloc(sizeof(ADDCONTACTSTRUCT));
	memcpy(acs, (ADDCONTACTSTRUCT*)lParam, sizeof(ADDCONTACTSTRUCT));
	if (acs->psr) {
		// bad! structures that are bigger than psr will cause crashes if they define pointers within unreachable structural space
		PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)mir_alloc(acs->psr->cbSize);
		memcpy(psr, acs->psr, acs->psr->cbSize);
		psr->nick = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->nick) : mir_a2t((char*)psr->nick);
		psr->firstName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->firstName) : mir_a2t((char*)psr->firstName);
		psr->lastName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->lastName) : mir_a2t((char*)psr->lastName);
		psr->email = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->email) : mir_a2t((char*)psr->email);
		psr->flags = psr->flags & ~PSR_UNICODE | PSR_TCHAR;
		acs->psr = psr;
		/* copied the passed acs structure, the psr structure with, the pointers within that  */
	}

	if (wParam)
		DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs);
	else
		CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs);
	return 0;
}
Esempio n. 2
0
TopButtonInt *CreateButton(TTBButton *but)
{
	TopButtonInt *b = new TopButtonInt;
	b->id = nextButtonId++;

	b->dwFlags = but->dwFlags;

	b->wParamUp = but->wParamUp;
	b->lParamUp = but->lParamUp;
	b->wParamDown = but->wParamDown;
	b->lParamDown = but->lParamDown;

	if (!(b->dwFlags & TTBBF_ISSEPARATOR)) {
		b->bPushed = (but->dwFlags & TTBBF_PUSHED) ? TRUE : FALSE;

		if (but->dwFlags & TTBBF_ISLBUTTON) {
			b->ptszProgram = mir_tstrdup(but->program);
			b->pszService = mir_strdup(TTB_LAUNCHSERVICE);
		}
		else {
			b->ptszProgram = NULL;
			b->pszService = mir_strdup(but->pszService);
		}

		b->pszName = mir_strdup(but->name);

		Icon2button(but, b->hIconHandleUp, b->hIconUp, true);
		Icon2button(but, b->hIconHandleDn, b->hIconDn, false);

		b->ptszTooltipUp = mir_a2t(but->pszTooltipUp);
		b->ptszTooltipDn = mir_a2t(but->pszTooltipDn);
	}
	return b;
}
Esempio n. 3
0
// dialog box for the tokens
static TCHAR *getTokenCategory(TOKENREGISTEREX *tr) {
	if (tr == NULL) {
		return NULL;
	}
	char *cat = NULL;
	char *helpText = mir_strdup(tr->szHelpText);
	if (helpText == NULL) {
		return NULL;
	}
	char *cur = helpText;
	while (*cur != 0) {
		if (*cur == '\t') {
			*cur = 0;
			helpText = ( char* )mir_realloc(helpText, strlen(helpText)+1);

			TCHAR *res = mir_a2t(helpText);
			mir_free(helpText);
			return res;
		}
		cur++;
	}

	TCHAR *res = mir_a2t(helpText);
	mir_free(helpText);
	return res;

}
Esempio n. 4
0
void CAimProto::chat_event(const char* id, const char* sn, int evt, const TCHAR* msg)
{
	TCHAR* idt = mir_a2t(id);
	TCHAR* snt = mir_a2t(sn);

	HANDLE hContact = contact_from_sn(sn);
	TCHAR* nick = hContact ? (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, 
		WPARAM(hContact), GCDNF_TCHAR) : snt;

	GCDEST gcd = { m_szModuleName, { NULL },  evt };
	gcd.ptszID = idt;

	GCEVENT gce = {0};
	gce.cbSize = sizeof(gce);
	gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
	gce.pDest = &gcd;
	gce.ptszNick = nick;
	gce.ptszUID = snt;
	gce.bIsMe = _stricmp(sn, username) == 0;
	gce.ptszStatus = gce.bIsMe ? TranslateT("Me") : TranslateT("Others");
	gce.ptszText = msg;
	gce.time = time(NULL);
	CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

	mir_free(snt);
	mir_free(idt);
}
Esempio n. 5
0
void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old)
{
	// replace % to %% to not interfere with chat color codes
	std::string smessage = message;
	utils::text::replace_all(&smessage, "%", "%%");

	ptrT tid(mir_a2t(id));
	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT ttext(mir_a2t_cp(smessage.c_str(), CP_UTF8));
	ptrT tchat_id(mir_a2t(chat_id));

	GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.ptszText = ttext;
	gce.time = timestamp ? timestamp : ::time(NULL);
	if (id != NULL)
		gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str());
	gce.dwFlags |= GCEF_ADDTOLOG;
	if (is_old) {
		gce.dwFlags |= GCEF_NOTNOTIFY;
		gce.dwFlags &= ~GCEF_ADDTOLOG;
	}
	gce.ptszNick = tnick;
	gce.ptszUID = tid;
	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));

	facy.erase_reader(ChatIDToHContact(chat_id));
}
Esempio n. 6
0
void FacebookProto::RemoveChatContact(const char *chat_id, const char *id)
{
    // We dont want to remove our self-contact from chat. Ever.
    if (!strcmp(id, facy.self_.user_id.c_str()))
        return;

    GCDEST gcd = { m_szModuleName };
    gcd.ptszID = mir_a2t(chat_id);
    gcd.iType  = GC_EVENT_PART;

    GCEVENT gce    = {sizeof(gce)};
    gce.pDest      = &gcd;
    gce.dwFlags    = GC_TCHAR | GCEF_ADDTOLOG;
    //gce.ptszNick   = mir_a2t_cp(name, CP_UTF8);
    gce.ptszUID    = mir_a2t(id);
    gce.ptszNick   = gce.ptszUID;
    gce.time       = ::time(NULL);
    gce.bIsMe      = false;//!strcmp(id, facy.self_.user_id.c_str());

    CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));

    mir_free(const_cast<TCHAR*>(gcd.ptszID));
    mir_free(const_cast<TCHAR*>(gce.ptszNick));
    mir_free(const_cast<TCHAR*>(gce.ptszUID));
}
Esempio n. 7
0
void FacebookProto::AddChatContact(const char *chat_id, const char *id, const char *name)
{
	if (IsChatContact(chat_id, id))
		return;

	ptrT tchat_id(mir_a2t(chat_id));
	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT tid(mir_a2t(id));

	GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_JOIN };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.pDest = &gcd;
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszNick = tnick;
	gce.ptszUID = tid;
	gce.time = ::time(NULL);
	gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str());

	if (gce.bIsMe) {
		gce.ptszStatus = TranslateT("Myself");
	}
	else {
		MCONTACT hContact = ContactIDToHContact(id);
		if (hContact == NULL || getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) != CONTACT_FRIEND)
			gce.ptszStatus = TranslateT("User");
		else {
			gce.ptszStatus = TranslateT("Friend");
		}
	}

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
Esempio n. 8
0
void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message)
{
    GCDEST gcd = { m_szModuleName };
    gcd.ptszID = mir_a2t(chat_id);

    GCEVENT gce  = {sizeof(gce)};
    gce.pDest    = &gcd;
    gce.ptszText = mir_a2t_cp(message,CP_UTF8);
    gce.time     = ::time(NULL);
    gce.dwFlags  = GC_TCHAR;
    gcd.iType  = GC_EVENT_MESSAGE;
    gce.bIsMe = !strcmp(id,facy.self_.user_id.c_str());
    gce.dwFlags  |= GCEF_ADDTOLOG;

    gce.ptszNick = mir_a2t_cp(name,CP_UTF8);
    gce.ptszUID  = mir_a2t(id);

    CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));

    mir_free(const_cast<TCHAR*>(gce.ptszUID));
    mir_free(const_cast<TCHAR*>(gce.ptszNick));
    mir_free(const_cast<TCHAR*>(gce.ptszText));
    mir_free(const_cast<TCHAR*>(gcd.ptszID));


    // Close chat window, if set
    ForkThread( &FacebookProto::MessagingWorker, this, new send_messaging(chat_id, FACEBOOK_SEND_MESSAGE ) );
}
Esempio n. 9
0
void TwitterProto::UpdateChat(const twitter_user &update)
{
	GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.pDest = &gcd;
	gce.bIsMe = (update.username == twit_.get_username());
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszUID = mir_a2t(update.username.c_str());
	//TODO: write code here to replace % with %% in update.status.text (which is a std::string)

	std::string chatText = update.status.text;

	replaceAll(chatText, "%", "%%");

	gce.ptszText = mir_a2t_cp(chatText.c_str(), CP_UTF8);
	//gce.ptszText = mir_a2t_cp(update.status.text.c_str(),CP_UTF8);
	gce.time = static_cast<DWORD>(update.status.time);

	DBVARIANT nick;
	MCONTACT hContact = UsernameToHContact(update.username.c_str());
	if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) {
		gce.ptszNick = mir_a2t(nick.pszVal);
		db_free(&nick);
	}
	else
		gce.ptszNick = mir_a2t(update.username.c_str());

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));

	mir_free(const_cast<TCHAR*>(gce.ptszNick));
	mir_free(const_cast<TCHAR*>(gce.ptszUID));
	mir_free(const_cast<TCHAR*>(gce.ptszText));
}
Esempio n. 10
0
void CSkypeProto::RemoveChatContact(const TCHAR *tchat_id, const char *id, const char *name, bool isKick, const char *initiator)
{
	if (IsMe(id))
		return;

	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT tid(mir_a2t(id));
	ptrT tinitiator(mir_a2t(initiator));

	GCDEST gcd = { m_szModuleName, tchat_id, isKick ? GC_EVENT_KICK : GC_EVENT_PART };
	GCEVENT gce = { sizeof(gce), &gcd };
	if (isKick)
	{
		gce.ptszUID = tid;
		gce.ptszNick = tnick;
		gce.ptszStatus = tinitiator;
		gce.time = time(NULL);
	}
	else
	{
		gce.dwFlags = GCEF_ADDTOLOG;
		gce.ptszNick = tnick;
		gce.ptszUID = tid;
		gce.time = time(NULL);
		gce.bIsMe = IsMe(id);
	}

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
Esempio n. 11
0
void FacebookProto::AddChatContact(const char *chat_id, const char *id, const char *name)
{
    GCDEST gcd = { m_szModuleName };
    gcd.ptszID = mir_a2t(chat_id);
    gcd.iType  = GC_EVENT_JOIN;

    GCEVENT gce    = {sizeof(gce)};
    gce.pDest      = &gcd;
    gce.dwFlags    = GC_TCHAR | GCEF_ADDTOLOG;
    gce.ptszNick   = mir_a2t_cp(name, CP_UTF8);
    gce.ptszUID    = mir_a2t(id);
    gce.time       = ::time(NULL);
    gce.bIsMe      = !strcmp(id, facy.self_.user_id.c_str());

    if (gce.bIsMe)
        gce.ptszStatus = _T("Admin");
    else
        gce.ptszStatus = _T("Normal");

    CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));

    mir_free(const_cast<TCHAR*>(gce.ptszNick));
    mir_free(const_cast<TCHAR*>(gce.ptszUID));
    mir_free(const_cast<TCHAR*>(gcd.ptszID));
}
Esempio n. 12
0
HXML __fastcall XmlGetChildByTag(HXML hXml, LPCSTR key, LPCSTR attrName, LPCTSTR attrValue)
{
	LPTSTR wszKey = mir_a2t(key), wszName = mir_a2t(attrName);
	HXML result = xmlGetChildByAttrValue(hXml, wszKey, wszName, attrValue);
	mir_free(wszKey), mir_free(wszName);
	return result;
}
Esempio n. 13
0
static void	  sttTBButton2MTBBUTTONINFO(TBButton * bi, MTB_BUTTONINFO * mtbi)
{
	// Convert TBButton struct to MTB_BUTTONINFO
	if (!bi || !mtbi) return;
	if (!(bi->tbbFlags&TBBF_ISSEPARATOR))
	{
		mtbi->szButtonName=mir_strdup(bi->pszButtonName);
		mtbi->szService=mir_strdup(bi->pszServiceName);
		mtbi->szButtonID=mir_strdup(bi->pszButtonID);
		mtbi->bPushButton=(bi->tbbFlags&TBBF_PUSHED)?TRUE:FALSE;
		mtbi->szTooltip=mir_a2t(Translate(bi->pszTooltipUp));
		mtbi->szTooltipPressed=mir_a2t(Translate(bi->pszTooltipDn));
		mtbi->bSeparator=SEPARATOR_NOT;
		mtbi->hPrimaryIconHandle=bi->hPrimaryIconHandle;
		mtbi->hSecondaryIconHandle=bi->hSecondaryIconHandle;
		mtbi->lParam=bi->lParam;
	}		
	else
	{
		mtbi->nOrderValue=bi->defPos;
		mtbi->bSeparator= (((bi->tbbFlags & TBBF_FLEXSIZESEPARATOR) == TBBF_FLEXSIZESEPARATOR)? 	SEPARATOR_FLEX :
		((bi->tbbFlags & TBBF_ISSEPARATOR) == TBBF_ISSEPARATOR)? SEPARATOR_FIXED : SEPARATOR_NOT);
	}
	mtbi->bVisible = ((bi->tbbFlags&TBBF_VISIBLE)!=0);
}
Esempio n. 14
0
	OptionsPageData(OPTIONSDIALOGPAGE *src)
	{
		if (src->hInstance != NULL && src->pszTemplate != NULL)
			pDialog = new COptionPageDialog(src->hInstance, (INT_PTR)src->pszTemplate, src->pfnDlgProc, src->dwInitParam);
		else
			pDialog = src->pDialog;
		assert(pDialog != NULL);

		flags = src->flags;
		hLangpack = src->hLangpack;

		if (src->flags & ODPF_UNICODE)
			ptszTitle = mir_tstrdup(src->ptszTitle);
		else
			ptszTitle = mir_a2t(src->pszTitle);

		if (src->flags & ODPF_UNICODE)
			ptszGroup = mir_tstrdup(src->ptszGroup);
		else
			ptszGroup = mir_a2t(src->pszGroup);

		if (src->flags & ODPF_UNICODE)
			ptszTab = mir_tstrdup(src->ptszTab);
		else
			ptszTab = mir_a2t(src->pszTab);
  	}
Esempio n. 15
0
//---------------------------------------------------------------------------
void TfrmAbout::btnPageClick()
{
	HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK);
	const TCHAR* credits = TranslateT("Credits");
	const TCHAR* copyright = TranslateT("Copyright");
	const TCHAR* title;
	const TCHAR* button;
	if (!m_Page) {
		ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE);
		ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW);
		SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWR));
		title = copyright;
		button = credits;
	}
	else {
		ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW);
		ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE);
		SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWL));
		title = credits;
		button = copyright;
	}
	SetWindowText(hCtrl, button);
	TCHAR newTitle[128];
	TCHAR* pszPlug = mir_a2t(__PLUGIN_NAME);
	TCHAR* pszVer = mir_a2t(__VERSION_STRING_DOTS);
	mir_sntprintf(newTitle, _T("%s - %s\nv%s"), pszPlug, title, pszVer);
	mir_free(pszPlug);
	mir_free(pszVer);
	SetDlgItemText(m_hWnd, IDC_HEADERBAR, newTitle);
	InvalidateRect(GetDlgItem(m_hWnd, IDC_HEADERBAR), NULL, 1);
}
Esempio n. 16
0
static INT_PTR NtlmCreateResponseService2( WPARAM wParam, LPARAM lParam )
{
	NETLIBNTLMREQUEST2* req = ( NETLIBNTLMREQUEST2* )lParam;
	if (req->cbSize < sizeof(*req)) return 0;

	char* response;

#ifdef UNICODE
	if (req->flags & NNR_UNICODE)
	{
		response = NtlmCreateResponseFromChallenge(( HANDLE )wParam, req->szChallenge, 
			req->szUserName, req->szPassword, false, req->complete );
	}
	else
	{
		TCHAR *szLogin = mir_a2t((char*)req->szUserName);
		TCHAR *szPassw = mir_a2t((char*)req->szPassword);
		response = NtlmCreateResponseFromChallenge(( HANDLE )wParam, req->szChallenge, 
			szLogin, szPassw, false, req->complete );
		mir_free(szLogin);
		mir_free(szPassw);
	}
#else
	response = NtlmCreateResponseFromChallenge(( HANDLE )wParam, req->szChallenge, 
		req->szUserName, req->szPassword, false, req->complete );
#endif

	return (INT_PTR)response;
}
Esempio n. 17
0
int WhatsAppProto::OnChatOutgoing(WPARAM wParam, LPARAM lParam)
{
	GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
	char *text;
	char *id;

	if (strcmp(hook->pDest->pszModule,m_szModuleName))
		return 0;

	switch(hook->pDest->iType)
	{
	case GC_USER_MESSAGE:
	{
		text = mir_t2a_cp(hook->ptszText,CP_UTF8);
		std::string msg = text;

		id = mir_t2a_cp(hook->pDest->ptszID,CP_UTF8);
		std::string chat_id = id;

		mir_free(text);
		mir_free(id);
	
		if (isOnline()) {
			MCONTACT hContact = this->ContactIDToHContact(chat_id);
			if (hContact)
			{
				debugLogA("**Chat - Outgoing message: %s", text);
				this->SendMsg(hContact, IS_CHAT, msg.c_str());
				
				// #TODO Move to SendMsgWorker, otherwise all messages are "acknowledged" by Miranda

				GCDEST gcd = { m_szModuleName, hook->pDest->ptszID, GC_EVENT_MESSAGE };
				GCEVENT gce = { sizeof(gce), &gcd };
				gce.dwFlags = GCEF_ADDTOLOG;
				gce.ptszNick = mir_a2t(this->nick.c_str());
				gce.ptszUID = mir_a2t(this->jid.c_str());
				gce.time = time(NULL);
				gce.ptszText = hook->ptszText;
				gce.bIsMe = TRUE;
				CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

				mir_free((void*)gce.ptszUID);
				mir_free((void*)gce.ptszNick);
			}
		}
	
		break;
	}

	case GC_USER_LEAVE:
	case GC_SESSION_TERMINATE:
	{
		break;
	}
	}

	return 0;
}
Esempio n. 18
0
static bool LoadOptionsPage(OPTIONSDIALOGPAGE *src, OptionsPageData *dst)
{
	HRSRC hrsrc = FindResourceA(src->hInstance, src->pszTemplate, MAKEINTRESOURCEA(5));
	if (hrsrc == NULL)
		return false;

	HGLOBAL hglb = LoadResource(src->hInstance, hrsrc);
	if (hglb == NULL)
		return false;

	DWORD resSize = SizeofResource(src->hInstance, hrsrc);
	dst->pTemplate = (DLGTEMPLATE*)mir_alloc(resSize);
	memcpy(dst->pTemplate, LockResource(hglb), resSize);
	DlgTemplateExBegin *dte = (struct DlgTemplateExBegin*)dst->pTemplate;
	if (dte->signature == 0xFFFF) {
		//this feels like an access violation, and is according to boundschecker
		//...but it works - for now
		//may well have to remove and sort out the original dialogs
		dte->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER);
		dte->style |= WS_CHILD;
	}
	else {
		dst->pTemplate->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER);
		dst->pTemplate->style |= WS_CHILD;
	}
	dst->dlgProc = src->pfnDlgProc;
	dst->hInst = src->hInstance;
	dst->hwnd = NULL;
	dst->changed = 0;
	dst->height = 0;
	dst->width = 0;
	dst->flags = src->flags;
	dst->hLangpack = src->hLangpack;
	dst->dwInitParam = src->dwInitParam;
	if (src->pszTitle == NULL)
		dst->ptszTitle = NULL;
	else if (src->flags & ODPF_UNICODE)
		dst->ptszTitle = mir_tstrdup(src->ptszTitle);
	else
		dst->ptszTitle = mir_a2t(src->pszTitle);

	if (src->pszGroup == NULL)
		dst->ptszGroup = NULL;
	else if (src->flags & ODPF_UNICODE)
		dst->ptszGroup = mir_tstrdup(src->ptszGroup);
	else
		dst->ptszGroup = mir_a2t(src->pszGroup);

	if (src->pszTab == NULL)
		dst->ptszTab = NULL;
	else if (src->flags & ODPF_UNICODE)
		dst->ptszTab = mir_tstrdup(src->ptszTab);
	else
		dst->ptszTab = mir_a2t(src->pszTab);

	return true;
}
Esempio n. 19
0
void CMsnProto::MSN_GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
{
	size_t tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);

	if (_taccess(pszDest, 0))
		CreateDirectoryTreeT(pszDest);

	size_t tPathLen2 = tPathLen;
	if (hContact != NULL) {
		DBVARIANT dbv;
		if (getString(hContact, "PictContext", &dbv) == 0) {
			char* szAvatarHash = MSN_GetAvatarHash(dbv.pszVal);
			if (szAvatarHash != NULL) {
				TCHAR *sztAvatarHash = mir_a2t(szAvatarHash);
				tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s."), sztAvatarHash);
				mir_free(sztAvatarHash);
				mir_free(szAvatarHash);
			}
			else {
				delSetting(hContact, "PictContext");
				if (cbLen) pszDest[0] = 0;
			}
			db_free(&dbv);
		}
		else if (cbLen)
			pszDest[0] = 0;
	}
	else {
		TCHAR *sztModuleName = mir_a2t(m_szModuleName);
		tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s avatar."), sztModuleName);
		mir_free(sztModuleName);
	}

	if (ext == NULL) {
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("*"));

		bool found = false;
		_tfinddata_t c_file;
		long hFile = _tfindfirst(pszDest, &c_file);
		if (hFile > -1L) {
			do {
				if (_tcsrchr(c_file.name, '.')) {
					mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name);
					found = true;
				}
			}
				while(_tfindnext(hFile, &c_file) == 0);
			_findclose( hFile );
		}

		if (!found) pszDest[0] = 0;
	}
	else {
		tPathLen--;
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext);
	}
}
Esempio n. 20
0
	char* Execute(NetlibConnection *nlc, char *szHost, const char *szProvider, const char *szChallenge, unsigned &complete)
	{
		char *szAuthHdr = NULL;
		bool justCreated = false;
		NetlibUser *nlu = nlc->nlu;

		if (m_hNtlmSecurity) {
			bool newAuth = !m_szProvider || !szProvider || _stricmp(m_szProvider, szProvider);
			newAuth = newAuth || (m_szHost != szHost && (!m_szHost || !szHost || _stricmp(m_szHost, szHost)));
			if (newAuth)
				Destroy();
		}

		if (m_hNtlmSecurity == NULL) {
			char szSpnStr[256] = "";
			if (szHost && _stricmp(szProvider, "Basic")) {
				unsigned long ip = inet_addr(szHost);
				PHOSTENT host = (ip == INADDR_NONE) ? gethostbyname(szHost) : gethostbyaddr((char*)&ip, 4, AF_INET);
				mir_snprintf(szSpnStr, "HTTP/%s", host && host->h_name ? host->h_name : szHost);
				_strlwr(szSpnStr + 5);
				NetlibLogf(nlu, "Host SPN: %s", szSpnStr);
			}
			m_hNtlmSecurity = NetlibInitSecurityProvider(szProvider, szSpnStr[0] ? szSpnStr : NULL);
			if (m_hNtlmSecurity) {
				m_szProvider = mir_strdup(szProvider);
				m_szHost = mir_strdup(szHost);
				justCreated = true;
			}
		}

		if (m_hNtlmSecurity) {
			TCHAR *szLogin = NULL, *szPassw = NULL;

			if (nlu->settings.useProxyAuth) {
				mir_cslock lck(csNetlibUser);
				szLogin = mir_a2t(nlu->settings.szProxyAuthUser);
				szPassw = mir_a2t(nlu->settings.szProxyAuthPassword);
			}

			szAuthHdr = NtlmCreateResponseFromChallenge(m_hNtlmSecurity,
				szChallenge, szLogin, szPassw, true, complete);

			if (!szAuthHdr) {
				NetlibLogf(NULL, "Security login %s failed, user: %S pssw: %S",
					szProvider, szLogin ? szLogin : _T("(no user)"), szPassw ? _T("(exist)") : _T("(no psw)"));
			}
			else if (justCreated)
				proxyAuthList.add(m_szHost, m_szProvider);

			mir_free(szLogin);
			mir_free(szPassw);
		}
		else complete = 1;

		return szAuthHdr;
	}
Esempio n. 21
0
HANDLE RegisterNotification(POPUPNOTIFICATION *notification)
{
 	POPUPTREEDATA *ptd = (POPUPTREEDATA *)mir_alloc(sizeof(POPUPTREEDATA));
	ptd->signature = PopupNotificationData_SIGNATURE;
	ptd->typ = 1;
	ptd->pszTreeRoot = mir_a2t(notification->lpzGroup);
	ptd->pszDescription = mir_a2t(notification->lpzName);
	ptd->notification = *notification;
	if (!ptd->notification.lpzLAction) ptd->notification.lpzLAction = POPUP_ACTION_NOTHING;
	if (!ptd->notification.lpzRAction) ptd->notification.lpzRAction = POPUP_ACTION_DISMISS;
	LoadNotificationSettings(ptd, "PopupNotifications");

	// ugly hack to make reset always possible
	SaveNotificationSettings(ptd,"PopupNotifications");

	FontID fontid = {0};
	fontid.cbSize = sizeof(fontid);
	mir_snprintf(fontid.group, sizeof(fontid.group), PU_FNT_AND_COLOR"/%s", notification->lpzGroup);
	lstrcpyA(fontid.dbSettingsGroup, "PopupNotifications");
	fontid.flags = FIDF_DEFAULTVALID;
	fontid.deffontsettings.charset = DEFAULT_CHARSET;
	fontid.deffontsettings.colour = ptd->notification.colorText;
	fontid.deffontsettings.size = -11;
	lstrcpynA(fontid.deffontsettings.szFace, "MS Shell Dlg", SIZEOF(fontid.deffontsettings.szFace));
	fontid.deffontsettings.style = 0;
	mir_snprintf(fontid.name, SIZEOF(fontid.name), "%s (colors only)", notification->lpzName);
	mir_snprintf(fontid.prefix, SIZEOF(fontid.prefix), "{%s/%s}text", notification->lpzGroup, notification->lpzName);
	fontid.deffontsettings.style = 0;
	FontRegister(&fontid);

	ColourID colourid = {0};
	colourid.cbSize = sizeof(colourid);
	mir_snprintf(colourid.group, sizeof(colourid.group), PU_FNT_AND_COLOR"/%s", notification->lpzGroup);
	lstrcpyA(colourid.dbSettingsGroup, "PopupNotifications");
	mir_snprintf(colourid.name, SIZEOF(colourid.name), "%s (colors only)", notification->lpzName);
	mir_snprintf(colourid.setting, SIZEOF(colourid.setting), "{%s/%s}backColor", notification->lpzGroup, notification->lpzName);
	colourid.defcolour = ptd->notification.colorBack;
	ColourRegister(&colourid);

	char section[MAXMODULELABELLENGTH], setting[MAXMODULELABELLENGTH];
	mir_snprintf(section, sizeof(section), "Popups/%s", notification->lpzGroup);
	mir_snprintf(setting, sizeof(setting), MODULNAME"_%s_%s", notification->lpzGroup, notification->lpzName);

	SKINICONDESC sid = { sizeof(sid) };
	sid.pszSection = section;
	sid.cx = sid.cy = 16;
	sid.pszName = setting;
	sid.pszDescription = notification->lpzName;
	sid.hDefaultIcon = notification->lchIcon;
	Skin_AddIcon(&sid);

	gTreeData.insert(ptd);
	return (HANDLE)ptd;
}
Esempio n. 22
0
void CMsnProto::MSN_GetCustomSmileyFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const char* SmileyName, int type)
{
	size_t tPathLen;

	InitCustomFolders();

	TCHAR* path = (TCHAR*)alloca(cbLen * sizeof(TCHAR));
	if (hCustomSmileyFolder == NULL || FoldersGetCustomPathT(hCustomSmileyFolder, path, (int)cbLen, _T(""))) {
		TCHAR *tmpPath = Utils_ReplaceVarsT(_T("%miranda_userdata%"));
		TCHAR *tszModuleName = mir_a2t(m_szModuleName);
		tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%s\\CustomSmiley"), tmpPath, tszModuleName);
		mir_free(tszModuleName);
		mir_free(tmpPath);
	}
	else {
		_tcscpy(pszDest, path);
		tPathLen = _tcslen(pszDest);
	}

	if (hContact != NULL)
	{
		DBVARIANT dbv = {0};
		if (getTString(hContact, "e-mail", &dbv))
		{
			dbv.type = DBVT_ASCIIZ;
			dbv.ptszVal = (TCHAR*)mir_alloc(11);
			_ui64tot((UINT_PTR)hContact, dbv.ptszVal, 10);
		}

		tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal);
		db_free(&dbv);
	}
	else {
		TCHAR *tszModuleName = mir_a2t(m_szModuleName);
		tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), tszModuleName);
		mir_free(tszModuleName);
	}

	bool exist = _taccess(pszDest, 0) == 0;

	if (type == 0) {
		if (!exist) pszDest[0] = 0;
		return;
	}

	if (!exist)
		CreateDirectoryTreeT(pszDest);

	TCHAR *sztSmileyName = mir_a2t(SmileyName);
	mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s.%s"), sztSmileyName,
		type == MSN_APPID_CUSTOMSMILEY ? _T("png") : _T("gif"));
	mir_free(sztSmileyName);
}
Esempio n. 23
0
// TODO: remove nick?
void TwitterProto::AddChatContact(const char *name, const char *nick)
{
	GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.time = DWORD(time(0));
	gce.ptszNick = mir_a2t(nick ? nick : name);
	gce.ptszUID = mir_a2t(name);
	gce.ptszStatus = _T("Normal");
	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));

	mir_free(const_cast<TCHAR*>(gce.ptszNick));
	mir_free(const_cast<TCHAR*>(gce.ptszUID));
}
Esempio n. 24
0
void CSkypeProto::ChangeChatTopic(const char *chat_id, const char *topic, const char *initiator)
{
	ptrT tchat_id(mir_a2t(chat_id));
	ptrT tname(mir_a2t(initiator));
	ptrT ttopic(mir_utf8decodeT(topic));

	GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_TOPIC };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.ptszUID = tname;
	gce.ptszNick = tname;
	gce.ptszText = ttopic;
	CallService(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
Esempio n. 25
0
INT_PTR registerToken(WPARAM wParam, LPARAM lParam)
{
	DWORD hash;
	int idx;

	TOKENREGISTEREX *newVr = (TOKENREGISTEREX*)lParam;
	if (newVr == NULL || newVr->szTokenString == NULL || newVr->cbSize <= 0)
		return -1;

	if (newVr->flags & TRF_TCHAR) {
		deRegisterToken(newVr->tszTokenString);
		hash = NameHashFunction(newVr->tszTokenString);
	}
	else {
		WCHAR *wtoken = mir_a2t(newVr->szTokenString);
		deRegisterToken(wtoken);
		hash = NameHashFunction(wtoken);
		mir_free(wtoken);
	}

	TokenRegisterEntry *tre = (TokenRegisterEntry*)mir_alloc(sizeof(TokenRegisterEntry));
	if (tre == NULL)
		return -1;

	memcpy(&tre->tr, newVr, newVr->cbSize);
	tre->nameHash = hash;
	if (!mir_tstrcmp(newVr->tszTokenString, _T("alias")))
		log_debugA("alias");

	if (!(newVr->flags & TRF_PARSEFUNC) && newVr->szService != NULL)
		tre->tr.szService = mir_strdup(newVr->szService);

	if (newVr->flags & TRF_TCHAR)
		tre->tr.tszTokenString = mir_tstrdup(newVr->tszTokenString);
	else
		tre->tr.tszTokenString = mir_a2t(newVr->szTokenString);

	if (newVr->szHelpText != NULL)
		tre->tr.szHelpText = mir_strdup(newVr->szHelpText);

	if ((newVr->flags & TRF_CLEANUP) && !(newVr->flags & TRF_CLEANUPFUNC) && newVr->szCleanupService != NULL)
		tre->tr.szCleanupService = mir_strdup(newVr->szCleanupService);

	mir_cslock lck(csRegister);
	List_GetIndex((SortedList*)&tokens, tre, &idx);
	List_Insert((SortedList*)&tokens, tre, idx);
	return 0;
}
Esempio n. 26
0
static void GetObjectSummary(DBEVENTINFO *dbei, TCHAR* str, int cbStr)
{
	TCHAR* pszSrc, *pszTmp = NULL;

	switch(dbei->eventType) {
	case EVENTTYPE_MESSAGE:
		if (dbei->flags & DBEF_SENT) pszSrc = TranslateT("Outgoing message");
		else                         pszSrc = TranslateT("Incoming message");
		break;

	case EVENTTYPE_URL:
		if (dbei->flags & DBEF_SENT) pszSrc = TranslateT("Outgoing URL");
		else                         pszSrc = TranslateT("Incoming URL");
		break;

	case EVENTTYPE_FILE:
		if (dbei->flags & DBEF_SENT) pszSrc = TranslateT("Outgoing file");
		else                         pszSrc = TranslateT("Incoming file");
		break;

	default:
		DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType);
		if (et && (et->flags & DETF_HISTORY)) {
			pszTmp = mir_a2t(et->descr);
			pszSrc = TranslateTS(pszTmp);
			break;
		}
		*str = 0;
		return;
	}

	_tcsncpy(str, (const TCHAR*)pszSrc, cbStr);
	str[cbStr-1] = 0;
	mir_free(pszTmp);
}
Esempio n. 27
0
static TCHAR* a2tf(const TCHAR* str, bool unicode)
{
	if (str == NULL)
		return NULL;

	return unicode ? mir_tstrdup(str) : mir_a2t((char*)str);
}
Esempio n. 28
0
void CMsnProto::MSN_ChatStart(ThreadData* info)
{
	if (info->mChatID[0] != 0)
		return;

	MSN_StartStopTyping(info, false);

	NotifyEventHooks(hInitChat, (WPARAM)info, 0);

	// add all participants onto the list
	GCDEST gcd = { m_szModuleName, { NULL }, GC_EVENT_JOIN };
	gcd.ptszID = info->mChatID;

	GCEVENT gce = {0};
	gce.cbSize = sizeof(GCEVENT);
	gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
	gce.pDest = &gcd;
	gce.ptszStatus = TranslateT("Others");
	gce.time = time(NULL);
	gce.bIsMe = FALSE;

	for (int j=0; j < info->mJoinedContactsWLID.getCount(); j++) 
	{
		HANDLE hContact = MSN_HContactFromEmail(info->mJoinedContactsWLID[j]);
		TCHAR *wlid = mir_a2t(info->mJoinedContactsWLID[j]);

		gce.ptszNick = GetContactNameT(hContact);
		gce.ptszUID = wlid;
		CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

		mir_free(wlid);
	}	
}
Esempio n. 29
0
HXML __fastcall XmlGetChild(HXML hXml, LPCSTR key)
{
	LPTSTR wszKey = mir_a2t(key);
	HXML result = xmlGetNthChild(hXml, wszKey, 0);
	mir_free(wszKey);
	return result;
}
CContactCache::CContactCache(const HANDLE hContact)
{
	ZeroMemory(this, sizeof(CContactCache));

	m_Valid = m_isMeta = false;
	m_hContact = hContact;
	m_wOldStatus = m_wStatus = m_wMetaStatus = ID_STATUS_OFFLINE;

	m_szStatusMsg = m_ListeningInfo = m_xStatusMsg = 0;
	m_nMax = 0;

	if(hContact) {
		m_szProto = reinterpret_cast<char *>(::CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)m_hContact, 0));
		if(m_szProto)
			m_tszProto = mir_a2t(m_szProto);
		initPhaseTwo();
	}
	else {
		m_szProto = C_INVALID_PROTO;
		m_tszProto = C_INVALID_PROTO_T;
		m_szAccount = C_INVALID_ACCOUNT;
		m_isMeta = false;
		m_Valid = false;
	}
}