Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9a7924658 | ||
|
|
6105789fcc |
@@ -5,6 +5,7 @@
|
|||||||
#include "easylogging++.h"
|
#include "easylogging++.h"
|
||||||
|
|
||||||
#include "wechat_function.h"
|
#include "wechat_function.h"
|
||||||
|
#include "utils.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
@@ -117,8 +118,16 @@ int DB::Select(DWORD db_hanle, const char *sql,
|
|||||||
vector<string> item;
|
vector<string> item;
|
||||||
for (size_t i = 0; i < it.size(); i++) {
|
for (size_t i = 0; i < it.size(); i++) {
|
||||||
if (!it[i].is_blob) {
|
if (!it[i].is_blob) {
|
||||||
string content(it[i].content);
|
bool is_utf8 = Utils::IsTextUtf8(it[i].content, it[i].content_len);
|
||||||
item.push_back(content);
|
if (is_utf8) {
|
||||||
|
string content(it[i].content);
|
||||||
|
item.push_back(content);
|
||||||
|
} else {
|
||||||
|
string base64_str =
|
||||||
|
base64_encode((BYTE *)it[i].content, it[i].content_len);
|
||||||
|
item.push_back(base64_str);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
string b64_str =
|
string b64_str =
|
||||||
base64_encode((BYTE *)it[i].content, it[i].content_len);
|
base64_encode((BYTE *)it[i].content, it[i].content_len);
|
||||||
|
|||||||
+1
-1
@@ -588,7 +588,7 @@ void HttpHandler::HandlerRequest(struct mg_connection *c, void *ev_data) {
|
|||||||
ret = res.dump();
|
ret = res.dump();
|
||||||
}
|
}
|
||||||
if (ret != "") {
|
if (ret != "") {
|
||||||
mg_http_reply(c, 200, "", ret.c_str(), 0, 0);
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n", ret.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mg_http_reply(c, 500, NULL, "%s", "Invalid URI");
|
mg_http_reply(c, 500, NULL, "%s", "Invalid URI");
|
||||||
|
|||||||
+44
-7
@@ -1,7 +1,6 @@
|
|||||||
#include "pch.h"
|
#include "utils.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
std::wstring Utils::UTF8ToWstring(const std::string &str) {
|
std::wstring Utils::UTF8ToWstring(const std::string &str) {
|
||||||
@@ -19,7 +18,7 @@ std::wstring Utils::AnsiToWstring(const std::string &input, DWORD locale) {
|
|||||||
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len);
|
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len);
|
||||||
return std::wstring(&temp[0]);
|
return std::wstring(&temp[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::wstring();
|
return std::wstring();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,8 +101,6 @@ void Utils::Hex2Bytes(const std::string &hex, BYTE *bytes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Utils::IsDigit(std::string str) {
|
bool Utils::IsDigit(std::string str) {
|
||||||
if (str.length() == 0) {
|
if (str.length() == 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -119,7 +116,8 @@ bool Utils::IsDigit(std::string str) {
|
|||||||
bool Utils::FindOrCreateDirectoryW(const wchar_t *path) {
|
bool Utils::FindOrCreateDirectoryW(const wchar_t *path) {
|
||||||
WIN32_FIND_DATAW fd;
|
WIN32_FIND_DATAW fd;
|
||||||
HANDLE hFind = ::FindFirstFileW(path, &fd);
|
HANDLE hFind = ::FindFirstFileW(path, &fd);
|
||||||
if (hFind != INVALID_HANDLE_VALUE && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
if (hFind != INVALID_HANDLE_VALUE &&
|
||||||
|
(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -174,4 +172,43 @@ std::string Utils::WCharToUTF8(wchar_t *wstr) {
|
|||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils::IsTextUtf8(const char *str,int length) {
|
||||||
|
char endian = 1;
|
||||||
|
bool littlen_endian = (*(char *)&endian == 1);
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
int bytes_num;
|
||||||
|
unsigned char chr;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
bytes_num = 0;
|
||||||
|
while (i < length) {
|
||||||
|
if (littlen_endian) {
|
||||||
|
chr = *(str + i);
|
||||||
|
} else { // Big Endian
|
||||||
|
chr = (*(str + i) << 8) | *(str + i + 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_num == 0) {
|
||||||
|
if ((chr & 0x80) != 0) {
|
||||||
|
while ((chr & 0x80) != 0) {
|
||||||
|
chr <<= 1;
|
||||||
|
bytes_num++;
|
||||||
|
}
|
||||||
|
if ((bytes_num < 2) || (bytes_num > 6)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bytes_num--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((chr & 0xC0) != 0x80) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bytes_num--;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (bytes_num == 0);
|
||||||
|
}
|
||||||
} // namespace wxhelper
|
} // namespace wxhelper
|
||||||
@@ -47,6 +47,8 @@ class Utils {
|
|||||||
|
|
||||||
static std::string WCharToUTF8(wchar_t *wstr);
|
static std::string WCharToUTF8(wchar_t *wstr);
|
||||||
|
|
||||||
|
static bool IsTextUtf8(const char * str,int length) ;
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
static std::vector<T1> split(T1 str, T2 letter) {
|
static std::vector<T1> split(T1 str, T2 letter) {
|
||||||
std::vector<T1> arr;
|
std::vector<T1> arr;
|
||||||
|
|||||||
Reference in New Issue
Block a user