void mupnp_xml_node_copy(mUpnpXmlNode *dstNode, mUpnpXmlNode *srcNode) { mUpnpXmlAttribute *attr; mUpnpXmlNode *dstChildNode; mUpnpXmlNode *srcChildNode; mupnp_log_debug_l4("Entering...\n"); if (!dstNode || !srcNode) return; mupnp_xml_node_setname(dstNode, mupnp_xml_node_getname(srcNode)); mupnp_xml_node_setvalue(dstNode, mupnp_xml_node_getvalue(srcNode)); for (attr = mupnp_xml_node_getattributes(srcNode); attr != NULL; attr = mupnp_xml_attribute_next(attr)) mupnp_xml_node_setattribute(dstNode, mupnp_xml_attribute_getname(attr), mupnp_xml_attribute_getvalue(attr)); for (srcChildNode = mupnp_xml_node_getchildnodes(srcNode); srcChildNode != NULL; srcChildNode = mupnp_xml_node_next(srcChildNode)) { dstChildNode = mupnp_xml_node_new(); mupnp_xml_node_copy(dstChildNode, srcChildNode); mupnp_xml_node_addchildnode(dstNode, dstChildNode); } mupnp_log_debug_l4("Leaving...\n"); }
const char* mupnp_xml_attributelist_getvalue(mUpnpXmlAttributeList* attrList, const char* name) { mUpnpXmlAttribute* attr; mupnp_log_debug_l4("Entering...\n"); attr = mupnp_xml_attributelist_get(attrList, name); if (attr == NULL) return NULL; return mupnp_xml_attribute_getvalue(attr); mupnp_log_debug_l4("Leaving...\n"); }
static char *mupnp_xml_node_attribute_tostring(mUpnpXmlNode *node, mUpnpString *str) { mUpnpXmlAttribute *attr; const char *name; const char *value; mUpnpString *valueStr; mupnp_log_debug_l4("Entering...\n"); valueStr = mupnp_string_new(); if (valueStr == NULL) return NULL; for (attr = mupnp_xml_node_getattributes(node); attr != NULL; attr = mupnp_xml_attribute_next(attr)) { name = mupnp_xml_attribute_getname(attr); value = mupnp_xml_attribute_getvalue(attr); mupnp_string_setvalue(valueStr, value); mupnp_xml_escapechars(valueStr); /* All the following functions return NULL only when memory allocation fails, so we can check them all */ if (!mupnp_string_naddvalue(str, " ", 1) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, "=\"", 2) || !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) || !mupnp_string_naddvalue(str, "\"", 1)) { /* Memory allocation failed */ mupnp_string_delete(valueStr); return NULL; } } mupnp_string_delete(valueStr); mupnp_log_debug_l4("Leaving...\n"); return mupnp_string_getvalue(str); }
mUpnpXmlNode *mupnp_soap_request_getbodynode(mUpnpSoapRequest *soapReq) { mUpnpXmlNode *envNode; mUpnpXmlNode *bodyNode = NULL; mUpnpXmlAttribute *attr; char *name; mUpnpStringTokenizer *tok; char *nsPrefix; size_t bodyLen; char *body; mupnp_log_debug_l4("Entering...\n"); envNode = mupnp_soap_request_getenvelopenode(soapReq); if (envNode == NULL) return NULL; if (mupnp_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 = mupnp_xml_node_getattributes(envNode); attr != NULL; attr = mupnp_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 = mupnp_strdup( mupnp_xml_attribute_getname(attr) ); tok = mupnp_string_tokenizer_new(name, ":"); nsPrefix = mupnp_string_tokenizer_nexttoken(tok); if ( -1 != mupnp_strstr(nsPrefix, "xmlns")) { /* This attribute is a namespace declaration. Check is it the one defined for SOAP. */ if (mupnp_strcmp(mupnp_xml_attribute_getvalue(attr), MUPNP_SOAP_XMLNS_URL) == 0) { /* This namespace declaration is correct. Use it to find the body node... */ if (mupnp_string_tokenizer_hasmoretoken(tok)) { /* There is a prefix */ nsPrefix = mupnp_string_tokenizer_nexttoken(tok); bodyLen = mupnp_strlen(nsPrefix) + mupnp_strlen(MUPNP_SOAP_DELIM) + mupnp_strlen(MUPNP_SOAP_BODY) + 1; /* +1 for trailing '\0'*/ body = (char*)malloc(bodyLen); if ( NULL == body ) { mupnp_log_debug_s("Memory allocation failure!\n"); return NULL; } #if defined(HAVE_SNPRINTF) snprintf(body, bodyLen, "%s%s%s", nsPrefix, MUPNP_SOAP_DELIM, MUPNP_SOAP_BODY); #else sprintf(body, "%s%s%s", nsPrefix, MUPNP_SOAP_DELIM, MUPNP_SOAP_BODY); #endif bodyNode = mupnp_xml_node_getchildnode(envNode, body); free(body); } else { /* No prefix */ bodyNode = mupnp_xml_node_getchildnode(envNode, MUPNP_SOAP_BODY); } /* Free memory before leaving the loop */ mupnp_string_tokenizer_delete(tok); free(name); break; } } mupnp_string_tokenizer_delete(tok); free(name); } mupnp_log_debug_l4("Leaving...\n"); return bodyNode; }