void cg_upnpav_content_copy(CgUpnpAvContent* destContent, CgUpnpAvContent* srcContent) { CgXmlAttribute* attr; CgUpnpAvContent* destNode; CgUpnpAvContent* srcNode; cg_xml_node_setname(destContent, cg_xml_node_getname(srcContent)); cg_xml_node_setvalue(destContent, cg_xml_node_getvalue(srcContent)); for (attr = cg_xml_node_getattributes(srcContent); attr; attr = cg_xml_attribute_next(attr)) cg_xml_node_setattribute(destContent, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr)); for (srcNode = cg_xml_node_getchildnodes(srcContent); srcNode; srcNode = cg_xml_node_next(srcNode)) { if (cg_upnpav_content_gettype(srcNode) != CG_UPNPAV_CONTENT_NONE) continue; if (cg_streq(cg_xml_node_getname(srcNode), CG_UPNPAV_RESOURCE_NAME)) { destNode = cg_upnpav_resource_new(); cg_upnpav_resource_copy(destNode, srcNode); } else { destNode = cg_upnpav_content_new(); cg_xml_node_setname(destNode, cg_xml_node_getname(srcNode)); cg_xml_node_setvalue(destNode, cg_xml_node_getvalue(srcNode)); for (attr = cg_xml_node_getattributes(srcNode); attr; attr = cg_xml_attribute_next(attr)) cg_xml_node_setattribute(destNode, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr)); } cg_xml_node_addchildnode(destContent, destNode); } }
void cg_xml_node_copy(CgXmlNode *dstNode, CgXmlNode *srcNode) { CgXmlAttribute *attr; CgXmlNode *dstChildNode; CgXmlNode *srcChildNode; cg_log_debug_l4("Entering...\n"); if (!dstNode || !srcNode) return; cg_xml_node_setname(dstNode, cg_xml_node_getname(srcNode)); cg_xml_node_setvalue(dstNode, cg_xml_node_getvalue(srcNode)); for (attr = cg_xml_node_getattributes(srcNode); attr != NULL; attr = cg_xml_attribute_next(attr)) cg_xml_node_setattribute(dstNode, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr)); for (srcChildNode = cg_xml_node_getchildnodes(srcNode); srcChildNode != NULL; srcChildNode = cg_xml_node_next(srcChildNode)) { dstChildNode = cg_xml_node_new(); cg_xml_node_copy(dstChildNode, srcChildNode); cg_xml_node_addchildnode(dstNode, dstChildNode); } cg_log_debug_l4("Leaving...\n"); }
void cg_upnpav_resource_copy(CgUpnpAvResource *destRes, CgUpnpAvResource *srcRes) { CgXmlAttribute *attr; cg_xml_node_setname(destRes, cg_xml_node_getname(srcRes)); cg_xml_node_setvalue(destRes, cg_xml_node_getvalue(srcRes)); for (attr=cg_xml_node_getattributes(srcRes); attr; attr=cg_xml_attribute_next(attr)) cg_xml_node_setattribute(destRes, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr)); cg_upnpav_resource_data_copy((CgUpnpAvResourceData *)cg_xml_node_getuserdata(destRes), (CgUpnpAvResourceData *)cg_xml_node_getuserdata(srcRes)); }
static char *cg_xml_node_attribute_tostring(CgXmlNode *node, CgString *str) { CgXmlAttribute *attr; char *name; char *value; CgString *valueStr; cg_log_debug_l4("Entering...\n"); valueStr = cg_string_new(); if (valueStr == NULL) return NULL; for (attr = cg_xml_node_getattributes(node); attr != NULL; attr = cg_xml_attribute_next(attr)) { name = cg_xml_attribute_getname(attr); value = cg_xml_attribute_getvalue(attr); cg_string_setvalue(valueStr, value); cg_xml_escapechars(valueStr); /* All the following functions return NULL only when memory allocation fails, so we can check them all */ if (!cg_string_naddvalue(str, " ", 1) || !cg_string_addvalue(str, name) || !cg_string_naddvalue(str, "=\"", 2) || !cg_string_addvalue(str, cg_string_getvalue(valueStr)) || !cg_string_naddvalue(str, "\"", 1)) { /* Memory allocation failed */ cg_string_delete(valueStr); return NULL; } } cg_string_delete(valueStr); cg_log_debug_l4("Leaving...\n"); return cg_string_getvalue(str); }
CgXmlNode *cg_soap_request_getbodynode(CgSoapRequest *soapReq) { CgXmlNode *envNode; CgXmlNode *bodyNode = NULL; CgXmlAttribute *attr; char *name; CgStringTokenizer *tok; char *nsPrefix; size_t bodyLen; char *body; cg_log_debug_l4("Entering...\n"); envNode = cg_soap_request_getenvelopenode(soapReq); if (envNode == NULL) return NULL; if (cg_xml_node_haschildnodes(envNode) == FALSE) return NULL; /* We cannot assume the namespace prefix for Body is 's'. According to spec, it could be anything... */ for (attr = cg_xml_node_getattributes(envNode); attr != NULL; attr = cg_xml_attribute_next(attr)) { /* First, find the namespace declaration attribute. */ /* Note: We must take a copy of the attr name. Tokenizer doesn't do it (by default) */ name = cg_strdup( cg_xml_attribute_getname(attr) ); tok = cg_string_tokenizer_new(name, ":"); nsPrefix = cg_string_tokenizer_nexttoken(tok); if ( -1 != cg_strstr(nsPrefix, "xmlns")) { /* This attribute is a namespace declaration. Check is it the one defined for SOAP. */ if (cg_strcmp(cg_xml_attribute_getvalue(attr), CG_SOAP_XMLNS_URL) == 0) { /* This namespace declaration is correct. Use it to find the body node... */ if (cg_string_tokenizer_hasmoretoken(tok)) { /* There is a prefix */ nsPrefix = cg_string_tokenizer_nexttoken(tok); bodyLen = cg_strlen(nsPrefix) + cg_strlen(CG_SOAP_DELIM) + cg_strlen(CG_SOAP_BODY) + 1; /* +1 for trailing '\0'*/ body = (char*)malloc(bodyLen); if ( NULL == body ) { cg_log_debug_s("Memory allocation failure!\n"); return NULL; } #if defined(HAVE_SNPRINTF) snprintf(body, bodyLen, "%s%s%s", nsPrefix, CG_SOAP_DELIM, CG_SOAP_BODY); #else sprintf(body, "%s%s%s", nsPrefix, CG_SOAP_DELIM, CG_SOAP_BODY); #endif bodyNode = cg_xml_node_getchildnode(envNode, body); free(body); } else { /* No prefix */ bodyNode = cg_xml_node_getchildnode(envNode, CG_SOAP_BODY); } /* Free memory before leaving the loop */ cg_string_tokenizer_delete(tok); free(name); break; } } cg_string_tokenizer_delete(tok); free(name); } cg_log_debug_l4("Leaving...\n"); return bodyNode; }