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:
Marcelo Roberto Jimenez 2008-07-27 05:01:52 +00:00
parent 881b212690
commit 812d019d12
18 changed files with 7393 additions and 8275 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +1,53 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "ixmlparser.h" #include "ixmlparser.h"
/*================================================================
* Function: Attr_init #include <string.h>
* Initializes an attribute node
* External function.
* void ixmlAttr_init(IN IXML_Attr *attr)
*=================================================================*/
void
ixmlAttr_init( IN IXML_Attr * attr )
{ {
if (attr != NULL) { if (attr != NULL) {
memset(attr, 0, sizeof (IXML_Attr)); memset(attr, 0, sizeof (IXML_Attr));
} }
} }
/*================================================================
* Function: Attr_free void ixmlAttr_free(IN IXML_Attr *attr)
* Frees an attribute node.
* external function.
*
*=================================================================*/
void
ixmlAttr_free( IN IXML_Attr * attr )
{ {
if (attr != NULL) { if (attr != NULL) {
ixmlNode_free((IXML_Node *)attr); ixmlNode_free((IXML_Node *)attr);
} }
} }

View File

@ -1,119 +1,97 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/*!
* \file
*/
#include "ixmldebug.h"
#include "ixmlparser.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "ixmlparser.h"
/*================================================================ void ixmlDocument_init(IXML_Document *doc)
* ixmlDocument_init
* It initialize the document structure.
* External function.
*
*=================================================================*/
void
ixmlDocument_init( IN IXML_Document * doc )
{ {
memset(doc, 0, sizeof(IXML_Document)); memset(doc, 0, sizeof(IXML_Document));
} }
/*================================================================
* ixmlDocument_free void ixmlDocument_free(IXML_Document *doc)
* It frees the whole document tree.
* External function.
*
*=================================================================*/
void
ixmlDocument_free( IN IXML_Document * doc )
{ {
if (doc != NULL) { if (doc != NULL) {
ixmlNode_free((IXML_Node *)doc); ixmlNode_free((IXML_Node *)doc);
} }
} }
/*================================================================
* ixmlDocument_setOwnerDocument /*!
* * When this function is called first time, nodeptr is the root of the subtree,
* When this function is called first time, nodeptr is the root * so it is not necessay to do two steps recursion.
* of the subtree, so it is not necessay to do two steps
* recursion.
* *
* Internal function called by ixmlDocument_importNode * Internal function called by ixmlDocument_importNode
* */
*=================================================================*/ static void ixmlDocument_setOwnerDocument(
void /*! [in] The document node. */
ixmlDocument_setOwnerDocument( IN IXML_Document * doc, IXML_Document *doc,
IN IXML_Node * nodeptr ) /*! [in] \todo documentation. */
IXML_Node *nodeptr)
{ {
if (nodeptr != NULL) { if (nodeptr != NULL) {
nodeptr->ownerDocument = doc; nodeptr->ownerDocument = doc;
ixmlDocument_setOwnerDocument( doc, ixmlDocument_setOwnerDocument(
ixmlNode_getFirstChild( nodeptr ) ); doc, ixmlNode_getFirstChild(nodeptr));
ixmlDocument_setOwnerDocument( doc, ixmlDocument_setOwnerDocument(
ixmlNode_getNextSibling doc, ixmlNode_getNextSibling(nodeptr));
( 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 int ixmlDocument_importNode(
* by the importing document, with attribute values identical to IXML_Document *doc,
* the source node's nodeName and nodeType, plus the attributes IXML_Node *importNode,
* related to namespaces (prefix, localName, and namespaceURI). BOOL deep,
* As in the cloneNode operation on a node, the source node is IXML_Node **rtNode)
* not altered.
*
* External function.
*
*=================================================================*/
int
ixmlDocument_importNode( IN IXML_Document * doc,
IN IXML_Node * importNode,
IN BOOL deep,
OUT IXML_Node ** rtNode )
{ {
unsigned short nodeType; unsigned short nodeType;
IXML_Node *newNode; IXML_Node *newNode;
*rtNode = NULL; *rtNode = NULL;
if( ( doc == NULL ) || ( importNode == NULL ) ) { if (doc == NULL || importNode == NULL) {
return IXML_INVALID_PARAMETER; return IXML_INVALID_PARAMETER;
} }
@ -133,29 +111,16 @@ ixmlDocument_importNode( IN IXML_Document * doc,
return IXML_SUCCESS; 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; int errCode = IXML_SUCCESS;
IXML_Element *newElement = NULL; IXML_Element *newElement = NULL;
if( ( doc == NULL ) || ( tagName == NULL ) ) { if (doc == NULL || tagName == NULL) {
errCode = IXML_INVALID_PARAMETER; errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler; goto ErrorHandler;
} }
@ -188,46 +153,23 @@ ixmlDocument_createElementEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*rtElement = newElement; *rtElement = newElement;
return errCode;
return errCode;
} }
/*================================================================
* ixmlDocument_createElement IXML_Element *ixmlDocument_createElement(
* Creates an element of the type specified. IXML_Document *doc,
* External function. const DOMString tagName)
* 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 *newElement = NULL; IXML_Element *newElement = NULL;
ixmlDocument_createElementEx(doc, tagName, &newElement); ixmlDocument_createElementEx(doc, tagName, &newElement);
return newElement; return newElement;
} }
/*================================================================
* ixmlDocument_createDocumentEx int ixmlDocument_createDocumentEx(IXML_Document **rtDoc)
* 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 )
{ {
IXML_Document *doc; IXML_Document *doc;
int errCode = IXML_SUCCESS; int errCode = IXML_SUCCESS;
@ -257,49 +199,27 @@ ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
return errCode; return errCode;
} }
/*================================================================
* ixmlDocument_createDocument IXML_Document *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 *doc = NULL; IXML_Document *doc = NULL;
ixmlDocument_createDocumentEx(&doc); ixmlDocument_createDocumentEx(&doc);
return doc; return doc;
} }
/*================================================================
* ixmlDocument_createTextNodeEx int ixmlDocument_createTextNodeEx(
* Creates an text node. IXML_Document *doc,
* External function. const DOMString data,
* Parameters: IXML_Node **textNode)
* 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 )
{ {
IXML_Node *returnNode; IXML_Node *returnNode;
int rc = IXML_SUCCESS; int rc = IXML_SUCCESS;
returnNode = NULL; returnNode = NULL;
if( ( doc == NULL ) || ( data == NULL ) ) { if (doc == NULL || data == NULL) {
rc = IXML_INVALID_PARAMETER; rc = IXML_INVALID_PARAMETER;
goto ErrorHandler; goto ErrorHandler;
} }
@ -336,22 +256,12 @@ ixmlDocument_createTextNodeEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*textNode = returnNode; *textNode = returnNode;
return rc; return rc;
} }
/*================================================================
* ixmlDocument_createTextNode IXML_Node *ixmlDocument_createTextNode(
* Creates an text node. IXML_Document *doc,
* External function. const DOMString data)
* 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 *returnNode = NULL; IXML_Node *returnNode = NULL;
@ -360,21 +270,11 @@ ixmlDocument_createTextNode( IN IXML_Document * doc,
return returnNode; return returnNode;
} }
/*================================================================
* ixmlDocument_createAttributeEx int ixmlDocument_createAttributeEx(
* Creates an attribute of the given name. IXML_Document *doc,
* External function. const char *name,
* Parameters: IXML_Attr **rtAttr)
* 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 )
{ {
IXML_Attr *attrNode = NULL; IXML_Attr *attrNode = NULL;
int errCode = IXML_SUCCESS; int errCode = IXML_SUCCESS;
@ -385,7 +285,7 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
goto ErrorHandler; goto ErrorHandler;
} }
if( ( doc == NULL ) || ( name == NULL ) ) { if (doc == NULL || name == NULL) {
ixmlAttr_free(attrNode); ixmlAttr_free(attrNode);
attrNode = NULL; attrNode = NULL;
errCode = IXML_INVALID_PARAMETER; errCode = IXML_INVALID_PARAMETER;
@ -393,7 +293,6 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
} }
ixmlAttr_init(attrNode); ixmlAttr_init(attrNode);
attrNode->n.nodeType = eATTRIBUTE_NODE; attrNode->n.nodeType = eATTRIBUTE_NODE;
// set the node fields // set the node fields
@ -410,56 +309,31 @@ ixmlDocument_createAttributeEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*rtAttr = attrNode; *rtAttr = attrNode;
return errCode; return errCode;
} }
/*================================================================
* ixmlDocument_createAttribute IXML_Attr *ixmlDocument_createAttribute(
* Creates an attribute of the given name. IXML_Document *doc,
* External function. const char *name)
* 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 *attrNode = NULL; IXML_Attr *attrNode = NULL;
ixmlDocument_createAttributeEx(doc, name, &attrNode); ixmlDocument_createAttributeEx(doc, name, &attrNode);
return attrNode;
return attrNode;
} }
/*================================================================
* ixmlDocument_createAttributeNSEx int ixmlDocument_createAttributeNSEx(
* Creates an attrbute of the given name and namespace URI IXML_Document *doc,
* External function. const DOMString namespaceURI,
* Parameters: const DOMString qualifiedName,
* namespaceURI: the namespace fo the attribute to create IXML_Attr **rtAttr )
* 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 )
{ {
IXML_Attr *attrNode = NULL; IXML_Attr *attrNode = NULL;
int errCode = IXML_SUCCESS; int errCode = IXML_SUCCESS;
if( ( doc == NULL ) || ( namespaceURI == NULL ) if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) {
|| ( qualifiedName == NULL ) ) {
errCode = IXML_INVALID_PARAMETER; errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler; goto ErrorHandler;
} }
@ -489,68 +363,43 @@ ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*rtAttr = attrNode; *rtAttr = attrNode;
return errCode; return errCode;
} }
/*================================================================
* ixmlDocument_createAttributeNS IXML_Attr *ixmlDocument_createAttributeNS(
* Creates an attrbute of the given name and namespace URI IXML_Document *doc,
* External function. const DOMString namespaceURI,
* Parameters: const DOMString qualifiedName)
* 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 *attrNode = NULL; IXML_Attr *attrNode = NULL;
ixmlDocument_createAttributeNSEx( doc, namespaceURI, qualifiedName, ixmlDocument_createAttributeNSEx(
&attrNode ); doc, namespaceURI, qualifiedName, &attrNode);
return attrNode; return attrNode;
} }
/*================================================================
* ixmlDocument_createCDATASectionEx int ixmlDocument_createCDATASectionEx(
* Creates an CDATASection node whose value is the specified string IXML_Document *doc,
* External function. const DOMString data,
* Parameters: IXML_CDATASection **rtCD)
* 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 errCode = IXML_SUCCESS; int errCode = IXML_SUCCESS;
IXML_CDATASection *cDSectionNode = NULL; IXML_CDATASection *cDSectionNode = NULL;
if( ( doc == NULL ) || ( data == NULL ) ) { if(doc == NULL || data == NULL) {
errCode = IXML_INVALID_PARAMETER; errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler; goto ErrorHandler;
} }
cDSectionNode = cDSectionNode = (IXML_CDATASection *)malloc(sizeof (IXML_CDATASection));
( IXML_CDATASection * ) malloc( sizeof( IXML_CDATASection ) );
if (cDSectionNode == NULL) { if (cDSectionNode == NULL) {
errCode = IXML_INSUFFICIENT_MEMORY; errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler; goto ErrorHandler;
} }
ixmlCDATASection_init(cDSectionNode); ixmlCDATASection_init(cDSectionNode);
cDSectionNode->n.nodeType = eCDATA_SECTION_NODE; cDSectionNode->n.nodeType = eCDATA_SECTION_NODE;
cDSectionNode->n.nodeName = strdup(CDATANODENAME); cDSectionNode->n.nodeName = strdup(CDATANODENAME);
if (cDSectionNode->n.nodeName == NULL) { if (cDSectionNode->n.nodeName == NULL) {
@ -573,77 +422,55 @@ ixmlDocument_createCDATASectionEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*rtCD = cDSectionNode; *rtCD = cDSectionNode;
return errCode; 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; IXML_CDATASection *cDSectionNode = NULL;
ixmlDocument_createCDATASectionEx(doc, data, &cDSectionNode); ixmlDocument_createCDATASectionEx(doc, data, &cDSectionNode);
return 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; IXML_Element *newElement = NULL;
int errCode = IXML_SUCCESS; int errCode = IXML_SUCCESS;
int line = 0;
if( ( doc == NULL ) || ( namespaceURI == NULL ) if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) {
|| ( qualifiedName == NULL ) ) { line = __LINE__;
errCode = IXML_INVALID_PARAMETER; errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler; goto ErrorHandler;
} }
errCode = errCode = ixmlDocument_createElementEx(doc, qualifiedName, &newElement);
ixmlDocument_createElementEx( doc, qualifiedName, &newElement );
if (errCode != IXML_SUCCESS) { if (errCode != IXML_SUCCESS) {
line = __LINE__;
goto ErrorHandler; goto ErrorHandler;
} }
// set the namespaceURI field // set the namespaceURI field
newElement->n.namespaceURI = strdup(namespaceURI); newElement->n.namespaceURI = strdup(namespaceURI);
if (newElement->n.namespaceURI == NULL) { if (newElement->n.namespaceURI == NULL) {
line = __LINE__;
ixmlElement_free(newElement); ixmlElement_free(newElement);
newElement = NULL; newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY; errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler; goto ErrorHandler;
} }
// set the localName and prefix // set the localName and prefix
errCode = errCode = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName);
ixmlNode_setNodeName( ( IXML_Node * ) newElement, qualifiedName );
if (errCode != IXML_SUCCESS) { if (errCode != IXML_SUCCESS) {
line = __LINE__;
ixmlElement_free(newElement); ixmlElement_free(newElement);
newElement = NULL; newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY; errCode = IXML_INSUFFICIENT_MEMORY;
@ -654,115 +481,71 @@ ixmlDocument_createElementNSEx( IN IXML_Document * doc,
ErrorHandler: ErrorHandler:
*rtElement = newElement; *rtElement = newElement;
return errCode; if (errCode != IXML_SUCCESS) {
IxmlPrintf("(%s::ixmlDocument_createElementNSEx): Error %d, line %d\n",
__FILE__, errCode, line);
} }
/*================================================================ return errCode;
* ixmlDocument_createElementNS }
* Creates an element of the given qualified name and namespace URI.
* External function.
* Parameters: IXML_Element *ixmlDocument_createElementNS(
* namespaceURI: the namespace URI of the element to create. IXML_Document *doc,
* qualifiedName: the qualified name of the element to instantiate. const DOMString namespaceURI,
* Return Value: const DOMString qualifiedName)
* 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 )
{ {
IXML_Element *newElement = NULL; IXML_Element *newElement = NULL;
ixmlDocument_createElementNSEx( doc, namespaceURI, qualifiedName, ixmlDocument_createElementNSEx(doc, namespaceURI, qualifiedName, &newElement);
&newElement );
return newElement; return newElement;
} }
/*================================================================
* ixmlDocument_getElementsByTagName IXML_NodeList *ixmlDocument_getElementsByTagName(
* Returns a nodeList of all the Elements with a given tag name IXML_Document *doc,
* in the order in which they are encountered in a preorder traversal const DOMString tagName)
* 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 *returnNodeList = NULL; IXML_NodeList *returnNodeList = NULL;
if( ( doc == NULL ) || ( tagName == NULL ) ) { if (doc == NULL || tagName == NULL) {
return NULL; return NULL;
} }
ixmlNode_getElementsByTagName( ( IXML_Node * ) doc, tagName, ixmlNode_getElementsByTagName((IXML_Node *)doc, tagName, &returnNodeList);
&returnNodeList );
return returnNodeList; return returnNodeList;
} }
/*================================================================
* ixmlDocument_getElementsByTagNameNS IXML_NodeList *ixmlDocument_getElementsByTagNameNS(
* Returns a nodeList of all the Elements with a given local name and IXML_Document *doc,
* namespace URI in the order in which they are encountered in a const DOMString namespaceURI,
* preorder traversal of the document tree. const DOMString localName)
* 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 *returnNodeList = NULL; IXML_NodeList *returnNodeList = NULL;
if( ( doc == NULL ) || ( namespaceURI == NULL ) if (doc == NULL || namespaceURI == NULL || localName == NULL) {
|| ( localName == NULL ) ) {
return NULL; return NULL;
} }
ixmlNode_getElementsByTagNameNS( ( IXML_Node * ) doc, namespaceURI, ixmlNode_getElementsByTagNameNS(
localName, &returnNodeList ); (IXML_Node *)doc, namespaceURI, localName, &returnNodeList);
return returnNodeList; return returnNodeList;
} }
/*================================================================
* ixmlDocument_getElementById IXML_Element *ixmlDocument_getElementById(
* Returns the element whose ID is given by tagName. If no such IXML_Document *doc,
* element exists, returns null. const DOMString tagName)
* 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 *rtElement = NULL; IXML_Element *rtElement = NULL;
IXML_Node *nodeptr = (IXML_Node *)doc; IXML_Node *nodeptr = (IXML_Node *)doc;
const char *name; const char *name;
if( ( nodeptr == NULL ) || ( tagName == NULL ) ) { if (nodeptr == NULL || tagName == NULL) {
return rtElement; return rtElement;
} }
@ -776,29 +559,26 @@ ixmlDocument_getElementById( IN IXML_Document * doc,
rtElement = (IXML_Element *)nodeptr; rtElement = (IXML_Element *)nodeptr;
return rtElement; return rtElement;
} else { } else {
rtElement = ixmlDocument_getElementById( ( IXML_Document * ) rtElement = ixmlDocument_getElementById(
ixmlNode_getFirstChild (IXML_Document *)ixmlNode_getFirstChild(nodeptr),
( nodeptr ),
tagName ); tagName );
if (rtElement == NULL) { if (rtElement == NULL) {
rtElement = ixmlDocument_getElementById( ( IXML_Document rtElement = ixmlDocument_getElementById(
* ) (IXML_Document *)ixmlNode_getNextSibling(nodeptr),
ixmlNode_getNextSibling
( nodeptr ),
tagName); tagName);
} }
} }
} else { } else {
rtElement = ixmlDocument_getElementById( ( IXML_Document * ) rtElement = ixmlDocument_getElementById(
ixmlNode_getFirstChild (IXML_Document *)ixmlNode_getFirstChild(nodeptr),
( nodeptr ), tagName ); tagName);
if (rtElement == NULL) { if (rtElement == NULL) {
rtElement = ixmlDocument_getElementById( ( IXML_Document * ) rtElement = ixmlDocument_getElementById(
ixmlNode_getNextSibling (IXML_Document *)ixmlNode_getNextSibling(nodeptr),
( nodeptr ),
tagName); tagName);
} }
} }
return rtElement; return rtElement;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,73 +1,173 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 "ixml.h"
#include <stdlib.h> /* for size_t */
#define MINVAL(a, b) ( (a) < (b) ? (a) : (b) ) #define MINVAL(a, b) ( (a) < (b) ? (a) : (b) )
#define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) ) #define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
#define MEMBUF_DEF_SIZE_INC 20 #define MEMBUF_DEF_SIZE_INC 20
typedef struct // ixml_membuf /*!
* \brief The ixml_membuf type.
*/
typedef struct
{ {
char *buf; char *buf;
size_t length; size_t length;
size_t capacity; size_t capacity;
size_t size_inc; size_t size_inc;
} ixml_membuf; } ixml_membuf;
//--------------------------------------------------
//////////////// functions ///////////////////////// /*!
//-------------------------------------------------- * \brief ixml_membuf initialization routine.
/*
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
*/ */
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 */

View File

@ -1,41 +1,49 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 "ixml.h"
#include "ixmlmembuf.h" #include "ixmlmembuf.h"
// Parser definitions
/* Parser definitions */
#define QUOT "&quot;" #define QUOT "&quot;"
#define LT "&lt;" #define LT "&lt;"
#define GT "&gt;" #define GT "&gt;"
@ -44,6 +52,7 @@
#define ESC_HEX "&#x" #define ESC_HEX "&#x"
#define ESC_DEC "&#" #define ESC_DEC "&#"
typedef struct _IXML_NamespaceURI typedef struct _IXML_NamespaceURI
{ {
char *nsURI; char *nsURI;
@ -69,52 +78,192 @@ typedef enum
eCONTENT, eCONTENT,
} PARSER_STATE; } PARSER_STATE;
typedef struct _Parser typedef struct _Parser
{ {
char *dataBuffer; //data buffer /*! Data buffer. */
char *curPtr; //ptr to the token parsed char *dataBuffer;
char *savePtr; //Saves for backup /*! Pointer to the token parsed. */
char *curPtr;
/*! Saves for backup. */
char *savePtr;
ixml_membuf lastElem; ixml_membuf lastElem;
ixml_membuf tokenBuf; ixml_membuf tokenBuf;
IXML_Node *pNeedPrefixNode; IXML_Node *pNeedPrefixNode;
IXML_ElementStack *pCurElement; IXML_ElementStack *pCurElement;
IXML_Node *currentNodePtr; IXML_Node *currentNodePtr;
PARSER_STATE state; PARSER_STATE state;
BOOL bHasTopLevel; BOOL bHasTopLevel;
} Parser; } 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); 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); 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); 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 */

View File

@ -1,51 +1,65 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// **************************************************************************/
/*!
* \file
*/
#include "ixmldebug.h"
#include "ixmlmembuf.h" #include "ixmlmembuf.h"
#include "ixmlparser.h" #include "ixmlparser.h"
/*================================================================
* copy_with_escape #include <stdlib.h> /* for free() */
* #include <string.h>
*
*=================================================================*/
static void /*!
copy_with_escape( INOUT ixml_membuf * buf, * \brief Appends a string to a buffer, substituting some characters by escape
IN const char *p ) * 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 i;
int plen; int plen;
if( p == NULL ) if (p == NULL) {
return; return;
}
plen = strlen( p ); plen = strlen( p );
@ -73,19 +87,21 @@ copy_with_escape( INOUT ixml_membuf * buf,
default: default:
ixml_membuf_append(buf, &p[i]); 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. * Internal to parser only.
* */
*=================================================================*/ static void ixmlPrintDomTreeRecursive(
void /*! [in] \todo documentation. */
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr, IXML_Node *nodeptr,
IN ixml_membuf * buf ) /*! [in] \todo documentation. */
ixml_membuf *buf)
{ {
const char *nodeName = NULL; const char *nodeName = NULL;
const char *nodeValue = NULL; const char *nodeValue = NULL;
@ -97,7 +113,6 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
nodeValue = ixmlNode_getNodeValue(nodeptr); nodeValue = ixmlNode_getNodeValue(nodeptr);
switch (ixmlNode_getNodeType(nodeptr)) { switch (ixmlNode_getNodeType(nodeptr)) {
case eTEXT_NODE: case eTEXT_NODE:
copy_with_escape(buf, nodeValue); copy_with_escape(buf, nodeValue);
break; break;
@ -117,8 +132,8 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
break; break;
case eDOCUMENT_NODE: case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild ixmlPrintDomTreeRecursive(
( nodeptr ), buf ); ixmlNode_getFirstChild(nodeptr), buf);
break; break;
case eATTRIBUTE_NODE: case eATTRIBUTE_NODE:
@ -126,7 +141,6 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
ixml_membuf_append_str(buf, "=\""); ixml_membuf_append_str(buf, "=\"");
copy_with_escape(buf, nodeValue); copy_with_escape(buf, nodeValue);
ixml_membuf_append_str(buf, "\""); ixml_membuf_append_str(buf, "\"");
if (nodeptr->nextSibling != NULL) { if (nodeptr->nextSibling != NULL) {
ixml_membuf_append_str(buf, " "); ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf); ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf);
@ -136,71 +150,69 @@ ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
case eELEMENT_NODE: case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<"); ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) { if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " "); ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
} }
child = ixmlNode_getFirstChild(nodeptr); child = ixmlNode_getFirstChild(nodeptr);
if( ( child != NULL ) if (child != NULL &&
&& ( ixmlNode_getNodeType( child ) == ixmlNode_getNodeType(child) == eELEMENT_NODE) {
eELEMENT_NODE ) ) {
ixml_membuf_append_str(buf, ">\r\n"); ixml_membuf_append_str(buf, ">\r\n");
} else { } else {
ixml_membuf_append_str(buf, ">"); ixml_membuf_append_str(buf, ">");
} }
// output the children // output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild ixmlPrintDomTreeRecursive(
( nodeptr ), buf ); ixmlNode_getFirstChild(nodeptr), buf);
// Done with children. Output the end tag. // Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</"); ixml_membuf_append_str(buf, "</");
ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, nodeName);
sibling = ixmlNode_getNextSibling(nodeptr); sibling = ixmlNode_getNextSibling(nodeptr);
if( sibling != NULL if (sibling != NULL &&
&& ixmlNode_getNodeType( sibling ) == eTEXT_NODE ) { ixmlNode_getNodeType(sibling) == eTEXT_NODE) {
ixml_membuf_append_str( buf, ">" ); ixml_membuf_append_str( buf, ">" );
} else { } else {
ixml_membuf_append_str( buf, ">\r\n" ); ixml_membuf_append_str( buf, ">\r\n" );
} }
ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling ixmlPrintDomTreeRecursive(
( nodeptr ), buf ); ixmlNode_getNextSibling(nodeptr), buf);
break; break;
default: default:
IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break; break;
} }
} }
} }
/*================================================================
* ixmlPrintDomTree /*!
* Print a DOM tree. * \brief 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.
* *
*=================================================================*/ * Element, and Attribute nodes are handled differently. We don't want to print
void * the Element and Attribute nodes' sibling.
ixmlPrintDomTree( IN IXML_Node * nodeptr, */
IN ixml_membuf * buf ) static void ixmlPrintDomTree(
/*! [in] \todo documentation. */
IXML_Node *nodeptr,
/*! [in] \todo documentation. */
ixml_membuf *buf)
{ {
const char *nodeName = NULL; const char *nodeName = NULL;
const char *nodeValue = NULL; const char *nodeValue = NULL;
IXML_Node *child = NULL; IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) { if (nodeptr == NULL || buf == NULL) {
return; return;
} }
nodeName = (const char *)ixmlNode_getNodeName(nodeptr); nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
nodeValue = ixmlNode_getNodeValue(nodeptr); nodeValue = ixmlNode_getNodeValue(nodeptr);
switch (ixmlNode_getNodeType(nodeptr)) { switch (ixmlNode_getNodeType(nodeptr)) {
case eTEXT_NODE: case eTEXT_NODE:
case eCDATA_SECTION_NODE: case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE: case ePROCESSING_INSTRUCTION_NODE:
@ -218,23 +230,21 @@ ixmlPrintDomTree( IN IXML_Node * nodeptr,
case eELEMENT_NODE: case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<"); ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) { if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " "); ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
} }
child = ixmlNode_getFirstChild(nodeptr); child = ixmlNode_getFirstChild(nodeptr);
if( ( child != NULL ) if (child != NULL &&
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) { ixmlNode_getNodeType(child) == eELEMENT_NODE) {
ixml_membuf_append_str(buf, ">\r\n"); ixml_membuf_append_str(buf, ">\r\n");
} else { } else {
ixml_membuf_append_str(buf, ">"); ixml_membuf_append_str(buf, ">");
} }
// output the children // output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ), ixmlPrintDomTreeRecursive(
buf ); ixmlNode_getFirstChild(nodeptr), buf);
// Done with children. Output the end tag. // Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</"); ixml_membuf_append_str(buf, "</");
@ -243,27 +253,31 @@ ixmlPrintDomTree( IN IXML_Node * nodeptr,
break; break;
default: default:
IxmlPrintf("(%s::ixmlPrintDomTree) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break; break;
} }
} }
/*================================================================
* ixmlDomTreetoString /*!
* Converts a DOM tree into a text string * \brief 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.
* *
*=================================================================*/ * Element, and Attribute nodes are handled differently. We don't want to print
void * the Element and Attribute nodes' sibling.
ixmlDomTreetoString( IN IXML_Node * nodeptr, */
IN ixml_membuf * buf ) static void ixmlDomTreetoString(
/*! [in] \todo documentation. */
IXML_Node *nodeptr,
/*! [in] \todo documentation. */
ixml_membuf *buf)
{ {
const char *nodeName = NULL; const char *nodeName = NULL;
const char *nodeValue = NULL; const char *nodeValue = NULL;
IXML_Node *child = NULL; IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) { if (nodeptr == NULL || buf == NULL) {
return; return;
} }
@ -271,7 +285,6 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
nodeValue = ixmlNode_getNodeValue(nodeptr); nodeValue = ixmlNode_getNodeValue(nodeptr);
switch (ixmlNode_getNodeType(nodeptr)) { switch (ixmlNode_getNodeType(nodeptr)) {
case eTEXT_NODE: case eTEXT_NODE:
case eCDATA_SECTION_NODE: case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE: case ePROCESSING_INSTRUCTION_NODE:
@ -289,23 +302,20 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
case eELEMENT_NODE: case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<"); ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName); ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) { if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " "); ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
} }
child = ixmlNode_getFirstChild(nodeptr); child = ixmlNode_getFirstChild(nodeptr);
if( ( child != NULL ) if (child != NULL &&
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) { ixmlNode_getNodeType(child) == eELEMENT_NODE) {
ixml_membuf_append_str(buf, ">"); ixml_membuf_append_str(buf, ">");
} else { } else {
ixml_membuf_append_str(buf, ">"); ixml_membuf_append_str(buf, ">");
} }
// output the children // output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ), ixmlPrintDomTreeRecursive(ixmlNode_getFirstChild(nodeptr), buf);
buf );
// Done with children. Output the end tag. // Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</"); ixml_membuf_append_str(buf, "</");
@ -314,54 +324,35 @@ ixmlDomTreetoString( IN IXML_Node * nodeptr,
break; break;
default: default:
IxmlPrintf("(%s::ixmlDomTreetoString) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break; 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 IXML_INVALID_PARAMETER;
} }
return Parser_LoadDocument(doc, xmlFile, TRUE); 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; IXML_Document *doc = NULL;
ixmlLoadDocumentEx(xmlFile, &doc); ixmlLoadDocumentEx(xmlFile, &doc);
return doc; return doc;
} }
/*================================================================
* ixmlPrintDocument
* Prints entire document, prepending XML prolog first.
* Puts lots of white spaces.
* External function.
*
*=================================================================*/
DOMString DOMString ixmlPrintDocument(IXML_Document *doc)
ixmlPrintDocument(IXML_Document *doc)
{ {
IXML_Node* rootNode = (IXML_Node *)doc; IXML_Node* rootNode = (IXML_Node *)doc;
ixml_membuf memBuf; ixml_membuf memBuf;
@ -374,20 +365,13 @@ ixmlPrintDocument(IXML_Document *doc)
ixml_membuf_init(buf); ixml_membuf_init(buf);
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n"); ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
ixmlPrintDomTree(rootNode, buf); 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 memBuf;
ixml_membuf *buf = &memBuf; ixml_membuf *buf = &memBuf;
@ -397,20 +381,12 @@ ixmlPrintNode( IN IXML_Node * node )
ixml_membuf_init(buf); ixml_membuf_init(buf);
ixmlPrintDomTree(node, 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 DOMString ixmlDocumenttoString(IXML_Document *doc)
ixmlDocumenttoString(IXML_Document *doc)
{ {
IXML_Node* rootNode = (IXML_Node *)doc; IXML_Node* rootNode = (IXML_Node *)doc;
ixml_membuf memBuf; ixml_membuf memBuf;
@ -423,20 +399,13 @@ ixmlDocumenttoString(IXML_Document *doc)
ixml_membuf_init(buf); ixml_membuf_init(buf);
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n"); ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
ixmlDomTreetoString(rootNode, buf); 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 memBuf;
ixml_membuf *buf = &memBuf; ixml_membuf *buf = &memBuf;
@ -446,35 +415,20 @@ ixmlNodetoString( IN IXML_Node * node )
ixml_membuf_init(buf); ixml_membuf_init(buf);
ixmlDomTreetoString(node, buf); ixmlDomTreetoString(node, buf);
return buf->buf;
return buf->buf;
} }
/*================================================================
* ixmlRelaxParser void ixmlRelaxParser(char errorChar)
* Makes the XML parser more tolerant to malformed text.
* External function.
*
*=================================================================*/
void
ixmlRelaxParser(char errorChar)
{ {
Parser_setErrorChar(errorChar); Parser_setErrorChar(errorChar);
} }
/*================================================================ int ixmlParseBufferEx(const char *buffer, IXML_Document **retDoc)
* ixmlParseBufferEx
* Parse xml file stored in buffer.
* External function.
*
*=================================================================*/
int
ixmlParseBufferEx( IN const char *buffer,
IXML_Document ** retDoc )
{ {
if (buffer == NULL || retDoc == NULL) {
if( ( buffer == NULL ) || ( retDoc == NULL ) ) {
return IXML_INVALID_PARAMETER; return IXML_INVALID_PARAMETER;
} }
@ -485,47 +439,31 @@ ixmlParseBufferEx( IN const char *buffer,
return Parser_LoadDocument(retDoc, buffer, FALSE); return Parser_LoadDocument(retDoc, buffer, FALSE);
} }
/*================================================================
* ixmlParseBuffer IXML_Document *ixmlParseBuffer(const char *buffer)
* Parse xml file stored in buffer.
* External function.
*
*=================================================================*/
IXML_Document *
ixmlParseBuffer( IN const char *buffer )
{ {
IXML_Document *doc = NULL; IXML_Document *doc = NULL;
ixmlParseBufferEx(buffer, &doc); ixmlParseBufferEx(buffer, &doc);
return doc; return doc;
} }
/*================================================================
* ixmlCloneDOMString DOMString ixmlCloneDOMString(const DOMString src)
* Clones a DOM String.
* External function.
*
*=================================================================*/
DOMString
ixmlCloneDOMString( IN const DOMString src )
{ {
if (src == NULL) { if (src == NULL) {
return NULL; return NULL;
} }
return ( strdup( src ) ); return strdup(src);
} }
/*================================================================
* ixmlFreeDOMString void ixmlFreeDOMString(DOMString buf)
* Frees a DOM String.
* External function.
*
*=================================================================*/
void
ixmlFreeDOMString( IN DOMString buf )
{ {
if (buf != NULL) { if (buf != NULL) {
free(buf); free(buf);
} }
} }

View File

@ -1,79 +1,87 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// **************************************************************************/
/*!
* \file
*/
#include "ixmlmembuf.h"
#include "ixml.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "ixmlmembuf.h"
#include "ixml.h"
/*================================================================
* ixml_membuf_set_size /*!
* * \brief Increases or decreases buffer capacity so that at least 'new_length'
* Increases or decreases buffer cap so that at least * bytes can be stored.
* 'new_length' bytes can be stored
* *
* On error, m's fields do not change. * On error, m's fields do not change.
* *
* returns: * \return
* UPNP_E_SUCCESS * \li UPNP_E_SUCCESS
* UPNP_E_OUTOF_MEMORY * \li UPNP_E_OUTOF_MEMORY
* */
*=================================================================*/ static int ixml_membuf_set_size(
static int /*! [in,out] The memory buffer. */
ixml_membuf_set_size( INOUT ixml_membuf * m, INOUT ixml_membuf *m,
/*! [in] The new lenght. */
IN size_t new_length) IN size_t new_length)
{ {
size_t diff; size_t diff;
size_t alloc_len; size_t alloc_len;
char *temp_buf; char *temp_buf;
if( new_length >= m->length ) // increase length if (new_length >= m->length) {
{ /* increase length */
// need more mem? /* need more mem? */
if (new_length <= m->capacity) { if (new_length <= m->capacity) {
return 0; // have enough mem; done /* have enough mem; done */
return 0;
} }
diff = new_length - m->length; diff = new_length - m->length;
alloc_len = MAXVAL(m->size_inc, diff) + m->capacity; alloc_len = MAXVAL(m->size_inc, diff) + m->capacity;
} else // decrease length } else {
{ // decrease length
assert(new_length <= m->length); assert(new_length <= m->length);
// if diff is 0..m->size_inc, don't free // if diff is 0..m->size_inc, don't free
if ((m->capacity - new_length) <= m->size_inc) { if ((m->capacity - new_length) <= m->size_inc) {
return 0; return 0;
} }
alloc_len = new_length + m->size_inc; 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); temp_buf = realloc(m->buf, alloc_len + 1);
if (temp_buf == NULL) { if (temp_buf == NULL) {
// try smaller size /* try smaller size */
alloc_len = new_length; alloc_len = new_length;
temp_buf = realloc(m->buf, alloc_len + 1); temp_buf = realloc(m->buf, alloc_len + 1);
if (temp_buf == NULL) { if (temp_buf == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
} }
// save /* save */
m->buf = temp_buf; m->buf = temp_buf;
m->capacity = alloc_len; m->capacity = alloc_len;
return 0; return 0;
} }
/*================================================================
* membuffer_init void ixml_membuf_init(ixml_membuf *m)
*
*
*=================================================================*/
void
ixml_membuf_init( INOUT ixml_membuf * m )
{ {
assert(m != NULL); assert(m != NULL);
@ -111,13 +114,8 @@ ixml_membuf_init( INOUT ixml_membuf * m )
m->capacity = 0; m->capacity = 0;
} }
/*================================================================
* membuffer_destroy void ixml_membuf_destroy(ixml_membuf *m)
*
*
*=================================================================*/
void
ixml_membuf_destroy( INOUT ixml_membuf * m )
{ {
if (m == NULL) { if (m == NULL) {
return; return;
@ -127,15 +125,11 @@ ixml_membuf_destroy( INOUT ixml_membuf * m )
ixml_membuf_init(m); ixml_membuf_init(m);
} }
/*================================================================
* ixml_membuf_assign int ixml_membuf_assign(
* ixml_membuf *m,
* const void *buf,
*=================================================================*/ size_t buf_len)
int
ixml_membuf_assign( INOUT ixml_membuf * m,
IN const void *buf,
IN size_t buf_len )
{ {
int return_code; int return_code;
@ -151,35 +145,28 @@ ixml_membuf_assign( INOUT ixml_membuf * m,
if (return_code != 0) { if (return_code != 0) {
return return_code; return return_code;
} }
// copy // copy
memcpy(m->buf, buf, buf_len); memcpy(m->buf, buf, buf_len);
m->buf[buf_len] = 0; // null-terminate
// null-terminate
m->buf[buf_len] = 0;
m->length = buf_len; m->length = buf_len;
return IXML_SUCCESS; return IXML_SUCCESS;
} }
/*================================================================
* ixml_membuf_assign_str int ixml_membuf_assign_str(
* ixml_membuf *m,
* const char *c_str)
*=================================================================*/
int
ixml_membuf_assign_str( INOUT ixml_membuf * m,
IN const char *c_str )
{ {
return ixml_membuf_assign(m, c_str, strlen(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) IN const void *buf)
{ {
assert(m != NULL); assert(m != NULL);
@ -187,50 +174,45 @@ ixml_membuf_append( INOUT ixml_membuf * m,
return ixml_membuf_insert(m, buf, 1, m->length); 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) IN const char *c_str)
{ {
return ixml_membuf_insert(m, c_str, strlen(c_str), m->length); 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 const void *buf,
IN size_t buf_len, IN size_t buf_len,
int index) int index)
{ {
int return_code; int return_code = 0;
assert(m != NULL); assert(m != NULL);
if( index < 0 || index > ( int )m->length ) if (index < 0 || index > (int)m->length) {
return IXML_INDEX_SIZE_ERR; return IXML_INDEX_SIZE_ERR;
}
if (buf == NULL || buf_len == 0) { if (buf == NULL || buf_len == 0) {
return 0; return 0;
} }
// alloc mem /* alloc mem */
return_code = ixml_membuf_set_size(m, m->length + buf_len); return_code = ixml_membuf_set_size(m, m->length + buf_len);
if (return_code != 0) { if (return_code != 0) {
return return_code; return return_code;
} }
// insert data /* insert data */
// move data to right of insertion point /* move data to right of insertion point */
memmove(m->buf + index + buf_len, m->buf + index, m->length - index); memmove(m->buf + index + buf_len, m->buf + index, m->length - index);
memcpy(m->buf + index, buf, buf_len); memcpy(m->buf + index, buf, buf_len);
m->length += buf_len; m->length += buf_len;
m->buf[m->length] = 0; // null-terminate /* Null terminate */
m->buf[m->length] = 0;
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,53 +1,62 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// **************************************************************************/
/*!
* \file
*/
#include "ixmlparser.h" #include "ixmlparser.h"
/*================================================================
* NamedNodeMap_getItemNumber #include <assert.h>
* return the item number of a item in NamedNodeMap. #include <stdlib.h> /* for free(), malloc() */
* Internal to parser only. #include <string.h>
* Parameters:
* name: the name of the item to find
* /*!
*=================================================================*/ * \brief Return the item number of a item in NamedNodeMap.
unsigned long */
ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap, 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) IN const char *name)
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
unsigned long returnItemNo = 0; unsigned long returnItemNo = 0;
assert(nnMap != NULL && name != NULL); assert(nnMap != NULL && name != NULL);
if( ( nnMap == NULL ) || ( name == NULL ) ) { if (nnMap == NULL || name == NULL) {
return IXML_INVALID_ITEM_NUMBER; return IXML_INVALID_ITEM_NUMBER;
} }
@ -56,7 +65,6 @@ ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
if (strcmp(name, tempNode->nodeName) == 0) { if (strcmp(name, tempNode->nodeName) == 0) {
return returnItemNo; return returnItemNo;
} }
tempNode = tempNode->nextSibling; tempNode = tempNode->nextSibling;
returnItemNo++; returnItemNo++;
} }
@ -64,39 +72,22 @@ ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
return IXML_INVALID_ITEM_NUMBER; return IXML_INVALID_ITEM_NUMBER;
} }
/*================================================================
* NamedNodeMap_init void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap)
* Initializes a NamedNodeMap object.
* External function.
*
*=================================================================*/
void
ixmlNamedNodeMap_init( IN IXML_NamedNodeMap * nnMap )
{ {
assert(nnMap != NULL); assert(nnMap != NULL);
memset(nnMap, 0, sizeof (IXML_NamedNodeMap)); memset(nnMap, 0, sizeof (IXML_NamedNodeMap));
} }
/*================================================================
* NamedNodeMap_getNamedItem IXML_Node *ixmlNamedNodeMap_getNamedItem(
* Retrieves a node specified by name. IXML_NamedNodeMap *nnMap,
* External function. const DOMString name)
*
* 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 )
{ {
long index; long index;
if( ( nnMap == NULL ) || ( name == NULL ) ) { if (nnMap == NULL || name == NULL) {
return NULL; return NULL;
} }
@ -104,26 +95,13 @@ ixmlNamedNodeMap_getNamedItem( IN IXML_NamedNodeMap * nnMap,
if (index == IXML_INVALID_ITEM_NUMBER) { if (index == IXML_INVALID_ITEM_NUMBER) {
return NULL; return NULL;
} else { } else {
return ( ixmlNamedNodeMap_item( nnMap, ( unsigned long )index ) ); return ixmlNamedNodeMap_item(nnMap, (unsigned long)index);
} }
} }
/*================================================================
* NamedNodeMap_item IXML_Node *ixmlNamedNodeMap_item(
* Returns the indexth item in the map. If index is greater than or IN IXML_NamedNodeMap *nnMap,
* 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,
IN unsigned long index ) IN unsigned long index )
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
@ -145,16 +123,8 @@ ixmlNamedNodeMap_item( IN IXML_NamedNodeMap * nnMap,
return tempNode; return tempNode;
} }
/*================================================================
* NamedNodeMap_getLength unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
* Return the number of Nodes in this map.
* External function.
*
* Parameters:
*
*=================================================================*/
unsigned long
ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
unsigned long length = 0; unsigned long length = 0;
@ -165,17 +135,12 @@ ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
tempNode = tempNode->nextSibling; tempNode = tempNode->nextSibling;
} }
} }
return length; return length;
} }
/*================================================================
* ixmlNamedNodeMap_free void ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap)
* frees a NamedNodeMap.
* External function.
*
*=================================================================*/
void
ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
{ {
IXML_NamedNodeMap *pNext; IXML_NamedNodeMap *pNext;
@ -186,38 +151,27 @@ ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
} }
} }
/*================================================================
* NamedNodeMap_addToNamedNodeMap int ixmlNamedNodeMap_addToNamedNodeMap(
* add a node to a NamedNodeMap. IXML_NamedNodeMap **nnMap,
* Internal to parser only. IXML_Node *add)
* Parameters:
* add: the node to add into NamedNodeMap.
* Return:
* IXML_SUCCESS or failure.
*
*=================================================================*/
int
ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
IN IXML_Node * add )
{ {
IXML_NamedNodeMap *traverse = NULL, IXML_NamedNodeMap *traverse = NULL;
*p = NULL; IXML_NamedNodeMap *p = NULL;
IXML_NamedNodeMap *newItem = NULL; IXML_NamedNodeMap *newItem = NULL;
if(add == NULL) { if(add == NULL) {
return IXML_SUCCESS; return IXML_SUCCESS;
} }
if( *nnMap == NULL ) // nodelist is empty if (*nnMap == NULL) {
{ // nodelist is empty
*nnMap = *nnMap = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
if (*nnMap == NULL) { if (*nnMap == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
ixmlNamedNodeMap_init(*nnMap); ixmlNamedNodeMap_init(*nnMap);
} }
if ((*nnMap)->nodeItem == NULL) { if ((*nnMap)->nodeItem == NULL) {
(*nnMap)->nodeItem = add; (*nnMap)->nodeItem = add;
} else { } else {
@ -227,9 +181,7 @@ ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
p = traverse; p = traverse;
traverse = traverse->next; traverse = traverse->next;
} }
newItem = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
newItem =
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
if (newItem == NULL) { if (newItem == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
@ -240,3 +192,4 @@ ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
return IXML_SUCCESS; return IXML_SUCCESS;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +1,57 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/*!
* \file
*/
#include "ixmlparser.h" #include "ixmlparser.h"
/*================================================================
* ixmlNodeList_init #include <assert.h>
* initializes a nodelist #include <string.h>
* External function.
*
*=================================================================*/ void ixmlNodeList_init(IXML_NodeList *nList)
void
ixmlNodeList_init( IXML_NodeList * nList )
{ {
assert(nList != NULL); assert(nList != NULL);
memset(nList, 0, sizeof (IXML_NodeList)); memset(nList, 0, sizeof (IXML_NodeList));
} }
/*================================================================
* ixmlNodeList_item IXML_Node *ixmlNodeList_item(
* Returns the indexth item in the collection. If index is greater IXML_NodeList *nList,
* than or equal to the number of nodes in the list, this returns
* null.
* External function.
*
*=================================================================*/
IXML_Node *
ixmlNodeList_item( IXML_NodeList * nList,
unsigned long index) unsigned long index)
{ {
IXML_NodeList *next; IXML_NodeList *next;
@ -75,24 +71,19 @@ ixmlNodeList_item( IXML_NodeList * nList,
next = next->next; next = next->next;
} }
if( next == NULL ) return NULL; if (next == NULL) {
return NULL;
return next->nodeItem;
} }
/*================================================================ return next->nodeItem;
* ixmlNodeList_addToNodeList }
* Add a node to nodelist
* Internal to parser only. int ixmlNodeList_addToNodeList(
* IXML_NodeList **nList,
*=================================================================*/ IXML_Node *add)
int
ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
IN IXML_Node * add )
{ {
IXML_NodeList *traverse, IXML_NodeList *traverse = NULL;
*p = NULL; IXML_NodeList *p = NULL;
IXML_NodeList *newListItem; IXML_NodeList *newListItem;
assert(add != NULL); assert(add != NULL);
@ -101,8 +92,8 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
return IXML_FAILED; return IXML_FAILED;
} }
if( *nList == NULL ) // nodelist is empty if (*nList == NULL) {
{ // nodelist is empty
*nList = (IXML_NodeList *)malloc(sizeof (IXML_NodeList)); *nList = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
if (*nList == NULL) { if (*nList == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
@ -120,8 +111,7 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
traverse = traverse->next; traverse = traverse->next;
} }
newListItem = newListItem = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
if (newListItem == NULL) { if (newListItem == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
@ -133,15 +123,8 @@ ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
return IXML_SUCCESS; return IXML_SUCCESS;
} }
/*================================================================
* ixmlNodeList_length unsigned long ixmlNodeList_length(IXML_NodeList *nList)
* 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 )
{ {
IXML_NodeList *list; IXML_NodeList *list;
unsigned long length = 0; unsigned long length = 0;
@ -155,22 +138,15 @@ ixmlNodeList_length( IN IXML_NodeList * nList )
return length; return length;
} }
/*================================================================
* ixmlNodeList_free void ixmlNodeList_free(IXML_NodeList *nList)
* frees a nodeList
* External function
*
*=================================================================*/
void
ixmlNodeList_free( IN IXML_NodeList * nList )
{ {
IXML_NodeList *next; IXML_NodeList *next;
while (nList != NULL) { while (nList != NULL) {
next = nList->next; next = nList->next;
free(nList); free(nList);
nList = next; nList = next;
} }
} }

View File

@ -1,36 +1,41 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "sample_util.h" #include "sample_util.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#if !UPNP_HAVE_TOOLS #if !UPNP_HAVE_TOOLS
# error "Need upnptools.h to compile samples ; try ./configure --enable-tools" # error "Need upnptools.h to compile samples ; try ./configure --enable-tools"
@ -45,7 +50,7 @@ int initialize = 1;
print_string gPrintFun = NULL; print_string gPrintFun = NULL;
state_update gStateUpdateFun = NULL; state_update gStateUpdateFun = NULL;
//mutex to control displaying of events /*! mutex to control displaying of events */
ithread_mutex_t display_mutex; ithread_mutex_t display_mutex;
/******************************************************************************** /********************************************************************************
@ -425,10 +430,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
a_event->ServiceID ); a_event->ServiceID );
if( a_event->ActionRequest ) { if( a_event->ActionRequest ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
if( xmlbuff ) if ( xmlbuff ) {
SampleUtil_Print( "ActRequest = %s\n", xmlbuff ); SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActRequest = (null)\n" ); SampleUtil_Print( "ActRequest = (null)\n" );
@ -436,10 +441,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
if( a_event->ActionResult ) { if( a_event->ActionResult ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
if( xmlbuff ) if ( xmlbuff ) {
SampleUtil_Print( "ActResult = %s\n", xmlbuff ); SampleUtil_Print( "ActResult = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActResult = (null)\n" ); SampleUtil_Print( "ActResult = (null)\n" );
@ -459,10 +464,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
a_event->CtrlUrl ); a_event->CtrlUrl );
if( a_event->ActionRequest ) { if( a_event->ActionRequest ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
if( xmlbuff ) if( xmlbuff ) {
SampleUtil_Print( "ActRequest = %s\n", xmlbuff ); SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActRequest = (null)\n" ); SampleUtil_Print( "ActRequest = (null)\n" );
@ -470,10 +475,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
if( a_event->ActionResult ) { if( a_event->ActionResult ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
if( xmlbuff ) if( xmlbuff ) {
SampleUtil_Print( "ActResult = %s\n", xmlbuff ); SampleUtil_Print( "ActResult = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActResult = (null)\n" ); SampleUtil_Print( "ActResult = (null)\n" );
@ -599,7 +604,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
( "======================================================================\n\n\n\n" ); ( "======================================================================\n\n\n\n" );
ithread_mutex_unlock( &display_mutex ); ithread_mutex_unlock( &display_mutex );
return ( 0 ); return 0;
} }
/******************************************************************************** /********************************************************************************
@ -620,7 +625,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
********************************************************************************/ ********************************************************************************/
int int
SampleUtil_FindAndParseService( IN IXML_Document * DescDoc, SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
IN char *location, IN const char *location,
IN char *serviceType, IN char *serviceType,
OUT char **serviceId, OUT char **serviceId,
OUT char **eventURL, OUT char **eventURL,
@ -632,18 +637,18 @@ SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
int ret; int ret;
char *tempServiceType = NULL; char *tempServiceType = NULL;
char *baseURL = NULL; char *baseURL = NULL;
char *base; const char *base = NULL;
char *relcontrolURL = NULL, char *relcontrolURL = NULL,
*releventURL = NULL; *releventURL = NULL;
IXML_NodeList *serviceList = NULL; IXML_NodeList *serviceList = NULL;
IXML_Element *service = NULL; IXML_Element *service = NULL;
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" ); baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
if (baseURL) {
if( baseURL )
base = baseURL; base = baseURL;
else } else {
base = location; base = location;
}
serviceList = SampleUtil_GetFirstServiceList( DescDoc ); serviceList = SampleUtil_GetFirstServiceList( DescDoc );
length = ixmlNodeList_length( serviceList ); length = ixmlNodeList_length( serviceList );
@ -753,21 +758,22 @@ uprint1( char *fmt,
* Same as printf() * Same as printf()
* *
********************************************************************************/ ********************************************************************************/
int int SampleUtil_Print(char *fmt, ...)
SampleUtil_Print( char *fmt,
... )
{ {
#define MAX_BUF 1024
va_list ap; va_list ap;
char buf[200]; static char buf[MAX_BUF];
int rc; int rc;
/* Protect both the display and the static buffer with the mutex */
ithread_mutex_lock(&display_mutex);
va_start(ap, fmt); va_start(ap, fmt);
rc = vsnprintf( buf, 200, fmt, ap ); rc = vsnprintf(buf, MAX_BUF, fmt, ap);
va_end(ap); va_end(ap);
ithread_mutex_lock( &display_mutex ); if (gPrintFun) {
if( gPrintFun )
gPrintFun(buf); gPrintFun(buf);
}
ithread_mutex_unlock(&display_mutex); ithread_mutex_unlock(&display_mutex);
return rc; return rc;

View File

@ -166,7 +166,7 @@ int SampleUtil_PrintEvent(IN Upnp_EventType EventType,
********************************************************************************/ ********************************************************************************/
int SampleUtil_FindAndParseService ( int SampleUtil_FindAndParseService (
IN IXML_Document *DescDoc, IN IXML_Document *DescDoc,
IN char* location, IN const char *location,
IN char *serviceType, IN char *serviceType,
OUT char **serviceId, OUT char **serviceId,
OUT char **eventURL, OUT char **eventURL,

View File

@ -1,40 +1,47 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "upnp_tv_device.h" #include "upnp_tv_device.h"
#include <assert.h>
#define DEFAULT_WEB_DIR "./web" #define DEFAULT_WEB_DIR "./web"
#define DESC_URL_SIZE 200 #define DESC_URL_SIZE 200
/* /*
Device type for tv device Device type for tv device
*/ */
@ -178,7 +185,6 @@ SetServiceTable( IN int serviceType,
} }
return SetActionTable( serviceType, out ); return SetActionTable( serviceType, out );
} }
/****************************************************************************** /******************************************************************************
@ -249,7 +255,6 @@ SetActionTable( IN int serviceType,
} }
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -385,19 +390,22 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
/* /*
PropSet = NULL; 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 // add each variable to the property set
// for initial state dump // for initial state dump
UpnpAddToPropertySet(&PropSet, UpnpAddToPropertySet(
&PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state // dump initial state
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN, UpnpAcceptSubscriptionExt(
device_handle,
sr_event->UDN,
sr_event->ServiceId, sr_event->ServiceId,
PropSet,sr_event->Sid); PropSet,
sr_event->Sid);
// free document // free document
Document_free(PropSet); Document_free(PropSet);
@ -418,9 +426,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return 1;
} }
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest
* *
@ -437,8 +446,8 @@ int
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
*cgv_event ) *cgv_event )
{ {
unsigned int i = 0, unsigned int i = 0;
j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
cgv_event->CurrentVal = NULL; cgv_event->CurrentVal = NULL;
@ -496,7 +505,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
int int
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event ) TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
{ {
/* /*
Defaults if action not found Defaults if action not found
*/ */
@ -649,7 +657,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return ( 1 );
} }
/****************************************************************************** /******************************************************************************
@ -672,7 +679,7 @@ TvDeviceSetPower( IN int on )
if( on != POWER_ON && on != POWER_OFF ) { if( on != POWER_ON && on != POWER_OFF ) {
SampleUtil_Print( "error: can't set power to value %d\n", on ); 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, ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
value ); value );
return ( ret ); return ret;
} }
/****************************************************************************** /******************************************************************************
@ -700,9 +707,7 @@ TvDeviceSetPower( IN int on )
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOn( IN IXML_Document * in, TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
@ -722,7 +727,6 @@ TvDevicePowerOn( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -779,11 +783,8 @@ TvDevicePowerOff( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetChannel( IN IXML_Document * in, TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int channel = 0; int channel = 0;
@ -828,7 +829,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -846,13 +846,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementChannel( IN int incr, IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curchannel, int curchannel;
newchannel; int newchannel;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -914,12 +911,9 @@ IncrementChannel( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseChannel( IN IXML_Document * in, TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( -1, in, out, errorString ); return IncrementChannel( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -936,12 +930,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseChannel( IN IXML_Document * in, TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( 1, in, out, errorString ); return IncrementChannel( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -960,13 +951,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetVolume( IN IXML_Document * in, TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int volume = 0; int volume = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1007,7 +994,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1026,10 +1012,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
IncrementVolume( IN int incr, IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curvolume, int curvolume,
newvolume; newvolume;
@ -1066,8 +1049,7 @@ IncrementVolume( IN int incr,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
if( UpnpAddToActionResponse( out, actionName, if( UpnpAddToActionResponse( out, actionName,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
"Volume", value ) != UPNP_E_SUCCESS ) "Volume", value ) != UPNP_E_SUCCESS ) {
{
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
@ -1077,7 +1059,6 @@ IncrementVolume( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1094,13 +1075,9 @@ IncrementVolume( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseVolume( IN IXML_Document * in, TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( 1, in, out, errorString ); return IncrementVolume( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1117,13 +1094,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseVolume( IN IXML_Document * in, TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( -1, in, out, errorString ); return IncrementVolume( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1142,13 +1115,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetColor( IN IXML_Document * in, TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int color = 0; int color = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1188,7 +1157,6 @@ TvDeviceSetColor( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1205,16 +1173,11 @@ TvDeviceSetColor( IN IXML_Document * in,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementColor( IN int incr, IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcolor, int curcolor;
newcolor; int newcolor;
char *actionName; char *actionName;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1272,11 +1235,8 @@ IncrementColor( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseColor( IN IXML_Document * in, TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( -1, in, out, errorString ); return IncrementColor( -1, in, out, errorString );
} }
@ -1293,11 +1253,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseColor( IN IXML_Document * in, TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( 1, in, out, errorString ); return IncrementColor( 1, in, out, errorString );
} }
@ -1317,13 +1274,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetTint( IN IXML_Document * in, TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int tint = -1; int tint = -1;
( *out ) = NULL; ( *out ) = NULL;
@ -1382,14 +1335,10 @@ TvDeviceSetTint( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementTint( IN int incr, IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curtint, int curtint;
newtint; int newtint;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1432,7 +1381,6 @@ IncrementTint( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1449,11 +1397,8 @@ IncrementTint( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseTint( IN IXML_Document * in, TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( 1, in, out, errorString ); return IncrementTint( 1, in, out, errorString );
} }
@ -1471,11 +1416,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseTint( IN IXML_Document * in, TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( -1, in, out, errorString ); return IncrementTint( -1, in, out, errorString );
} }
@ -1495,11 +1437,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
* *
****************************************************************************/ ****************************************************************************/
int int
TvDeviceSetContrast( IN IXML_Document * in, TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int contrast = -1; int contrast = -1;
@ -1560,14 +1499,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementContrast( IN int incr, IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcontrast, int curcontrast;
newcontrast; int newcontrast;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1629,11 +1564,8 @@ IncrementContrast( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseContrast( IN IXML_Document * in, TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementContrast( 1, in, out, errorString ); return IncrementContrast( 1, in, out, errorString );
} }
@ -1651,9 +1583,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseContrast( IXML_Document * in, TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IXML_Document ** out,
char **errorString )
{ {
return IncrementContrast( -1, in, out, errorString ); return IncrementContrast( -1, in, out, errorString );
} }
@ -1671,11 +1601,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetBrightness( IN IXML_Document * in, TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int brightness = -1; int brightness = -1;
@ -1718,7 +1645,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1736,13 +1662,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementBrightness( IN int incr, IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curbrightness, int curbrightness;
newbrightness; int newbrightness;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1803,9 +1726,7 @@ IncrementBrightness( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseBrightness( IN IXML_Document * in, TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( 1, in, out, errorString ); return IncrementBrightness( 1, in, out, errorString );
} }
@ -1823,9 +1744,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseBrightness( IN IXML_Document * in, TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( -1, in, out, errorString ); return IncrementBrightness( -1, in, out, errorString );
} }
@ -1849,14 +1768,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
* Cookie -- Optional data specified during callback registration * Cookie -- Optional data specified during callback registration
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
void *Event,
void *Cookie )
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( ( struct TvDeviceHandleSubscriptionRequest( ( struct
@ -1890,17 +1804,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
break; break;
default: default:
SampleUtil_Print SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
EventType ); EventType );
} }
/* /* Print a summary of the event received */
Print a summary of the event received
*/
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent( EventType, Event );
return ( 0 ); return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1919,6 +1830,7 @@ TvDeviceStop()
UpnpFinish(); UpnpFinish();
SampleUtil_Finish(); SampleUtil_Finish();
ithread_mutex_destroy( &TVDevMutex ); ithread_mutex_destroy( &TVDevMutex );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -1951,7 +1863,6 @@ TvDeviceStart( char *ip_address,
print_string pfun ) print_string pfun )
{ {
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
char desc_doc_url[DESC_URL_SIZE]; char desc_doc_url[DESC_URL_SIZE];
ithread_mutex_init( &TVDevMutex, NULL ); ithread_mutex_init( &TVDevMutex, NULL );
@ -1963,19 +1874,15 @@ TvDeviceStart( char *ip_address,
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); 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 ); SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
if( ip_address == NULL ) {
ip_address = UpnpGetServerIpAddress(); ip_address = UpnpGetServerIpAddress();
}
if( port == 0 ) {
port = UpnpGetServerPort(); port = UpnpGetServerPort();
}
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
@ -1995,12 +1902,12 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( "Specifying the webserver root directory -- %s\n", SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
web_dir_path ); web_dir_path );
if( ( ret = ret = UpnpSetWebServerRootDir( web_dir_path );
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) { if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
( "Error specifying webserver root directory -- %s: %d\n",
web_dir_path, ret ); web_dir_path, ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
@ -2009,12 +1916,12 @@ TvDeviceStart( char *ip_address,
"\t with desc_doc_url: %s\n", "\t with desc_doc_url: %s\n",
desc_doc_url ); desc_doc_url );
if( ( ret = UpnpRegisterRootDevice( desc_doc_url, ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
TvDeviceCallbackEventHandler, &device_handle, &device_handle );
&device_handle, &device_handle ) ) if( ret != UPNP_E_SUCCESS ) {
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret ); SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} else { } else {
SampleUtil_Print( SampleUtil_Print(
@ -2022,17 +1929,17 @@ TvDeviceStart( char *ip_address,
"Initializing State Table\n"); "Initializing State Table\n");
TvDeviceStateTableInit( desc_doc_url ); TvDeviceStateTableInit( desc_doc_url );
SampleUtil_Print("State Table Initialized\n"); SampleUtil_Print("State Table Initialized\n");
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
if( ( ret = if( ret != UPNP_E_SUCCESS ) {
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error sending advertisements : %d\n", ret ); SampleUtil_Print( "Error sending advertisements : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
SampleUtil_Print("Advertisements Sent\n"); SampleUtil_Print("Advertisements Sent\n");
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }

View File

@ -1,40 +1,47 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "upnp_tv_device.h" #include "upnp_tv_device.h"
#include <assert.h>
#define DEFAULT_WEB_DIR "./web" #define DEFAULT_WEB_DIR "./web"
#define DESC_URL_SIZE 200 #define DESC_URL_SIZE 200
/* /*
Device type for tv device Device type for tv device
*/ */
@ -180,7 +187,6 @@ SetServiceTable( IN int serviceType,
} }
return SetActionTable( serviceType, out ); return SetActionTable( serviceType, out );
} }
/****************************************************************************** /******************************************************************************
@ -251,7 +257,6 @@ SetActionTable( IN int serviceType,
} }
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -387,19 +392,22 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
/* /*
PropSet = NULL; 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 // add each variable to the property set
// for initial state dump // for initial state dump
UpnpAddToPropertySet(&PropSet, UpnpAddToPropertySet(
&PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state // dump initial state
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN, UpnpAcceptSubscriptionExt(
device_handle,
sr_event->UDN,
sr_event->ServiceId, sr_event->ServiceId,
PropSet,sr_event->Sid); PropSet,
sr_event->Sid);
// free document // free document
Document_free(PropSet); Document_free(PropSet);
@ -420,9 +428,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return 1;
} }
/****************************************************************************** /******************************************************************************
* TvDeviceHandleGetVarRequest * TvDeviceHandleGetVarRequest
* *
@ -439,8 +448,8 @@ int
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
*cgv_event ) *cgv_event )
{ {
unsigned int i = 0, unsigned int i = 0;
j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
cgv_event->CurrentVal = NULL; cgv_event->CurrentVal = NULL;
@ -498,7 +507,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
int int
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event ) TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
{ {
/* /*
Defaults if action not found Defaults if action not found
*/ */
@ -651,7 +659,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return ( 1 );
} }
/****************************************************************************** /******************************************************************************
@ -674,7 +681,7 @@ TvDeviceSetPower( IN int on )
if( on != POWER_ON && on != POWER_OFF ) { if( on != POWER_ON && on != POWER_OFF ) {
SampleUtil_Print( "error: can't set power to value %d\n", on ); 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, ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
value ); value );
return ( ret ); return ret;
} }
/****************************************************************************** /******************************************************************************
@ -702,9 +709,7 @@ TvDeviceSetPower( IN int on )
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOn( IN IXML_Document * in, TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
@ -724,7 +729,6 @@ TvDevicePowerOn( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -781,11 +785,8 @@ TvDevicePowerOff( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetChannel( IN IXML_Document * in, TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int channel = 0; int channel = 0;
@ -830,7 +831,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -848,13 +848,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementChannel( IN int incr, IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curchannel, int curchannel;
newchannel; int newchannel;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -916,12 +913,9 @@ IncrementChannel( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseChannel( IN IXML_Document * in, TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( -1, in, out, errorString ); return IncrementChannel( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -938,12 +932,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseChannel( IN IXML_Document * in, TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( 1, in, out, errorString ); return IncrementChannel( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -962,13 +953,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetVolume( IN IXML_Document * in, TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int volume = 0; int volume = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1009,7 +996,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1028,10 +1014,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
IncrementVolume( IN int incr, IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curvolume, int curvolume,
newvolume; newvolume;
@ -1068,8 +1051,7 @@ IncrementVolume( IN int incr,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
if( UpnpAddToActionResponse( out, actionName, if( UpnpAddToActionResponse( out, actionName,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
"Volume", value ) != UPNP_E_SUCCESS ) "Volume", value ) != UPNP_E_SUCCESS ) {
{
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
@ -1079,7 +1061,6 @@ IncrementVolume( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1096,13 +1077,9 @@ IncrementVolume( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseVolume( IN IXML_Document * in, TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( 1, in, out, errorString ); return IncrementVolume( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1119,13 +1096,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseVolume( IN IXML_Document * in, TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( -1, in, out, errorString ); return IncrementVolume( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1144,13 +1117,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetColor( IN IXML_Document * in, TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int color = 0; int color = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1190,7 +1159,6 @@ TvDeviceSetColor( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1207,16 +1175,11 @@ TvDeviceSetColor( IN IXML_Document * in,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementColor( IN int incr, IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcolor, int curcolor;
newcolor; int newcolor;
char *actionName; char *actionName;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1274,11 +1237,8 @@ IncrementColor( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseColor( IN IXML_Document * in, TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( -1, in, out, errorString ); return IncrementColor( -1, in, out, errorString );
} }
@ -1295,11 +1255,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseColor( IN IXML_Document * in, TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( 1, in, out, errorString ); return IncrementColor( 1, in, out, errorString );
} }
@ -1319,13 +1276,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetTint( IN IXML_Document * in, TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int tint = -1; int tint = -1;
( *out ) = NULL; ( *out ) = NULL;
@ -1384,14 +1337,10 @@ TvDeviceSetTint( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementTint( IN int incr, IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curtint, int curtint;
newtint; int newtint;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1434,7 +1383,6 @@ IncrementTint( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1451,11 +1399,8 @@ IncrementTint( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseTint( IN IXML_Document * in, TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( 1, in, out, errorString ); return IncrementTint( 1, in, out, errorString );
} }
@ -1473,11 +1418,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseTint( IN IXML_Document * in, TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( -1, in, out, errorString ); return IncrementTint( -1, in, out, errorString );
} }
@ -1497,11 +1439,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
* *
****************************************************************************/ ****************************************************************************/
int int
TvDeviceSetContrast( IN IXML_Document * in, TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int contrast = -1; int contrast = -1;
@ -1562,14 +1501,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementContrast( IN int incr, IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcontrast, int curcontrast;
newcontrast; int newcontrast;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1631,11 +1566,8 @@ IncrementContrast( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseContrast( IN IXML_Document * in, TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementContrast( 1, in, out, errorString ); return IncrementContrast( 1, in, out, errorString );
} }
@ -1653,9 +1585,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseContrast( IXML_Document * in, TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IXML_Document ** out,
char **errorString )
{ {
return IncrementContrast( -1, in, out, errorString ); return IncrementContrast( -1, in, out, errorString );
} }
@ -1673,11 +1603,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetBrightness( IN IXML_Document * in, TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int brightness = -1; int brightness = -1;
@ -1720,7 +1647,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1738,13 +1664,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementBrightness( IN int incr, IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curbrightness, int curbrightness;
newbrightness; int newbrightness;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1805,9 +1728,7 @@ IncrementBrightness( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseBrightness( IN IXML_Document * in, TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( 1, in, out, errorString ); return IncrementBrightness( 1, in, out, errorString );
} }
@ -1825,9 +1746,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseBrightness( IN IXML_Document * in, TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( -1, in, out, errorString ); return IncrementBrightness( -1, in, out, errorString );
} }
@ -1851,14 +1770,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
* Cookie -- Optional data specified during callback registration * Cookie -- Optional data specified during callback registration
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
void *Event,
void *Cookie )
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( ( struct TvDeviceHandleSubscriptionRequest( ( struct
@ -1892,17 +1806,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
break; break;
default: default:
SampleUtil_Print SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
EventType ); EventType );
} }
/* /* Print a summary of the event received */
Print a summary of the event received
*/
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent( EventType, Event );
return ( 0 ); return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1921,6 +1832,7 @@ TvDeviceStop()
UpnpFinish(); UpnpFinish();
SampleUtil_Finish(); SampleUtil_Finish();
ithread_mutex_destroy( &TVDevMutex ); ithread_mutex_destroy( &TVDevMutex );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -1953,7 +1865,6 @@ TvDeviceStart( char *ip_address,
print_string pfun ) print_string pfun )
{ {
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
char desc_doc_url[DESC_URL_SIZE]; char desc_doc_url[DESC_URL_SIZE];
ithread_mutex_init( &TVDevMutex, NULL ); ithread_mutex_init( &TVDevMutex, NULL );
@ -1965,16 +1876,14 @@ TvDeviceStart( char *ip_address,
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); 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 ); SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
if( ip_address == NULL ) {
ip_address = UpnpGetServerIpAddress(); ip_address = UpnpGetServerIpAddress();
}
port = UpnpGetServerPort(); port = UpnpGetServerPort();
SampleUtil_Print( SampleUtil_Print(
@ -1995,12 +1904,12 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( "Specifying the webserver root directory -- %s\n", SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
web_dir_path ); web_dir_path );
if( ( ret = ret = UpnpSetWebServerRootDir( web_dir_path );
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) { if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
( "Error specifying webserver root directory -- %s: %d\n",
web_dir_path, ret ); web_dir_path, ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
@ -2009,12 +1918,12 @@ TvDeviceStart( char *ip_address,
"\t with desc_doc_url: %s\n", "\t with desc_doc_url: %s\n",
desc_doc_url ); desc_doc_url );
if( ( ret = UpnpRegisterRootDevice( desc_doc_url, ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
TvDeviceCallbackEventHandler, &device_handle, &device_handle );
&device_handle, &device_handle ) ) if( ret != UPNP_E_SUCCESS ) {
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret ); SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} else { } else {
SampleUtil_Print( SampleUtil_Print(
@ -2022,17 +1931,17 @@ TvDeviceStart( char *ip_address,
"Initializing State Table\n"); "Initializing State Table\n");
TvDeviceStateTableInit( desc_doc_url ); TvDeviceStateTableInit( desc_doc_url );
SampleUtil_Print("State Table Initialized\n"); SampleUtil_Print("State Table Initialized\n");
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
if( ( ret = if( ret != UPNP_E_SUCCESS ) {
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error sending advertisements : %d\n", ret ); SampleUtil_Print( "Error sending advertisements : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
SampleUtil_Print("Advertisements Sent\n"); SampleUtil_Print("Advertisements Sent\n");
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }

View File

@ -1,4 +1,4 @@
/******************************************************************************* /**************************************************************************
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
@ -6,12 +6,12 @@
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -27,30 +27,52 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
******************************************************************************/ **************************************************************************/
#include "config.h" #include "config.h"
/*!
* \file
*/
#if EXCLUDE_DOM == 0 #if EXCLUDE_DOM == 0
#include <stdarg.h> #include "upnp.h"
#include "upnptools.h" #include "upnptools.h"
#include "uri.h" #include "uri.h"
#include <stdarg.h>
#include <stdio.h>
/*! Maximum action header buffer length. */
#define HEADER_LENGTH 2000 #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_HANDLE, "UPNP_E_INVALID_HANDLE"},
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"}, {UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
{UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"}, {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_NOTIFY_UNACCEPTED, "UPNP_E_NOTIFY_UNACCEPTED"},
{UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"}, {UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"},
{UPNP_E_INVALID_ARGUMENT, "UPNP_E_INVALID_ARGUMENT"}, {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 const char *UpnpGetErrorMessage(int rc)
*
* 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 )
{ {
int i; int i;
for( i = 0; i < sizeof( ErrorMessages ) / sizeof( ErrorMessages[0] ); for (i = 0; i < sizeof (ErrorMessages) / sizeof (ErrorMessages[0]); ++i) {
i++ ) { if (rc == ErrorMessages[i].rc) {
if( rc == ErrorMessages[i].rc )
return ErrorMessages[i].rcError; return ErrorMessages[i].rcError;
}
} }
return "Unknown Error"; return "Unknown error code";
} }
/************************************************************************
* Function : UpnpResolveURL /*!
* * \todo There is some unnecessary allocation and deallocation going on here
* Parameters: * because of the way resolve_rel_url() was originally written and used. In the
* IN char * BaseURL: Base URL string * future it would be nice to clean this up.
* IN char * RelURL: relative URL string */
* OUT char * AbsURL: Absolute URL string int UpnpResolveURL(
* Description: const char *BaseURL,
* This functions concatinates the base URL and relative URL to generate const char *RelURL,
* the absolute URL char *AbsURL)
* Returns: int
* return either UPNP_E_SUCCESS or appropriate error
***************************************************************************/
int
UpnpResolveURL( IN const char *BaseURL,
IN const char *RelURL,
OUT char *AbsURL )
{ {
// There is some unnecessary allocation and int ret = UPNP_E_SUCCESS;
// deallocation going on here because of the way char *tempRel = NULL;
// resolve_rel_url was originally written and used
// in the future it would be nice to clean this up
char *tempRel; if (RelURL == NULL) {
ret = UPNP_E_INVALID_PARAM;
if( RelURL == NULL ) goto ExitFunction;
return UPNP_E_INVALID_PARAM; }
tempRel = NULL;
tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL); tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL);
if (tempRel) { if (tempRel) {
strcpy(AbsURL, tempRel); strcpy(AbsURL, tempRel);
free(tempRel); free(tempRel);
} else { } else {
return UPNP_E_INVALID_URL; ret = UPNP_E_INVALID_URL;
} }
ExitFunction:
return UPNP_E_SUCCESS; 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 * 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, otherwise the appropriate error.
* returns UPNP_E_SUCCESS if successful else returns appropriate error */
***************************************************************************/ static int addToAction(
static int /*! [in] flag to tell if the ActionDoc is for response or request. */
addToAction( IN int response, int response,
INOUT IXML_Document ** ActionDoc, /*! [in,out] Request or response document. */
IN const char *ActionName, IXML_Document **ActionDoc,
IN const char *ServType, /*! [in] Name of the action request or response. */
IN const char *ArgName, const char *ActionName,
IN const char *ArgValue ) /*! [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; char *ActBuff = NULL;
IXML_Node *node = NULL; IXML_Node *node = NULL;
@ -227,39 +219,32 @@ addToAction( IN int response,
Txt = ixmlDocument_createTextNode(*ActionDoc, ArgValue); Txt = ixmlDocument_createTextNode(*ActionDoc, ArgValue);
ixmlNode_appendChild((IXML_Node *)Ele, Txt); ixmlNode_appendChild((IXML_Node *)Ele, Txt);
} }
ixmlNode_appendChild(node, (IXML_Node *)Ele); ixmlNode_appendChild(node, (IXML_Node *)Ele);
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/************************************************************************
* Function : makeAction /*!
* \brief Creates the action request or response from the argument list.
* *
* Parameters: * \return Action request or response document if successful, otherwise
* IN int response: flag to tell if the ActionDoc is for response * returns NULL
* or request */
* IN char * ActionName: Name of the action request or response static IXML_Document *makeAction(
* IN char * ServType: Service type /*! [in] flag to tell if the ActionDoc is for response or request. */
* IN int NumArg :Number of arguments in the action request or response int response,
* IN char * Arg : pointer to the first argument /*! [in] Name of the action request or response. */
* IN va_list ArgList: Argument list const char *ActionName,
* /*! [in] Service type. */
* Description: const char *ServType,
* This function creates the action request or response from the argument /*! [in] Number of arguments in the action request or response. */
* list. int NumArg,
* Returns: IXML_Document * /*! [in] pointer to the first argument. */
* returns action request or response document if successful const char *Arg,
* else returns NULL /*! [in] Argument list. */
***************************************************************************/ va_list ArgList)
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 )
{ {
const char *ArgName; const char *ArgName;
const char *ArgValue; const char *ArgValue;
@ -288,14 +273,12 @@ makeAction( IN int response,
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>", "<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
ActionName, ServType, ActionName); ActionName, ServType, ActionName);
} }
if (ixmlParseBufferEx(ActBuff, &ActionDoc) != IXML_SUCCESS) { if (ixmlParseBufferEx(ActBuff, &ActionDoc) != IXML_SUCCESS) {
free(ActBuff); free(ActBuff);
return NULL; return NULL;
} }
free(ActBuff); free(ActBuff);
if(ActionDoc == NULL) { if(ActionDoc == NULL) {
return NULL; return NULL;
} }
@ -305,19 +288,15 @@ makeAction( IN int response,
ArgName = Arg; ArgName = Arg;
for ( ; ; ) { for ( ; ; ) {
ArgValue = va_arg(ArgList, const char *); ArgValue = va_arg(ArgList, const char *);
if (ArgName != NULL) { if (ArgName != NULL) {
node = ixmlNode_getFirstChild((IXML_Node *)ActionDoc); node = ixmlNode_getFirstChild((IXML_Node *)ActionDoc);
Ele = ixmlDocument_createElement(ActionDoc, ArgName); Ele = ixmlDocument_createElement(ActionDoc, ArgName);
if (ArgValue) { if (ArgValue) {
Txt = Txt = ixmlDocument_createTextNode(ActionDoc, ArgValue);
ixmlDocument_createTextNode( ActionDoc, ArgValue );
ixmlNode_appendChild((IXML_Node *)Ele, Txt); ixmlNode_appendChild((IXML_Node *)Ele, Txt);
} }
ixmlNode_appendChild(node, (IXML_Node *)Ele); ixmlNode_appendChild(node, (IXML_Node *)Ele);
} }
if (++Idx < NumArg) { if (++Idx < NumArg) {
ArgName = va_arg(ArgList, const char *); ArgName = va_arg(ArgList, const char *);
} else { } else {
@ -330,28 +309,9 @@ makeAction( IN int response,
return ActionDoc; return ActionDoc;
} }
/************************************************************************
* Function : UpnpMakeAction IXML_Document *UpnpMakeAction(
* const char *ActionName,
* 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,
const char *ServType, const char *ServType,
int NumArg, int NumArg,
const char *Arg, const char *Arg,
@ -367,28 +327,9 @@ UpnpMakeAction( const char *ActionName,
return out; return out;
} }
/************************************************************************
* Function : UpnpMakeActionResponse IXML_Document *UpnpMakeActionResponse(
* const char *ActionName,
* 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,
const char *ServType, const char *ServType,
int NumArg, int NumArg,
const char *Arg, const char *Arg,
@ -404,89 +345,86 @@ UpnpMakeActionResponse( const char *ActionName,
return out; 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 );
}
/************************************************************************ int UpnpAddToAction(
* Function : UpnpAddToAction IXML_Document **ActionDoc,
*
* 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,
const char *ActionName, const char *ActionName,
const char *ServType, const char *ServType,
const char *ArgName, const char *ArgName,
const char *ArgValue) 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" int UpnpAddToActionResponse(
"-upnp-org:event-1-0\"></e:propertyset>"; 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_Node *node;
IXML_Element *Ele; IXML_Element *Ele;
IXML_Element *Ele1; IXML_Element *Ele1;
@ -520,71 +458,6 @@ UpnpAddToPropertySet( INOUT IXML_Document ** PropSet,
return UPNP_E_SUCCESS; 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 ) { #endif /* EXCLUDE_DOM == 0 */
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

View File

@ -1,43 +1,48 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * 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. * 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 * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/************************************************************************ /************************************************************************
* Purpose: This file contains functions for copying strings based on * Purpose: This file contains functions for copying strings based on
* different options. * different options.
************************************************************************/ ************************************************************************/
#include "config.h" #include "config.h"
#include "upnp.h" #include "upnp.h"
#include "util.h" #include "util.h"
#include <string.h>
/************************************************************************ /************************************************************************
* Function : linecopy * Function : linecopy
* *