Imported Upstream version 3.3.1
[debian/amanda] / server-src / amindex.c
index 2e763dc44b88225ae38bb16cce821af42cd149d8..e71fc013d1d3eb490b4e1aafae5e1f5011512133 100644 (file)
  *                        University of Maryland at College Park
  */
 /*
- * $Id: amindex.c,v 1.13 2001/09/01 03:36:24 jrjackson Exp $
+ * $Id: amindex.c,v 1.15 2006/05/25 01:47:19 johnfranks Exp $
  *
  * index control
  */
 
+#include "amanda.h"
 #include "conffile.h"
 #include "amindex.h"
 
-char *getindexfname(host, disk, date, level)
-char *host, *disk, *date;
-int level;
+char *
+getindexfname(
+    char *     host,
+    char *     disk,
+    char *     date,
+    int                level)
 {
   char *conf_indexdir;
   char *buf;
   char level_str[NUM_STR_SIZE];
-  char datebuf[8 + 1];
+  char datebuf[14 + 1];
   char *dc = NULL;
   char *pc;
   int ch;
@@ -48,8 +52,67 @@ int level;
   if (date != NULL) {
     dc = date;
     pc = datebuf;
-    while (pc < datebuf + sizeof (datebuf)) {
-      if ((*pc++ = ch = *dc++) == '\0') {
+    while (pc < datebuf + SIZEOF(datebuf)) {
+      ch = *dc++;
+      *pc++ = (char)ch;
+      if (ch == '\0') {
+        break;
+      } else if (! isdigit (ch)) {
+        pc--;
+      }
+    }
+    datebuf[SIZEOF(datebuf)-1] = '\0';
+    dc = datebuf;
+
+    g_snprintf(level_str, SIZEOF(level_str), "%d", level);
+  }
+
+  host = sanitise_filename(host);
+  if (disk != NULL) {
+    disk = sanitise_filename(disk);
+  }
+
+  conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR));
+  /*
+   * Note: vstralloc() will stop at the first NULL, which might be
+   * "disk" or "dc" (datebuf) rather than the full file name.
+   */
+  buf = vstralloc(conf_indexdir, "/",
+                 host, "/",
+                 disk, "/",
+                 dc, "_",
+                 level_str, COMPRESS_SUFFIX,
+                 NULL);
+
+  amfree(conf_indexdir);
+  amfree(host);
+  amfree(disk);
+
+  return buf;
+}
+
+char *
+getheaderfname(
+    char *     host,
+    char *     disk,
+    char *     date,
+    int                level)
+{
+  char *conf_indexdir;
+  char *buf;
+  char level_str[NUM_STR_SIZE];
+  char datebuf[14 + 1];
+  char *dc = NULL;
+  char *pc;
+  int ch;
+
+  if (date != NULL) {
+    dc = date;
+    pc = datebuf;
+    while (pc < datebuf + sizeof(datebuf)) {
+      ch = *dc++;
+      *pc++ = (char)ch;
+      if (ch == '\0') {
         break;
       } else if (! isdigit (ch)) {
         pc--;
@@ -58,7 +121,7 @@ int level;
     datebuf[sizeof(datebuf)-1] = '\0';
     dc = datebuf;
 
-    snprintf(level_str, sizeof(level_str), "%d", level);
+    g_snprintf(level_str, sizeof(level_str), "%d", level);
   }
 
   host = sanitise_filename(host);
@@ -66,12 +129,64 @@ int level;
     disk = sanitise_filename(disk);
   }
 
-  conf_indexdir = getconf_str(CNF_INDEXDIR);
-  if (*conf_indexdir == '/') {
-    conf_indexdir = stralloc(conf_indexdir);
-  } else {
-    conf_indexdir = stralloc2(config_dir, conf_indexdir);
+  conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR));
+  /*
+   * Note: g_strjoin(NULL, ) will stop at the first NULL, which might be
+   * "disk" or "dc" (datebuf) rather than the full file name.
+   */
+  buf = g_strjoin(NULL, conf_indexdir, "/",
+                 host, "/",
+                 disk, "/",
+                 dc, "_",
+                 level_str, ".header",
+                 NULL);
+
+  amfree(conf_indexdir);
+  amfree(host);
+  amfree(disk);
+
+  return buf;
+}
+
+char *
+getoldindexfname(
+    char *     host,
+    char *     disk,
+    char *     date,
+    int                level)
+{
+  char *conf_indexdir;
+  char *buf;
+  char level_str[NUM_STR_SIZE];
+  char datebuf[14 + 1];
+  char *dc = NULL;
+  char *pc;
+  int ch;
+
+  if (date != NULL) {
+    dc = date;
+    pc = datebuf;
+    while (pc < datebuf + SIZEOF(datebuf)) {
+      ch = *dc++;
+      *pc++ = (char)ch;
+      if (ch == '\0') {
+        break;
+      } else if (! isdigit (ch)) {
+        pc--;
+      }
+    }
+    datebuf[SIZEOF(datebuf)-1] = '\0';
+    dc = datebuf;
+
+    g_snprintf(level_str, SIZEOF(level_str), "%d", level);
+  }
+
+  host = old_sanitise_filename(host);
+  if (disk != NULL) {
+    disk = old_sanitise_filename(disk);
   }
+
+  conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR));
   /*
    * Note: vstralloc() will stop at the first NULL, which might be
    * "disk" or "dc" (datebuf) rather than the full file name.