X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famindex.c;h=c87c22b9189ce1a057add0d250a74e6622e8deb9;hb=HEAD;hp=6e50fe5a1b369c0fd13e550cc94bbe12500e808d;hpb=310f09c0f55a2fb6f3f3746d6ded20099792b773;p=debian%2Famanda diff --git a/server-src/amindex.c b/server-src/amindex.c index 6e50fe5..c87c22b 100644 --- a/server-src/amindex.c +++ b/server-src/amindex.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -25,7 +26,7 @@ * University of Maryland at College Park */ /* - * $Id: amindex.c,v 1.15.2.1 2006/11/24 18:05:05 martinea Exp $ + * $Id: amindex.c,v 1.15 2006/05/25 01:47:19 johnfranks Exp $ * * index control */ @@ -64,7 +65,7 @@ getindexfname( 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); @@ -72,12 +73,7 @@ getindexfname( 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: vstralloc() will stop at the first NULL, which might be * "disk" or "dc" (datebuf) rather than the full file name. @@ -96,6 +92,63 @@ getindexfname( 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--; + } + } + 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: 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, @@ -126,7 +179,7 @@ getoldindexfname( 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 = old_sanitise_filename(host); @@ -134,12 +187,7 @@ getoldindexfname( 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); - } + 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.