head 1.6; access; symbols last-version-in-peti-style:1.5 callback-semantic-rewrite:1.3.0.2; locks; strict; comment @ * @; 1.6 date 2001.08.08.19.15.23; author rse; state dead; branches; next 1.5; 1.5 date 2001.08.02.08.10.13; author simons; state Exp; branches; next 1.4; 1.4 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.3; 1.3 date 2001.07.23.15.33.42; author simons; state Exp; branches 1.3.2.1; next 1.2; 1.2 date 2001.07.20.10.56.01; author simons; state Exp; branches; next 1.1; 1.1 date 2001.07.19.12.28.15; author simons; state Exp; branches; next ; 1.3.2.1 date 2001.08.01.11.26.56; author simons; state Exp; branches; next 1.3.2.2; 1.3.2.2 date 2001.08.01.13.26.29; author simons; state Exp; branches; next 1.3.2.3; 1.3.2.3 date 2001.08.01.14.38.07; author simons; state Exp; branches; next ; desc @@ 1.6 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 "xds.h" int xdr_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) { xds_uint64_t value; xds_init_encoding_engine(8); /* Get value and format it into the buffer. */ value = va_arg(*args, xds_uint64_t); ((xds_uint8_t*)buffer)[0] = (value >> 56) & 0x000000ff; ((xds_uint8_t*)buffer)[1] = (value >> 48) & 0x000000ff; ((xds_uint8_t*)buffer)[2] = (value >> 40) & 0x000000ff; ((xds_uint8_t*)buffer)[3] = (value >> 32) & 0x000000ff; ((xds_uint8_t*)buffer)[4] = (value >> 24) & 0x000000ff; ((xds_uint8_t*)buffer)[5] = (value >> 16) & 0x000000ff; ((xds_uint8_t*)buffer)[6] = (value >> 8) & 0x000000ff; ((xds_uint8_t*)buffer)[7] = (value >> 0) & 0x000000ff; /* Done. */ return XDS_OK; } @ 1.5 log @Include xds.h, not internal.h! @ text @@ 1.4 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 @d28 1 a28 1 #include "internal.h" @ 1.3 log @Removed redundant include of sys/types.h. @ text @a27 1 #include d30 3 a32 1 int xdr_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) d34 1 a34 1 /* Consistency checks. */ d36 1 a36 6 assert(xds != NULL); assert(buffer != NULL); assert(buffer_size != 0); assert(args != NULL); if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; d40 9 a48 12 if (buffer_size >= 8) { xds_uint64_t value = va_arg(*args, xds_uint64_t); ((xds_uint8_t*)buffer)[0] = (value >> 56) & 0x000000ff; ((xds_uint8_t*)buffer)[1] = (value >> 48) & 0x000000ff; ((xds_uint8_t*)buffer)[2] = (value >> 40) & 0x000000ff; ((xds_uint8_t*)buffer)[3] = (value >> 32) & 0x000000ff; ((xds_uint8_t*)buffer)[4] = (value >> 24) & 0x000000ff; ((xds_uint8_t*)buffer)[5] = (value >> 16) & 0x000000ff; ((xds_uint8_t*)buffer)[6] = (value >> 8) & 0x000000ff; ((xds_uint8_t*)buffer)[7] = (value >> 0) & 0x000000ff; } d52 1 a52 1 return 8; @ 1.3.2.1 log @- Rewrote callbacks for new semantics. - Added use of the xds_check_parameter() macro. @ text @d31 1 a31 3 int xdr_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) a32 2 xds_uint64_t value; d35 6 a40 13 xds_check_parameter(xds != NULL); xds_check_parameter(buffer != NULL); xds_check_parameter(buffer_size != 0); xds_check_parameter(used_buffer_size != NULL); xds_check_parameter(args != NULL); /* We need 8 bytes in the buffer to format our parameter. If we don't have them, return an overflow error. */ if (buffer_size < 8) return XDS_ERR_OVERFLOW; else *used_buffer_size = 8; d44 12 a55 9 value = va_arg(*args, xds_uint64_t); ((xds_uint8_t*)buffer)[0] = (value >> 56) & 0x000000ff; ((xds_uint8_t*)buffer)[1] = (value >> 48) & 0x000000ff; ((xds_uint8_t*)buffer)[2] = (value >> 40) & 0x000000ff; ((xds_uint8_t*)buffer)[3] = (value >> 32) & 0x000000ff; ((xds_uint8_t*)buffer)[4] = (value >> 24) & 0x000000ff; ((xds_uint8_t*)buffer)[5] = (value >> 16) & 0x000000ff; ((xds_uint8_t*)buffer)[6] = (value >> 8) & 0x000000ff; ((xds_uint8_t*)buffer)[7] = (value >> 0) & 0x000000ff; d59 1 a59 1 return XDS_OK; @ 1.3.2.2 log @Now that internal.h includes assert.h we don't need to do that anymore. @ text @d28 1 @ 1.3.2.3 log @Rewrote engines to conform with the new semantic. @ text @d36 15 a50 1 xds_init_encoding_engine(8); @ 1.2 log @Use xds_(u)int(8|16|32|64) instead of the system defines. @ text @a28 1 #include @ 1.1 log @Split the various encoding and decoding routines into separate files so that the linker may pull them in separately. @ text @d47 9 a55 9 u_int64_t value = va_arg(*args, u_int64_t); ((u_int8_t*)buffer)[0] = (value >> 56) & 0x000000ff; ((u_int8_t*)buffer)[1] = (value >> 48) & 0x000000ff; ((u_int8_t*)buffer)[2] = (value >> 40) & 0x000000ff; ((u_int8_t*)buffer)[3] = (value >> 32) & 0x000000ff; ((u_int8_t*)buffer)[4] = (value >> 24) & 0x000000ff; ((u_int8_t*)buffer)[5] = (value >> 16) & 0x000000ff; ((u_int8_t*)buffer)[6] = (value >> 8) & 0x000000ff; ((u_int8_t*)buffer)[7] = (value >> 0) & 0x000000ff; @