Exemple #1
0
static TACommandVerdict deflateInit__cmd(TAThread thread,TAInputStream stream)
{
    z_stream strm;
    int level, stream_size, res, is_null;
    char* version;

    is_null = readZStream(&stream, &strm);
    level = readInt(&stream);
    version = readString(&stream);
    stream_size = readInt(&stream);

    START_TARGET_OPERATION(thread);

    if(!is_null)
        res = deflateInit_(&strm, level, version, stream_size);
    else
        res = deflateInit_(0, level, version, stream_size);

    END_TARGET_OPERATION(thread);

    ta_debug_printf("res==%d\n");

    // Response
    if(!is_null)
        writeZStream(thread, &strm);
    else
        writeZStream(thread, 0);

    writeInt(thread, res);

    sendResponse(thread);

    return taDefaultVerdict;
}
Exemple #2
0
int XdeflateInit_(Z1Ctx *Zc,int level,const char *version,int siz){
	Z32_stream Z32;

	if( deflateInit_(Zc->z1_Z1,level,version,sizeof(Z64_stream)) == Z_OK ){
		Zc->z1_ssize = sizeof(Z64_stream);
		return Z_OK;
	}
	Zenpack(Zc,&Z32);
	if( deflateInit_(&Z32,level,version,sizeof(Z32_stream)) == Z_OK ){
		Zdepack(Zc,&Z32);
		Zc->z1_ssize = sizeof(Z32_stream);
		return Z_OK;
	}
	return Z_VERSION_ERROR;
}
Exemple #3
0
static int zlib_stateful_init(COMP_CTX *ctx)
{
    int err;
    struct zlib_state *state = OPENSSL_zalloc(sizeof(*state));

    if (state == NULL)
        goto err;

    state->istream.zalloc = zlib_zalloc;
    state->istream.zfree = zlib_zfree;
    state->istream.opaque = Z_NULL;
    state->istream.next_in = Z_NULL;
    state->istream.next_out = Z_NULL;
    err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    state->ostream.zalloc = zlib_zalloc;
    state->ostream.zfree = zlib_zfree;
    state->ostream.opaque = Z_NULL;
    state->ostream.next_in = Z_NULL;
    state->ostream.next_out = Z_NULL;
    err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
                       ZLIB_VERSION, sizeof(z_stream));
    if (err != Z_OK)
        goto err;

    ctx->data = state;
    return 1;
 err:
    OPENSSL_free(state);
    return 0;
}
Exemple #4
0
void Extension::CompressSendBinary()
{
    if (SendMsgSize <= 0)
        CreateError("Cannot compress; Message is too small.");
    else
    {
        int ret;
        z_stream strm = { 0 };
        ret = deflateInit_(&strm, 9, ZLIB_VERSION, sizeof(z_stream));
        if (ret)
        {
            std::stringstream error;
            error << "Error " << ret << "occured with initiating compression.";
            CreateError(error.str().c_str());
            return;
        }

        unsigned char * output_buffer = (unsigned char *)malloc(SendMsgSize + 256);
        if (!output_buffer)
        {
            std::stringstream error;
            error << "Error, could not allocate enough memory. Desired " << SendMsgSize + 256 << "bytes.";
            CreateError(error.str().c_str());
            deflateEnd(&strm);
            return;
        }
        strm.next_in = (unsigned char *)SendMsg;
        strm.avail_in = SendMsgSize;
        // Allocate memory for compression
        strm.avail_out = _msize(output_buffer);
        strm.next_out = output_buffer;
        ret = deflate(&strm, Z_FINISH);
        if (ret != Z_STREAM_END)
        {
            std::stringstream error;
            error << "Error with compression, deflate() returned " << ret << "! Text: " << strm.msg ? strm.msg : "";
            free(output_buffer);
            deflateEnd(&strm);
            CreateError(error.str().c_str());
            return;
        }
        deflateEnd(&strm);
        void * v = realloc(output_buffer, strm.total_out);
        if (!v)
        {
            free(output_buffer);
            CreateError("Error with compression, reallocating memory failed.");
            return;
        }
        free(SendMsg);

        SendMsg = (char *)v;
        SendMsgSize = strm.total_out;
    }
}
Exemple #5
0
static int zlib_stateful_init(COMP_CTX *ctx)
{
    int err;
    struct zlib_state *state =
        (struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));

    if (state == NULL)
        goto err;

    state->istream.zalloc = zlib_zalloc;
    state->istream.zfree = zlib_zfree;
    state->istream.opaque = Z_NULL;
    state->istream.next_in = Z_NULL;
    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)
        goto err;

    state->ostream.zalloc = zlib_zalloc;
    state->ostream.zfree = zlib_zfree;
    state->ostream.opaque = Z_NULL;
    state->ostream.next_in = Z_NULL;
    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)
        goto err;

    CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
    CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
    return 1;
 err:
    if (state)
        OPENSSL_free(state);
    return 0;
}
Exemple #6
0
void CDeflate::Init(int level, int stream_size)
{
    deflateInit_(&m_internal->m_stream, level, ZLIB_VERSION, (stream_size == -1) ? sizeof(z_stream) : stream_size);
}