OSSP CVS Repository

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

Check-in Number: 4193
Date: 2001-Jul-09 21:00:44 (local)
2001-Jul-09 19:00:44 (UTC)
User:simons
Branch:
Comment: Implemented xds_decode().
Tickets:
Inspections:
Files:
ossp-pkg/xds/decode.c      1.1->removed
ossp-pkg/xds/vdecode.c      1.1 -> 1.2     67 inserted, 2 deleted
ossp-pkg/xds/xds.h      1.14 -> 1.15     2 inserted, 1 deleted

ossp-pkg/xds/decode.c 1.1 -> 1.2

--- decode.c     2001/07/04 15:58:51     1.1
+++ decode.c     2001/07/09 19:00:44     1.2
@@ -29,5 +29,10 @@
 
 int xds_decode(xds_t* xds, const char* fmt, ...)
     {
-    return XDS_ERR_INVALID_ARG;
+    int rc;
+    va_list args;
+    va_start(args, fmt);
+    rc = xds_vdecode(xds, fmt, args);
+    va_end(args);
+    return rc;
     }


ossp-pkg/xds/vdecode.c 1.1 -> 1.2

--- vdecode.c    2001/07/04 15:58:51     1.1
+++ vdecode.c    2001/07/09 19:00:44     1.2
@@ -25,9 +25,74 @@
    SUCH DAMAGE.
 */
 
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
 #include "internal.h"
 
-int xds_vdecode(xds_t* xds, const char* fmt, va_list args)
+int xds_vdecode(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_DECODE);
+    if (xds == NULL || fmt_arg == NULL)
+        return XDS_ERR_INVALID_ARG;
+    if (xds->mode != XDS_DECODE)
+        return XDS_ERR_INVALID_MODE;
+
+    /* Ensure we have a buffer to decode. */
+
+    if (xds->buffer == NULL || xds->buffer_capacity == 0)
+        return XDS_ERR_UNDERFLOW;
+
+    /* 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;
+        if (*p)
+            *p++ = '\0';
+        else
+            *p = '\0';
+
+        if (strlen(name) > 0)
+            {
+            size_t pos;
+            if (xds_find_engine(xds->engines, xds->engines_len, name, &pos))
+                {
+                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
+                    xds->buffer_len += rc;
+                }
+            else
+                {
+                rc = XDS_ERR_UNKNOWN_ENGINE;
+                goto leave;
+                }
+            }
+        }
+    rc = XDS_OK;
+
+    /* Clean up and leave. */
+  leave:
+    free(fmt);
+    return rc;
     }


ossp-pkg/xds/xds.h 1.14 -> 1.15

--- xds.h        2001/07/09 17:19:26     1.14
+++ xds.h        2001/07/09 19:00:44     1.15
@@ -41,7 +41,8 @@
     XDS_ERR_INVALID_ARG    = -3,
     XDS_ERR_TYPE_MISMATCH  = -4,
     XDS_ERR_UNKNOWN_ENGINE = -5,
-    XDS_ERR_INVALID_MODE   = -6
+    XDS_ERR_INVALID_MODE   = -6,
+    XDS_ERR_UNDERFLOW      = -7
     };
 typedef enum { XDS_ENCODE, XDS_DECODE } xds_mode_t;
 typedef enum { XDS_LOAN,   XDS_GIFT   } xds_scope_t;

CVSTrac 2.0.1