Imported Upstream version 2.5.1p3
[debian/amanda] / server-src / amindex.c
index b775c43d2a5b551ad4f943bbcaffcca5cc352f75..6e50fe5a1b369c0fd13e550cc94bbe12500e808d 100644 (file)
@@ -25,7 +25,7 @@
  *                        University of Maryland at College Park
  */
 /*
- * $Id: amindex.c,v 1.15 2006/05/25 01:47:19 johnfranks Exp $
+ * $Id: amindex.c,v 1.15.2.1 2006/11/24 18:05:05 martinea Exp $
  *
  * index control
  */
@@ -95,3 +95,65 @@ getindexfname(
 
   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;
+
+    snprintf(level_str, SIZEOF(level_str), "%d", level);
+  }
+
+  host = old_sanitise_filename(host);
+  if (disk != NULL) {
+    disk = old_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);
+  }
+  /*
+   * 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;
+}