head 1.6; access; symbols last-version-in-peti-style:1.5 callback-semantic-rewrite:1.2.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.08.11.50.16; author simons; state Exp; branches; next 1.4; 1.4 date 2001.08.02.08.10.13; author simons; state Exp; branches; next 1.3; 1.3 date 2001.08.01.15.25.47; author simons; state Exp; branches; next 1.2; 1.2 date 2001.07.24.13.52.41; author simons; state Exp; branches 1.2.2.1; next 1.1; 1.1 date 2001.07.23.16.17.43; author simons; state Exp; branches; next ; 1.2.2.1 date 2001.08.01.13.26.29; author simons; state Exp; branches; next 1.2.2.2; 1.2.2.2 date 2001.08.01.15.08.02; 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 #include "xds.h" int xml_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) { xds_uint32_t* value; char* p; xds_init_decoding_engine(8 + 9 + 1); /* Does the opening XML tag match? */ if (strncasecmp(buffer, "", 8) != 0) return XDS_ERR_TYPE_MISMATCH; /* Decode the representation of the value. */ value = va_arg(*args, xds_uint32_t*); *value = 0; p = (char*)buffer + 8; while(isdigit((int)*p)) { if (p >= (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; *value *= 10; *value += *p++ - '0'; } /* Does the closing XML tag match? */ if (p+9 > (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; else if (strncasecmp(p, "", 9) != 0) return XDS_ERR_TYPE_MISMATCH; *used_buffer_size = p + 9 - (char*)buffer; return XDS_OK; } @ 1.5 log @Fixed warnings that complained about feeding a "char" into the isxxx() routines, which expect an "int". @ text @@ 1.4 log @Include xds.h, not internal.h! @ text @d51 1 a51 1 while(isdigit(*p)) @ 1.3 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 @d30 1 a30 1 #include "internal.h" @ 1.2 log @If there are any ladies reading this: Please pardon my language in the following paragraph! Fuck snprintf(). Since apparently the Unix vendors are too bloody stupid to provide a working snprintf() implementation that conforms to an 8 year old standard, we don't use snprintf() at all but convert the numbers ourselves. I re-implemented all XML callbacks to do maths on their own. @ text @a29 1 #include d32 3 a34 1 int xml_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) d39 1 a39 14 /* 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; /* The buffer must contain at least opening tag, closing tag and one digit. Check whether it is large enough. */ if (buffer_size < 8 + 9 + 1) return XDS_ERR_UNDERFLOW; d43 1 a43 1 if (strncmp(buffer, "", 8) != 0) d63 1 a63 1 else if (strncmp(p, "", 9) != 0) d66 2 a67 1 return p + 9 - (char*)buffer; @ 1.2.2.1 log @Now that internal.h includes assert.h we don't need to do that anymore. @ text @d30 1 @ 1.2.2.2 log @Rewrote callbacks for new semantic. @ text @d32 1 a32 3 int xml_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) d37 14 a50 1 xds_init_decoding_engine(8 + 9 + 1); d54 1 a54 1 if (strncasecmp(buffer, "", 8) != 0) d74 1 a74 1 else if (strncasecmp(p, "", 9) != 0) d77 1 a77 2 *used_buffer_size = p + 9 - (char*)buffer; return XDS_OK; @ 1.1 log @Added XML implementations for uint32, int64, and uint64. @ text @d28 2 a29 1 #include a34 1 int rc; d36 1 a36 1 int len; d47 12 a58 1 /* Format value into buffer. */ d61 13 a73 2 rc = sscanf(buffer, "%u%n", value, &len); if (rc <= 0) d75 2 d78 1 a78 1 return len; @