예제 #1
0
int set_node_value(struct xmlelement *element, const char *newNodeValue)
{
	IXML_Node *node = (IXML_Node*) to_ielem(element);
	node = ixmlNode_getFirstChild(node);

	return ixmlNode_setNodeValue(node, newNodeValue);
}
예제 #2
0
/*================================================================
*   ixmlNode_cloneElement
*       returns a clone of element node
*       Internal to parser only.
*
*=================================================================*/
IXML_Element *
ixmlNode_cloneElement( IN IXML_Element * nodeptr )
{
    IXML_Element *newElement;
    IXML_Node *elementNode;
    IXML_Node *srcNode;
    int rc;

    assert( nodeptr != NULL );

    newElement = ( IXML_Element * ) malloc( sizeof( IXML_Element ) );
    if( newElement == NULL ) {
        return NULL;
    }

    ixmlElement_init( newElement );
    rc = ixmlElement_setTagName( newElement, nodeptr->tagName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    elementNode = ( IXML_Node * ) newElement;
    srcNode = ( IXML_Node * ) nodeptr;
    rc = ixmlNode_setNodeName( elementNode, srcNode->nodeName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setNodeValue( elementNode, srcNode->nodeValue );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setNamespaceURI( elementNode, srcNode->namespaceURI );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setPrefix( elementNode, srcNode->prefix );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    rc = ixmlNode_setLocalName( elementNode, srcNode->localName );
    if( rc != IXML_SUCCESS ) {
        ixmlElement_free( newElement );
        return NULL;
    }

    elementNode->nodeType = eELEMENT_NODE;

    return newElement;

}
예제 #3
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;
}
예제 #4
0
int xmldb_changeMetaVariable(IXML_Node* meta, const char* newValue)
{
    int error = ixmlNode_setNodeValue(meta, newValue);
    if (error != IXML_SUCCESS)
    {
        const char* metaName =
            ixmlElement_getTagName(ixmlAttr_getOwnerElement(
                                       ixmlNode_convertToAttr(meta)));
        log_error("Unable to change value of meta attribute \"%s\" to \"%s\":"
                  "ixmlNode_setNodeValue returned %d.",
                  metaName, newValue, error);
        return -1;
    }
    return 0;
}
/*================================================================
*   ixmlNode_setNodeProperties
*       Internal to parser only.
*
*=================================================================*/
int
ixmlNode_setNodeProperties( IN IXML_Node * destNode,
                            IN IXML_Node * src )
{

    int rc;

    assert( destNode != NULL || src != NULL );

    rc = ixmlNode_setNodeValue( destNode, src->nodeValue );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }

    rc = ixmlNode_setLocalName( destNode, src->localName );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }

    rc = ixmlNode_setPrefix( destNode, src->prefix );
    if( rc != IXML_SUCCESS ) {
        goto ErrorHandler;
    }
    // set nodetype
    destNode->nodeType = src->nodeType;

    return IXML_SUCCESS;

  ErrorHandler:
    if( destNode->nodeName != NULL ) {
        ixml_free( destNode->nodeName );
        destNode->nodeName = NULL;
    }
    if( destNode->nodeValue != NULL ) {
        ixml_free( destNode->nodeValue );
        destNode->nodeValue = NULL;
    }
    if( destNode->localName != NULL ) {
        ixml_free( destNode->localName );
        destNode->localName = NULL;
    }

    return IXML_INSUFFICIENT_MEMORY;
}
/*================================================================
*   ixmlNode_cloneTextNode
*       Returns a clone of nodeptr
*       Internal to parser only.
*
*=================================================================*/
IXML_Node *
ixmlNode_cloneTextNode( IN IXML_Node * nodeptr )
{
    IXML_Node *newNode = NULL;

    assert( nodeptr != NULL );

    newNode = ( IXML_Node * ) ixml_malloc( sizeof( IXML_Node ) );
    if( newNode == NULL ) {
        return NULL;
    } else {
        ixmlNode_init( newNode );

        ixmlNode_setNodeName( newNode, nodeptr->nodeName );
        ixmlNode_setNodeValue( newNode, nodeptr->nodeValue );
        newNode->nodeType = eTEXT_NODE;
    }

    return newNode;
}
예제 #7
0
파일: node.c 프로젝트: rxwen/pupnp
/*!
 * \brief Return a clone of CDATASection node.
 *
 * \return A clone of CDATASection node.
 */
static IXML_CDATASection *ixmlNode_cloneCDATASect(
    /*! [in] The \b Node to clone. */
    IXML_CDATASection *nodeptr)
{
    IXML_CDATASection *newCDATA = NULL;
    IXML_Node *newNode;
    IXML_Node *srcNode;

    assert(nodeptr != NULL);
    newCDATA = (IXML_CDATASection *)malloc(sizeof (IXML_CDATASection));
    if (newCDATA != NULL) {
        newNode = (IXML_Node *)newCDATA;
        ixmlNode_init(newNode);
        srcNode = (IXML_Node *)nodeptr;
        ixmlNode_setNodeName(newNode, srcNode->nodeName);
        ixmlNode_setNodeValue(newNode, srcNode->nodeValue);
        newNode->nodeType = eCDATA_SECTION_NODE;
    }

    return newCDATA;
}
예제 #8
0
//path,  friendlyName
static void UpdateValue(const char *Path,const char *NodeElement, char *NewValue)
{
	char *Buf = NULL;

	IXML_Document *doc = NULL;
	IXML_NodeList *node = NULL;
	IXML_Node *NodePtr = NULL;

	if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER)
		goto EXIT_THIS;

	node = ixmlDocument_getElementsByTagName(doc, NodeElement);

	if (node) 
	{
		if (NodePtr = ixmlNodeList_item(node, 0)) 
		{
			NodePtr = ixmlNode_getFirstChild(NodePtr);
			ixmlNode_setNodeValue(NodePtr,NewValue);
		} 
	}
	else
	{
		goto EXIT_XML;
	}

	Buf = ixmlPrintDocument(doc);

	if(WriteFile(Path,Buf) != SUCCESS)
		goto EXIT_THIS;

EXIT_XML:
	if (node)
		ixmlNodeList_free(node);
	free(Buf);
	ixmlDocument_free(doc);  
EXIT_THIS:
	return;
}
예제 #9
0
파일: rtpxml.c 프로젝트: layerfsd/cifssmb
int rtpxmlNode_setNodeValue(RTPXML_Node *nodeptr, char *newNodeValue)
{
	return ixmlNode_setNodeValue((IXML_Node *)nodeptr, newNodeValue);
}
예제 #10
0
파일: urlconfig.c 프로젝트: BlackGrey/upnp
/************************************************************************
*	Function :	config_description_doc
*
*	Parameters :
*		INOUT IXML_Document *doc ;IMXL description document to be 
*					configured	
*		IN const char* ip_str ;	string containing the IP port number
*		OUT char** root_path_str ;	buffer to hold the root path
*					of the configured description document
*		INOUT IXML_Document *doc :	Description document
*		IN const char* ip_str :	ipaddress string
*		OUT char** root_path_str :	root path string
*
*	Description : Configure the description document. Add the standard 
*		format and then add information from the root device and any
*		child nodes.
*
*	Return : int ;
*		UPNP_E_SUCCESS - On Success
*		UPNP_E_OUTOF_MEMORY - Default Error
*		UPNP_E_INVALID_DESC - Invalid child node		
*		UPNP_E_INVALID_URL - Invalid node information
*
*	Note :
************************************************************************/
static int
config_description_doc( INOUT IXML_Document * doc,
                        IN const char *ip_str,
                        OUT char **root_path_str )
{
    xboolean addNew = FALSE;
    IXML_NodeList *baseList;
    IXML_Element *element = NULL;
    IXML_Element *newElement = NULL;
    IXML_Node *textNode = NULL;
    IXML_Node *rootNode = NULL;
    IXML_Node *urlbase_node = NULL;
    char *urlBaseStr = "URLBase";
    const DOMString domStr = NULL;
    uri_type uri;
    int err_code;
    int len;
    membuffer url_str;
    membuffer root_path;

    membuffer_init( &url_str );
    membuffer_init( &root_path );

    err_code = UPNP_E_OUTOF_MEMORY; // default error

    baseList = ixmlDocument_getElementsByTagName( doc, urlBaseStr );
    if( baseList == NULL ) {
        // urlbase not found -- create new one
        addNew = TRUE;
        element = ixmlDocument_createElement( doc, urlBaseStr );
        if( element == NULL ) {
            goto error_handler;
        }

        if( membuffer_append_str( &url_str, "http://" ) != 0 ||
            membuffer_append_str( &url_str, ip_str ) != 0 ||
            membuffer_append_str( &url_str, "/" ) != 0 ||
            membuffer_append_str( &root_path, "/" ) != 0 ) {
            goto error_handler;
        }

        rootNode = ixmlNode_getFirstChild( ( IXML_Node * ) doc );
        if( rootNode == NULL ) {
            err_code = UPNP_E_INVALID_DESC;
            goto error_handler;
        }

        err_code =
            ixmlNode_appendChild( rootNode, ( IXML_Node * ) element );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }

        textNode =
            ixmlDocument_createTextNode( doc, ( char * )url_str.buf );
        if( textNode == NULL ) {
            goto error_handler;
        }

        err_code =
            ixmlNode_appendChild( ( IXML_Node * ) element, textNode );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }

    } else {
        // urlbase found
        urlbase_node = ixmlNodeList_item( baseList, 0 );
        assert( urlbase_node != NULL );

        textNode = ixmlNode_getFirstChild( urlbase_node );
        if( textNode == NULL ) {
            err_code = UPNP_E_INVALID_DESC;
            goto error_handler;
        }

        domStr = ixmlNode_getNodeValue( textNode );
        if( domStr == NULL ) {
            err_code = UPNP_E_INVALID_URL;
            goto error_handler;
        }

        len = parse_uri( domStr, strlen( domStr ), &uri );
        if( len < 0 || uri.type != ABSOLUTE ) {
            err_code = UPNP_E_INVALID_URL;
            goto error_handler;
        }

        if( membuffer_assign( &url_str, uri.scheme.buff,
                              uri.scheme.size ) != 0 ||
            membuffer_append_str( &url_str, "://" ) != 0 ||
            membuffer_append_str( &url_str, ip_str ) != 0 ) {
            goto error_handler;
        }
        // add leading '/' if missing from relative path
        if( ( uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/' ) ||
            ( uri.pathquery.size == 0 )
             ) {
            if( membuffer_append_str( &url_str, "/" ) != 0 ||
                membuffer_append_str( &root_path, "/" ) != 0 ) {
                goto error_handler;
            }
        }

        if( membuffer_append( &url_str, uri.pathquery.buff,
                              uri.pathquery.size ) != 0 ||
            membuffer_append( &root_path, uri.pathquery.buff,
                              uri.pathquery.size ) != 0 ) {
            goto error_handler;
        }
        // add trailing '/' if missing
        if( url_str.buf[url_str.length - 1] != '/' ) {
            if( membuffer_append( &url_str, "/", 1 ) != 0 ) {
                goto error_handler;
            }
        }

        err_code = ixmlNode_setNodeValue( textNode, url_str.buf );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }
    }

    *root_path_str = membuffer_detach( &root_path );    // return path
    err_code = UPNP_E_SUCCESS;

  error_handler:
    if( err_code != UPNP_E_SUCCESS ) {
        ixmlElement_free( newElement );
    }

    ixmlNodeList_free( baseList );

    membuffer_destroy( &root_path );
    membuffer_destroy( &url_str );

    return err_code;
}
예제 #11
0
static int SetFriendlyName(char *file, char *newname, int status) 
{
	int iRet = 0;
	IXML_Document * doc = NULL;
	IXML_NodeList * nodelist = NULL;
	IXML_Node * node = NULL;
	char * escapeStr = NULL;	
	void * zdbhandle = NULL;
	if(ZDBOpen(Z_UTIL_ZQDEV,DBfile,&zdbhandle) != Z_SUCCESS){
		fprintf(stderr,"open db error\n");
		return 0;
	}

	if(!newname || !file){
		iRet = -3;
		goto FuncOut;
	}
	
	doc = ixmlLoadDocument(file);
	if(!doc){
		fprintf(stderr, "Document not parsed successfully.");
		iRet = -1;
		goto FuncOut;
	}
	
	if((nodelist = ixmlDocument_getElementsByTagName(doc, "friendlyName"))!= NULL){
		node = ixmlNodeList_item(nodelist, 0);
		node = ixmlNode_getFirstChild(node);

		if(node != NULL)
		{	
			if(strlen(newname) > 0)
				iRet = ixmlNode_setNodeValue(node, newname);

			if(iRet == IXML_SUCCESS){
				iRet = 0;
				if(ixmlUpdateDocument(doc, file)==0)
				{
					//update the zconfig database by jyan 09-06-08
					if(!strcmp(file,DMSCFGFILE))
						updateDB(zdbhandle,"LocalDMSName",newname);
					else
						updateDB(zdbhandle,"LocalDMRName",newname);
				}
				else
					fprintf(stderr,"Update Document fail!!");
				goto FuncOut;
			}
			else {
				iRet = -32;
				goto FuncOut;
			}
		}
	}

FuncOut:
	if(escapeStr)
	{
		free(escapeStr);
		escapeStr = NULL;
	}
	if(nodelist)
		  ixmlNodeList_free(nodelist);
	if(doc)
		ixmlDocument_free(doc);
	ZDBClose(zdbhandle);
	return iRet;	
}