Mixe for Privacy and Anonymity in the Internet
CADataRetentionLog.cpp
Go to the documentation of this file.
00001 #include "StdAfx.h"
00002 #ifdef DATA_RETENTION_LOG
00003 #include "CADataRetentionLog.hpp"
00004 
00005 CADataRetentionLog::CADataRetentionLog()
00006   {
00007     m_pLogFile=NULL;
00008     m_pPublicEncryptionKey=NULL;
00009     m_strLogDir=NULL;
00010   }
00011 
00012 CADataRetentionLog::~CADataRetentionLog()
00013   {
00014     closeLog();
00015     delete[] m_strLogDir;
00016   }
00017 
00018 SINT32 CADataRetentionLog::setPublicEncryptionKey(CAASymCipher* pPublicKey)
00019   {
00020     m_pPublicEncryptionKey=pPublicKey;
00021     return E_SUCCESS;
00022   }
00023 
00024 SINT32 CADataRetentionLog::setLogDir(UINT8* strDir)
00025   {
00026     UINT32 l=strlen((char*)strDir);
00027     m_strLogDir=new UINT8[l+1];
00028     memcpy(m_strLogDir,strDir,l);
00029     m_strLogDir[l]=0;
00030     m_max_t_out=0;
00031     return E_SUCCESS;
00032   }
00033 
00034 SINT32 CADataRetentionLog::openLogFile(UINT32 time)
00035   {
00036     m_pLogFile=new CADataRetentionLogFile();
00037     if(m_pLogFile->openLog(m_strLogDir,time,m_pPublicEncryptionKey)!=E_SUCCESS)
00038       return E_UNKNOWN;
00039     m_max_t_out=m_pLogFile->getMaxLogTime();
00040     return E_SUCCESS;
00041   }
00042 
00043 SINT32 CADataRetentionLog::closeLog()
00044   {
00045     if(m_pLogFile!=NULL)
00046       {
00047         m_pLogFile->closeLog();
00048         delete m_pLogFile;
00049         m_pLogFile=NULL;
00050       }
00051     return E_SUCCESS;
00052   }
00053 
00054 SINT32 CADataRetentionLog::log(t_dataretentionLogEntry* logEntry)
00055   {
00056     if(ntohl(logEntry->t_out)>m_max_t_out)
00057       {
00058         if(m_pLogFile!=NULL)
00059           {
00060             m_pLogFile->closeLog();
00061             delete m_pLogFile;
00062             m_pLogFile=NULL;
00063           }
00064         if(openLogFile(ntohl(logEntry->t_out))!=E_SUCCESS)
00065           return E_UNKNOWN;
00066       }
00067     return m_pLogFile->log(logEntry);
00068   }
00069 #endif //DATA_RETENTION_LOG