OSSP CVS Repository

ossp - Check-in [623]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 623
Date: 2001-Aug-08 13:21:27 (local)
2001-Aug-08 11:21:27 (UTC)
User:simons
Branch:
Comment: Implemented xml engines for encoding or decoding strings plus the apropriate test cases.
Tickets:
Inspections:
Files:
ossp-pkg/xds/Makefile.in      1.21 -> 1.22     1 inserted, 0 deleted
ossp-pkg/xds/regression-tests/Makefile.in      added-> 1.14
ossp-pkg/xds/regression-tests/xml-string-empty.c      added-> 1.1
ossp-pkg/xds/regression-tests/xml-string.c      added-> 1.1
ossp-pkg/xds/xml-decode-string.c      added-> 1.1
ossp-pkg/xds/xml-encode-string.c      added-> 1.1

ossp-pkg/xds/Makefile.in 1.21 -> 1.22

--- Makefile.in  2001/08/07 14:46:38     1.21
+++ Makefile.in  2001/08/08 11:21:27     1.22
@@ -15,6 +15,7 @@
                   xml-encode-begin.o       xml-decode-begin.o \
                   xml-encode-end.o         xml-decode-end.o \
                   xml-encode-octetstream.o xml-decode-octetstream.o \
+                  xml-encode-string.o      xml-decode-string.o \
                   $(XML64_OBJS)
 
 XDR64_OBJS      = @xdr_64_bit_objects@


ossp-pkg/xds/regression-tests/Makefile.in -> 1.14

*** /dev/null    Sun Apr 28 15:37:05 2024
--- -    Sun Apr 28 15:37:09 2024
***************
*** 0 ****
--- 1,43 ----
+ # Build and run the regression tests for libxds.
+ 
+ CC             = @CC@
+ AR             = ar
+ RANLIB         = @RANLIB@
+ 
+ CPPFLAGS       = @CPPFLAGS@ @DEFS@ -D_GNU_SOURCE
+ CFLAGS         = @CFLAGS@
+ LDFLAGS                = @LDFLAGS@ @xdr_lib@ -L..
+ 
+ TESTS64                = @tests_64_bit@
+ TESTS          = xds-core.exe xds-find-engine.exe xds-register.exe xds-encode.exe \
+                  xds-getbuffer.exe xds-decode.exe xds-setbuffer.exe xds-engine-restart.exe \
+                  xdr-uint32.exe xdr-int32.exe xdr-octetstream.exe xdr-octetstream-empty.exe \
+                  xdr-string.exe xdr-string-empty.exe xml-uint32.exe xml-int32.exe \
+                  xml-double.exe xml-octetstream.exe xml-octetstream-empty.exe \
+                  xml-string.exe xml-string-empty.exe $(TESTS64)
+ 
+ .SUFFIXES:
+ .SUFFIXES:     .c .exe
+ 
+ .c.exe:
+        $(CC) $(CPPFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< -lxds
+ 
+ all:   $(TESTS)
+ 
+ check: all
+        @./.run-tests $(TESTS)
+ 
+ ../libxds.a:
+        (cd .. && $(MAKE) libxds.a)
+ clean::
+        rm -f $(TESTS) *.log
+ 
+ distclean::    clean
+        rm -f  Makefile
+ 
+ realclean::    distclean
+ 
+ 
+ # Dependencies
+ 
+ $(TESTS): ../libxds.a ../internal.h ../xds.h


ossp-pkg/xds/regression-tests/xml-string-empty.c -> 1.1

*** /dev/null    Sun Apr 28 15:37:05 2024
--- -    Sun Apr 28 15:37:09 2024
***************
*** 0 ****
--- 1,112 ----
+ /*
+    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 <unistd.h>
+ 
+ #include <stdio.h>
+ #include <string.h>
+ #include "../internal.h"
+ 
+ int main()
+     {
+     xds_t* xds;
+     char*  buffer;
+     size_t buffer_size;
+ 
+     char   msg[] = "";
+     char*  new_msg;
+ 
+     /* Encode the string, 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, "string", &xml_encode_string, NULL) != XDS_OK ||
+        xds_register(xds, "begin", &xml_encode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_encode_end, NULL) != XDS_OK)
+        {
+        printf("Failed to register my encoding engines.\n");
+        return 1;
+        }
+     if (xds_encode(xds, "begin string end", msg, sizeof(msg)-1) != 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);
+     write(1, buffer, buffer_size);
+     printf("\n");
+ 
+     xds = xds_init(XDS_DECODE);
+     if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+     if (xds_register(xds, "string", &xml_decode_string, NULL) != XDS_OK ||
+        xds_register(xds, "begin", &xml_decode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_decode_end, 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, "begin string end", &new_msg) != XDS_OK)
+        {
+        printf("xds_decode() failed.\n");
+        return 1;
+        }
+     if (strlen(new_msg) != sizeof(msg)-1)
+        {
+        printf("The size of the decoded message is wrong.\n");
+        return 1;
+        }
+     if (memcmp(msg, new_msg, sizeof(msg)-1) != 0)
+        {
+        printf("The decoded string is not correct.\n");
+        return 1;
+        }
+     xds_destroy(xds);
+     free(new_msg);
+ 
+     /* Everything went fine. */
+ 
+     return 0;
+     }


ossp-pkg/xds/regression-tests/xml-string.c -> 1.1

*** /dev/null    Sun Apr 28 15:37:05 2024
--- -    Sun Apr 28 15:37:09 2024
***************
*** 0 ****
--- 1,112 ----
+ /*
+    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 <unistd.h>
+ 
+ #include <stdio.h>
+ #include <string.h>
+ #include "../internal.h"
+ 
+ int main()
+     {
+     xds_t* xds;
+     char*  buffer;
+     size_t buffer_size;
+ 
+     char   msg[] = "<Hallo> ]]>&<&>World";
+     char*  new_msg;
+ 
+     /* Encode the string, 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, "string", &xml_encode_string, NULL) != XDS_OK ||
+        xds_register(xds, "begin", &xml_encode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_encode_end, NULL) != XDS_OK)
+        {
+        printf("Failed to register my encoding engines.\n");
+        return 1;
+        }
+     if (xds_encode(xds, "begin string end", msg, sizeof(msg)-1) != 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);
+     write(1, buffer, buffer_size);
+     printf("\n");
+ 
+     xds = xds_init(XDS_DECODE);
+     if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+     if (xds_register(xds, "string", &xml_decode_string, NULL) != XDS_OK ||
+        xds_register(xds, "begin", &xml_decode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_decode_end, 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, "begin string end", &new_msg) != XDS_OK)
+        {
+        printf("xds_decode() failed.\n");
+        return 1;
+        }
+     if (strlen(new_msg) != sizeof(msg)-1)
+        {
+        printf("The size of the decoded message is wrong.\n");
+        return 1;
+        }
+     if (memcmp(msg, new_msg, sizeof(msg)-1) != 0)
+        {
+        printf("The decoded string is not correct.\n");
+        return 1;
+        }
+     xds_destroy(xds);
+     free(new_msg);
+ 
+     /* Everything went fine. */
+ 
+     return 0;
+     }


ossp-pkg/xds/xml-decode-string.c -> 1.1

*** /dev/null    Sun Apr 28 15:37:05 2024
--- -    Sun Apr 28 15:37:09 2024
***************
*** 0 ****
--- 1,114 ----
+ /*
+    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 <string.h>
+ #include "xds.h"
+ 
+ static const char TAG_OPEN[] = "<string>";
+ static const char TAG_CLOSE[] = "</string>";
+ static const size_t TAG_OPEN_LEN = sizeof(TAG_OPEN)-1;
+ static const size_t TAG_CLOSE_LEN = sizeof(TAG_CLOSE)-1;
+ 
+ int xml_decode_string(xds_t* xds, void* engine_context,
+                      void* buffer, size_t buffer_size, size_t* used_buffer_size,
+                      va_list* args)
+     {
+     char**  target_buffer;
+     char*   src;
+     size_t  src_len;
+     char*   dst;
+ 
+     /* Setup the engine. We need at least space for our tags; how long
+        the actual content is going to be will be seen soon. */
+ 
+     xds_init_encoding_engine(TAG_OPEN_LEN + TAG_CLOSE_LEN);
+ 
+     /* Is the opening tag there? */
+ 
+     if (strncasecmp(buffer, TAG_OPEN, TAG_OPEN_LEN) != 0)
+         return XDS_ERR_TYPE_MISMATCH;
+ 
+     /* Determine the length of the encoded data. */
+ 
+     src = (char*)buffer + TAG_OPEN_LEN;
+     for (src_len = 0; src[src_len] != '<'; ++src_len)
+        if (src[src_len] == '\0')
+            return XDS_ERR_TYPE_MISMATCH;
+ 
+     /* Check the closing tag. */
+ 
+     if (strncasecmp(src + src_len, TAG_CLOSE, TAG_CLOSE_LEN) != 0)
+         return XDS_ERR_TYPE_MISMATCH;
+     *used_buffer_size = TAG_OPEN_LEN + src_len + TAG_CLOSE_LEN;
+ 
+     /* Allocate target buffer. */
+ 
+     target_buffer = va_arg(*args, char**);
+     xds_check_parameter(target_buffer != NULL);
+     *target_buffer = dst = malloc(src_len + 1);
+     if (dst == NULL)
+        return XDS_ERR_NO_MEM;
+ 
+     /* Decode the data into the target buffer. */
+ 
+     while(src_len > 0)
+        {
+        if (*src == '&')
+            {
+            if (src_len >= 4 && strncmp(src, "&lt;", 4) == 0)
+                {
+                *dst++ = '<';
+                src += 4; src_len -= 4;
+                }
+            else if (src_len >= 4 && strncmp(src, "&gt;", 4) == 0)
+                {
+                *dst++ = '>';
+                src += 4; src_len -= 4;
+                }
+            else if (src_len >= 5 && strncmp(src, "&amp;", 5) == 0)
+                {
+                *dst++ = '&';
+                src += 5; src_len -= 5;
+                }
+            else
+                {
+                free(dst);
+                return XDS_ERR_TYPE_MISMATCH;
+                }
+            }
+        else
+            {
+            *dst++ = *src++;
+            --src_len;
+            }
+        }
+     *dst = '\0';
+ 
+     /* Done. */
+ 
+     return XDS_OK;
+     }


ossp-pkg/xds/xml-encode-string.c -> 1.1

*** /dev/null    Sun Apr 28 15:37:05 2024
--- -    Sun Apr 28 15:37:09 2024
***************
*** 0 ****
--- 1,126 ----
+ /*
+    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 <string.h>
+ #include "xds.h"
+ 
+ static const char TAG_OPEN[] = "<string>";
+ static const char TAG_CLOSE[] = "</string>";
+ static const size_t TAG_OPEN_LEN = sizeof(TAG_OPEN)-1;
+ static const size_t TAG_CLOSE_LEN = sizeof(TAG_CLOSE)-1;
+ 
+ int xml_encode_string(xds_t* xds, void* engine_context,
+                      void* buffer, size_t buffer_size, size_t* used_buffer_size,
+                      va_list* args)
+     {
+     char*  src;
+     size_t src_len;
+     char*  dst;
+     size_t dst_size;
+ 
+     /* Setup the engine. We need at least space for our tags; how long
+        the actual content is going to be will be seen soon. */
+ 
+     xds_init_encoding_engine(TAG_OPEN_LEN + TAG_CLOSE_LEN);
+ 
+     /* Get the data from the stack. */
+ 
+     src      = va_arg(*args, char*);
+     xds_check_parameter(src != NULL);
+     src_len  = strlen(src);
+ 
+     /* Set up the target buffer. */
+ 
+     dst      = buffer;
+     dst_size = buffer_size;
+ 
+     /* Write the opening tag. */
+ 
+     memmove(dst, TAG_OPEN, TAG_OPEN_LEN);
+     dst      += TAG_OPEN_LEN;
+     dst_size -= TAG_OPEN_LEN;
+ 
+     /* Format the data into the buffer. */
+ 
+     while(src_len > 0 && dst_size > 0)
+        {
+        switch(*src)
+            {
+            case '<':           /* Turn into "&lt;". */
+                if (dst_size >= 4)
+                    {
+                    *dst++ = '&'; --dst_size;
+                    *dst++ = 'l'; --dst_size;
+                    *dst++ = 't'; --dst_size;
+                    *dst++ = ';'; --dst_size;
+                    ++src; --src_len;
+                    }
+                break;
+            case '&':           /* Turn into "&amp;". */
+                if (dst_size >= 5)
+                    {
+                    *dst++ = '&'; --dst_size;
+                    *dst++ = 'a'; --dst_size;
+                    *dst++ = 'm'; --dst_size;
+                    *dst++ = 'p'; --dst_size;
+                    *dst++ = ';'; --dst_size;
+                    ++src; --src_len;
+                    }
+                break;
+            case '>':           /* Turn into "&gt;". */
+                if (dst_size >= 4)
+                    {
+                    *dst++ = '&'; --dst_size;
+                    *dst++ = 'g'; --dst_size;
+                    *dst++ = 't'; --dst_size;
+                    *dst++ = ';'; --dst_size;
+                    ++src; --src_len;
+                    }
+                break;
+            default:            /* Just copy it. */
+                *dst++ = *src++;
+                --src_len;
+                --dst_size;
+            }
+        }
+     if (src_len > 0)
+        {                       /* Target buffer was too small. */
+        *used_buffer_size = dst - (char*)buffer + 1;
+        return XDS_ERR_OVERFLOW;
+        }
+ 
+     /* Write the closing tag. */
+ 
+     memmove(dst, TAG_CLOSE, TAG_CLOSE_LEN);
+     dst      += TAG_CLOSE_LEN;
+     dst_size -= TAG_CLOSE_LEN;
+ 
+     /* Done. */
+ 
+     *used_buffer_size = dst - (char*)buffer;
+     return XDS_OK;
+     }

CVSTrac 2.0.1