This commit is contained in:
DarthArgus
2017-01-04 10:35:31 -06:00
parent 8775730b20
commit 07a0cdc7fb
2 changed files with 20 additions and 11 deletions

View File

@@ -310,6 +310,8 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg &msg) {
bool cont = false;
StationId apiSuid = 0;
FATAL(sessURL.empty(), ("Session URL is empty in connection server."));
const std::string clientIP = getRemoteAddress();
const std::string sess = sessionId;

View File

@@ -60,17 +60,17 @@ std::unordered_map<int, std::string> webAPI::getStringMap(const std::string &slo
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) &&
!this->responseData[slot].is_null()) {
nlohmann::json j = this->responseData[slot];
for (nlohmann::json::iterator it = j.begin(); it != j.end(); ++it) {
int k = std::stoi(it.key());
std::string val = it.value();
nlohmann::json j = this->responseData[slot];
ret.insert({k, val});
}
for (nlohmann::json::iterator it = j.begin(); it != j.end(); ++it) {
int k = std::stoi(it.key());
std::string val = it.value();
ret.insert({k, val});
}
}
return ret;
}
@@ -101,9 +101,11 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
if (!uri.empty()) //data is allowed to be an empty string if we're doing a normal GET
{
printf("User not empty");
CURL *curl = curl_easy_init(); // start up curl
if (curl) {
printf("Starting curl");
std::string readBuffer; // container for the remote response
struct curl_slist *slist = nullptr;
@@ -118,8 +120,7 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
slist = curl_slist_append(slist, "charsets: utf-8");
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
writeCallback); // place the data into readBuffer using writeCallback
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // place the data into readBuffer using writeCallback
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); // specify readBuffer as the container for data
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
@@ -136,21 +137,27 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
// want to do a put, or whatever other type? feel free to add here
}
printf("Making request");
CURLcode res = curl_easy_perform(curl); // make the request!
char *contentType;
printf("done");
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &this->statusCode); //get status code
curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &contentType); // get response mime type
std::string conType(contentType);
printf("got content type");
if (res == CURLE_OK && this->statusCode == 200 && !(readBuffer.empty())) // check it all out and parse
{
printf("parsing");
this->sResponse = readBuffer;
if (conType == "application/json") {
printf("json");
fetchStatus = this->processJSON();
printf("json done");
} else {
printf("error %s received", this->responseData.c_str());
this->responseData.clear();
fetchStatus = true;
}