reSIProcate/stack  9694
Pkcs7Contents.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/Pkcs7Contents.hxx"
00006 #include "resip/stack/SipMessage.hxx"
00007 #include "rutil/Logger.hxx"
00008 #include "rutil/ParseBuffer.hxx"
00009 #include "rutil/WinLeakCheck.hxx"
00010 
00011 using namespace resip;
00012 using namespace std;
00013 
00014 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00015 
00016 const Pkcs7Contents Pkcs7Contents::Empty;
00017 const Pkcs7SignedContents Pkcs7SignedContents::Empty;
00018 
00019 bool
00020 Pkcs7Contents::init()
00021 {
00022    static ContentsFactory<Pkcs7Contents> factory;
00023    (void)factory;
00024    return true;
00025 }
00026 
00027 bool
00028 Pkcs7SignedContents::init()
00029 {
00030    static ContentsFactory<Pkcs7SignedContents> factory;
00031    (void)factory;
00032    return true;
00033 }
00034 
00035 Pkcs7Contents::Pkcs7Contents()
00036    : Contents(getStaticType()),
00037      mText()
00038 {
00039 }
00040 
00041 Pkcs7SignedContents::Pkcs7SignedContents()
00042 {
00043 }
00044 
00045 Pkcs7Contents::Pkcs7Contents(const Data& txt)
00046    : Contents(getStaticType()),
00047      mText(txt)
00048 {
00049 }
00050 
00051 Pkcs7SignedContents::Pkcs7SignedContents(const Data& txt)
00052    : Pkcs7Contents(txt, getStaticType())
00053 {
00054 }
00055 
00056 Pkcs7Contents::Pkcs7Contents(const Data& txt, const Mime& contentsType)
00057    : Contents(contentsType),
00058      mText(txt)
00059 {
00060 }
00061  
00062 Pkcs7Contents::Pkcs7Contents(const HeaderFieldValue& hfv, const Mime& contentsType)
00063    : Contents(hfv, contentsType),
00064      mText()
00065 {
00066 }
00067  
00068 Pkcs7SignedContents::Pkcs7SignedContents(const HeaderFieldValue& hfv, const Mime& contentsType)
00069    : Pkcs7Contents(hfv, contentsType)
00070 {
00071 }
00072  
00073 Pkcs7Contents::Pkcs7Contents(const Pkcs7Contents& rhs)
00074    : Contents(rhs),
00075      mText(rhs.mText)
00076 {
00077 }
00078 
00079 Pkcs7SignedContents::Pkcs7SignedContents(const Pkcs7SignedContents& rhs)
00080    : Pkcs7Contents(rhs)
00081 {
00082 }
00083 
00084 Pkcs7Contents::~Pkcs7Contents()
00085 {
00086 }
00087 
00088 Pkcs7SignedContents::~Pkcs7SignedContents()
00089 {
00090 }
00091 
00092 Pkcs7Contents&
00093 Pkcs7Contents::operator=(const Pkcs7Contents& rhs)
00094 {
00095    if (this != &rhs)
00096    {
00097       Contents::operator=(rhs);
00098       mText = rhs.mText;
00099    }
00100    return *this;
00101 }
00102 
00103 Contents* 
00104 Pkcs7Contents::clone() const
00105 {
00106    return new Pkcs7Contents(*this);
00107 }
00108 
00109 Contents* 
00110 Pkcs7SignedContents::clone() const
00111 {
00112    return new Pkcs7SignedContents(*this);
00113 }
00114 
00115 const Mime& 
00116 Pkcs7Contents::getStaticType() 
00117 {
00118    static Mime type("application","pkcs7-mime");
00119    return type;
00120 }
00121 
00122 const Mime& 
00123 Pkcs7SignedContents::getStaticType() 
00124 {
00125    static Mime type("application","pkcs7-signature");
00126    return type;
00127 }
00128 
00129 
00130 EncodeStream& 
00131 Pkcs7Contents::encodeParsed(EncodeStream& str) const
00132 {
00133    //DebugLog(<< "Pkcs7Contents::encodeParsed " << mText);
00134    str << mText;
00135    return str;
00136 }
00137 
00138 
00139 void 
00140 Pkcs7Contents::parse(ParseBuffer& pb)
00141 {
00142    const char* anchor = pb.position();
00143    pb.skipToEnd();
00144    pb.data(mText, anchor);
00145 
00146    if ( mTransferEncoding )
00147    {
00148       InfoLog( << "Transfer Encoding is " << mTransferEncoding->value() );
00149       if ( mTransferEncoding->value() == Data("base64") )
00150       {
00151          Data bin = mText.base64decode();
00152          mText = bin;
00153          InfoLog( << "Base64 decoded to " << mText.escaped() );
00154       }
00155    }
00156    
00157    DebugLog(<< "Pkcs7Contents::parsed <" << mText.escaped() << ">" );
00158 }
00159 
00160 
00161 /* ====================================================================
00162  * The Vovida Software License, Version 1.0 
00163  * 
00164  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00165  * 
00166  * Redistribution and use in source and binary forms, with or without
00167  * modification, are permitted provided that the following conditions
00168  * are met:
00169  * 
00170  * 1. Redistributions of source code must retain the above copyright
00171  *    notice, this list of conditions and the following disclaimer.
00172  * 
00173  * 2. Redistributions in binary form must reproduce the above copyright
00174  *    notice, this list of conditions and the following disclaimer in
00175  *    the documentation and/or other materials provided with the
00176  *    distribution.
00177  * 
00178  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00179  *    and "Vovida Open Communication Application Library (VOCAL)" must
00180  *    not be used to endorse or promote products derived from this
00181  *    software without prior written permission. For written
00182  *    permission, please contact vocal@vovida.org.
00183  *
00184  * 4. Products derived from this software may not be called "VOCAL", nor
00185  *    may "VOCAL" appear in their name, without prior written
00186  *    permission of Vovida Networks, Inc.
00187  * 
00188  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00189  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00190  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00191  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00192  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00193  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00194  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00195  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00196  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00197  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00198  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00199  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00200  * DAMAGE.
00201  * 
00202  * ====================================================================
00203  * 
00204  * This software consists of voluntary contributions made by Vovida
00205  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00206  * Inc.  For more information on Vovida Networks, Inc., please see
00207  * <http://www.vovida.org/>.
00208  *
00209  */