Backport of ixml from 1.8.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@478 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
881b212690
commit
812d019d12
3230
ixml/inc/ixml.h
3230
ixml/inc/ixml.h
File diff suppressed because it is too large
Load Diff
@ -1,60 +1,53 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* Function: Attr_init
|
||||
* Initializes an attribute node
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlAttr_init( IN IXML_Attr * attr )
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void ixmlAttr_init(IN IXML_Attr *attr)
|
||||
{
|
||||
if( attr != NULL ) {
|
||||
memset( attr, 0, sizeof( IXML_Attr ) );
|
||||
}
|
||||
if (attr != NULL) {
|
||||
memset(attr, 0, sizeof (IXML_Attr));
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* Function: Attr_free
|
||||
* Frees an attribute node.
|
||||
* external function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlAttr_free( IN IXML_Attr * attr )
|
||||
|
||||
void ixmlAttr_free(IN IXML_Attr *attr)
|
||||
{
|
||||
if( attr != NULL ) {
|
||||
ixmlNode_free( ( IXML_Node * ) attr );
|
||||
}
|
||||
if (attr != NULL) {
|
||||
ixmlNode_free((IXML_Node *)attr);
|
||||
}
|
||||
}
|
||||
|
||||
|
1136
ixml/src/document.c
1136
ixml/src/document.c
File diff suppressed because it is too large
Load Diff
1434
ixml/src/element.c
1434
ixml/src/element.c
File diff suppressed because it is too large
Load Diff
@ -1,73 +1,173 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef IXML_MEMBUF_H
|
||||
#define IXML_MEMBUF_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
#ifndef _IXML_MEMBUF_H
|
||||
#define _IXML_MEMBUF_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ixml.h"
|
||||
|
||||
#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
|
||||
|
||||
|
||||
typedef struct // ixml_membuf
|
||||
/*!
|
||||
* \brief The ixml_membuf type.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *buf;
|
||||
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
size_t size_inc;
|
||||
|
||||
char *buf;
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
size_t size_inc;
|
||||
} 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);
|
||||
int ixml_membuf_assign(INOUT ixml_membuf *m, IN const void *buf,
|
||||
IN size_t buf_len );
|
||||
int ixml_membuf_assign_str(INOUT ixml_membuf *m, IN const char *c_str );
|
||||
int ixml_membuf_append(INOUT ixml_membuf *m, IN const void *buf);
|
||||
int ixml_membuf_append_str(INOUT ixml_membuf *m, IN const char *c_str);
|
||||
int ixml_membuf_insert(INOUT ixml_membuf *m, IN const void* buf,
|
||||
IN size_t buf_len, int index );
|
||||
/*!
|
||||
* \brief ixml_membuf initialization routine.
|
||||
*/
|
||||
void ixml_membuf_init(
|
||||
/*! [in,out] The memory buffer to initializa. */
|
||||
ixml_membuf *m);
|
||||
|
||||
|
||||
/*!
|
||||
* \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
|
||||
|
@ -1,41 +1,49 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _IXMLPARSER_H
|
||||
#define _IXMLPARSER_H
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef IXMLPARSER_H
|
||||
#define IXMLPARSER_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixml.h"
|
||||
#include "ixmlmembuf.h"
|
||||
|
||||
// Parser definitions
|
||||
|
||||
/* Parser definitions */
|
||||
#define QUOT """
|
||||
#define LT "<"
|
||||
#define GT ">"
|
||||
@ -44,77 +52,218 @@
|
||||
#define ESC_HEX "&#x"
|
||||
#define ESC_DEC "&#"
|
||||
|
||||
|
||||
typedef struct _IXML_NamespaceURI
|
||||
{
|
||||
char *nsURI;
|
||||
char *prefix;
|
||||
struct _IXML_NamespaceURI *nextNsURI;
|
||||
char *nsURI;
|
||||
char *prefix;
|
||||
struct _IXML_NamespaceURI *nextNsURI;
|
||||
} IXML_NamespaceURI;
|
||||
|
||||
|
||||
typedef struct _IXML_ElementStack
|
||||
{
|
||||
char *element;
|
||||
char *prefix;
|
||||
char *namespaceUri;
|
||||
IXML_NamespaceURI *pNsURI;
|
||||
struct _IXML_ElementStack *nextElement;
|
||||
char *element;
|
||||
char *prefix;
|
||||
char *namespaceUri;
|
||||
IXML_NamespaceURI *pNsURI;
|
||||
struct _IXML_ElementStack *nextElement;
|
||||
} IXML_ElementStack;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
eELEMENT,
|
||||
eATTRIBUTE,
|
||||
eCONTENT,
|
||||
eELEMENT,
|
||||
eATTRIBUTE,
|
||||
eCONTENT,
|
||||
} PARSER_STATE;
|
||||
|
||||
|
||||
typedef struct _Parser
|
||||
{
|
||||
char *dataBuffer; //data buffer
|
||||
char *curPtr; //ptr to the token parsed
|
||||
char *savePtr; //Saves for backup
|
||||
ixml_membuf lastElem;
|
||||
ixml_membuf tokenBuf;
|
||||
|
||||
IXML_Node *pNeedPrefixNode;
|
||||
IXML_ElementStack *pCurElement;
|
||||
IXML_Node *currentNodePtr;
|
||||
PARSER_STATE state;
|
||||
|
||||
BOOL bHasTopLevel;
|
||||
|
||||
/*! Data buffer. */
|
||||
char *dataBuffer;
|
||||
/*! Pointer to the token parsed. */
|
||||
char *curPtr;
|
||||
/*! Saves for backup. */
|
||||
char *savePtr;
|
||||
ixml_membuf lastElem;
|
||||
ixml_membuf tokenBuf;
|
||||
IXML_Node *pNeedPrefixNode;
|
||||
IXML_ElementStack *pCurElement;
|
||||
IXML_Node *currentNodePtr;
|
||||
PARSER_STATE state;
|
||||
BOOL bHasTopLevel;
|
||||
} Parser;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Check to see whether name is a valid xml name.
|
||||
*/
|
||||
BOOL Parser_isValidXmlName(
|
||||
/*! [in] The string to be checked. */
|
||||
const DOMString name);
|
||||
|
||||
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 ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add);
|
||||
int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file);
|
||||
|
||||
void ixmlNode_init(IXML_Node *IXML_Nodeptr);
|
||||
BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node);
|
||||
int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
|
||||
|
||||
void ixmlNode_getElementsByTagName( IXML_Node *n, const char *tagname, IXML_NodeList **list);
|
||||
void ixmlNode_getElementsByTagNameNS( IXML_Node *IXML_Node, const char *namespaceURI,
|
||||
const char *localName, IXML_NodeList **list);
|
||||
|
||||
int ixmlNode_setNodeProperties(IXML_Node* node, IXML_Node *src);
|
||||
int ixmlNode_setNodeName( IXML_Node* node, const DOMString qualifiedName);
|
||||
void ixmlAttr_init(IXML_Attr *attrNode);
|
||||
|
||||
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 */
|
||||
|
||||
|
956
ixml/src/ixml.c
956
ixml/src/ixml.c
@ -1,531 +1,469 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmldebug.h"
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* copy_with_escape
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
static void
|
||||
copy_with_escape( INOUT ixml_membuf * buf,
|
||||
IN const char *p )
|
||||
|
||||
#include <stdlib.h> /* for free() */
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Appends a string to a buffer, substituting some characters by escape
|
||||
* sequences.
|
||||
*/
|
||||
static void copy_with_escape(
|
||||
/*! [in,out] The input/output buffer. */
|
||||
ixml_membuf *buf,
|
||||
/*! [in] The string to copy from. */
|
||||
const char *p)
|
||||
{
|
||||
int i;
|
||||
int plen;
|
||||
|
||||
if( p == NULL )
|
||||
return;
|
||||
|
||||
plen = strlen( p );
|
||||
|
||||
for( i = 0; i < plen; i++ ) {
|
||||
switch ( p[i] ) {
|
||||
case '<':
|
||||
ixml_membuf_append_str( buf, "<" );
|
||||
break;
|
||||
|
||||
case '>':
|
||||
ixml_membuf_append_str( buf, ">" );
|
||||
break;
|
||||
|
||||
case '&':
|
||||
ixml_membuf_append_str( buf, "&" );
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
ixml_membuf_append_str( buf, "'" );
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
ixml_membuf_append_str( buf, """ );
|
||||
break;
|
||||
|
||||
default:
|
||||
ixml_membuf_append( buf, &p[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* 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 );
|
||||
int i;
|
||||
int plen;
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
plen = strlen( p );
|
||||
|
||||
for (i = 0; i < plen; i++) {
|
||||
switch (p[i]) {
|
||||
case '<':
|
||||
ixml_membuf_append_str(buf, "<");
|
||||
break;
|
||||
|
||||
case '>':
|
||||
ixml_membuf_append_str(buf, ">");
|
||||
break;
|
||||
|
||||
case '&':
|
||||
ixml_membuf_append_str(buf, "&");
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
ixml_membuf_append_str(buf, "'");
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
ixml_membuf_append_str(buf, """);
|
||||
break;
|
||||
|
||||
default:
|
||||
ixml_membuf_append(buf, &p[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*================================================================
|
||||
* ixmlParseBufferEx
|
||||
* Parse xml file stored in buffer.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlParseBufferEx( IN const char *buffer,
|
||||
IXML_Document ** retDoc )
|
||||
/*!
|
||||
* \brief Recursive function to print all the node in a tree.
|
||||
* Internal to parser only.
|
||||
*/
|
||||
static void ixmlPrintDomTreeRecursive(
|
||||
/*! [in] \todo documentation. */
|
||||
IXML_Node *nodeptr,
|
||||
/*! [in] \todo documentation. */
|
||||
ixml_membuf *buf)
|
||||
{
|
||||
const char *nodeName = NULL;
|
||||
const char *nodeValue = NULL;
|
||||
IXML_Node *child = NULL,
|
||||
*sibling = NULL;
|
||||
|
||||
if( ( buffer == NULL ) || ( retDoc == NULL ) ) {
|
||||
return IXML_INVALID_PARAMETER;
|
||||
}
|
||||
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;
|
||||
|
||||
if( buffer[0] == '\0' ) {
|
||||
return IXML_INVALID_PARAMETER;
|
||||
}
|
||||
case eCDATA_SECTION_NODE:
|
||||
ixml_membuf_append_str(buf, "<![CDATA[");
|
||||
ixml_membuf_append_str(buf, nodeValue);
|
||||
ixml_membuf_append_str(buf, "]]>");
|
||||
break;
|
||||
|
||||
return Parser_LoadDocument( retDoc, buffer, FALSE );
|
||||
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
|
||||
* Frees a DOM String.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlFreeDOMString( IN DOMString buf )
|
||||
|
||||
int ixmlLoadDocumentEx(const char *xmlFile, IXML_Document **doc)
|
||||
{
|
||||
if( buf != NULL ) {
|
||||
free( buf );
|
||||
}
|
||||
if (xmlFile == NULL || doc == NULL) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,236 +1,218 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixml.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ixmlmembuf.h"
|
||||
#include "ixml.h"
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_set_size
|
||||
*
|
||||
* Increases or decreases buffer cap so that at least
|
||||
* 'new_length' bytes can be stored
|
||||
*
|
||||
* On error, m's fields do not change.
|
||||
*
|
||||
* returns:
|
||||
* UPNP_E_SUCCESS
|
||||
* UPNP_E_OUTOF_MEMORY
|
||||
*
|
||||
*=================================================================*/
|
||||
static int
|
||||
ixml_membuf_set_size( INOUT ixml_membuf * m,
|
||||
IN size_t new_length )
|
||||
|
||||
/*!
|
||||
* \brief Increases or decreases buffer capacity so that at least 'new_length'
|
||||
* bytes can be stored.
|
||||
*
|
||||
* On error, m's fields do not change.
|
||||
*
|
||||
* \return
|
||||
* \li UPNP_E_SUCCESS
|
||||
* \li UPNP_E_OUTOF_MEMORY
|
||||
*/
|
||||
static int ixml_membuf_set_size(
|
||||
/*! [in,out] The memory buffer. */
|
||||
INOUT ixml_membuf *m,
|
||||
/*! [in] The new lenght. */
|
||||
IN size_t new_length)
|
||||
{
|
||||
size_t diff;
|
||||
size_t alloc_len;
|
||||
char *temp_buf;
|
||||
size_t diff;
|
||||
size_t alloc_len;
|
||||
char *temp_buf;
|
||||
|
||||
if( new_length >= m->length ) // increase length
|
||||
{
|
||||
// need more mem?
|
||||
if( new_length <= m->capacity ) {
|
||||
return 0; // have enough mem; done
|
||||
}
|
||||
if (new_length >= m->length) {
|
||||
/* increase length */
|
||||
/* need more mem? */
|
||||
if (new_length <= m->capacity) {
|
||||
/* have enough mem; done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff = new_length - m->length;
|
||||
alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity;
|
||||
} else // decrease length
|
||||
{
|
||||
assert( new_length <= m->length );
|
||||
diff = new_length - m->length;
|
||||
alloc_len = MAXVAL(m->size_inc, diff) + m->capacity;
|
||||
} else {
|
||||
// decrease length
|
||||
assert(new_length <= m->length);
|
||||
|
||||
// if diff is 0..m->size_inc, don't free
|
||||
if( ( m->capacity - new_length ) <= m->size_inc ) {
|
||||
return 0;
|
||||
}
|
||||
// if diff is 0..m->size_inc, don't free
|
||||
if ((m->capacity - new_length) <= m->size_inc) {
|
||||
return 0;
|
||||
}
|
||||
alloc_len = new_length + m->size_inc;
|
||||
}
|
||||
|
||||
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 );
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* membuffer_init
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixml_membuf_init( INOUT ixml_membuf * m )
|
||||
{
|
||||
assert( m != NULL );
|
||||
|
||||
m->size_inc = MEMBUF_DEF_SIZE_INC;
|
||||
m->buf = NULL;
|
||||
m->length = 0;
|
||||
m->capacity = 0;
|
||||
void ixml_membuf_init(ixml_membuf *m)
|
||||
{
|
||||
assert(m != NULL);
|
||||
|
||||
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 );
|
||||
ixml_membuf_init( m );
|
||||
void ixml_membuf_destroy(ixml_membuf *m)
|
||||
{
|
||||
if (m == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(m->buf);
|
||||
ixml_membuf_init(m);
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixml_membuf_assign
|
||||
*
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixml_membuf_assign( INOUT ixml_membuf * m,
|
||||
IN const void *buf,
|
||||
IN size_t buf_len )
|
||||
|
||||
int ixml_membuf_assign(
|
||||
ixml_membuf *m,
|
||||
const void *buf,
|
||||
size_t buf_len)
|
||||
{
|
||||
int return_code;
|
||||
int return_code;
|
||||
|
||||
assert( m != NULL );
|
||||
assert(m != NULL);
|
||||
|
||||
// set value to null
|
||||
if( buf == NULL ) {
|
||||
ixml_membuf_destroy( m );
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
// alloc mem
|
||||
return_code = ixml_membuf_set_size( m, buf_len );
|
||||
if( return_code != 0 ) {
|
||||
return return_code;
|
||||
}
|
||||
// copy
|
||||
memcpy( m->buf, buf, buf_len );
|
||||
m->buf[buf_len] = 0; // null-terminate
|
||||
// set value to null
|
||||
if (buf == NULL) {
|
||||
ixml_membuf_destroy(m);
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
// alloc mem
|
||||
return_code = ixml_membuf_set_size(m, buf_len);
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
|
||||
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( INOUT ixml_membuf * m,
|
||||
IN const char *c_str )
|
||||
|
||||
int ixml_membuf_assign_str(
|
||||
ixml_membuf *m,
|
||||
const char *c_str)
|
||||
{
|
||||
return ixml_membuf_assign( m, c_str, strlen( c_str ) );
|
||||
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 index )
|
||||
|
||||
int ixml_membuf_insert(
|
||||
INOUT ixml_membuf *m,
|
||||
IN const void *buf,
|
||||
IN size_t buf_len,
|
||||
int index)
|
||||
{
|
||||
int return_code;
|
||||
int return_code = 0;
|
||||
|
||||
assert( m != NULL );
|
||||
assert(m != NULL);
|
||||
|
||||
if( index < 0 || index > ( int )m->length )
|
||||
return IXML_INDEX_SIZE_ERR;
|
||||
if (index < 0 || index > (int)m->length) {
|
||||
return IXML_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
if( buf == NULL || buf_len == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
// alloc mem
|
||||
return_code = ixml_membuf_set_size( m, m->length + buf_len );
|
||||
if( return_code != 0 ) {
|
||||
return return_code;
|
||||
}
|
||||
// insert data
|
||||
// move data to right of insertion point
|
||||
memmove( m->buf + index + buf_len, m->buf + index, m->length - index );
|
||||
memcpy( m->buf + index, buf, buf_len );
|
||||
m->length += buf_len;
|
||||
m->buf[m->length] = 0; // null-terminate
|
||||
if (buf == NULL || buf_len == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* alloc mem */
|
||||
return_code = ixml_membuf_set_size(m, m->length + buf_len);
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
/* insert data */
|
||||
/* move data to right of insertion point */
|
||||
memmove(m->buf + index + buf_len, m->buf + index, m->length - index);
|
||||
memcpy(m->buf + index, buf, buf_len);
|
||||
m->length += buf_len;
|
||||
/* Null terminate */
|
||||
m->buf[m->length] = 0;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,242 +1,195 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_getItemNumber
|
||||
* return the item number of a item in NamedNodeMap.
|
||||
* Internal to parser only.
|
||||
* Parameters:
|
||||
* name: the name of the item to find
|
||||
*
|
||||
*=================================================================*/
|
||||
unsigned long
|
||||
ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
|
||||
IN const char *name )
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> /* for free(), malloc() */
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Return the item number of a item in NamedNodeMap.
|
||||
*/
|
||||
static unsigned long ixmlNamedNodeMap_getItemNumber(
|
||||
/*! [in] The named node map to process. */
|
||||
IN IXML_NamedNodeMap *nnMap,
|
||||
/*! [in] The name of the item to find. */
|
||||
IN const char *name)
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
unsigned long returnItemNo = 0;
|
||||
IXML_Node *tempNode;
|
||||
unsigned long returnItemNo = 0;
|
||||
|
||||
assert( nnMap != NULL && name != NULL );
|
||||
if( ( nnMap == NULL ) || ( name == NULL ) ) {
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
}
|
||||
assert(nnMap != NULL && name != NULL);
|
||||
if (nnMap == NULL || name == NULL) {
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
}
|
||||
|
||||
tempNode = nnMap->nodeItem;
|
||||
while( tempNode != NULL ) {
|
||||
if( strcmp( name, tempNode->nodeName ) == 0 ) {
|
||||
return returnItemNo;
|
||||
}
|
||||
tempNode = nnMap->nodeItem;
|
||||
while (tempNode != NULL) {
|
||||
if (strcmp(name, tempNode->nodeName) == 0) {
|
||||
return returnItemNo;
|
||||
}
|
||||
tempNode = tempNode->nextSibling;
|
||||
returnItemNo++;
|
||||
}
|
||||
|
||||
tempNode = tempNode->nextSibling;
|
||||
returnItemNo++;
|
||||
}
|
||||
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
return IXML_INVALID_ITEM_NUMBER;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_init
|
||||
* Initializes a NamedNodeMap object.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNamedNodeMap_init( IN IXML_NamedNodeMap * nnMap )
|
||||
|
||||
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
assert( nnMap != NULL );
|
||||
memset( nnMap, 0, sizeof( IXML_NamedNodeMap ) );
|
||||
assert(nnMap != NULL);
|
||||
|
||||
memset(nnMap, 0, sizeof (IXML_NamedNodeMap));
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_getNamedItem
|
||||
* Retrieves a node specified by name.
|
||||
* External function.
|
||||
*
|
||||
* Parameter:
|
||||
* name: type nodeName of a node to retrieve.
|
||||
*
|
||||
* Return Value:
|
||||
* A Node with the specified nodeName, or null if it
|
||||
* does not identify any node in this map.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNamedNodeMap_getNamedItem( IN IXML_NamedNodeMap * nnMap,
|
||||
IN const char *name )
|
||||
|
||||
IXML_Node *ixmlNamedNodeMap_getNamedItem(
|
||||
IXML_NamedNodeMap *nnMap,
|
||||
const DOMString name)
|
||||
{
|
||||
long index;
|
||||
long index;
|
||||
|
||||
if( ( nnMap == NULL ) || ( name == NULL ) ) {
|
||||
return NULL;
|
||||
}
|
||||
if (nnMap == NULL || name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
index = ixmlNamedNodeMap_getItemNumber( nnMap, name );
|
||||
if( index == IXML_INVALID_ITEM_NUMBER ) {
|
||||
return NULL;
|
||||
} else {
|
||||
return ( ixmlNamedNodeMap_item( nnMap, ( unsigned long )index ) );
|
||||
}
|
||||
index = ixmlNamedNodeMap_getItemNumber(nnMap, name);
|
||||
if (index == IXML_INVALID_ITEM_NUMBER) {
|
||||
return NULL;
|
||||
} else {
|
||||
return ixmlNamedNodeMap_item(nnMap, (unsigned long)index);
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_item
|
||||
* Returns the indexth item in the map. If index is greater than or
|
||||
* equal to the number of nodes in this map, this returns null.
|
||||
* External function.
|
||||
*
|
||||
* Parameter:
|
||||
* index: index into this map.
|
||||
*
|
||||
* Return Value:
|
||||
* The node at the indexth position in the map, or null if that is
|
||||
* not a valid index.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNamedNodeMap_item( IN IXML_NamedNodeMap * nnMap,
|
||||
IN unsigned long index )
|
||||
|
||||
IXML_Node *ixmlNamedNodeMap_item(
|
||||
IN IXML_NamedNodeMap *nnMap,
|
||||
IN unsigned long index )
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
unsigned int i;
|
||||
IXML_Node *tempNode;
|
||||
unsigned int i;
|
||||
|
||||
if( nnMap == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
if (nnMap == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( index > ixmlNamedNodeMap_getLength( nnMap ) - 1 ) {
|
||||
return NULL;
|
||||
}
|
||||
if (index > ixmlNamedNodeMap_getLength(nnMap) - 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tempNode = nnMap->nodeItem;
|
||||
for( i = 0; i < index && tempNode != NULL; ++i ) {
|
||||
tempNode = tempNode->nextSibling;
|
||||
}
|
||||
tempNode = nnMap->nodeItem;
|
||||
for (i = 0; i < index && tempNode != NULL; ++i) {
|
||||
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 ) {
|
||||
tempNode = nnMap->nodeItem;
|
||||
for( length = 0; tempNode != NULL; ++length ) {
|
||||
tempNode = tempNode->nextSibling;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
IXML_Node *tempNode;
|
||||
unsigned long length = 0;
|
||||
|
||||
if (nnMap != NULL) {
|
||||
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 ) {
|
||||
pNext = nnMap->next;
|
||||
free( nnMap );
|
||||
nnMap = pNext;
|
||||
}
|
||||
void ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap)
|
||||
{
|
||||
IXML_NamedNodeMap *pNext;
|
||||
|
||||
while (nnMap != NULL) {
|
||||
pNext = nnMap->next;
|
||||
free(nnMap);
|
||||
nnMap = pNext;
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* NamedNodeMap_addToNamedNodeMap
|
||||
* add a node to a NamedNodeMap.
|
||||
* Internal to parser only.
|
||||
* Parameters:
|
||||
* add: the node to add into NamedNodeMap.
|
||||
* Return:
|
||||
* IXML_SUCCESS or failure.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
|
||||
IN IXML_Node * add )
|
||||
|
||||
int ixmlNamedNodeMap_addToNamedNodeMap(
|
||||
IXML_NamedNodeMap **nnMap,
|
||||
IXML_Node *add)
|
||||
{
|
||||
IXML_NamedNodeMap *traverse = NULL,
|
||||
*p = NULL;
|
||||
IXML_NamedNodeMap *newItem = NULL;
|
||||
IXML_NamedNodeMap *traverse = NULL;
|
||||
IXML_NamedNodeMap *p = NULL;
|
||||
IXML_NamedNodeMap *newItem = NULL;
|
||||
|
||||
if( add == NULL ) {
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
if(add == NULL) {
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
if( *nnMap == NULL ) // nodelist is empty
|
||||
{
|
||||
*nnMap =
|
||||
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
|
||||
if( *nnMap == NULL ) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
ixmlNamedNodeMap_init( *nnMap );
|
||||
}
|
||||
if (*nnMap == NULL) {
|
||||
// nodelist is empty
|
||||
*nnMap = (IXML_NamedNodeMap *)malloc(sizeof (IXML_NamedNodeMap));
|
||||
if (*nnMap == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
ixmlNamedNodeMap_init(*nnMap);
|
||||
}
|
||||
if ((*nnMap)->nodeItem == NULL) {
|
||||
(*nnMap)->nodeItem = add;
|
||||
} else {
|
||||
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 ) {
|
||||
( *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;
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
|
2790
ixml/src/node.c
2790
ixml/src/node.c
File diff suppressed because it is too large
Load Diff
@ -1,176 +1,152 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#include "ixmlparser.h"
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_init
|
||||
* initializes a nodelist
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNodeList_init( IXML_NodeList * nList )
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void ixmlNodeList_init(IXML_NodeList *nList)
|
||||
{
|
||||
assert( nList != NULL );
|
||||
|
||||
memset( nList, 0, sizeof( IXML_NodeList ) );
|
||||
assert(nList != NULL);
|
||||
|
||||
memset(nList, 0, sizeof (IXML_NodeList));
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_item
|
||||
* Returns the indexth item in the collection. If index is greater
|
||||
* than or equal to the number of nodes in the list, this returns
|
||||
* null.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
IXML_Node *
|
||||
ixmlNodeList_item( IXML_NodeList * nList,
|
||||
unsigned long index )
|
||||
|
||||
IXML_Node *ixmlNodeList_item(
|
||||
IXML_NodeList *nList,
|
||||
unsigned long index)
|
||||
{
|
||||
IXML_NodeList *next;
|
||||
unsigned int i;
|
||||
IXML_NodeList *next;
|
||||
unsigned int i;
|
||||
|
||||
// if the list ptr is NULL
|
||||
if( nList == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
// if index is more than list length
|
||||
if( index > ixmlNodeList_length( nList ) - 1 ) {
|
||||
return NULL;
|
||||
}
|
||||
// if the list ptr is NULL
|
||||
if (nList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// if index is more than list length
|
||||
if (index > ixmlNodeList_length(nList) - 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
next = nList;
|
||||
for( i = 0; i < index && next != NULL; ++i ) {
|
||||
next = next->next;
|
||||
}
|
||||
next = nList;
|
||||
for (i = 0; i < index && next != NULL; ++i) {
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
if( next == NULL ) return NULL;
|
||||
|
||||
return next->nodeItem;
|
||||
if (next == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return next->nodeItem;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_addToNodeList
|
||||
* Add a node to nodelist
|
||||
* Internal to parser only.
|
||||
*
|
||||
*=================================================================*/
|
||||
int
|
||||
ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
|
||||
IN IXML_Node * add )
|
||||
int ixmlNodeList_addToNodeList(
|
||||
IXML_NodeList **nList,
|
||||
IXML_Node *add)
|
||||
{
|
||||
IXML_NodeList *traverse,
|
||||
*p = NULL;
|
||||
IXML_NodeList *newListItem;
|
||||
IXML_NodeList *traverse = NULL;
|
||||
IXML_NodeList *p = NULL;
|
||||
IXML_NodeList *newListItem;
|
||||
|
||||
assert( add != NULL );
|
||||
assert(add != NULL);
|
||||
|
||||
if( add == NULL ) {
|
||||
return IXML_FAILED;
|
||||
}
|
||||
if (add == NULL) {
|
||||
return IXML_FAILED;
|
||||
}
|
||||
|
||||
if( *nList == NULL ) // nodelist is empty
|
||||
{
|
||||
*nList = ( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
|
||||
if( *nList == NULL ) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
if (*nList == NULL) {
|
||||
// nodelist is empty
|
||||
*nList = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
|
||||
if (*nList == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
ixmlNodeList_init( *nList );
|
||||
}
|
||||
ixmlNodeList_init(*nList);
|
||||
}
|
||||
|
||||
if( ( *nList )->nodeItem == NULL ) {
|
||||
( *nList )->nodeItem = add;
|
||||
} else {
|
||||
traverse = *nList;
|
||||
while( traverse != NULL ) {
|
||||
p = traverse;
|
||||
traverse = traverse->next;
|
||||
}
|
||||
if ((*nList)->nodeItem == NULL) {
|
||||
(*nList)->nodeItem = add;
|
||||
} else {
|
||||
traverse = *nList;
|
||||
while (traverse != NULL) {
|
||||
p = traverse;
|
||||
traverse = traverse->next;
|
||||
}
|
||||
|
||||
newListItem =
|
||||
( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
|
||||
if( newListItem == NULL ) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
p->next = newListItem;
|
||||
newListItem->nodeItem = add;
|
||||
newListItem->next = NULL;
|
||||
}
|
||||
newListItem = (IXML_NodeList *)malloc(sizeof (IXML_NodeList));
|
||||
if (newListItem == NULL) {
|
||||
return IXML_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
p->next = newListItem;
|
||||
newListItem->nodeItem = add;
|
||||
newListItem->next = NULL;
|
||||
}
|
||||
|
||||
return IXML_SUCCESS;
|
||||
return IXML_SUCCESS;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_length
|
||||
* Returns the number of nodes in the list. The range of valid
|
||||
* child node indices is 0 to length-1 inclusive.
|
||||
* External function.
|
||||
*
|
||||
*=================================================================*/
|
||||
unsigned long
|
||||
ixmlNodeList_length( IN IXML_NodeList * nList )
|
||||
|
||||
unsigned long ixmlNodeList_length(IXML_NodeList *nList)
|
||||
{
|
||||
IXML_NodeList *list;
|
||||
unsigned long length = 0;
|
||||
IXML_NodeList *list;
|
||||
unsigned long length = 0;
|
||||
|
||||
list = nList;
|
||||
while( list != NULL ) {
|
||||
++length;
|
||||
list = list->next;
|
||||
}
|
||||
list = nList;
|
||||
while (list != NULL) {
|
||||
++length;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return length;
|
||||
return length;
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
* ixmlNodeList_free
|
||||
* frees a nodeList
|
||||
* External function
|
||||
*
|
||||
*=================================================================*/
|
||||
void
|
||||
ixmlNodeList_free( IN IXML_NodeList * nList )
|
||||
|
||||
void ixmlNodeList_free(IXML_NodeList *nList)
|
||||
{
|
||||
IXML_NodeList *next;
|
||||
|
||||
while( nList != NULL ) {
|
||||
next = nList->next;
|
||||
|
||||
free( nList );
|
||||
nList = next;
|
||||
}
|
||||
IXML_NodeList *next;
|
||||
|
||||
while (nList != NULL) {
|
||||
next = nList->next;
|
||||
free(nList);
|
||||
nList = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,36 +1,41 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "sample_util.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if !UPNP_HAVE_TOOLS
|
||||
# error "Need upnptools.h to compile samples ; try ./configure --enable-tools"
|
||||
@ -45,7 +50,7 @@ int initialize = 1;
|
||||
print_string gPrintFun = NULL;
|
||||
state_update gStateUpdateFun = NULL;
|
||||
|
||||
//mutex to control displaying of events
|
||||
/*! mutex to control displaying of events */
|
||||
ithread_mutex_t display_mutex;
|
||||
|
||||
/********************************************************************************
|
||||
@ -425,10 +430,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
a_event->ServiceID );
|
||||
if( a_event->ActionRequest ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
|
||||
if( xmlbuff )
|
||||
if ( xmlbuff ) {
|
||||
SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActRequest = (null)\n" );
|
||||
@ -436,10 +441,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
|
||||
if( a_event->ActionResult ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
|
||||
if( xmlbuff )
|
||||
if ( xmlbuff ) {
|
||||
SampleUtil_Print( "ActResult = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActResult = (null)\n" );
|
||||
@ -459,10 +464,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
a_event->CtrlUrl );
|
||||
if( a_event->ActionRequest ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest );
|
||||
if( xmlbuff )
|
||||
if( xmlbuff ) {
|
||||
SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActRequest = (null)\n" );
|
||||
@ -470,10 +475,10 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
|
||||
if( a_event->ActionResult ) {
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult );
|
||||
if( xmlbuff )
|
||||
if( xmlbuff ) {
|
||||
SampleUtil_Print( "ActResult = %s\n", xmlbuff );
|
||||
if( xmlbuff )
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
}
|
||||
xmlbuff = NULL;
|
||||
} else {
|
||||
SampleUtil_Print( "ActResult = (null)\n" );
|
||||
@ -542,7 +547,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
e_event->EventKey );
|
||||
xmlbuff = ixmlPrintNode( ( IXML_Node * ) e_event->ChangedVariables );
|
||||
SampleUtil_Print( "ChangedVars = %s\n", xmlbuff );
|
||||
ixmlFreeDOMString( xmlbuff );
|
||||
ixmlFreeDOMString(xmlbuff);
|
||||
xmlbuff = NULL;
|
||||
}
|
||||
break;
|
||||
@ -599,7 +604,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
( "======================================================================\n\n\n\n" );
|
||||
|
||||
ithread_mutex_unlock( &display_mutex );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
@ -620,7 +625,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
|
||||
********************************************************************************/
|
||||
int
|
||||
SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
|
||||
IN char *location,
|
||||
IN const char *location,
|
||||
IN char *serviceType,
|
||||
OUT char **serviceId,
|
||||
OUT char **eventURL,
|
||||
@ -632,18 +637,18 @@ SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
|
||||
int ret;
|
||||
char *tempServiceType = NULL;
|
||||
char *baseURL = NULL;
|
||||
char *base;
|
||||
const char *base = NULL;
|
||||
char *relcontrolURL = NULL,
|
||||
*releventURL = NULL;
|
||||
IXML_NodeList *serviceList = NULL;
|
||||
IXML_Element *service = NULL;
|
||||
|
||||
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
|
||||
|
||||
if( baseURL )
|
||||
if (baseURL) {
|
||||
base = baseURL;
|
||||
else
|
||||
} else {
|
||||
base = location;
|
||||
}
|
||||
|
||||
serviceList = SampleUtil_GetFirstServiceList( DescDoc );
|
||||
length = ixmlNodeList_length( serviceList );
|
||||
@ -753,22 +758,23 @@ uprint1( char *fmt,
|
||||
* Same as printf()
|
||||
*
|
||||
********************************************************************************/
|
||||
int
|
||||
SampleUtil_Print( char *fmt,
|
||||
... )
|
||||
int SampleUtil_Print(char *fmt, ...)
|
||||
{
|
||||
#define MAX_BUF 1024
|
||||
va_list ap;
|
||||
char buf[200];
|
||||
static char buf[MAX_BUF];
|
||||
int rc;
|
||||
|
||||
va_start( ap, fmt );
|
||||
rc = vsnprintf( buf, 200, fmt, ap );
|
||||
va_end( ap );
|
||||
/* Protect both the display and the static buffer with the mutex */
|
||||
ithread_mutex_lock(&display_mutex);
|
||||
va_start(ap, fmt);
|
||||
rc = vsnprintf(buf, MAX_BUF, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
ithread_mutex_lock( &display_mutex );
|
||||
if( gPrintFun )
|
||||
gPrintFun( buf );
|
||||
ithread_mutex_unlock( &display_mutex );
|
||||
if (gPrintFun) {
|
||||
gPrintFun(buf);
|
||||
}
|
||||
ithread_mutex_unlock(&display_mutex);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ int SampleUtil_PrintEvent(IN Upnp_EventType EventType,
|
||||
********************************************************************************/
|
||||
int SampleUtil_FindAndParseService (
|
||||
IN IXML_Document *DescDoc,
|
||||
IN char* location,
|
||||
IN const char *location,
|
||||
IN char *serviceType,
|
||||
OUT char **serviceId,
|
||||
OUT char **eventURL,
|
||||
|
@ -1,40 +1,47 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define DEFAULT_WEB_DIR "./web"
|
||||
|
||||
|
||||
#define DESC_URL_SIZE 200
|
||||
|
||||
|
||||
/*
|
||||
Device type for tv device
|
||||
*/
|
||||
@ -178,7 +185,6 @@ SetServiceTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return SetActionTable( serviceType, out );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -249,7 +255,6 @@ SetActionTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -372,10 +377,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
{
|
||||
unsigned int i = 0; //,j=0;
|
||||
|
||||
// IXML_Document *PropSet=NULL;
|
||||
// IXML_Document *PropSet = NULL;
|
||||
|
||||
//lock state mutex
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
// lock state mutex
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
|
||||
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
|
||||
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) &&
|
||||
@ -383,44 +388,48 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
== 0 ) ) {
|
||||
|
||||
/*
|
||||
PropSet = NULL;
|
||||
PropSet = NULL;
|
||||
|
||||
for (j=0; j< tv_service_table[i].VariableCount; j++)
|
||||
{
|
||||
//add each variable to the property set
|
||||
//for initial state dump
|
||||
UpnpAddToPropertySet(&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
|
||||
// add each variable to the property set
|
||||
// for initial state dump
|
||||
UpnpAddToPropertySet(
|
||||
&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
|
||||
//dump initial state
|
||||
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,sr_event->Sid);
|
||||
//free document
|
||||
Document_free(PropSet);
|
||||
// dump initial state
|
||||
UpnpAcceptSubscriptionExt(
|
||||
device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,
|
||||
sr_event->Sid);
|
||||
// free document
|
||||
Document_free(PropSet);
|
||||
|
||||
*/
|
||||
|
||||
UpnpAcceptSubscription( device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
( const char ** )tv_service_table[i].
|
||||
VariableName,
|
||||
( const char ** )tv_service_table[i].
|
||||
VariableStrVal,
|
||||
tv_service_table[i].VariableCount,
|
||||
sr_event->Sid );
|
||||
UpnpAcceptSubscription( device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
(const char **)tv_service_table[i].
|
||||
VariableName,
|
||||
(const char **)tv_service_table[i].
|
||||
VariableStrVal,
|
||||
tv_service_table[i].VariableCount,
|
||||
sr_event->Sid);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* TvDeviceHandleGetVarRequest
|
||||
*
|
||||
@ -437,8 +446,8 @@ int
|
||||
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
*cgv_event )
|
||||
{
|
||||
unsigned int i = 0,
|
||||
j = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
cgv_event->CurrentVal = NULL;
|
||||
@ -446,12 +455,12 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
|
||||
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 )
|
||||
&&
|
||||
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId )
|
||||
== 0 ) ) {
|
||||
//check variable name
|
||||
// check variable name
|
||||
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
|
||||
if( strcmp( cgv_event->StateVarName,
|
||||
tv_service_table[i].VariableName[j] ) == 0 ) {
|
||||
@ -496,7 +505,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
int
|
||||
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
{
|
||||
|
||||
/*
|
||||
Defaults if action not found
|
||||
*/
|
||||
@ -549,7 +557,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
ActionRequest,
|
||||
&ca_event->
|
||||
ActionResult,
|
||||
&errorString );
|
||||
&errorString );
|
||||
} else {
|
||||
errorString = "Power is Off";
|
||||
retCode = UPNP_E_INTERNAL_ERROR;
|
||||
@ -567,7 +575,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
if( retCode == UPNP_E_SUCCESS ) {
|
||||
ca_event->ErrCode = UPNP_E_SUCCESS;
|
||||
} else {
|
||||
//copy the error string
|
||||
// copy the error string
|
||||
strcpy( ca_event->ErrStr, errorString );
|
||||
switch ( retCode ) {
|
||||
case UPNP_E_INVALID_PARAM:
|
||||
@ -649,7 +657,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -672,7 +679,7 @@ TvDeviceSetPower( IN int on )
|
||||
|
||||
if( on != POWER_ON && on != POWER_OFF ) {
|
||||
SampleUtil_Print( "error: can't set power to value %d\n", on );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -683,7 +690,7 @@ TvDeviceSetPower( IN int on )
|
||||
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
|
||||
value );
|
||||
|
||||
return ( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -700,9 +707,7 @@ TvDeviceSetPower( IN int on )
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOn( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = NULL;
|
||||
@ -722,7 +727,6 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -740,7 +744,7 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOff( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT IXML_Document **out,
|
||||
OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
@ -779,11 +783,8 @@ TvDevicePowerOff( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int channel = 0;
|
||||
@ -828,7 +829,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -846,13 +846,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementChannel( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curchannel,
|
||||
newchannel;
|
||||
int curchannel;
|
||||
int newchannel;
|
||||
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
@ -914,12 +911,9 @@ IncrementChannel( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -936,12 +930,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -960,13 +951,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int volume = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1007,7 +994,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1026,10 +1012,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementVolume( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curvolume,
|
||||
newvolume;
|
||||
@ -1066,8 +1049,7 @@ IncrementVolume( IN int incr,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
if( UpnpAddToActionResponse( out, actionName,
|
||||
TvServiceType[TV_SERVICE_CONTROL],
|
||||
"Volume", value ) != UPNP_E_SUCCESS )
|
||||
{
|
||||
"Volume", value ) != UPNP_E_SUCCESS ) {
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
@ -1077,7 +1059,6 @@ IncrementVolume( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1094,13 +1075,9 @@ IncrementVolume( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1117,13 +1094,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1142,13 +1115,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int color = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1188,7 +1157,6 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1205,16 +1173,11 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
* IXML_Document **out - action result document
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
IncrementColor( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcolor,
|
||||
newcolor;
|
||||
|
||||
int curcolor;
|
||||
int newcolor;
|
||||
char *actionName;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1272,11 +1235,8 @@ IncrementColor( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1293,11 +1253,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1317,13 +1274,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int tint = -1;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1382,14 +1335,10 @@ TvDeviceSetTint( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementTint( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curtint,
|
||||
newtint;
|
||||
|
||||
int curtint;
|
||||
int newtint;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1432,7 +1381,6 @@ IncrementTint( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1449,11 +1397,8 @@ IncrementTint( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1471,11 +1416,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1495,11 +1437,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
****************************************************************************/
|
||||
int
|
||||
TvDeviceSetContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int contrast = -1;
|
||||
|
||||
@ -1560,14 +1499,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementContrast( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcontrast,
|
||||
newcontrast;
|
||||
|
||||
int curcontrast;
|
||||
int newcontrast;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1629,11 +1564,8 @@ IncrementContrast( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementContrast( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1651,9 +1583,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
IXML_Document ** out,
|
||||
char **errorString )
|
||||
TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementContrast( -1, in, out, errorString );
|
||||
}
|
||||
@ -1671,11 +1601,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int brightness = -1;
|
||||
|
||||
@ -1718,7 +1645,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1736,13 +1662,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementBrightness( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curbrightness,
|
||||
newbrightness;
|
||||
int curbrightness;
|
||||
int newbrightness;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1803,9 +1726,7 @@ IncrementBrightness( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( 1, in, out, errorString );
|
||||
}
|
||||
@ -1823,9 +1744,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( -1, in, out, errorString );
|
||||
}
|
||||
@ -1849,14 +1768,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
* Cookie -- Optional data specified during callback registration
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
void *Event,
|
||||
void *Cookie )
|
||||
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
|
||||
{
|
||||
|
||||
switch ( EventType ) {
|
||||
|
||||
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
|
||||
|
||||
TvDeviceHandleSubscriptionRequest( ( struct
|
||||
@ -1890,17 +1804,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print
|
||||
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
}
|
||||
|
||||
/*
|
||||
Print a summary of the event received
|
||||
*/
|
||||
/* Print a summary of the event received */
|
||||
SampleUtil_PrintEvent( EventType, Event );
|
||||
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1919,6 +1830,7 @@ TvDeviceStop()
|
||||
UpnpFinish();
|
||||
SampleUtil_Finish();
|
||||
ithread_mutex_destroy( &TVDevMutex );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1951,7 +1863,6 @@ TvDeviceStart( char *ip_address,
|
||||
print_string pfun )
|
||||
{
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
|
||||
char desc_doc_url[DESC_URL_SIZE];
|
||||
|
||||
ithread_mutex_init( &TVDevMutex, NULL );
|
||||
@ -1963,19 +1874,15 @@ TvDeviceStart( char *ip_address,
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address, port );
|
||||
|
||||
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) {
|
||||
ret = UpnpInit( ip_address, port );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
|
||||
UpnpFinish();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if( ip_address == NULL ) {
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
}
|
||||
|
||||
if( port == 0 ) {
|
||||
port = UpnpGetServerPort();
|
||||
}
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
port = UpnpGetServerPort();
|
||||
|
||||
SampleUtil_Print(
|
||||
"UPnP Initialized\n"
|
||||
@ -1995,12 +1902,12 @@ TvDeviceStart( char *ip_address,
|
||||
|
||||
SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
|
||||
web_dir_path );
|
||||
if( ( ret =
|
||||
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error specifying webserver root directory -- %s: %d\n",
|
||||
ret = UpnpSetWebServerRootDir( web_dir_path );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
|
||||
web_dir_path, ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2009,12 +1916,12 @@ TvDeviceStart( char *ip_address,
|
||||
"\t with desc_doc_url: %s\n",
|
||||
desc_doc_url );
|
||||
|
||||
if( ( ret = UpnpRegisterRootDevice( desc_doc_url,
|
||||
TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
SampleUtil_Print(
|
||||
@ -2022,17 +1929,17 @@ TvDeviceStart( char *ip_address,
|
||||
"Initializing State Table\n");
|
||||
TvDeviceStateTableInit( desc_doc_url );
|
||||
SampleUtil_Print("State Table Initialized\n");
|
||||
|
||||
if( ( ret =
|
||||
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error sending advertisements : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Advertisements Sent\n");
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,40 +1,47 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "upnp_tv_device.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define DEFAULT_WEB_DIR "./web"
|
||||
|
||||
|
||||
#define DESC_URL_SIZE 200
|
||||
|
||||
|
||||
/*
|
||||
Device type for tv device
|
||||
*/
|
||||
@ -180,7 +187,6 @@ SetServiceTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return SetActionTable( serviceType, out );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -251,7 +257,6 @@ SetActionTable( IN int serviceType,
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -374,10 +379,10 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
{
|
||||
unsigned int i = 0; //,j=0;
|
||||
|
||||
// IXML_Document *PropSet=NULL;
|
||||
// IXML_Document *PropSet = NULL;
|
||||
|
||||
//lock state mutex
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
// lock state mutex
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
|
||||
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
|
||||
if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) &&
|
||||
@ -385,44 +390,48 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
|
||||
== 0 ) ) {
|
||||
|
||||
/*
|
||||
PropSet = NULL;
|
||||
PropSet = NULL;
|
||||
|
||||
for (j=0; j< tv_service_table[i].VariableCount; j++)
|
||||
{
|
||||
//add each variable to the property set
|
||||
//for initial state dump
|
||||
UpnpAddToPropertySet(&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
|
||||
// add each variable to the property set
|
||||
// for initial state dump
|
||||
UpnpAddToPropertySet(
|
||||
&PropSet,
|
||||
tv_service_table[i].VariableName[j],
|
||||
tv_service_table[i].VariableStrVal[j]);
|
||||
}
|
||||
|
||||
//dump initial state
|
||||
UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,sr_event->Sid);
|
||||
//free document
|
||||
Document_free(PropSet);
|
||||
// dump initial state
|
||||
UpnpAcceptSubscriptionExt(
|
||||
device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
PropSet,
|
||||
sr_event->Sid);
|
||||
// free document
|
||||
Document_free(PropSet);
|
||||
|
||||
*/
|
||||
|
||||
UpnpAcceptSubscription( device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
( const char ** )tv_service_table[i].
|
||||
VariableName,
|
||||
( const char ** )tv_service_table[i].
|
||||
VariableStrVal,
|
||||
tv_service_table[i].VariableCount,
|
||||
sr_event->Sid );
|
||||
UpnpAcceptSubscription( device_handle,
|
||||
sr_event->UDN,
|
||||
sr_event->ServiceId,
|
||||
(const char **)tv_service_table[i].
|
||||
VariableName,
|
||||
(const char **)tv_service_table[i].
|
||||
VariableStrVal,
|
||||
tv_service_table[i].VariableCount,
|
||||
sr_event->Sid);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* TvDeviceHandleGetVarRequest
|
||||
*
|
||||
@ -439,8 +448,8 @@ int
|
||||
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
*cgv_event )
|
||||
{
|
||||
unsigned int i = 0,
|
||||
j = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
int getvar_succeeded = 0;
|
||||
|
||||
cgv_event->CurrentVal = NULL;
|
||||
@ -448,12 +457,12 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
ithread_mutex_lock( &TVDevMutex );
|
||||
|
||||
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 )
|
||||
&&
|
||||
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId )
|
||||
== 0 ) ) {
|
||||
//check variable name
|
||||
// check variable name
|
||||
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
|
||||
if( strcmp( cgv_event->StateVarName,
|
||||
tv_service_table[i].VariableName[j] ) == 0 ) {
|
||||
@ -498,7 +507,6 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
|
||||
int
|
||||
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
{
|
||||
|
||||
/*
|
||||
Defaults if action not found
|
||||
*/
|
||||
@ -551,7 +559,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
ActionRequest,
|
||||
&ca_event->
|
||||
ActionResult,
|
||||
&errorString );
|
||||
&errorString );
|
||||
} else {
|
||||
errorString = "Power is Off";
|
||||
retCode = UPNP_E_INTERNAL_ERROR;
|
||||
@ -569,7 +577,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
|
||||
if( retCode == UPNP_E_SUCCESS ) {
|
||||
ca_event->ErrCode = UPNP_E_SUCCESS;
|
||||
} else {
|
||||
//copy the error string
|
||||
// copy the error string
|
||||
strcpy( ca_event->ErrStr, errorString );
|
||||
switch ( retCode ) {
|
||||
case UPNP_E_INVALID_PARAM:
|
||||
@ -651,7 +659,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
|
||||
ithread_mutex_unlock( &TVDevMutex );
|
||||
|
||||
return ( 1 );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -674,7 +681,7 @@ TvDeviceSetPower( IN int on )
|
||||
|
||||
if( on != POWER_ON && on != POWER_OFF ) {
|
||||
SampleUtil_Print( "error: can't set power to value %d\n", on );
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -685,7 +692,7 @@ TvDeviceSetPower( IN int on )
|
||||
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
|
||||
value );
|
||||
|
||||
return ( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -702,9 +709,7 @@ TvDeviceSetPower( IN int on )
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOn( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = NULL;
|
||||
@ -724,7 +729,6 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -742,7 +746,7 @@ TvDevicePowerOn( IN IXML_Document * in,
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDevicePowerOff( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT IXML_Document **out,
|
||||
OUT char **errorString )
|
||||
{
|
||||
( *out ) = NULL;
|
||||
@ -781,11 +785,8 @@ TvDevicePowerOff( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int channel = 0;
|
||||
@ -830,7 +831,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -848,13 +848,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementChannel( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curchannel,
|
||||
newchannel;
|
||||
int curchannel;
|
||||
int newchannel;
|
||||
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
@ -916,12 +913,9 @@ IncrementChannel( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -938,12 +932,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementChannel( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -962,13 +953,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int volume = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1009,7 +996,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1028,10 +1014,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementVolume( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curvolume,
|
||||
newvolume;
|
||||
@ -1068,8 +1051,7 @@ IncrementVolume( IN int incr,
|
||||
TV_CONTROL_VOLUME, value ) ) {
|
||||
if( UpnpAddToActionResponse( out, actionName,
|
||||
TvServiceType[TV_SERVICE_CONTROL],
|
||||
"Volume", value ) != UPNP_E_SUCCESS )
|
||||
{
|
||||
"Volume", value ) != UPNP_E_SUCCESS ) {
|
||||
( *out ) = NULL;
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
@ -1079,7 +1061,6 @@ IncrementVolume( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1096,13 +1077,9 @@ IncrementVolume( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( 1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1119,13 +1096,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementVolume( -1, in, out, errorString );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1144,13 +1117,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int color = 0;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1190,7 +1159,6 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1207,16 +1175,11 @@ TvDeviceSetColor( IN IXML_Document * in,
|
||||
* IXML_Document **out - action result document
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
|
||||
int
|
||||
IncrementColor( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcolor,
|
||||
newcolor;
|
||||
|
||||
int curcolor;
|
||||
int newcolor;
|
||||
char *actionName;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1274,11 +1237,8 @@ IncrementColor( IN int incr,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1295,11 +1255,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementColor( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1319,13 +1276,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
|
||||
int tint = -1;
|
||||
|
||||
( *out ) = NULL;
|
||||
@ -1384,14 +1337,10 @@ TvDeviceSetTint( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementTint( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curtint,
|
||||
newtint;
|
||||
|
||||
int curtint;
|
||||
int newtint;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1434,7 +1383,6 @@ IncrementTint( IN int incr,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1451,11 +1399,8 @@ IncrementTint( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1473,11 +1418,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementTint( -1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1497,11 +1439,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
|
||||
*
|
||||
****************************************************************************/
|
||||
int
|
||||
TvDeviceSetContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int contrast = -1;
|
||||
|
||||
@ -1562,14 +1501,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementContrast( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curcontrast,
|
||||
newcontrast;
|
||||
|
||||
int curcontrast;
|
||||
int newcontrast;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1631,11 +1566,8 @@ IncrementContrast( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
return IncrementContrast( 1, in, out, errorString );
|
||||
}
|
||||
|
||||
@ -1653,9 +1585,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
IXML_Document ** out,
|
||||
char **errorString )
|
||||
TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementContrast( -1, in, out, errorString );
|
||||
}
|
||||
@ -1673,11 +1603,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
|
||||
char *value = NULL;
|
||||
int brightness = -1;
|
||||
|
||||
@ -1720,7 +1647,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
( *errorString ) = "Internal Error";
|
||||
return UPNP_E_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1738,13 +1664,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
|
||||
* char **errorString - errorString (in case action was unsuccessful)
|
||||
*****************************************************************************/
|
||||
int
|
||||
IncrementBrightness( IN int incr,
|
||||
IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
int curbrightness,
|
||||
newbrightness;
|
||||
int curbrightness;
|
||||
int newbrightness;
|
||||
char *actionName = NULL;
|
||||
char value[TV_MAX_VAL_LEN];
|
||||
|
||||
@ -1805,9 +1728,7 @@ IncrementBrightness( IN int incr,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( 1, in, out, errorString );
|
||||
}
|
||||
@ -1825,9 +1746,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
OUT IXML_Document ** out,
|
||||
OUT char **errorString )
|
||||
TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
|
||||
{
|
||||
return IncrementBrightness( -1, in, out, errorString );
|
||||
}
|
||||
@ -1851,14 +1770,9 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
|
||||
* Cookie -- Optional data specified during callback registration
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
void *Event,
|
||||
void *Cookie )
|
||||
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
|
||||
{
|
||||
|
||||
switch ( EventType ) {
|
||||
|
||||
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
|
||||
|
||||
TvDeviceHandleSubscriptionRequest( ( struct
|
||||
@ -1892,17 +1806,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
|
||||
break;
|
||||
|
||||
default:
|
||||
SampleUtil_Print
|
||||
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
|
||||
EventType );
|
||||
}
|
||||
|
||||
/*
|
||||
Print a summary of the event received
|
||||
*/
|
||||
/* Print a summary of the event received */
|
||||
SampleUtil_PrintEvent( EventType, Event );
|
||||
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -1921,6 +1832,7 @@ TvDeviceStop()
|
||||
UpnpFinish();
|
||||
SampleUtil_Finish();
|
||||
ithread_mutex_destroy( &TVDevMutex );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1953,7 +1865,6 @@ TvDeviceStart( char *ip_address,
|
||||
print_string pfun )
|
||||
{
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
|
||||
char desc_doc_url[DESC_URL_SIZE];
|
||||
|
||||
ithread_mutex_init( &TVDevMutex, NULL );
|
||||
@ -1965,16 +1876,14 @@ TvDeviceStart( char *ip_address,
|
||||
"\tipaddress = %s port = %u\n",
|
||||
ip_address, port );
|
||||
|
||||
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) {
|
||||
ret = UpnpInit( ip_address, port );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
|
||||
UpnpFinish();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if( ip_address == NULL ) {
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
}
|
||||
|
||||
ip_address = UpnpGetServerIpAddress();
|
||||
port = UpnpGetServerPort();
|
||||
|
||||
SampleUtil_Print(
|
||||
@ -1995,12 +1904,12 @@ TvDeviceStart( char *ip_address,
|
||||
|
||||
SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
|
||||
web_dir_path );
|
||||
if( ( ret =
|
||||
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print
|
||||
( "Error specifying webserver root directory -- %s: %d\n",
|
||||
ret = UpnpSetWebServerRootDir( web_dir_path );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
|
||||
web_dir_path, ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2009,12 +1918,12 @@ TvDeviceStart( char *ip_address,
|
||||
"\t with desc_doc_url: %s\n",
|
||||
desc_doc_url );
|
||||
|
||||
if( ( ret = UpnpRegisterRootDevice( desc_doc_url,
|
||||
TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
|
||||
&device_handle, &device_handle );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
SampleUtil_Print(
|
||||
@ -2022,17 +1931,17 @@ TvDeviceStart( char *ip_address,
|
||||
"Initializing State Table\n");
|
||||
TvDeviceStateTableInit( desc_doc_url );
|
||||
SampleUtil_Print("State Table Initialized\n");
|
||||
|
||||
if( ( ret =
|
||||
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
|
||||
!= UPNP_E_SUCCESS ) {
|
||||
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
|
||||
if( ret != UPNP_E_SUCCESS ) {
|
||||
SampleUtil_Print( "Error sending advertisements : %d\n", ret );
|
||||
UpnpFinish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SampleUtil_Print("Advertisements Sent\n");
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*******************************************************************************
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
@ -6,12 +6,12 @@
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither name of Intel Corporation nor the names of its contributors
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
@ -27,564 +27,437 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#if EXCLUDE_DOM == 0
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "upnp.h"
|
||||
#include "upnptools.h"
|
||||
|
||||
|
||||
#include "uri.h"
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/*! Maximum action header buffer length. */
|
||||
#define HEADER_LENGTH 2000
|
||||
|
||||
// Structure to maintain a error code and string associated with the
|
||||
// error code
|
||||
|
||||
/*!
|
||||
* \brief Structure to maintain a error code and string associated with the
|
||||
* error code.
|
||||
*/
|
||||
struct ErrorString {
|
||||
int rc; /* error code */
|
||||
const char *rcError; /* error description */
|
||||
|
||||
/*! Error code. */
|
||||
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"},
|
||||
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
|
||||
{UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"},
|
||||
{UPNP_E_OUTOF_CONTEXT, "UPNP_E_OUTOF_CONTEXT"},
|
||||
{UPNP_E_OUTOF_MEMORY, "UPNP_E_OUTOF_MEMOR"},
|
||||
{UPNP_E_INIT, "UPNP_E_INIT"},
|
||||
{UPNP_E_BUFFER_TOO_SMALL, "UPNP_E_BUFFER_TOO_SMALL"},
|
||||
{UPNP_E_INVALID_DESC, "UPNP_E_INVALID_DESC"},
|
||||
{UPNP_E_INVALID_URL, "UPNP_E_INVALID_URL"},
|
||||
{UPNP_E_INVALID_SID, "UPNP_E_INVALID_SID"},
|
||||
{UPNP_E_INVALID_DEVICE, "UPNP_E_INVALID_DEVICE"},
|
||||
{UPNP_E_INVALID_SERVICE, "UPNP_E_INVALID_SERVICE"},
|
||||
{UPNP_E_BAD_RESPONSE, "UPNP_E_BAD_RESPONSE"},
|
||||
{UPNP_E_BAD_REQUEST, "UPNP_E_BAD_REQUEST"},
|
||||
{UPNP_E_INVALID_ACTION, "UPNP_E_INVALID_ACTION"},
|
||||
{UPNP_E_FINISH, "UPNP_E_FINISH"},
|
||||
{UPNP_E_INIT_FAILED, "UPNP_E_INIT_FAILED"},
|
||||
{UPNP_E_BAD_HTTPMSG, "UPNP_E_BAD_HTTPMSG"},
|
||||
{UPNP_E_NETWORK_ERROR, "UPNP_E_NETWORK_ERROR"},
|
||||
{UPNP_E_SOCKET_WRITE, "UPNP_E_SOCKET_WRITE"},
|
||||
{UPNP_E_SOCKET_READ, "UPNP_E_SOCKET_READ"},
|
||||
{UPNP_E_SOCKET_BIND, "UPNP_E_SOCKET_BIND"},
|
||||
{UPNP_E_SOCKET_CONNECT, "UPNP_E_SOCKET_CONNECT"},
|
||||
{UPNP_E_OUTOF_SOCKET, "UPNP_E_OUTOF_SOCKET"},
|
||||
{UPNP_E_LISTEN, "UPNP_E_LISTEN"},
|
||||
{UPNP_E_EVENT_PROTOCOL, "UPNP_E_EVENT_PROTOCOL"},
|
||||
{UPNP_E_SUBSCRIBE_UNACCEPTED, "UPNP_E_SUBSCRIBE_UNACCEPTED"},
|
||||
{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"}
|
||||
|
||||
/*!
|
||||
* \brief Array of error structures.
|
||||
*/
|
||||
struct ErrorString ErrorMessages[] = {
|
||||
{UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
||||
{UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
|
||||
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
|
||||
{UPNP_E_OUTOF_HANDLE, "UPNP_E_OUTOF_HANDLE"},
|
||||
{UPNP_E_OUTOF_CONTEXT, "UPNP_E_OUTOF_CONTEXT"},
|
||||
{UPNP_E_OUTOF_MEMORY, "UPNP_E_OUTOF_MEMOR"},
|
||||
{UPNP_E_INIT, "UPNP_E_INIT"},
|
||||
{UPNP_E_BUFFER_TOO_SMALL, "UPNP_E_BUFFER_TOO_SMALL"},
|
||||
{UPNP_E_INVALID_DESC, "UPNP_E_INVALID_DESC"},
|
||||
{UPNP_E_INVALID_URL, "UPNP_E_INVALID_URL"},
|
||||
{UPNP_E_INVALID_SID, "UPNP_E_INVALID_SID"},
|
||||
{UPNP_E_INVALID_DEVICE, "UPNP_E_INVALID_DEVICE"},
|
||||
{UPNP_E_INVALID_SERVICE, "UPNP_E_INVALID_SERVICE"},
|
||||
{UPNP_E_BAD_RESPONSE, "UPNP_E_BAD_RESPONSE"},
|
||||
{UPNP_E_BAD_REQUEST, "UPNP_E_BAD_REQUEST"},
|
||||
{UPNP_E_INVALID_ACTION, "UPNP_E_INVALID_ACTION"},
|
||||
{UPNP_E_FINISH, "UPNP_E_FINISH"},
|
||||
{UPNP_E_INIT_FAILED, "UPNP_E_INIT_FAILED"},
|
||||
{UPNP_E_BAD_HTTPMSG, "UPNP_E_BAD_HTTPMSG"},
|
||||
{UPNP_E_NETWORK_ERROR, "UPNP_E_NETWORK_ERROR"},
|
||||
{UPNP_E_SOCKET_WRITE, "UPNP_E_SOCKET_WRITE"},
|
||||
{UPNP_E_SOCKET_READ, "UPNP_E_SOCKET_READ"},
|
||||
{UPNP_E_SOCKET_BIND, "UPNP_E_SOCKET_BIND"},
|
||||
{UPNP_E_SOCKET_CONNECT, "UPNP_E_SOCKET_CONNECT"},
|
||||
{UPNP_E_OUTOF_SOCKET, "UPNP_E_OUTOF_SOCKET"},
|
||||
{UPNP_E_LISTEN, "UPNP_E_LISTEN"},
|
||||
{UPNP_E_EVENT_PROTOCOL, "UPNP_E_EVENT_PROTOCOL"},
|
||||
{UPNP_E_SUBSCRIBE_UNACCEPTED, "UPNP_E_SUBSCRIBE_UNACCEPTED"},
|
||||
{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
|
||||
*
|
||||
* Parameters:
|
||||
* IN int rc: error code
|
||||
*
|
||||
* Description:
|
||||
* This functions returns the error string mapped to the error code
|
||||
* Returns: const char *
|
||||
* return either the right string or "Unknown Error"
|
||||
***************************************************************************/
|
||||
const char *
|
||||
UpnpGetErrorMessage( IN int rc )
|
||||
|
||||
const char *UpnpGetErrorMessage(int rc)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < sizeof( ErrorMessages ) / sizeof( ErrorMessages[0] );
|
||||
i++ ) {
|
||||
if( rc == ErrorMessages[i].rc )
|
||||
return ErrorMessages[i].rcError;
|
||||
|
||||
}
|
||||
|
||||
return "Unknown Error";
|
||||
for (i = 0; i < sizeof (ErrorMessages) / sizeof (ErrorMessages[0]); ++i) {
|
||||
if (rc == ErrorMessages[i].rc) {
|
||||
return ErrorMessages[i].rcError;
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown error code";
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpResolveURL
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * BaseURL: Base URL string
|
||||
* IN char * RelURL: relative URL string
|
||||
* OUT char * AbsURL: Absolute URL string
|
||||
* Description:
|
||||
* This functions concatinates the base URL and relative URL to generate
|
||||
* the absolute URL
|
||||
* Returns: int
|
||||
* return either UPNP_E_SUCCESS or appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpResolveURL( IN const char *BaseURL,
|
||||
IN const char *RelURL,
|
||||
OUT char *AbsURL )
|
||||
|
||||
/*!
|
||||
* \todo There is some unnecessary allocation and deallocation going on here
|
||||
* because of the way resolve_rel_url() was originally written and used. In the
|
||||
* future it would be nice to clean this up.
|
||||
*/
|
||||
int UpnpResolveURL(
|
||||
const char *BaseURL,
|
||||
const char *RelURL,
|
||||
char *AbsURL)
|
||||
{
|
||||
// There is some unnecessary allocation and
|
||||
// deallocation going on here because of the way
|
||||
// resolve_rel_url was originally written and used
|
||||
// in the future it would be nice to clean this up
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
char *tempRel = NULL;
|
||||
|
||||
char *tempRel;
|
||||
if (RelURL == NULL) {
|
||||
ret = UPNP_E_INVALID_PARAM;
|
||||
goto ExitFunction;
|
||||
}
|
||||
|
||||
if( RelURL == NULL )
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
|
||||
tempRel = NULL;
|
||||
|
||||
tempRel = resolve_rel_url((char*) BaseURL, (char*) RelURL );
|
||||
|
||||
if( tempRel ) {
|
||||
strcpy( AbsURL, tempRel );
|
||||
free( tempRel );
|
||||
} else {
|
||||
return UPNP_E_INVALID_URL;
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL);
|
||||
if (tempRel) {
|
||||
strcpy(AbsURL, tempRel);
|
||||
free(tempRel);
|
||||
} else {
|
||||
ret = UPNP_E_INVALID_URL;
|
||||
}
|
||||
|
||||
ExitFunction:
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : addToAction
|
||||
*
|
||||
* Parameters:
|
||||
* IN int response: flag to tell if the ActionDoc is for response
|
||||
* or request
|
||||
* INOUT IXML_Document **ActionDoc: request or response document
|
||||
* IN char *ActionName: Name of the action request or response
|
||||
* IN char *ServType: Service type
|
||||
* IN char * ArgName: Name of the argument
|
||||
* IN char * ArgValue: Value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the action request or response.
|
||||
* This function creates the action request or response if it is a first
|
||||
* argument else it will add the argument in the document
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful else returns appropriate error
|
||||
***************************************************************************/
|
||||
static int
|
||||
addToAction( IN int response,
|
||||
INOUT IXML_Document ** ActionDoc,
|
||||
IN const char *ActionName,
|
||||
IN const char *ServType,
|
||||
IN const char *ArgName,
|
||||
IN const char *ArgValue )
|
||||
|
||||
/*!
|
||||
* \brief Adds the argument in the action request or response.
|
||||
*
|
||||
* This function creates the action request or response if it is a first
|
||||
* argument, otherwise it will add the argument in the document.
|
||||
*
|
||||
* \returns UPNP_E_SUCCESS if successful, otherwise the appropriate error.
|
||||
*/
|
||||
static int addToAction(
|
||||
/*! [in] flag to tell if the ActionDoc is for response or request. */
|
||||
int response,
|
||||
/*! [in,out] Request or response document. */
|
||||
IXML_Document **ActionDoc,
|
||||
/*! [in] Name of the action request or response. */
|
||||
const char *ActionName,
|
||||
/*! [in] Service type. */
|
||||
const char *ServType,
|
||||
/*! [in] Name of the argument. */
|
||||
const char *ArgName,
|
||||
/*! [in] Value of the argument. */
|
||||
const char *ArgValue)
|
||||
{
|
||||
char *ActBuff = NULL;
|
||||
IXML_Node *node = NULL;
|
||||
IXML_Element *Ele = NULL;
|
||||
IXML_Node *Txt = NULL;
|
||||
int rc = 0;
|
||||
char *ActBuff = NULL;
|
||||
IXML_Node *node = NULL;
|
||||
IXML_Element *Ele = NULL;
|
||||
IXML_Node *Txt = NULL;
|
||||
int rc = 0;
|
||||
|
||||
if( ActionName == NULL || ServType == NULL ) {
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
if (ActionName == NULL || ServType == NULL) {
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if( *ActionDoc == NULL ) {
|
||||
ActBuff = ( char * )malloc( HEADER_LENGTH );
|
||||
if( ActBuff == NULL ) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
if (*ActionDoc == NULL) {
|
||||
ActBuff = (char *)malloc(HEADER_LENGTH);
|
||||
if (ActBuff == NULL) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
if( response ) {
|
||||
sprintf( ActBuff,
|
||||
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
|
||||
ActionName, ServType, ActionName );
|
||||
} else {
|
||||
sprintf( ActBuff,
|
||||
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
|
||||
ActionName, ServType, ActionName );
|
||||
}
|
||||
if (response) {
|
||||
sprintf(ActBuff,
|
||||
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
|
||||
ActionName, ServType, ActionName);
|
||||
} else {
|
||||
sprintf(ActBuff,
|
||||
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
|
||||
ActionName, ServType, ActionName);
|
||||
}
|
||||
|
||||
rc = ixmlParseBufferEx( ActBuff, ActionDoc );
|
||||
free( ActBuff );
|
||||
if( rc != IXML_SUCCESS ) {
|
||||
if( rc == IXML_INSUFFICIENT_MEMORY ) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
} else {
|
||||
return UPNP_E_INVALID_DESC;
|
||||
}
|
||||
}
|
||||
}
|
||||
rc = ixmlParseBufferEx(ActBuff, ActionDoc);
|
||||
free(ActBuff);
|
||||
if (rc != IXML_SUCCESS) {
|
||||
if (rc == IXML_INSUFFICIENT_MEMORY) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
} else {
|
||||
return UPNP_E_INVALID_DESC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ArgName != NULL /*&& ArgValue != 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 );
|
||||
}
|
||||
if (ArgName != NULL /*&& ArgValue != 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);
|
||||
}
|
||||
|
||||
ixmlNode_appendChild( node, ( IXML_Node * ) Ele );
|
||||
}
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : makeAction
|
||||
*
|
||||
* Parameters:
|
||||
* IN int response: flag to tell if the ActionDoc is for response
|
||||
* or request
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action request or response from the argument
|
||||
* list.
|
||||
* Returns: IXML_Document *
|
||||
* returns action request or response document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
static IXML_Document *
|
||||
makeAction( IN int response,
|
||||
IN const char *ActionName,
|
||||
IN const char *ServType,
|
||||
IN int NumArg,
|
||||
IN const char *Arg,
|
||||
IN va_list ArgList )
|
||||
|
||||
/*!
|
||||
* \brief Creates the action request or response from the argument list.
|
||||
*
|
||||
* \return Action request or response document if successful, otherwise
|
||||
* returns NULL
|
||||
*/
|
||||
static IXML_Document *makeAction(
|
||||
/*! [in] flag to tell if the ActionDoc is for response or request. */
|
||||
int response,
|
||||
/*! [in] Name of the action request or response. */
|
||||
const char *ActionName,
|
||||
/*! [in] Service type. */
|
||||
const char *ServType,
|
||||
/*! [in] Number of arguments in the action request or response. */
|
||||
int NumArg,
|
||||
/*! [in] pointer to the first argument. */
|
||||
const char *Arg,
|
||||
/*! [in] Argument list. */
|
||||
va_list ArgList)
|
||||
{
|
||||
const char *ArgName;
|
||||
const char *ArgValue;
|
||||
char *ActBuff;
|
||||
int Idx = 0;
|
||||
IXML_Document *ActionDoc;
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Node *Txt = NULL;
|
||||
const char *ArgName;
|
||||
const char *ArgValue;
|
||||
char *ActBuff;
|
||||
int Idx = 0;
|
||||
IXML_Document *ActionDoc;
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Node *Txt = NULL;
|
||||
|
||||
if( ActionName == NULL || ServType == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
if (ActionName == NULL || ServType == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ActBuff = ( char * )malloc( HEADER_LENGTH );
|
||||
if( ActBuff == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
ActBuff = (char *)malloc(HEADER_LENGTH);
|
||||
if (ActBuff == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( response ) {
|
||||
sprintf( ActBuff,
|
||||
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
|
||||
ActionName, ServType, ActionName );
|
||||
} else {
|
||||
sprintf( ActBuff,
|
||||
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
|
||||
ActionName, ServType, ActionName );
|
||||
}
|
||||
if (response) {
|
||||
sprintf(ActBuff,
|
||||
"<u:%sResponse xmlns:u=\"%s\">\r\n</u:%sResponse>",
|
||||
ActionName, ServType, ActionName);
|
||||
} else {
|
||||
sprintf(ActBuff,
|
||||
"<u:%s xmlns:u=\"%s\">\r\n</u:%s>",
|
||||
ActionName, ServType, ActionName);
|
||||
}
|
||||
if (ixmlParseBufferEx(ActBuff, &ActionDoc) != IXML_SUCCESS) {
|
||||
free(ActBuff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( ixmlParseBufferEx( ActBuff, &ActionDoc ) != IXML_SUCCESS ) {
|
||||
free( ActBuff );
|
||||
return NULL;
|
||||
}
|
||||
free(ActBuff);
|
||||
if(ActionDoc == 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 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;
|
||||
return ActionDoc;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpMakeAction
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN ... : variable argument list
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action request from the argument
|
||||
* list. Its a wrapper function that calls makeAction function to create
|
||||
* the action request.
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns action request document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpMakeAction( const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
... )
|
||||
|
||||
IXML_Document *UpnpMakeAction(
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
...)
|
||||
{
|
||||
va_list ArgList;
|
||||
IXML_Document *out = NULL;
|
||||
va_list ArgList;
|
||||
IXML_Document *out = NULL;
|
||||
|
||||
va_start( ArgList, Arg );
|
||||
out = makeAction( 0, ActionName, ServType, NumArg, Arg, ArgList );
|
||||
va_end( ArgList );
|
||||
va_start(ArgList, Arg);
|
||||
out = makeAction(0, ActionName, ServType, NumArg, Arg, ArgList);
|
||||
va_end(ArgList);
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpMakeActionResponse
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int NumArg :Number of arguments in the action request or response
|
||||
* IN char * Arg : pointer to the first argument
|
||||
* IN ... : variable argument list
|
||||
* IN va_list ArgList: Argument list
|
||||
*
|
||||
* Description:
|
||||
* This function creates the action response from the argument
|
||||
* list. Its a wrapper function that calls makeAction function to create
|
||||
* the action response.
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns action response document if successful
|
||||
* else returns NULL
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpMakeActionResponse( const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
... )
|
||||
|
||||
IXML_Document *UpnpMakeActionResponse(
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
...)
|
||||
{
|
||||
va_list ArgList;
|
||||
IXML_Document *out = NULL;
|
||||
va_list ArgList;
|
||||
IXML_Document *out = NULL;
|
||||
|
||||
va_start( ArgList, Arg );
|
||||
out = makeAction( 1, ActionName, ServType, NumArg, Arg, ArgList );
|
||||
va_end( ArgList );
|
||||
va_start(ArgList, Arg);
|
||||
out = makeAction(1, ActionName, ServType, NumArg, Arg, ArgList);
|
||||
va_end(ArgList);
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToActionResponse
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **ActionResponse: action response document
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int ArgName :Name of argument to be added in the action response
|
||||
* IN char * ArgValue : value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the action response. Its a wrapper
|
||||
* function that calls addToAction function to add the argument in the
|
||||
* action response.
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful
|
||||
* else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToActionResponse( INOUT IXML_Document ** ActionResponse,
|
||||
IN const char *ActionName,
|
||||
IN const char *ServType,
|
||||
IN const char *ArgName,
|
||||
IN const char *ArgValue )
|
||||
|
||||
int UpnpAddToAction(
|
||||
IXML_Document **ActionDoc,
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
const char *ArgName,
|
||||
const char *ArgValue)
|
||||
{
|
||||
return addToAction( 1, ActionResponse, ActionName, ServType, ArgName,
|
||||
ArgValue );
|
||||
return addToAction(0, ActionDoc, ActionName, ServType, ArgName, ArgValue);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToAction
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **ActionDoc: action request document
|
||||
* IN char * ActionName: Name of the action request or response
|
||||
* IN char * ServType: Service type
|
||||
* IN int ArgName :Name of argument to be added in the action response
|
||||
* IN char * ArgValue : value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the action request. Its a wrapper
|
||||
* function that calls addToAction function to add the argument in the
|
||||
* action request.
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful
|
||||
* else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToAction( IXML_Document ** ActionDoc,
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
const char *ArgName,
|
||||
const char *ArgValue )
|
||||
{
|
||||
|
||||
return addToAction( 0, ActionDoc, ActionName, ServType, ArgName,
|
||||
ArgValue );
|
||||
int UpnpAddToActionResponse(
|
||||
IXML_Document **ActionResponse,
|
||||
const char *ActionName,
|
||||
const char *ServType,
|
||||
const char *ArgName,
|
||||
const char *ArgValue)
|
||||
{
|
||||
return addToAction(1, ActionResponse, ActionName, ServType, ArgName, ArgValue);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpAddToPropertySet
|
||||
*
|
||||
* Parameters:
|
||||
* INOUT IXML_Document **PropSet: propertyset document
|
||||
* IN char *ArgName: Name of the argument
|
||||
* IN char *ArgValue: value of the argument
|
||||
*
|
||||
* Description:
|
||||
* This function adds the argument in the propertyset node
|
||||
*
|
||||
* Returns: int
|
||||
* returns UPNP_E_SUCCESS if successful else returns appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
UpnpAddToPropertySet( INOUT IXML_Document ** PropSet,
|
||||
IN const char *ArgName,
|
||||
IN const char *ArgValue )
|
||||
|
||||
IXML_Document *UpnpCreatePropertySet(
|
||||
int NumArg,
|
||||
const char *Arg,
|
||||
...)
|
||||
{
|
||||
va_list ArgList;
|
||||
int Idx = 0;
|
||||
char BlankDoc[] =
|
||||
"<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"
|
||||
"</e:propertyset>";
|
||||
const char *ArgName,
|
||||
*ArgValue;
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
IXML_Node *Txt;
|
||||
IXML_Document *PropSet;
|
||||
|
||||
char BlankDoc[] = "<e:propertyset xmlns:e=\"urn:schemas"
|
||||
"-upnp-org:event-1-0\"></e:propertyset>";
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
IXML_Node *Txt;
|
||||
int rc;
|
||||
if(ixmlParseBufferEx(BlankDoc, &PropSet) != IXML_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( ArgName == NULL ) {
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
if (NumArg < 1) {
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
if( *PropSet == NULL ) {
|
||||
rc = ixmlParseBufferEx( BlankDoc, PropSet );
|
||||
if( rc != IXML_SUCCESS ) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
}
|
||||
va_start(ArgList, Arg);
|
||||
ArgName = Arg;
|
||||
while (Idx++ != NumArg) {
|
||||
ArgValue = va_arg(ArgList, const char *);
|
||||
if (ArgName != NULL /*&& ArgValue != NULL */) {
|
||||
node = ixmlNode_getFirstChild((IXML_Node *)PropSet);
|
||||
Ele1 = ixmlDocument_createElement(PropSet, "e:property");
|
||||
Ele = ixmlDocument_createElement(PropSet, ArgName);
|
||||
if (ArgValue) {
|
||||
Txt = ixmlDocument_createTextNode(PropSet, ArgValue);
|
||||
ixmlNode_appendChild((IXML_Node *)Ele, Txt);
|
||||
}
|
||||
ixmlNode_appendChild((IXML_Node *)Ele1, (IXML_Node *)Ele);
|
||||
ixmlNode_appendChild( node, (IXML_Node *)Ele1);
|
||||
}
|
||||
ArgName = va_arg(ArgList, const char *);
|
||||
}
|
||||
va_end(ArgList);
|
||||
|
||||
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 );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
return PropSet;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : UpnpCreatePropertySet
|
||||
*
|
||||
* Parameters:
|
||||
* IN int NumArg: Number of argument that will go in the propertyset node
|
||||
* IN char * Args: argument strings
|
||||
*
|
||||
* Description:
|
||||
* This function creates a propertyset node and put all the input
|
||||
* parameters in the node as elements
|
||||
*
|
||||
* Returns: IXML_Document *
|
||||
* returns the document containing propertyset node.
|
||||
***************************************************************************/
|
||||
IXML_Document *
|
||||
UpnpCreatePropertySet( IN int NumArg,
|
||||
IN const char *Arg,
|
||||
... )
|
||||
|
||||
int UpnpAddToPropertySet(
|
||||
IXML_Document **PropSet,
|
||||
const char *ArgName,
|
||||
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-upnp-org:event-1-0\">"
|
||||
"</e:propertyset>";
|
||||
IXML_Node *node;
|
||||
IXML_Element *Ele;
|
||||
IXML_Element *Ele1;
|
||||
IXML_Node *Txt;
|
||||
int rc;
|
||||
|
||||
if( ixmlParseBufferEx( BlankDoc, &PropSet ) != IXML_SUCCESS ) {
|
||||
return NULL;
|
||||
}
|
||||
if (ArgName == NULL) {
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (NumArg < 1) {
|
||||
return PropSet;
|
||||
}
|
||||
if (*PropSet == NULL) {
|
||||
rc = ixmlParseBufferEx(BlankDoc, PropSet);
|
||||
if (rc != IXML_SUCCESS) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
va_start( ArgList, Arg );
|
||||
ArgName = Arg;
|
||||
node = ixmlNode_getFirstChild((IXML_Node *)*PropSet);
|
||||
|
||||
while( Idx++ != NumArg ) {
|
||||
ArgValue = va_arg( ArgList, const char * );
|
||||
Ele1 = ixmlDocument_createElement(*PropSet, "e:property");
|
||||
Ele = ixmlDocument_createElement(*PropSet, ArgName);
|
||||
|
||||
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 );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
ixmlNode_appendChild((IXML_Node *)Ele1, (IXML_Node *)Ele);
|
||||
ixmlNode_appendChild(node, (IXML_Node *)Ele1);
|
||||
|
||||
ArgName = va_arg( ArgList, const char * );
|
||||
|
||||
}
|
||||
va_end( ArgList );
|
||||
return PropSet;
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
#endif // EXCLUDE_DOM == 0
|
||||
|
||||
#endif /* EXCLUDE_DOM == 0 */
|
||||
|
||||
|
@ -1,43 +1,48 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Purpose: This file contains functions for copying strings based on
|
||||
* different options.
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "upnp.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : linecopy
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user