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

Generated on Sun Jan 28 19:37:24 2007 for XML-Security-C by  doxygen 1.4.2