Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

XSECDOMUtils.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * imitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * XSECDOMUtils:= Utilities to manipulate DOM within XML-SECURITY
00021  *
00022  * Author(s): Berin Lautenbach
00023  *
00024  * $Id: XSECDOMUtils.hpp,v 1.15 2004/02/08 10:25:39 blautenb Exp $
00025  *
00026  */
00027 
00028 #ifndef XSECDOMUTILS_HEADER
00029 #define XSECDOMUTILS_HEADER
00030 
00031 // XSEC
00032 
00033 #include <xsec/utils/XSECPlatformUtils.hpp>
00034 #include <xsec/utils/XSECSafeBuffer.hpp>
00035 #include <xsec/dsig/DSIGConstants.hpp>
00036 
00037 // Xerces
00038 
00039 #include <xercesc/dom/DOM.hpp>
00040 #include <xercesc/util/XMLString.hpp>
00041 
00042 #define COMPARE_STRING_LENGTH   256
00043 
00044 // --------------------------------------------------------------------------------
00045 //           "Quick" Transcode Class (low performance)
00046 // --------------------------------------------------------------------------------
00047 
00048 
00049 class DSIG_EXPORT XMLT {
00050 
00051 public:
00052 
00053     XMLT(const char * str);
00054     ~XMLT(void);
00055 
00056     XMLCh * getUnicodeStr(void);
00057 
00058 private:
00059 
00060     XMLCh * mp_unicodeStr;
00061     XMLT();
00062 
00063 };
00064 
00065 #define MAKE_UNICODE_STRING(str) XMLT(str).getUnicodeStr()
00066 
00067 // --------------------------------------------------------------------------------
00068 //           Utilities to manipulate namespaces
00069 // --------------------------------------------------------------------------------
00070 
00071 const XMLCh DSIG_EXPORT * getDSIGLocalName(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00072 const XMLCh DSIG_EXPORT * getECLocalName(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00073 const XMLCh DSIG_EXPORT * getXPFLocalName(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00074 const XMLCh DSIG_EXPORT * getXENCLocalName(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00075 
00076 // --------------------------------------------------------------------------------
00077 //           Do UTF-8 <-> UTF-16 transcoding
00078 // --------------------------------------------------------------------------------
00079 
00080 XMLCh DSIG_EXPORT * transcodeFromUTF8(const unsigned char * src);
00081 
00082 // --------------------------------------------------------------------------------
00083 //           Find a nominated DSIG/XENC node in a document
00084 // --------------------------------------------------------------------------------
00085 
00086 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findDSIGNode(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, const char * nodeName);
00087 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findXENCNode(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, const char * nodeName);
00088 
00089 // --------------------------------------------------------------------------------
00090 //           Find particular type of node child
00091 // --------------------------------------------------------------------------------
00092 
00093 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findFirstChildOfType(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode::NodeType t);
00094 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findNextChildOfType(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode::NodeType t);
00095 
00096 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DSIG_EXPORT * findFirstElementChild(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n);
00097 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DSIG_EXPORT * findNextElementChild(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n);
00098 
00099 // --------------------------------------------------------------------------------
00100 //           Make a QName
00101 // --------------------------------------------------------------------------------
00102 
00103 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, safeBuffer &prefix, const char * localName);
00104 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, const XMLCh *prefix, const char * localName);
00105 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, const XMLCh *prefix, const XMLCh * localName);
00106 
00107 // --------------------------------------------------------------------------------
00108 //           Gather text from children
00109 // --------------------------------------------------------------------------------
00110 
00111 void DSIG_EXPORT gatherChildrenText(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * parent, safeBuffer &output);
00112 
00113 // --------------------------------------------------------------------------------
00114 //           String decode/encode
00115 // --------------------------------------------------------------------------------
00116 
00117 /*
00118  * Distinguished names have a particular encoding that needs to be performed prior
00119  * to enclusion in the DOM
00120  */
00121 
00122 XMLCh * encodeDName(const XMLCh * toEncode);
00123 XMLCh * decodeDName(const XMLCh * toDecode);
00124 
00125 // --------------------------------------------------------------------------------
00126 //           String Functions 
00127 // --------------------------------------------------------------------------------
00128 
00129 // Remove escape (%XX) characters from URIs and return a new buffer containing the
00130 // "cleaned" string
00131 
00132 XMLCh * cleanURIEscapes(const XMLCh * str);
00133 
00134 inline
00135 bool strEquals (const XMLCh * str1, const XMLCh *str2) {
00136 
00137     return (XMLString::compareString(str1, str2) == 0);
00138 
00139 }
00140 
00141 inline
00142 bool strEquals (const char * str1, const char *str2) {
00143 
00144     return (XMLString::compareString(str1, str2) == 0);
00145 
00146 }
00147 
00148 inline 
00149 bool strEquals (const char * str1, const XMLCh * str2) {
00150 
00151     bool ret;
00152     XMLCh * str1XMLCh = XMLString::transcode(str1);
00153 
00154     if (str1XMLCh != NULL) {
00155 
00156         ret = (XMLString::compareString(str1XMLCh, str2) == 0);
00157         delete str1XMLCh;
00158 
00159     }
00160     else
00161         ret = false;
00162 
00163     return ret;
00164 
00165 }
00166 
00167 inline 
00168 bool strEquals (const XMLCh * str1, const char * str2) {
00169 
00170     bool ret;
00171     XMLCh * str2XMLCh = XMLString::transcode(str2);
00172 
00173     if (str2XMLCh != NULL) {
00174 
00175         ret = (XMLString::compareString(str1, str2XMLCh) == 0);
00176         delete [] str2XMLCh;
00177 
00178     }
00179     else
00180         ret = false;
00181 
00182     return ret;
00183 
00184 }
00185 
00186 #endif /* XSECDOMUTILS_HEADER */
00187 

Generated on Sun Mar 14 21:35:34 2004 for XML-Security-C by doxygen 1.3.2