OSSP CVS Repository

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

Check-in Number: 4209
Date: 2001-Jul-18 20:26:32 (local)
2001-Jul-18 18:26:32 (UTC)
User:simons
Branch:
Comment: Implemented decoding engines for the integer data types and extended the existing test suites to verify them.
Tickets:
Inspections:
Files:
ossp-pkg/xds/Makefile      1.14 -> 1.15     3 inserted, 2 deleted
ossp-pkg/xds/regression-tests/xdr-int32.c      1.1 -> 1.2     36 inserted, 0 deleted
ossp-pkg/xds/regression-tests/xdr-int64.c      1.1 -> 1.2     36 inserted, 0 deleted
ossp-pkg/xds/regression-tests/xdr-uint32.c      1.1 -> 1.2     36 inserted, 0 deleted
ossp-pkg/xds/regression-tests/xdr-uint64.c      1.1 -> 1.2     36 inserted, 0 deleted
ossp-pkg/xds/xdr-decode-int.c      added-> 1.1
ossp-pkg/xds/xds.h      1.18 -> 1.19     5 inserted, 0 deleted

ossp-pkg/xds/Makefile 1.14 -> 1.15

--- Makefile     2001/07/18 11:30:19     1.14
+++ Makefile     2001/07/18 18:26:32     1.15
@@ -5,7 +5,8 @@
 AR              = ar
 RANLIB          = ranlib
 
-WARNFLAGS       = -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wcast-align -Winline -Wmissing-prototypes -Wmissing-declarations -Wnested-externs
+WARNFLAGS       = -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wcast-align -Winline -Wmissing-prototypes \
+                  -Wmissing-declarations -Wnested-externs
 OPTFLAGS        = -O3 -pipe
 
 CPPFLAGS        = -D_GNU_SOURCE
@@ -15,7 +16,7 @@
 
 OBJS            = decode.o destroy.o encode.o getbuffer.o init.o register.o \
                   setbuffer.o unregister.o vdecode.o vencode.o find-engine.o \
-                  set-capacity.o xdr-encode-int.o
+                  set-capacity.o xdr-encode-int.o xdr-decode-int.o
 
 .c.o:
         $(CC) $(CPPFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(CFLAGS) -c $<


ossp-pkg/xds/regression-tests/xdr-int32.c 1.1 -> 1.2

--- xdr-int32.c  2001/07/18 11:29:46     1.1
+++ xdr-int32.c  2001/07/18 18:26:33     1.2
@@ -102,6 +102,42 @@
         return 1;
         }
 
+    /* Now we decode the values again using the XDS implementation and
+       compare them to our original values. Obviously, they should not
+       differ. */
+
+    xds = xds_init(XDS_DECODE);
+    if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+    if (xds_register(xds, "int", &xdr_decode_int32, NULL) != XDS_OK)
+        {
+        printf("Failed to register my decoding engines.\n");
+        return 1;
+        }
+    if (xds_setbuffer(xds, XDS_GIFT, xds_buf, xds_buf_size) != XDS_OK)
+        {
+        printf("setbuffer() failed.\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof(values)/sizeof(int32_t); ++i)
+        {
+        int32_t tmp;
+        if (xds_decode(xds, "int", &tmp) != XDS_OK)
+            {
+            printf("xds_encode() failed for the %d value!", i);
+            return 1;
+            }
+        if (values[i] != tmp)
+            {
+            printf("The %dth value has not been decoded correctly!", i);
+            return 1;
+            }
+        }
+    xds_destroy(xds);
+
     /* Everything went fine. */
 
     return 0;


ossp-pkg/xds/regression-tests/xdr-int64.c 1.1 -> 1.2

--- xdr-int64.c  2001/07/18 16:59:28     1.1
+++ xdr-int64.c  2001/07/18 18:26:33     1.2
@@ -102,6 +102,42 @@
         return 1;
         }
 
+    /* Now we decode the values again using the XDS implementation and
+       compare them to our original values. Obviously, they should not
+       differ. */
+
+    xds = xds_init(XDS_DECODE);
+    if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+    if (xds_register(xds, "int", &xdr_decode_int64, NULL) != XDS_OK)
+        {
+        printf("Failed to register my decoding engines.\n");
+        return 1;
+        }
+    if (xds_setbuffer(xds, XDS_GIFT, xds_buf, xds_buf_size) != XDS_OK)
+        {
+        printf("setbuffer() failed.\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof(values)/sizeof(int64_t); ++i)
+        {
+        int64_t tmp;
+        if (xds_decode(xds, "int", &tmp) != XDS_OK)
+            {
+            printf("xds_encode() failed for the %d value!", i);
+            return 1;
+            }
+        if (values[i] != tmp)
+            {
+            printf("The %dth value has not been decoded correctly!", i);
+            return 1;
+            }
+        }
+    xds_destroy(xds);
+
     /* Everything went fine. */
 
     return 0;


ossp-pkg/xds/regression-tests/xdr-uint32.c 1.1 -> 1.2

--- xdr-uint32.c 2001/07/18 11:29:46     1.1
+++ xdr-uint32.c 2001/07/18 18:26:33     1.2
@@ -101,6 +101,42 @@
         return 1;
         }
 
+    /* Now we decode the values again using the XDS implementation and
+       compare them to our original values. Obviously, they should not
+       differ. */
+
+    xds = xds_init(XDS_DECODE);
+    if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+    if (xds_register(xds, "uint", &xdr_decode_uint32, NULL) != XDS_OK)
+        {
+        printf("Failed to register my decoding engines.\n");
+        return 1;
+        }
+    if (xds_setbuffer(xds, XDS_GIFT, xds_buf, xds_buf_size) != XDS_OK)
+        {
+        printf("setbuffer() failed.\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof(values)/sizeof(u_int32_t); ++i)
+        {
+        u_int32_t tmp;
+        if (xds_decode(xds, "uint", &tmp) != XDS_OK)
+            {
+            printf("xds_encode() failed for the %d value!", i);
+            return 1;
+            }
+        if (values[i] != tmp)
+            {
+            printf("The %dth value has not been decoded correctly!", i);
+            return 1;
+            }
+        }
+    xds_destroy(xds);
+
     /* Everything went fine. */
 
     return 0;


ossp-pkg/xds/regression-tests/xdr-uint64.c 1.1 -> 1.2

--- xdr-uint64.c 2001/07/18 16:59:28     1.1
+++ xdr-uint64.c 2001/07/18 18:26:33     1.2
@@ -101,6 +101,42 @@
         return 1;
         }
 
+    /* Now we decode the values again using the XDS implementation and
+       compare them to our original values. Obviously, they should not
+       differ. */
+
+    xds = xds_init(XDS_DECODE);
+    if (xds == NULL)
+        {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+        }
+    if (xds_register(xds, "uint", &xdr_decode_uint64, NULL) != XDS_OK)
+        {
+        printf("Failed to register my decoding engines.\n");
+        return 1;
+        }
+    if (xds_setbuffer(xds, XDS_GIFT, xds_buf, xds_buf_size) != XDS_OK)
+        {
+        printf("setbuffer() failed.\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof(values)/sizeof(u_int64_t); ++i)
+        {
+        u_int64_t tmp;
+        if (xds_decode(xds, "uint", &tmp) != XDS_OK)
+            {
+            printf("xds_encode() failed for the %d value!", i);
+            return 1;
+            }
+        if (values[i] != tmp)
+            {
+            printf("The %dth value has not been decoded correctly!", i);
+            return 1;
+            }
+        }
+    xds_destroy(xds);
+
     /* Everything went fine. */
 
     return 0;


ossp-pkg/xds/xdr-decode-int.c -> 1.1

*** /dev/null    Sun Apr 28 14:44:01 2024
--- -    Sun Apr 28 14:44:02 2024
***************
*** 0 ****
--- 1,183 ----
+ /*
+    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 <assert.h>
+ #include "internal.h"
+ 
+ int xdr_decode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+     {
+     int32_t*  value;
+     u_int32_t tmp;
+ 
+     /* Consistency checks. */
+ 
+     assert(xds != NULL);
+     assert(buffer != NULL);
+     assert(args != NULL);
+     if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
+        return XDS_ERR_INVALID_ARG;
+     if (buffer_size < 4)
+        return XDS_ERR_UNDERFLOW;
+ 
+     /* Get value and format it into the buffer. */
+ 
+     value = va_arg(*args, int32_t*);
+     assert(value != NULL);
+ 
+     if (((u_int8_t*)buffer)[0] & 0x80)
+        {                       /* negative number */
+        tmp  = ((u_int8_t*)buffer)[0]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[1]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[2]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[3];
+        tmp = 0 - tmp;
+        *value = 0 - (int32_t)tmp;
+        }
+     else
+        {                       /* positive number */
+        *value  = ((u_int8_t*)buffer)[0]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[1]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[2]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[3];
+        }
+ 
+     /* Done. */
+ 
+     return 4;
+     }
+ 
+ int xdr_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+     {
+     u_int32_t*  value;
+ 
+     /* Consistency checks. */
+ 
+     assert(xds != NULL);
+     assert(buffer != NULL);
+     assert(args != NULL);
+     if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
+        return XDS_ERR_INVALID_ARG;
+     if (buffer_size < 4)
+        return XDS_ERR_UNDERFLOW;
+ 
+     /* Get value and format it into the buffer. */
+ 
+     value = va_arg(*args, u_int32_t*);
+     assert(value != NULL);
+ 
+     *value  = ((u_int8_t*)buffer)[0]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[1]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[2]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[3];
+ 
+     /* Done. */
+ 
+     return 4;
+     }
+ 
+ int xdr_decode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+     {
+     int64_t*  value;
+     u_int64_t tmp;
+ 
+     /* Consistency checks. */
+ 
+     assert(xds != NULL);
+     assert(buffer != NULL);
+     assert(args != NULL);
+     if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
+        return XDS_ERR_INVALID_ARG;
+     if (buffer_size < 8)
+        return XDS_ERR_UNDERFLOW;
+ 
+     /* Get value and format it into the buffer. */
+ 
+     value = va_arg(*args, int64_t*);
+     assert(value != NULL);
+ 
+     if (((u_int8_t*)buffer)[0] & 0x80)
+        {                       /* negative number */
+        tmp  = ((u_int8_t*)buffer)[0]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[1]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[2]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[3]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[4]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[5]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[6]; tmp = tmp << 8;
+        tmp += ((u_int8_t*)buffer)[7];
+        tmp = 0 - tmp;
+        *value = 0 - (int64_t)tmp;
+        }
+     else
+        {                       /* positive number */
+        *value  = ((u_int8_t*)buffer)[0]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[1]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[2]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[3]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[4]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[5]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[6]; *value = *value << 8;
+        *value += ((u_int8_t*)buffer)[7];
+        }
+ 
+     /* Done. */
+ 
+     return 8;
+     }
+ 
+ int xdr_decode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+     {
+     u_int64_t*  value;
+ 
+     /* Consistency checks. */
+ 
+     assert(xds != NULL);
+     assert(buffer != NULL);
+     assert(args != NULL);
+     if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
+        return XDS_ERR_INVALID_ARG;
+     if (buffer_size < 8)
+        return XDS_ERR_UNDERFLOW;
+ 
+     /* Get value and format it into the buffer. */
+ 
+     value = va_arg(*args, u_int64_t*);
+     assert(value != NULL);
+ 
+     *value  = ((u_int8_t*)buffer)[0]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[1]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[2]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[3]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[4]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[5]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[6]; *value = *value << 8;
+     *value += ((u_int8_t*)buffer)[7];
+ 
+     /* Done. */
+ 
+     return 8;
+     }


ossp-pkg/xds/xds.h 1.18 -> 1.19

--- xds.h        2001/07/18 16:59:27     1.18
+++ xds.h        2001/07/18 18:26:32     1.19
@@ -75,4 +75,9 @@
 int xdr_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
 int xdr_encode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
 
+int xdr_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
+int xdr_decode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
+int xdr_decode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
+int xdr_decode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args);
+
 #endif /* !defined(__LIBXDS_H__) */

CVSTrac 2.0.1