void MusicRadioPlayListThread::startToDownload(const QString &id) { m_manager = new QNetworkAccessManager(this); QNetworkRequest request; request.setUrl(QUrl(playListUrl + id)); #ifndef QT_NO_SSL connect(m_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); M_LOGGER_INFO(QString("MusicRadioPlayListThread Support ssl: %1").arg(QSslSocket::supportsSsl())); QSslConfiguration sslConfig = request.sslConfiguration(); sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(sslConfig); #endif if(m_cookJar) { m_manager->setCookieJar(m_cookJar); m_cookJar->setParent(nullptr); } m_reply = m_manager->get(request); connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError))); }
QGeoCodeReply *QGeoCodingManagerEngineKokudo::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds) { Q_UNUSED(offset) QNetworkRequest request; request.setRawHeader("User-Agent", m_userAgent); QUrl url(QString("%1/search").arg(m_urlPrefix)); QUrlQuery query; query.addQueryItem(QStringLiteral("q"), address); query.addQueryItem(QStringLiteral("format"), QStringLiteral("json")); query.addQueryItem(QStringLiteral("accept-language"), locale().name().left(2)); //query.addQueryItem(QStringLiteral("countrycodes"), QStringLiteral("au,jp")); if (bounds.type() == QGeoShape::RectangleType) { query.addQueryItem(QStringLiteral("viewbox"), boundingBoxToLtrb(bounds)); query.addQueryItem(QStringLiteral("bounded"), QStringLiteral("1")); } query.addQueryItem(QStringLiteral("polygon_geojson"), QStringLiteral("1")); query.addQueryItem(QStringLiteral("addressdetails"), QStringLiteral("1")); if (limit != -1) query.addQueryItem(QStringLiteral("limit"), QString::number(limit)); url.setQuery(query); request.setUrl(url); QNetworkReply *reply = m_networkManager->get(request); QGeoCodeReplyKokudo *geocodeReply = new QGeoCodeReplyKokudo(reply, this); connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)), this, SLOT(replyError(QGeoCodeReply::Error,QString))); return geocodeReply; }
void MusicDownLoadQueryKWThread::startToPage(int offset) { if(!m_manager) { return; } M_LOGGER_INFO(QString("%1 startToPage %2").arg(getClassName()).arg(offset)); deleteAll(); QUrl musicUrl = MusicUtils::Algorithm::mdII(KW_SONG_SEARCH_URL, false) .arg(m_searchText).arg(offset).arg(m_pageSize); m_interrupt = true; m_pageTotal = 0; m_pageIndex = offset; QNetworkRequest request; request.setUrl(musicUrl); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRawHeader("User-Agent", MusicUtils::Algorithm::mdII(KW_UA_URL_1, ALG_UA_KEY, false).toUtf8()); setSslConfiguration(&request); m_reply = m_manager->get(request); connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError))); }
int HttpDownload::downloadFile(const QString &url, const QString &file, const QString &dir){ m_reply = m_manager->get(QNetworkRequest(QUrl(url+file))); if(dir.isEmpty()){ m_file = new QFile(file); return 0; }else{ QDir directory(dir); if(!directory.exists()){ directory.mkpath(dir); } if(dir.endsWith("/")) m_file = new QFile(dir+file); else m_file = new QFile(dir+"/"+file); } if(!m_file->open(QIODevice::WriteOnly)){ QMessageBox::warning(0,"错误","文件打开失败",QMessageBox::Ok); return 0; } connect(m_reply,SIGNAL(readyRead()),this,SLOT(replyNewDate())); connect(m_reply,SIGNAL(finished()),this,SLOT(replyFinished())); connect(m_reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(replyError())); connect(m_reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(replyProgress(qint64,qint64))); connect(this,SIGNAL(finished()),m_loop,SLOT(quit())); m_loop->exec(); return m_down_size; }
QGeoRouteReply* QGeoRoutingManagerEngineOsm::calculateRoute(const QGeoRouteRequest &request) { QNetworkRequest networkRequest; networkRequest.setRawHeader("User-Agent", m_userAgent); QUrl url(QStringLiteral("http://router.project-osrm.org/viaroute")); QUrlQuery query; query.addQueryItem(QStringLiteral("instructions"), QStringLiteral("true")); foreach (const QGeoCoordinate &c, request.waypoints()) { query.addQueryItem(QStringLiteral("loc"), QString::number(c.latitude()) + QLatin1Char(',') + QString::number(c.longitude())); } url.setQuery(query); networkRequest.setUrl(url); QNetworkReply *reply = m_networkManager->get(networkRequest); QGeoRouteReplyOsm *routeReply = new QGeoRouteReplyOsm(reply, request, this); connect(routeReply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(routeReply, SIGNAL(error(QGeoRouteReply::Error,QString)), this, SLOT(replyError(QGeoRouteReply::Error,QString))); return routeReply; }
QGeoCodeReply *QGeoCodingManagerEngineQGC::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds) { Q_UNUSED(bounds) QNetworkRequest request; request.setRawHeader("User-Agent", m_userAgent); QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json")); QUrlQuery query; query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false")); query.addQueryItem(QStringLiteral("language"), locale().name().left(2)); query.addQueryItem(QStringLiteral("latlng"), QStringLiteral("%1,%2") .arg(coordinate.latitude()) .arg(coordinate.longitude())); url.setQuery(query); request.setUrl(url); //qDebug() << url; QNetworkReply *reply = m_networkManager->get(request); reply->setParent(0); QGeoCodeReplyQGC *geocodeReply = new QGeoCodeReplyQGC(reply); connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)), this, SLOT(replyError(QGeoCodeReply::Error,QString))); return geocodeReply; }
int BdLogic::ConnectAndDownload(const QString &username, const QString &password) { QString loginPostData; m_dlState = DLSTATE_LOGIN; m_statusCode = BDLOGIC_STATUS_DOWNLOADING; m_statusString = QString("Logging in"); m_actionListOrderedForQML.clear(); m_boxMapParsedJson.clear(); m_boxMapRawJson.clear(); m_replyGotError = false; m_inactiveProjectListParsedJson.clear(); m_currentInactiveProjectDlIx = 0; loginPostData = "username="******"&password="; loginPostData += password; QNetworkRequest request; request.setUrl(QUrl(DOIT_LOGIN_URL)); m_reply = m_netManager->post(request, loginPostData.toUtf8()); connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); connect(m_reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(replySSLError(QList<QSslError>))); emit downloadStatusUpdated(m_statusCode, m_statusString); return 0; }
void ApplyMarkQuery::doRequest() { if (httpQuery == "" || jsonQuery == "") { qDebug() << "ApplyMarkQuery: can't do request because query isn't set"; return; } QNetworkRequest request; QUrl url(httpQuery); url.setPort(getServerPort()); request.setUrl(url); QByteArray data(jsonQuery.toAscii(), jsonQuery.size()); QNetworkReply *reply = manager->post(request, data); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onManagerFinished(QNetworkReply*))); connect(manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SIGNAL(managerSslErrors())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SIGNAL(replyError(QNetworkReply::NetworkError))); qDebug() << "ApplyMarkQuery did request:\n" << httpQuery << jsonQuery; }
static void reply(int s, char *buf) { char *myaddr, *heraddr; myaddr = heraddr = NULL; if (parseAddrs(buf, &myaddr, &heraddr)) replyError(s, "X-INVALID-REQUEST"); else { struct iovec iv[6]; iv[0].iov_base = myaddr; iv[0].iov_len = strlen(myaddr); iv[1].iov_base = ", "; iv[1].iov_len = 2; iv[2].iov_base = heraddr; iv[2].iov_len = strlen(heraddr); iv[3].iov_base = (void *)ident_substr; iv[3].iov_len = ident_substr_len; iv[4].iov_base = (void *)G.identuser; iv[4].iov_len = strlen(G.identuser); iv[5].iov_base = "\r\n"; iv[5].iov_len = 2; writev(s, iv, 6); } }
QGeoCodeReply *QGeoCodingManagerEngineQGC::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds) { Q_UNUSED(limit); Q_UNUSED(offset); QNetworkRequest request; request.setRawHeader("User-Agent", m_userAgent); QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json")); QUrlQuery query; query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false")); query.addQueryItem(QStringLiteral("language"), locale().name().left(2)); query.addQueryItem(QStringLiteral("address"), address); if (bounds.type() == QGeoShape::RectangleType) { query.addQueryItem(QStringLiteral("bounds"), boundingBoxToLtrb(bounds)); } url.setQuery(query); request.setUrl(url); //qDebug() << url; QNetworkReply *reply = m_networkManager->get(request); reply->setParent(0); QGeoCodeReplyQGC *geocodeReply = new QGeoCodeReplyQGC(reply); connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)), this, SLOT(replyError(QGeoCodeReply::Error,QString))); return geocodeReply; }
PendingDisco::PendingDisco (Util::QueueManager *queue, const QString& artist, const QString& release, QNetworkAccessManager *nam, QObject *parent) : QObject (parent) , ReleaseName_ (release.toLower ()) , Queue_ (queue) , NAM_ (nam) , PendingReleases_ (0) { Queue_->Schedule ([this, artist, nam] () -> void { auto idLookup = new ArtistLookup (artist, nam, this); connect (idLookup, SIGNAL(gotID (QString)), this, SLOT (handleGotID (QString))); connect (idLookup, SIGNAL (replyError ()), this, SLOT (handleIDError ())); connect (idLookup, SIGNAL (networkError ()), this, SLOT (handleIDError ())); }, this); }
QGeoCodeReply *QGeoCodingManagerEngineKokudo::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds) { Q_UNUSED(bounds) QNetworkRequest request; request.setRawHeader("User-Agent", m_userAgent); QUrl url(QString("%1/reverse").arg(m_urlPrefix)); QUrlQuery query; query.addQueryItem(QStringLiteral("format"), QStringLiteral("json")); query.addQueryItem(QStringLiteral("accept-language"), locale().name().left(2)); query.addQueryItem(QStringLiteral("lat"), QString::number(coordinate.latitude())); query.addQueryItem(QStringLiteral("lon"), QString::number(coordinate.longitude())); query.addQueryItem(QStringLiteral("zoom"), QStringLiteral("18")); query.addQueryItem(QStringLiteral("addressdetails"), QStringLiteral("1")); url.setQuery(query); request.setUrl(url); QNetworkReply *reply = m_networkManager->get(request); QGeoCodeReplyKokudo *geocodeReply = new QGeoCodeReplyKokudo(reply, this); connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)), this, SLOT(replyError(QGeoCodeReply::Error,QString))); return geocodeReply; }
void HttpMethod::call() { try { onCall(); } catch (base::AppException& e) { LOG(error, EXCEPTION_DIAG_INFO(e)); replyError(400, e.msg()); } catch (exception& e) { LOG(error, EXCEPTION_DIAG_INFO(e)); replyError(500, e.what()); } }
void FalhttpdClient::serveRequest( const String& sRequest, const String& sUri, const String& sProto, Stream* si ) { m_log->log( LOGLEVEL_INFO, "Serving request from "+ m_sRemote + ": " + sRequest + " " + sUri + " " + sProto ); // first, read the headers. WOPI::Request* req = new WOPI::Request; req->startedAt( Sys::_seconds() ); if( ! req->parse( si ) ) { replyError( 400, req->partHandler().error() ); delete req; return; } m_log->log( LOGLEVEL_DEBUG, "Request parsed from "+ m_sRemote + " URI: " + sUri ); req->setURI( sUri ); req->m_remote_ip = m_sRemote; String sFile = req->parsedUri().path(); m_log->log( LOGLEVEL_DEBUG, "Remapping file "+ sFile ); // Time to re-map the file if ( ! m_options.remap( sFile ) ) { m_log->log( LOGLEVEL_WARN, "Not found file "+ sFile ); replyError( 404 ); } else { m_log->log( LOGLEVEL_DEBUG, "File remapped as "+ sFile ); req->m_filename = sFile; // and finally process the request through the appropriate request handler. FalhttpdRequestHandler* rh = m_options.getHandler( sFile, this ); rh->serve( req ); delete rh; } delete req; m_log->log( LOGLEVEL_INFO, "Served client "+ m_sRemote ); }
bool Responder::onInput(IOStream& ios) { while (ios.buffer().in_avail() > 0) { if (advance(ios.buffer())) { if (_failed) { replyError(ios, _errorMessage.c_str(), 0); } else { try { _result = _proc->endCall(); reply(ios); } catch (const RemoteException& e) { ios.buffer().discard(); replyError(ios, e.what(), e.rc()); } catch (const std::exception& e) { ios.buffer().discard(); replyError(ios, e.what(), 0); } } _serviceRegistry.releaseProcedure(_proc); _proc = 0; _args = 0; _result = 0; _state = state_0; _failed = false; _errorMessage.clear(); _deserializer.begin(); return true; } } return false; }
MojErr MojServiceMessage::replyError(MojErr code) { MojString str; MojErr err = MojErrToString(code, str); MojErrCheck(err); err = replyError(code, str); MojErrCheck(err); return MojErrNone; }
Sound::Sound(const QUrl& sampleURL, QObject* parent) : QObject(parent), _hasDownloaded(false) { // assume we have a QApplication or QCoreApplication instance and use the // QNetworkAccess manager to grab the raw audio file at the given URL NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); qDebug() << "Requesting audio file" << sampleURL.toDisplayString(); QNetworkReply* soundDownload = networkAccessManager.get(QNetworkRequest(sampleURL)); connect(soundDownload, &QNetworkReply::finished, this, &Sound::replyFinished); connect(soundDownload, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); }
static int closeOldest(void) { time_t min = conns[0].lasttime; int idx = 0; int i; for (i = 1; i < MAXCONNS; i++) if (conns[i].lasttime < min) idx = i; replyError(idx + FCS, "X-SERVER-TOO-BUSY"); close(idx + FCS); return idx; }
void MusicRadioSongsThread::startToDownload(const QString &id) { m_manager = new QNetworkAccessManager(this); QNetworkRequest networkRequest; networkRequest.setUrl(QUrl(songsUrl + id)); if(m_cookJar) { m_manager->setCookieJar(m_cookJar); m_cookJar->setParent(nullptr); } m_reply = m_manager->get(networkRequest); connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError))); }
QT_BEGIN_NAMESPACE QPlaceContentReplyImpl::QPlaceContentReplyImpl(const QPlaceContentRequest &request, QNetworkReply *reply, QPlaceManagerEngineNokiaV2 *engine) : QPlaceContentReply(engine), m_reply(reply), m_engine(engine) { Q_ASSERT(engine); setRequest(request); if (!m_reply) return; m_reply->setParent(this); connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); }
void MusicMVRadioThreadAbstract::startToSearch(QueryType type, const QString &text) { Q_UNUSED(type); deleteAll(); m_searchText = text.isEmpty() ? "1" : text; m_interrupt = true; QNetworkRequest request; QUrl musicUrl = MusicUtils::Algorithm::mdII(MV_CATEGORY_URL, false); request.setUrl(musicUrl); request.setRawHeader("User-Agent", MusicUtils::Algorithm::mdII(KG_UA_URL_1, ALG_UA_KEY, false).toUtf8()); setSslConfiguration(&request); m_reply = m_manager->get(request); connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError))); }
void FileDownloader::onReplyFinished(QNetworkReply * reply) { if (mQueuedUrls.contains(reply->url())) { mQueuedUrls.removeOne(reply->url()); mFinishedUrls.append(reply->url()); } if (reply->error() != QNetworkReply::NoError) { mErrorUrls.append(reply->url()); emit replyError(reply); } emit replyFinished(reply); reply->deleteLater(); if (mQueuedUrls.isEmpty()) emit finished(); }
PendingDisco::PendingDisco (const QString& artist, QNetworkAccessManager *nam, QObject *parent) : QObject (parent) , NAM_ (nam) , PendingReleases_ (0) { auto idLookup = new ArtistLookup (artist, nam, this); connect (idLookup, SIGNAL(gotID (QString)), this, SLOT (handleGotID (QString))); connect (idLookup, SIGNAL (replyError ()), this, SLOT (handleIDError ())); connect (idLookup, SIGNAL (networkError ()), this, SLOT (handleIDError ())); }
void Downloader::doHttpRequest(QString url){ QNetworkRequest request; request.setUrl(QUrl(url)); request.setRawHeader( "User-Agent" , "Mozilla Firefox" ); // :) Probabilly is not really need! qInfo() << endl << "Starting http request to" << url; reply.reset( httpClient.get(request)); if(reply->error() != QNetworkReply::NoError){ throw std::runtime_error(reply->errorString().toStdString()); } connect(reply.data(), SIGNAL(finished()), this, SIGNAL(downloadFinished())); connect(reply.data(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgressed(qint64,qint64))); connect(reply.data(), SIGNAL(readyRead()), this, SLOT(bytesAvailable())); connect(reply.data(), SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); emit downloadStarted(); }
void MusicDownLoadQuerySingleThread::startSearchSong(QueryType type, const QString &text) { m_searchText = text.trimmed(); m_currentType = type; QUrl musicUrl = (type != MovieQuery ) ? MUSIC_REQUERY_URL.arg(text) : MV_REQUERY_URL.arg(text); ///This is a ttop music API if(m_reply) { m_reply->deleteLater(); m_reply = nullptr; } m_reply = m_manager->get(QNetworkRequest(musicUrl)); connect(m_reply, SIGNAL(finished()), SLOT(searchFinshed()) ); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError)) ); }
static int closeOldest(void) { time_t min = conns[0].lasttime; int idx = 0; int i; for (i = 1; i < MAXCONNS; i++) { if (conns[i].lasttime < min) { idx = i; } } TRACE(("closeOldest(): index %d, socket %d\n", idx, idx + FCS)); replyError(idx + FCS, "X-SERVER-TOO-BUSY"); close(idx + FCS); return idx; }
void QWebdav::replyFinished(QNetworkReply* reply) { #ifdef DEBUG_WEBDAV qDebug() << "QWebdav::replyFinished()"; #endif disconnect(reply, SIGNAL(readyRead()), this, SLOT(replyReadyRead())); disconnect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); QIODevice* dataIO = m_inDataDevices.value(reply, 0); if (dataIO != 0) { dataIO->write(reply->readAll()); static_cast<QFile*>(dataIO)->flush(); dataIO->close(); delete dataIO; } m_inDataDevices.remove(reply); QMetaObject::invokeMethod(this,"replyDeleteLater", Qt::QueuedConnection, Q_ARG(QNetworkReply*, reply)); }
QPlaceReply *QPlaceManagerEngineOsm::initializeCategories() { // Only fetch categories once if (m_categories.isEmpty() && !m_categoriesReply) { m_categoryLocales = m_locales; m_categoryLocales.append(QLocale(QLocale::English)); fetchNextCategoryLocale(); } QPlaceCategoriesReplyOsm *reply = new QPlaceCategoriesReplyOsm(this); connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(reply, SIGNAL(error(QPlaceReply::Error,QString)), this, SLOT(replyError(QPlaceReply::Error,QString))); // TODO delayed finished() emission if (!m_categories.isEmpty()) reply->emitFinished(); m_pendingCategoriesReply.append(reply); return reply; }
void MusicXMArtistSimilarThread::startToSearch(const QString &text) { if(!m_manager) { return; } M_LOGGER_INFO(QString("%1 startToSearch %2").arg(getClassName()).arg(text)); QUrl musicUrl = MusicUtils::Algorithm::mdII(XM_AR_SIM_URL, false).arg(text); deleteAll(); m_interrupt = true; QNetworkRequest request; request.setUrl(musicUrl); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRawHeader("User-Agent", MusicUtils::Algorithm::mdII(XM_UA_URL_1, ALG_UA_KEY, false).toUtf8()); setSslConfiguration(&request); m_reply = m_manager->get(request); connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(replyError(QNetworkReply::NetworkError))); }
static void reply(int s, char * buf) { int myaddr, heraddr; myaddr = heraddr = 0; if (parseAddrs(buf, &myaddr, &heraddr)) { replyError(s, "X-INVALID-REQUEST"); } else { fdprintf(s, "%d, %d " IDENT_SUBSTR " %.*s\r\n", myaddr, heraddr, IDSTR_MAX, #ifdef XXXMULTI G.identuserlist[random() % G.identusers] #else G.identuser #endif ); } }