Пример #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;
}
Пример #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;

}
Пример #3
0
/* ---- */
int main(int argc, const char * argv[]) {
	int cread, serial_fd, nfds, fds_ready;
	char readbuf[DEFAULT_BUFFER_SIZE];

	/* set options from commandline */
	setOptions(argc, argv);

	/* initialize the serial port */
	serial_fd = serial_init(settings.device);

	/* check whether there are files to be sent first */
	if (settings.file)
		sendfiles(1, &(settings.file), serial_fd);

	/* initialize bowshell */
	bowshell_init(serial_fd);

	/* define & clear "fd_set"s for select */
	fd_set rd, wr, er; /* read, write, and error file descriptor sets*/
	FD_ZERO(&wr); /* won't be used, so one-time zero */
	FD_ZERO(&er); /* won't be used, so one-time zero */

	nfds = 1 + (serial_fd > STDIN_FILENO ? serial_fd : STDIN_FILENO);

	/* say hi */
	printMOTD();

	/* start receiving from the pipe to the child process and from the
	 * serial device */
	for (;;) {
		/* reset "fd_set"s each loop because select() modifies it */
		FD_ZERO( &rd );
		FD_SET( STDIN_FILENO, &rd );
		FD_SET( serial_fd, &rd ); /* watch the serial port for reading */

		/* select filedescriptors that are ready for reading */
		fds_ready = select( nfds, &rd, &wr, &er, NULL );
		if ( fds_ready == -1 ) { perror("select()"); }

		/* stdin ready */
		if (FD_ISSET(STDIN_FILENO, &rd)) {
			bowshell_notify();
			if (bowshell_eof()) {
				bowshell_cleanup();
				puts("Thank you, come again!");
				return 0;
			}
		}

		/* serial ready */
		if (FD_ISSET(serial_fd, &rd)) {
			cread = read(serial_fd, readbuf, (DEFAULT_BUFFER_SIZE - 1));
			if (cread < 0)
				perror("serial read");
			else {
				if (cread == 0) {
					puts("serial disconnect");
					rl_callback_handler_remove();
					exit(1);
				}
				else {
					readbuf[cread] = '\0'; /* make readbuf suitable for printing */
#ifdef __CYGWIN__
					/* XXX Setting icrnl on the serial line is not supported in
					 * cygwin, so we change those characters here manually. */
					replacechars(readbuf, '\r', '\n');
#endif /* __CYGWIN__ */
					bowshell_print(readbuf);
				}
			}
		}
	}
	return EXIT_SUCCESS;
}