Index: ossp-pkg/xds/xml-decode-octetstream.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-octetstream.c,v co -q -kk -p'1.2' '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-octetstream.c,v' | diff -u - /dev/null -L'ossp-pkg/xds/xml-decode-octetstream.c' 2>/dev/null --- ossp-pkg/xds/xml-decode-octetstream.c +++ /dev/null 2024-05-14 17:11:00.000000000 +0200 @@ -1,224 +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 "xds.h" - -static int base64_decode(unsigned char *dst, size_t dstlen, char const *src, size_t srclen) - { - int dstidx, state, ch = 0; - unsigned char res; - char *pos; - - if (srclen == 0) - srclen = strlen(src); - state = 0; - dstidx = 0; - res = 0; - while (srclen-- > 0) - { - ch = *src++; - if (isascii(ch) && isspace(ch)) /* Skip whitespace anywhere */ - continue; - if (ch == xds_pad64) - break; - pos = strchr(xds_base64, ch); - if (pos == 0) /* A non-base64 character */ - return -1; - switch (state) - { - case 0: - if (dst != NULL) - { - if ((size_t)dstidx >= dstlen) - return -1; - dst[dstidx] = ((pos - xds_base64) << 2); - } - state = 1; - break; - case 1: - if (dst != NULL) - { - if ((size_t)dstidx >= dstlen) - return -1; - dst[dstidx] |= ((pos - xds_base64) >> 4); - res = (((pos - xds_base64) & 0x0f) << 4); - } - dstidx++; - state = 2; - break; - case 2: - if (dst != NULL) - { - if ((size_t)dstidx >= dstlen) - return -1; - dst[dstidx] = res | ((pos - xds_base64) >> 2); - res = ((pos - xds_base64) & 0x03) << 6; - } - dstidx++; - state = 3; - break; - case 3: - if (dst != NULL) - { - if ((size_t)dstidx >= dstlen) - return -1; - dst[dstidx] = res | (pos - xds_base64); - } - dstidx++; - state = 0; - break; - default: - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == xds_pad64) - { /* We got a pad char. */ - switch (state) - { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return -1; - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - while(srclen > 0) - { - ch = *src++; - --srclen; - if (!(isascii(ch) && isspace(ch))) - break; - } - /* Make sure there is another trailing = sign. */ - if (ch != xds_pad64) - return -1; - /* FALLTHROUGH */ - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - while(srclen > 0) - { - ch = *src++; - --srclen; - if (!(isascii(ch) && isspace(ch))) - return -1; - } - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (dst != NULL && res != 0) - return -1; - default: - break; - } - } - else - { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return -1; - } - - return dstidx; - } - -int xml_decode_octetstream(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; - xds_uint8_t** data; - size_t* data_len; - - /* We need at least 27 byte for the starting and ending tag. */ - - xds_init_encoding_engine(13 + 14); - - /* Get parameters from stack. */ - - data = va_arg(*args, xds_uint8_t**); - xds_check_parameter(data != NULL); - data_len = va_arg(*args, size_t*); - - /* Check for the opening tag. */ - - if (memcmp("", buffer, 13) != 0) - return XDS_ERR_TYPE_MISMATCH; - - /* Find the end of the data and calculate the length of the - base64-encoded stuff. */ - - p = (char*)buffer + 13; - while(p < ((char*)buffer+buffer_size) && *p != '<') - ++p; - if (p == ((char*)buffer+buffer_size)) - return XDS_ERR_TYPE_MISMATCH; - else - { - p_len = p - ((char*)buffer + 13); - p = (char*)buffer + 13; - } - - /* Now find out how long the decoded data is going to be, allocate - a buffer for it, and decode away. */ - - *data_len = base64_decode(NULL, 0, p, p_len); - if (*data_len == (size_t)-1) - return XDS_ERR_UNKNOWN; - *data = malloc(*data_len); - if (*data == NULL) - return XDS_ERR_NO_MEM; - base64_decode(*data, *data_len, p, p_len); - - /* Check that we have a closing tag. */ - - if (memcmp(p + p_len, "", 14) != 0) - { - free(*data); - return XDS_ERR_TYPE_MISMATCH; - } - - /* Done. */ - - *used_buffer_size = 13 + p_len + 14; - return XDS_OK; - } Index: ossp-pkg/xds/xml-encode-octetstream.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-octetstream.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-octetstream.c,v' | diff -u - /dev/null -L'ossp-pkg/xds/xml-encode-octetstream.c' 2>/dev/null --- ossp-pkg/xds/xml-encode-octetstream.c +++ /dev/null 2024-05-14 17:11:00.000000000 +0200 @@ -1,142 +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 "xds.h" - -const char xds_base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -const char xds_pad64 = '='; - -static int base64_encode(char *dst, size_t dstlen, unsigned char const *src, size_t srclen) - { - size_t dstpos; - unsigned char input[3]; - unsigned char output[4]; - int ocnt; - size_t i; - - if (srclen == 0) - return -1; - if (dst == NULL) - { - /* just calculate required length of dst */ - dstlen = (((srclen + 2) / 3) * 4); - return dstlen; - } - - /* bulk encoding */ - dstpos = 0; - ocnt = 0; - while (srclen >= 3) - { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclen -= 3; - - output[0] = (input[0] >> 2); - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = (input[2] & 0x3f); - - if (dstpos + 4 > dstlen) - return -1; - dst[dstpos++] = xds_base64[output[0]]; - dst[dstpos++] = xds_base64[output[1]]; - dst[dstpos++] = xds_base64[output[2]]; - dst[dstpos++] = xds_base64[output[3]]; - } - - /* now worry about padding with remaining 1 or 2 bytes */ - if (srclen != 0) - { - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclen; i++) - input[i] = *src++; - - output[0] = (input[0] >> 2); - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (dstpos + 4 > dstlen) - return -1; - dst[dstpos++] = xds_base64[output[0]]; - dst[dstpos++] = xds_base64[output[1]]; - if (srclen == 1) - dst[dstpos++] = xds_pad64; - else - dst[dstpos++] = xds_base64[output[2]]; - dst[dstpos++] = xds_pad64; - } - - if (dstpos >= dstlen) - return -1; - dst[dstpos] = '\0'; - - return dstpos; - } - -int xml_encode_octetstream(xds_t* xds, void* engine_context, - void* buffer, size_t buffer_size, size_t* used_buffer_size, - va_list* args) - { - xds_uint8_t* src; - size_t src_len; - - /* We need at least 27 byte for the starting and ending tag. */ - - xds_init_encoding_engine(13 + 14); - - /* Get parameters from stack. */ - - src = (xds_uint8_t*)va_arg(*args, void*); - xds_check_parameter(src != NULL); - src_len = va_arg(*args, size_t); - - /* Calculate how many bytes we'll need in buffer and make sure we - have them. */ - - *used_buffer_size = base64_encode(NULL, 0, src, src_len); - if (*used_buffer_size == (size_t)-1) - return XDS_ERR_UNKNOWN; - else - *used_buffer_size += 13 + 14; - if (buffer_size < *used_buffer_size) - return XDS_ERR_OVERFLOW; - - /* Format the data into the buffer. */ - - memmove(buffer, "", 13); - if (base64_encode((char*)buffer + 13, buffer_size - 13, src, src_len) < 0) - return XDS_ERR_UNKNOWN; - memmove((char*)buffer + *used_buffer_size - 14, "", 14); - - /* Done. */ - - return XDS_OK; - }