This commit is contained in:
cora32 2015-12-29 13:58:43 +03:00
parent 38567a9177
commit aeeb2d6e4b
2 changed files with 53 additions and 18 deletions

View File

@ -130,11 +130,12 @@ size_t nWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
//return realsize; //return realsize;
} }
int Connector::nConnect(const char* ip, const int port, std::string *buffer, int pConnect(const char* ip, const int port, std::string *buffer,
const char *postData, const char *postData,
const std::vector<std::string> *customHeaders, const std::vector<std::string> *customHeaders,
const std::string *lpString, const std::string *lpString,
bool digestMode){ bool digestMode)
{
buffer->clear(); buffer->clear();
int res = 0; int res = 0;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
@ -174,7 +175,7 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
for (auto &ch : *customHeaders) chunk = curl_slist_append(chunk, ch.c_str()); for (auto &ch : *customHeaders) chunk = curl_slist_append(chunk, ch.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
} }
if (lpString != NULL) { if (lpString != NULL) {
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L); curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, 1L); curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, 1L);
@ -183,7 +184,7 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
{ {
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (port != 21 && lpString != NULL) { if (port != 21 && lpString != NULL) {
int pos = Utils::ustrstr(*buffer, "\r\n\r\n"); int pos = Utils::ustrstr(*buffer, "\r\n\r\n");
if (pos != -1) { if (pos != -1) {
@ -194,7 +195,7 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
else res = curl_easy_perform(curl); else res = curl_easy_perform(curl);
} }
else res = curl_easy_perform(curl); else res = curl_easy_perform(curl);
int sz = buffer->size(); int sz = buffer->size();
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -233,14 +234,15 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
res != 56 && res != 56 &&
res != 35 && res != 35 &&
res != 19 && res != 19 &&
res != 23) res != 23)
{ {
if (res == 5) { if (res == 5) {
stt->doEmitionRedFoundData("The given proxy host could not be resolved."); stt->doEmitionRedFoundData("The given proxy host could not be resolved.");
return -2; return -2;
} else if (res == 8) { }
stt->doEmitionFoundData("Strange ftp reply. (" + else if (res == 8) {
QString::number(res) + ") " + QString(ip) + stt->doEmitionFoundData("Strange ftp reply. (" +
QString::number(res) + ") " + QString(ip) +
":" + QString::number(port)); ":" + QString::number(port));
return -2; return -2;
} }
@ -250,10 +252,10 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
":" + QString::number(port)); ":" + QString::number(port));
return -2; return -2;
} }
else stt->doEmitionRedFoundData("CURL error: (" + QString::number(res) + ") " + else stt->doEmitionRedFoundData("CURL error: (" + QString::number(res) + ") " +
QString(ip) + ":" + QString::number(port)); QString(ip) + ":" + QString::number(port));
}; };
//if (res == 23 && sz > 0) { //if (res == 23 && sz > 0) {
// return sz; // return sz;
//} //}
@ -264,12 +266,42 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
if (MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str())); if (MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str()));
return sz; return sz;
} else { }
stt->doEmitionRedFoundData("Curl error."); else {
return -1; stt->doEmitionRedFoundData("Curl error.");
return -1;
}; };
} }
void eraser(std::string *buffer, const std::string delim1, const std::string delim2) {
int pos = -1;
while ((pos = buffer->find(delim1)) != -1) {
int ePos = buffer->find(delim2, pos);
if (ePos != -1) {
buffer->erase(pos, ePos - pos - 1 + delim2.length());
}
else {
buffer->erase(pos, buffer->length() - pos - 1);
}
}
}
void cutoutComments(std::string *buffer) {
eraser(buffer, "<!--", "-->");
eraser(buffer, "/*", "*/");
eraser(buffer, "//", "\n");
}
int Connector::nConnect(const char* ip, const int port, std::string *buffer,
const char *postData,
const std::vector<std::string> *customHeaders,
const std::string *lpString,
bool digestMode){
int res = pConnect(ip, port, buffer, postData, customHeaders, lpString, digestMode);
cutoutComments(buffer);
return buffer->size();
}
bool portCheck(const char * sDVRIP, int wDVRPort) { bool portCheck(const char * sDVRIP, int wDVRPort) {
// sockaddr_in sa; // sockaddr_in sa;
// sa.sin_family = AF_INET; // sa.sin_family = AF_INET;

View File

@ -3208,7 +3208,7 @@ int handleFramesets(std::string *buffcpy, char* ip, int port, int flag) {
Connector con; Connector con;
int framePos = pos + 9; int framePos = pos + 9;
int counter = 0;
while (framePos != -1) { while (framePos != -1) {
framePos = buffcpy->find("<frame ", framePos + 1); framePos = buffcpy->find("<frame ", framePos + 1);
if (-1 == framePos) { if (-1 == framePos) {
@ -3233,6 +3233,9 @@ int handleFramesets(std::string *buffcpy, char* ip, int port, int flag) {
int quotePos2 = frameString.find_first_of("\"'", quotePos1 + 1); int quotePos2 = frameString.find_first_of("\"'", quotePos1 + 1);
if (quotePos1 != quotePos2) { if (quotePos1 != quotePos2) {
if (counter++ > 5) {
return 0;
};
std::string location = frameString.substr(quotePos1 + 1, quotePos2 - quotePos1 - 1); std::string location = frameString.substr(quotePos1 + 1, quotePos2 - quotePos1 - 1);
std::string tIP = std::string(ip) + (location[0] == '/' ? "" : "/") + location; std::string tIP = std::string(ip) + (location[0] == '/' ? "" : "/") + location;
std::string buff; std::string buff;