Skip to content

Commit

Permalink
Telemetry: use POST
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnet committed Dec 8, 2020
1 parent 78276cf commit 1e73123
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define TIME_URL "http://downloads.raspberrypi.org/os_list_imagingutility_v2.json?time_synchronization"

/* Phone home the name of images downloaded for image popularity ranking */
#define TELEMETRY_URL "https://rpi-imager-stats.raspberrypi.org/downloads?url=$imageurl&os=$parentcategory&image=$osname"
#define TELEMETRY_URL "https://rpi-imager-stats.raspberrypi.org/downloads"
#define TELEMETRY_ENABLED_DEFAULT true

/* Hash algorithm for verifying (uncompressed image) checksum */
Expand Down
8 changes: 6 additions & 2 deletions downloadstatstelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*/

DownloadStatsTelemetry::DownloadStatsTelemetry(const QByteArray &url, const QByteArray &parentcategory, const QByteArray &osname, QObject *parent)
: QThread(parent)
: QThread(parent), _url(TELEMETRY_URL)
{
_url = QByteArray(TELEMETRY_URL).replace("$imageurl", QUrl::toPercentEncoding(url)).replace("$parentcategory", QUrl::toPercentEncoding(parentcategory)).replace("$osname", QUrl::toPercentEncoding(osname));
_postfields = "url="+QUrl::toPercentEncoding(url)
+"&os="+QUrl::toPercentEncoding(parentcategory)
+"&image="+QUrl::toPercentEncoding(osname);
_useragent = "Mozilla/5.0 rpi-imager/" IMAGER_VERSION_STR;
}

Expand All @@ -27,6 +29,8 @@ void DownloadStatsTelemetry::run()
curl_easy_setopt(_c, CURLOPT_WRITEFUNCTION, &DownloadStatsTelemetry::_curl_write_callback);
curl_easy_setopt(_c, CURLOPT_HEADERFUNCTION, &DownloadStatsTelemetry::_curl_header_callback);
curl_easy_setopt(_c, CURLOPT_URL, _url.constData());
curl_easy_setopt(_c, CURLOPT_POSTFIELDSIZE, _postfields.length());
curl_easy_setopt(_c, CURLOPT_POSTFIELDS, _postfields.constData());
curl_easy_setopt(_c, CURLOPT_USERAGENT, _useragent.constData());
curl_easy_setopt(_c, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(_c, CURLOPT_LOW_SPEED_TIME, 10);
Expand Down
2 changes: 1 addition & 1 deletion downloadstatstelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DownloadStatsTelemetry : public QThread

protected:
CURL *_c;
QByteArray _url, _useragent;
QByteArray _url, _useragent, _postfields;
virtual void run();
static size_t _curl_write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
static size_t _curl_header_callback( void *ptr, size_t size, size_t nmemb, void *userdata);
Expand Down

0 comments on commit 1e73123

Please sign in to comment.