int
MOD_on_headers_done(config_t *config, header_info_t *header) 
{
    char *full_path;
    int err;
    int full_path_len;
    full_path_len = 0;
    err = 0;
    if (!config->base_path) {
        fprintf(stderr, "mod_file - no base_path\n");
        return 1;
    }
    if (!header->base_url) {
        fprintf(stderr, "mod_file - no base_url\n");
        return 1;
    }

    full_path_len += strlen(config->base_path);
    full_path_len += strlen(header->base_url);
    if (full_path_len > 0) {
        full_path = malloc(full_path_len + 1);
        if (!full_path) {
            fprintf(stderr, "mod_file - no memory for full_path\n");
            return 1;
        }
        strcpy(full_path, config->base_path);
        strcat(full_path, header->base_url);
        send_file_to_socket(full_path, header->fd);
        free(full_path);
    }
    return err;
}
Пример #2
0
int check_updates(const char *path, const struct stat *info, int type)
{	
	if(strcmp(path, ".") == 0 
		|| strcmp(path, "..") == 0 
		|| strcmp(path, backup_main_path) == 0)
			return 0;	

	if(strstr(path, OLD_FILE) != NULL)
		return 0;

	/* Check and send file if it was modified after last update */
	if(type == FTW_F && difftime(info -> st_mtime, current_time) > FILE_DIFF) {		
		if(send_file_to_socket(current_socket, path, backup_main_path, info) < 0) {
			error("Error sending file!");
		}
	} else if(type == FTW_D && difftime(info -> st_mtime, current_time) > FILE_DIFF) {
		if(send_dir_to_socket(current_socket, path, backup_main_path, info) < 0) {
			error("Error sending file!");
		}
	}

	return 0;	
}