|
@@ -15,21 +15,22 @@
|
|
|
|
|
|
using namespace qcloud_cos;
|
|
using namespace qcloud_cos;
|
|
CosConfig g_config;
|
|
CosConfig g_config;
|
|
|
|
+std::string g_strBucketName = "";
|
|
|
|
|
|
-void result2ufileError(ufile_error & retError, qcloud_cos::CosResult tRet)
|
|
|
|
|
|
+void result2ufileError(ufile_error & retError, qcloud_cos::CosResult * tRet)
|
|
{
|
|
{
|
|
- 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.bIsSuccess = tRet.IsSucc();
|
|
|
|
|
|
+ strncpy_s(retError.errorCode, tRet->GetErrorCode().c_str(), sizeof(retError.errorCode));
|
|
|
|
+ strncpy_s(retError.errorMessage, tRet->GetErrorMsg().c_str(), sizeof(retError.errorMessage));
|
|
|
|
+ strncpy_s(retError.resourceAddr, tRet->GetResourceAddr().c_str(), sizeof(retError.resourceAddr));
|
|
|
|
+ strncpy_s(retError.cosRequestId, tRet->GetXCosRequestId().c_str(), sizeof(retError.cosRequestId));
|
|
|
|
+ strncpy_s(retError.cosTraceId, tRet->GetXCosTraceId().c_str(), sizeof(retError.cosTraceId));
|
|
|
|
+ retError.httpStatus = tRet->GetHttpStatus();
|
|
|
|
+ retError.bIsSuccess = tRet->IsSucc();
|
|
}
|
|
}
|
|
|
|
|
|
ufile_error ufile_load_config_from_json(const char * json_buf, ufile_config * cfg)
|
|
ufile_error ufile_load_config_from_json(const char * json_buf, ufile_config * cfg)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
if (nullptr == cfg)
|
|
if (nullptr == cfg)
|
|
return retError;
|
|
return retError;
|
|
Poco::JSON::Parser parser;
|
|
Poco::JSON::Parser parser;
|
|
@@ -38,13 +39,11 @@ ufile_error ufile_load_config_from_json(const char * json_buf, ufile_config * cf
|
|
result = parser.parse(json_buf);
|
|
result = parser.parse(json_buf);
|
|
}
|
|
}
|
|
catch (Poco::JSON::JSONException& jsonErr) {
|
|
catch (Poco::JSON::JSONException& jsonErr) {
|
|
- retError.errorMessage = jsonErr.message();
|
|
|
|
- retError.bIsSuccess = false;
|
|
|
|
|
|
+ strncpy_s(retError.errorMessage, jsonErr.message().c_str(), sizeof(retError.errorMessage));
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
if (result.type() != typeid(Poco::JSON::Object::Ptr)) {
|
|
if (result.type() != typeid(Poco::JSON::Object::Ptr)) {
|
|
- retError.errorMessage = "failed to parse config file";
|
|
|
|
- retError.bIsSuccess = false;
|
|
|
|
|
|
+ strncpy_s(retError.errorMessage, "failed to parse config file", sizeof(retError.errorMessage));
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
|
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
|
@@ -74,9 +73,10 @@ void ufile_free_config(ufile_config cfg)
|
|
ufile_error ufile_sdk_initialize(const ufile_config cfg, int open_verbose)
|
|
ufile_error ufile_sdk_initialize(const ufile_config cfg, int open_verbose)
|
|
{
|
|
{
|
|
UNUSED_PARAM(open_verbose);
|
|
UNUSED_PARAM(open_verbose);
|
|
- ufile_error retError;
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
CosConfig config(cfg.appid, cfg.public_key, cfg.private_key, cfg.region);
|
|
CosConfig config(cfg.appid, cfg.public_key, cfg.private_key, cfg.region);
|
|
g_config = config;
|
|
g_config = config;
|
|
|
|
+ g_strBucketName = cfg.bucket_host;
|
|
retError.bIsSuccess = true;
|
|
retError.bIsSuccess = true;
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
@@ -98,27 +98,28 @@ void ufile_free_file_info(ufile_file_info info)
|
|
|
|
|
|
ufile_error ufile_put_buf(const char * bucket_name, const char * key, const char * mime_type, char * buffer, size_t buf_len)
|
|
ufile_error ufile_put_buf(const char * bucket_name, const char * key, const char * mime_type, char * buffer, size_t buf_len)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
-
|
|
|
|
|
|
+ //此函数无调用,暂且不实现
|
|
return ufile_error();
|
|
return ufile_error();
|
|
}
|
|
}
|
|
|
|
|
|
ufile_error ufile_put_file(const char * bucket_name, const char * key, const char * mime_type, FILE * file)
|
|
ufile_error ufile_put_file(const char * bucket_name, const char * key, const char * mime_type, FILE * file)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
-
|
|
|
|
|
|
+ //此函数无调用,暂且不实现
|
|
return ufile_error();
|
|
return ufile_error();
|
|
}
|
|
}
|
|
|
|
|
|
ufile_error ufile_put_file_by_filepath(const char * bucket_name, const char * key, const char * mime_type, const char * file_path)
|
|
ufile_error ufile_put_file_by_filepath(const char * bucket_name, const char * key, const char * mime_type, const char * file_path)
|
|
{
|
|
{
|
|
UNUSED_PARAM(mime_type);
|
|
UNUSED_PARAM(mime_type);
|
|
- ufile_error retError;
|
|
|
|
- qcloud_cos::PutObjectByFileReq req(bucket_name, key, file_path);
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
|
|
+ std::string strBucketName = bucket_name;
|
|
|
|
+ if (strBucketName.empty())
|
|
|
|
+ strBucketName = g_strBucketName;
|
|
|
|
+ qcloud_cos::PutObjectByFileReq req(strBucketName, key, file_path);
|
|
qcloud_cos::PutObjectByFileResp resp;
|
|
qcloud_cos::PutObjectByFileResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.PutObject(req, &resp);
|
|
CosResult result = cosApi.PutObject(req, &resp);
|
|
- result2ufileError(retError, result);
|
|
|
|
|
|
+ result2ufileError(retError, &result);
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -128,12 +129,15 @@ void set_upload_company(int company)
|
|
|
|
|
|
ufile_error ufile_delete(const char * bucket_name, const char * key)
|
|
ufile_error ufile_delete(const char * bucket_name, const char * key)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
- qcloud_cos::DeleteObjectReq req(bucket_name, key);
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
|
|
+ std::string strBucketName = bucket_name;
|
|
|
|
+ if (strBucketName.empty())
|
|
|
|
+ strBucketName = g_strBucketName;
|
|
|
|
+ qcloud_cos::DeleteObjectReq req(strBucketName, key);
|
|
qcloud_cos::DeleteObjectResp resp;
|
|
qcloud_cos::DeleteObjectResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.DeleteObject(req, &resp);
|
|
CosResult result = cosApi.DeleteObject(req, &resp);
|
|
- result2ufileError(retError, result);
|
|
|
|
|
|
+ result2ufileError(retError, &result);
|
|
return ufile_error();
|
|
return ufile_error();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -163,14 +167,17 @@ ufile_error ufile_multiple_upload_abort(ufile_mutipart_state * self)
|
|
|
|
|
|
ufile_error ufile_download(const char * bucket_name, const char * key, FILE * file, size_t * return_size, const char * path)
|
|
ufile_error ufile_download(const char * bucket_name, const char * key, FILE * file, size_t * return_size, const char * path)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
if (nullptr == file)
|
|
if (nullptr == file)
|
|
{
|
|
{
|
|
- retError.errorMessage = "file is nullptr";
|
|
|
|
|
|
+ strncpy_s(retError.errorMessage, "file is nullptr", sizeof(retError.errorMessage));
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
std::ostringstream os;
|
|
std::ostringstream os;
|
|
- qcloud_cos::GetObjectByStreamReq req(bucket_name, key, os);
|
|
|
|
|
|
+ std::string strBucketName = bucket_name;
|
|
|
|
+ if (strBucketName.empty())
|
|
|
|
+ strBucketName = g_strBucketName;
|
|
|
|
+ qcloud_cos::GetObjectByStreamReq req(strBucketName, key, os);
|
|
qcloud_cos::GetObjectByStreamResp resp;
|
|
qcloud_cos::GetObjectByStreamResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.GetObject(req, &resp);
|
|
CosResult result = cosApi.GetObject(req, &resp);
|
|
@@ -179,7 +186,7 @@ ufile_error ufile_download(const char * bucket_name, const char * key, FILE * fi
|
|
const char * tBuf = os.str().c_str();
|
|
const char * tBuf = os.str().c_str();
|
|
fwrite(tBuf, sizeof(tBuf), strlen(tBuf), file);
|
|
fwrite(tBuf, sizeof(tBuf), strlen(tBuf), file);
|
|
}
|
|
}
|
|
- result2ufileError(retError, result);
|
|
|
|
|
|
+ result2ufileError(retError, &result);
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,12 +204,14 @@ ufile_error ufile_bucket_create(const char * bucket_name, const char * region, c
|
|
|
|
|
|
ufile_error ufile_bucket_delete(const char * bucket_name)
|
|
ufile_error ufile_bucket_delete(const char * bucket_name)
|
|
{
|
|
{
|
|
- ufile_error retError;
|
|
|
|
- qcloud_cos::DeleteBucketReq req(bucket_name);
|
|
|
|
|
|
+ ufile_error retError = { false, 0, "", "", "", "", "" };
|
|
|
|
+ std::string strBucketName = bucket_name;
|
|
|
|
+ if (strBucketName.empty())
|
|
|
|
+ strBucketName = g_strBucketName;
|
|
|
|
+ qcloud_cos::DeleteBucketReq req(strBucketName);
|
|
qcloud_cos::DeleteBucketResp resp;
|
|
qcloud_cos::DeleteBucketResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.DeleteBucket(req, &resp);
|
|
CosResult result = cosApi.DeleteBucket(req, &resp);
|
|
- result2ufileError(retError, result);
|
|
|
|
|
|
+ result2ufileError(retError, &result);
|
|
return ufile_error();
|
|
return ufile_error();
|
|
}
|
|
}
|
|
-
|
|
|