Example #1
0
/*================================================================
*   ixmlElement_setTagName
*       Sets the given element's tagName.
*   Parameters:
*       tagName: new tagName for the element.
*
*=================================================================*/
int
ixmlElement_setTagName( IN IXML_Element * element,
                        IN char *tagName )
{
    int rc = IXML_SUCCESS;

    assert( ( element != NULL ) && ( tagName != NULL ) );
    if( ( element == NULL ) || ( tagName == NULL ) ) {
        return IXML_FAILED;
    }

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

#ifdef _UPNP_MM_
    element->tagName = upnp_strdup( tagName );
#else
    element->tagName = strdup( tagName );
#endif
    if( element->tagName == NULL ) {
        rc = IXML_INSUFFICIENT_MEMORY;
    }

    return rc;

}
Example #2
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;
}
Example #3
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;
}
Example #4
0
// strdup
static void * sdu()
{
	int size = 0;
	char *temp = NULL;
	char *retptr = NULL;

	while (!size)
	{
		size = (random() % MAX_ALLOCATE_SIZE);
	}

	TotalAlloc ++;

	TotalAllocSize += size;

	temp = (char *)upnp_malloc(size);

	if (!temp)
	{
		if (size)
		{
			printf("allocate Warning: out of memory (size : %d)\n", size);
			upnp_mm_dump();
			NullAlloc ++;
		}
		return NULL;
	}

	bzero(temp, size);
	memset((void *)temp, 'A', (size - 1));

	TotalAlloc ++;

	retptr = upnp_strdup(temp);

	upnp_free(temp);

	/* check phase */
	if (retptr)
	{
		char *ptr = retptr;
		int i;
		int slen = strlen(retptr);

		TotalAllocSize += size;

		if (slen != (size - 1))
		{
			printf("strdup error ! duplicated string length : %d [expected: %d]\n", slen, (size - 1));
			upnp_mm_dump();
			exit(1);
		}

		if (slen)
		{
			for (i = 0 ; i < slen ; i ++, ptr ++)
			{
				if ((*ptr) != 'A')
				{
					printf("strdup error ! duplicated character error : %c [expected: %c]\n", *ptr, 'A');
					upnp_mm_dump();
					exit(1);
				}
			}
		}
		
	}else
	{
		printf("strdup Warning: out of memory (size : %d)\n", size);
		upnp_mm_dump();
		NullAlloc ++;
	}

	return retptr;
}