Exemplo n.º 1
0
void CToxNodeEditor::OnOk(CCtrlBase*)
{
	if (!m_ipv4.GetInt())
	{
		MessageBox(m_hwnd, TranslateT("Enter IPv4"), TranslateT("Error"), MB_OK);
		return;
	}
	if (!m_pkey.GetInt())
	{
		MessageBox(m_hwnd, TranslateT("Enter public key"), TranslateT("Error"), MB_OK);
		return;
	}

	ptrT ipv4(m_ipv4.GetText());
	if (m_iItem == -1)
	{
		m_iItem = m_list->AddItem(ipv4, -1, NULL, 1);
		m_list->SetItemState(m_iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);
		m_list->EnsureVisible(m_iItem, TRUE);
	}
	else
		m_list->SetItem(m_iItem, 0, ipv4);
	m_list->SetItem(m_iItem, 1, ptrT(m_ipv6.GetText()));
	m_list->SetItem(m_iItem, 2, ptrT(m_port.GetText()));
	m_list->SetItem(m_iItem, 3, ptrT(m_pkey.GetText()));
	m_list->SetItem(m_iItem, 4, _T(""), 0);
	m_list->SetItem(m_iItem, 5, _T(""), 1);

	EndDialog(m_hwnd, 1);
}
Exemplo n.º 2
0
void CSteamProto::OnGotHistoryMessages(const HttpResponse *response, void *arg)
{
	MCONTACT hContact = FindContact((char*)arg);
	if (!hContact)
		return;

	if (!ResponseHttpOk(response))
		return;

	JSONROOT root(response->pData);
	if (root == NULL)
		return;

	JSONNode *node = json_get(root, "response");

	JSONNode *messages = json_get(node, "messages");
	JSONNode *nmessages = json_as_array(messages);

	// Self SteamID
	ptrA steamId(getStringA("SteamID"));

	for (size_t i = json_size(nmessages); i > 0; i--)
	{
		JSONNode *message = json_at(nmessages, i - 1);

		node = json_get(message, "accountid");
		const char *authorSteamId = AccountIdToSteamId(_ttoi64(ptrT(json_as_string(node))));

		node = json_get(message, "message");
		ptrT text(json_as_string(node));
		T2Utf szMessage(text);

		node = json_get(message, "timestamp");
		time_t timestamp = _ttoi64(ptrT(json_as_string(node)));

		// Ignore already existing messages
		if (timestamp <= m_lastMessageTS)
			continue;

		PROTORECVEVENT recv = { 0 };
		recv.timestamp = timestamp;
		recv.szMessage = szMessage;

		if (strcmp(steamId, authorSteamId))
		{
			// Received message
			ProtoChainRecvMsg(hContact, &recv);
		}
		else
		{
			// Sent message
			recv.flags = PREF_SENT;
			Proto_RecvMessage(hContact, &recv);
		}
	}

	json_delete(nmessages);
}
Exemplo n.º 3
0
void CSteamProto::OnLoggedOn(const HttpResponse *response)
{
	if (!CheckResponse(response))
	{
		if (response && response->resultCode == HTTP_CODE_UNAUTHORIZED)
		{
			// Probably expired TokenSecret
			HandleTokenExpired();
			return;
		}

		// Probably timeout or no connection, we can do nothing here
		ShowNotification(_T("Steam"), TranslateT("Unknown login error."));

		SetStatus(ID_STATUS_OFFLINE);
		return;
	}

	JSONROOT root(response->pData);

	JSONNode *node = json_get(root, "error");
	ptrT error(json_as_string(node));
	if (mir_tstrcmpi(error, _T("OK")))
	{
		// Probably expired TokenSecret
		HandleTokenExpired();
		return;
	}

	node = json_get(root, "umqid");
	setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node)))));

	node = json_get(root, "message");
	setDword("MessageID", json_as_int(node));
	
	if (m_lastMessageTS <= 0) {
		node = json_get(root, "utc_timestamp");
		time_t timestamp = _ttoi64(ptrT(json_as_string(node)));
		setDword("LastMessageTS", timestamp);
	}

	// load contact list
	ptrA token(getStringA("TokenSecret"));
	ptrA steamId(getStringA("SteamID"));

	PushRequest(
		new GetFriendListRequest(token, steamId),
		&CSteamProto::OnGotFriendList);

	// start polling thread
	m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, 0, NULL);

	// go to online now
	ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
}
Exemplo n.º 4
0
void CSteamProto::OnGotConversations(const HttpResponse *response)
{
	// Don't load any messages when we don't have lastMessageTS, as it may cause duplicates
	if (m_lastMessageTS <= 0)
		return;

	if (!ResponseHttpOk(response))
		return;

	JSONROOT root(response->pData);
	if (root == NULL)
		return;

	JSONNode *node = json_get(root, "response");
	JSONNode *sessions = json_get(node, "message_sessions");
	JSONNode *nsessions = json_as_array(sessions);

	if (nsessions != NULL)
	{
		ptrA token(getStringA("TokenSecret"));
		ptrA steamId(getStringA("SteamID"));
		

		for (size_t i = 0; i < json_size(nsessions); i++)
		{
			JSONNode *session = json_at(nsessions, i);

			node = json_get(session, "accountid_friend");
			const char *who = AccountIdToSteamId(_ttoi64(ptrT(json_as_string(node))));

			node = json_get(session, "last_message");
			time_t lastMessageTS = _ttoi64(ptrT(json_as_string(node)));

			/*node = json_get(session, "last_view");
			time_t last_view = _ttoi64(ptrT(json_as_string(node)));

			node = json_get(session, "unread_message_count");
			long unread_count = json_as_int(node);*/

			if (lastMessageTS > m_lastMessageTS)
			{
				PushRequest(
					new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS),
					&CSteamProto::OnGotHistoryMessages,
					mir_strdup(who),
					MirFreeArg);
			}
		}

		json_delete(nsessions);
	}
}
Exemplo n.º 5
0
INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	TMsgQueue *item = (TMsgQueue*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			RECT rc, rcParent;
			ErrorDlgParam *param = (ErrorDlgParam *)lParam;
			item = param->item;

			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)item);

			if (!param->szMsg || !param->szMsg[0])
				SetDlgItemText(hwndDlg, IDC_ERRORTEXT, TranslateT("An unknown error has occurred."));
			else {
				ptrT ptszError(Langpack_PcharToTchar(param->szMsg));
				SetDlgItemText(hwndDlg, IDC_ERRORTEXT, ptszError);
			}

			SetDlgItemText(hwndDlg, IDC_MSGTEXT, ptrT(mir_utf8decodeT(item->szMsg)));

			GetWindowRect(hwndDlg, &rc);
			GetWindowRect(GetParent(hwndDlg), &rcParent);
			SetWindowPos(hwndDlg, 0, (rcParent.left + rcParent.right - (rc.right - rc.left)) / 2,
				(rcParent.top + rcParent.bottom - (rc.bottom - rc.top)) / 2,
				0, 0, SWP_NOZORDER | SWP_NOSIZE);
		}
		return TRUE;

	case WM_DESTROY:
		mir_free(item->szMsg);
		mir_free(item);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
			SendMessageDirect(ptrT(mir_utf8decodeT(item->szMsg)), item->hContact, GetContactProto(item->hContact));
			DestroyWindow(hwndDlg);
			break;

		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;
		}
		break;
	}
	return FALSE;
}
Exemplo n.º 6
0
void CToxProto::LoadChatRoomList(void*)
{
	uint32_t count = tox_count_chatlist(toxThread->Tox());
	if (count == 0)
	{
		debugLogA(__FUNCTION__": your group chat list is empty");
		return;
	}
	int32_t *groupChats = (int32_t*)mir_alloc(count * sizeof(int32_t));
	tox_get_chatlist(toxThread->Tox(), groupChats, count);
	for (uint32_t i = 0; i < count; i++)
	{
		int32_t groupNumber = groupChats[i];
		int type = tox_group_get_type(toxThread->Tox(), groupNumber);
		if (type == TOX_GROUPCHAT_TYPE_AV)
		{
			continue;
		}
		MCONTACT hContact = AddChatRoom(groupNumber);
		if (hContact)
		{
			uint8_t title[TOX_MAX_NAME_LENGTH] = { 0 };
			tox_group_get_title(toxThread->Tox(), groupNumber, title, TOX_MAX_NAME_LENGTH);
			setWString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)title)));
		}
	}
	mir_free(groupChats);
}
Exemplo n.º 7
0
void __cdecl CJabberProto::OnAddContactForever(DBCONTACTWRITESETTING *cws, HANDLE hContact)
{
	if (cws->value.type != DBVT_DELETED && !(cws->value.type == DBVT_BYTE && cws->value.bVal == 0))
		return;

	ptrT jid(getTStringA(hContact, "jid"));
	if (jid == NULL)
		return;

	debugLogA("Add %S permanently to list", jid);
	ptrT nick(db_get_tsa(hContact, "CList", "MyHandle"));
	if (nick == NULL)
		nick = getTStringA(hContact, "Nick");
	if (nick == NULL)
		nick = JabberNickFromJID(jid);
	if (nick == NULL)
		return;

	AddContactToRoster(jid, nick, ptrT(db_get_tsa(hContact, "CList", "Group")));

	XmlNode xPresence(_T("presence")); xPresence << XATTR(_T("to"), LPCTSTR(jid)) << XATTR(_T("type"), _T("subscribe"));
	ptrT myNick(getTStringA(NULL, "Nick"));
	if (myNick != NULL)
		xPresence << XCHILD(_T("nick"), LPCTSTR(myNick)) << XATTR(_T("xmlns"), JABBER_FEAT_NICK);
	m_ThreadInfo->send(xPresence);

	SendGetVcard(jid);

	db_unset(hContact, "CList", "Hidden");
}
Exemplo n.º 8
0
void __cdecl CJabberProto::OnRenameGroup(DBCONTACTWRITESETTING *cws, HANDLE hContact)
{
	JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, ptrT(getTStringA(hContact, "jid")));
	if (item == NULL)
		return;

	ptrT tszNick(db_get_tsa(hContact, "CList", "MyHandle"));
	if (tszNick == NULL)
		tszNick = getTStringA(hContact, "Nick");
	if (tszNick == NULL)
		tszNick = JabberNickFromJID(item->jid);
	if (tszNick == NULL)
		return;

	if (cws->value.type == DBVT_DELETED) {
		if (item->group != NULL) {
			debugLogA("Group set to nothing");
			AddContactToRoster(item->jid, tszNick, NULL);
		}
	}
	else {
		TCHAR *p = sttSettingToTchar(cws);
		if (cws->value.pszVal != NULL && lstrcmp(p, item->group)) {
			debugLogA("Group set to %S", p);
			if (p)
				AddContactToRoster(item->jid, tszNick, p);
		}
		mir_free(p);
	}
}
Exemplo n.º 9
0
void CJabberDlgBookmarks::OpenBookmark()
{
	int iItem = m_lvBookmarks.GetNextItem(-1, LVNI_SELECTED);
	if (iItem < 0) return;

	TCHAR *address = (TCHAR *)m_lvBookmarks.GetItemData(iItem);
	if (address == NULL) return;

	JABBER_LIST_ITEM *item = m_proto->ListGetItemPtr(LIST_BOOKMARK, address);
	if (item == NULL) return;

	if (!mir_tstrcmpi(item->type, _T("conference"))) {
		m_lvBookmarks.SetItemState(iItem, 0, LVIS_SELECTED); // Unselect the item

		/* some hack for using bookmark to transport not under XEP-0048 */
		if (!_tcschr(item->jid, _T('@')))
			//the room name is not provided let consider that it is transport and send request to registration
			m_proto->RegisterAgent(NULL, item->jid);
		else {
			TCHAR *room = NEWTSTR_ALLOCA(item->jid);
			TCHAR *server = _tcschr(room, _T('@'));
			*(server++) = 0;

			if (item->nick && *item->nick)
				m_proto->GroupchatJoinRoom(server, room, item->nick, item->password);
			else
				m_proto->GroupchatJoinRoom(server, room, ptrT(JabberNickFromJID(m_proto->m_szJabberJID)), item->password);
		}
	}
	else Utils_OpenUrlT(item->jid);
}
Exemplo n.º 10
0
void CVkProto::OnReceiveStatusMsg(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveStatusMsg %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	OnReceiveStatus(reply, pReq);

	ptrT ptszOldStatusMsg(db_get_tsa(NULL, m_szModuleName, "OldStatusMsg"));
	CMString tszOldStatusMsg(ptszOldStatusMsg);

	ENTER_STRING pForm = { sizeof(pForm) };
	pForm.type = ESF_MULTILINE;
	pForm.caption = TranslateT("Enter new status message");
	pForm.ptszInitVal = ptszOldStatusMsg;
	pForm.szModuleName = m_szModuleName;
	pForm.szDataPrefix = "statusmsgform_";

	if (!EnterString(&pForm))
		return;

	CMString tszNewStatusMsg(ptrT(pForm.ptszResult));
	if (tszOldStatusMsg == tszNewStatusMsg)
		return;

	RetrieveStatusMsg(tszNewStatusMsg);
	setTString("OldStatusMsg", ptszOldStatusMsg);
}
Exemplo n.º 11
0
bool CSteamProto::Relogin()
{
	ptrA token(getStringA("TokenSecret"));
	if (mir_strlen(token) <= 0)
		return false;

	HttpRequest *request = new LogonRequest(token);
	HttpResponse *response = request->Send(m_hNetlibUser);

	bool success = false;
	if (CheckResponse(response))
	{
		JSONROOT root(response->pData);
		if (root != NULL) {
			JSONNode *node = json_get(root, "error");

			ptrT error(json_as_string(node));
			if (!mir_tstrcmpi(error, _T("OK")))
			{
				node = json_get(root, "umqid");
				setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node)))));

				node = json_get(root, "message");
				setDword("MessageID", json_as_int(node));

				success = true;
			}
		}
	}

	delete request;
	delete response;

	return success;
}
Exemplo n.º 12
0
CMString ExpandPath(const TCHAR *format)
{
	CMString res;

	if (ServiceExists(MS_VARS_FORMATSTRING))
		res = VARST(ptrT(variables_parse((TCHAR*)format, NULL, NULL)));
	else
		res = VARST(format);

	res.Replace(PROFILE_PATHT, szCurrentProfilePath);
	res.Replace(CURRENT_PROFILET, szCurrentProfile);
	res.Replace(MIRANDA_PATHT, szMirandaPath);
	res.Replace(MIRANDA_USERDATAT, szUserDataPath);
	res.Trim();

	// also remove the trailing slash
	if (!res.IsEmpty()) {
		int iNewSize = res.GetLength() - 1;
		switch (res[iNewSize]) {
		case '\\': case '/':
			res.Truncate(iNewSize);
		}
	}

	return res;
}
Exemplo n.º 13
0
void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceivePollingInfo %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	JSONROOT pRoot;
	JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
	if (pResponse == NULL)
		return;

	m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pResponse, "ts"))));
	m_pollingKey = mir_t2a(ptrT(json_as_string(json_get(pResponse, "key"))));
	m_pollingServer = mir_t2a(ptrT(json_as_string(json_get(pResponse, "server"))));
	if (!m_hPollingThread && m_pollingTs != NULL && m_pollingKey != NULL && m_pollingServer != NULL)
		m_hPollingThread = ForkThreadEx(&CVkProto::PollingThread, NULL, NULL);
}
Exemplo n.º 14
0
INT_PTR __cdecl CVkProto::SvcOpenBroadcast(WPARAM hContact, LPARAM)
{
	debugLogA("CVkProto::SvcOpenBroadcast");

	CMString tszAudio(ptrT(db_get_tsa(hContact, m_szModuleName, "AudioUrl")));
	if (!tszAudio.IsEmpty())
		Utils_OpenUrlT(tszAudio);

	return 0;
}
Exemplo n.º 15
0
CMString CSkypeProto::ChangeTopicForm()
{
	CMString caption(FORMAT, _T("[%s] %s"), _A2T(m_szModuleName), TranslateT("Enter new chatroom topic"));
	ENTER_STRING pForm = { sizeof(pForm) };
	pForm.type = ESF_MULTILINE;
	pForm.caption = caption;
	pForm.ptszInitVal = NULL;
	pForm.szModuleName = m_szModuleName;
	return (!EnterString(&pForm)) ? CMString() : CMString(ptrT(pForm.ptszResult));
}
Exemplo n.º 16
0
INT_PTR __cdecl CJabberProto::OnMenuSendNote(WPARAM wParam, LPARAM)
{
	if (wParam) {
		CNoteItem *pItem = new CNoteItem(NULL, ptrT(getTStringA(wParam, "jid")));
		CJabberDlgBase *pDlg = new CJabberDlgNoteItem(this, pItem, &CJabberProto::ProcessOutgoingNote);
		pDlg->Show();
	}

	return 0;
}
Exemplo n.º 17
0
int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* fbc)
{
	std::string jsonData = data->substr(9);

	JSONNode root = JSONNode::parse(jsonData.c_str());
	if (!root)
		return EXIT_FAILURE;

	const JSONNode &threads = root["payload"].at("threads");
	if (!threads)
		return EXIT_FAILURE;

	/*const JSONNode &roger = payload, "roger");
	if (roger) {
	for (unsigned int i = 0; i < json_size(roger); i++) {
	const JSONNode &it = json_at(roger, i);
	std::tstring id = _A2T(json_name(it));

	// Ignore "wrong" (duplicit) identifiers - these that doesn't begin with "id."
	if (id.substr(0, 3) == _T("id.")) {
	facebook_chatroom *room = new facebook_chatroom();
	room->thread_id = id;

	chatrooms->insert(std::make_pair((char*)_T2A(room->thread_id.c_str()), room));
	}
	}
	}*/

	for (auto it = threads.begin(); it != threads.end(); ++it) {
		const JSONNode &is_canonical_user_ = (*it)["is_canonical_user"];
		const JSONNode &thread_id_ = (*it)["thread_id"];
		const JSONNode &name_ = (*it)["name"];
		//const JSONNode &message_count_ = (*it)["message_count");
		//const JSONNode &unread_count_ = (*it)["unread_count"); // TODO: use it to check against number of loaded messages... but how?

		if (!thread_id_ || !is_canonical_user_ || is_canonical_user_.as_bool())
			continue;

		std::string tid = thread_id_.as_string();

		// TODO: allow more users to parse at once
		if (fbc->thread_id != tid)
			continue;

		const JSONNode &participants = (*it)["participants"];
		for (auto jt = participants.begin(); jt != participants.end(); ++jt) {
			std::string user_id = (*jt).as_string();
			fbc->participants.insert(std::make_pair(user_id.substr(5), ""));
		}

		fbc->chat_name = std::tstring(ptrT(mir_utf8decodeT(name_.as_string().c_str())));
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 18
0
void CSametimeProto::AddGroup(const char* name, bool expanded)
{
	if (name && mir_strcmp(name, "MetaContacts Hidden Group") == 0)
		return;

	if (name && mir_strcmp(name, Translate("None")) == 0)
		return;

	MGROUP hGroup = Clist_GroupCreate(NULL, ptrT(mir_utf8decodeT(name)));
	Clist_GroupSetExpanded(hGroup, expanded);
}
Exemplo n.º 19
0
static int lua_CreateRoot(lua_State *L)
{
	int hMenuObject = lua_tointeger(L, 1);
	const char *name = luaL_checkstring(L, 2);
	int position = lua_tointeger(L, 3);
	HANDLE hIcon = (HANDLE)lua_touserdata(L, 4);

	HGENMENU res = Menu_CreateRoot(MO_MAIN, ptrT(Utf8DecodeT(name)), position, hIcon);
	lua_pushlightuserdata(L, res);

	return 1;
}
Exemplo n.º 20
0
int CJabberProto::OnProcessSrmmIconClick(WPARAM hContact, LPARAM lParam)
{
    StatusIconClickData *sicd = (StatusIconClickData *)lParam;
    if (mir_strcmp(sicd->szModule, m_szModuleName))
        return 0;

    if (!hContact)
        return 0;

    JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, ptrT(getTStringA(hContact, "jid")));
    if (LI == NULL)
        return 0;

    HMENU hMenu = CreatePopupMenu();
    TCHAR buf[256];

    mir_sntprintf(buf, TranslateT("Last active (%s)"),
                  LI->m_pLastSeenResource ? LI->m_pLastSeenResource->m_tszResourceName : TranslateT("No activity yet, use server's choice"));
    AppendMenu(hMenu, MF_STRING, MENUITEM_LASTSEEN, buf);

    AppendMenu(hMenu, MF_STRING, MENUITEM_SERVER, TranslateT("Highest priority (server's choice)"));

    AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
    for (int i = 0; i < LI->arResources.getCount(); i++)
        AppendMenu(hMenu, MF_STRING, MENUITEM_RESOURCES + i, LI->arResources[i]->m_tszResourceName);

    if (LI->resourceMode == RSMODE_LASTSEEN)
        CheckMenuItem(hMenu, MENUITEM_LASTSEEN, MF_BYCOMMAND | MF_CHECKED);
    else if (LI->resourceMode == RSMODE_SERVER)
        CheckMenuItem(hMenu, MENUITEM_SERVER, MF_BYCOMMAND | MF_CHECKED);
    else if (LI->m_pManualResource)
        CheckMenuItem(hMenu, MENUITEM_RESOURCES + LI->arResources.indexOf(LI->m_pManualResource), MF_BYCOMMAND | MF_CHECKED);

    int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, WindowList_Find(hDialogsList, hContact), NULL);

    if (res == MENUITEM_LASTSEEN) {
        LI->m_pManualResource = NULL;
        LI->resourceMode = RSMODE_LASTSEEN;
    }
    else if (res == MENUITEM_SERVER) {
        LI->m_pManualResource = NULL;
        LI->resourceMode = RSMODE_SERVER;
    }
    else if (res >= MENUITEM_RESOURCES) {
        LI->m_pManualResource = LI->arResources[res - MENUITEM_RESOURCES];
        LI->resourceMode = RSMODE_MANUAL;
    }

    UpdateMirVer(LI);
    MenuUpdateSrmmIcon(LI);

    return 0;
}
Exemplo n.º 21
0
void loginError(FacebookProto *proto, std::string error_str) {
	error_str = utils::text::trim(
			utils::text::special_expressions_decode(
				utils::text::remove_html(
					utils::text::edit_html(error_str))));
	
	proto->debugLogA(" ! !  Login error: %s", !error_str.empty() ? error_str.c_str() : "Unknown error");

	TCHAR buf[200];
	mir_sntprintf(buf, SIZEOF(buf), TranslateT("Login error: %s"), 
		(error_str.empty()) ? TranslateT("Unknown error") : ptrT(mir_utf8decodeT(error_str.c_str())));
	proto->facy.client_notify(buf);
}
Exemplo n.º 22
0
void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
	CToxThread toxThread;

	ptrT profilePath(m_proto->GetToxProfilePath());
	if (!m_proto->IsFileExists(profilePath))
	{
		HANDLE hProfile = CreateFile(profilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hProfile == NULL)
		{
			m_proto->logger->Log(__FUNCTION__": failed to create tox profile");
			return;
		}
		CloseHandle(hProfile);
	}

	if (m_proto->InitToxCore(&toxThread))
	{
		ptrT group(m_group.GetText());
		if (mir_tstrlen(group) > 0 && Clist_GroupExists(group))
			Clist_CreateGroup(0, group);

		m_proto->UninitToxCore(&toxThread);

		m_toxAddress.Enable();
		m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));

		m_nickname.SetText(ptrT(m_proto->getTStringA("Nick")));
		m_password.SetText(ptrT(m_proto->getTStringA("Password")));
		m_group.SetText(ptrT(m_proto->getTStringA(TOX_SETTINGS_GROUP)));

		ShowWindow(m_profileCreate.GetHwnd(), FALSE);
		ShowWindow(m_profileImport.GetHwnd(), FALSE);

		ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
		ShowWindow(m_profileExport.GetHwnd(), TRUE);
	}
}
Exemplo n.º 23
0
static POPUPDATAT* MakePopupData(lua_State *L)
{
	POPUPDATAT *ppd = (POPUPDATAT*)mir_calloc(sizeof(POPUPDATAT));

	lua_pushliteral(L, "ContactName");
	lua_gettable(L, -2);
	mir_tstrcpy(ppd->lptzContactName, ptrT(mir_utf8decodeT(lua_tostring(L, -1))));
	lua_pop(L, 1);

	lua_pushliteral(L, "Text");
	lua_gettable(L, -2);
	mir_tstrcpy(ppd->lptzText, ptrT(mir_utf8decodeT(luaL_checkstring(L, -1))));
	lua_pop(L, 1);

	lua_pushliteral(L, "hContact");
	lua_gettable(L, -2);
	ppd->lchContact = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorBack");
	lua_gettable(L, -2);
	ppd->colorBack = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorText");
	lua_gettable(L, -2);
	ppd->colorText = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Seconds");
	lua_gettable(L, -2);
	ppd->iSeconds = lua_tointeger(L, -1);
	lua_pop(L, 1);

	return ppd;
}
Exemplo n.º 24
0
INT_PTR __cdecl CJabberProto::OnMenuTransportLogin(WPARAM hContact, LPARAM)
{
    if (!getByte(hContact, "IsTransport", 0))
        return 0;

    JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, ptrT(getTStringA(hContact, "jid")));
    if (item != NULL) {
        XmlNode p(_T("presence"));
        XmlAddAttr(p, _T("to"), item->jid);
        if (item->getTemp()->m_iStatus == ID_STATUS_ONLINE)
            XmlAddAttr(p, _T("type"), _T("unavailable"));
        m_ThreadInfo->send(p);
    }
    return 0;
}
Exemplo n.º 25
0
	void OnOk(CCtrlButton*)
	{
		MCONTACT hContact = INVALID_CONTACT_ID;
		switch (m_acs.handleType) {
		case HANDLE_EVENT:
			{
				DBEVENTINFO dbei = { sizeof(dbei) };
				db_event_get(m_acs.hDbEvent, &dbei);
				hContact = (MCONTACT)CallProtoServiceInt(NULL, dbei.szModule, PS_ADDTOLISTBYEVENT, 0, (LPARAM)m_acs.hDbEvent);
			}
			break;

		case HANDLE_SEARCHRESULT:
			hContact = (MCONTACT)CallProtoServiceInt(NULL, m_acs.szProto, PS_ADDTOLIST, 0, (LPARAM)m_acs.psr);
			break;

		case HANDLE_CONTACT:
			hContact = m_acs.hContact;
			break;
		}

		if (hContact == NULL)
			return;

		ptrT szHandle(m_myHandle.GetText());
		if (mir_tstrlen(szHandle))
			db_set_ts(hContact, "CList", "MyHandle", szHandle);

		int item = m_group.GetCurSel();
		if (item > 0)
			CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, m_group.GetItemData(item));

		db_unset(hContact, "CList", "NotOnList");

		if (m_chkAdded.GetState())
			CallContactService(hContact, PSS_ADDED, 0, 0);

		if (m_chkAuth.GetState()) {
			DWORD flags = CallProtoServiceInt(NULL, m_acs.szProto, PS_GETCAPS, PFLAGNUM_4, 0);
			if (flags & PF4_NOCUSTOMAUTH)
				CallContactService(hContact, PSS_AUTHREQUEST, 0, 0);
			else
				CallContactService(hContact, PSS_AUTHREQUEST, 0, ptrT(m_authReq.GetText()));
		}

		if (m_chkOpen.GetState())
			CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
	}
Exemplo n.º 26
0
void CToxOptionsMain::OnApply()
{
	ptrT group(m_group.GetText());
	if (mir_tstrlen(group) > 0 && Clist_GroupExists(group))
		Clist_CreateGroup(0, group);

	if (m_proto->IsOnline())
	{
		CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_TCHAR, (LPARAM)ptrT(m_nickname.GetText()));

		// todo: add checkbox
		m_proto->setTString("Password", pass_ptrT(m_password.GetText()));

		m_proto->SaveToxProfile();
	}
}
Exemplo n.º 27
0
void MakeMenuItem(lua_State *L, CMenuItem &mi)
{
	mi.hLangpack = hScriptsLangpack;

	lua_pushliteral(L, "Flags");
	lua_gettable(L, -2);
	mi.flags = lua_tointeger(L, -1);
	lua_pop(L, 1);

	if (!(mi.flags & CMIF_TCHAR))
		mi.flags |= CMIF_TCHAR;

	lua_pushliteral(L, "Uid");
	lua_gettable(L, -2);
	const char* uuid = (char*)lua_tostring(L, -1);
	if (CLSIDFromString((LPCOLESTR)ptrT(mir_utf8decodeT(uuid)), (LPCLSID)&mi.uid) != NOERROR)
		UNSET_UID(mi);
	lua_pop(L, 1);

	lua_pushliteral(L, "Name");
	lua_gettable(L, -2);
	mi.name.t = mir_utf8decodeT((char*)luaL_checkstring(L, -1));
	lua_pop(L, 1);

	lua_pushliteral(L, "Position");
	lua_gettable(L, -2);
	mi.position = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Icon");
	lua_gettable(L, -2);
	mi.hIcolibItem = (HANDLE)lua_touserdata(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Service");
	lua_gettable(L, -2);
	mi.pszService = (char*)lua_tostring(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Parent");
	lua_gettable(L, -2);
	mi.root = (HGENMENU)lua_touserdata(L, -1);
	lua_pop(L, 1);
}
Exemplo n.º 28
0
CVKNewsItem* CVkProto::GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
	debugLogA("CVkProto::GetVkGroupInvates");
	if (!jnItem)
		return NULL;

	CMString tszType(jnItem["type"].as_mstring());
	VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
	CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
	
	if (!jnItem["id"])
		return NULL;

	LONG iGroupId = jnItem["id"].as_int();
	CMString tszId;
	tszId.AppendFormat(_T("%d,"), iGroupId);
	CMString tszIds = ptrT(db_get_tsa(NULL, m_szModuleName, "InviteGroupIds"));

	if (tszIds.Find(tszId, 0) != -1)
		return NULL;
		
	LONG iUserId = !jnItem["invited_by"] ? 0 : jnItem["invited_by"].as_int();
	CVKNewsItem *vkNotification = new CVKNewsItem();
	vkNotification->tDate = time(NULL);
	vkNotification->vkUser = GetVkUserInfo(iUserId, vkUsers);
	vkNotification->tszType = tszType;
	vkNotification->tszId = tszId;
	vkNotification->vkFeedbackType = vkFeedbackType;
	vkNotification->vkParentType = vkParentType;

	CMString tszGroupName, tszGLink;
	CMString tszGName = jnItem["name"].as_mstring();
	tszGLink.AppendFormat(_T("https://vk.com/%s"), jnItem["screen_name"].as_mstring());
	tszGroupName = SetBBCString(tszGName, m_iBBCForNews, vkbbcUrl, tszGLink);

	CMString tszUsers = SetBBCString(iUserId ? vkNotification->vkUser->m_tszUserNick : TranslateT("Unknown"), m_iBBCForNews, vkbbcUrl, iUserId ? vkNotification->vkUser->m_tszLink : _T("https://vk.com/"));

	vkNotification->tszText.AppendFormat(_T("%s %s %s"), tszUsers, tszNotificationTranslate, tszGroupName);
	
	tszIds += tszId;
	setTString("InviteGroupIds", tszIds);	

	return vkNotification;	
}
Exemplo n.º 29
0
INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
{
	debugLogA("CVkProto::SvcReportAbuse");
	LONG userID = getDword(hContact, "ID", -1);
	if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
		return 1;

	CMString tszNick(ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"))),
		ptszMsg(FORMAT, TranslateT("Are you sure to report abuse on %s?"), tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
	if (IDNO == MessageBox(NULL, ptszMsg, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
		return 1;

	Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.report.json", true, &CVkProto::OnReceiveSmth)
		<< INT_PARAM("user_id", userID)
		<< CHAR_PARAM("type", "spam")
		<< VER_API);

	return 0;
}
Exemplo n.º 30
0
int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
{
	LONG userID = getDword(hContact, "ID", -1);
	bool bisFriend = (getBool(hContact, "Auth", true) == 0);
	bool bisBroadcast = !(IsEmpty(ptrT(db_get_tsa(hContact, m_szModuleName, "AudioUrl"))));
	Menu_ShowItem(g_hContactMenuItems[CMI_VISITPROFILE], !isChatRoom(hContact) && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_WALLPOST], !isChatRoom(hContact));
	Menu_ShowItem(g_hContactMenuItems[CMI_ADDASFRIEND], !bisFriend && !isChatRoom(hContact) && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_DELETEFRIEND], bisFriend && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_BANUSER], !isChatRoom(hContact) && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_REPORTABUSE], !isChatRoom(hContact) && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_DESTROYKICKCHAT], isChatRoom(hContact) && getBool(hContact, "off"));
	Menu_ShowItem(g_hContactMenuItems[CMI_OPENBROADCAST], !isChatRoom(hContact) && bisBroadcast);
	Menu_ShowItem(g_hContactMenuItems[CMI_GETSERVERHISTORY], !isChatRoom(hContact) && userID != VK_FEED_USER);
	Menu_ShowItem(g_hContactMenuItems[CMI_LOADVKNEWS], userID == VK_FEED_USER);
	for (int i = 0; i < CHMI_COUNT; i++)
		Menu_ShowItem(g_hContactHistoryMenuItems[i], !isChatRoom(hContact) && userID != VK_FEED_USER);
	return 0;
}