OWBI1_CIMBase.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OWBI1_config.h"
00037 #include "OWBI1_CIMBase.hpp"
00038 #include "OWBI1_Exception.hpp"
00039 #include "OWBI1_String.hpp"
00040 #include "OW_Format.hpp"
00041 #include "OW_Assertion.hpp"
00042 #include "OW_StringStream.hpp"
00043 #include "OW_BinarySerialization.hpp"
00044 #include <cstring>
00045 
00046 namespace OWBI1
00047 {
00048 using namespace OpenWBEM;
00049 using std::istream;
00050 using std::ostream;
00052 // static
00053 void
00054 CIMBase::readSig( istream& istr, const char* const sig )
00055 {
00056    char expected, read;
00057    OW_ASSERT( strlen(sig) == 1 );
00058    expected = sig[0];
00059    BinarySerialization::read(istr, &read, sizeof(read));
00060    if (expected != read)
00061    {
00062       OWBI1_THROW_ERR(BadCIMSignatureException,
00063          Format("Signature does not match. In CIMBase::readSig. signature read: %1, expected: %2",
00064             read, sig).c_str(), E_UNEXPECTED_SIGNATURE);
00065    }
00066 }
00068 // static
00069 UInt32
00070 CIMBase::readSig(std::istream& istr, const char* const sig,
00071    const char* const verSig, UInt32 maxVersion)
00072 {
00073    UInt32 version = 0;
00074    char ch;
00075    OW_ASSERT( strlen(sig) == 1);
00076    OW_ASSERT( strlen(verSig) == 1);
00077 
00078    BinarySerialization::read(istr, &ch, sizeof(ch));
00079    if (sig[0] != ch)
00080    {
00081       if (verSig[0] != ch)
00082       {
00083          OWBI1_THROW_ERR(BadCIMSignatureException,
00084             Format("Signature does not match. In CIMBase::readSig. "
00085                "signature read: %1, expected: %2 or %3",
00086                ch, sig, verSig).c_str(), E_UNEXPECTED_SIGNATURE);
00087       }
00088 
00089       // Version is ASN.1 length encoded
00090       BinarySerialization::readLen(istr, version);
00091       if (version > maxVersion)
00092       {
00093          OWBI1_THROW_ERR(BadCIMSignatureException,
00094             Format("CIMBase::readSig. Unknown version %1, only versions <= %2 are handled.",
00095             version, maxVersion).c_str(), E_UNKNOWN_VERSION);
00096       }
00097    }
00098 
00099    return version;
00100 }
00101 
00103 // static
00104 void
00105 CIMBase::writeSig( ostream& ostr, const char* const sig )
00106 {
00107    OW_ASSERT(strlen(sig) == 1);
00108    BinarySerialization::write(ostr, sig, 1);
00109 }
00111 // static
00112 void
00113 CIMBase::writeSig(std::ostream& ostr, const char* const sig, UInt32 version)
00114 {
00115    OW_ASSERT(strlen(sig) == 1);
00116    BinarySerialization::write(ostr, sig, 1);
00117    // Use ASN.1 length encoding for version
00118    BinarySerialization::writeLen(ostr, version);
00119 }
00120 
00122 std::ostream& operator<<(std::ostream& ostr, const CIMBase& cb)
00123 {
00124    ostr << cb.toString();
00125    return ostr;
00126 }
00128 CIMBase::~CIMBase()
00129 {
00130 }
00131 
00132 } // end namespace OWBI1
00133 

Generated on Thu Feb 9 08:48:25 2006 for openwbem by  doxygen 1.4.6