Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions source/gameanalytics/Http/GAHttpCurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <openssl/ssl.h>
#include <openssl/crypto.h>

#include <memory>

namespace gameanalytics
{
size_t writefunc(void *ptr, size_t size, size_t nmemb, GAHttpClient::Response *s)
Expand Down Expand Up @@ -39,39 +41,39 @@ namespace gameanalytics

GAHttpClient::Response GAHttpClientCurl::sendRequest(std::string const& url, std::string const& auth, std::vector<uint8_t> const& payloadData, bool useGzip, void* userData)
{
CURL* curl = curl_easy_init();
std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> curl(curl_easy_init(), &curl_easy_cleanup);
if (!curl)
{
return {};
}

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl.get(), CURLOPT_SSL_VERIFYPEER, 0L);

GAHttpClient::Response response = {};

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response);

createRequest(curl, url, auth, payloadData, useGzip);
std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)> header(
createRequest(curl.get(), url, auth, payloadData, useGzip), &curl_slist_free_all);

CURLcode res = curl_easy_perform(curl);
CURLcode res = curl_easy_perform(curl.get());
if (res != CURLE_OK)
{
logging::GALogger::d("CURL request failed: %s", curl_easy_strerror(res));
return {};
}

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response.code);
curl_easy_cleanup(curl);
curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &response.code);

return response;
}

void GAHttpClientCurl::createRequest(CURL *curl, std::string const& url, std::string const& auth, const std::vector<uint8_t>& payloadData, bool gzip)
curl_slist* GAHttpClientCurl::createRequest(CURL *curl, std::string const& url, std::string const& auth, const std::vector<uint8_t>& payloadData, bool gzip)
{
if(!curl)
{
return;
return nullptr;
}

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
Expand All @@ -90,8 +92,9 @@ namespace gameanalytics

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payloadData.data());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, payloadData.size());

return header;
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/gameanalytics/Http/GAHttpCurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gameanalytics

private:

void createRequest(CURL *curl, std::string const& url, std::string const& auth, const std::vector<uint8_t>& payloadData, bool gzip);
curl_slist* createRequest(CURL *curl, std::string const& url, std::string const& auth, const std::vector<uint8_t>& payloadData, bool gzip);
};
}

Expand Down
23 changes: 12 additions & 11 deletions source/gameanalytics/Platform/GALinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,35 +252,36 @@ std::string gameanalytics::GAPlatformLinux::getConnectionType()
return connection;
}

int sock = socket(AF_INET, SOCK_STREAM, 0);

current = list;
while(current)
{
int sock = -1;
if (!current->ifa_addr || current->ifa_addr->sa_family != AF_PACKET)
if (!current->ifa_addr || current->ifa_addr->sa_family != AF_PACKET)
{
struct iwreq req = {};
strncpy(req.ifr_name, current->ifa_name, IFNAMSIZ);

int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
if (sock == -1)
{
connection = CONNECTION_LAN;
}
else
{
if (ioctl(sock, SIOCGIWNAME, &req) != -1)
struct iwreq req = {};
strncpy(req.ifr_name, current->ifa_name, IFNAMSIZ);

if (ioctl(sock, SIOCGIWNAME, &req) != -1)
{
connection = CONNECTION_WIFI;
break;
}
}
}

if(sock != -1)
close(sock);

current = current->ifa_next;
}

if(sock != -1)
close(sock);

freeifaddrs(list);
return connection;
}
Expand Down
Loading