📄 element.c
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000 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./////////////////////////////////////////////////////////////////////////////// $Revision: 1.1.2.11 $// $Date: 2004/08/16 03:17:47 $#include "../../inc/tools/config.h"#if EXCLUDE_DOM == 0#include "../../inc/upnpdom/Element.h"//For now it just adds a new attribute with the name and value apecified in the//argument. DOM Level1 actually has to search if there is already a node present//if there is a node present then it should modify the valuevoid Element_setAttribute(struct strNode *pNode, char *name, char *value){ struct strAttr *addAttr; struct strNode *n; struct strNode *p; struct strNamedNodeMap *nm; nm=Node_getAttributes(pNode); n = NamedNodeMap_getNamedItem(nm, name); if(n->nact==NULL) { addAttr = (struct strAttr *) malloc (sizeof(struct strAttr) + 1); Attr_Attr_2(addAttr, name, value); //addAttr = new Attr(name, value); if(!addAttr) {DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");)} p = (struct strNode *)addAttr; Node_appendChild((struct strNode *)pNode->nact, (struct strNode *)p->nact); free(addAttr); free(p); } else { free(n->nact->NA_NodeValue); n->nact->NA_NodeValue=(char *) malloc (strlen(value) + 1); //new char[strlen(value)+1]; strcpy(n->nact->NA_NodeValue, value); } Node_deleteNode(n); NamedNodeMap_deleteNamedNodeMap(nm); }struct strAttr *Element_setAttributeNode(struct strNode *pNode, struct strAttr *newAttr){ struct strNode *Node1 = (struct strNode *)newAttr; pNode->nact->RefCount++; Node_appendChild((struct strNode *)pNode->nact, (struct strNode *)Node1->nact); newAttr = (struct strAttr *) Node1; free (Node1); return newAttr;}struct strNodeList *Element_getElementsByTagName( Element *pElement, Node *pNode, char * tagName){ struct strNodeList *returnNodeList; returnNodeList= (struct strNodeList *) malloc (sizeof(struct strNodeList) + 1); if(!returnNodeList) {DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");)} returnNodeList->ownerNodeList=returnNodeList; pNode->nact->NA_NodeType = DOCUMENT_NODE; DBGONLY(UpnpPrintf(UPNP_ALL,DOM,__FILE__,__LINE__,"Calling MakeNodeList for element whose tagname is %s\n", tagName);) Node_SearchList(pNode, tagName, returnNodeList, strchr(tagName,':')==NULL); pNode->nact->NA_NodeType = ELEMENT_NODE; return returnNodeList;}void Element_Element_1(Element *pElement, struct strNode *pNode, char *name){ pNode->nact = (struct strNodeAct *) malloc (sizeof(struct strNodeAct) + 1); NodeAct_NodeAct_4(pNode->nact, ELEMENT_NODE, name,NULL,pNode); //nact = new NodeAct(ELEMENT_NODE, name,NULL,this); if(!pNode->nact) {DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");)} pNode->nact->RefCount++; pElement->ownerElement=(struct strElement *)pNode;}void Element_Element_0(Element *pElement, struct strNode *pNode){ pElement->ownerElement=(struct strElement *)pNode; pNode->nact=NULL;}void Element_Element_free(Element *pElement){}void Element_deleteElement(Element *pElement){ free(pElement->ownerElement);// delete ownerElement;// this->nact=NULL;}Element *Element_Element_operator_eq(Element *pElement, const Element *other){ struct strNode *p, *q; q = (struct strNode *) pElement; p = (struct strNode *) other; if (q->nact != p->nact) { q->nact = p->nact; q->nact->RefCount++; } pElement->ownerElement=other->ownerElement; return pElement;}/****Element & Element::operator = (const Element &other){ if (this->nact != other.nact) { this->nact = other.nact; this->nact->RefCount++; } this->ownerElement=other.ownerElement; return *this;};****/#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -