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.20.09.22.25; 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 #include "xds.h" int xdr_decode_octetstream(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) { void** p; size_t* p_len; size_t padding; xds_init_decoding_engine(4); p = va_arg(*args, void**); p_len = va_arg(*args, size_t*); xds_check_parameter(p != NULL); xds_check_parameter(p_len != NULL); /* Read the size of the message. */ *p_len = ((xds_uint8_t*)buffer)[0]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[1]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[2]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[3]; /* Calculate padding. */ padding = (4 - (*p_len & 0x03)) & 0x03; /* Do we have enough data?. */ *used_buffer_size = 4 + *p_len + padding; if (buffer_size < *used_buffer_size) return XDS_ERR_UNDERFLOW; /* Allocate buffer for the data. */ *p = malloc(*p_len); if (*p == NULL) return XDS_ERR_NO_MEM; /* Copy data into the buffer. */ memmove(*p, (xds_uint8_t*)buffer+4, *p_len); /* 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 @d29 1 a29 1 #include "internal.h" @ 1.3 log @Removed redundant include of sys/types.h. @ text @a28 1 #include d31 3 a33 1 int xdr_decode_octetstream(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) d39 1 a39 10 /* Consistency checks. */ 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; /* Get pointers from the stack. */ d43 2 a44 2 assert(p != NULL); assert(p_len != NULL); d48 4 a51 9 if (buffer_size >= 4) { *p_len = ((xds_uint8_t*)buffer)[0]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[1]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[2]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[3]; } else return XDS_ERR_UNDERFLOW; d59 2 a60 1 if (buffer_size < 4 + *p_len + padding) d75 1 a75 1 return 4 + *p_len + padding; @ 1.3.2.1 log @- Rewrote callbacks for new semantics. - Added use of the xds_check_parameter() macro. @ text @d32 1 a32 3 int xdr_decode_octetstream(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) d40 6 a45 5 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); a73 2 else *used_buffer_size = 4 + *p_len + padding; d87 1 a87 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 @d29 1 @ 1.3.2.3 log @Rewrote engines to conform with the new semantic. @ text @d39 9 a47 1 xds_init_decoding_engine(4); d51 2 a52 2 xds_check_parameter(p != NULL); xds_check_parameter(p_len != NULL); d56 9 a64 4 *p_len = ((xds_uint8_t*)buffer)[0]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[1]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[2]; *p_len = *p_len << 8; *p_len += ((xds_uint8_t*)buffer)[3]; d72 1 a72 2 *used_buffer_size = 4 + *p_len + padding; if (buffer_size < *used_buffer_size) d74 2 @ 1.2 log @Use xds_(u)int(8|16|32|64) instead of the system defines. @ text @a29 1 #include @ 1.1 log @People who know how to spell clearly have an advantage. @ text @d59 4 a62 4 *p_len = ((u_int8_t*)buffer)[0]; *p_len = *p_len << 8; *p_len += ((u_int8_t*)buffer)[1]; *p_len = *p_len << 8; *p_len += ((u_int8_t*)buffer)[2]; *p_len = *p_len << 8; *p_len += ((u_int8_t*)buffer)[3]; d84 1 a84 1 memmove(*p, (u_int8_t*)buffer+4, *p_len); @