Пример #1
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_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 );

}
Пример #3
0
IXML_Element*
XMLUtil_FindFirstElement (const IXML_Node* const node,
			  const char* const tagname,
			  bool const deep, bool const log_error)
{
	IXML_Element* res = NULL;

	if (node == NULL || tagname == NULL) {
		Log_Printf (LOG_ERROR, 
			    "GetFirstElementByTagName invalid NULL parameter");
	} else {
		IXML_Node* const n = discard_const_p (IXML_Node, node);
		if (ixmlNode_getNodeType (n) == eELEMENT_NODE) {
			const char* const name = ixmlNode_getNodeName (n);
			if (name && strcmp (tagname, name) == 0) {
				res = (IXML_Element*) n;
			}
		}
		if (res == NULL) {
			res = findFirstElementRecursive (n, tagname, deep);
		}
		if (res == NULL) {
			Log_Printf ((log_error ? LOG_ERROR : LOG_DEBUG), 
				    "Can't find '%s' element in XML Node"
				    " (deep search=%d)", tagname, (int) deep);
		}
	}
	return res;
}
Пример #4
0
void printNodes(IXML_Node *tmpRoot, int depth)
{
    unsigned long i;
    IXML_NodeList *NodeList1;
    IXML_Node *ChildNode1;
    unsigned short NodeType;
    const DOMString NodeValue;
    const DOMString NodeName;
    NodeList1 = ixmlNode_getChildNodes(tmpRoot);
    for (i = 0; i < 100; ++i) {
        ChildNode1 = ixmlNodeList_item(NodeList1, i);
        if (ChildNode1 == NULL) {
            break;
        }
    
        printNodes(ChildNode1, depth+1);
        NodeType = ixmlNode_getNodeType(ChildNode1);
        NodeValue = ixmlNode_getNodeValue(ChildNode1);
        NodeName = ixmlNode_getNodeName(ChildNode1);
	IxmlPrintf(__FILE__, __LINE__, "printNodes",
            "DEPTH-%2d-IXML_Node Type %d, "
            "IXML_Node Name: %s, IXML_Node Value: %s\n",
            depth, NodeType, NodeName, NodeValue);
    }
}
Пример #5
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);
    }
}
Пример #6
0
/*================================================================
*   ixmlDocument_importNode
*       Imports a node from another document to this document. The
*       returned node has no parent; (parentNode is null). The source
*       node is not altered or removed from the original document;
*       this method creates a new copy of the source node.

*       For all nodes, importing a node creates a node object owned
*       by the importing document, with attribute values identical to
*       the source node's nodeName and nodeType, plus the attributes
*       related to namespaces (prefix, localName, and namespaceURI).
*       As in the cloneNode operation on a node, the source node is
*       not altered.
*
*       External function.
*
*=================================================================*/
int
ixmlDocument_importNode( IN IXML_Document * doc,
                         IN IXML_Node * importNode,
                         IN unsigned char deep,
                         OUT IXML_Node ** rtNode )
{
    unsigned short nodeType;
    IXML_Node *newNode;

    *rtNode = NULL;

    if( ( doc == NULL ) || ( importNode == NULL ) ) {
        return IXML_INVALID_PARAMETER;
    }

    nodeType = ixmlNode_getNodeType( importNode );
    if( nodeType == eDOCUMENT_NODE ) {
        return IXML_NOT_SUPPORTED_ERR;
    }

    newNode = ixmlNode_cloneNode( importNode, deep );
    if( newNode == NULL ) {
        return IXML_FAILED;
    }

    ixmlDocument_setOwnerDocument( doc, newNode );
    *rtNode = newNode;

    return IXML_SUCCESS;
}
Пример #7
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;
}
Пример #8
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;
}
Пример #9
0
const unsigned short rtpxmlNode_getNodeType(RTPXML_Node *nodeptr)
{
	/* We only test for type == eELEMENT_NODE in the source code so to retain separation of
	   datastructures between the application and the xml implementation test for that value only */
	if (ixmlNode_getNodeType((IXML_Node *)nodeptr) == eELEMENT_NODE)
		return (rtpxeELEMENT_NODE);
	else
		return(0);
}
Пример #10
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;
}
Пример #11
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;
}
Пример #12
0
/************************************************************************
*	Function :	getElementValue
*
*	Parameters :
*		IXML_Node *node ;	Input node which provides the list of child 
*							nodes
*
*	Description :	Returns the clone of the element value
*
*	Return : DOMString ;
*
*	Note : value must be freed with DOMString_free
************************************************************************/
DOMString
getElementValue( IXML_Node * node )
{
    IXML_Node *child = ( IXML_Node * ) ixmlNode_getFirstChild( node );
    const DOMString temp = NULL;

    if( ( child != 0 ) && ( ixmlNode_getNodeType( child ) == eTEXT_NODE ) ) {
        temp = ixmlNode_getNodeValue( child );
        return ixmlCloneDOMString( temp );
    } else {
        return NULL;
    }
}
Пример #13
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;
}
Пример #14
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;
}
Пример #15
0
Файл: node.c Проект: rxwen/pupnp
void ixmlNode_getElementsByTagName(
    IXML_Node *n,
    const char *tagname,
    IXML_NodeList **list)
{
    const char *name;

    assert(n != NULL && tagname != 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);
}
Пример #16
0
Файл: node.c Проект: rxwen/pupnp
/*!
 * \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);
    }
}
Пример #17
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;
}
Пример #18
0
/*================================================================
*   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 );
    }

}
Пример #19
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;
        }
    }
}
Пример #20
0
/*================================================================
*   ixmlDomTreetoString
*       Converts a DOM tree into a text string
*       Element, and Attribute nodes are handled differently.
*       We don't want to print the Element and Attribute nodes' sibling.
*       External function.
*
*=================================================================*/
void
ixmlDomTreetoString( IN IXML_Node * nodeptr,
                     IN ixml_membuf * buf )
{
    char *nodeName = NULL;
    char *nodeValue = NULL;
    IXML_Node *child = NULL;

    if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
        return;
    }

    nodeName = ( char * )ixmlNode_getNodeName( nodeptr );
    nodeValue = ixmlNode_getNodeValue( nodeptr );

    switch ( ixmlNode_getNodeType( nodeptr ) ) {

        case eTEXT_NODE:
        case eCDATA_SECTION_NODE:
        case ePROCESSING_INSTRUCTION_NODE:
        case eDOCUMENT_NODE:
            ixmlPrintDomTreeRecursive( nodeptr, buf );
            break;

        case eATTRIBUTE_NODE:
            ixml_membuf_append_str( buf, nodeName );
            ixml_membuf_append_str( buf, "=\"" );
            ixml_membuf_append_str( buf, nodeValue );
            ixml_membuf_append_str( 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, ">" );
            } 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 );
            ixml_membuf_append_str( buf, ">" );
            break;

        default:
            break;
    }
}
Пример #21
0
int WscUPnPCPHandleActionResponse(
	IN struct Upnp_Action_Complete *a_event)
{
	IXML_NodeList *nodeList = NULL, *msgNodeList = NULL;
	IXML_Node *element, *child = NULL;
	char *varName = NULL;
	struct upnpDeviceNode *nodePtr;
	
	char *inStr = NULL, *pWscU2KMsg = NULL;
	unsigned char *decodeStr = NULL;
	int i, decodeLen = 0, wscU2KMsgLen;
	
	unsigned int UPnPDevIP = 0;
			
	DBGPRINTF(RT_DBG_INFO, "ErrCode = %d, CtrlUrl=%s!\n", a_event->ErrCode, a_event->CtrlUrl);
	
	if(a_event->ActionResult == NULL || a_event->ErrCode != 0)
		return 0;

	// Check if this device is already in the list
	nodePtr = WscDeviceList;
	while (nodePtr)
	{
		if(strcmp(nodePtr->device.services.ControlURL, a_event->CtrlUrl) == 0)
		{
			UPnPDevIP = nodePtr->device.ipAddr;
			nodePtr->device.timeCount = nodePtr->device.AdvrTimeOut;
			break;
		}
		nodePtr = nodePtr->next;
    }
	if (UPnPDevIP == 0)
		goto done;
	DBGPRINTF(RT_DBG_INFO, "Find the ActionResponse Device IP=%x\n", UPnPDevIP);

	
	/*
		We just support following ActionResponse from remote device.
	*/
	for (i=0; i < CP_RESP_SUPPORT_LIST_NUM; i++)
	{
		DBGPRINTF(RT_DBG_INFO, "check actionResNames[%d]=%s!\n", i, actionResNames[i]);
		nodeList = ixmlDocument_getElementsByTagName(a_event->ActionResult, actionResNames[i]);
		if(nodeList){
			varName = stateVarNames[i];
			break;
		}
	}

	if(nodeList == NULL)
	{
		DBGPRINTF(RT_DBG_INFO, "UnSupportted ActResponse!\n");
		goto done;
	}
	
	if ((element = ixmlNodeList_item(nodeList, 0)))
	{
		//First check if we have supportted State Variable name!
		ixmlNode_getElementsByTagName(element, varName, &msgNodeList);
		if(msgNodeList != NULL)
		{
			DBGPRINTF(RT_DBG_INFO, "find stateVarName=%s!\n", varName);
			while((child = ixmlNode_getFirstChild(element))!= NULL)
			{	// Find the Response text content!
				if (ixmlNode_getNodeType(child) == eTEXT_NODE)
				{
					inStr = strdup(ixmlNode_getNodeValue(child));
					break;
				}
				element = child;
			}
			ixmlNodeList_free(msgNodeList);
		}
	}
	
	// Here depends on the ActionRequest and ActionResponse, dispatch to correct handler!
	if(inStr!= NULL)
	{
		DBGPRINTF(RT_DBG_INFO, "Receive a %s Message!\n", actionResNames[i]);
		DBGPRINTF(RT_DBG_INFO, "\tinStr=%s!\n", inStr);
		decodeLen = ILibBase64Decode((unsigned char *)inStr, strlen(inStr), &decodeStr);
		if((decodeLen > 0) && (ioctl_sock >= 0))
		{
			RTMP_WSC_U2KMSG_HDR *msgHdr;
			WscEnvelope *msgEnvelope;
			int msgQIdx = -1;
			 
			/* Prepare the msg buffers */
			wscU2KMsgLen = wscU2KMsgCreate(&pWscU2KMsg, (char *)decodeStr, decodeLen, EAP_FRAME_TYPE_WSC);
			if (wscU2KMsgLen == 0)
				goto done;

			/* Prepare the msg envelope */
			if ((msgEnvelope = wscEnvelopeCreate()) == NULL)
				goto done;
			msgEnvelope->callBack = wscCPPutMessage;
			
			/* Lock the msgQ and check if we can get a valid mailbox to insert our request! */
			if (wscMsgQInsert(msgEnvelope, &msgQIdx) != WSC_SYS_SUCCESS)
				goto done;

			// Fill the session ID to the U2KMsg buffer header.
			msgHdr = (RTMP_WSC_U2KMSG_HDR *)pWscU2KMsg;
			msgHdr->envID = msgEnvelope->envID;

			// copy the Addr1 & Addr2
			memcpy(msgHdr->Addr1, HostMacAddr, MAC_ADDR_LEN);
			memcpy(msgHdr->Addr2, &UPnPDevIP, sizeof(unsigned int));

			// Now send the msg to kernel space.
			DBGPRINTF(RT_DBG_INFO, "(%s):Ready to send pWscU2KMsg(len=%d) to kernel by ioctl(%d)!\n", __FUNCTION__, wscU2KMsgLen, ioctl_sock);
			//wsc_hexdump("U2KMsg", pWscU2KMsg, wscU2KMsgLen);
	
			if(wsc_set_oid(RT_OID_WSC_EAPMSG, pWscU2KMsg, wscU2KMsgLen) != 0)
				wscEnvelopeRemove(msgEnvelope, msgQIdx);
		}
	}


done:
	if (nodeList)
		ixmlNodeList_free(nodeList);
	if (inStr)
		free(inStr);
	if (pWscU2KMsg)
		free(pWscU2KMsg);
	if (decodeStr)
		free(decodeStr);
			
	//wsc_printEvent(UPNP_CONTROL_ACTION_COMPLETE, (void *)a_event);
	return 0;
}
Пример #22
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;
		}
	}
}