コード例 #1
0
ファイル: node.c プロジェクト: rxwen/pupnp
/*!
 * \brief Returns a clone of an attribute node.
 *
 * \return A clone of an attribute node.
 */
static IXML_Attr *ixmlNode_cloneAttr(
    /*! [in] The \b Node to clone. */
    IXML_Attr *nodeptr)
{
    IXML_Attr *newAttr;
    IXML_Node *attrNode;
    IXML_Node *srcNode;
    int rc;

    assert(nodeptr != NULL);

    newAttr = (IXML_Attr *)malloc(sizeof (IXML_Attr));
    if (newAttr == NULL) {
        return NULL;
    }

    ixmlAttr_init(newAttr);
    attrNode = (IXML_Node *)newAttr;
    srcNode = (IXML_Node *)nodeptr;

    rc = ixmlNode_setNodeName(attrNode, srcNode->nodeName);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setNodeValue(attrNode, srcNode->nodeValue);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    /* Check to see whether we need to split prefix and localname for attribute */
    rc = ixmlNode_setNamespaceURI(attrNode, srcNode->namespaceURI);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setPrefix(attrNode, srcNode->prefix);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    rc = ixmlNode_setLocalName(attrNode, srcNode->localName);
    if (rc != IXML_SUCCESS) {
        ixmlAttr_free(newAttr);
        return NULL;
    }

    attrNode->nodeType = eATTRIBUTE_NODE;

    return newAttr;
}
コード例 #2
0
ファイル: document.c プロジェクト: Open-SFC/ondir-platform
/*================================================================
*   ixmlDocument_createAttributeNSEx
*       Creates an attrbute of the given name and namespace URI
*       External function.
*   Parameters:
*       namespaceURI: the namespace fo the attribute to create
*       qualifiedName: qualifiedName of the attribute to instantiate
*   Return Value:
*       IXML_SUCCESS
*       IXML_INVALID_PARAMETER:     if either doc,namespaceURI or qualifiedName is NULL
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
                                  IN DOMString namespaceURI,
                                  IN DOMString qualifiedName,
                                  OUT IXML_Attr ** rtAttr )
{
    IXML_Attr *attrNode = NULL;
    int errCode = IXML_SUCCESS;

    if( ( doc == NULL ) || ( namespaceURI == NULL )
        || ( qualifiedName == NULL ) ) {
        errCode = IXML_INVALID_PARAMETER;
        goto ErrorHandler;
    }

    errCode =
        ixmlDocument_createAttributeEx( doc, qualifiedName, &attrNode );
    if( errCode != IXML_SUCCESS ) {
        goto ErrorHandler;
    }
    /* set the namespaceURI field */
    attrNode->n.namespaceURI = strdup( namespaceURI );
    if( attrNode->n.namespaceURI == NULL ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }
    /* set the localName and prefix */
    errCode =
        ixmlNode_setNodeName( ( IXML_Node * ) attrNode, qualifiedName );
    if( errCode != IXML_SUCCESS ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        goto ErrorHandler;
    }

  ErrorHandler:
    *rtAttr = attrNode;
    return errCode;

}
コード例 #3
0
ファイル: document.c プロジェクト: Open-SFC/ondir-platform
/*================================================================
*   ixmlDocument_createAttributeEx
*       Creates an attribute of the given name.
*       External function.
*   Parameters:
*       name: The name of the Attribute node.
*   Return Value:
*       IXML_SUCCESS
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
================================================================*/
int
ixmlDocument_createAttributeEx( IN IXML_Document * doc,
                                IN char *name,
                                OUT IXML_Attr ** rtAttr )
{
    IXML_Attr *attrNode = NULL;
    int errCode = IXML_SUCCESS;

    attrNode = ( IXML_Attr * ) malloc( sizeof( IXML_Attr ) );
    if( attrNode == NULL ) {
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    if( ( doc == NULL ) || ( name == NULL ) ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        errCode = IXML_INVALID_PARAMETER;
        goto ErrorHandler;
    }

    ixmlAttr_init( attrNode );

    attrNode->n.nodeType = eATTRIBUTE_NODE;

    /* set the node fields */
    attrNode->n.nodeName = strdup( name );
    if( attrNode->n.nodeName == NULL ) {
        ixmlAttr_free( attrNode );
        attrNode = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    attrNode->n.ownerDocument = doc;

  ErrorHandler:
    *rtAttr = attrNode;
    return errCode;

}
コード例 #4
0
/*================================================================
*   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 DOMString namespaceURI,
                            IN DOMString qualifiedName,
                            IN DOMString value )
{
    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( Parser_isValidXmlName( qualifiedName ) == FALSE ) {
        return IXML_INVALID_CHARACTER_ERR;
    }

    ixmlNode_init( &newAttrNode );

#ifdef _UPNP_MM_
    newAttrNode.nodeName = upnp_strdup( qualifiedName );
#else
    newAttrNode.nodeName = strdup( qualifiedName );
#endif
    if( newAttrNode.nodeName == NULL ) {
        return IXML_INSUFFICIENT_MEMORY;
    }

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

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

    if( attrNode != NULL ) {
        if( attrNode->prefix != NULL ) {
#ifdef _UPNP_MM_
            upnp_free( attrNode->prefix );   // remove the old prefix
#else
            free( attrNode->prefix );   // remove the old prefix
#endif
        }
        // replace it with the new prefix
#ifdef _UPNP_MM_
        attrNode->prefix = upnp_strdup( newAttrNode.prefix );
#else
        attrNode->prefix = strdup( newAttrNode.prefix );
#endif
        if( attrNode->prefix == NULL ) {
            Parser_freeNodeContent( &newAttrNode );
            return IXML_INSUFFICIENT_MEMORY;
        }

        if( attrNode->nodeValue != NULL ) {
#ifdef _UPNP_MM_
            upnp_free( attrNode->nodeValue );
#else
            free( attrNode->nodeValue );
#endif
        }

#ifdef _UPNP_MM_
        attrNode->nodeValue = upnp_strdup( value );
#else
        attrNode->nodeValue = strdup( value );
#endif
        if( attrNode->nodeValue == NULL ) {
#ifdef _UPNP_MM_
            upnp_free( attrNode->prefix );
#else
            free( attrNode->prefix );
#endif
            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;
        }

#ifdef _UPNP_MM_
        newAttr->n.nodeValue = upnp_strdup( value );
#else
        newAttr->n.nodeValue = strdup( value );
#endif
        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;
}
コード例 #5
0
/*================================================================
*   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( IN IXML_Element * element,
                          IN char *name,
                          IN char *value )
{
    IXML_Node *attrNode;
    IXML_Attr *newAttrNode;
    short errCode = IXML_SUCCESS;

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

    attrNode = element->n.firstAttr;
    while( attrNode != NULL ) {
        if( strcmp( attrNode->nodeName, name ) == 0 ) {
            break;              //found it
        } 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;
        }

        attrNode = ( IXML_Node * ) newAttrNode;

#ifdef _UPNP_MM_
        attrNode->nodeValue = upnp_strdup( value );
#else
        attrNode->nodeValue = strdup( value );
#endif
        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
#ifdef _UPNP_MM_
            upnp_free( attrNode->nodeValue );
#else
            free( attrNode->nodeValue );
#endif
        }

#ifdef _UPNP_MM_
        attrNode->nodeValue = upnp_strdup( value );
#else
        attrNode->nodeValue = strdup( value );
#endif
        if( attrNode->nodeValue == NULL ) {
            errCode = IXML_INSUFFICIENT_MEMORY;
        }
    }

  ErrorHandler:
    return errCode;
}
コード例 #6
0
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;

	if (element == NULL || namespaceURI == NULL || qualifiedName == NULL ||
	    value == NULL) {
		return IXML_INVALID_PARAMETER;
	}

	if (Parser_isValidXmlName(qualifiedName) == FALSE) {
		return IXML_INVALID_CHARACTER_ERR;
	}

	ixmlNode_init(&newAttrNode);
	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;
	}

	/* see DOM 2 spec page 59 */
	if ((newAttrNode.prefix != NULL && namespaceURI == NULL) ||
	    (newAttrNode.prefix != 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) {
			/* 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 */
		if (newAttrNode.prefix != NULL) {
		attrNode->prefix = strdup( newAttrNode.prefix );
		if (attrNode->prefix == NULL) {
			Parser_freeNodeContent(&newAttrNode);
			return IXML_INSUFFICIENT_MEMORY;
		}
		} else
			attrNode->prefix = newAttrNode.prefix;

		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) {
			Parser_freeNodeContent(&newAttrNode);
			return rc;
		}
		newAttr->n.nodeValue = strdup(value);
		if (newAttr->n.nodeValue == NULL) {
			ixmlAttr_free(newAttr);
			Parser_freeNodeContent(&newAttrNode);
			return IXML_INSUFFICIENT_MEMORY;
		}
		if (ixmlElement_setAttributeNodeNS(element, newAttr, &newAttr) != IXML_SUCCESS) {
			ixmlAttr_free(newAttr);
			Parser_freeNodeContent(&newAttrNode);
			return IXML_FAILED;
		}
	}
	Parser_freeNodeContent(&newAttrNode);

	return IXML_SUCCESS;
}
コード例 #7
0
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;

	if (!element || !newAttr)
		return IXML_INVALID_PARAMETER;
	if (newAttr->n.ownerDocument != element->n.ownerDocument)
		return IXML_WRONG_DOCUMENT_ERR;
	if (newAttr->ownerElement)
		return IXML_INUSE_ATTRIBUTE_ERR;
	newAttr->ownerElement = element;
	node = (IXML_Node *)newAttr;
	attrNode = element->n.firstAttr;
	while (attrNode) {
		if (!strcmp(attrNode->nodeName, node->nodeName))
			/* Found it */
			break;
		else
			attrNode = attrNode->nextSibling;
		}
	if (attrNode) {
		/* Already present, will replace by newAttr */
		preSib = attrNode->prevSibling;
		nextSib = attrNode->nextSibling;
		if (preSib)
			preSib->nextSibling = node;
		if (nextSib)
			nextSib->prevSibling = node;
		if (element->n.firstAttr == attrNode)
			element->n.firstAttr = node;
		if (rtAttr)
			*rtAttr = (IXML_Attr *)attrNode;
		else
			ixmlAttr_free((IXML_Attr *)attrNode);
	} else {
		/* Add this attribute */
		if (element->n.firstAttr) {
			prevAttr = element->n.firstAttr;
			nextAttr = prevAttr->nextSibling;
			while (nextAttr) {
				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)
			*rtAttr = NULL;
		}

	return IXML_SUCCESS;
}
コード例 #8
0
int ixmlElement_setAttribute(
	IXML_Element *element,
	const DOMString name,
	const DOMString value)
{
	IXML_Node *attrNode;
	IXML_Attr *newAttrNode;
	int errCode = IXML_SUCCESS;

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

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

		attrNode = (IXML_Node *)newAttrNode;
		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;
		}
	}

ErrorHandler:
	return errCode;
}