⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 find.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 2 页
字号:
static intparse_taper_datestamp_log(    char *logline,    char **datestamp,    char **label){    char *s;    int ch;    s = logline;    ch = *s++;    skip_whitespace(s, ch);    if(ch == '\0') {	return 0;    }    if(strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {	return 0;    }    skip_whitespace(s, ch);    if(ch == '\0') {	return 0;    }    *datestamp = s - 1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    skip_whitespace(s, ch);    if(ch == '\0') {	return 0;    }    if(strncmp_const_skip(s - 1, "label", s, ch) != 0) {	return 0;    }    skip_whitespace(s, ch);    if(ch == '\0') {	return 0;    }    *label = s - 1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    return 1;}/* Returns TRUE if the given logfile mentions the given tape. */static gboolean logfile_has_tape(char * label, char * datestamp,                                 char * logfile) {    FILE * logf;    char * ck_datestamp, *ck_label;    if((logf = fopen(logfile, "r")) == NULL) {	error(_("could not open logfile %s: %s"), logfile, strerror(errno));	/*NOTREACHED*/    }    while(get_logline(logf)) {	if(curlog == L_START && curprog == P_TAPER) {	    if(parse_taper_datestamp_log(curstr,					 &ck_datestamp, &ck_label) == 0) {		g_printf(_("strange log line \"start taper %s\" curstr='%s'\n"),                         logfile, curstr);	    } else if(strcmp(ck_datestamp, datestamp) == 0		      && strcmp(ck_label, label) == 0) {                afclose(logf);                return TRUE;	    }	}    }    afclose(logf);    return FALSE;}/* Like (strcmp(label1, label2) == 0), except that NULL values force TRUE. */static gboolean volume_matches(const char * label1, const char * label2) {    return (label1 == NULL || label2 == NULL || strcmp(label1, label2) == 0);}/* WARNING: Function accesses globals find_diskqp, curlog, curlog, curstr, * dynamic_disklist */gbooleansearch_logfile(    find_result_t **output_find,    const char *label,    const char *passed_datestamp,    const char *logfile,    disklist_t * dynamic_disklist){    FILE *logf;    char *host, *host_undo;    char *disk, *qdisk, *disk_undo;    char *date, *date_undo;    char *partnum=NULL, *partnum_undo;    char *number;    int fileno;    char *current_label = NULL;    char *rest;    char *ck_label=NULL;    int level = 0;     off_t filenum;    char *ck_datestamp, *datestamp;    char *s;    int ch;    disk_t *dp;    find_result_t *part_find = NULL;  /* List for all part of a DLE */    find_result_t *a_part_find;    gboolean right_label = FALSE;    gboolean found_something = FALSE;    g_return_val_if_fail(output_find != NULL, 0);    g_return_val_if_fail(logfile != NULL, 0);    datestamp = g_strdup(passed_datestamp);    if((logf = fopen(logfile, "r")) == NULL) {	error(_("could not open logfile %s: %s"), logfile, strerror(errno));	/*NOTREACHED*/    }    filenum = (off_t)0;    while(get_logline(logf)) {	if (curlog == L_START && curprog == P_TAPER) {	    if(parse_taper_datestamp_log(curstr, &ck_datestamp,                                         &ck_label) == 0) {		g_printf(_("strange log line in %s \"start taper %s\"\n"),                         logfile, curstr);                continue;	    }            if (datestamp != NULL) {                if (strcmp(datestamp, ck_datestamp) != 0) {                    g_printf(_("Log file %s stamped %s, expecting %s!\n"),                             logfile, ck_datestamp, datestamp);                    break;                }            }                        right_label = volume_matches(label, ck_label);	    if (label && datestamp && right_label) {		found_something = TRUE;	    }            amfree(current_label);            current_label = g_strdup(ck_label);            if (datestamp == NULL) {                datestamp = g_strdup(ck_datestamp);            }	}        if (!right_label) {	    continue;	} 	if ((curlog == L_SUCCESS ||	     curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTPARTIAL) &&	    curprog == P_TAPER) {	    filenum++;	}	partnum = "--";	if (curlog == L_SUCCESS || curlog == L_CHUNKSUCCESS ||	    curlog == L_DONE    || curlog == L_FAIL ||	    curlog == L_CHUNK   || curlog == L_PART || curlog == L_PARTIAL ||	    curlog == L_PARTPARTIAL ) {	    s = curstr;	    ch = *s++;	    skip_whitespace(s, ch);	    if(ch == '\0') {		g_printf(_("strange log line in %s \"%s\"\n"),		    logfile, curstr);		continue;	    }	    if (curlog == L_PART || curlog == L_PARTPARTIAL) {		char * part_label = s - 1;		skip_non_whitespace(s, ch);		s[-1] = '\0';		if (strcmp(current_label, part_label) != 0) {		    g_printf("PART label %s doesn't match START label %s\n",                             part_label, current_label);		    continue;		}		skip_whitespace(s, ch);		if(ch == '\0') {		    g_printf("strange log line in %s \"%s\"\n",			   logfile, curstr);		    continue;		}		number = s - 1;		skip_non_whitespace(s, ch);		s[-1] = '\0';		fileno = atoi(number);		filenum = fileno;		skip_whitespace(s, ch);		if(ch == '\0') {		    g_printf("strange log line in %s \"%s\"\n",			   logfile, curstr);		    continue;		}	    }	    host = s - 1;	    skip_non_whitespace(s, ch);	    host_undo = s - 1;	    *host_undo = '\0';	    skip_whitespace(s, ch);	    if(ch == '\0') {		g_printf(_("strange log line in %s \"%s\"\n"),		    logfile, curstr);		continue;	    }	    qdisk = s - 1;	    skip_quoted_string(s, ch);	    disk_undo = s - 1;	    *disk_undo = '\0';	    disk = unquote_string(qdisk);	    skip_whitespace(s, ch);	    if(ch == '\0') {		g_printf(_("strange log line in %s \"%s\"\n"),                         logfile, curstr);		continue;	    }	    date = s - 1;	    skip_non_whitespace(s, ch);	    date_undo = s - 1;	    *date_undo = '\0';	    if(strlen(date) < 3) { /* old log didn't have datestamp */		level = atoi(date);		date = stralloc(datestamp);	    } else {		if (curlog == L_CHUNK || curlog == L_PART ||		    curlog == L_PARTPARTIAL || curlog == L_DONE){		    skip_whitespace(s, ch);		    partnum = s - 1;		    skip_non_whitespace(s, ch);		    partnum_undo = s - 1;		    *partnum_undo = '\0';		}		skip_whitespace(s, ch);		if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {		    g_printf(_("strange log line in %s \"%s\"\n"),		    logfile, curstr);		    continue;		}		skip_integer(s, ch);	    }	    skip_whitespace(s, ch);	    if(ch == '\0') {		g_printf(_("strange log line in %s \"%s\"\n"),		    logfile, curstr);		continue;	    }	    rest = s - 1;	    if((s = strchr(s, '\n')) != NULL) {		*s = '\0';	    }	    dp = lookup_disk(host,disk);	    if ( dp == NULL ) {		if (dynamic_disklist == NULL) {		    continue;		}		dp = add_disk(dynamic_disklist, host, disk);		enqueue_disk(dynamic_disklist, dp);	    }            if (find_match(host, disk)) {		if(curprog == P_TAPER) {		    find_result_t *new_output_find =			(find_result_t *)alloc(SIZEOF(find_result_t));		    new_output_find->timestamp = stralloc(date);		    new_output_find->hostname=stralloc(host);		    new_output_find->diskname=stralloc(disk);		    new_output_find->level=level;		    new_output_find->partnum = stralloc(partnum);                    new_output_find->label=stralloc(current_label);		    new_output_find->status=NULL;		    new_output_find->filenum=filenum;		    new_output_find->next=NULL;		    if (curlog == L_SUCCESS) {			new_output_find->status = stralloc("OK");			new_output_find->next = *output_find;			*output_find = new_output_find;                        found_something = TRUE;		    } else if (curlog == L_CHUNKSUCCESS || curlog == L_DONE ||			       curlog == L_PARTIAL      || curlog == L_FAIL) {			/* result line */			if (curlog == L_PARTIAL || curlog == L_FAIL) {			    /* change status of each part */			    for (a_part_find = part_find; a_part_find;				 a_part_find = a_part_find->next) {				if (curlog == L_PARTIAL)				    a_part_find->status = stralloc("PARTIAL");				else				    a_part_find->status = stralloc(rest);			    }			}			if (part_find) { /* find last element */			    for (a_part_find = part_find;				 a_part_find->next != NULL;				 a_part_find=a_part_find->next) {			    }			    /* merge part_find to *output_find */			    a_part_find->next = *output_find;			    *output_find = part_find;			    part_find = NULL;                            found_something = TRUE;			}			free_find_result(&new_output_find);		    } else { /* part line */			if (curlog == L_PART || curlog == L_CHUNK)			    new_output_find->status=stralloc("OK");			else /* PARTPARTIAL */			    new_output_find->status=stralloc("PARTIAL");			/* Add to part_find list */			new_output_find->next = part_find;			part_find = new_output_find;			found_something = TRUE;		    }		}		else if(curlog == L_FAIL) {	/* print other failures too */		    find_result_t *new_output_find =			(find_result_t *)alloc(SIZEOF(find_result_t));		    new_output_find->next=*output_find;		    new_output_find->timestamp = stralloc(date);		    new_output_find->hostname=stralloc(host);		    new_output_find->diskname=stralloc(disk);		    new_output_find->level=level;		    new_output_find->label=NULL;		    new_output_find->partnum=stralloc(partnum);		    new_output_find->filenum=0;		    new_output_find->status=vstralloc(			 "FAILED (",			 program_str[(int)curprog],			 ") ",			 rest,			 NULL);		    *output_find=new_output_find;                    found_something = TRUE;		}	    }	    amfree(disk);	}    }    if (part_find != NULL) {	if (label) {	    /* parse log file until PARTIAL/DONE/SUCCESS/FAIL from taper */	    while(get_logline(logf)) {		if (curprog == P_TAPER &&		    (curlog == L_DONE || curlog == L_SUCCESS ||		     curlog == L_PARTIAL || curlog == L_FAIL)) {		    break;		}	    }	}	for (a_part_find = part_find; a_part_find;	     a_part_find = a_part_find->next) {	    if (curlog == L_PARTIAL)		a_part_find->status = stralloc("PARTIAL");	    else if (curlog == L_FAIL)		a_part_find->status = stralloc("FAIL");	}	for (a_part_find = part_find;	     a_part_find->next != NULL;	     a_part_find=a_part_find->next) {	}	/* merge part_find to *output_find */	a_part_find->next = *output_find;	*output_find = part_find;	part_find = NULL;    }    afclose(logf);    amfree(datestamp);    amfree(current_label);    return found_something;}/* * Return the set of dumps that match *all* of the given patterns (we consider * an empty pattern to match .*, though).  If 'ok' is true, will only match * dumps with SUCCESS status. * * Returns a newly allocated list of results, where all strings are also newly * allocated.  Apparently some part of Amanda leaks under this condition. */find_result_t *dumps_match(    find_result_t *output_find,    char *hostname,    char *diskname,    char *datestamp,    char *level,    int ok){    find_result_t *cur_result;    find_result_t *matches = NULL;    for(cur_result=output_find;	cur_result;	cur_result=cur_result->next) {	char level_str[NUM_STR_SIZE];	g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);	if((!hostname || *hostname == '\0' || match_host(hostname, cur_result->hostname)) &&	   (!diskname || *diskname == '\0' || match_disk(diskname, cur_result->diskname)) &&	   (!datestamp || *datestamp== '\0' || match_datestamp(datestamp, cur_result->timestamp)) &&	   (!level || *level== '\0' || match_level(level, level_str)) &&	   (!ok || !strcmp(cur_result->status, "OK"))){	    find_result_t *curmatch = alloc(SIZEOF(find_result_t));	    memcpy(curmatch, cur_result, SIZEOF(find_result_t));	    curmatch->timestamp = stralloc(cur_result->timestamp);	    curmatch->hostname = stralloc(cur_result->hostname);	    curmatch->diskname = stralloc(cur_result->diskname);	    curmatch->level = cur_result->level;	    curmatch->label = stralloc(cur_result->label);	    curmatch->filenum = cur_result->filenum;	    curmatch->status = stralloc(cur_result->status);	    curmatch->partnum = stralloc(cur_result->partnum);	    curmatch->next = matches;	    matches = curmatch;	}    }    return(matches);}/* * Return the set of dumps that match one or more of the given dumpspecs, * If 'ok' is true, only dumps with a SUCCESS status will be matched. *  * Returns a newly allocated list of results, where all strings are also newly * allocated.  Apparently some part of Amanda leaks under this condition. */find_result_t *dumps_match_dumpspecs(    find_result_t *output_find,    GSList        *dumpspecs,    int ok){    find_result_t *cur_result;    find_result_t *matches = NULL;    GSList        *dumpspec;    dumpspec_t    *ds;    for(cur_result=output_find;	cur_result;	cur_result=cur_result->next) {	char level_str[NUM_STR_SIZE];	g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);	for (dumpspec = dumpspecs; dumpspec; dumpspec = dumpspec->next) {	    ds = (dumpspec_t *)dumpspec->data;	    if((!ds->host || *ds->host == '\0' || match_host(ds->host, cur_result->hostname)) &&	       (!ds->disk || *ds->disk == '\0' || match_disk(ds->disk, cur_result->diskname)) &&	       (!ds->datestamp || *ds->datestamp== '\0' || match_datestamp(ds->datestamp, cur_result->timestamp)) &&	       (!ds->level || *ds->level== '\0' || match_level(ds->level, level_str)) &&	       (!ok || !strcmp(cur_result->status, "OK"))){		find_result_t *curmatch = alloc(SIZEOF(find_result_t));		memcpy(curmatch, cur_result, SIZEOF(find_result_t));		curmatch->timestamp = stralloc(cur_result->timestamp);		curmatch->hostname = stralloc(cur_result->hostname);		curmatch->diskname = stralloc(cur_result->diskname);		curmatch->level = cur_result->level;		curmatch->label = stralloc(cur_result->label);		curmatch->filenum = cur_result->filenum;		curmatch->status = stralloc(cur_result->status);		curmatch->partnum = stralloc(cur_result->partnum);		curmatch->next = matches;		matches = curmatch;		break;	    }	}    }    return(matches);}find_result_t *dump_exist(    find_result_t *output_find,    char *hostname,    char *diskname,    char *datestamp,    int level){    find_result_t *output_find_result;    for(output_find_result=output_find;	output_find_result;	output_find_result=output_find_result->next) {	if( !strcmp(output_find_result->hostname, hostname) &&	    !strcmp(output_find_result->diskname, diskname) &&	    !strcmp(output_find_result->timestamp, datestamp) &&	    output_find_result->level == level) {	    return output_find_result;	}    }    return(NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -