Bläddra i källkod

修正代码逻辑

huanggen 1 år sedan
förälder
incheckning
f8f640f487
2 ändrade filer med 31 tillägg och 25 borttagningar
  1. 14 19
      UCloudSDK/api.cpp
  2. 17 6
      UCloudSDK/api.h

+ 14 - 19
UCloudSDK/api.cpp

@@ -14,17 +14,16 @@
 #include <vector>
 
 using namespace qcloud_cos;
-
 CosConfig g_config;
 
 void result2ufileError(ufile_error & retError, qcloud_cos::CosResult tRet)
 {
-	retError.errorCode = tRet.GetErrorCode().c_str();
-	retError.errorMessage = tRet.GetErrorMsg().c_str();
+	retError.errorCode = tRet.GetErrorCode();
+	retError.errorMessage = tRet.GetErrorMsg();
+	retError.resourceAddr = tRet.GetResourceAddr();
+	retError.cosRequestId = tRet.GetXCosRequestId();
+	retError.cosTraceId = tRet.GetXCosTraceId();
 	retError.httpStatus = tRet.GetHttpStatus();
-	retError.resourceAddr = tRet.GetResourceAddr().c_str();
-	retError.cosRequestId = tRet.GetXCosRequestId().c_str();
-	retError.cosTraceId = tRet.GetXCosTraceId().c_str();
 	retError.bIsSuccess = tRet.IsSucc();
 }
 
@@ -32,17 +31,14 @@ ufile_error ufile_load_config_from_json(const char * json_buf, ufile_config * cf
 {
 	ufile_error retError;
 	if (nullptr == cfg)
-	{
-		retError.bIsSuccess = false;
 		return retError;
-	}
 	Poco::JSON::Parser parser;
 	Poco::Dynamic::Var result;
 	try {
 		result = parser.parse(json_buf);
 	}
 	catch (Poco::JSON::JSONException& jsonErr) {
-		retError.errorMessage = jsonErr.message().c_str();
+		retError.errorMessage = jsonErr.message();
 		retError.bIsSuccess = false;
 		return retError;
 	}
@@ -118,8 +114,8 @@ ufile_error ufile_put_file_by_filepath(const char * bucket_name, const char * ke
 {
 	UNUSED_PARAM(mime_type);
 	ufile_error retError;
-	PutObjectByFileReq req(bucket_name, key, file_path);
-	PutObjectByFileResp resp;
+	qcloud_cos::PutObjectByFileReq req(bucket_name, key, file_path);
+	qcloud_cos::PutObjectByFileResp resp;
 	CosAPI cosApi(g_config);
 	CosResult result = cosApi.PutObject(req, &resp);
 	result2ufileError(retError, result);
@@ -133,8 +129,8 @@ void set_upload_company(int company)
 ufile_error ufile_delete(const char * bucket_name, const char * key)
 {
 	ufile_error retError;
-	DeleteObjectReq req(bucket_name, key);
-	DeleteObjectResp resp;
+	qcloud_cos::DeleteObjectReq req(bucket_name, key);
+	qcloud_cos::DeleteObjectResp resp;
 	CosAPI cosApi(g_config);
 	CosResult result = cosApi.DeleteObject(req, &resp);
 	result2ufileError(retError, result);
@@ -171,12 +167,11 @@ ufile_error ufile_download(const char * bucket_name, const char * key, FILE * fi
 	if (nullptr == file)
 	{
 		retError.errorMessage = "file is nullptr";
-		retError.bIsSuccess = false;
 		return retError;
 	}
 	std::ostringstream os;
-	GetObjectByStreamReq req(bucket_name, key, os);
-	GetObjectByStreamResp resp;
+	qcloud_cos::GetObjectByStreamReq req(bucket_name, key, os);
+	qcloud_cos::GetObjectByStreamResp resp;
 	CosAPI cosApi(g_config);
 	CosResult result = cosApi.GetObject(req, &resp);
 	if (result.IsSucc())
@@ -203,8 +198,8 @@ ufile_error ufile_bucket_create(const char * bucket_name, const char * region, c
 ufile_error ufile_bucket_delete(const char * bucket_name)
 {
 	ufile_error retError;
-	DeleteBucketReq req(bucket_name);
-	DeleteBucketResp resp;
+	qcloud_cos::DeleteBucketReq req(bucket_name);
+	qcloud_cos::DeleteBucketResp resp;
 	CosAPI cosApi(g_config);
 	CosResult result = cosApi.DeleteBucket(req, &resp);
 	result2ufileError(retError, result);

+ 17 - 6
UCloudSDK/api.h

@@ -2,19 +2,30 @@
 #define _H_UFILESDK_C_UCLOUD_API_
 
 #include <stdio.h>
+#include <string>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 //*******************************common data********************************
-struct __declspec(dllexport) ufile_error{
-    const char * errorCode;
-	const char * errorMessage;
-	const char * resourceAddr;
-	const char * cosRequestId;
-	const char * cosTraceId;
+struct __declspec(dllexport) ufile_error {
+	std::string errorCode;
+	std::string errorMessage;
+	std::string resourceAddr;
+	std::string cosRequestId;
+	std::string cosTraceId;
 	bool bIsSuccess;
 	int httpStatus;
+	ufile_error()
+	{
+		errorCode = "";
+		errorMessage = "";
+		resourceAddr = "";
+		cosRequestId = "";
+		cosTraceId = "";
+		bIsSuccess = false;
+		httpStatus = 0;
+	}
 };
 
 #define UFILE_OK  0