メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcTelecomConfirmFile.c

説明を見る。

    00001
    00008 #define  DKUTIL_C_TELECOM_CONFIRM_FILE_C
    00009 #include "dkcTelecomConfirmFile.h"
    00010 #include "dkcMath.h"
    00011
    00012
    00013 #if 0
    00014
    00015
    00016 DKC_INLINE DKC_TELECOM_CONFIRM_FILE* WINAPI dkcAllocTelecomConfirmFileGenerate(uint32 version,size_t lzw_output_block_size)
    00017 {
    00018     DKC_TELECOM_CONFIRM_FILE *p;
    00019     if(dkcmTelecomConfirmFileVersionError(version)){return NULL;}
    00020     p = dkcAllocate(sizeof(DKC_TELECOM_CONFIRM_FILE));
    00021     if(NULL==p){return NULL;}
    00022
    00023
    00024     p->mLZW = dkcAllocLZW(lzw_output_block_size);
    00025     //if(NULL==p->mLZW ) goto Error;
    00026     p->mMD5 = dkcAllocMD5();
    00027     //if(NULL==p->mMD5) goto Error;
    00028
    00029     p->mSHA512 = dkcAllocSHA512();
    00030     p->mBuff = dkcAllocBuffer(NULL,dkcdTELECOM_CONFIRM_FILE_BEGIN_BUFFER_SIZE);
    00031     if(NULL==p->mSHA512 || NULL==p->mMD5 || NULL==p->mLZW || NULL==p->mBuff){
    00032         goto Error;
    00033     }
    00034     p->version = version;
    00035     p->block_num = 0;
    00036     p->lzw_output_block_size = lzw_output_block_size;
    00037     return p;
    00038 Error:
    00039     dkcFreeTelecomConfirmFile(&p);
    00040     return NULL;
    00041 }
    00042
    00043 DKC_INLINE DKC_TELECOM_CONFIRM_FILE *WINAPI dkcAllocTelecomConfirmFileExtract(DKC_STREAM *input)
    00044 {
    00045
    00046
    00047 }
    00048
    00049 DKC_INLINE int WINAPI dkcFreeTelecomConfirmFile(DKC_TELECOM_CONFIRM_FILE **pp){
    00050
    00051     DKC_TELECOM_CONFIRM_FILE *p = *pp;
    00052     if(NULL==pp || NULL==p) return edk_FAILED;
    00053     if(p->mBuff){dkcFreeBuffer(&(p->mBuff));}
    00054     if(p->mLZW){dkcFreeLZW(&(p->mLZW));}
    00055     if(p->mMD5){dkcFreeMD5(&(p->mMD5));}
    00056     if(p->mSHA512){dkcFreeSHA512(&(p->mSHA512));}
    00057     return dkcFree(&p);
    00058 }
    00059
    00060 DKC_INLINE int WINAPI dkcTelecomConfirmFileInit(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *pstream)
    00061 {
    00062     int r;
    00063     dkcMD5Init(p->mMD5);
    00064     dkcSHA512Init(p->mSHA512);
    00065     r = dkcBufferResize(p->mBuff,dkcdTELECOM_CONFIRM_FILE_BEGIN_BUFFER_SIZE);
    00066     if(DKUTIL_FAILED(r)) return r;
    00067     if(pstream){
    00068         dkcmFAILED_CHECK_RETURN(r,dkcStreamSeek(pstream,0,edkcStreamSeekSet));
    00069     }
    00070     p->block_num = 0;
    00071     return edk_SUCCEEDED;
    00072 }
    00073
    00074 DKC_INLINE int WINAPI dkcTelecomConfirmFileGenerateBegin(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *output)
    00075 {
    00076
    00077     if(0 != dkcStreamTell(output)){
    00078         return edk_LogicError;
    00079     }
    00080     r = dkcStreamSeek(output,sizeof(DKC_TELECOM_CONFIRM_FILE_HEADER01),edkcStreamCurrent);
    00081     if(DKUTIL_FAILED(r)) return r;
    00082     return r;
    00083 }
    00084
    00085 static DKC_INLINE int tcpf_generate_output_block_version01(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *output,const uint8 *src,size_t ssize)
    00086 {
    00087     int r;
    00088     DKC_LZW_HEADER lzw_header;
    00089     DKC_TELECOM_CONFIRM_FILE_BLOCK01 block;
    00090
    00091     if(p->mBuff->mSize < ssize){
    00092         r = dkcBufferResize(p->mBuff,ssize);
    00093         if(DKUTIL_FAILED(r)){
    00094             return r;
    00095         }
    00096     }
    00097
    00098     dkcSHA512Load(p->mSHA512,src,ssize);
    00099
    00100     {
    00101
    00102         dkcMD5Init(p->mMD5);
    00103         dkcmFAILED_CHECK_RETURN(r,dkcMD5Load(p->mMD5,src,ssize));
    00104         dkcmFAILED_CHECK_RETURN(r,dkcMD5FinalDigest(p->mMD5,block.origin_md5,sizeof(block.origin_md5)));
    00105
    00106
    00107     }
    00108
    00109     r = dkcLZWEncode(p->mLZW,&lzw_header,p->mBuff->mBuff,p->mBuff->mSize,
    00110         src,ssize,UINT_MAX,'LZW',edkcLZW_Default);
    00111
    00112     if(DKUTIL_FAILED(r)) return r;
    00113
    00114
    00115     {
    00116
    00117         dkcMD5Init(p->mMD5);
    00118         dkcmFAILED_CHECK_RETURN(r,dkcMD5Load(p->mMD5,p->mBuff->mBuff,lzw_header.mCompressedSize));
    00119         dkcmFAILED_CHECK_RETURN(r,dkcMD5FinalDigest(p->mMD5,block.compress_md5,sizeof(block.compress_md5)));
    00120
    00121     }
    00122     memcpy(&(block.lzw_header),&lzw_header,sizeof(block.lzw_header));
    00123     dkcmFAILED_CHECK_RETURN(r,dkcStreamWrite(output,&block,sizeof(block)));
    00124     dkcmFAILED_CHECK_RETURN(r,dkcStreamWrite(output,p->mBuff->mBuff,lzw_header.mCompressedSize);
    00125
    00126     p->block_num++;
    00127     return edk_SUCCEEDED;
    00128 }
    00129
    00130 DKC_INLINE int WINAPI dkcTelecomConfirmFileGenerateOutputBlock(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *output,const uint8 *src,size_t ssize)
    00131 {
    00132     int r;
    00133     switch(p->version){
    00134     case edkcTelecomConfirmFileVersion01:
    00135         r = tcpf_generate_output_block_version01(p,output,src,ssize);
    00136         break;
    00137     default:
    00138         return edk_LogicError;
    00139     }
    00140     return r;
    00141 }
    00142 static DKC_INLINE int tcpf_generate_final(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *output)
    00143 {
    00144     int r;
    00145     DKC_TELECOM_CONFIRM_FILE_HEADER01 header;
    00146     uint64 length = dkcStreamTell64(output);
    00147     dkcmFAILED_CHECK_RETURN(r,dkcStreamSeek(output,0,edkcStreamSeekSet));
    00148     dkcSHA512FinalDigest(p->mSHA512,header.origin_sig,sizeof(header.origin_sig));
    00149     header.lzw_output_block_size = p->lzw_output_block_size;
    00150     header.length
    00151
    00152 }
    00153
    00154 DKC_INLINE int WINAPI dkcTelecomConfirmFileGenerateFinal(DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *output)
    00155 {
    00156     int r;
    00157     switch(p->version){
    00158     case edkcTelecomConfirmFileVersion01:
    00159         r = tcpf_generate_final(p,output);
    00160         break;
    00161     default:
    00162         return edk_LogicError;
    00163     }
    00164     return r;
    00165
    00166 }
    00167
    00168
    00169 DKC_INLINE int WINAPI dkcTelecomConfirmFileGetHeader(DKC_STREAM *input,DKC_TELECOM_CONFIRM_FILE_HEADER *header);
    00170
    00171 DKC_INLINE int WINAPI dkcTelecomConfirmFileGetBlock(DKC_STREAM *input,DKC_TELECOM_CONFIRM_FILE_BLOCK *block);
    00172
    00173
    00174 DKC_INLINE int WINAPI dkcTelecomConfirmFileExtractOutputBlock(
    00175     DKC_TELECOM_CONFIRM_FILE *p,DKC_STREAM *input,const DKC_TELECOM_CONFIRM_FILE_BLOCK *block,
    00176     uint8 *buff,size_t buffsize
    00177 );
    00178
    00179
    00180 DKC_INLINE int WINAPI dkcTelecomConfirmFileEncode(const char *dest_filename,const char *src_filename);
    00181
    00182
    00183 DKC_INLINE int WINAPI dkcTelecomConfirmFileDecode(const char *dest_filename,const char *src_filename);
    00184
    00185
    00186 DKC_INLINE size_t WINAPI dkcTelecomConfirmFileGetDecodeSize(const char *filename);
    00187
    00188 #endif