コード例 #1
0
ファイル: dcc-files.c プロジェクト: svn2github/irssi
static void dcc_resume_rec(DCC_REC *dcc)
{
	char *str;

	g_return_if_fail(dcc != NULL);

	dcc->get_type = DCC_GET_RESUME;
	dcc->file = dcc_get_download_path(dcc->arg);

	dcc->fhandle = open(dcc->file, O_WRONLY, dcc_file_create_mode);
	if (dcc->fhandle == -1) {
		signal_emit("dcc error file not found", 2, dcc, dcc->file);
		dcc_destroy(dcc);
		return;
	}

	dcc->transfd = lseek(dcc->fhandle, 0, SEEK_END);
	if (dcc->transfd < 0) dcc->transfd = 0;
	dcc->skipped = dcc->transfd;

	str = g_strdup_printf("DCC RESUME %s %d %lu",
			      dcc->arg, dcc->port, dcc->transfd);
	dcc_ctcp_message(dcc->nick, dcc->server, dcc->chat, FALSE, str);
	g_free(str);
}
コード例 #2
0
ファイル: dcc-resume.c プロジェクト: svn2github/irssi
/* Resume a DCC GET */
static void dcc_send_resume(GET_DCC_REC *dcc)
{
	char *str;

	g_return_if_fail(dcc != NULL);

	dcc->file = dcc_get_download_path(dcc->arg);
	dcc->fhandle = open(dcc->file, O_WRONLY);
	if (dcc->fhandle == -1) {
		signal_emit("dcc error file not found", 2, dcc, dcc->file);
		return;
	}

	dcc->get_type = DCC_GET_RESUME;

	dcc->transfd = lseek(dcc->fhandle, 0, SEEK_END);
	if (dcc->transfd < 0) dcc->transfd = 0;
	dcc->skipped = dcc->transfd;

	if (dcc->skipped == dcc->size) {
		/* already received whole file */
		dcc->starttime = time(NULL);
		dcc_reject(DCC(dcc), NULL);
	} else {
		str = g_strdup_printf(dcc->file_quoted ?
				      "DCC RESUME \"%s\" %d %lu" :
				      "DCC RESUME %s %d %lu",
				      dcc->arg, dcc->port, dcc->transfd);
		dcc_ctcp_message(dcc->server, dcc->nick,
				 dcc->chat, FALSE, str);
		g_free(str);
	}
}
コード例 #3
0
ファイル: dcc-resume.c プロジェクト: svn2github/irssi
/* Resume a DCC GET */
static void dcc_send_resume(GET_DCC_REC *dcc)
{
        off_t pos;
	char *str;

	g_return_if_fail(dcc != NULL);

	dcc->file = dcc_get_download_path(dcc->arg);
	dcc->fhandle = open(dcc->file, O_WRONLY);
	if (dcc->fhandle == -1) {
		signal_emit("dcc error file open", 3, dcc->nick, dcc->file,
			    GINT_TO_POINTER(errno));
		return;
	}

	dcc->get_type = DCC_GET_RESUME;

	pos = lseek(dcc->fhandle, 0, SEEK_END);
	dcc->transfd = pos == (off_t)-1 ? 0 : (unsigned long) pos;
	dcc->skipped = dcc->transfd;

	if (dcc->skipped == dcc->size) {
		/* already received whole file */
		dcc->starttime = time(NULL);
		dcc_reject(DCC(dcc), NULL);
	} else {
		str = g_strdup_printf(dcc->file_quoted ?
				      "DCC RESUME \"%s\" %d %lu" :
				      "DCC RESUME %s %d %lu",
				      dcc->arg, dcc->port, dcc->transfd);
		dcc_ctcp_message(dcc->server, dcc->nick,
				 dcc->chat, FALSE, str);
		g_free(str);
	}
}
コード例 #4
0
ファイル: dcc-autoget.c プロジェクト: irssi/irssi
static void sig_dcc_request(GET_DCC_REC *dcc, const char *nickaddr)
{
        struct stat statbuf;
	const char *masks;
        char *str, *file, *esc_arg;
        int max_size;

        if (!IS_DCC_GET(dcc)) return;

	/* check if we want to autoget file offer */
	if (!settings_get_bool("dcc_autoget"))
		return;

	/* check for lowports */
	if (dcc->port < 1024 && !settings_get_bool("dcc_autoaccept_lowports"))
                return;

	/* check that autoget masks match */
	masks = settings_get_str("dcc_autoget_masks");
	if (*masks != '\0' &&
	    !masks_match(SERVER(dcc->server), masks, dcc->nick, nickaddr))
		return;

	/* Unless specifically said in dcc_autoget_masks, don't do autogets
	   sent to channels. */
	if (*masks == '\0' && dcc->target != NULL && server_ischannel(SERVER(dcc->server), dcc->target))
		return;

	/* don't autoget files beginning with a dot, if download dir is
	   our home dir (stupid kludge for stupid people) */
	if (*dcc->arg == '.' &&
	    g_strcmp0(settings_get_str("dcc_download_path"), "~") == 0)
		return;

	/* check file size limit, NOTE: it's still possible to send a
	   bogus file size and then just send what ever sized file.. */
        max_size = settings_get_size("dcc_autoget_max_size");
	if (max_size > 0 && (uoff_t)max_size < dcc->size)
                return;

	/* ok. but do we want/need to resume? */
	file = dcc_get_download_path(dcc->arg);
	esc_arg = escape_string(dcc->arg);
	str = g_strdup_printf(settings_get_bool("dcc_autoresume") &&
			      stat(file, &statbuf) == 0 ?
			      "RESUME %s \"%s\"" : "GET %s \"%s\"",
			      dcc->nick, esc_arg);
	signal_emit("command dcc", 2, str, dcc->server);
	g_free(esc_arg);
        g_free(file);
	g_free(str);
}
コード例 #5
0
ファイル: dcc-files.c プロジェクト: svn2github/irssi
/* callback: net_connect() finished for DCC GET */
static void sig_dccget_connected(DCC_REC *dcc)
{
	struct stat statbuf;
	char *fname;

	g_return_if_fail(dcc != NULL);

	if (net_geterror(dcc->handle) != 0) {
		/* error connecting */
		signal_emit("dcc error connect", 1, dcc);
		dcc_destroy(dcc);
		return;
	}

	g_source_remove(dcc->tagconn);

	g_free_not_null(dcc->file);
	dcc->file = dcc_get_download_path(dcc->arg);

	/* if some plugin wants to change the file name/path here.. */
	signal_emit("dcc get receive", 1, dcc);

	if (stat(dcc->file, &statbuf) == 0 && dcc->get_type == DCC_GET_RENAME) {
		/* file exists, rename.. */
		fname = get_rename_file(dcc->file);
		g_free(dcc->file);
		dcc->file = fname;
	}

	if (dcc->get_type != DCC_GET_RESUME) {
		dcc->fhandle = open(dcc->file, O_WRONLY | O_TRUNC | O_CREAT, dcc_file_create_mode);
		if (dcc->fhandle == -1) {
			signal_emit("dcc error file create", 2, dcc, dcc->file);
			dcc_destroy(dcc);
			return;
		}
	}

	dcc->databufsize = settings_get_int("dcc_block_size");
        if (dcc->databufsize <= 0) dcc->databufsize = 2048;
	dcc->databuf = g_malloc(dcc->databufsize);

	dcc->starttime = time(NULL);
	dcc->tagread = g_input_add(dcc->handle, G_INPUT_READ,
				   (GInputFunction) sig_dccget_receive, dcc);
	signal_emit("dcc connected", 1, dcc);
}
コード例 #6
0
ファイル: dcc-get.c プロジェクト: Liaf/irssi
/* callback: net_connect() finished for DCC GET */
void sig_dccget_connected(GET_DCC_REC *dcc)
{
	struct stat statbuf;
	char *fname, *tempfname, *str;
        int ret, ret_errno, temphandle, old_umask;

	if (!dcc->from_dccserver) {
		if (net_geterror(dcc->handle) != 0) {
			/* error connecting */
			signal_emit("dcc error connect", 1, dcc);
			dcc_destroy(DCC(dcc));
			return;
		}

		g_source_remove(dcc->tagconn);
		dcc->tagconn = -1;
	}

	g_free_not_null(dcc->file);
	dcc->file = dcc_get_download_path(dcc->arg);

	/* if some plugin wants to change the file name/path here.. */
	signal_emit("dcc get receive", 1, dcc);

	if (stat(dcc->file, &statbuf) == 0 &&
	    dcc->get_type == DCC_GET_RENAME) {
		/* file exists, rename.. */
		fname = dcc_get_rename_file(dcc->file);
		g_free(dcc->file);
		dcc->file = fname;
	}

	if (dcc->get_type != DCC_GET_RESUME) {
		int dcc_file_create_mode = octal2dec(settings_get_int("dcc_file_create_mode"));

		/* we want to overwrite the file, remove it here.
		   if it gets created after this, we'll fail. */
		unlink(dcc->file);

		/* just to make sure we won't run into race conditions
		   if download_path is in some global temp directory */
		tempfname = g_strconcat(dcc->file, ".XXXXXX", NULL);

                old_umask = umask(0077);
		temphandle = mkstemp(tempfname);
		umask(old_umask);

		if (temphandle == -1)
			ret = -1;
		else
			ret = fchmod(temphandle, dcc_file_create_mode);

		close(temphandle);

		if (ret != -1) {
			ret = link(tempfname, dcc->file);

			if (ret == -1 &&
			    /* Linux */
			    (errno == EPERM ||
			     /* FUSE */
			     errno == ENOSYS ||
			     /* BSD */
			     errno == EOPNOTSUPP)) {
				/* hard links aren't supported - some people
				   want to download stuff to FAT/NTFS/etc
				   partitions, so fallback to rename() */
				ret = rename(tempfname, dcc->file);
			}
		}

		/* if ret = 0, we're the file owner now */
		dcc->fhandle = ret == -1 ? -1 :
			open(dcc->file, O_WRONLY | O_TRUNC);

		/* close/remove the temp file */
		ret_errno = errno;
		unlink(tempfname);
		g_free(tempfname);

		if (dcc->fhandle == -1) {
			signal_emit("dcc error file create", 3,
				    dcc, dcc->file, g_strerror(ret_errno));
			dcc_destroy(DCC(dcc));
			return;
		}
	}

	dcc->starttime = time(NULL);
	if (dcc->size == 0) {
		dcc_close(DCC(dcc));
		return;
	}
	dcc->tagread = g_input_add(dcc->handle, G_INPUT_READ,
				   (GInputFunction) sig_dccget_receive, dcc);
	signal_emit("dcc connected", 1, dcc);

	if (dcc->from_dccserver) {
		str = g_strdup_printf("121 %s %d\n",
				      dcc->server ? dcc->server->nick : "??", 0);
		net_transmit(dcc->handle, str, strlen(str));
	}
}