Beispiel #1
0
void protocol_process_image_data(struct vfs_device_t *dev, int size, int first_block)
{
	int pos=0;
	static int plen = 0;

	if (dev->fingerprint_length + size >= MAX_FINGERPRINT_SIZE)
		return;

	if (first_block)
	{
		plen = 0;
		while (!(dev->bulkin_data_buffer[pos]==0x01 && dev->bulkin_data_buffer[pos+1]==0xfe)) pos++;
		memcpy(dev->fingerprint_buffer, dev->bulkin_data_buffer + pos, VFS_SEGMENT_LENGTH);
		pos += VFS_SEGMENT_LENGTH;
		dev->fingerprint_length += VFS_SEGMENT_LENGTH;
	}
	else
	{
		if (plen)
		{
			memcpy(dev->fingerprint_buffer + dev->fingerprint_length, dev->bulkin_data_buffer, VFS_SEGMENT_LENGTH - plen);
			dev->fingerprint_length += VFS_SEGMENT_LENGTH - plen;
			pos += VFS_SEGMENT_LENGTH - plen;
			if (!diff_lines(dev->fingerprint_buffer+dev->fingerprint_length-VFS_SEGMENT_LENGTH*2, dev->fingerprint_buffer+dev->fingerprint_length-VFS_SEGMENT_LENGTH))
				dev->fingerprint_length -= VFS_SEGMENT_LENGTH;
		}

	}

	while (size - pos >= VFS_SEGMENT_LENGTH)
	{
		if (diff_lines(dev->fingerprint_buffer+dev->fingerprint_length-VFS_SEGMENT_LENGTH, dev->bulkin_data_buffer+pos))
		{
			memcpy(dev->fingerprint_buffer + dev->fingerprint_length, dev->bulkin_data_buffer+pos, VFS_SEGMENT_LENGTH);
			dev->fingerprint_length += VFS_SEGMENT_LENGTH;
		}
		pos += VFS_SEGMENT_LENGTH;
	}
	plen = size-pos;
	memcpy(dev->fingerprint_buffer + dev->fingerprint_length, dev->bulkin_data_buffer+pos, plen);
	dev->fingerprint_length += plen;
}
Beispiel #2
0
static void compare_diff(char *catalogpath1, unsigned int rev1,
                        char *catalogpath2, unsigned int rev2, const char *file,
                        FILE * out)
{
    char **file1;
    char **file2;
    unsigned int len1;
    unsigned int len2;
    struct rule *rules;
    int status;

    /* Load both files */
    len1 = commit_file(catalogpath1, rev1, file, &file1);
    len2 = commit_file(catalogpath2, rev2, file, &file2);

    /* And diff them */
    status = diff_lines(&rules, file1, len1, file2, len2);

    /* DIFF_SAME is acceptable if both files are empty (one might not exist) */
    assert(status != DIFF_ERROR);
    assert(status != DIFF_SAME || (len1 == 0 && len2 == 0));

    fprintf(out, "File: %s\n", file);

    if (status != DIFF_SAME) {
        diff_print(out, rules, file1, file2);
        diff_free_rules(rules);
    } else if (commit_file_is_involved(catalogpath2, rev2, file)) {
        fprintf(out, "The file is empty\n");
    } else {
        fprintf(out, "The empty file was removed\n");
    }
    fprintf(out, "\n");

    freereadfile(file1);
    freereadfile(file2);
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    unsigned int alength, blength;
    char **alines, **blines;
    struct rule *rules;
    int status;

    if (argc != 3 && argc >= 1) {
        fprintf(stderr, "Usage: %s <original> <modified>\n", argv[0]);
        return 1;
    }

    FILE *filea = fopen(argv[1], "r");
    FILE *fileb = fopen(argv[2], "r");

    if (filea == NULL || fileb == NULL) {
        fprintf(stderr, "Error opening files.\n");

        /* Close any possibly open file */
        if (filea != NULL)
            fclose(filea);
        if (fileb != NULL)
            fclose(fileb);

        return 2;
    }

    /* Read the files to memory */
    alines = readfile(filea, &alength);
    blines = readfile(fileb, &blength);

    if (alines == NULL || blines == NULL) {
        fprintf(stderr, "Error reading files.\n");

        /* Free any possibly used resources */
        if (alines != NULL)
            freereadfile(alines);
        if (blines != NULL)
            freereadfile(blines);

        fclose(filea);
        fclose(fileb);

        return 3;
    }

    status = diff_lines(&rules, alines, alength, blines, blength);

    if (status == DIFF_ERROR) {
        fprintf(stderr, "Error computing differences.\n");
        return 4;
    }

    /* Don't print rules if the files are identical */
    if (status != DIFF_SAME) {
        diff_print(stdout, rules, alines, blines);
        diff_free_rules(rules);
    }

    /* Free and close everything */
    freereadfile(alines);
    freereadfile(blines);
    fclose(filea);
    fclose(fileb);

    return 0;
}