mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
remove cURL from Agent code
This commit is contained in:
parent
7e1a823a25
commit
1e3ab1a201
1 changed files with 96 additions and 135 deletions
|
@ -6,7 +6,10 @@
|
|||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#include <AvatarData.h>
|
||||
#include <NodeList.h>
|
||||
|
@ -27,18 +30,6 @@ void Agent::stop() {
|
|||
_shouldStop = true;
|
||||
}
|
||||
|
||||
static size_t writeScriptDataToString(void *contents, size_t size, size_t nmemb, void *userdata) {
|
||||
size_t realSize = size * nmemb;
|
||||
|
||||
QString* scriptContents = (QString*) userdata;
|
||||
|
||||
// append this chunk to the scriptContents
|
||||
scriptContents->append(QByteArray((char*) contents, realSize));
|
||||
|
||||
// return the amount of data read
|
||||
return realSize;
|
||||
}
|
||||
|
||||
QScriptValue vec3toScriptValue(QScriptEngine *engine, const glm::vec3 &vec3) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("x", vec3.x);
|
||||
|
@ -68,38 +59,17 @@ void Agent::run() {
|
|||
scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainIP().toString(),
|
||||
uuidStringWithoutCurlyBraces(_uuid));
|
||||
|
||||
// setup curl for script download
|
||||
CURLcode curlResult;
|
||||
|
||||
CURL* curlHandle = curl_easy_init();
|
||||
|
||||
// tell curl which file to grab
|
||||
curl_easy_setopt(curlHandle, CURLOPT_URL, scriptURLString.toStdString().c_str());
|
||||
|
||||
// send the data to the WriteMemoryCallback function
|
||||
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, writeScriptDataToString);
|
||||
|
||||
QString scriptContents;
|
||||
|
||||
// pass the scriptContents QString to append data to
|
||||
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, (void *)&scriptContents);
|
||||
|
||||
// send a user agent since some servers will require it
|
||||
curl_easy_setopt(curlHandle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
||||
|
||||
// make sure CURL fails on a 400 code
|
||||
curl_easy_setopt(curlHandle, CURLOPT_FAILONERROR, true);
|
||||
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
|
||||
QNetworkReply *reply = networkManager->get(QNetworkRequest(QUrl(scriptURLString)));
|
||||
|
||||
qDebug() << "Downloading script at" << scriptURLString << "\n";
|
||||
|
||||
// blocking get for JS file
|
||||
curlResult = curl_easy_perform(curlHandle);
|
||||
QEventLoop loop;
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
|
||||
if (curlResult == CURLE_OK) {
|
||||
// cleanup curl
|
||||
curl_easy_cleanup(curlHandle);
|
||||
curl_global_cleanup();
|
||||
loop.exec();
|
||||
|
||||
QString scriptContents(reply->readAll());
|
||||
QScriptEngine engine;
|
||||
|
||||
// register meta-type for glm::vec3 conversions
|
||||
|
@ -196,13 +166,4 @@ void Agent::run() {
|
|||
}
|
||||
|
||||
NodeList::getInstance()->stopSilentNodeRemovalThread();
|
||||
|
||||
} else {
|
||||
// error in curl_easy_perform
|
||||
qDebug() << "curl_easy_perform for JS failed:" << curl_easy_strerror(curlResult) << "\n";
|
||||
|
||||
// cleanup curl
|
||||
curl_easy_cleanup(curlHandle);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue