diff --git a/sdk/webservice/HttpUser.cpp b/sdk/webservice/HttpUser.cpp index e9387eee..b72107b4 100644 --- a/sdk/webservice/HttpUser.cpp +++ b/sdk/webservice/HttpUser.cpp @@ -286,9 +286,13 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) devParam.param = GetJsonStringValue(p, "param"); devParam.ftpUrl = GetJsonStringValue(p, "ftpUrl"); devParam.ftpPath = GetJsonStringValue(p, "ftpPath"); + if (!devParam.ftpPath.empty() && devParam.ftpPath[0] != '/') + devParam.ftpPath.insert(0, "/"); devParam.ftpUser = GetJsonStringValue(p, "ftpUser"); devParam.ftpPassword = GetJsonStringValue(p, "ftpPassword"); devParam.ftpPort = GetJsonIntValue(p, "ftpPort"); + if (0 == devParam.ftpPort) + devParam.ftpPort = atoi(GetJsonStringValue(p, "ftpPort").c_str()); devParam.ftpMode = GetJsonIntValue(p, "ftpMode"); } @@ -462,19 +466,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) uploadParam.param = GetJsonStringValue(json, "param"); uploadParam.ftpUrl = GetJsonStringValue(json, "ftpUrl"); uploadParam.ftpPath = GetJsonStringValue(json, "ftpPath"); + if (!uploadParam.ftpPath.empty() && uploadParam.ftpPath[0] != '/') + uploadParam.ftpPath.insert(0, "/"); uploadParam.ftpUser = GetJsonStringValue(json, "ftpUser"); uploadParam.ftpPassword = GetJsonStringValue(json, "ftpPassword"); uploadParam.ftpPort = GetJsonIntValue(json, "ftpPort"); + if (0 == uploadParam.ftpPort) + uploadParam.ftpPort = atoi(GetJsonStringValue(json, "ftpPort").c_str()); uploadParam.ftpMode = GetJsonIntValue(json, "ftpMode"); uploadParam.format = GetJsonIntValue(json, "format"); cJSON_Delete(json); } - GetManager()->UploadImage(uploadParam); + bool ret = GetManager()->UploadImage(uploadParam); char result[256]; - sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success"); + if (ret) + sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success"); + else + sprintf(result, "{\"code\":%d, \"msg\":\"%s\", \"data\":\"%s\"}", 201, "uploadImage failed", "fail"); SendResponse(requestHttpVersion.c_str(), 200, "OK", (const HGByte*)result, (HGUInt)strlen(result), "application/json"); } diff --git a/sdk/webservice/Manager.cpp b/sdk/webservice/Manager.cpp index 875a49d4..388a263a 100644 --- a/sdk/webservice/Manager.cpp +++ b/sdk/webservice/Manager.cpp @@ -44,6 +44,7 @@ void DevParam::Reset() noiseDetach = 15; uploadMode = 2; + ftpPath = "/images"; ftpPort = 21; ftpMode = 2; } @@ -366,9 +367,7 @@ bool Manager::GetDevParam(const std::string& devId, DevParam& devParam) if (NULL == desp) continue; - std::string title = Utf8ToStdString(desp->title); - TrimString(title); - HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "title=%s", title.c_str()); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "title=%s", Utf8ToStdString(desp->title).c_str()); if (SANE_TYPE_BOOL == desp->type) { @@ -376,9 +375,9 @@ bool Manager::GetDevParam(const std::string& devId, DevParam& devParam) sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=BOOL, value=%s", value ? "TRUE" : "FALSE"); - if (0 == strcmp(title.c_str(), "图像拆分")) + if (0 == strcmp(desp->title, OPTION_TITLE_TXCF)) m_devParam.splitImage = value ? 1 : 0; - else if (0 == strcmp(title.c_str(), "黑白图像噪点优化")) + else if (0 == strcmp(desp->title, OPTION_TITLE_HBTXZDYH)) m_devParam.noiseDetachEnable = (bool)value; } else if (SANE_TYPE_INT == desp->type) @@ -387,9 +386,9 @@ bool Manager::GetDevParam(const std::string& devId, DevParam& devParam) sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=INT, value=%d", value); - if (0 == strcmp(title.c_str(), "跳过空白页灵敏度")) + if (0 == strcmp(desp->title, OPTION_TITLE_TGKBYLMD)) m_devParam.discardBlankThre = value; - else if (0 == strcmp(title.c_str(), "分辨率")) + else if (0 == strcmp(desp->title, OPTION_TITLE_FBL)) m_devParam.resolution = value; } else if (SANE_TYPE_FIXED == desp->type) @@ -400,48 +399,48 @@ bool Manager::GetDevParam(const std::string& devId, DevParam& devParam) { char value[256] = {0}; sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, value, NULL); - std::string stdValue = Utf8ToStdString(value); - TrimString(stdValue); - HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=STRING, value=%s", stdValue.c_str()); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=STRING, value=%s", Utf8ToStdString(value).c_str()); - if (0 == strcmp("扫描张数", title.c_str()) && 0 == strcmp("连续扫描", stdValue.c_str())) + if (0 == strcmp(OPTION_TITLE_SMZS, desp->title) && 0 == strcmp(OPTION_VALUE_SMZS_LXSM, value)) m_devParam.autofeeder = true; - else if (0 == strcmp("扫描张数", title.c_str()) && 0 == strcmp("扫描指定张数", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_SMZS, desp->title) && 0 == strcmp(OPTION_VALUE_SMZS_SMZDZS, value)) m_devParam.autofeeder = false; - else if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("24位彩色", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_YSMS, desp->title) && (0 == strcmp(OPTION_VALUE_YSMS_24WCS, value) + || 0 == strcmp(OPTION_VALUE_YSMS_YSZDSB, value))) m_devParam.pixel = 2; - else if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("256级灰度", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_YSMS, desp->title) && 0 == strcmp(OPTION_VALUE_YSMS_256JHD, value)) m_devParam.pixel = 1; - else if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("黑白", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_YSMS, desp->title) && 0 == strcmp(OPTION_VALUE_YSMS_HB, value)) m_devParam.pixel = 0; - else if (0 == strcmp("扫描页面", title.c_str()) && 0 == strcmp("双面", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title) && 0 == strcmp(OPTION_VALUE_SMYM_SM, value)) { m_devParam.white = false; m_devParam.single = false; } - else if (0 == strcmp("扫描页面", title.c_str()) && 0 == strcmp("单面", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title) && 0 == strcmp(OPTION_VALUE_SMYM_DM, value)) { m_devParam.white = false; m_devParam.single = true; } - else if (0 == strcmp("扫描页面", title.c_str()) && NULL != strstr(stdValue.c_str(), "跳过空白页")) + else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title) && (0 == strcmp(OPTION_VALUE_SMYM_TGKBYTY, value) + || 0 == strcmp(OPTION_VALUE_SMYM_TGKBYFPZ, value))) { m_devParam.white = true; m_devParam.single = false; } - else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("0°", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_WGFX, desp->title) && 0 == strcmp(OPTION_VALUE_WGFX_0, value)) m_devParam.orentation = 0; - else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("90°", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_WGFX, desp->title) && 0 == strcmp(OPTION_VALUE_WGFX_90, value)) m_devParam.orentation = 90; - else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("180°", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_WGFX, desp->title) && 0 == strcmp(OPTION_VALUE_WGFX_180, value)) m_devParam.orentation = 180; - else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("-90°", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_WGFX, desp->title) && 0 == strcmp(OPTION_VALUE_WGFX__90, value)) m_devParam.orentation = 270; - else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("匹配原始尺寸", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title) && 0 == strcmp(OPTION_VALUE_ZZCC_PPYSCC, value)) m_devParam.paperType = "Auto"; - else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("A3", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title) && 0 == strcmp(OPTION_VALUE_ZZCC_A3, value)) m_devParam.paperType = "A3"; - else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("A4", stdValue.c_str())) + else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title) && 0 == strcmp(OPTION_VALUE_ZZCC_A4, value)) m_devParam.paperType = "A4"; } else if (SANE_TYPE_BUTTON == desp->type) @@ -490,19 +489,16 @@ bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam) if (NULL == desp) continue; - std::string title = Utf8ToStdString(desp->title); - TrimString(title); - if (SANE_TYPE_BOOL == desp->type) { - if (0 == strcmp(title.c_str(), "图像拆分")) + if (0 == strcmp(desp->title, OPTION_TITLE_TXCF)) { SANE_Bool value = SANE_FALSE; if (0 != m_devParam.splitImage) value = SANE_TRUE; sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL); } - else if (0 == strcmp(title.c_str(), "黑白图像噪点优化")) + else if (0 == strcmp(desp->title, OPTION_TITLE_HBTXZDYH)) { SANE_Bool value = SANE_FALSE; if (m_devParam.noiseDetachEnable) @@ -512,21 +508,19 @@ bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam) } else if (SANE_TYPE_INT == desp->type) { - if (0 == strcmp(title.c_str(), "跳过空白页灵敏度")) + if (0 == strcmp(desp->title, OPTION_TITLE_TGKBYLMD)) { SANE_Int value = m_devParam.discardBlankThre; sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL); } - else if (0 == strcmp(title.c_str(), "分辨率")) + else if (0 == strcmp(desp->title, OPTION_TITLE_FBL)) { SANE_Int value = m_devParam.resolution; sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL); } - else if (0 == strcmp(title.c_str(), "扫描数量")) + else if (0 == strcmp(desp->title, OPTION_TITLE_SMSL)) { SANE_Int value = 1; - //if (!m_devParam.autofeeder) - // value = 1; sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL); } } @@ -536,55 +530,55 @@ bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam) } else if (SANE_TYPE_STRING == desp->type) { - if (0 == strcmp("扫描张数", title.c_str())) + if (0 == strcmp(OPTION_TITLE_SMZS, desp->title)) { char value[256] = { 0 }; - strcpy(value, "连续扫描"); + strcpy(value, OPTION_VALUE_SMZS_LXSM); if (!m_devParam.autofeeder) - strcpy(value, "扫描指定张数"); - sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL); + strcpy(value, OPTION_VALUE_SMZS_SMZDZS); + sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)value, NULL); } - else if (0 == strcmp("颜色模式", title.c_str())) + else if (0 == strcmp(OPTION_TITLE_YSMS, desp->title)) { char value[256] = { 0 }; - strcpy(value, "24位彩色"); + strcpy(value, OPTION_VALUE_YSMS_24WCS); if (1 == m_devParam.pixel) - strcpy(value, "256级灰度"); + strcpy(value, OPTION_VALUE_YSMS_256JHD); else if (0 == m_devParam.pixel) - strcpy(value, "黑白"); - sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void *)(StdStringToUtf8(value).c_str()), NULL); + strcpy(value, OPTION_VALUE_YSMS_HB); + sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void *)value, NULL); } - else if (0 == strcmp("扫描页面", title.c_str())) + else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title)) { char value[256] = { 0 }; - strcpy(value, "双面"); + strcpy(value, OPTION_VALUE_SMYM_SM); if (m_devParam.single) - strcpy(value, "单面"); + strcpy(value, OPTION_VALUE_SMYM_DM); else if (m_devParam.white) - strcpy(value, "跳过空白页(通用)"); - sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL); + strcpy(value, OPTION_VALUE_SMYM_TGKBYTY); + sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)value, NULL); } - else if (0 == strcmp("文稿方向", title.c_str())) + else if (0 == strcmp(OPTION_TITLE_WGFX, desp->title)) { char value[256] = { 0 }; - strcpy(value, "0°"); + strcpy(value, OPTION_VALUE_WGFX_0); if (90 == m_devParam.orentation) - strcpy(value, "90°"); + strcpy(value, OPTION_VALUE_WGFX_90); else if (180 == m_devParam.orentation) - strcpy(value, "180°"); + strcpy(value, OPTION_VALUE_WGFX_180); else if (270 == m_devParam.orentation) - strcpy(value, "-90°"); - sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL); + strcpy(value, OPTION_VALUE_WGFX__90); + sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)value, NULL); } - else if (0 == strcmp("纸张尺寸", title.c_str())) + else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title)) { char value[256] = { 0 }; - strcpy(value, "匹配原始尺寸"); + strcpy(value, OPTION_VALUE_ZZCC_PPYSCC); if ("A3" == m_devParam.paperType) - strcpy(value, "A3"); + strcpy(value, OPTION_VALUE_ZZCC_A3); else if ("A4" == m_devParam.paperType) - strcpy(value, "A4"); - sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL); + strcpy(value, OPTION_VALUE_ZZCC_A4); + sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)value, NULL); } } else if (SANE_TYPE_BUTTON == desp->type) @@ -937,11 +931,20 @@ bool Manager::UploadImage(const UploadParam& uploadParam) HGChar tmpFileName[512]; HGBase_GetTmpFileName(tmpFileName, 512); if (0 == uploadParam.format) + { + strcat(tmpFileName, ".ofd"); ExportOfdFile(devId, true, tmpFileName); + } else if (1 == uploadParam.format) + { + strcat(tmpFileName, ".pdf"); ExportPdfFile(devId, tmpFileName); + } else + { + strcat(tmpFileName, ".zip"); ExportZipFile(devId, tmpFileName); + } bool ret = false; if (0 == uploadParam.uploadMode) // HTTP @@ -1571,7 +1574,7 @@ static size_t read_callback(char* ptr, size_t size, size_t nmemb, void* stream) if (retcode > 0) { nread = (unsigned long)retcode; - fprintf(stderr, "*** We read %lu bytes from file\n", nread); + //fprintf(stderr, "*** We read %lu bytes from file\n", nread); } return retcode; @@ -1586,6 +1589,7 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp return false; } + bool ret = false; fseek(file, 0, SEEK_END); long fsize = ftell(file); fseek(file, 0, SEEK_SET); @@ -1594,7 +1598,7 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp /* get a curl handle */ CURL *curl = curl_easy_init(); - if (curl) + if (NULL != curl) { char tmpName[256]; HGBase_GetUuid(tmpName, 256); @@ -1616,10 +1620,19 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); char url[512]; - sprintf(url, "ftp://%s:%s@%s:%d/%s/%s", ftpUser.c_str(), ftpPassword.c_str(), - ftpUrl.c_str(), ftpPort, ftpPath.c_str(), tmpName); + if (!ftpUser.empty() && !ftpPassword.empty()) + { + sprintf(url, "ftp://%s:%s@%s:%d%s/%s", ftpUser.c_str(), ftpPassword.c_str(), + ftpUrl.c_str(), ftpPort, ftpPath.c_str(), tmpName); + } + else + { + sprintf(url, "ftp://%s:%d%s/%s", ftpUrl.c_str(), ftpPort, ftpPath.c_str(), tmpName); + } curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1); + /* pass in that last of FTP commands to run after the transfer */ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist); @@ -1637,6 +1650,8 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp /* Check for errors */ if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + else + ret = true; /* clean up the FTP commands list */ curl_slist_free_all(headerlist); @@ -1647,7 +1662,7 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp fclose(file); /* close the local file */ curl_global_cleanup(); - return true; + return ret; } int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param) diff --git a/sdk/webservice/Manager.h b/sdk/webservice/Manager.h index b214f99b..70943f97 100644 --- a/sdk/webservice/Manager.h +++ b/sdk/webservice/Manager.h @@ -6,6 +6,7 @@ #include "../../base/HGLock.h" #include "../../base/HGImage.h" #include "sane/sane_ex.h" +#include "sane/sane_option_definitions.h" #include "WebMsg.h" #include #include