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

XSECDOMUtils.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 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  * limitations 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.20 2005/02/26 10:12:31 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 const XMLCh DSIG_EXPORT * getXKMSLocalName(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
00076 
00077 // --------------------------------------------------------------------------------
00078 //           Do UTF-8 <-> UTF-16 transcoding
00079 // --------------------------------------------------------------------------------
00080 
00081 XMLCh DSIG_EXPORT * transcodeFromUTF8(const unsigned char * src);
00082 
00083 // --------------------------------------------------------------------------------
00084 //           Find a nominated DSIG/XENC node in a document
00085 // --------------------------------------------------------------------------------
00086 
00087 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findDSIGNode(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, const char * nodeName);
00088 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findXENCNode(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, const char * nodeName);
00089 
00090 // --------------------------------------------------------------------------------
00091 //           Find particular type of node child
00092 // --------------------------------------------------------------------------------
00093 
00094 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findFirstChildOfType(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode::NodeType t);
00095 XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DSIG_EXPORT * findNextChildOfType(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode::NodeType t);
00096 
00097 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DSIG_EXPORT * findFirstElementChild(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n);
00098 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DSIG_EXPORT * findNextElementChild(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *n);
00099 
00100 // --------------------------------------------------------------------------------
00101 //           Make a QName
00102 // --------------------------------------------------------------------------------
00103 
00104 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, safeBuffer &prefix, const char * localName);
00105 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, const XMLCh *prefix, const char * localName);
00106 safeBuffer DSIG_EXPORT &makeQName(safeBuffer & qname, const XMLCh *prefix, const XMLCh * localName);
00107 
00108 // --------------------------------------------------------------------------------
00109 //           Gather text from children
00110 // --------------------------------------------------------------------------------
00111 
00112 void DSIG_EXPORT gatherChildrenText(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * parent, safeBuffer &output);
00113 
00114 // --------------------------------------------------------------------------------
00115 //           String decode/encode
00116 // --------------------------------------------------------------------------------
00117 
00118 /*
00119  * Distinguished names have a particular encoding that needs to be performed prior
00120  * to enclusion in the DOM
00121  */
00122 
00123 XMLCh * encodeDName(const XMLCh * toEncode);
00124 XMLCh * decodeDName(const XMLCh * toDecode);
00125 
00126 // --------------------------------------------------------------------------------
00127 //           Generate Ids
00128 // --------------------------------------------------------------------------------
00129 
00130 XMLCh DSIG_EXPORT * generateId(unsigned int bytes = 16);
00131 
00132 // --------------------------------------------------------------------------------
00133 //           String Functions 
00134 // --------------------------------------------------------------------------------
00135 
00136 // Remove escape (%XX) characters from URIs and return a new buffer containing the
00137 // "cleaned" string
00138 
00139 XMLCh * cleanURIEscapes(const XMLCh * str);
00140 
00141 inline
00142 bool strEquals (const XMLCh * str1, const XMLCh *str2) {
00143 
00144     return (XMLString::compareString(str1, str2) == 0);
00145 
00146 }
00147 
00148 inline
00149 bool strEquals (const char * str1, const char *str2) {
00150 
00151     return (XMLString::compareString(str1, str2) == 0);
00152 
00153 }
00154 
00155 inline 
00156 bool strEquals (const char * str1, const XMLCh * str2) {
00157 
00158     bool ret;
00159     XMLCh * str1XMLCh = XMLString::transcode(str1);
00160 
00161     if (str1XMLCh != NULL) {
00162 
00163         ret = (XMLString::compareString(str1XMLCh, str2) == 0);
00164         XSEC_RELEASE_XMLCH(str1XMLCh);
00165 
00166     }
00167     else
00168         ret = false;
00169 
00170     return ret;
00171 
00172 }
00173 
00174 inline 
00175 bool strEquals (const XMLCh * str1, const char * str2) {
00176 
00177     bool ret;
00178     XMLCh * str2XMLCh = XMLString::transcode(str2);
00179 
00180     if (str2XMLCh != NULL) {
00181 
00182         ret = (XMLString::compareString(str1, str2XMLCh) == 0);
00183         XSEC_RELEASE_XMLCH(str2XMLCh);
00184 
00185     }
00186     else
00187         ret = false;
00188 
00189     return ret;
00190 
00191 }
00192 
00193 #endif /* XSECDOMUTILS_HEADER */
00194 

Generated on Sun Jul 3 17:37:28 2005 for XML-Security-C by  doxygen 1.4.2