prepare for cdn
This commit is contained in:
@@ -82,6 +82,13 @@ result_t ScanHelper::collectConfigFiles(const string& relPath, const string& pre
|
|||||||
if (!m_configHttpClient->get(uri, "", &names)) {
|
if (!m_configHttpClient->get(uri, "", &names)) {
|
||||||
return RESULT_ERR_NOTFOUND;
|
return RESULT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
} else if (!json && names[0]=='<') { // html
|
||||||
|
uri = m_configUriPrefix + relPathWithSlash + "index.json";
|
||||||
|
json = true;
|
||||||
|
logDebug(lf_main, "trying index.json");
|
||||||
|
if (!m_configHttpClient->get(uri, "", &names, nullptr, nullptr, &json)) {
|
||||||
|
return RESULT_ERR_NOTFOUND;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
istringstream stream(names);
|
istringstream stream(names);
|
||||||
string name;
|
string name;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <algorithm>
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x10101000L
|
#if OPENSSL_VERSION_NUMBER < 0x10101000L
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -301,10 +302,12 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strcmp(peerName, hostname) != 0) {
|
if (strcmp(peerName, hostname) != 0) {
|
||||||
char* dotpos = NULL;
|
char* dotpos = strchr((char*)hostname, '.');
|
||||||
if (peerName[0] == '*' && peerName[1] == '.' && (dotpos=strchr((char*)hostname, '.'))
|
if (peerName[0] == '*' && peerName[1] == '.' && dotpos
|
||||||
&& strcmp(peerName+2, dotpos+1) == 0) {
|
&& strcmp(peerName+2, dotpos+1) == 0) {
|
||||||
// wildcard matches
|
// wildcard matches
|
||||||
|
} else if (dotpos && strcmp(peerName, dotpos+1) == 0) {
|
||||||
|
// hostname matches
|
||||||
} else if (isError("subject", 1, 0)) {
|
} else if (isError("subject", 1, 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -513,15 +516,16 @@ bool* repeatable, time_t* time, bool* jsonString) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string headers = result.substr(0, pos+2); // including final \r\n
|
string headers = result.substr(0, pos+2); // including final \r\n
|
||||||
|
transform(headers.begin(), headers.end(), headers.begin(), ::tolower);
|
||||||
const char* hdrs = headers.c_str();
|
const char* hdrs = headers.c_str();
|
||||||
*response = result.substr(pos+4);
|
*response = result.substr(pos+4);
|
||||||
#if defined(HAVE_TIME_H) && defined(HAVE_TIMEGM)
|
#if defined(HAVE_TIME_H) && defined(HAVE_TIMEGM)
|
||||||
if (time) {
|
if (time) {
|
||||||
pos = headers.find("\r\nLast-Modified: ");
|
pos = headers.find("\r\nlast-modified: ");
|
||||||
if (pos != string::npos && headers.substr(pos+42, 4) == " GMT") {
|
if (pos != string::npos && headers.substr(pos+42, 4) == " gmt") {
|
||||||
// Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
|
// Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
|
||||||
struct tm t;
|
struct tm t;
|
||||||
pos += strlen("\r\nLast-Modified: ") + 5;
|
pos += strlen("\r\nlast-modified: ") + 5;
|
||||||
char* strEnd = nullptr;
|
char* strEnd = nullptr;
|
||||||
t.tm_mday = static_cast<int>(strtol(hdrs + pos, &strEnd, 10));
|
t.tm_mday = static_cast<int>(strtol(hdrs + pos, &strEnd, 10));
|
||||||
if (strEnd != hdrs + pos + 2 || t.tm_mday < 1 || t.tm_mday > 31) {
|
if (strEnd != hdrs + pos + 2 || t.tm_mday < 1 || t.tm_mday > 31) {
|
||||||
@@ -556,28 +560,34 @@ bool* repeatable, time_t* time, bool* jsonString) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
pos = headers.find("\r\nContent-Length: ");
|
bool isJson = headers.find("\r\ncontent-type: application/json") != string::npos;
|
||||||
if (pos == string::npos) {
|
pos = headers.find("\r\ncontent-length: ");
|
||||||
|
bool noLength = pos == string::npos;
|
||||||
|
if (noLength && !isJson) {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
if (jsonString) {
|
||||||
|
*jsonString = false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
char* strEnd = nullptr;
|
char* strEnd = nullptr;
|
||||||
unsigned long length = strtoul(hdrs + pos + strlen("\r\nContent-Length: "), &strEnd, 10);
|
unsigned long length = 4*1024; // default max length
|
||||||
if (strEnd == nullptr || *strEnd != '\r') {
|
if (!noLength) {
|
||||||
disconnect();
|
length = strtoul(hdrs + pos + strlen("\r\ncontent-length: "), &strEnd, 10);
|
||||||
*response = "invalid content length ";
|
if (strEnd == nullptr || *strEnd != '\r') {
|
||||||
return false;
|
disconnect();
|
||||||
}
|
*response = "invalid content length ";
|
||||||
bool isJson = headers.find("\r\nContent-Type: application/json") != string::npos;
|
return false;
|
||||||
if (pos == string::npos) {
|
}
|
||||||
disconnect();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
pos = readUntil("", length, response);
|
pos = readUntil("", length, response);
|
||||||
disconnect();
|
disconnect();
|
||||||
if (pos != length) {
|
if (noLength ? pos<1 : pos != length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (noLength) {
|
||||||
|
length = pos;
|
||||||
|
}
|
||||||
if (jsonString && isJson && *jsonString && length >= 2 && response->at(0) == '"') {
|
if (jsonString && isJson && *jsonString && length >= 2 && response->at(0) == '"') {
|
||||||
// check for inline conversion of JSON to string expecting a single string to de-escape
|
// check for inline conversion of JSON to string expecting a single string to de-escape
|
||||||
pos = length;
|
pos = length;
|
||||||
|
|||||||
Reference in New Issue
Block a user