예제 #1
0
void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response)
{
	if (response == NULL)
		return;

	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	const JSONNode &metadata = root["_metadata"];
	const JSONNode &conversations = root["conversations"].as_array();

	int totalCount = metadata["totalCount"].as_int();
	std::string syncState = metadata["syncState"].as_string();

	if (totalCount >= 99 || conversations.size() >= 99)
		PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), (char*)m_szRegToken), &CSkypeProto::OnSyncHistory);

	for (size_t i = 0; i < conversations.size(); i++)
	{
		const JSONNode &conversation = conversations.at(i);
		const JSONNode &lastMessage = conversation["lastMessage"];
		const JSONNode &threadProperties = conversation["threadProperties"];
		if (!lastMessage)
			continue;

		std::string conversationLink = lastMessage["conversationLink"].as_string();
		if (conversationLink.find("/19:") != -1)
		{
			CMStringA skypename(ChatUrlToName(conversationLink.c_str()));
			CMString topic(threadProperties["topic"].as_mstring());
			SendRequest(new GetChatInfoRequest(m_szRegToken, skypename, m_szServer), &CSkypeProto::OnGetChatInfo, topic.Detach());
		}
	}
}
예제 #2
0
MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
{
	MCONTACT hContact = NULL;
	ptrA steamId(mir_u2a(psr->id.t));
	if (psr->cbSize == sizeof(PROTOSEARCHRESULT))
	{
		if (!FindContact(steamId))
		{
			//hContact = AddContact(steamId, true);
			//ForkThread(&CSteamProto::UpdateContactsThread, (void*)mir_strdup(steamId));

			ptrA token(getStringA("TokenSecret"));

			PushRequest(
				new GetUserSummariesRequest(token, steamId),
				&CSteamProto::OnGotUserSummaries);
		}
	}
	else if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT))
	{
		STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr;
		hContact = AddContact(steamId, true);
		UpdateContact(hContact, ssr->data);
	}

	return hContact;
}
예제 #3
0
void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p)
{
	TCHAR *topic = (TCHAR*)p;
	if (response == NULL || response->pData == NULL)
		return;

	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	const JSONNode &members = root["members"];
	const JSONNode &properties = root["properties"];
	if (!properties["capabilities"] || properties["capabilities"].empty())
		return;

	CMStringA chatId(ChatUrlToName(root["messages"].as_string().c_str()));
	StartChatRoom(_A2T(chatId), topic);
	for (size_t i = 0; i < members.size(); i++)
	{
		const JSONNode &member = members.at(i);

		CMStringA username(ContactUrlToName(member["userLink"].as_string().c_str()));
		std::string role = member["role"].as_string();
		if (!IsChatContact(_A2T(chatId), username))
			AddChatContact(_A2T(chatId), username, username, _A2T(role.c_str()), true);
	}
	PushRequest(new GetHistoryRequest(m_szRegToken, chatId, 15, true, 0, m_szServer), &CSkypeProto::OnGetServerHistory);
	mir_free(topic);
}
예제 #4
0
int CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
{
	if (IsOnline() && hDbEvent)
	{
		MCONTACT hContact = GetContactFromAuthEvent(hDbEvent);
		if (hContact == INVALID_CONTACT_ID)
			return 1;

		//ForkThread(&CSteamProto::AuthDenyThread, (void*)hContact);

		ptrA token(getStringA("TokenSecret"));
		ptrA sessionId(getStringA("SessionID"));
		ptrA steamId(getStringA("SteamID"));
		char *who = getStringA(hContact, "SteamID");

		PushRequest(
			new IgnorePendingRequest(token, sessionId, steamId, who),
			&CSteamProto::OnPendingIgnoreded,
			who, MirFreeArg);

		return 0;
	}

	return 1;
}
예제 #5
0
int CSkypeProto::GetInfo(MCONTACT hContact, int)
{
	if (!isChatRoom(hContact))
		PushRequest(
			new GetProfileRequest(li, ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))),
			&CSkypeProto::LoadProfile);
	return 0;
}
예제 #6
0
int CSkypeProto::OnContactDeleted(MCONTACT hContact, LPARAM)
{
	if (!IsOnline()) return 1;

	if (hContact && !isChatRoom(hContact))
		PushRequest(new DeleteContactRequest(li, ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))));
	return 0;
}
예제 #7
0
void CSteamProto::OnGotRsaKey(const HttpResponse *response)
{
	if (!CheckResponse(response))
		return;

	// load rsa key parts
	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	if (!root["success"].as_bool())
		return;

	std::string modulus = root["publickey_mod"].as_string();
	// exponent "010001" is used as constant in CSteamProto::RsaEncrypt
	//std::string exponent = root["publickey_exp"].as_string();

	std::string timestamp = root["timestamp"].as_string();

	// encrcrypt password
	ptrA base64RsaEncryptedPassword;
	ptrA szPassword(getStringA("Password"));

	DWORD error = 0;
	DWORD encryptedSize = 0;
	if ((error = RsaEncrypt(modulus.c_str(), szPassword, NULL, encryptedSize)) != 0)
	{
		debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
		return;
	}

	BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize);
	if ((error = RsaEncrypt(modulus.c_str(), szPassword, encryptedPassword, encryptedSize)) != 0)
	{
		debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
		return;
	}

	base64RsaEncryptedPassword = mir_base64_encode(encryptedPassword, encryptedSize);
	mir_free(encryptedPassword);

	// run authorization request
	T2Utf username(getTStringA("Username"));

	ptrA guardId(getStringA("GuardId"));
	if (!guardId) guardId = mir_strdup("");
	ptrA guardCode(getStringA("GuardCode"));
	if (!guardCode) guardCode = mir_strdup("");

	ptrA captchaId(getStringA("CaptchaId"));
	if (!captchaId) captchaId = mir_strdup("-1");
	ptrA captchaText(getStringA("CaptchaText"));
	if (!captchaText) captchaText = mir_strdup("");

	PushRequest(
		new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp.c_str(), "", guardCode, guardId, captchaId, captchaText),
		&CSteamProto::OnAuthorization);
}
예제 #8
0
void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
{
	if (response == NULL || response->pData == NULL)
		return;

	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	const JSONNode &metadata = root["_metadata"];
	const JSONNode &conversations = root["conversations"].as_array();

	int totalCount = metadata["totalCount"].as_int();
	std::string syncState = metadata["syncState"].as_string();

	if (totalCount >= 99 || conversations.size() >= 99)
		PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), li), &CSkypeProto::OnSyncHistory);

	for (size_t i = 0; i < conversations.size(); i++)
	{
		const JSONNode &conversation = conversations.at(i);
		const JSONNode &lastMessage = conversation["lastMessage"];
		if (lastMessage)
		{
			std::string strConversationLink = lastMessage["conversationLink"].as_string();

			if (strConversationLink.find("/8:") != -1)
			{
				CMStringA szSkypename = UrlToSkypename(strConversationLink.c_str());
				time_t composeTime(IsoToUnixTime(lastMessage["composetime"].as_string().c_str()));

				MCONTACT hContact = FindContact(szSkypename);
				if (hContact != NULL)
				{
					if (db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0) < composeTime)
					{
						PushRequest(new GetHistoryRequest(szSkypename, 100, false, 0, li), &CSkypeProto::OnGetServerHistory);
					}
				}
			}
		}
	}

	m_bHistorySynced = true;
}
예제 #9
0
INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM)
{
	if (hContact == INVALID_CONTACT_ID)
		return 1;

	ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
	PushRequest(new AuthAcceptRequest(li, skypename));
	return 0;
}
예제 #10
0
void CSkypeProto::ProcessTimer()
{
	if (IsOnline())
	{
		PushRequest(new GetContactListRequest(m_szTokenSecret), &CSkypeProto::LoadContactList);
		SendPresence(false);
		if (!m_hTrouterThread)
			SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter);
	}
}
예제 #11
0
void CSkypeProto::ProcessTimer()
{
    if (IsOnline())
    {
        PushRequest(new GetContactListRequest(li, NULL), &CSkypeProto::LoadContactList);
        SendPresence(false);
        //if (!m_hTrouterThread)
        //	SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter);
    }
}
예제 #12
0
int CSkypeProto::AuthRequest(MCONTACT hContact, const TCHAR *szMessage)
{
	if (hContact == INVALID_CONTACT_ID)
		return 1;

	ptrA token(getStringA("TokenSecret"));
	ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
	PushRequest(new AddContactRequest(li, skypename, T2Utf(szMessage)));
	return 0;
}
예제 #13
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);
}
예제 #14
0
void CSteamProto::OnAuthorizationSuccess(const JSONNode &node)
{
	delSetting("GuardId");
	delSetting("GuardCode");
	delSetting("CaptchaId");
	delSetting("CaptchaText");

	if (!node["login_complete"].as_bool())
	{
		SetStatus(ID_STATUS_OFFLINE);
		return;
	}

	std::string oauth = node["oauth"].as_string();
	JSONNode root = JSONNode::parse(oauth.c_str());
	if (!root)
	{
		SetStatus(ID_STATUS_OFFLINE);
		return;
	}

	std::string steamId = root["steamid"].as_string();
	setString("SteamID", steamId.c_str());

	std::string token = root["oauth_token"].as_string();
	setString("TokenSecret", token.c_str());

	std::string cookie = root["webcookie"].as_string();

	PushRequest(
		new GetSessionRequest(token.c_str(), steamId.c_str(), cookie.c_str()),
		&CSteamProto::OnGotSession);

	// We need to load homepage to get sessionid cookie
	PushRequest(
		new GetSessionRequest2(),
		&CSteamProto::OnGotSession);

	PushRequest(
		new LogonRequest(token.c_str()),
		&CSteamProto::OnLoggedOn);
}
예제 #15
0
INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM)
{
	ptrA token(getStringA("TokenSecret"));
	ptrA steamId(getStringA("SteamID"));

	PushRequest(
		new SteamWebApi::GetFriendListRequest(token, steamId, "ignoredfriend"),
		&CSteamProto::OnGotBlockList);

	return 0;
}
예제 #16
0
int CSkypeProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
{
	MCONTACT hContact = GetContactFromAuthEvent(hDbEvent);
	if (hContact == INVALID_CONTACT_ID)
		return 1;

	ptrA token(getStringA("TokenSecret"));
	ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
	PushRequest(new AuthDeclineRequest(li, skypename));
	return 0;
}
예제 #17
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);
	}
}
예제 #18
0
void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response)
{
	if (!IsStatusConnecting(m_iStatus)) return;

	if (response == NULL || response->pData == NULL)
	{
		ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
		SetStatus(ID_STATUS_OFFLINE);
		return;
	}

	SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), li), &CSkypeProto::OnStatusChanged);

	LIST<char> skypenames(1);
	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
	{
		if (!isChatRoom(hContact))
			skypenames.insert(getStringA(hContact, SKYPE_SETTINGS_ID));
	}
	SendRequest(new CreateContactsSubscriptionRequest(skypenames, li));
	FreeList(skypenames);
	skypenames.destroy();

	m_hPollingEvent.Set();

	SendRequest(new LoadChatsRequest(li), &CSkypeProto::OnLoadChats);
	SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter);
	PushRequest(new GetContactListRequest(li, NULL), &CSkypeProto::LoadContactList);
	PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl"))), &CSkypeProto::OnReceiveAvatar, NULL);
	
	if (getBool("AutoSync", true))
		PushRequest(new SyncHistoryFirstRequest(100, li), &CSkypeProto::OnSyncHistory);

	JSONNode root = JSONNode::parse(response->pData);
	if (root)
		setString("SelfEndpointName", UrlToSkypename(root["selfLink"].as_string().c_str()));

	PushRequest(new GetProfileRequest(li), &CSkypeProto::LoadProfile);
}
예제 #19
0
int CSteamProto::BlockCommand(WPARAM hContact, LPARAM)
{
	ptrA token(getStringA("TokenSecret"));
	ptrA sessionId(getStringA("SessionID"));
	ptrA steamId(getStringA("SteamID"));
	char *who = getStringA(hContact, "SteamID");

	PushRequest(
		new SteamWebApi::BlockFriendRequest(token, sessionId, steamId, who),
		&CSteamProto::OnFriendBlocked,
		who);

	return 0;
}
예제 #20
0
HANDLE CSteamProto::SearchBasic(const TCHAR* id)
{
	if (!this->IsOnline())
		return 0;

	//ForkThread(&CSteamProto::SearchByIdThread, mir_wstrdup(id));

	ptrA token(getStringA("TokenSecret"));
	ptrA steamId(mir_t2a(id));

	PushRequest(
		new GetUserSummariesRequest(token, steamId),
		&CSteamProto::OnSearchByIdEnded,
		mir_tstrdup(id),
		MirFreeArg);

	return (HANDLE)STEAM_SEARCH_BYID;
}
예제 #21
0
void LcEpollCli::EpollSend(OverLap* pOverLap)
{
	int fd = pOverLap->fd;

	pthread_mutex_lock(&m_SndSync);
	OverLap* pSndList = pOverLap->pSndList;
	pOverLap->pSndList = NULL;
	pthread_mutex_unlock(&m_SndSync);

	while(pSndList)
	{
		pSndList->uiSndFinishLen = 0;
		while(pSndList->uiSndComLen > 0)
		{
			int ret = send(fd, pSndList->szpComBuf + pSndList->uiSndFinishLen, pSndList->uiSndComLen, MSG_NOSIGNAL);
			if(ret == -1 && errno == EAGAIN)
			{
				PushRequest(pSndList);
				return;
			}
			else if(ret == 0 || ret > (int)pSndList->uiSndComLen)
			{
				RemoveConnect(pOverLap);
				return;
			}
			else if(ret == -1)
			{
				RemoveConnect(pOverLap);
				return;
			}

			pSndList->uiSndFinishLen += ret;
			pSndList->uiSndComLen -= ret;
		}

		pOverLap->u64PacketSnd += 1;
		OverLap* pTmpOverLap = pSndList;
		pSndList = pSndList->pSndList;
		pTmpOverLap->pSndList = NULL;
		m_IONetSndMemQue.Push((long)pTmpOverLap);
	}
}
예제 #22
0
void CSkypeProto::SendPresence(bool isLogin)
{
	ptrA epname;

	ptrT place(getTStringA("Place"));
	if (!getBool("UseHostName", false) && place && *place)
		epname = mir_utf8encodeT(place);
	else
	{
		TCHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
		DWORD size = _countof(compName);
		GetComputerName(compName, &size);
		epname = mir_utf8encodeT(compName);
	}

	if (isLogin)
		SendRequest(new SendCapabilitiesRequest(epname, li), &CSkypeProto::OnCapabilitiesSended);
	else 
		PushRequest(new SendCapabilitiesRequest(epname, li));
}
예제 #23
0
int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
	switch (eventType)
	{
	case EV_PROTO_ONLOAD:
		return this->OnModulesLoaded(wParam, lParam);

	case EV_PROTO_ONEXIT:
		return this->OnPreShutdown(wParam, lParam);

	/*case EV_PROTO_ONOPTIONS:
		return this->OnOptionsInit(wParam, lParam);*/

	case EV_PROTO_ONCONTACTDELETED:
		if (IsOnline())
		{
			MCONTACT hContact = (MCONTACT)wParam;

			ptrA token(getStringA("TokenSecret"));
			ptrA sessionId(getStringA("SessionID"));
			ptrA steamId(getStringA("SteamID"));
			ptrA who(getStringA(hContact, "SteamID"));

			// Don't request delete contact from server when we're not friends anyway
			if (getByte(hContact, "Auth", 0) != 0)
				return 0;

			PushRequest(
				new RemoveFriendRequest(token, sessionId, steamId, who),
				&CSteamProto::OnFriendRemoved,
				(void*)hContact);
		}
		return 0;

	case EV_PROTO_ONMENU:
		this->OnInitStatusMenu();
		break;
	}

	return 1;
}
nsresult sbRequestThreadQueue::Start()
{
  TRACE_FUNCTION("");
  // Ensure we've allocated our lock and monitor
  NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
  NS_ENSURE_TRUE(mStopWaitMonitor, NS_ERROR_OUT_OF_MEMORY);

  nsresult rv;

  // No need to lock since Start should not be called while the request thread
  // is running or from multiple threads.
  // Start should not be called more than once before Stop is called.
  NS_ENSURE_FALSE(mThreadStarted, NS_ERROR_FAILURE);

  // Clear the stop request processing flag. No need to lock since this is
  // the only live thread with access to the object.
  mStopProcessing = false;

  // Create the request added event object.
  rv = sbRTQAddedEvent::New(this, getter_AddRefs(mReqAddedEvent));
  NS_ENSURE_SUCCESS(rv, rv);


  rv = sbRunnableMethod(*this,
                        &sbRequestThreadQueue::ThreadShutdownAction,
                        NS_ERROR_FAILURE,
                        0,
                        getter_AddRefs(mShutdownAction));
  NS_ENSURE_SUCCESS(rv, rv);

  mThreadStarted = true;

  // Create the request processing thread.
  rv = NS_NewThread(getter_AddRefs(mThread), nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = PushRequest(sbRequestItem::New(REQUEST_THREAD_START));
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
예제 #25
0
int CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
{
	if (IsOnline() && hContact)
	{
		UINT hAuth = InterlockedIncrement(&hAuthProcess);

		SendAuthParam *param = (SendAuthParam*)mir_calloc(sizeof(SendAuthParam));
		param->hContact = hContact;
		param->hAuth = (HANDLE)hAuth;

		//ForkThread(&CSteamProto::AddContactThread, param);

		ptrA token(getStringA("TokenSecret"));
		ptrA sessionId(getStringA("SessionID"));
		ptrA steamId(getStringA("SteamID"));
		ptrA who(getStringA(hContact, "SteamID"));

		/*
		posilame: (kdyz my zadame)
		sessionID	MjYzNDM4NDgw
		steamid	76561198166125402
		accept_invite	0

		pri uspesnem pozadavku vrati: {"invited":["76561198166125402"],"success":1}
		kdyz nas ignoruje: {"failed_invites":["76561198166125402"],"failed_invites_result":[41],"success":1}

		*/

		PushRequest(
			new AddFriendRequest(token, sessionId, steamId, who),
			&CSteamProto::OnFriendAdded,
			param);

		return hAuth;
	}

	return 1;
}
예제 #26
0
INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM)
{
	PushRequest(new GetHistoryRequest(ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID)), 100, false, 0, li), &CSkypeProto::OnGetServerHistory);
	return 0;
}
nsresult
sbIPDDevice::ConnectInternal()
{
  nsresult rv;

  // Do nothing if device is already connected.  If the device is not connected,
  // nothing should be accessing the "connect lock" fields.
  {
    sbAutoReadLock autoConnectLock(mConnectLock);
    if (mConnected)
      return NS_OK;
  }

  // Invoke the super-class.
  rv = sbBaseDevice::Connect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the device properties.
  nsCOMPtr<nsIPropertyBag2> properties = do_QueryInterface(mCreationProperties,
                                                           &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the device mount path.
  rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("MountPath"),
                                        mMountPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the Firewire GUID.
  rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("FirewireGUID"),
                                        mFirewireGUID);
  if (NS_SUCCEEDED(rv)) {
    FIELD_LOG
      (("Connect %s\n", NS_LossyConvertUTF16toASCII(mFirewireGUID).get()));
  } else {
    FIELD_LOG(("Connect could not get iPod Firewire GUID.\n"));
  }

  // Connect the device capabilities.
  rv = CapabilitiesConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the iPod database.
  rv = DBConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the iPod preference services.
  rv = PrefConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the Songbird device library.
  rv = LibraryConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the FairPlay services.
  rv = FPConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Mark the device as connected.  After this, "connect lock" fields may be
  // used.
  {
    sbAutoWriteLock autoConnectLock(mConnectLock);
    mConnected = PR_TRUE;
  }

  // Start the iPod request processing.
  rv = ReqProcessingStart();
  NS_ENSURE_SUCCESS(rv, rv);

  // Mount the device.
  //XXXeps Do in DBConnect
  rv = PushRequest(TransferRequest::REQUEST_MOUNT, nsnull, mDeviceLibrary);
  NS_ENSURE_SUCCESS(rv, rv);

  // Set up the iPod for the first time if needed
  rv = SetUpIfNeeded();
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
예제 #28
0
void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
{
	if (response == NULL)
		return;

	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	const JSONNode &metadata = root["_metadata"];
	const JSONNode &conversations = root["messages"].as_array();

	int totalCount = metadata["totalCount"].as_int();
	std::string syncState = metadata["syncState"].as_string();

	bool markAllAsUnread = getBool("MarkMesUnread", true);

	if (totalCount >= 99 || conversations.size() >= 99)
		PushRequest(new GetHistoryOnUrlRequest(syncState.c_str(), li), &CSkypeProto::OnGetServerHistory);

	for (int i = (int)conversations.size(); i >= 0; i--)
	{
		const JSONNode &message = conversations.at(i);

		CMStringA szMessageId = message["clientmessageid"] ? message["clientmessageid"].as_string().c_str() : message["skypeeditedid"].as_string().c_str();

		std::string messageType = message["messagetype"].as_string();
		std::string from = message["from"].as_string();
		std::string content = message["content"].as_string();
		std::string conversationLink = message["conversationLink"].as_string();
		int emoteOffset = message["skypeemoteoffset"].as_int();
		time_t timestamp = IsoToUnixTime(message["composetime"].as_string().c_str());
		CMStringA skypename(UrlToSkypename(from.c_str()));

		bool isEdited = message["skypeeditedid"];

		MCONTACT hContact = FindContact(UrlToSkypename(conversationLink.c_str()));
			  
		if (timestamp > db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0))
			db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp);

		int iFlags = DBEF_UTF;

		if (!markAllAsUnread)
			iFlags |= DBEF_READ;

		if (IsMe(skypename))
			iFlags |= DBEF_SENT;

		if (strstr(conversationLink.c_str(), "/8:"))
		{
			if (messageType == "Text" || messageType == "RichText")
			{
				ptrA szMessage(messageType == "RichText" ? RemoveHtml(content.c_str()) : mir_strdup(content.c_str()));
				MEVENT dbevent = GetMessageFromDb(hContact, szMessageId);

				if (isEdited && dbevent != NULL)
				{
					AppendDBEvent(hContact, dbevent, szMessage, szMessageId, timestamp);
				}
				else AddDbEvent(emoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact, timestamp, iFlags, &szMessage[emoteOffset], szMessageId);
			}
			else if (messageType == "Event/Call")
			{
				AddDbEvent(SKYPE_DB_EVENT_TYPE_CALL_INFO, hContact, timestamp, iFlags, content.c_str(), szMessageId);
			}
			else if (messageType == "RichText/Files")
			{
				AddDbEvent(SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO, hContact, timestamp, iFlags, content.c_str(), szMessageId);
			}
			else if (messageType == "RichText/UriObject")
			{
				AddDbEvent(SKYPE_DB_EVENT_TYPE_URIOBJ, hContact, timestamp, iFlags, content.c_str(), szMessageId);
			}
			else if (messageType == "RichText/Contacts")
			{
				ProcessContactRecv(hContact, timestamp, content.c_str(), szMessageId);
			}
			else
			{
				AddDbEvent(SKYPE_DB_EVENT_TYPE_UNKNOWN, hContact, timestamp, iFlags, content.c_str(), szMessageId);
			}
		}
		else if (conversationLink.find("/19:") != -1)
		{
			CMStringA chatname(UrlToSkypename(conversationLink.c_str()));
			if (messageType == "Text" || messageType == "RichText")
			{
				AddMessageToChat(_A2T(chatname), _A2T(skypename), content.c_str(), emoteOffset != NULL, emoteOffset, timestamp, true);
			}
		}
	}
}
예제 #29
0
void CSteamProto::OnAuthorizationError(const JSONNode &node)
{
	std::string message = node["message"].as_string();
	ptrT messageT(mir_utf8decodeT(message.c_str()));
	if (!mir_tstrcmpi(messageT, _T("Incorrect login.")))
	{
		// We can't continue with incorrect login/password
		delSetting("GuardId");
		delSetting("GuardCode");
		delSetting("CaptchaId");
		delSetting("CaptchaText");
		SetStatus(ID_STATUS_OFFLINE);
		return;
	}

	T2Utf username(getTStringA("Username"));

	if (node["requires_twofactor"].as_bool())
	{
		return;
	}

	if (node["emailauth_needed"].as_bool())
	{
		std::string guardId = node["emailsteamid"].as_string();
		ptrA oldGuardId(getStringA("GuardId"));
		if (mir_strcmp(guardId.c_str(), oldGuardId) == 0)
		{
			delSetting("GuardId");
			delSetting("GuardCode");
			PushRequest(
				new GetRsaKeyRequest(username),
				&CSteamProto::OnGotRsaKey);
			return;
		}

		std::string domain = node["emaildomain"].as_string();

		// Make absolute link
		if (domain.find("://") == std::string::npos)
			domain = "http://" + domain;

		CSteamGuardDialog guardDialog(this, domain.c_str());
		if (guardDialog.DoModal() != DIALOG_RESULT_OK)
		{
			delSetting("GuardId");
			delSetting("GuardCode");
			delSetting("CaptchaId");
			delSetting("CaptchaText");
			SetStatus(ID_STATUS_OFFLINE);
			return;
		}

		setString("GuardId", guardId.c_str());
		setString("GuardCode", guardDialog.GetGuardCode());

		PushRequest(
			new GetRsaKeyRequest(username),
			&CSteamProto::OnGotRsaKey);
		return;
	}

	if (node["captcha_needed"].as_bool())
	{
		std::string captchaId = node["captcha_gid"].as_string();

		GetCaptchaRequest *request = new GetCaptchaRequest(captchaId.c_str());
		HttpResponse *response = request->Send(m_hNetlibUser);
		delete request;

		CSteamCaptchaDialog captchaDialog(this, (BYTE*)response->pData, response->dataLength);
		delete response;
		if (captchaDialog.DoModal() != DIALOG_RESULT_OK)
		{
			delSetting("CaptchaId");
			delSetting("CaptchaText");
			SetStatus(ID_STATUS_OFFLINE);
			return;
		}

		setString("CaptchaId", captchaId.c_str());
		setString("CaptchaText", captchaDialog.GetCaptchaText());

		PushRequest(
			new GetRsaKeyRequest(username),
			&CSteamProto::OnGotRsaKey);
		return;
	}

	delSetting("GuardId");
	delSetting("GuardCode");
	delSetting("CaptchaId");
	delSetting("CaptchaText");
	SetStatus(ID_STATUS_OFFLINE);
}
예제 #30
0
void CSteamProto::ParsePollData(JSONNode *data)
{
	JSONNode *node, *item = NULL;

	std::string steamIds;
	for (size_t i = 0; i < json_size(data); i++)
	{
		item = json_at(data, i);
		if (item == NULL)
			break;

		node = json_get(item, "steamid_from");
		ptrA steamId(mir_t2a(ptrT(json_as_string(node))));

		node = json_get(item, "utc_timestamp");
		time_t timestamp = atol(ptrA(mir_t2a(ptrT(json_as_string(node)))));

		node = json_get(item, "type");
		ptrT type(json_as_string(node));
		if (!lstrcmpi(type, _T("saytext")) || !lstrcmpi(type, _T("emote")) ||
			!lstrcmpi(type, _T("my_saytext")) || !lstrcmpi(type, _T("my_emote")))
		{
			MCONTACT hContact = FindContact(steamId);
			if (!hContact)
				continue;

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

			if (_tcsstr(type, _T("my_")) == NULL)
			{
				PROTORECVEVENT recv = { 0 };
				recv.timestamp = timestamp;
				recv.szMessage = szMessage;
				ProtoChainRecvMsg(hContact, &recv);
			}
			else
			{
				AddDBEvent(hContact, EVENTTYPE_MESSAGE, timestamp, DBEF_UTF | DBEF_SENT, (int)mir_strlen(szMessage) + 1, (PBYTE)(char*)szMessage);
			}
		}
		else if (!lstrcmpi(type, _T("typing")))
		{
			MCONTACT hContact = FindContact(steamId);
			if (hContact)
			{
				CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)STEAM_TYPING_TIME);
			}
		}
		else if (!lstrcmpi(type, _T("personastate")))
		{
			node = json_get(item, "persona_state");
			int status = node ? SteamToMirandaStatus(json_as_int(node)) : -1;

			if (IsMe(steamId))
			{
				node = json_get(item, "persona_name");
				setTString("Nick", ptrT(json_as_string(node)));

				if (status == -1 || status == ID_STATUS_OFFLINE)
					continue;

				if (status != m_iStatus)
				{
					debugLog(_T("CSteamProto::ParsePollData: Change own status to %i"), status);
					int oldStatus = m_iStatus;
					m_iStatus = m_iDesiredStatus = status;
					ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
				}

				continue;
			}
			
			MCONTACT hContact = FindContact(steamId);
			if (hContact == NULL)
				continue; // probably this is info about random player playing on same server, so we ignore it

			if (status != -1)
				SetContactStatus(hContact, status);

			node = json_get(item, "persona_name");
			setTString(hContact, "Nick", ptrT(json_as_string(node)));

			// todo: find difference between state changing and info changing
			steamIds.append(steamId).append(",");
		}
		else if (!lstrcmpi(type, _T("personarelationship")))
		{
			node = json_get(item, "persona_state");
			int state = json_as_int(node);

			switch (state)
			{
			case 0:
				{// removed
					MCONTACT hContact = FindContact(steamId);
					if (hContact)
					{
						ContactIsRemoved(hContact);
					}
				}
				break;

			case 1:
				{// ignored
					MCONTACT hContact = FindContact(steamId);
					if (hContact)
					{
						ContactIsIgnored(hContact);
					}
				}
				break;

			case 2:
				{// auth request
					/*MCONTACT hContact = FindContact(steamId);
					if (!hContact)
						hContact = AddContact(steamId, true);*/

					//RaiseAuthRequestThread((void*)hContact);

					ptrA token(getStringA("TokenSecret"));

					PushRequest(
						new GetUserSummariesRequest(token, steamId),
						&CSteamProto::OnAuthRequested,
						mir_strdup(steamId),
						MirFreeArg);
				}
				break;

			case 3:
				// add to list
				// todo
				break;

			default: continue;
			}
		}
		/*else if (!lstrcmpi(type, _T("leftconversation")))
		{
		}*/
		else
		{
			continue;
		}
	}

	if (!steamIds.empty())
	{
		steamIds.pop_back();
		ptrA token(getStringA("TokenSecret"));

		PushRequest(
			new GetUserSummariesRequest(token, steamIds.c_str()),
			&CSteamProto::OnGotUserSummaries);
	}
}