174664626SKris Kennaway #include <stdio.h> 274664626SKris Kennaway #include <stdlib.h> 374664626SKris Kennaway #include <string.h> 474664626SKris Kennaway #include <openssl/objects.h> 574664626SKris Kennaway #include <openssl/comp.h> 674664626SKris Kennaway 774664626SKris Kennaway COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) 874664626SKris Kennaway { 974664626SKris Kennaway COMP_CTX *ret; 1074664626SKris Kennaway 1174664626SKris Kennaway if ((ret=(COMP_CTX *)Malloc(sizeof(COMP_CTX))) == NULL) 1274664626SKris Kennaway { 1374664626SKris Kennaway /* ZZZZZZZZZZZZZZZZ */ 1474664626SKris Kennaway return(NULL); 1574664626SKris Kennaway } 1674664626SKris Kennaway memset(ret,0,sizeof(COMP_CTX)); 1774664626SKris Kennaway ret->meth=meth; 1874664626SKris Kennaway if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 1974664626SKris Kennaway { 2074664626SKris Kennaway Free(ret); 2174664626SKris Kennaway ret=NULL; 2274664626SKris Kennaway } 2374664626SKris Kennaway #if 0 2474664626SKris Kennaway else 2574664626SKris Kennaway CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); 2674664626SKris Kennaway #endif 2774664626SKris Kennaway return(ret); 2874664626SKris Kennaway } 2974664626SKris Kennaway 3074664626SKris Kennaway void COMP_CTX_free(COMP_CTX *ctx) 3174664626SKris Kennaway { 3274664626SKris Kennaway /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */ 3374664626SKris Kennaway 3474664626SKris Kennaway if(ctx == NULL) 3574664626SKris Kennaway return; 3674664626SKris Kennaway 3774664626SKris Kennaway if (ctx->meth->finish != NULL) 3874664626SKris Kennaway ctx->meth->finish(ctx); 3974664626SKris Kennaway 4074664626SKris Kennaway Free(ctx); 4174664626SKris Kennaway } 4274664626SKris Kennaway 4374664626SKris Kennaway int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 4474664626SKris Kennaway unsigned char *in, int ilen) 4574664626SKris Kennaway { 4674664626SKris Kennaway int ret; 4774664626SKris Kennaway if (ctx->meth->compress == NULL) 4874664626SKris Kennaway { 4974664626SKris Kennaway /* ZZZZZZZZZZZZZZZZZ */ 5074664626SKris Kennaway return(-1); 5174664626SKris Kennaway } 5274664626SKris Kennaway ret=ctx->meth->compress(ctx,out,olen,in,ilen); 5374664626SKris Kennaway if (ret > 0) 5474664626SKris Kennaway { 5574664626SKris Kennaway ctx->compress_in+=ilen; 5674664626SKris Kennaway ctx->compress_out+=ret; 5774664626SKris Kennaway } 5874664626SKris Kennaway return(ret); 5974664626SKris Kennaway } 6074664626SKris Kennaway 6174664626SKris Kennaway int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 6274664626SKris Kennaway unsigned char *in, int ilen) 6374664626SKris Kennaway { 6474664626SKris Kennaway int ret; 6574664626SKris Kennaway 6674664626SKris Kennaway if (ctx->meth->expand == NULL) 6774664626SKris Kennaway { 6874664626SKris Kennaway /* ZZZZZZZZZZZZZZZZZ */ 6974664626SKris Kennaway return(-1); 7074664626SKris Kennaway } 7174664626SKris Kennaway ret=ctx->meth->expand(ctx,out,olen,in,ilen); 7274664626SKris Kennaway if (ret > 0) 7374664626SKris Kennaway { 7474664626SKris Kennaway ctx->expand_in+=ilen; 7574664626SKris Kennaway ctx->expand_out+=ret; 7674664626SKris Kennaway } 7774664626SKris Kennaway return(ret); 7874664626SKris Kennaway } 79