void CCBServer::ForwardRequestToTarget( CCBServerRequest *request, CCBTarget *target ) { Sock *sock = target->getSock(); ClassAd msg; msg.Assign( ATTR_COMMAND, CCB_REQUEST ); msg.Assign( ATTR_MY_ADDRESS, request->getReturnAddr() ); msg.Assign( ATTR_CLAIM_ID, request->getConnectID() ); // for easier debugging msg.Assign( ATTR_NAME, request->getSock()->peer_description() ); MyString reqid_str; CCBIDToString( request->getRequestID(), reqid_str); msg.Assign( ATTR_REQUEST_ID, reqid_str ); sock->encode(); if( !msg.put( *sock ) || !sock->end_of_message() ) { dprintf(D_ALWAYS, "CCB: failed to forward request id %lu from %s to target " "daemon %s with ccbid %lu\n", request->getRequestID(), request->getSock()->peer_description(), target->getSock()->peer_description(), target->getCCBID()); RequestFinished( request, false, "failed to forward request to target" ); return; } // Now wait for target to respond (HandleRequestResultsMsg). // We will get the response next time we poll the socket. // To get a faster response, we _could_ register the socket // now, if it has not already been registered. }
void MusicDnsClient::Start(int id, const QString& fingerprint, int duration_msec) { typedef QPair<QString, QString> Param; QList<Param> parameters; parameters << Param("alb", "unknown") << Param("art", "unknown") << Param("brt", "0") << Param("cid", kClientId) << Param("cvr", QString("%1 %2").arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion())) << Param("dur", QString::number(duration_msec)) << Param("fmt", "unknown") << Param("fpt", fingerprint) << Param("gnr", "unknown") << Param("rmd", "1") << Param("tnm", "0") << Param("ttl", "unknown") << Param("yrr", "0"); QUrl url(kUrl); url.setQueryItems(parameters); QNetworkRequest req(url); QNetworkReply* reply = network_->get(req); connect(reply, SIGNAL(finished()), SLOT(RequestFinished())); requests_[reply] = id; timeouts_->AddReply(reply); }
void LastfmTrackInfoProvider::FetchInfo(int id, const Song& metadata) { QMap<QString, QString> params; params["method"] = "track.getInfo"; params["track"] = metadata.title(); params["artist"] = metadata.artist(); if (!lastfm::ws::Username.isEmpty()) params["username"] = lastfm::ws::Username; QNetworkReply* reply = lastfm::ws::get(params); connect(reply, SIGNAL(finished()), SLOT(RequestFinished())); requests_[reply] = id; }
void TeamWorkApi::IssueRequest( QString strUrl, QString strData ){ strCurrentRequest.clear(); QNetworkRequest objRequest = CreateRequestObject( strUrl ); if( 0 < strData.length() ) pobjReply = objNetwork.post( objRequest, strData.toAscii() ); else pobjReply = objNetwork.get( objRequest ); QObject::connect( pobjReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( HandleHttpError( QNetworkReply::NetworkError ) ) ); QObject::connect( pobjReply, SIGNAL( finished() ), this, SLOT( RequestFinished() ) ); QObject::connect( pobjReply, SIGNAL( readyRead() ), this, SLOT( ReadHttpData() ) ); }
void CCBServer::HandleRequestResultsMsg( CCBTarget *target ) { // Reply from target daemon about whether it succeeded in // connecting to the requested client. Sock *sock = target->getSock(); ClassAd msg; sock->decode(); if( !msg.initFromStream( *sock ) || !sock->end_of_message() ) { // disconnect dprintf(D_FULLDEBUG, "CCB: received disconnect from target daemon %s " "with ccbid %lu.\n", sock->peer_description(), target->getCCBID() ); RemoveTarget( target ); return; } int command = 0; if( msg.LookupInteger( ATTR_COMMAND, command ) && command == ALIVE ) { SendHeartbeatResponse( target ); return; } target->decPendingRequestResults(); bool success = false; MyString error_msg; MyString reqid_str; CCBID reqid; MyString connect_id; msg.LookupBool( ATTR_RESULT, success ); msg.LookupString( ATTR_ERROR_STRING, error_msg ); msg.LookupString( ATTR_REQUEST_ID, reqid_str ); msg.LookupString( ATTR_CLAIM_ID, connect_id ); if( !CCBIDFromString( reqid, reqid_str.Value() ) ) { MyString msg_str; msg.sPrint(msg_str); dprintf(D_ALWAYS, "CCB: received reply from target daemon %s with ccbid %lu " "without a valid request id: %s\n", sock->peer_description(), target->getCCBID(), msg_str.Value()); RemoveTarget( target ); return; } CCBServerRequest *request = GetRequest( reqid ); if( request && request->getSock()->readReady() ) { // Request socket must have just closed. To avoid noise in // logs when we fail to write to it, delete the request now. RemoveRequest( request ); request = NULL; } char const *request_desc = "(client which has gone away)"; if( request ) { request_desc = request->getSock()->peer_description(); } if( success ) { dprintf(D_FULLDEBUG,"CCB: received 'success' from target daemon %s " "with ccbid %lu for " "request %s from %s.\n", sock->peer_description(), target->getCCBID(), reqid_str.Value(), request_desc); } else { dprintf(D_FULLDEBUG,"CCB: received error from target daemon %s " "with ccbid %lu for " "request %s from %s: %s\n", sock->peer_description(), target->getCCBID(), reqid_str.Value(), request_desc, error_msg.Value()); } if( !request ) { if( success ) { // expected: the client has gone away; it got what it wanted return; } dprintf( D_FULLDEBUG, "CCB: client for request %s to target daemon %s with ccbid " "%lu disappeared before receiving error details.\n", reqid_str.Value(), sock->peer_description(), target->getCCBID()); return; } if( connect_id != request->getConnectID() ) { MyString msg_str; msg.sPrint(msg_str); dprintf( D_FULLDEBUG, "CCB: received wrong connect id (%s) from target daemon %s " "with ccbid %lu for " "request %s\n", connect_id.Value(), sock->peer_description(), target->getCCBID(), reqid_str.Value()); RemoveTarget( target ); return; } RequestFinished( request, success, error_msg.Value() ); }