X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fbase64.c;h=02e42639c711681d250ec6b1bf0f17e0c6705838;hb=d8628580f5e43ec26d4816ac521cf2b1675a129b;hp=d956dca29eb784193ae583a097f273eab6edf583;hpb=56bbed88464979b01f841bf1332c3b9cfa769654;p=bacula%2Fbacula diff --git a/bacula/src/lib/base64.c b/bacula/src/lib/base64.c index d956dca29e..02e42639c7 100644 --- a/bacula/src/lib/base64.c +++ b/bacula/src/lib/base64.c @@ -1,34 +1,42 @@ -/* - * Generic base 64 input and output routines - * - * Written by Kern E. Sibbald, March MM. - * - * 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-2007 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 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 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 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. +*/ +/* + * Generic base 64 input and output routines + * + * Written by Kern E. Sibbald, March MM. + * + * Version $Id$ */ #include "bacula.h" + #ifdef TEST_MODE #include #endif @@ -45,13 +53,13 @@ static uint8_t const base64_digits[64] = static int base64_inited = 0; static uint8_t base64_map[128]; - + /* Initialize the Base 64 conversion routines */ void base64_init(void) -{ - int i; +{ + int i; memset(base64_map, 0, sizeof(base64_map)); for (i=0; i<64; i++) base64_map[(uint8_t)base64_digits[i]] = i; @@ -105,11 +113,11 @@ to_base64(intmax_t value, char *where) */ int from_base64(intmax_t *value, char *where) -{ +{ uintmax_t val = 0; int i, neg; - if (!base64_inited) + if (!base64_inited) base64_init(); /* Check if it is negative */ i = neg = 0; @@ -122,7 +130,7 @@ from_base64(intmax_t *value, char *where) val <<= 6; val += base64_map[(uint8_t)where[i++]]; } - + *value = neg ? -(intmax_t)val : (intmax_t)val; return i; } @@ -132,11 +140,14 @@ from_base64(intmax_t *value, char *where) * Encode binary data in bin of len bytes into * buf as base64 characters. * + * If compatible is true, the bin_to_base64 routine will be compatible + * with what the rest of the world uses. + * * Returns: the number of characters stored not - * including the EOS + * including the EOS */ int -bin_to_base64(char *buf, char *bin, int len) +bin_to_base64(char *buf, int buflen, char *bin, int binlen, int compatible) { uint32_t reg, save, mask; int rem, i; @@ -144,24 +155,32 @@ bin_to_base64(char *buf, char *bin, int len) reg = 0; rem = 0; - for (i=0; i>= (rem - 6); - buf[j++] = base64_digits[reg & (uint32_t)0x3F]; + if (j < buflen) { + buf[j++] = base64_digits[reg & 0x3F]; + } reg = save; rem -= 6; } - if (rem) { - mask = 1; - for (i=1; i 1 && strcmp(argv[1], "-v") == 0) - debug_level++; + debug_level++; base64_init(); @@ -228,13 +247,14 @@ int main(int argc, char *argv[]) for (i=0; my_glob.gl_pathv[i]; i++) { fname = my_glob.gl_pathv[i]; if (lstat(fname, &statp) < 0) { - printf("Cannot stat %s: %s\n", fname, strerror(errno)); - continue; + berrno be; + printf("Cannot stat %s: %s\n", fname, be.bstrerror(errno)); + continue; } - encode_stat(where, &statp); + encode_stat(where, &statp, 0, 0); printf("Encoded stat=%s\n", where); - + #ifdef xxx p = where; p += to_base64((intmax_t)(statp.st_atime), p); @@ -259,25 +279,25 @@ int main(int argc, char *argv[]) if (debug_level) printf("%s: len=%d val=%s\n", fname, strlen(where), where); - + decode_stat(where, &statn); - if (statp.st_dev != statn.st_dev || - statp.st_ino != statn.st_ino || - statp.st_mode != statn.st_mode || - statp.st_nlink != statn.st_nlink || - statp.st_uid != statn.st_uid || - statp.st_gid != statn.st_gid || - statp.st_rdev != statn.st_rdev || - statp.st_size != statn.st_size || - statp.st_blksize != statn.st_blksize || - statp.st_blocks != statn.st_blocks || - statp.st_atime != statn.st_atime || - statp.st_mtime != statn.st_mtime || - statp.st_ctime != statn.st_ctime) { + if (statp.st_dev != statn.st_dev || + statp.st_ino != statn.st_ino || + statp.st_mode != statn.st_mode || + statp.st_nlink != statn.st_nlink || + statp.st_uid != statn.st_uid || + statp.st_gid != statn.st_gid || + statp.st_rdev != statn.st_rdev || + statp.st_size != statn.st_size || + statp.st_blksize != statn.st_blksize || + statp.st_blocks != statn.st_blocks || + statp.st_atime != statn.st_atime || + statp.st_mtime != statn.st_mtime || + statp.st_ctime != statn.st_ctime) { printf("%s: %s\n", fname, where); - encode_stat(where, &statn); + encode_stat(where, &statn, 0, 0); printf("%s: %s\n", fname, where); printf("NOT EQAL\n"); } @@ -291,5 +311,5 @@ int main(int argc, char *argv[]) printf("UINT32_MAX=%s\n", where); return 0; -} +} #endif