Beispiel #1
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;
}
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;
}
Beispiel #3
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 #4
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;
}
Beispiel #5
0
/*!
 * \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);
    }
}
Beispiel #6
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;
}
/*================================================================
*   ixmlNode_getElementsByTagNameNSRecursive
*	    Internal function to parser.	
*		
*
*=================================================================*/
void
ixmlNode_getElementsByTagNameNSRecursive( IN IXML_Node * n,
                                          IN char *namespaceURI,
                                          IN char *localName,
                                          OUT IXML_NodeList ** list )
{
     DOMString nsURI;
     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 );
    }

}
Beispiel #8
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;
}
Beispiel #9
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 #10
0
/*!
 * \brief Returns the next sibling of a given child.
 */
IXML_Element *CUPnPLib::Element_GetNextSibling(
	IXML_Element *child) const
{
	IXML_Node *node = REINTERPRET_CAST(IXML_Node *)(child);
	IXML_Node *sibling = ixmlNode_getNextSibling(node);

	return REINTERPRET_CAST(IXML_Element *)(sibling);
}
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;
}
Beispiel #12
0
/*================================================================
*   ixmlDocument_setOwnerDocument
*
*       When this function is called first time, nodeptr is the root
*       of the subtree, so it is not necessay to do two steps
*       recursion.
*
*       Internal function called by ixmlDocument_importNode
*
*=================================================================*/
void
ixmlDocument_setOwnerDocument( IN IXML_Document * doc,
                               IN IXML_Node * nodeptr )
{
    if( nodeptr != NULL ) {
        nodeptr->ownerDocument = doc;
        ixmlDocument_setOwnerDocument( doc,
                                       ixmlNode_getFirstChild( nodeptr ) );
        ixmlDocument_setOwnerDocument( doc,
                                       ixmlNode_getNextSibling
                                       ( nodeptr ) );
    }
}
Beispiel #13
0
/*!
 * When this function is called first time, nodeptr is the root of the subtree,
 * so it is not necessay to do two steps recursion.
 *  
 * Internal function called by ixmlDocument_importNode
 */
static void ixmlDocument_setOwnerDocument(
	/*! [in] The document node. */
	IXML_Document *doc,
	/*! [in] \todo documentation. */
	IXML_Node *nodeptr)
{
	if (nodeptr != NULL) {
		nodeptr->ownerDocument = doc;
		ixmlDocument_setOwnerDocument(
			doc, ixmlNode_getFirstChild(nodeptr));
		ixmlDocument_setOwnerDocument(
			doc, ixmlNode_getNextSibling(nodeptr));
	}
}
Beispiel #14
0
const char*
XMLUtil_GetElementValue (IN const IXML_Element* element)
{
	char* res = NULL;
	IXML_Node* child = ixmlNode_getFirstChild 
		(discard_const_p (IXML_Node, XML_E2N (element)));
	while (child && !res) {
		if (ixmlNode_getNodeType (child) == eTEXT_NODE) {
		    // The resulting string should be copied if necessary
		    res = ixmlNode_getNodeValue (child);
		}
		child = ixmlNode_getNextSibling (child);
	}
	return res;
}
IXML_Node * get_child_tag ( IXML_Node * node, 
                            char * tag )
{
    IXML_Node * temp;

    for( temp = ixmlNode_getFirstChild(node);
         temp;
         temp = ixmlNode_getNextSibling(temp) ) {
        if ( strcasecmp(temp->localName, tag) == 0 ) {
            return temp;
        }
    }

    return NULL;
}
Beispiel #16
0
/*!
 * \brief Returns the next sibling element that matches the requested tag. Should be
 * used with the return value of Element_GetFirstChildByTag().
 */
IXML_Element *CUPnPLib::Element_GetNextSiblingByTag(
	IXML_Element *element, const DOMString tag) const
{
	if (!element || !tag) {
		return NULL;
	}
	
	IXML_Node *child = REINTERPRET_CAST(IXML_Node *)(element);
	const DOMString childTag = NULL;
	do {
		child = ixmlNode_getNextSibling(child);
		childTag = ixmlNode_getNodeName(child);
	} while(child && childTag && strcmp(tag, childTag));

	return REINTERPRET_CAST(IXML_Element *)(child);
}
Beispiel #17
0
static int _LoadPalleteFromPalletTemplate(HBROWSER_HANDLE hbrowser, HDOC_HANDLE hdoc, int isShadow)
{
char newhtml[256];
IXML_Element *ParentElement;
IXML_Element *xmlElement;
IXML_Document *Doc = PalletTemplate;
char *lbuffer,*p;
HELEMENT_HANDLE h;

	p = (char *) rtp_malloc(100000);
	lbuffer = p;
	*p = 0;
	newhtml[0] = 0;
	if (isShadow)
		h = webc_DocFindElement (hdoc, "ShadowPallete", 0, HTML_ELEMENT_ANY, 0);
	else
		h = webc_DocFindElement (hdoc, "Pallete", 0, HTML_ELEMENT_ANY, 0);
	if (!h)
		goto error;
	xmlElement = 0;
	ParentElement = rtpxmlGetElemInDocFromDomStr(Doc, PALLETDOMSTR); /* "PalletImages" */
	if (ParentElement)
		xmlElement = (IXML_Element *)ixmlNode_getFirstChild((IXML_Node*) ParentElement);
	while (xmlElement)
	{
		if (xmlPalletElementToHtml(xmlElement, newhtml, isShadow) != 0)
			goto error;
		rtp_strcat(p,newhtml); p += rtp_strlen(p);
		xmlElement = (IXML_Element *) ixmlNode_getNextSibling((IXML_Node*) xmlElement);
	}
	webc_ElementSetInnerHtmlASCII (h, lbuffer);
	if (lbuffer)
		rtp_free(lbuffer);
	return 0;
error:
	if (lbuffer)
		rtp_free(lbuffer);
	printf("Error CreatePalleteFromPalletTemplate()\n");
	assert(0);
  	return -1;
}
Beispiel #18
0
/*!
 * \brief Recursively traverse the whole tree, search for element with the
 * given tagname.
 */
static void ixmlNode_getElementsByTagNameRecursive(
    /*! [in] The \b Node tree. */
    IXML_Node *n,
    /*! [in] The tag name to match. */
    const char *tagname,
    /*! [out] The output \b NodeList. */
    IXML_NodeList **list)
{
    const char *name;

    if (n != NULL) {
        if (ixmlNode_getNodeType(n) == eELEMENT_NODE) {
            name = ixmlNode_getNodeName(n);
            if (strcmp(tagname, name) == 0 || strcmp(tagname, "*") == 0) {
                ixmlNodeList_addToNodeList(list, n);
            }
        }
        ixmlNode_getElementsByTagNameRecursive(ixmlNode_getFirstChild(n), tagname, list);
        ixmlNode_getElementsByTagNameRecursive(ixmlNode_getNextSibling(n), tagname, list);
    }
}
Beispiel #19
0
/**
 * Checks for all href attributes in the provided piece of XML and inserts
 * @a /obix prefix if necessary to all URI's which are absolute.
 */
static void insertDefaultUriPrefix(IXML_Node* node)
{
    if (node == NULL)
        return;	// exit point for the recursion

    // if this node is element and has 'href' attribute than check it:
    IXML_Element* element = ixmlNode_convertToElement(node);
    if (element != NULL)
    {
        const char* href = ixmlElement_getAttribute(element, OBIX_ATTR_HREF);
        if ((href != NULL) && (*href == '/'))
        {
            // href attribute points to the server root
            // check whether it starts with /obix/
            if (strncmp(href,
                        DEFAULT_URI_PREFIX,
                        DEFAULT_URI_PREFIX_LENGTH) != 0)
            {
                // let's add /obix prefix
                char newHref[strlen(href) + DEFAULT_URI_PREFIX_LENGTH + 1];
                strcpy(newHref, DEFAULT_URI_PREFIX);
                strcpy(newHref + DEFAULT_URI_PREFIX_LENGTH, href);
                int error = ixmlElement_setAttribute(element,
                                                     OBIX_ATTR_HREF,
                                                     newHref);
                if (error != IXML_SUCCESS)
                {
                    log_warning("Unable to update \"%s\" attribute of the object "
                                "before storing it: ixmlElement_setAttribute "
                                "returned %d.", OBIX_ATTR_HREF, error);
                }
            }
        }
    }

    // search also in child and neighbor tags
    insertDefaultUriPrefix(ixmlNode_getFirstChild(node));
    insertDefaultUriPrefix(ixmlNode_getNextSibling(node));
}
Beispiel #20
0
static IXML_Element*
findFirstElementRecursive (const IXML_Node* const node, 
			   const char* const tagname,
			   bool const deep)
{
	IXML_Element* res = NULL;
	IXML_Node* n = ixmlNode_getFirstChild (discard_const_p (IXML_Node, 
								node));
	while (n && !res) {
		if (ixmlNode_getNodeType (n) == eELEMENT_NODE) {
			const char* const name = ixmlNode_getNodeName (n);
			if (name && strcmp (tagname, name) == 0) {
				res = (IXML_Element*) n;
			}
		}
		if (deep && !res) {
			res = findFirstElementRecursive (n, tagname, deep);
		}
		n = ixmlNode_getNextSibling (n);
	}
	return res;
}
/*================================================================
*   ixmlNode_getElementsByTagNameRecursive
*       Recursively traverse the whole tree, search for element
*       with the given tagname.
*       Internal to parser.
*
*=================================================================*/
void
ixmlNode_getElementsByTagNameRecursive( IN IXML_Node * n,
                                        IN char *tagname,
                                        OUT IXML_NodeList ** list )
{
    const char *name;

    if( n != NULL ) {
        if( ixmlNode_getNodeType( n ) == eELEMENT_NODE ) {
            name = ixmlNode_getNodeName( n );
            if( strcmp( tagname, name ) == 0
                || strcmp( tagname, "*" ) == 0 ) {
                ixmlNodeList_addToNodeList( list, n );
            }
        }

        ixmlNode_getElementsByTagNameRecursive( ixmlNode_getFirstChild
                                                ( n ), tagname, list );
        ixmlNode_getElementsByTagNameRecursive( ixmlNode_getNextSibling
                                                ( n ), tagname, list );
    }

}
Beispiel #22
0
char *
upnp_get_string (struct Upnp_Action_Request *request, const char *key)
{
  IXML_Node *node = NULL;

  if (!request || !request->ActionRequest || !key)
    return NULL;

  node = (IXML_Node *) request->ActionRequest;
  if (!node)
  {
    log_verbose ("Invalid action request document\n");
    return NULL;
  }

  node = ixmlNode_getFirstChild (node);
  if (!node)
  {
    log_verbose ("Invalid action request document\n");
    return NULL;
  }

  node = ixmlNode_getFirstChild (node);
  for (; node; node = ixmlNode_getNextSibling (node))
    if (!strcmp (ixmlNode_getNodeName (node), key))
    {
      node = ixmlNode_getFirstChild (node);
      if (!node)
        return strdup ("");
      return strdup (ixmlNode_getNodeValue (node));
    }

  log_verbose ("Missing action request argument (%s)\n", key);

  return NULL;
}
Beispiel #23
0
/*================================================================
*	ixmlPrintDomTreeRecursive
*       It is a recursive function to print all the node in a tree.
*       Internal to parser only.
*
*=================================================================*/
void
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
                           IN ixml_membuf * buf )
{
    char *nodeName = NULL;
    char *nodeValue = NULL;
    IXML_Node *child = NULL,
     *sibling = NULL;

    if( nodeptr != NULL ) {
        nodeName = ( char * )ixmlNode_getNodeName( nodeptr );
        nodeValue = ixmlNode_getNodeValue( nodeptr );

        switch ( ixmlNode_getNodeType( nodeptr ) ) {

            case eTEXT_NODE:
                copy_with_escape( buf, nodeValue );
                break;

            case eCDATA_SECTION_NODE:
                ixml_membuf_append_str( buf, nodeValue );
                break;

            case ePROCESSING_INSTRUCTION_NODE:
                ixml_membuf_append_str( buf, "<?" );
                ixml_membuf_append_str( buf, nodeName );
                ixml_membuf_append_str( buf, " " );
                ixml_membuf_append_str( buf, nodeValue );
                ixml_membuf_append_str( buf, "?>\n" );
                break;

            case eDOCUMENT_NODE:
                ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
                                           ( nodeptr ), buf );
                break;

            case eATTRIBUTE_NODE:
                ixml_membuf_append_str( buf, nodeName );
                ixml_membuf_append_str( buf, "=\"" );
                if( nodeValue != NULL ) {
                    ixml_membuf_append_str( buf, nodeValue );
                }
                ixml_membuf_append_str( buf, "\"" );
                if( nodeptr->nextSibling != NULL ) {
                    ixml_membuf_append_str( buf, " " );
                    ixmlPrintDomTreeRecursive( nodeptr->nextSibling, buf );
                }
                break;

            case eELEMENT_NODE:
                ixml_membuf_append_str( buf, "<" );
                ixml_membuf_append_str( buf, nodeName );

                if( nodeptr->firstAttr != NULL ) {
                    ixml_membuf_append_str( buf, " " );
                    ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
                }

                child = ixmlNode_getFirstChild( nodeptr );
                if( ( child != NULL )
                    && ( ixmlNode_getNodeType( child ) ==
                         eELEMENT_NODE ) ) {
                    ixml_membuf_append_str( buf, ">\n" );
                } else {
                    ixml_membuf_append_str( buf, ">" );
                }

                //  output the children
                ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
                                           ( nodeptr ), buf );

                // Done with children.  Output the end tag.
                ixml_membuf_append_str( buf, "</" );
                ixml_membuf_append_str( buf, nodeName );

                sibling = ixmlNode_getNextSibling( nodeptr );
                if( sibling != NULL
                    && ixmlNode_getNodeType( sibling ) == eTEXT_NODE ) {
                    ixml_membuf_append_str( buf, ">" );
                } else {
                    ixml_membuf_append_str( buf, ">\n" );
                }
                ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling
                                           ( nodeptr ), buf );
                break;

            default:
                break;
        }
    }
}
Beispiel #24
0
RTPXML_Node* rtpxmlNode_getNextSibling(RTPXML_Node *nodeptr)
{
	return (RTPXML_Node *)ixmlNode_getNextSibling((IXML_Node *)nodeptr);
}
Beispiel #25
0
/*!
 * \brief Recursive function to print all the node in a tree.
 * Internal to parser only.
 */
static void ixmlPrintDomTreeRecursive(
	/*! [in] \todo documentation. */
	IXML_Node *nodeptr,
	/*! [in] \todo documentation. */
	ixml_membuf *buf)
{
	const char *nodeName = NULL;
	const char *nodeValue = NULL;
	IXML_Node *child = NULL,
	*sibling = NULL;

	if (nodeptr != NULL) {
		nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
		nodeValue = ixmlNode_getNodeValue(nodeptr);
		
		switch (ixmlNode_getNodeType(nodeptr)) {
		case eTEXT_NODE:
			copy_with_escape(buf, nodeValue);
			break;

		case eCDATA_SECTION_NODE:
			ixml_membuf_append_str(buf, "<![CDATA[");
			ixml_membuf_append_str(buf, nodeValue);
			ixml_membuf_append_str(buf, "]]>");
			break;

		case ePROCESSING_INSTRUCTION_NODE:
			ixml_membuf_append_str(buf, "<?");
			ixml_membuf_append_str(buf, nodeName);
			ixml_membuf_append_str(buf, " ");
			copy_with_escape(buf, nodeValue);
			ixml_membuf_append_str(buf, "?>\n");
			break;

		case eDOCUMENT_NODE:
			ixmlPrintDomTreeRecursive(
				ixmlNode_getFirstChild(nodeptr), buf);
			break;

		case eATTRIBUTE_NODE:
			ixml_membuf_append_str(buf, nodeName);
			ixml_membuf_append_str(buf, "=\"");
			copy_with_escape(buf, nodeValue);
			ixml_membuf_append_str(buf, "\"");
			if (nodeptr->nextSibling != NULL) {
				ixml_membuf_append_str(buf, " ");
				ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf);
			}
			break;

		case eELEMENT_NODE:
			ixml_membuf_append_str(buf, "<");
			ixml_membuf_append_str(buf, nodeName);
			if (nodeptr->firstAttr != NULL) {
				ixml_membuf_append_str(buf, " ");
				ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
			}
			child = ixmlNode_getFirstChild(nodeptr);
			if (child != NULL &&
			    ixmlNode_getNodeType(child) == eELEMENT_NODE) {
				ixml_membuf_append_str(buf, ">\r\n");
			} else {
				ixml_membuf_append_str(buf, ">");
			}
			//  output the children
			ixmlPrintDomTreeRecursive(
				ixmlNode_getFirstChild(nodeptr), buf);

			// Done with children.  Output the end tag.
			ixml_membuf_append_str(buf, "</");
			ixml_membuf_append_str(buf, nodeName);

			sibling = ixmlNode_getNextSibling(nodeptr);
			if (sibling != NULL &&
			    ixmlNode_getNodeType(sibling) == eTEXT_NODE) {
				ixml_membuf_append_str( buf, ">" );
			} else {
				ixml_membuf_append_str( buf, ">\r\n" );
			}
			ixmlPrintDomTreeRecursive(
				ixmlNode_getNextSibling(nodeptr), buf);
			break;

		default:
			IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: "
				"Warning, unknown node type %d\n",
				__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
			break;
		}
	}
}
Beispiel #26
0
/*
	Function:Prints a callback event type as a string;
	INPUT:
		S -- The callback event;
	SUCCESS:0;
	ERROR:-1;		
*/
int
PrintEvent( IN Upnp_EventType EventType,
                       IN void *Event )
{

    ithread_mutex_lock( &display_mutex );

    SA_Print
        ( "\n\n\n======================================================================\n" );
    SA_Print
        ( "----------------------------------------------------------------------\n" );
    PrintEventType( EventType );

    switch ( EventType ) {

            /*
               SSDP 
             */
        case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
        case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
        case UPNP_DISCOVERY_SEARCH_RESULT:
            {
                struct Upnp_Discovery *d_event =
                    ( struct Upnp_Discovery * )Event;

                SA_Print( "ErrCode     =  %d\n",
                                  d_event->ErrCode );
                SA_Print( "Expires     =  %d\n",
                                  d_event->Expires );
                SA_Print( "DeviceId    =  %s\n",
                                  d_event->DeviceId );
                SA_Print( "DeviceType  =  %s\n",
                                  d_event->DeviceType );
                SA_Print( "ServiceType =  %s\n",
                                  d_event->ServiceType );
                SA_Print( "ServiceVer  =  %s\n",
                                  d_event->ServiceVer );
                SA_Print( "Location    =  %s\n",
                                  d_event->Location );
	

                SA_Print( "OS          =  %s\n", d_event->Os );
                SA_Print( "Ext         =  %s\n", d_event->Ext );
	
		sem_post(&ServerSem);

            }
            break;

        case UPNP_DISCOVERY_SEARCH_TIMEOUT:
            // Nothing to print out here
            break;

            /*
               SOAP 
             */
        case UPNP_CONTROL_ACTION_REQUEST:
            {
                struct Upnp_Action_Request *a_event =
                    ( struct Upnp_Action_Request * )Event;
                char *xmlbuff = NULL;

                SA_Print( "ErrCode     =  %d\n",
                                  a_event->ErrCode );
                SA_Print( "ErrStr      =  %s\n", a_event->ErrStr );
                SA_Print( "ActionName  =  %s\n",
                                  a_event->ActionName );
                SA_Print( "UDN         =  %s\n", a_event->DevUDN );
                SA_Print( "ServiceID   =  %s\n",
                                  a_event->ServiceID );
                if( a_event->ActionRequest ) {
                    xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );	
			
                    if( xmlbuff )
                        SA_Print( "ActRequest  =  %s\n", xmlbuff );
                    if( xmlbuff )
                        ixmlFreeDOMString( xmlbuff );
                    xmlbuff = NULL;
                } else {
                    SA_Print( "ActRequest  =  (null)\n" );
                }

                if( a_event->ActionResult ) {
                    xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
                    if( xmlbuff )
                        SA_Print( "ActResult   =  %s\n", xmlbuff );
                    if( xmlbuff )
                        ixmlFreeDOMString( xmlbuff );
                    xmlbuff = NULL;
                } else {
                    SA_Print( "ActResult   =  (null)\n" );
                }
            }
            break;

        case UPNP_CONTROL_ACTION_COMPLETE:
            {
                struct Upnp_Action_Complete *a_event =
                    ( struct Upnp_Action_Complete * )Event;
                char *xmlbuff = NULL;

                SA_Print( "ErrCode     =  %d\n",
                                  a_event->ErrCode );
                SA_Print( "CtrlUrl     =  %s\n",
                                  a_event->CtrlUrl );

                if( a_event->ActionRequest ) {
                    xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
                    if( xmlbuff )
                        SA_Print( "ActRequest  =  %s\n", xmlbuff );
                    if( xmlbuff )
                        ixmlFreeDOMString( xmlbuff );
                    xmlbuff = NULL;
                } else {
                    SA_Print( "ActRequest  =  (null)\n" );
                }

                if( a_event->ActionResult ) 
		{
		    xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
                    if( xmlbuff )
                        SA_Print( "ActResult   =  %s\n", xmlbuff );

		if(strncmp(NowCommand,"Browse",6) == 0)
		{

			FNode *Now = (FNode *)malloc(sizeof(FNode));

			FNode *Last = NowNode;

			NowNode -> LeftChild = Now;		

			IXML_Document *document = ixmlParseBuffer(XMLP_GetFirstDocumentItem(a_event->ActionResult,"Result"));

			IXML_NodeList *ContainerList = ixmlElement_getElementsByTagName( ( IXML_Element * ) document, "container" );

			IXML_Node *ContainerNode = ixmlNodeList_item(ContainerList,0);

			IXML_NodeList *FileList = ixmlElement_getElementsByTagName( ( IXML_Element * ) document, "item" );

			IXML_Node *FileNode = ixmlNodeList_item(FileList,0);

			int ContainerLength = ixmlNodeList_length(ContainerList);

			int FileLength = ixmlNodeList_length(FileList);
		
			if(ContainerLength)
			{

				int i=0;
	
				for(i=0;i<ContainerLength;i++)
				{		

					char *Container_id = ixmlElement_getAttribute(( IXML_Element * ) ContainerNode,"id");

					IXML_NodeList *Title = ixmlElement_getElementsByTagName( ( IXML_Element * ) ContainerNode, "dc:title" );
	
					IXML_Node *TitleNode = ixmlNodeList_item(Title,0);

					TitleNode= ixmlNode_getFirstChild(TitleNode);

					char *TitleName = strdup(ixmlNode_getNodeValue(TitleNode));

					SA_Print("%s %s\n", Container_id,TitleName);

					Now -> Type = 0;

					strcpy(Now -> Name,TitleName);

					strcpy(Now -> Url,Container_id);

					Now -> LeftChild = NULL;
			
					Now -> Brother = NULL;

					Now -> Brother = (FNode *)malloc(sizeof(FNode));

					Last = Now;

					Now = Now -> Brother;

					ContainerNode = ixmlNode_getNextSibling(ContainerNode);
			
				}

			}

			if(FileLength)
			{	

				int j=0;	

				for(j=0;j<FileLength;j++)
				{		

					IXML_NodeList *Path = ixmlElement_getElementsByTagName( ( IXML_Element * ) FileNode, "res" );
	
					IXML_Node *PathNode = ixmlNodeList_item(Path,0);

					PathNode= ixmlNode_getFirstChild(PathNode);

					char *PathName = strdup(ixmlNode_getNodeValue(PathNode));

					IXML_NodeList *Title = ixmlElement_getElementsByTagName( ( IXML_Element * ) FileNode, "dc:title" );
	
					IXML_Node *TitleNode = ixmlNodeList_item(Title,0);

					TitleNode= ixmlNode_getFirstChild(TitleNode);

					char *TitleName = strdup(ixmlNode_getNodeValue(TitleNode));

					SA_Print( "%s %s\n", PathName,TitleName);

					Now -> Type = 1;

					strcpy(Now -> Name,TitleName);

					strcpy(Now -> Url,PathName);

					Now -> LeftChild = NULL;
			
					Now -> Brother = NULL;

					Now -> Brother = (FNode *)malloc(sizeof(FNode));

					Last = Now;	

					Now = Now -> Brother;
			
					FileNode = ixmlNode_getNextSibling(FileNode);
			
				}
					
			}

			Last -> Brother = NULL;

			Last -> LeftChild = NULL;

			free(Now);

			Now = NULL;


		}

                if( xmlbuff )
	        {
                      	ixmlFreeDOMString( xmlbuff );
                   	xmlbuff = NULL;
                }


		}
		else 
		{
                    SA_Print( "ActResult   =  (null)\n" );
                }

		sem_post(&BrowseSem);

            }
            break;

            /*
               GENA 
             */
        case UPNP_EVENT_SUBSCRIPTION_REQUEST:
            {
                struct Upnp_Subscription_Request *sr_event =
                    ( struct Upnp_Subscription_Request * )Event;

                SA_Print( "ServiceID   =  %s\n",
                                  sr_event->ServiceId );
                SA_Print( "UDN         =  %s\n", sr_event->UDN );
                SA_Print( "SID         =  %s\n", sr_event->Sid );
            }
            break;

        case UPNP_EVENT_RECEIVED:
            break;

        case UPNP_EVENT_RENEWAL_COMPLETE:
            {
                struct Upnp_Event_Subscribe *es_event =
                    ( struct Upnp_Event_Subscribe * )Event;

                SA_Print( "SID         =  %s\n", es_event->Sid );
                SA_Print( "ErrCode     =  %d\n",
                                  es_event->ErrCode );
                SA_Print( "TimeOut     =  %d\n",
                                  es_event->TimeOut );
            }
            break;

        case UPNP_EVENT_SUBSCRIBE_COMPLETE:
        case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
            {
                struct Upnp_Event_Subscribe *es_event =
                    ( struct Upnp_Event_Subscribe * )Event;

                SA_Print( "SID         =  %s\n", es_event->Sid );
                SA_Print( "ErrCode     =  %d\n",
                                  es_event->ErrCode );
                SA_Print( "PublisherURL=  %s\n",
                                  es_event->PublisherUrl );
                SA_Print( "TimeOut     =  %d\n",
                                  es_event->TimeOut );
            }
            break;

        case UPNP_EVENT_AUTORENEWAL_FAILED:
        case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
            {
                struct Upnp_Event_Subscribe *es_event =
                    ( struct Upnp_Event_Subscribe * )Event;

                SA_Print( "SID         =  %s\n", es_event->Sid );
                SA_Print( "ErrCode     =  %d\n",
                                  es_event->ErrCode );
                SA_Print( "PublisherURL=  %s\n",
                                  es_event->PublisherUrl );
                SA_Print( "TimeOut     =  %d\n",
                                  es_event->TimeOut );
            }
            break;
	default:
	    break;
    }
    SA_Print
        ( "----------------------------------------------------------------------\n" );
    SA_Print
        ( "======================================================================\n\n\n\n" );

    ithread_mutex_unlock( &display_mutex );
    return ( 0 );
}
/**************************************************************************
* Function: prepareParameter
* Functionality: it will get the parameter from pipe and check it
* @IN : fd: the file description id for the pipe
*      enable: enable or disable flag
* @OUT: 0 success, else failed.
* Used description:
    The parameter is a xml, it will get from the pipe
* Date: 20080108
* Changed history:
* Date 		Who		Reason
* 20080108	kelly  		First  creation
***************************************************************************/
int prepareParameter(PSystemConfig **pList,int *count)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_NodeList   *nodeList2 = NULL;
    IXML_Node       *node = NULL;
    IXML_Node       *cmdNode = NULL;
    char buffer[1024] = {0};
    char Str[1024] = {0};
    int i = 0;
	int nodeLen = 0;
	PSystemConfig *pConfigList  = NULL;

    while(1)
    {
        fgets(Str, 1024, stdin);
        strcat(buffer, Str);
        if(strstr(buffer,EndFlag))
            break;
    }

	if(strlen(buffer) == 0)
		goto failed;

	if((rootDom = ixmlParseBuffer(buffer)) == NULL)
		goto failed;
	if((nodeList = ixmlDocument_getElementsByTagName(rootDom,"cmd")) != NULL) 
	{
		cmdNode   = ixmlGetFirstNodeByTagName(rootDom,"cmd");
		nodeList2 = ixmlNode_getChildNodes(cmdNode);
		nodeLen   = ixmlNodeList_length(nodeList2);
/*        fprintf(stderr, "=======nodeLen -> [%d]\n", nodeLen);*/
		pConfigList = (PSystemConfig*)malloc(sizeof(PSystemConfig) * nodeLen);
		memset(pConfigList, 0, sizeof(PSystemConfig)*nodeLen);

		node = ixmlNodeList_item(nodeList, 0);
		node = ixmlNode_getFirstChild(node);
		for(i=0; i<nodeLen; i++) {
			if(node){
				pConfigList[i] = (PSystemConfig)malloc(sizeof(SystemConfig));
				memset(pConfigList[i],0,sizeof(SystemConfig));
				pConfigList[i]->name = strdup(ixmlNode_getNodeName(node));
				if(i != nodeLen-1)
				node = ixmlNode_getNextSibling(node);
			}
			else{
				fprintf(stderr, "===== node is empty. i->[%d]\n", i);
			}
		}
	}

	*count = nodeLen;

	if(pConfigList){
		*pList = pConfigList;
	}
	else{
		fprintf(stderr, " !!!!!!pLIST is NULL");
	}

	if (rootDom)
		ixmlDocument_free(rootDom);
	if (nodeList)
		ixmlNodeList_free(nodeList);
	if (nodeList2)
		ixmlNodeList_free(nodeList2);
	return i;

failed:
        fprintf(stderr,"Got a command parameter->%s", buffer);
        //fprintf(stderr,"Got a command parameter->%s", buffer);
    return i;
}
/**************************************************************************
* Function: prepareParameter
* Functionality: it will get the parameter from pipe and check it
* @IN : fd: the file description id for the pipe
*      enable: enable or disable flag
* @OUT: 0 success, else failed.
* Used description:
    The parameter is a xml, it will get from the pipe
* Date: 20080108
* Changed history:
* Date 		Who		Reason
* 20080108	kelly  		First  creation
***************************************************************************/
int prepareParameter(PSystemConfig **pList,int *count)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_NodeList   *nodeList2 = NULL;
    IXML_Node       *node = NULL;
    IXML_Node       *cmdNode = NULL;
	IXML_Node       *node2 = NULL;
    char buffer[1024] = {0};
    char Str[1024] = {0};
    int i = 0;
	int i_ret=0;
	int nodeLen = 0;
	PSystemConfig *pConfigList = NULL;

    while(1)
    {
        fgets(Str, 1024, stdin);
        strcat(buffer, Str);
        if(strstr(buffer,EndFlag))
            break;
    }

    if(strlen(buffer) == 0)
        goto failed;

    if((rootDom = ixmlParseBuffer(buffer)) == NULL){
		i_ret = -1;
		goto Err_handler;
	}

	if((nodeList = ixmlDocument_getElementsByTagName(rootDom,"cmd")) != NULL) 
	{
		cmdNode   = ixmlGetFirstNodeByTagName(rootDom,"cmd");
		nodeList2 = ixmlNode_getChildNodes(cmdNode);
		nodeLen   = ixmlNodeList_length(nodeList2);

		pConfigList = (PSystemConfig*)malloc(sizeof(PSystemConfig) * nodeLen);
		memset(pConfigList, 0, sizeof(PSystemConfig)*nodeLen);

		node = ixmlNodeList_item(nodeList, 0);
		node = ixmlNode_getFirstChild(node);
		while (node != NULL)
		{
			pConfigList[i] = (PSystemConfig)malloc(sizeof(SystemConfig));
			memset(pConfigList[i],0,sizeof(SystemConfig));						
			pConfigList[i]->name = strdup(ixmlNode_getNodeName(node));


			node2 = ixmlNode_getFirstChild(node);
			pConfigList[i]->value = (ixmlNode_getNodeValue(node2))?strdup(ixmlNode_getNodeValue(node2)):strdup("");

/*            fprintf(stderr, "name->%s , value ->%s\n" , pConfigList[i]->name , pConfigList[i]->value);		*/

			i_ret=CheckVariable(pConfigList[i]->name,pConfigList[i]->value);
			if(i_ret<0)
			{
				i_ret = -3;
				goto Err_handler;
			}

			node = ixmlNode_getNextSibling(node);
			i++;
		}
	}

	*count = nodeLen;

	if(pConfigList){
		*pList = pConfigList;
	}
	else{
		fprintf(stderr, " !!!!!!pLIST is NULL");
	}

	if (rootDom)
        ixmlDocument_free(rootDom);
    if (nodeList)
        ixmlNodeList_free(nodeList);
    if (nodeList2)
        ixmlNodeList_free(nodeList2);
    return i;

failed:
        fprintf(stderr,"Got a command parameter->%s", buffer);
        //fprintf(stderr,"Got a command parameter->%s", buffer);
		return i;
Err_handler:
		if (rootDom)
			ixmlDocument_free(rootDom);
		if (nodeList)
			ixmlNodeList_free(nodeList);
		if (nodeList2)
			ixmlNodeList_free(nodeList2);
		return i_ret;
}
Beispiel #29
0
/**
 * Helper function for #getNodeByHref(IXML_Document*,const char*).
 *
 * @param checked specifies number of symbols from href which are already
 * checked (and match) in parent node.
 */
static IXML_Node* getNodeByHrefRecursive(IXML_Node* node, const char* href,
        int checked, int* slashFlag)
{
    if (node == NULL)
    {
        //recursion exit point
        return NULL;
    }

    IXML_Node* match = NULL;
    IXML_Element* element = ixmlNode_convertToElement(node);
    int compareResult = 0;
    // ignore all nodes which are not tags, are reference tags
    // or do not have 'href' attribute
    if (element != NULL)
    {
        const char* currentUri =
            ixmlElement_getAttribute(element, OBIX_ATTR_HREF);
        if ((strcmp(ixmlElement_getTagName(element), OBIX_OBJ_REF) != 0)
                && (currentUri != NULL))
        {
            compareResult = compare_uri(currentUri, href, checked, slashFlag);
            if (compareResult == 0)
            {
                // we found the required node
                return node;
            }
        }
    }

    // check children
    // note that compareResult == 0 means that URI's
    // were not compared at all
    if (compareResult == 0)
    {
        match = getNodeByHrefRecursive(ixmlNode_getFirstChild(node),
                                       href,
                                       checked,
                                       slashFlag);
    }
    else if (compareResult > 0)
    {
        // we found part of the uri on this step
        // continue search in children the remaining address
        match = getNodeByHrefRecursive(ixmlNode_getFirstChild(node),
                                       href,
                                       compareResult,
                                       slashFlag);
    }
    // do not check children if compareResult < 0

    if (match == NULL)
    {
        match = getNodeByHrefRecursive(ixmlNode_getNextSibling(node),
                                       href,
                                       checked,
                                       slashFlag);
    }

    return match;
}
Beispiel #30
0
int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
		      enum SsdpSearchType SearchType,
		      struct sockaddr *DestAddr, char *DeviceType,
		      char *DeviceUDN, char *ServiceType, int Exp)
{
	int retVal = UPNP_E_SUCCESS;
	long unsigned int i;
	long unsigned int j;
	int defaultExp = DEFAULT_MAXAGE;
	struct Handle_Info *SInfo = NULL;
	char UDNstr[100];
	char devType[100];
	char servType[100];
	IXML_NodeList *nodeList = NULL;
	IXML_NodeList *tmpNodeList = NULL;
	IXML_Node *tmpNode = NULL;
	IXML_Node *tmpNode2 = NULL;
	IXML_Node *textNode = NULL;
	const DOMString tmpStr;
	const DOMString dbgStr;
	int NumCopy = 0;

	memset(UDNstr, 0, sizeof(UDNstr));
	memset(devType, 0, sizeof(devType));
	memset(servType, 0, sizeof(servType));

	UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
		   "Inside AdvertiseAndReply with AdFlag = %d\n", AdFlag);

	/* Use a read lock */
	HandleReadLock();
	if (GetHandleInfo(Hnd, &SInfo) != HND_DEVICE) {
		retVal = UPNP_E_INVALID_HANDLE;
		goto end_function;
	}
	defaultExp = SInfo->MaxAge;
	/* parse the device list and send advertisements/replies */
	while (NumCopy == 0 || (AdFlag && NumCopy < NUM_SSDP_COPY)) {
		if (NumCopy != 0)
			imillisleep(SSDP_PAUSE);
		NumCopy++;
		for (i = 0lu;; i++) {
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Entering new device list with i = %lu\n\n",
				   i);
			tmpNode = ixmlNodeList_item(SInfo->DeviceList, i);
			if (!tmpNode) {
				UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
					   "Exiting new device list with i = %lu\n\n",
					   i);
				break;
			}
			dbgStr = ixmlNode_getNodeName(tmpNode);
			UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
				   "Extracting device type once for %s\n",
				   dbgStr);
			ixmlNodeList_free(nodeList);
			nodeList = ixmlElement_getElementsByTagName((IXML_Element *) tmpNode, "deviceType");
			if (!nodeList)
				continue;
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Extracting UDN for %s\n", dbgStr);
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Extracting device type\n");
			tmpNode2 = ixmlNodeList_item(nodeList, 0lu);
			if (!tmpNode2)
				continue;
			textNode = ixmlNode_getFirstChild(tmpNode2);
			if (!textNode)
				continue;
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Extracting device type \n");
			tmpStr = ixmlNode_getNodeValue(textNode);
			if (!tmpStr)
				continue;
			strncpy(devType, tmpStr, sizeof(devType) - 1);
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Extracting device type = %s\n", devType);
			if (!tmpNode) {
				UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
					   "TempNode is NULL\n");
			}
			dbgStr = ixmlNode_getNodeName(tmpNode);
			UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
				   "Extracting UDN for %s\n", dbgStr);
			ixmlNodeList_free(nodeList);
			nodeList = ixmlElement_getElementsByTagName((IXML_Element *) tmpNode, "UDN");
			if (!nodeList) {
				UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
					   __LINE__, "UDN not found!\n");
				continue;
			}
			tmpNode2 = ixmlNodeList_item(nodeList, 0lu);
			if (!tmpNode2) {
				UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
					   __LINE__, "UDN not found!\n");
				continue;
			}
			textNode = ixmlNode_getFirstChild(tmpNode2);
			if (!textNode) {
				UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
					   __LINE__, "UDN not found!\n");
				continue;
			}
			tmpStr = ixmlNode_getNodeValue(textNode);
			if (!tmpStr) {
				UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
					   __LINE__, "UDN not found!\n");
				continue;
			}
			strncpy(UDNstr, tmpStr, sizeof(UDNstr) - 1);
			UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
				   "Sending UDNStr = %s \n", UDNstr);
			if (AdFlag) {
				/* send the device advertisement */
				if (AdFlag == 1) {
                    DeviceAdvertisement(devType, i == 0lu, NumCopy - 1,
							    UDNstr,
							    SInfo->DescURL, Exp,
							    SInfo->DeviceAf,
							    SInfo->PowerState,
	                                                    SInfo->SleepPeriod,
	                                                    SInfo->RegistrationState);
				} else {
					/* AdFlag == -1 */
                    DeviceShutdown(devType, i == 0lu, NumCopy - 1, UDNstr,
						       SInfo->DescURL,
						       Exp, SInfo->DeviceAf,
						       SInfo->PowerState,
						       SInfo->SleepPeriod,
						       SInfo->RegistrationState);
				}
			} else {
				switch (SearchType) {
				case SSDP_ALL:
                    DeviceReply(DestAddr, devType, i == 0lu, NumCopy - 1,
						    UDNstr, SInfo->DescURL,
						    defaultExp, SInfo->PowerState,
						    SInfo->SleepPeriod,
						    SInfo->RegistrationState);
					break;
				case SSDP_ROOTDEVICE:
					if (i == 0lu) {
                        SendReply(DestAddr, devType, 1, NumCopy - 1,
							  UDNstr,
							  SInfo->DescURL,
							  defaultExp, 0,
							  SInfo->PowerState,
							  SInfo->SleepPeriod,
							  SInfo->RegistrationState);
					}
					break;
				case SSDP_DEVICEUDN: {
					if (DeviceUDN && strlen(DeviceUDN) != (size_t)0) {
						if (strcasecmp(DeviceUDN, UDNstr)) {
							UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
								"DeviceUDN=%s and search UDN=%s DID NOT match\n",
								UDNstr, DeviceUDN);
							break;
						} else {
							UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
								"DeviceUDN=%s and search UDN=%s MATCH\n",
								UDNstr, DeviceUDN);
                            SendReply(DestAddr, devType, 0, NumCopy - 1, UDNstr, SInfo->DescURL, defaultExp, 0,
								SInfo->PowerState,
								SInfo->SleepPeriod,
								SInfo->RegistrationState);
							break;
						}
					}
				}
				case SSDP_DEVICETYPE: {
					if (!strncasecmp(DeviceType, devType, strlen(DeviceType) - (size_t)2)) {
						if (atoi(strrchr(DeviceType, ':') + 1)
						    < atoi(&devType[strlen(devType) - (size_t)1])) {
							/* the requested version is lower than the device version
							 * must reply with the lower version number and the lower
							 * description URL */
							UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
								   "DeviceType=%s and search devType=%s MATCH\n",
								   devType, DeviceType);
                            SendReply(DestAddr, DeviceType, 0, NumCopy - 1, UDNstr, SInfo->LowerDescURL,
								  defaultExp, 1,
								  SInfo->PowerState,
								  SInfo->SleepPeriod,
								  SInfo->RegistrationState);
						} else if (atoi(strrchr(DeviceType, ':') + 1)
							   == atoi(&devType[strlen(devType) - (size_t)1])) {
							UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
								   "DeviceType=%s and search devType=%s MATCH\n",
								   devType, DeviceType);
                            SendReply(DestAddr, DeviceType, 0, NumCopy - 1, UDNstr, SInfo->DescURL,
								  defaultExp, 1,
								  SInfo->PowerState,
								  SInfo->SleepPeriod,
								  SInfo->RegistrationState);
						} else {
							UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
								   "DeviceType=%s and search devType=%s DID NOT MATCH\n",
								   devType, DeviceType);
						}
					} else {
						UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
							   "DeviceType=%s and search devType=%s DID NOT MATCH\n",
							   devType, DeviceType);
					}
					break;
				}
				default:
					break;
				}
			}
			/* send service advertisements for services corresponding
			 * to the same device */
			UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
				   "Sending service Advertisement\n");
			/* Correct service traversal such that each device's serviceList
			 * is directly traversed as a child of its parent device. This
			 * ensures that the service's alive message uses the UDN of
			 * the parent device. */
			tmpNode = ixmlNode_getFirstChild(tmpNode);
			while (tmpNode) {
				dbgStr = ixmlNode_getNodeName(tmpNode);
				if (!strncmp
				    (dbgStr, SERVICELIST_STR,
				     sizeof SERVICELIST_STR)) {
					break;
				}
				tmpNode = ixmlNode_getNextSibling(tmpNode);
			}
			ixmlNodeList_free(nodeList);
			if (!tmpNode) {
				nodeList = NULL;
				continue;
			}
			nodeList = ixmlElement_getElementsByTagName((IXML_Element *) tmpNode, "service");
			if (!nodeList) {
				UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
					   "Service not found 3\n");
				continue;
			}
			for (j = 0lu;; j++) {
				tmpNode = ixmlNodeList_item(nodeList, j);
				if (!tmpNode) {
					break;
				}
				ixmlNodeList_free(tmpNodeList);
				tmpNodeList = ixmlElement_getElementsByTagName((IXML_Element *) tmpNode, "serviceType");
				if (!tmpNodeList) {
					UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
						   __LINE__,
						   "ServiceType not found \n");
					continue;
				}
				tmpNode2 = ixmlNodeList_item(tmpNodeList, 0lu);
				if (!tmpNode2)
					continue;
				textNode = ixmlNode_getFirstChild(tmpNode2);
				if (!textNode)
					continue;
				/* servType is of format Servicetype:ServiceVersion */
				tmpStr = ixmlNode_getNodeValue(textNode);
				if (!tmpStr)
					continue;
				strncpy(servType, tmpStr, sizeof(servType) - 1);
				UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
					   "ServiceType = %s\n", servType);
				if (AdFlag) {
					if (AdFlag == 1) {
                        ServiceAdvertisement(NumCopy - 1, UDNstr,
							servType, SInfo->DescURL,
							Exp, SInfo->DeviceAf,
							SInfo->PowerState,
							SInfo->SleepPeriod,
							SInfo->RegistrationState);
					} else {
						/* AdFlag == -1 */
                        ServiceShutdown(NumCopy - 1, UDNstr,
							servType, SInfo->DescURL,
							Exp, SInfo->DeviceAf,
							SInfo->PowerState,
							SInfo->SleepPeriod,
							SInfo->RegistrationState);
					}
				} else {
					switch (SearchType) {
					case SSDP_ALL:
                        ServiceReply(DestAddr,
                                 servType,
                                 NumCopy - 1,
							     UDNstr,
							     SInfo->DescURL,
							     defaultExp,
							     SInfo->PowerState,
							     SInfo->SleepPeriod,
							     SInfo->RegistrationState);
						break;
					case SSDP_SERVICE:
						if (ServiceType) {
							if (!strncasecmp(ServiceType, servType, strlen(ServiceType) - (size_t)2)) {
								if (atoi(strrchr(ServiceType, ':') + 1) <
								    atoi(&servType[strlen(servType) - (size_t)1])) {
									/* the requested version is lower than the service version
									 * must reply with the lower version number and the lower
									 * description URL */
									UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
										   "ServiceType=%s and search servType=%s MATCH\n",
										   ServiceType, servType);
                                    SendReply(DestAddr, ServiceType, 0, NumCopy - 1, UDNstr, SInfo->LowerDescURL,
										  defaultExp, 1,
										  SInfo->PowerState,
										  SInfo->SleepPeriod,
										  SInfo->RegistrationState);
								} else if (atoi(strrchr (ServiceType, ':') + 1) ==
									   atoi(&servType[strlen(servType) - (size_t)1])) {
									UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
										   "ServiceType=%s and search servType=%s MATCH\n",
										   ServiceType, servType);
                                    SendReply(DestAddr, ServiceType, 0, NumCopy - 1, UDNstr, SInfo->DescURL,
										  defaultExp, 1,
										  SInfo->PowerState,
										  SInfo->SleepPeriod,
										  SInfo->RegistrationState);
								} else {
									UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
									   "ServiceType=%s and search servType=%s DID NOT MATCH\n",
									   ServiceType, servType);
								}
							} else {
								UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
									   "ServiceType=%s and search servType=%s DID NOT MATCH\n",
									   ServiceType, servType);
							}
						}
						break;
					default:
						break;
					}
				}
			}
			ixmlNodeList_free(tmpNodeList);
			tmpNodeList = NULL;
			ixmlNodeList_free(nodeList);
			nodeList = NULL;
		}
	}

end_function:
	ixmlNodeList_free(tmpNodeList);
	ixmlNodeList_free(nodeList);
	UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
		   "Exiting AdvertiseAndReply.\n");
	HandleUnlock();

	return retVal;
}