os/ossrv/ssl/libcrypto/src/crypto/comp/c_rle.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/comp/c_rle.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,111 @@
     1.4 +/*
     1.5 +Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 +
     1.7 +Redistribution and use in source and binary forms, with or without 
     1.8 +modification, are permitted provided that the following conditions are met:
     1.9 +
    1.10 +* Redistributions of source code must retain the above copyright notice, this 
    1.11 +  list of conditions and the following disclaimer.
    1.12 +* Redistributions in binary form must reproduce the above copyright notice, 
    1.13 +  this list of conditions and the following disclaimer in the documentation 
    1.14 +  and/or other materials provided with the distribution.
    1.15 +* Neither the name of Nokia Corporation nor the names of its contributors 
    1.16 +  may be used to endorse or promote products derived from this software 
    1.17 +  without specific prior written permission.
    1.18 +
    1.19 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    1.20 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    1.21 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    1.22 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
    1.23 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    1.24 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    1.25 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
    1.26 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    1.27 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.28 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.29 +
    1.30 +Description:
    1.31 +*/
    1.32 +
    1.33 +
    1.34 +#include <stdio.h>
    1.35 +#include <stdlib.h>
    1.36 +#include <string.h>
    1.37 +#include <openssl/objects.h>
    1.38 +#include <openssl/comp.h>
    1.39 +#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
    1.40 +#include "libcrypto_wsd_macros.h"
    1.41 +#include "libcrypto_wsd.h"
    1.42 +#endif
    1.43 +
    1.44 +static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
    1.45 +	unsigned int olen, unsigned char *in, unsigned int ilen);
    1.46 +static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
    1.47 +	unsigned int olen, unsigned char *in, unsigned int ilen);
    1.48 +
    1.49 +#ifndef EMULATOR
    1.50 +static COMP_METHOD rle_method={
    1.51 +	NID_rle_compression,
    1.52 +	LN_rle_compression,
    1.53 +	NULL,
    1.54 +	NULL,
    1.55 +	rle_compress_block,
    1.56 +	rle_expand_block,
    1.57 +	NULL,
    1.58 +	NULL,
    1.59 +	};
    1.60 +#else
    1.61 +  GET_STATIC_VAR_FROM_TLS(rle_method,c_rle,COMP_METHOD)
    1.62 +  #define rle_method (*GET_WSD_VAR_NAME(rle_method,c_rle,s)())
    1.63 +  const COMP_METHOD temp_s_rle_method={
    1.64 +	NID_rle_compression,
    1.65 +	LN_rle_compression,
    1.66 +	NULL,
    1.67 +	NULL,
    1.68 +	rle_compress_block,
    1.69 +	rle_expand_block,
    1.70 +	NULL,
    1.71 +	NULL,
    1.72 +	};
    1.73 +#endif
    1.74 +
    1.75 +EXPORT_C COMP_METHOD *COMP_rle(void)
    1.76 +	{
    1.77 +	return(&rle_method);
    1.78 +	}
    1.79 +
    1.80 +static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
    1.81 +	     unsigned int olen, unsigned char *in, unsigned int ilen)
    1.82 +	{
    1.83 +	/* int i; */
    1.84 +
    1.85 +	if (olen < (ilen+1))
    1.86 +		{
    1.87 +		/* ZZZZZZZZZZZZZZZZZZZZZZ */
    1.88 +		return(-1);
    1.89 +		}
    1.90 +
    1.91 +	*(out++)=0;
    1.92 +	memcpy(out,in,ilen);
    1.93 +	return(ilen+1);
    1.94 +	}
    1.95 +
    1.96 +static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
    1.97 +	     unsigned int olen, unsigned char *in, unsigned int ilen)
    1.98 +	{
    1.99 +	int i;
   1.100 +
   1.101 +	if (olen < (ilen-1))
   1.102 +		{
   1.103 +		/* ZZZZZZZZZZZZZZZZZZZZZZ */
   1.104 +		return(-1);
   1.105 +		}
   1.106 +
   1.107 +	i= *(in++);
   1.108 +	if (i == 0)
   1.109 +		{
   1.110 +		memcpy(out,in,ilen-1);
   1.111 +		}
   1.112 +	return(ilen-1);
   1.113 +	}
   1.114 +