nsCrossSiteListenerProxy::nsCrossSiteListenerProxy(nsIStreamListener* aOuter,
        nsIPrincipal* aRequestingPrincipal,
        nsIChannel* aChannel,
        PRBool aWithCredentials,
        const nsCString& aPreflightMethod,
        const nsTArray<nsCString>& aPreflightHeaders,
        nsresult* aResult)
    : mOuterListener(aOuter),
      mRequestingPrincipal(aRequestingPrincipal),
      mWithCredentials(aWithCredentials && !gDisableCORSPrivateData),
      mRequestApproved(PR_FALSE),
      mHasBeenCrossSite(PR_FALSE),
      mIsPreflight(PR_TRUE),
      mPreflightMethod(aPreflightMethod),
      mPreflightHeaders(aPreflightHeaders)
{
    for (PRUint32 i = 0; i < mPreflightHeaders.Length(); ++i) {
        ToLowerCase(mPreflightHeaders[i]);
    }
    mPreflightHeaders.Sort();

    aChannel->GetNotificationCallbacks(getter_AddRefs(mOuterNotificationCallbacks));
    aChannel->SetNotificationCallbacks(this);

    *aResult = UpdateChannel(aChannel);
    if (NS_FAILED(*aResult)) {
        mOuterListener = nsnull;
        mRequestingPrincipal = nsnull;
        mOuterNotificationCallbacks = nsnull;
    }
}
NS_IMETHODIMP
nsCrossSiteListenerProxy::OnRedirectVerifyCallback(nsresult result)
{
  NS_ASSERTION(mRedirectCallback, "mRedirectCallback not set in callback");
  NS_ASSERTION(mOldRedirectChannel, "mOldRedirectChannel not set in callback");
  NS_ASSERTION(mNewRedirectChannel, "mNewRedirectChannel not set in callback");

  if (NS_SUCCEEDED(result)) {
      nsresult rv = UpdateChannel(mNewRedirectChannel);
      if (NS_FAILED(rv)) {
          NS_WARNING("nsCrossSiteListenerProxy::OnRedirectVerifyCallback: "
                     "UpdateChannel() returned failure");
      }
      result = rv;
  }

  if (NS_FAILED(result)) {
    mOldRedirectChannel->Cancel(result);
  }

  mOldRedirectChannel = nsnull;
  mNewRedirectChannel = nsnull;
  mRedirectCallback->OnRedirectVerifyCallback(result);
  mRedirectCallback   = nsnull;
  return NS_OK;
}
Beispiel #3
0
MumbleChannel::MumbleChannel(MumbleClient* client, MumbleProto::ChannelState& channelState)
	: m_client(client)
{
	m_hasDescription = false;
	m_temporary = false;

	UpdateChannel(channelState);
}
// Подключение к каналу виртуального пользователя.
void OnVirtualUserChannelConnect(BYTE *InBuffer) {
	String name, channel_name;

	try {
		// virtual user.
		GetStreamString (&InBuffer, &name);
		// channel.
		GetStreamString(&InBuffer, &channel_name);
		// topic.
		GetStreamString(&InBuffer, NULL);
		// greeting.
		GetStreamString(&InBuffer, NULL);

		LogicalConnections::iterator connection = FindConnectionByUser(name);
		OnlineUsersList::iterator user = GetConnectionUser(connection);
		ChannelsList::iterator channel = FindChannelByName(channel_name);
		StringList channel_users;
		if (!IsChannelMonitored(channel_name)) {
			AddChannelWatcher(name, channel_name);
			Channel channel_info = GetChannelInfo(channel_name);
			channel_users = GetChannelUsersList(name, channel_name);
			channel_info.online_users = channel_users.size();
			UpdateChannel(channel, GetChannelInfo(channel_name));
			for (unsigned int i = 0; i < channel_info.online_users; i++) {
				AddUserChannel(name, channel_name);
			}
		} else {
			AddUserChannel(name, channel_name);
			channel_users = GetChannelUsers(channel_name);
        }

		MapList params;
		params.insert(pair<String, String>("channel", channel_name));
		params.insert(pair<String, String>("topic", channel->topic));
		params.insert(pair<String, String>("greeting", channel->greeting));
		params.insert(pair<String, String>("users", "[" + implode(channel_users) + "]"));

		String json_object = SetParametersObject(params, true);
		SendNotification("virtual_user_channel_connect", json_object, connection, false);
	} catch (Exception *E) {
		throw(Format(e_virtual_user_channel_connect, ARRAYOFCONST((E->Message))));
	}
}
nsCrossSiteListenerProxy::nsCrossSiteListenerProxy(nsIStreamListener* aOuter,
        nsIPrincipal* aRequestingPrincipal,
        nsIChannel* aChannel,
        PRBool aWithCredentials,
        nsresult* aResult)
    : mOuterListener(aOuter),
      mRequestingPrincipal(aRequestingPrincipal),
      mWithCredentials(aWithCredentials && !gDisableCORSPrivateData),
      mRequestApproved(PR_FALSE),
      mHasBeenCrossSite(PR_FALSE),
      mIsPreflight(PR_FALSE)
{
    aChannel->GetNotificationCallbacks(getter_AddRefs(mOuterNotificationCallbacks));
    aChannel->SetNotificationCallbacks(this);

    *aResult = UpdateChannel(aChannel);
    if (NS_FAILED(*aResult)) {
        mOuterListener = nsnull;
        mRequestingPrincipal = nsnull;
        mOuterNotificationCallbacks = nsnull;
    }
}
NS_IMETHODIMP
nsCrossSiteListenerProxy::OnChannelRedirect(nsIChannel *aOldChannel,
        nsIChannel *aNewChannel,
        PRUint32    aFlags)
{
    nsChannelCanceller canceller(aOldChannel);
    nsresult rv;
    if (!NS_IsInternalSameURIRedirect(aOldChannel, aNewChannel, aFlags)) {
        rv = CheckRequestApproved(aOldChannel, PR_TRUE);
        if (NS_FAILED(rv)) {
            if (nsXMLHttpRequest::sAccessControlCache) {
                nsCOMPtr<nsIURI> oldURI;
                aOldChannel->GetURI(getter_AddRefs(oldURI));
                if (oldURI) {
                    nsXMLHttpRequest::sAccessControlCache->
                    RemoveEntries(oldURI, mRequestingPrincipal);
                }
            }
            return NS_ERROR_DOM_BAD_URI;
        }
    }

    nsCOMPtr<nsIChannelEventSink> outer =
        do_GetInterface(mOuterNotificationCallbacks);
    if (outer) {
        rv = outer->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    rv = UpdateChannel(aNewChannel);
    NS_ENSURE_SUCCESS(rv, rv);

    canceller.DontCancel();

    return NS_OK;
}