Index: ossp-pkg/xds/regression-tests/xdr-string-empty.c RCS File: /v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xdr-string-empty.c,v co -q -kk -p'1.3' '/v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xdr-string-empty.c,v' | diff -u - /dev/null -L'ossp-pkg/xds/regression-tests/xdr-string-empty.c' 2>/dev/null --- ossp-pkg/xds/regression-tests/xdr-string-empty.c +++ /dev/null 2024-05-16 01:55:00.000000000 +0200 @@ -1,110 +0,0 @@ -/* - 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 "../internal.h" - -int main() - { - xds_t* xds; - char* buffer; - size_t buffer_size; - - char msg[] = ""; - char* new_msg; - size_t new_msg_size; - - /* Encode the string as octet stream. Then erase the buffer and - decode the string back, verifying that it hasn't changed. */ - - xds = xds_init(XDS_ENCODE); - if (xds == NULL) - { - printf("Failed to initialize XDS context.\n"); - return 1; - } - if (xds_register(xds, "os", &xdr_encode_string, NULL) != XDS_OK) - { - printf("Failed to register my encoding engines.\n"); - return 1; - } - if (xds_encode(xds, "os", msg, 0) != XDS_OK) - { - printf("xds_encode() failed.\n"); - return 1; - } - if (xds_getbuffer(xds, XDS_GIFT, (void**)&buffer, &buffer_size) != XDS_OK) - { - printf("xds_getbuffer() failed.\n"); - return 1; - } - xds_destroy(xds); - if (buffer_size % 4 != 0) - { - printf("The encoded strings' buffer size is not a multiple of 4.\n"); - return 1; - } - - xds = xds_init(XDS_DECODE); - if (xds == NULL) - { - printf("Failed to initialize XDS context.\n"); - return 1; - } - if (xds_register(xds, "os", &xdr_decode_string, NULL) != XDS_OK) - { - printf("Failed to register my decoding engines.\n"); - return 1; - } - if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) - { - printf("xds_setbuffer() failed.\n"); - return 1; - } - if (xds_decode(xds, "os", &new_msg, &new_msg_size) != XDS_OK) - { - printf("xds_decode() failed.\n"); - return 1; - } - if (new_msg_size != 0) - { - printf("The size of the decoded message is wrong.\n"); - return 1; - } - if (memcmp(msg, new_msg, new_msg_size) != 0) - { - printf("The decoded string is not correct.\n"); - return 1; - } - xds_destroy(xds); - free(new_msg); - - /* Everything went fine. */ - - return 0; - } Index: ossp-pkg/xds/regression-tests/xdr-string.c RCS File: /v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xdr-string.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/xds/regression-tests/Attic/xdr-string.c,v' 2>/dev/null --- xdr-string.c 2001/08/01 15:25:50 1.3 +++ xdr-string.c 2001/08/02 11:52:12 1.4 @@ -37,7 +37,6 @@ char msg[] = "Hello World"; char* new_msg; - size_t new_msg_size; /* Encode the string as octet stream. Then erase the buffer and decode the string back, verifying that it hasn't changed. */ @@ -48,12 +47,12 @@ printf("Failed to initialize XDS context.\n"); return 1; } - if (xds_register(xds, "os", &xdr_encode_string, NULL) != XDS_OK) + if (xds_register(xds, "string", &xdr_encode_string, NULL) != XDS_OK) { printf("Failed to register my encoding engines.\n"); return 1; } - if (xds_encode(xds, "os", msg) != XDS_OK) + if (xds_encode(xds, "string", msg) != XDS_OK) { printf("xds_encode() failed.\n"); return 1; @@ -76,7 +75,7 @@ printf("Failed to initialize XDS context.\n"); return 1; } - if (xds_register(xds, "os", &xdr_decode_string, NULL) != XDS_OK) + if (xds_register(xds, "string", &xdr_decode_string, NULL) != XDS_OK) { printf("Failed to register my decoding engines.\n"); return 1; @@ -86,17 +85,17 @@ printf("xds_setbuffer() failed.\n"); return 1; } - if (xds_decode(xds, "os", &new_msg, &new_msg_size) != XDS_OK) + if (xds_decode(xds, "string", &new_msg) != XDS_OK) { printf("xds_decode() failed.\n"); return 1; } - if (new_msg_size != strlen(msg)) + if (strlen(new_msg) != strlen(msg)) { - printf("The size of the decoded message is wrong: %d.\n", new_msg_size); + printf("The size of the decoded message is wrong.\n"); return 1; } - if (memcmp(msg, new_msg, new_msg_size) != 0) + if (memcmp(msg, new_msg, strlen(new_msg)) != 0) { printf("The decoded string is not correct.\n"); return 1; Index: ossp-pkg/xds/xdr-decode-string.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xdr-decode-string.c,v co -q -kk -p'1.6' '/v/ossp/cvs/ossp-pkg/xds/Attic/xdr-decode-string.c,v' | diff -u - /dev/null -L'ossp-pkg/xds/xdr-decode-string.c' 2>/dev/null --- ossp-pkg/xds/xdr-decode-string.c +++ /dev/null 2024-05-16 01:55:00.000000000 +0200 @@ -1,77 +0,0 @@ -/* - 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_string(xds_t* xds, void* engine_context, - void* buffer, size_t buffer_size, size_t* used_buffer_size, - va_list* args) - { - char** p; - size_t* p_len; - size_t padding; - - xds_init_decoding_engine(4); - - p = va_arg(*args, char**); - 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 = (char*)malloc(*p_len + 1); - if (*p == NULL) - return XDS_ERR_NO_MEM; - - /* Copy data into the buffer. */ - - memmove(*p, (xds_uint8_t*)buffer+4, *p_len); - ((xds_uint8_t*)buffer)[4+*p_len] = '\0'; - - /* Done. */ - - return XDS_OK; - }