diff options
author | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
commit | ab124e78b0271ddb904b761b31e5c9a0cf24e070 (patch) | |
tree | 0cf1447720c45721ed3d214a4eaaa6834bda155d /lib/libftp | |
parent | 15748830d0fcd29294a1969a1012655e74908c1e (diff) | |
download | FreeBSD-src-ab124e78b0271ddb904b761b31e5c9a0cf24e070.zip FreeBSD-src-ab124e78b0271ddb904b761b31e5c9a0cf24e070.tar.gz |
recording cvs-1.6 file death
Diffstat (limited to 'lib/libftp')
41 files changed, 0 insertions, 6924 deletions
diff --git a/lib/libftp/FtpAbort.c b/lib/libftp/FtpAbort.c deleted file mode 100644 index 80943e5..0000000 --- a/lib/libftp/FtpAbort.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> - -int -FtpAbort(FTP *ftp) -{ - fd_set fds; - char msgc=IAC; - String msg; - - FD_ZERO(&fds); - FD_SET(fileno(FTPCMD(ftp)),&fds); - - FtpPutc(ftp, FTPCMD(ftp), IAC); - FtpPutc(ftp, FTPCMD(ftp), IP); - - if ( send ( fileno(FTPCMD(ftp)), &msgc , 1 ,MSG_OOB) != 1 ) - return EXIT(ftp,QUIT); - - FtpPutc(ftp, FTPCMD(ftp), DM); - - FtpSendMessage(ftp,"ABOR"); - - while (select ( getdtablesize(), &fds, 0,0, &(ftp->timeout) )>0) - { - FtpGetMessage(ftp,msg); - if (FtpGood(FtpNumber(msg),225,226,EOF)) break; - } - return 0; -} - - - diff --git a/lib/libftp/FtpArchie.c b/lib/libftp/FtpArchie.c deleted file mode 100644 index 22a05e1..0000000 --- a/lib/libftp/FtpArchie.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -#define C2I(n) ((int)((n)-'0')) - -int FtpArchie ( char *what, ARCHIE *result, int len) -{ - FILE *archie; - String cmd,tmp; - int i; - - bzero(result,sizeof(result[0])*len); - - sprintf(cmd,"archie -l -m %d %s",len,what); - - if ((archie = popen(cmd,"r"))==NULL) - return 0; - - for(i=0;i<len;i++) - { - char *p, *pp; - - if (fgets(tmp,sizeof (tmp), archie)==NULL) - break; - - - result[i].createtime.tm_year = C2I (tmp[2 ])*10 - 70 + C2I(tmp[3]); - result[i].createtime.tm_mday = C2I (tmp[4 ])*10 + C2I(tmp[5]); - result[i].createtime.tm_hour = C2I (tmp[6 ])*10 + C2I(tmp[7]); - result[i].createtime.tm_min = C2I (tmp[8 ])*10 + C2I(tmp[9]); - result[i].createtime.tm_sec = C2I (tmp[10])*10 + C2I(tmp[11]); - - for(p=tmp; *p!=' '; p++); - for(; *p==' '; p++); - - result[i].size = atoi(p); - - for(; *p!=' '; p++); - for(; *p==' '; p++); - - for (pp=result[i].host;*p!=' ';p++,pp++) *pp=*p; - *pp=0; - for(; *p==' '; p++); - for (pp=result[i].file;*p!='\n';p++,pp++) *pp=*p; - *pp=0; - - } - - return i; -} diff --git a/lib/libftp/FtpBye.c b/lib/libftp/FtpBye.c deleted file mode 100644 index 7094843..0000000 --- a/lib/libftp/FtpBye.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <signal.h> - -STATUS FtpBye(FTP *ftp) -{ - FtpAssert(ftp,FtpCommand(ftp,"QUIT",221,EOF)); - - fclose(FTPCMD(ftp)); - free(ftp); - return 0; -} - -STATUS FtpQuickBye(FTP *ftp) -{ - if (ftp == NULL) return 0; - - if (FTPDATA(ftp)!=NULL) - { - shutdown(fileno(FTPDATA(ftp)),2); - fclose(FTPDATA(ftp)); - } - - if (FTPCMD(ftp)!=NULL) - { - shutdown(fileno(FTPCMD(ftp)),2); - fclose(FTPCMD(ftp)); - } - free(ftp); - return 0; -} - diff --git a/lib/libftp/FtpClose.c b/lib/libftp/FtpClose.c deleted file mode 100644 index a14658e..0000000 --- a/lib/libftp/FtpClose.c +++ /dev/null @@ -1,26 +0,0 @@ -/* 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 existing programs. -Commercial usage is also possible with participation of it's author. -*/ - -#include "FtpLibrary.h" - -STATUS FtpClose(FTP *ftp) -{ - int i; - String S1; - - fflush(FTPDATA(ftp)); - shutdown(fileno(FTPDATA(ftp)),2); - fclose(FTPDATA(ftp)); - - FtpAssert(ftp,i=FtpGetMessage(ftp,S1)); - if ( i != 226 ) - return EXIT(ftp,-i); - return EXIT(ftp,i); -} diff --git a/lib/libftp/FtpCommand.c b/lib/libftp/FtpCommand.c deleted file mode 100644 index 25fd460..0000000 --- a/lib/libftp/FtpCommand.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <varargs.h> - -STATUS FtpCommand(va_alist) - va_dcl -{ - FTP *con; - char *command, *param; - int Answer[MAX_ANSWERS]; - va_list args; - String S1; - int i,counter=0; - - va_start(args); - - con = va_arg(args,FTP *); - command = va_arg(args,char *); - param = va_arg(args, char *); - - while ( 1 ) - { - if (counter == MAX_ANSWERS) - return EXIT(con,QUIT); - Answer[counter] = va_arg(args,int); - if (Answer[counter] == EOF ) break; - counter++; - } - - va_end(args); - - - sprintf(S1,command,param); - - if ( FtpSendMessage(con,S1) == QUIT ) - return EXIT(con,QUIT); - - if ( (i=FtpGetMessage(con,S1)) == QUIT ) - return EXIT(con,QUIT); - - if ( ! FtpGood1 ( i , Answer )) - return EXIT(con,-i); - - return EXIT(con,i); -} - - - diff --git a/lib/libftp/FtpConnect.c b/lib/libftp/FtpConnect.c deleted file mode 100644 index 4de95ab..0000000 --- a/lib/libftp/FtpConnect.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> - -STATUS FtpConnect(FTP **con,char * hostname) -{ - struct sockaddr_in unit; - register struct hostent *host; - register int new_socket; - String S1; - STATUS x; - - *con = FtpCreateObject(); - - if ((host=FtpGetHost(hostname))==NULL) - return EXIT((*con),QUIT); - - strcpy((*con) -> title,host -> h_name); /* Default title for FtpLog */ - - unit.sin_family = host -> h_addrtype; /* AF_INET */ - - bcopy(host-> h_addr_list[0],(char *)&unit.sin_addr,host->h_length); - if ( ( new_socket = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0) - return EXIT((*con),QUIT); - - unit.sin_port = htons((*con)->port); - - while ( connect ( new_socket , (struct sockaddr *)&unit , sizeof unit ) < 0 ) - { - host -> h_addr_list ++; - if (host -> h_addr_list[0]==NULL) { - close(new_socket); - return EXIT((*con),QUIT); - } - bcopy(host -> h_addr_list[0],(char *)&unit,host->h_length); - close(new_socket); - if ( ( new_socket = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0) - { - close(new_socket); - return EXIT((*con),QUIT); - } - } - - FTPCMD(*con) = fdopen(new_socket,"r+"); - - if ( (x=FtpGetMessage(*con,S1)) == QUIT ) - return EXIT((*con),QUIT); - if ( ! FtpGood(x,120,220,EOF)) - { - close(new_socket); - return EXIT((*con),-x); - } - if ( (*con)->mode != 'A' ) FtpType(*con,(*con)->mode); - - return EXIT((*con),x); -} - - - diff --git a/lib/libftp/FtpCopy.c b/lib/libftp/FtpCopy.c deleted file mode 100644 index db582d2..0000000 --- a/lib/libftp/FtpCopy.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpCopy (FTP * ftp1 , FTP * ftp2 ,char *in , char * out) -{ - int size; - char buffer[FTPBUFSIZ]; - - if (!*out) out=in; - - if ( FtpTestFlag(ftp1,FTP_REST) && FtpTestFlag(ftp2,FTP_REST) - && (size=FtpSize(ftp1,in))>0 - && FtpCommand(ftp1,"REST 0",0,0,EOF)==350 && FtpCommand(ftp2,"REST 0",0,0,EOF)==350 ) - ftp1->seek=ftp2->seek=size; - else - ftp1->seek=ftp2->seek=0; - - FtpAssert(ftp1,FtpData(ftp1,"RETR %s",in,"r")); - FtpAssert(ftp2,FtpData(ftp2,"STOR %s",out,"w")); - - while ((size=FtpReadBlock(ftp1,buffer,FTPBUFSIZ))>0) - { - if (FtpWriteBlock(ftp2,buffer,size)!=size) - return EXIT(ftp2,QUIT); - } - - FtpAssert(ftp1,FtpClose(ftp1)); - FtpAssert(ftp2,FtpClose(ftp2)); - return 0; -} - - - - - - - diff --git a/lib/libftp/FtpData.c b/lib/libftp/FtpData.c deleted file mode 100644 index 066671f..0000000 --- a/lib/libftp/FtpData.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> - -STATUS FtpData(FTP * con,char * command , char * file ,char * mode) -{ - struct sockaddr_in data,from; - register struct hostent *host; - String hostname; - int NewSocket,Accepted_Socket,len=sizeof(data),one=1,fromlen=sizeof(from), - i = 0; - char *a,*b; - - FREE(data); - FREE(from); - - if ( gethostname( hostname , sizeof hostname ) == -1 ) - return EXIT(con,QUIT); - - if ((host=(struct hostent *)gethostbyname(hostname))==0) - return EXIT(con,QUIT); - - data.sin_family = host -> h_addrtype; - - bcopy(host-> h_addr_list[0],(char *)&data.sin_addr,host->h_length); - - if ((NewSocket = socket ( AF_INET , SOCK_STREAM , 0 ))<0) - return EXIT(con,QUIT); - - if ( setsockopt ( NewSocket , SOL_SOCKET , SO_REUSEADDR , - (char *)&one , sizeof(one) ) < 0 ) - { - close(NewSocket); - return EXIT ( con,QUIT ); - } - - data.sin_port = 0 ; - - if ( bind ( NewSocket , (struct sockaddr *)&data , sizeof data ) < 0 ) - return EXIT(con,QUIT); - - if ( getsockname ( NewSocket , (struct sockaddr *)&data , &len ) < 0 ) - return EXIT(con,QUIT); - - if ( listen ( NewSocket , 1 ) < 0 ) - return EXIT(con,QUIT); - - a = ( char * ) & data.sin_addr; - b = ( char * ) & data.sin_port; - - FtpAssert(con,FtpPort(con,CUT(a[0]),CUT(a[1]),CUT(a[2]), - CUT(a[3]),CUT(b[0]),CUT(b[1]))); - - if ( con -> seek != 0) - { - if ((i = FtpCommand ( con, "REST %d" , con -> seek , 0, EOF)) != 350 ) - return -i; - } - - FtpAssert(con, FtpCommand ( con , command , file , - 200, 120 , 150 , 125 , 250 , EOF )); - - if (( Accepted_Socket = accept (NewSocket , (struct sockaddr *)&from , &fromlen )) < 0) - { - close(NewSocket); - return EXIT(con,QUIT); - } - - close(NewSocket); - - FTPDATA(con) = fdopen(Accepted_Socket, "r+"); - - return i; -} - - - - - diff --git a/lib/libftp/FtpDebug.c b/lib/libftp/FtpDebug.c deleted file mode 100644 index d2b5af9..0000000 --- a/lib/libftp/FtpDebug.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -void FtpDebug(FTP *ftp) -{ - STATUS FtpDebugDebug(), - FtpDebugError(), - FtpDebugIO(); - - FtpSetDebugHandler(ftp,FtpDebugDebug); - FtpSetErrorHandler(ftp,FtpDebugError); - FtpSetIOHandler(ftp,FtpDebugIO); -} - -STATUS FtpDebugDebug(FTP *ftp,int n, char * Message) -{ - String tmp; - - - strcpy(tmp,Message); - - if (strncmp(tmp,"PASS ",5)==0) - { - char *p=tmp+5; - while ( *p != '\0') *p++='*'; - }; - - FtpLog(ftp->title,tmp); - return 1; -} - -STATUS FtpDebugError(FTP *ftp,int n, char * Message) -{ - - FtpLog("FtpDebugError",""); - FtpLog(ftp->title,Message); - if ( ! FtpTestFlag(ftp,FTP_NOEXIT)) - exit(1); - return 0; -} - -STATUS FtpDebugIO(FTP *ftp,int n, char * Message) -{ - FtpLog("FtpDebugIO",""); - FtpLog(ftp->title,Message); - if ( ! FtpTestFlag(ftp,FTP_NOEXIT)) - exit(1); - return 0; -} - -STATUS FtpLog(char *name,char *str) -{ - time_t t=time((time_t *)0); - struct tm *lt=localtime(&t); - fprintf(stderr,"%02d:%02d:%02d %s %s\n",lt->tm_hour, - lt->tm_min,lt->tm_sec,name,str); - fflush(stderr); - return 0; -} - -int -FtpHash(FTP *ftp, unsigned long chars) -{ - - if (chars==0) return ftp->counter=0; - ftp->counter+=chars; - fprintf(stdout,"%10u bytes transfered\r",(unsigned int)ftp->counter); - fflush(stdout); - return ftp->counter; -} - - -STATUS FtpBadReply550(char *s) -{ - if( - (strstr(s,"unreachable")!=NULL) || - (strstr(s,"Broken pipe")!=NULL) - ) - return 0; - return 1; -} diff --git a/lib/libftp/FtpFilenameChecker.c b/lib/libftp/FtpFilenameChecker.c deleted file mode 100644 index 99946eb..0000000 --- a/lib/libftp/FtpFilenameChecker.c +++ /dev/null @@ -1,43 +0,0 @@ -/* 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 existing programs. -Commercial usage is also possible with participation of it's author. -*/ - -#include "FtpLibrary.h" - -static char * simplename(char *s) -{ - char *p; - - if ( (p=(char *)strrchr(s,'/')) == NULL ) - return s; - return p+1; -} - - - - -STATUS FtpFilenameChecker(char ** in, char ** out) -{ - struct stat st; - - if ( (stat(*out,&st) == 0) && S_ISDIR(st.st_mode)) - { - char * sfn = simplename(*in); - char * new = (char *) malloc ( strlen(*out)+ strlen(sfn) + 2 ); - - strcpy(new,*out); - strcat(new,"/"); - strcat(new,sfn); - *out=new; - return 0; - }; - return 0; -} - - diff --git a/lib/libftp/FtpFull.c b/lib/libftp/FtpFull.c deleted file mode 100644 index 51c87dc..0000000 --- a/lib/libftp/FtpFull.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> -#include <pwd.h> - -static FTP *ftp_table[256]; - -FILE * FtpFullOpen(char * file , char * mode ) -{ - FTP *ftp; - FILE *tmp; - String Host,User,Passwd,RemoteFile; - STATUS i; - - if ( ! FtpFullSyntax (file,Host,User,Passwd,RemoteFile)) - { - tmp=fopen(file,mode); - if (tmp==NULL) return tmp; - ftp_table[(int)fileno(tmp)] = NULL; - return tmp; - } - if ( FtpError(i=FtpLogin(&ftp,Host,User,Passwd,NULL))) - return NULL; - - if (mode[1]=='b') FtpBinary(ftp); - - switch(mode[0]) - { - case 'r': - if (FtpError(FtpOpenRead(ftp,RemoteFile))) - return NULL; - ftp_table[fileno(FTPDATA(ftp))] = ftp; - return FTPDATA(ftp); - case 'w': - if (FtpError(FtpOpenWrite(ftp,RemoteFile))) - return NULL; - ftp_table[fileno(FTPDATA(ftp))] = ftp; - return FTPDATA(ftp); - case 'a': - if (FtpError(FtpOpenAppend(ftp,RemoteFile))) - return NULL; - ftp_table[fileno(FTPDATA(ftp))] = ftp; - return FTPDATA(ftp); - } - /* Error Mode */ - return NULL; -} - -STATUS FtpFullClose(FILE *f) -{ - FTP *ftp=ftp_table[(int)fileno(f)]; - if (ftp == NULL) - return fclose(f); - FtpClose(ftp); - return FtpQuickBye(ftp); -} - - -/* Format of ftp's file [user[/passord]@]hostname:filename_with_path */ - -STATUS FtpFullSyntax ( String source , - String host , - String user , - String passwd , - String file) - -{ - char *in,*out; - String tmp; - - host[0] = user[0] = passwd[0] = file[0] = '\0'; - - for ( in=source, out = user; - *in !='\0' && *in != '/' && *in!='@' && *in!=':' ; - *out++ = *in++); - *out = '\0'; - - if ( *in == '\0' ) return 0; - - if ( *in == ':' ) - { - strcpy(host,user); - strcpy(user,"anonymous"); - gethostname(tmp, sizeof tmp); - sprintf(passwd,"%s@%s", - getpwuid(getuid())->pw_name,gethostbyname(tmp)->h_name); - goto file; - } - - if ( *in == '/' ) - { - for ( in++, out = passwd; - *in !='\0' && *in!='@' ; - *out++ = *in++); - *out = '\0'; - if ( *in == '\0' ) return 0; - } - else - { - gethostname(tmp, sizeof tmp); - sprintf(passwd,"%s@%s", - getpwuid(getuid())->pw_name,gethostbyname(tmp)->h_name); - } - - - for ( in++, out = host; - *in !='\0' && *in!=':' ; - *out++ = *in++); - *out = '\0'; - - if ( *in == '\0' ) return 0; - -file: - - for ( in++, out = file; - *in !='\0'; - *out++ = *in++); - *out = '\0'; - - return 1; -} - - - - - - - - diff --git a/lib/libftp/FtpGetHost.c b/lib/libftp/FtpGetHost.c deleted file mode 100644 index 7171ba3..0000000 --- a/lib/libftp/FtpGetHost.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <arpa/inet.h> - - -struct hostent *FtpGetHost(char *host) -{ - - static struct in_addr addr; - static struct hostent _host; - static char *point[2]; - static char *alias[1]; - - bzero(&_host,sizeof _host); - if ( (addr.s_addr=inet_addr(host)) != -1 ) - { - _host.h_addr_list = point; - _host.h_addr_list[0] = (char *) &addr; - _host.h_addr_list[1] = (char *) 0; - alias[0]=NULL; - _host.h_aliases=alias; - _host.h_name=host; - _host.h_length=sizeof(unsigned long); - _host.h_addrtype=AF_INET; - return &_host; - } - - return gethostbyname(host); -} - - diff --git a/lib/libftp/FtpGood.c b/lib/libftp/FtpGood.c deleted file mode 100644 index 20af4e0..0000000 --- a/lib/libftp/FtpGood.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <varargs.h> - -STATUS FtpGood(va_alist) - va_dcl -{ - va_list args; - int Number; - int Answer[MAX_ANSWERS]; - int counter=0; - - va_start(args); - - Number = va_arg(args,int); - - while ( 1 ) - { - if (counter == MAX_ANSWERS) - return 0; - Answer[counter] = va_arg(args,int); - if (Answer[counter] == EOF ) break; - counter++; - } - - va_end(args); - - return FtpGood1(Number,Answer); -} - - -STATUS FtpGood1(int Number , int *Answer) -{ - while (1) - { - if ( *Answer == Number) return 1; - if ( *Answer == 0) return 1; - if ( *Answer == EOF ) return 0; - Answer++; - } -} - diff --git a/lib/libftp/FtpIO.c b/lib/libftp/FtpIO.c deleted file mode 100644 index b7f6af5..0000000 --- a/lib/libftp/FtpIO.c +++ /dev/null @@ -1,174 +0,0 @@ -/* 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 <unistd.h> - -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;i<rsize;i++,ii++) - if (buffer[i]==Ctrl('M')&&buffer[i+1]==Ctrl('J')) - buffer2[ii]='\n',i++; - else - buffer2[ii]=buffer[i]; - - rsize=ii; - bcopy(buffer2,buffer,rsize); - } - return rsize; -} - - -STATUS FtpWriteBlock(FTP *ftp, char *buffer, int size) -{ - fd_set fds; - register int wsize; - char buffer2[size*2]; - - FD_ZERO(&fds); - FD_SET(fileno(FTPDATA(ftp)),&fds); - - if (select(getdtablesize(), 0, &fds, 0, &(ftp->timeout))<1) - return EXIT(ftp,QUIT); - - - if (ftp->mode=='A') - { - register int i,ii; - - for(i=0,ii=0;i<size;i++,ii++) - if (buffer[i]=='\n') - buffer2[ii++]=Ctrl('M'),buffer2[ii]=Ctrl('J'); - else - buffer2[ii]=buffer[i]; - buffer=buffer2; - size=ii; - } - - if ((wsize=write(fileno(FTPDATA(ftp)),buffer,size))!=size) - return EXIT(ftp,QUIT); - - if ( ftp->hash!=NULL && wsize!=0 ) (*ftp->hash)(ftp,wsize); - - return wsize; -} - - - - - - - - - - - - diff --git a/lib/libftp/FtpInit.c b/lib/libftp/FtpInit.c deleted file mode 100644 index 4e43c8c..0000000 --- a/lib/libftp/FtpInit.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -FTP FtpInit = { - NULL, /*sock*/ - NULL, /*data*/ - 'A', /*mode*/ - 0, /*errno*/ - 0, /*ch*/ - NULL,NULL,NULL, NULL, /*funcs*/ - 0, /*seek*/ - 0, /*flags*/ - {120,0}, /*timeout 2 min*/ - 21, /*Port*/ - "johndoe", /* Title */ - 0, /*Counter*/ -}; - -FTP *FtpCreateObject() -{ - FTP *new = (FTP *) malloc (sizeof(FTP)); - - bcopy(&FtpInit,new,sizeof(FTP)); - - return new; -} - - diff --git a/lib/libftp/FtpLibrary.h b/lib/libftp/FtpLibrary.h deleted file mode 100644 index 754e5a1..0000000 --- a/lib/libftp/FtpLibrary.h +++ /dev/null @@ -1,268 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - -*/ - - -#ifndef __FTPLIBRARY_H -#define __FTPLIBRARY_H - - -#ifdef __cplusplus - extern "C" { -#endif -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/timeb.h> -#include <sys/socket.h> -#include <arpa/ftp.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/telnet.h> -#include <sys/stat.h> - - -#ifndef __FreeBSD__ -extern char *sys_errlist[]; -extern int errno; -#else -#include <errno.h> -#endif - - - /* Standard Macros & Definitions */ - - - -#define EXIT(con,e) \ - ( con -> errno = e, \ - ((e==QUIT||e==LQUIT)&&(con->IO != NULL))?(*(con->IO))(con,e,sys_errlist[errno]):0,\ - ((con->error != NULL) && (e < 0) )?(*(con->error))(con,e,FtpMessage(e)):0,\ - e) - - -#define MAX_ANSWERS 10 /* Number of known goodest answers for reqest */ -#define NFDS 64 -#define FTPBUFSIZ BUFSIZ -#define LQUIT (-6) -#define QUIT (-5) /* Few time ago QUIT character been - equivalence to zero, changed for clear - conflicts with reading functions */ -#define Ctrl(x) ((x) - '@') -#define FREE(x) memset ( &(x) , '\0' , sizeof (x) ) -#define CUT(x) ((x)&0xff) -#define FtpError(x) ((x)<0) -#define FtpAssert(ftp,x) if (FtpError(x)) return EXIT((ftp),(ftp)->errno); - -typedef int STATUS; -typedef char String[256]; - -#ifdef __GNUC__ -#define INLINE inline -#else -#define INLINE -#endif - - - - /* Common Information Structure */ - -typedef struct/* All structure initialize from edited struct FtpInit */ -{ - FILE *sock; /* Command stream to server */ - -#define FTPDATA(x) ((x)->data) -#define FTPCMD(x) ((x)->sock) - - - FILE *data; /* Data stream to server */ - char mode; /* Binary, Ascii, ......... */ - int errno; /* Last error code */ - int ch; /* Help character for ascii streams */ - - STATUS (*error)(); - STATUS (*debug)(); - STATUS (*IO)(); - STATUS (*hash)(); /* Call with reading/writing next "int" characters - from stream */ - int seek; /* - Warning! If server not supported REST-command, - then seek variable automaticaly turn to zero - */ - int flags; /* FTP_REST, - FTP_NOEXIT */ - struct timeval timeout; - /* How long must be waiting next character - from server */ - int port; - String title; /* Using for FtpLog, FtpConnect lets hostname */ - unsigned long counter; - /* Using by FtpHash */ -} FTP; - -typedef struct -{ - struct tm createtime; - unsigned long size; - String host; - String file; -} ARCHIE; - - -enum {FTP_REST=1,FTP_NOEXIT=2}; -enum {no,yes}; -enum {off,on}; -enum {false,true}; - -extern FTP FtpInit; - -/* Options defines */ - -#define FtpSetFlag(ftp,flag) ((ftp)->flags|=(flag)) -#define FtpClearFlag(ftp,flag) ((ftp)->flags &= (~(flag)) ) -#define FtpTestFlag(ftp,flag) ((ftp)->flags&(flag)==flag) -#define FtpSetTimeout(ftp,tim) \ - ((ftp)->timeout.tv_sec=tim,(ftp)->timeout.tv_usec=0) -#define FtpSetPort(ftp,prt) ((ftp)->port=(prt)) - -/* Connect & disconnect */ - -STATUS FtpConnect(FTP **con,char *hostname); -#define FtpUser(ftp,user) FtpCommand(ftp,"USER %s",user,230,331,332,EOF) -#define FtpPassword(ftp,pas) FtpCommand(ftp,"PASS %s",pas,230,332,EOF) -#define FtpAccount(ftp,acc) FtpCommand(ftp,"ACCT %s",acc,230,EOF) -STATUS FtpLogin(FTP **con,char *host ,char *user,char *pass,char *acct); -STATUS FtpBye (FTP * con); -STATUS FtpQuickBye (FTP * con); -STATUS FtpAbort(FTP *ftp); - -/* Set type of transfer */ - -STATUS FtpType(FTP *ftp,char type); -#define FtpAscii(ftp) FtpType(ftp,'A') -#define FtpBinary(ftp) FtpType(ftp,'I') - - -/* Send/Receive and handling Procedure(s) */ - -STATUS FtpCopy(FTP *ftp1, FTP *ftp2, char *in, char *out); -STATUS FtpPassiveTransfer(FTP *ftp1, FTP *ftp2, char *in, char *out); - -STATUS FtpRetr(FTP *con, char *command,char *inp,char *out); -#define FtpGet(ftp,in,out) FtpRetr(ftp,"RETR %s",in,out) -#define FtpDirectory(ftp,pat,out) FtpRetr(ftp,"LIST %s",pat,out) -#define FtpDir(ftp,out) FtpRetr(ftp,"LIST","",out) - -STATUS FtpStor(FTP *con ,char*command ,char *inp,char *out); -#define FtpPut(ftp,in,out) FtpStor(ftp,"STOR %s",in,out) - -STATUS FtpData( FTP * con , char * command , char * param , char *mode); -STATUS FtpPort ( FTP *con ,int ,int ,int ,int ,int ,int ); -#define FtpOpenRead(ftp,file) FtpData(ftp,"RETR %s",file,"r") -#define FtpOpenWrite(ftp,file) FtpData(ftp,"STOR %s",file,"w") -#define FtpOpenAppend(ftp,file) FtpData(ftp,"APPE %s",file,"r") -STATUS FtpOpenDir( FTP * con , char * files ); -STATUS FtpClose ( FTP *); - -STATUS FtpReadBlock(FTP *ftp, char *buffer, int size); -STATUS FtpWriteBlock(FTP *ftp, char *buffer, int size); - -/* Command for hand transfer */ - -STATUS FtpRead ( FTP * con); -STATUS FtpWrite ( FTP * con , char c); -int FtpGetc ( FTP * ftp, FILE *fp ); -STATUS FtpPutc (FTP *ftp, FILE *fp, char c); - -/* Manipulation commands for remote server */ - -STATUS FtpCommand (); -#define FtpChdir(ftp,dir) FtpCommand(ftp,"CWD %s",dir,200,250,EOF) -#define FtpMkdir(ftp,dir) FtpCommand(ftp,"MKD %s",dir,200,257,EOF) -#define FtpRm(ftp,dir) FtpCommand(ftp,"DELE %s",dir,200,250,EOF) -char *FtpPwd(FTP *con); -int FtpSize(FTP *con,char *filename); -STATUS FtpMove ( FTP *con,char * old,char *new); - -/* Procedures for dialog with remote server */ - -STATUS FtpInitMessageList(); -STATUS FtpSendMessage( FTP * con , char * Message ); -int FtpGetMessage( FTP * con , char * Message); -char *FtpMessage(int Number); -int FtpNumber ( char * Message ); - - -/* Debug */ - -#define FtpSetErrorHandler(con,f) (con)->error = f -#define FtpSetDebugHandler(con,f) (con)->debug = f -#define FtpSetIOHandler(con,f) (con)->IO =f -#define FtpSetHashHandler(con,f) (con)->hash =f -#define FtplibDebug(t) FtpDebug(&FtpInit) - -STATUS FtpDebugDebug ( FTP *con, int errno, char * Message); -STATUS FtpDebugError ( FTP *con, int errno, char * Message); -STATUS FtpDebugIO ( FTP *con, int errno, char * Message); -STATUS FtpLog(char *progtitle, char *msg); -STATUS FtpHash ( FTP *con, unsigned long number_of_bytes ); -void FtpDebug ( FTP * con ); -STATUS FtpBadReply550 (char *message); - - -/* Other Procedures */ - -FTP *FtpCreateObject(); -FILE *FtpFullOpen(char * file,char * mode ); -STATUS FtpFullSyntax(String,String,String,String,String); -FILE *Ftpfopen(char *filename,char *mode); -STATUS Ftpfclose(FILE *); -STATUS FtpFullClose(FILE *); -STATUS FtpGood (); -STATUS FtpGood1 (int, int *); -struct hostent *FtpGetHost(char *host); -STATUS FtpFilenameChecher(char *input, char *output); -STATUS FtpLink(FTP *,FTP *); -int FtpArchie(char *what, ARCHIE *, int number); - -#ifdef __cplusplus -} -#endif - - -/* Additional definitions */ - -#ifdef _AIX -int accept (int, struct sockaddr_in*, int*); -char *bcopy (char*, char*, size_t); -int bind (int, const void*, int); -int connect (int, struct sockaddr_in*, int); -int gethostname (char*, size_t); -int getsockname (int, struct sockaddr_in*, int*); -int getpeername (int, struct sockaddr_in*, int*); -int getsockopt (int, int, int, void*, int*); -int listen(int, int); -int setsockopt (int, int, int, void*, int); -int socket (int, int, int); -void free (void*); -void *malloc (size_t); -#endif - - - - -#endif /* __FTPLIBRARYH_ */ - - - diff --git a/lib/libftp/FtpLogin.c b/lib/libftp/FtpLogin.c deleted file mode 100644 index e066d55..0000000 --- a/lib/libftp/FtpLogin.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpLogin ( FTP ** con, char * host , char * user , - char * password , char * account) -{ - - FtpAssert((*con),FtpConnect(con,host)); - FtpAssert((*con),FtpUser((*con),user)); - if (((*con)->errno)==230 ) - return ((*con)->errno); - if (((*con)->errno)==332) - { - if ( account == NULL ) - return EXIT(((*con)),(*con)->errno); - FtpAssert((*con),FtpAccount( (*con) , account )); - if ( ((*con)->errno)==230 ) - return (*con)->errno; - } - return FtpPassword((*con),password); -} diff --git a/lib/libftp/FtpMessage.c b/lib/libftp/FtpMessage.c deleted file mode 100644 index 8009d05..0000000 --- a/lib/libftp/FtpMessage.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <ctype.h> - -static char * FtpMessageList[1000]; - -INLINE static char *___gets(char *s, int maxchars, FTP *ftp) -{ - char *p=s; - int c; - - while (1) - { - if ((c = FtpGetc(ftp,FTPCMD(ftp))) == EOF) - return NULL; - - if ( c == '\n' && *(p-1) == '\r' ) - { - p--; - *p='\0'; - return s; - } - - if ( (p-s) > maxchars ) return NULL; - - *p++=(char)c; - } -} - - - - -int FtpGetMessage(FTP *con , char * Message ) -{ - int n; - char tmp[1024]; - - while(1) - { - if (___gets(tmp,sizeof tmp,con)==NULL) - return EXIT(con,QUIT); - if (isdigit(tmp[0]) && - isdigit(tmp[1]) && - isdigit(tmp[2]) && - tmp[3]!='-') break; - if ( con -> debug != NULL ) - (*con->debug)(con,0,tmp); - } - - strcpy(Message,tmp); - FtpInitMessageList(); - FtpMessageList[n=FtpNumber(Message)] = - ( char * ) malloc ( strlen(Message) + 1); - strcpy(FtpMessageList[n] , Message ); - if ( con -> debug != NULL ) - (*con->debug)(con,n,Message); - - return n; -} - -STATUS FtpSendMessage(FTP *ftp,char * Message ) -{ - char *msg=Message; - - while (*Message) - FtpAssert(ftp,FtpPutc(ftp,FTPCMD(ftp),*Message++)); - - FtpAssert(ftp,FtpPutc(ftp,FTPCMD(ftp),'\015')); - FtpAssert(ftp,FtpPutc(ftp,FTPCMD(ftp),'\012')); - - if ( ftp -> debug != NULL ) - (*ftp->debug)(ftp,0,msg); - return 1; -} - -char *FtpMessage(int number) -{ - extern int sys_nerr,errno; -#ifndef __FreeBSD__ - extern char *sys_errlist[]; -#endif - - FtpInitMessageList(); - if ( number == 0 ) - return (char *)sys_errlist[errno]; - return (FtpMessageList[abs(number)]==NULL)? - "":FtpMessageList[abs(number)]; -} - - -STATUS FtpInitMessageList() -{ - int i; - static u = 0; - - if ( u ) - return 1; - - u = 1; - - for (i=0;i<1000;i++) - FtpMessageList[i]=NULL; - - return 1; -} - -int FtpNumber(char *Message) -{ - return (Message[0] - '0') * 100 + - (Message[1] - '0') * 10 + - (Message[2] - '0') ; -} - - - - - diff --git a/lib/libftp/FtpMove.c b/lib/libftp/FtpMove.c deleted file mode 100644 index 8037b6b..0000000 --- a/lib/libftp/FtpMove.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpMove(FTP *con,char * oldname , char * newname ) -{ - STATUS i; - - if ((i=FtpCommand(con,"RNFR %s",oldname,200,350,EOF)) > 1 ) - return FtpCommand(con,"RNTO %s",newname,200,250,EOF); - else - return i; -} diff --git a/lib/libftp/FtpNumber.c b/lib/libftp/FtpNumber.c deleted file mode 100644 index a6d7114..0000000 --- a/lib/libftp/FtpNumber.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -int FtpNumber(char *Message) -{ - return (Message[0] - '0') * 100 + - (Message[1] - '0') * 10 + - (Message[2] - '0') ; -} diff --git a/lib/libftp/FtpOpenDir.c b/lib/libftp/FtpOpenDir.c deleted file mode 100644 index 3f2bcf1..0000000 --- a/lib/libftp/FtpOpenDir.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpOpenDir(FTP * con,char * file) -{ - String command; - - if ( file == NULL || *file == '\0' ) - strcpy(command,"NLST"); - else - sprintf(command,"NLST %s",file); - - return FtpCommand(con,command,"",120,150,200,EOF); -} diff --git a/lib/libftp/FtpPasv.c b/lib/libftp/FtpPasv.c deleted file mode 100644 index 3dd52fe..0000000 --- a/lib/libftp/FtpPasv.c +++ /dev/null @@ -1,100 +0,0 @@ -/* 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 <unistd.h> -#include <ctype.h> - -char * FtpPasv (FTP *ftp) -{ - char *msg; - static String PORT; - char *p=PORT; - - if FtpError(FtpCommand(ftp,"PASV","",227,EOF)) - return ""; - - msg = FtpMessage (227); - - msg+=3; - - while (!isdigit(*msg++)); - msg--; - - while (isdigit(*msg)||*msg==',') *p++=*msg++; - *p=0; - - return PORT; -} - - -STATUS FtpLink(FTP *ftp1, FTP *ftp2) -{ - - String PORT; - - strcpy(PORT,FtpPasv(ftp1)); - - FtpCommand(ftp2,"PORT %s",PORT,200,EOF); - return 0; -} - -STATUS FtpPassiveTransfer(FTP *ftp1, FTP *ftp2, char *f1, char *f2) -{ - String tmp; - fd_set fds; - - FtpAssert(ftp1,FtpLink(ftp1,ftp2)); - - - if (!*f2) f2=f1; - - FtpAssert(ftp2,FtpCommand(ftp2,"STOR %s",f2, 200, 120 , 150 , 125 , 250 , EOF )); - FtpAssert(ftp1,FtpCommand(ftp1,"RETR %s",f1, 200, 120 , 150 , 125 , 250 , EOF )); - - FD_ZERO(&fds); - - FD_SET(fileno(FTPCMD(ftp1)),&fds); - FD_SET(fileno(FTPCMD(ftp2)),&fds); - - if (select(getdtablesize(),&fds,0,0,0)<0) - { - if (ftp1->error!=NULL) - return (*(ftp1->error))(ftp1,QUIT,sys_errlist[errno]); - if (ftp2->error!=NULL) - return (*(ftp2->error))(ftp1,QUIT,sys_errlist[errno]); - return QUIT; - } - - if (FD_ISSET(fileno(FTPCMD(ftp1)),&fds)) - { - FtpGetMessage(ftp1,tmp); - FtpLog(ftp1->title,tmp); - FtpGetMessage(ftp2,tmp); - FtpLog(ftp2->title,tmp); - } - else - { - FtpGetMessage(ftp2,tmp); - FtpLog(ftp2->title,tmp); - FtpGetMessage(ftp1,tmp); - FtpLog(ftp1->title,tmp); - } - return 0; -} - - - - - diff --git a/lib/libftp/FtpPort.c b/lib/libftp/FtpPort.c deleted file mode 100644 index eb15ac0..0000000 --- a/lib/libftp/FtpPort.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpPort(FTP *con,int a,int b,int c,int d,int e,int f) -{ - String cmd; - int i; - - sprintf(cmd,"PORT %d,%d,%d,%d,%d,%d",a,b,c,d,e,f); - if ( FtpSendMessage(con,cmd) == QUIT) - return QUIT; - if ( (i=FtpGetMessage(con,cmd)) == QUIT) - return QUIT; - - if ( ! FtpGood ( i , 200 , EOF )) - return EXIT(con,-i); - - return EXIT(con,i); -} diff --git a/lib/libftp/FtpPwd.c b/lib/libftp/FtpPwd.c deleted file mode 100644 index 59c792d..0000000 --- a/lib/libftp/FtpPwd.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -char * FtpPwd(FTP * con) -{ - String tmp; - static String tmp1; - int i; - - if ( FtpSendMessage(con,"PWD") == QUIT ) - return (char *) EXIT(con,QUIT); - if ( (i=FtpGetMessage(con,tmp)) == QUIT ) - return (char *) EXIT(con,QUIT); - - if ( i != 257 ) - return (char *) EXIT(con,-i); - - sscanf(tmp,"%*[^\"]%*c%[^\"]%*s",tmp1); - con -> errno = i; - return tmp1; -} diff --git a/lib/libftp/FtpRetr.c b/lib/libftp/FtpRetr.c deleted file mode 100644 index ced19b8..0000000 --- a/lib/libftp/FtpRetr.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> - -extern STATUS FtpFilenameChecker(char ** in, char ** out); - -STATUS FtpRetr (FTP * con , char * command , - char *in , char * out) -{ - FILE *o; - struct stat st; - char buffer[FTPBUFSIZ]; - register int size; - - FtpFilenameChecker(&in,&out); - - if ( FtpTestFlag(con,FTP_REST) && stat(out,&st)==0) - { - con -> seek = st.st_size; - if ((o=Ftpfopen(out,"a+"))==NULL) - return EXIT(con,LQUIT); - } - else - { - con -> seek = 0; - if ((o=Ftpfopen(out,"w+"))==NULL) - return EXIT(con,LQUIT); - } - - - if ( FtpError(FtpData(con,command,in,"r"))) - { - - if (con->seek==0) return EXIT(con,con->errno); - - con -> seek = 0; - fclose(o); - - if ( FtpError(FtpData(con,command,in,"r")) ) - { - return EXIT(con,con->errno); - } - - if ((o=Ftpfopen(out,"w+"))==NULL) - return EXIT(con,LQUIT); - } - - - fseek(o,con->seek,0); - - while((size=FtpReadBlock(con,buffer,FTPBUFSIZ))>0) - { - if (write(fileno(o),buffer,size)!=size) - return EXIT(con,LQUIT); - } - - Ftpfclose(o); - return FtpClose(con); -} - - - - - - - - - - - - diff --git a/lib/libftp/FtpSize.c b/lib/libftp/FtpSize.c deleted file mode 100644 index 581e186..0000000 --- a/lib/libftp/FtpSize.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -int FtpSize(FTP * con, char *filename) -{ - String tmp; - int i,size; - - strcpy(tmp,"SIZE "); - strcat(tmp,filename); - - if ( FtpSendMessage(con,tmp) == QUIT ) - return EXIT(con,QUIT); - if ( (i=FtpGetMessage(con,tmp)) == QUIT ) - return EXIT(con,QUIT); - - if ( i != 213 ) - return con -> errno = (-i); - - sscanf(tmp,"%*d %d",&size); - return size; -} diff --git a/lib/libftp/FtpStor.c b/lib/libftp/FtpStor.c deleted file mode 100644 index 9cd0e4e..0000000 --- a/lib/libftp/FtpStor.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> - -STATUS FtpStor (FTP * con , char * command , - char *in , char * out) -{ - FILE *i; - char buffer[FTPBUFSIZ]; - int size; - - con->seek=0; - - if ( (i=Ftpfopen(in,"rb")) == NULL ) - return EXIT(con,LQUIT); - - if ( FtpTestFlag(con,FTP_REST) && - (con->seek=FtpSize(con,out))<0 ) - con->seek=0; - - - if ( FtpError(FtpData(con,command,out,"w"))) - { - if (con->seek==0) return EXIT(con,con->errno); - - con -> seek =0; - if ( FtpError(FtpData(con,command,out,"w")) ) - return EXIT(con,con->errno); - } - - if (con->seek) fseek(i,con->seek,0); - - while ( (size=read ( fileno(i) , buffer, FTPBUFSIZ ))>0) - FtpWriteBlock(con,buffer,size); - - Ftpfclose(i); - return FtpClose(con); -} - - - - - - - diff --git a/lib/libftp/FtpSyscalls.c b/lib/libftp/FtpSyscalls.c deleted file mode 100644 index 67fa4ca..0000000 --- a/lib/libftp/FtpSyscalls.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" -#include <unistd.h> -#include <errno.h> - -#define DEF(syscal,name) int name(void *a, void *b, void *c) \ -{\ - register int status;\ - while (((status=syscal(a,b,c))==-1) && (errno==EINTR));\ - return status;\ -} - -DEF(open,nointr_open) -DEF(close,nointr_close) -DEF(select,nointr_select) -DEF(read,nointr_read) -DEF(write,nointr_write) -DEF(dup,nointr_dup) -DEF(wait,nointr_wait) -DEF(connect,nointr_connect) -DEF(listen,nointr_listen) -DEF(accept,nointr_accept) diff --git a/lib/libftp/FtpType.c b/lib/libftp/FtpType.c deleted file mode 100644 index ae0d0ea..0000000 --- a/lib/libftp/FtpType.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include "FtpLibrary.h" - -STATUS FtpType(FTP *ftp, char type) -{ - STATUS p; - - if ((p=FtpCommand(ftp,"TYPE %c",type,200,EOF))>0) - ftp->mode=(int)type; - return p; -} - - diff --git a/lib/libftp/Ftpfopen.c b/lib/libftp/Ftpfopen.c deleted file mode 100644 index 9b89bb3..0000000 --- a/lib/libftp/Ftpfopen.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - 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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -#include <FtpLibrary.h> - -#define NFSD 256 - -static int fds_types[NFDS]; -static int init=0; - -enum {T_EMPTY=0,T_FILE,T_STREAM,T_PIPE,T_FULL}; - -FILE *Ftpfopen(char *filename,char *mode) -{ - FILE *fp; - - if (!init) - { - bzero(fds_types,NFDS*sizeof(fds_types[0])); - init=1; - } - - if (!strcmp(filename,"*STDIN*") || (!strcmp(filename,"-") && (mode[0]=='r')) ) - { - fds_types[fileno(stdin)]=T_STREAM; - return stdin; - } - - if (!strcmp(filename,"*STDOUT*") || (!strcmp(filename,"-") && (mode[0]=='w'))) - { - fds_types[fileno(stdout)]=T_STREAM; - return stdout; - } - - if (strcmp(filename,"*STDERR*")==0) - { - fds_types[fileno(stderr)]=T_STREAM; - return stderr; - } - - - - if (*filename=='|') - { - fp=popen(filename+1,mode); - if (fp==NULL) return fp; - fds_types[fileno(fp)]=T_PIPE; - return fp; - } - - fp=FtpFullOpen(filename,mode); - if (fp==NULL) return fp; - fds_types[fileno(fp)]=T_FILE; - return fp; - -} - -int Ftpfclose(FILE *fp) -{ - - if (!init) - { - bzero(fds_types,NFDS*sizeof(fds_types[0])); - init=1; - } - - switch (fds_types[fileno(fp)]) - { - - case T_FILE: - - return FtpFullClose(fp); - - case T_STREAM: - - return fflush(fp); - - case T_PIPE: - - return pclose(fp); - - default: - - return -1; - } - -} diff --git a/lib/libftp/Makefile b/lib/libftp/Makefile deleted file mode 100644 index ebb6b5b..0000000 --- a/lib/libftp/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -LIB= ftp -CFLAGS+= -I${.CURDIR} -Wall - -SRCS= FtpAbort.c FtpFull.c FtpPasv.c \ - FtpArchie.c FtpGetHost.c FtpPort.c \ - FtpBye.c FtpGood.c FtpPwd.c \ - FtpClose.c FtpIO.c FtpRetr.c \ - FtpCommand.c FtpInit.c FtpSize.c \ - FtpConnect.c FtpLogin.c FtpStor.c \ - FtpCopy.c FtpMessage.c \ - FtpData.c FtpMove.c FtpType.c \ - FtpDebug.c Ftpfopen.c \ - FtpFilenameChecker.c FtpOpenDir.c - -beforeinstall: - -cd ${.CURDIR}; cmp -s FtpLibrary.h ${DESTDIR}/usr/include/FtpLibrary.h || \ - install -c -o ${BINOWN} -g ${BINGRP} -m 444 FtpLibrary.h \ - ${DESTDIR}/usr/include - -.include <bsd.lib.mk> diff --git a/lib/libftp/doc/example.c b/lib/libftp/doc/example.c deleted file mode 100644 index 0606592..0000000 --- a/lib/libftp/doc/example.c +++ /dev/null @@ -1,51 +0,0 @@ - -/* Include standard libftp's header */ - -#include <FtpLibrary.h> - - - -main(int argc, char *argv[]) -{ - - FILE *input,*output; - int c; - - - if (argc<3) - exit(fprintf(stderr,"Usage: %s input-file output-file\n",argv[0])); - - FtplibDebug(yes); - - if ((input=Ftpfopen(argv[1],"r"))==NULL) - { - perror(argv[1]); - exit(1); - } - - if ((output=Ftpfopen(argv[2],"w"))==NULL) - { - perror(argv[2]); - exit(1); - } - - while ( (c=getc(input)) != EOF && (putc(c,output)!=EOF) ); - - if (ferror(input)) - { - perror(argv[1]); - exit(1); - } - - if (ferror(output)) - { - perror(argv[1]); - exit(1); - } - - Ftpfclose(input); - Ftpfclose(output); - - exit(0); - -} diff --git a/lib/libftp/utils/Makefile b/lib/libftp/utils/Makefile deleted file mode 100644 index bae516b..0000000 --- a/lib/libftp/utils/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# -# A rather bogus Makefile, but one intended to be used by hand anyway.. -# - -CFLAGS = -I${.CURDIR} -I${.CURDIR}/.. -DREADLINE -LDADD+= -L${.CURDIR} -DPADD+= libetc.a - -.if exists(${.CURDIR}/../obj) -LDADD+= -L${.CURDIR}/../obj -DPADD+= ${.CURDIR}/../obj/libftp.a -.else -LDADD+= -L${.CURDIR}/.. -DPADD+= ${.CURDIR}/../libftp.a -.endif - -all: ftptry mirror uftp - -ftptry: ftptry.o - $(CC) $(CFLAGS) -o ftptry ftptry.o ${LDADD} -lftp - -uftp: uftp.o uftpcmd.o libetc.a - $(CC) $(CFLAGS) -o uftp uftp.o uftpcmd.o ${LDADD} -lftp -letc - -mirror: mirror.o - $(CC) $(CFLAGS) -o mirror mirror.o ${LDADD} -lftp - -clean: - rm -f ftptry mirror uftp *~ *.o *.a - -LIBOBJS= readline.o glob.o -libetc.a: $(LIBOBJS) - ar qc libetc.a $(LIBOBJS) - ranlib libetc.a diff --git a/lib/libftp/utils/cdefs.h b/lib/libftp/utils/cdefs.h deleted file mode 100644 index aede2ec..0000000 --- a/lib/libftp/utils/cdefs.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Berkeley Software Design, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)cdefs.h 8.7 (Berkeley) 1/21/94 - */ - -#ifndef _CDEFS_H_ -#define _CDEFS_H_ - -#if defined(__cplusplus) -#define __BEGIN_DECLS extern "C" { -#define __END_DECLS }; -#else -#define __BEGIN_DECLS -#define __END_DECLS -#endif - -#if (defined(__STDC__) || defined(__cplusplus)) -#define __const const /* define reserved names to standard */ -#define __signed signed -#define __volatile volatile -#if defined(__cplusplus) -#define __inline inline /* convert to C++ keyword */ -#else -#ifndef __GNUC__ -#define __inline /* delete GCC keyword */ -#endif /* !__GNUC__ */ -#endif /* !__cplusplus */ - -#else /* !(__STDC__ || __cplusplus) */ -#define __P(protos) () /* traditional C preprocessor */ -#define __CONCAT(x,y) x/**/y -#define __STRING(x) "x" - -#ifndef __GNUC__ -#define __const /* delete pseudo-ANSI C keywords */ -#define __inline -#define __signed -#define __volatile -/* - * In non-ANSI C environments, new programs will want ANSI-only C keywords - * deleted from the program and old programs will want them left alone. - * When using a compiler other than gcc, programs using the ANSI C keywords - * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. - * When using "gcc -traditional", we assume that this is the intent; if - * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. - */ -#ifndef NO_ANSI_KEYWORDS -#define const /* delete ANSI C keywords */ -#define inline -#define signed -#define volatile -#endif -#endif /* !__GNUC__ */ -#endif /* !(__STDC__ || __cplusplus) */ - -/* - * GCC1 and some versions of GCC2 declare dead (non-returning) and - * pure (no side effects) functions using "volatile" and "const"; - * unfortunately, these then cause warnings under "-ansi -pedantic". - * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of - * these work for GNU C++ (modulo a slight glitch in the C++ grammar - * in the distribution version of 2.5.5). - */ -#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 5 -#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define __dead __volatile -#define __pure __const -#endif -#endif - -/* Delete pseudo-keywords wherever they are not available or needed. */ -#ifndef __dead -#define __dead -#define __pure -#endif - -#endif /* !_CDEFS_H_ */ diff --git a/lib/libftp/utils/ftptry.c b/lib/libftp/utils/ftptry.c deleted file mode 100644 index 7dfb130..0000000 --- a/lib/libftp/utils/ftptry.c +++ /dev/null @@ -1,633 +0,0 @@ -/* -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 existing programs. -Commercial usage is also possible with participation of it's author. - - - -*/ - -char intro[]="\ - Ftptry - try transfer via FTP.\n\ - Copyright by Oleg Orel is Reserved.\n\ -\n\ -This program is writen using \"libftp\".The main orientation for this\n\ -program is FTPing via bad-working network. Many network links are\n\ -down-up switched and networks are broaken, so the problem of\n\ -transfering large files exists. The main method, used by this\n\ -software is repetition until successfull transfer. There are some\n\ -keys for setting repetition and timeout intervals, modes of transfer\n\ -(binary and ascii), types of transfer (get,put,directory). All options\n\ -will be described in usage, if the program is started without them.\n\ -\n\ - The libftp you may transfer from host lpuds.oea.ihep.su via ftp-anonymous.\n\ - All question are sent to author via e-mail (orel@oea.ihep.su)\n\ - "; - -#include <FtpLibrary.h> -#include <sys/types.h> -#include <sys/file.h> -#include <signal.h> -#include <setjmp.h> -#include <string.h> - -#ifdef __GNUC__ -#define INLINE inline -#else -#define inline -#endif - -#define FTPTRY "FTPTRY" /* The name of enviroment - variable with default options*/ -#define log(x) FtpLog("ftptry",x) -#define DEBUG(x) (debug?log(x):0) -#define USERNAME (getenv("USER")==NULL?getenv("LOGNAME"):getenv("USER")) -#define DEFAULT_TIMEOUT 600 - - -enum __type__ {ascii=1,binary}; -enum __mode__ {get=1,put,dir,multiget}; -enum __logmode__ {lm_tty,lm_file,lm_mail}; -enum __rcode__ {OK_, BREAK_, CANCEL_}; - -char *gethost(); -char *date(); -int my_abort(); -int my_IO(); -int my_debug(); -void done(),leave(),sighup(); - -char - *machine ="localhost", - *user="anonymous", - *password, - *localfile=NULL, - *progname="ftptry"; - -jmp_buf stack,trap; -int counter=0; -String tmp; -FTP *ftp; -int type=ascii; -int sleeptime=600; -int debug=false; -int mode=get; -int logmode=lm_tty; -char *logfile=NULL; -FILE *LIST=NULL; -extern int errno; -extern char *optarg; -extern int optind, opterr; -String PASSWORD; - - -/* Setup enviroment */ - -main(int argc,char **argv) -{ - FILE *out,*in; - int i; - - if (setjmp(trap)!=0) - exit(1); - - signal(SIGHUP,sighup); - signal(SIGTRAP,done); - signal(SIGINT,done); - signal(SIGQUIT,done); - - sprintf(password=PASSWORD,"%s@%s", - USERNAME, - gethost()); - - progname=argv[0]; - - FtpDebug(&FtpInit); - FtpSetErrorHandler(&FtpInit,my_abort); - FtpSetIOHandler(&FtpInit,my_IO); - FtpSetFlag(&FtpInit,FTP_REST); - FtpSetTimeout(&FtpInit,DEFAULT_TIMEOUT); - - setoptions(); - optind=1; - options(argc,argv); - if ( argc<2 ) usage(); - - switch(logmode) - { - - case lm_file: - - if (fork()) quit("Deattaching....."); - close(0);close(1);close(2); - - if (logfile==NULL) - { - sprintf(tmp,"/tmp/ftptry-%s.XXXXXX",USERNAME); - mktemp(tmp); - } - else - strcpy(tmp,logfile); - - open(tmp,O_TRUNC|O_CREAT|O_WRONLY,0600); - dup(0); - dup(0); - break; - - case lm_mail: - - - - if (fork()) quit("Deattaching....."); - - close(0);close(1);close(2); - if (popen("/usr/lib/sendmail -t","w")==NULL) - perror("sendmail"), - quit(""); - - dup(0); - dup(0); - - printf("From: %s@%s\n",USERNAME,gethost()); - printf("To: %s@%s\n",USERNAME,gethost()); - printf("Subject: ftptry session log\n\n"); - - fflush(stdout); - - break; - } - - - signal(SIGHUP,sighup); - if (isatty(fileno(stdout))) FtpSetHashHandler(&FtpInit,FtpHash); - loop(argc,argv,optind); - exit(0); -} - - - -INLINE noargs(int argc, char **argv, int optind) -{ - int i; - - for (i=optind;i<argc;i++) - if (argv[i]!=NULL) return 0; - return 1; -} - - - -/* Main loop */ - -loop(int argc, char **argv, int optind /* First args as filename */ ) -{ - int i,rcode; - String tmp; - String machine; - String filename; - String localfilename; - char *p1; - - for(i=optind;;(i==argc-1)?i=optind, - sprintf(tmp,"Sleeping %d secs",sleeptime),log(tmp),sleep(sleeptime): - i++) - { - if (noargs(argc,argv,optind)) - quit("Nothing doing"); - - if (strchr(argv[i],':')==NULL) - { - if (find_archie(argv[i],machine,filename,localfilename)==0) - argv[i]=NULL; - } - else - { - sscanf(argv[i],"%[^:]:%s",machine,filename); - if ((p1=strrchr(filename,'/'))!=NULL) - strcpy(localfilename,p1+1); - else - strcpy(localfilename,filename); - } - if (localfile == NULL ) localfile=localfilename; - if ((rcode=transfer(machine, filename, localfile))==OK_) - DEBUG("Transfer complete"), - exit(0); - if (rcode==CANCEL_ && strchr(argv[i],':')!=NULL) - argv[i]=NULL; - } -} - -transfer(char *machine, char *file, char *localfile) -{ - int r; - String tmp; - - if ((r=setjmp(stack))!=0) - return r; - - sprintf(tmp,"Start transfer, machine is %s, remote file is %s, local file is %s", - machine, file, localfile); - DEBUG(tmp); - - FtpLogin(&ftp,machine,user,password,NULL); - - if (type==binary) - FtpBinary(ftp); - - switch (mode) - { - - case get: - - FtpRetr(ftp,"RETR %s",file,localfile); - break; - - case put: - - FtpStor(ftp,"STOR %s",localfile,file); - break; - - case dir: - - FtpRetr(ftp,"LIST %s",file,localfile); - break; - - case multiget: - domultiget(file); - break; - - } - - FtpBye(ftp); - - DEBUG("Transfer complete"); - return OK_; -} - - -void leave(int code) -{ - FtpQuickBye(ftp); - DEBUG("Leaving transfering"); - longjmp(stack,code); -} - -void sighup() -{ - leave(BREAK_); -} - - -quit(char *s) -{ - log(s); - longjmp(trap,1); -} - - -my_IO(FTP *ftp, int n, char *s ) -{ - - DEBUG(s); - leave(BREAK_); -} - -my_abort(FTP *ftp, int n, char *s ) -{ - - log(s); - /* No access or not found, exclude network or host unreachable */; - if (abs(n) == 550 && FtpBadReply550(s)) - leave(CANCEL_); - leave(BREAK_); -} - - -domultiget(char *file) -{ - String list,localname,tmp_name; - char *p1; - - sprintf(list,"/tmp/ftptry-%s-multiget.XXXXXX",USERNAME); - mktemp(list); - - FtpRetr(ftp,"NLST %s",file,list); - - if ((LIST=fopen(list,"r"))==NULL) quit((char *)sys_errlist[errno]); - - while ( fgets (tmp, sizeof tmp, LIST) != NULL ) - { - tmp[strlen(tmp)-1]=0; - if ((p1=strrchr(tmp,'/'))!=NULL) - strcpy(localname,p1+1); - else - strcpy(localname,tmp); - - DEBUG(localname); - FtpGet(ftp,tmp,localname); - } - - fclose(LIST); - LIST=NULL; - return; -} - -usage() -{ - fprintf(stderr,"\ -Usage: %s [optins] [host:file]\n\ - (default host \"localhost\",\n\ - default file \"README\" or \".\" in directory mode)\n\ -\n\ -Valid options:\n\ -\n\ - -u user default anonymous\n\ - -p password default %s\n\ - -P inquire password from your terminal\n\ - -l local_file use only if remote and local file differ\n\ - -c direct output to stdout(like cat)\n\ - -r reverse mode, i.e. send file to remote host\n\ - -d directory mode, remote file is patern or \"ls\" options\n\ - default output is stdout.\n\ - -G multiget mode, file is patern for \"ls\" command\n\ - again at next try.\n\ - -b binary transfer mode\n\ - -s seconds Retry interval, default 10 minutes\n\ - -t seconds Timeout, default 10 minutes\n\ - -D Turn on debugging mode\n\ - -B Run in background and direct output to\n\ - /tmp/ftptry-%s.XXXXXX\n\ - -o file Run in background and direct output\n\ - to file\n\ - -m Send output to orel via e-mail\n\ - -I Print short introduction\n\ -\n\ -Example:\n\ - %s -Dbs 300 garbo.uwasa.fi:ls-lR.Z\n\ - Retrive file ls-lR.Z from garbo.uwasa.fi in binary mode\n\ - trying to reestablish connection every 5 minutes\n\ - on failure. Print debugging information.\n\ -\n\ - You can set default options to %s enviroment variable\n\ -",progname,password,USERNAME,progname,FTPTRY); - exit(-1); -} - - -char *gethost() -{ - static String tmp; - String tmp2; - - gethostname(tmp2,sizeof tmp2); - - strcpy(tmp,FtpGetHost(tmp2)->h_name); - return tmp; -} - - -void done(sig) -{ - String x; - - signal(sig,done); - sprintf(x,"interputed by signal %d",sig); - log(x); - longjmp(trap,1); -} - - -options(int argc,char **argv) -{ - char c; - - while((c=getopt(argc,argv,"GOIBDru:p:Pdbs:o:l:t:cm"))!=EOF) - { - switch(c) - { - - case 'G': - mode=multiget; - break; - - case 'c': - - if (localfile==NULL) localfile="*STDOUT*"; - break; - - case 'I': - fprintf(stderr,intro); - exit(0); - - case 'r': - - mode=put; - break; - - case 'd': - - mode=dir; - if (localfile==NULL) localfile="*STDOUT*"; - break; - - case 't': - - FtpSetTimeout(&FtpInit,atoi(optarg)); - break; - - case 'l': - - localfile=optarg; - break; - - case 'D': - - debug=true; - break; - - case 'u': - - user=optarg; - break; - - case 'p': - - password=optarg; - break; - - case 'P': - - password=(char *)getpass("Password:"); - break; - - case 'b': - - type=binary; - break; - - case 's': - - sleeptime=atoi(optarg); - break; - - case 'o': - - logmode=lm_file; - logfile=optarg; - break; - - case 'm': - - logmode=lm_mail; - break; - - case 'B': - - logmode=lm_file; - logfile=NULL; - break; - - default: - - usage(); - - } - } -} - - -setoptions() -{ - String x; - char *p,*sp; - int argc; - char *argv[100]; - - - - - if ((p=(char *)getenv(FTPTRY))!=NULL && *p!=0) - strcpy(x,p); - else - return; - - - - for (argv[0]="",p=x,sp=x,argc=1; *p!=0 ; p++) - { - if (*p==' ') - { - *p=0; - argv[argc++] = sp; - sp = p+1; - } - } - - argv[argc++]=sp; - - options(argc,argv); -} - - -INLINE unsigned long maxsize(String *result, int hops) -{ - unsigned long maxsiz=0,cursiz=0; - int i; - - for (i=0;i<hops;i++) - { - sscanf(result[i],"%*[^ ] %u %*s",&cursiz); - if (cursiz>maxsiz)maxsiz=cursiz; - } - return maxsiz; -} - - -find_archie(char *what,char *machine, char *filename, char *localfilename) -{ - -#define MAXHOPS 15 - - static String result[MAXHOPS]; - static int last=0; - static int size=0; - static int first=0; - int rnd; - static int init=0; - static String oldwhat={'\0'}; - char *p1; - int i; - - if (!init || strcmp(oldwhat,what)!=0 || last==0) - { - String cmd; - FILE *archie; - - for (i=0;i<MAXHOPS;i++) result[i][0]=0; - sprintf(cmd,"archie -l -m %d %s",MAXHOPS,what); - DEBUG(cmd); - - if ((archie = popen(cmd,"r"))==NULL) - quit("Archie can't execute"); - - for(i=0;i<MAXHOPS;i++) - { - if (fgets(result[i],sizeof (result[i]), archie)==NULL) - break; - result[i][strlen(result[i])-1]=0; - DEBUG(result[i]); - } - - - last=i; - - if ( last==0 ) - { - DEBUG("archie not found need file"); - return(0); - } - - - init=1; - first=0; - strcpy(oldwhat,what); - size=maxsize(result,MAXHOPS); - } - - if (first >= last-1) first=0; - for ( i=first; i<last; i++) - if ( atoi ( strchr(result[i],' ') + 1 ) == size) - { - first=i+1; - break; - } - - DEBUG("Archie select is ... (see next line)"); - DEBUG(result[i]); - - if (sscanf ( result[i] , "%*[^ ] %*[^ ] %[^ ] %s", machine, filename )!=2) - { - DEBUG("Bad archie output format"); - last=0; - return(0); - } - - - if ( (p1=strrchr(filename,'/'))!= NULL) - strcpy(localfilename,p1+1); - else - strcpy(localfilename,filename); - - return(1); -} - - - - - - diff --git a/lib/libftp/utils/glob.c b/lib/libftp/utils/glob.c deleted file mode 100644 index efaeaa6..0000000 --- a/lib/libftp/utils/glob.c +++ /dev/null @@ -1,850 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; -#endif /* LIBC_SCCS and not lint */ - -/* - * glob(3) -- a superset of the one defined in POSIX 1003.2. - * - * The [!...] convention to negate a range is supported (SysV, Posix, ksh). - * - * Optional extra services, controlled by flags not defined by POSIX: - * - * GLOB_QUOTE: - * Escaping convention: \ inhibits any special meaning the following - * character might have (except \ at end of string is retained). - * GLOB_MAGCHAR: - * Set in gl_flags if pattern contained a globbing character. - * GLOB_NOMAGIC: - * Same as GLOB_NOCHECK, but it will only append pattern if it did - * not contain any magic characters. [Used in csh style globbing] - * GLOB_ALTDIRFUNC: - * Use alternately specified directory access functions. - * GLOB_TILDE: - * expand ~user/foo to the /home/dir/of/user/foo - * GLOB_BRACE: - * expand {1,2}{a,b} to 1a 1b 2a 2b - * gl_matchc: - * Number of matches in the current invocation of glob. - */ - -#include <sys/param.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <dirent.h> -#include <errno.h> -#include <glob.h> -#include <pwd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#define DOLLAR '$' -#define DOT '.' -#define EOS '\0' -#define LBRACKET '[' -#define NOT '!' -#define QUESTION '?' -#define QUOTE '\\' -#define RANGE '-' -#define RBRACKET ']' -#define SEP '/' -#define STAR '*' -#define TILDE '~' -#define UNDERSCORE '_' -#define LBRACE '{' -#define RBRACE '}' -#define SLASH '/' -#define COMMA ',' - -#ifndef DEBUG - -#define M_QUOTE 0x8000 -#define M_PROTECT 0x4000 -#define M_MASK 0xffff -#define M_ASCII 0x00ff - -typedef u_short Char; - -#else - -#define M_QUOTE 0x80 -#define M_PROTECT 0x40 -#define M_MASK 0xff -#define M_ASCII 0x7f - -typedef char Char; - -#endif - - -#define CHAR(c) ((Char)((c)&M_ASCII)) -#define META(c) ((Char)((c)|M_QUOTE)) -#define M_ALL META('*') -#define M_END META(']') -#define M_NOT META('!') -#define M_ONE META('?') -#define M_RNG META('-') -#define M_SET META('[') -#define ismeta(c) (((c)&M_QUOTE) != 0) - - -static int compare __P((const void *, const void *)); -static void g_Ctoc __P((const Char *, char *)); -static int g_lstat __P((Char *, struct stat *, glob_t *)); -static DIR *g_opendir __P((Char *, glob_t *)); -static Char *g_strchr __P((Char *, int)); -#ifdef notdef -static Char *g_strcat __P((Char *, const Char *)); -#endif -static int g_stat __P((Char *, struct stat *, glob_t *)); -static int glob0 __P((const Char *, glob_t *)); -static int glob1 __P((Char *, glob_t *)); -static int glob2 __P((Char *, Char *, Char *, glob_t *)); -static int glob3 __P((Char *, Char *, Char *, Char *, glob_t *)); -static int globextend __P((const Char *, glob_t *)); -static const Char * globtilde __P((const Char *, Char *, glob_t *)); -static int globexp1 __P((const Char *, glob_t *)); -static int globexp2 __P((const Char *, const Char *, glob_t *, int *)); -static int match __P((Char *, Char *, Char *)); -#ifdef DEBUG -static void qprintf __P((const char *, Char *)); -#endif - -int -glob(pattern, flags, errfunc, pglob) - const char *pattern; - int flags, (*errfunc) __P((const char *, int)); - glob_t *pglob; -{ - const u_char *patnext; - int c; - Char *bufnext, *bufend, patbuf[MAXPATHLEN+1]; - - patnext = (u_char *) pattern; - if (!(flags & GLOB_APPEND)) { - pglob->gl_pathc = 0; - pglob->gl_pathv = NULL; - if (!(flags & GLOB_DOOFFS)) - pglob->gl_offs = 0; - } - pglob->gl_flags = flags & ~GLOB_MAGCHAR; - pglob->gl_errfunc = errfunc; - pglob->gl_matchc = 0; - - bufnext = patbuf; - bufend = bufnext + MAXPATHLEN; - if (flags & GLOB_QUOTE) { - /* Protect the quoted characters. */ - while (bufnext < bufend && (c = *patnext++) != EOS) - if (c == QUOTE) { - if ((c = *patnext++) == EOS) { - c = QUOTE; - --patnext; - } - *bufnext++ = c | M_PROTECT; - } - else - *bufnext++ = c; - } - else - while (bufnext < bufend && (c = *patnext++) != EOS) - *bufnext++ = c; - *bufnext = EOS; - - if (flags & GLOB_BRACE) - return globexp1(patbuf, pglob); - else - return glob0(patbuf, pglob); -} - -/* - * Expand recursively a glob {} pattern. When there is no more expansion - * invoke the standard globbing routine to glob the rest of the magic - * characters - */ -static int globexp1(pattern, pglob) - const Char *pattern; - glob_t *pglob; -{ - const Char* ptr = pattern; - int rv; - - /* Protect a single {}, for find(1), like csh */ - if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) - return glob0(pattern, pglob); - - while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) - if (!globexp2(ptr, pattern, pglob, &rv)) - return rv; - - return glob0(pattern, pglob); -} - - -/* - * Recursive brace globbing helper. Tries to expand a single brace. - * If it succeeds then it invokes globexp1 with the new pattern. - * If it fails then it tries to glob the rest of the pattern and returns. - */ -static int globexp2(ptr, pattern, pglob, rv) - const Char *ptr, *pattern; - glob_t *pglob; - int *rv; -{ - int i; - Char *lm, *ls; - const Char *pe, *pm, *pl; - Char patbuf[MAXPATHLEN + 1]; - - /* copy part up to the brace */ - for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) - continue; - ls = lm; - - /* Find the balanced brace */ - for (i = 0, pe = ++ptr; *pe; pe++) - if (*pe == LBRACKET) { - /* Ignore everything between [] */ - for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) - continue; - if (*pe == EOS) { - /* - * We could not find a matching RBRACKET. - * Ignore and just look for RBRACE - */ - pe = pm; - } - } - else if (*pe == LBRACE) - i++; - else if (*pe == RBRACE) { - if (i == 0) - break; - i--; - } - - /* Non matching braces; just glob the pattern */ - if (i != 0 || *pe == EOS) { - *rv = glob0(patbuf, pglob); - return 0; - } - - for (i = 0, pl = pm = ptr; pm <= pe; pm++) - switch (*pm) { - case LBRACKET: - /* Ignore everything between [] */ - for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) - continue; - if (*pm == EOS) { - /* - * We could not find a matching RBRACKET. - * Ignore and just look for RBRACE - */ - pm = pl; - } - break; - - case LBRACE: - i++; - break; - - case RBRACE: - if (i) { - i--; - break; - } - /* FALLTHROUGH */ - case COMMA: - if (i && *pm == COMMA) - break; - else { - /* Append the current string */ - for (lm = ls; (pl < pm); *lm++ = *pl++) - continue; - /* - * Append the rest of the pattern after the - * closing brace - */ - for (pl = pe + 1; (*lm++ = *pl++) != EOS;) - continue; - - /* Expand the current pattern */ -#ifdef DEBUG - qprintf("globexp2:", patbuf); -#endif - *rv = globexp1(patbuf, pglob); - - /* move after the comma, to the next string */ - pl = pm + 1; - } - break; - - default: - break; - } - *rv = 0; - return 0; -} - - - -/* - * expand tilde from the passwd file. - */ -static const Char * -globtilde(pattern, patbuf, pglob) - const Char *pattern; - Char *patbuf; - glob_t *pglob; -{ - struct passwd *pwd; - char *h; - const Char *p; - Char *b; - - if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) - return pattern; - - /* Copy up to the end of the string or / */ - for (p = pattern + 1, h = (char *) patbuf; *p && *p != SLASH; - *h++ = *p++) - continue; - - *h = EOS; - - if (((char *) patbuf)[0] == EOS) { - /* - * handle a plain ~ or ~/ by expanding $HOME - * first and then trying the password file - */ - if ((h = getenv("HOME")) == NULL) { - if ((pwd = getpwuid(getuid())) == NULL) - return pattern; - else - h = pwd->pw_dir; - } - } - else { - /* - * Expand a ~user - */ - if ((pwd = getpwnam((char*) patbuf)) == NULL) - return pattern; - else - h = pwd->pw_dir; - } - - /* Copy the home directory */ - for (b = patbuf; *h; *b++ = *h++) - continue; - - /* Append the rest of the pattern */ - while ((*b++ = *p++) != EOS) - continue; - - return patbuf; -} - - -/* - * The main glob() routine: compiles the pattern (optionally processing - * quotes), calls glob1() to do the real pattern matching, and finally - * sorts the list (unless unsorted operation is requested). Returns 0 - * if things went well, nonzero if errors occurred. It is not an error - * to find no matches. - */ -static int -glob0(pattern, pglob) - const Char *pattern; - glob_t *pglob; -{ - const Char *qpatnext; - int c, err, oldpathc; - Char *bufnext, patbuf[MAXPATHLEN+1]; - - qpatnext = globtilde(pattern, patbuf, pglob); - oldpathc = pglob->gl_pathc; - bufnext = patbuf; - - /* We don't need to check for buffer overflow any more. */ - while ((c = *qpatnext++) != EOS) { - switch (c) { - case LBRACKET: - c = *qpatnext; - if (c == NOT) - ++qpatnext; - if (*qpatnext == EOS || - g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) { - *bufnext++ = LBRACKET; - if (c == NOT) - --qpatnext; - break; - } - *bufnext++ = M_SET; - if (c == NOT) - *bufnext++ = M_NOT; - c = *qpatnext++; - do { - *bufnext++ = CHAR(c); - if (*qpatnext == RANGE && - (c = qpatnext[1]) != RBRACKET) { - *bufnext++ = M_RNG; - *bufnext++ = CHAR(c); - qpatnext += 2; - } - } while ((c = *qpatnext++) != RBRACKET); - pglob->gl_flags |= GLOB_MAGCHAR; - *bufnext++ = M_END; - break; - case QUESTION: - pglob->gl_flags |= GLOB_MAGCHAR; - *bufnext++ = M_ONE; - break; - case STAR: - pglob->gl_flags |= GLOB_MAGCHAR; - /* collapse adjacent stars to one, - * to avoid exponential behavior - */ - if (bufnext == patbuf || bufnext[-1] != M_ALL) - *bufnext++ = M_ALL; - break; - default: - *bufnext++ = CHAR(c); - break; - } - } - *bufnext = EOS; -#ifdef DEBUG - qprintf("glob0:", patbuf); -#endif - - if ((err = glob1(patbuf, pglob)) != 0) - return(err); - - /* - * If there was no match we are going to append the pattern - * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified - * and the pattern did not contain any magic characters - * GLOB_NOMAGIC is there just for compatibility with csh. - */ - if (pglob->gl_pathc == oldpathc && - ((pglob->gl_flags & GLOB_NOCHECK) || - ((pglob->gl_flags & GLOB_NOMAGIC) && - !(pglob->gl_flags & GLOB_MAGCHAR)))) - return(globextend(pattern, pglob)); - else if (!(pglob->gl_flags & GLOB_NOSORT)) - qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, - pglob->gl_pathc - oldpathc, sizeof(char *), compare); - return(0); -} - -static int -compare(p, q) - const void *p, *q; -{ - return(strcmp(*(char **)p, *(char **)q)); -} - -static int -glob1(pattern, pglob) - Char *pattern; - glob_t *pglob; -{ - Char pathbuf[MAXPATHLEN+1]; - - /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ - if (*pattern == EOS) - return(0); - return(glob2(pathbuf, pathbuf, pattern, pglob)); -} - -/* - * The functions glob2 and glob3 are mutually recursive; there is one level - * of recursion for each segment in the pattern that contains one or more - * meta characters. - */ -static int -glob2(pathbuf, pathend, pattern, pglob) - Char *pathbuf, *pathend, *pattern; - glob_t *pglob; -{ - struct stat sb; - Char *p, *q; - int anymeta; - - /* - * Loop over pattern segments until end of pattern or until - * segment with meta character found. - */ - for (anymeta = 0;;) { - if (*pattern == EOS) { /* End of pattern? */ - *pathend = EOS; - if (g_lstat(pathbuf, &sb, pglob)) - return(0); - - if (((pglob->gl_flags & GLOB_MARK) && - pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) -#ifdef S_ISLNK - || (S_ISLNK(sb.st_mode) && -#else - || ( (sb.st_mode&S_IFLNK) && -#endif - (g_stat(pathbuf, &sb, pglob) == 0) && - S_ISDIR(sb.st_mode)))) { - *pathend++ = SEP; - *pathend = EOS; - } - ++pglob->gl_matchc; - return(globextend(pathbuf, pglob)); - } - - /* Find end of next segment, copy tentatively to pathend. */ - q = pathend; - p = pattern; - while (*p != EOS && *p != SEP) { - if (ismeta(*p)) - anymeta = 1; - *q++ = *p++; - } - - if (!anymeta) { /* No expansion, do next segment. */ - pathend = q; - pattern = p; - while (*pattern == SEP) - *pathend++ = *pattern++; - } else /* Need expansion, recurse. */ - return(glob3(pathbuf, pathend, pattern, p, pglob)); - } - /* NOTREACHED */ -} - -static int -glob3(pathbuf, pathend, pattern, restpattern, pglob) - Char *pathbuf, *pathend, *pattern, *restpattern; - glob_t *pglob; -{ - register struct dirent *dp; - DIR *dirp; - int err; - char buf[MAXPATHLEN]; - - /* - * The readdirfunc declaration can't be prototyped, because it is - * assigned, below, to two functions which are prototyped in glob.h - * and dirent.h as taking pointers to differently typed opaque - * structures. - */ - struct dirent *(*readdirfunc)(); - - *pathend = EOS; - errno = 0; - - if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { - /* TODO: don't call for ENOENT or ENOTDIR? */ - if (pglob->gl_errfunc) { - g_Ctoc(pathbuf, buf); - if (pglob->gl_errfunc(buf, errno) || - pglob->gl_flags & GLOB_ERR) - return (GLOB_ABEND); - } - return(0); - } - - err = 0; - - /* Search directory for matching names. */ - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - readdirfunc = pglob->gl_readdir; - else - readdirfunc = readdir; - while ((dp = (*readdirfunc)(dirp))) { - register u_char *sc; - register Char *dc; - - /* Initial DOT must be matched literally. */ - if (dp->d_name[0] == DOT && *pattern != DOT) - continue; - for (sc = (u_char *) dp->d_name, dc = pathend; - (*dc++ = *sc++) != EOS;) - continue; - if (!match(pathend, pattern, restpattern)) { - *pathend = EOS; - continue; - } - err = glob2(pathbuf, --dc, restpattern, pglob); - if (err) - break; - } - - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - (*pglob->gl_closedir)(dirp); - else - closedir(dirp); - return(err); -} - - -/* - * Extend the gl_pathv member of a glob_t structure to accomodate a new item, - * add the new item, and update gl_pathc. - * - * This assumes the BSD realloc, which only copies the block when its size - * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic - * behavior. - * - * Return 0 if new item added, error code if memory couldn't be allocated. - * - * Invariant of the glob_t structure: - * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and - * gl_pathv points to (gl_offs + gl_pathc + 1) items. - */ -static int -globextend(path, pglob) - const Char *path; - glob_t *pglob; -{ - register char **pathv; - register int i; - u_int newsize; - char *copy; - const Char *p; - - newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); - pathv = pglob->gl_pathv ? - realloc((char *)pglob->gl_pathv, newsize) : - malloc(newsize); - if (pathv == NULL) - return(GLOB_NOSPACE); - - if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { - /* first time around -- clear initial gl_offs items */ - pathv += pglob->gl_offs; - for (i = pglob->gl_offs; --i >= 0; ) - *--pathv = NULL; - } - pglob->gl_pathv = pathv; - - for (p = path; *p++;) - continue; - if ((copy = malloc(p - path)) != NULL) { - g_Ctoc(path, copy); - pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; - } - pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; - return(copy == NULL ? GLOB_NOSPACE : 0); -} - - -/* - * pattern matching function for filenames. Each occurrence of the * - * pattern causes a recursion level. - */ -static int -match(name, pat, patend) - register Char *name, *pat, *patend; -{ - int ok, negate_range; - Char c, k; - - while (pat < patend) { - c = *pat++; - switch (c & M_MASK) { - case M_ALL: - if (pat == patend) - return(1); - do - if (match(name, pat, patend)) - return(1); - while (*name++ != EOS); - return(0); - case M_ONE: - if (*name++ == EOS) - return(0); - break; - case M_SET: - ok = 0; - if ((k = *name++) == EOS) - return(0); - if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) - ++pat; - while (((c = *pat++) & M_MASK) != M_END) - if ((*pat & M_MASK) == M_RNG) { - if (c <= k && k <= pat[1]) - ok = 1; - pat += 2; - } else if (c == k) - ok = 1; - if (ok == negate_range) - return(0); - break; - default: - if (*name++ != c) - return(0); - break; - } - } - return(*name == EOS); -} - -/* Free allocated data belonging to a glob_t structure. */ -void -globfree(pglob) - glob_t *pglob; -{ - register int i; - register char **pp; - - if (pglob->gl_pathv != NULL) { - pp = pglob->gl_pathv + pglob->gl_offs; - for (i = pglob->gl_pathc; i--; ++pp) - if (*pp) - free(*pp); - free(pglob->gl_pathv); - } -} - -static DIR * -g_opendir(str, pglob) - register Char *str; - glob_t *pglob; -{ - char buf[MAXPATHLEN]; - - if (!*str) - strcpy(buf, "."); - else - g_Ctoc(str, buf); - - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_opendir)(buf)); - - return(opendir(buf)); -} - -static int -g_lstat(fn, sb, pglob) - register Char *fn; - struct stat *sb; - glob_t *pglob; -{ - char buf[MAXPATHLEN]; - - g_Ctoc(fn, buf); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_lstat)(buf, sb)); - return(lstat(buf, sb)); -} - -static int -g_stat(fn, sb, pglob) - register Char *fn; - struct stat *sb; - glob_t *pglob; -{ - char buf[MAXPATHLEN]; - - g_Ctoc(fn, buf); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_stat)(buf, sb)); - return(stat(buf, sb)); -} - -static Char * -g_strchr(str, ch) - Char *str; - int ch; -{ - do { - if (*str == ch) - return (str); - } while (*str++); - return (NULL); -} - -#ifdef notdef -static Char * -g_strcat(dst, src) - Char *dst; - const Char* src; -{ - Char *sdst = dst; - - while (*dst++) - continue; - --dst; - while((*dst++ = *src++) != EOS) - continue; - - return (sdst); -} -#endif - -static void -g_Ctoc(str, buf) - register const Char *str; - char *buf; -{ - register char *dc; - - for (dc = buf; (*dc++ = *str++) != EOS;) - continue; -} - -#ifdef DEBUG -static void -qprintf(str, s) - const char *str; - register Char *s; -{ - register Char *p; - - (void)printf("%s:\n", str); - for (p = s; *p; p++) - (void)printf("%c", CHAR(*p)); - (void)printf("\n"); - for (p = s; *p; p++) - (void)printf("%c", *p & M_PROTECT ? '"' : ' '); - (void)printf("\n"); - for (p = s; *p; p++) - (void)printf("%c", ismeta(*p) ? '_' : ' '); - (void)printf("\n"); -} -#endif diff --git a/lib/libftp/utils/glob.h b/lib/libftp/utils/glob.h deleted file mode 100644 index b0432b7..0000000 --- a/lib/libftp/utils/glob.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)glob.h 8.1 (Berkeley) 6/2/93 - */ - -#ifndef _GLOB_H_ -#define _GLOB_H_ - - -#include <cdefs.h> - -struct stat; -typedef struct { - int gl_pathc; /* Count of total paths so far. */ - int gl_matchc; /* Count of paths matching pattern. */ - int gl_offs; /* Reserved at beginning of gl_pathv. */ - int gl_flags; /* Copy of flags parameter to glob. */ - char **gl_pathv; /* List of paths matching pattern. */ - /* Copy of errfunc parameter to glob. */ - int (*gl_errfunc) __P((const char *, int)); - - /* - * Alternate filesystem access methods for glob; replacement - * versions of closedir(3), readdir(3), opendir(3), stat(2) - * and lstat(2). - */ - void (*gl_closedir) __P((void *)); - struct dirent *(*gl_readdir) __P((void *)); - void *(*gl_opendir) __P((const char *)); - int (*gl_lstat) __P((const char *, struct stat *)); - int (*gl_stat) __P((const char *, struct stat *)); -} glob_t; - -#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ -#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ -#define GLOB_ERR 0x0004 /* Return on error. */ -#define GLOB_MARK 0x0008 /* Append / to matching directories. */ -#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ -#define GLOB_NOSORT 0x0020 /* Don't sort. */ - -#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ -#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ -#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ -#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ -#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ -#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ - -#define GLOB_NOSPACE (-1) /* Malloc call failed. */ -#define GLOB_ABEND (-2) /* Unignored error. */ - -__BEGIN_DECLS -int glob __P((const char *, int, int (*)(const char *, int), glob_t *)); -void globfree __P((glob_t *)); -__END_DECLS - -#endif /* !_GLOB_H_ */ diff --git a/lib/libftp/utils/mirror.c b/lib/libftp/utils/mirror.c deleted file mode 100644 index a0d329c..0000000 --- a/lib/libftp/utils/mirror.c +++ /dev/null @@ -1,92 +0,0 @@ - -/* Mirror directrory structure to another host */ - - -#include <stdio.h> -#include <sys/types.h> -#include <sys/dir.h> -#include <sys/stat.h> -#include <syslog.h> -#include <FtpLibrary.h> - -/* Usage: mirror <local_dir> <host> <user> <passwd> <remote_dir> */ -FTP *ftp; - -main(int a,char **b) -{ - -#define LOCAL_DIR b[1] -#define HOST b[2] -#define USER b[3] -#define PASSWD b[4] -#define REMOTE_DIR b[5] - - if ( a < 5 ) - quit("Usage: mirror <local_dir> <host> <user> <passwd> <remote_dir>"); - - - FtplibDebug(yes); - FtpLogin(&ftp,HOST,USER,PASSWD,NULL); - FtpChdir(ftp,REMOTE_DIR); - FtpBinary(ftp); - doit(LOCAL_DIR); - exit(0); -} - -doit(char *dirname) -{ - DIR *dp; - struct direct *de; - char n[256],fn[256]; - struct stat st; - - - if ( (dp=opendir(dirname)) == NULL ) - { - log(dirname); - return; - } - - while ( (de = readdir(dp)) != NULL ) - { - if ( de -> d_name[0] == '.' ) - continue; - - sprintf(fn,"%s/%s",dirname,de->d_name); - - if ( stat(fn,&st) != 0 ) { - log(fn); - continue; - } - - if ( S_ISDIR (st.st_mode) ) - { - FtpCommand(ftp,"MKD %s",fn,0,EOF); /* Ignore errors (0,EOF) */ - doit(fn); - continue; - } - - if ( st.st_size != FtpSize(ftp,fn)) - - FtpPut(ftp,fn,fn); - } - - closedir(dp); - -} - - - -quit(char *s) -{ - log(s); - exit(1); -} - -log(char *s) -{ - perror(s); -} - - - diff --git a/lib/libftp/utils/readline.c b/lib/libftp/utils/readline.c deleted file mode 100644 index e019bc1..0000000 --- a/lib/libftp/utils/readline.c +++ /dev/null @@ -1,961 +0,0 @@ -#ifndef lint -static char *RCSid = "$Id: readline.c,v 1.1.1.1 1995/04/25 15:05:09 jkh Exp $"; -#endif - - -/* GNUPLOT - readline.c */ -/* - * Copyright (C) 1986 - 1993 Thomas Williams, Colin Kelley - * - * Permission to use, copy, and distribute this software and its - * documentation for any purpose with or without fee is hereby granted, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - * - * Permission to modify the software is granted, but not the right to - * distribute the modified code. Modifications are to be distributed - * as patches to released version. - * - * This software is provided "as is" without express or implied warranty. - * - * - * AUTHORS - * - * Original Software: - * Tom Tkacik - * - * Msdos port and some enhancements: - * Gershon Elber and many others. - * - * There is a mailing list for gnuplot users. Note, however, that the - * newsgroup - * comp.graphics.gnuplot - * is identical to the mailing list (they - * both carry the same set of messages). We prefer that you read the - * messages through that newsgroup, to subscribing to the mailing list. - * (If you can read that newsgroup, and are already on the mailing list, - * please send a message info-gnuplot-request@dartmouth.edu, asking to be - * removed from the mailing list.) - * - * The address for mailing to list members is - * info-gnuplot@dartmouth.edu - * and for mailing administrative requests is - * info-gnuplot-request@dartmouth.edu - * The mailing list for bug reports is - * bug-gnuplot@dartmouth.edu - * The list of those interested in beta-test versions is - * info-gnuplot-beta@dartmouth.edu - */ - -#ifdef READLINE -#ifdef ATARI -#include "plot.h" -#endif -#ifdef _WINDOWS -#define _Windows -#endif - -/* a small portable version of GNU's readline */ -/* this is not the BASH or GNU EMACS version of READLINE due to Copyleft - restrictions */ -/* do not need any terminal capabilities except backspace, */ -/* and space overwrites a character */ - -/* NANO-EMACS line editing facility */ -/* printable characters print as themselves (insert not overwrite) */ -/* ^A moves to the beginning of the line */ -/* ^B moves back a single character */ -/* ^E moves to the end of the line */ -/* ^F moves forward a single character */ -/* ^K kills from current position to the end of line */ -/* ^P moves back through history */ -/* ^N moves forward through history */ -/* ^H and DEL delete the previous character */ -/* ^D deletes the current character, or EOF if line is empty */ -/* ^L/^R redraw line in case it gets trashed */ -/* ^U kills the entire line */ -/* ^W kills last word */ -/* LF and CR return the entire line regardless of the cursor postition */ -/* EOF with an empty line returns (char *)NULL */ - -/* all other characters are ignored */ - -#include <stdio.h> -#include <ctype.h> -#include <signal.h> - -#if !defined(MSDOS) && !defined(ATARI) && !defined(_Windows) && !defined(DOS386) - -/* - * Set up structures using the proper include file - */ -#if defined(_IBMR2) || defined(alliant) -#define SGTTY -#endif - -/* submitted by Francois.Dagorn@cicb.fr */ -#ifdef SGTTY -#include <sgtty.h> -static struct sgttyb orig_termio, rl_termio; -/* define terminal control characters */ -static struct tchars s_tchars; -#define VERASE 0 -#define VEOF 1 -#define VKILL 2 -#ifdef TIOCGLTC /* available only with the 'new' line discipline */ -static struct ltchars s_ltchars; -#define VWERASE 3 -#define VREPRINT 4 -#define VSUSP 5 -#endif /* TIOCGLTC */ -#define NCCS 6 - -#else /* SGTTY */ - -/* SIGTSTP defines job control */ -/* if there is job control then we need termios.h instead of termio.h */ -/* (Are there any systems with job control that use termio.h? I hope not.) */ -#ifdef SIGTSTP -#define TERMIOS -#include <termios.h> -/* Added by Robert Eckardt, RobertE@beta.TP2.Ruhr-Uni-Bochum.de */ -#ifdef ISC22 -#ifndef ONOCR /* taken from sys/termio.h */ -#define ONOCR 0000020 /* true at least for ISC 2.2 */ -#endif -#ifndef IUCLC -#define IUCLC 0001000 -#endif -#endif /* ISC22 */ - -static struct termios orig_termio, rl_termio; -#else -#include <termio.h> -static struct termio orig_termio, rl_termio; -/* termio defines NCC instead of NCCS */ -#define NCCS NCC -#endif /* SIGTSTP */ -#endif /* SGTTY */ - -/* ULTRIX defines VRPRNT instead of VREPRINT */ -#ifdef VRPRNT -#define VREPRINT VRPRNT -#endif - -/* define characters to use with our input character handler */ -static char term_chars[NCCS]; - -static int term_set = 0; /* =1 if rl_termio set */ - -#define special_getc() ansi_getc() -static char ansi_getc(); - -#else /* !MSDOS && !ATARI && !_Windows */ - -#ifdef _Windows -#include <windows.h> -#include "win/wtext.h" -#include "win/wgnuplib.h" -extern TW textwin; -#define TEXTUSER 0xf1 -#define TEXTGNUPLOT 0xf0 -#define special_getc() msdos_getch() -static char msdos_getch(); -#endif - -#if defined(MSDOS) || defined(DOS386) -/* MSDOS specific stuff */ -#ifdef DJGPP -#include <pc.h> -#endif -#ifdef __EMX__ -#include <conio.h> -#endif -#define special_getc() msdos_getch() -static char msdos_getch(); -#endif /* MSDOS */ - -#ifdef ATARI -#include <stdlib.h> -#ifdef __PUREC__ -#include <tos.h> -#else -#include <osbind.h> -#endif -#define special_getc() tos_getch() -static char tos_getch(); -#endif - -#endif /* !MSDOS && !ATARI && !_Windows */ - -#if !defined(ATARI) -/* is it <string.h> or <strings.h>? just declare what we need */ -extern int strlen(); -extern char *strcpy(); -#endif -#define alloc malloc -extern char *alloc(); /* we'll use the safe malloc from misc.c */ - -#define MAXBUF 1024 -#define BACKSPACE 0x08 /* ^H */ -#define SPACE ' ' - -struct hist { - char *line; - struct hist *prev; - struct hist *next; -}; - -static struct hist *history = NULL; /* no history yet */ -static struct hist *cur_entry = NULL; - -static char cur_line[MAXBUF]; /* current contents of the line */ -static int cur_pos = 0; /* current position of the cursor */ -static int max_pos = 0; /* maximum character position */ - - -void add_history(); -static void fix_line(); -static void redraw_line(); -static void clear_line(); -static void clear_eoline(); -static void copy_line(); -static void set_termio(); -void reset_termio(); - -/* user_putc and user_puts should be used in the place of - * fputc(ch,stderr) and fputs(str,stderr) for all output - * of user typed characters. This allows MS-Windows to - * display user input in a different color. */ -int -user_putc(ch) -int ch; -{ - int rv; -#ifdef _Windows - TextAttr(&textwin,TEXTUSER); -#endif - rv = fputc(ch, stderr); -#ifdef _Windows - TextAttr(&textwin,TEXTGNUPLOT); -#endif - return rv; -} - -int -user_puts(str) -char *str; -{ - int rv; -#ifdef _Windows - TextAttr(&textwin,TEXTUSER); -#endif - rv = fputs(str, stderr); -#ifdef _Windows - TextAttr(&textwin,TEXTGNUPLOT); -#endif - return rv; -} - -/* This function provides a centralized non-destructive backspace capability */ -/* M. Castro */ - -backspace() -{ - user_putc(BACKSPACE); -} - -char * -readline(prompt) -char *prompt; -{ - - unsigned char cur_char; - char *new_line; - /* unsigned char *new_line; */ - - /* set the termio so we can do our own input processing */ - set_termio(); - - /* print the prompt */ - fputs(prompt, stderr); - cur_line[0] = '\0'; - cur_pos = 0; - max_pos = 0; - cur_entry = NULL; - - /* get characters */ - for(;;) { - cur_char = special_getc(); -#ifdef OS2 - /* for emx: remap scan codes for cursor keys */ - if( cur_char == 0 ) { - cur_char = getc(stdin); - switch( cur_char){ - case 75: /* left, map to ^B */ - cur_char=2; - break ; - case 77: /* right, map to ^F */ - cur_char=6; - break ; - case 115: /* ctrl left */ - case 71: /* home, map to ^A */ - cur_char=1; - break ; - case 116: /* ctrl right */ - case 79: /* end, map to ^E */ - cur_char=5; - break ; - case 72: /* up, map to ^P */ - cur_char=16; - break ; - case 80: /* down, map to ^N */ - cur_char=14; - break ; - case 83: /* delete, map to ^D */ - cur_char=4; - break ; - default: /* ignore */ - cur_char=0; - continue ; - } - } -#endif /*OS2*/ - if((isprint(cur_char) -#if defined(ATARI) || defined(_Windows) || defined(MSDOS) || defined(DOS386) - /* this should be used for all 8bit ASCII machines, I guess */ - || ((unsigned char)cur_char > 0x7f) -#endif - )&& max_pos<MAXBUF-1) { - int i; - for(i=max_pos; i>cur_pos; i--) { - cur_line[i] = cur_line[i-1]; - } - user_putc(cur_char); - cur_line[cur_pos] = cur_char; - cur_pos += 1; - max_pos += 1; - if (cur_pos < max_pos) - fix_line(); - cur_line[max_pos] = '\0'; - - /* else interpret unix terminal driver characters */ -#ifdef VERASE - } else if(cur_char == term_chars[VERASE] ){ /* DEL? */ - if(cur_pos > 0) { - int i; - cur_pos -= 1; - backspace(); - for(i=cur_pos; i<max_pos; i++) - cur_line[i] = cur_line[i+1]; - max_pos -= 1; - fix_line(); - } -#endif /* VERASE */ -#ifdef VEOF - } else if(cur_char == term_chars[VEOF] ){ /* ^D? */ - if(max_pos == 0) { - reset_termio(); - return((char *)NULL); - } - if((cur_pos < max_pos)&&(cur_char == 004)) { /* ^D */ - int i; - for(i=cur_pos; i<max_pos; i++) - cur_line[i] = cur_line[i+1]; - max_pos -= 1; - fix_line(); - } -#endif /* VEOF */ -#ifdef VKILL - } else if(cur_char == term_chars[VKILL] ){ /* ^U? */ - clear_line(prompt); -#endif /* VKILL */ -#ifdef VWERASE - } else if(cur_char == term_chars[VWERASE] ){ /* ^W? */ - while((cur_pos > 0) && - (cur_line[cur_pos-1] == SPACE)) { - cur_pos -= 1; - backspace(); - } - while((cur_pos > 0) && - (cur_line[cur_pos-1] != SPACE)) { - cur_pos -= 1; - backspace(); - } - clear_eoline(); - max_pos = cur_pos; -#endif /* VWERASE */ -#ifdef VREPRINT - } else if(cur_char == term_chars[VREPRINT] ){ /* ^R? */ - putc('\n',stderr); /* go to a fresh line */ - redraw_line(prompt); -#endif /* VREPRINT */ -#ifdef VSUSP - } else if(cur_char == term_chars[VSUSP]) { - reset_termio(); - kill(0, SIGTSTP); - - /* process stops here */ - - set_termio(); - /* print the prompt */ - redraw_line(prompt); -#endif /* VSUSP */ - } else { - /* do normal editing commands */ - /* some of these are also done above */ - int i; - switch(cur_char) { - case EOF: - reset_termio(); - return((char *)NULL); - case 001: /* ^A */ - while(cur_pos > 0) { - cur_pos -= 1; - backspace(); - } - break; - case 002: /* ^B */ - if(cur_pos > 0) { - cur_pos -= 1; - backspace(); - } - break; - case 005: /* ^E */ - while(cur_pos < max_pos) { - user_putc(cur_line[cur_pos]); - cur_pos += 1; - } - break; - case 006: /* ^F */ - if(cur_pos < max_pos) { - user_putc(cur_line[cur_pos]); - cur_pos += 1; - } - break; - case 013: /* ^K */ - clear_eoline(); - max_pos = cur_pos; - break; - case 020: /* ^P */ - if(history != NULL) { - if(cur_entry == NULL) { - cur_entry = history; - clear_line(prompt); - copy_line(cur_entry->line); - } else if(cur_entry->prev != NULL) { - cur_entry = cur_entry->prev; - clear_line(prompt); - copy_line(cur_entry->line); - } - } - break; - case 016: /* ^N */ - if(cur_entry != NULL) { - cur_entry = cur_entry->next; - clear_line(prompt); - if(cur_entry != NULL) - copy_line(cur_entry->line); - else - cur_pos = max_pos = 0; - } - break; - case 014: /* ^L */ - case 022: /* ^R */ - putc('\n',stderr); /* go to a fresh line */ - redraw_line(prompt); - break; - case 0177: /* DEL */ - case 010: /* ^H */ - if(cur_pos > 0) { - cur_pos -= 1; - backspace(); - for(i=cur_pos; i<max_pos; i++) - cur_line[i] = cur_line[i+1]; - max_pos -= 1; - fix_line(); - } - break; - case 004: /* ^D */ - if(max_pos == 0) { - reset_termio(); - return((char *)NULL); - } - if(cur_pos < max_pos) { - for(i=cur_pos; i<max_pos; i++) - cur_line[i] = cur_line[i+1]; - max_pos -= 1; - fix_line(); - } - break; - case 025: /* ^U */ - clear_line(prompt); - break; - case 027: /* ^W */ - while((cur_pos > 0) && - (cur_line[cur_pos-1] == SPACE)) { - cur_pos -= 1; - backspace(); - } - while((cur_pos > 0) && - (cur_line[cur_pos-1] != SPACE)) { - cur_pos -= 1; - backspace(); - } - clear_eoline(); - max_pos = cur_pos; - break; - case '\n': /* ^J */ - case '\r': /* ^M */ - cur_line[max_pos+1] = '\0'; - putc('\n', stderr); - new_line = (char *)alloc((unsigned long) (strlen(cur_line)+1), "history"); - strcpy(new_line,cur_line); - reset_termio(); - return(new_line); - default: - break; - } - } - } -} - -/* fix up the line from cur_pos to max_pos */ -/* do not need any terminal capabilities except backspace, */ -/* and space overwrites a character */ -static void -fix_line() -{ - int i; - - /* write tail of string */ - for(i=cur_pos; i<max_pos; i++) - user_putc(cur_line[i]); - - /* write a space at the end of the line in case we deleted one */ - user_putc(SPACE); - - /* backup to original position */ - for(i=max_pos+1; i>cur_pos; i--) - backspace(); - -} - -/* redraw the entire line, putting the cursor where it belongs */ -static void -redraw_line(prompt) -char *prompt; -{ - int i; - - fputs(prompt, stderr); - user_puts(cur_line); - - /* put the cursor where it belongs */ - for(i=max_pos; i>cur_pos; i--) - backspace(); -} - -/* clear cur_line and the screen line */ -static void -clear_line(prompt) -char *prompt; -{ - int i; - for(i=0; i<max_pos; i++) - cur_line[i] = '\0'; - - for(i=cur_pos; i>0; i--) - backspace(); - - for(i=0; i<max_pos; i++) - putc(SPACE, stderr); - - putc('\r', stderr); - fputs(prompt, stderr); - - cur_pos = 0; - max_pos = 0; -} - -/* clear to end of line and the screen end of line */ -static void -clear_eoline(prompt) -char *prompt; -{ - int i; - for(i=cur_pos; i<max_pos; i++) - cur_line[i] = '\0'; - - for(i=cur_pos; i<max_pos; i++) - putc(SPACE, stderr); - for(i=cur_pos; i<max_pos; i++) - backspace(); -} - -/* copy line to cur_line, draw it and set cur_pos and max_pos */ -static void -copy_line(line) -char *line; -{ - strcpy(cur_line, line); - user_puts(cur_line); - cur_pos = max_pos = strlen(cur_line); -} - -/* add line to the history */ -void -add_history(line) -char *line; -{ - struct hist *entry; - entry = (struct hist *)alloc((unsigned long)sizeof(struct hist),"history"); - entry->line = alloc((unsigned long)(strlen(line)+1),"history"); - strcpy(entry->line, line); - - entry->prev = history; - entry->next = NULL; - if(history != NULL) { - history->next = entry; - } - history = entry; -} - - -/* Convert ANSI arrow keys to control characters */ -static char -ansi_getc() -{ - char c = getc(stdin); - if (c == 033) { - c = getc(stdin); /* check for CSI */ - if (c == '[') { - c = getc(stdin); /* get command character */ - switch (c) { - case 'D': /* left arrow key */ - c = 002; - break; - case 'C': /* right arrow key */ - c = 006; - break; - case 'A': /* up arrow key */ - c = 020; - break; - case 'B': /* down arrow key */ - c = 016; - break; - } - } - } - return c; -} - -#if defined(MSDOS) || defined(_Windows) || defined(DOS386) - -/* Convert Arrow keystrokes to Control characters: */ -static char -msdos_getch() -{ -#ifdef DJGPP - char c; - int ch = getkey(); - c = (ch & 0xff00) ? 0 : ch & 0xff; -#else - char c = getch(); -#endif - - if (c == 0) { -#ifdef DJGPP - c = ch & 0xff; -#else - c = getch(); /* Get the extended code. */ -#endif - switch (c) { - case 75: /* Left Arrow. */ - c = 002; - break; - case 77: /* Right Arrow. */ - c = 006; - break; - case 72: /* Up Arrow. */ - c = 020; - break; - case 80: /* Down Arrow. */ - c = 016; - break; - case 115: /* Ctl Left Arrow. */ - case 71: /* Home */ - c = 001; - break; - case 116: /* Ctl Right Arrow. */ - case 79: /* End */ - c = 005; - break; - case 83: /* Delete */ - c = 004; - break; - default: - c = 0; - break; - } - } - else if (c == 033) { /* ESC */ - c = 025; - } - - - return c; -} - -#endif /* MSDOS */ - -#ifdef ATARI - -/* Convert Arrow keystrokes to Control characters: TOS version */ - -/* the volatile could be necessary to keep gcc from reordering - the two Super calls -*/ -#define CONTERM ((/*volatile*/ char *)0x484L) - -static void -remove_conterm() -{ - void *ssp=(void*)Super(0L); - *CONTERM &= ~0x8; - Super(ssp); -} - -static char -tos_getch() -{ - long rawkey; - char c; - int scan_code; - void *ssp; - static int init = 1; - static int in_help = 0; - - if (in_help) { - switch(in_help) { - case 1: - case 5: in_help++; return 'e'; - case 2: - case 6: in_help++; return 'l'; - case 3: - case 7: in_help++; return 'p'; - case 4: in_help = 0; return 0x0d; - case 8: in_help = 0; return ' '; - } - } - - if (init) { - ssp = (void*)Super(0L); - if( !(*CONTERM & 0x8) ) { - *CONTERM |= 0x8; - } else { - init=0; - } - (void)Super(ssp); - if( init ) { - atexit(remove_conterm); - init = 0; - } - } - - (void)Cursconf(1, 0); /* cursor on */ - rawkey = Cnecin(); - c = (char)rawkey; - scan_code= ((int)(rawkey>>16)) & 0xff; /* get the scancode */ - if( rawkey&0x07000000 ) scan_code |= 0x80; /* shift or control */ - - switch (scan_code) { - case 0x62: /* HELP */ - if (max_pos==0) { - in_help = 1; - return 'h'; - } else { - return 0; - } - case 0xe2: /* shift HELP */ - if (max_pos==0) { - in_help = 5; - return 'h'; - } else { - return 0; - } - case 0x48: /* Up Arrow */ - return 0x10; /* ^P */ - case 0x50: /* Down Arrow */ - return 0x0e; /* ^N */ - case 0x4b: /* Left Arrow */ - return 0x02; /* ^B */ - case 0x4d: /* Right Arrow */ - return 0x06; /* ^F */ - case 0xcb: /* Shift Left Arrow */ - case 0xf3: /* Ctrl Left Arrow (TOS-bug ?) */ - case 0x47: /* Home */ - return 0x01; /* ^A */ - case 0xcd: /* Shift Right Arrow */ - case 0xf4: /* Ctrl Right Arrow (TOS-bug ?) */ - case 0xc7: /* Shift Home */ - case 0xf7: /* Crtl Home */ - return 0x05; /* ^E */ - case 0x61: /* Undo - redraw line */ - return 0x0c; /* ^L */ - default: - if (c == 0x1b) return 0x15; /* ESC becomes ^U */ - if (c == 0x7f) return 0x04; /* Del becomes ^D */ - break; - } - - return c; -} - -#endif /* ATARI */ - - /* set termio so we can do our own input processing */ -static void -set_termio() -{ -#if !defined(MSDOS) && !defined(ATARI) && !defined(_Windows) && !defined(DOS386) -/* set termio so we can do our own input processing */ -/* and save the old terminal modes so we can reset them later */ - if(term_set == 0) { - /* - * Get terminal modes. - */ -#ifdef SGTTY - ioctl(0, TIOCGETP, &orig_termio); -#else /* SGTTY */ -#ifdef TERMIOS -#ifdef TCGETS - ioctl(0, TCGETS, &orig_termio); -#else - tcgetattr(0, &orig_termio); -#endif /* TCGETS */ -#else - ioctl(0, TCGETA, &orig_termio); -#endif /* TERMIOS */ -#endif /* SGTTY */ - - /* - * Save terminal modes - */ - rl_termio = orig_termio; - - /* - * Set the modes to the way we want them - * and save our input special characters - */ -#ifdef SGTTY - rl_termio.sg_flags |= CBREAK; - rl_termio.sg_flags &= ~(ECHO|XTABS); - ioctl(0, TIOCSETN, &rl_termio); - - ioctl(0, TIOCGETC, &s_tchars); - term_chars[VERASE] = orig_termio.sg_erase; - term_chars[VEOF] = s_tchars.t_eofc; - term_chars[VKILL] = orig_termio.sg_kill; -#ifdef TIOCGLTC - ioctl(0, TIOCGLTC, &s_ltchars); - term_chars[VWERASE] = s_ltchars.t_werasc; - term_chars[VREPRINT] = s_ltchars.t_rprntc; - term_chars[VSUSP] = s_ltchars.t_suspc; - - /* disable suspending process on ^Z */ - s_ltchars.t_suspc = 0; - ioctl(0, TIOCSLTC, &s_ltchars); -#endif /* TIOCGLTC */ -#else /* SGTTY */ -#ifdef IUCLC - rl_termio.c_iflag &= ~(BRKINT|PARMRK|INPCK|IUCLC|IXON|IXOFF); -#else - rl_termio.c_iflag &= ~(BRKINT|PARMRK|INPCK|IXON|IXOFF); -#endif - rl_termio.c_iflag |= (IGNBRK|IGNPAR); - - /* rl_termio.c_oflag &= ~(ONOCR); Costas Sphocleous Irvine,CA */ - - rl_termio.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|NOFLSH); -#ifdef OS2 - /* for emx: remove default terminal processing */ - rl_termio.c_lflag &= ~(IDEFAULT); -#endif /* OS2 */ - rl_termio.c_lflag |= (ISIG); - rl_termio.c_cc[VMIN] = 1; - rl_termio.c_cc[VTIME] = 0; - -#ifndef VWERASE -#define VWERASE 3 -#endif - term_chars[VERASE] = orig_termio.c_cc[VERASE]; - term_chars[VEOF] = orig_termio.c_cc[VEOF]; - term_chars[VKILL] = orig_termio.c_cc[VKILL]; -#ifdef TERMIOS - term_chars[VWERASE] = orig_termio.c_cc[VWERASE]; -#ifdef VREPRINT - term_chars[VREPRINT] = orig_termio.c_cc[VREPRINT]; -#else -#ifdef VRPRNT - term_chars[VRPRNT] = orig_termio.c_cc[VRPRNT]; -#endif -#endif - term_chars[VSUSP] = orig_termio.c_cc[VSUSP]; - - /* disable suspending process on ^Z */ - rl_termio.c_cc[VSUSP] = 0; -#endif /* TERMIOS */ -#endif /* SGTTY */ - - /* - * Set the new terminal modes. - */ -#ifdef SGTTY - ioctl(0, TIOCSLTC, &s_ltchars); -#else -#ifdef TERMIOS -#ifdef TCSETSW - ioctl(0, TCSETSW, &rl_termio); -#else - tcsetattr(0, TCSADRAIN, &rl_termio); -#endif /* TCSETSW */ -#else - ioctl(0, TCSETAW, &rl_termio); -#endif /* TERMIOS */ -#endif /* SGTTY */ - term_set = 1; - } -#endif /* !MSDOS && !ATARI && !defined(_Windows) */ -} - -void -reset_termio() -{ -#if !defined(MSDOS) && !defined(ATARI) && !defined(_Windows) && !defined(DOS386) -/* reset saved terminal modes */ - if(term_set == 1) { -#ifdef SGTTY - ioctl(0, TIOCSETN, &orig_termio); -#ifdef TIOCGLTC - /* enable suspending process on ^Z */ - s_ltchars.t_suspc = term_chars[VSUSP]; - ioctl(0, TIOCSLTC, &s_ltchars); -#endif /* TIOCGLTC */ -#else /* SGTTY */ -#ifdef TERMIOS -#ifdef TCSETSW - ioctl(0, TCSETSW, &orig_termio); -#else - tcsetattr(0, TCSADRAIN, &orig_termio); -#endif /* TCSETSW */ -#else - ioctl(0, TCSETAW, &orig_termio); -#endif /* TERMIOS */ -#endif /* SGTTY */ - term_set = 0; - } -#endif /* !MSDOS && !ATARI && !_Windows */ -} -#endif /* READLINE */ diff --git a/lib/libftp/utils/uftp.c b/lib/libftp/utils/uftp.c deleted file mode 100644 index 4c8961f..0000000 --- a/lib/libftp/utils/uftp.c +++ /dev/null @@ -1,824 +0,0 @@ -/* File Transfer Protocol Toolkit based on libftp */ - -#include "uftp.h" -#include <varargs.h> - - -FTP *ftp[NFRAMES]; -LINKINFO iftp[NFRAMES]; -int frame=0; - - -int status; -jmp_buf start; -int lastcmd=0; -int glassmode=0; -int trymode=1; -int restmode=1; -int hashmode=0; -int sleeptime=30; -time_t noopinterval=0; -time_t nooptimeout=1; -time_t prevtime=0; - -String cmd; -String prompt="%T %u@%H:%d> "; -String defaultuser; - -ALIAS *firstalias=NULL; - -/* if main have any arguments, interprets each it as command with args */ - - -main(int argc, char **argv) - -{ - register int i; - register char *p1; - FILE *fp; - String tmp; - - if (setjmp(start)!=0) - goto main_loop; - - setsignals(); - - - - FtpSetErrorHandler(&FtpInit,my_error); - FtpSetIOHandler(&FtpInit,my_error); - - strcpy(defaultuser,getpwuid(getuid())->pw_name); - - - memset(ftp,0,sizeof(FTP*)*NFRAMES); - memset(iftp,0,sizeof(LINKINFO)*NFRAMES); - - - - batch(SYSTEMRC); - - if (access(getrcname(),F_OK)) - { - FILE *out=fdopen(open(getrcname(),O_WRONLY|O_CREAT|O_TRUNC,0700),"w"); - - printf("Create default rc-file \"%s\"\n",getrcname()); - - if (out==NULL) - perror(getrcname()); - - else - { - - fprintf(out,"set timeout 120\nset hash\nset debug\nset bin\n"); - fprintf(out,"set prompt \"%%T %%u@%%h:%%d\\> \"\n"); - fprintf(out,"alias a alias\na ed ! emacs\nalias tn ! telnet\n"); - - fclose(out); - } - } - - - batch(getrcname()); - batch(getaliasrcname()); - - - for (i=1, tmp[0]=0; i< argc; i++) - { - strcat(tmp,argv[i]); - if (i+1!=argc) strcat(tmp," "); - } - - if (tmp[0]!=0) - { - String new; - -/* - if (!strcmp(defaultuser,"ftp") || !strcmp(defaultuser,"anonymous")) - strcpy(new,"ftp "); - else -*/ - strcpy(new,"open "); - - if (ifalias(tmp)) - execute (tmp); - else - strcat(new,tmp), - execute(new); - } - - -main_loop: - - setsignals(); - - while (1) - { - - setjmp(start); - if (lastcmd) exit(0); - - - if (isatty(fileno(stdin))) - p1=readline(getprompt()); - else - p1=gets(cmd); - - if (p1==NULL) - { - putchar('\n'); - exit(0); - } - - strcpy(cmd,p1); - - if (cmd[0]) add_history(cmd); - execute(cmd); - } -} - -INLINE char *findspace(char *str) -{ - while ( !isspace(*str) && *str != '\0' ) str++; - return str; -} - - - -char *word(char *str, int n) -{ - String new; - register char *p1, *p2; - register int i; - - strcpy(new,str); - - p1=new; - - while (isspace(*p1)) p1++; - - if (n>1 ) - for (i=0;i<n-1;i++) /* Skip n-1 words */ - { - if ((*p1=='"')||(*p1=='\'')) - { - p1=strchr(p1+1,*p1); - if (p1==NULL) return ""; - p1++; - while ( isspace(*p1) ) p1++; - continue; - } - p1=findspace(p1); - if ( *p1=='\0' ) return ""; - p1++; - while ( isspace(*p1) ) p1++; - } - - if ((*p1=='"')|(*p1=='\'')) - { - p2=strchr(p1+1,*p1); - if (p2==NULL) return p1+1; - *p2=0; - return p1+1; - } - - if ((p2=findspace(p1)) != NULL ) - { - *p2=0; - return p1; - } - return ""; -} - - -/* Exacute few command separated by ';' . The character ' must use for mark complex - works*/ - -execute (char *cmd) -{ - String w1,w2,w3,w4,w5,w6; - String newcmd; - char *p; - - if (!*cmd || *cmd=='#' ) return; - - for ( p=newcmd ; *cmd; cmd++) - { - if ( *cmd == '\'' ) - { - *p++=*cmd++; - while ( *cmd != '\'' && *cmd != 0 ) *p++=*cmd++; - if ( *cmd == 0 ) - return puts("Unbalanced \', please corrected!\n"); - *p++=*cmd; - continue; - } - - if ( *cmd == ';' ) - { - *p=0; - execute(newcmd); - p=newcmd; - continue; - } - *p++=*cmd; - } - - - *p=0; - cmd=newcmd; - - if ( *cmd=='\\' ) - cmd++; - else - { - String new; - strcpy(new,"\\"); - strcat(new,expandalias(cmd)); - return execute(new); - } - - if ( *cmd == '!' ) - { - int pid,_pid; - int status; - - if (!(pid=fork())) - { - execlp((getenv("SHELL")==NULL)?"/bin/sh":(char *)getenv("SHELL"), - "shell","-c",cmd+1,NULL); - } - - while(1) - { - _pid=wait(&status); - if (_pid==pid) - return; - } - } - - - redir(cmd); - - if (cmd[strlen(cmd)-1]=='&') - { - String tmp; - - cmd[strlen(cmd)-1]=0; - - strcpy(tmp,"bg "); - strcat(tmp,cmd); - - strcpy(cmd,tmp); - } - - strcpy(w1,word(cmd,1)); - strcpy(w2,word(cmd,2)); - strcpy(w3,word(cmd,3)); - strcpy(w4,word(cmd,4)); - strcpy(w5,word(cmd,5)); - strcpy(w6,word(cmd,6)); - - return executev(w1,w2,w3,w4,w5,w6); -} - -executev(ARGS) -{ - CMDS *xcmd=&cmds[0]; - String tmp; - - if (isdigit(*w1)) - return - atoi(w1)<NFRAMES?frame=atoi(w1):0, - executev(w2,w3,w4,w5,w6,""); - - while ( xcmd -> cmd != NULL ) - { - if ( !strcmp(xcmd->cmd,w1) && (xcmd -> func != NULL) ) - { - int status; - - if ( xcmd -> need && LINK == NULL) - return puts("Need connection to server"); - iftp[frame].lock=1; unsetsignals(); - status = (*xcmd->func)(w1,w2,w3,w4,w5,w6); - iftp[frame].lock=0; setsignals(); - redirback(); - return status; - } - xcmd++; - } - - - if (LINK!=NULL && glassmode) - return FtpCommand(LINK,cmd,"",0,EOF); - - printf("%s: unknown command\n",w1); - fflush(stdout); - return -1; -} - - -void intr(int sig) -{ - printf("Interupted by signal %d\n",sig); - if (LINK!=NULL) FtpSetHashHandler(LINK,NULL); - setsignals(); - reset_termio(); /* From readline */ - prevtime = time((time_t *)0); - longjmp(start,1); -} - -newframe(int connecteble) -{ - register int i; - - if (connecteble) - for (i=0; i<NFRAMES; i++) if (ftp[i]!=NULL) return frame=i; - for (i=0; i<NFRAMES; i++) if (ftp[i]==NULL) return frame=i; - return -1; -} - -STATUS my_error(FTP *ftp, int code, char *msg) -{ - - if (code==LQUIT||(ftp==NULL)) log(msg); - else - FtpLog(ftp->title,msg); - - if ( abs(code) == 530 && (strstr(msg,"anonymous")!=NULL)) - { - Ftp_reopen(); - longjmp(start,1); - } - longjmp(start,1); -} - -char *getrcname() -{ - static String rcpath; - struct passwd *pwd=getpwuid(getuid()); - - sprintf(rcpath,"%s/.uftprc",pwd->pw_dir); - return rcpath; -} - -char *getaliasrcname() -{ - static String rcpath; - struct passwd *pwd=getpwuid(getuid()); - - sprintf(rcpath,"%s/.uftp_aliases",pwd->pw_dir); - return rcpath; -} - -char *makestr(va_alist) - va_dcl -{ - char *p1; - va_list args; - String new={0}; - - va_start(args); - - while(1) - { - p1=va_arg(args,char *); - if (p1==NULL) break; - if (*p1!=0) - { - if (new[0]!=0) strcat(new," "); - strcat(new,p1); - } - } - va_end(args); - return new; -} - - -#define ADD(str,chr) (*str++=chr,*str=0) - -INLINE ADDSTR(char **str, char *str1) -{ - while (*str1) *(*str)++=*str1++; -} - -char *expandalias(char *str) -{ - ALIAS *a=firstalias; - String new={0},w1={0}; - char *p,*p1=new,*args; - int dollar=0; - - strcpy(w1,word(str,1)); - - if ( (p=strchr(str,' '))!=NULL ) - args=p+1; - else - args=""; - - while (a) - { - if (!strcmp(a->name,w1)) - break; - a=a->next; - } - - if (!a) - return str; - - for ( p=a->str; *p; p++) - { - if ( *p != '$' ) - { - ADD(p1,*p); - continue; - } - - dollar=1; - p++; - - if (isdigit(*p)) - { - ADDSTR(&p1,word(str,(*p)-'0'+1)); - continue; - } - - switch (*p) - { - - case '\0': - case '$': ADD(p1,'$');continue; - case '*': ADDSTR(&p1,args);continue; - default: ADD(p1,'$');ADD(p1,*p);continue; - } - } - - if (!dollar) - { - ADD(p1,' '); - ADDSTR(&p1,args); - } - - *p=0; - - return new; -} - -ifalias(char *cmd) -{ - String what; - ALIAS *a=firstalias; - - - strcpy(what,word(cmd,1)); - - while ( a!=NULL) - { - if (!strcmp(a->name,what)) - return 1; - a=a->next; - } - return 0; -} - - - -char *getprompt() -{ - - static String _prompt; - String tmp; - char *s; - - _prompt[0]=0; - - for(s=prompt;*s;s++) - switch (*s) - { - case '%': - switch (*++s) - { - - case 'H': - strcat(_prompt,iftp[frame].host); - break; - - case 'h': - strcpy(tmp,iftp[frame].host); - if (strchr(tmp,'.')!=NULL) *(char *)strchr(tmp,'.')=0; - strcat(_prompt,tmp); - break; - - case 'M': - gethostname(tmp, sizeof tmp); - strcat(_prompt,gethostbyname(tmp)->h_name); - break; - - case 'm': - gethostname(tmp, sizeof tmp); - strcpy(tmp,gethostbyname(tmp)->h_name); - if (strchr(tmp,'.')!=NULL) *(char *)strchr(tmp,'.')=0; - strcat(_prompt,tmp); - break; - - case 'u': - strcat(_prompt,iftp[frame].user); - break; - - case 'd': - strcat(_prompt,iftp[frame].pwd); - break; - - case 'D': - strcat(_prompt,(char *)getcwd(tmp,sizeof(tmp))); - break; - - case 'f': - sprintf(tmp,"%d",frame); - strcat(_prompt,tmp); - break; - - case 'p': - sprintf(tmp,"%d",(LINK==NULL)?0:LINK->port); - strcat(_prompt,tmp); - break; - - case 't': - - sprintf(tmp,"%d",(LINK==NULL)?0:LINK->timeout.tv_sec); - strcat(_prompt,tmp); - break; - - - case 'T': - - { - time_t t=time((time_t *)0); - struct tm *lt=localtime(&t); - sprintf(tmp,"%02d:%02d:%02d",lt->tm_hour, - lt->tm_min,lt->tm_sec); - strcat(_prompt,tmp); - } - break; - - case 'P': - - sprintf(tmp,"%d",getpid()); - strcat(_prompt,tmp); - break; - - default: - sprintf(tmp,"%%%c",*s); - strcat(_prompt,tmp); - break; - } - break; - - case '^': - - ++s; - if (isalpha(*s)) - { - sprintf(tmp,"%c",toupper(*s)-'A'+1); - strcat(_prompt,tmp); - } - break; - - default: - - sprintf(tmp,"%c",*s); - strcat(_prompt,tmp); - break; - } - return _prompt; -} - - -void noop() -{ - int i; - time_t curtime,save; - STATUS (*func1)(),(*func2)(),(*func3)(); - - - if (noopinterval==0) return; - - curtime = time((time_t *)0); - - signal(SIGALRM,noop); - - if (prevtime==0) - { - prevtime=curtime; - alarm(noopinterval); - return; - } - - if (curtime-prevtime < noopinterval) - { - alarm(prevtime+noopinterval-curtime); - return; - } - - printf("Waiting...");fflush(stdout); - - for (i=0;i<NFRAMES;i++) - { - if ( ftp[i]==NULL || FTPCMD(ftp[i]) == NULL || iftp[i].lock ) - continue; - - func1=ftp[i]->debug; ftp[i]->debug=NULL; - func2=ftp[i]->error; ftp[i]->error=NULL; - func3=ftp[i]->IO; ftp[i]->IO=NULL; - save = ftp[i]->timeout.tv_sec; - ftp[i]->timeout.tv_sec = nooptimeout; - - FtpCommand(ftp[i],"NOOP","",0,EOF); - - ftp[i]->timeout.tv_sec = save; - ftp[i]->debug=func1; - ftp[i]->error=func1; - ftp[i]->IO=func1; - - } - - alarm(noopinterval); - prevtime=curtime; - - for (i=0;i<10;i++) putchar(8),putchar(' '),putchar(8); - fflush(stdout); -} - - -setsignals() -{ - signal(SIGINT,intr); - signal(SIGQUIT,intr); - noop(); -} - -unsetsignals() -{ - signal(SIGALRM,SIG_IGN); - alarm(0); -} - - -int myhash(FTP *ftp,unsigned int chars) -{ - - if (hashmode) - { - if (chars==0) return ftp -> counter=0; - ftp -> counter += chars; - fprintf(stdout,"%10u bytes transfered\r",ftp -> counter); - fflush(stdout); - } - - if (!lastcmd) - { - noop(); - alarm(0); - } -} - - - -char *makefilename(char *f1, char *f2) -{ - char *p; - - if (*f2!=0) - return f2; - - if ( (p=strrchr(f1,'/'))!=NULL) - return p+1; - return f1; -} - -redir(char *cmdline) -{ - char *p=cmdline; - String result; - char *r=result; - - for ( ; *p ; p++ , r++ ) - { - if ( *p == '\\' ) - { - *r = * ++ p ; - continue; - } - - if ( *p == '>' || *p == '<' ) - { - String filename; - char *q=filename; - char c=*p; - - for (p++;isspace(*p)&&*p!=0;p++); - if (*p=='"') - { - for (p++; *p!='"' && *p!=0 ; p++,q++) *q=*p; - if (*p!='"') p++; - } - else - for (; !isspace(*p) && *p!=0 ; p++,q++) *q=*p; - - *q=0; - - if ( c == '>' ) - output(filename); - else - input(filename); - } - *r=*p; - } - *r=0; - strcpy(cmdline,result); -} - -int itty=-1,otty=-1; -FILE *is=NULL,*os=NULL; - - -input(char *filename) -{ - - if ((is=Ftpfopen(filename,"r"))==NULL) - { - perror(filename); - return; - } - - fflush(stdin); - itty=dup(0); - close(0); - dup2(fileno(is),0); - -} - -output(char *filename) -{ - - if ((os=Ftpfopen(filename,"w"))==NULL) - { - perror(filename); - return; - } - - fflush(stdout); - otty=dup(1); - close(1); - dup2(fileno(os),1); -} - -redirback() -{ - - if (itty!=-1) - { - fflush(stdin); - close(0); - Ftpfclose(is); - dup2(itty,0); - is=NULL; - itty=-1; - } - - if (otty!=-1) - { - fflush(stdout); - close(1); - Ftpfclose(os); - dup2(otty,1); - os=NULL; - otty=-1; - } -} - - -batch(char *filename) -{ - FILE *fp; - String tmp; - - if ((fp=fopen(filename,"r"))!=NULL) - { - - while ( fgets(tmp, sizeof tmp, fp) != NULL) - { - tmp[strlen(tmp)-1]=0; - execute(tmp); - if (tmp[0]) add_history(tmp); - } - fclose(fp); - } -} - - - - - - diff --git a/lib/libftp/utils/uftpcmd.c b/lib/libftp/utils/uftpcmd.c deleted file mode 100644 index 2eb3cb2..0000000 --- a/lib/libftp/utils/uftpcmd.c +++ /dev/null @@ -1,1202 +0,0 @@ -#include "uftp.h" - -String tmp; - -jmp_buf connectstack; - - - -Ftp_connect_hook(FTP *ftp,int code, char *msg) -{ - FtpLog(ftp->title,msg); - longjmp(connectstack,1); - -} - - -Ftp_connect(ARGS) -{ - STATUS (*func1)(),(*func2)(); - - if (*w2==0) w2=readline("Host:"); - - if (FtpGetHost(w2)==NULL && FtpInit.IO != NULL) - { - char *msg; - extern int h_errno; - - switch(h_errno) - { - case HOST_NOT_FOUND: msg = "Host unknown"; break; - case TRY_AGAIN: msg = "Hostname lookup failure";break; - default: msg = "gethostbyname failure"; - } - return (*FtpInit.IO)(LINK,QUIT,msg); - } - - newframe(0); - - func1 = FtpInit.error; - func2 = FtpInit.IO; - - if (trymode) - { - FtpSetErrorHandler(&FtpInit,Ftp_connect_hook); - FtpSetIOHandler(&FtpInit,Ftp_connect_hook); - setjmp(connectstack); - } - - FtpConnect(&LINK,w2); - strcpy(iftp[frame].host,FtpGetHost(w2)->h_name); - - FtpSetErrorHandler(LINK,func1); - FtpSetErrorHandler(&FtpInit,func1); - FtpSetIOHandler(LINK,func2); - FtpSetIOHandler(&FtpInit,func2); - - return; -} - -Ftp_user(ARGS) -{ - - if (*w2==0) - { - sprintf(tmp,"login (default %s):",defaultuser); - w2=readline(tmp); - if (*w2==0) - w2=defaultuser; - } - strcpy(iftp[frame].user,w2); - strcpy(iftp[frame].pass,w3); - if (FtpUser(LINK,w2)==331) Ftp_pass("",w3,"","","",""); -} - -Ftp_pass(ARGS) -{ - if (*w2==0) - { - String pass; - String host; - - gethostname(host, sizeof host); - strcpy(host,FtpGetHost(host)->h_name); - sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,host); - sprintf(tmp,"Password (default %s):",pass); - w2=getpass(tmp); - if (*w2==0) w2=pass; - } - - strcpy(iftp[frame].pass,w2); - FtpPassword(LINK,w2); - strcpy(iftp[frame].pwd,FtpPwd(LINK)); -} - -Ftp_open(ARGS) -{ - register char *p1; - STATUS (*err)(); - - Ftp_connect("",w2,"","","",""); - Ftp_user("",w3,w4,"","","" ); - if (ifalias("autologin")) execute("autologin"); - if (*w5) - Ftp_cd("cd",w5,"","","",""); -} - -Ftp_reopen(ARGS) -{ - String host,user,pass,pwd; - - strcpy(host,iftp[frame].host); - strcpy(user,iftp[frame].user); - strcpy(pass,iftp[frame].pass); - strcpy(pwd,iftp[frame].pwd); - - Ftp_close("","","","","",""); - Ftp_open("",host,user,pass,pwd,""); -} - -Ftp_ftp(ARGS) -{ - String pass; - String host; - - gethostname(host, sizeof host); - strcpy(host,FtpGetHost(host)->h_name); - sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,host); - - Ftp_open("",w2,"anonymous",pass,w3,""); - return; -} - -Ftp_quit(ARGS) -{ - exit(0); -} - -Ftp_mput_handler() -{ - log("File(s) or directory not found"); - longjmp(start,1); -} - - -Ftp_lcd(ARGS) -{ - glob_t gl; - - bzero(&gl,sizeof gl); - - glob(w2,GLOB_BRACE|GLOB_TILDE|GLOB_QUOTE, - Ftp_mput_handler, &gl); - - - if (gl.gl_matchc<1 || chdir(*gl.gl_pathv)) - perror(w2); - - printf("Local directory is \"%s\"\n",getwd(tmp)); -} - -Ftp_dir(ARGS) -{ - char *cmd1; - String cmd; - char mode=LINK->mode; - - if ( !strcmp(w1,"dir") ) - cmd1="LIST"; - else - cmd1="NLST"; - - strcpy(cmd,makestr(cmd1,w2,w3,w4,w5,w6,NULL)); - - if ( LINK->mode != 'A' ) FtpAscii(LINK); - FtpRetr(LINK,cmd,"","-"); - if ( LINK->mode != mode ) FtpType(LINK,mode); - -} - -Ftp_close(ARGS) -{ - register int i; - - if (isdigit(*w2)) - { - i=atoi(w2); - } - else - { - i=frame; - } - - FtpQuickBye(ftp[i]); - - iftp[i].host[0]=0; - iftp[i].pwd[0]=0; - ftp[i]=NULL; - newframe(1); -} - - -INLINE SetLogicalVar(char arg, int * var, char *msg) -{ - switch(arg) - { - - case 'y': - - *var=1; - break; - - case 'n': - - *var=0; - break; - - default: - - (*var)?(*var=0):(*var=1); - break; - } - return printf("%s %s\n",msg,(*var)?"enable":"disable"); -} - - -Ftp_set(ARGS) -{ - if (!strcmp("frame",w2)) - return atoi(w3)<NFRAMES?frame=atoi(w3):0; - - if (!strcmp("timeout",w2)) - { - FtpSetTimeout(&FtpInit,atoi(w3)); - if (LINK!=0) - FtpSetTimeout(LINK,atoi(w3)); - return; - } - - if (!strcmp("sleep",w2)) - { - sleeptime=atoi(w3); - return; - } - - if (!strcmp("debug",w2)) - { - if ( *w3=='y' || *w3==0) - { - if (LINK!=NULL) FtpSetDebugHandler(LINK,FtpDebugDebug); - FtpSetDebugHandler(&FtpInit,FtpDebugDebug); - return puts("Debuging on for current and next session"); - } - if ( *w3 == 'n') - { - if (LINK!=NULL) FtpSetDebugHandler(LINK,NULL); - FtpSetDebugHandler(&FtpInit,NULL); - return puts("Debuging off for current and next session"); - } - } - - if (!strcmp("bin",w2)) - { - if ( *w3=='y' || *w3==0) - { - FtpInit.mode='I'; - return puts("Binary mode enable"); - } - if ( *w3 == 'n') - { - FtpInit.mode='A'; - return puts("Binary mode disable"); - } - } - - if (!strcmp("try",w2)) - return SetLogicalVar(*w3,&trymode,"Try mode"); - if (!strcmp("hash",w2)) - return SetLogicalVar(*w3,&hashmode,"Hash mode"); - if (!strcmp("glass",w2)) - return SetLogicalVar(*w3,&glassmode,"Glass mode"); - if (!strcmp("rest",w2)||!strcmp(w2,"restore")) - return SetLogicalVar(*w3,&restmode,"Restore mode"); - - if (!strcmp("prompt",w2)) - { - strcpy(prompt,w3); - return; - } - - if (!strcmp("port",w2)) - { - if ( isdigit(*w3)) - return FtpSetPort(&FtpInit,atoi(w3)); - puts("Port must be number"); - fflush(stdout); - return; - } - - if (!strcmp("noopinterval",w2)||!strcmp("noop",w2)) - { - if ( isdigit(*w3)) - return noopinterval=(time_t)atoi(w3); - puts("Time must be number"); - fflush(stdout); - return; - } - - if (!strcmp("nooptimeout",w2)) - { - if ( isdigit(*w3)) - return nooptimeout=(time_t)atoi(w3); - puts("Time must be number"); - fflush(stdout); - return; - } - - - - if (!strcmp("user",w2)||!strcmp("login",w2)) - { - strcpy(defaultuser,w3); - return; - } - - if (!strcmp("",w2)) - { - - printf("frime %d\n",frame); - printf("timeout %d secs\n",FtpInit.timeout.tv_sec); - printf("sleep time %d secs\n",sleeptime); - printf("debug %s\n",(FtpInit.debug!=NULL)?"enable":"disable"); - printf("glass mode %s\n",glassmode?"enable":"disable"); - printf("try mode %s\n",trymode?"enable":"disable"); - printf("hash mode %s\n",hashmode?"enable":"disable"); - printf("restore mode %s\n",restmode?"enable":"disable"); - printf("automatic binary mode %s\n",(FtpInit.mode=='I')?"enable":"disable"); - printf("prompt \"%s\"\n",prompt); - printf("port %d\n",FtpInit.port); - printf("noop interval %d\n",noopinterval); - printf("noop timeout %d\n",nooptimeout); - printf("Default login name \"%s\"\n",defaultuser); - fflush(stdout); - return; - } - return puts("arg 2 unknown"); - -} - -jmp_buf getstack; - -Ftp_get_hook(FTP *con,int code, char *msg) -{ - - if ( abs(code)==550 && FtpBadReply550(msg) ) - { - FtpLog(con->title,msg); - log("Transfer cancel"); - longjmp(getstack,2); - } - - if ( code == LQUIT ) - { - log(msg); - log("Transfer leave after I/O error with local file"); - longjmp(getstack,2); - } - - - - FtpLog(con->title,msg); - FtpQuickBye(LINK); - LINK=NULL; - - log("sleeping......"); - sleep(sleeptime); - log("try again..."); - - longjmp(getstack,1); - -} - -void Ftp_get_intr(int sig) -{ - signal(SIGINT,intr); - log("Transfer interupt"); - Ftp_abort(); - longjmp(getstack,3); -} - -Ftp_get(ARGS) -{ - FTP OldInit; - int back=0; - int code; - int status=0; - - OldInit=FtpInit; - - if (strstr(w1,"put")!=NULL) back=1; - - - if (restmode || ((*w1=='r')&&(*(w1+1)=='e')) ) - FtpSetFlag(LINK,FTP_REST); - else - FtpClearFlag(LINK,FTP_REST); - - - - if (trymode) - { - FtpSetErrorHandler(LINK,Ftp_get_hook); - FtpSetIOHandler(LINK,Ftp_get_hook); - FtpInit=*LINK; - FTPCMD(&FtpInit)=FTPCMD(&OldInit); - FTPDATA(&FtpInit)=FTPDATA(&OldInit); - } - - signal(SIGINT,Ftp_get_intr); - FtpSetHashHandler(LINK,NULL); - - - if ((status=setjmp(getstack))==2||status==3) - goto done; - - if ((LINK==NULL)||(LINK->sock==FtpInit.sock)) - { - FtpLogin(&LINK,iftp[frame].host,iftp[frame].user, - iftp[frame].pass,NULL); - FtpChdir(LINK,iftp[frame].pwd); - } - - if (hashmode && isatty(fileno(stdout))) - FtpSetHashHandler(LINK,myhash); - else - FtpSetHashHandler(LINK,NULL); - - myhash(LINK,0); - - if (!back) - FtpGet(LINK,w2,makefilename(w2,w3)); - else - FtpPut(LINK,w2,makefilename(w2,w3)); - - - log("Transfer compliete"); - - -done: - - - FtpSetHashHandler(LINK,NULL); - FtpSetErrorHandler(LINK,my_error); - FtpSetIOHandler(LINK,my_error); - FtpClearFlag(LINK,FTP_REST); - FtpInit=OldInit; -} - -Ftp_mget(ARGS) -{ - FILE *list; - char mode=LINK->mode; - - sprintf(tmp,"/tmp/uftplist-%s.XXXXXX",getpwuid(getuid())->pw_name); - mktemp(tmp); - - if ( LINK->mode != 'A' ) FtpAscii(LINK); - - if (*w2==0) - FtpRetr(LINK,"NLST","",tmp); - else - FtpRetr(LINK,"NLST %s",w2,tmp); - - if ( LINK->mode != mode ) FtpType(LINK,mode); - - if ((list=fopen(tmp,"r"))==NULL) - return FtpLog(tmp,sys_errlist[errno]); - - while ( fgets(tmp,sizeof tmp,list)!=NULL) - { - tmp[strlen(tmp)-1]=0; - Ftp_get("get",tmp,w3,"","",""); - } - - fclose(list); -} - -Ftp_mput(ARGS) -{ - glob_t gl; - - glob(w2,GLOB_BRACE|GLOB_TILDE|GLOB_QUOTE, - Ftp_mput_handler, &gl); - - while(gl.gl_matchc--) - { - Ftp_get("put",*gl.gl_pathv,"","","",""); - gl.gl_pathv++; - } -} - - -Ftp_bget(ARGS) -{ - - String fn,lfn; - char *p; - - newframe(0); - - if (!FtpFullSyntax(w2,iftp[frame].host,iftp[frame].user, - iftp[frame].pass,fn)) - return puts("Filename syntax error"); - - strcpy(iftp[frame].pwd,"/"); - - if ((p=strrchr(fn,'/'))!=NULL) - strcpy(lfn,p+1); - else - strcpy(lfn,fn); - - FtpQuickBye(LINK); - LINK=FtpCreateObject(); - LINK->sock=NULL; - - Ftp_get("get",fn,(*w3==0)?lfn:w3,"","",""); -} - -Ftp_bput(ARGS) -{ - - String fn,lfn; - char *p; - - if (!FtpFullSyntax((*w3==0)?w2:w3,iftp[frame].host,iftp[frame].user, - iftp[frame].pass,fn)) - return puts("Filename syntax error"); - - strcpy(iftp[frame].pwd,"/"); - - if ((p=strrchr(fn,'/'))!=NULL) - strcpy(lfn,p+1); - else - strcpy(lfn,fn); - - FtpQuickBye(LINK); - LINK=FtpCreateObject(); - LINK->sock=NULL; - - Ftp_get("put",(*w3==0)?lfn:w2,fn,"","",""); -} - -Ftp_copy(ARGS) -{ - char *p; - int in,out; - - if ( !*w2 || !*w3 ) return puts("Must pass two args"); - - if ((p=strchr(w2,'!'))!=NULL) - { - *p=0; - in=atoi(w2); - w2=p+1; - } - else - in=frame; - - if ((p=strchr(w3,'!'))!=NULL) - { - *p=0; - out=atoi(w3); - w3=p+1; - } - else - in=frame; - - if (in==out) return puts("Files must been from different frames"); - - FtpCopy(ftp[in],ftp[out],w2,w3); -} - -Ftp_ccopy(ARGS) -{ - char *p; - int in,out; - - if ( !*w2 || !*w3 ) return puts("Must pass two args"); - - if ((p=strchr(w2,'!'))!=NULL) - { - *p=0; - in=atoi(w2); - w2=p+1; - } - else - in=frame; - - if ((p=strchr(w3,'!'))!=NULL) - { - *p=0; - out=atoi(w3); - w3=p+1; - } - else - in=frame; - - if (in==out) return puts("Files must been from different frames"); - - FtpPassiveTransfer(ftp[in],ftp[out],w2,w3); -} - -Ftp_bin(ARGS) -{ - FtpBinary(LINK); -} - -Ftp_ascii(ARGS) -{ - FtpAscii(LINK); -} - -Ftp_cd(ARGS) -{ - FtpChdir(LINK,w2); - strcpy(iftp[frame].pwd,FtpPwd(LINK)); - if (ifalias("autocd")) execute("autocd"); -} - - -Ftp_dup(ARGS) -{ - LINKINFO oldinfo; - FTP oldftp; - - oldinfo=iftp[frame]; - oldftp=*LINK; - - newframe(0); - puts("Make alternative connection..."); - Ftp_open("",oldinfo.host,oldinfo.user,oldinfo.pass,"",""); - if (strcmp(oldinfo.pwd,iftp[frame].pwd)) - Ftp_cd("",oldinfo.pwd,"","","",""); - if (LINK->mode!=oldftp.mode) - FtpType(LINK,oldftp.mode); - LINK -> timeout = oldftp.timeout; - LINK -> flags = oldftp.flags; - FtpSetDebugHandler(LINK,oldftp.debug); - FtpSetErrorHandler(LINK,oldftp.error); - FtpSetIOHandler(LINK,oldftp.IO); - FtpSetHashHandler(LINK,oldftp.hash); -} - - - -Ftp_bg(ARGS) -{ - if (fork()) - { - - log("Backgrounding..."); - return; - } - else - { - int i=frame; - - lastcmd=1; - - /* Ignoring keypad */ - - alarm (0); - signal(SIGALRM,SIG_IGN); - signal(SIGURG,SIG_IGN); - signal(SIGPIPE,SIG_IGN); - signal(SIGTSTP,SIG_IGN); - signal(SIGINT,SIG_IGN); - signal(SIGQUIT,SIG_IGN); - signal(SIGCHLD,SIG_IGN); - signal(SIGIO,SIG_IGN); - - /* Droping output */ - - - sprintf(tmp,"/tmp/uftp-%s.XXXXXX",getpwuid(getuid())->pw_name); - mktemp(tmp); - close(0);close(1);close(2); - open(tmp,O_RDWR|O_TRUNC|O_CREAT,0600); - dup(0);dup(0); - - if (LINK!=NULL) - { - Ftp_dup("","","","","",""); - free(ftp[i]); - ftp[i]=NULL; - } - - return executev(w2,w3,w4,w5,w6,""); - } -} - - -Ftp_list() -{ - register int i; - -#define _FMT "%-5s %-15s %-10s %-25s %-7s %-4s\n" -#define FMT "%-5d %-15s %-10s %-25s %-7d %-4d\n" - - printf(_FMT,"Frame","Host name","User's name","Working directory","Timeout","Port"); - - for ( i = 0 ; i < NFRAMES ; i++ ) - if (ftp[i]!=NULL) - printf(FMT,i,iftp[i].host,iftp[i].user,iftp[i].pwd, - ftp[i]->timeout.tv_sec,ftp[i]->port); - fflush(stdout); - return; -} - -Ftp_abort(ARGS) -{ - time_t save; - - if (LINK!=NULL) - { - save = LINK ->timeout.tv_sec; - LINK->timeout.tv_sec = nooptimeout; - FtpAbort(LINK); - LINK->timeout.tv_sec = save; - } -} - -Ftp_type(ARGS) -{ - FtpGet(LINK,w2,"*STDOUT*"); -} - - -Ftp_page(ARGS) -{ - register char *pager; - String out={'|',0}; - - if ((pager=(char *)getenv("PAGER"))==NULL) - pager="more"; - - strcat(out,pager); - FtpGet(LINK,w2,out); -} - - -Ftp_mkdir(ARGS) -{ - FtpMkdir(LINK,w2); -} - -Ftp_rm(ARGS) -{ - FILE *list; - - sprintf(tmp,"/tmp/uftplist-%s.XXXXXX",getpwuid(getuid())->pw_name); - mktemp(tmp); - - if (*w2==0) - { - log("Filename specification must present"); - return; - } - - FtpRetr(LINK,"NLST %s",w2,tmp); - - if ((list=fopen(tmp,"r"))==NULL) - return FtpLog(tmp,sys_errlist[errno]); - - while ( fgets(tmp,sizeof tmp,list)!=NULL) - { - tmp[strlen(tmp)-1]=0; - FtpCommand(LINK,"DELE %s",tmp,0,EOF); - } - - fclose(list); -} - - - - -Ftp_move(ARGS) -{ - FtpMove(LINK,w2,w3); -} - -Ftp_help(ARGS) -{ - register int i,ii; - - if ( !*w2 ) - { - puts("Warrning!!!! \nPlease read general information using command \"help etc\"\n\n"); - - for ( i = 0 ;1; i++) - { - for ( ii = 0 ; ii < 5 ; ii++) - { - if (cmds[ii+i*5].cmd==NULL) return putchar('\n'); - printf("%-16s",cmds[ii+i*5].cmd); - } - putchar ('\n'); - } - } - - - for ( i = 0 ; 1; i++) - { - - if (cmds[i].cmd==NULL) return puts("Command not found"); - if (!strcmp(cmds[i].cmd,w2)) - break; - } - - puts(cmds[i].help); - -} - -Ftp_quote(ARGS) -{ - String new; - - new[0]=0; - - if (*w2!=0) strcpy(new,w2); - if (*w3!=0) strcat(new," "),strcat(new,w3); - if (*w4!=0) strcat(new," "),strcat(new,w4); - if (*w5!=0) strcat(new," "),strcat(new,w5); - if (*w6!=0) strcat(new," "),strcat(new,w6); - - FtpCommand(LINK,new,"",0,EOF); -} - -Ftp_alias(ARGS) -{ - ALIAS *a=firstalias; - - - if ( *w2==0 ) - { - while (a!=NULL) - { - printf("%s=%s\n",a->name,a->str); - a=a->next; - } - return; - } - - - while (1) - { - - if ( a == NULL ) - { - firstalias = a = (ALIAS *) malloc(sizeof(ALIAS)); - memset(a,0,sizeof(ALIAS)); - a -> next = NULL; - break; - } - - if (!strcmp(a->name,w2)) - break; - - if ( a->next == NULL) - { - a -> next = (ALIAS *) malloc(sizeof(ALIAS)); - a = a->next; - memset(a,0,sizeof(ALIAS)); - a -> next = NULL; - break; - } - a=a->next; - } - - strcpy(a -> name,w2); - strcpy(a -> str,makestr(w3,w4,w5,w6,NULL)); -} - -Ftp_mkalias(ARGS) -{ - String new; - - if (!*w2) return puts("Arg must present\n"); - - sprintf(new,"open \"%s\" \"%s\" \"%s\" \"%s\"", - iftp[frame].host,iftp[frame].user, - iftp[frame].pass,iftp[frame].pwd); - - Ftp_alias("alias",w2,new,"","",""); -} - -Ftp_unalias(ARGS) -{ - ALIAS *cur,*prev; - - cur=prev=firstalias; - - while ( cur != NULL ) - { - if (!strcmp(cur->name,w2)) - { - if ( cur == firstalias ) - { - firstalias = cur->next; - free(cur); - return; - } - prev -> next = cur -> next; - free(cur); - } - prev=cur; - cur=cur->next; - } -} - - -Ftp_save(ARGS) -{ - ALIAS *a=firstalias; - String fn; - FILE *out; - - if ((out=fopen (getaliasrcname(),"w"))==NULL) - { - perror(getaliasrcname()); - return; - } - - while (a!=NULL) - { - fprintf(out,"alias %s '%s'\n",a->name,a->str); - a=a->next; - } - fclose(out); - chmod ( getaliasrcname(), 0600); - puts("Aliases saved"); -} - -#define ARCHIE_MAX_TARGETS 20 - -Ftp_acd(ARGS) -{ - static int targets=0; - static String what={0}; - static ARCHIE result[ARCHIE_MAX_TARGETS]; - - int i, selected_target; - String tmp; - char *p; - - - if ( (what[0] == 0 || strcmp(w2,what) != 0) && *w2!=0 ) - { - if ((targets=FtpArchie(w2,result,ARCHIE_MAX_TARGETS))<1) - return puts("Archie failure or target not found"); - strcpy(what,w2); - } - - for (i=0;i<targets;i++) - printf("%2d %s:%s\n",i,result[i].host,result[i].file); - - if (strcmp(w1,"archie")==0) - return; - - - p = readline("Your selection? "); - if (p==NULL) return; - - selected_target = atoi(p); - - if ( result[selected_target].file[strlen(result[selected_target].file)-1] - == '/' ) - { - Ftp_ftp("ftp",result[selected_target].host,result[selected_target].file, - "","",""); - return; - } - else - { - sprintf(tmp,"%s:%s", - result[selected_target].host,result[selected_target].file); - Ftp_bget("bget",tmp,"","","",""); - } -} - - -CMDS cmds[]={ - - "connect", Ftp_connect, 0, - "connect <hostname> - make new ftp connection", - - "open", Ftp_open, 0, - "open <hostname> <user> <pass> <directory> - login to server", - - "reopen", Ftp_reopen, 1, - "Open again connection with existing frame information", - - "ftp", Ftp_ftp, 0, - "ftp <hostname> - anonymously login to server", - - "close", Ftp_close, 1, - "Close connection", - - "quit", Ftp_quit, 0, - "Exit from uftp", - - "set", Ftp_set, 0, -"Set variables: (Without args print current settings)\n\ - frame <number> - select another session(frame)\n\ - timeout <secs> - Set network timeout\n\ - nooptimeout <secs>- Set network timeout with clearing timeout\n\ - noop <secs> - Set time interval for sending NOOP operator\n\ - to server for erased delay\n\ - sleep <secs> - Set pause beetween transfer attempt\n\ - debug <y|n> - Set debuging ftp's protocol (Default no)\n\ - try <y|n> - Set retransfer mode with broken network (Default yes)\n\ - hash <y|n> - Set hashing transfer (Default no)\n\ - restore <y|n> - Set retransfer mode (reget/reput) (Default yes!!!!)\n\ - bin <y|n> - Set automatic turn on binary mode (Default no) \n\ - glass <y|n> - Set glass mode (bad commands interprets as commands for FTPD)\n\ - prompt <string> - Set prompt (See help prompt)\n\ - port <number> - Set ftpd's port for next sessions\n\ - user <name> - Set default user name (default you name)", - - "prompt", NULL, 0, - "\ -prompt is a string, which may be contains %<char> -or ^<char> combitanion, which have next interprets: - -%H, %h - full and short remote host names -%M, %m - full and short local host names -%u - remote user's name -%d - remote current directory -%D - local current directory -%f - number of current frame -%p - the ftp's port number -%t - timeout -%T - current time -%P - uftp process id -%% - character % -^<char>- control character -%^ - character ^ -", - - "list", Ftp_list, 0, -"List session's information", - - "user", Ftp_user, 1, -"user <user> - send user's name", - - "pass", Ftp_pass, 1, -"pass <pass> - send user's password", - - "bin", Ftp_bin, 1, -"Set binary mode for current frame", - - "ascii", Ftp_ascii, 1, -"Set ASCII mode for current frame", - - "cd", Ftp_cd, 1, -"cd <directory> - change current remote directory ", - - "acd", Ftp_acd, 0, -"acd <file_or_directory> - search pointed directory using archie, and setup connection to it", - - "lcd", Ftp_lcd, 0, -"Change local directory", - - "abort", Ftp_abort, 1, -"abort last operation", - - "mkdir", Ftp_mkdir, 1, -"mkdir <dirname> - create new directory", - - "rm", Ftp_rm, 1, -"rm <filename_spec> - remove file(s)", - - "mv", Ftp_move, 1, -"mv <old> <new> - rename file", - - "dir", Ftp_dir, 1, -"dir <argslist> ... - print list of files", - - "ls", Ftp_dir, 1, -"ls <arglist> ... - print short list of files", - - "get", Ftp_get, 1, -"get <remote_file> [<local_file>] - receive file from server", - - "mget", Ftp_mget, 1, -"mget <remote_file(s)> [<local_directory>] - receive file(s) from server", - - "reget", Ftp_get, 1, -"reget <remote_file> <local_file> - receive file restarting at end of local file", - - "aget", Ftp_acd, 0, -"aget <file> - search pointed file using archie, and retrive it", - - "put", Ftp_get, 1, -"put <local_file> [<remote_file>] - send server to file", - - "mput", Ftp_mput, 1, -"mput <local_file(s)> - send file(s) from server", - - "reput", Ftp_get, 1, -"reput <local_file> [<remote_file>] - send file restarting at end of remote file", - - "bget", Ftp_bget, 0, -"bget <libftp_file> [<localfile>] - full session procedure (See \"help etc\")", - - "bput", Ftp_bput, 0, -"bput [<localfile>] <libftp_file> - full session procedure (See \"help etc\")", - - "copy", Ftp_copy, 1, -"copy [<frame>!]file [<frame>!]file - copy file via client cache", - - "ccopy", Ftp_ccopy, 1, -"ccopy [<frame>!]file [<frame>!]file - copy file directly beetween servers", - - "cat", Ftp_type, 1, -"cat <file> - print body of remote file to screen", - - "page", Ftp_page, 1, -"page <file> - print body of remote file to screen via pager", - - "bg", Ftp_bg, 0, -"bg <any_command> - run command(s) backgroundly (output redirect to file),\n\ -You can also add &-char to back of line without \"bg\"", - - "archie", Ftp_acd, 0, -"Find file using archie service and display to screen", - - "dup", Ftp_dup, 1, -"Make new analogous frame", - - "quote", Ftp_quote, 1, -"quote <some_string> - send command directly to server", - - "help", Ftp_help, 0, -"help <command> - print list of commands or command description", - - "alias", Ftp_alias, 0, -"\ -alias aliasname <list> .... - make new alias, use $X for taking \n\ - X's argument from command string, and $* for taking\n\ - all arguments. If $<anything> on alias not present,\n\ - the arguments appending to end of command string", - - "unalias", Ftp_unalias, 0, -"unalias <aliasname> - remove alias", - - "mkalias", Ftp_mkalias, 0, -"make alias for create this frame, use savealias for saving it to file", - - "savealias", Ftp_save, 0, - "Save aliases to file", - - "etc", NULL, 0, - "\ -1. In any command you may use constructions <file and >file for\n\ - redirect input output.\n\ -\n\ -2. All local files files interprets as libftp file(s), \n\ - this support next specification:\n\ -\n\ - |string - interprets string as shell command, which must be\n\ - execute and input or output take from/to it.\n\ - \n\ - hostname:filename - interprets as file, witch must be take \n\ - using ftp protocol with anonymously access\n\ - \n\ - user@hostname:filename - interprets as file accesses via ftp\n\ - with password yourname@your_host.your_domain\n\ -\n\ - user/pass@hostname:filename - also ftp file.\n\ -\n\ - *STDIN*, *STDOUT*, *STDERR* - opened streams.\n\ -\n\ - anything - local file name.\n\ -\n\ -3. Command started with '!' passed to shell.\n -\n\ -4. If string beetween two \" or \', its interprets as one word.\n\ -\n\ -5. Any string may be devide to few commands using ';'.", - - - - NULL - -}; - - - - - - - |