Use std::unique_ptr in libxml functions (#2317)

References #2261.
This commit is contained in:
Andrew Gaul 2023-09-25 23:46:52 +09:00 committed by GitHub
parent cbc33cd7ae
commit c5fb42ff10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 105 deletions

View File

@ -3509,13 +3509,11 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
return -EIO; return -EIO;
} }
if(true == (truncated = is_truncated(doc))){ if(true == (truncated = is_truncated(doc))){
xmlChar* tmpch; auto tmpch = get_next_continuation_token(doc);
if(nullptr != (tmpch = get_next_continuation_token(doc))){ if(nullptr != tmpch){
next_continuation_token = reinterpret_cast<char*>(tmpch); next_continuation_token = reinterpret_cast<const char*>(tmpch.get());
xmlFree(tmpch);
}else if(nullptr != (tmpch = get_next_marker(doc))){ }else if(nullptr != (tmpch = get_next_marker(doc))){
next_marker = reinterpret_cast<char*>(tmpch); next_marker = reinterpret_cast<const char*>(tmpch.get());
xmlFree(tmpch);
} }
if(next_continuation_token.empty() && next_marker.empty()){ if(next_continuation_token.empty() && next_marker.empty()){

View File

@ -86,19 +86,18 @@ static bool GetXmlNsUrl(xmlDocPtr doc, std::string& nsurl)
return result; return result;
} }
static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp) static unique_ptr_xmlChar get_base_exp(xmlDocPtr doc, const char* exp)
{ {
xmlXPathObjectPtr marker_xp;
std::string xmlnsurl; std::string xmlnsurl;
std::string exp_string; std::string exp_string;
if(!doc){ if(!doc){
return nullptr; return {nullptr, xmlFree};
} }
xmlXPathContextPtr ctx = xmlXPathNewContext(doc); unique_ptr_xmlXPathContext ctx(xmlXPathNewContext(doc), xmlXPathFreeContext);
if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){
xmlXPathRegisterNs(ctx, reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str())); xmlXPathRegisterNs(ctx.get(), reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str()));
exp_string = "/s3:ListBucketResult/s3:"; exp_string = "/s3:ListBucketResult/s3:";
} else { } else {
exp_string = "/ListBucketResult/"; exp_string = "/ListBucketResult/";
@ -106,36 +105,31 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp)
exp_string += exp; exp_string += exp;
if(nullptr == (marker_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_string.c_str()), ctx))){ unique_ptr_xmlXPathObject marker_xp(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_string.c_str()), ctx.get()), xmlXPathFreeObject);
xmlXPathFreeContext(ctx); if(nullptr == marker_xp){
return nullptr; return {nullptr, xmlFree};
} }
if(xmlXPathNodeSetIsEmpty(marker_xp->nodesetval)){ if(xmlXPathNodeSetIsEmpty(marker_xp->nodesetval)){
S3FS_PRN_ERR("marker_xp->nodesetval is empty."); S3FS_PRN_ERR("marker_xp->nodesetval is empty.");
xmlXPathFreeObject(marker_xp); return {nullptr, xmlFree};
xmlXPathFreeContext(ctx);
return nullptr;
} }
xmlNodeSetPtr nodes = marker_xp->nodesetval; xmlNodeSetPtr nodes = marker_xp->nodesetval;
xmlChar* result = xmlNodeListGetString(doc, nodes->nodeTab[0]->xmlChildrenNode, 1);
xmlXPathFreeObject(marker_xp);
xmlXPathFreeContext(ctx);
unique_ptr_xmlChar result(xmlNodeListGetString(doc, nodes->nodeTab[0]->xmlChildrenNode, 1), xmlFree);
return result; return result;
} }
static xmlChar* get_prefix(xmlDocPtr doc) static unique_ptr_xmlChar get_prefix(xmlDocPtr doc)
{ {
return get_base_exp(doc, "Prefix"); return get_base_exp(doc, "Prefix");
} }
xmlChar* get_next_continuation_token(xmlDocPtr doc) unique_ptr_xmlChar get_next_continuation_token(xmlDocPtr doc)
{ {
return get_base_exp(doc, "NextContinuationToken"); return get_base_exp(doc, "NextContinuationToken");
} }
xmlChar* get_next_marker(xmlDocPtr doc) unique_ptr_xmlChar get_next_marker(xmlDocPtr doc)
{ {
return get_base_exp(doc, "NextMarker"); return get_base_exp(doc, "NextMarker");
} }
@ -146,24 +140,22 @@ xmlChar* get_next_marker(xmlDocPtr doc)
static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path) static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
{ {
// Get full path // Get full path
xmlChar* fullpath = xmlNodeListGetString(doc, node, 1); unique_ptr_xmlChar fullpath(xmlNodeListGetString(doc, node, 1), xmlFree);
if(!fullpath){ if(!fullpath){
S3FS_PRN_ERR("could not get object full path name.."); S3FS_PRN_ERR("could not get object full path name..");
return nullptr; return nullptr;
} }
// basepath(path) is as same as fullpath. // basepath(path) is as same as fullpath.
if(0 == strcmp(reinterpret_cast<char*>(fullpath), path)){ if(0 == strcmp(reinterpret_cast<char*>(fullpath.get()), path)){
xmlFree(fullpath);
return const_cast<char*>(c_strErrorObjectName); return const_cast<char*>(c_strErrorObjectName);
} }
// Make dir path and filename // Make dir path and filename
std::string strdirpath = mydirname(reinterpret_cast<const char*>(fullpath)); std::string strdirpath = mydirname(reinterpret_cast<const char*>(fullpath.get()));
std::string strmybpath = mybasename(reinterpret_cast<const char*>(fullpath)); std::string strmybpath = mybasename(reinterpret_cast<const char*>(fullpath.get()));
const char* dirpath = strdirpath.c_str(); const char* dirpath = strdirpath.c_str();
const char* mybname = strmybpath.c_str(); const char* mybname = strmybpath.c_str();
const char* basepath= (path && '/' == path[0]) ? &path[1] : path; const char* basepath= (path && '/' == path[0]) ? &path[1] : path;
xmlFree(fullpath);
if('\0' == mybname[0]){ if('\0' == mybname[0]){
return nullptr; return nullptr;
@ -210,35 +202,32 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
return const_cast<char*>(c_strErrorObjectName); return const_cast<char*>(c_strErrorObjectName);
} }
static xmlChar* get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const char* exp_key) static unique_ptr_xmlChar get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const char* exp_key)
{ {
if(!doc || !ctx || !exp_key){ if(!doc || !ctx || !exp_key){
return nullptr; return {nullptr, xmlFree};
} }
xmlXPathObjectPtr exp;
xmlNodeSetPtr exp_nodes; xmlNodeSetPtr exp_nodes;
xmlChar* exp_value;
// search exp_key tag // search exp_key tag
if(nullptr == (exp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_key), ctx))){ unique_ptr_xmlXPathObject exp(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_key), ctx), xmlXPathFreeObject);
if(nullptr == exp){
S3FS_PRN_ERR("Could not find key(%s).", exp_key); S3FS_PRN_ERR("Could not find key(%s).", exp_key);
return nullptr; return {nullptr, xmlFree};
} }
if(xmlXPathNodeSetIsEmpty(exp->nodesetval)){ if(xmlXPathNodeSetIsEmpty(exp->nodesetval)){
S3FS_PRN_ERR("Key(%s) node is empty.", exp_key); S3FS_PRN_ERR("Key(%s) node is empty.", exp_key);
S3FS_XMLXPATHFREEOBJECT(exp); return {nullptr, xmlFree};
return nullptr;
} }
// get exp_key value & set in struct // get exp_key value & set in struct
exp_nodes = exp->nodesetval; exp_nodes = exp->nodesetval;
if(nullptr == (exp_value = xmlNodeListGetString(doc, exp_nodes->nodeTab[0]->xmlChildrenNode, 1))){ unique_ptr_xmlChar exp_value(xmlNodeListGetString(doc, exp_nodes->nodeTab[0]->xmlChildrenNode, 1), xmlFree);
if(nullptr == exp_value){
S3FS_PRN_ERR("Key(%s) value is empty.", exp_key); S3FS_PRN_ERR("Key(%s) value is empty.", exp_key);
S3FS_XMLXPATHFREEOBJECT(exp); return {nullptr, xmlFree};
return nullptr;
} }
S3FS_XMLXPATHFREEOBJECT(exp);
return exp_value; return exp_value;
} }
@ -248,7 +237,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
return false; return false;
} }
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);; unique_ptr_xmlXPathContext ctx(xmlXPathNewContext(doc), xmlXPathFreeContext);
std::string xmlnsurl; std::string xmlnsurl;
std::string ex_upload = "//"; std::string ex_upload = "//";
@ -257,7 +246,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
std::string ex_date; std::string ex_date;
if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){
xmlXPathRegisterNs(ctx, reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str())); xmlXPathRegisterNs(ctx.get(), reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str()));
ex_upload += "s3:"; ex_upload += "s3:";
ex_key += "s3:"; ex_key += "s3:";
ex_id += "s3:"; ex_id += "s3:";
@ -269,15 +258,13 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
ex_date += "Initiated"; ex_date += "Initiated";
// get "Upload" Tags // get "Upload" Tags
xmlXPathObjectPtr upload_xp; unique_ptr_xmlXPathObject upload_xp(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_upload.c_str()), ctx.get()), xmlXPathFreeObject);
if(nullptr == (upload_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_upload.c_str()), ctx))){ if(nullptr == upload_xp){
S3FS_PRN_ERR("xmlXPathEvalExpression returns null."); S3FS_PRN_ERR("xmlXPathEvalExpression returns null.");
return false; return false;
} }
if(xmlXPathNodeSetIsEmpty(upload_xp->nodesetval)){ if(xmlXPathNodeSetIsEmpty(upload_xp->nodesetval)){
S3FS_PRN_INFO("upload_xp->nodesetval is empty."); S3FS_PRN_INFO("upload_xp->nodesetval is empty.");
S3FS_XMLXPATHFREEOBJECT(upload_xp);
S3FS_XMLXPATHFREECONTEXT(ctx);
return true; return true;
} }
@ -289,70 +276,57 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
ctx->node = upload_nodes->nodeTab[cnt]; ctx->node = upload_nodes->nodeTab[cnt];
INCOMP_MPU_INFO part; INCOMP_MPU_INFO part;
xmlChar* ex_value;
// search "Key" tag // search "Key" tag
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_key.c_str()))){ unique_ptr_xmlChar ex_value(get_exp_value_xml(doc, ctx.get(), ex_key.c_str()));
if(nullptr == ex_value){
continue; continue;
} }
if('/' != *(reinterpret_cast<char*>(ex_value))){ if('/' != *(reinterpret_cast<char*>(ex_value.get()))){
part.key = "/"; part.key = "/";
}else{ }else{
part.key = ""; part.key = "";
} }
part.key += reinterpret_cast<char*>(ex_value); part.key += reinterpret_cast<char*>(ex_value.get());
S3FS_XMLFREE(ex_value);
// search "UploadId" tag // search "UploadId" tag
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_id.c_str()))){ if(nullptr == (ex_value = get_exp_value_xml(doc, ctx.get(), ex_id.c_str()))){
continue; continue;
} }
part.id = reinterpret_cast<char*>(ex_value); part.id = reinterpret_cast<char*>(ex_value.get());
S3FS_XMLFREE(ex_value);
// search "Initiated" tag // search "Initiated" tag
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_date.c_str()))){ if(nullptr == (ex_value = get_exp_value_xml(doc, ctx.get(), ex_date.c_str()))){
continue; continue;
} }
part.date = reinterpret_cast<char*>(ex_value); part.date = reinterpret_cast<char*>(ex_value.get());
S3FS_XMLFREE(ex_value);
list.push_back(part); list.push_back(part);
} }
S3FS_XMLXPATHFREEOBJECT(upload_xp);
S3FS_XMLXPATHFREECONTEXT(ctx);
return true; return true;
} }
bool is_truncated(xmlDocPtr doc) bool is_truncated(xmlDocPtr doc)
{ {
bool result = false; unique_ptr_xmlChar strTruncate(get_base_exp(doc, "IsTruncated"));
xmlChar* strTruncate = get_base_exp(doc, "IsTruncated");
if(!strTruncate){ if(!strTruncate){
return false; return false;
} }
if(0 == strcasecmp(reinterpret_cast<const char*>(strTruncate), "true")){ return 0 == strcasecmp(reinterpret_cast<const char*>(strTruncate.get()), "true");
result = true;
}
xmlFree(strTruncate);
return result;
} }
int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextPtr ctx, const char* ex_contents, const char* ex_key, const char* ex_etag, int isCPrefix, S3ObjList& head, bool prefix) int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextPtr ctx, const char* ex_contents, const char* ex_key, const char* ex_etag, int isCPrefix, S3ObjList& head, bool prefix)
{ {
xmlXPathObjectPtr contents_xp;
xmlNodeSetPtr content_nodes; xmlNodeSetPtr content_nodes;
if(nullptr == (contents_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_contents), ctx))){ unique_ptr_xmlXPathObject contents_xp(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_contents), ctx), xmlXPathFreeObject);
if(nullptr == contents_xp){
S3FS_PRN_ERR("xmlXPathEvalExpression returns null."); S3FS_PRN_ERR("xmlXPathEvalExpression returns null.");
return -1; return -1;
} }
if(xmlXPathNodeSetIsEmpty(contents_xp->nodesetval)){ if(xmlXPathNodeSetIsEmpty(contents_xp->nodesetval)){
S3FS_PRN_DBG("contents_xp->nodesetval is empty."); S3FS_PRN_DBG("contents_xp->nodesetval is empty.");
S3FS_XMLXPATHFREEOBJECT(contents_xp);
return 0; return 0;
} }
content_nodes = contents_xp->nodesetval; content_nodes = contents_xp->nodesetval;
@ -364,14 +338,13 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
ctx->node = content_nodes->nodeTab[i]; ctx->node = content_nodes->nodeTab[i];
// object name // object name
xmlXPathObjectPtr key; unique_ptr_xmlXPathObject key(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_key), ctx), xmlXPathFreeObject);
if(nullptr == (key = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_key), ctx))){ if(nullptr == key){
S3FS_PRN_WARN("key is null. but continue."); S3FS_PRN_WARN("key is null. but continue.");
continue; continue;
} }
if(xmlXPathNodeSetIsEmpty(key->nodesetval)){ if(xmlXPathNodeSetIsEmpty(key->nodesetval)){
S3FS_PRN_WARN("node is empty. but continue."); S3FS_PRN_WARN("node is empty. but continue.");
xmlXPathFreeObject(key);
continue; continue;
} }
xmlNodeSetPtr key_nodes = key->nodesetval; xmlNodeSetPtr key_nodes = key->nodesetval;
@ -386,19 +359,17 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
if(!isCPrefix && ex_etag){ if(!isCPrefix && ex_etag){
// Get ETag // Get ETag
xmlXPathObjectPtr ETag; unique_ptr_xmlXPathObject ETag(xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_etag), ctx), xmlXPathFreeObject);
if(nullptr != (ETag = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_etag), ctx))){ if(nullptr != ETag){
if(xmlXPathNodeSetIsEmpty(ETag->nodesetval)){ if(xmlXPathNodeSetIsEmpty(ETag->nodesetval)){
S3FS_PRN_INFO("ETag->nodesetval is empty."); S3FS_PRN_INFO("ETag->nodesetval is empty.");
}else{ }else{
xmlNodeSetPtr etag_nodes = ETag->nodesetval; xmlNodeSetPtr etag_nodes = ETag->nodesetval;
xmlChar* petag = xmlNodeListGetString(doc, etag_nodes->nodeTab[0]->xmlChildrenNode, 1); unique_ptr_xmlChar petag(xmlNodeListGetString(doc, etag_nodes->nodeTab[0]->xmlChildrenNode, 1), xmlFree);
if(petag){ if(petag){
stretag = reinterpret_cast<char*>(petag); stretag = reinterpret_cast<const char*>(petag.get());
xmlFree(petag);
} }
} }
xmlXPathFreeObject(ETag);
} }
} }
@ -414,17 +385,12 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
} }
if(!head.insert(decname.c_str(), (!stretag.empty() ? stretag.c_str() : nullptr), is_dir)){ if(!head.insert(decname.c_str(), (!stretag.empty() ? stretag.c_str() : nullptr), is_dir)){
S3FS_PRN_ERR("insert_object returns with error."); S3FS_PRN_ERR("insert_object returns with error.");
xmlXPathFreeObject(key);
xmlXPathFreeObject(contents_xp);
S3FS_MALLOCTRIM(0);
return -1; return -1;
} }
}else{ }else{
S3FS_PRN_DBG("name is file or subdir in dir. but continue."); S3FS_PRN_DBG("name is file or subdir in dir. but continue.");
} }
xmlXPathFreeObject(key);
} }
S3FS_XMLXPATHFREEOBJECT(contents_xp);
return 0; return 0;
} }
@ -443,16 +409,13 @@ int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head)
} }
// If there is not <Prefix>, use path instead of it. // If there is not <Prefix>, use path instead of it.
xmlChar* pprefix = get_prefix(doc); auto pprefix = get_prefix(doc);
std::string prefix = (pprefix ? reinterpret_cast<char*>(pprefix) : path ? path : ""); std::string prefix = (pprefix ? reinterpret_cast<char*>(pprefix.get()) : path ? path : "");
if(pprefix){
xmlFree(pprefix);
}
xmlXPathContextPtr ctx = xmlXPathNewContext(doc); unique_ptr_xmlXPathContext ctx(xmlXPathNewContext(doc), xmlXPathFreeContext);
if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){
xmlXPathRegisterNs(ctx, reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str())); xmlXPathRegisterNs(ctx.get(), reinterpret_cast<const xmlChar*>("s3"), reinterpret_cast<const xmlChar*>(xmlnsurl.c_str()));
ex_contents+= "s3:"; ex_contents+= "s3:";
ex_key += "s3:"; ex_key += "s3:";
ex_cprefix += "s3:"; ex_cprefix += "s3:";
@ -465,14 +428,12 @@ int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head)
ex_prefix += "Prefix"; ex_prefix += "Prefix";
ex_etag += "ETag"; ex_etag += "ETag";
if(-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_contents.c_str(), ex_key.c_str(), ex_etag.c_str(), 0, head, /*prefix=*/ false) || if(-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx.get(), ex_contents.c_str(), ex_key.c_str(), ex_etag.c_str(), 0, head, /*prefix=*/ false) ||
-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_cprefix.c_str(), ex_prefix.c_str(), nullptr, 1, head, /*prefix=*/ true) ) -1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx.get(), ex_cprefix.c_str(), ex_prefix.c_str(), nullptr, 1, head, /*prefix=*/ true) )
{ {
S3FS_PRN_ERR("append_objects_from_xml_ex returns with error."); S3FS_PRN_ERR("append_objects_from_xml_ex returns with error.");
S3FS_XMLXPATHFREECONTEXT(ctx);
return -1; return -1;
} }
S3FS_XMLXPATHFREECONTEXT(ctx);
return 0; return 0;
} }
@ -489,13 +450,12 @@ bool simple_parse_xml(const char* data, size_t len, const char* key, std::string
} }
value.clear(); value.clear();
xmlDocPtr doc; std::unique_ptr<xmlDoc, decltype(&xmlFreeDoc)> doc(xmlReadMemory(data, static_cast<int>(len), "", nullptr, 0), xmlFreeDoc);
if(nullptr == (doc = xmlReadMemory(data, static_cast<int>(len), "", nullptr, 0))){ if(nullptr == doc){
return false; return false;
} }
if(nullptr == doc->children){ if(nullptr == doc->children){
S3FS_XMLFREEDOC(doc);
return false; return false;
} }
for(xmlNodePtr cur_node = doc->children->children; nullptr != cur_node; cur_node = cur_node->next){ for(xmlNodePtr cur_node = doc->children->children; nullptr != cur_node; cur_node = cur_node->next){
@ -519,7 +479,6 @@ bool simple_parse_xml(const char* data, size_t len, const char* key, std::string
} }
} }
} }
S3FS_XMLFREEDOC(doc);
return result; return result;
} }

View File

@ -22,21 +22,26 @@
#define S3FS_S3FS_XML_H_ #define S3FS_S3FS_XML_H_
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <memory>
#include <string> #include <string>
#include "mpu_util.h" #include "mpu_util.h"
class S3ObjList; class S3ObjList;
typedef std::unique_ptr<xmlChar, decltype(xmlFree)> unique_ptr_xmlChar;
typedef std::unique_ptr<xmlXPathObject, decltype(&xmlXPathFreeObject)> unique_ptr_xmlXPathObject;
typedef std::unique_ptr<xmlXPathContext, decltype(&xmlXPathFreeContext)> unique_ptr_xmlXPathContext;
typedef std::unique_ptr<xmlDoc, decltype(&xmlFreeDoc)> unique_ptr_xmlDoc;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Functions // Functions
//------------------------------------------------------------------- //-------------------------------------------------------------------
bool is_truncated(xmlDocPtr doc); bool is_truncated(xmlDocPtr doc);
int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextPtr ctx, const char* ex_contents, const char* ex_key, const char* ex_etag, int isCPrefix, S3ObjList& head, bool prefix); int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextPtr ctx, const char* ex_contents, const char* ex_key, const char* ex_etag, int isCPrefix, S3ObjList& head, bool prefix);
int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head); int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head);
xmlChar* get_next_continuation_token(xmlDocPtr doc); unique_ptr_xmlChar get_next_continuation_token(xmlDocPtr doc);
xmlChar* get_next_marker(xmlDocPtr doc); unique_ptr_xmlChar get_next_marker(xmlDocPtr doc);
bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list); bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list);
bool simple_parse_xml(const char* data, size_t len, const char* key, std::string& value); bool simple_parse_xml(const char* data, size_t len, const char* key, std::string& value);