fix bug in mq C++

This commit is contained in:
lnk
2026-04-30 15:45:34 +08:00
parent 073c98e89a
commit 3c98bf7eae
5 changed files with 109 additions and 94 deletions

View File

@@ -1865,18 +1865,20 @@ static int ParseFileDirReq(const char *body, file_dir_req_t *req)
return -1;
cJSON *guid = cJSON_GetObjectItem(root, "guid");
cJSON *frontid = cJSON_GetObjectItem(root, "frontid");
cJSON *processNo = cJSON_GetObjectItem(root, "ProcessNo");
cJSON *devid = cJSON_GetObjectItem(root, "devid");
cJSON *frontid = cJSON_GetObjectItem(root, "nodeId");
cJSON *processNo = cJSON_GetObjectItem(root, "processNo");
cJSON *devid = cJSON_GetObjectItem(root, "devId");
cJSON *type = cJSON_GetObjectItem(root, "type");
cJSON *path = cJSON_GetObjectItem(root, "Path");
cJSON *path = cJSON_GetObjectItem(root, "path");
cJSON *remotepath = cJSON_GetObjectItem(root, "remotePath");
if (!guid || guid->type != cJSON_String ||
!frontid || frontid->type != cJSON_String ||
!processNo || processNo->type != cJSON_Number ||
!devid || devid->type != cJSON_String ||
!type || type->type != cJSON_Number ||
!path || path->type != cJSON_String)
!path || path->type != cJSON_String ||
!remotepath || remotepath->type != cJSON_String)
{
cJSON_Delete(root);
return -1;
@@ -1889,6 +1891,7 @@ static int ParseFileDirReq(const char *body, file_dir_req_t *req)
snprintf(req->devid, sizeof(req->devid), "%s", devid->valuestring);
req->type = type->valueint;
snprintf(req->path, sizeof(req->path), "%s", path->valuestring);
snprintf(req->remote_path, sizeof(req->remote_path), "%s", remotepath->valuestring);
req->create_time = time(NULL);
cJSON_Delete(root);
@@ -1943,25 +1946,28 @@ static std::string BuildFileDirRespJsonEx(const file_dir_req_t *req,
int result)
{
cJSON *root = cJSON_CreateObject();
cJSON *detail = cJSON_CreateObject();
cJSON *dirInfo = cJSON_CreateArray();
cJSON_AddStringToObject(root, "guid", req ? req->guid : "");
cJSON_AddStringToObject(root, "frontid", req ? req->frontid : "");
cJSON_AddStringToObject(root, "nodeId", req ? req->frontid : "");
cJSON_AddNumberToObject(root, "processNo", req ? req->processNo : 0);
cJSON_AddStringToObject(root, "devid", req ? req->devid : "");
cJSON_AddStringToObject(root, "devId", req ? req->devid : "");
cJSON_AddNumberToObject(root, "type", req ? req->type : 0);
cJSON_AddNumberToObject(root, "result", result);
for (int i = 0; i < itemNum; ++i)
{
cJSON *item = cJSON_CreateObject();
cJSON_AddStringToObject(item, "name", (names && names[i]) ? names[i] : "");
cJSON_AddStringToObject(item, "type", (itemTypes && itemTypes[i]) ? itemTypes[i] : "file");
cJSON_AddNumberToObject(item, "size", (itemSizes ? itemSizes[i] : 1));
cJSON_AddNumberToObject(item, "size", itemSizes ? itemSizes[i] : 1);
cJSON_AddItemToArray(dirInfo, item);
}
cJSON_AddItemToObject(root, "dirInfo", dirInfo);
cJSON_AddNumberToObject(root, "result", result);
cJSON_AddItemToObject(detail, "dirInfo", dirInfo);
cJSON_AddItemToObject(root, "detail", detail);
char *json = cJSON_PrintUnformatted(root);
std::string jsonStr = json ? json : "";
@@ -2196,22 +2202,22 @@ static int HandleTypeTransferToDevice(chnl_usr_t* chnl_usr,
return -1;
char localpath[512] = {0};
if (BuildTempLocalPath(localpath, sizeof(localpath), chnl_usr, req->path) != 0)
if (BuildTempLocalPath(localpath, sizeof(localpath), chnl_usr, req->remote_path) != 0)
{
DIY_ERRORLOG_CODE(req->devid,1, LOG_CODE_FILE_CONTROL,
"【ERROR】构造本地临时路径失败 devid=%s path=%s",
req->devid, req->path);
req->devid, req->remote_path);
jsonString = BuildSingleFileRespJson(req, NULL, "file", 1, -1);
return -1;
}
int dlRet = DownloadFileWeb(WEB_FILEDOWNLOAD, req->path, localpath);
int dlRet = DownloadFileWeb(WEB_FILEDOWNLOAD, req->remote_path, localpath);
if (dlRet != 0)
{
DIY_ERRORLOG_CODE(req->devid,1, LOG_CODE_FILE_CONTROL,
"【ERROR】Web 文件下载失败 devid=%s, path=%s",
req->devid, req->path);
req->devid, req->remote_path);
jsonString = BuildSingleFileRespJson(req, NULL, "file", 1, -1);
return -1;
@@ -2219,23 +2225,18 @@ static int HandleTypeTransferToDevice(chnl_usr_t* chnl_usr,
DIY_INFOLOG_CODE(req->devid,1, LOG_CODE_FILE_CONTROL,
"【NORMAL】Web 文件下载成功 devid=%s, webpath=%s, local=%s",
req->devid, req->path, localpath);
char destfilename[512] = {0};
const char* fileName = GetFileNameOnly(req->path);
snprintf(destfilename, sizeof(destfilename), "/etc/%s",
(fileName && fileName[0]) ? fileName : "tmp_file.dat");
req->devid, req->remote_path, localpath);
ST_RET ret = mms_mvla_obtfile(chnl_usr->net_info,
(ST_CHAR*)localpath,
(ST_CHAR*)destfilename,
(ST_CHAR*)localpath, //本地路径
(ST_CHAR*)req->path, //装置路径
3 * g_pt61850app->mmsOpTimeout);
if (ret != SD_SUCCESS)
{
DIY_ERRORLOG_CODE(req->devid,1, LOG_CODE_FILE_CONTROL,
"【ERROR】文件传送到装置失败 devid=%s, src=%s, dest=%s, ret=0x%X",
req->devid, localpath, destfilename, ret);
req->devid, localpath, req->path, ret);
jsonString = BuildSingleFileRespJson(req, NULL, "file", 1, ret);
return -1;
@@ -2243,10 +2244,10 @@ static int HandleTypeTransferToDevice(chnl_usr_t* chnl_usr,
DIY_INFOLOG_CODE(req->devid,1, LOG_CODE_FILE_CONTROL,
"【NORMAL】文件传送到装置成功 devid=%s, src=%s, dest=%s",
req->devid, localpath, destfilename);
req->devid, localpath, req->path);
jsonString = BuildSingleFileRespJson(req,
destfilename,
req->path,
"file",
1,
0);