OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xds_engine_xml.c versions 1.3 and 1.4
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xds_engine_xml.c 1.3 -> 1.4

--- xds_engine_xml.c     2001/08/09 19:58:35     1.3
+++ xds_engine_xml.c     2001/08/09 20:59:05     1.4
@@ -41,48 +41,49 @@
 static const char xds_xml_end_text[] = 
     "</xds>\n";
 
-int xml_encode_begin(xds_t * xds, void *engine_context,
+int xml_encode_begin(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_init_encoding_engine(strlen(xds_xml_begin_text));
     memmove(buffer, xds_xml_begin_text, strlen(xds_xml_begin_text));
     return XDS_OK;
 }
 
-int xml_decode_begin(xds_t * xds, void *engine_context,
+int xml_decode_begin(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_init_encoding_engine(strlen(xds_xml_begin_text));
-    if (strncasecmp(buffer, xds_xml_begin_text, strlen(xds_xml_begin_text)) !=
-        0)
+    if (strncasecmp(buffer, xds_xml_begin_text, 
+                    strlen(xds_xml_begin_text)) != 0)
         return XDS_ERR_TYPE_MISMATCH;
     return XDS_OK;
 }
 
-int xml_encode_end(xds_t * xds, void *engine_context,
+int xml_encode_end(xds_t *xds, void *engine_context,
                    void *buffer, size_t buffer_size,
-                   size_t * used_buffer_size, va_list * args)
+                   size_t *used_buffer_size, va_list *args)
 {
     xds_init_encoding_engine(strlen(xds_xml_end_text));
     memmove(buffer, xds_xml_end_text, strlen(xds_xml_end_text));
     return XDS_OK;
 }
 
-int xml_decode_end(xds_t * xds, void *engine_context,
+int xml_decode_end(xds_t *xds, void *engine_context,
                    void *buffer, size_t buffer_size,
-                   size_t * used_buffer_size, va_list * args)
+                   size_t *used_buffer_size, va_list *args)
 {
     xds_init_decoding_engine(strlen(xds_xml_end_text));
-    if (strncasecmp(buffer, xds_xml_end_text, strlen(xds_xml_end_text)) != 0)
+    if (strncasecmp(buffer, xds_xml_end_text, 
+                    strlen(xds_xml_end_text)) != 0)
         return XDS_ERR_TYPE_MISMATCH;
     return XDS_OK;
 }
 
-int xml_encode_int32(xds_t * xds, void *engine_context,
+int xml_encode_int32(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_int32_t value;
     char buf[32];
@@ -93,8 +94,7 @@
     xds_init_encoding_engine(7 + 8 + 11);
 
     /* Get the value and format it into our buffer. Keep track of the length
-     * of the formatted result. */
-
+       of the formatted result. */
     value = va_arg(*args, xds_int32_t);
     if (value < 0) {
         negative = XDS_TRUE;
@@ -107,29 +107,26 @@
         unsigned char remainder = value % 10;
         value = value / 10;
         buf[i++] = '0' + remainder;
-    }
-    while (value != 0);
+    } while (value != 0);
     if (negative)
         buf[i++] = '-';
 
     /* Now that we know the correct size of our data's representation, write
-     * it into the buffer. */
-
+       it into the buffer. */
     *used_buffer_size = 7 + 8 + i;
     p = buffer;
     memmove(p, "<int32>", 7);
     p += 7;
-    for (j = i; j > 0;) {
+    for (j = i; j > 0;)
         *p++ = buf[--j];
-    }
     memmove(p, "</int32>", 8);
 
     return XDS_OK;
 }
 
-int xml_decode_int32(xds_t * xds, void *engine_context,
+int xml_decode_int32(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_int32_t *value;
     char *p;
@@ -138,18 +135,16 @@
     xds_init_decoding_engine(7 + 8 + 1);
 
     /* Does the opening XML tag match? */
-
     if (strncasecmp(buffer, "<int32>", 7) != 0)
         return XDS_ERR_TYPE_MISMATCH;
 
     /* Decode the representation of the value. */
-
     value = va_arg(*args, xds_int32_t *);
     *value = 0;
     p = (char *)buffer + 7;
     if (*p == '-') {
         negative = XDS_TRUE;
-        ++p;
+        p++;
     }
     else
         negative = XDS_FALSE;
@@ -163,7 +158,6 @@
         *value = 0 - *value;
 
     /* Does the closing XML tag match? */
-
     if (p + 8 > (char *)buffer + buffer_size)
         return XDS_ERR_UNDERFLOW;
     else if (strncasecmp(p, "</int32>", 8) != 0)
@@ -173,9 +167,9 @@
     return XDS_OK;
 }
 
-int xml_encode_uint32(xds_t * xds, void *engine_context,
+int xml_encode_uint32(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     xds_uint32_t value;
     char buf[32];
@@ -185,36 +179,31 @@
     xds_init_encoding_engine(8 + 9 + 10);
 
     /* Format value into our buffer. */
-
     value = va_arg(*args, xds_uint32_t);
     i = 0;
     do {
         unsigned char remainder = value % 10;
         value = value / 10;
         buf[i++] = '0' + remainder;
-    }
-    while (value != 0);
+    } while (value != 0);
 
     /* Store the correct buffer size. */
-
     *used_buffer_size = 8 + 9 + i;
 
     /* Write result into the buffer. */
-
     p = buffer;
     memmove(p, "<uint32>", 8);
     p += 8;
-    for (j = i; j > 0;) {
+    for (j = i; j > 0;)
         *p++ = buf[--j];
-    }
     memmove(p, "</uint32>", 9);
 
     return XDS_OK;
 }
 
-int xml_decode_uint32(xds_t * xds, void *engine_context,
+int xml_decode_uint32(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     xds_uint32_t *value;
     char *p;
@@ -222,12 +211,10 @@
     xds_init_decoding_engine(8 + 9 + 1);
 
     /* Does the opening XML tag match? */
-
     if (strncasecmp(buffer, "<uint32>", 8) != 0)
         return XDS_ERR_TYPE_MISMATCH;
 
     /* Decode the representation of the value. */
-
     value = va_arg(*args, xds_uint32_t *);
     *value = 0;
     p = (char *)buffer + 8;
@@ -239,7 +226,6 @@
     }
 
     /* Does the closing XML tag match? */
-
     if (p + 9 > (char *)buffer + buffer_size)
         return XDS_ERR_UNDERFLOW;
     else if (strncasecmp(p, "</uint32>", 9) != 0)
@@ -251,9 +237,9 @@
 
 #ifdef XDS_HAVE_64_BIT_SUPPORT
 
-int xml_encode_int64(xds_t * xds, void *engine_context,
+int xml_encode_int64(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_int64_t value;
     char buf[64];
@@ -264,7 +250,6 @@
     xds_init_encoding_engine(7 + 8 + 21);
 
     /* Format value into our buffer. */
-
     value = va_arg(*args, xds_int64_t);
     if (value < 0) {
         negative = XDS_TRUE;
@@ -277,31 +262,27 @@
         unsigned char remainder = value % 10;
         value = value / 10;
         buf[i++] = '0' + remainder;
-    }
-    while (value != 0);
+    } while (value != 0);
     if (negative)
         buf[i++] = '-';
 
     /* Store the correct buffer size. */
-
     *used_buffer_size = 7 + 8 + i;
 
     /* Write result into the buffer. */
-
     p = buffer;
     memmove(p, "<int64>", 7);
     p += 7;
-    for (j = i; j > 0;) {
+    for (j = i; j > 0;)
         *p++ = buf[--j];
-    }
     memmove(p, "</int64>", 8);
 
     return XDS_OK;
 }
 
-int xml_decode_int64(xds_t * xds, void *engine_context,
+int xml_decode_int64(xds_t *xds, void *engine_context,
                      void *buffer, size_t buffer_size,
-                     size_t * used_buffer_size, va_list * args)
+                     size_t *used_buffer_size, va_list *args)
 {
     xds_int64_t *value;
     char *p;
@@ -310,18 +291,16 @@
     xds_init_decoding_engine(7 + 8 + 1);
 
     /* Does the opening XML tag match? */
-
     if (strncasecmp(buffer, "<int64>", 7) != 0)
         return XDS_ERR_TYPE_MISMATCH;
 
     /* Decode the representation of the value. */
-
     value = va_arg(*args, xds_int64_t *);
     *value = 0;
     p = (char *)buffer + 7;
     if (*p == '-') {
         negative = XDS_TRUE;
-        ++p;
+        p++;
     }
     else
         negative = XDS_FALSE;
@@ -335,7 +314,6 @@
         *value = 0 - *value;
 
     /* Does the closing XML tag match? */
-
     if (p + 8 > (char *)buffer + buffer_size)
         return XDS_ERR_UNDERFLOW;
     else if (strncasecmp(p, "</int64>", 8) != 0)
@@ -345,9 +323,9 @@
     return XDS_OK;
 }
 
-int xml_encode_uint64(xds_t * xds, void *engine_context,
+int xml_encode_uint64(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     xds_uint64_t value;
     char buf[64];
@@ -357,36 +335,31 @@
     xds_init_encoding_engine(8 + 9 + 20);
 
     /* Format value into our buffer. */
-
     value = va_arg(*args, xds_uint64_t);
     i = 0;
     do {
         unsigned char remainder = value % 10;
         value = value / 10;
         buf[i++] = '0' + remainder;
-    }
-    while (value != 0);
+    } while (value != 0);
 
     /* Store the correct buffer size. */
-
     *used_buffer_size = 8 + 9 + i;
 
     /* Write result into the buffer. */
-
     p = buffer;
     memmove(p, "<uint64>", 8);
     p += 8;
-    for (j = i; j > 0;) {
+    for (j = i; j > 0;)
         *p++ = buf[--j];
-    }
     memmove(p, "</uint64>", 9);
 
     return XDS_OK;
 }
 
-int xml_decode_uint64(xds_t * xds, void *engine_context,
+int xml_decode_uint64(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     xds_uint64_t *value;
     char *p;
@@ -394,12 +367,10 @@
     xds_init_decoding_engine(8 + 9 + 1);
 
     /* Does the opening XML tag match? */
-
     if (strncasecmp(buffer, "<uint64>", 8) != 0)
         return XDS_ERR_TYPE_MISMATCH;
 
     /* Decode the representation of the value. */
-
     value = va_arg(*args, xds_uint64_t *);
     *value = 0;
     p = (char *)buffer + 8;
@@ -411,7 +382,6 @@
     }
 
     /* Does the closing XML tag match? */
-
     if (p + 9 > (char *)buffer + buffer_size)
         return XDS_ERR_UNDERFLOW;
     else if (strncasecmp(p, "</uint64>", 9) != 0)
@@ -423,22 +393,24 @@
 
 #endif /* XDS_HAVE_64_BIT_SUPPORT */
 
-int xml_encode_double(xds_t * xds, void *engine_context,
+int xml_encode_double(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
+    /* XXX */
     return -1;
 }
 
-int xml_decode_double(xds_t * xds, void *engine_context,
+int xml_decode_double(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
+    /* XXX */
     return -1;
 }
 
-#define bits(c) (0x80 | ((c) & 0x3F))
-#define put(c)  *strptr++ = (c);
+#define bits(c)     (0x80 | ((c) & 0x3F))
+#define put(c)      *strptr++ = (c);
 #define putbits(c)  put(bits(c))
 #define finish()    *strptr = '\0'
 
@@ -487,19 +459,19 @@
         finish();
     }
     else
-        finish();                      /* Not a valid Unicode "character" */
+        finish(); /* Not a valid Unicode "character" */
 
     return strptr;
 }
 
-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 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,
+int xml_encode_string(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     char *src;
     size_t src_len;
@@ -508,120 +480,120 @@
     char *tmp;
 
     /* Setup the engine. We need at least space for our tags; how long the
-     * actual content is going to be will be seen soon. */
-
+       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) {
-        if (*((xds_uint8_t *) src) >= 0x80) {   /* UTF-8ify it. */
+        if (*((xds_uint8_t *) src) >= 0x80) { 
+            /* UTF-8ify it. */
             if (dst_size >= 7) {
                 tmp = sputu8((xds_uint32_t) * ((xds_uint8_t *) src), dst);
-                ++src;
-                --src_len;
+                src++;
+                src_len--;
                 dst_size -= tmp - dst;
                 dst = tmp;
             }
             else
                 dst_size = 0;
         }
-        else if (*src == '<') {        /* Turn into "&lt;". */
+        else if (*src == '<') { 
+            /* Turn into "&lt;". */
             if (dst_size >= 4) {
                 *dst++ = '&';
-                --dst_size;
+                dst_size--;
                 *dst++ = 'l';
-                --dst_size;
+                dst_size--;
                 *dst++ = 't';
-                --dst_size;
+                dst_size--;
                 *dst++ = ';';
-                --dst_size;
-                ++src;
-                --src_len;
+                dst_size--;
+                src++;
+                src_len--;
             }
             else
                 dst_size = 0;
         }
-        else if (*src == '&') {        /* Turn into "&amp;". */
+        else if (*src == '&') {
+            /* Turn into "&amp;". */
             if (dst_size >= 5) {
                 *dst++ = '&';
-                --dst_size;
+                dst_size--;
                 *dst++ = 'a';
-                --dst_size;
+                dst_size--;
                 *dst++ = 'm';
-                --dst_size;
+                dst_size--;
                 *dst++ = 'p';
-                --dst_size;
+                dst_size--;
                 *dst++ = ';';
-                --dst_size;
-                ++src;
-                --src_len;
+                dst_size--;
+                src++;
+                src_len--;
             }
             else
                 dst_size = 0;
         }
-        else if (*src == '>') {        /* Turn into "&gt;". */
+        else if (*src == '>') {
+            /* Turn into "&gt;". */
             if (dst_size >= 4) {
                 *dst++ = '&';
-                --dst_size;
+                dst_size--;
                 *dst++ = 'g';
-                --dst_size;
+                dst_size--;
                 *dst++ = 't';
-                --dst_size;
+                dst_size--;
                 *dst++ = ';';
-                --dst_size;
-                ++src;
-                --src_len;
+                dst_size--;
+                src++;
+                src_len--;
             }
             else
                 dst_size = 0;
         }
-        else {                         /* No special character; just copy it. 
-                                        */
+        else {  
+            /* No special character; just copy it. */
             *dst++ = *src++;
-            --src_len;
-            --dst_size;
+            src_len--;
+            dst_size--;
         }
     }
-    if (src_len > 0) {                 /* Target buffer was too small. */
+    if (src_len > 0) {
+        /* Target buffer was too small. */
         *used_buffer_size = buffer_size + 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;
 }
 
-#define INVALID 0x80000000
-
-#define get(c)  c = *strptr++; \
-    if (chars) (*chars)++; \
-    if ((c) == 0) return (unsigned int)EOF
+#define INVALID \
+    0x80000000
+#define get(c) \
+    c = *strptr++; \
+    if (chars) \
+        (*chars)++; \
+    if ((c) == 0) \
+        return (unsigned int)EOF
 
 static unsigned int sgetu8(unsigned char *strptr, int *chars)
 {
@@ -636,7 +608,6 @@
         return (unsigned int)EOF;
 
     get(c);
-
     if ((c & 0xFE) == 0xFC) {
         c &= 0x01;
         iterations = 5;
@@ -673,9 +644,9 @@
     return c;
 }
 
-int xml_decode_string(xds_t * xds, void *engine_context,
+int xml_decode_string(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
-                      size_t * used_buffer_size, va_list * args)
+                      size_t *used_buffer_size, va_list *args)
 {
     char **target_buffer;
     char *src;
@@ -685,30 +656,25 @@
     unsigned int rc;
 
     /* Setup the engine. We need at least space for our tags; how long the
-     * actual content is going to be will be seen soon. */
-
+       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);
@@ -716,7 +682,6 @@
         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) {
@@ -740,24 +705,22 @@
             }
         }
         else if (*((xds_uint8_t *) src) >= 0x80) {
-            rc = sgetu8((xds_uint8_t *) src, &utf8_len);
+            rc = sgetu8((xds_uint8_t *)src, &utf8_len);
             if (rc == (unsigned int)EOF)
                 return XDS_ERR_UNDERFLOW;
             else if (rc == INVALID || rc > 255)
                 return XDS_ERR_TYPE_MISMATCH;
-            *dst++ = (xds_uint8_t) rc;
+            *dst++ = (xds_uint8_t)rc;
             src += utf8_len;
             src_len -= utf8_len;
         }
         else {
             *dst++ = *src++;
-            --src_len;
+            src_len--;
         }
     }
     *dst = '\0';
 
-    /* Done. */
-
     return XDS_OK;
 }
 
@@ -765,8 +728,8 @@
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 static const char xds_pad64 = '=';
 
-static int base64_encode(char *dst, size_t dstlen, unsigned char const *src,
-                         size_t srclen)
+static int base64_encode(char *dst, size_t dstlen, 
+                         unsigned char const *src, size_t srclen)
 {
     size_t dstpos;
     unsigned char input[3];
@@ -791,10 +754,10 @@
         input[2] = *src++;
         srclen -= 3;
 
-        output[0] = (input[0] >> 2);
+        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);
+        output[3] = ( input[2] & 0x3f);
 
         if (dstpos + 4 > dstlen)
             return -1;
@@ -810,7 +773,7 @@
         for (i = 0; i < srclen; i++)
             input[i] = *src++;
 
-        output[0] = (input[0] >> 2);
+        output[0] = ( input[0] >> 2);
         output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
         output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
 
@@ -832,26 +795,23 @@
     return dstpos;
 }
 
-int xml_encode_octetstream(xds_t * xds, void *engine_context,
+int xml_encode_octetstream(xds_t *xds, void *engine_context,
                            void *buffer, size_t buffer_size,
-                           size_t * used_buffer_size, va_list * args)
+                           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 *);
+    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. */
-
+       them. */
     *used_buffer_size = base64_encode(NULL, 0, src, src_len);
     if (*used_buffer_size == (size_t) - 1)
         return XDS_ERR_UNKNOWN;
@@ -861,10 +821,8 @@
         return XDS_ERR_OVERFLOW;
 
     /* Format the data into the buffer. */
-
     memmove(buffer, "<octetstream>", 13);
-    if (base64_encode((char *)buffer + 13, buffer_size - 13, src, src_len) <
-        0)
+    if (base64_encode((char *)buffer + 13, buffer_size - 13, src, src_len) < 0)
         return XDS_ERR_UNKNOWN;
     memmove((char *)buffer + *used_buffer_size - 14, "</octetstream>", 14);
 
@@ -873,8 +831,8 @@
     return XDS_OK;
 }
 
-static int base64_decode(unsigned char *dst, size_t dstlen, char const *src,
-                         size_t srclen)
+static int base64_decode(unsigned char *dst, size_t dstlen, 
+                         char const *src, size_t srclen)
 {
     int dstidx, state, ch = 0;
     unsigned char res;
@@ -941,8 +899,7 @@
      * 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. */
+    if (ch == xds_pad64) {         /* We got a pad char. */
         switch (state) {
             case 0:                /* Invalid = in first position */
             case 1:                /* Invalid = in second position */
@@ -994,9 +951,9 @@
     return dstidx;
 }
 
-int xml_decode_octetstream(xds_t * xds, void *engine_context,
+int xml_decode_octetstream(xds_t *xds, void *engine_context,
                            void *buffer, size_t buffer_size,
-                           size_t * used_buffer_size, va_list * args)
+                           size_t *used_buffer_size, va_list *args)
 {
     char *p;
     size_t p_len;
@@ -1004,23 +961,19 @@
     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("<octetstream>", buffer, 13) != 0)
         return XDS_ERR_TYPE_MISMATCH;
 
     /* Find the end of the data and calculate the length of the
-     * base64-encoded stuff. */
-
+       base64-encoded stuff. */
     p = (char *)buffer + 13;
     while (p < ((char *)buffer + buffer_size) && *p != '<')
         ++p;
@@ -1032,8 +985,7 @@
     }
 
     /* Now find out how long the decoded data is going to be, allocate a
-     * buffer for it, and decode away. */
-
+       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;
@@ -1043,14 +995,12 @@
     base64_decode(*data, *data_len, p, p_len);
 
     /* Check that we have a closing tag. */
-
     if (memcmp(p + p_len, "</octetstream>", 14) != 0) {
         free(*data);
         return XDS_ERR_TYPE_MISMATCH;
     }
 
-    /* Done. */
-
     *used_buffer_size = 13 + p_len + 14;
     return XDS_OK;
 }
+

CVSTrac 2.0.1