ContentCollection.cpp

Go to the documentation of this file.
00001 
00009 #include "ContentInfo.h"
00010 #include "ContentCollection.h"
00011 
00012 #include "PKIFMessageException.h"
00013 #include "ASN1Helper.h"
00014 #include "ContentCollectionModule.h"
00015 #include "ToolkitUtils.h"
00016 #include "PKIFMessageErrors.h"
00017 #include "PKIFCMSUtils.h"
00018 
00019 #include "OID.h"
00020 #include "Buffer.h"
00021 #include "PKIFBase64.h"
00022 
00024 struct CPKIFContentCollectionImpl
00025 {
00026     CPKIFContentInfoList m_contentInfoList;
00027 };
00029 
00037 CPKIFContentCollection::CPKIFContentCollection()
00038     :m_impl (new CPKIFContentCollectionImpl)
00039 {
00040     LOG_STRING_DEBUG("CPKIFContentCollection::CPKIFContentCollection()", TOOLKIT_MESSAGE_CONTENT_INFO, 0, this);
00041     SetContentType(g_contentCollection);
00042 }
00050 CPKIFContentCollection::~CPKIFContentCollection()
00051 {
00052     LOG_STRING_DEBUG("CPKIFContentCollection::~CPKIFContentCollection()", TOOLKIT_MESSAGE_CONTENT_INFO, 0, this);
00053 
00054     delete m_impl;
00055     m_impl = NULL;
00056 }
00057 
00065 void CPKIFContentCollection::SetContentList(
00067     CPKIFContentInfoList& contentList) 
00068 {
00069     m_impl->m_contentInfoList = contentList;
00070 }
00077 void CPKIFContentCollection::GetContentList(
00079      CPKIFContentInfoList& contentList) const 
00080 {
00081     contentList = m_impl->m_contentInfoList;
00082 }
00083 
00096 void CPKIFContentCollection::Decode(
00098     const unsigned char* buf,
00100     int bufLen)
00101 {
00102     LOG_STRING_DEBUG("CPKIFContentCollection::Decode(const unsigned char* buf, int bufLen)", TOOLKIT_MESSAGE_CONTENT_INFO, 0, this);
00103 
00104     //if the input is empty - fail now
00105     if(NULL == buf || 0 == bufLen)
00106     {
00107         throw CPKIFMessageException(thisComponent, COMMON_INVALID_INPUT, "NULL parameter passed to CPKIFContentCollection::Decode");
00108     }
00109 
00110     try
00111     {
00112         //otherwise, try to parse (the decode function may throw)
00113         CPKIFASNWrapper<ContentCollection> cmsMsg(BEREncContentCollection, BERDecContentCollection);
00114         cmsMsg.Decode(buf, bufLen);
00115 
00116         DListNode * curr = cmsMsg->head;
00117         while(curr != NULL)
00118         {
00119             CACCMSContentInfo *tmp = (CACCMSContentInfo*)curr->data;
00120 
00121             CPKIFOIDPtr tmpOID(new CPKIFOID(tmp->contentType.subid, tmp->contentType.numids));
00122             CPKIFBufferPtr tmpBuff(new CPKIFBuffer(tmp->content.data, tmp->content.numocts));
00123             CPKIFContentInfoPtr ci(new CPKIFContentInfo(tmpOID, tmpBuff));
00124 
00125 
00126             m_impl->m_contentInfoList.push_back(ci);
00127             curr = curr->next;
00128         }
00129     }
00130     catch(CPKIFException& e)
00131     {
00132         unsigned char * decoded = NULL;
00133         unsigned long decodedLen;
00134         bool b = PEMDecode((char *)buf, &decoded, &decodedLen);
00135         if(b)
00136         {
00137             try
00138             {
00139                 CPKIFASNWrapper<ContentCollection> cmsMsg(BEREncContentCollection, BERDecContentCollection);
00140                 cmsMsg.Decode(decoded, decodedLen);
00141 
00142                 DListNode * curr = cmsMsg->head;
00143                 while(curr != NULL)
00144                 {
00145                     CACCMSContentInfo *tmp = (CACCMSContentInfo*)curr->data;
00146 
00147                     CPKIFOIDPtr tmpOID(new CPKIFOID(tmp->contentType.subid, tmp->contentType.numids));
00148                     CPKIFBufferPtr tmpBuff(new CPKIFBuffer(tmp->content.data, tmp->content.numocts));
00149                     CPKIFContentInfoPtr ci(new CPKIFContentInfo(tmpOID, tmpBuff));
00150 
00151 
00152                     m_impl->m_contentInfoList.push_back(ci);
00153                     curr = curr->next;
00154                 }
00155                 if(NULL != decoded)
00156                     delete decoded;
00157 
00158             }catch(CPKIFException& e)
00159             {
00160                 if(NULL != decoded)
00161                     delete decoded;
00162 
00163                 CPKIFMessageException me(thisComponent, MSG_DECODE_FAILED);
00164                 me.push_info(e);
00165                 //delete e;
00166                 throw me;
00167             }
00168         }
00169         else
00170         {
00171             if(NULL != decoded)
00172                 delete decoded;
00173 
00174             CPKIFMessageException me(thisComponent, MSG_DECODE_FAILED);
00175             me.push_info(e);
00176             //delete e;
00177             throw me;
00178         }
00179     }
00180 }
00191 void CPKIFContentCollection::Decode(
00193     CPKIFBufferPtr& buf)
00194 {
00195     if(buf == (CPKIFBuffer*)NULL)
00196     {
00197         throw CPKIFMessageException(thisComponent, COMMON_INVALID_INPUT, "NULL parameter passed to CPKIFContentCollection::Decode");
00198     }
00199 
00200     Decode(buf->GetBuffer(), buf->GetLength());
00201 }
00214 //CPKIFBufferPtr CPKIFContentCollection::Encode()
00215 //{
00216 //  LOG_STRING_DEBUG("CPKIFContentCollection::Encode()", TOOLKIT_MESSAGE_CONTENT_INFO, 0, this);
00217 
00218     //if we don't have a content OID and content then fail
00219     //if(m_impl->m_contentType == (CPKIFOID*)NULL || m_impl->m_content == (CPKIFBuffer*)NULL)
00220     //{
00221     //  throw CPKIFMessageException(thisComponent, MSG_INCOMPLETE);
00222     //}
00223 
00225     //CACCMSContentInfo cmsMsg;
00226 
00228     //CPKIFStringPtr str(new std::string(m_impl->m_contentType->ToString())); 
00229     //ASN1OBJID* tmpOid = ConvertStringToASN1OBJID(str);
00230     //CopyOID(&cmsMsg.contentType, tmpOid);
00231 
00232     //if(NULL != tmpOid)
00233     //  delete tmpOid;
00236     //cmsMsg.content.data = m_impl->m_content->GetBuffer();
00237     //cmsMsg.content.numocts = m_impl->m_content->GetLength();
00238 
00239     //ASN1OpenType* data = NULL;
00240 
00241     //try
00242     //{
00243     //  //encode the message
00244     //  CACASNWRAPPER_CREATE(CACCMSContentInfo, objPDU);
00245     //  data = objPDU.Encode(&cmsMsg);
00246 
00247     //  //return a CPKIFBufferPtr containing the encoded message
00248     //  CPKIFBufferPtr tmp(new CPKIFBuffer(data->data, data->numocts));
00249     //  delete data;
00250     //  return tmp;
00251     //}
00252     //catch(CPKIFException& e)
00253     //{
00254     //  CPKIFMessageException me(thisComponent, MSG_ENCODE_FAILED);
00255     //  me.push_info(e);
00256     //  //delete e;
00257     //  throw me;
00258     //}
00259 //}
00260 
00261 CPKIFBufferPtr CPKIFContentCollection::Encode()
00262 {
00263     RAISE_MESSAGE_EXCEPTION("Content collection creation is not supported in this version.", thisComponent, COMMON_NOT_IMPLEMENTED, this);
00264 }

Generated on Mon Nov 15 11:15:47 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6