📄 domcif.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.6 $// $Date: 2004/08/16 03:17:47 $//#include "../../inc/tools/config.h"#if EXCLUDE_DOM == 0#include <stdio.h>#include <string.h>#include <malloc.h>#include "../../inc/upnpdom/domCif.h"#include <genlib/util/membuffer.h>#include "../../inc/upnpdom/DOMException.h"// ---------------------------------------------------------------------------// Forward references// ---------------------------------------------------------------------------//void copyToTarget(char* target, const char* p);//void DumpDocument(char *target, struct strNode *n, int loop);//void DumpNonEscapedDocument(char* target, struct strNode *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_removeChild(Upnp_Node OperationNode, Upnp_Node oldChild, Upnp_DOMException *err){ struct strNode *ret; // = new Node; ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); //Node_Node_0(ret); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; ret = Node_removeChild(ret, ((struct strNode *)oldChild)); if (!ret) { Handle_DOMException(NOT_FOUND_ERR_DOM); *err = NOT_FOUND_ERR; } //try //{ // *ret = (*(Node *)OperationNode).removeChild((*(Node *)oldChild)); //} //catch(DOMException &tocatch) //{ // *err = (enum Upnp_DOMException)tocatch.code; //} if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Node UpnpNode_appendChild(Upnp_Node OperationNode, Upnp_Node newChild, Upnp_DOMException *err){ struct strNode *ret; // = new Node; ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); //Node_Node_0(ret); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; ret = Node_appendChild(ret, ((struct strNode *)newChild)); if (!ret) { Handle_DOMException(NOT_FOUND_ERR_DOM); *err = NOT_FOUND_ERR; } //try //{ // *ret = (*(Node *)OperationNode).appendChild((*(Node *)newChild)); //} //catch(DOMException &tocatch) //{ // *err = (enum Upnp_DOMException)tocatch.code; //} if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);} Upnp_Bool UpnpNode_hasChildNodes(Upnp_Node OperationNode){ return Node_hasChildNodes( ((struct strNode *)OperationNode) );}Upnp_DOMString UpnpNode_getNodeName(Upnp_Node OperationNode){ Upnp_DOMString temp; temp = Node_getNodeName( ((struct strNode *)OperationNode) ); return(temp);}Upnp_DOMString UpnpNode_getNodeValue(Upnp_Node OperationNode, Upnp_DOMException *err){ Upnp_DOMString temp=NULL; *err =NO_ERR; //try //{ temp = Node_getNodeValue( ((struct strNode *)OperationNode) ); if (!temp) { Handle_DOMException(NOT_FOUND_ERR_DOM); *err = NOT_FOUND_ERR; } //} //catch(DOMException &tocatch) //{ // *err = (enum Upnp_DOMException)tocatch.code; //} return(temp);}Upnp_Void UpnpNode_setNodeValue(Upnp_Node OperationNode, Upnp_DOMString nodeValue, Upnp_DOMException *err){ int ret = 0; *err =NO_ERR; ret = Node_setNodeValue(((struct strNode *)OperationNode), nodeValue); if (ret != 0) { printf("error\n"); Handle_DOMException(NOT_FOUND_ERR_DOM); *err = NOT_FOUND_ERR; } //try //{ // (*(Node *)OperationNode).setNodeValue(nodeValue); //} //catch(DOMException &tocatch) //{ // *err = (enum Upnp_DOMException)tocatch.code; //}}Upnp_UShort UpnpNode_getNodeType(Upnp_Node OperationNode){ return Node_getNodeType(((struct strNode *)OperationNode));} Upnp_Node UpnpNode_getParentNode(Upnp_Node OperationNode){ struct strNode *ret; // = new Node; ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); //Node_Node_0(ret); //Node *ret = new Node; if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Node_getParentNode(((struct strNode *)OperationNode)); if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_NodeList UpnpNode_getChildNodes(Upnp_Node OperationNode){ struct strNodeList *ret; // = new NodeList; ret = (struct strNodeList *) malloc (sizeof(struct strNodeList) + 1); //NodeList_NodeList_0(ret); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Node_getChildNodes(((struct strNode *)OperationNode)); if(!NodeList_getLength(ret)) { UpnpNodeList_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getFirstChild(Upnp_Node OperationNode){ struct strNode *ret; //= new Node; ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); //Node_Node_0(ret); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Node_getFirstChild(((struct strNode *)OperationNode)); if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Node UpnpNode_getNextSibling(Upnp_Node OperationNode){ struct strNode *ret; //= new Node; //Node_Node_0(); ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Node_getNextSibling(((struct strNode *)OperationNode)); if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Void UpnpNode_free(Upnp_Node OperationNode){ if(OperationNode == NULL) return; struct strNode *rmv; rmv=(struct strNode *)OperationNode; Node_deleteNode(rmv); free(rmv); rmv=NULL;}/*******************************************************************************************************************************///Interface Document Implementation/*******************************************************************************************************************************/Upnp_Element UpnpDocument_createElement(Upnp_Document OperationDocument, Upnp_DOMString tagName, Upnp_DOMException *err){ struct strElement *ret; // = new Element; //Element_Element_0(); ret = (struct strElement *) malloc (sizeof(struct strElement) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } *err =NO_ERR; ret = Document_createElement(tagName); if (!ret) { Handle_DOMException(NOT_FOUND_ERR_DOM); *err = NOT_FOUND_ERR; } //try //{ // *ret = (*(Document *)OperationDocument).createElement(tagName); //} //catch(DOMException &tocatch) //{ // *err = (enum Upnp_DOMException)tocatch.code; //} if( Node_isNull((struct strNode *) ret) ) { UpnpElement_free(ret); return NULL; } else return((void *)ret);}Upnp_Text UpnpDocument_createTextNode(Upnp_Document OperationDocument, Upnp_DOMString data){ struct strNode *ret; // = new Node; //Node_Node_0(); ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Document_createTextNode(((struct strDocument *)OperationDocument), data); if(Node_isNull((struct strNode *)ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_NodeList UpnpDocument_getElementsByTagName(Upnp_Document OperationDocument, Upnp_DOMString tagname){ struct strNodeList *ret; // = new NodeList; //NodeList_NodeList_0(); ret = (struct strNodeList *) malloc (sizeof(struct strNodeList) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Document_getElementsByTagName(((struct strNode *)OperationDocument), tagname); if(!NodeList_getLength(ret)) { 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_getFirstChild(Upnp_Document OperationDocument){ struct strNode *ret; // = new Node; //Node_Node_0(); ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = Node_getFirstChild(((struct strNode *)OperationDocument)); if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}Upnp_Void UpnpDocument_free(Upnp_Document OperationDocument){ if(OperationDocument == NULL) return; struct strDocument *rmv; rmv=(struct strDocument *)OperationDocument; Document_deleteDocumentTree(rmv); // Be ware everything is deleted Document_deleteDocument(rmv, (struct strNode *)OperationDocument); free(rmv); rmv=NULL;}/*******************************************************************************************************************************///Interface NodeList Implementation/*******************************************************************************************************************************/Upnp_Node UpnpNodeList_item(Upnp_NodeList OperationNodeList, unsigned long index){ struct strNode *ret; // = new Node; ret = (struct strNode *) malloc (sizeof(struct strNode) + 1); if(!ret) { DBGONLY(UpnpPrintf(UPNP_CRITICAL,DOM,__FILE__,__LINE__,"Insuffecient memory\n");) return NULL; } ret = NodeList_item(((struct strNodeList *)OperationNodeList), index); if(Node_isNull(ret)) { UpnpNode_free(ret); return NULL; } else return((void *)ret);}int UpnpNodeList_getLength(Upnp_NodeList OperationNodeList){ return NodeList_getLength(((struct strNodeList *)OperationNodeList));}Upnp_Void UpnpNodeList_free(Upnp_NodeList OperationNodeList){ if(OperationNodeList ==NULL) return; struct strNodeList *rmv; rmv=(struct strNodeList *)OperationNodeList; NodeList_deleteNodeList(rmv); free(rmv);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -