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);
} }
} }

File diff suppressed because it is too large Load Diff

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"
#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) ) #include <stdlib.h> /* for size_t */
#define MINVAL(a, b) ( (a) < (b) ? (a) : (b) )
#define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
#define MEMBUF_DEF_SIZE_INC 20 #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 /////////////////////////
//--------------------------------------------------
/*
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
*/
void ixml_membuf_init(INOUT ixml_membuf *m); /*!
void ixml_membuf_destroy(INOUT ixml_membuf *m); * \brief ixml_membuf initialization routine.
int ixml_membuf_assign(INOUT ixml_membuf *m, IN const void *buf, */
IN size_t buf_len ); void ixml_membuf_init(
int ixml_membuf_assign_str(INOUT ixml_membuf *m, IN const char *c_str ); /*! [in,out] The memory buffer to initializa. */
int ixml_membuf_append(INOUT ixml_membuf *m, IN const void *buf); ixml_membuf *m);
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 ); /*!
* \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 */
#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,77 +52,218 @@
#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;
char *prefix; char *prefix;
struct _IXML_NamespaceURI *nextNsURI; struct _IXML_NamespaceURI *nextNsURI;
} IXML_NamespaceURI; } IXML_NamespaceURI;
typedef struct _IXML_ElementStack typedef struct _IXML_ElementStack
{ {
char *element; char *element;
char *prefix; char *prefix;
char *namespaceUri; char *namespaceUri;
IXML_NamespaceURI *pNsURI; IXML_NamespaceURI *pNsURI;
struct _IXML_ElementStack *nextElement; struct _IXML_ElementStack *nextElement;
} IXML_ElementStack; } IXML_ElementStack;
typedef enum typedef enum
{ {
eELEMENT, eELEMENT,
eATTRIBUTE, eATTRIBUTE,
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. */
ixml_membuf lastElem; char *curPtr;
ixml_membuf tokenBuf; /*! Saves for backup. */
char *savePtr;
IXML_Node *pNeedPrefixNode; ixml_membuf lastElem;
IXML_ElementStack *pCurElement; ixml_membuf tokenBuf;
IXML_Node *currentNodePtr; IXML_Node *pNeedPrefixNode;
PARSER_STATE state; IXML_ElementStack *pCurElement;
IXML_Node *currentNodePtr;
BOOL bHasTopLevel; PARSER_STATE state;
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);
int Parser_LoadDocument( IXML_Document **retDoc, const char * xmlFile, BOOL file);
BOOL Parser_isValidXmlName( const DOMString name);
int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
void Parser_freeNodeContent( IXML_Node *IXML_Nodeptr);
void Parser_setErrorChar( char c ); /*!
* \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);
void ixmlAttr_free(IXML_Attr *attrNode);
void ixmlAttr_init(IXML_Attr *attrNode);
int ixmlElement_setTagName(IXML_Element *element, const char *tagName); /*!
* \brief Fees a node contents.
*/
void Parser_freeNodeContent(
/*! [in] The Node to process. */
IXML_Node *IXML_Nodeptr);
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap); int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file);
int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add);
void ixmlNode_init(IXML_Node *IXML_Nodeptr); int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node);
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); void ixmlAttr_init(IXML_Attr *attrNode);
int ixmlNode_setNodeName( IXML_Node* node, const DOMString qualifiedName);
void ixmlNodeList_init(IXML_NodeList *nList); /*!
int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add); * \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);
#endif // _IXMLPARSER_H
/*!
* \brief Initializes a NamedNodeMap object.
*/
void ixmlNamedNodeMap_init(
/*! [in] The named node map to process. */
IXML_NamedNodeMap *nnMap);
/*!
* \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);
/*!
* \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);
/*!
* \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,531 +1,469 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// 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 );
for( i = 0; i < plen; i++ ) {
switch ( p[i] ) { for (i = 0; i < plen; i++) {
case '<': switch (p[i]) {
ixml_membuf_append_str( buf, "&lt;" ); case '<':
break; ixml_membuf_append_str(buf, "&lt;");
break;
case '>':
ixml_membuf_append_str( buf, "&gt;" ); case '>':
break; ixml_membuf_append_str(buf, "&gt;");
break;
case '&':
ixml_membuf_append_str( buf, "&amp;" ); case '&':
break; ixml_membuf_append_str(buf, "&amp;");
break;
case '\'':
ixml_membuf_append_str( buf, "&apos;" ); case '\'':
break; ixml_membuf_append_str(buf, "&apos;");
break;
case '\"':
ixml_membuf_append_str( buf, "&quot;" ); case '\"':
break; ixml_membuf_append_str(buf, "&quot;");
break;
default:
ixml_membuf_append( buf, &p[i] ); default:
} ixml_membuf_append(buf, &p[i]);
} break;
} }
}
/*================================================================
* ixmlPrintDomTreeRecursive
* It is a recursive function to print all the node in a tree.
* Internal to parser only.
*
*=================================================================*/
void
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL,
*sibling = NULL;
if( nodeptr != NULL ) {
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
copy_with_escape( buf, nodeValue );
break;
case eCDATA_SECTION_NODE:
ixml_membuf_append_str( buf, "<![CDATA[" );
ixml_membuf_append_str( buf, nodeValue );
ixml_membuf_append_str( buf, "]]>" );
break;
case ePROCESSING_INSTRUCTION_NODE:
ixml_membuf_append_str( buf, "<?" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, " " );
copy_with_escape( buf, nodeValue );
ixml_membuf_append_str( buf, "?>\n" );
break;
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
( nodeptr ), buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
copy_with_escape( buf, nodeValue );
ixml_membuf_append_str( buf, "\"" );
if( nodeptr->nextSibling != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->nextSibling, buf );
}
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) ==
eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">\r\n" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
( nodeptr ), buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
sibling = ixmlNode_getNextSibling( nodeptr );
if( sibling != NULL
&& ixmlNode_getNodeType( sibling ) == eTEXT_NODE ) {
ixml_membuf_append_str( buf, ">" );
} else {
ixml_membuf_append_str( buf, ">\r\n" );
}
ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling
( nodeptr ), buf );
break;
default:
break;
}
}
}
/*================================================================
* ixmlPrintDomTree
* Print a DOM tree.
* Element, and Attribute nodes are handled differently.
* We don't want to print the Element and Attribute nodes' sibling.
* External function.
*
*=================================================================*/
void
ixmlPrintDomTree( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
return;
}
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( nodeptr, buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
copy_with_escape( buf, nodeValue );
ixml_membuf_append_str( buf, "\"" );
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">\r\n" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, ">\r\n" );
break;
default:
break;
}
}
/*================================================================
* ixmlDomTreetoString
* Converts a DOM tree into a text string
* Element, and Attribute nodes are handled differently.
* We don't want to print the Element and Attribute nodes' sibling.
* External function.
*
*=================================================================*/
void
ixmlDomTreetoString( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
return;
}
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( nodeptr, buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
copy_with_escape( buf, nodeValue );
ixml_membuf_append_str( buf, "\"" );
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, ">" );
break;
default:
break;
}
}
/*================================================================
* 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 ) ) {
return IXML_INVALID_PARAMETER;
}
return Parser_LoadDocument( doc, xmlFile, TRUE );
}
/*================================================================
* ixmlLoadDocument
* Parses the given file, and returns the DOM tree from it.
* External function.
*
*=================================================================*/
IXML_Document *
ixmlLoadDocument( IN const char *xmlFile )
{
IXML_Document *doc = NULL;
ixmlLoadDocumentEx( xmlFile, &doc );
return doc;
}
/*================================================================
* ixmlPrintDocument
* Prints entire document, prepending XML prolog first.
* Puts lots of white spaces.
* External function.
*
*=================================================================*/
DOMString
ixmlPrintDocument(IXML_Document *doc)
{
IXML_Node* rootNode = ( IXML_Node * )doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( rootNode == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\r\n" );
ixmlPrintDomTree( rootNode, buf );
return buf->buf;
}
/*================================================================
* ixmlPrintNode
* Print DOM tree under node. Puts lots of white spaces
* External function.
*
*=================================================================*/
DOMString
ixmlPrintNode( IN IXML_Node * node )
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( node == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixmlPrintDomTree( node, buf );
return buf->buf;
}
/*================================================================
* ixmlDocumenttoString
* converts DOM tree under node to text string,
* prepending XML prolog first.
* External function.
*
*=================================================================*/
DOMString
ixmlDocumenttoString(IXML_Document *doc)
{
IXML_Node* rootNode = ( IXML_Node * )doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( rootNode == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\r\n" );
ixmlDomTreetoString( rootNode, buf );
return buf->buf;
}
/*================================================================
* ixmlNodetoString
* converts DOM tree under node to text string
* External function.
*
*=================================================================*/
DOMString
ixmlNodetoString( IN IXML_Node * node )
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( node == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixmlDomTreetoString( node, buf );
return buf->buf;
}
/*================================================================
* ixmlRelaxParser
* Makes the XML parser more tolerant to malformed text.
* External function.
*
*=================================================================*/
void
ixmlRelaxParser(char errorChar)
{
Parser_setErrorChar( errorChar );
} }
/*================================================================ /*!
* ixmlParseBufferEx * \brief Recursive function to print all the node in a tree.
* Parse xml file stored in buffer. * Internal to parser only.
* External function. */
* static void ixmlPrintDomTreeRecursive(
*=================================================================*/ /*! [in] \todo documentation. */
int IXML_Node *nodeptr,
ixmlParseBufferEx( IN const char *buffer, /*! [in] \todo documentation. */
IXML_Document ** retDoc ) ixml_membuf *buf)
{ {
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL,
*sibling = NULL;
if( ( buffer == NULL ) || ( retDoc == NULL ) ) { if (nodeptr != NULL) {
return IXML_INVALID_PARAMETER; nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
} nodeValue = ixmlNode_getNodeValue(nodeptr);
if( buffer[0] == '\0' ) { switch (ixmlNode_getNodeType(nodeptr)) {
return IXML_INVALID_PARAMETER; case eTEXT_NODE:
} copy_with_escape(buf, nodeValue);
break;
return Parser_LoadDocument( retDoc, buffer, FALSE ); case eCDATA_SECTION_NODE:
ixml_membuf_append_str(buf, "<![CDATA[");
ixml_membuf_append_str(buf, nodeValue);
ixml_membuf_append_str(buf, "]]>");
break;
case ePROCESSING_INSTRUCTION_NODE:
ixml_membuf_append_str(buf, "<?");
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, " ");
copy_with_escape(buf, nodeValue);
ixml_membuf_append_str(buf, "?>\n");
break;
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive(
ixmlNode_getFirstChild(nodeptr), buf);
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, "=\"");
copy_with_escape(buf, nodeValue);
ixml_membuf_append_str(buf, "\"");
if (nodeptr->nextSibling != NULL) {
ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf);
}
break;
case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
}
child = ixmlNode_getFirstChild(nodeptr);
if (child != NULL &&
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
ixml_membuf_append_str(buf, ">\r\n");
} else {
ixml_membuf_append_str(buf, ">");
}
// output the children
ixmlPrintDomTreeRecursive(
ixmlNode_getFirstChild(nodeptr), buf);
// Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</");
ixml_membuf_append_str(buf, nodeName);
sibling = ixmlNode_getNextSibling(nodeptr);
if (sibling != NULL &&
ixmlNode_getNodeType(sibling) == eTEXT_NODE) {
ixml_membuf_append_str( buf, ">" );
} else {
ixml_membuf_append_str( buf, ">\r\n" );
}
ixmlPrintDomTreeRecursive(
ixmlNode_getNextSibling(nodeptr), buf);
break;
default:
IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break;
}
}
} }
/*================================================================
* ixmlParseBuffer
* Parse xml file stored in buffer.
* External function.
*
*=================================================================*/
IXML_Document *
ixmlParseBuffer( IN const char *buffer )
{
IXML_Document *doc = NULL;
ixmlParseBufferEx( buffer, &doc ); /*!
return doc; * \brief Print a DOM tree.
*
* Element, and Attribute nodes are handled differently. We don't want to print
* the Element and Attribute nodes' sibling.
*/
static void ixmlPrintDomTree(
/*! [in] \todo documentation. */
IXML_Node *nodeptr,
/*! [in] \todo documentation. */
ixml_membuf *buf)
{
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL;
if (nodeptr == NULL || buf == NULL) {
return;
}
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
nodeValue = ixmlNode_getNodeValue(nodeptr);
switch (ixmlNode_getNodeType(nodeptr)) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive(nodeptr, buf);
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, "=\"");
copy_with_escape(buf, nodeValue);
ixml_membuf_append_str(buf, "\"");
break;
case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
}
child = ixmlNode_getFirstChild(nodeptr);
if (child != NULL &&
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
ixml_membuf_append_str(buf, ">\r\n");
} else {
ixml_membuf_append_str(buf, ">");
}
// output the children
ixmlPrintDomTreeRecursive(
ixmlNode_getFirstChild(nodeptr), buf);
// Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</");
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, ">\r\n");
break;
default:
IxmlPrintf("(%s::ixmlPrintDomTree) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break;
}
} }
/*================================================================
* ixmlCloneDOMString
* Clones a DOM String.
* External function.
*
*=================================================================*/
DOMString
ixmlCloneDOMString( IN const DOMString src )
{
if( src == NULL ) {
return NULL;
}
return ( strdup( src ) ); /*!
* \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.
*/
static void ixmlDomTreetoString(
/*! [in] \todo documentation. */
IXML_Node *nodeptr,
/*! [in] \todo documentation. */
ixml_membuf *buf)
{
const char *nodeName = NULL;
const char *nodeValue = NULL;
IXML_Node *child = NULL;
if (nodeptr == NULL || buf == NULL) {
return;
}
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
nodeValue = ixmlNode_getNodeValue(nodeptr);
switch (ixmlNode_getNodeType(nodeptr)) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive(nodeptr, buf);
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, "=\"");
copy_with_escape(buf, nodeValue );
ixml_membuf_append_str(buf, "\"");
break;
case eELEMENT_NODE:
ixml_membuf_append_str(buf, "<");
ixml_membuf_append_str(buf, nodeName);
if (nodeptr->firstAttr != NULL) {
ixml_membuf_append_str(buf, " ");
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
}
child = ixmlNode_getFirstChild(nodeptr);
if (child != NULL &&
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
ixml_membuf_append_str(buf, ">");
} else {
ixml_membuf_append_str(buf, ">");
}
// output the children
ixmlPrintDomTreeRecursive(ixmlNode_getFirstChild(nodeptr), buf);
// Done with children. Output the end tag.
ixml_membuf_append_str(buf, "</");
ixml_membuf_append_str(buf, nodeName);
ixml_membuf_append_str(buf, ">");
break;
default:
IxmlPrintf("(%s::ixmlDomTreetoString) line %d: "
"Warning, unknown node type %d\n",
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
break;
}
} }
/*================================================================
* ixmlFreeDOMString int ixmlLoadDocumentEx(const char *xmlFile, IXML_Document **doc)
* Frees a DOM String.
* External function.
*
*=================================================================*/
void
ixmlFreeDOMString( IN DOMString buf )
{ {
if( buf != NULL ) { if (xmlFile == NULL || doc == NULL) {
free( buf ); return IXML_INVALID_PARAMETER;
} }
return Parser_LoadDocument(doc, xmlFile, TRUE);
} }
IXML_Document *ixmlLoadDocument(const char *xmlFile)
{
IXML_Document *doc = NULL;
ixmlLoadDocumentEx(xmlFile, &doc);
return doc;
}
DOMString ixmlPrintDocument(IXML_Document *doc)
{
IXML_Node* rootNode = (IXML_Node *)doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if(rootNode == NULL) {
return NULL;
}
ixml_membuf_init(buf);
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
ixmlPrintDomTree(rootNode, buf);
return buf->buf;
}
DOMString ixmlPrintNode(IXML_Node *node)
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if (node == NULL) {
return NULL;
}
ixml_membuf_init(buf);
ixmlPrintDomTree(node, buf);
return buf->buf;
}
DOMString ixmlDocumenttoString(IXML_Document *doc)
{
IXML_Node* rootNode = (IXML_Node *)doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if(rootNode == NULL) {
return NULL;
}
ixml_membuf_init(buf);
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
ixmlDomTreetoString(rootNode, buf);
return buf->buf;
}
DOMString ixmlNodetoString(IXML_Node *node)
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if (node == NULL) {
return NULL;
}
ixml_membuf_init(buf);
ixmlDomTreetoString(node, buf);
return buf->buf;
}
void ixmlRelaxParser(char errorChar)
{
Parser_setErrorChar(errorChar);
}
int ixmlParseBufferEx(const char *buffer, IXML_Document **retDoc)
{
if (buffer == NULL || retDoc == NULL) {
return IXML_INVALID_PARAMETER;
}
if (buffer[0] == '\0') {
return IXML_INVALID_PARAMETER;
}
return Parser_LoadDocument(retDoc, buffer, FALSE);
}
IXML_Document *ixmlParseBuffer(const char *buffer)
{
IXML_Document *doc = NULL;
ixmlParseBufferEx(buffer, &doc);
return doc;
}
DOMString ixmlCloneDOMString(const DOMString src)
{
if (src == NULL) {
return NULL;
}
return strdup(src);
}
void ixmlFreeDOMString(DOMString buf)
{
if (buf != NULL) {
free(buf);
}
}

View File

@ -1,236 +1,218 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// 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. *
* * \return
* returns: * \li UPNP_E_SUCCESS
* UPNP_E_SUCCESS * \li UPNP_E_OUTOF_MEMORY
* UPNP_E_OUTOF_MEMORY */
* static int ixml_membuf_set_size(
*=================================================================*/ /*! [in,out] The memory buffer. */
static int INOUT ixml_membuf *m,
ixml_membuf_set_size( 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; assert(alloc_len >= new_length);
}
assert( alloc_len >= new_length ); temp_buf = realloc(m->buf, alloc_len + 1);
if (temp_buf == NULL) {
/* try smaller size */
alloc_len = new_length;
temp_buf = realloc(m->buf, alloc_len + 1);
if (temp_buf == NULL) {
return IXML_INSUFFICIENT_MEMORY;
}
}
/* save */
m->buf = temp_buf;
m->capacity = alloc_len;
temp_buf = realloc( m->buf, alloc_len + 1 ); return 0;
if( temp_buf == NULL ) {
// try smaller size
alloc_len = new_length;
temp_buf = realloc( m->buf, alloc_len + 1 );
if( temp_buf == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
}
// save
m->buf = temp_buf;
m->capacity = alloc_len;
return 0;
} }
/*================================================================
* membuffer_init
*
*
*=================================================================*/
void
ixml_membuf_init( INOUT ixml_membuf * m )
{
assert( m != NULL );
m->size_inc = MEMBUF_DEF_SIZE_INC; void ixml_membuf_init(ixml_membuf *m)
m->buf = NULL; {
m->length = 0; assert(m != NULL);
m->capacity = 0;
m->size_inc = MEMBUF_DEF_SIZE_INC;
m->buf = NULL;
m->length = 0;
m->capacity = 0;
} }
/*================================================================
* membuffer_destroy
*
*
*=================================================================*/
void
ixml_membuf_destroy( INOUT ixml_membuf * m )
{
if( m == NULL ) {
return;
}
free( m->buf ); void ixml_membuf_destroy(ixml_membuf *m)
ixml_membuf_init( m ); {
if (m == NULL) {
return;
}
free(m->buf);
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;
assert( m != NULL ); assert(m != NULL);
// set value to null // set value to null
if( buf == NULL ) { if (buf == NULL) {
ixml_membuf_destroy( m ); ixml_membuf_destroy(m);
return IXML_SUCCESS; return IXML_SUCCESS;
} }
// alloc mem // alloc mem
return_code = ixml_membuf_set_size( m, buf_len ); return_code = ixml_membuf_set_size(m, buf_len);
if( return_code != 0 ) { if (return_code != 0) {
return return_code; return return_code;
} }
// copy
memcpy( m->buf, buf, buf_len );
m->buf[buf_len] = 0; // null-terminate
m->length = buf_len; // copy
memcpy(m->buf, buf, buf_len);
return IXML_SUCCESS; // null-terminate
m->buf[buf_len] = 0;
m->length = buf_len;
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,
IN const void *buf )
{
assert( m != NULL );
return ixml_membuf_insert( m, buf, 1, m->length ); int ixml_membuf_append(
INOUT ixml_membuf *m,
IN const void *buf)
{
assert(m != NULL);
return ixml_membuf_insert(m, buf, 1, m->length);
} }
/*================================================================
* ixml_membuf_append_str int ixml_membuf_append_str(
* INOUT ixml_membuf *m,
* IN const char *c_str)
*=================================================================*/
int
ixml_membuf_append_str( INOUT ixml_membuf * m,
IN const char *c_str )
{ {
return ixml_membuf_insert( m, c_str, strlen( c_str ), m->length ); return ixml_membuf_insert(m, c_str, strlen(c_str), m->length);
} }
/*================================================================
* ixml_membuf_insert int ixml_membuf_insert(
* INOUT ixml_membuf *m,
* IN const void *buf,
*=================================================================*/ IN size_t buf_len,
int int index)
ixml_membuf_insert( INOUT ixml_membuf * m,
IN const void *buf,
IN size_t buf_len,
int index )
{ {
int return_code; int return_code = 0;
assert( m != NULL ); 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,242 +1,195 @@
/////////////////////////////////////////////////////////////////////////// /**************************************************************************
// *
// 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 const char *name ) /*! [in] The named node map to process. */
IN IXML_NamedNodeMap *nnMap,
/*! [in] The name of the item to find. */
IN const char *name)
{ {
IXML_Node *tempNode; 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;
} }
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;
while( tempNode != NULL ) { while (tempNode != NULL) {
if( strcmp( name, tempNode->nodeName ) == 0 ) { if (strcmp(name, tempNode->nodeName) == 0) {
return returnItemNo; return returnItemNo;
} }
tempNode = tempNode->nextSibling;
returnItemNo++;
}
tempNode = tempNode->nextSibling; return IXML_INVALID_ITEM_NUMBER;
returnItemNo++;
}
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;
} }
index = ixmlNamedNodeMap_getItemNumber( nnMap, name ); index = ixmlNamedNodeMap_getItemNumber(nnMap, name);
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. IN unsigned long index )
* 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 )
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
unsigned int i; unsigned int i;
if( nnMap == NULL ) { if (nnMap == NULL) {
return NULL; return NULL;
} }
if( index > ixmlNamedNodeMap_getLength( nnMap ) - 1 ) { if (index > ixmlNamedNodeMap_getLength(nnMap) - 1) {
return NULL; return NULL;
} }
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;
for( i = 0; i < index && tempNode != NULL; ++i ) { for (i = 0; i < index && tempNode != NULL; ++i) {
tempNode = tempNode->nextSibling; tempNode = tempNode->nextSibling;
} }
return tempNode; return tempNode;
} }
/*================================================================
* NamedNodeMap_getLength
* Return the number of Nodes in this map.
* External function.
*
* Parameters:
*
*=================================================================*/
unsigned long
ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
{
IXML_Node *tempNode;
unsigned long length = 0;
if( nnMap != NULL ) { unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
tempNode = nnMap->nodeItem; {
for( length = 0; tempNode != NULL; ++length ) { IXML_Node *tempNode;
tempNode = tempNode->nextSibling; unsigned long length = 0;
}
} if (nnMap != NULL) {
return length; tempNode = nnMap->nodeItem;
for (length = 0; tempNode != NULL; ++length) {
tempNode = tempNode->nextSibling;
}
}
return length;
} }
/*================================================================
* ixmlNamedNodeMap_free
* frees a NamedNodeMap.
* External function.
*
*=================================================================*/
void
ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
{
IXML_NamedNodeMap *pNext;
while( nnMap != NULL ) { void ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap)
pNext = nnMap->next; {
free( nnMap ); IXML_NamedNodeMap *pNext;
nnMap = pNext;
} while (nnMap != NULL) {
pNext = nnMap->next;
free(nnMap);
nnMap = pNext;
}
} }
/*================================================================
* 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) {
(*nnMap)->nodeItem = add;
} else {
traverse = *nnMap;
p = traverse;
while (traverse != NULL) {
p = traverse;
traverse = traverse->next;
}
newItem = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
if (newItem == NULL) {
return IXML_INSUFFICIENT_MEMORY;
}
p->next = newItem;
newItem->nodeItem = add;
newItem->next = NULL;
}
if( ( *nnMap )->nodeItem == NULL ) { return IXML_SUCCESS;
( *nnMap )->nodeItem = add;
} else {
traverse = *nnMap;
p = traverse;
while( traverse != NULL ) {
p = traverse;
traverse = traverse->next;
}
newItem =
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
if( newItem == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
p->next = newItem;
newItem->nodeItem = add;
newItem->next = NULL;
}
return IXML_SUCCESS;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,176 +1,152 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// 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 unsigned long index)
* null.
* External function.
*
*=================================================================*/
IXML_Node *
ixmlNodeList_item( IXML_NodeList * nList,
unsigned long index )
{ {
IXML_NodeList *next; IXML_NodeList *next;
unsigned int i; unsigned int i;
// if the list ptr is NULL // if the list ptr is NULL
if( nList == NULL ) { if (nList == NULL) {
return NULL; return NULL;
} }
// if index is more than list length // if index is more than list length
if( index > ixmlNodeList_length( nList ) - 1 ) { if (index > ixmlNodeList_length(nList) - 1) {
return NULL; return NULL;
} }
next = nList; next = nList;
for( i = 0; i < index && next != NULL; ++i ) { for (i = 0; i < index && next != NULL; ++i) {
next = next->next; next = next->next;
} }
if( next == NULL ) return NULL; if (next == NULL) {
return NULL;
return next->nodeItem; }
return next->nodeItem;
} }
/*================================================================ int ixmlNodeList_addToNodeList(
* ixmlNodeList_addToNodeList IXML_NodeList **nList,
* Add a node to nodelist IXML_Node *add)
* Internal to parser only.
*
*=================================================================*/
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);
if( add == NULL ) { if (add == NULL) {
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;
} }
ixmlNodeList_init( *nList ); ixmlNodeList_init(*nList);
} }
if( ( *nList )->nodeItem == NULL ) { if ((*nList)->nodeItem == NULL) {
( *nList )->nodeItem = add; (*nList)->nodeItem = add;
} else { } else {
traverse = *nList; traverse = *nList;
while( traverse != NULL ) { while (traverse != NULL) {
p = traverse; p = traverse;
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; }
} p->next = newListItem;
p->next = newListItem; newListItem->nodeItem = add;
newListItem->nodeItem = add; newListItem->next = NULL;
newListItem->next = NULL; }
}
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;
list = nList; list = nList;
while( list != NULL ) { while (list != NULL) {
++length; ++length;
list = list->next; list = list->next;
} }
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 ) {
next = nList->next;
free( nList );
nList = next;
}
while (nList != NULL) {
next = nList->next;
free(nList);
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" );
@ -542,7 +547,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
e_event->EventKey ); e_event->EventKey );
xmlbuff = ixmlPrintNode( ( IXML_Node * ) e_event->ChangedVariables ); xmlbuff = ixmlPrintNode( ( IXML_Node * ) e_event->ChangedVariables );
SampleUtil_Print( "ChangedVars = %s\n", xmlbuff ); SampleUtil_Print( "ChangedVars = %s\n", xmlbuff );
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString(xmlbuff);
xmlbuff = NULL; xmlbuff = NULL;
} }
break; break;
@ -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,22 +758,23 @@ 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;
va_start( ap, fmt ); /* Protect both the display and the static buffer with the mutex */
rc = vsnprintf( buf, 200, fmt, ap ); ithread_mutex_lock(&display_mutex);
va_end( ap ); va_start(ap, fmt);
rc = vsnprintf(buf, MAX_BUF, fmt, 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;
} }
/****************************************************************************** /******************************************************************************
@ -372,10 +377,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
{ {
unsigned int i = 0; //,j=0; unsigned int i = 0; //,j=0;
// IXML_Document *PropSet=NULL; // IXML_Document *PropSet = NULL;
//lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) && if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) &&
@ -383,44 +388,48 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
== 0 ) ) { == 0 ) ) {
/* /*
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(
UpnpAddToPropertySet(&PropSet, &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(
sr_event->ServiceId, device_handle,
PropSet,sr_event->Sid); sr_event->UDN,
//free document sr_event->ServiceId,
Document_free(PropSet); PropSet,
sr_event->Sid);
// free document
Document_free(PropSet);
*/ */
UpnpAcceptSubscription( device_handle, UpnpAcceptSubscription( device_handle,
sr_event->UDN, sr_event->UDN,
sr_event->ServiceId, sr_event->ServiceId,
( const char ** )tv_service_table[i]. (const char **)tv_service_table[i].
VariableName, VariableName,
( const char ** )tv_service_table[i]. (const char **)tv_service_table[i].
VariableStrVal, VariableStrVal,
tv_service_table[i].VariableCount, tv_service_table[i].VariableCount,
sr_event->Sid ); sr_event->Sid);
} }
} }
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;
@ -446,12 +455,12 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
//check udn and service id // check udn and service id
if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 ) if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 )
&& &&
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId ) ( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId )
== 0 ) ) { == 0 ) ) {
//check variable name // check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
if( strcmp( cgv_event->StateVarName, if( strcmp( cgv_event->StateVarName,
tv_service_table[i].VariableName[j] ) == 0 ) { tv_service_table[i].VariableName[j] ) == 0 ) {
@ -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
*/ */
@ -549,7 +557,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
ActionRequest, ActionRequest,
&ca_event-> &ca_event->
ActionResult, ActionResult,
&errorString ); &errorString );
} else { } else {
errorString = "Power is Off"; errorString = "Power is Off";
retCode = UPNP_E_INTERNAL_ERROR; retCode = UPNP_E_INTERNAL_ERROR;
@ -567,7 +575,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
if( retCode == UPNP_E_SUCCESS ) { if( retCode == UPNP_E_SUCCESS ) {
ca_event->ErrCode = UPNP_E_SUCCESS; ca_event->ErrCode = UPNP_E_SUCCESS;
} else { } else {
//copy the error string // copy the error string
strcpy( ca_event->ErrStr, errorString ); strcpy( ca_event->ErrStr, errorString );
switch ( retCode ) { switch ( retCode ) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
@ -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;
} }
} }
/****************************************************************************** /******************************************************************************
@ -740,7 +744,7 @@ TvDevicePowerOn( IN IXML_Document * in,
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOff( IN IXML_Document * in, TvDevicePowerOff( IN IXML_Document * in,
OUT IXML_Document ** out, OUT IXML_Document **out,
OUT char **errorString ) OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
@ -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(); port = UpnpGetServerPort();
}
if( port == 0 ) {
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;
} }
/****************************************************************************** /******************************************************************************
@ -374,10 +379,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
{ {
unsigned int i = 0; //,j=0; unsigned int i = 0; //,j=0;
// IXML_Document *PropSet=NULL; // IXML_Document *PropSet = NULL;
//lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) && if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) &&
@ -385,44 +390,48 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
== 0 ) ) { == 0 ) ) {
/* /*
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(
UpnpAddToPropertySet(&PropSet, &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(
sr_event->ServiceId, device_handle,
PropSet,sr_event->Sid); sr_event->UDN,
//free document sr_event->ServiceId,
Document_free(PropSet); PropSet,
sr_event->Sid);
// free document
Document_free(PropSet);
*/ */
UpnpAcceptSubscription( device_handle, UpnpAcceptSubscription( device_handle,
sr_event->UDN, sr_event->UDN,
sr_event->ServiceId, sr_event->ServiceId,
( const char ** )tv_service_table[i]. (const char **)tv_service_table[i].
VariableName, VariableName,
( const char ** )tv_service_table[i]. (const char **)tv_service_table[i].
VariableStrVal, VariableStrVal,
tv_service_table[i].VariableCount, tv_service_table[i].VariableCount,
sr_event->Sid ); sr_event->Sid);
} }
} }
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;
@ -448,12 +457,12 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
//check udn and service id // check udn and service id
if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 ) if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 )
&& &&
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId ) ( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId )
== 0 ) ) { == 0 ) ) {
//check variable name // check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
if( strcmp( cgv_event->StateVarName, if( strcmp( cgv_event->StateVarName,
tv_service_table[i].VariableName[j] ) == 0 ) { tv_service_table[i].VariableName[j] ) == 0 ) {
@ -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
*/ */
@ -551,7 +559,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
ActionRequest, ActionRequest,
&ca_event-> &ca_event->
ActionResult, ActionResult,
&errorString ); &errorString );
} else { } else {
errorString = "Power is Off"; errorString = "Power is Off";
retCode = UPNP_E_INTERNAL_ERROR; retCode = UPNP_E_INTERNAL_ERROR;
@ -569,7 +577,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
if( retCode == UPNP_E_SUCCESS ) { if( retCode == UPNP_E_SUCCESS ) {
ca_event->ErrCode = UPNP_E_SUCCESS; ca_event->ErrCode = UPNP_E_SUCCESS;
} else { } else {
//copy the error string // copy the error string
strcpy( ca_event->ErrStr, errorString ); strcpy( ca_event->ErrStr, errorString );
switch ( retCode ) { switch ( retCode ) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
@ -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;
} }
} }
/****************************************************************************** /******************************************************************************
@ -742,7 +746,7 @@ TvDevicePowerOn( IN IXML_Document * in,
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOff( IN IXML_Document * in, TvDevicePowerOff( IN IXML_Document * in,
OUT IXML_Document ** out, OUT IXML_Document **out,
OUT char **errorString ) OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
@ -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,564 +27,437 @@
* 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 /*!
* \brief Structure to maintain a error code and string associated with the
* error code.
*/
struct ErrorString { struct ErrorString {
int rc; /* error code */ /*! Error code. */
const char *rcError; /* error description */ int rc;
/*! Error description. */
const char *rcError;
}; };
// Initializing the array of error structures.
struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"}, /*!
{UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"}, * \brief Array of error structures.
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"}, */
{UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"}, struct ErrorString ErrorMessages[] = {
{UPNP_E_OUTOF_CONTEXT, "UPNP_E_OUTOF_CONTEXT"}, {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
{UPNP_E_OUTOF_MEMORY, "UPNP_E_OUTOF_MEMOR"}, {UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
{UPNP_E_INIT, "UPNP_E_INIT"}, {UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
{UPNP_E_BUFFER_TOO_SMALL, "UPNP_E_BUFFER_TOO_SMALL"}, {UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"},
{UPNP_E_INVALID_DESC, "UPNP_E_INVALID_DESC"}, {UPNP_E_OUTOF_CONTEXT, "UPNP_E_OUTOF_CONTEXT"},
{UPNP_E_INVALID_URL, "UPNP_E_INVALID_URL"}, {UPNP_E_OUTOF_MEMORY, "UPNP_E_OUTOF_MEMOR"},
{UPNP_E_INVALID_SID, "UPNP_E_INVALID_SID"}, {UPNP_E_INIT, "UPNP_E_INIT"},
{UPNP_E_INVALID_DEVICE, "UPNP_E_INVALID_DEVICE"}, {UPNP_E_BUFFER_TOO_SMALL, "UPNP_E_BUFFER_TOO_SMALL"},
{UPNP_E_INVALID_SERVICE, "UPNP_E_INVALID_SERVICE"}, {UPNP_E_INVALID_DESC, "UPNP_E_INVALID_DESC"},
{UPNP_E_BAD_RESPONSE, "UPNP_E_BAD_RESPONSE"}, {UPNP_E_INVALID_URL, "UPNP_E_INVALID_URL"},
{UPNP_E_BAD_REQUEST, "UPNP_E_BAD_REQUEST"}, {UPNP_E_INVALID_SID, "UPNP_E_INVALID_SID"},
{UPNP_E_INVALID_ACTION, "UPNP_E_INVALID_ACTION"}, {UPNP_E_INVALID_DEVICE, "UPNP_E_INVALID_DEVICE"},
{UPNP_E_FINISH, "UPNP_E_FINISH"}, {UPNP_E_INVALID_SERVICE, "UPNP_E_INVALID_SERVICE"},
{UPNP_E_INIT_FAILED, "UPNP_E_INIT_FAILED"}, {UPNP_E_BAD_RESPONSE, "UPNP_E_BAD_RESPONSE"},
{UPNP_E_BAD_HTTPMSG, "UPNP_E_BAD_HTTPMSG"}, {UPNP_E_BAD_REQUEST, "UPNP_E_BAD_REQUEST"},
{UPNP_E_NETWORK_ERROR, "UPNP_E_NETWORK_ERROR"}, {UPNP_E_INVALID_ACTION, "UPNP_E_INVALID_ACTION"},
{UPNP_E_SOCKET_WRITE, "UPNP_E_SOCKET_WRITE"}, {UPNP_E_FINISH, "UPNP_E_FINISH"},
{UPNP_E_SOCKET_READ, "UPNP_E_SOCKET_READ"}, {UPNP_E_INIT_FAILED, "UPNP_E_INIT_FAILED"},
{UPNP_E_SOCKET_BIND, "UPNP_E_SOCKET_BIND"}, {UPNP_E_BAD_HTTPMSG, "UPNP_E_BAD_HTTPMSG"},
{UPNP_E_SOCKET_CONNECT, "UPNP_E_SOCKET_CONNECT"}, {UPNP_E_NETWORK_ERROR, "UPNP_E_NETWORK_ERROR"},
{UPNP_E_OUTOF_SOCKET, "UPNP_E_OUTOF_SOCKET"}, {UPNP_E_SOCKET_WRITE, "UPNP_E_SOCKET_WRITE"},
{UPNP_E_LISTEN, "UPNP_E_LISTEN"}, {UPNP_E_SOCKET_READ, "UPNP_E_SOCKET_READ"},
{UPNP_E_EVENT_PROTOCOL, "UPNP_E_EVENT_PROTOCOL"}, {UPNP_E_SOCKET_BIND, "UPNP_E_SOCKET_BIND"},
{UPNP_E_SUBSCRIBE_UNACCEPTED, "UPNP_E_SUBSCRIBE_UNACCEPTED"}, {UPNP_E_SOCKET_CONNECT, "UPNP_E_SOCKET_CONNECT"},
{UPNP_E_UNSUBSCRIBE_UNACCEPTED, "UPNP_E_UNSUBSCRIBE_UNACCEPTED"}, {UPNP_E_OUTOF_SOCKET, "UPNP_E_OUTOF_SOCKET"},
{UPNP_E_NOTIFY_UNACCEPTED, "UPNP_E_NOTIFY_UNACCEPTED"}, {UPNP_E_LISTEN, "UPNP_E_LISTEN"},
{UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"}, {UPNP_E_EVENT_PROTOCOL, "UPNP_E_EVENT_PROTOCOL"},
{UPNP_E_INVALID_ARGUMENT, "UPNP_E_INVALID_ARGUMENT"}, {UPNP_E_SUBSCRIBE_UNACCEPTED, "UPNP_E_SUBSCRIBE_UNACCEPTED"},
{UPNP_E_OUTOF_BOUNDS, "UPNP_E_OUTOF_BOUNDS"} {UPNP_E_UNSUBSCRIBE_UNACCEPTED, "UPNP_E_UNSUBSCRIBE_UNACCEPTED"},
{UPNP_E_NOTIFY_UNACCEPTED, "UPNP_E_NOTIFY_UNACCEPTED"},
{UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"},
{UPNP_E_INVALID_ARGUMENT, "UPNP_E_INVALID_ARGUMENT"},
{UPNP_E_OUTOF_BOUNDS, "UPNP_E_OUTOF_BOUNDS"},
}; };
/************************************************************************
* 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;
goto ExitFunction;
}
if( RelURL == NULL ) tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL);
return UPNP_E_INVALID_PARAM; if (tempRel) {
strcpy(AbsURL, tempRel);
tempRel = NULL; free(tempRel);
} else {
tempRel = resolve_rel_url((char*) BaseURL, (char*) RelURL ); ret = UPNP_E_INVALID_URL;
}
if( tempRel ) {
strcpy( AbsURL, tempRel );
free( tempRel );
} else {
return UPNP_E_INVALID_URL;
}
return UPNP_E_SUCCESS;
ExitFunction:
return UPNP_E_SUCCESS;
} }
/************************************************************************
* Function : addToAction /*!
* * \brief Adds the argument in the action request or response.
* Parameters: *
* IN int response: flag to tell if the ActionDoc is for response * This function creates the action request or response if it is a first
* or request * argument, otherwise it will add the argument in the document.
* INOUT IXML_Document **ActionDoc: request or response document *
* IN char *ActionName: Name of the action request or response * \returns UPNP_E_SUCCESS if successful, otherwise the appropriate error.
* IN char *ServType: Service type */
* IN char * ArgName: Name of the argument static int addToAction(
* IN char * ArgValue: Value of the argument /*! [in] flag to tell if the ActionDoc is for response or request. */
* int response,
* Description: /*! [in,out] Request or response document. */
* This function adds the argument in the action request or response. IXML_Document **ActionDoc,
* This function creates the action request or response if it is a first /*! [in] Name of the action request or response. */
* argument else it will add the argument in the document const char *ActionName,
* /*! [in] Service type. */
* Returns: int const char *ServType,
* returns UPNP_E_SUCCESS if successful else returns appropriate error /*! [in] Name of the argument. */
***************************************************************************/ const char *ArgName,
static int /*! [in] Value of the argument. */
addToAction( IN int response, const char *ArgValue)
INOUT IXML_Document ** ActionDoc,
IN const char *ActionName,
IN const char *ServType,
IN const char *ArgName,
IN const char *ArgValue )
{ {
char *ActBuff = NULL; char *ActBuff = NULL;
IXML_Node *node = NULL; IXML_Node *node = NULL;
IXML_Element *Ele = NULL; IXML_Element *Ele = NULL;
IXML_Node *Txt = NULL; IXML_Node *Txt = NULL;
int rc = 0; int rc = 0;
if( ActionName == NULL || ServType == NULL ) { if (ActionName == NULL || ServType == NULL) {
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
if( *ActionDoc == NULL ) { if (*ActionDoc == NULL) {
ActBuff = ( char * )malloc( HEADER_LENGTH ); ActBuff = (char *)malloc(HEADER_LENGTH);
if( ActBuff == NULL ) { if (ActBuff == NULL) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
if( response ) { if (response) {
sprintf( ActBuff, sprintf(ActBuff,
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>", "<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
ActionName, ServType, ActionName ); ActionName, ServType, ActionName);
} else { } else {
sprintf( ActBuff, sprintf(ActBuff,
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>", "<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
ActionName, ServType, ActionName ); ActionName, ServType, ActionName);
} }
rc = ixmlParseBufferEx( ActBuff, ActionDoc ); rc = ixmlParseBufferEx(ActBuff, ActionDoc);
free( ActBuff ); free(ActBuff);
if( rc != IXML_SUCCESS ) { if (rc != IXML_SUCCESS) {
if( rc == IXML_INSUFFICIENT_MEMORY ) { if (rc == IXML_INSUFFICIENT_MEMORY) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} else { } else {
return UPNP_E_INVALID_DESC; return UPNP_E_INVALID_DESC;
} }
} }
} }
if( ArgName != NULL /*&& ArgValue != NULL */ ) { if (ArgName != NULL /*&& ArgValue != 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 = 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: *
* IN int response: flag to tell if the ActionDoc is for response * \return Action request or response document if successful, otherwise
* or request * returns NULL
* IN char * ActionName: Name of the action request or response */
* IN char * ServType: Service type static IXML_Document *makeAction(
* IN int NumArg :Number of arguments in the action request or response /*! [in] flag to tell if the ActionDoc is for response or request. */
* IN char * Arg : pointer to the first argument int response,
* IN va_list ArgList: Argument list /*! [in] Name of the action request or response. */
* const char *ActionName,
* Description: /*! [in] Service type. */
* This function creates the action request or response from the argument const char *ServType,
* list. /*! [in] Number of arguments in the action request or response. */
* Returns: IXML_Document * int NumArg,
* returns action request or response document if successful /*! [in] pointer to the first argument. */
* else returns NULL const char *Arg,
***************************************************************************/ /*! [in] Argument list. */
static IXML_Document * va_list ArgList)
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;
char *ActBuff; char *ActBuff;
int Idx = 0; int Idx = 0;
IXML_Document *ActionDoc; IXML_Document *ActionDoc;
IXML_Node *node; IXML_Node *node;
IXML_Element *Ele; IXML_Element *Ele;
IXML_Node *Txt = NULL; IXML_Node *Txt = NULL;
if( ActionName == NULL || ServType == NULL ) { if (ActionName == NULL || ServType == NULL) {
return NULL; return NULL;
} }
ActBuff = ( char * )malloc( HEADER_LENGTH ); ActBuff = (char *)malloc(HEADER_LENGTH);
if( ActBuff == NULL ) { if (ActBuff == NULL) {
return NULL; return NULL;
} }
if( response ) { if (response) {
sprintf( ActBuff, sprintf(ActBuff,
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>", "<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
ActionName, ServType, ActionName ); ActionName, ServType, ActionName);
} else { } else {
sprintf( ActBuff, sprintf(ActBuff,
"<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) {
free(ActBuff);
return NULL;
}
if( ixmlParseBufferEx( ActBuff, &ActionDoc ) != IXML_SUCCESS ) { free(ActBuff);
free( ActBuff ); if(ActionDoc == NULL) {
return NULL; return NULL;
} }
free( ActBuff ); if (NumArg > 0) {
//va_start(ArgList, Arg);
ArgName = Arg;
for ( ; ; ) {
ArgValue = va_arg(ArgList, const char *);
if (ArgName != NULL) {
node = ixmlNode_getFirstChild((IXML_Node *)ActionDoc);
Ele = ixmlDocument_createElement(ActionDoc, ArgName);
if (ArgValue) {
Txt = ixmlDocument_createTextNode(ActionDoc, ArgValue);
ixmlNode_appendChild((IXML_Node *)Ele, Txt);
}
ixmlNode_appendChild(node, (IXML_Node *)Ele);
}
if (++Idx < NumArg) {
ArgName = va_arg(ArgList, const char *);
} else {
break;
}
}
//va_end(ArgList);
}
if( ActionDoc == NULL ) { return ActionDoc;
return NULL;
}
if( NumArg > 0 ) {
//va_start(ArgList, Arg);
ArgName = Arg;
for ( ; ; ) {
ArgValue = va_arg( ArgList, const char * );
if( ArgName != NULL ) {
node = ixmlNode_getFirstChild( ( IXML_Node * ) ActionDoc );
Ele = ixmlDocument_createElement( ActionDoc, ArgName );
if( ArgValue ) {
Txt =
ixmlDocument_createTextNode( ActionDoc, ArgValue );
ixmlNode_appendChild( ( IXML_Node * ) Ele, Txt );
}
ixmlNode_appendChild( node, ( IXML_Node * ) Ele );
}
if (++Idx < NumArg) {
ArgName = va_arg( ArgList, const char * );
} else {
break;
}
}
//va_end(ArgList);
}
return ActionDoc;
} }
/************************************************************************
* Function : UpnpMakeAction IXML_Document *UpnpMakeAction(
* const char *ActionName,
* Parameters: const char *ServType,
* IN char * ActionName: Name of the action request or response int NumArg,
* IN char * ServType: Service type const char *Arg,
* 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,
int NumArg,
const char *Arg,
... )
{ {
va_list ArgList; va_list ArgList;
IXML_Document *out = NULL; IXML_Document *out = NULL;
va_start( ArgList, Arg ); va_start(ArgList, Arg);
out = makeAction( 0, ActionName, ServType, NumArg, Arg, ArgList ); out = makeAction(0, ActionName, ServType, NumArg, Arg, ArgList);
va_end( ArgList ); va_end(ArgList);
return out; return out;
} }
/************************************************************************
* Function : UpnpMakeActionResponse IXML_Document *UpnpMakeActionResponse(
* const char *ActionName,
* Parameters: const char *ServType,
* IN char * ActionName: Name of the action request or response int NumArg,
* IN char * ServType: Service type const char *Arg,
* 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,
int NumArg,
const char *Arg,
... )
{ {
va_list ArgList; va_list ArgList;
IXML_Document *out = NULL; IXML_Document *out = NULL;
va_start( ArgList, Arg ); va_start(ArgList, Arg);
out = makeAction( 1, ActionName, ServType, NumArg, Arg, ArgList ); out = makeAction(1, ActionName, ServType, NumArg, Arg, ArgList);
va_end( ArgList ); va_end(ArgList);
return out; return out;
} }
/************************************************************************
* Function : UpnpAddToActionResponse int UpnpAddToAction(
* IXML_Document **ActionDoc,
* Parameters: const char *ActionName,
* INOUT IXML_Document **ActionResponse: action response document const char *ServType,
* IN char * ActionName: Name of the action request or response const char *ArgName,
* IN char * ServType: Service type const char *ArgValue)
* 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, return addToAction(0, ActionDoc, ActionName, ServType, ArgName, ArgValue);
ArgValue );
} }
/************************************************************************
* Function : UpnpAddToAction
*
* Parameters:
* INOUT IXML_Document **ActionDoc: action request document
* IN char * ActionName: Name of the action request or response
* IN char * ServType: Service type
* IN int ArgName :Name of argument to be added in the action response
* IN char * ArgValue : value of the argument
*
* Description:
* This function adds the argument in the action request. Its a wrapper
* function that calls addToAction function to add the argument in the
* action request.
*
* Returns: int
* returns UPNP_E_SUCCESS if successful
* else returns appropriate error
***************************************************************************/
int
UpnpAddToAction( IXML_Document ** ActionDoc,
const char *ActionName,
const char *ServType,
const char *ArgName,
const char *ArgValue )
{
return addToAction( 0, ActionDoc, ActionName, ServType, ArgName, int UpnpAddToActionResponse(
ArgValue ); IXML_Document **ActionResponse,
const char *ActionName,
const char *ServType,
const char *ArgName,
const char *ArgValue)
{
return addToAction(1, ActionResponse, ActionName, ServType, ArgName, ArgValue);
} }
/************************************************************************
* Function : UpnpAddToPropertySet IXML_Document *UpnpCreatePropertySet(
* int NumArg,
* Parameters: const char *Arg,
* 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 )
{ {
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;
char BlankDoc[] = "<e:propertyset xmlns:e=\"urn:schemas" if(ixmlParseBufferEx(BlankDoc, &PropSet) != IXML_SUCCESS) {
"-upnp-org:event-1-0\"></e:propertyset>"; return NULL;
IXML_Node *node; }
IXML_Element *Ele;
IXML_Element *Ele1;
IXML_Node *Txt;
int rc;
if( ArgName == NULL ) { if (NumArg < 1) {
return UPNP_E_INVALID_PARAM; return PropSet;
} }
if( *PropSet == NULL ) { va_start(ArgList, Arg);
rc = ixmlParseBufferEx( BlankDoc, PropSet ); ArgName = Arg;
if( rc != IXML_SUCCESS ) { while (Idx++ != NumArg) {
return UPNP_E_OUTOF_MEMORY; 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);
node = ixmlNode_getFirstChild( ( IXML_Node * ) * PropSet ); return 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 );
return UPNP_E_SUCCESS;
} }
/************************************************************************
* Function : UpnpCreatePropertySet int UpnpAddToPropertySet(
* IXML_Document **PropSet,
* Parameters: const char *ArgName,
* IN int NumArg: Number of argument that will go in the propertyset node const char *ArgValue)
* 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; char BlankDoc[] =
int Idx = 0; "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"
char BlankDoc[] = "<e:propertyset xmlns:e=\"urn:schemas-" "</e:propertyset>";
"upnp-org:event-1-0\"></e:propertyset>"; IXML_Node *node;
const char *ArgName, IXML_Element *Ele;
*ArgValue; IXML_Element *Ele1;
IXML_Node *node; IXML_Node *Txt;
IXML_Element *Ele; int rc;
IXML_Element *Ele1;
IXML_Node *Txt;
IXML_Document *PropSet;
if( ixmlParseBufferEx( BlankDoc, &PropSet ) != IXML_SUCCESS ) { if (ArgName == NULL) {
return NULL; return UPNP_E_INVALID_PARAM;
} }
if (NumArg < 1) { if (*PropSet == NULL) {
return PropSet; rc = ixmlParseBufferEx(BlankDoc, PropSet);
} if (rc != IXML_SUCCESS) {
return UPNP_E_OUTOF_MEMORY;
}
}
va_start( ArgList, Arg ); node = ixmlNode_getFirstChild((IXML_Node *)*PropSet);
ArgName = Arg;
while( Idx++ != NumArg ) { Ele1 = ixmlDocument_createElement(*PropSet, "e:property");
ArgValue = va_arg( ArgList, const char * ); Ele = ixmlDocument_createElement(*PropSet, ArgName);
if( ArgName != NULL /*&& ArgValue != NULL */ ) { if (ArgValue) {
node = ixmlNode_getFirstChild( ( IXML_Node * ) PropSet ); Txt = ixmlDocument_createTextNode(*PropSet, ArgValue);
Ele1 = ixmlDocument_createElement( PropSet, "e:property" ); ixmlNode_appendChild((IXML_Node *)Ele, Txt);
Ele = ixmlDocument_createElement( PropSet, ArgName ); }
if( ArgValue ) {
Txt = ixmlDocument_createTextNode( PropSet, ArgValue );
ixmlNode_appendChild( ( IXML_Node * ) Ele, Txt );
}
ixmlNode_appendChild( ( IXML_Node * ) Ele1, ixmlNode_appendChild((IXML_Node *)Ele1, (IXML_Node *)Ele);
( IXML_Node * ) Ele ); ixmlNode_appendChild(node, (IXML_Node *)Ele1);
ixmlNode_appendChild( node, ( IXML_Node * ) Ele1 );
}
ArgName = va_arg( ArgList, const char * ); return UPNP_E_SUCCESS;
}
va_end( ArgList );
return PropSet;
} }
#endif // EXCLUDE_DOM == 0
#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
* *