Backport of ixml from 1.8.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@478 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
881b212690
commit
812d019d12
2634
ixml/inc/ixml.h
2634
ixml/inc/ixml.h
File diff suppressed because it is too large
Load Diff
@ -1,60 +1,53 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* Function: Attr_init
|
||||
* Initializes an attribute node
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlAttr_init( IN IXML_Attr * attr )
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void ixmlAttr_init(IN IXML_Attr *attr)
|
||||
{
|
||||
if (attr != NULL) {
|
||||
memset(attr, 0, sizeof (IXML_Attr));
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* Function: Attr_free
|
||||
* Frees an attribute node.
|
||||
* external function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlAttr_free( IN IXML_Attr * attr )
|
||||
|
||||
void ixmlAttr_free(IN IXML_Attr *attr)
|
||||
{
|
||||
if (attr != NULL) {
|
||||
ixmlNode_free((IXML_Node *)attr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,119 +1,97 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmldebug.h"
|
||||
#include "ixmlparser.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_init
|
||||
* It initialize the document structure.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlDocument_init( IN IXML_Document * doc )
|
||||
void ixmlDocument_init(IXML_Document *doc)
|
||||
{
|
||||
memset(doc, 0, sizeof(IXML_Document));
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_free
|
||||
* It frees the whole document tree.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlDocument_free( IN IXML_Document * doc )
|
||||
|
||||
void ixmlDocument_free(IXML_Document *doc)
|
||||
{
|
||||
if (doc != NULL) {
|
||||
ixmlNode_free((IXML_Node *)doc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* 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.
|
||||
|
||||
/*!
|
||||
* 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 )
|
||||
*/
|
||||
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 ) );
|
||||
ixmlDocument_setOwnerDocument(
|
||||
doc, ixmlNode_getFirstChild(nodeptr));
|
||||
ixmlDocument_setOwnerDocument(
|
||||
doc, ixmlNode_getNextSibling(nodeptr));
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* 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 BOOL deep,
|
||||
OUT IXML_Node ** rtNode )
|
||||
int ixmlDocument_importNode(
|
||||
IXML_Document *doc,
|
||||
IXML_Node *importNode,
|
||||
BOOL deep,
|
||||
IXML_Node **rtNode)
|
||||
{
|
||||
unsigned short nodeType;
|
||||
IXML_Node *newNode;
|
||||
|
||||
*rtNode = NULL;
|
||||
|
||||
if( ( doc == NULL ) || ( importNode == NULL ) ) {
|
||||
if (doc == NULL || importNode == NULL) {
|
||||
return IXML_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@ -133,29 +111,16 @@ ixmlDocument_importNode( IN IXML_Document * doc,
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createElementEx
|
||||
* Creates an element of the type specified.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* doc: pointer to document
|
||||
* tagName: The name of the element, it is case-sensitive.
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INVALID_PARAMETER: if either doc or tagName is NULL
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createElementEx( IN IXML_Document * doc,
|
||||
IN const DOMString tagName,
|
||||
OUT IXML_Element ** rtElement )
|
||||
{
|
||||
|
||||
int ixmlDocument_createElementEx(
|
||||
IXML_Document *doc,
|
||||
const DOMString tagName,
|
||||
IXML_Element **rtElement)
|
||||
{
|
||||
int errCode = IXML_SUCCESS;
|
||||
IXML_Element *newElement = NULL;
|
||||
|
||||
if( ( doc == NULL ) || ( tagName == NULL ) ) {
|
||||
if (doc == NULL || tagName == NULL) {
|
||||
errCode = IXML_INVALID_PARAMETER;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
@ -188,46 +153,23 @@ ixmlDocument_createElementEx( IN IXML_Document * doc,
|
||||
|
||||
ErrorHandler:
|
||||
*rtElement = newElement;
|
||||
return errCode;
|
||||
|
||||
return errCode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createElement
|
||||
* Creates an element of the type specified.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* doc: pointer to document
|
||||
* tagName: The name of the element, it is case-sensitive.
|
||||
* Return Value:
|
||||
* A new element object with the nodeName set to tagName, and
|
||||
* localName, prefix and namespaceURI set to null.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Element *
|
||||
ixmlDocument_createElement( IN IXML_Document * doc,
|
||||
IN const DOMString tagName )
|
||||
|
||||
IXML_Element *ixmlDocument_createElement(
|
||||
IXML_Document *doc,
|
||||
const DOMString tagName)
|
||||
{
|
||||
IXML_Element *newElement = NULL;
|
||||
|
||||
ixmlDocument_createElementEx(doc, tagName, &newElement);
|
||||
return newElement;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createDocumentEx
|
||||
* Creates an document object
|
||||
* Internal function.
|
||||
* Parameters:
|
||||
* rtDoc: the document created or NULL on failure
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
|
||||
|
||||
int ixmlDocument_createDocumentEx(IXML_Document **rtDoc)
|
||||
{
|
||||
IXML_Document *doc;
|
||||
int errCode = IXML_SUCCESS;
|
||||
@ -257,49 +199,27 @@ ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
|
||||
return errCode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createDocument
|
||||
* Creates an document object
|
||||
* Internal function.
|
||||
* Parameters:
|
||||
* none
|
||||
* Return Value:
|
||||
* A new document object with the nodeName set to "#document".
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Document *
|
||||
ixmlDocument_createDocument()
|
||||
|
||||
IXML_Document *ixmlDocument_createDocument()
|
||||
{
|
||||
IXML_Document *doc = NULL;
|
||||
|
||||
ixmlDocument_createDocumentEx(&doc);
|
||||
|
||||
return doc;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createTextNodeEx
|
||||
* Creates an text node.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* data: text data for the text node. It is stored in nodeValue field.
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INVALID_PARAMETER: if either doc or data is NULL
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createTextNodeEx( IN IXML_Document * doc,
|
||||
IN const char *data,
|
||||
OUT IXML_Node ** textNode )
|
||||
|
||||
int ixmlDocument_createTextNodeEx(
|
||||
IXML_Document *doc,
|
||||
const DOMString data,
|
||||
IXML_Node **textNode)
|
||||
{
|
||||
IXML_Node *returnNode;
|
||||
int rc = IXML_SUCCESS;
|
||||
|
||||
returnNode = NULL;
|
||||
if( ( doc == NULL ) || ( data == NULL ) ) {
|
||||
if (doc == NULL || data == NULL) {
|
||||
rc = IXML_INVALID_PARAMETER;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
@ -336,22 +256,12 @@ ixmlDocument_createTextNodeEx( IN IXML_Document * doc,
|
||||
ErrorHandler:
|
||||
*textNode = returnNode;
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createTextNode
|
||||
* Creates an text node.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* data: text data for the text node. It is stored in nodeValue field.
|
||||
* Return Value:
|
||||
* The new text node.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlDocument_createTextNode( IN IXML_Document * doc,
|
||||
IN const char *data )
|
||||
|
||||
IXML_Node *ixmlDocument_createTextNode(
|
||||
IXML_Document *doc,
|
||||
const DOMString data)
|
||||
{
|
||||
IXML_Node *returnNode = NULL;
|
||||
|
||||
@ -360,21 +270,11 @@ ixmlDocument_createTextNode( IN IXML_Document * doc,
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createAttributeEx
|
||||
* Creates an attribute of the given name.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* name: The name of the Attribute node.
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
================================================================*/
|
||||
int
|
||||
ixmlDocument_createAttributeEx( IN IXML_Document * doc,
|
||||
IN const char *name,
|
||||
OUT IXML_Attr ** rtAttr )
|
||||
|
||||
int ixmlDocument_createAttributeEx(
|
||||
IXML_Document *doc,
|
||||
const char *name,
|
||||
IXML_Attr **rtAttr)
|
||||
{
|
||||
IXML_Attr *attrNode = NULL;
|
||||
int errCode = IXML_SUCCESS;
|
||||
@ -385,7 +285,7 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
|
||||
goto ErrorHandler;
|
||||
}
|
||||
|
||||
if( ( doc == NULL ) || ( name == NULL ) ) {
|
||||
if (doc == NULL || name == NULL) {
|
||||
ixmlAttr_free(attrNode);
|
||||
attrNode = NULL;
|
||||
errCode = IXML_INVALID_PARAMETER;
|
||||
@ -393,7 +293,6 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
|
||||
}
|
||||
|
||||
ixmlAttr_init(attrNode);
|
||||
|
||||
attrNode->n.nodeType = eATTRIBUTE_NODE;
|
||||
|
||||
// set the node fields
|
||||
@ -410,56 +309,31 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
|
||||
ErrorHandler:
|
||||
*rtAttr = attrNode;
|
||||
return errCode;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createAttribute
|
||||
* Creates an attribute of the given name.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* name: The name of the Attribute node.
|
||||
* Return Value:
|
||||
* A new attr object with the nodeName attribute set to the
|
||||
* given name, and the localName, prefix and namespaceURI set to NULL.
|
||||
* The value of the attribute is the empty string.
|
||||
*
|
||||
================================================================*/
|
||||
IXML_Attr *
|
||||
ixmlDocument_createAttribute( IN IXML_Document * doc,
|
||||
IN const char *name )
|
||||
|
||||
IXML_Attr *ixmlDocument_createAttribute(
|
||||
IXML_Document *doc,
|
||||
const char *name)
|
||||
{
|
||||
IXML_Attr *attrNode = NULL;
|
||||
|
||||
ixmlDocument_createAttributeEx(doc, name, &attrNode);
|
||||
return attrNode;
|
||||
|
||||
return attrNode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createAttributeNSEx
|
||||
* Creates an attrbute of the given name and namespace URI
|
||||
* External function.
|
||||
* Parameters:
|
||||
* namespaceURI: the namespace fo the attribute to create
|
||||
* qualifiedName: qualifiedName of the attribute to instantiate
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
|
||||
IN const DOMString namespaceURI,
|
||||
IN const DOMString qualifiedName,
|
||||
OUT IXML_Attr ** rtAttr )
|
||||
|
||||
int ixmlDocument_createAttributeNSEx(
|
||||
IXML_Document *doc,
|
||||
const DOMString namespaceURI,
|
||||
const DOMString qualifiedName,
|
||||
IXML_Attr **rtAttr )
|
||||
{
|
||||
IXML_Attr *attrNode = NULL;
|
||||
int errCode = IXML_SUCCESS;
|
||||
|
||||
if( ( doc == NULL ) || ( namespaceURI == NULL )
|
||||
|| ( qualifiedName == NULL ) ) {
|
||||
if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) {
|
||||
errCode = IXML_INVALID_PARAMETER;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
@ -489,68 +363,43 @@ ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
|
||||
ErrorHandler:
|
||||
*rtAttr = attrNode;
|
||||
return errCode;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createAttributeNS
|
||||
* Creates an attrbute of the given name and namespace URI
|
||||
* External function.
|
||||
* Parameters:
|
||||
* namespaceURI: the namespace fo the attribute to create
|
||||
* qualifiedName: qualifiedName of the attribute to instantiate
|
||||
* Return Value:
|
||||
* Creates an attribute node with the given namespaceURI and
|
||||
* qualifiedName. The prefix and localname are extracted from
|
||||
* the qualifiedName. The node value is empty.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Attr *
|
||||
ixmlDocument_createAttributeNS( IN IXML_Document * doc,
|
||||
IN const DOMString namespaceURI,
|
||||
IN const DOMString qualifiedName )
|
||||
|
||||
IXML_Attr *ixmlDocument_createAttributeNS(
|
||||
IXML_Document *doc,
|
||||
const DOMString namespaceURI,
|
||||
const DOMString qualifiedName)
|
||||
{
|
||||
IXML_Attr *attrNode = NULL;
|
||||
|
||||
ixmlDocument_createAttributeNSEx( doc, namespaceURI, qualifiedName,
|
||||
&attrNode );
|
||||
ixmlDocument_createAttributeNSEx(
|
||||
doc, namespaceURI, qualifiedName, &attrNode);
|
||||
|
||||
return attrNode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createCDATASectionEx
|
||||
* Creates an CDATASection node whose value is the specified string
|
||||
* External function.
|
||||
* Parameters:
|
||||
* data: the data for the CDATASection contents.
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INVALID_PARAMETER: if either doc or data is NULL
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createCDATASectionEx( IN IXML_Document * doc,
|
||||
IN const DOMString data,
|
||||
OUT IXML_CDATASection ** rtCD )
|
||||
|
||||
int ixmlDocument_createCDATASectionEx(
|
||||
IXML_Document *doc,
|
||||
const DOMString data,
|
||||
IXML_CDATASection **rtCD)
|
||||
{
|
||||
int errCode = IXML_SUCCESS;
|
||||
IXML_CDATASection *cDSectionNode = NULL;
|
||||
|
||||
if( ( doc == NULL ) || ( data == NULL ) ) {
|
||||
if(doc == NULL || data == NULL) {
|
||||
errCode = IXML_INVALID_PARAMETER;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
|
||||
cDSectionNode =
|
||||
( IXML_CDATASection * ) malloc( sizeof( IXML_CDATASection ) );
|
||||
cDSectionNode = (IXML_CDATASection *)malloc(sizeof (IXML_CDATASection));
|
||||
if (cDSectionNode == NULL) {
|
||||
errCode = IXML_INSUFFICIENT_MEMORY;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
|
||||
ixmlCDATASection_init(cDSectionNode);
|
||||
|
||||
cDSectionNode->n.nodeType = eCDATA_SECTION_NODE;
|
||||
cDSectionNode->n.nodeName = strdup(CDATANODENAME);
|
||||
if (cDSectionNode->n.nodeName == NULL) {
|
||||
@ -573,77 +422,55 @@ ixmlDocument_createCDATASectionEx( IN IXML_Document * doc,
|
||||
ErrorHandler:
|
||||
*rtCD = cDSectionNode;
|
||||
return errCode;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createCDATASection
|
||||
* Creates an CDATASection node whose value is the specified string
|
||||
* External function.
|
||||
* Parameters:
|
||||
* data: the data for the CDATASection contents.
|
||||
* Return Value:
|
||||
* The new CDATASection object.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_CDATASection *
|
||||
ixmlDocument_createCDATASection( IN IXML_Document * doc,
|
||||
IN const DOMString data )
|
||||
{
|
||||
|
||||
IXML_CDATASection *ixmlDocument_createCDATASection(
|
||||
IXML_Document *doc,
|
||||
const DOMString data)
|
||||
{
|
||||
IXML_CDATASection *cDSectionNode = NULL;
|
||||
|
||||
ixmlDocument_createCDATASectionEx(doc, data, &cDSectionNode);
|
||||
|
||||
return cDSectionNode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createElementNSEx
|
||||
* Creates an element of the given qualified name and namespace URI.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* namespaceURI: the namespace URI of the element to create.
|
||||
* qualifiedName: the qualified name of the element to instantiate.
|
||||
* Return Value:
|
||||
* Return Value:
|
||||
* IXML_SUCCESS
|
||||
* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
|
||||
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlDocument_createElementNSEx( IN IXML_Document * doc,
|
||||
IN const DOMString namespaceURI,
|
||||
IN const DOMString qualifiedName,
|
||||
OUT IXML_Element ** rtElement )
|
||||
{
|
||||
|
||||
int ixmlDocument_createElementNSEx(
|
||||
IXML_Document *doc,
|
||||
const DOMString namespaceURI,
|
||||
const DOMString qualifiedName,
|
||||
IXML_Element **rtElement)
|
||||
{
|
||||
IXML_Element *newElement = NULL;
|
||||
int errCode = IXML_SUCCESS;
|
||||
int line = 0;
|
||||
|
||||
if( ( doc == NULL ) || ( namespaceURI == NULL )
|
||||
|| ( qualifiedName == NULL ) ) {
|
||||
if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) {
|
||||
line = __LINE__;
|
||||
errCode = IXML_INVALID_PARAMETER;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
|
||||
errCode =
|
||||
ixmlDocument_createElementEx( doc, qualifiedName, &newElement );
|
||||
errCode = ixmlDocument_createElementEx(doc, qualifiedName, &newElement);
|
||||
if (errCode != IXML_SUCCESS) {
|
||||
line = __LINE__;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
// set the namespaceURI field
|
||||
newElement->n.namespaceURI = strdup(namespaceURI);
|
||||
if (newElement->n.namespaceURI == NULL) {
|
||||
line = __LINE__;
|
||||
ixmlElement_free(newElement);
|
||||
newElement = NULL;
|
||||
errCode = IXML_INSUFFICIENT_MEMORY;
|
||||
goto ErrorHandler;
|
||||
}
|
||||
// set the localName and prefix
|
||||
errCode =
|
||||
ixmlNode_setNodeName( ( IXML_Node * ) newElement, qualifiedName );
|
||||
errCode = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName);
|
||||
if (errCode != IXML_SUCCESS) {
|
||||
line = __LINE__;
|
||||
ixmlElement_free(newElement);
|
||||
newElement = NULL;
|
||||
errCode = IXML_INSUFFICIENT_MEMORY;
|
||||
@ -654,115 +481,71 @@ ixmlDocument_createElementNSEx( IN IXML_Document * doc,
|
||||
|
||||
ErrorHandler:
|
||||
*rtElement = newElement;
|
||||
return errCode;
|
||||
|
||||
if (errCode != IXML_SUCCESS) {
|
||||
IxmlPrintf("(%s::ixmlDocument_createElementNSEx): Error %d, line %d\n",
|
||||
__FILE__, errCode, line);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_createElementNS
|
||||
* Creates an element of the given qualified name and namespace URI.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* namespaceURI: the namespace URI of the element to create.
|
||||
* qualifiedName: the qualified name of the element to instantiate.
|
||||
* Return Value:
|
||||
* The new element object with tagName qualifiedName, prefix and
|
||||
* localName extraced from qualfiedName, nodeName of qualfiedName,
|
||||
* namespaceURI of namespaceURI.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Element *
|
||||
ixmlDocument_createElementNS( IN IXML_Document * doc,
|
||||
IN const DOMString namespaceURI,
|
||||
IN const DOMString qualifiedName )
|
||||
return errCode;
|
||||
}
|
||||
|
||||
|
||||
IXML_Element *ixmlDocument_createElementNS(
|
||||
IXML_Document *doc,
|
||||
const DOMString namespaceURI,
|
||||
const DOMString qualifiedName)
|
||||
{
|
||||
IXML_Element *newElement = NULL;
|
||||
|
||||
ixmlDocument_createElementNSEx( doc, namespaceURI, qualifiedName,
|
||||
&newElement );
|
||||
ixmlDocument_createElementNSEx(doc, namespaceURI, qualifiedName, &newElement);
|
||||
|
||||
return newElement;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_getElementsByTagName
|
||||
* Returns a nodeList of all the Elements with a given tag name
|
||||
* in the order in which they are encountered in a preorder traversal
|
||||
* of the document tree.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* tagName: the name of the tag to match on. The special value "*"
|
||||
* matches all tags.
|
||||
* Return Value:
|
||||
* A new nodeList object containing all the matched Elements.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_NodeList *
|
||||
ixmlDocument_getElementsByTagName( IN IXML_Document * doc,
|
||||
IN const char *tagName )
|
||||
|
||||
IXML_NodeList *ixmlDocument_getElementsByTagName(
|
||||
IXML_Document *doc,
|
||||
const DOMString tagName)
|
||||
{
|
||||
IXML_NodeList *returnNodeList = NULL;
|
||||
|
||||
if( ( doc == NULL ) || ( tagName == NULL ) ) {
|
||||
if (doc == NULL || tagName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ixmlNode_getElementsByTagName( ( IXML_Node * ) doc, tagName,
|
||||
&returnNodeList );
|
||||
ixmlNode_getElementsByTagName((IXML_Node *)doc, tagName, &returnNodeList);
|
||||
|
||||
return returnNodeList;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocument_getElementsByTagNameNS
|
||||
* Returns a nodeList of all the Elements with a given local name and
|
||||
* namespace URI in the order in which they are encountered in a
|
||||
* preorder traversal of the document tree.
|
||||
* External function.
|
||||
* Parameters:
|
||||
* namespaceURI: the namespace of the elements to match on. The special
|
||||
* value "*" matches all namespaces.
|
||||
* localName: the local name of the elements to match on. The special
|
||||
* value "*" matches all local names.
|
||||
* Return Value:
|
||||
* A new nodeList object containing all the matched Elements.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_NodeList *
|
||||
ixmlDocument_getElementsByTagNameNS( IN IXML_Document * doc,
|
||||
IN const DOMString namespaceURI,
|
||||
IN const DOMString localName )
|
||||
|
||||
IXML_NodeList *ixmlDocument_getElementsByTagNameNS(
|
||||
IXML_Document *doc,
|
||||
const DOMString namespaceURI,
|
||||
const DOMString localName)
|
||||
{
|
||||
IXML_NodeList *returnNodeList = NULL;
|
||||
|
||||
if( ( doc == NULL ) || ( namespaceURI == NULL )
|
||||
|| ( localName == NULL ) ) {
|
||||
if (doc == NULL || namespaceURI == NULL || localName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ixmlNode_getElementsByTagNameNS( ( IXML_Node * ) doc, namespaceURI,
|
||||
localName, &returnNodeList );
|
||||
ixmlNode_getElementsByTagNameNS(
|
||||
(IXML_Node *)doc, namespaceURI, localName, &returnNodeList);
|
||||
|
||||
return returnNodeList;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* 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 const DOMString tagName )
|
||||
|
||||
IXML_Element *ixmlDocument_getElementById(
|
||||
IXML_Document *doc,
|
||||
const DOMString tagName)
|
||||
{
|
||||
IXML_Element *rtElement = NULL;
|
||||
IXML_Node *nodeptr = (IXML_Node *)doc;
|
||||
const char *name;
|
||||
|
||||
if( ( nodeptr == NULL ) || ( tagName == NULL ) ) {
|
||||
if (nodeptr == NULL || tagName == NULL) {
|
||||
return rtElement;
|
||||
}
|
||||
|
||||
@ -776,29 +559,26 @@ ixmlDocument_getElementById( IN IXML_Document * doc,
|
||||
rtElement = (IXML_Element *)nodeptr;
|
||||
return rtElement;
|
||||
} else {
|
||||
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
|
||||
ixmlNode_getFirstChild
|
||||
( nodeptr ),
|
||||
rtElement = ixmlDocument_getElementById(
|
||||
(IXML_Document *)ixmlNode_getFirstChild(nodeptr),
|
||||
tagName );
|
||||
if (rtElement == NULL) {
|
||||
rtElement = ixmlDocument_getElementById( ( IXML_Document
|
||||
* )
|
||||
ixmlNode_getNextSibling
|
||||
( nodeptr ),
|
||||
rtElement = ixmlDocument_getElementById(
|
||||
(IXML_Document *)ixmlNode_getNextSibling(nodeptr),
|
||||
tagName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
|
||||
ixmlNode_getFirstChild
|
||||
( nodeptr ), tagName );
|
||||
rtElement = ixmlDocument_getElementById(
|
||||
(IXML_Document *)ixmlNode_getFirstChild(nodeptr),
|
||||
tagName);
|
||||
if (rtElement == NULL) {
|
||||
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
|
||||
ixmlNode_getNextSibling
|
||||
( nodeptr ),
|
||||
rtElement = ixmlDocument_getElementById(
|
||||
(IXML_Document *)ixmlNode_getNextSibling(nodeptr),
|
||||
tagName);
|
||||
}
|
||||
}
|
||||
|
||||
return rtElement;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,73 +1,173 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef IXML_MEMBUF_H
|
||||
#define IXML_MEMBUF_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
#ifndef _IXML_MEMBUF_H
|
||||
#define _IXML_MEMBUF_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ixml.h"
|
||||
|
||||
|
||||
#include <stdlib.h> /* for size_t */
|
||||
|
||||
|
||||
#define MINVAL(a, b) ( (a) < (b) ? (a) : (b) )
|
||||
#define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
|
||||
|
||||
|
||||
#define MEMBUF_DEF_SIZE_INC 20
|
||||
|
||||
|
||||
typedef struct // ixml_membuf
|
||||
/*!
|
||||
* \brief The ixml_membuf type.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *buf;
|
||||
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
size_t size_inc;
|
||||
|
||||
} ixml_membuf;
|
||||
|
||||
//--------------------------------------------------
|
||||
//////////////// functions /////////////////////////
|
||||
//--------------------------------------------------
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/*!
|
||||
* \brief ixml_membuf initialization routine.
|
||||
*/
|
||||
void ixml_membuf_init(
|
||||
/*! [in,out] The memory buffer to initializa. */
|
||||
ixml_membuf *m);
|
||||
|
||||
void ixml_membuf_init(INOUT ixml_membuf *m);
|
||||
void ixml_membuf_destroy(INOUT ixml_membuf *m);
|
||||
int ixml_membuf_assign(INOUT ixml_membuf *m, IN const void *buf,
|
||||
IN size_t buf_len );
|
||||
int ixml_membuf_assign_str(INOUT ixml_membuf *m, IN const char *c_str );
|
||||
int ixml_membuf_append(INOUT ixml_membuf *m, IN const void *buf);
|
||||
int ixml_membuf_append_str(INOUT ixml_membuf *m, IN const char *c_str);
|
||||
int ixml_membuf_insert(INOUT ixml_membuf *m, IN const void* buf,
|
||||
IN size_t buf_len, int index );
|
||||
|
||||
#endif // _IXML_MEMBUF_H
|
||||
/*!
|
||||
* \brief ixml_membuf clearing routine.
|
||||
*
|
||||
* The internal buffer is deleted and ixml_membuf_init() is called in the end
|
||||
* to reinitialize the buffer.
|
||||
*/
|
||||
void ixml_membuf_destroy(
|
||||
/*! [in,out] The memory buffer to clear. */
|
||||
ixml_membuf *m);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Copies the contents o a buffer to the designated ixml_membuf.
|
||||
*
|
||||
* The previous contents of the ixml_membuf are destroyed.
|
||||
*
|
||||
* \return IXML_SUCCESS if successfull, or the error code returned
|
||||
* by ixml_membuf_set_size().
|
||||
*
|
||||
* \sa ixml_membuf_assign_str().
|
||||
*/
|
||||
int ixml_membuf_assign(
|
||||
/*! [in,out] The memory buffer on which to operate. */
|
||||
ixml_membuf *m,
|
||||
/*! [in] The input buffer to copy from. */
|
||||
const void *buf,
|
||||
/*! [in] The number of bytes to copy from the input buffer. */
|
||||
size_t buf_len);
|
||||
|
||||
/*!
|
||||
* \brief Copies a \b NULL terminated string to the ixml_buffer.
|
||||
*
|
||||
* This is a convenience function that internally uses ixml_membuf_assign().
|
||||
*
|
||||
* \return The return value of ixml_membuf_assign().
|
||||
*
|
||||
* \sa ixml_membuf_assign().
|
||||
*/
|
||||
int ixml_membuf_assign_str(
|
||||
/*! [in,out] The memory buffer on which to operate. */
|
||||
ixml_membuf *m,
|
||||
/*! [in] The input string to copy from. */
|
||||
const char *c_str);
|
||||
|
||||
/*!
|
||||
* \brief Appends one byte to the designated ixml_membuffer.
|
||||
*
|
||||
* This is a convenience function that internally uses ixml_membuf_insert().
|
||||
*
|
||||
* \return The return value of ixml_membuf_insert().
|
||||
*
|
||||
* \sa ixml_membuf_insert()
|
||||
*/
|
||||
int ixml_membuf_append(
|
||||
/*! [in,out] The memory buffer on which to operate. */
|
||||
ixml_membuf *m,
|
||||
/*! [in] The pointer to the byte to append. */
|
||||
const void *buf);
|
||||
|
||||
/*!
|
||||
* \brief Appends the contents of a \b NULL terminated string to the designated
|
||||
* ixml_membuf.
|
||||
*
|
||||
* This is a convenience function that internally uses ixml_membuf_insert().
|
||||
*
|
||||
* \return The return value of ixml_membuf_insert().
|
||||
*
|
||||
* \sa ixml_membuf_insert().
|
||||
*/
|
||||
int ixml_membuf_append_str(
|
||||
/*! [in,out] The memory buffer on which to operate. */
|
||||
ixml_membuf *m,
|
||||
/*! [in] The input string to copy from. */
|
||||
const char *c_str);
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*
|
||||
* \return
|
||||
* \li 0 if successfull.
|
||||
* \li IXML_INDEX_SIZE_ERR if the index parameter is out of range.
|
||||
* \li Or the return code of ixml_membuf_set_size()
|
||||
*
|
||||
* \sa ixml_membuf_set_size()
|
||||
*/
|
||||
int ixml_membuf_insert(
|
||||
/*! [in,out] The memory buffer on which to operate. */
|
||||
ixml_membuf *m,
|
||||
/*! [in] The pointer to the input buffer. */
|
||||
const void *buf,
|
||||
/*! [in] The buffer length. */
|
||||
size_t buf_len,
|
||||
/*! [in] The point of insertion relative to the beggining of the
|
||||
* ixml_membuf internal buffer. */
|
||||
int index);
|
||||
|
||||
|
||||
#endif /* IXML_MEMBUF_H */
|
||||
|
||||
|
@ -1,41 +1,49 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef IXMLPARSER_H
|
||||
#define IXMLPARSER_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
#ifndef _IXMLPARSER_H
|
||||
#define _IXMLPARSER_H
|
||||
|
||||
#include "ixml.h"
|
||||
#include "ixmlmembuf.h"
|
||||
|
||||
// Parser definitions
|
||||
|
||||
/* Parser definitions */
|
||||
#define QUOT """
|
||||
#define LT "<"
|
||||
#define GT ">"
|
||||
@ -44,6 +52,7 @@
|
||||
#define ESC_HEX "&#x"
|
||||
#define ESC_DEC "&#"
|
||||
|
||||
|
||||
typedef struct _IXML_NamespaceURI
|
||||
{
|
||||
char *nsURI;
|
||||
@ -69,52 +78,192 @@ typedef enum
|
||||
eCONTENT,
|
||||
} PARSER_STATE;
|
||||
|
||||
|
||||
typedef struct _Parser
|
||||
{
|
||||
char *dataBuffer; //data buffer
|
||||
char *curPtr; //ptr to the token parsed
|
||||
char *savePtr; //Saves for backup
|
||||
/*! Data buffer. */
|
||||
char *dataBuffer;
|
||||
/*! Pointer to the token parsed. */
|
||||
char *curPtr;
|
||||
/*! Saves for backup. */
|
||||
char *savePtr;
|
||||
ixml_membuf lastElem;
|
||||
ixml_membuf tokenBuf;
|
||||
|
||||
IXML_Node *pNeedPrefixNode;
|
||||
IXML_ElementStack *pCurElement;
|
||||
IXML_Node *currentNodePtr;
|
||||
PARSER_STATE state;
|
||||
|
||||
BOOL bHasTopLevel;
|
||||
|
||||
} Parser;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Check to see whether name is a valid xml name.
|
||||
*/
|
||||
BOOL Parser_isValidXmlName(
|
||||
/*! [in] The string to be checked. */
|
||||
const DOMString name);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Sets the error character.
|
||||
*
|
||||
* If 'c' is 0 (default), the parser is strict about XML encoding:
|
||||
* invalid UTF-8 sequences or "&" entities are rejected, and the parsing
|
||||
* aborts.
|
||||
*
|
||||
* If 'c' is not 0, the parser is relaxed: invalid UTF-8 characters
|
||||
* are replaced by this character, and invalid "&" entities are left
|
||||
* untranslated. The parsing is then allowed to continue.
|
||||
*/
|
||||
void Parser_setErrorChar(
|
||||
/*! [in] The character to become the error character. */
|
||||
char c);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Fees a node contents.
|
||||
*/
|
||||
void Parser_freeNodeContent(
|
||||
/*! [in] The Node to process. */
|
||||
IXML_Node *IXML_Nodeptr);
|
||||
|
||||
int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file);
|
||||
BOOL Parser_isValidXmlName( const DOMString name);
|
||||
|
||||
int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
|
||||
void Parser_freeNodeContent( IXML_Node *IXML_Nodeptr);
|
||||
|
||||
void Parser_setErrorChar( char c );
|
||||
|
||||
void ixmlAttr_free(IXML_Attr *attrNode);
|
||||
void ixmlAttr_init(IXML_Attr *attrNode);
|
||||
|
||||
int ixmlElement_setTagName(IXML_Element *element, const char *tagName);
|
||||
/*!
|
||||
* \brief Set the given element's tagName.
|
||||
*
|
||||
* \return One of the following:
|
||||
* \li \b IXML_SUCCESS, if successfull.
|
||||
* \li \b IXML_FAILED, if element of tagname is \b NULL.
|
||||
* \li \b IXML_INSUFFICIENT_MEMORY, if there is no memory to allocate the
|
||||
* buffer for the element's tagname.
|
||||
*/
|
||||
int ixmlElement_setTagName(
|
||||
/*! [in] The element to change the tagname. */
|
||||
IXML_Element *element,
|
||||
/*! [in] The new tagName for the element. */
|
||||
const char *tagName);
|
||||
|
||||
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap);
|
||||
int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add);
|
||||
|
||||
void ixmlNode_init(IXML_Node *IXML_Nodeptr);
|
||||
BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node);
|
||||
/*!
|
||||
* \brief Initializes a NamedNodeMap object.
|
||||
*/
|
||||
void ixmlNamedNodeMap_init(
|
||||
/*! [in] The named node map to process. */
|
||||
IXML_NamedNodeMap *nnMap);
|
||||
|
||||
void ixmlNode_getElementsByTagName( IXML_Node *n, const char *tagname, IXML_NodeList **list);
|
||||
void ixmlNode_getElementsByTagNameNS( IXML_Node *IXML_Node, const char *namespaceURI,
|
||||
const char *localName, IXML_NodeList **list);
|
||||
|
||||
int ixmlNode_setNodeProperties(IXML_Node* node, IXML_Node *src);
|
||||
int ixmlNode_setNodeName( IXML_Node* node, const DOMString qualifiedName);
|
||||
/*!
|
||||
* \brief Add a node to a NamedNodeMap.
|
||||
*
|
||||
* \return IXML_SUCCESS or failure.
|
||||
*/
|
||||
int ixmlNamedNodeMap_addToNamedNodeMap(
|
||||
/* [in] The named node map. */
|
||||
IXML_NamedNodeMap **nnMap,
|
||||
/* [in] The node to add. */
|
||||
IXML_Node *add);
|
||||
|
||||
void ixmlNodeList_init(IXML_NodeList *nList);
|
||||
int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add);
|
||||
/*!
|
||||
* \brief Add a node to nodelist.
|
||||
*/
|
||||
int ixmlNodeList_addToNodeList(
|
||||
/*! [in] The pointer to the nodelist. */
|
||||
IXML_NodeList **nList,
|
||||
/*! [in] The node to add. */
|
||||
IXML_Node *add);
|
||||
|
||||
#endif // _IXMLPARSER_H
|
||||
|
||||
/*!
|
||||
* \brief Intializes a node.
|
||||
*/
|
||||
void ixmlNode_init(
|
||||
/*! [in] The \b Node to iniatialize. */
|
||||
IN IXML_Node *nodeptr);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Compare two nodes to see whether they are the same node.
|
||||
* Parent, sibling and children node are ignored.
|
||||
*
|
||||
* \return
|
||||
* \li TRUE, the two nodes are the same.
|
||||
* \li FALSE, the two nodes are not the same.
|
||||
*/
|
||||
BOOL ixmlNode_compare(
|
||||
/*! [in] The first \b Node. */
|
||||
IXML_Node *srcNode,
|
||||
/*! [in] The second \b Node. */
|
||||
IXML_Node *destNode);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Returns a nodeList of all descendant Elements with a given tagName,
|
||||
* in the order in which they are encountered in a traversal of this element
|
||||
* tree.
|
||||
*/
|
||||
void ixmlNode_getElementsByTagName(
|
||||
/*! [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);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief 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.
|
||||
*/
|
||||
void ixmlNode_getElementsByTagNameNS(
|
||||
/*! [in] The \b Element tree. */
|
||||
IXML_Node *n,
|
||||
/*! [in] The name space to match. */
|
||||
const char *namespaceURI,
|
||||
/*! [in] The local name to match. */
|
||||
const char *localName,
|
||||
/*! [out] The output \b NodeList. */
|
||||
IXML_NodeList **list);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
int ixmlNode_setNodeName(
|
||||
/*! [in] The \b Node. */
|
||||
IXML_Node *node,
|
||||
/*! [in] . */
|
||||
const DOMString qualifiedName);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
int ixmlNode_setNodeProperties(
|
||||
/*! [in] . */
|
||||
IXML_Node *destNode,
|
||||
/*! [in] . */
|
||||
IXML_Node *src);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Initializes a nodelist
|
||||
*/
|
||||
void ixmlNodeList_init(
|
||||
/*! [in,out] The \b NodeList to initialize. */
|
||||
IXML_NodeList *nList);
|
||||
|
||||
|
||||
#endif /* IXMLPARSER_H */
|
||||
|
||||
|
346
ixml/src/ixml.c
346
ixml/src/ixml.c
@ -1,51 +1,65 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmldebug.h"
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* copy_with_escape
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
static void
|
||||
copy_with_escape( INOUT ixml_membuf * buf,
|
||||
IN const char *p )
|
||||
|
||||
#include <stdlib.h> /* for free() */
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Appends a string to a buffer, substituting some characters by escape
|
||||
* sequences.
|
||||
*/
|
||||
static void copy_with_escape(
|
||||
/*! [in,out] The input/output buffer. */
|
||||
ixml_membuf *buf,
|
||||
/*! [in] The string to copy from. */
|
||||
const char *p)
|
||||
{
|
||||
int i;
|
||||
int plen;
|
||||
|
||||
if( p == NULL )
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
plen = strlen( p );
|
||||
|
||||
@ -73,19 +87,21 @@ copy_with_escape( INOUT ixml_membuf * buf,
|
||||
|
||||
default:
|
||||
ixml_membuf_append(buf, &p[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlPrintDomTreeRecursive
|
||||
* It is a recursive function to print all the node in a tree.
|
||||
|
||||
/*!
|
||||
* \brief Recursive function to print all the node in a tree.
|
||||
* Internal to parser only.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
||||
IN ixml_membuf * buf )
|
||||
*/
|
||||
static void ixmlPrintDomTreeRecursive(
|
||||
/*! [in] \todo documentation. */
|
||||
IXML_Node *nodeptr,
|
||||
/*! [in] \todo documentation. */
|
||||
ixml_membuf *buf)
|
||||
{
|
||||
const char *nodeName = NULL;
|
||||
const char *nodeValue = NULL;
|
||||
@ -97,7 +113,6 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
||||
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||
|
||||
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||
|
||||
case eTEXT_NODE:
|
||||
copy_with_escape(buf, nodeValue);
|
||||
break;
|
||||
@ -117,8 +132,8 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
||||
break;
|
||||
|
||||
case eDOCUMENT_NODE:
|
||||
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
|
||||
( nodeptr ), buf );
|
||||
ixmlPrintDomTreeRecursive(
|
||||
ixmlNode_getFirstChild(nodeptr), buf);
|
||||
break;
|
||||
|
||||
case eATTRIBUTE_NODE:
|
||||
@ -126,7 +141,6 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
||||
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);
|
||||
@ -136,71 +150,69 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
||||
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 ) ) {
|
||||
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 );
|
||||
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 ) {
|
||||
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 );
|
||||
ixmlPrintDomTreeRecursive(
|
||||
ixmlNode_getNextSibling(nodeptr), buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: "
|
||||
"Warning, unknown node type %d\n",
|
||||
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlPrintDomTree
|
||||
* Print a DOM tree.
|
||||
* Element, and Attribute nodes are handled differently.
|
||||
* We don't want to print the Element and Attribute nodes' sibling.
|
||||
* External function.
|
||||
|
||||
/*!
|
||||
* \brief Print a DOM tree.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlPrintDomTree( IN IXML_Node * nodeptr,
|
||||
IN ixml_membuf * buf )
|
||||
* Element, and Attribute nodes are handled differently. We don't want to print
|
||||
* the Element and Attribute nodes' sibling.
|
||||
*/
|
||||
static void ixmlPrintDomTree(
|
||||
/*! [in] \todo documentation. */
|
||||
IXML_Node *nodeptr,
|
||||
/*! [in] \todo documentation. */
|
||||
ixml_membuf *buf)
|
||||
{
|
||||
const char *nodeName = NULL;
|
||||
const char *nodeValue = NULL;
|
||||
IXML_Node *child = NULL;
|
||||
|
||||
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
|
||||
if (nodeptr == NULL || buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
|
||||
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||
|
||||
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||
|
||||
case eTEXT_NODE:
|
||||
case eCDATA_SECTION_NODE:
|
||||
case ePROCESSING_INSTRUCTION_NODE:
|
||||
@ -218,23 +230,21 @@ ixmlPrintDomTree( IN IXML_Node * nodeptr,
|
||||
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 ) ) {
|
||||
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 );
|
||||
ixmlPrintDomTreeRecursive(
|
||||
ixmlNode_getFirstChild(nodeptr), buf);
|
||||
|
||||
// Done with children. Output the end tag.
|
||||
ixml_membuf_append_str(buf, "</");
|
||||
@ -243,27 +253,31 @@ ixmlPrintDomTree( IN IXML_Node * nodeptr,
|
||||
break;
|
||||
|
||||
default:
|
||||
IxmlPrintf("(%s::ixmlPrintDomTree) line %d: "
|
||||
"Warning, unknown node type %d\n",
|
||||
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* 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.
|
||||
|
||||
/*!
|
||||
* \brief Converts a DOM tree into a text string.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlDomTreetoString( IN IXML_Node * nodeptr,
|
||||
IN ixml_membuf * buf )
|
||||
* Element, and Attribute nodes are handled differently. We don't want to print
|
||||
* the Element and Attribute nodes' sibling.
|
||||
*/
|
||||
static void ixmlDomTreetoString(
|
||||
/*! [in] \todo documentation. */
|
||||
IXML_Node *nodeptr,
|
||||
/*! [in] \todo documentation. */
|
||||
ixml_membuf *buf)
|
||||
{
|
||||
const char *nodeName = NULL;
|
||||
const char *nodeValue = NULL;
|
||||
IXML_Node *child = NULL;
|
||||
|
||||
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
|
||||
if (nodeptr == NULL || buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -271,7 +285,6 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
|
||||
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||
|
||||
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||
|
||||
case eTEXT_NODE:
|
||||
case eCDATA_SECTION_NODE:
|
||||
case ePROCESSING_INSTRUCTION_NODE:
|
||||
@ -289,23 +302,20 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
|
||||
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 ) ) {
|
||||
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 );
|
||||
ixmlPrintDomTreeRecursive(ixmlNode_getFirstChild(nodeptr), buf);
|
||||
|
||||
// Done with children. Output the end tag.
|
||||
ixml_membuf_append_str(buf, "</");
|
||||
@ -314,54 +324,35 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
|
||||
break;
|
||||
|
||||
default:
|
||||
IxmlPrintf("(%s::ixmlDomTreetoString) line %d: "
|
||||
"Warning, unknown node type %d\n",
|
||||
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlLoadDocumentEx
|
||||
* Parses the given file, and returns the DOM tree from it.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlLoadDocumentEx( IN const char *xmlFile,
|
||||
IXML_Document ** doc )
|
||||
{
|
||||
|
||||
if( ( xmlFile == NULL ) || ( doc == NULL ) ) {
|
||||
int ixmlLoadDocumentEx(const char *xmlFile, IXML_Document **doc)
|
||||
{
|
||||
if (xmlFile == NULL || doc == NULL) {
|
||||
return IXML_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return Parser_LoadDocument(doc, xmlFile, TRUE);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlLoadDocument
|
||||
* Parses the given file, and returns the DOM tree from it.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Document *
|
||||
ixmlLoadDocument( IN const char *xmlFile )
|
||||
{
|
||||
|
||||
IXML_Document *ixmlLoadDocument(const char *xmlFile)
|
||||
{
|
||||
IXML_Document *doc = NULL;
|
||||
|
||||
ixmlLoadDocumentEx(xmlFile, &doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlPrintDocument
|
||||
* Prints entire document, prepending XML prolog first.
|
||||
* Puts lots of white spaces.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
|
||||
DOMString
|
||||
ixmlPrintDocument(IXML_Document *doc)
|
||||
DOMString ixmlPrintDocument(IXML_Document *doc)
|
||||
{
|
||||
IXML_Node* rootNode = (IXML_Node *)doc;
|
||||
ixml_membuf memBuf;
|
||||
@ -374,20 +365,13 @@ ixmlPrintDocument(IXML_Document *doc)
|
||||
ixml_membuf_init(buf);
|
||||
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
|
||||
ixmlPrintDomTree(rootNode, buf);
|
||||
return buf->buf;
|
||||
|
||||
return buf->buf;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlPrintNode
|
||||
* Print DOM tree under node. Puts lots of white spaces
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
DOMString
|
||||
ixmlPrintNode( IN IXML_Node * node )
|
||||
{
|
||||
|
||||
DOMString ixmlPrintNode(IXML_Node *node)
|
||||
{
|
||||
ixml_membuf memBuf;
|
||||
ixml_membuf *buf = &memBuf;
|
||||
|
||||
@ -397,20 +381,12 @@ ixmlPrintNode( IN IXML_Node * node )
|
||||
|
||||
ixml_membuf_init(buf);
|
||||
ixmlPrintDomTree(node, buf);
|
||||
return buf->buf;
|
||||
|
||||
return buf->buf;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlDocumenttoString
|
||||
* converts DOM tree under node to text string,
|
||||
* prepending XML prolog first.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
|
||||
DOMString
|
||||
ixmlDocumenttoString(IXML_Document *doc)
|
||||
DOMString ixmlDocumenttoString(IXML_Document *doc)
|
||||
{
|
||||
IXML_Node* rootNode = (IXML_Node *)doc;
|
||||
ixml_membuf memBuf;
|
||||
@ -423,20 +399,13 @@ ixmlDocumenttoString(IXML_Document *doc)
|
||||
ixml_membuf_init(buf);
|
||||
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
|
||||
ixmlDomTreetoString(rootNode, buf);
|
||||
return buf->buf;
|
||||
|
||||
return buf->buf;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodetoString
|
||||
* converts DOM tree under node to text string
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
DOMString
|
||||
ixmlNodetoString( IN IXML_Node * node )
|
||||
{
|
||||
|
||||
DOMString ixmlNodetoString(IXML_Node *node)
|
||||
{
|
||||
ixml_membuf memBuf;
|
||||
ixml_membuf *buf = &memBuf;
|
||||
|
||||
@ -446,35 +415,20 @@ ixmlNodetoString( IN IXML_Node * node )
|
||||
|
||||
ixml_membuf_init(buf);
|
||||
ixmlDomTreetoString(node, buf);
|
||||
return buf->buf;
|
||||
|
||||
return buf->buf;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlRelaxParser
|
||||
* Makes the XML parser more tolerant to malformed text.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlRelaxParser(char errorChar)
|
||||
|
||||
void ixmlRelaxParser(char errorChar)
|
||||
{
|
||||
Parser_setErrorChar(errorChar);
|
||||
}
|
||||
|
||||
|
||||
/*================================================================
|
||||
* ixmlParseBufferEx
|
||||
* Parse xml file stored in buffer.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlParseBufferEx( IN const char *buffer,
|
||||
IXML_Document ** retDoc )
|
||||
int ixmlParseBufferEx(const char *buffer, IXML_Document **retDoc)
|
||||
{
|
||||
|
||||
if( ( buffer == NULL ) || ( retDoc == NULL ) ) {
|
||||
if (buffer == NULL || retDoc == NULL) {
|
||||
return IXML_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@ -485,47 +439,31 @@ ixmlParseBufferEx( IN const char *buffer,
|
||||
return Parser_LoadDocument(retDoc, buffer, FALSE);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlParseBuffer
|
||||
* Parse xml file stored in buffer.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Document *
|
||||
ixmlParseBuffer( IN const char *buffer )
|
||||
|
||||
IXML_Document *ixmlParseBuffer(const char *buffer)
|
||||
{
|
||||
IXML_Document *doc = NULL;
|
||||
|
||||
ixmlParseBufferEx(buffer, &doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlCloneDOMString
|
||||
* Clones a DOM String.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
DOMString
|
||||
ixmlCloneDOMString( IN const DOMString src )
|
||||
|
||||
DOMString ixmlCloneDOMString(const DOMString src)
|
||||
{
|
||||
if (src == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ( strdup( src ) );
|
||||
return strdup(src);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlFreeDOMString
|
||||
* Frees a DOM String.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlFreeDOMString( IN DOMString buf )
|
||||
|
||||
void ixmlFreeDOMString(DOMString buf)
|
||||
{
|
||||
if (buf != NULL) {
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,79 +1,87 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixml.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixml.h"
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_set_size
|
||||
*
|
||||
* Increases or decreases buffer cap so that at least
|
||||
* 'new_length' bytes can be stored
|
||||
|
||||
/*!
|
||||
* \brief Increases or decreases buffer capacity so that at least 'new_length'
|
||||
* bytes can be stored.
|
||||
*
|
||||
* On error, m's fields do not change.
|
||||
*
|
||||
* returns:
|
||||
* UPNP_E_SUCCESS
|
||||
* UPNP_E_OUTOF_MEMORY
|
||||
*
|
||||
*=================================================================*/
|
||||
static int
|
||||
ixml_membuf_set_size( INOUT ixml_membuf * m,
|
||||
* \return
|
||||
* \li UPNP_E_SUCCESS
|
||||
* \li UPNP_E_OUTOF_MEMORY
|
||||
*/
|
||||
static int ixml_membuf_set_size(
|
||||
/*! [in,out] The memory buffer. */
|
||||
INOUT ixml_membuf *m,
|
||||
/*! [in] The new lenght. */
|
||||
IN size_t new_length)
|
||||
{
|
||||
size_t diff;
|
||||
size_t alloc_len;
|
||||
char *temp_buf;
|
||||
|
||||
if( new_length >= m->length ) // increase length
|
||||
{
|
||||
// need more mem?
|
||||
if (new_length >= m->length) {
|
||||
/* increase length */
|
||||
/* need more mem? */
|
||||
if (new_length <= m->capacity) {
|
||||
return 0; // have enough mem; done
|
||||
/* have enough mem; done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff = new_length - m->length;
|
||||
alloc_len = MAXVAL(m->size_inc, diff) + m->capacity;
|
||||
} else // decrease length
|
||||
{
|
||||
} else {
|
||||
// decrease length
|
||||
assert(new_length <= m->length);
|
||||
|
||||
// if diff is 0..m->size_inc, don't free
|
||||
if ((m->capacity - new_length) <= m->size_inc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
alloc_len = new_length + m->size_inc;
|
||||
}
|
||||
|
||||
@ -81,27 +89,22 @@ ixml_membuf_set_size( INOUT ixml_membuf * m,
|
||||
|
||||
temp_buf = realloc(m->buf, alloc_len + 1);
|
||||
if (temp_buf == NULL) {
|
||||
// try smaller size
|
||||
/* try smaller size */
|
||||
alloc_len = new_length;
|
||||
temp_buf = realloc(m->buf, alloc_len + 1);
|
||||
|
||||
if (temp_buf == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
}
|
||||
// save
|
||||
/* save */
|
||||
m->buf = temp_buf;
|
||||
m->capacity = alloc_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* membuffer_init
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixml_membuf_init( INOUT ixml_membuf * m )
|
||||
|
||||
void ixml_membuf_init(ixml_membuf *m)
|
||||
{
|
||||
assert(m != NULL);
|
||||
|
||||
@ -111,13 +114,8 @@ ixml_membuf_init( INOUT ixml_membuf * m )
|
||||
m->capacity = 0;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* membuffer_destroy
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixml_membuf_destroy( INOUT ixml_membuf * m )
|
||||
|
||||
void ixml_membuf_destroy(ixml_membuf *m)
|
||||
{
|
||||
if (m == NULL) {
|
||||
return;
|
||||
@ -127,15 +125,11 @@ ixml_membuf_destroy( INOUT ixml_membuf * m )
|
||||
ixml_membuf_init(m);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_assign
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_assign( INOUT ixml_membuf * m,
|
||||
IN const void *buf,
|
||||
IN size_t buf_len )
|
||||
|
||||
int ixml_membuf_assign(
|
||||
ixml_membuf *m,
|
||||
const void *buf,
|
||||
size_t buf_len)
|
||||
{
|
||||
int return_code;
|
||||
|
||||
@ -151,35 +145,28 @@ ixml_membuf_assign( INOUT ixml_membuf * m,
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
|
||||
// copy
|
||||
memcpy(m->buf, buf, buf_len);
|
||||
m->buf[buf_len] = 0; // null-terminate
|
||||
|
||||
// null-terminate
|
||||
m->buf[buf_len] = 0;
|
||||
m->length = buf_len;
|
||||
|
||||
return IXML_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_assign_str
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_assign_str( INOUT ixml_membuf * m,
|
||||
IN const char *c_str )
|
||||
|
||||
int ixml_membuf_assign_str(
|
||||
ixml_membuf *m,
|
||||
const char *c_str)
|
||||
{
|
||||
return ixml_membuf_assign(m, c_str, strlen(c_str));
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_append
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_append( INOUT ixml_membuf * m,
|
||||
|
||||
int ixml_membuf_append(
|
||||
INOUT ixml_membuf *m,
|
||||
IN const void *buf)
|
||||
{
|
||||
assert(m != NULL);
|
||||
@ -187,50 +174,45 @@ ixml_membuf_append( INOUT ixml_membuf * m,
|
||||
return ixml_membuf_insert(m, buf, 1, m->length);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_append_str
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_append_str( INOUT ixml_membuf * m,
|
||||
|
||||
int ixml_membuf_append_str(
|
||||
INOUT ixml_membuf *m,
|
||||
IN const char *c_str)
|
||||
{
|
||||
return ixml_membuf_insert(m, c_str, strlen(c_str), m->length);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_insert
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_insert( INOUT ixml_membuf * m,
|
||||
|
||||
int ixml_membuf_insert(
|
||||
INOUT ixml_membuf *m,
|
||||
IN const void *buf,
|
||||
IN size_t buf_len,
|
||||
int index)
|
||||
{
|
||||
int return_code;
|
||||
int return_code = 0;
|
||||
|
||||
assert(m != NULL);
|
||||
|
||||
if( index < 0 || index > ( int )m->length )
|
||||
if (index < 0 || index > (int)m->length) {
|
||||
return IXML_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
if (buf == NULL || buf_len == 0) {
|
||||
return 0;
|
||||
}
|
||||
// alloc mem
|
||||
/* alloc mem */
|
||||
return_code = ixml_membuf_set_size(m, m->length + buf_len);
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
// insert data
|
||||
// move data to right of insertion point
|
||||
/* insert data */
|
||||
/* move data to right of insertion point */
|
||||
memmove(m->buf + index + buf_len, m->buf + index, m->length - index);
|
||||
memcpy(m->buf + index, buf, buf_len);
|
||||
m->length += buf_len;
|
||||
m->buf[m->length] = 0; // null-terminate
|
||||
/* Null terminate */
|
||||
m->buf[m->length] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,53 +1,62 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_getItemNumber
|
||||
* return the item number of a item in NamedNodeMap.
|
||||
* Internal to parser only.
|
||||
* Parameters:
|
||||
* name: the name of the item to find
|
||||
*
|
||||
*=================================================================*/
|
||||
unsigned long
|
||||
ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> /* for free(), malloc() */
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Return the item number of a item in NamedNodeMap.
|
||||
*/
|
||||
static unsigned long ixmlNamedNodeMap_getItemNumber(
|
||||
/*! [in] The named node map to process. */
|
||||
IN IXML_NamedNodeMap *nnMap,
|
||||
/*! [in] The name of the item to find. */
|
||||
IN const char *name)
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
unsigned long returnItemNo = 0;
|
||||
|
||||
assert(nnMap != NULL && name != NULL);
|
||||
if( ( nnMap == NULL ) || ( name == NULL ) ) {
|
||||
if (nnMap == NULL || name == NULL) {
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
}
|
||||
|
||||
@ -56,7 +65,6 @@ ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
|
||||
if (strcmp(name, tempNode->nodeName) == 0) {
|
||||
return returnItemNo;
|
||||
}
|
||||
|
||||
tempNode = tempNode->nextSibling;
|
||||
returnItemNo++;
|
||||
}
|
||||
@ -64,39 +72,22 @@ ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_init
|
||||
* Initializes a NamedNodeMap object.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNamedNodeMap_init( IN IXML_NamedNodeMap * nnMap )
|
||||
|
||||
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
assert(nnMap != NULL);
|
||||
|
||||
memset(nnMap, 0, sizeof (IXML_NamedNodeMap));
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_getNamedItem
|
||||
* Retrieves a node specified by name.
|
||||
* External function.
|
||||
*
|
||||
* Parameter:
|
||||
* name: type nodeName of a node to retrieve.
|
||||
*
|
||||
* Return Value:
|
||||
* A Node with the specified nodeName, or null if it
|
||||
* does not identify any node in this map.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNamedNodeMap_getNamedItem( IN IXML_NamedNodeMap * nnMap,
|
||||
IN const char *name )
|
||||
|
||||
IXML_Node *ixmlNamedNodeMap_getNamedItem(
|
||||
IXML_NamedNodeMap *nnMap,
|
||||
const DOMString name)
|
||||
{
|
||||
long index;
|
||||
|
||||
if( ( nnMap == NULL ) || ( name == NULL ) ) {
|
||||
if (nnMap == NULL || name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -104,26 +95,13 @@ ixmlNamedNodeMap_getNamedItem( IN IXML_NamedNodeMap * nnMap,
|
||||
if (index == IXML_INVALID_ITEM_NUMBER) {
|
||||
return NULL;
|
||||
} else {
|
||||
return ( ixmlNamedNodeMap_item( nnMap, ( unsigned long )index ) );
|
||||
return ixmlNamedNodeMap_item(nnMap, (unsigned long)index);
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_item
|
||||
* Returns the indexth item in the map. If index is greater than or
|
||||
* equal to the number of nodes in this map, this returns null.
|
||||
* External function.
|
||||
*
|
||||
* Parameter:
|
||||
* index: index into this map.
|
||||
*
|
||||
* Return Value:
|
||||
* The node at the indexth position in the map, or null if that is
|
||||
* not a valid index.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNamedNodeMap_item( IN IXML_NamedNodeMap * nnMap,
|
||||
|
||||
IXML_Node *ixmlNamedNodeMap_item(
|
||||
IN IXML_NamedNodeMap *nnMap,
|
||||
IN unsigned long index )
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
@ -145,16 +123,8 @@ ixmlNamedNodeMap_item( IN IXML_NamedNodeMap * nnMap,
|
||||
return tempNode;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_getLength
|
||||
* Return the number of Nodes in this map.
|
||||
* External function.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
*=================================================================*/
|
||||
unsigned long
|
||||
ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
|
||||
|
||||
unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
unsigned long length = 0;
|
||||
@ -165,17 +135,12 @@ ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
|
||||
tempNode = tempNode->nextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNamedNodeMap_free
|
||||
* frees a NamedNodeMap.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
|
||||
|
||||
void ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
IXML_NamedNodeMap *pNext;
|
||||
|
||||
@ -186,38 +151,27 @@ ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_addToNamedNodeMap
|
||||
* add a node to a NamedNodeMap.
|
||||
* Internal to parser only.
|
||||
* Parameters:
|
||||
* add: the node to add into NamedNodeMap.
|
||||
* Return:
|
||||
* IXML_SUCCESS or failure.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
|
||||
IN IXML_Node * add )
|
||||
|
||||
int ixmlNamedNodeMap_addToNamedNodeMap(
|
||||
IXML_NamedNodeMap **nnMap,
|
||||
IXML_Node *add)
|
||||
{
|
||||
IXML_NamedNodeMap *traverse = NULL,
|
||||
*p = NULL;
|
||||
IXML_NamedNodeMap *traverse = NULL;
|
||||
IXML_NamedNodeMap *p = NULL;
|
||||
IXML_NamedNodeMap *newItem = NULL;
|
||||
|
||||
if(add == NULL) {
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
if( *nnMap == NULL ) // nodelist is empty
|
||||
{
|
||||
*nnMap =
|
||||
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
|
||||
if (*nnMap == NULL) {
|
||||
// nodelist is empty
|
||||
*nnMap = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
|
||||
if (*nnMap == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
ixmlNamedNodeMap_init(*nnMap);
|
||||
}
|
||||
|
||||
if ((*nnMap)->nodeItem == NULL) {
|
||||
(*nnMap)->nodeItem = add;
|
||||
} else {
|
||||
@ -227,9 +181,7 @@ ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
|
||||
p = traverse;
|
||||
traverse = traverse->next;
|
||||
}
|
||||
|
||||
newItem =
|
||||
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
|
||||
newItem = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
|
||||
if (newItem == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
@ -240,3 +192,4 @@ ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
|
||||
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
|
1090
ixml/src/node.c
1090
ixml/src/node.c
File diff suppressed because it is too large
Load Diff
@ -1,61 +1,57 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_init
|
||||
* initializes a nodelist
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNodeList_init( IXML_NodeList * nList )
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void ixmlNodeList_init(IXML_NodeList *nList)
|
||||
{
|
||||
assert(nList != NULL);
|
||||
|
||||
memset(nList, 0, sizeof (IXML_NodeList));
|
||||
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_item
|
||||
* Returns the indexth item in the collection. If index is greater
|
||||
* than or equal to the number of nodes in the list, this returns
|
||||
* null.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNodeList_item( IXML_NodeList * nList,
|
||||
|
||||
IXML_Node *ixmlNodeList_item(
|
||||
IXML_NodeList *nList,
|
||||
unsigned long index)
|
||||
{
|
||||
IXML_NodeList *next;
|
||||
@ -75,24 +71,19 @@ ixmlNodeList_item( IXML_NodeList * nList,
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
if( next == NULL ) return NULL;
|
||||
|
||||
return next->nodeItem;
|
||||
|
||||
if (next == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_addToNodeList
|
||||
* Add a node to nodelist
|
||||
* Internal to parser only.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
|
||||
IN IXML_Node * add )
|
||||
return next->nodeItem;
|
||||
}
|
||||
|
||||
int ixmlNodeList_addToNodeList(
|
||||
IXML_NodeList **nList,
|
||||
IXML_Node *add)
|
||||
{
|
||||
IXML_NodeList *traverse,
|
||||
*p = NULL;
|
||||
IXML_NodeList *traverse = NULL;
|
||||
IXML_NodeList *p = NULL;
|
||||
IXML_NodeList *newListItem;
|
||||
|
||||
assert(add != NULL);
|
||||
@ -101,8 +92,8 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
|
||||
return IXML_FAILED;
|
||||
}
|
||||
|
||||
if( *nList == NULL ) // nodelist is empty
|
||||
{
|
||||
if (*nList == NULL) {
|
||||
// nodelist is empty
|
||||
*nList = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
|
||||
if (*nList == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
@ -120,8 +111,7 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
|
||||
traverse = traverse->next;
|
||||
}
|
||||
|
||||
newListItem =
|
||||
( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
|
||||
newListItem = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
|
||||
if (newListItem == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
@ -133,15 +123,8 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_length
|
||||
* Returns the number of nodes in the list. The range of valid
|
||||
* child node indices is 0 to length-1 inclusive.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
unsigned long
|
||||
ixmlNodeList_length( IN IXML_NodeList * nList )
|
||||
|
||||
unsigned long ixmlNodeList_length(IXML_NodeList *nList)
|
||||
{
|
||||
IXML_NodeList *list;
|
||||
unsigned long length = 0;
|
||||
@ -155,22 +138,15 @@ ixmlNodeList_length( IN IXML_NodeList * nList )
|
||||
return length;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_free
|
||||
* frees a nodeList
|
||||
* External function
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNodeList_free( IN IXML_NodeList * nList )
|
||||
|
||||
void ixmlNodeList_free(IXML_NodeList *nList)
|
||||
{
|
||||
IXML_NodeList *next;
|
||||
|
||||
while (nList != NULL) {
|
||||
next = nList->next;
|
||||
|
||||
free(nList);
|
||||
nList = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,36 +1,41 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "sample_util.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if !UPNP_HAVE_TOOLS
|
||||
# error "Need upnptools.h to compile samples ; try ./configure --enable-tools"
|
||||
@ -45,7 +50,7 @@ int initialize = 1;
|
||||
print_string gPrintFun = NULL;
|
||||
state_update gStateUpdateFun = NULL;
|
||||
|
||||
//mutex to control displaying of events
|
||||
/*! mutex to control displaying of events */
|
||||
ithread_mutex_t display_mutex;
|
||||
|
||||
/********************************************************************************
|
||||
@ -425,10 +430,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
a_event->ServiceID );
|
||||
if( a_event->ActionRequest ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
|
||||
if( xmlbuff )
|
||||
if ( xmlbuff ) {
|
||||
SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActRequest = (null)\n" );
|
||||
@ -436,10 +441,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
|
||||
if( a_event->ActionResult ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
|
||||
if( xmlbuff )
|
||||
if ( xmlbuff ) {
|
||||
SampleUtil_Print( "ActResult = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActResult = (null)\n" );
|
||||
@ -459,10 +464,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
a_event->CtrlUrl );
|
||||
if( a_event->ActionRequest ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
|
||||
if( xmlbuff )
|
||||
if( xmlbuff ) {
|
||||
SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActRequest = (null)\n" );
|
||||
@ -470,10 +475,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
|
||||
if( a_event->ActionResult ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
|
||||
if( xmlbuff )
|
||||
if( xmlbuff ) {
|
||||
SampleUtil_Print( "ActResult = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActResult = (null)\n" );
|
||||
@ -599,7 +604,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
( "======================================================================\n\n\n\n" );
|
||||
|
||||
ithread_mutex_unlock( &display_mutex );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
@ -620,7 +625,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
********************************************************************************/
|
||||
int
|
||||
SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
|
||||
IN char *location,
|
||||
IN const char *location,
|
||||
IN char *serviceType,
|
||||
OUT char **serviceId,
|
||||
OUT char **eventURL,
|
||||
@ -632,18 +637,18 @@ SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
|
||||
int ret;
|
||||
char *tempServiceType = NULL;
|
||||
char *baseURL = NULL;
|
||||
char *base;
|
||||
const char *base = NULL;
|
||||
char *relcontrolURL = NULL,
|
||||
*releventURL = NULL;
|
||||
IXML_NodeList *serviceList = NULL;
|
||||
IXML_Element *service = NULL;
|
||||
|
||||
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
|
||||
|
||||
if( baseURL )
|
||||
if (baseURL) {
|
||||
base = baseURL;
|
||||
else
|
||||
} else {
|
||||
base = location;
|
||||
}
|
||||
|
||||
serviceList = SampleUtil_GetFirstServiceList( DescDoc );
|
||||
length = ixmlNodeList_length( serviceList );
|
||||
@ -753,21 +758,22 @@ uprint1( char *fmt,
|
||||
* Same as printf()
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
SampleUtil_Print( char *fmt,
|
||||
... )
|
||||
int SampleUtil_Print(char *fmt, ...)
|
||||
{
|
||||
#define MAX_BUF 1024
|
||||
va_list ap;
|
||||
char buf[200];
|
||||
static char buf[MAX_BUF];
|
||||
int rc;
|
||||
|
||||
/* Protect both the display and the static buffer with the mutex */
|
||||
ithread_mutex_lock(&display_mutex);
|
||||
va_start(ap, fmt);
|
||||
rc = vsnprintf( buf, 200, fmt, ap );
|
||||
rc = vsnprintf(buf, MAX_BUF, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
ithread_mutex_lock( &display_mutex );
|
||||
if( gPrintFun )
|
||||
if (gPrintFun) {
|
||||
gPrintFun(buf);
|
||||
}
|
||||
ithread_mutex_unlock(&display_mutex);
|
||||
|
||||
return rc;
|
||||
|
@ -166,7 +166,7 @@ int SampleUtil_PrintEvent(IN Upnp_EventType EventType,
|
||||
********************************************************************************/
|
||||
int SampleUtil_FindAndParseService (
|
||||
IN IXML_Document *DescDoc,
|
||||
IN char* location,
|
||||
IN const char *location,
|
||||
IN char *serviceType,
|
||||
OUT char **serviceId,
|
||||
OUT char **eventURL,
|
||||
|
@ -1,40 +1,47 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define DEFAULT_WEB_DIR "./web"
|
||||
|
||||
|
||||
#define DESC_URL_SIZE 200
|
||||
|
||||
|
||||
/*
|
||||
Device type for tv device
|
||||
*/
|
||||
@ -178,7 +185,6 @@ SetServiceTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return SetActionTable( serviceType, out );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -249,7 +255,6 @@ SetActionTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -385,19 +390,22 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
/*
|
||||
PropSet = NULL;
|
||||
|
||||
for (j=0; j< tv_service_table[i].VariableCount; j++)
|
||||
{
|
||||
for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
|
||||
// add each variable to the property set
|
||||
// for initial state dump
|
||||
UpnpAddToPropertySet(&PropSet,
|
||||
UpnpAddToPropertySet(
|
||||
&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
|
||||
// dump initial state
|
||||
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN,
|
||||
UpnpAcceptSubscriptionExt(
|
||||
device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,sr_event->Sid);
|
||||
PropSet,
|
||||
sr_event->Sid);
|
||||
// free document
|
||||
Document_free(PropSet);
|
||||
|
||||
@ -418,9 +426,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* TvDeviceHandleGetVarRequest
|
||||
*
|
||||
@ -437,8 +446,8 @@ int
|
||||
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
*cgv_event )
|
||||
{
|
||||
unsigned int i = 0,
|
||||
j = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
cgv_event->CurrentVal = NULL;
|
||||
@ -496,7 +505,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
int
|
||||
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
{
|
||||
|
||||
/*
|
||||
Defaults if action not found
|
||||
*/
|
||||
@ -649,7 +657,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -672,7 +679,7 @@ TvDeviceSetPower( IN int on )
|
||||
|
||||
if( on != POWER_ON && on != POWER_OFF ) {
|
||||
SampleUtil_Print( "error: can't set power to value %d\n", on );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -683,7 +690,7 @@ TvDeviceSetPower( IN int on )
|
||||
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
|
||||
value );
|
||||
|
||||
return ( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -700,9 +707,7 @@ TvDeviceSetPower( IN int on )
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOn( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = NULL;
|
||||
@ -722,7 +727,6 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -779,11 +783,8 @@ TvDevicePowerOff( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int channel = 0;
|
||||
@ -828,7 +829,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -846,13 +846,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementChannel( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curchannel,
|
||||
newchannel;
|
||||
int curchannel;
|
||||
int newchannel;
|
||||
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
@ -914,12 +911,9 @@ IncrementChannel( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -936,12 +930,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -960,13 +951,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int volume = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1007,7 +994,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1026,10 +1012,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementVolume( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curvolume,
|
||||
newvolume;
|
||||
@ -1066,8 +1049,7 @@ IncrementVolume( IN int incr,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
if( UpnpAddToActionResponse( out, actionName,
|
||||
TvServiceType[TV_SERVICE_CONTROL],
|
||||
"Volume", value ) != UPNP_E_SUCCESS )
|
||||
{
|
||||
"Volume", value ) != UPNP_E_SUCCESS ) {
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
@ -1077,7 +1059,6 @@ IncrementVolume( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1094,13 +1075,9 @@ IncrementVolume( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1117,13 +1094,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1142,13 +1115,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int color = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1188,7 +1157,6 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1205,16 +1173,11 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
* IXML_Document **out - action result document
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
IncrementColor( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcolor,
|
||||
newcolor;
|
||||
|
||||
int curcolor;
|
||||
int newcolor;
|
||||
char *actionName;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1272,11 +1235,8 @@ IncrementColor( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1293,11 +1253,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1317,13 +1274,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int tint = -1;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1382,14 +1335,10 @@ TvDeviceSetTint( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementTint( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curtint,
|
||||
newtint;
|
||||
|
||||
int curtint;
|
||||
int newtint;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1432,7 +1381,6 @@ IncrementTint( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1449,11 +1397,8 @@ IncrementTint( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1471,11 +1416,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1495,11 +1437,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
****************************************************************************/
|
||||
int
|
||||
TvDeviceSetContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int contrast = -1;
|
||||
|
||||
@ -1560,14 +1499,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementContrast( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcontrast,
|
||||
newcontrast;
|
||||
|
||||
int curcontrast;
|
||||
int newcontrast;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1629,11 +1564,8 @@ IncrementContrast( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementContrast( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1651,9 +1583,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
IXML_Document ** out,
|
||||
char **errorString )
|
||||
TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementContrast( -1, in, out, errorString );
|
||||
}
|
||||
@ -1671,11 +1601,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int brightness = -1;
|
||||
|
||||
@ -1718,7 +1645,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1736,13 +1662,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementBrightness( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curbrightness,
|
||||
newbrightness;
|
||||
int curbrightness;
|
||||
int newbrightness;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1803,9 +1726,7 @@ IncrementBrightness( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( 1, in, out, errorString );
|
||||
}
|
||||
@ -1823,9 +1744,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( -1, in, out, errorString );
|
||||
}
|
||||
@ -1849,14 +1768,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
* Cookie -- Optional data specified during callback registration
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
void *Event,
|
||||
void *Cookie )
|
||||
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
|
||||
{
|
||||
|
||||
switch ( EventType ) {
|
||||
|
||||
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
|
||||
|
||||
TvDeviceHandleSubscriptionRequest( ( struct
|
||||
@ -1890,17 +1804,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print
|
||||
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
}
|
||||
|
||||
/*
|
||||
Print a summary of the event received
|
||||
*/
|
||||
/* Print a summary of the event received */
|
||||
SampleUtil_PrintEvent( EventType, Event );
|
||||
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1919,6 +1830,7 @@ TvDeviceStop()
|
||||
UpnpFinish();
|
||||
SampleUtil_Finish();
|
||||
ithread_mutex_destroy( &TVDevMutex );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1951,7 +1863,6 @@ TvDeviceStart( char *ip_address,
|
||||
print_string pfun )
|
||||
{
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
|
||||
char desc_doc_url[DESC_URL_SIZE];
|
||||
|
||||
ithread_mutex_init( &TVDevMutex, NULL );
|
||||
@ -1963,19 +1874,15 @@ TvDeviceStart( char *ip_address,
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address, port );
|
||||
|
||||
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) {
|
||||
ret = UpnpInit( ip_address, port );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
|
||||
UpnpFinish();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if( ip_address == NULL ) {
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
}
|
||||
|
||||
if( port == 0 ) {
|
||||
port = UpnpGetServerPort();
|
||||
}
|
||||
|
||||
SampleUtil_Print(
|
||||
"UPnP Initialized\n"
|
||||
@ -1995,12 +1902,12 @@ TvDeviceStart( char *ip_address,
|
||||
|
||||
SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
|
||||
web_dir_path );
|
||||
if( ( ret =
|
||||
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error specifying webserver root directory -- %s: %d\n",
|
||||
ret = UpnpSetWebServerRootDir( web_dir_path );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
|
||||
web_dir_path, ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2009,12 +1916,12 @@ TvDeviceStart( char *ip_address,
|
||||
"\t with desc_doc_url: %s\n",
|
||||
desc_doc_url );
|
||||
|
||||
if( ( ret = UpnpRegisterRootDevice( desc_doc_url,
|
||||
TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
SampleUtil_Print(
|
||||
@ -2022,17 +1929,17 @@ TvDeviceStart( char *ip_address,
|
||||
"Initializing State Table\n");
|
||||
TvDeviceStateTableInit( desc_doc_url );
|
||||
SampleUtil_Print("State Table Initialized\n");
|
||||
|
||||
if( ( ret =
|
||||
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error sending advertisements : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Advertisements Sent\n");
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,40 +1,47 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define DEFAULT_WEB_DIR "./web"
|
||||
|
||||
|
||||
#define DESC_URL_SIZE 200
|
||||
|
||||
|
||||
/*
|
||||
Device type for tv device
|
||||
*/
|
||||
@ -180,7 +187,6 @@ SetServiceTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return SetActionTable( serviceType, out );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -251,7 +257,6 @@ SetActionTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -387,19 +392,22 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
/*
|
||||
PropSet = NULL;
|
||||
|
||||
for (j=0; j< tv_service_table[i].VariableCount; j++)
|
||||
{
|
||||
for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
|
||||
// add each variable to the property set
|
||||
// for initial state dump
|
||||
UpnpAddToPropertySet(&PropSet,
|
||||
UpnpAddToPropertySet(
|
||||
&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
|
||||
// dump initial state
|
||||
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN,
|
||||
UpnpAcceptSubscriptionExt(
|
||||
device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,sr_event->Sid);
|
||||
PropSet,
|
||||
sr_event->Sid);
|
||||
// free document
|
||||
Document_free(PropSet);
|
||||
|
||||
@ -420,9 +428,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* TvDeviceHandleGetVarRequest
|
||||
*
|
||||
@ -439,8 +448,8 @@ int
|
||||
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
*cgv_event )
|
||||
{
|
||||
unsigned int i = 0,
|
||||
j = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
cgv_event->CurrentVal = NULL;
|
||||
@ -498,7 +507,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
int
|
||||
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
{
|
||||
|
||||
/*
|
||||
Defaults if action not found
|
||||
*/
|
||||
@ -651,7 +659,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -674,7 +681,7 @@ TvDeviceSetPower( IN int on )
|
||||
|
||||
if( on != POWER_ON && on != POWER_OFF ) {
|
||||
SampleUtil_Print( "error: can't set power to value %d\n", on );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -685,7 +692,7 @@ TvDeviceSetPower( IN int on )
|
||||
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
|
||||
value );
|
||||
|
||||
return ( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -702,9 +709,7 @@ TvDeviceSetPower( IN int on )
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOn( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = NULL;
|
||||
@ -724,7 +729,6 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -781,11 +785,8 @@ TvDevicePowerOff( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int channel = 0;
|
||||
@ -830,7 +831,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -848,13 +848,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementChannel( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curchannel,
|
||||
newchannel;
|
||||
int curchannel;
|
||||
int newchannel;
|
||||
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
@ -916,12 +913,9 @@ IncrementChannel( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -938,12 +932,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -962,13 +953,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int volume = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1009,7 +996,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1028,10 +1014,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementVolume( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curvolume,
|
||||
newvolume;
|
||||
@ -1068,8 +1051,7 @@ IncrementVolume( IN int incr,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
if( UpnpAddToActionResponse( out, actionName,
|
||||
TvServiceType[TV_SERVICE_CONTROL],
|
||||
"Volume", value ) != UPNP_E_SUCCESS )
|
||||
{
|
||||
"Volume", value ) != UPNP_E_SUCCESS ) {
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
@ -1079,7 +1061,6 @@ IncrementVolume( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1096,13 +1077,9 @@ IncrementVolume( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1119,13 +1096,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1144,13 +1117,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int color = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1190,7 +1159,6 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1207,16 +1175,11 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
* IXML_Document **out - action result document
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
IncrementColor( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcolor,
|
||||
newcolor;
|
||||
|
||||
int curcolor;
|
||||
int newcolor;
|
||||
char *actionName;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1274,11 +1237,8 @@ IncrementColor( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1295,11 +1255,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1319,13 +1276,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int tint = -1;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1384,14 +1337,10 @@ TvDeviceSetTint( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementTint( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curtint,
|
||||
newtint;
|
||||
|
||||
int curtint;
|
||||
int newtint;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1434,7 +1383,6 @@ IncrementTint( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1451,11 +1399,8 @@ IncrementTint( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1473,11 +1418,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1497,11 +1439,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
****************************************************************************/
|
||||
int
|
||||
TvDeviceSetContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int contrast = -1;
|
||||
|
||||
@ -1562,14 +1501,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementContrast( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcontrast,
|
||||
newcontrast;
|
||||
|
||||
int curcontrast;
|
||||
int newcontrast;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1631,11 +1566,8 @@ IncrementContrast( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementContrast( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1653,9 +1585,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
IXML_Document ** out,
|
||||
char **errorString )
|
||||
TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementContrast( -1, in, out, errorString );
|
||||
}
|
||||
@ -1673,11 +1603,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int brightness = -1;
|
||||
|
||||
@ -1720,7 +1647,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1738,13 +1664,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementBrightness( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curbrightness,
|
||||
newbrightness;
|
||||
int curbrightness;
|
||||
int newbrightness;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1805,9 +1728,7 @@ IncrementBrightness( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( 1, in, out, errorString );
|
||||
}
|
||||
@ -1825,9 +1746,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( -1, in, out, errorString );
|
||||
}
|
||||
@ -1851,14 +1770,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
* Cookie -- Optional data specified during callback registration
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
void *Event,
|
||||
void *Cookie )
|
||||
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
|
||||
{
|
||||
|
||||
switch ( EventType ) {
|
||||
|
||||
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
|
||||
|
||||
TvDeviceHandleSubscriptionRequest( ( struct
|
||||
@ -1892,17 +1806,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print
|
||||
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
}
|
||||
|
||||
/*
|
||||
Print a summary of the event received
|
||||
*/
|
||||
/* Print a summary of the event received */
|
||||
SampleUtil_PrintEvent( EventType, Event );
|
||||
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1921,6 +1832,7 @@ TvDeviceStop()
|
||||
UpnpFinish();
|
||||
SampleUtil_Finish();
|
||||
ithread_mutex_destroy( &TVDevMutex );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1953,7 +1865,6 @@ TvDeviceStart( char *ip_address,
|
||||
print_string pfun )
|
||||
{
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
|
||||
char desc_doc_url[DESC_URL_SIZE];
|
||||
|
||||
ithread_mutex_init( &TVDevMutex, NULL );
|
||||
@ -1965,16 +1876,14 @@ TvDeviceStart( char *ip_address,
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address, port );
|
||||
|
||||
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) {
|
||||
ret = UpnpInit( ip_address, port );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
|
||||
UpnpFinish();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if( ip_address == NULL ) {
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
}
|
||||
|
||||
port = UpnpGetServerPort();
|
||||
|
||||
SampleUtil_Print(
|
||||
@ -1995,12 +1904,12 @@ TvDeviceStart( char *ip_address,
|
||||
|
||||
SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
|
||||
web_dir_path );
|
||||
if( ( ret =
|
||||
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error specifying webserver root directory -- %s: %d\n",
|
||||
ret = UpnpSetWebServerRootDir( web_dir_path );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
|
||||
web_dir_path, ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2009,12 +1918,12 @@ TvDeviceStart( char *ip_address,
|
||||
"\t with desc_doc_url: %s\n",
|
||||
desc_doc_url );
|
||||
|
||||
if( ( ret = UpnpRegisterRootDevice( desc_doc_url,
|
||||
TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
SampleUtil_Print(
|
||||
@ -2022,17 +1931,17 @@ TvDeviceStart( char *ip_address,
|
||||
"Initializing State Table\n");
|
||||
TvDeviceStateTableInit( desc_doc_url );
|
||||
SampleUtil_Print("State Table Initialized\n");
|
||||
|
||||
if( ( ret =
|
||||
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error sending advertisements : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Advertisements Sent\n");
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*******************************************************************************
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
@ -6,12 +6,12 @@
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither name of Intel Corporation nor the names of its contributors
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
@ -27,30 +27,52 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#if EXCLUDE_DOM == 0
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "upnp.h"
|
||||
#include "upnptools.h"
|
||||
|
||||
|
||||
#include "uri.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/*! Maximum action header buffer length. */
|
||||
#define HEADER_LENGTH 2000
|
||||
|
||||
// Structure to maintain a error code and string associated with the
|
||||
// error code
|
||||
struct ErrorString {
|
||||
int rc; /* error code */
|
||||
const char *rcError; /* error description */
|
||||
|
||||
/*!
|
||||
* \brief Structure to maintain a error code and string associated with the
|
||||
* error code.
|
||||
*/
|
||||
struct ErrorString {
|
||||
/*! Error code. */
|
||||
int rc;
|
||||
/*! Error description. */
|
||||
const char *rcError;
|
||||
};
|
||||
|
||||
// Initializing the array of error structures.
|
||||
struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
||||
|
||||
/*!
|
||||
* \brief Array of error structures.
|
||||
*/
|
||||
struct ErrorString ErrorMessages[] = {
|
||||
{UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
||||
{UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
|
||||
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
|
||||
{UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"},
|
||||
@ -82,106 +104,76 @@ struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
||||
{UPNP_E_NOTIFY_UNACCEPTED, "UPNP_E_NOTIFY_UNACCEPTED"},
|
||||
{UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"},
|
||||
{UPNP_E_INVALID_ARGUMENT, "UPNP_E_INVALID_ARGUMENT"},
|
||||
{UPNP_E_OUTOF_BOUNDS, "UPNP_E_OUTOF_BOUNDS"}
|
||||
{UPNP_E_OUTOF_BOUNDS, "UPNP_E_OUTOF_BOUNDS"},
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpGetErrorMessage
|
||||
*
|
||||
* Parameters:
|
||||
* IN int rc: error code
|
||||
*
|
||||
* Description:
|
||||
* This functions returns the error string mapped to the error code
|
||||
* Returns: const char *
|
||||
* return either the right string or "Unknown Error"
|
||||
***************************************************************************/
|
||||
const char *
|
||||
UpnpGetErrorMessage( IN int rc )
|
||||
|
||||
const char *UpnpGetErrorMessage(int rc)
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < sizeof( ErrorMessages ) / sizeof( ErrorMessages[0] );
|
||||
i++ ) {
|
||||
if( rc == ErrorMessages[i].rc )
|
||||
for (i = 0; i < sizeof (ErrorMessages) / sizeof (ErrorMessages[0]); ++i) {
|
||||
if (rc == ErrorMessages[i].rc) {
|
||||
return ErrorMessages[i].rcError;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown Error";
|
||||
|
||||
return "Unknown error code";
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpResolveURL
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * BaseURL: Base URL string
|
||||
* IN char * RelURL: relative URL string
|
||||
* OUT char * AbsURL: Absolute URL string
|
||||
* Description:
|
||||
* This functions concatinates the base URL and relative URL to generate
|
||||
* the absolute URL
|
||||
* Returns: int
|
||||
* return either UPNP_E_SUCCESS or appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpResolveURL( IN const char *BaseURL,
|
||||
IN const char *RelURL,
|
||||
OUT char *AbsURL )
|
||||
|
||||
/*!
|
||||
* \todo There is some unnecessary allocation and deallocation going on here
|
||||
* because of the way resolve_rel_url() was originally written and used. In the
|
||||
* future it would be nice to clean this up.
|
||||
*/
|
||||
int UpnpResolveURL(
|
||||
const char *BaseURL,
|
||||
const char *RelURL,
|
||||
char *AbsURL)
|
||||
{
|
||||
// There is some unnecessary allocation and
|
||||
// deallocation going on here because of the way
|
||||
// resolve_rel_url was originally written and used
|
||||
// in the future it would be nice to clean this up
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
char *tempRel = NULL;
|
||||
|
||||
char *tempRel;
|
||||
|
||||
if( RelURL == NULL )
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
|
||||
tempRel = NULL;
|
||||
if (RelURL == NULL) {
|
||||
ret = UPNP_E_INVALID_PARAM;
|
||||
goto ExitFunction;
|
||||
}
|
||||
|
||||
tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL);
|
||||
|
||||
if (tempRel) {
|
||||
strcpy(AbsURL, tempRel);
|
||||
free(tempRel);
|
||||
} else {
|
||||
return UPNP_E_INVALID_URL;
|
||||
ret = UPNP_E_INVALID_URL;
|
||||
}
|
||||
|
||||
ExitFunction:
|
||||
return UPNP_E_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : addToAction
|
||||
|
||||
/*!
|
||||
* \brief Adds the argument in the action request or response.
|
||||
*
|
||||
* 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
|
||||
* argument, otherwise 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 )
|
||||
* \returns UPNP_E_SUCCESS if successful, otherwise the appropriate error.
|
||||
*/
|
||||
static int addToAction(
|
||||
/*! [in] flag to tell if the ActionDoc is for response or request. */
|
||||
int response,
|
||||
/*! [in,out] Request or response document. */
|
||||
IXML_Document **ActionDoc,
|
||||
/*! [in] Name of the action request or response. */
|
||||
const char *ActionName,
|
||||
/*! [in] Service type. */
|
||||
const char *ServType,
|
||||
/*! [in] Name of the argument. */
|
||||
const char *ArgName,
|
||||
/*! [in] Value of the argument. */
|
||||
const char *ArgValue)
|
||||
{
|
||||
char *ActBuff = NULL;
|
||||
IXML_Node *node = NULL;
|
||||
@ -227,39 +219,32 @@ addToAction( IN int response,
|
||||
Txt = ixmlDocument_createTextNode(*ActionDoc, ArgValue);
|
||||
ixmlNode_appendChild((IXML_Node *)Ele, Txt);
|
||||
}
|
||||
|
||||
ixmlNode_appendChild(node, (IXML_Node *)Ele);
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : makeAction
|
||||
|
||||
/*!
|
||||
* \brief Creates the action request or response from the argument list.
|
||||
*
|
||||
* Parameters:
|
||||
* IN int response: flag to tell if the ActionDoc is for response
|
||||
* or request
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action request or response from the argument
|
||||
* list.
|
||||
* Returns: IXML_Document *
|
||||
* returns action request or response document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
static IXML_Document *
|
||||
makeAction( IN int response,
|
||||
IN const char *ActionName,
|
||||
IN const char *ServType,
|
||||
IN int NumArg,
|
||||
IN const char *Arg,
|
||||
IN va_list ArgList )
|
||||
* \return Action request or response document if successful, otherwise
|
||||
* returns NULL
|
||||
*/
|
||||
static IXML_Document *makeAction(
|
||||
/*! [in] flag to tell if the ActionDoc is for response or request. */
|
||||
int response,
|
||||
/*! [in] Name of the action request or response. */
|
||||
const char *ActionName,
|
||||
/*! [in] Service type. */
|
||||
const char *ServType,
|
||||
/*! [in] Number of arguments in the action request or response. */
|
||||
int NumArg,
|
||||
/*! [in] pointer to the first argument. */
|
||||
const char *Arg,
|
||||
/*! [in] Argument list. */
|
||||
va_list ArgList)
|
||||
{
|
||||
const char *ArgName;
|
||||
const char *ArgValue;
|
||||
@ -288,14 +273,12 @@ makeAction( IN int response,
|
||||
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
|
||||
ActionName, ServType, ActionName);
|
||||
}
|
||||
|
||||
if (ixmlParseBufferEx(ActBuff, &ActionDoc) != IXML_SUCCESS) {
|
||||
free(ActBuff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(ActBuff);
|
||||
|
||||
if(ActionDoc == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -305,19 +288,15 @@ makeAction( IN int response,
|
||||
ArgName = Arg;
|
||||
for ( ; ; ) {
|
||||
ArgValue = va_arg(ArgList, const char *);
|
||||
|
||||
if (ArgName != NULL) {
|
||||
node = ixmlNode_getFirstChild((IXML_Node *)ActionDoc);
|
||||
Ele = ixmlDocument_createElement(ActionDoc, ArgName);
|
||||
if (ArgValue) {
|
||||
Txt =
|
||||
ixmlDocument_createTextNode( ActionDoc, ArgValue );
|
||||
Txt = ixmlDocument_createTextNode(ActionDoc, ArgValue);
|
||||
ixmlNode_appendChild((IXML_Node *)Ele, Txt);
|
||||
}
|
||||
|
||||
ixmlNode_appendChild(node, (IXML_Node *)Ele);
|
||||
}
|
||||
|
||||
if (++Idx < NumArg) {
|
||||
ArgName = va_arg(ArgList, const char *);
|
||||
} else {
|
||||
@ -330,28 +309,9 @@ makeAction( IN int response,
|
||||
return ActionDoc;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpMakeAction
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN ... : variable argument list
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action request from the argument
|
||||
* list. Its a wrapper function that calls makeAction function to create
|
||||
* the action request.
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns action request document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpMakeAction( const char *ActionName,
|
||||
|
||||
IXML_Document *UpnpMakeAction(
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
@ -367,28 +327,9 @@ UpnpMakeAction( const char *ActionName,
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpMakeActionResponse
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN ... : variable argument list
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action response from the argument
|
||||
* list. Its a wrapper function that calls makeAction function to create
|
||||
* the action response.
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns action response document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpMakeActionResponse( const char *ActionName,
|
||||
|
||||
IXML_Document *UpnpMakeActionResponse(
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
@ -404,89 +345,86 @@ UpnpMakeActionResponse( const char *ActionName,
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToActionResponse
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **ActionResponse: action response document
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int ArgName :Name of argument to be added in the action response
|
||||
* IN char * ArgValue : value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the action response. Its a wrapper
|
||||
* function that calls addToAction function to add the argument in the
|
||||
* action response.
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful
|
||||
* else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToActionResponse( INOUT IXML_Document ** ActionResponse,
|
||||
IN const char *ActionName,
|
||||
IN const char *ServType,
|
||||
IN const char *ArgName,
|
||||
IN const char *ArgValue )
|
||||
{
|
||||
return addToAction( 1, ActionResponse, ActionName, ServType, ArgName,
|
||||
ArgValue );
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToAction
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **ActionDoc: action request document
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int ArgName :Name of argument to be added in the action response
|
||||
* IN char * ArgValue : value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the action request. Its a wrapper
|
||||
* function that calls addToAction function to add the argument in the
|
||||
* action request.
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful
|
||||
* else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToAction( IXML_Document ** ActionDoc,
|
||||
int UpnpAddToAction(
|
||||
IXML_Document **ActionDoc,
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
const char *ArgName,
|
||||
const char *ArgValue)
|
||||
{
|
||||
|
||||
return addToAction( 0, ActionDoc, ActionName, ServType, ArgName,
|
||||
ArgValue );
|
||||
return addToAction(0, ActionDoc, ActionName, ServType, ArgName, ArgValue);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToPropertySet
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **PropSet: propertyset document
|
||||
* IN char *ArgName: Name of the argument
|
||||
* IN char *ArgValue: value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the propertyset node
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToPropertySet( INOUT IXML_Document ** PropSet,
|
||||
IN const char *ArgName,
|
||||
IN const char *ArgValue )
|
||||
{
|
||||
|
||||
char BlankDoc[] = "<e:propertyset xmlns:e=\"urn:schemas"
|
||||
"-upnp-org:event-1-0\"></e:propertyset>";
|
||||
int UpnpAddToActionResponse(
|
||||
IXML_Document **ActionResponse,
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
const char *ArgName,
|
||||
const char *ArgValue)
|
||||
{
|
||||
return addToAction(1, ActionResponse, ActionName, ServType, ArgName, ArgValue);
|
||||
}
|
||||
|
||||
|
||||
IXML_Document *UpnpCreatePropertySet(
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
...)
|
||||
{
|
||||
va_list ArgList;
|
||||
int Idx = 0;
|
||||
char BlankDoc[] =
|
||||
"<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"
|
||||
"</e:propertyset>";
|
||||
const char *ArgName,
|
||||
*ArgValue;
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
IXML_Node *Txt;
|
||||
IXML_Document *PropSet;
|
||||
|
||||
if(ixmlParseBufferEx(BlankDoc, &PropSet) != IXML_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (NumArg < 1) {
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
va_start(ArgList, Arg);
|
||||
ArgName = Arg;
|
||||
while (Idx++ != NumArg) {
|
||||
ArgValue = va_arg(ArgList, const char *);
|
||||
if (ArgName != NULL /*&& ArgValue != NULL */) {
|
||||
node = ixmlNode_getFirstChild((IXML_Node *)PropSet);
|
||||
Ele1 = ixmlDocument_createElement(PropSet, "e:property");
|
||||
Ele = ixmlDocument_createElement(PropSet, ArgName);
|
||||
if (ArgValue) {
|
||||
Txt = ixmlDocument_createTextNode(PropSet, ArgValue);
|
||||
ixmlNode_appendChild((IXML_Node *)Ele, Txt);
|
||||
}
|
||||
ixmlNode_appendChild((IXML_Node *)Ele1, (IXML_Node *)Ele);
|
||||
ixmlNode_appendChild( node, (IXML_Node *)Ele1);
|
||||
}
|
||||
ArgName = va_arg(ArgList, const char *);
|
||||
}
|
||||
va_end(ArgList);
|
||||
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
|
||||
int UpnpAddToPropertySet(
|
||||
IXML_Document **PropSet,
|
||||
const char *ArgName,
|
||||
const char *ArgValue)
|
||||
{
|
||||
char BlankDoc[] =
|
||||
"<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"
|
||||
"</e:propertyset>";
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
@ -520,71 +458,6 @@ UpnpAddToPropertySet( INOUT IXML_Document ** PropSet,
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpCreatePropertySet
|
||||
*
|
||||
* Parameters:
|
||||
* IN int NumArg: Number of argument that will go in the propertyset node
|
||||
* IN char * Args: argument strings
|
||||
*
|
||||
* Description:
|
||||
* This function creates a propertyset node and put all the input
|
||||
* parameters in the node as elements
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns the document containing propertyset node.
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpCreatePropertySet( IN int NumArg,
|
||||
IN const char *Arg,
|
||||
... )
|
||||
{
|
||||
va_list ArgList;
|
||||
int Idx = 0;
|
||||
char BlankDoc[] = "<e:propertyset xmlns:e=\"urn:schemas-"
|
||||
"upnp-org:event-1-0\"></e:propertyset>";
|
||||
const char *ArgName,
|
||||
*ArgValue;
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
IXML_Node *Txt;
|
||||
IXML_Document *PropSet;
|
||||
|
||||
if( ixmlParseBufferEx( BlankDoc, &PropSet ) != IXML_SUCCESS ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (NumArg < 1) {
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
va_start( ArgList, Arg );
|
||||
ArgName = Arg;
|
||||
|
||||
while( Idx++ != NumArg ) {
|
||||
ArgValue = va_arg( ArgList, const char * );
|
||||
|
||||
if( ArgName != NULL /*&& ArgValue != NULL */ ) {
|
||||
node = ixmlNode_getFirstChild( ( IXML_Node * ) PropSet );
|
||||
Ele1 = ixmlDocument_createElement( PropSet, "e:property" );
|
||||
Ele = ixmlDocument_createElement( PropSet, ArgName );
|
||||
if( ArgValue ) {
|
||||
Txt = ixmlDocument_createTextNode( PropSet, ArgValue );
|
||||
ixmlNode_appendChild( ( IXML_Node * ) Ele, Txt );
|
||||
}
|
||||
|
||||
ixmlNode_appendChild( ( IXML_Node * ) Ele1,
|
||||
( IXML_Node * ) Ele );
|
||||
ixmlNode_appendChild( node, ( IXML_Node * ) Ele1 );
|
||||
}
|
||||
|
||||
ArgName = va_arg( ArgList, const char * );
|
||||
|
||||
}
|
||||
va_end( ArgList );
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
#endif // EXCLUDE_DOM == 0
|
||||
#endif /* EXCLUDE_DOM == 0 */
|
||||
|
||||
|
@ -1,43 +1,48 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Purpose: This file contains functions for copying strings based on
|
||||
* different options.
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "upnp.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : linecopy
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user