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
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
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
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
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
00215
00216
00217
00218
00219
00220
00221
00222
00223
00225
00226
00228
00229
00230
00231
00232
00233
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
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 }