nesca/Utils.cpp

160 lines
3.5 KiB
C++
Raw Normal View History

2015-03-22 00:43:15 +00:00
#include "Utils.h"
#include <sstream>
2016-02-28 16:07:10 +00:00
#include "STh.h"
2015-08-07 22:37:28 +00:00
std::string Utils::startDate;
2015-08-08 20:31:07 +00:00
std::string Utils::startTime;
2016-02-28 16:07:10 +00:00
std::string Utils::currentTarget;
2015-08-07 22:37:28 +00:00
2016-01-06 20:40:43 +00:00
//void Utils::emitScaryError() {
// __asm{
// push edx
// push ecx
// push ebx
//
// mov eax, 'VMXh'
// mov ebx, 0
// mov ecx, 10
// mov edx, 'VX'
//
// in eax, dx
// cmp ebx, 'VMXh'
//
// pop ebx
// pop ecx
// pop edx
// };
//}
2015-08-07 22:37:28 +00:00
std::string Utils::getHeaderValue(std::string *buff, const std::string headerValue, const std::string outputName) {
if (buff->size() > 0) {
int headerSize = headerValue.size();
int pos = buff->find(headerValue);
if (-1 != pos) {
int diff = pos + headerSize;
std::string fieldChunk = buff->substr(diff, buff->find("\r\n", pos) - diff);
std::string fieldHeader = outputName + fieldChunk.substr(0, fieldChunk.find(";"));
return fieldHeader;
}
else {
return "";
}
}
else {
return "";
}
}
2015-08-07 22:37:28 +00:00
void Utils::saveStartDate() {
2015-08-08 20:31:07 +00:00
QDate date = QDate::currentDate();
2016-02-28 16:07:10 +00:00
startDate = date.toString("dd.MM.yyyy").toUtf8().constData();
2015-08-08 20:31:07 +00:00
}
2016-02-28 16:07:10 +00:00
2015-08-08 20:31:07 +00:00
void Utils::saveStartTime() {
QTime time = QTime::currentTime();
2016-02-28 16:07:10 +00:00
startTime = time.toString("HH_mm").toUtf8().constData();
2015-08-07 22:37:28 +00:00
}
std::string Utils::getStartDate() {
return startDate;
}
2016-02-28 16:07:10 +00:00
int Utils::addBARow(QString str1, QString str2, QString str3, int rowIndex) {
if (BALogSwitched) {
if (rowIndex == -1) {
rowIndex = nesca_3::addBARow(str1, str2, str3);
}
else {
stt->doEmitionChangeBARow(rowIndex, str2, str3);
}
return rowIndex;
}
return -1;
}
2015-08-08 20:31:07 +00:00
std::string Utils::getStartTime() {
return startTime;
}
2016-02-28 16:07:10 +00:00
void Utils::setCurrentTarget(const std::string target) {
currentTarget = target;
}
std::string Utils::getCurrentTarget() {
return currentTarget;
}
2015-04-25 19:45:01 +00:00
int Utils::isDigest(const std::string *buffer) {
if (Utils::ustrstr(buffer, "401 authorization") != -1
|| Utils::ustrstr(buffer, "401 unauthorized") != -1
|| (Utils::ustrstr(buffer, "www-authenticate") != -1
&& Utils::ustrstr(buffer, "401 ") != -1
)
|| Utils::ustrstr(buffer, "401 unauthorized access denied") != -1
|| Utils::ustrstr(buffer, "401 unauthorised") != -1
|| (Utils::ustrstr(buffer, "www-authenticate") != -1
&& Utils::ustrstr(buffer, " 401\r\n") != -1
)
) {
if (Utils::ustrstr(buffer, "digest realm") != -1
&& Utils::ustrstr(buffer, "basic realm") == -1) {
return 1;
}
else return 0;
};
return -1;
}
std::vector<std::string> Utils::splitToStrVector(const std::string &s, char delim) {
std::vector<std::string> elems;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<int> Utils::splitToIntVector(const std::string &s, char delim) {
std::vector<int> elems;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(std::stoi(item));
}
return elems;
}
std::string Utils::getStrValue(const std::string &data, const std::string &delim1, const std::string &delim2) {
int pos1 = data.find(delim1);
int pos2;
int offset;
if (pos1 != std::string::npos) {
offset = delim1.length();
pos2 = data.find(delim2, pos1 + offset);
if (pos2 != std::string::npos) {
return data.substr(pos1 + offset, pos2 - pos1 - offset);
}
}
return "";
}
2015-03-05 14:29:05 +00:00
2015-03-06 14:32:36 +00:00
char *getSystemProxy() {
2015-03-07 17:31:48 +00:00
return "";
2015-03-06 14:32:36 +00:00
}
int Utils::getProxyPort() {
2015-03-07 17:31:48 +00:00
return 0;
2015-03-06 14:32:36 +00:00
}
char * Utils::getProxy() {
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#else
getSystemProxy();
#endif
2015-03-07 17:31:48 +00:00
return "";
}