]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/serial.c
dhb Medialist : created context menu function and moved lines which create
[bacula/bacula] / bacula / src / lib / serial.c
index a042324108f5dedd4346330c71e5d6ba756c847a..8f5da389f5ab00f52fe2438bb55ca64c586eee4c 100644 (file)
@@ -1,30 +1,38 @@
 /*
 
-                  Serialisation Support Functions
-                         John Walker
+                   Serialisation Support Functions
+                          John Walker
 
 
      Version $Id$
 */
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   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.
+
+   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   You should have received a copy of the GNU 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.
+   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"
 
 /*
 
-       NOTE:  The following functions should work on any
-              vaguely contemporary platform.  Production
-              builds should use optimised macros (void
-              on platforms with network byte order and IEEE
-              floating point format as native.
+        NOTE:  The following functions should work on any
+               vaguely contemporary platform.  Production
+               builds should use optimised macros (void
+               on platforms with network byte order and IEEE
+               floating point format as native.
 
 */
 
@@ -85,16 +93,16 @@ 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) {
-       memcpy(*ptr, &v, sizeof(int64_t));
+        memcpy(*ptr, &v, sizeof(int64_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(int64_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(*ptr, &rv, sizeof(int64_t));
+        int i;
+        uint8_t rv[sizeof(int64_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(*ptr, &rv, sizeof(int64_t));
     }
     *ptr += sizeof(int64_t);
 }
@@ -105,16 +113,16 @@ 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) {
-       memcpy(*ptr, &v, sizeof(uint64_t));
+        memcpy(*ptr, &v, sizeof(uint64_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(uint64_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(*ptr, &rv, sizeof(uint64_t));
+        int i;
+        uint8_t rv[sizeof(uint64_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(*ptr, &rv, sizeof(uint64_t));
     }
     *ptr += sizeof(uint64_t);
 }
@@ -125,42 +133,42 @@ 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) {
-       memcpy(*ptr, &v, sizeof(btime_t));
+        memcpy(*ptr, &v, sizeof(btime_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(btime_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(*ptr, &rv, sizeof(btime_t));
+        int i;
+        uint8_t rv[sizeof(btime_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(*ptr, &rv, sizeof(btime_t));
     }
     *ptr += sizeof(btime_t);
 }
 
 
 
-/*  serial_float64  -- Serialise a 64 bit IEEE floating point number.
-                       This code assumes that the host floating point
-                       format is IEEE and that floating point quantities
-                       are stored in IEEE format either LSB first or MSB
-                       first.  More creative host formats will require
-                       additional transformations here.  */
+/*  serial_float64  --  Serialise a 64 bit IEEE floating point number.
+                        This code assumes that the host floating point
+                        format is IEEE and that floating point quantities
+                        are stored in IEEE format either LSB first or MSB
+                        first.  More creative host formats will require
+                        additional transformations here.  */
 
 void serial_float64(uint8_t * * const ptr, const float64_t v)
 {
     if (htonl(1) == 1L) {
-       memcpy(*ptr, &v, sizeof(float64_t));
+        memcpy(*ptr, &v, sizeof(float64_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(float64_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(*ptr, &rv, sizeof(float64_t));
+        int i;
+        uint8_t rv[sizeof(float64_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(*ptr, &rv, sizeof(float64_t));
     }
     *ptr += sizeof(float64_t);
 }
@@ -174,7 +182,7 @@ void serial_string(uint8_t * * const ptr, const char * const str)
 }
 
 
-/*  unserial_int16  -- Unserialise a signed 16 bit integer.  */
+/*  unserial_int16  --  Unserialise a signed 16 bit integer.  */
 
 int16_t unserial_int16(uint8_t * * const ptr)
 {
@@ -196,7 +204,7 @@ uint16_t unserial_uint16(uint8_t * * const ptr)
     return ntohs(vo);
 }
 
-/*  unserial_int32  -- Unserialise a signed 32 bit integer.  */
+/*  unserial_int32  --  Unserialise a signed 32 bit integer.  */
 
 int32_t unserial_int32(uint8_t * * const ptr)
 {
@@ -225,40 +233,40 @@ uint64_t unserial_uint64(uint8_t * * const ptr)
     uint64_t v;
 
     if (htonl(1) == 1L) {
-       memcpy(&v, *ptr, sizeof(uint64_t));
+        memcpy(&v, *ptr, sizeof(uint64_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(uint64_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       memcpy(&v, *ptr, sizeof(uint64_t));
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(&v, &rv, sizeof(uint64_t));
+        int i;
+        uint8_t rv[sizeof(uint64_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        memcpy(&v, *ptr, sizeof(uint64_t));
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(&v, &rv, sizeof(uint64_t));
     }
     *ptr += sizeof(uint64_t);
     return v;
 }
 
-/*  unserial_btime  -- Unserialise a btime_t 64 bit integer.  */
+/*  unserial_btime  --  Unserialise a btime_t 64 bit integer.  */
 
 btime_t unserial_btime(uint8_t * * const ptr)
 {
     btime_t v;
 
     if (htonl(1) == 1L) {
-       memcpy(&v, *ptr, sizeof(btime_t));
+        memcpy(&v, *ptr, sizeof(btime_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(btime_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       memcpy(&v, *ptr, sizeof(btime_t));
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(&v, &rv, sizeof(btime_t));
+        int i;
+        uint8_t rv[sizeof(btime_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        memcpy(&v, *ptr, sizeof(btime_t));
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(&v, &rv, sizeof(btime_t));
     }
     *ptr += sizeof(btime_t);
     return v;
@@ -267,28 +275,28 @@ btime_t unserial_btime(uint8_t * * const ptr)
 
 
 /*  unserial_float64  --  Unserialise a 64 bit IEEE floating point number.
-                        This code assumes that the host floating point
-                        format is IEEE and that floating point quantities
-                        are stored in IEEE format either LSB first or MSB
-                        first.  More creative host formats will require
-                        additional transformations here.  */
+                         This code assumes that the host floating point
+                         format is IEEE and that floating point quantities
+                         are stored in IEEE format either LSB first or MSB
+                         first.  More creative host formats will require
+                         additional transformations here.  */
 
 float64_t unserial_float64(uint8_t * * const ptr)
 {
     float64_t v;
 
     if (htonl(1) == 1L) {
-       memcpy(&v, *ptr, sizeof(float64_t));
+        memcpy(&v, *ptr, sizeof(float64_t));
     } else {
-       int i;
-       uint8_t rv[sizeof(float64_t)];
-       uint8_t *pv = (uint8_t *) &v;
-
-       memcpy(&v, *ptr, sizeof(float64_t));
-       for (i = 0; i < 8; i++) {
-           rv[i] = pv[7 - i];
-       }
-       memcpy(&v, &rv, sizeof(float64_t));
+        int i;
+        uint8_t rv[sizeof(float64_t)];
+        uint8_t *pv = (uint8_t *) &v;
+
+        memcpy(&v, *ptr, sizeof(float64_t));
+        for (i = 0; i < 8; i++) {
+            rv[i] = pv[7 - i];
+        }
+        memcpy(&v, &rv, sizeof(float64_t));
     }
     *ptr += sizeof(float64_t);
     return v;