]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/base64.c
Use the command line utility dropdb instead of the psql command
[bacula/bacula] / bacula / src / lib / base64.c
index 6a9f8a8382106bb2f3af5e918b5d56f6dbb6a488..ae8e2bfd65b620f18379e337dcc4990bf9a303be 100644 (file)
@@ -34,7 +34,7 @@
 #endif
 
 
-static char const base64_digits[64] =
+static uint8_t const base64_digits[64] =
 {
   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
   'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
@@ -44,7 +44,7 @@ static char const base64_digits[64] =
 };
 
 static int base64_inited = 0;
-static char base64_map[128];
+static uint8_t base64_map[128];
   
 
 /* Initialize the Base 64 conversion routines */
@@ -54,7 +54,7 @@ base64_init(void)
    int i; 
    memset(base64_map, 0, sizeof(base64_map));
    for (i=0; i<64; i++)
-      base64_map[(int)base64_digits[i]] = i;
+      base64_map[(uint8_t)base64_digits[i]] = i;
    base64_inited = 1;
 }
 
@@ -90,7 +90,7 @@ to_base64(intmax_t value, char *where)
    val = value;
    where[i] = 0;
    do {
-      where[--i] = base64_digits[val & (unsigned)0x3F];
+      where[--i] = base64_digits[val & (uintmax_t)0x3F];
       val >>= 6;
    } while (val);
    return n;
@@ -120,102 +120,13 @@ from_base64(intmax_t *value, char *where)
    /* Construct value */
    while (where[i] != 0 && where[i] != ' ') {
       val <<= 6;
-      val += base64_map[(int)where[i++]];
+      val += base64_map[(uint8_t)where[i++]];
    }
         
    *value = neg ? -(intmax_t)val : (intmax_t)val;
    return i;
 }
 
-/* Encode a stat structure into a base64 character string */
-void
-encode_stat(char *buf, struct stat *statp)
-{
-   char *p = buf;
-   /*
-    * NOTE: we should use rdev as major and minor device if
-    * it is a block or char device (S_ISCHR(statp->st_mode)
-    * or S_ISBLK(statp->st_mode)).  In all other cases,
-    * it is not used.  
-    *
-    */
-   p += to_base64((intmax_t)statp->st_dev, p);
-   *p++ = ' ';                        /* separate fields with a space */
-   p += to_base64((intmax_t)statp->st_ino, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_mode, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_nlink, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_uid, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_gid, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_rdev, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_size, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_blksize, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_blocks, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_atime, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_mtime, p);
-   *p++ = ' ';
-   p += to_base64((intmax_t)statp->st_ctime, p);
-   *p++ = 0;
-   return;
-}
-
-
-/* Decode a stat packet from base64 characters */
-void
-decode_stat(char *buf, struct stat *statp)
-{
-   char *p = buf;
-   intmax_t val;
-
-   p += from_base64(&val, p);
-   statp->st_dev = val;
-   p++;                              /* skip space */
-   p += from_base64(&val, p);
-   statp->st_ino = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_mode = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_nlink = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_uid = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_gid = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_rdev = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_size = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_blksize = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_blocks = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_atime = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_mtime = val;
-   p++;
-   p += from_base64(&val, p);
-   statp->st_ctime = val;
-   p++;
-}
 
 /*
  * Encode binary data in bin of len bytes into
@@ -227,7 +138,7 @@ decode_stat(char *buf, struct stat *statp)
 int
 bin_to_base64(char *buf, char *bin, int len)
 {
-   unsigned int reg, save, mask;
+   uint32_t reg, save, mask;
    int rem, i;
    int j = 0;
 
@@ -236,12 +147,12 @@ bin_to_base64(char *buf, char *bin, int len)
    for (i=0; i<len; ) {
       if (rem < 6) {
         reg <<= 8;
-        reg |= bin[i++];
+        reg |= (int8_t)bin[i++];
         rem += 8;
       }
       save = reg;
       reg >>= (rem - 6);
-      buf[j++] = base64_digits[reg & (unsigned)0x3F];
+      buf[j++] = base64_digits[reg & (uint32_t)0x3F];
       reg = save;
       rem -= 6;
    }
@@ -265,11 +176,17 @@ int main(int argc, char *argv[])
    char junk[100];
    int i;
 
-   for (i=0; i < 100; i++) {
+#ifdef xxxx
+   for (i=0; i < 1000; i++) {
       bin_to_base64(buf, (char *)&xx, 4);
       printf("xx=%s\n", buf);
       xx++;
    }
+#endif
+   junk[0] = 0xFF;
+   for (i=1; i<100; i++) {
+      junk[i] = junk[i-1]-1;
+   }
    len = bin_to_base64(buf, junk, 16);
    printf("len=%d junk=%s\n", len, buf);
    return 0;
@@ -279,7 +196,7 @@ int main(int argc, char *argv[])
 #ifdef TEST_MODE
 static int errfunc(const char *epath, int eernoo)
 {
-  Dmsg0(-1, "in errfunc\n");
+  printf("in errfunc\n");
   return 1;
 }
 
@@ -297,6 +214,8 @@ int main(int argc, char *argv[])
    struct stat statp;
    struct stat statn;
    int debug_level = 0;
+   char *p;
+   time_t t = 1028712799;
 
    if (argc > 1 && strcmp(argv[1], "-v") == 0)
       debug_level++;  
@@ -304,7 +223,7 @@ int main(int argc, char *argv[])
    base64_init();
 
    my_glob.gl_offs = 0;
-   glob("/etc/*", GLOB_MARK, errfunc, &my_glob);
+   glob("/etc/grub.conf", GLOB_MARK, errfunc, &my_glob);
 
    for (i=0; my_glob.gl_pathv[i]; i++) {
       fname = my_glob.gl_pathv[i];
@@ -314,6 +233,30 @@ int main(int argc, char *argv[])
       }
       encode_stat(where, &statp);
 
+      printf("Encoded stat=%s\n", where);
+     
+#ifdef xxx
+      p = where;
+      p += to_base64((intmax_t)(statp.st_atime), p);
+      *p++ = ' ';
+      p += to_base64((intmax_t)t, p);
+      printf("%s %s\n", fname, where);
+
+      printf("%s %lld\n", "st_dev", (intmax_t)statp.st_dev);
+      printf("%s %lld\n", "st_ino", (intmax_t)statp.st_ino);
+      printf("%s %lld\n", "st_mode", (intmax_t)statp.st_mode);
+      printf("%s %lld\n", "st_nlink", (intmax_t)statp.st_nlink);
+      printf("%s %lld\n", "st_uid", (intmax_t)statp.st_uid);
+      printf("%s %lld\n", "st_gid", (intmax_t)statp.st_gid);
+      printf("%s %lld\n", "st_rdev", (intmax_t)statp.st_rdev);
+      printf("%s %lld\n", "st_size", (intmax_t)statp.st_size);
+      printf("%s %lld\n", "st_blksize", (intmax_t)statp.st_blksize);
+      printf("%s %lld\n", "st_blocks", (intmax_t)statp.st_blocks);
+      printf("%s %lld\n", "st_atime", (intmax_t)statp.st_atime);
+      printf("%s %lld\n", "st_mtime", (intmax_t)statp.st_mtime);
+      printf("%s %lld\n", "st_ctime", (intmax_t)statp.st_ctime);
+#endif
+
       if (debug_level)
          printf("%s: len=%d val=%s\n", fname, strlen(where), where);
       
@@ -344,6 +287,9 @@ int main(int argc, char *argv[])
 
    printf("%d files examined\n", i);
 
+   to_base64(UINT32_MAX, where);
+   printf("UINT32_MAX=%s\n", where);
+
    return 0;
 }   
 #endif