Serialisation Support Functions
                           John Walker
-
-
-     Version $Id$
 */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
     *ptr += sizeof(float64_t);
 }
 
-void serial_string(uint8_t * * const ptr, const char * const str)
+void serial_string(uint8_t * * const ptr, const char * const str, int max)
 {
-   int len = strlen(str) + 1;
-
-   memcpy(*ptr, str, len);
-   *ptr += len;
+   int i;                   
+   char *dest = (char *)*ptr;
+   char *src = (char *)str;
+   for (i=0; i<max && src[i] != 0;  i++) {
+      dest[i] = src[i];
+   }
+   dest[i++] = 0;                  /* terminate output string */
+   *ptr += i;                      /* update pointer */
+// Dmsg2(000, "ser src=%s dest=%s\n", src, dest);
 }
 
 
     return v;
 }
 
-void unserial_string(uint8_t * * const ptr, char * const str)
+void unserial_string(uint8_t * * const ptr, char * const str, int max)
 {
-   int len = strlen((char *) *ptr) + 1;
-   memcpy(str, (char *) *ptr, len);
-   *ptr += len;
+   int i;                   
+   char *src = (char*)(*ptr);
+   char *dest = str;
+   for (i=0; i<max && src[i] != 0;  i++) {
+      dest[i] = src[i];
+   }
+   dest[i++] = 0;            /* terminate output string */
+   *ptr += i;                /* update pointer */
+// Dmsg2(000, "unser src=%s dest=%s\n", src, dest);
 }
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
  *
  * Written by John Walker, MM
  *
- *   Version $Id$
  */
 
 /*  Serialisation support functions from serial.c.  */
 extern void serial_uint64(uint8_t * * const ptr, const uint64_t v);
 extern void serial_btime(uint8_t * * const ptr, const btime_t v);
 extern void serial_float64(uint8_t * * const ptr, const float64_t v);
-extern void serial_string(uint8_t * * const ptr, const char * const str);
+extern void serial_string(uint8_t * * const ptr, const char * const str, int max);
 
 extern int16_t unserial_int16(uint8_t * * const ptr);
 extern uint16_t unserial_uint16(uint8_t * * const ptr);
 extern uint64_t unserial_uint64(uint8_t * * const ptr);
 extern btime_t unserial_btime(uint8_t * * const ptr);
 extern float64_t unserial_float64(uint8_t * * const ptr);
-extern void unserial_string(uint8_t * * const ptr, char * const str);
+extern void unserial_string(uint8_t * * const ptr, char * const str, int max);
 
 /*
 
 #define ser_buffer(x)   ser_bytes((x), (sizeof (x)))
 
 /* Binary string not requiring serialization */
-#define ser_string(x)   serial_string(&ser_ptr, (x))
+#define ser_string(x)   serial_string(&ser_ptr, (x), (int)sizeof(x))
 
 /*                         Unserialisation                  */
 
 #define unser_buffer(x)  unser_bytes((x), (sizeof (x)))
 
 /* Binary string not requiring serialization */
-#define unser_string(x) unserial_string(&ser_ptr, (x))
+#define unser_string(x) unserial_string(&ser_ptr, (x), (int)sizeof(x))
 
 #endif /* __SERIAL_H_ */