Check-in [fca1f0422c]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:fca1f0422c1017871a627a1fdc6333ba1a5f30c7
Date: 2008-11-14 11:05:56
User: stephan
Comment:cleanups to the base64 handling
Changes
hide diffs unified diffs patch

Changes to src/test-clob.c

Old (acc1c6efd936844b) New (05fbebc50bbe33f8)
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include <ctype.h> 4 #include <ctype.h>
5 #include <assert.h> 5 #include <assert.h>
6 hidden lines
12 #define MARKER if(0) printf 12 #define MARKER if(0) printf
13 #endif 13 #endif
14 14
15 #define DUMP(CL) MARKER("clob@%p size=%ld capacity=%ld data=[%s]\n",(void const *)CL,whclob_size(CL),whclob_capacity(CL),whclob_bufferc(CL)) 15 #define DUMP(CL) MARKER("clob@%p size=%ld capacity=%ld data=[%s]\n",(void const *)CL,whclob_size(CL),whclob_capacity(CL),whclob_bufferc(CL))
16 16
> 17 typedef struct MyStruct
> 18 {
> 19 int x;
> 20 int y;
> 21 } MyStruct;
> 22
17 int main( int argc, char const ** argv ) 23 int main( int argc, char const ** argv )
18 { 24 {
19 char const * input = 25 char const * input =
20 //"a b c" 26 //"a b c"
21 "A <B> C*D \"inner string\"" 27 "A <B> C*D \"inner string\""
15 hidden lines
37 long rc = whclob_import_filename( cb, __FILE__ ); 43 long rc = whclob_import_filename( cb, __FILE__ );
38 MARKER("Import [%s] rc = %ld\n",__FILE__, rc); 44 MARKER("Import [%s] rc = %ld\n",__FILE__, rc);
39 whclob_base64_enc( cb, cb ); 45 whclob_base64_enc( cb, cb );
40 46
41 MARKER("base64-encoded (size=%ld):\n",whclob_size(cb)); 47 MARKER("base64-encoded (size=%ld):\n",whclob_size(cb));
42 whclob_export_FILE( cb, stdout ); | 48 //whclob_export_FILE( cb, stdout );
43 //fputc( '\n', stdout ); 49 //fputc( '\n', stdout );
44 MARKER("End encoded data.\n"); 50 MARKER("End encoded data.\n");
45 whclob_base64_dec( cb, cb ); 51 whclob_base64_dec( cb, cb );
46 MARKER("base64-decoded size=%ld\n",whclob_size(cb)); 52 MARKER("base64-decoded size=%ld\n",whclob_size(cb));
47 MARKER("base64-decoded:\n"); | 53 //MARKER("base64-decoded:\n");
| 54 //whclob_export_FILE( cb, stdout );
| 55
| 56 whclob_reset(cb);
| 57 MyStruct my;
| 58 my.x = 42;
| 59 my.y = -42;
| 60 whclob_append( cb, (char const *)&my, sizeof(MyStruct));
| 61 MARKER("MyStruct clob size: %ld\n", whclob_size(cb) );
| 62 whclob_base64_enc( cb, cb );
| 63 MARKER("MyStruct clob encoded size: %ld\n", whclob_size(cb) );
48 whclob_export_FILE( cb, stdout ); 64 whclob_export_FILE( cb, stdout );
> 65
> 66 MyStruct my2;
> 67 whclob_base64_dec( cb, cb );
> 68 memcpy( &my2, whclob_bufferc(cb), (size_t) whclob_size(cb) );
> 69 MARKER("my2: x=%d y=%d\n", my2.x, my2.y );
> 70 whclob_reset(cb);
> 71
49 whclob_finalize(cb); 72 whclob_finalize(cb);
50 return 0; 73 return 0;
51 } 74 }

Changes to src/whclob.c

Old (eef3a8d9d3c27784) New (54232cf93b0c90fe)
1 #include <string.h> 1 #include <string.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stdio.h> 3 #include <stdio.h>
4 #include <stdarg.h> 4 #include <stdarg.h>
5 5
1196 hidden lines
1202 #include "s11n.net/c11n/detail/b64/cencode.h" 1202 #include "s11n.net/c11n/detail/b64/cencode.h"
1203 #include "s11n.net/c11n/detail/b64/cdecode.h" 1203 #include "s11n.net/c11n/detail/b64/cdecode.h"
1204 long whclob_base64_enc( whclob const *cIn, whclob *cOut ) 1204 long whclob_base64_enc( whclob const *cIn, whclob *cOut )
1205 { 1205 {
1206 unsigned int szIn = whclob_size(cIn); 1206 unsigned int szIn = whclob_size(cIn);
1207 unsigned int szOut = (szIn+1) * 1.4; | 1207 unsigned int szOut = (unsigned int) ((szIn+1) * 1.4);
1208 long rc = 0; 1208 long rc = 0;
1209 whclob * tmp = 0; 1209 whclob * tmp = 0;
1210 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError; 1210 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError;
1211 if( szOut < 10 ) szOut = 10; | 1211 if( szOut < (szIn-5) ) szOut = szIn + 5;
1212 if( cOut != cIn ) whclob_reset( cOut ); 1212 if( cOut != cIn ) whclob_reset( cOut );
1213 rc = whclob_init( &tmp, 0, szOut ); 1213 rc = whclob_init( &tmp, 0, szOut );
1214 if( whclob_rc.OK != rc ) 1214 if( whclob_rc.OK != rc )
1215 { 1215 {
1216 return rc; 1216 return rc;
15 hidden lines
1232 unsigned int szIn = whclob_size(cIn); 1232 unsigned int szIn = whclob_size(cIn);
1233 unsigned int szOut = szIn; 1233 unsigned int szOut = szIn;
1234 long rc = 0; 1234 long rc = 0;
1235 whclob * tmp = 0; 1235 whclob * tmp = 0;
1236 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError; 1236 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError;
1237 if( szOut < 10 ) szOut = 10; <
1238 if( cOut != cIn ) whclob_reset( cOut ); 1237 if( cOut != cIn ) whclob_reset( cOut );
1239 rc = whclob_init( &tmp, 0, szOut ); 1238 rc = whclob_init( &tmp, 0, szOut );
1240 if( whclob_rc.OK != rc ) 1239 if( whclob_rc.OK != rc )
1241 { 1240 {
1242 return rc; 1241 return rc;
8 hidden lines
1251 return whclob_rc.OK; 1250 return whclob_rc.OK;
1252 } 1251 }
1253 #endif /* WHCLOB_USE_BASE64 */ 1252 #endif /* WHCLOB_USE_BASE64 */
1254 1253
1255 #undef WHCLOB_DEBUG 1254 #undef WHCLOB_DEBUG