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

XSECSafeBuffer.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  * XSECSafeBuffer := a class for storing expanding amounts of information.
00021  *
00022  * Author(s): Berin Lautenbach
00023  *
00024  * $Id: XSECSafeBuffer.hpp,v 1.15 2005/02/03 13:53:54 milan Exp $
00025  *                   
00026  */
00027 
00028 
00029 #ifndef XSECSAFEBUFFER_INCLUDE
00030 #define XSECSAFEBUFFER_INCLUDE
00031 
00032 #include <xsec/framework/XSECDefs.hpp>
00033 #include <xercesc/util/XMLString.hpp>
00034 
00035 class TXFMBase;
00036 
00043 #define DEFAULT_SAFE_BUFFER_SIZE        1024        // Default size for a safe Buffer
00044 
00061 class CANON_EXPORT safeBuffer {
00062 
00063 public:
00064 
00065     // For checking we are operating on the buffer correctly
00066     enum bufferType {
00067 
00068         BUFFER_UNKNOWN      = 0,
00069         BUFFER_CHAR         = 1,
00070         BUFFER_UNICODE      = 2
00071     };
00072 
00073 
00074     safeBuffer();
00075     safeBuffer(int initialSize);
00076     safeBuffer(const char * inStr, unsigned int initialSize = DEFAULT_SAFE_BUFFER_SIZE);
00077     safeBuffer(const safeBuffer & other);
00078 
00079     ~safeBuffer();
00080 
00081     static void init(void);
00082 
00083     // "IN" functions - these read in information to the buffer
00084 
00085     void sbStrcpyIn(const char * inStr);
00086     void sbStrcpyIn(const safeBuffer & inStr);
00087     void sbStrncpyIn(const char * inStr, int n);
00088     void sbStrncpyIn(const safeBuffer & inStr, int n);
00089     void sbStrcatIn(const char * inStr);
00090     void sbStrcatIn(const safeBuffer & inStr);
00091     void sbStrncatIn(const char * inStr, int n);
00092     void sbStrinsIn(const char * inStr, unsigned int offset);
00093 
00094     void sbMemcpyIn(const void * inBuf, int n);
00095     void sbMemcpyIn(int offset, const void * inBuf, int n);
00096 
00097     void sbMemcpyOut(void * outBuf, int n) const;
00098     void sbMemshift(int toOffset, int fromOffset, int len);
00099 
00100     // Comparison functions
00101 
00102     int sbStrncmp(const char * inStr, int n) const;
00103     int sbOffsetStrcmp(const char * inStr, unsigned int offset) const;
00104     int sbOffsetStrncmp(const char * inStr, unsigned int offset, int n) const;
00105     int sbStrcmp(const char * inStr) const;
00106     int sbStrcmp(const safeBuffer & inStr) const;
00107     int sbStrstr(const char * inStr) const;
00108     int sbOffsetStrstr(const char * inStr, unsigned int offset) const;
00109 
00110     // XMLCh versions
00111     int sbStrstr(const XMLCh * inStr) const;
00112     void sbStrinsIn(const XMLCh * inStr, unsigned int offset);
00113 
00114     // XMLCh and char common functions
00115     void sbStrlwr(void);        // Lowercase the string
00116 
00117     // Operators
00118 
00119     unsigned char & operator[](int n);
00120     safeBuffer & operator= (const safeBuffer & cpy);
00121     safeBuffer & operator= (const XMLCh * inStr);
00122     safeBuffer & operator << (TXFMBase * t);
00123 
00124     // Get functions
00125 
00126     int sbStrlen(void) const;
00127     unsigned int sbRawBufferSize(void) const;
00128 
00129     // raw buffer manipulation
00130 
00131     const unsigned char * rawBuffer() const;
00132     const char * rawCharBuffer() const;
00133     const XMLCh * rawXMLChBuffer() const;
00134     void resize(unsigned int sz);           // NOTE : Only grows
00135     void setBufferType(bufferType bt);      // Use with care
00136 
00137     // Unicode (UTF-16 manipulation)
00138     const XMLCh * sbStrToXMLCh(void);           // Note does not affect internal buffer
00139     void sbTranscodeIn(const XMLCh * inStr);    // Create a local string from UTF-16
00140     void sbTranscodeIn(const char * inStr);     // Create a UTF-16 string from local
00141     void sbXMLChIn(const XMLCh * in);           // Buffer holds XMLCh *
00142     void sbXMLChAppendCh(const XMLCh c);        // Append a Unicode character to the buffer
00143     void sbXMLChCat(const XMLCh *str);          // Append a UTF-16 string to the buffer
00144     void sbXMLChCat(const char * str);          // Append a (transcoded) local string to the buffer
00145     void sbXMLChCat8(const char * str);         // Append a (transcoded) UTF-8 string to the buffer
00146 
00147     // Sensitive data functions
00148     void isSensitive(void);
00149     void cleanseBuffer(void);
00150 
00151 private:
00152 
00153     // Internal function that is used to get a string size and 
00154     // then re-allocate if necessary
00155 
00156     void checkAndExpand(unsigned int size);
00157     void checkBufferType(bufferType bt) const;
00158 
00159     unsigned char * buffer;
00160     unsigned int    bufferSize;
00161     XMLCh           * mp_XMLCh;
00162     bufferType      m_bufferType;
00163 
00164     // For XMLCh manipulation
00165     static size_t   size_XMLCh;
00166 
00167     // For sensitive data
00168     bool            m_isSensitive;
00169 };
00170 
00173 #endif /* XSECSAFEBUFFER_INCLUDE */
00174 

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