创建
This commit is contained in:
73
cache/tango_cache_xml.cpp
vendored
Normal file
73
cache/tango_cache_xml.cpp
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include "tango_cache_xml.h"
|
||||
|
||||
bool parse_uploadID_xml(const char *content, int len, char **uploadID)
|
||||
{
|
||||
xmlDoc *pdoc;
|
||||
xmlNode *pcur;
|
||||
|
||||
if((pdoc = xmlParseMemory(content, len)) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if((pcur = xmlDocGetRootElement(pdoc)) == NULL)
|
||||
{
|
||||
xmlFreeDoc(pdoc);
|
||||
return false;
|
||||
}
|
||||
|
||||
while(pcur->type != XML_ELEMENT_NODE)
|
||||
pcur = pcur->next;
|
||||
if(xmlStrcmp(pcur->name, (const xmlChar *)"InitiateMultipartUploadResult"))
|
||||
{
|
||||
xmlFreeDoc(pdoc);
|
||||
return false;
|
||||
}
|
||||
pcur = pcur->children;
|
||||
while(pcur != NULL)
|
||||
{
|
||||
if(pcur->type != XML_ELEMENT_NODE || xmlStrcmp(pcur->name, (const xmlChar *)"UploadId"))
|
||||
{
|
||||
pcur = pcur->next;
|
||||
continue;
|
||||
}
|
||||
*uploadID = (char *)xmlNodeGetContent(pcur);
|
||||
xmlFreeDoc(pdoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlFreeDoc(pdoc);
|
||||
return false;
|
||||
}
|
||||
|
||||
int construct_complete_xml(struct tango_cache_ctx *ctx, char **xml, int *len)
|
||||
{
|
||||
struct buffer_cache_list *list;
|
||||
xmlDoc *pdoc;
|
||||
xmlNode *root, *child;
|
||||
char number[20];
|
||||
|
||||
pdoc = xmlNewDoc((const xmlChar *)"1.0");
|
||||
root = xmlNewNode(NULL, (const xmlChar *)"CompleteMultipartUpload");
|
||||
xmlNewProp(root, (const xmlChar *)"xmlns",(const xmlChar *)"http://s3.amazonaws.com/doc/2006-03-01/");
|
||||
xmlDocSetRootElement(pdoc, root);
|
||||
|
||||
TAILQ_FOREACH(list, &ctx->cache_head, node)
|
||||
{
|
||||
sprintf(number, "%u", list->part_number);
|
||||
child = xmlNewChild(root, NULL, (const xmlChar*)"Part", NULL);
|
||||
xmlNewChild(child, NULL, (const xmlChar*)"ETag", (const xmlChar*)list->etag);
|
||||
xmlNewChild(child, NULL, (const xmlChar*)"PartNumber", (const xmlChar*)number);
|
||||
}
|
||||
|
||||
xmlDocDumpFormatMemory(pdoc, (xmlChar **)xml, len, 1);
|
||||
xmlFreeDoc(pdoc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user