Check-in [fa136f8afe]

Not logged in

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

Overview
SHA1 Hash:fa136f8afe49e7fd2c996fbe6aa5309f4cf11140
Date: 2008-11-14 10:53:20
User: stephan
Comment:added base64 encode/decode routines, so we can c11n binary data.
Changes
hide diffs unified diffs patch

Changes to include/s11n.net/c11n/detail/whclob.h

Old (0a98da244b21da3a) New (2b0b5649e2f46674)
1 #ifndef WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_ 1 #ifndef WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_
2 #define WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_ 1 2 #define WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_ 1
3 #include <stdarg.h> 3 #include <stdarg.h>
4 #include <stddef.h> 4 #include <stddef.h>
5 5
71 hidden lines
77 objects from/to FILE handles. 77 objects from/to FILE handles.
78 */ 78 */
79 #if !defined(WHCLOB_USE_FILE) 79 #if !defined(WHCLOB_USE_FILE)
80 #define WHCLOB_USE_FILE 1 80 #define WHCLOB_USE_FILE 1
81 #endif 81 #endif
> 82 #if WHCLOB_USE_FILE
> 83 #include <stdio.h>
> 84 #endif
82 85
83 /** @def WHCLOB_USE_ZLIB 86 /** @def WHCLOB_USE_ZLIB
84 87
85 If whclob is built with WHCLOB_USE_ZLIB set to a true value then 88 If whclob is built with WHCLOB_USE_ZLIB set to a true value then
86 some routines are added which use zlib to de/compress whclob 89 some routines are added which use zlib to de/compress whclob
2 hidden lines
89 */ 92 */
90 #if !defined(WHCLOB_USE_ZLIB) 93 #if !defined(WHCLOB_USE_ZLIB)
91 #define WHCLOB_USE_ZLIB 0 94 #define WHCLOB_USE_ZLIB 0
92 #endif 95 #endif
93 96
94 #if WHCLOB_USE_FILE | 97 /** @def WHCLOB_USE_BASE64
95 #include <stdio.h> | 98
| 99 If whclob is built with WHCLOB_USE_BASE64 set to a true value then
| 100 an import/export API is included for importing/export whclob
| 101 objects from/to FILE handles.
| 102 */
| 103 #if !defined(WHCLOB_USE_BASE64)
| 104 #define WHCLOB_USE_BASE64 1
96 #endif 105 #endif
> 106
97 107
98 108
99 #ifdef __cplusplus 109 #ifdef __cplusplus
100 extern "C" { 110 extern "C" {
101 #endif 111 #endif
835 hidden lines
937 whclob_uncompress(), but uses the zlib inflate() algorithm instead of 947 whclob_uncompress(), but uses the zlib inflate() algorithm instead of
938 the uncompress() algorithm. 948 the uncompress() algorithm.
939 */ 949 */
940 int whclob_inflate( whclob *cIn, whclob *cOut ); 950 int whclob_inflate( whclob *cIn, whclob *cOut );
941 #endif /* WHCLOB_USE_ZLIB */ 951 #endif /* WHCLOB_USE_ZLIB */
> 952
> 953 #if WHCLOB_USE_BASE64
> 954 /**
> 955 Encodes cIn's contents in base64 and sends it to cOut.
> 956 cIn may be the same as cOut. If cOut is not cIn then
> 957 it is cleared before encoding begins. On success, cOut is populated with
> 958 the encoded data and whclob_rc.OK is returned. On error:
> 959
> 960 - If (!cIn, !cOut, or !whclob_size(cIn)) then whclob_rc.ArgError
> 961 is returned and cOut is unmodified.
> 962
> 963 - On any other error, if (cIn!=cOut) then cOut will contain no
> 964 data, otherwise cIn/cOut will be unmodified. In these cases some
> 965 other error code from whclob_rc will be returned.
> 966 */
> 967 long whclob_base64_enc( whclob const *cIn, whclob *cOut );
> 968
> 969 /**
> 970 The converse of whclob_base64_enc(), with the same
> 971 conventions.
> 972 */
> 973 long whclob_base64_dec( whclob const *cIn, whclob *cOut );
> 974 #endif /* WHCLOB_USE_BASE64 */
> 975
942 976
943 #ifdef __cplusplus 977 #ifdef __cplusplus
944 } /* extern "C" */ 978 } /* extern "C" */
945 #endif 979 #endif
946 #endif /* WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_ */ 980 #endif /* WANDERINGHORSE_NET_WHCLOB_H_INCLUDED_ */

Changes to src/Makefile

Old (f0522c06355f2629) New (9ae08179472d1581)
1 #!/usr/bin/make -f 1 #!/usr/bin/make -f
2 # Requires GNU Make 3.80+! 2 # Requires GNU Make 3.80+!
3 default: all 3 default: all
4 4
5 ifeq (1,$(TCC)) 5 ifeq (1,$(TCC))
97 hidden lines
103 $(call ShakeNMake.CALL.RULES.LIBS,libwhgc) 103 $(call ShakeNMake.CALL.RULES.LIBS,libwhgc)
104 $(libwhgc.LIB): $(libwhhash.LIB) 104 $(libwhgc.LIB): $(libwhhash.LIB)
105 105
106 ######################################################################## 106 ########################################################################
107 # Clob lib 107 # Clob lib
108 WHCLOB_OBJ := whclob.o vappendf.o | 108 WHCLOB_OBJ := whclob.o vappendf.o cencode.o cdecode.o
109 libwhclob.LIB.OBJECTS = $(WHCLOB_OBJ) 109 libwhclob.LIB.OBJECTS = $(WHCLOB_OBJ)
110 $(call ShakeNMake.CALL.RULES.LIBS,libwhclob) 110 $(call ShakeNMake.CALL.RULES.LIBS,libwhclob)
111 libs: $(libwhclob.LIB) 111 libs: $(libwhclob.LIB)
112 112
113 ######################################################################## 113 ########################################################################
58 hidden lines
172 bins: 172 bins:
173 173
174 scratch.o: CFLAGS += -Wno-format 174 scratch.o: CFLAGS += -Wno-format
175 scratch.BIN.LDFLAGS := $(libc11n.LIB) $(EXPAT_LDFLAGS) $(SQLITE3.LDFLAGS) 175 scratch.BIN.LDFLAGS := $(libc11n.LIB) $(EXPAT_LDFLAGS) $(SQLITE3.LDFLAGS)
176 scratch.BIN.OBJECTS := scratch.o whclob.o 176 scratch.BIN.OBJECTS := scratch.o whclob.o
177 ifeq (1,$(USE_SQLITE3)) <
178 scratch.BIN.LDFLAGS += <
179 endif <
180 <
181 $(call ShakeNMake.CALL.RULES.BINS,scratch) 177 $(call ShakeNMake.CALL.RULES.BINS,scratch)
182 $(scratch.BIN): $(libc11n.LIB) 178 $(scratch.BIN): $(libc11n.LIB)
183 bins: $(scratch.BIN) 179 bins: $(scratch.BIN)
184 180
185 181
> 182 clobtest.o: CFLAGS += -Wno-format
> 183 clobtest.BIN.LDFLAGS := $(libwhclob.LIB)
> 184 clobtest.BIN.OBJECTS := test-clob.o
> 185 $(call ShakeNMake.CALL.RULES.BINS,clobtest)
> 186 $(clobtest.BIN): $(libwhclob.LIB)
> 187 bins: $(clobtest.BIN)
> 188
> 189
186 c11nconvert.BIN.LDFLAGS := $(libc11n.LIB) $(libwhgc.LIB) $(SQLITE3.LDFLAGS) $(EXPAT_LDFLAGS) 190 c11nconvert.BIN.LDFLAGS := $(libc11n.LIB) $(libwhgc.LIB) $(SQLITE3.LDFLAGS) $(EXPAT_LDFLAGS)
187 c11nconvert.BIN.OBJECTS := c11nconvert.o 191 c11nconvert.BIN.OBJECTS := c11nconvert.o
188 <
189 $(call ShakeNMake.CALL.RULES.BINS,c11nconvert) 192 $(call ShakeNMake.CALL.RULES.BINS,c11nconvert)
190 $(c11nconvert.BIN): $(libc11n.LIB) $(libwhgc.LIB) 193 $(c11nconvert.BIN): $(libc11n.LIB) $(libwhgc.LIB)
191 bins: $(c11nconvert.BIN) 194 bins: $(c11nconvert.BIN)
192 195
193 196
6 hidden lines
200 #$(MEGA.BIN): $(libc11n.LIB) $(libwhgc.LIB) 203 #$(MEGA.BIN): $(libc11n.LIB) $(libwhgc.LIB)
201 # tcc $(INCLUDES) -r -o $(MEGA.OBJ) $(wildcard c11n*.c wh*.c vappendf.c) 204 # tcc $(INCLUDES) -r -o $(MEGA.OBJ) $(wildcard c11n*.c wh*.c vappendf.c)
202 # tcc -o $(MEGA.BIN) $(MEGA.OBJ) $(SQLITE3.LDFLAGS) 205 # tcc -o $(MEGA.BIN) $(MEGA.OBJ) $(SQLITE3.LDFLAGS)
203 206
204 all: libs bins 207 all: libs bins

Changes to src/shake-n-make.make

Old (b84d4488535ebe11) New (440fe4e220ae5cad)
1 #!/usr/bin/make -f 1 #!/usr/bin/make -f
2 all: 2 all:
3 SHELL=/bin/bash 3 SHELL=/bin/bash
4 MAKE_REQUIRED_VERSION := 380# MAKE_VERSION stripped of any dots 4 MAKE_REQUIRED_VERSION := 380# MAKE_VERSION stripped of any dots
5 VERSION_CHECK := \ 5 VERSION_CHECK := \
554 hidden lines
560 ifneq (,$(ShakeNMake.CISH_SOURCES)) 560 ifneq (,$(ShakeNMake.CISH_SOURCES))
561 ShakeNMake.CISH_DEPS_FILE := .make.c_deps 561 ShakeNMake.CISH_DEPS_FILE := .make.c_deps
562 ShakeNMake.BINS.MKDEP = gcc -E -MM $(INCLUDES) 562 ShakeNMake.BINS.MKDEP = gcc -E -MM $(INCLUDES)
563 CLEAN_FILES += $(ShakeNMake.CISH_DEPS_FILE) 563 CLEAN_FILES += $(ShakeNMake.CISH_DEPS_FILE)
564 $(ShakeNMake.CISH_DEPS_FILE): $(PACKAGE.MAKEFILE) $(ShakeNMake.MAKEFILE) $(ShakeNMake.CISH_SOURCES) 564 $(ShakeNMake.CISH_DEPS_FILE): $(PACKAGE.MAKEFILE) $(ShakeNMake.MAKEFILE) $(ShakeNMake.CISH_SOURCES)
565 @-$(ShakeNMake.BINS.MKDEP) $(ShakeNMake.CISH_SOURCES) > $@ \ | 565 @-$(ShakeNMake.BINS.MKDEP) $(ShakeNMake.CISH_SOURCES) 2>/dev/null > $@ \
566 || $(ShakeNMake.BINS.RM) -f $@ 2>/dev/null 566 || $(ShakeNMake.BINS.RM) -f $@ 2>/dev/null
567 # ^^^^ We rm -f the deps file if mkdep fails because we don't want a bad generated makefile 567 # ^^^^ We rm -f the deps file if mkdep fails because we don't want a bad generated makefile
568 # to kill the build. 568 # to kill the build.
569 deps: $(ShakeNMake.CISH_DEPS_FILE) 569 deps: $(ShakeNMake.CISH_DEPS_FILE)
570 ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS)))) 570 ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS))))
90 hidden lines
661 endif # $(ShakeNMake.BINS.DOXYGEN) 661 endif # $(ShakeNMake.BINS.DOXYGEN)
662 endif # $(ShakeNMake.BINS.PERL) 662 endif # $(ShakeNMake.BINS.PERL)
663 # end Doxygen 663 # end Doxygen
664 ######################################################################## 664 ########################################################################
665 665

Changes to src/test-clob.c

Old (1e003859b6d93841) New (acc1c6efd936844b)
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>
24 hidden lines
30 DUMP(cb); 30 DUMP(cb);
31 whclob_truncate(cb,5,0); 31 whclob_truncate(cb,5,0);
32 DUMP(cb); 32 DUMP(cb);
33 whclob_truncate(cb,8,-1); 33 whclob_truncate(cb,8,-1);
34 DUMP(cb); 34 DUMP(cb);
> 35 whclob_reset(cb);
> 36
> 37 long rc = whclob_import_filename( cb, __FILE__ );
> 38 MARKER("Import [%s] rc = %ld\n",__FILE__, rc);
> 39 whclob_base64_enc( cb, cb );
> 40
> 41 MARKER("base64-encoded (size=%ld):\n",whclob_size(cb));
> 42 whclob_export_FILE( cb, stdout );
> 43 //fputc( '\n', stdout );
> 44 MARKER("End encoded data.\n");
> 45 whclob_base64_dec( cb, cb );
> 46 MARKER("base64-decoded size=%ld\n",whclob_size(cb));
> 47 MARKER("base64-decoded:\n");
> 48 whclob_export_FILE( cb, stdout );
35 whclob_finalize(cb); 49 whclob_finalize(cb);
36 return 0; 50 return 0;
37 } 51 }

Changes to src/whclob.c

Old (7a37db85b2a5c1fc) New (eef3a8d9d3c27784)
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
1190 hidden lines
1196 return whclob_import( dest, (void*)fn, whclob_importer_filename ); 1196 return whclob_import( dest, (void*)fn, whclob_importer_filename );
1197 /* i HATE that cast, but we know the importer won't change fn. */ 1197 /* i HATE that cast, but we know the importer won't change fn. */
1198 } 1198 }
1199 #endif /* WHCLOB_USE_FILE */ 1199 #endif /* WHCLOB_USE_FILE */
1200 1200
1201 #undef WHCLOB_USE_ZLIB | 1201 #if WHCLOB_USE_BASE64
| 1202 #include "s11n.net/c11n/detail/b64/cencode.h"
| 1203 #include "s11n.net/c11n/detail/b64/cdecode.h"
| 1204 long whclob_base64_enc( whclob const *cIn, whclob *cOut )
| 1205 {
| 1206 unsigned int szIn = whclob_size(cIn);
| 1207 unsigned int szOut = (szIn+1) * 1.4;
| 1208 long rc = 0;
| 1209 whclob * tmp = 0;
| 1210 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError;
| 1211 if( szOut < 10 ) szOut = 10;
| 1212 if( cOut != cIn ) whclob_reset( cOut );
| 1213 rc = whclob_init( &tmp, 0, szOut );
| 1214 if( whclob_rc.OK != rc )
| 1215 {
| 1216 return rc;
| 1217 }
| 1218 base64_encodestate state;
| 1219 base64_init_encodestate( &state );
| 1220 char * outBuf = whclob_buffer(tmp);
| 1221 rc = base64_encode_block( whclob_bufferc(cIn), whclob_size(cIn), outBuf, &state );
| 1222 //MARKER("enc inSize=%ld, rc=%ld\n",whclob_size(cIn), rc);
| 1223 rc += base64_encode_blockend( outBuf+rc, &state);
| 1224 //MARKER("enc rc=%ld\n",rc);
| 1225 whclob_resize( tmp, rc );
| 1226 whclob_swap( cOut, tmp );
| 1227 whclob_finalize( tmp );
| 1228 return whclob_rc.OK;
| 1229 }
| 1230 long whclob_base64_dec( whclob const *cIn, whclob *cOut )
| 1231 {
| 1232 unsigned int szIn = whclob_size(cIn);
| 1233 unsigned int szOut = szIn;
| 1234 long rc = 0;
| 1235 whclob * tmp = 0;
| 1236 if( ! cIn || !cOut || !szIn ) return whclob_rc.ArgError;
| 1237 if( szOut < 10 ) szOut = 10;
| 1238 if( cOut != cIn ) whclob_reset( cOut );
| 1239 rc = whclob_init( &tmp, 0, szOut );
| 1240 if( whclob_rc.OK != rc )
| 1241 {
| 1242 return rc;
| 1243 }
| 1244 base64_decodestate state;
| 1245 base64_init_decodestate( &state );
| 1246 rc = base64_decode_block( whclob_bufferc(cIn), whclob_size(cIn), whclob_buffer(tmp), &state );
| 1247 whclob_resize( tmp, rc );
| 1248 //MARKER("dec inSize=%ld, outSize=%ld, rc=%ld\n",whclob_size(cIn), whclob_size(tmp), rc);
| 1249 whclob_swap( cOut, tmp );
| 1250 whclob_finalize( tmp );
| 1251 return whclob_rc.OK;
| 1252 }
| 1253 #endif /* WHCLOB_USE_BASE64 */
| 1254
1202 #undef WHCLOB_DEBUG 1255 #undef WHCLOB_DEBUG