/* Library for ftpd clients.(libftp) Copyright by Oleg Orel All rights reserved. This library is desined for free, non-commercial software creation. It is changeable and can be improved. The author would greatly appreciate any advises, new components and patches of the exist ing programs. Commercial usage is also possible with participation of it's author. */ #include "FtpLibrary.h" #include int FtpRead(FTP *con) { int c; if ( con -> mode == 'I' ) return FtpGetc(con,FTPDATA(con)); if ( con->ch != EOF ) { c=con->ch; con->ch=EOF; return c; } c=FtpGetc(con,FTPDATA(con)); if ( c == Ctrl('M') ) { c = FtpGetc(con,FTPDATA(con)); if ( c == Ctrl('J') ) return '\n'; con->ch = c; return Ctrl('M'); } return c; } int FtpWrite(FTP *ftp,char c) { if ( ftp -> mode == 'I' || c != '\n' ) return FtpPutc(ftp,FTPDATA(ftp),c); FtpPutc(ftp,FTPDATA(ftp),Ctrl('M')); return FtpPutc(ftp,FTPDATA(ftp),Ctrl('J')); } int FtpGetc(FTP *ftp,FILE *fp) { fd_set fds; char c; FD_ZERO(&fds); FD_SET(fileno(fp),&fds); if (select(getdtablesize(), &fds, 0, 0, &(ftp->timeout))<1) return EXIT(ftp,QUIT); if (read(fileno(fp),&c,1)<1) return EOF; if (ftp->hash!=NULL) (*ftp->hash)(ftp,1); return (int)c; } STATUS FtpPutc(FTP *ftp,FILE *fp,char c) { fd_set fds; FD_ZERO(&fds); FD_SET(fileno(fp),&fds); if (select(getdtablesize(), 0, &fds, 0, &(ftp->timeout))<1) return EXIT(ftp,QUIT); if (write(fileno(fp),&c,1)!=1) return EXIT(ftp,QUIT); if (ftp->hash!=NULL) (*ftp->hash)(ftp,1); return 0; } STATUS FtpReadBlock(FTP *ftp, char *buffer, int size) { fd_set fds; register int rsize; FD_ZERO(&fds); FD_SET(fileno(FTPDATA(ftp)),&fds); if (select(getdtablesize(), &fds,0, 0, &(ftp->timeout))<1) return EXIT(ftp,QUIT); if ((rsize=read(fileno(FTPDATA(ftp)),buffer,size))<0) return EXIT(ftp,QUIT); if (ftp->hash!=NULL && rsize!=0) (*ftp->hash)(ftp,rsize); if (ftp->mode == 'A') { char buffer2[size]; register int i,ii; for (i=0,ii=0;itimeout))<1) return EXIT(ftp,QUIT); if (ftp->mode=='A') { register int i,ii; for(i=0,ii=0;ihash!=NULL && wsize!=0 ) (*ftp->hash)(ftp,wsize); return wsize; }