Пример #1
0
int btTextCmp(void *a, void *b) {                      //printf("btTextCmp\n");
	uint32 slen1, slen2;
	uchar  *s1     = (uchar *)a;
	uchar  *s2     = (uchar *)b;
	s1 = (getSflag(*s1)) ? getTString(s1, &slen1) : getString( s1, &slen1);
	s2 = (getSflag(*s2)) ? getTString(s2, &slen2) : getString( s2, &slen2);
	if (slen1 == slen2) return strncmp((char *)s1, (char *)s2, slen1);
	else {
		int i   = (slen1 < slen2) ? slen1 : slen2;
		int ret = strncmp((char *)s1, (char *)s2, i);
		return (ret == 0) ? ((slen1 < slen2) ? -1 : 1) : ret;
	}
}
Пример #2
0
MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary)
{
	MCONTACT hContact = FindContact(skypename);

	if (!hContact)
	{
		hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
		Proto_AddToContact(hContact, m_szModuleName);

		setString(hContact, SKYPE_SETTINGS_ID, skypename);

		DBVARIANT dbv;
		if (!getTString(SKYPE_SETTINGS_GROUP, &dbv))
		{
			db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
			db_free(&dbv);
		}

		setByte(hContact, "Auth", 1);
		setByte(hContact, "Grant", 1);

		if (isTemporary)
			db_set_b(hContact, "CList", "NotOnList", 1);
	}
	return hContact;
}
Пример #3
0
bool CIrcProto::CList_SetAllOffline(BYTE ChatsToo)
{
	DBVARIANT dbv;

	DisconnectAllDCCSessions(false);

	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		if (isChatRoom(hContact))
			continue;

		if (getByte(hContact, "DCC", 0) != 0) {
			if (ChatsToo)
				setWord(hContact, "Status", ID_STATUS_OFFLINE);
		}
		else if (!getTString(hContact, "Default", &dbv)) {
			setTString(hContact, "Nick", dbv.ptszVal);
			setWord(hContact, "Status", ID_STATUS_OFFLINE);
			db_free(&dbv);
		}
		db_unset(hContact, m_szModuleName, "IP");
		setString(hContact, "User", "");
		setString(hContact, "Host", "");
	}
	return true;
}
Пример #4
0
MCONTACT TwitterProto::AddToClientList(const char *name, const char *status)
{
	// First, check if this contact exists
	MCONTACT hContact = UsernameToHContact(name);
	if (hContact)
		return hContact;

	if (in_chat_)
		AddChatContact(name);

	// If not, make a new contact!
	hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
	if (hContact) {
		if (Proto_AddToContact(hContact, m_szModuleName) == 0) {
			setString(hContact, TWITTER_KEY_UN, name);
			setWord(hContact, "Status", ID_STATUS_ONLINE);
			db_set_utf(hContact, "CList", "StatusMsg", status);

			std::string url = profile_base_url(twit_.get_base_url()) + http::url_encode(name);
			setString(hContact, "Homepage", url.c_str());

			DBVARIANT dbv;
			if (!getTString(TWITTER_KEY_GROUP, &dbv)) {
				db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
				db_free(&dbv);
			}

			return hContact;
		}
		CallService(MS_DB_CONTACT_DELETE, hContact, 0);
	}

	return 0;
}
Пример #5
0
/*
Service: /GetMyAvatar
wParam=(char *)Buffer to file name
lParam=(int)Buffer size
return=0 on success, else on error
*/
INT_PTR __cdecl CYahooProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
{
	TCHAR *buffer = (TCHAR*)wParam;
	int size = (int)lParam;

	debugLogA("[YahooGetMyAvatar]");

	if (buffer == NULL || size <= 0)
		return -1;

	if (!getByte("ShowAvatars", 1))
		return -2;

	DBVARIANT dbv;
	int ret = -3;

	if (getDword("AvatarHash", 0)) {
		if (!getTString("AvatarFile", &dbv)) {
			if (_taccess(dbv.ptszVal, 0) == 0) {
				mir_tstrncpy(buffer, dbv.ptszVal, size - 1);
				buffer[size - 1] = '\0';

				ret = 0;
			}
			db_free(&dbv);
		}
	}

	return ret;
}
Пример #6
0
int CAimProto::get_avatar_filename(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
{
	size_t tPathLen;
	bool found = false;

	init_custom_folders();

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

	if (ext && _taccess(pszDest, 0))
		CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)pszDest);

	size_t tPathLen2 = tPathLen;
	
	DBVARIANT dbv;
	if (getTString(hContact, AIM_KEY_AH, &dbv)) return GAIR_NOAVATAR;
	tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal);
	DBFreeVariant(&dbv);

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

		_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
	{
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext);
		found = _taccess(pszDest, 0) == 0;
	}

	return found ? GAIR_SUCCESS : GAIR_WAITFOR;
}
Пример #7
0
int __cdecl CIrcProto::OnInitUserInfo(WPARAM wParam, LPARAM lParam)
{
	MCONTACT hContact = lParam;
	char *szProto = GetContactProto(hContact);
	if (!hContact || !szProto || mir_strcmpi(szProto, m_szModuleName))
		return 0;

	if (isChatRoom(hContact))
		return 0;

	if (getByte(hContact, "DCC", 0) != 0)
		return 0;

	DBVARIANT dbv;
	if (!getTString(hContact, "Default", &dbv)) {
		if (IsChannel(dbv.ptszVal)) {
			db_free(&dbv);
			return 0;
		}
		db_free(&dbv);
	}

	OPTIONSDIALOGPAGE odp = { sizeof(odp) };
	odp.flags = ODPF_DONTTRANSLATE;
	odp.pszTitle = m_szModuleName;
	odp.hIcon = NULL;
	odp.dwInitParam = (LPARAM)this;
	odp.hInstance = hInst;
	odp.position = -1900000000;
	odp.pfnDlgProc = UserDetailsDlgProc;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO);
	odp.pszTitle = m_szModuleName;
	UserInfo_AddPage(wParam, &odp);
	return 0;
}
Пример #8
0
void CIrcProto::AddToJTemp(TCHAR op, CMString& sCommand)
{
    CMString res;

    int pos = 0;
    for ( ;; ) {
        CMString tmp = sCommand.Tokenize( _T(","), pos );
        if ( pos == -1 )
            break;

        tmp = op + tmp;
        if ( res.IsEmpty() )
            res = tmp;
        else
            res += _T(" ") + tmp;
    }

    DBVARIANT dbv;
    if ( !getTString( "JTemp", &dbv )) {
        res = CMString(dbv.ptszVal) + _T(" ") + res;
        DBFreeVariant( &dbv );
    }

    setTString("JTemp", res.c_str());
}
Пример #9
0
INT_PTR CMsnProto::OnLeaveChat(WPARAM hContact, LPARAM)
{
	if (isChatRoom(hContact) != 0) {
		DBVARIANT dbv;
		if (getTString(hContact, "ChatRoomID", &dbv) == 0) {
			MSN_KillChatSession(dbv.ptszVal);
			db_free(&dbv);
		}
	}
	return 0;
}
Пример #10
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);
}
Пример #11
0
int FacebookProto::GetMyAwayMsg( WPARAM wParam, LPARAM lParam )
{
	DBVARIANT dbv = { DBVT_TCHAR };
	if ( !getTString( "StatusMsg", &dbv ) && lstrlen( dbv.ptszVal ) != 0 )
	{
		int res = (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(dbv.ptszVal) : (INT_PTR)mir_t2a(dbv.ptszVal);
		DBFreeVariant( &dbv );
		return res;
	} else {
		return 0;
	}
}
Пример #12
0
TCHAR* CIcqProto::GetOwnAvatarFileName()
{
	DBVARIANT dbvFile = {DBVT_DELETED};
	if (getTString(NULL, "AvatarFile", &dbvFile))
		return NULL;

	TCHAR tmp[MAX_PATH * 2];
	PathToAbsoluteT(dbvFile.ptszVal, tmp);
	db_free(&dbvFile);

	return null_strdup(tmp);
}
Пример #13
0
HANDLE CIrcProto::CList_SetOffline(struct CONTACT * user)
{
	DBVARIANT dbv;
	HANDLE hContact = CList_FindContact(user);
	if ( hContact ) {
		if ( !getTString( hContact, "Default", &dbv )) {
			setString(hContact, "User", "");
			setString(hContact, "Host", "");
			setTString(hContact, "Nick", dbv.ptszVal);
			setWord(hContact, "Status", ID_STATUS_OFFLINE);
			db_free(&dbv);
			return hContact;
	}	}

	return 0;
}
Пример #14
0
void CSkypeProto::SetAccountSettings()
{
	int port = this->getWord("Port", rand() % 10000 + 10000);
	this->debugLogW(L"Setting port number to %d", port);
	this->SetInt(SETUPKEY_PORT, port);

	bool useAlternativePorts = this->getByte("UseAlternativePorts", 1) > 0;
	if (useAlternativePorts)
		this->debugLogW(L"Setting listening of alternative ports (80, 443)");
	this->SetInt(SETUPKEY_DISABLE_PORT80, (int)!useAlternativePorts);

	// Create default group for new contacts
	DBVARIANT dbv = {0};
	if ( !getTString(SKYPE_SETTINGS_DEF_GROUP, &dbv) && lstrlen(dbv.ptszVal) > 0)
	{
		this->debugLogW(L"Setting default group for new contacts");
		::Clist_CreateGroup(0, dbv.ptszVal);
		::db_free(&dbv);
	}
}
Пример #15
0
int CMsnProto::OnContactDeleted(WPARAM hContact, LPARAM)
{
	if (!msnLoggedIn)  //should never happen for MSN contacts
		return 0;

	if (isChatRoom(hContact)) {
		DBVARIANT dbv;
		if (!getTString(hContact, "ChatRoomID", &dbv)) {
			MSN_KillChatSession(dbv.ptszVal);
			db_free(&dbv);
		}
	}
	else {
		char szEmail[MSN_MAX_EMAIL_LEN];
		if (MSN_IsMeByContact(hContact, szEmail))
			pcli->pfnRemoveEvent(hContact, 1);

		if (szEmail[0]) {
			debugLogA("Deleted Handler Email");

			if (Lists_IsInList(LIST_FL, szEmail)) {
				DeleteParam param = { this, hContact };
				DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_DELETECONTACT), NULL, DlgDeleteContactUI, (LPARAM)&param);

				MsnContact *msc = Lists_Get(szEmail);
				if (msc)
					msc->hContact = NULL;
			}

			if (Lists_IsInList(LIST_LL, szEmail))
				MSN_AddUser(hContact, szEmail, 0, LIST_LL | LIST_REMOVE);
		}
	}

	return 0;
}
Пример #16
0
int __cdecl CIrcProto::OnInitUserInfo(WPARAM wParam, LPARAM lParam)
{
	char* szProto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, lParam, 0);
	HANDLE hContact = (HANDLE) lParam;
	if ( !hContact || !szProto || lstrcmpiA( szProto, m_szModuleName ))
		return 0;

	if ( getByte( hContact, "ChatRoom", 0 ) != 0 )
		return 0;

	if ( getByte( hContact, "DCC", 0 ) != 0 )
		return 0;

	DBVARIANT dbv;
	if ( !getTString( hContact, "Default", &dbv )) {
		if ( IsChannel( dbv.ptszVal )) {
			DBFreeVariant( &dbv );
			return 0;
		}
		DBFreeVariant(&dbv);
	}

	OPTIONSDIALOGPAGE odp = { 0 };
	odp.cbSize = sizeof(odp);
	odp.flags = ODPF_DONTTRANSLATE;
	odp.pszTitle = m_szModuleName;
	odp.hIcon = NULL;
	odp.dwInitParam = ( LPARAM )this;
	odp.hInstance = hInst;
	odp.position = -1900000000;
	odp.pfnDlgProc = UserDetailsDlgProc;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO);
	odp.pszTitle = m_szModuleName;
	CallService( MS_USERINFO_ADDPAGE, wParam, (LPARAM) & odp);
	return 0;
}
Пример #17
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;
}
Пример #18
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;
}
Пример #19
0
int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK*)lParam;
	if (!gch)
		return 1;

	if (_stricmp(gch->pDest->pszModule, m_szModuleName)) return 0;

	switch (gch->pDest->iType) {
	case GC_SESSION_TERMINATE:
		{
			GCThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID);
			if (thread != NULL) {
				m_arGCThreads.remove(thread);
				for (int i = 0; i < thread->mJoinedContacts.getCount(); i++)
					delete thread->mJoinedContacts[i];
				delete thread;
			}
		}
		break;

	case GC_USER_MESSAGE:
		if (gch->ptszText && gch->ptszText[0]) {
			GCThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID);
			if (thread) {
				TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText));
				rtrimt(pszMsg); // remove the ending linebreak
				msnNsThread->sendMessage('N', thread->szEmail, thread->netId, UTF8(pszMsg), 0);

				DBVARIANT dbv;
				int bError = getTString("Nick", &dbv);

				GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE };
				GCEVENT gce = { sizeof(gce), &gcd };
				gce.dwFlags = GCEF_ADDTOLOG;
				gce.ptszNick = bError ? _T("") : dbv.ptszVal;
				gce.ptszUID = mir_a2t(MyOptions.szEmail);
				gce.time = time(NULL);
				gce.ptszText = gch->ptszText;
				gce.bIsMe = TRUE;
				CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

				mir_free((void*)gce.ptszUID);
				if (!bError)
					db_free(&dbv);
			}
		}
		break;

	case GC_USER_CHANMGR:
		DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat,
			LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this)));
		break;

	case GC_USER_PRIVMESS:
		{
			char *email = mir_t2a(gch->ptszUID);
			MCONTACT hContact = MSN_HContactFromEmail(email);
			CallService(MS_MSG_SENDMESSAGE, hContact, 0);
			mir_free(email);
		}
		break;

	case GC_USER_LOGMENU:
		switch (gch->dwData) {
		case 10:
			DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat,
				LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this)));
			break;

		case 20:
			MSN_KillChatSession(gch->pDest->ptszID);
			break;
		}
		break;

	case GC_USER_NICKLISTMENU:
		MCONTACT hContact = MSN_HContactFromEmail(_T2A(gch->ptszUID));

		switch (gch->dwData) {
		case 10:
			CallService(MS_USERINFO_SHOWDIALOG, hContact, 0);
			break;

		case 20:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0);
			break;

		case 30:
			MSN_Kickuser(gch);
			break;

		case 110:
			MSN_KillChatSession(gch->pDest->ptszID);
			break;

		case 40:
			const TCHAR *pszRole = MSN_GCGetRole(MSN_GetThreadByChatId(gch->pDest->ptszID), _T2A(gch->ptszUID));
			MSN_Promoteuser(gch, (pszRole && !mir_tstrcmp(pszRole, _T("admin"))) ? "user" : "admin");
			break;
		}
		break;
	}

	return 0;
}
Пример #20
0
int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) 
{
	GCHOOK *gch = (GCHOOK*) lParam;
	if (!gch)
		return 1;

	if (_stricmp(gch->pDest->pszModule, m_szModuleName)) return 0;

	switch (gch->pDest->iType) 
	{
		case GC_SESSION_TERMINATE: 
		{
 			ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID);
			if (thread != NULL) 
				thread->sendTerminate();
			break;
		}

		case GC_USER_MESSAGE:
			if (gch->ptszText && gch->ptszText[0]) 
			{
				ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID);
				if (thread)
				{
					rtrim(gch->ptszText); // remove the ending linebreak
					TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText));
					thread->sendMessage('N', NULL, NETID_MSN, UTF8(pszMsg), 0);

					DBVARIANT dbv;
					int bError = getTString("Nick", &dbv);

					GCDEST gcd = { m_szModuleName, { NULL }, GC_EVENT_MESSAGE };
					gcd.ptszID = gch->pDest->ptszID;

					GCEVENT gce = {0};
					gce.cbSize = sizeof(GCEVENT);
					gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG;
					gce.pDest = &gcd;
					gce.ptszNick = bError ? _T("") : dbv.ptszVal;
					gce.ptszUID = mir_a2t(MyOptions.szEmail);
					gce.time = time(NULL);
					gce.ptszText = gch->ptszText;
					gce.bIsMe = TRUE;
					CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

					mir_free((void*)gce.ptszUID);
					if (!bError)
						MSN_FreeVariant(&dbv);
				}
			}
			break;

		case GC_USER_CHANMGR: 
			DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, 
				LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this)));
			break;

		case GC_USER_PRIVMESS: 
		{
			char *email = mir_t2a(gch->ptszUID);
			HANDLE hContact = MSN_HContactFromEmail(email);
			MSN_CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0);
			mir_free(email);
			break;
		}

		case GC_USER_LOGMENU:
			switch(gch->dwData) 
			{
			case 10: 
				DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, 
					LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this)));
				break;

			case 20:
				MSN_KillChatSession(gch->pDest->ptszID);
				break;
			}
			break;

		case GC_USER_NICKLISTMENU: 
		{
			char *email = mir_t2a(gch->ptszUID);
			HANDLE hContact = MSN_HContactFromEmail(email);
			mir_free(email);

			switch(gch->dwData) 
			{
			case 10:
				MSN_CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
				break;

			case 20:
				MSN_CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)hContact, 0);
				break;

			case 110:
				MSN_KillChatSession(gch->pDest->ptszID);
				break;
			}
			break;
		}
/*	haven't implemented in chat.dll
		case GC_USER_TYPNOTIFY: 
		{
			int chatID = atoi(p);
			ThreadData* thread = MSN_GetThreadByContact((HANDLE)-chatID);
			for (int j=0; j < thread->mJoinedCount; j++) 
			{
				if ((long)thread->mJoinedContacts[j] > 0)
					CallService(MS_PROTO_SELFISTYPING, (WPARAM) thread->mJoinedContacts[j], (LPARAM) PROTOTYPE_SELFTYPING_ON);
			}
			break;
		}
*/
	}

	return 0;
}
Пример #21
0
void CYahooProto::ext_got_picture(const char *me, const char *who, const char *pic_url, int cksum, int type)
{
	MCONTACT hContact = 0;

	LOG(("[ext_yahoo_got_picture] for %s with url %s (checksum: %d) type: %d", who, pic_url, cksum, type));

	/*
	  Type:

	  1 - Send Avatar Info
	  2 - Got Avatar Info
	  3 - YIM6 didn't like my avatar? Expired? We need to invalidate and re-load
	  */
	switch (type) {
	case 1:
		{
			int cksum = 0;
			DBVARIANT dbv;

			/* need to send avatar info */
			if (!getByte("ShowAvatars", 1)) {
				LOG(("[ext_yahoo_got_picture] We are not using/showing avatars!"));
				yahoo_send_picture_update(m_id, who, 0); // no avatar (disabled)
				return;
			}

			LOG(("[ext_yahoo_got_picture] Getting ready to send info!"));
			/* need to read CheckSum */
			cksum = getDword("AvatarHash", 0);
			if (cksum) {
				if (!getString("AvatarURL", &dbv)) {
					LOG(("[ext_yahoo_got_picture] Sending url: %s checksum: %d to '%s'!", dbv.pszVal, cksum, who));
					//void yahoo_send_picture_info(int id, const char *me, const char *who, const char *pic_url, int cksum)
					yahoo_send_picture_info(m_id, who, 2, dbv.pszVal, cksum);
					db_free(&dbv);
					break;
				}
				else
					LOG(("No AvatarURL???"));

				/*
				 * Try to re-upload the avatar
				 */
				if (getByte("AvatarUL", 0) != 1) {
					// NO avatar URL??
					if (!getTString("AvatarFile", &dbv)) {
						struct _stat statbuf;

						if (_tstat(dbv.ptszVal, &statbuf) != 0) {
							LOG(("[ext_yahoo_got_picture] Avatar File Missing? Can't find file: %s", dbv.ptszVal));
						}
						else {
							setString("AvatarInv", who);
							SendAvatar(dbv.ptszVal);
						}

						db_free(&dbv);
					}
					else {
						LOG(("[ext_yahoo_got_picture] No Local Avatar File??? "));
					}
				}
				else
					LOG(("[ext_yahoo_got_picture] Another avatar upload in progress?"));
			}
		}
		break;
	case 2: /*
			  * We got Avatar Info for our buddy.
			  */
		if (!getByte("ShowAvatars", 1)) {
			LOG(("[ext_yahoo_got_picture] We are not using/showing avatars!"));
			return;
		}

		/* got avatar info, so set miranda up */
		hContact = getbuddyH(who);
		if (!hContact) {
			LOG(("[ext_yahoo_got_picture] Buddy not on my buddy list?."));
			return;
		}

		if (!cksum && pic_url) {
			const char *chk = strstr(pic_url, "chksum=");
			if (chk)
				cksum = strtol(chk + 7, NULL, 10);
		}

		if (!cksum || cksum == -1) {
			LOG(("[ext_yahoo_got_picture] Resetting avatar."));
			setDword(hContact, "PictCK", 0);
			reset_avatar(hContact);
		}
		else {
			if (pic_url == NULL) {
				LOG(("[ext_yahoo_got_picture] WARNING: Empty URL for avatar?"));
				return;
			}

			TCHAR z[1024];
			GetAvatarFileName(hContact, z, 1024, getByte(hContact, "AvatarType", 0));

			if (getDword(hContact, "PictCK", 0) != cksum || _taccess(z, 0) != 0) {

				debugLogA("[ext_yahoo_got_picture] Checksums don't match or avatar file is missing. Current: %d, New: %d",
					getDword(hContact, "PictCK", 0), cksum);

				struct avatar_info *avt = (avatar_info*)malloc(sizeof(struct avatar_info));
				avt->who = strdup(who);
				avt->pic_url = strdup(pic_url);
				avt->cksum = cksum;

				ForkThread(&CYahooProto::recv_avatarthread, avt);
			}
		}

		break;
	case 3:
		// Our Avatar is not good anymore? Need to re-upload??
		/* who, pic_url, cksum */
		{
			int mcksum = 0;
			DBVARIANT dbv;

			/* need to send avatar info */
			if (!getByte("ShowAvatars", 1)) {
				LOG(("[ext_yahoo_got_picture] We are not using/showing avatars!"));
				yahoo_send_picture_update(m_id, who, 0); // no avatar (disabled)
				return;
			}

			LOG(("[ext_yahoo_got_picture] Getting ready to send info!"));
			/* need to read CheckSum */
			mcksum = getDword("AvatarHash", 0);
			if (mcksum == 0) {
				/* this should NEVER Happen??? */
				LOG(("[ext_yahoo_got_picture] No personal checksum? and Invalidate?!"));
				yahoo_send_picture_update(m_id, who, 0); // no avatar (disabled)
				return;
			}

			LOG(("[ext_yahoo_got_picture] My Checksum: %d", mcksum));

			if (!getString("AvatarURL", &dbv)) {
				if (mir_strcmpi(pic_url, dbv.pszVal) == 0) {
					DBVARIANT dbv2;
					/*time_t  ts;
					DWORD	ae;*/

					if (mcksum != cksum)
						LOG(("[ext_yahoo_got_picture] WARNING: Checksums don't match!"));

					/*time(&ts);
					ae = getDword("AvatarExpires", 0);

					if (ae != 0 && ae > (ts - 300)) {
					LOG(("[ext_yahoo_got_picture] Current Time: %lu Expires: %lu ", ts, ae));
					LOG(("[ext_yahoo_got_picture] We just reuploaded! Stop screwing with Yahoo FT. "));

					// don't leak stuff
					db_free(&dbv);

					break;
					}*/

					LOG(("[ext_yahoo_got_picture] Buddy: %s told us this is bad??Expired??. Re-uploading", who));
					delSetting("AvatarURL");

					if (!getTString("AvatarFile", &dbv2)) {
						setString("AvatarInv", who);
						SendAvatar(dbv2.ptszVal);
						db_free(&dbv2);
					}
					else {
						LOG(("[ext_yahoo_got_picture] No Local Avatar File??? "));
					}
				}
				else {
					LOG(("[ext_yahoo_got_picture] URL doesn't match? Tell them the right thing!!!"));
					yahoo_send_picture_info(m_id, who, 2, dbv.pszVal, mcksum);
				}
				// don't leak stuff
				db_free(&dbv);
			}
			else {
				LOG(("[ext_yahoo_got_picture] no AvatarURL?"));
			}
		}
		break;
	default:
		LOG(("[ext_yahoo_got_picture] Unknown request/packet type exiting!"));
	}

	LOG(("ext_yahoo_got_picture exiting"));
}
Пример #22
0
HANDLE CIrcProto::CList_FindContact (CONTACT* user) 
{
	if ( !user || !user->name )
		return 0;
	
	TCHAR* lowercasename = mir_tstrdup( user->name );
	CharLower(lowercasename);
	
	DBVARIANT dbv1;
	DBVARIANT dbv2;	
	DBVARIANT dbv3;	
	DBVARIANT dbv4;	
	DBVARIANT dbv5;	

	for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		if ( isChatRoom(hContact))
			continue;

		HANDLE hContact_temp = NULL;
		TCHAR* DBDefault = NULL;
		TCHAR* DBNick = NULL;
		TCHAR* DBWildcard = NULL;
		TCHAR* DBUser = NULL;
		TCHAR* DBHost = NULL;
		if ( !getTString(hContact, "Default",   &dbv1)) DBDefault = dbv1.ptszVal;
		if ( !getTString(hContact, "Nick",      &dbv2)) DBNick = dbv2.ptszVal;
		if ( !getTString(hContact, "UWildcard", &dbv3)) DBWildcard = dbv3.ptszVal;
		if ( !getTString(hContact, "UUser",     &dbv4)) DBUser = dbv4.ptszVal;
		if ( !getTString(hContact, "UHost",     &dbv5)) DBHost = dbv5.ptszVal;
				
		if ( DBWildcard )
			CharLower( DBWildcard );
		if ( IsChannel( user->name )) {
			if ( DBDefault && !lstrcmpi( DBDefault, user->name ))
				hContact_temp = (HANDLE)-1;
		}
		else if ( user->ExactNick && DBNick && !lstrcmpi( DBNick, user->name ))
			hContact_temp = hContact;
				
		else if ( user->ExactOnly && DBDefault && !lstrcmpi( DBDefault, user->name ))
			hContact_temp = hContact;
			
		else if ( user->ExactWCOnly ) {
			if ( DBWildcard && !lstrcmpi( DBWildcard, lowercasename ) 
				|| ( DBWildcard && !lstrcmpi( DBNick, lowercasename ) && !WCCmp( DBWildcard, lowercasename ))
				|| ( !DBWildcard && !lstrcmpi(DBNick, lowercasename)))
			{
				hContact_temp = hContact;
			}
		}
		else if ( _tcschr(user->name, ' ' ) == 0 ) {
			if (( DBDefault && !lstrcmpi(DBDefault, user->name) || DBNick && !lstrcmpi(DBNick, user->name) || 
					DBWildcard && WCCmp( DBWildcard, lowercasename ))
				&& ( WCCmp(DBUser, user->user) && WCCmp(DBHost, user->host)))
			{
				hContact_temp = hContact;
		}	}

		if ( DBDefault )   db_free(&dbv1);
		if ( DBNick )      db_free(&dbv2);
		if ( DBWildcard )  db_free(&dbv3);
		if ( DBUser )      db_free(&dbv4);
		if ( DBHost )      db_free(&dbv5);

		if ( hContact_temp != NULL ) {
			mir_free(lowercasename);
			if ( hContact_temp != (HANDLE)-1 )
				return hContact_temp;
			return 0;
		}
	}
	mir_free(lowercasename);
	return 0;
}