void xmldb_deleteMetaInfo(IXML_Element* doc) { IXML_NodeList* list = ixmlElement_getElementsByTagName(doc, OBIX_META); if (list == NULL) { log_debug("oBIX object doesn't contain any meta information."); return; } int length = ixmlNodeList_length(list); IXML_Node* node; int error; int i; for (i = 0; i < length; i++) { node = ixmlNodeList_item(list, i); error = ixmlNode_removeChild(ixmlNode_getParentNode(node), node, &node); if (error != IXML_SUCCESS) { log_warning("Unable to clean the oBIX object from meta information " "(error %d).", error); ixmlNodeList_free(list); return; } ixmlNode_free(node); } ixmlNodeList_free(list); }
/*================================================================ * ixmlNode_insertBefore * Inserts the node newChild before the existing child node refChild. * If refChild is null, insert newChild at the end of the list of * children. If the newChild is already in the tree, it is first * removed. * External function. * Parameters: * newChild: the node to insert. * Returns: * *=================================================================*/ int ixmlNode_insertBefore( IN IXML_Node * nodeptr, IN IXML_Node * newChild, IN IXML_Node * refChild ) { int ret = IXML_SUCCESS; if( ( nodeptr == NULL ) || ( newChild == NULL ) ) { return IXML_INVALID_PARAMETER; } // whether nodeptr allow children of the type of newChild if( ixmlNode_allowChildren( nodeptr, newChild ) == FALSE ) { return IXML_HIERARCHY_REQUEST_ERR; } // or if newChild is one of nodeptr's ancestors if( ixmlNode_isAncestor( newChild, nodeptr ) == TRUE ) { return IXML_HIERARCHY_REQUEST_ERR; } // if newChild was created from a different document if( nodeptr->ownerDocument != newChild->ownerDocument ) { return IXML_WRONG_DOCUMENT_ERR; } // if refChild is not a child of nodeptr if( ixmlNode_isParent( nodeptr, refChild ) == FALSE ) { return IXML_NOT_FOUND_ERR; } if( refChild != NULL ) { if( ixmlNode_isParent( nodeptr, newChild ) == TRUE ) { ixmlNode_removeChild( nodeptr, newChild, NULL ); newChild->nextSibling = NULL; newChild->prevSibling = NULL; } newChild->nextSibling = refChild; if( refChild->prevSibling != NULL ) { ( refChild->prevSibling )->nextSibling = newChild; newChild->prevSibling = refChild->prevSibling; } refChild->prevSibling = newChild; if( newChild->prevSibling == NULL ) { nodeptr->firstChild = newChild; } newChild->parentNode = nodeptr; } else { ret = ixmlNode_appendChild( nodeptr, newChild ); } return ret; }
/*============================================================================= * ixmlNode_appendChild * Adds the node newChild to the end of the list of children of this node. * If the newChild is already in the tree, it is first removed. * External function. * Parameter: * newChild: the node to add. * Return Value: * IXML_SUCCESS * IXML_INVALID_PARAMETER: if either nodeptr or newChild is NULL * IXML_WRONG_DOCUMENT_ERR: if newChild was created from a different document than * the one that created nodeptr. * IXML_HIERARCHY_REQUEST_ERR: if newChild is ancestor of nodeptr or if nodeptr is of * a type that does not allow children of the type of the * newChild node. * *=================================================================*/ int ixmlNode_appendChild( IN IXML_Node * nodeptr, IN IXML_Node * newChild ) { IXML_Node *prev = NULL, *next = NULL; if( ( nodeptr == NULL ) || ( newChild == NULL ) ) { return IXML_INVALID_PARAMETER; } // if newChild was created from a different document if( ( newChild->ownerDocument != NULL ) && ( nodeptr->ownerDocument != newChild->ownerDocument ) ) { return IXML_WRONG_DOCUMENT_ERR; } // if newChild is an ancestor of nodeptr if( ixmlNode_isAncestor( newChild, nodeptr ) == TRUE ) { return IXML_HIERARCHY_REQUEST_ERR; } // if nodeptr does not allow to have newChild as children if( ixmlNode_allowChildren( nodeptr, newChild ) == FALSE ) { return IXML_HIERARCHY_REQUEST_ERR; } if( ixmlNode_isParent( nodeptr, newChild ) == TRUE ) { ixmlNode_removeChild( nodeptr, newChild, NULL ); } // set the parent node pointer newChild->parentNode = nodeptr; newChild->ownerDocument = nodeptr->ownerDocument; //if the first child if( nodeptr->firstChild == NULL ) { nodeptr->firstChild = newChild; } else { prev = nodeptr->firstChild; next = prev->nextSibling; while( next != NULL ) { prev = next; next = prev->nextSibling; } prev->nextSibling = newChild; newChild->prevSibling = prev; } return IXML_SUCCESS; }
int xmldb_deleteMetaVariable(IXML_Node* meta) { IXML_Node* metaItem = ixmlElement_getNode( ixmlAttr_getOwnerElement( ixmlNode_convertToAttr(meta))); int error = ixmlNode_removeChild( ixmlNode_getParentNode(metaItem), metaItem, &metaItem); if (error != IXML_SUCCESS) { log_error("Unable to delete meta data: ixmlNode_removeChild() " "returned %d", error); return -1; } ixmlNode_free(metaItem); return 0; }
int xmldb_delete(const char* href) { IXML_Node* node = getNodeByHref(_storage, href, NULL); if (node == NULL) { log_warning("Unable to delete data. Provided URI (%s) doesn't " "exist.", href); return -1; } int error = ixmlNode_removeChild(ixmlNode_getParentNode(node), node, &node); if (error != IXML_SUCCESS) { log_warning("Error occurred when deleting data (error %d).", error); return -1; } ixmlNode_free(node); return 0; }
/*================================================================ * ixmlNode_replaceChild * Replaces the child node oldChild with newChild in the list of children, * and returns the oldChild node. * External function. * Parameters: * newChild: the new node to put in the child list. * oldChild: the node being replaced in the list. * returnNode: the node replaced. * Return Value: * IXML_SUCCESS * IXML_INVALID_PARAMETER: if anyone of nodeptr, newChild or oldChild is NULL. * IXML_HIERARCHY_REQUEST_ERR: if the newChild is ancestor of nodeptr or nodeptr * is of a type that does not allow children of the * type of the newChild node. * IXML_WRONG_DOCUMENT_ERR: if newChild was created from a different document than * the one that created this node. * IXML_NOT_FOUND_ERR: if oldChild is not a child of nodeptr. * *=================================================================*/ int ixmlNode_replaceChild( IN IXML_Node * nodeptr, IN IXML_Node * newChild, IN IXML_Node * oldChild, OUT IXML_Node ** returnNode ) { int ret = IXML_SUCCESS; if( ( nodeptr == NULL ) || ( newChild == NULL ) || ( oldChild == NULL ) ) { return IXML_INVALID_PARAMETER; } // if nodetype of nodeptr does not allow children of the type of newChild // needs to add later // or if newChild is one of nodeptr's ancestors if( ixmlNode_isAncestor( newChild, nodeptr ) == TRUE ) { return IXML_HIERARCHY_REQUEST_ERR; } if( ixmlNode_allowChildren( nodeptr, newChild ) == FALSE ) { return IXML_HIERARCHY_REQUEST_ERR; } // if newChild was created from a different document if( nodeptr->ownerDocument != newChild->ownerDocument ) { return IXML_WRONG_DOCUMENT_ERR; } // if refChild is not a child of nodeptr if( ixmlNode_isParent( nodeptr, oldChild ) != TRUE ) { return IXML_NOT_FOUND_ERR; } ret = ixmlNode_insertBefore( nodeptr, newChild, oldChild ); if( ret != IXML_SUCCESS ) { return ret; } ret = ixmlNode_removeChild( nodeptr, oldChild, returnNode ); return ret; }
void processInsertEncode(IXML_Document * persXmlDoc,U32 * InserID) { int i, numPending; IXML_NodeList *nodeList; char *xmlBuff; char * xmlBuff2; IXML_Node *node; U32 tempId; char persFile[128]; INSERT_PENDING sInsertP;/* for InsertPending table */ ENC_PENDING sEncodeP; U32 affectedDiscId = 0; U32 prevDiscId; int b_updated = 0; sprintf(persFile, ZRIP_OLD_TASKFILE); /* first test if have rip interupt */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "WavPending")) != NULL){ if ((numPending = ixmlNodeList_length(nodeList)) != 0){ if (numPending != 1){ goto funcOut; } if ((node = ixmlNodeList_item(nodeList, 0)) != NULL){ if ((xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId")) != NULL){ sscanf(xmlBuff,"%x",&affectedDiscId); xmlBuff2=ixmlElement_getAttribute((IXML_Element *)node, TOTAL_FRMTAG); if(xmlBuff2) { sInsertP.uCDID = affectedDiscId; sInsertP.ptrFrames = strdup(xmlBuff2); InsertPendingTask(INSERTPENDING, &sInsertP); ZFREE(sInsertP.ptrFrames); /* Insert in to database */ } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } else{ b_updated = 1; } } } } ixmlNodeList_free(nodeList); } /* second test if have EncPending */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "EncPending")) == NULL){ goto funcOut; } if ((numPending = ixmlNodeList_length(nodeList)) == 0){ ixmlNodeList_free(nodeList); goto funcOut; } prevDiscId = 0; node = NULL; for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId"); if (!xmlBuff){ continue; } sscanf(xmlBuff,"%x",&tempId); if (affectedDiscId == tempId){ continue; } /* getAudioFormat */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "AudioFormat"); if (!xmlBuff){ continue; } else{ sEncodeP.ptrAudioFormat = strdup(xmlBuff); } if(strncasecmp(xmlBuff, AUDIO_MP3_TYPE, 3) == 0) { sEncodeP.ptrFormatCfg = strdup("128"); } else sEncodeP.ptrFormatCfg = strdup("0"); /* getpbject */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "objid"); if (!xmlBuff){ ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); continue; } else{ sEncodeP.objID = strdup(xmlBuff); } InsertPendingTask(ENCPENDING,&sEncodeP); ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); ZFREE(sEncodeP.objID); /* insert database */ } for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } } /* remove all child */ b_updated = 1; ixmlNodeList_free(nodeList); funcOut: if ( affectedDiscId){ /* delete no use */ *InserID = affectedDiscId; } if ( b_updated && ixmlUpdateDocument(persXmlDoc, persFile) == -1){ dprintf("Unable to write file path->%s", persFile); } return; }
void processCDDBUp(IXML_Document * persXmlDoc,U32 InserID) { IXML_NodeList *nodeList = NULL; IXML_Node *node; int i; int numPending; char *xmlBuff; char * xmlBuff2=NULL; char tempStr[1024]; int bUpdated = 0; CDDB_PENDING sCddbP; sprintf(tempStr,ZRIP_OLD_TASKFILE); if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "CDDBPending")) == NULL) { dprintf( "Can't find <CDDBPending> node in the %s file", tempStr); goto funcOut; } if ((numPending = ixmlNodeList_length(nodeList)) == 0) { dprintf( "Can't find any <CDDBPending> nodes in the %s file", tempStr); goto funcOut; } for (i = 0; i < numPending; i++) { if ((node = ixmlNodeList_item(nodeList, i)) == NULL) { continue; } xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId"); if (!xmlBuff) continue; sscanf(xmlBuff,"%x",&sCddbP.uCDID); if(sCddbP.uCDID == InserID) continue; xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "playsecs" ); if ( xmlBuff == NULL ) { continue; } else { sCddbP.nPlaySecs = atoi(xmlBuff); } xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "tracks" ); if ( xmlBuff == NULL ) { continue; } else { sCddbP.uTotalTracks = atoi(xmlBuff); } xmlBuff2=ixmlGetFirstElementItem( (IXML_Element *)node, "frames" ); if ( !xmlBuff2) continue; else{ sCddbP.ptrFrames = strdup(xmlBuff2); ZFREE(xmlBuff2); } /* insert into database and free the memory */ InsertPendingTask(CDDBPENDING,&sCddbP); ZFREE(sCddbP.ptrFrames); } /* free the xml */ for (i = 0; i < numPending; i++) { if ((node = ixmlNodeList_item(nodeList, i)) == NULL) { continue; } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ dprintf("Failed to remove <cddbPending>"); } } bUpdated = 1; funcOut: if ( nodeList ) ixmlNodeList_free(nodeList); if (bUpdated && ixmlUpdateDocument(persXmlDoc, tempStr) == -1) { /* free it odirect */ dprintf( "Unable to write file path->%s", tempStr); } return; }
/****************************************************************************** * DIDLObject_Create *****************************************************************************/ DIDLObject* DIDLObject_Create (void* talloc_context, IN IXML_Element* elem, IN bool is_container) { if (elem == NULL) { Log_Printf (LOG_ERROR, "DIDLObject can't create from NULL XML Element"); return NULL; // ----------> } DIDLObject* o = talloc (talloc_context, DIDLObject); if (o) { *o = (DIDLObject) { .is_container = is_container }; IXML_Node* node = NULL; /* Steal the node from its parent (instead of copying it, given * that the parent document is going to be deallocated anyway) */ ixmlNode_removeChild (ixmlNode_getParentNode (XML_E2N (elem)), XML_E2N (elem), &node); o->element = (IXML_Element*) node; // TBD need to copy ?? o->id = talloc_strdup (o, ixmlElement_getAttribute (o->element, "id")); if (o->id == NULL || o->id[0] == NUL) { char* s = DIDLObject_GetElementString (o, NULL); Log_Printf (LOG_ERROR, "DIDLObject can't create with NULL " "or empty id, XML = %s", s); talloc_free (s); talloc_free (o); return NULL; // ----------> } o->title = XMLUtil_FindFirstElementValue (node, "dc:title", false, true); if (o->title == NULL) o->title = ""; o->basename = String_CleanFileName (o, o->title); if (o->basename[0] == NUL) { char* s = DIDLObject_GetElementString (o, NULL); Log_Printf (LOG_WARNING, "DIDLObject NULL or empty <dc:title>, " "XML = %s", s); talloc_free (s); talloc_free (o->basename); o->basename = talloc_asprintf (o, "-id-%s", o->id); } else if (o->basename[0] == '.' || o->basename[0] == '_') { o->basename[0] = '-'; } o->cds_class = String_StripSpaces (o, XMLUtil_FindFirstElementValue (node, "upnp:class", false, true)); if (o->cds_class == NULL) o->cds_class = ""; char* s = ixmlElement_getAttribute (o->element, "searchable"); o->searchable = String_ToBoolean (s, false); Log_Printf (LOG_DEBUG, "new DIDLObject : %s : id='%s' " "title='%s' class='%s'", (is_container ? "container" : "item"), o->id, o->title, o->cds_class); // Register destructor talloc_set_destructor (o, DestroyObject); } return o; }