Index: ossp-pkg/xds/encode.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/encode.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/xds/Attic/encode.c,v' | diff -u - /dev/null -L'ossp-pkg/xds/encode.c' 2>/dev/null --- ossp-pkg/xds/encode.c +++ /dev/null 2024-05-15 02:33:00.000000000 +0200 @@ -1,33 +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 "internal.h" - -int xds_encode(xds_t* xds, const char* fmt, ...) - { - return XDS_ERR_INVALID_ARG; - } Index: ossp-pkg/xds/vencode.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/vencode.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/vencode.c,v' 2>/dev/null --- vencode.c 2001/07/04 15:58:51 1.1 +++ vencode.c 2001/07/09 17:19:58 1.2 @@ -25,9 +25,139 @@ SUCH DAMAGE. */ +#include /* delete me */ + +#include +#include +#include #include "internal.h" -int xds_vencode(xds_t* xds, const char* fmt, va_list args) +int xds_vencode(xds_t* xds, const char* fmt_arg, va_list args) { - return XDS_ERR_INVALID_ARG; + char* name; + char* p; + char* fmt; + int rc; + + /* Sanity checks. */ + + assert(xds != NULL); + assert(fmt_arg != NULL); + assert(xds->mode == XDS_ENCODE); + if (xds == NULL || fmt_arg == NULL) + return XDS_ERR_INVALID_ARG; + if (xds->mode != XDS_ENCODE) + return XDS_ERR_INVALID_MODE; + + /* Ensure we have a buffer allocated ready for use. */ + + if (xds->buffer == NULL) + { /* allocate a new buffer */ + int rc = xds_set_capacity((void**)&xds->buffer, + &xds->buffer_capacity, + XDS_INITIAL_BUFFER_CAPACITY, + sizeof(char), + XDS_INITIAL_BUFFER_CAPACITY); + assert(rc == XDS_OK || rc == XDS_ERR_NO_MEM); + if (rc != XDS_OK) + return rc; + printf("Enlarged buffer to %d byte.\n", xds->buffer_capacity); + xds->buffer_len = 0; + xds->we_own_buffer = (1==1); + } + + /* Ensure the buffer has free space. */ + + assert(xds->buffer_len <= xds->buffer_capacity); + if (xds->buffer_len == xds->buffer_capacity) + { + if (xds->we_own_buffer) + { + int rc = xds_set_capacity((void**)&xds->buffer, + &xds->buffer_capacity, + xds->buffer_len + 1, + sizeof(char), + XDS_INITIAL_BUFFER_CAPACITY); + assert(rc == XDS_OK || rc == XDS_ERR_NO_MEM); + if (rc != XDS_OK) + return rc; + printf("Enlarged buffer to %d byte.\n", xds->buffer_capacity); + } + else + return XDS_ERR_OVERFLOW; + } + + /* Iterate through the items in the format string and execute the + apropriate engines. */ + + fmt = p = strdup(fmt_arg); + if (fmt == NULL) + return XDS_ERR_NO_MEM; + for(name = p; *p != '\0'; name = p) + { + while(isalnum(*p) || *p == '-' || *p == '_') + ++p; + *p++ = '\0'; + + if (strlen(name) > 0) + { + size_t pos; + if (xds_find_engine(xds->engines, xds->engines_len, name, &pos)) + { + int restart_engine; + do + { + printf("Executing engine '%s' ...\n", name); + rc = (*xds->engines[pos].engine)(xds, + xds->engines[pos].context, + xds->buffer + xds->buffer_len, + xds->buffer_capacity - xds->buffer_len, + args); + if (rc < 0) + goto leave; + else if (rc >= xds->buffer_capacity - xds->buffer_len) + { /* enlarge buffer */ + int rc2; + + if (!xds->we_own_buffer) + { + rc = XDS_ERR_OVERFLOW; + goto leave; + } + + rc2 = xds_set_capacity((void**)&xds->buffer, + &xds->buffer_capacity, + xds->buffer_capacity + rc, + sizeof(char), + XDS_INITIAL_BUFFER_CAPACITY); + assert(rc2 == XDS_OK || rc2 == XDS_ERR_NO_MEM); + if (rc2 != XDS_OK) + { + rc = rc2; + goto leave; + } + restart_engine = (1==1); + printf("Enlarged buffer to %d byte.\n", xds->buffer_capacity); + } + else + { + restart_engine = (1!=1); + xds->buffer_len += rc; + } + } + while (restart_engine); + } + else + { + rc = XDS_ERR_UNKNOWN_ENGINE; + goto leave; + } + } + } + rc = XDS_OK; + + /* Clean up and leave. */ + leave: + free(fmt); + return rc; }