CgXmlNode *cg_upnp_control_query_response_getreturnnode(CgUpnpQueryResponse *queryRes)
{
	CgSoapResponse *soapRes;	
	CgXmlNode *bodyNode;
	CgXmlNode *queryResNode;
	
	cg_log_debug_l4("Entering...\n");

	soapRes = cg_upnp_control_query_response_getsoapresponse(queryRes);
	
	bodyNode = cg_soap_response_getbodynode(soapRes);
	if (bodyNode == NULL)
		return NULL;
	if (cg_xml_node_haschildnodes(bodyNode) == FALSE)
		return NULL;

	queryResNode = cg_xml_node_getchildnodes(bodyNode);		
	if (queryResNode == NULL)
		return NULL;
	if (cg_xml_node_haschildnodes(queryResNode) == FALSE)
		return NULL;
		
	return cg_xml_node_getchildnodes(queryResNode);		

	cg_log_debug_l4("Leaving...\n");
}
CgXmlNode *cg_upnp_event_notify_request_getvariablenode(CgUpnpNotifyRequest *nofityReq)
{
    CgXmlNode *propSetNode;
    CgXmlNode *propNode;

    cg_log_debug_l4("Entering...\n");

    propSetNode = cg_upnp_event_notify_request_getpropertysetnode(nofityReq);
    if (propSetNode == NULL)
        return NULL;
    if (cg_xml_node_haschildnodes(propSetNode) == FALSE)
        return NULL;

    propNode = cg_xml_node_getchildnodes(propSetNode);
    if (propNode == NULL)
        return NULL;
    if (cg_xml_node_haschildnodes(propNode) == FALSE)
        return NULL;

    cg_log_debug_l4("Leaving...\n");

    return cg_xml_node_getchildnodes(propNode);
}
CgXmlNode *cg_soap_response_getbodynode(CgSoapResponse *soapRes)
{
	CgXmlNode *envNode;
	 
	cg_log_debug_l4("Entering...\n");

	envNode = cg_soap_response_getenvelopenode(soapRes);
	if (envNode == NULL)
		return NULL;
	if (cg_xml_node_haschildnodes(envNode) == FALSE)
		return NULL;
	return cg_xml_node_getchildnodes(envNode);

	cg_log_debug_l4("Leaving...\n");
}
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;
}
Beispiel #5
0
static char *cg_xml_node_tostring_indent(CgXmlNode *node, int indentLevel, BOOL withChildNode, CgString *str)
{
	char *name;
	char *value;
	CgString *valueStr;
	CgXmlNode *childNode;
	
	cg_log_debug_l4("Entering...\n");

	name = cg_xml_node_getname(node);
	value = cg_xml_node_getvalue(node);

	if (cg_xml_node_haschildnodes(node) == FALSE || withChildNode == FALSE) {
		cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
		if (!cg_string_naddvalue(str, "<", 1) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_xml_node_attribute_tostring(node, str))
			/* Memory allocation failed */
			return NULL;
		
		valueStr = cg_string_new();
		if (!valueStr)
			/* Memory allocation failed */
			return NULL;
		
		cg_string_setvalue(valueStr, value);
		cg_xml_escapechars(valueStr);

		if (!cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, cg_string_getvalue(valueStr)) ||
		    !cg_string_naddvalue(str, "</", 2) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, "\n"))
		{
			/* Memory allocation failed */
			cg_string_delete(valueStr);
			return NULL;
		}

		cg_string_delete(valueStr);
		
		return cg_string_getvalue(str);
	}

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "<", 1) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_xml_node_attribute_tostring(node, str) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	for (childNode = cg_xml_node_getchildnodes(node); childNode != NULL; childNode = cg_xml_node_next(childNode))
		if (!cg_xml_node_tostring_indent(childNode, indentLevel+1, TRUE, str))
			/* Memory allocation failed */
			return NULL;

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "</", 2) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	cg_log_debug_l4("Leaving...\n");
	
	return cg_string_getvalue(str);
}