]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/serial.c
bat: Add pattern filter and make restore to start from brestore
[bacula/bacula] / bacula / src / lib / serial.c
index 93855b6de753d01177bc95ca6b51c7b185a25ff9..3bcecd607f8be65db4cc8f277d59ac4997a2961e 100644 (file)
@@ -2,24 +2,34 @@
 
                    Serialisation Support Functions
                           John Walker
-
-
-     Version $Id$
 */
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   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 
-   the file LICENSE for additional details.
-
- */
+   Bacula® - The Network Backup Solution
+
+   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 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 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 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.
+*/
 
 
 #include "bacula.h"
@@ -79,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;
@@ -99,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;
@@ -119,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;
@@ -145,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;
@@ -162,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);
 }
 
 
@@ -219,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;
@@ -242,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;
@@ -272,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;
@@ -289,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);
 }