Exemple #1
0
void Request::handleRouterComplete() {
  if (router_->receivedData()) {
    onRequestComplete();
    return;
  } else { /* keep trying to route this packet until it expires */
    if (packet_->expired()) {
      onRequestComplete();
      return;
    }
    printf("Route failed. Retrying...\n");
    routePacket();
  }
}
Exemple #2
0
void Request::routePacket() {
  if (peers_.empty()) {
    printf("We are out of peers to try and route to.\n");
    onRequestComplete();
    return;
  }
  if (!respond(BinaryBuffer())) {
    printf("The tunnel has failed (1).\n");
    onRequestComplete();
    return;
  }
  BinaryBuffer request = decrementHopCount(request_);
  assert(!router_ || router_->stopped());
  router_ = boost::make_shared<Router>(boost::ref(io_), popPeer(), request);
  router_->onReceive.connect(boost::bind(&Request::handleRouterBuffer, this, _1));
  router_->onDisconnect.connect(boost::bind(&Request::handleRouterComplete, this));
}
Exemple #3
0
void HttpClient::startRequest(std::string& url)
{
    http_request_.setDataCallback([this] (uint8_t* data, uint32_t len) { onData(data, len); });
    http_request_.setWriteCallback([this] (int err) { onSend(err); });
    http_request_.setErrorCallback([this] (int err) { onClose(err); });
    http_request_.setHeaderCompleteCallback([this] { onHeaderComplete(); });
    http_request_.setResponseCompleteCallback([this] { onRequestComplete(); });
    http_request_.sendRequest("GET", url.c_str(), "HTTP/1.1");
}
Exemple #4
0
void Request::handleRequest(boost::shared_ptr<libtorrent::socket_type>& socket, const libtorrent::rc4_handler& cipher) {
  if (!packet_ || packet_->expired()) {
    socket->close();
    onRequestComplete();
    return;
  }
  
  if (!!socket_) {
    /* we are currently handling exactly the same request for another peer */
    socket->close(); /* note that we are closing the second connection only */
    return;
  }

  socket_ = socket;
  cipher_ = cipher;
  channelReady_ = false;

  if (state_ == StateInitializing) {
    state_ = initializeState(socket);
  }

  if (state_ == StateArpUnresolved) {
    respond(BinaryBuffer());
    closeSocket();
    return;
  }

  if (state_ == StateArpResolved) {
    BinaryBuffer response = arpTable_.query(packet_->payload, externalEndpoint_);
    if (!response.empty()) {
      printf("Responding to an ARP request.\n");
      respond(response);
    }
    closeSocket();
    return;
  }

  if (state_ == StateComplete) {
    onRequestComplete();
    return;
  }
}
PlaylistQueryManager::PlaylistQueryManager(QObject *parent, MafwPlaylistAdapter *mafwPlaylist) :
    QObject(parent),
    mafwPlaylist(mafwPlaylist)
{
    priority = 0;
    getItemsOp = NULL;
    connect(mafwPlaylist, SIGNAL(gotItem(QString,GHashTable*,uint,gpointer)),
            this, SLOT(onItemReceived(QString,GHashTable*,uint,gpointer)));
    connect(mafwPlaylist, SIGNAL(getItemsComplete(gpointer)),
            this, SLOT(onRequestComplete(gpointer)));
}
Exemple #6
0
int HttpTest::attachSocket(TcpSocket&& tcp, HttpParser&& parser)
{
    http_.setWriteCallback([this] (int err) { onSend(err); });
    http_.setErrorCallback([this] (int err) { onClose(err); });
    
    http_.setDataCallback([this] (uint8_t* data, uint32_t len) { onHttpData(data, len); });
    http_.setHeaderCompleteCallback([this] () { onHeaderComplete(); });
    http_.setRequestCompleteCallback([this] () { onRequestComplete(); });
    http_.setResponseCompleteCallback([this] () { onResponseComplete(); });
    
    return http_.attachSocket(std::move(tcp), std::move(parser));
}
Exemple #7
0
int HttpTest::attachFd(SOCKET_FD fd, uint32_t ssl_flags)
{
    http_.setWriteCallback([this] (int err) { onSend(err); });
    http_.setErrorCallback([this] (int err) { onClose(err); });
    
    http_.setDataCallback([this] (uint8_t* data, uint32_t len) { onHttpData(data, len); });
    http_.setHeaderCompleteCallback([this] () { onHeaderComplete(); });
    http_.setRequestCompleteCallback([this] () { onRequestComplete(); });
    http_.setResponseCompleteCallback([this] () { onResponseComplete(); });
    http_.setSslFlags(ssl_flags);
    return http_.attachFd(fd);
}
Exemple #8
0
bool ResourceHandle::start()
{
    if (firstRequest().url().isLocalFile() || firstRequest().url().protocolIsData()) {
        ref(); // balanced by deref in fileLoadTimer
        if (d->m_loadSynchronously)
            fileLoadTimer(0);
        else
            d->m_fileLoadTimer.startOneShot(0.0);
        return true;
    }

    if (!d->m_internetHandle)
        d->m_internetHandle = asynchronousInternetHandle(d->m_context->userAgent());

    if (!d->m_internetHandle)
        return false;

    DWORD flags = INTERNET_FLAG_KEEP_CONNECTION
        | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
        | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
        | INTERNET_FLAG_DONT_CACHE
        | INTERNET_FLAG_RELOAD;

    d->m_connectHandle = InternetConnectW(d->m_internetHandle, firstRequest().url().host().charactersWithNullTermination(), firstRequest().url().port(),
                                          0, 0, INTERNET_SERVICE_HTTP, flags, reinterpret_cast<DWORD_PTR>(this));

    if (!d->m_connectHandle)
        return false;

    String urlStr = firstRequest().url().path();
    String urlQuery = firstRequest().url().query();

    if (!urlQuery.isEmpty()) {
        urlStr.append('?');
        urlStr.append(urlQuery);
    }

    String httpMethod = firstRequest().httpMethod();
    String httpReferrer = firstRequest().httpReferrer();

    LPCWSTR httpAccept[] = { L"*/*", 0 };

    d->m_requestHandle = HttpOpenRequestW(d->m_connectHandle, httpMethod.charactersWithNullTermination(), urlStr.charactersWithNullTermination(),
                                          0, httpReferrer.charactersWithNullTermination(), httpAccept, flags, reinterpret_cast<DWORD_PTR>(this));

    if (!d->m_requestHandle) {
        InternetCloseHandle(d->m_connectHandle);
        return false;
    }

    if (firstRequest().httpBody()) {
        firstRequest().httpBody()->flatten(d->m_formData);
        d->m_bytesRemainingToWrite = d->m_formData.size();
    }

    Vector<UChar> httpHeaders;
    const HTTPHeaderMap& httpHeaderFields = firstRequest().httpHeaderFields();

    for (HTTPHeaderMap::const_iterator it = httpHeaderFields.begin(); it != httpHeaderFields.end(); ++it) {
        if (equalIgnoringCase(it->key, "Accept") || equalIgnoringCase(it->key, "Referer") || equalIgnoringCase(it->key, "User-Agent"))
            continue;

        if (!httpHeaders.isEmpty())
            httpHeaders.append('\n');

        httpHeaders.append(it->key.characters(), it->key.length());
        httpHeaders.append(':');
        httpHeaders.append(it->value.characters(), it->value.length());
    }

    INTERNET_BUFFERSW internetBuffers;
    ZeroMemory(&internetBuffers, sizeof(internetBuffers));
    internetBuffers.dwStructSize = sizeof(internetBuffers);
    internetBuffers.lpcszHeader = httpHeaders.data();
    internetBuffers.dwHeadersLength = httpHeaders.size();
    internetBuffers.dwBufferTotal = d->m_bytesRemainingToWrite;

    HttpSendRequestExW(d->m_requestHandle, &internetBuffers, 0, 0, reinterpret_cast<DWORD_PTR>(this));

    ref(); // balanced by deref in onRequestComplete

    if (d->m_loadSynchronously)
        while (onRequestComplete()) {
            // Loop until finished.
        }

    return true;
}
Exemple #9
0
HttpsRequest::HttpsRequest(ds::ui::SpriteEngine& eng)
	: mRequests(eng)
{
	mRequests.setReplyHandler([this](HttpsRequest::IndividualRequest& q){onRequestComplete(q); });
}