📄 domcif.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// 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.1.6 $// $Date: 2001/06/15 00:22:17 $//#include "../../inc/tools/config.h"#if EXCLUDE_DOM == 0#include <stdio.h>#include <string.h>#include <iostream.h>#include <malloc.h>#include "../../inc/upnpdom/domCif.h"#include "../../inc/upnpdom/Parser.h"#include "../../inc/upnpdom/Node.h"#include "../../inc/upnpdom/NodeAct.h"#include "../../inc/upnpdom/NodeList.h"#include "../../inc/upnpdom/Document.h"#include <genlib/util/membuffer.h>// ---------------------------------------------------------------------------// Forward references// ---------------------------------------------------------------------------void copyToTarget(char*& target, const char* p);void DumpDocument(char *&target, Node& n, int loop);void DumpNonEscapedDocument(char*& target, Node& n, int loop);// todo:://bool Upnp_DOMImplementation_hasFeature( const Upnp_DOMString & feature,const Upnp_DOMString & version)//{// DOMImplementation UpnpDOM;// return(UpnpDOM.hasFeature(feature,version));//}/*******************************************************************************************************************************///Interface Node Implementation/*******************************************************************************************************************************/Upnp_Node UpnpNode_insertBefore(Upnp_Node OperationNode, Upnp_Node newChild, Upnp_Node refChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Node *)OperationNode).insertBefore((*(Node *)newChild),(*(Node *)refChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpNode_replaceChild(Upnp_Node OperationNode, Upnp_Node newChild, Upnp_Node oldChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Node *)OperationNode).replaceChild((*(Node *)newChild),(*(Node *)oldChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpNode_removeChild(Upnp_Node OperationNode, Upnp_Node oldChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Node *)OperationNode).removeChild((*(Node *)oldChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpNode_appendChild(Upnp_Node OperationNode, Upnp_Node newChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Node *)OperationNode).appendChild((*(Node *)newChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Bool UpnpNode_hasChildNodes(Upnp_Node OperationNode){ return((*(Node *)OperationNode).hasChildNodes());} Upnp_Node UpnpNode_cloneNode(Upnp_Node OperationNode, Upnp_Bool deep){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).cloneNode((deep>0)); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_DOMString UpnpNode_getNodeName(Upnp_Node OperationNode){ Upnp_DOMString temp; temp = (*(Node *)OperationNode).getNodeName(); return(temp);}Upnp_DOMString UpnpNode_getNodeValue(Upnp_Node OperationNode, Upnp_DOMException *err){ Upnp_DOMString temp=NULL; *err =NO_ERR; try { temp = (*(Node *)OperationNode).getNodeValue(); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } return(temp);}Upnp_Void UpnpNode_setNodeValue(Upnp_Node OperationNode, Upnp_DOMString nodeValue, Upnp_DOMException *err){ *err =NO_ERR; try { (*(Node *)OperationNode).setNodeValue(nodeValue); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; }}Upnp_UShort UpnpNode_getNodeType(Upnp_Node OperationNode){ return((*(Node *)OperationNode).getNodeType());} Upnp_Node UpnpNode_getParentNode(Upnp_Node OperationNode){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getParentNode(); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_NodeList UpnpNode_getChildNodes(Upnp_Node OperationNode){ NodeList *ret = new NodeList; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getChildNodes(); if(!ret->getLength()) { UpnpNodeList_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getFirstChild(Upnp_Node OperationNode){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getFirstChild(); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getLastChild(Upnp_Node OperationNode){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getLastChild(); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getPreviousSibling(Upnp_Node OperationNode){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getPreviousSibling(); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getNextSibling(Upnp_Node OperationNode){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getNextSibling(); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_NamedNodeMap UpnpNode_getAttributes(Upnp_Node OperationNode){ NamedNodeMap *ret = new NamedNodeMap; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getAttributes(); if(!ret->getLength()) { UpnpNamedNodeMap_free(ret); return NULL; } else return((void *)ret);}Upnp_Document UpnpNode_getOwnerDocument(Upnp_Node OperationNode){ Document *ret = new Document; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Node *)OperationNode).getOwnerDocument(); if(ret->isNull()) { UpnpDocument_free(ret); return NULL; } else return((void *)ret);}Upnp_Void UpnpNode_free(Upnp_Node OperationNode){ if(OperationNode == NULL) return; Node *rmv; rmv=(Node *)OperationNode; rmv->deleteNode(); delete rmv; rmv=NULL;}/*******************************************************************************************************************************///Interface Document Implementation/*******************************************************************************************************************************/Upnp_Document UpnpDocument_createDocument(Upnp_Document OperationDocument){ Document *ret = new Document; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Document *)OperationDocument).createDocument(); if(ret->isNull()) { UpnpDocument_free(ret); return NULL; } else return((void *)ret);}Upnp_Element UpnpDocument_createElement(Upnp_Document OperationDocument, Upnp_DOMString tagName, Upnp_DOMException *err){ Element *ret = new Element; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Document *)OperationDocument).createElement(tagName); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpElement_free(ret); return NULL; } else return((void *)ret);}Upnp_Text UpnpDocument_createTextNode(Upnp_Document OperationDocument, Upnp_DOMString data){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Document *)OperationDocument).createTextNode(data); if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Attr UpnpDocument_createAttribute(Upnp_Document OperationDocument, Upnp_DOMString name, Upnp_DOMException *err){ Attr *ret = new Attr; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Document *)OperationDocument).createAttribute(name); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) {// UpnpAttr_free(ret); delete ret; return NULL; } else return((void *)ret);}Upnp_NodeList UpnpDocument_getElementsByTagName(Upnp_Document OperationDocument, Upnp_DOMString tagname){ NodeList *ret = new NodeList; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *ret = (*(Document *)OperationDocument).getElementsByTagName(tagname); if(!ret->getLength()) { UpnpNodeList_free(ret); return NULL; } else return((void *)ret);}/*Upnp_Element UpnpDocument_getDocumentElement(Upnp_Document OperationDocument){ Element *ret = new Element; *ret = (*(Document *)OperationDocument).getDocumentElement(); if(ret->isNull()) { UpnpDocument_free(ret); return NULL; } else return((void *)ret);}*/Upnp_Node UpnpDocument_insertBefore(Upnp_Document OperationDocument, Upnp_Node newChild, Upnp_Node refChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Document *)OperationDocument).insertBefore((*(Node *)newChild),(*(Node *)refChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpDocument_replaceChild(Upnp_Document OperationDocument, Upnp_Node newChild, Upnp_Node oldChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; try { *ret = (*(Document *)OperationDocument).replaceChild((*(Node *)newChild),(*(Node *)oldChild)); } catch(DOMException &tocatch) { *err = (enum Upnp_DOMException)tocatch.code; } if(ret->isNull()) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpDocument_removeChild(Upnp_Document OperationDocument, Upnp_Node oldChild, Upnp_DOMException *err){ Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -