* Added plugin support

* Improved Filer (LocalFiler)
* Supports Explicit SSL/TLS with OpenSSL/Crypto
* Fixed most of the bugs that drove me nuts.
* Properly handled socket closes
* Improved socket cleanup
* Buffered file downloads
* Lots 'o errors!

I did it again! I made a single commit with everything!
This commit is contained in:
2024-12-13 10:51:10 -06:00
parent 841c1e1ead
commit 5ff35c26ab
32 changed files with 2551 additions and 653 deletions

View File

@@ -8,6 +8,7 @@
#include <vector>
#include <iterator>
#include <algorithm>
#include <filesystem>
std::string replace(std::string subject, const std::string& search, const std::string& replace) {
size_t pos = 0;
@@ -21,18 +22,18 @@ std::string replace(std::string subject, const std::string& search, const std::s
template <typename Out>
void split(const std::string &s, char delim, Out result, int limit) {
int it = 0;
std::istringstream iss(s);
std::string item;
while (std::getline(iss, item, delim) && it <= limit) {
*result++ = item;
if (limit > 0) it++;
}
std::istringstream iss(s);
std::string item;
while (std::getline(iss, item, delim) && it <= limit) {
*result++ = item;
if (limit > 0) it++;
}
}
std::vector<std::string> split(const std::string &s, char delim, int limit) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems), limit);
return elems;
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems), limit);
return elems;
}
static std::string toLower(std::string str) {
@@ -45,6 +46,93 @@ static std::string toUpper(std::string str) {
return str;
}
static std::vector<std::string> parseArgs(std::string line) {
if (line.size() == 0) {
return {};
}
int state = 0;
std::vector<std::string> result;
std::string current;
bool lastTokenHasBeenQuoted = false;
bool lastTokenWasEscaped = false;
for (int i = 0; i < line.size(); i++) {
char nextTok = line[i];
switch (state) {
case 1:
if (nextTok == '\\') {
lastTokenWasEscaped = true;
} else if (nextTok == '\'' && !lastTokenWasEscaped) {
lastTokenHasBeenQuoted = true;
state = 0;
} else {
if (lastTokenWasEscaped) {
if (nextTok == 't') nextTok = '\t';
if (nextTok == 'b') nextTok = '\b';
if (nextTok == 'n') nextTok = '\n';
if (nextTok == 'r') nextTok = '\r';
if (nextTok == 'f') nextTok = '\f';
}
current.push_back(nextTok);
lastTokenWasEscaped = false;
}
break;
case 2:
if (nextTok == '\\') {
lastTokenWasEscaped = true;
} else if (nextTok == '\"' && !lastTokenWasEscaped) {
lastTokenHasBeenQuoted = true;
state = 0;
} else {
if (lastTokenWasEscaped) {
if (nextTok == 't') nextTok = '\t';
if (nextTok == 'b') nextTok = '\b';
if (nextTok == 'n') nextTok = '\n';
if (nextTok == 'r') nextTok = '\r';
if (nextTok == 'f') nextTok = '\f';
}
current.push_back(nextTok);
lastTokenWasEscaped = false;
}
break;
default:
switch (nextTok) {
case '\\': lastTokenWasEscaped = true; break;
case '\'': state = 1; break;
case '\"': state = 2; break;
case ' ':
if (!lastTokenWasEscaped && (lastTokenHasBeenQuoted || current.length() != 0)) {
result.push_back(current);
current = "";
}
break;
default:
if (lastTokenWasEscaped) {
if (nextTok == 't') nextTok = '\t';
if (nextTok == 'b') nextTok = '\b';
if (nextTok == 'n') nextTok = '\n';
if (nextTok == 'r') nextTok = '\r';
if (nextTok == 'f') nextTok = '\f';
lastTokenWasEscaped = false;
}
current.push_back(nextTok);
break;
}
lastTokenHasBeenQuoted = false;
break;
}
}
if (lastTokenHasBeenQuoted || current.size() != 0) {
result.push_back(current);
}
return result;
}
std::string concatPath(std::string dir1, std::string dir2) {
return std::filesystem::weakly_canonical(dir1+"/"+dir2).string();
}
static char* trim(char *str) {
char *end;
while(isspace(*str))