Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | 426b66a01c67c6ca2765557a1667b7b097b1c72e |
|---|---|
| Date: | 2008-11-14 14:01:19 |
| User: | stephan |
| Comment: | added c11n_(de)serialize_binary(). other minor touch-ups |
Changes
Changes to include/s11n.net/c11n/c11n.h
| Old (96592c642e0a9df9) | New (6edd5438695ea732) | |||
|---|---|---|---|---|
| 1 | #ifndef S11N_NET_C11N_H_INCLUDED | 1 | #ifndef S11N_NET_C11N_H_INCLUDED | |
| 2 | #define S11N_NET_C11N_H_INCLUDED 1 | 2 | #define S11N_NET_C11N_H_INCLUDED 1 | |
| 3 | 3 | |||
| 4 | /** @page c11n_page_main c11n: generic serialization library for C | 4 | /** @page c11n_page_main c11n: generic serialization library for C | |
| 5 | 5 | |||
| 87 hidden lines | ||||
| 93 | a bit long. This is probably a misfeature i can't get around. In C++ | 93 | a bit long. This is probably a misfeature i can't get around. In C++ | |
| 94 | we do it with class templates, but in C that's not an option. | 94 | we do it with class templates, but in C that's not an option. | |
| 95 | 95 | |||
| 96 | - Currently only natively handles ASCII (or, theoretically, latin1) | 96 | - Currently only natively handles ASCII (or, theoretically, latin1) | |
| 97 | data. Binary can be handled indirectly, by encoding it using (e.g.) | 97 | data. Binary can be handled indirectly, by encoding it using (e.g.) | |
| 98 | bin64. The API heavily uses typedefs for string parameter types, | | | 98 | base64. The API heavily uses typedefs for string parameter types, |
| 99 | so that an eventual port to, e.g. wchar_t, should be feasible. | 99 | so that an eventual port to, e.g. wchar_t, should be feasible. | |
| 100 | 100 | |||
| 101 | - Verbose. Much of the API has horribly long function names, mainly | 101 | - Verbose. Much of the API has horribly long function names, mainly | |
| 102 | due to a lack of namespaces in C. | 102 | due to a lack of namespaces in C. | |
| 103 | 103 | |||
| 1588 hidden lines | ||||
| 1692 | - factory function: void* (*)(); | 1692 | - factory function: void* (*)(); | |
| 1693 | 1693 | |||
| 1694 | */ | 1694 | */ | |
| 1695 | #endif | 1695 | #endif | |
| 1696 | 1696 | |||
| > | 1697 | /** | ||
| > | 1698 | Saves src as encoded binary data in dest. It does this by casting | ||
| > | 1699 | src to a (char const *), writing sizeOfSrc bytes to a string | ||
| > | 1700 | buffer, base64-encoding that buffer and then storing the | ||
| > | 1701 | base64-encoded string as a property (with an unspecified name) in | ||
| > | 1702 | dest. | ||
| > | 1703 | |||
| > | 1704 | Caveats and warnings: | ||
| > | 1705 | |||
| > | 1706 | - Be very careful to use matching pairs of c11n_serialize_binary() and | ||
| > | 1707 | c11n_deserialize_binary(), using the exact same src type for each | ||
| > | 1708 | matching call. Failure to do so will potentially result in overwriting | ||
| > | 1709 | memory with contents from a different type of object. | ||
| > | 1710 | |||
| > | 1711 | - This is certainly not endianness-safe, and probably also not safe | ||
| > | 1712 | across different platforms of different bits (e.g. 32bit vs | ||
| > | 1713 | 64bit). Data stored this way may or may not be loadable on | ||
| > | 1714 | platforms other than the one it is stored on. | ||
| > | 1715 | |||
| > | 1716 | |||
| > | 1717 | Example: | ||
| > | 1718 | |||
| > | 1719 | @code | ||
| > | 1720 | MyType my; | ||
| > | 1721 | my.x = 13; | ||
| > | 1722 | my.y = -13; | ||
| > | 1723 | c11n_serialize_binary( myNode, &my, sizeof(MyType) ); | ||
| > | 1724 | @endcode | ||
| > | 1725 | |||
| > | 1726 | |||
| > | 1727 | @see c11n_deserialize_binary() | ||
| > | 1728 | */ | ||
| > | 1729 | bool c11n_serialize_binary( c11n_node * dest, void const * src, size_t sizeOfSrc ); | ||
| > | 1730 | |||
| > | 1731 | /** | ||
| > | 1732 | c11n_binary_data is a helper type for use with | ||
| > | 1733 | c11n_deserialize_binary(). | ||
| > | 1734 | */ | ||
| > | 1735 | typedef struct c11n_binary_data | ||
| > | 1736 | { | ||
| > | 1737 | /** See c11n_deserialize_binary(). */ | ||
| > | 1738 | void * data; | ||
| > | 1739 | /** See c11n_deserialize_binary(). */ | ||
| > | 1740 | size_t size; | ||
| > | 1741 | } c11n_binary_data; | ||
| > | 1742 | /** | ||
| > | 1743 | UNTESTED! | ||
| > | 1744 | |||
| > | 1745 | The converse of c11n_serialize_binary(). The caller must supply a non-null | ||
| > | 1746 | dest pointer. The serialized data pulled from src is stored in dest. | ||
| > | 1747 | If dest->data points to an object before this call then the caller | ||
| > | 1748 | should clean it up (if appropriate) before calling this, as this call | ||
| > | 1749 | will overwrite that pointer. | ||
| > | 1750 | |||
| > | 1751 | On success: | ||
| > | 1752 | |||
| > | 1753 | - dest->data points to dest->size bytes of malloced memory which | ||
| > | 1754 | has been set to the binary image which was passed to | ||
| > | 1755 | c11n_serialize_binary(). e.g. if a MyType was serialized, the | ||
| > | 1756 | deserialized data will be a bitwise copy of that MyType object. | ||
| > | 1757 | |||
| > | 1758 | - The caller is responsible for cleaning up dest->data using whatever | ||
| > | 1759 | approach is appropriate for its specific type. | ||
| > | 1760 | |||
| > | 1761 | On error: | ||
| > | 1762 | |||
| > | 1763 | - dest->data will be 0. | ||
| > | 1764 | |||
| > | 1765 | - dest->size will be set to the reported size of the binary data, | ||
| > | 1766 | or 0 if no size information is found (in which case dest->data will | ||
| > | 1767 | also be 0). | ||
| > | 1768 | |||
| > | 1769 | Errors can be any of: | ||
| > | 1770 | |||
| > | 1771 | - Properties set by c11n_serialize_binary() are not found. | ||
| > | 1772 | |||
| > | 1773 | - Allocation error. | ||
| > | 1774 | |||
| > | 1775 | - !src or !dest. | ||
| > | 1776 | |||
| > | 1777 | Example: | ||
| > | 1778 | |||
| > | 1779 | @code | ||
| > | 1780 | MyType my; | ||
| > | 1781 | c11n_binary_data bin; | ||
| > | 1782 | if( ! c11n_deserialize_binary( myNode, &bin ) ) ... error ...; | ||
| > | 1783 | my = *((MyType*)bin.data); | ||
| > | 1784 | free(bin.data); | ||
| > | 1785 | @endcode | ||
| > | 1786 | |||
| > | 1787 | @see c11n_deserialize_binary() | ||
| > | 1788 | */ | ||
| > | 1789 | bool c11n_deserialize_binary( c11n_node const * src, c11n_binary_data * dest ); | ||
| 1697 | 1790 | |||
| 1698 | #ifdef __cplusplus | 1791 | #ifdef __cplusplus | |
| 1699 | } /* extern "C" */ | 1792 | } /* extern "C" */ | |
| 1700 | #endif | 1793 | #endif | |
| 1701 | 1794 | |||
| 1702 | #endif /* S11N_NET_C11N_H_INCLUDED */ | 1795 | #endif /* S11N_NET_C11N_H_INCLUDED */ | |
Changes to include/s11n.net/c11n/io/c11n_io.h
| Old (2d54f0a8f425c1c9) | New (836884ee4f81529a) | |||
|---|---|---|---|---|
| 1 | #ifndef S11N_NET_C11N_IO_H_INCLUDED | 1 | #ifndef S11N_NET_C11N_IO_H_INCLUDED | |
| 2 | #define S11N_NET_C11N_IO_H_INCLUDED 1 | 2 | #define S11N_NET_C11N_IO_H_INCLUDED 1 | |
| 3 | /* | 3 | /* | |
| 4 | This file contains declarations and documentation for the generic | 4 | This file contains declarations and documentation for the generic | |
| 5 | i/o routines for c11n. The core does not know about this API and no | 5 | i/o routines for c11n. The core does not know about this API and no | |
| 753 hidden lines | ||||
| 759 | tree. | 759 | tree. | |
| 760 | */ | 760 | */ | |
| 761 | bool c11n_save_node( c11n_node const * src, c11n_stream * dest, c11n_io_handler * h ); | 761 | bool c11n_save_node( c11n_node const * src, c11n_stream * dest, c11n_io_handler * h ); | |
| 762 | 762 | |||
| 763 | /** | 763 | /** | |
| 764 | Works similarly to c11n_load_node(). If a node can be loaded (as described for | | | 764 | Works similarly to c11n_load_node(), except that it goes one step further and tries to |
| | | 765 | deserialize that node into a new object. If a node can be loaded (as described for | ||
| 765 | c11n_load_node()) then a new object is created via m->api->create(m). That object | 766 | c11n_load_node()) then a new object is created via m->api->create(m). That object | |
| 766 | is passed to c11n_deserialize(). If the deserialize succeeds then that object | 767 | is passed to c11n_deserialize(). If the deserialize succeeds then that object | |
| 767 | is returned, otherwise everything is cleaned up and 0 is returned. | 768 | is returned, otherwise everything is cleaned up and 0 is returned. | |
| 768 | */ | 769 | */ | |
| 769 | void * c11n_load_serializable( c11n_stream * src, c11n_marshaller const * m ); | 770 | void * c11n_load_serializable( c11n_stream * src, c11n_marshaller const * m ); | |
| 117 hidden lines | ||||
| 887 | #ifdef __cplusplus | 888 | #ifdef __cplusplus | |
| 888 | } /* extern "C" */ | 889 | } /* extern "C" */ | |
| 889 | #endif | 890 | #endif | |
| 890 | 891 | |||
| 891 | #endif // S11N_NET_C11N_IO_H_INCLUDED | 892 | #endif // S11N_NET_C11N_IO_H_INCLUDED | |
Changes to src/Doxyfile.at
| Old (3a13b241f0843211) | New (a88461a49f1cb017) | |||
|---|---|---|---|---|
| 1 | # Doxyfile 1.5.5 | 1 | # Doxyfile 1.5.5 | |
| 2 | 2 | |||
| 3 | # This file describes the settings to be used by the documentation system | 3 | # This file describes the settings to be used by the documentation system | |
| 4 | # doxygen (www.doxygen.org) for a project | 4 | # doxygen (www.doxygen.org) for a project | |
| 5 | # | 5 | # | |
| 549 hidden lines | ||||
| 555 | # certain files from those directories. Note that the wildcards are matched | 555 | # certain files from those directories. Note that the wildcards are matched | |
| 556 | # against the file with absolute path, so to exclude all test directories | 556 | # against the file with absolute path, so to exclude all test directories | |
| 557 | # for example use the pattern */test/* | 557 | # for example use the pattern */test/* | |
| 558 | 558 | |||
| 559 | EXCLUDE_PATTERNS = whhash.* \ | 559 | EXCLUDE_PATTERNS = whhash.* \ | |
| 560 | whgc.* | | | 560 | whgc.* \ |
| | | 561 | My*.* test*.* | ||
| 561 | 562 | |||
| 562 | # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names | 563 | # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names | |
| 563 | # (namespaces, classes, functions, etc.) that should be excluded from the | 564 | # (namespaces, classes, functions, etc.) that should be excluded from the | |
| 564 | # output. The symbol name can be a fully qualified name, a word, or if the | 565 | # output. The symbol name can be a fully qualified name, a word, or if the | |
| 565 | # wildcard * is used, a substring. Examples: ANamespace, AClass, | 566 | # wildcard * is used, a substring. Examples: ANamespace, AClass, | |
| 789 hidden lines | ||||
| 1355 | 1356 | |||
| 1356 | # The SEARCHENGINE tag specifies whether or not a search engine should be | 1357 | # The SEARCHENGINE tag specifies whether or not a search engine should be | |
| 1357 | # used. If set to NO the values of all tags below this one will be ignored. | 1358 | # used. If set to NO the values of all tags below this one will be ignored. | |
| 1358 | 1359 | |||
| 1359 | SEARCHENGINE = NO | 1360 | SEARCHENGINE = NO | |
Changes to src/Makefile
| Old (9ae08179472d1581) | New (32cc1aaa4916df68) | |||
|---|---|---|---|---|
| 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)) | |
| 153 hidden lines | ||||
| 159 | libs: $(libc11n.DLL) | 159 | libs: $(libc11n.DLL) | |
| 160 | endif | 160 | endif | |
| 161 | 161 | |||
| 162 | test.o: CFLAGS += -Wno-format | 162 | test.o: CFLAGS += -Wno-format | |
| 163 | test.BIN.LDFLAGS := $(libc11n.LIB) $(libwhgc.LIB) $(EXPAT_LDFLAGS) | 163 | test.BIN.LDFLAGS := $(libc11n.LIB) $(libwhgc.LIB) $(EXPAT_LDFLAGS) | |
| 164 | test.BIN.OBJECTS := test.o MyType.o | | | 164 | test.BIN.OBJECTS := test.o MyType.o MyGraph.o |
| 165 | ifeq (1,$(USE_SQLITE3)) | 165 | ifeq (1,$(USE_SQLITE3)) | |
| 166 | test.BIN.LDFLAGS += $(SQLITE3.LDFLAGS) | 166 | test.BIN.LDFLAGS += $(SQLITE3.LDFLAGS) | |
| 167 | endif | 167 | endif | |
| 168 | 168 | |||
| 169 | $(call ShakeNMake.CALL.RULES.BINS,test) | 169 | $(call ShakeNMake.CALL.RULES.BINS,test) | |
| 33 hidden lines | ||||
| 203 | #$(MEGA.BIN): $(libc11n.LIB) $(libwhgc.LIB) | 203 | #$(MEGA.BIN): $(libc11n.LIB) $(libwhgc.LIB) | |
| 204 | # 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) | |
| 205 | # tcc -o $(MEGA.BIN) $(MEGA.OBJ) $(SQLITE3.LDFLAGS) | 205 | # tcc -o $(MEGA.BIN) $(MEGA.OBJ) $(SQLITE3.LDFLAGS) | |
| 206 | 206 | |||
| 207 | all: libs bins | 207 | all: libs bins | |
Changes to src/c11n.c
| Old (fa8e376b283de72d) | New (b5a36e9c9e733543) | |||
|---|---|---|---|---|
| 1 | /** | 1 | /** | |
| 2 | This the main implementation file for the c11n core library. Some | 2 | This the main implementation file for the c11n core library. Some | |
| 3 | maintenance notes: | 3 | maintenance notes: | |
| 4 | 4 | |||
| 5 | - NO dependency on any code from the c11n_io API is allowed. | 5 | - NO dependency on any code from the c11n_io API is allowed. | |
| 71 hidden lines | ||||
| 77 | extern "C" { | 77 | extern "C" { | |
| 78 | #else | 78 | #else | |
| 79 | #define ARG_UNUSED(X) X | 79 | #define ARG_UNUSED(X) X | |
| 80 | #endif | 80 | #endif | |
| 81 | 81 | |||
| 82 | #if 0 | | | 82 | #if 1 |
| 83 | #include <stdio.h> // only for debuggering | 83 | #include <stdio.h> // only for debuggering | |
| 84 | #define MARKER if(1) printf("MARKER: %s:%d:%s():\n",__FILE__,__LINE__,__func__); if(1) printf | 84 | #define MARKER if(1) printf("MARKER: %s:%d:%s():\n",__FILE__,__LINE__,__func__); if(1) printf | |
| 85 | #else | 85 | #else | |
| 86 | static void bogo_printf(char const * fmt, ...) {} | 86 | static void bogo_printf(char const * fmt, ...) {} | |
| 87 | #define MARKER if(0) bogo_printf | 87 | #define MARKER if(0) bogo_printf | |
| 973 hidden lines | ||||
| 1061 | ch = 0; | 1061 | ch = 0; | |
| 1062 | } | 1062 | } | |
| 1063 | } | 1063 | } | |
| 1064 | return ch; | 1064 | return ch; | |
| 1065 | } | 1065 | } | |
| > | 1066 | |||
| > | 1067 | bool c11n_serialize_binary( c11n_node * dest, void const * src, size_t sizeOf ) | ||
| > | 1068 | { | ||
| > | 1069 | if( ! dest || !src || !sizeOf ) return false; | ||
| > | 1070 | whclob * buf = whclob_new_n( sizeOf ); | ||
| > | 1071 | if( ! buf ) return false; | ||
| > | 1072 | whclob_append( buf, src, sizeOf ); | ||
| > | 1073 | whclob_base64_enc( buf, buf ); | ||
| > | 1074 | c11n_node_prop_set_fe( dest, "size", "%u", sizeOf ); | ||
| > | 1075 | c11n_string_t key = c11n_copy_str( "base64" ); | ||
| > | 1076 | char * val = whclob_take_buffer( buf ); | ||
| > | 1077 | if( ! c11n_node_prop_give_kvp( dest, key, val ) ) | ||
| > | 1078 | { | ||
| > | 1079 | free(key); | ||
| > | 1080 | free(val); | ||
| > | 1081 | } | ||
| > | 1082 | whclob_finalize( buf ); | ||
| > | 1083 | return true; | ||
| > | 1084 | } | ||
| > | 1085 | |||
| > | 1086 | bool c11n_deserialize_binary( c11n_node const * src, c11n_binary_data * dest ) | ||
| > | 1087 | { | ||
| > | 1088 | dest->data = 0; | ||
| > | 1089 | dest->size = 0; | ||
| > | 1090 | if( ! src || !dest ) return false; | ||
| > | 1091 | size_t sz = 0; | ||
| > | 1092 | if( 1 != c11n_node_prop_get_fe( src, "size", "%u", &sz ) ) return false; | ||
| > | 1093 | dest->size = sz; | ||
| > | 1094 | c11n_const_string_t val = 0; | ||
| > | 1095 | if( ! c11n_node_prop_get( src, "base64", &val ) || !val ) return false; | ||
| > | 1096 | dest->data = malloc(sz); | ||
| > | 1097 | if( ! dest->data ) return false; | ||
| > | 1098 | memset( dest->data, 0, sz ); | ||
| > | 1099 | whclob * cb = whclob_new(); | ||
| > | 1100 | whclob_append( cb, val, -1 ); | ||
| > | 1101 | //MARKER("whclob_size(cb) ==%ld, strlen(val)=%d val=[%s]\n",whclob_size(cb),strlen(val),val); | ||
| > | 1102 | bool rc = true; | ||
| > | 1103 | if( ! cb ) | ||
| > | 1104 | { | ||
| > | 1105 | rc = false; | ||
| > | 1106 | free( dest->data ); | ||
| > | 1107 | dest->data = 0; | ||
| > | 1108 | } | ||
| > | 1109 | else | ||
| > | 1110 | { | ||
| > | 1111 | whclob_base64_dec( cb, cb ); | ||
| > | 1112 | if( (size_t)whclob_size(cb) != sz ) | ||
| > | 1113 | { | ||
| > | 1114 | rc = false; | ||
| > | 1115 | C11N_LOG(C11N_LOG_ERROR)("Declared size of data (%u) is not the same as the decoded size (%ld)", | ||
| > | 1116 | sz, whclob_size(cb)); | ||
| > | 1117 | } | ||
| > | 1118 | else | ||
| > | 1119 | { | ||
| > | 1120 | memcpy( dest->data, whclob_bufferc(cb), sz ); | ||
| > | 1121 | } | ||
| > | 1122 | } | ||
| > | 1123 | whclob_finalize( cb ); | ||
| > | 1124 | return rc; | ||
| > | 1125 | } | ||
| > | 1126 | |||
| 1066 | 1127 | |||
| 1067 | 1128 | |||
| 1068 | void c11n_dump_node( c11n_node const * c, bool recurse ) | 1129 | void c11n_dump_node( c11n_node const * c, bool recurse ) | |
| 1069 | { | 1130 | { | |
| 1070 | if( ! c ) return; | 1131 | if( ! c ) return; | |
| 370 hidden lines | ||||
| 1441 | #undef C11N_MARSHALLER_INIT | 1502 | #undef C11N_MARSHALLER_INIT | |
| 1442 | #undef C11N_MARSHALLER_API_DEFAULT | 1503 | #undef C11N_MARSHALLER_API_DEFAULT | |
| 1443 | #ifdef __cplusplus | 1504 | #ifdef __cplusplus | |
| 1444 | } /* extern "C" */ | 1505 | } /* extern "C" */ | |
| 1445 | #endif | 1506 | #endif | |
Changes to src/cdecode.c
| Old (33dfb5c2cb7a09f6) | New (5f6b5544c1521eb7) | |||
|---|---|---|---|---|
| 1 | /* | 1 | /* | |
| 2 | cdecoder.c - c source to a base64 decoding algorithm implementation | 2 | cdecoder.c - c source to a base64 decoding algorithm implementation | |
| 3 | 3 | |||
| 4 | This is part of the libb64 project, and has been placed in the public domain. | 4 | This is part of the libb64 project, and has been placed in the public domain. | |
| 5 | For details, see http://sourceforge.net/projects/libb64 | 5 | For details, see http://sourceforge.net/projects/libb64 | |
| 6 | */ | 6 | */ | |
| 7 | 7 | |||
| 8 | #include <b64/cdecode.h> | | | 8 | #include "s11n.net/c11n/detail/b64/cdecode.h" |
| 9 | 9 | |||
| 10 | int base64_decode_value(char value_in) | 10 | int base64_decode_value(char value_in) | |
| 11 | { | 11 | { | |
| 12 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; | 12 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; | |
| 13 | static const char decoding_size = sizeof(decoding); | 13 | static const char decoding_size = sizeof(decoding); | |
| 69 hidden lines | ||||
| 83 | } | 83 | } | |
| 84 | } | 84 | } | |
| 85 | /* control should not reach here */ | 85 | /* control should not reach here */ | |
| 86 | return plainchar - plaintext_out; | 86 | return plainchar - plaintext_out; | |
| 87 | } | 87 | } | |
Changes to src/cencode.c
| Old (daf85ac49a712d98) | New (678381d817164cce) | |||
|---|---|---|---|---|
| 1 | /* | 1 | /* | |
| 2 | cencoder.c - c source to a base64 encoding algorithm implementation | 2 | cencoder.c - c source to a base64 encoding algorithm implementation | |
| 3 | 3 | |||
| 4 | This is part of the libb64 project, and has been placed in the public domain. | 4 | This is part of the libb64 project, and has been placed in the public domain. | |
| 5 | For details, see http://sourceforge.net/projects/libb64 | 5 | For details, see http://sourceforge.net/projects/libb64 | |
| 6 | */ | 6 | */ | |
| 7 | 7 | |||
| 8 | #include <b64/cencode.h> | | | 8 | #include "s11n.net/c11n/detail/b64/cencode.h" |
| 9 | 9 | |||
| 10 | const int CHARS_PER_LINE = 72; | 10 | const int CHARS_PER_LINE = 72; | |
| 11 | 11 | |||
| 12 | void base64_init_encodestate(base64_encodestate* state_in) | 12 | void base64_init_encodestate(base64_encodestate* state_in) | |
| 13 | { | 13 | { | |
| 90 hidden lines | ||||
| 104 | } | 104 | } | |
| 105 | *codechar++ = '\n'; | 105 | *codechar++ = '\n'; | |
| 106 | 106 | |||
| 107 | return codechar - code_out; | 107 | return codechar - code_out; | |
| 108 | } | 108 | } | |
Changes to src/test.c
| Old (9063e71e1dcb9858) | New (5a68ab0207bd4620) | |||
|---|---|---|---|---|
| 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> | |
| 448 hidden lines | ||||
| 454 | //whclob_finalize(check); | 454 | //whclob_finalize(check); | |
| 455 | //whclob_finalize(cb); | 455 | //whclob_finalize(cb); | |
| 456 | return 0; | 456 | return 0; | |
| 457 | } | 457 | } | |
| 458 | 458 | |||
| > | 459 | int test_binary() | ||
| > | 460 | { | ||
| > | 461 | MARKER("Serializing binary data...\n"); | ||
| > | 462 | MyType my; | ||
| > | 463 | my.x = 42; | ||
| > | 464 | my.y = -42; | ||
| > | 465 | c11n_node * n = c11n_node_create("my"); | ||
| > | 466 | if( ! c11n_serialize_binary( n, &my, sizeof(MyType) ) ) | ||
| > | 467 | { | ||
| > | 468 | MARKER("serialize binary failed!\n"); | ||
| > | 469 | c11n_node_destroy( n ); | ||
| > | 470 | return 1; | ||
| > | 471 | } | ||
| > | 472 | c11n_save_node( n, ThisApp.cout, 0 ); | ||
| > | 473 | |||
| > | 474 | MyType my2; | ||
| > | 475 | c11n_binary_data bin; | ||
| > | 476 | if( ! c11n_deserialize_binary( n, &bin ) ) | ||
| > | 477 | { | ||
| > | 478 | MARKER("deserialize binary failed!\n"); | ||
| > | 479 | c11n_node_destroy( n ); | ||
| > | 480 | return 2; | ||
| > | 481 | } | ||
| > | 482 | c11n_node_destroy( n ); | ||
| > | 483 | if( bin.size != sizeof(MyType) ) | ||
| > | 484 | { | ||
| > | 485 | MARKER("Read-in binary data is not the right size!\n"); | ||
| > | 486 | free(bin.data); | ||
| > | 487 | return 3; | ||
| > | 488 | } | ||
| > | 489 | my2 = *((MyType*)bin.data); | ||
| > | 490 | free(bin.data); | ||
| > | 491 | MARKER("Deserialize binary MyType object: my2.x=%d my2.y=%d\n",my2.x, my2.y); | ||
| > | 492 | return 0; | ||
| > | 493 | } | ||
| > | 494 | |||
| 459 | #if C11N_IO_USE_SQL | 495 | #if C11N_IO_USE_SQL | |
| 460 | int test_sql() | 496 | int test_sql() | |
| 461 | { | 497 | { | |
| 462 | c11n_io_handler * ioh = | 498 | c11n_io_handler * ioh = | |
| 463 | //c11n_io_handler_by_name("binarish") | 499 | //c11n_io_handler_by_name("binarish") | |
| 66 hidden lines | ||||
| 530 | DO(test_builder()); | 566 | DO(test_builder()); | |
| 531 | DO(test_otherstuff()); | 567 | DO(test_otherstuff()); | |
| 532 | #if C11N_IO_USE_SQL | 568 | #if C11N_IO_USE_SQL | |
| 533 | DO(test_sql()); | 569 | DO(test_sql()); | |
| 534 | #endif | 570 | #endif | |
| > | 571 | DO(test_binary()); | ||
| 535 | #undef DO | 572 | #undef DO | |
| 536 | printf("Done - cleaning up. rc=%d=[%s].\n",rc, | 573 | printf("Done - cleaning up. rc=%d=[%s].\n",rc, | |
| 537 | (0==rc) | 574 | (0==rc) | |
| 538 | ? "You win :)" | 575 | ? "You win :)" | |
| 539 | : "You lose :("); | 576 | : "You lose :("); | |
| 540 | ThisApp.cout->api->destroy(ThisApp.cout); | 577 | ThisApp.cout->api->destroy(ThisApp.cout); | |
| 541 | whgc_destroy_context(ThisApp.gc); | 578 | whgc_destroy_context(ThisApp.gc); | |
| 542 | return rc; | 579 | return rc; | |
| 543 | } | 580 | } | |
Changes to src/whclob.c
| Old (54232cf93b0c90fe) | New (11d6042d3c580e26) | |||
|---|---|---|---|---|
| 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 | |||
| 309 hidden lines | ||||
| 315 | if( !n ) return whclob_rc.OK; | 315 | if( !n ) return whclob_rc.OK; | |
| 316 | } | 316 | } | |
| 317 | if( data && (n < 0) ) n = strlen( data ); | 317 | if( data && (n < 0) ) n = strlen( data ); | |
| 318 | #if 1 | 318 | #if 1 | |
| 319 | rc = whclob_reserve( *cb, n ); | 319 | rc = whclob_reserve( *cb, n ); | |
| > | 320 | //rc = whclob_resize( *cb, n ); | ||
| 320 | if( rc < whclob_rc.OK ) | 321 | if( rc < whclob_rc.OK ) | |
| 321 | { | 322 | { | |
| 322 | free( *cb ); | 323 | free( *cb ); | |
| 323 | *cb = 0; | 324 | *cb = 0; | |
| 324 | return rc; | 325 | return rc; | |
| 900 hidden lines | ||||
| 1225 | whclob_resize( tmp, rc ); | 1226 | whclob_resize( tmp, rc ); | |
| 1226 | whclob_swap( cOut, tmp ); | 1227 | whclob_swap( cOut, tmp ); | |
| 1227 | whclob_finalize( tmp ); | 1228 | whclob_finalize( tmp ); | |
| 1228 | return whclob_rc.OK; | 1229 | return whclob_rc.OK; | |
| 1229 | } | 1230 | } | |
| > | 1231 | |||
| 1230 | long whclob_base64_dec( whclob const *cIn, whclob *cOut ) | 1232 | long whclob_base64_dec( whclob const *cIn, whclob *cOut ) | |
| 1231 | { | 1233 | { | |
| 1232 | unsigned int szIn = whclob_size(cIn); | 1234 | unsigned int szIn = whclob_size(cIn); | |
| 1233 | unsigned int szOut = szIn; | 1235 | unsigned int szOut = szIn; | |
| 1234 | long rc = 0; | 1236 | long rc = 0; | |
| 15 hidden lines | ||||
| 1250 | return whclob_rc.OK; | 1252 | return whclob_rc.OK; | |
| 1251 | } | 1253 | } | |
| 1252 | #endif /* WHCLOB_USE_BASE64 */ | 1254 | #endif /* WHCLOB_USE_BASE64 */ | |
| 1253 | 1255 | |||
| 1254 | #undef WHCLOB_DEBUG | 1256 | #undef WHCLOB_DEBUG | |