bool mupnp_control_action_response_getresult(mUpnpActionResponse *actionRes, mUpnpAction *action) { mUpnpXmlNode *resNode; mUpnpXmlNode *argNode; char *argName; mUpnpArgument *arg; mupnp_log_debug_l4("Entering...\n"); resNode = mupnp_control_action_response_getactionresponsenode(actionRes); if (resNode == NULL) return false; for (argNode = mupnp_xml_node_getchildnodes(resNode); argNode != NULL; argNode = mupnp_xml_node_next(argNode)) { argName = mupnp_xml_node_getname(argNode); arg = mupnp_action_getargumentbyname(action, argName); if (arg == NULL) continue; mupnp_argument_setvalue(arg, mupnp_xml_node_getvalue(argNode)); } return true; mupnp_log_debug_l4("Leaving...\n"); }
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"); }
void mupnp_control_action_request_setsoaprequest(mUpnpActionRequest *actionReq, mUpnpSoapRequest *soapReq) { mUpnpXmlNode *actionNode; mUpnpXmlNode *argNode; mUpnpArgument *arg; mupnp_log_debug_l4("Entering...\n"); if (actionReq->isSoapReqCreated == true) mupnp_soap_request_delete(actionReq->soapReq); actionReq->soapReq = soapReq; actionReq->isSoapReqCreated = false; mupnp_argumentlist_clear(actionReq->argList); actionNode = mupnp_control_action_request_getactionnode(actionReq); if (actionNode == NULL) return; for (argNode = mupnp_xml_node_getchildnodes(actionNode); argNode != NULL; argNode = mupnp_xml_node_next(argNode)) { arg = mupnp_argument_new(); mupnp_argument_setargumentnode(arg, argNode); mupnp_argument_setname(arg, mupnp_xml_node_getname( argNode ) ); mupnp_argument_setvalue(arg, mupnp_xml_node_getvalue( argNode ) ); mupnp_argumentlist_add(actionReq->argList, arg); } mupnp_soap_request_createcontent(soapReq); mupnp_log_debug_l4("Leaving...\n"); }
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; }
char *mupnp_control_action_request_getactionname(mUpnpActionRequest *actionReq) { mUpnpXmlNode *node; char *name; ssize_t urnDelimIdx; mupnp_log_debug_l4("Entering...\n"); node = mupnp_control_action_request_getactionnode(actionReq); if (node == NULL) return ""; name = mupnp_xml_node_getname(node); if (name == NULL) return ""; urnDelimIdx = mupnp_strstr(name, MUPNP_HTTP_SOAP_URN_DELIM); if (urnDelimIdx < 0) return ""; mupnp_log_debug_l4("Leaving...\n"); return (name + urnDelimIdx + 1); }
static char *mupnp_xml_node_tostring_indent(mUpnpXmlNode *node, int indentLevel, bool withChildNode, mUpnpString *str) { char *name; char *value; mUpnpString *valueStr; mUpnpXmlNode *childNode; mupnp_log_debug_l4("Entering...\n"); name = mupnp_xml_node_getname(node); value = mupnp_xml_node_getvalue(node); if (mupnp_xml_node_haschildnodes(node) == false || withChildNode == false) { mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "<", 1) || !mupnp_string_addvalue(str, name) || !mupnp_xml_node_attribute_tostring(node, str)) /* Memory allocation failed */ return NULL; valueStr = mupnp_string_new(); if (!valueStr) /* Memory allocation failed */ return NULL; mupnp_string_setvalue(valueStr, value); mupnp_xml_escapechars(valueStr); if (!mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) || !mupnp_string_naddvalue(str, "</", 2) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) { /* Memory allocation failed */ mupnp_string_delete(valueStr); return NULL; } mupnp_string_delete(valueStr); return mupnp_string_getvalue(str); } mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "<", 1) || !mupnp_string_addvalue(str, name) || !mupnp_xml_node_attribute_tostring(node, str) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) /* Memory allocation failed */ return NULL; for (childNode = mupnp_xml_node_getchildnodes(node); childNode != NULL; childNode = mupnp_xml_node_next(childNode)) if (!mupnp_xml_node_tostring_indent(childNode, indentLevel+1, true, str)) /* Memory allocation failed */ return NULL; mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "</", 2) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) /* Memory allocation failed */ return NULL; mupnp_log_debug_l4("Leaving...\n"); return mupnp_string_getvalue(str); }
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"); }