in src/s3fs_xml.cpp [340:459]
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, const char* ex_size, const char* ex_last_modified, int isCPrefix, S3ObjList& head)
{
xmlXPathObjectPtr contents_xp;
xmlNodeSetPtr content_nodes;
if(NULL == (contents_xp = xmlXPathEvalExpression((xmlChar*)ex_contents, ctx))){
S3FS_PRN_ERR("xmlXPathEvalExpression returns null.");
return -1;
}
if(xmlXPathNodeSetIsEmpty(contents_xp->nodesetval)){
S3FS_PRN_DBG("contents_xp->nodesetval is empty.");
S3FS_XMLXPATHFREEOBJECT(contents_xp);
return 0;
}
content_nodes = contents_xp->nodesetval;
bool is_dir;
std::string stretag;
std::string strsize;
std::string strlastmodified;
int i;
for(i = 0; i < content_nodes->nodeNr; i++){
ctx->node = content_nodes->nodeTab[i];
// object name
xmlXPathObjectPtr key;
if(NULL == (key = xmlXPathEvalExpression((xmlChar*)ex_key, ctx))){
S3FS_PRN_WARN("key is null. but continue.");
continue;
}
if(xmlXPathNodeSetIsEmpty(key->nodesetval)){
S3FS_PRN_WARN("node is empty. but continue.");
xmlXPathFreeObject(key);
continue;
}
xmlNodeSetPtr key_nodes = key->nodesetval;
char* name = get_object_name(doc, key_nodes->nodeTab[0]->xmlChildrenNode, path);
if(!name){
S3FS_PRN_WARN("name is something wrong. but continue.");
}else if((const char*)name != c_strErrorObjectName){
is_dir = isCPrefix ? true : false;
stretag = "";
strsize = "";
strlastmodified = "";
if(!isCPrefix){
// Get ETag
if (ex_etag) {
xmlXPathObjectPtr ETag;
if(NULL != (ETag = xmlXPathEvalExpression((xmlChar*)ex_etag, ctx))){
if(xmlXPathNodeSetIsEmpty(ETag->nodesetval)){
S3FS_PRN_INFO("ETag->nodesetval is empty.");
}else{
xmlNodeSetPtr etag_nodes = ETag->nodesetval;
xmlChar* petag = xmlNodeListGetString(doc, etag_nodes->nodeTab[0]->xmlChildrenNode, 1);
if(petag){
stretag = (char*)petag;
xmlFree(petag);
}
}
xmlXPathFreeObject(ETag);
}
}
// Get Size
if (ex_size) {
xmlXPathObjectPtr Size;
if(NULL != (Size = xmlXPathEvalExpression((xmlChar*)ex_size, ctx))){
if(xmlXPathNodeSetIsEmpty(Size->nodesetval)){
S3FS_PRN_INFO("Size->nodesetval is empty.");
}else{
xmlNodeSetPtr size_nodes = Size->nodesetval;
xmlChar* psize = xmlNodeListGetString(doc, size_nodes->nodeTab[0]->xmlChildrenNode, 1);
if(psize){
strsize = (char*)psize;
xmlFree(psize);
}
}
xmlXPathFreeObject(Size);
}
}
// Get Last Modified
if (ex_last_modified) {
xmlXPathObjectPtr LastModified;
if(NULL != (LastModified = xmlXPathEvalExpression((xmlChar*)ex_last_modified, ctx))){
if(xmlXPathNodeSetIsEmpty(LastModified->nodesetval)){
S3FS_PRN_INFO("LastModified->nodesetval is empty.");
}else{
xmlNodeSetPtr last_modified_nodes = LastModified->nodesetval;
xmlChar* plastmodified = xmlNodeListGetString(doc, last_modified_nodes->nodeTab[0]->xmlChildrenNode, 1);
if(plastmodified){
strlastmodified = (char*)plastmodified;
xmlFree(plastmodified);
}
}
xmlXPathFreeObject(LastModified);
}
}
}
if(!head.insert(name, (!stretag.empty() ? stretag.c_str() : NULL), is_dir, (!strsize.empty() ? strsize.c_str() : NULL), (!strlastmodified.empty() ? strlastmodified.c_str() : NULL))){
S3FS_PRN_ERR("insert_object returns with error.");
xmlXPathFreeObject(key);
xmlXPathFreeObject(contents_xp);
free(name);
S3FS_MALLOCTRIM(0);
return -1;
}
free(name);
}else{
S3FS_PRN_DBG("name is file or subdir in dir. but continue.");
}
xmlXPathFreeObject(key);
}
S3FS_XMLXPATHFREEOBJECT(contents_xp);
return 0;
}