Exemple #1
0
int download(const char *params)
{
	char parbuf[512];
	char bigbuf[10000];
	const char *srcstrh;
	int discon = 0;
	struct FFlag *myf;
	FILE *listh;
	char lastfile[100];
	int keepc = 1;

	bgrun = 0;
	wasbg = 0;

	setprotocol();
	changenodestatus("Downloading");
	TypeFile("download", TYPE_MAKE | TYPE_CONF | TYPE_WARN);

	if (!conference()->conf.CONF_FILEAREAS) {
		DDPut(sd[dlnoareasstr]);
		return 0;
	}
	if ((protocol->PROTOCOL_TYPE == 3 || protocol->PROTOCOL_TYPE == 2) && !conference()->conf.CONF_UPLOADAREA) {
		DDPut(sd[dlnouploadsstr]);
		return 0;
	}
	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		if (cleantemp() == -1) {
			DDPut(sd[tempcleanerrstr]);
			return 0;
		}
		if (!freespace())
			return 0;
		maketmplist();
	}
	srcstrh = params;

	for (;;) {
		if (strtoken(parbuf, &srcstrh, sizeof parbuf) > sizeof parbuf)
			continue;
		if (!*parbuf)
			break;
		flagfile(parbuf, 1);
	}
	for (;;) {
		typedlprompt();
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 200, 0)))
			return 0;
		if (!bigbuf[0]) {
			break;
		} else if (!strcasecmp(bigbuf, "a")) {
			return 0;
		} else {
			srcstrh = bigbuf;
			for (;;) {
				if (strtoken(parbuf, &srcstrh, 
					     sizeof parbuf) > sizeof parbuf)
					continue;
				if (!*parbuf)
					break;
				flagfile(parbuf, 1);
			}
		}
	}
	if (!filestagged)
		return 0;
	listtags();
	if (estimsecs(bytestagged) > timeleft) {
		DDPut(sd[dlnotimestr]);
		return 0;
	}
	for (;;) {
		DDPut(sd[dlproceedstr]);
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 3, 0)))
			return 0;
		if (!bigbuf[0] || bigbuf[0] == 'p' || bigbuf[0] == 'P')
			break;
		else if (bigbuf[0] == 'e' || bigbuf[0] == 'E') {
			taged(0);
		} else if (bigbuf[0] == 'd' || bigbuf[0] == 'D') {
			discon = 1;
			break;
		} else if (bigbuf[0] == 'a' || bigbuf[0] == 'A') {
			return 0;
		}
	}
	snprintf(parbuf, sizeof parbuf, "%s/dszlog.%d", DDTMP, node);

	sprintf(&parbuf[250], "%s/ddfilelist.%d", DDTMP, node);
	unlink(&parbuf[250]);

	if (!(listh = fopen(&parbuf[250], "w")))
		return 0;

	myf = (struct FFlag *) flaggedfiles->lh_Head;
	while (myf->fhead.ln_Succ) {
		char tbu[256];
		snprintf(tbu, sizeof tbu, "%s%s\n", 
			myf->f_path, myf->f_filename);
		fputs(tbu, listh);
		myf = (struct FFlag *) myf->fhead.ln_Succ;
	}
	fclose(listh);
	*lastfile = 0;

	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		if ((!(user.user_toggles & (1L << 15))) && (maincfg.CFG_FLAGS & (1L << 11))) {
			initbgchecker();

		}
	}
	sendfiles(&parbuf[250], lastfile, sizeof lastfile);


	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		upload(2);
	}
	if (*lastfile) {
		myf = (struct FFlag *) flaggedfiles->lh_Head;
		while (myf->fhead.ln_Succ && keepc) {
			struct FFlag *oldf;
			struct DD_DownloadLog ddl;
			char lbuf[100];
			int logfd;

			snprintf(lbuf, sizeof lbuf, 
				"%s/logfiles/downloadlog.dat", origdir);
			logfd = open(lbuf, O_WRONLY | O_CREAT, 0666);
			if (logfd != -1) {
				fsetperm(logfd, 0666);
				memset((char *) &ddl, 0, sizeof(struct DD_DownloadLog));
				ddl.DL_SLOT = user.user_account_id;
				strlcpy(ddl.DL_FILENAME, myf->f_filename, sizeof ddl.DL_FILENAME);
				ddl.DL_FILESIZE = myf->f_size;
				ddl.DL_TIME = time(0);
				ddl.DL_BPSRATE = bpsrate;
				ddl.DL_NODE = node;
				ddl.DL_CONF = (unsigned char) myf->f_conf;
				lseek(logfd, 0, SEEK_END);
				safe_write(logfd, &ddl, sizeof(struct DD_DownloadLog));
				close(logfd);
			}
			if (!(myf->f_flags & FLAG_FREE)) {
				user.user_dlbytes += myf->f_size;
				user.user_dlfiles++;
			}
			if (!strcasecmp(lastfile, myf->f_filename))
				keepc = 0;
			Remove((struct Node *) myf);
			oldf = myf;
			myf = (struct FFlag *) myf->fhead.ln_Succ;
			free(oldf);
		}
	}
	recountfiles();

	unlink(&parbuf[250]);

	if (discon) {
		if (autodisconnect())
			return 2;
	}
	return 1;
}
Exemple #2
0
int sysopdownload(const char *params)
{
	const char *srcstrh;
	char parbuf[1024];
	char bigbuf[4096];
	int discon = 0;
	struct FFlag *myf;
	FILE *listh;
	char lastfile[100];
	int keepc = 1;

	changenodestatus("SysOp download");
	TypeFile("sysopdownload", TYPE_MAKE);

	srcstrh = params;

	for (;;) {
		if (strtoken(parbuf, &srcstrh, sizeof parbuf) > sizeof parbuf)
			continue;
		if (!*parbuf)
			break;
		sflagfile(parbuf);
	}
	for (;;) {
		typedlprompt();
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 200, 0)))
			return 0;
		if (!bigbuf[0]) {
			break;
		} else if (!strcasecmp(bigbuf, "a")) {
			return 0;
		} else {
			srcstrh = bigbuf;
			for (;;) {
				if (strtoken(parbuf, &srcstrh,
					     sizeof parbuf) > sizeof parbuf)
					continue;
				if (!*parbuf)
					break;
				sflagfile(parbuf);
			}
		}
	}
	if (!filestagged)
		return 0;
	listtags();
	if (estimsecs(bytestagged) > timeleft) {
		DDPut(sd[dlnotimestr]);
		return 0;
	}
	for (;;) {
		DDPut(sd[dlproceedstr]);
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 3, 0)))
			return 0;
		if (!bigbuf[0] || bigbuf[0] == 'p' || bigbuf[0] == 'P')
			break;
		else if (bigbuf[0] == 'e' || bigbuf[0] == 'E') {
			taged(0);
		} else if (bigbuf[0] == 'd' || bigbuf[0] == 'D') {
			discon = 1;
			break;
		} else if (bigbuf[0] == 'a' || bigbuf[0] == 'A') {
			return 0;
		}
	}

	if (estimsecs(bytestagged) > timeleft) {
		DDPut(sd[dlnotimestr]);
		return 0;
	}
	snprintf(parbuf, sizeof parbuf - 250, "%s/dszlog.%d", DDTMP, node);

	snprintf(&parbuf[250], sizeof parbuf - 250, "%s/ddfilelist.%d", DDTMP, node);
	unlink(&parbuf[250]);

	if (!(listh = fopen(&parbuf[250], "w")))
		return 0;

	myf = (struct FFlag *) flaggedfiles->lh_Head;
	while (myf->fhead.ln_Succ) {
		char tbu[256];
		snprintf(tbu, sizeof tbu, "%s%s\n", 
			myf->f_path, myf->f_filename);
		fputs(tbu, listh);
		myf = (struct FFlag *) myf->fhead.ln_Succ;
	}
	fclose(listh);
	*lastfile = 0;
	sendfiles(&parbuf[250], lastfile, sizeof lastfile);

	if (*lastfile) {
		myf = (struct FFlag *) flaggedfiles->lh_Head;
		while (myf->fhead.ln_Succ && keepc) {
			struct FFlag *oldf;

			if (!strcasecmp(lastfile, myf->f_filename))
				keepc = 0;
			Remove((struct Node *) myf);
			oldf = myf;
			myf = (struct FFlag *) myf->fhead.ln_Succ;
			free(oldf);
		}
	}
	recountfiles();

	unlink(&parbuf[250]);

	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		upload(2);
	}
	if (discon) {
		if (autodisconnect())
			return 2;
	}
	return 1;

}
Exemple #3
0
static void directkey(void)
{
	char *shell[32] = SHELL;
	char *mail[32] = MAIL;
	char *editor[32] = EDITOR;
	int c = readchar();
	if (PASS && locked) {
		if (c == '\r') {
			pass[passlen] = '\0';
			if (!strcmp(PASS, pass))
				locked = 0;
			passlen = 0;
			return;
		}
		if (isprint(c) && passlen + 1 < sizeof(pass))
			pass[passlen++] = c;
		return;
	}
	if (c == ESC) {
		switch ((c = readchar())) {
		case 'c':
			execterm(shell);
			return;
		case 'm':
			execterm(mail);
			return;
		case 'e':
			execterm(editor);
			return;
		case 'j':
		case 'k':
			showterm(altterm(cterm()));
			return;
		case 'o':
			showtag(ltag);
			return;
		case 'p':
			listtags();
			return;
		case '\t':
			if (nextterm() != cterm())
				showterm(nextterm());
			return;
		case CTRLKEY('q'):
			exitit = 1;
			return;
		case 's':
			term_screenshot();
			return;
		case 'y':
			term_redraw(1);
			return;
		case CTRLKEY('l'):
			locked = 1;
			passlen = 0;
			return;
		case CTRLKEY('o'):
			taglock = 1 - taglock;
			return;
		case ',':
			term_scrl(pad_rows() / 2);
			return;
		case '.':
			term_scrl(-pad_rows() / 2);
			return;
		default:
			if (strchr(tags, c)) {
				showtag(strchr(tags, c) - tags);
				return;
			}
			if (mainterm())
				term_send(ESC);
		}
	}
	if (c != -1 && mainterm())
		term_send(c);
}