summaryrefslogtreecommitdiff
path: root/plugins/SendScreenshotPlus/src/CSend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SendScreenshotPlus/src/CSend.cpp')
-rw-r--r--plugins/SendScreenshotPlus/src/CSend.cpp147
1 files changed, 0 insertions, 147 deletions
diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp
index 98a22dfe63..180afe817e 100644
--- a/plugins/SendScreenshotPlus/src/CSend.cpp
+++ b/plugins/SendScreenshotPlus/src/CSend.cpp
@@ -452,153 +452,6 @@ const char* CSend::GetHTMLContent(char* str, const char* startTag, const char* e
return begin;
}
-int JSON_ParseData_(const char** jsondata, size_t jsonlen, const char** rawdata)
-{
- const char* c = *jsondata;
- const char* jsonend = *jsondata + jsonlen;
- int len = 0;
- *rawdata = nullptr;
- if (c == jsonend)
- return 0;
- if (*c == '{') { // scope (object)
- *rawdata = c;
- do {
- if (*c == '{') ++len;
- else if (*c == '}') --len;
- if (++c == jsonend)
- return 0;
- } while (len > 0);
- len = c - *rawdata;
- if (*c == ',') ++c;
- }
- else if (*c == '"' || *c == '\'') { // string
- char needle = *c;
- if (++c == jsonend)
- return 0;
- *rawdata = c;
- do {
- if (c == jsonend || (*c == '\\' && ++c == jsonend))
- return 0;
- } while (*c++ != needle);
- len = c - *rawdata - 1;
- if (*c == ',') ++c;
- }
- else { // other
- for (*rawdata = c; c < jsonend && *c++ != ',';);
- len = c - *rawdata;
- if (c[-1] == ',') --len;
- }
- *jsondata = c;
- return len;
-}
-
-int JSON_Get_(const char* json, size_t jsonlen, const char* variable, const char** value)
-{
- char needle[32];
- const char* needlechild;
- char var[32];
- char* tmp;
- const char* c;
- const char* jsonend = json + jsonlen;
- // get needle
- if (!jsonlen || *json != '{')
- return 0;
- for (tmp = needle, c = *variable == '[' ? variable + 1 : variable; *c != '[' && *c != ']'; ++c) {
- if (c == jsonend)
- return 0;
- if (tmp < needle + sizeof(needle) - 1) *tmp++ = *c;
- }
- *tmp = '\0';
- // get child needle (if any)
- if (*c == ']') ++c;
- if (c == jsonend)
- return 0;
- needlechild = c;
- // parse JSON
- for (c = json + 1; c < jsonend && (*c == '"' || *c == '\'');) {
- for (++c, tmp = var; c < jsonend && (*c != '"' && *c != '\''); ++c)
- if (tmp < var + sizeof(var) - 1) *tmp++ = *c;
- *tmp = '\0';
- if (c + 2 >= jsonend || *++c != ':') break;
- /// read data
- ++c;
- if (!mir_strcmp(var, needle)) {
- int datalen = JSON_ParseData_(&c, jsonend - c, value);
- if (!datalen)
- return 0;
- if (*needlechild && **value == '{') { // we need a child value, parse child object
- return JSON_Get_(*value, datalen, needlechild, value);
- }
- return datalen;
- }
- else {
- JSON_ParseData_(&c, jsonend - c, value);
- }
- }
- *value = nullptr;
- return 0;
-}
-
-int CSend::GetJSONString(const char* json, size_t jsonlen, const char* variable, char* value, size_t valuesize)
-{
- if (!jsonlen || !valuesize)
- return 0;
- const char* rawvalue;
- int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue);
- if (rawlen) {
- size_t out = 0;
- --valuesize;
- /// copy & parse escape sequences
- for (int in = 0; in < rawlen && out < valuesize; ++in, ++out) {
- if (rawvalue[in] == '\\') {
- if (++in == rawlen)
- break;
- switch (rawvalue[in]) {
- case 's': value[out] = ' '; break;
- case 't': value[out] = '\t'; break;
- case 'n': value[out] = '\n'; break;
- case 'r': value[out] = '\r'; break;
- default: value[out] = rawvalue[in];
- }
- continue;
- }
- value[out] = rawvalue[in];
- }
- value[out] = '\0';
- return 1;
- }
- *value = '\0';
- return 0;
-}
-
-int CSend::GetJSONInteger(const char* json, size_t jsonlen, const char* variable, int defvalue)
-{
- const char* rawvalue;
- int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue);
- if (rawlen) {
- defvalue = 0;
- for (int offset = 0; offset < rawlen; ++offset) {
- if (rawvalue[offset]<'0' || rawvalue[offset]>'9') break;
- defvalue *= 10;
- defvalue += rawvalue[offset] - '0';
- }
- }
- return defvalue;
-}
-
-bool CSend::GetJSONBool(const char* json, size_t jsonlen, const char* variable)
-{
- const char* rawvalue;
- int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue);
- if (rawlen) {
- if (rawlen == 4 && !memcmp(rawvalue, "true", 4))
- return true;
- if (*rawvalue > '0' && *rawvalue <= '9')
- return true;
- }
- return false;
-}
-
static void HTTPFormAppendData(NETLIBHTTPREQUEST* nlhr, size_t* dataMax, char** dataPos, const char* data, size_t len)
{
nlhr->dataLength = (*dataPos - nlhr->pData);