]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/serial.c
Fix typo.
[bacula/bacula] / bacula / src / lib / serial.c
index 8f5da389f5ab00f52fe2438bb55ca64c586eee4c..3bcecd607f8be65db4cc8f277d59ac4997a2961e 100644 (file)
@@ -2,33 +2,30 @@
 
                    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.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -92,7 +89,7 @@ void serial_uint32(uint8_t * * const ptr, const uint32_t v)
 
 void serial_int64(uint8_t * * const ptr, const int64_t v)
 {
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(*ptr, &v, sizeof(int64_t));
     } else {
         int i;
@@ -112,7 +109,7 @@ void serial_int64(uint8_t * * const ptr, const int64_t v)
 
 void serial_uint64(uint8_t * * const ptr, const uint64_t v)
 {
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(*ptr, &v, sizeof(uint64_t));
     } else {
         int i;
@@ -132,7 +129,7 @@ void serial_uint64(uint8_t * * const ptr, const uint64_t v)
 
 void serial_btime(uint8_t * * const ptr, const btime_t v)
 {
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(*ptr, &v, sizeof(btime_t));
     } else {
         int i;
@@ -158,7 +155,7 @@ void serial_btime(uint8_t * * const ptr, const btime_t v)
 
 void serial_float64(uint8_t * * const ptr, const float64_t v)
 {
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(*ptr, &v, sizeof(float64_t));
     } else {
         int i;
@@ -175,10 +172,15 @@ void serial_float64(uint8_t * * const ptr, const float64_t v)
 
 void serial_string(uint8_t * * const ptr, const char * const str)
 {
-   int len = strlen(str) + 1;
-
-   memcpy(*ptr, str, len);
-   *ptr += len;
+   int i;                   
+   char *dest = (char *)*ptr;
+   char *src = (char *)str;
+   for (i=0; 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);
 }
 
 
@@ -232,7 +234,7 @@ uint64_t unserial_uint64(uint8_t * * const ptr)
 {
     uint64_t v;
 
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(&v, *ptr, sizeof(uint64_t));
     } else {
         int i;
@@ -255,7 +257,7 @@ btime_t unserial_btime(uint8_t * * const ptr)
 {
     btime_t v;
 
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(&v, *ptr, sizeof(btime_t));
     } else {
         int i;
@@ -285,7 +287,7 @@ float64_t unserial_float64(uint8_t * * const ptr)
 {
     float64_t v;
 
-    if (htonl(1) == 1L) {
+    if (bigendian()) {
         memcpy(&v, *ptr, sizeof(float64_t));
     } else {
         int i;
@@ -302,9 +304,15 @@ float64_t unserial_float64(uint8_t * * const ptr)
     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);
 }