head 1.8; access; symbols last-version-in-peti-style:1.7 callback-semantic-rewrite:1.6.0.2; locks; strict; comment @ * @; 1.8 date 2001.08.08.19.15.23; author rse; state dead; branches; next 1.7; 1.7 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.6; 1.6 date 2001.07.31.06.33.55; author simons; state Exp; branches 1.6.2.1; next 1.5; 1.5 date 2001.07.18.17.49.51; author simons; state Exp; branches; next 1.4; 1.4 date 2001.07.09.19.20.58; author simons; state Exp; branches; next 1.3; 1.3 date 2001.07.09.19.19.37; author simons; state Exp; branches; next 1.2; 1.2 date 2001.07.09.17.20.56; author simons; state Exp; branches; next 1.1; 1.1 date 2001.07.04.15.58.51; author simons; state Exp; branches; next ; 1.6.2.1 date 2001.08.01.09.55.58; author simons; state Exp; branches; next 1.6.2.2; 1.6.2.2 date 2001.08.01.13.26.29; author simons; state Exp; branches; next ; desc @@ 1.8 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. */ #include "internal.h" int xds_setbuffer(xds_t* xds, xds_scope_t flag, void* buffer, size_t buffer_len) { /* Sanity checks. */ xds_check_parameter(xds != NULL); xds_check_parameter(flag == XDS_GIFT || flag == XDS_LOAN); xds_check_parameter((buffer != NULL && buffer_len != 0) || flag == XDS_GIFT); /* Free the old buffer if there is one. */ if (xds->buffer != NULL && xds->we_own_buffer) free(xds->buffer); xds->buffer_len = 0; if (flag == XDS_GIFT) { xds->buffer = buffer; if (buffer == NULL) xds->buffer_capacity = 0; else xds->buffer_capacity = buffer_len; xds->we_own_buffer = XDS_TRUE; } else { xds->buffer = buffer; xds->buffer_capacity = buffer_len; xds->we_own_buffer = XDS_FALSE; } return XDS_OK; } @ 1.7 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 @@ 1.6 log @Fixed three bugs revealed by RSE's review of the code. @ text @a27 1 #include "assert.h" d34 3 a36 6 assert(xds != NULL); assert(flag == XDS_GIFT || flag == XDS_LOAN); assert((buffer != NULL && buffer_len != 0) || flag == XDS_GIFT); if (xds == NULL || (flag != XDS_GIFT && flag != XDS_LOAN) || (flag == XDS_LOAN && (buffer == NULL || buffer_len == 0))) return XDS_ERR_INVALID_ARG; @ 1.6.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 @d35 6 a40 3 xds_check_parameter(xds != NULL); xds_check_parameter(flag == XDS_GIFT || flag == XDS_LOAN); xds_check_parameter((buffer != NULL && buffer_len != 0) || flag == XDS_GIFT); @ 1.6.2.2 log @Now that internal.h includes assert.h we don't need to do that anymore. @ text @d28 1 @ 1.5 log @Added XDS_TRUE and XDS_FALSE defines and started using them in the sources. @ text @d44 1 a44 1 if (xds->buffer != NULL) @ 1.4 log @Swapped order of if statement to be more efficient. @ text @d55 1 a55 1 xds->we_own_buffer = (1==1); d61 1 a61 1 xds->we_own_buffer = (1!=1); @ 1.3 log @Implemented xds_setbuffer(). @ text @d39 1 a39 1 ((buffer == NULL || buffer_len == 0) && flag == XDS_LOAN)) @ 1.2 log @Renamed argument in the xds_getbuffer() prototype from buffer_size to buffer_len for consistency. @ text @d28 1 d31 1 a31 1 int xds_setbuffer(xds_t* xds, xds_scope_t flag, void* buffer, size_t buffer_len) d33 32 a64 1 return XDS_ERR_INVALID_ARG; @ 1.1 log @Added function stubs that return errors when called. @ text @d30 1 a30 1 int xds_setbuffer(xds_t* xds, xds_scope_t flag, void* buffer, size_t buffer_size) @