head 1.10; access; symbols last-version-in-peti-style:1.9 callback-semantic-rewrite:1.7.0.2; locks; strict; comment @ * @; 1.10 date 2001.08.08.19.15.23; author rse; state dead; branches; next 1.9; 1.9 date 2001.08.02.08.12.26; author simons; state Exp; branches; next 1.8; 1.8 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.7; 1.7 date 2001.07.31.15.27.45; author simons; state Exp; branches 1.7.2.1; next 1.6; 1.6 date 2001.07.18.17.49.51; author simons; state Exp; branches; next 1.5; 1.5 date 2001.07.09.17.21.36; author simons; state Exp; branches; next 1.4; 1.4 date 2001.07.08.15.28.51; author simons; state Exp; branches; next 1.3; 1.3 date 2001.07.08.15.20.34; author simons; state Exp; branches; next 1.2; 1.2 date 2001.07.08.14.09.42; author simons; state Exp; branches; next 1.1; 1.1 date 2001.07.04.16.05.06; author simons; state Exp; branches; next ; 1.7.2.1 date 2001.08.01.09.55.58; author simons; state Exp; branches; next 1.7.2.2; 1.7.2.2 date 2001.08.01.13.25.20; author simons; state Exp; branches; next ; desc @@ 1.10 log @First cut of the ruthless style adjustments to OSSP XDS: o adjust source tree to follow OSSP source tree style by heavily combining sources into smaller sets (needs more work when still missing parts are added later) o automatic re-indentation of sources with GNU indent (still needs manual review and adjustments; will follow) These two heavy steps were mostly done automatically with the help of two helper scripts written in Perl. So expect more manual adjustments to follow... @ text @/* XDS - OSSP Extensible Data Serialization Library Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) This file is part of OSSP XDS, an extensible data serialization library which can be found at http://www.ossp.com/pkg/xds/. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. internal.h: internal C API */ #ifndef __INTERNAL_H__ #define __INTERNAL_H__ #include "xds.h" #define XDS_INITIAL_BUFFER_CAPACITY 512 #define XDS_INITIAL_ENGINES_CAPACITY 32 typedef struct { char* name; xds_engine_t engine; void* context; } engine_map_t; struct xds_context { xds_mode_t mode; char* buffer; size_t buffer_len; size_t buffer_capacity; int we_own_buffer; engine_map_t* engines; size_t engines_len; size_t engines_capacity; }; int xds_find_engine(const engine_map_t* engines, size_t last, const char* name, size_t* pos); int xds_set_capacity(void** array, size_t* array_capacity, size_t new_capacity, size_t elem_size, size_t initial_capacity); #endif /* !defined(__INTERNAL_H__) */ @ 1.9 log @- Moved definition of xds_check_parameter(), xds_init_encoding_engine(), and xds_init_decoding_engine() from internal.h to xds.h so that the callbacks don't need to include internal.h. - Renamed declare_formatting_engine() to xds_declare_formatting_engine(). @ text @@ 1.8 log @Merged the whole contents of branch "callback-semantic-rewrite" into the main branch. The changes there include: - A change of the callback semantics; callbacks do now return XDS_ERR_(UNDER|OVER)FLOW in case the buffer size doesn't fit. Rather than passing the differing byte size through the return code, it is stored in the location used_buffer_size points to -- a new parameter provided to all callbacks. In order to implement this, the framework, all callbacks and most of the test suits had to be adapted. - internal.h now provides the macro xds_check_parameter(), which can be used to verify the contents of function parameters with assert() and if in one line. If assert()s are deactivated, the routine will still return XDS_ERR_INVALID_ARG. Because of this change, internal.h now includes the system header assert.h. This means that this include coulde be removed from almost all modules. - internal.h now provides the macros xds_init_(en|de)coding_engine(). These can be used to comfortably verify a callback's parameters and to verify the buffer size. All engines have been rewritten to use these. @ text @a32 1 #include a34 3 #define XDS_TRUE (1==1) #define XDS_FALSE (1!=1) a61 37 extern const char xds_xml_begin_text[]; extern const char xds_xml_end_text[]; #define xds_check_parameter(condition) \ do \ { \ assert(condition); \ if (!(condition)) \ return XDS_ERR_INVALID_ARG; \ } while(XDS_FALSE) #define xds_init_encoding_engine(size) \ do \ { \ xds_check_parameter(xds != NULL); \ xds_check_parameter(buffer != NULL); \ xds_check_parameter(buffer_size != 0); \ xds_check_parameter(used_buffer_size != NULL && *used_buffer_size == 0); \ xds_check_parameter(args != NULL); \ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_OVERFLOW; \ } while(XDS_FALSE) #define xds_init_decoding_engine(size) \ do \ { \ xds_check_parameter(xds != NULL); \ xds_check_parameter(buffer != NULL); \ xds_check_parameter(buffer_size != 0); \ xds_check_parameter(used_buffer_size != NULL && *used_buffer_size == 0); \ xds_check_parameter(args != NULL); \ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_UNDERFLOW; \ } while(XDS_FALSE) @ 1.7 log @Implemented xml_encode_begin(), xml_decode_begin(), xml_encode_end(), and xml_decode_end(). @ text @d33 1 d69 34 @ 1.7.2.1 log @Added xds_check_parameter() macro to short-cut the assert() and if-statements at the begining of every routine. Also rewrote some modules to take advantage of that macro. @ text @a68 8 #define xds_check_parameter(condition) \ do \ { \ assert(condition); \ if (!(condition)) \ return XDS_ERR_INVALID_ARG; \ } while(XDS_FALSE) @ 1.7.2.2 log @- Added xds_init_encoding_engine() and xds_init_decoding_engine() macros. - Include assert.h since we use the assert() function in our header. @ text @a32 1 #include d74 1 a74 27 return XDS_ERR_INVALID_ARG; \ } while(XDS_FALSE) #define xds_init_encoding_engine(size) \ do \ { \ xds_check_parameter(xds != NULL); \ xds_check_parameter(buffer != NULL); \ xds_check_parameter(buffer_size != 0); \ xds_check_parameter(used_buffer_size != NULL && *used_buffer_size == 0); \ xds_check_parameter(args != NULL); \ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_OVERFLOW; \ } while(XDS_FALSE) #define xds_init_decoding_engine(size) \ do \ { \ xds_check_parameter(xds != NULL); \ xds_check_parameter(buffer != NULL); \ xds_check_parameter(buffer_size != 0); \ xds_check_parameter(used_buffer_size != NULL && *used_buffer_size == 0); \ xds_check_parameter(args != NULL); \ *used_buffer_size = size; \ if (buffer_size < size) \ return XDS_ERR_UNDERFLOW; \ @ 1.6 log @Added XDS_TRUE and XDS_FALSE defines and started using them in the sources. @ text @d66 3 @ 1.5 log @Added XDS_INITIAL_BUFFER_CAPACITY define. @ text @d35 3 @ 1.4 log @Added define for the initial size of the engines array to internal.h and use it in xds_register(). @ text @d35 2 a36 1 #define XDS_INITIAL_ENGINES_CAPACITY 32 @ 1.3 log @Added generic xds_set_capacity() function that will handle the enlarging of dynamic buffers for the rest of the code. @ text @d35 2 @ 1.2 log @- Added definition of engine_map_t. - Added prototype for xds_find_engine(). - Renamed buffer_size to buffer_capacity in xds_context. - Added engine_map_t stuff to xds_context. @ text @d58 1 @ 1.1 log @This is our internal header which defines all the data structures that are opaque for the application developer. @ text @d35 8 d45 1 a45 1 xds_mode_t mode; /* XDS_ENCODE or XDS_DECODE */ d47 8 a54 3 char* buffer; /* may be NULL if unallocated */ size_t buffer_size; /* physical size of the buffer */ size_t buffer_len; /* length of buffer's content */ d56 2 @