Example #1
0
fetchIO *
fetchXGetFile(struct url *u, struct url_stat *us, const char *flags)
{
	char *path;
	fetchIO *f;
	struct url_stat local_us;
	int if_modified_since, fd, *cookie;

	if_modified_since = CHECK_FLAG('i');
	if (if_modified_since && us == NULL)
		us = &local_us;

	if ((path = fetchUnquotePath(u)) == NULL) {
		fetch_syserr();
		return NULL;
	}

	fd = open(path, O_RDONLY);
	free(path);
	if (fd == -1) {
		fetch_syserr();
		return NULL;
	}

	if (us && fetch_stat_file(fd, us) == -1) {
		close(fd);
		fetch_syserr();
		return NULL;
	}

	if (if_modified_since && u->last_modified > 0 &&
	    u->last_modified >= us->mtime) {
		close(fd);
		fetchLastErrCode = FETCH_UNCHANGED;
		snprintf(fetchLastErrString, MAXERRSTRING, "Unchanged");
		return NULL;
	}

	if (u->offset && lseek(fd, u->offset, SEEK_SET) == -1) {
		close(fd);
		fetch_syserr();
		return NULL;
	}

	cookie = malloc(sizeof(int));
	if (cookie == NULL) {
		close(fd);
		fetch_syserr();
		return NULL;
	}

	*cookie = fd;
	f = fetchIO_unopen(cookie, fetchFile_read, fetchFile_write, fetchFile_close);
	if (f == NULL) {
		close(fd);
		free(cookie);
	}
	return f;
}
Example #2
0
fetchIO *
fetchPutFile(struct url *u, const char *flags)
{
	char *path;
	fetchIO *f;
	int fd, *cookie;

	if ((path = fetchUnquotePath(u)) == NULL) {
		fetch_syserr();
		return NULL;
	}

	if (CHECK_FLAG('a'))
		fd = open(path, O_WRONLY | O_APPEND);
	else
		fd = open(path, O_WRONLY);

	free(path);

	if (fd == -1) {
		fetch_syserr();
		return NULL;
	}

	if (u->offset && lseek(fd, u->offset, SEEK_SET) == -1) {
		close(fd);
		fetch_syserr();
		return NULL;
	}

	cookie = malloc(sizeof(int));
	if (cookie == NULL) {
		close(fd);
		fetch_syserr();
		return NULL;
	}

	*cookie = fd;
	f = fetchIO_unopen(cookie, fetchFile_read, fetchFile_write, fetchFile_close);
	if (f == NULL) {
		close(fd);
		free(cookie);
	}
	return f;
}
Example #3
0
static fetchIO *
ftp_setup(conn_t *cconn, conn_t *dconn, int mode)
{
	struct ftpio *io;
	fetchIO *f;

	if (cconn == NULL || dconn == NULL)
		return (NULL);
	if ((io = malloc(sizeof(*io))) == NULL)
		return (NULL);
	io->cconn = cconn;
	io->dconn = dconn;
	io->dir = mode;
	io->eof = io->err = 0;
	f = fetchIO_unopen(io, ftp_readfn, ftp_writefn, ftp_closefn);
	if (f == NULL)
		free(io);
	return (f);
}