2022-05-24 02:01:36 +00:00
|
|
|
|
#include "WSUser.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
|
#include "WSServer.h"
|
|
|
|
|
#include "ManagerV2.h"
|
|
|
|
|
#include "base/HGInfo.h"
|
2022-06-06 10:51:34 +00:00
|
|
|
|
#include "base/HGUtility.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
|
#include "sha1.h"
|
|
|
|
|
#include "base64.h"
|
2022-05-30 11:01:23 +00:00
|
|
|
|
#include "HGString.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
namespace ver_2
|
|
|
|
|
{
|
2022-06-01 10:36:22 +00:00
|
|
|
|
static int GetJsonIntValue(cJSON* json, const std::string& key, bool *find = NULL)
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (p->type == cJSON_Number)
|
2022-06-01 10:36:22 +00:00
|
|
|
|
{
|
2022-05-23 10:29:23 +00:00
|
|
|
|
ret = p->valueint;
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
static double GetJsonDoubleValue(cJSON* json, const std::string& key, bool* find = NULL)
|
|
|
|
|
{
|
|
|
|
|
double ret = 0.0;
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (p->type == cJSON_Number)
|
|
|
|
|
{
|
|
|
|
|
ret = p->valuedouble;
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 10:36:22 +00:00
|
|
|
|
static bool GetJsonBoolValue(cJSON* json, const std::string& key, bool* find = NULL)
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (p->type == cJSON_True || p->type == cJSON_False)
|
|
|
|
|
{
|
|
|
|
|
ret = (p->type == cJSON_True) ? true : false;
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 10:36:22 +00:00
|
|
|
|
static std::string GetJsonStringValue(cJSON* json, const std::string& key, bool* find = NULL)
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (p->type == cJSON_String || p->type == cJSON_NULL)
|
|
|
|
|
{
|
|
|
|
|
ret = (p->type == cJSON_String) ? p->valuestring : "";
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::vector<std::string> GetJsonStringListValue(cJSON* json, const std::string& key, bool* find = NULL)
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
2022-06-01 10:36:22 +00:00
|
|
|
|
if (p->type == cJSON_Array)
|
|
|
|
|
{
|
|
|
|
|
cJSON* pEx = p->child;
|
|
|
|
|
while (NULL != pEx)
|
|
|
|
|
{
|
|
|
|
|
if (pEx->type == cJSON_String)
|
|
|
|
|
ret.push_back(pEx->valuestring);
|
|
|
|
|
|
|
|
|
|
pEx = pEx->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 09:30:04 +00:00
|
|
|
|
static std::vector<int> GetJsonIntListValue(cJSON* json, const std::string& key, bool* find = NULL)
|
|
|
|
|
{
|
|
|
|
|
std::vector<int> ret;
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = false;
|
|
|
|
|
|
|
|
|
|
cJSON* p = json->child;
|
|
|
|
|
while (NULL != p)
|
|
|
|
|
{
|
|
|
|
|
if (0 == strcmp(p->string, key.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (p->type == cJSON_Array)
|
|
|
|
|
{
|
|
|
|
|
cJSON* pEx = p->child;
|
|
|
|
|
while (NULL != pEx)
|
|
|
|
|
{
|
|
|
|
|
if (pEx->type == cJSON_Number)
|
|
|
|
|
ret.push_back(pEx->valueint);
|
|
|
|
|
|
|
|
|
|
pEx = pEx->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL != find)
|
|
|
|
|
*find = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
WSUser::WSUser(WebServer* server, HGUInt id, const std::string& ip, uint16_t port, SOCKET sockConn)
|
|
|
|
|
#else
|
|
|
|
|
WSUser::WSUser(WebServer* server, HGUInt id, const std::string& ip, uint16_t port, int sockConn)
|
|
|
|
|
#endif
|
|
|
|
|
: WebUser(server, id, ip, port, sockConn)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
m_initDeviceIden.clear();
|
|
|
|
|
m_initDeviceHaveIden = false;
|
|
|
|
|
m_startScanIden.clear();
|
|
|
|
|
m_startScanHaveIden = false;
|
2022-06-09 03:05:24 +00:00
|
|
|
|
m_startScanIsGetBase64 = false;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-05-31 09:39:54 +00:00
|
|
|
|
GetManager()->SetSaneEvent(SaneEvent2, this);
|
|
|
|
|
GetManager()->SetSaneImageCallback(SaneImageCallback2, this);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WSUser::~WSUser()
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string errInfo;
|
|
|
|
|
GetManager()->DeinitDevice(errInfo);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
GetManager()->ResetSaneImageCallback();
|
|
|
|
|
GetManager()->ResetSaneEvent();
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ManagerV2* WSUser::GetManager()
|
|
|
|
|
{
|
|
|
|
|
return ((WSServer*)m_server)->GetManger();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::HandleCmd(const WSCmdParam* param)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != param && m_id == param->usrId);
|
|
|
|
|
|
|
|
|
|
std::string cmdData((const char*)param->data, param->size);
|
|
|
|
|
cJSON* json = cJSON_Parse(cmdData.c_str());
|
|
|
|
|
if (NULL != json)
|
|
|
|
|
{
|
|
|
|
|
std::string func = GetJsonStringValue(json, "func");
|
2022-05-30 11:01:23 +00:00
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden");
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
if ("set_global_config" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SetGlobalConfig(json);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("get_global_config" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
GetGlobalConfig(json);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("load_local_image" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
LoadLocalImage(json);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("save_local_image" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SaveLocalImage(json);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|
2022-06-01 10:36:22 +00:00
|
|
|
|
else if ("delete_local_file" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
DeleteLocalFile(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("clear_global_file_save_path" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
ClearGlobalFileSavePath(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("merge_local_image" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
MergeLocalImage(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("local_make_multi_image" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
LocalMakeMultiImage(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("split_local_image" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SplitLocalImage(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("local_make_zip_file" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
LocalMakeZipFile(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("local_image_deskew" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
LocalImageDeskew(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("upload_local_file" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
UploadLocalFile(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
2022-05-30 11:01:23 +00:00
|
|
|
|
else if ("init_device" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
InitDevice(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("deinit_device" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
DeinitDevice(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("get_device_name_list" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
GetDeviceNameList(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("open_device" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
OpenDevice(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("close_device" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
CloseDevice(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("set_device_param" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SetDeviceParam(json);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("get_device_param" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
GetDeviceParam(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("get_curr_device_name" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
GetCurrDeviceName(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("start_scan" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
StartScan(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if ("stop_scan" == func)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
StopScan(json);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
2022-06-07 10:22:27 +00:00
|
|
|
|
else if ("get_batch_id_list" == func)
|
|
|
|
|
{
|
|
|
|
|
GetBatchIdList(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("open_batch" == func)
|
|
|
|
|
{
|
|
|
|
|
OpenBatch(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("delete_batch" == func)
|
|
|
|
|
{
|
|
|
|
|
DeleteBatch(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("new_batch" == func)
|
|
|
|
|
{
|
|
|
|
|
NewBatch(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("get_curr_batch_id" == func)
|
|
|
|
|
{
|
|
|
|
|
GetCurrBatchId(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("modify_batch_id" == func)
|
|
|
|
|
{
|
|
|
|
|
ModifyBatchId(json);
|
|
|
|
|
}
|
2022-06-11 06:18:33 +00:00
|
|
|
|
else if ("bind_folder" == func)
|
|
|
|
|
{
|
|
|
|
|
BindFolder(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("stop_bind_folder" == func)
|
|
|
|
|
{
|
|
|
|
|
StopBindFolder(json);
|
|
|
|
|
}
|
2022-06-09 09:30:04 +00:00
|
|
|
|
else if ("get_image_thumbnail_list" == func)
|
|
|
|
|
{
|
|
|
|
|
GetImageThumbnailList(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("get_image_count" == func)
|
|
|
|
|
{
|
|
|
|
|
GetImageCount(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("load_image" == func)
|
|
|
|
|
{
|
|
|
|
|
LoadImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("save_image" == func)
|
|
|
|
|
{
|
|
|
|
|
SaveImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("insert_local_image" == func)
|
|
|
|
|
{
|
|
|
|
|
InsertLocalImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("insert_image" == func)
|
|
|
|
|
{
|
|
|
|
|
InsertImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("modify_image_tag" == func)
|
|
|
|
|
{
|
|
|
|
|
ModifyImageTag(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("delete_image" == func)
|
|
|
|
|
{
|
|
|
|
|
DeleteImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("clear_image_list" == func)
|
|
|
|
|
{
|
|
|
|
|
ClearImageList(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("modify_image" == func)
|
|
|
|
|
{
|
|
|
|
|
ModifyImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("modify_image_by_local" == func)
|
|
|
|
|
{
|
|
|
|
|
ModifyImageByLocal(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("move_image" == func)
|
|
|
|
|
{
|
|
|
|
|
MoveImage(json);
|
|
|
|
|
}
|
2022-06-11 06:18:33 +00:00
|
|
|
|
else if ("exchange_image" == func)
|
|
|
|
|
{
|
|
|
|
|
ExchangeImage(json);
|
|
|
|
|
}
|
2022-06-09 09:30:04 +00:00
|
|
|
|
else if ("image_book_sort" == func)
|
|
|
|
|
{
|
|
|
|
|
ImageBookSort(json);
|
|
|
|
|
}
|
2022-06-10 03:54:00 +00:00
|
|
|
|
else if ("merge_image" == func)
|
|
|
|
|
{
|
|
|
|
|
MergeImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("make_multi_image" == func)
|
|
|
|
|
{
|
|
|
|
|
MakeMultiImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("split_image" == func)
|
|
|
|
|
{
|
|
|
|
|
SplitImage(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("make_zip_file" == func)
|
|
|
|
|
{
|
|
|
|
|
MakeZipFile(json);
|
|
|
|
|
}
|
|
|
|
|
else if ("image_deskew" == func)
|
|
|
|
|
{
|
|
|
|
|
ImageDeskew(json);
|
|
|
|
|
}
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
cJSON_Delete(json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::HandleEvent(const WSEvtParam* param)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != param && m_id == param->usrId);
|
|
|
|
|
|
|
|
|
|
SendResponse(param->data, param->size, HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::PostCmdMsg(const HGByte* data, HGUInt dataSize)
|
|
|
|
|
{
|
|
|
|
|
WSCmdParam* param = new WSCmdParam;
|
|
|
|
|
param->svr = (WSServer*)m_server;
|
|
|
|
|
param->usrId = m_id;
|
|
|
|
|
param->data = new HGByte[dataSize];
|
|
|
|
|
param->size = dataSize;
|
|
|
|
|
memcpy(param->data, data, dataSize);
|
|
|
|
|
|
|
|
|
|
HGMsg msg;
|
|
|
|
|
msg.id = MSGID_WS_COMMAND;
|
|
|
|
|
msg.data = param;
|
|
|
|
|
if (HGBASE_ERR_OK != HGBase_PostPumpMessage(m_server->GetMsgPump(), &msg))
|
|
|
|
|
{
|
|
|
|
|
delete[] param->data;
|
|
|
|
|
param->size = 0;
|
|
|
|
|
delete param;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::PostEventMsg(const HGByte* data, HGUInt dataSize)
|
|
|
|
|
{
|
|
|
|
|
WSEvtParam* param = new WSEvtParam;
|
|
|
|
|
param->svr = (WSServer*)m_server;
|
|
|
|
|
param->usrId = m_id;
|
|
|
|
|
param->data = new HGByte[dataSize];
|
|
|
|
|
param->size = dataSize;
|
|
|
|
|
memcpy(param->data, data, dataSize);
|
|
|
|
|
|
|
|
|
|
HGMsg msg;
|
|
|
|
|
msg.id = MSGID_WS_EVENT;
|
|
|
|
|
msg.data = param;
|
|
|
|
|
if (HGBASE_ERR_OK != HGBase_PostPumpMessage(m_server->GetMsgPump(), &msg))
|
|
|
|
|
{
|
|
|
|
|
delete[] param->data;
|
|
|
|
|
param->size = 0;
|
|
|
|
|
delete param;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ThreadFunc()
|
|
|
|
|
{
|
|
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "WSUser::ThreadFunc");
|
|
|
|
|
|
|
|
|
|
char chBuffer[2048];
|
|
|
|
|
const char* pBuffer = chBuffer;
|
|
|
|
|
int nBufferSize = 0;
|
|
|
|
|
bool bConnect = false;
|
|
|
|
|
|
|
|
|
|
unsigned char connectDataTail[4] = { '\r', '\n', '\r', '\n' };
|
|
|
|
|
unsigned int connectDataTailLen = 0;
|
|
|
|
|
std::string connectData;
|
|
|
|
|
|
|
|
|
|
uint8_t* pData = NULL;
|
|
|
|
|
int nDataSize = 0;
|
|
|
|
|
uint8_t* pDataEx = NULL;
|
|
|
|
|
int nRemainSize = 0;
|
|
|
|
|
uint8_t headData[20];
|
|
|
|
|
uint32_t nHeadDataLen = 0;
|
|
|
|
|
uint8_t vMask[4];
|
|
|
|
|
uint32_t nMaskCount = 0;
|
|
|
|
|
bool bHandle = false;
|
|
|
|
|
std::vector<uint8_t> vAllData;
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
if (0 == nBufferSize)
|
|
|
|
|
{
|
|
|
|
|
int len = recv(m_sockConn, chBuffer, 2048, 0);
|
|
|
|
|
if (len <= 0)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 这里跳出,可能是服务器关闭了socketConn,或者客户端关闭了socket,或者网络断开
|
2022-05-23 10:29:23 +00:00
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pBuffer = chBuffer;
|
|
|
|
|
nBufferSize = len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(nBufferSize > 0);
|
|
|
|
|
|
|
|
|
|
if (!bConnect)
|
|
|
|
|
{
|
|
|
|
|
unsigned char b = *pBuffer;
|
|
|
|
|
++pBuffer;
|
|
|
|
|
--nBufferSize;
|
|
|
|
|
|
|
|
|
|
connectData.push_back(b);
|
|
|
|
|
if (b == connectDataTail[connectDataTailLen])
|
|
|
|
|
{
|
|
|
|
|
++connectDataTailLen;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connectDataTailLen = 0;
|
|
|
|
|
if (b == connectDataTail[connectDataTailLen])
|
|
|
|
|
{
|
|
|
|
|
++connectDataTailLen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (4 == connectDataTailLen)
|
|
|
|
|
{
|
|
|
|
|
connectDataTailLen = 0;
|
|
|
|
|
bool shakeRet = ShakeHand(connectData);
|
|
|
|
|
connectData.clear();
|
|
|
|
|
|
|
|
|
|
if (!shakeRet)
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bConnect = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pData)
|
|
|
|
|
{
|
|
|
|
|
assert(0 == nDataSize);
|
|
|
|
|
|
|
|
|
|
uint8_t b = *pBuffer;
|
|
|
|
|
++pBuffer;
|
|
|
|
|
--nBufferSize;
|
|
|
|
|
headData[nHeadDataLen] = b;
|
|
|
|
|
++nHeadDataLen;
|
|
|
|
|
|
|
|
|
|
if (1 == nHeadDataLen)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if ((0x80 | 0x08) == headData[0]) // 断开连接
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else if ((0x80 | 0x09) == headData[0]) // PING帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else if ((0x80 | 0x0A) == headData[0]) // PONG帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
else if ((0x00 | 0x01) == headData[0] || (0x00 | 0x02) == headData[0] || (0x00 | 0x00) == headData[0] || (0x80 | 0x00) == headData[0]
|
2022-05-24 02:01:36 +00:00
|
|
|
|
|| (0x80 | 0x01) == headData[0] || (0x80 | 0x02) == headData[0]) // 数据帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
if ((0x80 | 0x00) == headData[0] || (0x80 | 0x01) == headData[0] || (0x80 | 0x02) == headData[0])
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 分片结束
|
2022-05-23 10:29:23 +00:00
|
|
|
|
bHandle = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 分片帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
bHandle = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else // 帧错误,断开连接
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (2 == nHeadDataLen)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if (0 == (headData[1] & 0x80)) // 必须经过掩码处理
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if ((0x80 | 0x09) == headData[0]) // PING帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (0x80 != headData[1])
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else if ((0x80 | 0x0A) == headData[0]) // PONG帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (0x80 != headData[1])
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((headData[1] & 0x7F) <= 125)
|
|
|
|
|
{
|
|
|
|
|
uint32_t nCmdSize = (headData[1] & 0x7F);
|
|
|
|
|
nHeadDataLen = 0;
|
|
|
|
|
|
|
|
|
|
if (0 == nCmdSize)
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nDataSize = nCmdSize;
|
|
|
|
|
nRemainSize = nCmdSize;
|
|
|
|
|
pData = new uint8_t[nDataSize];
|
|
|
|
|
pDataEx = pData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (4 == nHeadDataLen)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if ((0x80 | 0x09) == headData[0]) // PING帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else if ((0x80 | 0x0A) == headData[0]) // PONG帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((headData[1] & 0x7F) == 126)
|
|
|
|
|
{
|
|
|
|
|
uint32_t nCmdSize = ntohs(*(uint16_t*)&headData[2]);
|
|
|
|
|
nHeadDataLen = 0;
|
|
|
|
|
|
|
|
|
|
if (0 == nCmdSize)
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nDataSize = nCmdSize;
|
|
|
|
|
nRemainSize = nCmdSize;
|
|
|
|
|
pData = new uint8_t[nDataSize];
|
|
|
|
|
pDataEx = pData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (6 == nHeadDataLen)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if ((0x80 | 0x09) == headData[0]) // PING帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
nHeadDataLen = 0;
|
|
|
|
|
|
|
|
|
|
Pong();
|
|
|
|
|
}
|
2022-05-24 02:01:36 +00:00
|
|
|
|
else if ((0x80 | 0x0A) == headData[0]) // PONG帧
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
nHeadDataLen = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (10 == nHeadDataLen)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
if ((headData[1] & 0x7F) == 127) // 这里一定会等于127
|
2022-05-23 10:29:23 +00:00
|
|
|
|
{
|
|
|
|
|
uint32_t nCmdSizeHigh = ntohl(*(uint32_t*)&headData[2]);
|
|
|
|
|
uint32_t nCmdSize = ntohl(*(uint32_t*)&headData[6]);
|
|
|
|
|
nHeadDataLen = 0;
|
|
|
|
|
|
|
|
|
|
if ((0 != nCmdSizeHigh) || (0 == nCmdSize))
|
|
|
|
|
{
|
|
|
|
|
PostDisConnectMsg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nDataSize = nCmdSize;
|
|
|
|
|
nRemainSize = nCmdSize;
|
|
|
|
|
pData = new uint8_t[nDataSize];
|
|
|
|
|
pDataEx = pData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (4 != nMaskCount)
|
|
|
|
|
{
|
|
|
|
|
uint8_t b = *pBuffer;
|
|
|
|
|
++pBuffer;
|
|
|
|
|
--nBufferSize;
|
|
|
|
|
vMask[nMaskCount] = b;
|
|
|
|
|
++nMaskCount;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int nWriteSize = HGMIN(nBufferSize, nRemainSize);
|
|
|
|
|
memcpy(pDataEx, pBuffer, nWriteSize);
|
|
|
|
|
pBuffer += nWriteSize;
|
|
|
|
|
nBufferSize -= nWriteSize;
|
|
|
|
|
pDataEx += nWriteSize;
|
|
|
|
|
nRemainSize -= nWriteSize;
|
|
|
|
|
|
|
|
|
|
if (0 == nRemainSize)
|
|
|
|
|
{
|
|
|
|
|
assert(pDataEx == pData + nDataSize);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nDataSize; ++i)
|
|
|
|
|
{
|
|
|
|
|
int j = i % 4;
|
|
|
|
|
pData[i] = pData[i] ^ vMask[j];
|
|
|
|
|
vAllData.push_back(pData[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete[] pData;
|
|
|
|
|
pData = NULL;
|
|
|
|
|
nDataSize = 0;
|
|
|
|
|
nMaskCount = 0;
|
|
|
|
|
|
|
|
|
|
if (bHandle)
|
|
|
|
|
{
|
2022-05-24 02:01:36 +00:00
|
|
|
|
PostCmdMsg(&vAllData[0], (HGUInt)vAllData.size());
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
bHandle = false;
|
|
|
|
|
vAllData.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL != pData)
|
|
|
|
|
{
|
|
|
|
|
delete[] pData;
|
|
|
|
|
pData = NULL;
|
|
|
|
|
nDataSize = 0;
|
|
|
|
|
nMaskCount = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:39:54 +00:00
|
|
|
|
void WSUser::SaneEvent2(int code, const char* str, bool err, void* param)
|
|
|
|
|
{
|
|
|
|
|
WSUser* p = (WSUser*)param;
|
|
|
|
|
|
|
|
|
|
if (code == SANEEVENT_ARRIVE)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (p->m_initDeviceHaveIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
fmt += "\"device_name\":\"%s\"}";
|
|
|
|
|
|
2022-05-31 09:39:54 +00:00
|
|
|
|
char resp[1024];
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (p->m_initDeviceHaveIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "device_arrive", p->m_initDeviceIden.c_str(), str);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "device_arrive", str);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
|
|
|
|
}
|
|
|
|
|
else if (code == SANEEVENT_REMOVE)
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (p->m_initDeviceHaveIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
fmt += "\"device_name\":\"%s\"}";
|
|
|
|
|
|
2022-05-31 09:39:54 +00:00
|
|
|
|
char resp[1024];
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (p->m_initDeviceHaveIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "device_remove", p->m_initDeviceIden.c_str(), str);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "device_remove", str);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
|
|
|
|
}
|
|
|
|
|
else if (code == SANEEVENT_WORKING)
|
|
|
|
|
{
|
|
|
|
|
char resp[1024];
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (p->m_startScanHaveIden)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\"}", "scan_begin", p->m_startScanIden.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\"}", "scan_begin");
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
if (p->m_startScanHaveIden)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"is_error\":%s, \"info\":\"%s\"}",
|
|
|
|
|
"scan_info", p->m_startScanIden.c_str(), err ? "true" : "false", str);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"is_error\":%s, \"info\":\"%s\"}",
|
|
|
|
|
"scan_info", err ? "true" : "false", str);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
|
|
|
|
}
|
|
|
|
|
else if (code == SANEEVENT_FINISH)
|
|
|
|
|
{
|
|
|
|
|
char resp[1024];
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (p->m_startScanHaveIden)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"is_error\":%s, \"info\":\"%s\"}",
|
|
|
|
|
"scan_info", p->m_startScanIden.c_str(), err ? "true" : "false", str);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"is_error\":%s, \"info\":\"%s\"}",
|
|
|
|
|
"scan_info", err ? "true" : "false", str);
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
if (p->m_startScanHaveIden)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\"}", "scan_end", p->m_startScanIden.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\"}", "scan_end");
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SaneImageCallback2(const char* path, void* param)
|
|
|
|
|
{
|
|
|
|
|
WSUser* p = (WSUser*)param;
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::string base64;
|
|
|
|
|
if (p->m_startScanIsGetBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
p->GetManager()->LoadLocalImage(path, base64, errInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + base64.size()];
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (p->m_startScanHaveIden)
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (p->m_startScanIsGetBase64)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"image_path\":\"%s\", \"image_base64\":\"%s\"}",
|
|
|
|
|
"scan_image", p->m_startScanIden.c_str(), StdStringToUtf8(strToJson(path)).c_str(), base64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"image_path\":\"%s\"}",
|
|
|
|
|
"scan_image", p->m_startScanIden.c_str(), StdStringToUtf8(strToJson(path)).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (p->m_startScanIsGetBase64)
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"image_path\":\"%s\", \"image_base64\":\"%s\"}",
|
|
|
|
|
"scan_image", StdStringToUtf8(strToJson(path)).c_str(), base64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, "{\"func\":\"%s\", \"image_path\":\"%s\"}",
|
|
|
|
|
"scan_image", StdStringToUtf8(strToJson(path)).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 09:39:54 +00:00
|
|
|
|
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
2022-06-09 03:05:24 +00:00
|
|
|
|
delete[] resp;
|
2022-05-31 09:39:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
std::string WSUser::strToJson(const std::string str)
|
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
|
|
|
|
for (size_t i = 0; i < str.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
char c = str[i];
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case '\"':
|
|
|
|
|
ret.append("\\\"");
|
|
|
|
|
break;
|
|
|
|
|
case '\\':
|
|
|
|
|
ret.append("\\\\");
|
|
|
|
|
break;
|
|
|
|
|
case '\b':
|
|
|
|
|
ret.append("\\b");
|
|
|
|
|
break;
|
|
|
|
|
case '\f':
|
|
|
|
|
ret.append("\\f");
|
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
|
|
|
|
ret.append("\\n");
|
|
|
|
|
break;
|
|
|
|
|
case '\r':
|
|
|
|
|
ret.append("\\r");
|
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
|
|
|
|
ret.append("\\t");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ret.push_back(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
bool WSUser::ShakeHand(const std::string& head)
|
|
|
|
|
{
|
|
|
|
|
std::string requestMethod;
|
|
|
|
|
std::string requestURIPath;
|
|
|
|
|
HttpPairs requestURIQueryInfos;
|
|
|
|
|
std::string requestURIFragment;
|
|
|
|
|
std::string httpVersion;
|
|
|
|
|
HttpPairs headInfos;
|
|
|
|
|
HttpHead::AnalysisHead(head, requestMethod, requestURIPath, requestURIQueryInfos,
|
|
|
|
|
requestURIFragment, httpVersion, headInfos);
|
|
|
|
|
|
2022-06-10 03:54:00 +00:00
|
|
|
|
if (std::string::npos == HttpHead::GetValue(headInfos, "Connection").find("Upgrade"))
|
2022-05-23 10:29:23 +00:00
|
|
|
|
return false;
|
|
|
|
|
if ("websocket" != HttpHead::GetValue(headInfos, "Upgrade"))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
std::string key = HttpHead::GetValue(headInfos, "Sec-WebSocket-Key");
|
|
|
|
|
if (key.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
|
|
|
|
|
|
|
|
unsigned int message_digest[5];
|
|
|
|
|
SHA1 sha;
|
|
|
|
|
sha.Reset();
|
|
|
|
|
sha << key.c_str();
|
|
|
|
|
sha.Result(message_digest);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
|
message_digest[i] = htonl(message_digest[i]);
|
|
|
|
|
std::string serverKey = base64_encode((const unsigned char*)message_digest, 20);
|
|
|
|
|
|
|
|
|
|
std::string handShakeResp = "HTTP/1.1 101 Switching Protocols\r\n";
|
|
|
|
|
handShakeResp += "Upgrade: websocket\r\n";
|
|
|
|
|
handShakeResp += "Connection: Upgrade\r\n";
|
|
|
|
|
handShakeResp += "Sec-WebSocket-Accept:";
|
|
|
|
|
handShakeResp += serverKey;
|
|
|
|
|
handShakeResp += "\r\n\r\n";
|
|
|
|
|
send(m_sockConn, handShakeResp.c_str(), (int)handShakeResp.length(), 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::Pong()
|
|
|
|
|
{
|
|
|
|
|
uint8_t vHead[2];
|
|
|
|
|
vHead[0] = 0x80 | 0x0A;
|
|
|
|
|
vHead[1] = 0;
|
|
|
|
|
|
|
|
|
|
HGBase_EnterLock(m_cs);
|
|
|
|
|
send(m_sockConn, (const char*)vHead, 2, 0);
|
|
|
|
|
HGBase_LeaveLock(m_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WSUser::SendResponse(const HGByte* data, HGUInt size, HGBool text)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == data || 0 == size)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t nHeadLen = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t vHead[20] = { 0 };
|
|
|
|
|
vHead[0] = text ? (0x80 | 0x01) : (0x80 | 0x02);
|
|
|
|
|
if (size <= 125)
|
|
|
|
|
{
|
|
|
|
|
vHead[1] = (uint8_t)size;
|
|
|
|
|
nHeadLen = 2;
|
|
|
|
|
}
|
|
|
|
|
else if (size <= 0xFFFF)
|
|
|
|
|
{
|
|
|
|
|
vHead[1] = 126;
|
|
|
|
|
uint16_t payloadLength16b = htons((uint16_t)size);
|
|
|
|
|
memcpy(&vHead[2], &payloadLength16b, 2);
|
|
|
|
|
nHeadLen = 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vHead[1] = 127;
|
|
|
|
|
vHead[2] = 0;
|
|
|
|
|
vHead[3] = 0;
|
|
|
|
|
vHead[4] = 0;
|
|
|
|
|
vHead[5] = 0;
|
|
|
|
|
uint32_t payloadLength32b = htonl(size);
|
|
|
|
|
memcpy(&vHead[6], &payloadLength32b, 4);
|
|
|
|
|
nHeadLen = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGBase_EnterLock(m_cs);
|
|
|
|
|
send(m_sockConn, (const char*)vHead, nHeadLen, 0);
|
|
|
|
|
send(m_sockConn, (const char*)data, size, 0);
|
|
|
|
|
HGBase_LeaveLock(m_cs);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
void WSUser::SetGlobalConfig(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
GlobalConfig cfg;
|
|
|
|
|
HGUInt mask = 0;
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
cfg.fileSavePath = Utf8ToStdString(GetJsonStringValue(json, "file_save_path", &find));
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::fileSavePathMask;
|
|
|
|
|
|
|
|
|
|
cfg.fileNamePrefix = Utf8ToStdString(GetJsonStringValue(json, "file_name_prefix", &find));
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::fileNamePrefixMask;
|
|
|
|
|
|
|
|
|
|
cfg.fileNameMode = GetJsonStringValue(json, "file_name_mode", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::fileNameModeMask;
|
|
|
|
|
|
|
|
|
|
cfg.imageFormat = GetJsonStringValue(json, "image_format", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::imageFormatMask;
|
|
|
|
|
|
|
|
|
|
cfg.imageJpegQuality = GetJsonIntValue(json, "image_jpeg_quality", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::imageJpegQualityMask;
|
|
|
|
|
|
|
|
|
|
cfg.imageTiffCompression = GetJsonStringValue(json, "image_tiff_compression", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::imageTiffCompressionMask;
|
|
|
|
|
|
|
|
|
|
cfg.imageTiffJpegQuality = GetJsonIntValue(json, "image_tiff_jpeg_quality", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= GlobalConfig::imageTiffJpegQualityMask;
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SetGlobalConfig(cfg, mask, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = {0};
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_global_config", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_global_config", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_global_config", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_global_config", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetGlobalConfig(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
GlobalConfig cfg;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetGlobalConfig(cfg, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"file_save_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"file_name_prefix\":\"%s\", ";
|
|
|
|
|
fmt += "\"file_name_mode\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_format\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_jpeg_quality\":%d, ";
|
|
|
|
|
fmt += "\"image_tiff_compression\":\"%s\", ";
|
2022-06-13 11:56:43 +00:00
|
|
|
|
fmt += "\"image_tiff_jpeg_quality\":%d}";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 10:22:27 +00:00
|
|
|
|
char resp[2048] = {0};
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_global_config", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_global_config", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_global_config", iden.c_str(), ret, StdStringToUtf8(strToJson(cfg.fileSavePath)).c_str(),
|
|
|
|
|
StdStringToUtf8(strToJson(cfg.fileNamePrefix)).c_str(), cfg.fileNameMode.c_str(), cfg.imageFormat.c_str(), cfg.imageJpegQuality,
|
2022-06-13 11:56:43 +00:00
|
|
|
|
cfg.imageTiffCompression.c_str(), cfg.imageTiffJpegQuality);
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_global_config", ret, StdStringToUtf8(strToJson(cfg.fileSavePath)).c_str(),
|
|
|
|
|
StdStringToUtf8(strToJson(cfg.fileNamePrefix)).c_str(), cfg.fileNameMode.c_str(), cfg.imageFormat.c_str(), cfg.imageJpegQuality,
|
2022-06-13 11:56:43 +00:00
|
|
|
|
cfg.imageTiffCompression.c_str(), cfg.imageTiffJpegQuality);
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::LoadLocalImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
|
|
|
|
|
|
|
|
|
std::string imageBase64;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->LoadLocalImage(imagePath, imageBase64, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + imageBase64.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_local_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_local_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_local_image", iden.c_str(), ret, imageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_local_image", ret, imageBase64.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SaveLocalImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imageBase64 = GetJsonStringValue(json, "image_base64");
|
|
|
|
|
|
|
|
|
|
std::string imagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SaveLocalImage(imageBase64, imagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = {0};
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_local_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_local_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(imagePath)).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_local_image", ret, StdStringToUtf8(strToJson(imagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::DeleteLocalFile(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string filePath = Utf8ToStdString(GetJsonStringValue(json, "file_path"));
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->DeleteLocalFile(filePath, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = {0};
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_local_file", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_local_file", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_local_file", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_local_file", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ClearGlobalFileSavePath(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ClearGlobalFileSavePath(errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = {0};
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_global_file_save_path", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_global_file_save_path", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_global_file_save_path", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_global_file_save_path", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::MergeLocalImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> imagePathList = GetJsonStringListValue(json, "image_path_list");
|
|
|
|
|
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
|
|
|
|
imagePathList[i] = Utf8ToStdString(imagePathList[i]);
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string mode = GetJsonStringValue(json, "mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
mode = "horz";
|
|
|
|
|
std::string align = GetJsonStringValue(json, "align", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
align = "center";
|
|
|
|
|
int interval = GetJsonIntValue(json, "interval", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
interval = 0;
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->MergeLocalImage(imagePathList, mode, align, interval, outImagePath, errInfo);
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-09 03:05:24 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
delete[] resp;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::LocalMakeMultiImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> imagePathList = GetJsonStringListValue(json, "image_path_list");
|
|
|
|
|
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
|
|
|
|
imagePathList[i] = Utf8ToStdString(imagePathList[i]);
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string format = GetJsonStringValue(json, "format", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
format = "tif";
|
|
|
|
|
std::string tiffCompression = GetJsonStringValue(json, "tiff_compression", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
tiffCompression = "lzw";
|
|
|
|
|
int tiffJpegQuality = GetJsonIntValue(json, "tiff_jpeg_quality", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
tiffJpegQuality = 80;
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->LocalMakeMultiImage(imagePathList, format, tiffCompression, tiffJpegQuality, outImagePath, errInfo);
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-09 03:05:24 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
delete[] resp;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SplitLocalImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string mode = GetJsonStringValue(json, "mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
mode = "horz";
|
|
|
|
|
int location = GetJsonIntValue(json, "location", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
location = 0;
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> outImagePathList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SplitLocalImage(imagePath, mode, location, outImagePathList, errInfo);
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::vector<std::string> outImageBase64List;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePathList[i], outImageBase64, errInfo2);
|
|
|
|
|
outImageBase64List.push_back(outImageBase64);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-09 03:05:24 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path_list\":%s, ";
|
|
|
|
|
fmt += "\"image_base64_list\":%s}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path_list\":%s}";
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
std::string pathList = "[";
|
|
|
|
|
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
pathList += "\"";
|
|
|
|
|
pathList += StdStringToUtf8(strToJson(outImagePathList[i]));
|
|
|
|
|
pathList += "\"";
|
|
|
|
|
if (i != (int)outImagePathList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
pathList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pathList += "]";
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::string base64List = "[";
|
|
|
|
|
for (int i = 0; i < (int)outImageBase64List.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
base64List += "\"";
|
|
|
|
|
base64List += outImageBase64List[i];
|
|
|
|
|
base64List += "\"";
|
|
|
|
|
if (i != (int)outImageBase64List.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
base64List += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base64List += "]";
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + base64List.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
2022-06-10 03:54:00 +00:00
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str(), base64List.c_str());
|
2022-06-09 03:05:24 +00:00
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
2022-06-10 03:54:00 +00:00
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str(), base64List.c_str());
|
2022-06-09 03:05:24 +00:00
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
delete[] resp;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::LocalMakeZipFile(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> filePathList = GetJsonStringListValue(json, "file_path_list");
|
|
|
|
|
for (int i = 0; i < (int)filePathList.size(); ++i)
|
|
|
|
|
filePathList[i] = Utf8ToStdString(filePathList[i]);
|
2022-06-11 09:54:04 +00:00
|
|
|
|
std::vector<std::string> nameList;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
std::string outZipPath;
|
|
|
|
|
std::string errInfo;
|
2022-06-11 09:54:04 +00:00
|
|
|
|
int ret = GetManager()->LocalMakeZipFile(filePathList, nameList, outZipPath, errInfo);
|
|
|
|
|
|
|
|
|
|
std::string outZipBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
GetManager()->LoadBase64(outZipPath, outZipBase64);
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-11 09:54:04 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"zip_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"zip_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"zip_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-13 04:02:51 +00:00
|
|
|
|
char* resp = new char[1024 + outZipBase64.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-11 09:54:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", iden.c_str(), ret, StdStringToUtf8(strToJson(outZipPath)).c_str(),
|
|
|
|
|
outZipBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", iden.c_str(), ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
2022-06-11 09:54:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", ret, StdStringToUtf8(strToJson(outZipPath)).c_str(),
|
|
|
|
|
outZipBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_make_zip_file", ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-13 04:02:51 +00:00
|
|
|
|
delete[] resp;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::LocalImageDeskew(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->LocalImageDeskew(imagePath, outImagePath, errInfo);
|
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-09 03:05:24 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-09 03:05:24 +00:00
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
else
|
2022-06-09 03:05:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
delete[] resp;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::UploadLocalFile(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string filePath = Utf8ToStdString(GetJsonStringValue(json, "file_path"));
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string remoteFilePath = Utf8ToStdString(GetJsonStringValue(json, "remote_file_path", &find));
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
HGChar fileName[256];
|
|
|
|
|
HGBase_GetFileName(filePath.c_str(), fileName, 256);
|
|
|
|
|
remoteFilePath.clear();
|
|
|
|
|
remoteFilePath += "/";
|
|
|
|
|
remoteFilePath += fileName;
|
|
|
|
|
}
|
2022-06-13 11:56:43 +00:00
|
|
|
|
std::string uploadMode = GetJsonStringValue(json, "upload_mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
uploadMode = "http";
|
|
|
|
|
std::string httpHost = GetJsonStringValue(json, "http_host", &find);
|
|
|
|
|
int httpPort = GetJsonIntValue(json, "http_port", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
httpPort = 80;
|
|
|
|
|
std::string httpPath = GetJsonStringValue(json, "http_path", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
httpPath = "/upload.cgi";
|
|
|
|
|
std::string ftpUser = GetJsonStringValue(json, "ftp_user", &find);
|
|
|
|
|
std::string ftpPassword = GetJsonStringValue(json, "ftp_password", &find);
|
|
|
|
|
std::string ftpHost = GetJsonStringValue(json, "ftp_host", &find);
|
|
|
|
|
int ftpPort = GetJsonIntValue(json, "ftp_port", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
ftpPort = 21;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
2022-06-13 11:56:43 +00:00
|
|
|
|
int ret = GetManager()->UploadLocalFile(filePath, remoteFilePath, uploadMode, httpHost, httpPort, httpPath,
|
|
|
|
|
ftpUser, ftpPassword, ftpHost, ftpPort, errInfo);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "upload_local_file", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "upload_local_file", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "upload_local_file", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "upload_local_file", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::InitDevice(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (!GetManager()->IsDeviceInit())
|
2022-06-06 10:51:34 +00:00
|
|
|
|
{
|
|
|
|
|
m_initDeviceIden = iden;
|
|
|
|
|
m_initDeviceHaveIden = findIden;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->InitDevice(errInfo);
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
m_initDeviceIden.clear();
|
|
|
|
|
m_initDeviceHaveIden = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "init_device", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "init_device", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "init_device", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "init_device", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::DeinitDevice(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->DeinitDevice(errInfo);
|
|
|
|
|
|
|
|
|
|
m_initDeviceIden.clear();
|
|
|
|
|
m_initDeviceHaveIden = false;
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "deinit_device", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "deinit_device", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "deinit_device", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "deinit_device", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetDeviceNameList(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> devNameList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetDeviceNameList(devNameList, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"device_name_list\":%s}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
std::string nameList = "[";
|
|
|
|
|
for (int i = 0; i < (int)devNameList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
nameList += "\"";
|
|
|
|
|
nameList += devNameList[i];
|
|
|
|
|
nameList += "\"";
|
|
|
|
|
if (i != (int)devNameList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
nameList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nameList += "]";
|
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_name_list", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_name_list", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_name_list", iden.c_str(), ret, nameList.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_name_list", ret, nameList.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::OpenDevice(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string devName = GetJsonStringValue(json, "device_name", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> devNameList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
GetManager()->GetDeviceNameList(devNameList, errInfo);
|
|
|
|
|
if (!devNameList.empty())
|
|
|
|
|
devName = devNameList[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->OpenDevice(devName, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_device", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_device", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_device", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_device", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::CloseDevice(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->CloseDevice(errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "close_device", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "close_device", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "close_device", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "close_device", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SetDeviceParam(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
DeviceParam param;
|
|
|
|
|
HGUInt mask = 0;
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
param.colorMode = GetJsonStringValue(json, "color_mode", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::colorModeMask;
|
|
|
|
|
|
|
|
|
|
param.pageMode = GetJsonStringValue(json, "page_mode", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::pageModeMask;
|
|
|
|
|
|
|
|
|
|
param.resolution = GetJsonIntValue(json, "resolution", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::resolutionMask;
|
|
|
|
|
|
|
|
|
|
param.brightness = GetJsonIntValue(json, "brightness", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::brightnessMask;
|
|
|
|
|
|
|
|
|
|
param.contrast = GetJsonIntValue(json, "contrast", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::contrastMask;
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
param.gamma = GetJsonDoubleValue(json, "gamma", &find);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::gammaMask;
|
|
|
|
|
|
|
|
|
|
param.paperSize = GetJsonStringValue(json, "paper_size", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperSizeMask;
|
|
|
|
|
|
|
|
|
|
param.paperCutEnabled = GetJsonBoolValue(json, "paper_cut_enabled", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperCutEnabledMask;
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
param.paperCutLeft = GetJsonDoubleValue(json, "paper_cut_left", &find);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperCutLeftMask;
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
param.paperCutTop = GetJsonDoubleValue(json, "paper_cut_top", &find);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperCutTopMask;
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
param.paperCutRight = GetJsonDoubleValue(json, "paper_cut_right", &find);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperCutRightMask;
|
|
|
|
|
|
2022-06-06 11:34:54 +00:00
|
|
|
|
param.paperCutBottom = GetJsonDoubleValue(json, "paper_cut_bottom", &find);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::paperCutBottomMask;
|
|
|
|
|
|
|
|
|
|
param.autoCrop = GetJsonBoolValue(json, "auto_crop", &find);
|
|
|
|
|
if (find)
|
|
|
|
|
mask |= DeviceParam::autoCropMask;
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SetDeviceParam(param, mask, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_device_param", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_device_param", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_device_param", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "set_device_param", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetDeviceParam(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
DeviceParam param;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetDeviceParam(param, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"color_mode_list\":%s, ";
|
|
|
|
|
fmt += "\"color_mode\":\"%s\", ";
|
|
|
|
|
fmt += "\"page_mode_list\":%s, ";
|
|
|
|
|
fmt += "\"page_mode\":\"%s\", ";
|
|
|
|
|
fmt += "\"resolution_list\":%s, ";
|
|
|
|
|
fmt += "\"resolution\":%d, ";
|
|
|
|
|
fmt += "\"brightness_min\":%d, ";
|
|
|
|
|
fmt += "\"brightness_max\":%d, ";
|
|
|
|
|
fmt += "\"brightness\":%d, ";
|
|
|
|
|
fmt += "\"contrast_min\":%d, ";
|
|
|
|
|
fmt += "\"contrast_max\":%d, ";
|
|
|
|
|
fmt += "\"contrast\":%d, ";
|
|
|
|
|
fmt += "\"gamma_min\":%f, ";
|
|
|
|
|
fmt += "\"gamma_max\":%f, ";
|
|
|
|
|
fmt += "\"gamma\":%f, ";
|
|
|
|
|
fmt += "\"paper_size_list\":%s, ";
|
|
|
|
|
fmt += "\"paper_size\":\"%s\", ";
|
|
|
|
|
fmt += "\"paper_size_width\":%f, ";
|
|
|
|
|
fmt += "\"paper_size_height\":%f, ";
|
|
|
|
|
fmt += "\"paper_cut_enabled\":%s, ";
|
|
|
|
|
fmt += "\"paper_cut_left\":%f, ";
|
|
|
|
|
fmt += "\"paper_cut_top\":%f, ";
|
|
|
|
|
fmt += "\"paper_cut_right\":%f, ";
|
|
|
|
|
fmt += "\"paper_cut_bottom\":%f, ";
|
|
|
|
|
fmt += "\"auto_crop\":%s}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
std::string colorModeList = "[";
|
|
|
|
|
for (int i = 0; i < (int)param.colorModeList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
colorModeList += "\"";
|
|
|
|
|
colorModeList += param.colorModeList[i];
|
|
|
|
|
colorModeList += "\"";
|
|
|
|
|
if (i != (int)param.colorModeList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
colorModeList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
colorModeList += "]";
|
|
|
|
|
|
|
|
|
|
std::string pageModeList = "[";
|
|
|
|
|
for (int i = 0; i < (int)param.pageModeList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
pageModeList += "\"";
|
|
|
|
|
pageModeList += param.pageModeList[i];
|
|
|
|
|
pageModeList += "\"";
|
|
|
|
|
if (i != (int)param.pageModeList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
pageModeList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pageModeList += "]";
|
|
|
|
|
|
|
|
|
|
std::string resolutionList = "[";
|
|
|
|
|
for (int i = 0; i < (int)param.resolutionList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
char resolution[32];
|
|
|
|
|
sprintf(resolution, "%d", param.resolutionList[i]);
|
|
|
|
|
resolutionList += resolution;
|
|
|
|
|
if (i != (int)param.resolutionList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
resolutionList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resolutionList += "]";
|
|
|
|
|
|
|
|
|
|
std::string paperSizeList = "[";
|
|
|
|
|
for (int i = 0; i < (int)param.paperSizeList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
paperSizeList += "\"";
|
|
|
|
|
paperSizeList += param.paperSizeList[i];
|
|
|
|
|
paperSizeList += "\"";
|
|
|
|
|
if (i != (int)param.paperSizeList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
paperSizeList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
paperSizeList += "]";
|
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[2048] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_param", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_param", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_param", iden.c_str(), ret, colorModeList.c_str(),
|
|
|
|
|
param.colorMode.c_str(), pageModeList.c_str(), param.pageMode.c_str(), resolutionList.c_str(), param.resolution,
|
|
|
|
|
param.brightnessMin, param.brightnessMax, param.brightness, param.contrastMin, param.contrastMax, param.contrast,
|
|
|
|
|
param.gammaMin, param.gammaMax, param.gamma, paperSizeList.c_str(), param.paperSize.c_str(), param.paperSizeWidth, param.paperSizeHeight,
|
|
|
|
|
param.paperCutEnabled ? "true" : "false", param.paperCutLeft, param.paperCutTop, param.paperCutRight, param.paperCutBottom,
|
|
|
|
|
param.autoCrop ? "true" : "false");
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_device_param", ret, colorModeList.c_str(),
|
|
|
|
|
param.colorMode.c_str(), pageModeList.c_str(), param.pageMode.c_str(), resolutionList.c_str(), param.resolution,
|
|
|
|
|
param.brightnessMin, param.brightnessMax, param.brightness, param.contrastMin, param.contrastMax, param.contrast,
|
|
|
|
|
param.gammaMin, param.gammaMax, param.gamma, paperSizeList.c_str(), param.paperSize.c_str(), param.paperSizeWidth, param.paperSizeHeight,
|
|
|
|
|
param.paperCutEnabled ? "true" : "false", param.paperCutLeft, param.paperCutTop, param.paperCutRight, param.paperCutBottom,
|
|
|
|
|
param.autoCrop ? "true" : "false");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetCurrDeviceName(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string devName;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetCurrDeviceName(devName, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"device_name\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_device_name", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_device_name", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_device_name", iden.c_str(), ret, devName.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_device_name", ret, devName.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::StartScan(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (!GetManager()->IsScanning())
|
|
|
|
|
{
|
|
|
|
|
m_startScanIden = iden;
|
|
|
|
|
m_startScanHaveIden = findIden;
|
2022-06-09 03:05:24 +00:00
|
|
|
|
m_startScanIsGetBase64 = getBase64;
|
2022-06-07 03:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->StartScan(errInfo);
|
2022-06-09 03:05:24 +00:00
|
|
|
|
if (0 != ret)
|
2022-06-06 10:51:34 +00:00
|
|
|
|
{
|
2022-06-07 03:18:55 +00:00
|
|
|
|
m_startScanIden.clear();
|
|
|
|
|
m_startScanHaveIden = false;
|
2022-06-09 03:05:24 +00:00
|
|
|
|
m_startScanIsGetBase64 = false;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "start_scan", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "start_scan", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "start_scan", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "start_scan", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::StopScan(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->StopScan(errInfo);
|
|
|
|
|
|
|
|
|
|
m_startScanIden.clear();
|
|
|
|
|
m_startScanHaveIden = false;
|
2022-06-09 03:05:24 +00:00
|
|
|
|
m_startScanIsGetBase64 = false;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
2022-06-07 03:18:55 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-06-07 03:18:55 +00:00
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_scan", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_scan", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
2022-06-06 10:51:34 +00:00
|
|
|
|
else
|
2022-06-07 03:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_scan", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_scan", ret);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 10:51:34 +00:00
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
2022-06-07 10:22:27 +00:00
|
|
|
|
|
|
|
|
|
void WSUser::GetBatchIdList(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> batchIdList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetBatchIdList(batchIdList, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"batch_id_list\":%s}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string idList = "[";
|
|
|
|
|
for (int i = 0; i < (int)batchIdList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
idList += "\"";
|
|
|
|
|
idList += batchIdList[i];
|
|
|
|
|
idList += "\"";
|
|
|
|
|
if (i != (int)batchIdList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
idList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
idList += "]";
|
|
|
|
|
|
|
|
|
|
char *resp = new char[1024 + idList.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_batch_id_list", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_batch_id_list", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_batch_id_list", iden.c_str(), ret, idList.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_batch_id_list", ret, idList.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::OpenBatch(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string batchId = GetJsonStringValue(json, "batch_id", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> batchIdList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
GetManager()->GetBatchIdList(batchIdList, errInfo);
|
|
|
|
|
|
|
|
|
|
if (!batchIdList.empty())
|
|
|
|
|
batchId = batchIdList[batchIdList.size() - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->OpenBatch(batchId, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_batch", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_batch", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_batch", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "open_batch", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::DeleteBatch(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string batchId = GetJsonStringValue(json, "batch_id");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->DeleteBatch(batchId, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_batch", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_batch", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_batch", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_batch", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::NewBatch(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
std::string newBatchId;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string batchId = GetJsonStringValue(json, "batch_id", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
HGChar uuid[256];
|
|
|
|
|
HGBase_GetUuid(uuid, 256);
|
|
|
|
|
batchId = std::string(uuid, 6);
|
|
|
|
|
|
|
|
|
|
ret = GetManager()->NewBatch(batchId, errInfo);
|
|
|
|
|
if (0 == ret)
|
|
|
|
|
{
|
|
|
|
|
newBatchId = batchId;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ret = GetManager()->NewBatch(batchId, errInfo);
|
|
|
|
|
if (0 == ret)
|
|
|
|
|
newBatchId = batchId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"batch_id\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "new_batch", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "new_batch", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "new_batch", iden.c_str(), ret, newBatchId.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "new_batch", ret, newBatchId.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetCurrBatchId(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string batchId;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetCurrBatchId(batchId, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"batch_id\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_batch_id", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_batch_id", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_batch_id", iden.c_str(), ret, batchId.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_curr_batch_id", ret, batchId.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ModifyBatchId(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string batchId = GetJsonStringValue(json, "batch_id", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
GetManager()->GetCurrBatchId(batchId, errInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string newBatchId = GetJsonStringValue(json, "new_batch_id");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ModifyBatchId(batchId, newBatchId, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_batch_id", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_batch_id", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_batch_id", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_batch_id", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
2022-06-09 09:30:04 +00:00
|
|
|
|
|
2022-06-11 06:18:33 +00:00
|
|
|
|
void WSUser::BindFolder(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string folder = Utf8ToStdString(GetJsonStringValue(json, "folder"));
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string nameMode = GetJsonStringValue(json, "name_mode");
|
|
|
|
|
if (!find)
|
2022-06-13 04:02:51 +00:00
|
|
|
|
nameMode = "order";
|
|
|
|
|
|
|
|
|
|
int nameWidth = GetJsonIntValue(json, "name_width", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
nameWidth = 1;
|
|
|
|
|
|
|
|
|
|
int nameBase = GetJsonIntValue(json, "name_base", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
nameBase = 0;
|
2022-06-11 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
2022-06-13 04:02:51 +00:00
|
|
|
|
int ret = GetManager()->BindFolder(folder, nameMode, nameWidth, nameBase, errInfo);
|
2022-06-11 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "bind_folder", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "bind_folder", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "bind_folder", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "bind_folder", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::StopBindFolder(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->StopBindFolder(errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_bind_folder", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_bind_folder", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_bind_folder", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "stop_bind_folder", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 09:30:04 +00:00
|
|
|
|
void WSUser::GetImageThumbnailList(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<ImageThumbInfo> imageThumbList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetImageThumbnailList(imageThumbList, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_thumbnail_list\":%s}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string thumbList = "[";
|
|
|
|
|
for (int i = 0; i < (int)imageThumbList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
thumbList += "{\"image_tag\":\"";
|
|
|
|
|
thumbList += imageThumbList[i].tag;
|
|
|
|
|
thumbList += "\", \"image_base64\":\"";
|
|
|
|
|
thumbList += imageThumbList[i].thumbBase64;
|
|
|
|
|
thumbList += "\"}";
|
|
|
|
|
|
|
|
|
|
if (i != (int)imageThumbList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
thumbList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
thumbList += "]";
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + thumbList.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_thumbnail_list", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_thumbnail_list", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_thumbnail_list", iden.c_str(), ret, thumbList.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_thumbnail_list", ret, thumbList.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::GetImageCount(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageCount = 0;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->GetImageCount(imageCount, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_count\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_count", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_count", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_count", iden.c_str(), ret, imageCount);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "get_image_count", ret, imageCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::LoadImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
|
|
|
|
|
std::string imageTag, imageBase64;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->LoadImage(imageIndex, imageTag, imageBase64, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_tag\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *resp = new char [1024 + imageTag.size() + imageBase64.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_image", iden.c_str(), ret, imageTag.c_str(), imageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "load_image", ret, imageTag.c_str(), imageBase64.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SaveImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
|
|
|
|
|
std::string imagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SaveImage(imageIndex, imagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_image", iden.c_str(), ret, StdStringToUtf8(strToJson(imagePath)).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "save_image", ret, StdStringToUtf8(strToJson(imagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::InsertLocalImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
int insertPos = GetJsonIntValue(json, "insert_pos", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
insertPos = -1;
|
|
|
|
|
|
|
|
|
|
std::string imageTag = GetJsonStringValue(json, "image_tag");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->InsertLocalImage(imagePath, insertPos, imageTag, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_local_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_local_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_local_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_local_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::InsertImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string imageBase64 = GetJsonStringValue(json, "image_base64");
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
int insertPos = GetJsonIntValue(json, "insert_pos", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
insertPos = -1;
|
|
|
|
|
|
|
|
|
|
std::string imageTag = GetJsonStringValue(json, "image_tag");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->InsertImage(imageBase64, insertPos, imageTag, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "insert_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ModifyImageTag(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
std::vector<std::string> imageTagList = GetJsonStringListValue(json, "image_tag_list");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ModifyImageTag(imageIndexList, imageTagList, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_tag", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_tag", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_tag", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_tag", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::DeleteImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->DeleteImage(imageIndexList, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "delete_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ClearImageList(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ClearImageList(errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_image_list", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_image_list", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_image_list", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "clear_image_list", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ModifyImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
std::string imageBase64 = GetJsonStringValue(json, "image_base64");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ModifyImage(imageIndex, imageBase64, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ModifyImageByLocal(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ModifyImageByLocal(imageIndex, imagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_by_local", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_by_local", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_by_local", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "modify_image_by_local", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::MoveImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string mode = GetJsonStringValue(json, "mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
mode = "index";
|
|
|
|
|
|
|
|
|
|
int target = GetJsonIntValue(json, "target");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->MoveImage(imageIndexList, mode, target, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "move_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "move_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "move_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "move_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 06:18:33 +00:00
|
|
|
|
void WSUser::ExchangeImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex1 = GetJsonIntValue(json, "image_index_1");
|
|
|
|
|
int imageIndex2 = GetJsonIntValue(json, "image_index_2");
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ExchangeImage(imageIndex1, imageIndex2, errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024] = { 0 };
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "exchange_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "exchange_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "exchange_image", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "exchange_image", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 09:30:04 +00:00
|
|
|
|
void WSUser::ImageBookSort(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ImageBookSort(errInfo);
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char resp[1024];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_book_sort", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_book_sort", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_book_sort", iden.c_str(), ret);
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_book_sort", ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
}
|
2022-06-10 03:54:00 +00:00
|
|
|
|
|
|
|
|
|
void WSUser::MergeImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string mode = GetJsonStringValue(json, "mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
mode = "horz";
|
|
|
|
|
std::string align = GetJsonStringValue(json, "align", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
align = "center";
|
|
|
|
|
int interval = GetJsonIntValue(json, "interval", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
interval = 0;
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->MergeImage(imageIndexList, mode, align, interval, outImagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::MakeMultiImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string format = GetJsonStringValue(json, "format", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
format = "tif";
|
|
|
|
|
std::string tiffCompression = GetJsonStringValue(json, "tiff_compression", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
tiffCompression = "lzw";
|
|
|
|
|
int tiffJpegQuality = GetJsonIntValue(json, "tiff_jpeg_quality", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
tiffJpegQuality = 80;
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->MakeMultiImage(imageIndexList, format, tiffCompression, tiffJpegQuality, outImagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::SplitImage(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
|
|
|
|
|
bool find = false;
|
|
|
|
|
std::string mode = GetJsonStringValue(json, "mode", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
mode = "horz";
|
|
|
|
|
int location = GetJsonIntValue(json, "location", &find);
|
|
|
|
|
if (!find)
|
|
|
|
|
location = 0;
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> outImagePathList;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->SplitImage(imageIndex, mode, location, outImagePathList, errInfo);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> outImageBase64List;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePathList[i], outImageBase64, errInfo2);
|
|
|
|
|
outImageBase64List.push_back(outImageBase64);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path_list\":%s, ";
|
|
|
|
|
fmt += "\"image_base64_list\":%s}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path_list\":%s}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string pathList = "[";
|
|
|
|
|
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
pathList += "\"";
|
|
|
|
|
pathList += StdStringToUtf8(strToJson(outImagePathList[i]));
|
|
|
|
|
pathList += "\"";
|
|
|
|
|
if (i != (int)outImagePathList.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
pathList += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pathList += "]";
|
|
|
|
|
|
|
|
|
|
std::string base64List = "[";
|
|
|
|
|
for (int i = 0; i < (int)outImageBase64List.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
base64List += "\"";
|
|
|
|
|
base64List += outImageBase64List[i];
|
|
|
|
|
base64List += "\"";
|
|
|
|
|
if (i != (int)outImageBase64List.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
base64List += ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base64List += "]";
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + base64List.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, pathList.c_str(), base64List.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, pathList.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", ret, pathList.c_str(), base64List.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "split_image", ret, pathList.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::MakeZipFile(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
|
|
|
|
|
|
|
|
|
std::string outZipPath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->MakeZipFile(imageIndexList, outZipPath, errInfo);
|
|
|
|
|
|
2022-06-11 09:54:04 +00:00
|
|
|
|
std::string outZipBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
GetManager()->LoadBase64(outZipPath, outZipBase64);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 03:54:00 +00:00
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
2022-06-11 09:54:04 +00:00
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"zip_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"zip_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"zip_path\":\"%s\"}";
|
|
|
|
|
}
|
2022-06-10 03:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 04:02:51 +00:00
|
|
|
|
char* resp = new char[1024 + outZipBase64.size()];
|
2022-06-10 03:54:00 +00:00
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
2022-06-11 09:54:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", iden.c_str(), ret, StdStringToUtf8(strToJson(outZipPath)).c_str(),
|
|
|
|
|
outZipBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", iden.c_str(), ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
|
|
|
|
}
|
2022-06-10 03:54:00 +00:00
|
|
|
|
else
|
2022-06-11 09:54:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", ret, StdStringToUtf8(strToJson(outZipPath)).c_str(),
|
|
|
|
|
outZipBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "make_zip_file", ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
|
|
|
|
}
|
2022-06-10 03:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
2022-06-13 04:02:51 +00:00
|
|
|
|
delete[] resp;
|
2022-06-10 03:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSUser::ImageDeskew(cJSON* json)
|
|
|
|
|
{
|
|
|
|
|
assert(NULL != json);
|
|
|
|
|
|
|
|
|
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
|
|
|
|
|
|
|
|
|
std::string outImagePath;
|
|
|
|
|
std::string errInfo;
|
|
|
|
|
int ret = GetManager()->ImageDeskew(imageIndex, outImagePath, errInfo);
|
|
|
|
|
|
|
|
|
|
std::string outImageBase64;
|
|
|
|
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
|
|
|
|
if (0 == ret && getBase64)
|
|
|
|
|
{
|
|
|
|
|
std::string errInfo2;
|
|
|
|
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool findIden = false;
|
|
|
|
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
|
|
|
|
|
|
|
|
|
std::string fmt;
|
|
|
|
|
fmt += "{\"func\":\"%s\", ";
|
|
|
|
|
if (findIden)
|
|
|
|
|
fmt += "\"iden\":\"%s\", ";
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
fmt += "\"err_info\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"ret\":%d, ";
|
|
|
|
|
if (getBase64)
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\", ";
|
|
|
|
|
fmt += "\"image_base64\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fmt += "\"image_path\":\"%s\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* resp = new char[1024 + outImageBase64.size()];
|
|
|
|
|
if (0 != ret)
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(errInfo).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (findIden)
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getBase64)
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
|
|
|
|
outImageBase64.c_str());
|
|
|
|
|
else
|
|
|
|
|
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
|
|
|
|
delete[] resp;
|
|
|
|
|
}
|
2022-05-23 10:29:23 +00:00
|
|
|
|
}
|