Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
0
/*!
 * \brief Searches for the node specifed by the last name in the 'name' array.
 *
 * \return UPNP_E_SUCCESS if successful, else returns appropriate error.
 */
static int dom_find_deep_node(
	/* [in] array of names. */
	const char *names[],
	/* [in] size of array. */
	int num_names,
	/* [in] Node from where it should should be searched. */
	IXML_Node *start_node,
	/* [out] Node that matches the last name of the array. */
	IXML_Node **matching_node)
{
	int i;
	IXML_Node *node;
	IXML_Node *match_node;

	assert(num_names > 0);

	node = start_node;
	if (dom_cmp_name(names[0], start_node) == 0) {
		if (num_names == 1) {
			*matching_node = start_node;
			return UPNP_E_SUCCESS;
		}
	}
	for (i = 1; i < num_names; i++) {
		if (dom_find_node(names[i], node, &match_node) != UPNP_E_SUCCESS)
			return UPNP_E_NOT_FOUND;
		if (i == num_names - 1) {
			*matching_node = match_node;
			return UPNP_E_SUCCESS;
		}
		/* try again */
		node = match_node;
	}

	/* this line not reached */
	return UPNP_E_NOT_FOUND;
}
Beispiel #4
0
/****************************************************************************
*	Function :	dom_find_deep_node
*
*	Parameters :
*			IN char* names[] : array of names
*			IN int num_names :	size of array
*			IN IXML_Node *start_node : Node from where it should should be 
*										searched	
*			OUT IXML_Node ** matching_node : Node that matches the last name
*											of the array
*
*	Description :	This function searches for the node specifed by the last 
*		name in the 'name' array.
*
*	Return : int
*		return UPNP_E_SUCCESS if successful else returns appropriate error
*	Note :
****************************************************************************/
static int
dom_find_deep_node( IN char *names[],
                    IN int num_names,
                    IN IXML_Node * start_node,
                    OUT IXML_Node ** matching_node )
{
    int i;
    IXML_Node *node;
    IXML_Node *match_node;

    assert( num_names > 0 );

    node = start_node;
    if( dom_cmp_name( names[0], start_node ) == 0 ) {
        if( num_names == 1 ) {
            *matching_node = start_node;
            return UPNP_E_SUCCESS;
        }
    }

    for( i = 1; i < num_names; i++ ) {
        if( dom_find_node( names[i], node, &match_node ) !=
            UPNP_E_SUCCESS ) {
            return UPNP_E_NOT_FOUND;
        }

        if( i == num_names - 1 ) {
            *matching_node = match_node;
            return UPNP_E_SUCCESS;
        }

        node = match_node;      // try again
    }

    return UPNP_E_NOT_FOUND;    // this line not reached
}