Skip to content

Commit

Permalink
tls: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 68fe076 commit d253dcd
Show file tree
Hide file tree
Showing 32 changed files with 3,803 additions and 3,497 deletions.
140 changes: 67 additions & 73 deletions src/modules/tls/fixed_c_zlib.h
Expand Up @@ -43,19 +43,19 @@


/* alloc functions for zlib initialization */
static void* comp_calloc(void* foo, unsigned int no, unsigned int size)
static void *comp_calloc(void *foo, unsigned int no, unsigned int size)
{
void *p;

p=OPENSSL_malloc(no*size);
if (p)
memset(p, 0, no*size);
p = OPENSSL_malloc(no * size);
if(p)
memset(p, 0, no * size);
return p;
}


/* alloc functions for zlib initialization */
static void comp_free(void* foo, void* p)
static void comp_free(void *foo, void *p)
{
OPENSSL_free(p);
}
Expand All @@ -69,15 +69,15 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
unsigned int olen, unsigned char *in, unsigned int ilen);


static COMP_METHOD zlib_method={
NID_zlib_compression,
LN_zlib_compression,
zlib_stateful_init,
zlib_stateful_finish,
zlib_stateful_compress_block,
zlib_stateful_expand_block,
NULL,
NULL,
static COMP_METHOD zlib_method = {
NID_zlib_compression,
LN_zlib_compression,
zlib_stateful_init,
zlib_stateful_finish,
zlib_stateful_compress_block,
zlib_stateful_expand_block,
NULL,
NULL,
};


Expand All @@ -87,57 +87,56 @@ struct zlib_state
z_stream ostream;
};

static int* pzlib_stateful_ex_idx = 0;
static int *pzlib_stateful_ex_idx = 0;
#define zlib_stateful_ex_idx (*pzlib_stateful_ex_idx)

static void zlib_stateful_free_ex_data(void *obj, void *item,
CRYPTO_EX_DATA *ad, int ind,long argl, void *argp);
CRYPTO_EX_DATA *ad, int ind, long argl, void *argp);

int fixed_c_zlib_init()
{
if (pzlib_stateful_ex_idx==0){
if ((pzlib_stateful_ex_idx=OPENSSL_malloc(sizeof(int)))!=0){
if(pzlib_stateful_ex_idx == 0) {
if((pzlib_stateful_ex_idx = OPENSSL_malloc(sizeof(int))) != 0) {
/* good side effect: it makes sure the ex_data hash
* in crypto/ex_data.c is created before fork
* (else each process would have its own copy :-( ) */
CRYPTO_w_lock(CRYPTO_LOCK_COMP);
zlib_stateful_ex_idx =
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
zlib_stateful_ex_idx = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
0, NULL, NULL, NULL, zlib_stateful_free_ex_data);
CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
return 0;
} else return -1;
} else
return -1;
}
return -1;
}



static void zlib_stateful_free_ex_data(void *obj, void *item,
CRYPTO_EX_DATA *ad, int ind,long argl, void *argp)
CRYPTO_EX_DATA *ad, int ind, long argl, void *argp)
{
struct zlib_state *state = (struct zlib_state *)item;
if (state)
{
if(state) {
inflateEnd(&state->istream);
deflateEnd(&state->ostream);
OPENSSL_free(state);
}
else LM_CRIT("WARNING: zlib_stateful_free_ex(%p, %p, %p, %d, %ld, %p)"
": cannot free, null item/state\n", obj, item, ad, ind, argl, argp);
} else
LM_CRIT("WARNING: zlib_stateful_free_ex(%p, %p, %p, %d, %ld, %p)"
": cannot free, null item/state\n",
obj, item, ad, ind, argl, argp);
}

static int zlib_stateful_init(COMP_CTX *ctx)
{
int err;
struct zlib_state *state =
(struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));
(struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));
int inflate_init, deflate_init;

if (state == NULL)
if(state == NULL)
goto err;
inflate_init=0;
deflate_init=0;
inflate_init = 0;
deflate_init = 0;

state->istream.zalloc = comp_calloc;
state->istream.zfree = comp_free;
Expand All @@ -146,11 +145,10 @@ static int zlib_stateful_init(COMP_CTX *ctx)
state->istream.next_out = Z_NULL;
state->istream.avail_in = 0;
state->istream.avail_out = 0;
err = inflateInit_(&state->istream,
ZLIB_VERSION, sizeof(z_stream));
if (err != Z_OK)
err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
if(err != Z_OK)
goto err;
inflate_init=1;
inflate_init = 1;

state->ostream.zalloc = comp_calloc;
state->ostream.zfree = comp_free;
Expand All @@ -159,36 +157,34 @@ static int zlib_stateful_init(COMP_CTX *ctx)
state->ostream.next_out = Z_NULL;
state->ostream.avail_in = 0;
state->ostream.avail_out = 0;
err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION,
ZLIB_VERSION, sizeof(z_stream));
if (err != Z_OK)
err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION, ZLIB_VERSION,
sizeof(z_stream));
if(err != Z_OK)
goto err;
deflate_init=1;
deflate_init = 1;

if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data))
if(!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data))
goto err;
if (zlib_stateful_ex_idx == -1)
{
if(zlib_stateful_ex_idx == -1) {
CRYPTO_w_lock(CRYPTO_LOCK_COMP);
if (zlib_stateful_ex_idx == -1)
zlib_stateful_ex_idx =
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
if(zlib_stateful_ex_idx == -1)
zlib_stateful_ex_idx = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
0, NULL, NULL, NULL, zlib_stateful_free_ex_data);
CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
if (zlib_stateful_ex_idx == -1)
if(zlib_stateful_ex_idx == -1)
goto err_ex_data;
}
if (!CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state))
if(!CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state))
goto err_ex_data;
return 1;
err_ex_data:
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
err:
if (state){
if(state) {
/* ctx->ex_data freed from outside */
if (inflate_init)
if(inflate_init)
inflateEnd(&state->istream);
if (deflate_init)
if(deflate_init)
deflateEnd(&state->ostream);
OPENSSL_free(state);
}
Expand All @@ -197,32 +193,31 @@ static int zlib_stateful_init(COMP_CTX *ctx)

static void zlib_stateful_finish(COMP_CTX *ctx)
{
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
}

static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
unsigned int olen, unsigned char *in, unsigned int ilen)
{
int err = Z_OK;
struct zlib_state *state =
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
zlib_stateful_ex_idx);
struct zlib_state *state = (struct zlib_state *)CRYPTO_get_ex_data(
&ctx->ex_data, zlib_stateful_ex_idx);

if (state == NULL)
if(state == NULL)
return -1;

state->ostream.next_in = in;
state->ostream.avail_in = ilen;
state->ostream.next_out = out;
state->ostream.avail_out = olen;
if (ilen > 0)
if(ilen > 0)
err = deflate(&state->ostream, Z_SYNC_FLUSH);
if (err != Z_OK)
if(err != Z_OK)
return -1;
#ifdef DEBUG_ZLIB
fprintf(stderr,"compress(%4d)->%4d %s\n",
ilen,olen - state->ostream.avail_out,
(ilen != olen - state->ostream.avail_out)?"zlib":"clear");
fprintf(stderr, "compress(%4d)->%4d %s\n", ilen,
olen - state->ostream.avail_out,
(ilen != olen - state->ostream.avail_out) ? "zlib" : "clear");
#endif
return olen - state->ostream.avail_out;
}
Expand All @@ -232,25 +227,24 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
{
int err = Z_OK;

struct zlib_state *state =
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
zlib_stateful_ex_idx);
struct zlib_state *state = (struct zlib_state *)CRYPTO_get_ex_data(
&ctx->ex_data, zlib_stateful_ex_idx);

if (state == NULL)
if(state == NULL)
return 0;

state->istream.next_in = in;
state->istream.avail_in = ilen;
state->istream.next_out = out;
state->istream.avail_out = olen;
if (ilen > 0)
if(ilen > 0)
err = inflate(&state->istream, Z_SYNC_FLUSH);
if (err != Z_OK)
if(err != Z_OK)
return -1;
#ifdef DEBUG_ZLIB
fprintf(stderr,"expand(%4d)->%4d %s\n",
ilen,olen - state->istream.avail_out,
(ilen != olen - state->istream.avail_out)?"zlib":"clear");
fprintf(stderr, "expand(%4d)->%4d %s\n", ilen,
olen - state->istream.avail_out,
(ilen != olen - state->istream.avail_out) ? "zlib" : "clear");
#endif
return olen - state->istream.avail_out;
}
Expand Down

0 comments on commit d253dcd

Please sign in to comment.