【1】修复HTTP Expect头部缺失时POST卡顿的问题;
【2】TODO:尝试增加multiple delete objects API,尚未成功(AccessDenied);
This commit is contained in:
102
cache/tango_cache_xml.cpp
vendored
102
cache/tango_cache_xml.cpp
vendored
@@ -46,7 +46,7 @@ bool parse_uploadID_xml(const char *content, int len, char **uploadID)
|
||||
return false;
|
||||
}
|
||||
|
||||
int construct_complete_xml(struct tango_cache_ctx *ctx, char **xml, int *len)
|
||||
void construct_complete_xml(struct tango_cache_ctx *ctx, char **xml, int *len)
|
||||
{
|
||||
struct multipart_etag_list *etag;
|
||||
xmlDoc *pdoc;
|
||||
@@ -68,6 +68,104 @@ int construct_complete_xml(struct tango_cache_ctx *ctx, char **xml, int *len)
|
||||
|
||||
xmlDocDumpFormatMemory(pdoc, (xmlChar **)xml, len, 1);
|
||||
xmlFreeDoc(pdoc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fill_multidelete_xml_errcode(xmlNode *error, char *out, int size)
|
||||
{
|
||||
xmlChar *errcode;
|
||||
xmlNode *child = error->children;
|
||||
|
||||
while(child != NULL)
|
||||
{
|
||||
if(child->type != XML_ELEMENT_NODE || xmlStrcmp(child->name, (const xmlChar *)"Message"))
|
||||
{
|
||||
child = child->next;
|
||||
continue;
|
||||
}
|
||||
errcode = xmlNodeGetContent(child);
|
||||
snprintf(out, size, "%s", (char *)errcode);
|
||||
xmlFree(errcode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool parse_multidelete_xml(const char *xml, int len, u_int32_t *errnum, char *errstr, int size)
|
||||
{
|
||||
xmlDoc *pdoc;
|
||||
xmlNode *pcur;
|
||||
int errornum=0;
|
||||
|
||||
if((pdoc = xmlParseMemory(xml, 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 *)"DeleteResult"))
|
||||
{
|
||||
xmlFreeDoc(pdoc);
|
||||
return false;
|
||||
}
|
||||
pcur = pcur->children;
|
||||
while(pcur != NULL)
|
||||
{
|
||||
if(pcur->type != XML_ELEMENT_NODE || xmlStrcmp(pcur->name, (const xmlChar *)"Error"))
|
||||
{
|
||||
pcur = pcur->next;
|
||||
continue;
|
||||
}
|
||||
if(errornum == 0)
|
||||
{
|
||||
fill_multidelete_xml_errcode(pcur, errstr, size);
|
||||
}
|
||||
errornum++;
|
||||
pcur = pcur->next;
|
||||
}
|
||||
*errnum = errornum;
|
||||
|
||||
xmlFreeDoc(pdoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
void construct_multiple_delete_xml(const char *bucket, char *key[], u_int32_t num, int is_hash, char **xml, size_t *len)
|
||||
{
|
||||
xmlDoc *pdoc;
|
||||
xmlNode *root, *child;
|
||||
int xmllen;
|
||||
|
||||
pdoc = xmlNewDoc((const xmlChar *)"1.0");
|
||||
root = xmlNewNode(NULL, (const xmlChar *)"Delete");
|
||||
xmlDocSetRootElement(pdoc, root);
|
||||
|
||||
xmlNewChild(root, NULL, (const xmlChar*)"Quiet", (const xmlChar*)"true");
|
||||
|
||||
if(is_hash)
|
||||
{
|
||||
char hashkey[72], sha256[72];
|
||||
for(u_int32_t i=0; i<num; i++)
|
||||
{
|
||||
child = xmlNewChild(root, NULL, (const xmlChar*)"Object", NULL);
|
||||
caculate_sha256(key[i], strlen(key[i]), sha256, 72);
|
||||
snprintf(hashkey, 256, "%c%c/%c%c/%s", sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
|
||||
xmlNewChild(child, NULL, (const xmlChar*)"Key", (const xmlChar*)hashkey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(u_int32_t i=0; i<num; i++)
|
||||
{
|
||||
child = xmlNewChild(root, NULL, (const xmlChar*)"Object", NULL);
|
||||
xmlNewChild(child, NULL, (const xmlChar*)"Key", (const xmlChar*)key[i]);
|
||||
}
|
||||
}
|
||||
xmlDocDumpFormatMemoryEnc(pdoc, (xmlChar **)xml, &xmllen, "UTF-8", 1);
|
||||
xmlFreeDoc(pdoc);
|
||||
*len = xmllen;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user