Пример #1
0
char *upnp_get_string(struct action_event *event, const char *key)
{
	IXML_Node *node;

	node = (IXML_Node *) event->request->ActionRequest;
	if (node == NULL) {
		upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
			       "Invalid action request document");
		return NULL;
	}
	node = ixmlNode_getFirstChild(node);
	if (node == NULL) {
		upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
			       "Invalid action request document");
		return NULL;
	}
	node = ixmlNode_getFirstChild(node);

	for (; node != NULL; node = ixmlNode_getNextSibling(node)) {
		if (strcmp(ixmlNode_getNodeName(node), key) == 0) {
			node = ixmlNode_getFirstChild(node);
			if (node == NULL) {
				/* Are we sure empty arguments are reported like this? */
				return strdup("");
			}
			return strdup(ixmlNode_getNodeValue(node));
		}
	}

	upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
		       "Missing action request argument (%s)", key);
	return NULL;
}
Пример #2
0
/*!
 * \brief Separates the action node from the root DOM node.
 *
 * \return 0 if successful, or -1 if fails.
 */
static UPNP_INLINE int get_action_node(
	/*! [in] The root DOM node. */
	IXML_Document *TempDoc,
	/*! [in] IXML_Node name to be searched. */
	char *NodeName,
	/*! [out] Response/Output node. */
	IXML_Document **RespNode)
{
	IXML_Node *EnvpNode = NULL;
	IXML_Node *BodyNode = NULL;
	IXML_Node *ActNode = NULL;
	DOMString ActNodeName = NULL;
	const DOMString nodeName;
	int ret_code = -1;	/* error, by default */
	IXML_NodeList *nl = NULL;

	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
		   "get_action_node(): node name =%s\n ", NodeName);
	*RespNode = NULL;
	/* Got the Envelope node here */
	EnvpNode = ixmlNode_getFirstChild((IXML_Node *) TempDoc);
	if (!EnvpNode)
		goto error_handler;
	nl = ixmlElement_getElementsByTagNameNS((IXML_Element *)EnvpNode,
						"*", "Body");
	if (!nl)
		goto error_handler;
	BodyNode = ixmlNodeList_item(nl, 0);
	if (!BodyNode)
		goto error_handler;
	/* Got action node here */
	ActNode = ixmlNode_getFirstChild(BodyNode);
	if (!ActNode)
		goto error_handler;
	/* Test whether this is the action node */
	nodeName = ixmlNode_getNodeName(ActNode);
	if (!nodeName)
		goto error_handler;
	if (!strstr(nodeName, NodeName))
		goto error_handler;
	else {
		ActNodeName = ixmlPrintNode(ActNode);
		if (!ActNodeName)
			goto error_handler;
		ret_code = ixmlParseBufferEx(ActNodeName, RespNode);
		if (ret_code != IXML_SUCCESS) {
			ixmlFreeDOMString(ActNodeName);
			ret_code = -1;
			goto error_handler;
		}
	}
	/* success */
	ret_code = 0;

error_handler:
	ixmlFreeDOMString(ActNodeName);
	if (nl)
		ixmlNodeList_free(nl);
	return ret_code;
}
Пример #3
0
char *upnp_get_string(struct action_event *event, const char *key)
{
	IXML_Node *node;

	node = (IXML_Node *) event->request->ActionRequest;
	if (node == NULL) {
		upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
			       "Invalid action request document");
		return NULL;
	}
	node = ixmlNode_getFirstChild(node);
	if (node == NULL) {
		upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
			       "Invalid action request document");
		return NULL;
	}
	node = ixmlNode_getFirstChild(node);

	for (/**/; node != NULL; node = ixmlNode_getNextSibling(node)) {
		if (strcmp(ixmlNode_getNodeName(node), key) == 0) {
			node = ixmlNode_getFirstChild(node);
			const char *node_value = (node != NULL
						  ? ixmlNode_getNodeValue(node)
						  : NULL);
			return strdup(node_value != NULL ? node_value : "");
		}
	}

	upnp_set_error(event, UPNP_SOAP_E_INVALID_ARGS,
		       "Missing action request argument (%s)", key);
	return NULL;
}
Пример #4
0
/****************************************************************************
*	Function :	get_var_name
*
*	Parameters :
*		IN IXML_Document *TempDoc :	Document containing variable request
*		OUT char* VarName :	Name of the state varible
*
*	Description :	This function finds the name of the state variable
*				asked in the SOAP request.
*
*	Return :	int
*		returns 0 if successful else returns -1.
*	Note :
****************************************************************************/
static UPNP_INLINE int
get_var_name( IN IXML_Document * TempDoc,
              OUT char *VarName )
{
    IXML_Node *EnvpNode = NULL;
    IXML_Node *BodyNode = NULL;
    IXML_Node *StNode = NULL;
    IXML_Node *VarNameNode = NULL;
    IXML_Node *VarNode = NULL;
    const DOMString StNodeName = NULL;
    const DOMString Temp = NULL;
    int ret_val = -1;

    // Got the Envelop node here
    EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc );
    if( EnvpNode == NULL ) {
        goto error_handler;
    }
    // Got Body here
    BodyNode = ixmlNode_getFirstChild( EnvpNode );
    if( BodyNode == NULL ) {
        goto error_handler;
    }
    // Got action node here
    StNode = ixmlNode_getFirstChild( BodyNode );
    if( StNode == NULL ) {
        goto error_handler;
    }
    //Test whether this is the action node
    StNodeName = ixmlNode_getNodeName( StNode );
    if( StNodeName == NULL || strstr( StNodeName,
                                      "QueryStateVariable" ) == NULL ) {
        goto error_handler;
    }

    VarNameNode = ixmlNode_getFirstChild( StNode );
    if( VarNameNode == NULL ) {
        goto error_handler;
    }

    VarNode = ixmlNode_getFirstChild( VarNameNode );
    Temp = ixmlNode_getNodeValue( VarNode );
    linecopy( VarName, Temp );

    UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
                "Received query for variable  name %s\n",
                VarName );

    ret_val = 0;            // success

error_handler:
    return ret_val;
}
Пример #5
0
/*================================================================
*   ixmlDocument_getElementById
*       Returns the element whose ID is given by tagName. If no such
*       element exists, returns null.
*       External function.
*   Parameter:
*       tagName: the tag name for an element.
*   Return Values:
*       The matching element.
*
*=================================================================*/
IXML_Element *
ixmlDocument_getElementById( IN IXML_Document * doc,
                             IN DOMString tagName )
{
    IXML_Element *rtElement = NULL;
    IXML_Node *nodeptr = ( IXML_Node * ) doc;
    const char *name;

    if( ( nodeptr == NULL ) || ( tagName == NULL ) ) {
        return rtElement;
    }

    if( ixmlNode_getNodeType( nodeptr ) == eELEMENT_NODE ) {
        name = ixmlNode_getNodeName( nodeptr );
        if( name == NULL ) {
            return rtElement;
        }

        if( strcmp( tagName, name ) == 0 ) {
            rtElement = ( IXML_Element * ) nodeptr;
            return rtElement;
        } else {
            rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                     ixmlNode_getFirstChild
                                                     ( nodeptr ),
                                                     tagName );
            if( rtElement == NULL ) {
                rtElement = ixmlDocument_getElementById( ( IXML_Document
                                                           * )
                                                         ixmlNode_getNextSibling
                                                         ( nodeptr ),
                                                         tagName );
            }
        }
    } else {
        rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                 ixmlNode_getFirstChild
                                                 ( nodeptr ), tagName );
        if( rtElement == NULL ) {
            rtElement = ixmlDocument_getElementById( ( IXML_Document * )
                                                     ixmlNode_getNextSibling
                                                     ( nodeptr ),
                                                     tagName );
        }
    }

    return rtElement;
}
Пример #6
0
int set_node_value(struct xmlelement *element, const char *newNodeValue)
{
	IXML_Node *node = (IXML_Node*) to_ielem(element);
	node = ixmlNode_getFirstChild(node);

	return ixmlNode_setNodeValue(node, newNodeValue);
}
Пример #7
0
Файл: node.c Проект: rxwen/pupnp
/*!
 * \brief
 */
static void ixmlNode_getElementsByTagNameNSRecursive(
    /*! [in] . */
    IXML_Node *n,
    /*! [in] . */
    const char *namespaceURI,
    /*! [in] . */
    const char *localName,
    /*! [out] . */
    IXML_NodeList **list)
{
    const DOMString nsURI;
    const DOMString name;

    if (n != NULL) {
        if (ixmlNode_getNodeType(n) == eELEMENT_NODE) {
            name = ixmlNode_getLocalName(n);
            nsURI = ixmlNode_getNamespaceURI(n);

            if (name != NULL && nsURI != NULL &&
                    (strcmp(namespaceURI, nsURI) == 0 ||
                     strcmp(namespaceURI, "*") == 0 ) &&
                    (strcmp(name, localName) == 0 ||
                     strcmp(localName, "*") == 0)) {
                ixmlNodeList_addToNodeList(list, n);
            }
        }
        ixmlNode_getElementsByTagNameNSRecursive(
            ixmlNode_getFirstChild(n), namespaceURI, localName, list);
        ixmlNode_getElementsByTagNameNSRecursive(
            ixmlNode_getNextSibling(n), namespaceURI, localName, list);
    }
}
Пример #8
0
char *upnp_igd_get_first_element_item(upnp_igd_context *igd_ctxt,IXML_Element *element, const char *item)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlElement_getElementsByTagName(element, (char *)item);
	if (nodeList == NULL) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s in XML Node",
			__FILE__, __LINE__, item);
		return NULL;
	}
	tmpNode = ixmlNodeList_item(nodeList, 0);
	if (!tmpNode) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s value in XML Node",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	textNode = ixmlNode_getFirstChild(tmpNode);
	ret = strdup(ixmlNode_getNodeValue(textNode));
	if (!ret) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error allocating memory for %s in XML Node",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	ixmlNodeList_free(nodeList);

	return ret;
}
Пример #9
0
IXML_Node* xmldb_getMetaVariable(IXML_Element* obj, const char* name)
{
    IXML_Element* metaInfo = xmldb_getMetaInfo(obj);
    if (metaInfo == NULL)
    {
        return NULL;
    }

    // iterate through all meta tags until we find corresponding name
    IXML_Node* metaNode = ixmlNode_getFirstChild(ixmlElement_getNode(metaInfo));

    for (; metaNode != NULL; metaNode = ixmlNode_getNextSibling(metaNode))
    {
        IXML_Element* metaElement = ixmlNode_convertToElement(metaNode);
        if (metaElement == NULL)
        {
            // this piece of meta data is not an element - ignore it
            continue;
        }

        if (strcmp(ixmlElement_getTagName(metaElement), name) == 0)
        {
            return ixmlAttr_getNode(
                       ixmlElement_getAttributeNode(metaElement, OBIX_ATTR_VAL));
        }
    }

    // no meta tag with such name found
    return NULL;
}
Пример #10
0
/****************************************************************************
*	Function :	check_soap_body
*
*	Parameters :
*		IN IXML_Document *doc :	soap body xml document
*		    IN const char *urn :
*		    IN const char *actionName : Name of the requested action
*
*	Description :	This function checks the soap body xml came in the
*		SOAP request.
*
*	Return : int
*		UPNP_E_SUCCESS if successful else returns appropriate error
*
*	Note :
****************************************************************************/
static int
check_soap_body( IN IXML_Document * doc,
                 IN const char *urn,
                 IN const char *actionName )
{
    IXML_NodeList *nl = NULL;
    IXML_Node *bodyNode = NULL;
    IXML_Node *actionNode = NULL;
    const DOMString ns = NULL;
    const DOMString name = NULL;

    int ret_code = UPNP_E_INVALID_ACTION;

    nl = ixmlDocument_getElementsByTagNameNS( doc, SOAP_URN, SOAP_BODY );

    if( nl ) {
        bodyNode = ixmlNodeList_item( nl, 0 );
        if( bodyNode ) {
            actionNode = ixmlNode_getFirstChild( bodyNode );
            if( actionNode ) {
                ns = ixmlNode_getNamespaceURI( actionNode );
                name = ixmlNode_getLocalName( actionNode );
                if (name && ns &&
                        !strcmp( actionName, name ) &&
                        !strcmp( urn, ns ) ) {
                    ret_code = UPNP_E_SUCCESS;
                }
            }
        }
        ixmlNodeList_free( nl );
    }
    return ret_code;

}
Пример #11
0
BOOL GetMultipleNodeValueString(IXML_Node *pNode, char *pszName, char (*arrOutStr)[VCA5_APP_MAX_STR_LEN])
{
	BOOL ret = FALSE;
	IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if( pTmpNodeList ) {

		IXML_Node *pTmpNode = pTmpNodeList->nodeItem;
		IXML_Node *child  = ixmlNode_getFirstChild( pTmpNode );
		char *pszNodeValue = ixmlNode_getNodeValue( child );

		switch ( ixmlNode_getNodeType( child ) ) {

		case eTEXT_NODE:
			strcpy(arrOutStr[0], pszNodeValue);
			ret = TRUE;
			break;

		case eELEMENT_NODE:
		//	while() {
		//	}
		//	break;

		default:
			break;
		}

		ixmlNodeList_free(pTmpNodeList);
	}

	return ret;
}
Пример #12
0
BOOL GetMultipleNodeValueInt(IXML_Node *pNode, char *pszName, int *arrOutint)
{
	BOOL ret = FALSE;
	IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if( pTmpNodeList ) {
		
		IXML_Node *pTmpNode = pTmpNodeList->nodeItem;
		IXML_Node *child  = ixmlNode_getFirstChild( pTmpNode );
		char *pszNodeValue = ixmlNode_getNodeValue( child );

		switch ( ixmlNode_getNodeType( child ) ) {

		case eTEXT_NODE:
			arrOutint[0] = atoi(pszNodeValue);
			ret = TRUE;
			break;

		case eELEMENT_NODE:
		//	while() {
		//	}
		//	break;

		default:
			break;
		}

		ixmlNodeList_free(pTmpNodeList);
	}

	return ret;
}
Пример #13
0
char *ReadElement(const char *Path,const char *NodeElement)
{
	char *Val = NULL;
	IXML_Document *doc = NULL;
	IXML_NodeList *node = NULL;
	IXML_Node *NodePtr = NULL;

	if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER)
		goto EXIT_THIS;

	node = ixmlDocument_getElementsByTagName(doc, NodeElement);

	if (node) 
	{
		if (NodePtr = ixmlNodeList_item(node, 0)) 
		{
			NodePtr = ixmlNode_getFirstChild(NodePtr);
			if(!NodePtr)
			{
				Val = (NULL);
			}
			Val = NodePtr->nodeValue;//strdup(NodePtr->nodeValue);
			if(!Val)
			{
				Val = (NULL);
			}
		} 
	}

	if (node)
		ixmlNodeList_free(node);
	ixmlDocument_free(doc);  
EXIT_THIS:
	return Val;
}
Пример #14
0
/*!
 * \brief Goes thru each child of 'start_node' looking for a node having
 * the name 'node_name'.
 *
 * \return UPNP_E_SUCCESS if successful else returns appropriate error.
 */
static int dom_find_node(
	/* [in] name of the node. */
	const char *node_name,
	/* [in] complete xml node. */
	IXML_Node *start_node,
	/* [out] matched node. */
	IXML_Node **matching_node)
{
	IXML_Node *node;

	/* invalid args */
	if (!node_name || !start_node)
		return UPNP_E_NOT_FOUND;
	node = ixmlNode_getFirstChild(start_node);
	while (node != NULL) {
		/* match name */
		if (dom_cmp_name(node_name, node) == 0) {
			*matching_node = node;
			return UPNP_E_SUCCESS;
		}
		/* free and next node */
		node = ixmlNode_getNextSibling(node);
	}

	return UPNP_E_NOT_FOUND;
}
Пример #15
0
/****************************************************************************
*	Function :	dom_find_node
*
*	Parameters :
*			IN char* node_name : name of the node	
*			IN IXML_Node *start_node :	complete xml node
*			OUT IXML_Node ** matching_node : matched node
*
*	Description :	This function goes thru each child of 'start_node' 
*		looking for a node having the name 'node_name'. 
*
*	Return : int
*		return UPNP_E_SUCCESS if successful else returns appropriate error
*
*	Note :
****************************************************************************/
static int
dom_find_node( IN char *node_name,
               IN IXML_Node * start_node,
               OUT IXML_Node ** matching_node )
{
    IXML_Node *node;

    // invalid args
    if( node_name == NULL || start_node == NULL ) {
        return UPNP_E_NOT_FOUND;
    }

    node = ixmlNode_getFirstChild( start_node );
    while( node != NULL ) {
        // match name
        if( dom_cmp_name( node_name, node ) == 0 ) {
            *matching_node = node;
            return UPNP_E_SUCCESS;
        }
        // free and next node
        node = ixmlNode_getNextSibling( node ); // next node
    }

    return UPNP_E_NOT_FOUND;
}
Пример #16
0
/************************************************************************
*	Function :	getSubElement
*
*	Parameters :
*		const char *element_name ;	sub element name to be searched for
*		IXML_Node *node ;	Input node which provides the list of child 
*							nodes
*		IXML_Node **out ;	Ouput node to which the matched child node is
*							returned.
*
*	Description :	Traverses through a list of XML nodes to find the 
*		node with the known element name.
*
*	Return : int ;
*		1 - On Success
*		0 - On Failure
*
*	Note :
************************************************************************/
int
getSubElement( const char *element_name,
               IXML_Node * node,
               IXML_Node ** out )
{

    const DOMString NodeName = NULL;
    int found = 0;

    IXML_Node *child = ( IXML_Node * ) ixmlNode_getFirstChild( node );

    ( *out ) = NULL;

    while( ( child != NULL ) && ( !found ) ) {

        switch ( ixmlNode_getNodeType( child ) ) {
            case eELEMENT_NODE:

                NodeName = ixmlNode_getNodeName( child );
                if( !strcmp( NodeName, element_name ) ) {
                    ( *out ) = child;
                    found = 1;
                    return found;
                }
                break;

            default:
                break;
        }

        child = ( IXML_Node * ) ixmlNode_getNextSibling( child );
    }

    return found;
}
Пример #17
0
/*
 * Extracts the result document from a SOAP response
 */
IXML_Document* parseBrowseResult( IXML_Document* p_doc )
{
    ixmlRelaxParser( 1 );

    if ( !p_doc ) return 0;

    IXML_NodeList* p_result_list = ixmlDocument_getElementsByTagName( p_doc,
                                                                   "Result" );

    if ( !p_result_list ) return 0;

    IXML_Node* p_result_node = ixmlNodeList_item( p_result_list, 0 );

    ixmlNodeList_free( p_result_list );

    if ( !p_result_node ) return 0;

    IXML_Node* p_text_node = ixmlNode_getFirstChild( p_result_node );
    if ( !p_text_node ) return 0;

    const char* psz_result_string = ixmlNode_getNodeValue( p_text_node );

    IXML_Document* p_browse_doc = ixmlParseBuffer( psz_result_string );

    return p_browse_doc;
}
Пример #18
0
// Extracts the result document from a SOAP response
IXML_Document* parseBrowseResult( IXML_Document* doc )
{
    ixmlRelaxParser(1);

    if ( !doc ) return 0;

    IXML_NodeList* resultList = ixmlDocument_getElementsByTagName( doc,
                                                                   "Result" );

    if ( !resultList ) return 0;

    IXML_Node* resultNode = ixmlNodeList_item( resultList, 0 );

    ixmlNodeList_free( resultList );

    if ( !resultNode ) return 0;

    IXML_Node* textNode = ixmlNode_getFirstChild( resultNode );
    if ( !textNode ) return 0;

    const char* resultString = ixmlNode_getNodeValue( textNode );
    char* resultXML = strdup( resultString );

    IXML_Document* browseDoc = ixmlParseBuffer( resultXML );

    free( resultXML );

    return browseDoc;
}
Пример #19
0
/*================================================================
*   ixmlNode_getElementsByTagNameNS
*       Returns a nodeList of all the descendant Elements with a given
*       local name and namespace URI in the order in which they are
*       encountered in a preorder traversal of this Elememt tree.		
*		External function.
*
*=================================================================*/
void
ixmlNode_getElementsByTagNameNS( IN IXML_Node * n,
                                 IN char *namespaceURI,
                                 IN char *localName,
                                 OUT IXML_NodeList ** list )
{
    DOMString nsURI;
    DOMString name;

    assert( n != NULL && namespaceURI != NULL && localName != NULL );

    if( ixmlNode_getNodeType( n ) == eELEMENT_NODE ) {
        name = ixmlNode_getLocalName( n );
        nsURI = ixmlNode_getNamespaceURI( n );

        if( ( name != NULL ) && ( nsURI != NULL ) &&
            ( strcmp( namespaceURI, nsURI ) == 0
              || strcmp( namespaceURI, "*" ) == 0 )
            && ( strcmp( name, localName ) == 0
                 || strcmp( localName, "*" ) == 0 ) ) {
            ixmlNodeList_addToNodeList( list, n );
        }
    }

    ixmlNode_getElementsByTagNameNSRecursive( ixmlNode_getFirstChild( n ),
                                              namespaceURI, localName,
                                              list );

}
Пример #20
0
char *SampleUtil_GetFirstElementItem(IXML_Element *element, const char *item)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlElement_getElementsByTagName(element, (char *)item);
	if (nodeList == NULL) {
		SampleUtil_Print("%s(%d): Error finding %s in XML Node\n",
			__FILE__, __LINE__, item);
		return NULL;
	}
	tmpNode = ixmlNodeList_item(nodeList, 0);
	if (!tmpNode) {
		SampleUtil_Print("%s(%d): Error finding %s value in XML Node\n",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	textNode = ixmlNode_getFirstChild(tmpNode);
	ret = strdup(ixmlNode_getNodeValue(textNode));
	if (!ret) {
		SampleUtil_Print("%s(%d): Error allocating memory for %s in XML Node\n",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	ixmlNodeList_free(nodeList);

	return ret;
}
Пример #21
0
/*!
 * \brief Finds the name of the state variable asked in the SOAP request.
 *
 * \return 0 if successful else returns -1.
 */
static UPNP_INLINE int get_var_name(
	/*! [in] Document containing variable request. */
	IXML_Document *TempDoc,
	/*! [out] Name of the state varible. */
	char *VarName)
{
	IXML_Node *EnvpNode = NULL;
	IXML_Node *BodyNode = NULL;
	IXML_Node *StNode = NULL;
	IXML_Node *VarNameNode = NULL;
	IXML_Node *VarNode = NULL;
	const DOMString StNodeName = NULL;
	const DOMString Temp = NULL;
	int ret_val = -1;

	/* Got the Envelop node here */
	EnvpNode = ixmlNode_getFirstChild((IXML_Node *) TempDoc);
	if (EnvpNode == NULL)
		goto error_handler;
	/* Got Body here */
	BodyNode = ixmlNode_getFirstChild(EnvpNode);
	if (BodyNode == NULL)
		goto error_handler;
	/* Got action node here */
	StNode = ixmlNode_getFirstChild(BodyNode);
	if (StNode == NULL)
		goto error_handler;
	/* Test whether this is the action node */
	StNodeName = ixmlNode_getNodeName(StNode);
	if (StNodeName == NULL ||
	    strstr(StNodeName, "QueryStateVariable") == NULL)
		goto error_handler;
	VarNameNode = ixmlNode_getFirstChild(StNode);
	if (VarNameNode == NULL)
		goto error_handler;
	VarNode = ixmlNode_getFirstChild(VarNameNode);
	Temp = ixmlNode_getNodeValue(VarNode);
	linecopy(VarName, Temp);
	UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
		   "Received query for variable  name %s\n", VarName);

	/* success */
	ret_val = 0;

error_handler:
	return ret_val;
}
Пример #22
0
char *get_node_value(struct xmlelement *element) {
	IXML_Node *node = (IXML_Node*) to_ielem(element);
	node = ixmlNode_getFirstChild(node);
	const char *node_value = (node != NULL
				  ? ixmlNode_getNodeValue(node)
				  : NULL);
	return strdup(node_value != NULL ? node_value : "");
}
Пример #23
0
/*!
 * \brief Returns the first child of a given element.
 */
IXML_Element *CUPnPLib::Element_GetFirstChild(
	IXML_Element *parent) const
{
	IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(parent);
	IXML_Node *child = ixmlNode_getFirstChild(node);

	return REINTERPRET_CAST(IXML_Element *)(child);
}
Пример #24
0
/************************************************************************
* Function : addToAction
*
* Parameters:
*	IN int response: flag to tell if the ActionDoc is for response
*		or request
*	INOUT IXML_Document **ActionDoc: request or response document
*	IN char *ActionName: Name of the action request or response
*	IN char *ServType: Service type
*	IN char * ArgName: Name of the argument
*	IN char * ArgValue: Value of the argument
*
* Description:
*	This function adds the argument in the action request or response.
* This function creates the action request or response if it is a first
* argument else it will add the argument in the document
*
* Returns: int
*	returns UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/
static int
addToAction( IN int response,
             INOUT IXML_Document ** ActionDoc,
             IN const char *ActionName,
             IN const char *ServType,
             IN const char *ArgName,
             IN const char *ArgValue )
{
    char *ActBuff = NULL;
    IXML_Node *node = NULL;
    IXML_Element *Ele = NULL;
    IXML_Node *Txt = NULL;
    int rc = 0;

    if( ActionName == NULL || ServType == NULL ) {
        return UPNP_E_INVALID_PARAM;
    }

    if( *ActionDoc == NULL ) {
        ActBuff = ( char * )malloc( HEADER_LENGTH );
        if( ActBuff == NULL ) {
            return UPNP_E_OUTOF_MEMORY;
        }

        if( response ) {
            sprintf( ActBuff,
                "<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
                ActionName, ServType, ActionName );
        } else {
            sprintf( ActBuff,
                "<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
                ActionName, ServType, ActionName );
        }

        rc = ixmlParseBufferEx( ActBuff, ActionDoc );
        free( ActBuff );
        if( rc != IXML_SUCCESS ) {
            if( rc == IXML_INSUFFICIENT_MEMORY ) {
                return UPNP_E_OUTOF_MEMORY;
            } else {
                return UPNP_E_INVALID_DESC;
            }
        }
    }

    if( ArgName != NULL /*&& ArgValue != NULL */  ) {
        node = ixmlNode_getFirstChild( ( IXML_Node * ) * ActionDoc );
        Ele = ixmlDocument_createElement( *ActionDoc, ArgName );
        if( ArgValue ) {
            Txt = ixmlDocument_createTextNode( *ActionDoc, ArgValue );
            ixmlNode_appendChild( ( IXML_Node * ) Ele, Txt );
        }

        ixmlNode_appendChild( node, ( IXML_Node * ) Ele );
    }

    return UPNP_E_SUCCESS;
}
Пример #25
0
/*!
 * \brief Returns the root node of a given document.
 */
IXML_Element *CUPnPLib::Element_GetRootElement(
	IXML_Document *doc) const
{
	IXML_Element *root = REINTERPRET_CAST(IXML_Element *)(
		ixmlNode_getFirstChild(
			REINTERPRET_CAST(IXML_Node *)(doc)));

	return root;
}
Пример #26
0
static struct xmlelement *find_element(IXML_Node *node, const char *key) {
	node = ixmlNode_getFirstChild(node);
	for (/**/; node != NULL; node = ixmlNode_getNextSibling(node)) {
		if (strcmp(ixmlNode_getNodeName(node), key) == 0) {
			return (struct xmlelement*) node;
		}
	}
	return NULL;
}
Пример #27
0
			v = (char*) ixmlNode_getNodeValue(l1_1_node);
			LoadConfigItem(Conf, sq_conf, n, v);
		}
		if (node_list) ixmlNodeList_free(node_list);
	}

	return node;
}

/*----------------------------------------------------------------------------*/
void *LoadConfig(char *name, tMRConfig *Conf, sq_dev_param_t *sq_conf)
{
	IXML_Element *elm;
	IXML_Document	*doc;

	doc = ixmlLoadDocument(name);
	if (!doc) return NULL;

	elm = ixmlDocument_getElementById(doc, "squeeze2upnp");
	if (elm) {
		unsigned i;
		char *n, *v;
		IXML_NodeList *l1_node_list;
		l1_node_list = ixmlNode_getChildNodes((IXML_Node*) elm);
		for (i = 0; i < ixmlNodeList_length(l1_node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(l1_node_list, i);
			n = (char*) ixmlNode_getNodeName(l1_node);
			l1_1_node = ixmlNode_getFirstChild(l1_node);
			v = (char*) ixmlNode_getNodeValue(l1_1_node);
			LoadGlobalItem(n, v);
		}
		if (l1_node_list) ixmlNodeList_free(l1_node_list);
	}

	elm = ixmlDocument_getElementById((IXML_Document	*)elm, "common");
	if (elm) {
		char *n, *v;
		IXML_NodeList *l1_node_list;
		unsigned i;
		l1_node_list = ixmlNode_getChildNodes((IXML_Node*) elm);
		for (i = 0; i < ixmlNodeList_length(l1_node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(l1_node_list, i);
Пример #28
0
/* 
 * supported properties are:
 * deviceType
 * friendlyName
 * manufacturer
 * modelName
 * UDN
 * serviceType
 * serviceId
 **/
const char *get_device_property(IXML_Document *desc, const char *prop) {
    IXML_NodeList *list = ixmlDocument_getElementsByTagName(desc, prop);
    int length = ixmlNodeList_length(list);
    if (length < 1) {
        fprintf(stderr, "Error obtaining device name\n");
    }
    IXML_Node *n = ixmlNodeList_item(list, 0);
    n = ixmlNode_getFirstChild(n);
    return ixmlNode_getNodeValue(n);
}
Пример #29
0
char *SampleUtil_GetElementValue(IXML_Element *element)
{
	IXML_Node *child = ixmlNode_getFirstChild((IXML_Node *)element);
	char *temp = NULL;

	if (child != 0 && ixmlNode_getNodeType(child) == eTEXT_NODE)
		temp = strdup(ixmlNode_getNodeValue(child));

	return temp;
}
Пример #30
0
char *upnp_igd_get_element_value(upnp_igd_context *igd_ctxt, IXML_Element *element)
{
	IXML_Node *child = ixmlNode_getFirstChild((IXML_Node *)element);
	char *temp = NULL;

	if (child != 0 && ixmlNode_getNodeType(child) == eTEXT_NODE)
		temp = strdup(ixmlNode_getNodeValue(child));

	return temp;
}