mUpnpXmlNode *mupnp_xml_nodelist_getbyxpath(mUpnpXmlNodeList *nodeList, const char *name) { mUpnpXmlNode *node; char *nodeName; mupnp_log_debug_l4("Entering...\n"); if (name == NULL) return NULL; for (node = mupnp_xml_nodelist_gets(nodeList); node != NULL; node = mupnp_xml_node_next(node)) { nodeName = mupnp_xml_node_getname(node); if (nodeName == NULL) continue; if (mupnp_strcasecmp(nodeName, name) == 0) return node; } mupnp_log_debug_l4("Leaving...\n"); return NULL; }
mUpnpXmlAttribute* mupnp_xml_attributelist_get(mUpnpXmlAttributeList* attrList, const char* name) { mUpnpXmlAttribute* attr; const char* attrName; mupnp_log_debug_l4("Entering...\n"); if (name == NULL) return NULL; for (attr = mupnp_xml_attributelist_gets(attrList); attr != NULL; attr = mupnp_xml_attribute_next(attr)) { attrName = mupnp_xml_attribute_getname(attr); if (attrName == NULL) continue; if (mupnp_strcasecmp(attrName, name) == 0) return attr; } return NULL; mupnp_log_debug_l4("Leaving...\n"); }
mUpnpHttpHeader *mupnp_http_headerlist_get(mUpnpHttpHeaderList *headerList, const char *name) { mUpnpHttpHeader *header; const char *headerName; mupnp_log_debug_l4("Entering...\n"); if (name == NULL) return NULL; for (header = mupnp_http_headerlist_gets(headerList); header != NULL; header = mupnp_http_header_next(header)) { headerName = mupnp_http_header_getname(header); if (headerName == NULL) continue; if (mupnp_strcasecmp(headerName, name) == 0) return header; } return NULL; mupnp_log_debug_l4("Leaving...\n"); }
mUpnpXmlNode *mupnp_xml_node_getchildnodewithnamespace(mUpnpXmlNode *node, const char *name, const char *ns, bool ignoreNs) { char *nameWithPrefix = NULL; size_t nameLen = 0; ssize_t nameIdx; mUpnpXmlNode *result = NULL; mUpnpXmlNode *child = NULL; char *nodeName = NULL; mupnp_log_debug_l4("Entering...\n"); if (node == NULL) return NULL; if (name == NULL) return NULL; if (ignoreNs == true) { for (child = mupnp_xml_node_getchildnodelist(node); child != NULL; child = mupnp_xml_node_next(child)) { nodeName = mupnp_xml_node_getname(child); if (nodeName == NULL) continue; nameIdx = mupnp_strstr(nodeName, ":"); if (nameIdx < 0) { /* No prefix (no ':') */ if (mupnp_strcasecmp(nodeName, name) == 0) return child; } else { if (mupnp_strcasecmp(&(nodeName[nameIdx+1]), name) == 0) return child; } } return NULL; } else { if (ns == NULL) { /* When ns is NULL, this works like normal ..._getchildnode */ return mupnp_xml_node_getchildnode(node, name); } nameLen = mupnp_strlen(name) + mupnp_strlen(ns) + 1; /* Not including the terminating \0 */ nameWithPrefix = (char*) malloc(nameLen + 1); if (nameWithPrefix == NULL) return NULL; #if defined(HAVE_SNPRINTF) snprintf(nameWithPrefix, nameLen + 1, "%s:%s", ns, name); #else sprintf(nameWithPrefix, "%s:%s", ns, name); #endif result = mupnp_xml_node_getchildnode(node, nameWithPrefix); free(nameWithPrefix); return result; } mupnp_log_debug_l4("Leaving...\n"); }