|
1 /* |
|
2 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 |
|
4 Redistribution and use in source and binary forms, with or without |
|
5 modification, are permitted provided that the following conditions are met: |
|
6 |
|
7 * Redistributions of source code must retain the above copyright notice, this |
|
8 list of conditions and the following disclaimer. |
|
9 * Redistributions in binary form must reproduce the above copyright notice, |
|
10 this list of conditions and the following disclaimer in the documentation |
|
11 and/or other materials provided with the distribution. |
|
12 * Neither the name of Nokia Corporation nor the names of its contributors |
|
13 may be used to endorse or promote products derived from this software |
|
14 without specific prior written permission. |
|
15 |
|
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
26 |
|
27 Description: |
|
28 */ |
|
29 |
|
30 |
|
31 #include <stdio.h> |
|
32 #include <stdlib.h> |
|
33 #include <string.h> |
|
34 #include <openssl/objects.h> |
|
35 #include <openssl/comp.h> |
|
36 #if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__))) |
|
37 #include "libcrypto_wsd_macros.h" |
|
38 #include "libcrypto_wsd.h" |
|
39 #endif |
|
40 |
|
41 static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, |
|
42 unsigned int olen, unsigned char *in, unsigned int ilen); |
|
43 static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, |
|
44 unsigned int olen, unsigned char *in, unsigned int ilen); |
|
45 |
|
46 #ifndef EMULATOR |
|
47 static COMP_METHOD rle_method={ |
|
48 NID_rle_compression, |
|
49 LN_rle_compression, |
|
50 NULL, |
|
51 NULL, |
|
52 rle_compress_block, |
|
53 rle_expand_block, |
|
54 NULL, |
|
55 NULL, |
|
56 }; |
|
57 #else |
|
58 GET_STATIC_VAR_FROM_TLS(rle_method,c_rle,COMP_METHOD) |
|
59 #define rle_method (*GET_WSD_VAR_NAME(rle_method,c_rle,s)()) |
|
60 const COMP_METHOD temp_s_rle_method={ |
|
61 NID_rle_compression, |
|
62 LN_rle_compression, |
|
63 NULL, |
|
64 NULL, |
|
65 rle_compress_block, |
|
66 rle_expand_block, |
|
67 NULL, |
|
68 NULL, |
|
69 }; |
|
70 #endif |
|
71 |
|
72 EXPORT_C COMP_METHOD *COMP_rle(void) |
|
73 { |
|
74 return(&rle_method); |
|
75 } |
|
76 |
|
77 static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, |
|
78 unsigned int olen, unsigned char *in, unsigned int ilen) |
|
79 { |
|
80 /* int i; */ |
|
81 |
|
82 if (olen < (ilen+1)) |
|
83 { |
|
84 /* ZZZZZZZZZZZZZZZZZZZZZZ */ |
|
85 return(-1); |
|
86 } |
|
87 |
|
88 *(out++)=0; |
|
89 memcpy(out,in,ilen); |
|
90 return(ilen+1); |
|
91 } |
|
92 |
|
93 static int rle_expand_block(COMP_CTX *ctx, unsigned char *out, |
|
94 unsigned int olen, unsigned char *in, unsigned int ilen) |
|
95 { |
|
96 int i; |
|
97 |
|
98 if (olen < (ilen-1)) |
|
99 { |
|
100 /* ZZZZZZZZZZZZZZZZZZZZZZ */ |
|
101 return(-1); |
|
102 } |
|
103 |
|
104 i= *(in++); |
|
105 if (i == 0) |
|
106 { |
|
107 memcpy(out,in,ilen-1); |
|
108 } |
|
109 return(ilen-1); |
|
110 } |
|
111 |