diff --git a/ixml/inc/ixml.h b/ixml/inc/ixml.h index 26f942b..97abb0a 100644 --- a/ixml/inc/ixml.h +++ b/ixml/inc/ixml.h @@ -273,7 +273,7 @@ extern "C" { * \return A constant \b DOMString of the node name. */ EXPORT_SPEC const DOMString ixmlNode_getNodeName( - /*! Pointer to the node to retrieve the name. */ + /*! [in] Pointer to the node to retrieve the name. */ IXML_Node *nodeptr); @@ -457,7 +457,7 @@ ixmlNode_getPrefix( * \c NULL. */ EXPORT_SPEC const DOMString ixmlNode_getLocalName( - /*! The \b Node from which to retrieve the local name. */ + /*! [in] The \b Node from which to retrieve the local name. */ IXML_Node *nodeptr); /*! @@ -1111,7 +1111,7 @@ EXPORT_SPEC int ixmlDocument_importNode( * \brief Initializes a \b IXML_Element node. */ EXPORT_SPEC void ixmlElement_init( - /*! The \b Element to initialize.*/ + /*! [in] The \b Element to initialize.*/ IXML_Element *element); @@ -1121,27 +1121,29 @@ EXPORT_SPEC void ixmlElement_init( * \return The name of the \b Element. */ EXPORT_SPEC const DOMString ixmlElement_getTagName( - /*! The \b Element from which to retrieve the name. */ + /*! [in] The \b Element from which to retrieve the name. */ IXML_Element *element); /*! * \brief Retrieves an attribute of an \b Element by name. * - * \return The value of the attribute. + * \return The value of the attribute, or \b NULL if that attribute +* does not have a specified value. */ EXPORT_SPEC const DOMString ixmlElement_getAttribute( - /*! The \b Element from which to retrieve the attribute. */ + /*! [in] The \b Element from which to retrieve the attribute. */ IXML_Element* element, - /*! The name of the attribute to retrieve. */ + /*! [in] The name of the attribute to retrieve. */ const DOMString name); /*! * \brief Adds a new attribute to an \b Element. * - * If an attribute with the same name already exists, the attribute value will - * be updated with the new value in \b value. + * If an attribute with the same name already exists in the element, the + * attribute value will be updated with the new value parameter. Otherwise, + * a new attribute is inserted into the element. * * \return An integer representing of the following: * \li \c IXML_SUCCESS: The operation completed successfully. @@ -1163,7 +1165,7 @@ EXPORT_SPEC int ixmlElement_setAttribute( /*! - * \brief Removes an attribute by name. + * \brief Removes an attribute value by name. The attribute node is not removed. * * \return An integer representing one of the following: * \li \c IXML_SUCCESS: The operation completed successfully. @@ -1182,7 +1184,8 @@ EXPORT_SPEC int ixmlElement_removeAttribute( * See \b ixmlElement_getAttributeNodeNS to retrieve an attribute node using * a qualified name or namespace URI. * - * \return A pointer to the attribute matching \b name or \c NULL on an error. + * \return A pointer to the attribute matching \b name or \c NULL on if there + * is no such attribute. */ EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNode( /*! [in] The \b Element from which to get the attribute node. */ @@ -1191,11 +1194,15 @@ EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNode( const DOMString name); -/*!Adds a new attribute node to an \b Element. If an attribute already - * exists with \b newAttr as a name, it will be replaced with the - * new one and the old one will be returned in \b rtAttr. +/*! + * \brief Adds a new attribute node to an \b Element. * - * \return An integer representing one of the following: + * If an attribute already exists with \b newAttr as a name, it will be + * replaced with the new one and the old one will be returned in \b rtAttr. + * + * \return If successfull, the replaced attribute node is returned in rtAttr, + * otherwise, \b NULL is returned in this pointer. The function return value + * is an integer representing one of the following: * \li \c IXML_SUCCESS: The operation completed successfully. * \li \c IXML_INVALID_PARAMETER: Either \b element or * \b newAttr is \c NULL. @@ -1205,11 +1212,11 @@ EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNode( * an attribute of another \b Element. */ EXPORT_SPEC int ixmlElement_setAttributeNode( - /*! The \b Element in which to add the new attribute. */ + /*! [in] The \b Element in which to add the new attribute. */ IXML_Element *element, - /*! The new \b Attr to add. */ + /*! [in] The new \b Attr to add. */ IXML_Attr* newAttr, - /*! A pointer to an \b Attr where the old \b Attr will be stored. + /*! [out] A pointer to an \b Attr where the old \b Attr will be stored. * This will have a \c NULL if no prior node existed. */ IXML_Attr** rtAttr); @@ -1225,11 +1232,11 @@ EXPORT_SPEC int ixmlElement_setAttributeNode( * attributes of \b element. */ EXPORT_SPEC int ixmlElement_removeAttributeNode( - /*! The \b Element from which to remove the attribute. */ + /*! [in] The \b Element from which to remove the attribute. */ IXML_Element *element, - /*! The attribute to remove from the \b Element. */ + /*! [in] The attribute to remove from the \b Element. */ IXML_Attr* oldAttr, - /*! A pointer to an attribute in which to place the removed attribute. */ + /*! [out] A pointer to an attribute in which to place the removed attribute. */ IXML_Attr** rtAttr); @@ -1255,14 +1262,15 @@ EXPORT_SPEC IXML_NodeList *ixmlElement_getElementsByTagName( /*! * \brief Retrieves an attribute value using the local name and namespace URI. * - * \return A \b DOMString representing the value of the matching attribute. + * \return A \b DOMString representing the value of the matching attribute, or + * \b NULL if that attribute does not have the specified value. */ EXPORT_SPEC const DOMString ixmlElement_getAttributeNS( - /*! The \b Element from which to get the attribute value. */ + /*! [in] The \b Element from which to get the attribute value. */ IXML_Element *element, - /*! The namespace URI of the attribute. */ + /*! [in] The namespace URI of the attribute. */ const DOMString namespaceURI, - /*! The local name of the attribute. */ + /*! [in] The local name of the attribute. */ const DOMString localname); @@ -1289,55 +1297,63 @@ EXPORT_SPEC const DOMString ixmlElement_getAttributeNS( * \li \c IXML_FAILED: The operation could not be completed. */ EXPORT_SPEC int ixmlElement_setAttributeNS( - /*! The \b Element on which to set the attribute. */ + /*! [in] The \b Element on which to set the attribute. */ IXML_Element *element, - /*! The namespace URI of the new attribute. */ + /*! [in] The namespace URI of the new attribute. */ const DOMString namespaceURI, - /*! The qualified name of the attribute. */ + /*! [in] The qualified name of the attribute. */ const DOMString qualifiedName, - /*! The new value for the attribute. */ + /*! [in] The new value for the attribute. */ const DOMString value); /*! * \brief Removes an attribute using the namespace URI and local name. * + * The replacing attribute has the same namespace URI and local name, as well + * as the original prefix. + * * \return An integer representing one of the following: * \li \c IXML_SUCCESS: The operation completed successfully. * \li \c IXML_INVALID_PARAMETER: Either \b element, * \b namespaceURI, or \b localName is \c NULL. */ EXPORT_SPEC int ixmlElement_removeAttributeNS( - /*! The \b Element from which to remove the the attribute. */ + /*! [in] The \b Element from which to remove the the attribute. */ IXML_Element *element, - /*! The namespace URI of the attribute. */ + /*! [in] The namespace URI of the attribute. */ const DOMString namespaceURI, - /*! The local name of the attribute.*/ + /*! [in] The local name of the attribute.*/ const DOMString localName); /*! * \brief Retrieves an \b Attr node by local name and namespace URI. * - * \return A pointer to an \b Attr or \c NULL on an error. + * \return A pointer to an \b Attribute node with the specified attribute + * local name and namespace URI or \c NULL if there is no such attribute. */ EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNodeNS( - /*! The \b Element from which to get the attribute. */ + /*! [in] The \b Element from which to get the attribute. */ IXML_Element *element, - /*! The namespace URI of the attribute. */ + /*! [in] The namespace URI of the attribute. */ const DOMString namespaceURI, - /*! The local name of the attribute. */ + /*! [in] The local name of the attribute. */ const DOMString localName); /*! - * \brief Adds a new attribute node. + * \brief Adds a new attribute node to the element node specified. * * If an attribute with the same local name and namespace URI already exists in * the \b Element, the existing attribute node is replaced with \b newAttr and * the old returned in \b rcAttr. * - * \return An integer representing one of the following: + * \return The output parameter rcAttr receives the replaced attribute node if + * the newAttr attribute replaces an existing attribute with the same local name + * and namespace, otherwise rcAttr receives \b NULL. + * + * The function return value is an integer representing one of the following: * \li \c IXML_SUCCESS: The operation completed successfully. * \li \c IXML_INVALID_PARAMETER: Either \b element or * \b newAttr is \c NULL. @@ -1347,27 +1363,29 @@ EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNodeNS( * attribute of another \b Element. */ EXPORT_SPEC int ixmlElement_setAttributeNodeNS( - /*! The \b Element in which to add the attribute node. */ + /*! [in] The \b Element in which to add the attribute node. */ IXML_Element *element, - /*! The new \b Attr to add. */ + /*! [in] The new \b Attr to add. */ IXML_Attr *newAttr, - /*! A pointer to the replaced \b Attr, if it exists. */ + /*! [out] A pointer to the replaced \b Attr, if it exists. */ IXML_Attr **rcAttr); /*! * \brief Returns a \b NodeList of all \em descendant \b Elements with a - * given tag name, in the order in which they are encountered in the - * pre-order traversal of the \b Element tree. + * given local name and namespace in the order in which they are encountered in + * the pre-order traversal of the \b Element tree. * * \return A \b NodeList of matching \b Elements or \c NULL on an error. */ EXPORT_SPEC IXML_NodeList *ixmlElement_getElementsByTagNameNS( - /*! The \b Element from which to start the search. */ + /*! [in] The \b Element from which to start the search. */ IXML_Element *element, - /*! The namespace URI of the \b Elements to find. */ + /*! [in] The namespace URI of the \b Elements to find. The special value + * "*" matches all namespaces. */ const DOMString namespaceURI, - /*! The local name of the \b Elements to find. */ + /*! [in] The local name of the \b Elements to find. The special value "*" + * matches all local names. */ const DOMString localName); @@ -1379,9 +1397,9 @@ EXPORT_SPEC IXML_NodeList *ixmlElement_getElementsByTagNameNS( * default value for that attribute, otherwise \c FALSE. */ EXPORT_SPEC BOOL ixmlElement_hasAttribute( - /*! The \b Element on which to check for an attribute. */ + /*! [in] The \b Element on which to check for an attribute. */ IXML_Element *element, - /*! The name of the attribute for which to check. */ + /*! [in] The name of the attribute for which to check. */ const DOMString name); @@ -1393,11 +1411,11 @@ EXPORT_SPEC BOOL ixmlElement_hasAttribute( * and local name or has a default value for that attribute, otherwise \c FALSE. */ EXPORT_SPEC BOOL ixmlElement_hasAttributeNS( - /*! The \b Element on which to check for the attribute. */ + /*! [in] The \b Element on which to check for the attribute. */ IXML_Element *element, - /*! The namespace URI of the attribute. */ + /*! [in] The namespace URI of the attribute. */ const DOMString namespaceURI, - /*! The local name of the attribute. */ + /*! [in] The local name of the attribute. */ const DOMString localName); @@ -1405,7 +1423,7 @@ EXPORT_SPEC BOOL ixmlElement_hasAttributeNS( * \brief Frees the given \b Element and any subtree of the \b Element. */ EXPORT_SPEC void ixmlElement_free( - /*! The \b Element to free. */ + /*! [in] The \b Element to free. */ IXML_Element *element); @@ -1431,14 +1449,15 @@ EXPORT_SPEC void ixmlElement_free( * \return The number of nodes in this map. */ EXPORT_SPEC unsigned long ixmlNamedNodeMap_getLength( - /*! The \b NamedNodeMap from which to retrieve the size. */ + /*! [in] The \b NamedNodeMap from which to retrieve the size. */ IXML_NamedNodeMap *nnMap); /*! * \brief Retrieves a \b Node from the \b NamedNodeMap by name. * - * \return A \b Node or \c NULL if there is an error. + * \return A Node with the specified nodeName, or \b NULL if it + * does not identify any node in this map. */ EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_getNamedItem( /*! [in] The \b NamedNodeMap to search. */ @@ -1474,15 +1493,16 @@ EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_removeNamedItem( /*! - * \brief Retrieves a \b Node from a \b NamedNodeMap specified by a numerical - * index. + * \brief Retrieves the indexth item in the map. If index is greater than or + * equal to the number of nodes in this map, this returns \b NULL. * - * \return A pointer to the \b Node, if found, or \c NULL if it wasn't. + * \return The node at the indexth position in the map, or \b NULL if that is + * not a valid index. */ EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_item( - /*! The \b NamedNodeMap from which to remove the \b Node. */ + /*! [in] The \b NamedNodeMap from which to remove the \b Node. */ IXML_NamedNodeMap *nnMap, - /*! The index into the map to remove. */ + /*! [in] The index into the map to remove. */ unsigned long index); @@ -1540,7 +1560,7 @@ EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_removeNamedItemNS( * The \b Nodes inside the map are not freed, just the \b NamedNodeMap object. */ EXPORT_SPEC void ixmlNamedNodeMap_free( - /*! The \b NamedNodeMap to free. */ + /*! [in] The \b NamedNodeMap to free. */ IXML_NamedNodeMap *nnMap); @@ -1567,9 +1587,9 @@ EXPORT_SPEC void ixmlNamedNodeMap_free( * \return A pointer to a \b Node or \c NULL if there was an error. */ EXPORT_SPEC IXML_Node *ixmlNodeList_item( - /*! The \b NodeList from which to retrieve the \b Node. */ + /*! [in] The \b NodeList from which to retrieve the \b Node. */ IXML_NodeList *nList, - /*! The index into the \b NodeList to retrieve. */ + /*! [in] The index into the \b NodeList to retrieve. */ unsigned long index); @@ -1579,7 +1599,7 @@ EXPORT_SPEC IXML_Node *ixmlNodeList_item( * \return The number of \b Nodes in the \b NodeList. */ EXPORT_SPEC unsigned long ixmlNodeList_length( - /*! The \b NodeList for which to retrieve the number of \b Nodes. */ + /*! [in] The \b NodeList for which to retrieve the number of \b Nodes. */ IXML_NodeList *nList); @@ -1590,7 +1610,7 @@ EXPORT_SPEC unsigned long ixmlNodeList_length( * operation. This only frees the \b NodeList object. */ EXPORT_SPEC void ixmlNodeList_free( - /*! The \b NodeList to free. */ + /*! [in] The \b NodeList to free. */ IXML_NodeList *nList); diff --git a/ixml/inc/ixmldebug.h b/ixml/inc/ixmldebug.h index ffe076d..17406fb 100644 --- a/ixml/inc/ixmldebug.h +++ b/ixml/inc/ixmldebug.h @@ -9,13 +9,15 @@ /*! * \file + * + * \brief Auxiliar routines to aid debugging. */ /*! * \brief Prints the debug statement either on the standard output or log file * along with the information from where this debug statement is coming. - **/ + */ #ifdef DEBUG void IxmlPrintf( /*! [in] Printf like format specification. */ diff --git a/ixml/src/element.c b/ixml/src/element.c index b13c37e..8ec0614 100644 --- a/ixml/src/element.c +++ b/ixml/src/element.c @@ -30,6 +30,11 @@ ******************************************************************************/ +/*! + * \file + */ + + #include "ixmlparser.h" @@ -37,939 +42,675 @@ #include -/*================================================================ -* ixmlElement_Init -* Initializes an element node. -* External function. -* -*=================================================================*/ -void -ixmlElement_init( IN IXML_Element * element ) +void ixmlElement_init(IXML_Element *element) { - if( element != NULL ) { - memset( element, 0, sizeof( IXML_Element ) ); - } + if (element != NULL) { + memset(element, 0, sizeof (IXML_Element)); + } } -/*================================================================ -* ixmlElement_getTagName -* Gets the element node's tagName -* External function. -* -*=================================================================*/ -const DOMString -ixmlElement_getTagName( IN IXML_Element * element ) +const DOMString ixmlElement_getTagName(IXML_Element *element) { - - if( element != NULL ) { - return element->tagName; - } else { - return NULL; - } + if( element != NULL ) { + return element->tagName; + } else { + return NULL; + } } -/*================================================================ -* ixmlElement_setTagName -* Sets the given element's tagName. -* Parameters: -* tagName: new tagName for the element. -* -*=================================================================*/ -int -ixmlElement_setTagName( IN IXML_Element * element, - IN const char *tagName ) + +int ixmlElement_setTagName(IXML_Element *element, const char *tagName) { - int rc = IXML_SUCCESS; + int rc = IXML_SUCCESS; - assert( ( element != NULL ) && ( tagName != NULL ) ); - if( ( element == NULL ) || ( tagName == NULL ) ) { - return IXML_FAILED; - } + assert(element != NULL && tagName != NULL); - if( element->tagName != NULL ) { - free( element->tagName ); - } + if (element == NULL || tagName == NULL) { + return IXML_FAILED; + } - element->tagName = strdup( tagName ); - if( element->tagName == NULL ) { - rc = IXML_INSUFFICIENT_MEMORY; - } - - return rc; + if (element->tagName != NULL) { + free(element->tagName); + } + element->tagName = strdup(tagName); + if (element->tagName == NULL) { + rc = IXML_INSUFFICIENT_MEMORY; + } + return rc; } -/*================================================================ -* ixmlElement_getAttribute -* Retrievea an attribute value by name. -* External function. -* Parameters: -* name: the name of the attribute to retrieve. -* Return Values: -* attribute value as a string, or the empty string if that attribute -* does not have a specified value. -* -*=================================================================*/ -const DOMString -ixmlElement_getAttribute( IN IXML_Element * element, - IN const DOMString name ) + +const DOMString ixmlElement_getAttribute(IXML_Element *element, const DOMString name) { - IXML_Node *attrNode; + IXML_Node *attrNode; - if( ( element == NULL ) || ( name == NULL ) ) { - return NULL; - } + if (element == NULL || name == NULL) { + return NULL; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it - return attrNode->nodeValue; - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + return attrNode->nodeValue; + } else { + attrNode = attrNode->nextSibling; + } + } - return NULL; + return NULL; } -/*================================================================ -* ixmlElement_setAttribute -* Adds a new attribute. If an attribute with that name is already -* present in the element, its value is changed to be that of the value -* parameter. If not, a new attribute is inserted into the element. -* -* External function. -* Parameters: -* name: the name of the attribute to create or alter. -* value: value to set in string form -* Return Values: -* IXML_SUCCESS or failure code. -* -*=================================================================*/ -int -ixmlElement_setAttribute(IXML_Element *element, - const DOMString name, - const DOMString value) + +int ixmlElement_setAttribute( + IXML_Element *element, + const DOMString name, + const DOMString value) { - IXML_Node *attrNode; - IXML_Attr *newAttrNode; - short errCode = IXML_SUCCESS; + IXML_Node *attrNode; + IXML_Attr *newAttrNode; + short errCode = IXML_SUCCESS; - if( ( element == NULL ) || ( name == NULL ) || ( value == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + if (element == NULL || name == NULL || value == NULL) { + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - if( Parser_isValidXmlName( name ) == FALSE ) { - errCode = IXML_INVALID_CHARACTER_ERR; - goto ErrorHandler; - } + if (Parser_isValidXmlName(name) == FALSE) { + errCode = IXML_INVALID_CHARACTER_ERR; + goto ErrorHandler; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } - if( attrNode == NULL ) { // add a new attribute - errCode = - ixmlDocument_createAttributeEx( ( IXML_Document * ) element->n. - ownerDocument, name, - &newAttrNode ); - if( errCode != IXML_SUCCESS ) { - goto ErrorHandler; - } + if (attrNode == NULL) { + /* Add a new attribute */ + errCode = ixmlDocument_createAttributeEx( + (IXML_Document *)element->n.ownerDocument, name, &newAttrNode); + if (errCode != IXML_SUCCESS) { + goto ErrorHandler; + } - attrNode = ( IXML_Node * ) newAttrNode; + attrNode = (IXML_Node *)newAttrNode; + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + ixmlAttr_free(newAttrNode); + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - ixmlAttr_free( newAttrNode ); - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + errCode = ixmlElement_setAttributeNode(element, newAttrNode, NULL); + if (errCode != IXML_SUCCESS) { + ixmlAttr_free(newAttrNode); + goto ErrorHandler; + } + } else { + if (attrNode->nodeValue != NULL) { + /* Attribute name has a value already */ + free(attrNode->nodeValue); + } + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + } + } - errCode = - ixmlElement_setAttributeNode( element, newAttrNode, NULL ); - if( errCode != IXML_SUCCESS ) { - ixmlAttr_free( newAttrNode ); - goto ErrorHandler; - } - - } else { - if( attrNode->nodeValue != NULL ) { // attribute name has a value already - free( attrNode->nodeValue ); - } - - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - } - } - - ErrorHandler: - return errCode; +ErrorHandler: + return errCode; } -/*================================================================ -* ixmlElement_removeAttribute -* Removes an attribute value by name. The attribute node is -* not removed. -* External function. -* Parameters: -* name: the name of the attribute to remove. -* Return Values: -* IXML_SUCCESS or error code. -* -*=================================================================*/ -int -ixmlElement_removeAttribute(IXML_Element *element, - const DOMString name) + +int ixmlElement_removeAttribute(IXML_Element *element, const DOMString name) { + IXML_Node *attrNode; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return IXML_INVALID_PARAMETER; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + /* Has the attribute */ + if (attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + attrNode->nodeValue = NULL; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - if( attrNode != NULL ) { // has the attribute - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - attrNode->nodeValue = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getAttributeNode -* Retrieve an attribute node by name. -* External function. -* Parameters: -* name: the name(nodeName) of the attribute to retrieve. -* Return Value: -* The attr node with the specified name (nodeName) or NULL if -* there is no such attribute. -* -*=================================================================*/ -IXML_Attr * -ixmlElement_getAttributeNode(IXML_Element *element, - const DOMString name) + +IXML_Attr *ixmlElement_getAttributeNode(IXML_Element *element, const DOMString name) { + IXML_Node *attrNode; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return NULL; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return NULL; - } - - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it - break; - } else { - attrNode = attrNode->nextSibling; - } - } - - return ( IXML_Attr * ) attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { // found it + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return (IXML_Attr *)attrNode; } -/*================================================================ -* ixmlElement_setAttributeNode -* Adds a new attribute node. If an attribute with that name(nodeName) -* is already present in the element, it is replaced by the new one. -* External function. -* Parameters: -* The attr node to add to the attribute list. -* Return Value: -* if newAttr replaces an existing attribute, the replaced -* attr node is returned, otherwise NULL is returned. -* -*=================================================================*/ -int -ixmlElement_setAttributeNode( IN IXML_Element * element, - IN IXML_Attr * newAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_setAttributeNode( + IXML_Element *element, + IXML_Attr *newAttr, + IXML_Attr **rtAttr) { + IXML_Node *attrNode = NULL; + IXML_Node *node = NULL; + IXML_Node *nextAttr = NULL; + IXML_Node *prevAttr = NULL; + IXML_Node *preSib = NULL; + IXML_Node *nextSib = NULL; - IXML_Node *attrNode; - IXML_Node *node; - IXML_Node *nextAttr = NULL; - IXML_Node *prevAttr = NULL; - IXML_Node *preSib, - *nextSib; + if (element == NULL || newAttr == NULL) { + return IXML_INVALID_PARAMETER; + } - if( ( element == NULL ) || ( newAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (newAttr->n.ownerDocument != element->n.ownerDocument) { + return IXML_WRONG_DOCUMENT_ERR; + } - if( newAttr->n.ownerDocument != element->n.ownerDocument ) { - return IXML_WRONG_DOCUMENT_ERR; - } + if (newAttr->ownerElement != NULL) { + return IXML_INUSE_ATTRIBUTE_ERR; + } - if( newAttr->ownerElement != NULL ) { - return IXML_INUSE_ATTRIBUTE_ERR; - } + newAttr->ownerElement = element; + node = (IXML_Node *)newAttr; - newAttr->ownerElement = element; - node = ( IXML_Node * ) newAttr; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, node->nodeName) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, node->nodeName ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + if (attrNode != NULL) { + /* Already present, will replace by newAttr */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = node; + } + if (nextSib != NULL) { + nextSib->prevSibling = node; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = node; + } + if (rtAttr != NULL) { + *rtAttr = (IXML_Attr *)attrNode; + } + } else { + /* Add this attribute */ + if (element->n.firstAttr != NULL) { + prevAttr = element->n.firstAttr; + nextAttr = prevAttr->nextSibling; + while (nextAttr != NULL) { + prevAttr = nextAttr; + nextAttr = prevAttr->nextSibling; + } + prevAttr->nextSibling = node; + node->prevSibling = prevAttr; + } else { + /* This is the first attribute node */ + element->n.firstAttr = node; + node->prevSibling = NULL; + node->nextSibling = NULL; + } - if( attrNode != NULL ) // already present, will replace by newAttr - { - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; + if (rtAttr != NULL) { + *rtAttr = NULL; + } + } - if( preSib != NULL ) { - preSib->nextSibling = node; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = node; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = node; - } - - if( rtAttr != NULL ) { - *rtAttr = ( IXML_Attr * ) attrNode; - } - } else // add this attribute - { - if( element->n.firstAttr != NULL ) { - prevAttr = element->n.firstAttr; - nextAttr = prevAttr->nextSibling; - while( nextAttr != NULL ) { - prevAttr = nextAttr; - nextAttr = prevAttr->nextSibling; - } - prevAttr->nextSibling = node; - node->prevSibling = prevAttr; - } else // this is the first attribute node - { - element->n.firstAttr = node; - node->prevSibling = NULL; - node->nextSibling = NULL; - } - - if( rtAttr != NULL ) { - *rtAttr = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_findAttributeNode -* Find a attribute node whose contents are the same as the oldAttr. -* Internal only to parser. -* Parameter: -* oldAttr: the attribute node to match -* Return: -* if found it, the attribute node is returned, -* otherwise, return NULL. -* -*=================================================================*/ -IXML_Node * -ixmlElement_findAttributeNode( IN IXML_Element * element, - IN IXML_Attr * oldAttr ) +/*! + * \brief Find a attribute node whose contents are the same as the oldAttr. + * + * \return If found, the attribute node is returned, otherwise \b NULL is + * returned. + */ +static IXML_Node *ixmlElement_findAttributeNode( + /*! [in] The element to search for the attribute. */ + IXML_Element *element, + /*! [in] The attribute node to match. */ + IXML_Attr *oldAttr) { - IXML_Node *attrNode; - IXML_Node *oldAttrNode = ( IXML_Node * ) oldAttr; + IXML_Node *attrNode; + IXML_Node *oldAttrNode = (IXML_Node *)oldAttr; - assert( ( element != NULL ) && ( oldAttr != NULL ) ); + assert(element != NULL && oldAttr != NULL); - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { // parentNode, prevSib, nextSib and ownerDocument doesn't matter - if( ixmlNode_compare( attrNode, oldAttrNode ) == TRUE ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - return attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + /* parentNode, prevSib, nextSib and ownerDocument doesn't matter */ + if (ixmlNode_compare(attrNode, oldAttrNode) == TRUE) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return attrNode; } -/*================================================================ -* ixmlElement_removeAttributeNode -* Removes the specified attribute node. -* External function. -* -* Parameters: -* oldAttr: the attr node to remove from the attribute list. -* -* Return Value: -* IXML_SUCCESS or failure -* -*=================================================================*/ -int -ixmlElement_removeAttributeNode( IN IXML_Element * element, - IN IXML_Attr * oldAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_removeAttributeNode( + IXML_Element *element, + IXML_Attr *oldAttr, + IXML_Attr **rtAttr) { - IXML_Node *attrNode; - IXML_Node *preSib, - *nextSib; + IXML_Node *attrNode; + IXML_Node *preSib; + IXML_Node *nextSib; - if( ( element == NULL ) || ( oldAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } - - attrNode = ixmlElement_findAttributeNode( element, oldAttr ); - if( attrNode != NULL ) { // has the attribute - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; - - if( preSib != NULL ) { - preSib->nextSibling = nextSib; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = preSib; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = nextSib; - } - - /* ( IXML_Attr * ) */ attrNode->parentNode = NULL; - /* ( IXML_Attr * ) */ attrNode->prevSibling = NULL; - /* ( IXML_Attr * ) */ attrNode->nextSibling = NULL; - *rtAttr = ( IXML_Attr * ) attrNode; - return IXML_SUCCESS; - - } else { - return IXML_NOT_FOUND_ERR; - } + if(element == NULL || oldAttr == NULL) { + return IXML_INVALID_PARAMETER; + } + attrNode = ixmlElement_findAttributeNode( element, oldAttr ); + if (attrNode != NULL) { + /* Has the attribute */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = nextSib; + } + if (nextSib != NULL) { + nextSib->prevSibling = preSib; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = nextSib; + } + attrNode->parentNode = NULL; + attrNode->prevSibling = NULL; + attrNode->nextSibling = NULL; + *rtAttr = (IXML_Attr *)attrNode; + return IXML_SUCCESS; + } else { + return IXML_NOT_FOUND_ERR; + } } -/*================================================================ -* ixmlElement_getElementsByTagName -* Returns a nodeList of all descendant Elements with a given -* tag name, in the order in which they are encountered in a preorder -* traversal of this element tree. -* External function. -* -* Parameters: -* tagName: the name of the tag to match on. The special value "*" -* matches all tags. -* -* Return Value: -* a nodeList of matching element nodes. -* -*=================================================================*/ -IXML_NodeList * -ixmlElement_getElementsByTagName(IXML_Element *element, - const DOMString tagName) -{ - IXML_NodeList *returnNodeList = NULL; - if( ( element != NULL ) && ( tagName != NULL ) ) { - ixmlNode_getElementsByTagName( ( IXML_Node * ) element, tagName, - &returnNodeList ); - } - return returnNodeList; +IXML_NodeList *ixmlElement_getElementsByTagName( + IXML_Element *element, + const DOMString tagName) +{ + IXML_NodeList *returnNodeList = NULL; + + if (element != NULL && tagName != NULL) { + ixmlNode_getElementsByTagName( + (IXML_Node *)element, tagName, &returnNodeList); + } + return returnNodeList; } -/*================================================================ -* ixmlElement_getAttributeNS -* Retrieves an attribute value by local name and namespace URI. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to retrieve. -* localName: the local name of the attribute to retrieve. -* -* Return Value: -* the attr value as a string, or NULL if that attribute does -* not have the specified value. -* -*=================================================================*/ -const DOMString -ixmlElement_getAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +const DOMString ixmlElement_getAttributeNS( + IN IXML_Element *element, + IN const DOMString namespaceURI, + IN const DOMString localName) { - IXML_Node *attrNode; + IXML_Node *attrNode; - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return NULL; - } + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return NULL; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it - return attrNode->nodeValue; - } else { - attrNode = attrNode->nextSibling; - } - } - - return NULL; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + return attrNode->nodeValue; + } else { + attrNode = attrNode->nextSibling; + } + } + return NULL; } -/*================================================================ -* ixmlElement_setAttributeNS -* Adds a new attribute. If an attribute with the same local name -* and namespace URI is already present on the element, its prefix -* is changed to be the prefix part of the qualifiedName, and its -* value is changed to be the value parameter. This value is a -* simple string. -* External function. -* -* Parameter: -* namespaceURI: the namespace of the attribute to create or alter. -* qualifiedName: the qualified name of the attribute to create or alter. -* value: the value to set in string form. -* -* Return Value: -* IXML_SUCCESS or failure -* -*=================================================================*/ -int -ixmlElement_setAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName, - IN const DOMString value ) + +int ixmlElement_setAttributeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString qualifiedName, + const DOMString value) { - IXML_Node *attrNode = NULL; - IXML_Node newAttrNode; - IXML_Attr *newAttr; - int rc; + IXML_Node *attrNode = NULL; + IXML_Node newAttrNode; + IXML_Attr *newAttr; + int rc; - if( ( element == NULL ) || ( namespaceURI == NULL ) || - ( qualifiedName == NULL ) || ( value == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || namespaceURI == NULL || qualifiedName == NULL || + value == NULL) { + return IXML_INVALID_PARAMETER; + } - if( Parser_isValidXmlName( qualifiedName ) == FALSE ) { - return IXML_INVALID_CHARACTER_ERR; - } + if (Parser_isValidXmlName(qualifiedName) == FALSE) { + return IXML_INVALID_CHARACTER_ERR; + } - ixmlNode_init( &newAttrNode ); + ixmlNode_init(&newAttrNode); + newAttrNode.nodeName = strdup(qualifiedName); + if (newAttrNode.nodeName == NULL) { + return IXML_INSUFFICIENT_MEMORY; + } - newAttrNode.nodeName = strdup( qualifiedName ); - if( newAttrNode.nodeName == NULL ) { - return IXML_INSUFFICIENT_MEMORY; - } + rc = Parser_setNodePrefixAndLocalName(&newAttrNode); + if (rc != IXML_SUCCESS) { + Parser_freeNodeContent(&newAttrNode); + return rc; + } - rc = Parser_setNodePrefixAndLocalName( &newAttrNode ); - if( rc != IXML_SUCCESS ) { - Parser_freeNodeContent( &newAttrNode ); - return rc; - } - // see DOM 2 spec page 59 - if( ( newAttrNode.prefix != NULL && namespaceURI == NULL ) || - ( strcmp( newAttrNode.prefix, "xml" ) == 0 && - strcmp( namespaceURI, - "http://www.w3.org/XML/1998/namespace" ) != 0 ) - || ( strcmp( qualifiedName, "xmlns" ) == 0 - && strcmp( namespaceURI, - "http://www.w3.org/2000/xmlns/" ) != 0 ) ) { - Parser_freeNodeContent( &newAttrNode ); - return IXML_NAMESPACE_ERR; - } + /* see DOM 2 spec page 59 */ + if ((newAttrNode.prefix != NULL && namespaceURI == NULL) || + (strcmp(newAttrNode.prefix, "xml") == 0 && + strcmp(namespaceURI, "http://www.w3.org/XML/1998/namespace") != 0) || + (strcmp(qualifiedName, "xmlns") == 0 && + strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/") != 0)) { + Parser_freeNodeContent( &newAttrNode ); + return IXML_NAMESPACE_ERR; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, newAttrNode.localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, newAttrNode.localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + if (attrNode->prefix != NULL) { + /* Remove the old prefix */ + free(attrNode->prefix); + } + /* replace it with the new prefix */ + attrNode->prefix = strdup( newAttrNode.prefix ); + if (attrNode->prefix == NULL) { + Parser_freeNodeContent(&newAttrNode); + return IXML_INSUFFICIENT_MEMORY; + } - if( attrNode != NULL ) { - if( attrNode->prefix != NULL ) { - free( attrNode->prefix ); // remove the old prefix - } - // replace it with the new prefix - attrNode->prefix = strdup( newAttrNode.prefix ); - if( attrNode->prefix == NULL ) { - Parser_freeNodeContent( &newAttrNode ); - return IXML_INSUFFICIENT_MEMORY; - } + if (attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + } + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + free(attrNode->prefix); + Parser_freeNodeContent(&newAttrNode); + return IXML_INSUFFICIENT_MEMORY; + } + } else { + /* Add a new attribute */ + rc = ixmlDocument_createAttributeNSEx( + (IXML_Document *)element->n.ownerDocument, + namespaceURI, + qualifiedName, + &newAttr); + if (rc != IXML_SUCCESS) { + return rc; + } + newAttr->n.nodeValue = strdup(value); + if (newAttr->n.nodeValue == NULL) { + ixmlAttr_free(newAttr); + return IXML_INSUFFICIENT_MEMORY; + } + if (ixmlElement_setAttributeNodeNS(element, newAttr, NULL) != IXML_SUCCESS) { + ixmlAttr_free(newAttr); + return IXML_FAILED; + } + } + Parser_freeNodeContent(&newAttrNode); - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - } - - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - free( attrNode->prefix ); - Parser_freeNodeContent( &newAttrNode ); - return IXML_INSUFFICIENT_MEMORY; - } - - } else { - // add a new attribute - rc = ixmlDocument_createAttributeNSEx( ( IXML_Document * ) - element->n.ownerDocument, - namespaceURI, qualifiedName, - &newAttr ); - if( rc != IXML_SUCCESS ) { - return rc; - } - - newAttr->n.nodeValue = strdup( value ); - if( newAttr->n.nodeValue == NULL ) { - ixmlAttr_free( newAttr ); - return IXML_INSUFFICIENT_MEMORY; - } - - if( ixmlElement_setAttributeNodeNS( element, newAttr, NULL ) != - IXML_SUCCESS ) { - ixmlAttr_free( newAttr ); - return IXML_FAILED; - } - - } - - Parser_freeNodeContent( &newAttrNode ); - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_removeAttributeNS -* Removes an attribute by local name and namespace URI. The replacing -* attribute has the same namespace URI and local name, as well as -* the original prefix. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to remove. -* localName: the local name of the atribute to remove. -* -* Return Value: -* IXML_SUCCESS or failure. -* -*=================================================================*/ -int -ixmlElement_removeAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +int ixmlElement_removeAttributeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { - IXML_Node *attrNode; + IXML_Node *attrNode = NULL; - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return IXML_INVALID_PARAMETER; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - if( attrNode != NULL ) { // has the attribute - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - attrNode->nodeValue = NULL; - } - } - - return IXML_SUCCESS; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if(attrNode != NULL) { + /* Has the attribute */ + if(attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + attrNode->nodeValue = NULL; + } + } + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getAttributeNodeNS -* Retrieves an attr node by local name and namespace URI. -* External function. -* -* Parameter: -* namespaceURI: the namespace of the attribute to retrieve. -* localName: the local name of the attribute to retrieve. -* -* Return Value: -* The attr node with the specified attribute local name and -* namespace URI or null if there is no such attribute. -* -*=================================================================*/ -IXML_Attr * -ixmlElement_getAttributeNodeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +IXML_Attr *ixmlElement_getAttributeNodeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return NULL; + } - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return NULL; - } - - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it - break; - } else { - attrNode = attrNode->nextSibling; - } - } - - return ( IXML_Attr * ) attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + // found it + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return (IXML_Attr *)attrNode; } -/*================================================================ -* ixmlElement_setAttributeNodeNS -* Adds a new attribute. If an attribute with that local name and -* that namespace URI is already present in the element, it is replaced -* by the new one. -* External function. -* -* Parameter: -* newAttr: the attr node to add to the attribute list. -* -* Return Value: -* If the newAttr attribute replaces an existing attribute with the -* same local name and namespace, the replaced attr node is returned, -* otherwise null is returned. -* -*=================================================================*/ -int -ixmlElement_setAttributeNodeNS( IN IXML_Element * element, - IN IXML_Attr * newAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_setAttributeNodeNS( + IN IXML_Element *element, + IN IXML_Attr *newAttr, + OUT IXML_Attr **rtAttr) { - IXML_Node *attrNode; - IXML_Node *node; - IXML_Node *prevAttr = NULL, - *nextAttr = NULL; - IXML_Node *preSib, - *nextSib; + IXML_Node *attrNode = NULL; + IXML_Node *node = NULL; + IXML_Node *prevAttr = NULL; + IXML_Node *nextAttr = NULL; + IXML_Node *preSib = NULL; + IXML_Node *nextSib = NULL; - if( ( element == NULL ) || ( newAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || newAttr == NULL) { + return IXML_INVALID_PARAMETER; + } - if( newAttr->n.ownerDocument != element->n.ownerDocument ) { - return IXML_WRONG_DOCUMENT_ERR; - } + if (newAttr->n.ownerDocument != element->n.ownerDocument) { + return IXML_WRONG_DOCUMENT_ERR; + } - if( ( newAttr->ownerElement != NULL ) - && ( newAttr->ownerElement != element ) ) { - return IXML_INUSE_ATTRIBUTE_ERR; - } + if (newAttr->ownerElement != NULL && newAttr->ownerElement != element) { + return IXML_INUSE_ATTRIBUTE_ERR; + } - newAttr->ownerElement = element; - node = ( IXML_Node * ) newAttr; + newAttr->ownerElement = element; + node = (IXML_Node *)newAttr; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, node->localName) == 0 && + strcmp(attrNode->namespaceURI, node->namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + /* already present, will replace by newAttr */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = node; + } + if (nextSib != NULL) { + nextSib->prevSibling = node; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = node; + } + *rtAttr = (IXML_Attr *)attrNode; - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, node->localName ) == 0 && - strcmp( attrNode->namespaceURI, node->namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + } else { + /* Add this attribute */ + if (element->n.firstAttr != NULL) { + /* Element has attribute already */ + prevAttr = element->n.firstAttr; + nextAttr = prevAttr->nextSibling; + while (nextAttr != NULL) { + prevAttr = nextAttr; + nextAttr = prevAttr->nextSibling; + } + prevAttr->nextSibling = node; + } else { + /* This is the first attribute node */ + element->n.firstAttr = node; + node->prevSibling = NULL; + node->nextSibling = NULL; + } + if (rtAttr != NULL) { + *rtAttr = NULL; + } + } - if( attrNode != NULL ) // already present, will replace by newAttr - { - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; - - if( preSib != NULL ) { - preSib->nextSibling = node; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = node; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = node; - } - - *rtAttr = ( IXML_Attr * ) attrNode; - - } else // add this attribute - { - if( element->n.firstAttr != NULL ) // element has attribute already - { - prevAttr = element->n.firstAttr; - nextAttr = prevAttr->nextSibling; - while( nextAttr != NULL ) { - prevAttr = nextAttr; - nextAttr = prevAttr->nextSibling; - } - prevAttr->nextSibling = node; - } else // this is the first attribute node - { - element->n.firstAttr = node; - node->prevSibling = NULL; - node->nextSibling = NULL; - } - - if( rtAttr != NULL ) { - *rtAttr = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getElementsByTagNameNS -* Returns a nodeList of all the descendant Elements with a given -* local name and namespace in the order in which they are encountered -* in a preorder traversal of the element tree. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the elements to match on. The -* special value "*" matches all namespaces. -* localName: the local name of the elements to match on. The special -* value "*" matches all local names. -* -* Return Value: -* A new nodeList object containing all the matched Elements. -* -*=================================================================*/ -IXML_NodeList * -ixmlElement_getElementsByTagNameNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +IXML_NodeList *ixmlElement_getElementsByTagNameNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { - IXML_Node *node = ( IXML_Node * ) element; - IXML_NodeList *nodeList = NULL; + IXML_Node *node = (IXML_Node *)element; + IXML_NodeList *nodeList = NULL; - if( ( element != NULL ) && ( namespaceURI != NULL ) - && ( localName != NULL ) ) { - ixmlNode_getElementsByTagNameNS( node, namespaceURI, localName, - &nodeList ); - } + if(element != NULL && namespaceURI != NULL && localName != NULL) { + ixmlNode_getElementsByTagNameNS( + node, namespaceURI, localName, &nodeList); + } - return nodeList; + return nodeList; } -/*================================================================ -* ixmlElement_hasAttribute -* Returns true when an attribute with a given name is specified on -* this element, false otherwise. -* External function. -* -* Parameters: -* name: the name of the attribute to look for. -* -* Return Value: -* ture if an attribute with the given name is specified on this -* element, false otherwise. -* -*=================================================================*/ -BOOL -ixmlElement_hasAttribute( IN IXML_Element * element, - IN const DOMString name ) + +BOOL ixmlElement_hasAttribute( + IXML_Element *element, + const DOMString name) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return FALSE; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return FALSE; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + return TRUE; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - return TRUE; - } else { - attrNode = attrNode->nextSibling; - } - } - - return FALSE; + return FALSE; } -/*================================================================ -* ixmlElement_hasAttributeNS -* Returns true when attribute with a given local name and namespace -* URI is specified on this element, false otherwise. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to look for. -* localName: the local name of the attribute to look for. -* -* Return Value: -* true if an attribute with the given local name and namespace URI -* is specified, false otherwise. -* -*=================================================================*/ -BOOL -ixmlElement_hasAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +BOOL ixmlElement_hasAttributeNS( + IXML_Element * element, + const DOMString namespaceURI, + const DOMString localName ) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return FALSE; + } - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return FALSE; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + return TRUE; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - return TRUE; - } else { - attrNode = attrNode->nextSibling; - } - } - - return FALSE; + return FALSE; } -/*================================================================ -* ixmlElement_free -* frees a element node. -* External function. -* -*=================================================================*/ -void -ixmlElement_free( IN IXML_Element * element ) + +void ixmlElement_free(IXML_Element *element) { - if( element != NULL ) { - ixmlNode_free( ( IXML_Node * ) element ); - } + if (element != NULL) { + ixmlNode_free((IXML_Node *)element); + } } + diff --git a/ixml/src/inc/ixmlmembuf.h b/ixml/src/inc/ixmlmembuf.h index 25b7c9f..38ead23 100644 --- a/ixml/src/inc/ixmlmembuf.h +++ b/ixml/src/inc/ixmlmembuf.h @@ -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 #include "ixml.h" -#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) ) -#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) ) + +#include + + +#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 diff --git a/ixml/src/inc/ixmlparser.h b/ixml/src/inc/ixmlparser.h index 06151ec..36e3cd5 100644 --- a/ixml/src/inc/ixmlparser.h +++ b/ixml/src/inc/ixmlparser.h @@ -1,41 +1,49 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// - +/************************************************************************** + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + + #ifndef _IXMLPARSER_H #define _IXMLPARSER_H + +/*! + * \file + */ + + #include "ixml.h" #include "ixmlmembuf.h" -// Parser definitions + +/* Parser definitions */ #define QUOT """ #define LT "<" #define GT ">" @@ -44,77 +52,147 @@ #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); + +int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file); + +int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr); + + +void ixmlAttr_free(IXML_Attr *attrNode); +void ixmlAttr_init(IXML_Attr *attrNode); + +/*! + * \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); + + +/*! + * \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); -void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap); -int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add); void ixmlNode_init(IXML_Node *IXML_Nodeptr); BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node); -void ixmlNode_getElementsByTagName( IXML_Node *n, const char *tagname, IXML_NodeList **list); -void ixmlNode_getElementsByTagNameNS( IXML_Node *IXML_Node, const char *namespaceURI, +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 ixmlNodeList_init(IXML_NodeList *nList); -int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add); + #endif // _IXMLPARSER_H diff --git a/ixml/src/ixml.c b/ixml/src/ixml.c index 2313c83..69bcd2c 100644 --- a/ixml/src/ixml.c +++ b/ixml/src/ixml.c @@ -44,12 +44,13 @@ /*! - * \todo Documentation. + * \brief Appends a string to a buffer, substituting some characters by escape + * sequences. */ static void copy_with_escape( - /*! [in,out] \todo documentation. */ + /*! [in,out] The input/output buffer. */ ixml_membuf *buf, - /*! [in] \todo documentation. */ + /*! [in] The string to copy from. */ const char *p) { int i; @@ -90,6 +91,7 @@ static void copy_with_escape( } } + /*! * \brief Recursive function to print all the node in a tree. * Internal to parser only. @@ -193,6 +195,7 @@ static void ixmlPrintDomTreeRecursive( } } + /*! * \brief Print a DOM tree. * @@ -263,6 +266,7 @@ static void ixmlPrintDomTree( } } + /*! * \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 diff --git a/ixml/src/ixmldebug.c b/ixml/src/ixmldebug.c index 406263b..cea4d66 100644 --- a/ixml/src/ixmldebug.c +++ b/ixml/src/ixmldebug.c @@ -1,5 +1,10 @@ +/*! + * \file + */ + + #include "autoconfig.h" @@ -10,15 +15,10 @@ #include -/*! - * \file - */ - - #ifdef DEBUG void IxmlPrintf( const char *FmtStr, - ... ) + ...) { va_list ArgList; diff --git a/ixml/src/ixmlmembuf.c b/ixml/src/ixmlmembuf.c index 31cbac6..42b67e3 100644 --- a/ixml/src/ixmlmembuf.c +++ b/ixml/src/ixmlmembuf.c @@ -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 #include #include -#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; } + diff --git a/ixml/src/ixmlparser.c b/ixml/src/ixmlparser.c index 1026cfc..87391dc 100644 --- a/ixml/src/ixmlparser.c +++ b/ixml/src/ixmlparser.c @@ -30,6 +30,11 @@ ******************************************************************************/ +/*! + * \file + */ + + #include "ixmlparser.h" @@ -48,6 +53,7 @@ static char g_error_char = '\0'; + static const char LESSTHAN = '<'; static const char GREATERTHAN = '>'; static const char SLASH = '/'; @@ -55,6 +61,7 @@ static const char EQUALS = '='; static const char QUOTE = '\"'; static const char SINGLEQUOTE = '\''; + static const char *WHITESPACE = "\n\t\r "; static const char *COMPLETETAG = "/>"; static const char *ENDTAG = "> 6 ); s[1] = 0x80 | ( c & 0x3f ); s[2] = 0; return 2; - } else if( c <= 0xFFFF ) { // 0x0800 < c <= 0xFFFF + } else if( c <= 0xFFFF ) { /* 0x0800 < c <= 0xFFFF */ s[0] = 0xE0 | ( c >> 12 ); s[1] = 0x80 | ( ( c >> 6 ) & 0x3f ); s[2] = 0x80 | ( c & 0x3f ); s[3] = 0; return 3; - } else if( c <= 0x1FFFFF ) { // 0x10000 < c <= 0x1FFFFF + } else if( c <= 0x1FFFFF ) { /* 0x10000 < c <= 0x1FFFFF */ s[0] = 0xF0 | ( c >> 18 ); s[1] = 0x80 | ( ( c >> 12 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 6 ) & 0x3f ); s[3] = 0x80 | ( c & 0x3f ); s[4] = 0; return 4; - } else if( c <= 0x3FFFFFF ) { // 0x200000 < c <= 3FFFFFF + } else if( c <= 0x3FFFFFF ) { /* 0x200000 < c <= 3FFFFFF */ s[0] = 0xF8 | ( c >> 24 ); s[1] = 0x80 | ( ( c >> 18 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 12 ) & 0x3f ); @@ -422,7 +446,7 @@ static int Parser_intToUTF8(IN int c, IN utf8char s) s[4] = 0x80 | ( c & 0x3f ); s[5] = 0; return 5; - } else if( c <= 0x7FFFFFFF ) { // 0x4000000 < c <= 7FFFFFFF + } else if( c <= 0x7FFFFFFF ) { /* 0x4000000 < c <= 7FFFFFFF */ s[0] = 0xFC | ( c >> 30 ); s[1] = 0x80 | ( ( c >> 24 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 18 ) & 0x3f ); @@ -431,23 +455,25 @@ static int Parser_intToUTF8(IN int c, IN utf8char s) s[5] = 0x80 | ( c & 0x3f ); s[6] = 0; return 6; - } else { // illegal + } else { /* illegal */ return 0; } } -/******************************************************************************* - * Parser_UTF8ToInt - * In UTF-8, characters are encoded using sequences of 1 to 6 octets. - * This functions will return a UTF-8 character value and its octets number. - * Internal to parser only. - * Internal to parser only - * - ******************************************************************************/ -static int Parser_UTF8ToInt(IN const char *ss, OUT int *len) +/*! + * \brief In UTF-8, characters are encoded using sequences of 1 to 6 octets. + * This functions will return a UTF-8 character value and its octets number. + * + * \return The UTF-8 character converted to an int (32 bits). + */ +static int Parser_UTF8ToInt( + /*! [in] The pointer to the character to encode. */ + const char *ss, + /*! [out] The number of octets of the UTF-8 encoding of this character. */ + int *len) { - const unsigned char *s = ( const unsigned char * )ss; + const unsigned char *s = (const unsigned char *)ss; int c = *s; if (c <= 127) { @@ -522,12 +548,11 @@ static int Parser_UTF8ToInt(IN const char *ss, OUT int *len) } -/******************************************************************************* - * Parser_init - * Initializes a xml parser. - * Internal to parser only - * - ******************************************************************************/ +/*! + * \brief Initializes a xml parser. + * + * \return The parser object or \b NULL if there is not enough memory. + */ static Parser *Parser_init() { Parser *newParser = NULL; @@ -545,12 +570,16 @@ static Parser *Parser_init() } -/******************************************************************************* - * Parser_isValidEndElement - * check if a new node->nodeName matches top of element stack. - * Internal to parser only. - ******************************************************************************/ -static int Parser_isValidEndElement(IN Parser *xmlParser, IN IXML_Node *newNode) +/*! + * \brief Check if a new node->nodeName matches top of element stack. + * + * \return TRUE if matches. + */ +static int Parser_isValidEndElement( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The node. */ + IXML_Node *newNode) { assert(xmlParser); assert(xmlParser->pCurElement); @@ -562,13 +591,16 @@ static int Parser_isValidEndElement(IN Parser *xmlParser, IN IXML_Node *newNode) } -/******************************************************************************* - * Parser_pushElement - * push a new element onto element stack - * Internal to parser only. +/*! + * \brief Push a new element onto element stack. * - ******************************************************************************/ -static int Parser_pushElement(IN Parser *xmlParser, IN IXML_Node *newElement) + * \return + */ +static int Parser_pushElement( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The element node to push. */ + IXML_Node *newElement) { IXML_ElementStack *pCurElement = NULL; IXML_ElementStack *pNewStackElement = NULL; @@ -622,13 +654,12 @@ static int Parser_pushElement(IN Parser *xmlParser, IN IXML_Node *newElement) } -/******************************************************************************* - * Parser_popElement - * Remove element from element stack. - * Internal to parser only. - * - ******************************************************************************/ -static void Parser_popElement(IN Parser *xmlParser) +/*! + * \brief Remove element from element stack. + */ +static void Parser_popElement( + /*! [in] The XML parser. */ + Parser *xmlParser) { IXML_ElementStack *pCur = NULL; IXML_NamespaceURI *pnsUri = NULL; @@ -650,16 +681,18 @@ static void Parser_popElement(IN Parser *xmlParser) } -/******************************************************************************* - * Parser_readFileOrBuffer - * read a xml file or buffer contents into xml parser. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Read a xml file or buffer contents into xml parser. + */ static int Parser_readFileOrBuffer( - IN Parser *xmlParser, - IN const char *xmlFileName, - IN BOOL file) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The file name or the buffer to copy, according to the + * parameter "file". */ + const char *xmlFileName, + /*! [in] TRUE if you want to read from a file, false if xmlFileName is + * the buffer to copy to the parser. */ + BOOL file) { int fileSize = 0; int bytesRead = 0; @@ -699,16 +732,19 @@ static int Parser_readFileOrBuffer( return IXML_SUCCESS; } -/******************************************************************************* - * Parser_LoadDocument - * parses a xml file and return the DOM tree. - * Internal to parser only - * - ******************************************************************************/ + +/*! + * \brief Parses a xml file and return the DOM tree. + */ int Parser_LoadDocument( - OUT IXML_Document **retDoc, - IN const char *xmlFileName, - IN BOOL file ) + /*! [out] The output document tree. */ + IXML_Document **retDoc, + /*! [in] The file name or the buffer to copy, according to the + * parameter "file". */ + const char *xmlFileName, + /*! [in] TRUE if you want to read from a file, false if xmlFileName is + * the buffer to copy to the parser. */ + BOOL file) { int rc = IXML_SUCCESS; Parser *xmlParser = NULL; @@ -731,27 +767,30 @@ int Parser_LoadDocument( } -/******************************************************************************* - * isTopLevelElement - * decides whether we have top level element already. - * Internal to parser only. +/*! + * \brief Reports whether there is a top level element in the parser. * - ******************************************************************************/ -static int isTopLevelElement(IN Parser *xmlParser) + * \return TRUE if there is a top level element in the parser. + */ +static int isTopLevelElement( + /*! [in] The XML parser. */ + Parser *xmlParser) { - assert( xmlParser ); - return ( xmlParser->pCurElement == NULL ); + assert(xmlParser); + return xmlParser->pCurElement == NULL; } -/******************************************************************************* - * isDuplicateAttribute - * Decide whether the new attribute is the same as an - * existing one. - * Internal to parser only. +/*! + * \brief Reports whether the new attribute is the same as an existing one. * - ******************************************************************************/ -static int isDuplicateAttribute(IN Parser *xmlParser, IN IXML_Node *newAttrNode) + * \return TRUE if the new attribute is the same as an existing one. + */ +static int isDuplicateAttribute( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The node attribute to compare. */ + IXML_Node *newAttrNode) { IXML_Node *elementNode = NULL; IXML_Node *attrNode = NULL; @@ -769,16 +808,18 @@ static int isDuplicateAttribute(IN Parser *xmlParser, IN IXML_Node *newAttrNode) return FALSE; } -/******************************************************************************* - * Parser_processAttributeName - * processes the attribute name. - * Internal to parser only. +/*! + * \brief Processes the attribute name. * - ******************************************************************************/ + * \return IXML_SUCCESS if successful, otherwise or an error code. + */ static int Parser_processAttributeName( - IN IXML_Document *rootDoc, - IN Parser *xmlParser, - IN IXML_Node *newNode ) + /*! [in] The XML document. */ + IXML_Document *rootDoc, + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode) { IXML_Attr *attr = NULL; int rc = IXML_SUCCESS; @@ -787,8 +828,7 @@ static int Parser_processAttributeName( return IXML_SYNTAX_ERR; } - rc = ixmlDocument_createAttributeEx( rootDoc, newNode->nodeName, - &attr ); + rc = ixmlDocument_createAttributeEx( rootDoc, newNode->nodeName, &attr ); if( rc != IXML_SUCCESS ) { return rc; } @@ -798,21 +838,23 @@ static int Parser_processAttributeName( return rc; } - rc = ixmlElement_setAttributeNode( ( IXML_Element * ) xmlParser-> - currentNodePtr, attr, NULL ); + rc = ixmlElement_setAttributeNode( + (IXML_Element *)xmlParser->currentNodePtr, attr, NULL ); return rc; } -/******************************************************************************* - * Parser_processElementName - * Processes element name - * Internal to parser only. +/*! + * \brief Processes element name. * - ******************************************************************************/ + * \return IXML_SUCCESS if successful, otherwise or an error code. + */ static int Parser_processElementName( - IN IXML_Document *rootDoc, - IN Parser *xmlParser, - IN IXML_Node *newNode ) + /*! [in] The XML document. */ + IXML_Document *rootDoc, + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode ) { IXML_Element *newElement = NULL; char *nsURI = NULL; @@ -827,8 +869,7 @@ static int Parser_processElementName( } xmlParser->savePtr = xmlParser->curPtr; - rc = ixmlDocument_createElementEx( rootDoc, newNode->nodeName, - &newElement ); + rc = ixmlDocument_createElementEx( rootDoc, newNode->nodeName, &newElement ); if( rc != IXML_SUCCESS ) { return rc; } @@ -873,16 +914,14 @@ static int Parser_processElementName( return rc; } -/******************************************************************************* - * Parser_eTagVerification - * Verifies endof element tag is the same as the openning - * element tag. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Verifies endof element tag is the same as the openning element tag. + */ static int Parser_eTagVerification( - IN Parser *xmlParser, - IN IXML_Node *newNode) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode) { assert( newNode->nodeName ); assert( xmlParser->currentNodePtr ); @@ -906,13 +945,7 @@ static int Parser_eTagVerification( } -/******************************************************************************* - * Parser_freeNodeContent - * frees a node contents - * Internal to parser only. - * - ******************************************************************************/ -void Parser_freeNodeContent(IN IXML_Node *nodeptr) +void Parser_freeNodeContent(IXML_Node *nodeptr) { if( nodeptr == NULL ) { return; @@ -940,15 +973,16 @@ void Parser_freeNodeContent(IN IXML_Node *nodeptr) } -/******************************************************************************* - * Parser_parseDocument - * Parses the xml file and returns the DOM document tree. - * External function. +/*! + * \brief Parses the xml file and returns the DOM document tree. * - ******************************************************************************/ + * \return + */ static int Parser_parseDocument( - OUT IXML_Document **retDoc, - IN Parser *xmlParser ) + /*! [out] The XML document. */ + IXML_Document **retDoc, + /*! [in] The XML parser. */ + Parser *xmlParser) { IXML_Document *gRootDoc = NULL; IXML_Node newNode; @@ -1078,15 +1112,14 @@ ErrorHandler: } -/******************************************************************************* - * Parser_setLastElem - * set the last element to be the given string. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Set the last element to be the given string. + */ static int Parser_setLastElem( - IN Parser *xmlParser, - IN const char *s ) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to copy from. */ + const char *s) { int rc; @@ -1099,29 +1132,25 @@ static int Parser_setLastElem( } -/******************************************************************************* - * - * Parser_clearTokenBuf - * clear token buffer. - * Internal to parser only. - * +/*! + * \brief Clear token buffer. ******************************************************************************/ -static void Parser_clearTokenBuf(IN Parser *xmlParser) +static void Parser_clearTokenBuf( + /*! [in] The XML parser. */ + Parser *xmlParser) { ixml_membuf_destroy( &( xmlParser->tokenBuf ) ); } -/******************************************************************************* - * - * Parser_appendTokBufStr - * Appends string s to token buffer - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Appends string s to token buffer. + */ static int Parser_appendTokBufStr( - IN Parser *xmlParser, - IN const char *s ) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to append. */ + const char *s) { int rc = IXML_SUCCESS; @@ -1133,16 +1162,14 @@ static int Parser_appendTokBufStr( } -/******************************************************************************* - * - * Parser_appendTokBufChar - * Appends c to token buffer. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Appends c to token buffer. + */ static int Parser_appendTokBufChar( - IN Parser *xmlParser, - IN char c) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The character to append. */ + char c) { int rc; @@ -1151,14 +1178,12 @@ static int Parser_appendTokBufChar( } -/******************************************************************************* - * - * Parser_skipWhiteSpaces - * skip white spaces - * Internal to parser only - * - ******************************************************************************/ -static void Parser_skipWhiteSpaces(IN Parser *xmlParser) +/*! + * \brief Skip white spaces. + */ +static void Parser_skipWhiteSpaces( + /*! [in] The XML parser. */ + Parser *xmlParser) { while( ( *( xmlParser->curPtr ) != 0 ) && ( strchr( WHITESPACE, *( xmlParser->curPtr ) ) != NULL ) ) { @@ -1167,13 +1192,14 @@ static void Parser_skipWhiteSpaces(IN Parser *xmlParser) } -/******************************************************************************* - * Parser_getChar - * returns next char value and its length - * Internal to parser only - * - ******************************************************************************/ -static int Parser_getChar(IN const char *src, INOUT int *cLen) +/*! + * \brief Returns next char value and its length. + */ +static int Parser_getChar( + /*! [in] . */ + const char *src, + /*! [in,out] . */ + int *cLen) { int ret = -1; int line = 0; @@ -1283,16 +1309,16 @@ ExitFunction: } -/******************************************************************************* - * Parser_copyToken - * copy string in src into xml parser token buffer - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Copy string in src into xml parser token buffer + */ static int Parser_copyToken( - IN Parser *xmlParser, - IN const char *src, - IN int len) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to copy from. */ + const char *src, + /*! [in] The lenght to copy. */ + int len) { int ret = IXML_SUCCESS; int line = 0; @@ -1351,15 +1377,15 @@ ExitFunction: } -/******************************************************************************* - * - * Parser_skipString - * Skips all characters in the string until it finds the skip key. - * Then it skips the skip key and returns. - * Internal to parser only - * - ******************************************************************************/ -static int Parser_skipString(INOUT char **pstrSrc, IN const char *strSkipKey) +/*! + * \brief Skips all characters in the string until it finds the skip key. + * Then it skips the skip key and returns. + */ +static int Parser_skipString( + /*! [in,out] The pointer to the skipped point. */ + char **pstrSrc, + /*! [in] The skip key. */ + const char *strSkipKey) { if( !( *pstrSrc ) || !strSkipKey ) { return IXML_FAILED; @@ -1380,14 +1406,12 @@ static int Parser_skipString(INOUT char **pstrSrc, IN const char *strSkipKey) } -/******************************************************************************* - * - * Function: - * Returns: - * - * - ******************************************************************************/ -static int Parser_skipPI(INOUT char **pSrc) +/*! + * \brief + */ +static int Parser_skipPI( + /*! [in,out] The pointer to the skipped point. */ + char **pSrc) { char *pEnd = NULL; @@ -1415,13 +1439,12 @@ static int Parser_skipPI(INOUT char **pSrc) } -/******************************************************************************* - * Parser_skipXMLDecl: - * skips XML declarations. - * Internal only to parser. - * - ******************************************************************************/ -static int Parser_skipXMLDecl(INOUT Parser *xmlParser) +/*! + * \brief Skips XML declarations. + */ +static int Parser_skipXMLDecl( + /*! [in,out] The XML parser. */ + Parser *xmlParser) { int rc = IXML_FAILED; @@ -1436,13 +1459,12 @@ static int Parser_skipXMLDecl(INOUT Parser *xmlParser) } -/******************************************************************************* - * Parser_skipProlog - * skip prolog - * Internal to parser only. - * - ******************************************************************************/ -static int Parser_skipProlog(INOUT Parser *xmlParser) +/*! + * \brief Skip prolog. + */ +static int Parser_skipProlog( + /*! [in,out] The XML parser. */ + Parser *xmlParser) { int rc = IXML_SUCCESS; @@ -1477,15 +1499,13 @@ static int Parser_skipProlog(INOUT Parser *xmlParser) } -/******************************************************************************* - * - * Function: - * Returns: - * Skips all characters in the string until it finds the skip key. - * Then it skips the skip key and returns. - * - ******************************************************************************/ -static int Parser_skipComment(INOUT char **pstrSrc) +/*! + * \brief Skips all characters in the string until it finds the skip key. + * Then it skips the skip key and returns. + */ +static int Parser_skipComment( + /*! [in,out] The pointer to the skipped point. */ + char **pstrSrc) { char *pStrFound = NULL; @@ -1506,12 +1526,12 @@ static int Parser_skipComment(INOUT char **pstrSrc) } -/******************************************************************************* -* Parser_skipDocType -* skips document type declaration -* -******************************************************************************/ -static int Parser_skipDocType(INOUT char **pstr) +/*! + * \brief Skips document type declaration + */ +static int Parser_skipDocType( + /*! [in,out] The pointer to the skipped point. */ + char **pstr) { char *pCur = *pstr; char *pNext = NULL; // default there is no nested < @@ -1548,14 +1568,12 @@ static int Parser_skipDocType(INOUT char **pstr) } -/******************************************************************************* - * - * Parser_skipMisc: - * skip comment, PI and white space - * - * - ******************************************************************************/ -static int Parser_skipMisc(IN Parser *xmlParser) +/*! + * \brief Skip comment, PI and white space. + */ +static int Parser_skipMisc( + /*! [in] The XML parser. */ + Parser *xmlParser) { int rc = IXML_SUCCESS; int done = FALSE; @@ -1582,14 +1600,12 @@ static int Parser_skipMisc(IN Parser *xmlParser) } -/******************************************************************************* - * - * Parser_getNextToken - * return the length of next token in tokenBuff - * - * - ******************************************************************************/ -static int Parser_getNextToken(IN Parser *xmlParser) +/*! + * \brief Return the length of next token in tokenBuff. + */ +static int Parser_getNextToken( + /*! [in] The XML parser. */ + Parser *xmlParser) { int tokenLength = 0; int temp, @@ -1653,14 +1669,14 @@ static int Parser_getNextToken(IN Parser *xmlParser) } -/******************************************************************************* - * - * Parser_getNameSpace - * return the namespce as defined as prefix. - * Internal to parser only - * - ******************************************************************************/ -static char *Parser_getNameSpace(IN Parser *xmlParser, IN const char *prefix) +/*! + * \brief Return the namespce as defined as prefix. + */ +static char *Parser_getNameSpace( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The prefix. */ + const char *prefix) { IXML_ElementStack *pCur; IXML_NamespaceURI *pNsUri; @@ -1683,14 +1699,12 @@ static char *Parser_getNameSpace(IN Parser *xmlParser, IN const char *prefix) } -/******************************************************************************* - * - * Parser_addNamespace - * Add a namespace definition - * Internal to parser only - * - ******************************************************************************/ -static int Parser_addNamespace(IN Parser *xmlParser) +/*! + * \brief Add a namespace definition. + */ +static int Parser_addNamespace( + /*! [in] The XML parser. */ + Parser *xmlParser) { IXML_Node *pNode; IXML_ElementStack *pCur; @@ -1735,15 +1749,13 @@ static int Parser_addNamespace(IN Parser *xmlParser) } -/******************************************************************************* - * - * Parser_setNodePrefixAndLocalName - * set the node prefix and localName as defined by the nodeName - * in the form of ns:name - * Internal to parser only. - * - ******************************************************************************/ -int Parser_setNodePrefixAndLocalName(IN IXML_Node *node) +/*! + * \brief Set the node prefix and localName as defined by the nodeName in the + * form of ns:name. + */ +int Parser_setNodePrefixAndLocalName( + /*! [in,out] The Node to process. */ + IXML_Node *node) { char *pStrPrefix = NULL; char *pLocalName; @@ -1787,16 +1799,14 @@ int Parser_setNodePrefixAndLocalName(IN IXML_Node *node) } -/******************************************************************************* - * - * Parser_xmlNamespace - * add namespace definition. - * internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Add namespace definition. + */ static int Parser_xmlNamespace( - IN Parser *xmlParser, - IN IXML_Node *newNode) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode) { IXML_ElementStack *pCur = xmlParser->pCurElement; IXML_NamespaceURI *pNewNs = NULL, @@ -1903,16 +1913,14 @@ static int Parser_xmlNamespace( } -/******************************************************************************* - * - * Parser_processSTag: - * Processes the STag as defined by XML spec. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Processes the STag as defined by XML spec. + */ static int Parser_processSTag( - IN Parser *xmlParser, - IN IXML_Node *node) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *node) { char *pCurToken = NULL; int rc; @@ -1968,17 +1976,16 @@ static int Parser_processSTag( } -/******************************************************************************* - * - * Parser_hasDefaultNamespace - * decide whether the current element has default namespace - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Decide whether the current element has default namespace + */ static BOOL Parser_hasDefaultNamespace( - IN Parser *xmlParser, - IN IXML_Node *newNode, - IN char **nsURI ) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode, + /*! [in,out] The name space URI. */ + char **nsURI ) { IXML_ElementStack *pCur = xmlParser->pCurElement; @@ -1995,17 +2002,16 @@ static BOOL Parser_hasDefaultNamespace( } -/******************************************************************************* - * - * Parser_ElementPrefixDefined - * decides whether element's prefix is already defined. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Decides whether element's prefix is already defined. + */ static BOOL Parser_ElementPrefixDefined( - IN Parser *xmlParser, - IN IXML_Node *newNode, - IN char **nsURI ) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode, + /*! [in,out] The name space URI. */ + char **nsURI ) { IXML_ElementStack *pCur = xmlParser->pCurElement; IXML_NamespaceURI *pNsUri; @@ -2036,18 +2042,17 @@ static BOOL Parser_ElementPrefixDefined( } -/******************************************************************************* +/*! + * \brief Processes CDSection as defined by XML spec. * - * Parser_processCDSect - * Processes CDSection as defined by XML spec. - * Internal to parser only. - * - ******************************************************************************/ + * \return + */ static int Parser_processCDSect( - IN char **pSrc, - IN IXML_Node *node) + /*! [in] . */ + char **pSrc, + /*! [in] The Node to process. */ + IXML_Node *node) { - char *pEnd; int tokenLength = 0; char *pCDataStart; @@ -2091,16 +2096,14 @@ static int Parser_processCDSect( } -/******************************************************************************* - * - * Parser_setElementNamespace - * set element's namespace - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Set element's namespace. + */ static int Parser_setElementNamespace( - IN IXML_Element *newElement, - IN const char *nsURI) + /*! [in] The Element Node to process. */ + IXML_Element *newElement, + /*! [in] The name space string. */ + const char *nsURI) { if( newElement != NULL ) { if( newElement->n.namespaceURI != NULL ) { @@ -2117,16 +2120,14 @@ static int Parser_setElementNamespace( } -/******************************************************************************* - * - * Parser_processContent - * processes the CONTENT as defined in XML spec. - * Internal to parser only - * - ******************************************************************************/ +/*! + * \brief Processes the CONTENT as defined in XML spec. + */ static int Parser_processContent( - IN Parser *xmlParser, - IN IXML_Node *node) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *node) { int ret = IXML_SUCCESS; int line = 0; @@ -2242,17 +2243,16 @@ ExitFunction: } -/******************************************************************************* - * - * Parser_processETag - * process ETag as defined by XML spec. - * Internal to parser only. - * - ******************************************************************************/ +/*! + * \brief Process ETag as defined by XML spec. + */ static int Parser_processETag( - IN Parser *xmlParser, - IN IXML_Node *node, - OUT BOOL *bETag) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *node, + /*! [out] . */ + BOOL *bETag) { int ret = IXML_SUCCESS; int line = 0; @@ -2316,14 +2316,12 @@ ExitFunction: } -/******************************************************************************* - * - * Parser_freeElementStackItem - * frees one ElementStack item. - * Internal to parser only. - * - ******************************************************************************/ -static void Parser_freeElementStackItem(IN IXML_ElementStack *pItem) +/*! + * \brief Frees one ElementStack item. + */ +static void Parser_freeElementStackItem( + /*! [in] The element stack item to free. */ + IXML_ElementStack *pItem) { assert( pItem != NULL ); if( pItem->element != NULL ) { @@ -2341,14 +2339,12 @@ static void Parser_freeElementStackItem(IN IXML_ElementStack *pItem) } -/******************************************************************************* - * - * Parser_freeNsURI - * frees namespaceURI item. - * Internal to parser only. - * - ******************************************************************************/ -static void Parser_freeNsURI(IN IXML_NamespaceURI *pNsURI) +/*! + * \brief Frees namespaceURI item. + */ +static void Parser_freeNsURI( + /*! [in] The name space URI item to free. */ + IXML_NamespaceURI *pNsURI) { assert( pNsURI != NULL ); if( pNsURI->nsURI != NULL ) { @@ -2360,15 +2356,12 @@ static void Parser_freeNsURI(IN IXML_NamespaceURI *pNsURI) } -/******************************************************************************* - * - * Parser_free - * frees all temporary memory allocated by xmlparser. - * Internal to parser only - * - * - ******************************************************************************/ -static void Parser_free(IN Parser *xmlParser) +/*! + * \brief Frees all temporary memory allocated by xmlparser. + */ +static void Parser_free( + /*! [in] The XML parser. */ + Parser *xmlParser) { IXML_ElementStack *pElement; IXML_ElementStack *pNextElement; @@ -2407,30 +2400,30 @@ static void Parser_free(IN Parser *xmlParser) } -/******************************************************************************* +/*! + * \brief Unimplemented function. * - * Parser_parseReference - * return IXML_SUCCESS or not - * - * - ******************************************************************************/ -static int Parser_parseReference(IN char *pStr) + * \return IXML_SUCCESS. + */ +static int Parser_parseReference( + /*! [in] Currently unused. */ + char *pStr) { // place holder for future implementation return IXML_SUCCESS; } -/******************************************************************************* +/*! + * \brief Processes attribute. * - * Parser_processAttribute - * processes attribute. - * Internal to parser only. - * returns IXML_SUCCESS or failure - * - * - ******************************************************************************/ -static int Parser_processAttribute(IN Parser *xmlParser, IN IXML_Node *node) + * \return IXML_SUCCESS or failure code. + */ +static int Parser_processAttribute( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *node) { char *strEndQuote = NULL; int tlen = 0; @@ -2541,18 +2534,18 @@ static int Parser_processAttribute(IN Parser *xmlParser, IN IXML_Node *node) } -/******************************************************************************* +/*! + * \brief Get the next node. * - * Parser_getNextNode - * return next node - * returns IXML_SUCCESS or - * - * - ******************************************************************************/ + * \return IXML_SUCCESS and the next node or IXML_FILE_DONE or an error. + */ static int Parser_getNextNode( - IN Parser *xmlParser, - OUT IXML_Node *node, - OUT BOOL *bETag) + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [out] The XML parser. */ + IXML_Node *node, + /*! [out] The XML parser. */ + BOOL *bETag) { char *pCurToken = NULL; char *lastElement = NULL; diff --git a/ixml/src/namedNodeMap.c b/ixml/src/namedNodeMap.c index ff6a80f..01e3f2d 100644 --- a/ixml/src/namedNodeMap.c +++ b/ixml/src/namedNodeMap.c @@ -30,6 +30,11 @@ **************************************************************************/ +/*! + * \file + */ + + #include "ixmlparser.h" @@ -37,212 +42,153 @@ #include -/*================================================================ -* 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 ) +/*! + * \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(IXML_NamedNodeMap *nnMap, - const DOMString 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; } + diff --git a/ixml/src/node.c b/ixml/src/node.c index 5f7a0ee..2d6a50a 100644 --- a/ixml/src/node.c +++ b/ixml/src/node.c @@ -30,6 +30,11 @@ ******************************************************************************/ +/*! + * \file + */ + + #include "ixmlparser.h" @@ -63,28 +68,21 @@ ixmlCDATASection_init( IN IXML_CDATASection * nodeptr ) memset( nodeptr, 0, sizeof( IXML_CDATASection ) ); } -/*================================================================ -* ixmlCDATASection_free -* frees a CDATASection node. -* External function. -* -*=================================================================*/ -void -ixmlCDATASection_free( IN IXML_CDATASection * nodeptr ) + +void ixmlCDATASection_free(IXML_CDATASection *nodeptr) { if( nodeptr != NULL ) { ixmlNode_free( ( IXML_Node * ) nodeptr ); } } -/*================================================================ -* ixmlNode_freeSingleNode -* frees a node content. -* Internal to parser only. -* -*=================================================================*/ -void -ixmlNode_freeSingleNode( IN IXML_Node * nodeptr ) + +/*! + * \brief Frees a node content. + */ +static void ixmlNode_freeSingleNode( + /*! [in] The node to free. */ + IXML_Node *nodeptr) { IXML_Element *element = NULL; @@ -119,34 +117,20 @@ ixmlNode_freeSingleNode( IN IXML_Node * nodeptr ) } } -/*================================================================ -* ixmlNode_free -* Frees all nodes under nodeptr subtree. -* External function. -* -*=================================================================*/ -void -ixmlNode_free( IN IXML_Node * nodeptr ) -{ - if( nodeptr != NULL ) { - ixmlNode_free( nodeptr->firstChild ); - ixmlNode_free( nodeptr->nextSibling ); - ixmlNode_free( nodeptr->firstAttr ); - ixmlNode_freeSingleNode( nodeptr ); - } +void ixmlNode_free(IXML_Node *nodeptr) +{ + if (nodeptr != NULL) { + ixmlNode_free(nodeptr->firstChild); + ixmlNode_free(nodeptr->nextSibling); + ixmlNode_free(nodeptr->firstAttr); + ixmlNode_freeSingleNode(nodeptr); + } } -/*================================================================ -* ixmlNode_getNodeName -* Returns the nodename(the qualified name) -* External function. -* -*=================================================================*/ -const DOMString -ixmlNode_getNodeName( IN IXML_Node * nodeptr ) -{ +const DOMString ixmlNode_getNodeName(IXML_Node *nodeptr) +{ if( nodeptr != NULL ) { return ( nodeptr->nodeName ); } @@ -154,34 +138,24 @@ ixmlNode_getNodeName( IN IXML_Node * nodeptr ) return NULL; } -/*================================================================ -* ixmlNode_getLocalName -* Returns the node local name -* External function. -* -*=================================================================*/ -const DOMString -ixmlNode_getLocalName( IN IXML_Node * nodeptr ) + +const DOMString ixmlNode_getLocalName(IXML_Node *nodeptr) { + if (nodeptr != NULL) { + return nodeptr->localName; + } - if( nodeptr != NULL ) { - return ( nodeptr->localName ); - } - - return NULL; + return NULL; } -/*================================================================ -* ixmlNode_setNamespaceURI -* sets the namespace URI of the node. -* Internal function. -* Return: -* IXML_SUCCESS or failure -* -*=================================================================*/ -int -ixmlNode_setNamespaceURI( IN IXML_Node * nodeptr, - IN const char *namespaceURI ) +/*! + * \brief Sets the namespace URI of the node. + */ +static int ixmlNode_setNamespaceURI( + /*! [in] . */ + IN IXML_Node *nodeptr, + /*! [in] . */ + IN const char *namespaceURI) { if( nodeptr == NULL ) { @@ -203,50 +177,44 @@ ixmlNode_setNamespaceURI( IN IXML_Node * nodeptr, return IXML_SUCCESS; } -/*================================================================ -* ixmlNode_setPrefix -* set the prefix of the node. -* Internal to parser only. -* Returns: -* IXML_SUCCESS or failure. -* -*=================================================================*/ -int -ixmlNode_setPrefix( IN IXML_Node * nodeptr, - IN const char *prefix ) + +/* + * \brief Set the prefix of the node. + */ +int ixmlNode_setPrefix( + IN IXML_Node *nodeptr, + IN const char *prefix) { - if( nodeptr == NULL ) { + if (nodeptr == NULL) { return IXML_INVALID_PARAMETER; } - if( nodeptr->prefix != NULL ) { - free( nodeptr->prefix ); + if (nodeptr->prefix != NULL) { + free(nodeptr->prefix); nodeptr->prefix = NULL; } - if( prefix != NULL ) { - nodeptr->prefix = strdup( prefix ); - if( nodeptr->prefix == NULL ) { + if (prefix != NULL) { + nodeptr->prefix = strdup(prefix); + if(nodeptr->prefix == NULL) { return IXML_INSUFFICIENT_MEMORY; } } return IXML_SUCCESS; - } -/*================================================================ -* ixmlNode_setLocalName -* set the localName of the node. -* Internal to parser only. -* Returns: -* IXML_SUCCESS or failure. -* -*=================================================================*/ -int -ixmlNode_setLocalName( IN IXML_Node * nodeptr, - IN const char *localName ) +/*! + * \brief Set the localName of the node. + * + * \return IXML_SUCCESS or failure. + */ +static int ixmlNode_setLocalName( + /*! [in] The pointer to the node. */ + IN IXML_Node *nodeptr, + /*! [in] The local name to set. */ + IN const char *localName) { assert( nodeptr != NULL ); diff --git a/ixml/src/nodeList.c b/ixml/src/nodeList.c index 0d8eb09..fa571f1 100644 --- a/ixml/src/nodeList.c +++ b/ixml/src/nodeList.c @@ -30,6 +30,11 @@ ******************************************************************************/ +/*! + * \file + */ + + #include "ixmlparser.h" @@ -37,146 +42,114 @@ #include -/*================================================================ -* ixmlNodeList_init -* initializes a nodelist -* External function. -* -*=================================================================*/ -void -ixmlNodeList_init( IXML_NodeList * nList ) +/*! + * \brief Initializes a nodelist + */ +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; + } } +