集成cgi方式的http上传

This commit is contained in:
luoliangyi 2022-06-24 13:52:34 +08:00
parent 08ade613b7
commit 3ffb868808
7 changed files with 375 additions and 36 deletions

View File

@ -44,6 +44,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HGTwainUser", "HGTwainUser\
{F85F4457-1B42-46E7-BA86-F088D6D5994F} = {F85F4457-1B42-46E7-BA86-F088D6D5994F}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HGUpload", "HGUpload\HGUpload.vcxproj", "{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}"
ProjectSection(ProjectDependencies) = postProject
{F85F4457-1B42-46E7-BA86-F088D6D5994F} = {F85F4457-1B42-46E7-BA86-F088D6D5994F}
{EFAE5F69-A4C2-4A07-8BE6-68714D86BCE2} = {EFAE5F69-A4C2-4A07-8BE6-68714D86BCE2}
{4954F36B-A0A3-4550-9C4E-3B3D210F5CE4} = {4954F36B-A0A3-4550-9C4E-3B3D210F5CE4}
{5D85F2AC-FACD-436C-A67B-E13056DD0C03} = {5D85F2AC-FACD-436C-A67B-E13056DD0C03}
{4909ACEA-80FF-482E-9FA2-5E8534789A82} = {4909ACEA-80FF-482E-9FA2-5E8534789A82}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -108,6 +117,14 @@ Global
{EFAE5F69-A4C2-4A07-8BE6-68714D86BCE2}.Release|x64.Build.0 = Release|x64
{EFAE5F69-A4C2-4A07-8BE6-68714D86BCE2}.Release|x86.ActiveCfg = Release|Win32
{EFAE5F69-A4C2-4A07-8BE6-68714D86BCE2}.Release|x86.Build.0 = Release|Win32
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Debug|x64.ActiveCfg = Debug|x64
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Debug|x64.Build.0 = Debug|x64
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Debug|x86.ActiveCfg = Debug|Win32
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Debug|x86.Build.0 = Debug|Win32
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Release|x64.ActiveCfg = Release|x64
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Release|x64.Build.0 = Release|x64
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Release|x86.ActiveCfg = Release|Win32
{FC39DAEA-2BB2-45AE-A7F3-F3879692A66B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\modules\base\HGUtility.cpp" />
<ClCompile Include="..\..\..\sdk\upload\main.cpp" />
<ClCompile Include="..\..\..\third_party\cgic\cgic.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\modules\base\HGUtility.h" />
<ClInclude Include="..\..\..\third_party\cgic\cgic.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{fc39daea-2bb2-45ae-a7f3-f3879692a66b}</ProjectGuid>
<RootNamespace>HGUpload</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>upload</TargetName>
<TargetExt>.cgi</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>upload</TargetName>
<TargetExt>.cgi</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>upload</TargetName>
<TargetExt>.cgi</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>upload</TargetName>
<TargetExt>.cgi</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/cgic/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/cgic/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
</Link>
<PostBuildEvent>
<Command>copy $(OutDir)upload.cgi $(SolutionDir)..\..\..\release\win\x86\Release\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/cgic/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/cgic/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
</Link>
<PostBuildEvent>
<Command>copy $(OutDir)upload.cgi $(SolutionDir)..\..\..\release\win\x64\Release\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -129,7 +129,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;OEM_HUAGAO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sqlite/;../../../utility/;../../../third_party/libzip/windows/include/;../../../third_party/libcurl/windows/include/;../../../../sdk/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -148,7 +148,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;OEM_HUAGAO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sqlite/;../../../utility/;../../../third_party/libzip/windows/include/;../../../third_party/libcurl/windows/include/;../../../../sdk/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -169,7 +169,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;OEM_HUAGAO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sqlite/;../../../utility/;../../../third_party/libzip/windows/include/;../../../third_party/libcurl/windows/include/;../../../../sdk/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -187,7 +187,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;OEM_HUAGAO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>../../../modules/;../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sqlite/;../../../utility/;../../../third_party/libzip/windows/include/;../../../third_party/libcurl/windows/include/;../../../../sdk/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

111
sdk/upload/main.cpp Normal file
View File

@ -0,0 +1,111 @@
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include <string>
#include "cgic.h"
int cgiMain()
{
char mimiType[32] = "text/html; charset=utf-8";
char fileName[32] = "filename";
char remoteFileName[32] = "remote_filename";
cgiHeaderContentType(mimiType);
char* scriptPath = getenv("PATH_INFO");
fprintf(cgiOut, "scriptPath: %s<br>\n", scriptPath);
char* scriptFullPath = getenv("PATH_TRANSLATED");
fprintf(cgiOut, "scriptFullPath: %s<br>\n", scriptFullPath);
if (NULL == scriptPath || NULL == scriptFullPath)
{
fprintf(cgiOut, "<p> get PATH_INFO or PATH_TRANSLATED failed. </p>\n");
return cgiFormNotFound;
}
char stdScriptPath[256];
HGBase_StandardiseFileName(scriptPath, stdScriptPath, 256);
char* p = strstr(scriptFullPath, stdScriptPath);
if (NULL == p)
{
fprintf(cgiOut, "<p> PATH_INFO or PATH_TRANSLATED error. </p>\n");
return cgiFormNotFound;
}
std::string rootPath(scriptFullPath, p - scriptFullPath);
fprintf(cgiOut, "rootPath: ");
cgiHtmlEscape(rootPath.c_str());
fprintf(cgiOut, "<br>\n");
char name[512];
if (cgiFormFileName(fileName, name, sizeof(name)) != cgiFormSuccess)
{
fprintf(cgiOut, "<p> no filename. </p>\n");
return cgiFormNoFileName;
}
fprintf(cgiOut, "filename: ");
cgiHtmlEscape(name);
fprintf(cgiOut, "<br>\n");
int size = 0;
cgiFormFileSize(fileName, &size);
if (size <= 0)
{
fprintf(cgiOut, "<p> bad file size. </p>\n");
return cgiFormEmpty;
}
fprintf(cgiOut, "file size: %d bytes<br>\n", size);
char remoteFilePath[512];
if (cgiFormString(remoteFileName, remoteFilePath, sizeof(remoteFilePath)) != cgiFormSuccess)
{
fprintf(cgiOut, "<p> no remote filename. </p>\n");
return cgiFormNoFileName;
}
fprintf(cgiOut, "remote_filepath: ");
cgiHtmlEscape(remoteFilePath);
fprintf(cgiOut, "<br>\n");
cgiFilePtr file = NULL;
if (cgiFormFileOpen(fileName, &file) != cgiFormSuccess)
{
fprintf(cgiOut, "<p> Could not open the file. </p>\n");
return cgiFormOpenFailed;
}
std::string savePath = rootPath + remoteFilePath;
char stdSavePath[256];
HGBase_StandardiseFileName(savePath.c_str(), stdSavePath, 256);
char stdSaveDir[256];
HGBase_GetFilePath(stdSavePath, stdSaveDir, 256);
HGBase_CreateDir(stdSaveDir);
fprintf(cgiOut, "savePath: ");
cgiHtmlEscape(stdSavePath);
fprintf(cgiOut, "<br>\n");
FILE *fd = fopen(stdSavePath, "wb+");
if (fd == NULL)
{
fprintf(cgiOut, "<p> create file failed. </p>\n");
cgiFormFileClose(file);
return cgiFormOpenFailed;
}
char tmp[1024];
int got = 0;
while (cgiFormFileRead(file, tmp, 1024, &got) == cgiFormSuccess)
{
fwrite(tmp, got, sizeof(char), fd); //把读出的content写入新文件
}
fclose(fd);
cgiFormFileClose(file);
//打印输出
fprintf(cgiOut, "<p> upload file success. </p>\n");
return cgiFormSuccess;
}

View File

@ -2830,7 +2830,41 @@ namespace ver_2
int ManagerV2::HttpUpload(const std::string& host, int port, const std::string& path,
const std::string& filePath, const std::string& remoteFilePath)
{
return -1;
curl_global_init(CURL_GLOBAL_ALL);
int ret = -1;
CURL* curl = curl_easy_init();
if (curl)
{
struct curl_httppost* formpost = NULL;
struct curl_httppost* lastptr = NULL;
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "filename", CURLFORM_FILE, filePath.c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "remote_filename", CURLFORM_COPYCONTENTS, remoteFilePath.c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Submit", CURLFORM_END);
char url[512];
sprintf(url, "http://%s:%d%s", host.c_str(), port, path.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
/* Perform the request, res will get the return code */
CURLcode res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
else
ret = 0;
/* always cleanup */
curl_easy_cleanup(curl);
/* then cleanup the formpost chain */
curl_formfree(formpost);
}
curl_global_cleanup();
return ret;
}
static size_t read_callback(char* ptr, size_t size, size_t nmemb, void* stream)
@ -2870,22 +2904,6 @@ namespace ver_2
CURL* curl = curl_easy_init();
if (NULL != curl)
{
//char tmpName[256];
//HGBase_GetUuid(tmpName, 256);
char remotePath[256];
HGBase_GetFilePath(remoteFilePath.c_str(), remotePath, 256);
char remoteName[256];
HGBase_GetFileName(remoteFilePath.c_str(), remoteName, 256);
//char ftp_rnfr[512];
//sprintf(ftp_rnfr, "RNFR %s", tmpName);
//char ftp_rnto[512];
//sprintf(ftp_rnto, "RNTO %s", remoteName);
//struct curl_slist* headerlist = NULL;
//headerlist = curl_slist_append(headerlist, ftp_rnfr);
//headerlist = curl_slist_append(headerlist, ftp_rnto);
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
@ -2894,12 +2912,12 @@ namespace ver_2
char url[512];
if (!user.empty() && !password.empty())
{
sprintf(url, "ftp://%s:%s@%s:%d%s%s", user.c_str(), password.c_str(),
host.c_str(), port, remotePath, remoteName);
sprintf(url, "ftp://%s:%s@%s:%d%s", user.c_str(), password.c_str(),
host.c_str(), port, remoteFilePath.c_str());
}
else
{
sprintf(url, "ftp://%s:%d%s%s", host.c_str(), port, remotePath, remoteName);
sprintf(url, "ftp://%s:%d%s", host.c_str(), port, remoteFilePath.c_str());
}
curl_easy_setopt(curl, CURLOPT_URL, url);

View File

@ -360,6 +360,18 @@
}));
}
function HttpUpload()
{
socket.send(JSON.stringify({
'func':'upload_local_file',
'file_path':'D:\\1.jpg',
'remote_file_path':'/savedir/123.jpg',
'upload_mode':'http',
'http_host':'192.168.100.148',
'http_port':8001
}));
}
function MergeLocalImage()
{
socket.send(JSON.stringify({
@ -831,10 +843,13 @@
<input id="serverPort" type="text" placeholder="服务器端口" value="38999" />
<input id="btnConnect" type="button" value="连接" onclick="connect()" />
<input id="btnDisConnect" type="button" value="断开" onclick="disconnect()" />
<input type="button" value="设置全局参数" onclick="SetGlobalParam()" />
<input type="button" value="获取全局参数" onclick="GetGlobalParam()" />
<input type="button" value="清理保存目录" onclick="ClearGlobalSavePath()" />
<input type="button" value="FTP上传" onclick="FtpUpload()" />
<input type="button" value="HTTP上传" onclick="HttpUpload()" />
<input type="button" value="合成本地图像" onclick="MergeLocalImage()" />
<input type="button" value="本地合成多张图像" onclick="LocalMakeMultiImage()" />
<input type="button" value="拆分本地图像" onclick="SplitLocalImage()" />
@ -876,6 +891,7 @@
<input type="button" value="移动图像" onclick="MoveImage()" />
<input type="button" value="交换图像" onclick="ExchangeImage()" />
<input type="button" value="图像书籍排序" onclick="ImageBookSort()" />
<input type="button" value="合成图像" onclick="MergeImage()" />
<input type="button" value="合成多张图像" onclick="MakeMultiImage()" />
<input type="button" value="拆分图像" onclick="SplitImage()" />

View File

@ -31,7 +31,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifdef WIN32
#ifdef _WIN32
#include <io.h>
/* cgic 2.01 */
@ -39,7 +39,7 @@
#else
#include <unistd.h>
#endif /* WIN32 */
#endif /* _WIN32 */
#include "cgic.h"
#define cgiStrEq(a, b) (!strcmp((a), (b)))
@ -200,12 +200,12 @@ int main(int argc, char *argv[]) {
fprintf(dout, "%s\n", cgiContentType);
CGICDEBUGEND
#endif /* CGICDEBUG */
#ifdef WIN32
#ifdef _WIN32
/* 1.07: Must set stdin and stdout to binary mode */
/* 2.0: this is particularly crucial now and must not be removed */
_setmode( _fileno( stdin ), _O_BINARY );
_setmode( _fileno( stdout ), _O_BINARY );
#endif /* WIN32 */
#endif /* _WIN32 */
cgiFormEntryFirst = 0;
cgiIn = stdin;
cgiOut = stdout;
@ -274,7 +274,7 @@ int main(int argc, char *argv[]) {
} else if (cgiStrEqNc(cgiRequestMethod, "get")) {
/* The spec says this should be taken care of by
the server, but... it isn't */
cgiContentLength = strlen(cgiQueryString);
cgiContentLength = (int)strlen(cgiQueryString);
if (cgiParseGetFormInput() != cgiParseSuccess) {
#ifdef CGICDEBUG
CGICDEBUGSTART
@ -371,7 +371,7 @@ int mpRead(mpStreamPtr mpp, char *buffer, int len)
}
}
if (len) {
int fgot = fread(buffer, 1, len, cgiIn);
int fgot = (int)fread(buffer, 1, len, cgiIn);
if (fgot >= 0) {
mpp->offset += (got + fgot);
return got + fgot;
@ -634,7 +634,7 @@ static cgiParseResultType getTempFile(FILE **tFile)
length is strlen(cgiTempDir) + a short unique pattern. */
char tfileName[1024];
#ifndef WIN32
#ifndef _WIN32
/* Unix. Use the robust 'mkstemp' function to create
a temporary file that is truly unique, with
permissions that are truly safe. The
@ -726,7 +726,7 @@ cgiParseResultType afterNextBoundary(mpStreamPtr mpp, FILE *outf, char **outP,
if (first) {
workingBoundary = workingBoundaryData + 2;
}
workingBoundaryLength = strlen(workingBoundary);
workingBoundaryLength = (int)strlen(workingBoundary);
while (1) {
got = mpRead(mpp, d, 1);
if (got != 1) {
@ -1060,7 +1060,7 @@ static cgiParseResultType cgiParseFormInput(char *data, int length) {
}
n->attr = attr;
n->value = value;
n->valueLength = strlen(n->value);
n->valueLength = (int)strlen(n->value);
n->fileName = (char *) malloc(1);
if (!n->fileName) {
free(attr);
@ -1345,7 +1345,7 @@ cgiFormResultType cgiFormFileRead(
if (!cfp) {
return cgiFormOpenFailed;
}
got = fread(buffer, 1, bufferSize, cfp->in);
got = (int)fread(buffer, 1, bufferSize, cfp->in);
if (got <= 0) {
return cgiFormEOF;
}
@ -2187,7 +2187,7 @@ cgiEnvironmentResultType cgiReadEnvironment(char *filename) {
if (tryr > ((int) sizeof(buffer))) {
tryr = sizeof(buffer);
}
got = fread(buffer, 1, tryr, in);
got = (int)fread(buffer, 1, tryr, in);
if (got <= 0) {
result = cgiEnvironmentIO;
fclose(out);
@ -2329,7 +2329,7 @@ static cgiFormEntry *cgiFormEntryFindNext() {
}
static int cgiFirstNonspaceChar(char *s) {
int len = strspn(s, " \n\r\t");
int len = (int)strspn(s, " \n\r\t");
return s[len];
}