mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
Updates for move of net apps to rosapps
svn path=/trunk/; revision=2446
This commit is contained in:
parent
f355097ad2
commit
3d9541523b
114 changed files with 0 additions and 35598 deletions
|
@ -1,54 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "Strn.h"
|
||||
|
||||
/*VARARGS*/
|
||||
char *
|
||||
Dynscat(char **dst, ...)
|
||||
{
|
||||
va_list ap;
|
||||
const char *src;
|
||||
char *newdst, *dcp;
|
||||
size_t curLen, catLen, srcLen;
|
||||
|
||||
if (dst == (char **) 0)
|
||||
return NULL;
|
||||
|
||||
catLen = 0;
|
||||
va_start(ap, dst);
|
||||
src = va_arg(ap, char *);
|
||||
while (src != NULL) {
|
||||
catLen += strlen(src);
|
||||
src = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
if ((*dst == NULL) || (**dst == '\0'))
|
||||
curLen = 0;
|
||||
else
|
||||
curLen = strlen(*dst);
|
||||
|
||||
if (*dst == NULL)
|
||||
newdst = malloc(curLen + catLen + 2);
|
||||
else
|
||||
newdst = realloc(*dst, curLen + catLen + 2);
|
||||
if (newdst == NULL)
|
||||
return NULL;
|
||||
|
||||
dcp = newdst + curLen;
|
||||
va_start(ap, dst);
|
||||
src = va_arg(ap, char *);
|
||||
while (src != NULL) {
|
||||
srcLen = strlen(src);
|
||||
memcpy(dcp, src, srcLen);
|
||||
dcp += srcLen;
|
||||
src = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
*dcp = '\0';
|
||||
|
||||
*dst = newdst;
|
||||
return (newdst);
|
||||
} /* Dynscat */
|
|
@ -1,115 +0,0 @@
|
|||
#
|
||||
# Strn makefile
|
||||
#
|
||||
VER=2.2.0
|
||||
PREFIX=@prefix@
|
||||
MAN=@prefix@/man
|
||||
SHELL=/bin/sh
|
||||
.SUFFIXES: .c .o .so
|
||||
LIB=libStrn.a
|
||||
LIBSO=libStrn.so.1
|
||||
LIBSOS=libStrn.so
|
||||
CC=@CC@
|
||||
CPPFLAGS=
|
||||
#CFLAGS=-O2
|
||||
CFLAGS=@CFLAGS@
|
||||
DEFS=-DSTRNP_ZERO_PAD=0 -DSTRN_ZERO_PAD=1
|
||||
|
||||
OBJS=Dynscat.o Strncpy.o Strncat.o Strntok.o Strnpcpy.o Strnpcat.o strtokc.o version.o
|
||||
SOBJS=Dynscat.so Strncpy.so Strncat.so Strntok.so Strnpcpy.so Strnpcat.so strtokc.so version.so
|
||||
|
||||
all: static
|
||||
-@echo "Done making Strn."
|
||||
|
||||
static: $(LIB)
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
ar rv $(LIB) $(OBJS)
|
||||
chmod 644 "$(LIB)"
|
||||
-ranlib "$(LIB)"
|
||||
echo "$(VER)" > Strn.version
|
||||
-@/bin/ls -l "$(LIB)"
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c
|
||||
|
||||
.c.so:
|
||||
$(CC) -fpic $(CFLAGS) $(CPPFLAGS) $(DEFS) $*.c -c -o $*.so
|
||||
|
||||
dynamic: $(LIBSO)
|
||||
|
||||
shared: $(LIBSO)
|
||||
|
||||
so: $(LIBSO)
|
||||
|
||||
$(LIBSO): $(SOBJS)
|
||||
/bin/rm -f "$(LIBSO)"
|
||||
gcc -shared "-Wl,-soname,$(LIBSO)" -o "$(LIBSO)" $(SOBJS)
|
||||
/bin/ln -s "$(LIBSO)" "$(LIBSOS)"
|
||||
-@/bin/ls -l "$(LIBSOS)" "$(LIBSO)"
|
||||
|
||||
soinstall: $(LIBSO)
|
||||
cp "$(LIBSO)" "$(PREFIX)/lib/$(LIBSO)"
|
||||
( cd "$(PREFIX)/lib" ; /bin/ln -s "$(LIBSO)" "$(LIBSOS)" )
|
||||
cp Strn.h "$(PREFIX)/include/Strn.h"
|
||||
-chmod a+r "$(PREFIX)/lib/$(LIBSO)" "$(PREFIX)/include/Strn.h"
|
||||
|
||||
tester: $(LIB) tester.c
|
||||
$(CC) $(CFLAGS) tester.c -o tester -I. -L. -lStrn
|
||||
|
||||
clean:
|
||||
/bin/rm -f "$(LIB)" "$(LIBSO)" $(OBJS) $(SOBJS)
|
||||
|
||||
install:
|
||||
if test ! -d $(PREFIX)/include ; then mkdir -p "$(PREFIX)/include" ; fi
|
||||
if test ! -d $(PREFIX)/lib ; then mkdir -p "$(PREFIX)/lib" ; fi
|
||||
cp "$(LIB)" Strn.version "$(PREFIX)/lib"
|
||||
cp Strn.h "$(PREFIX)/include/Strn.h"
|
||||
-chmod 664 "$(PREFIX)/include/Strn.h" "$(PREFIX)/lib/Strn.version" "$(PREFIX)/lib/$(LIB)"
|
||||
-cp Strn.3 "$(MAN)/man3/Strn.3"
|
||||
-chmod 664 "$(MAN)/man3/Strn.3"
|
||||
-ln "$(MAN)/man3/Strn.3" "$(MAN)/man3/Strncpy.3"
|
||||
-ln "$(MAN)/man3/Strn.3" "$(MAN)/man3/Strncat.3"
|
||||
|
||||
uninstall:
|
||||
/bin/rm -f "$(PREFIX)/lib/$(LIB)" "$(PREFIX)/include/Strn.h"
|
||||
|
||||
PACKAGE=configure Makefile.in configure.in Strn.dsp Strn.dsw Dynscat.c Strncpy.c Strncat.c Strnpcpy.c Strnpcat.c Strntok.c strtokc.c Strn.h Strn.3 tester.c version.c Strn.version
|
||||
|
||||
TMPDIR=/tmp
|
||||
TARDIR=Strn
|
||||
TARFILE=$(TARDIR).tar
|
||||
TGZFILE=$(TARDIR).tgz
|
||||
|
||||
tarcp:
|
||||
-@mkdir -p $(TMPDIR)/TAR/$(TARDIR)
|
||||
-@chmod ga+r $(PACKAGE)
|
||||
-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
|
||||
cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)
|
||||
|
||||
tar: $(PACKAGE)
|
||||
-@mkdir $(TMPDIR)/TAR
|
||||
-@mkdir $(TMPDIR)/TAR/$(TARDIR)
|
||||
-@chmod ga+r $(PACKAGE)
|
||||
-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
|
||||
cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)
|
||||
( cd $(TMPDIR)/TAR ; tar cf $(TARFILE) ./$(TARDIR) )
|
||||
cp $(TMPDIR)/TAR/$(TARFILE) .
|
||||
-@chmod 644 $(TARFILE)
|
||||
-@rm -rf $(TMPDIR)/TAR
|
||||
-@ls -l $(TARFILE)
|
||||
|
||||
gz: tar
|
||||
gzip -c $(TARFILE) > $(TGZFILE)
|
||||
-@rm $(TARFILE)
|
||||
-@chmod 644 $(TGZFILE)
|
||||
-@ls -l $(TGZFILE)
|
||||
|
||||
Dynscat.o: Dynscat.c Strn.h
|
||||
Strncat.o: Strncat.c Strn.h
|
||||
Strncpy.o: Strncpy.c Strn.h
|
||||
Strnpcat.o: Strnpcat.c Strn.h
|
||||
Strnpcpy.o: Strnpcpy.c Strn.h
|
||||
Strntok.o: Strntok.c Strn.h
|
||||
strtokc.o: strtokc.c Strn.h
|
||||
version.o: version.c
|
|
@ -1,52 +0,0 @@
|
|||
/* Strn.h */
|
||||
|
||||
#ifndef _Strn_h_
|
||||
#define _Strn_h_ 1
|
||||
|
||||
/* You should define this from the Makefile. */
|
||||
#ifndef STRN_ZERO_PAD
|
||||
# define STRN_ZERO_PAD 1
|
||||
#endif
|
||||
|
||||
/* You should define this from the Makefile. */
|
||||
#ifndef STRNP_ZERO_PAD
|
||||
# define STRNP_ZERO_PAD 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Strncat.c */
|
||||
char *Strncat(char *const, const char *const, const size_t);
|
||||
|
||||
/* Strncpy.c */
|
||||
char *Strncpy(char *const, const char *const, const size_t);
|
||||
|
||||
/* Strnpcat.c */
|
||||
char *Strnpcat(char *const, const char *const, size_t);
|
||||
|
||||
/* Strnpcpy.c */
|
||||
char *Strnpcpy(char *const, const char *const, size_t);
|
||||
|
||||
/* Strntok.c */
|
||||
char *Strtok(char *, const char *);
|
||||
int Strntok(char *, size_t, char *, const char *);
|
||||
|
||||
/* strtokc.c */
|
||||
char *strtokc(char *, const char *, char **);
|
||||
int strntokc(char *, size_t, char *, const char *, char **);
|
||||
|
||||
/* Dynscat.c */
|
||||
char * Dynscat(char **dst, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define STRNCPY(d,s) Strncpy((d), (s), (size_t) sizeof(d))
|
||||
#define STRNCAT(d,s) Strncat((d), (s), (size_t) sizeof(d))
|
||||
|
||||
#endif /* _Strn_h_ */
|
||||
|
||||
/* eof Strn.h */
|
|
@ -1,44 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
/*
|
||||
* Concatenate src on the end of dst. The resulting string will have at most
|
||||
* n-1 characters, not counting the NUL terminator which is always appended
|
||||
* unlike strncat. The other big difference is that strncpy uses n as the
|
||||
* max number of characters _appended_, while this routine uses n to limit
|
||||
* the overall length of dst.
|
||||
*/
|
||||
char *
|
||||
Strncat(char *const dst, const char *const src, const size_t n)
|
||||
{
|
||||
register size_t i;
|
||||
register char *d;
|
||||
register const char *s;
|
||||
|
||||
if (n != 0 && ((i = strlen(dst)) < (n - 1))) {
|
||||
d = dst + i;
|
||||
s = src;
|
||||
/* If they specified a maximum of n characters, use n - 1 chars to
|
||||
* hold the copy, and the last character in the array as a NUL.
|
||||
* This is the difference between the regular strncpy routine.
|
||||
* strncpy doesn't guarantee that your new string will have a
|
||||
* NUL terminator, but this routine does.
|
||||
*/
|
||||
for (++i; i<n; i++) {
|
||||
if ((*d++ = *s++) == 0) {
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (; i<n; i++)
|
||||
*d++ = 0;
|
||||
#endif /* STRN_ZERO_PAD */
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
/* If we get here, then we have a full string, with n - 1 characters,
|
||||
* so now we NUL terminate it and go home.
|
||||
*/
|
||||
*d = 0;
|
||||
}
|
||||
return (dst);
|
||||
} /* Strncat */
|
|
@ -1,45 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
|
||||
/*
|
||||
* Copy src to dst, truncating or null-padding to always copy n-1 bytes.
|
||||
* Return dst.
|
||||
*/
|
||||
char *
|
||||
Strncpy(char *const dst, const char *const src, const size_t n)
|
||||
{
|
||||
register char *d;
|
||||
register const char *s;
|
||||
register size_t i;
|
||||
|
||||
d = dst;
|
||||
*d = 0;
|
||||
if (n != 0) {
|
||||
s = src;
|
||||
/* If they specified a maximum of n characters, use n - 1 chars to
|
||||
* hold the copy, and the last character in the array as a NUL.
|
||||
* This is the difference between the regular strncpy routine.
|
||||
* strncpy doesn't guarantee that your new string will have a
|
||||
* NUL terminator, but this routine does.
|
||||
*/
|
||||
for (i=1; i<n; i++) {
|
||||
if ((*d++ = *s++) == 0) {
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (; i<n; i++)
|
||||
*d++ = 0;
|
||||
#endif /* STRN_ZERO_PAD */
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
/* If we get here, then we have a full string, with n - 1 characters,
|
||||
* so now we NUL terminate it and go home.
|
||||
*/
|
||||
*d = 0;
|
||||
}
|
||||
return (dst);
|
||||
} /* Strncpy */
|
||||
|
||||
/* eof Strn.c */
|
|
@ -1,54 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
/*
|
||||
* Concatenate src on the end of dst. The resulting string will have at most
|
||||
* n-1 characters, not counting the NUL terminator which is always appended
|
||||
* unlike strncat. The other big difference is that strncpy uses n as the
|
||||
* max number of characters _appended_, while this routine uses n to limit
|
||||
* the overall length of dst.
|
||||
*
|
||||
* This routine also differs in that it returns a pointer to the end
|
||||
* of the buffer, instead of strncat which returns a pointer to the start.
|
||||
*/
|
||||
char *
|
||||
Strnpcat(char *const dst, const char *const src, size_t n)
|
||||
{
|
||||
register size_t i;
|
||||
register char *d;
|
||||
register const char *s;
|
||||
register char c;
|
||||
char *ret;
|
||||
|
||||
if (n != 0 && ((i = strlen(dst)) < (n - 1))) {
|
||||
d = dst + i;
|
||||
s = src;
|
||||
/* If they specified a maximum of n characters, use n - 1 chars to
|
||||
* hold the copy, and the last character in the array as a NUL.
|
||||
* This is the difference between the regular strncpy routine.
|
||||
* strncpy doesn't guarantee that your new string will have a
|
||||
* NUL terminator, but this routine does.
|
||||
*/
|
||||
for (++i; i<n; i++) {
|
||||
c = *s++;
|
||||
if (c == '\0') {
|
||||
ret = d; /* Return ptr to end byte. */
|
||||
*d++ = c;
|
||||
#if (STRNP_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (; i<n; i++)
|
||||
*d++ = 0;
|
||||
#endif /* STRNP_ZERO_PAD */
|
||||
return ret;
|
||||
}
|
||||
*d++ = c;
|
||||
}
|
||||
/* If we get here, then we have a full string, with n - 1 characters,
|
||||
* so now we NUL terminate it and go home.
|
||||
*/
|
||||
*d = 0;
|
||||
return (d); /* Return ptr to end byte. */
|
||||
}
|
||||
return (dst);
|
||||
} /* Strnpcat */
|
|
@ -1,54 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
/*
|
||||
* Copy src to dst, truncating or null-padding to always copy n-1 bytes.
|
||||
*
|
||||
* This routine differs from strncpy in that it returns a pointer to the end
|
||||
* of the buffer, instead of strncat which returns a pointer to the start.
|
||||
*/
|
||||
char *
|
||||
Strnpcpy(char *const dst, const char *const src, size_t n)
|
||||
{
|
||||
register char *d;
|
||||
register const char *s;
|
||||
register char c;
|
||||
char *ret;
|
||||
register size_t i;
|
||||
|
||||
d = dst;
|
||||
if (n != 0) {
|
||||
s = src;
|
||||
/* If they specified a maximum of n characters, use n - 1 chars to
|
||||
* hold the copy, and the last character in the array as a NUL.
|
||||
* This is the difference between the regular strncpy routine.
|
||||
* strncpy doesn't guarantee that your new string will have a
|
||||
* NUL terminator, but this routine does.
|
||||
*/
|
||||
for (i=1; i<n; i++) {
|
||||
c = *s++;
|
||||
if (c == '\0') {
|
||||
ret = d; /* Return ptr to end byte. */
|
||||
*d++ = c;
|
||||
#if (STRNP_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (; i<n; i++)
|
||||
*d++ = 0;
|
||||
#endif /* STRNP_ZERO_PAD */
|
||||
return ret;
|
||||
}
|
||||
*d++ = c;
|
||||
}
|
||||
/* If we get here, then we have a full string, with n - 1 characters,
|
||||
* so now we NUL terminate it and go home.
|
||||
*/
|
||||
*d = '\0';
|
||||
return (d); /* Return ptr to end byte. */
|
||||
} else {
|
||||
*d = 0;
|
||||
}
|
||||
return (d); /* Return ptr to end byte. */
|
||||
} /* Strnpcpy */
|
||||
|
||||
/* eof Strn.c */
|
|
@ -1,179 +0,0 @@
|
|||
/* Strntok.c */
|
||||
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
/* This version of Strtok differs from the regular ANSI strtok in that
|
||||
* an empty token can be returned, and consecutive delimiters are not
|
||||
* ignored like ANSI does. Example:
|
||||
*
|
||||
* Parse String = ",,mike,gleason,-West Interactive,402-573-1000"
|
||||
* Delimiters = ",-"
|
||||
*
|
||||
* (ANSI strtok:)
|
||||
* strtok 1=[mike] length=4
|
||||
* strtok 2=[gleason] length=7
|
||||
* strtok 3=[West Interactive] length=16
|
||||
* strtok 4=[402] length=3
|
||||
* strtok 5=[573] length=3
|
||||
* strtok 6=[1000] length=4
|
||||
*
|
||||
* (Strtok:)
|
||||
* Strtok 1=[] length=0
|
||||
* Strtok 2=[] length=0
|
||||
* Strtok 3=[mike] length=4
|
||||
* Strtok 4=[gleason] length=7
|
||||
* Strtok 5=[] length=0
|
||||
* Strtok 6=[West Interactive] length=16
|
||||
* Strtok 7=[402] length=3
|
||||
* Strtok 8=[573] length=3
|
||||
* Strtok 9=[1000] length=4
|
||||
*
|
||||
*/
|
||||
|
||||
char *
|
||||
Strtok(char *buf, const char *delims)
|
||||
{
|
||||
static char *p = NULL;
|
||||
char *start, *end;
|
||||
|
||||
if (buf != NULL) {
|
||||
p = buf;
|
||||
} else {
|
||||
if (p == NULL)
|
||||
return (NULL); /* No more tokens. */
|
||||
}
|
||||
for (start = p, end = p; ; end++) {
|
||||
if (*end == '\0') {
|
||||
p = NULL; /* This is the last token. */
|
||||
break;
|
||||
}
|
||||
if (strchr(delims, (int) *end) != NULL) {
|
||||
*end++ = '\0';
|
||||
p = end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (start);
|
||||
} /* Strtok */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This is a bounds-safe version of Strtok, where you also pass a pointer
|
||||
* to the token to write into, and its size. Using the example above,
|
||||
* with a char token[8], you get the following. Notice that the token
|
||||
* is not overrun, and is always nul-terminated:
|
||||
*
|
||||
* Strntok 1=[] length=0
|
||||
* Strntok 2=[] length=0
|
||||
* Strntok 3=[mike] length=4
|
||||
* Strntok 4=[gleason] length=7
|
||||
* Strntok 5=[] length=0
|
||||
* Strntok 6=[West In] length=7
|
||||
* Strntok 7=[402] length=3
|
||||
* Strntok 8=[573] length=3
|
||||
* Strntok 9=[1000] length=4
|
||||
*/
|
||||
|
||||
int
|
||||
Strntok(char *dstTokenStart, size_t tokenSize, char *buf, const char *delims)
|
||||
{
|
||||
static char *p = NULL;
|
||||
char *end;
|
||||
char *lim;
|
||||
char *dst;
|
||||
int len;
|
||||
|
||||
dst = dstTokenStart;
|
||||
lim = dst + tokenSize - 1; /* Leave room for nul byte. */
|
||||
|
||||
if (buf != NULL) {
|
||||
p = buf;
|
||||
} else {
|
||||
if (p == NULL) {
|
||||
*dst = '\0';
|
||||
return (-1); /* No more tokens. */
|
||||
}
|
||||
}
|
||||
|
||||
for (end = p; ; end++) {
|
||||
if (*end == '\0') {
|
||||
p = NULL; /* This is the last token. */
|
||||
break;
|
||||
}
|
||||
if (strchr(delims, (int) *end) != NULL) {
|
||||
++end;
|
||||
p = end;
|
||||
break;
|
||||
}
|
||||
if (dst < lim) /* Don't overrun token size. */
|
||||
*dst++ = *end;
|
||||
}
|
||||
*dst = '\0';
|
||||
len = (int) (dst - dstTokenStart); /* Return length of token. */
|
||||
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (++dst; dst <= lim; )
|
||||
*dst++ = 0;
|
||||
#endif /* STRN_ZERO_PAD */
|
||||
|
||||
return (len);
|
||||
} /* Strntok */
|
||||
|
||||
|
||||
|
||||
#ifdef TESTING_STRTOK
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char buf[256];
|
||||
int i;
|
||||
char *t;
|
||||
char token[8];
|
||||
int tokenLen;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: test \"buffer,with,delims\" <delimiters>\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
t = strtok(buf, argv[2]);
|
||||
if (t == NULL)
|
||||
exit(0);
|
||||
do {
|
||||
printf("strtok %d=[%s] length=%d\n", i, t, (int) strlen(t));
|
||||
t = strtok(NULL, argv[2]);
|
||||
++i;
|
||||
} while (t != NULL);
|
||||
|
||||
printf("------------------------------------------------\n");
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
t = Strtok(buf, argv[2]);
|
||||
if (t == NULL)
|
||||
exit(0);
|
||||
do {
|
||||
printf("Strtok %d=[%s] length=%d\n", i, t, (int) strlen(t));
|
||||
t = Strtok(NULL, argv[2]);
|
||||
++i;
|
||||
} while (t != NULL);
|
||||
|
||||
printf("------------------------------------------------\n");
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
tokenLen = Strntok(token, sizeof(token), buf, argv[2]);
|
||||
if (tokenLen < 0)
|
||||
exit(0);
|
||||
do {
|
||||
printf("Strntok %d=[%s] length=%d\n", i, token, tokenLen);
|
||||
tokenLen = Strntok(token, sizeof(token), NULL, argv[2]);
|
||||
++i;
|
||||
} while (tokenLen >= 0);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
#undef const
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
|
@ -1,19 +0,0 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(Strn.h)
|
||||
wi_ARG_ENABLE_DEBUG
|
||||
|
||||
dnl Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_RANLIB
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
dnl Checks for library functions.
|
||||
|
||||
AC_OUTPUT(Makefile)
|
|
@ -1,240 +0,0 @@
|
|||
/* strtokc.c */
|
||||
|
||||
#include <string.h>
|
||||
#include "Strn.h"
|
||||
|
||||
char *
|
||||
strtokc(char *parsestr, const char *delims, char **context)
|
||||
{
|
||||
char *cp;
|
||||
const char *cp2;
|
||||
char c, c2;
|
||||
char *start;
|
||||
|
||||
if (parsestr == NULL)
|
||||
start = *context;
|
||||
else
|
||||
start = parsestr;
|
||||
|
||||
if ((start == NULL) || (delims == NULL)) {
|
||||
*context = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Eat leading delimiters. */
|
||||
for (cp = start; ; ) {
|
||||
next1:
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
/* No more tokens. */
|
||||
*context = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
for (cp2 = delims; ; ) {
|
||||
c2 = (char) *cp2++;
|
||||
if (c2 == '\0') {
|
||||
/* This character was not a delimiter.
|
||||
* The token starts here.
|
||||
*/
|
||||
start = cp - 1;
|
||||
goto starttok;
|
||||
}
|
||||
if (c2 == c) {
|
||||
/* This char was a delimiter. */
|
||||
/* Skip it, look at next character. */
|
||||
goto next1;
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
starttok:
|
||||
for ( ; ; cp++) {
|
||||
c = *cp;
|
||||
if (c == '\0') {
|
||||
/* Token is finished. */
|
||||
*context = cp;
|
||||
break;
|
||||
}
|
||||
for (cp2 = delims; ; ) {
|
||||
c2 = (char) *cp2++;
|
||||
if (c2 == '\0') {
|
||||
/* This character was not a delimiter.
|
||||
* Keep it as part of current token.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
if (c2 == c) {
|
||||
/* This char was a delimiter. */
|
||||
/* End of token. */
|
||||
*cp++ = '\0';
|
||||
*context = cp;
|
||||
return (start);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (start);
|
||||
} /* strtokc */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Same as strtokc, only you specify the destination buffer to write
|
||||
* the token in along with its size. strntokc will write to the dst
|
||||
* buffer, always nul-terminating it.
|
||||
*
|
||||
* It also returns the length of the token, or zero if there was no
|
||||
* token. This differs from strtokc, which returns a pointer to the
|
||||
* token or NULL for no token.
|
||||
*/
|
||||
|
||||
int
|
||||
strntokc(char *dstTokenStart, size_t tokenSize, char *parsestr, const char *delims, char **context)
|
||||
{
|
||||
char *cp;
|
||||
const char *cp2;
|
||||
char c, c2;
|
||||
char *start;
|
||||
int len;
|
||||
char *dst, *lim;
|
||||
|
||||
dst = dstTokenStart;
|
||||
lim = dst + tokenSize - 1; /* Leave room for nul byte. */
|
||||
|
||||
if (parsestr == NULL)
|
||||
start = *context;
|
||||
else
|
||||
start = parsestr;
|
||||
|
||||
if ((start == NULL) || (delims == NULL)) {
|
||||
*context = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Eat leading delimiters. */
|
||||
for (cp = start; ; ) {
|
||||
next1:
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
/* No more tokens. */
|
||||
*context = NULL;
|
||||
goto done;
|
||||
}
|
||||
for (cp2 = delims; ; ) {
|
||||
c2 = (char) *cp2++;
|
||||
if (c2 == '\0') {
|
||||
/* This character was not a delimiter.
|
||||
* The token starts here.
|
||||
*/
|
||||
start = cp - 1;
|
||||
if (dst < lim)
|
||||
*dst++ = c;
|
||||
goto starttok;
|
||||
}
|
||||
if (c2 == c) {
|
||||
/* This char was a delimiter. */
|
||||
/* Skip it, look at next character. */
|
||||
goto next1;
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
starttok:
|
||||
for ( ; ; cp++) {
|
||||
c = *cp;
|
||||
if (c == '\0') {
|
||||
/* Token is finished. */
|
||||
*context = cp;
|
||||
break;
|
||||
}
|
||||
for (cp2 = delims; ; ) {
|
||||
c2 = (char) *cp2++;
|
||||
if (c2 == '\0') {
|
||||
/* This character was not a delimiter.
|
||||
* Keep it as part of current token.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
if (c2 == c) {
|
||||
/* This char was a delimiter. */
|
||||
/* End of token. */
|
||||
*cp++ = '\0';
|
||||
*context = cp;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (dst < lim) /* Don't overrun token size. */
|
||||
*dst++ = c;
|
||||
}
|
||||
|
||||
done:
|
||||
*dst = '\0';
|
||||
len = (int) (dst - dstTokenStart); /* Return length of token. */
|
||||
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
/* Pad with zeros. */
|
||||
for (++dst; dst <= lim; )
|
||||
*dst++ = 0;
|
||||
#endif /* STRN_ZERO_PAD */
|
||||
|
||||
return (len);
|
||||
} /* strntokc */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef TESTING_STRTOK
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char buf[256];
|
||||
int i;
|
||||
char *t;
|
||||
char token[8];
|
||||
int tokenLen;
|
||||
char *context;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: test \"buffer,with,delims\" <delimiters>\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
t = strtok(buf, argv[2]);
|
||||
if (t == NULL)
|
||||
exit(0);
|
||||
do {
|
||||
printf("strtok %d=[%s] length=%d\n", i, t, (int) strlen(t));
|
||||
t = strtok(NULL, argv[2]);
|
||||
++i;
|
||||
} while (t != NULL);
|
||||
|
||||
printf("------------------------------------------------\n");
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
t = strtokc(buf, argv[2], &context);
|
||||
if (t == NULL)
|
||||
exit(0);
|
||||
do {
|
||||
printf("strtokc %d=[%s] length=%d\n", i, t, (int) strlen(t));
|
||||
t = strtokc(NULL, argv[2], &context);
|
||||
++i;
|
||||
} while (t != NULL);
|
||||
|
||||
printf("------------------------------------------------\n");
|
||||
strcpy(buf, argv[1]);
|
||||
i = 1;
|
||||
tokenLen = strntokc(token, sizeof(token), buf, argv[2], &context);
|
||||
if (tokenLen <= 0)
|
||||
exit(0);
|
||||
do {
|
||||
printf("strntokc %d=[%s] length=%d\n", i, token, tokenLen);
|
||||
tokenLen = strntokc(token, sizeof(token), NULL, argv[2], &context);
|
||||
++i;
|
||||
} while (tokenLen > 0);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
|
@ -1,135 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Strn.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char a[8];
|
||||
char pad1[32];
|
||||
char *b;
|
||||
char c[37];
|
||||
char pad2[23];
|
||||
int i;
|
||||
int len1, len2;
|
||||
|
||||
b = Strncpy(a, "hello", sizeof(a));
|
||||
b = Strncat(b, "world", sizeof(a));
|
||||
printf("1: result=[%s] should be=[%s]\n",
|
||||
b,
|
||||
"hellowo"
|
||||
);
|
||||
|
||||
for (i=0; i<sizeof(c); i++)
|
||||
c[i] = 'X';
|
||||
b = Strncpy(c, "testing", sizeof(c) - 2);
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
for (i=7; i<sizeof(c) - 2; i++) {
|
||||
if (c[i] != '\0') {
|
||||
printf("2: did not clear to end of buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (i=sizeof(c) - 2; i<sizeof(c); i++) {
|
||||
if (c[i] != 'X') {
|
||||
printf("2: overwrote buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<sizeof(c); i++)
|
||||
c[i] = 'X';
|
||||
b = Strncpy(c, "testing", sizeof(c) - 2);
|
||||
b = Strncat(b, " still", sizeof(c) - 2);
|
||||
#if (STRN_ZERO_PAD == 1)
|
||||
for (i=13; i<sizeof(c) - 2; i++) {
|
||||
if (c[i] != '\0') {
|
||||
printf("3: did not clear to end of buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (i=sizeof(c) - 2; i<sizeof(c); i++) {
|
||||
if (c[i] != 'X') {
|
||||
printf("3: overwrote buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------*/
|
||||
|
||||
b = Strnpcpy(a, "hello", sizeof(a));
|
||||
len1 = (int) (b - a);
|
||||
b = Strnpcat(a, "world", sizeof(a));
|
||||
len2 = (int) (b - a);
|
||||
printf("4: result=[%s] should be=[%s] len1=%d len2=%d\n",
|
||||
a,
|
||||
"hellowo",
|
||||
len1,
|
||||
len2
|
||||
);
|
||||
|
||||
for (i=0; i<sizeof(c); i++)
|
||||
c[i] = 'X';
|
||||
b = Strnpcpy(c, "testing", sizeof(c) - 2);
|
||||
#if (STRNP_ZERO_PAD == 1)
|
||||
for (i=7; i<sizeof(c) - 2; i++) {
|
||||
if (c[i] != '\0') {
|
||||
printf("5: did not clear to end of buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (i=sizeof(c) - 2; i<sizeof(c); i++) {
|
||||
if (c[i] != 'X') {
|
||||
printf("5: overwrote buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<sizeof(c); i++)
|
||||
c[i] = 'X';
|
||||
b = Strnpcpy(c, "testing", sizeof(c) - 2);
|
||||
b = Strnpcat(c, " still", sizeof(c) - 2);
|
||||
#if (STRNP_ZERO_PAD == 1)
|
||||
for (i=13; i<sizeof(c) - 2; i++) {
|
||||
if (c[i] != '\0') {
|
||||
printf("6: did not clear to end of buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (i=sizeof(c) - 2; i<sizeof(c); i++) {
|
||||
if (c[i] != 'X') {
|
||||
printf("6: overwrote buffer\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------*/
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = NULL;
|
||||
if (Dynscat(&str, "this is a test", 0) == NULL) {
|
||||
printf("7a: fail\n");
|
||||
} else if (strcmp(str, "this is a test") != 0) {
|
||||
printf("7b: fail\n");
|
||||
}
|
||||
free(str);
|
||||
|
||||
str = NULL;
|
||||
if (Dynscat(&str, "this is a test", 0) == NULL) {
|
||||
printf("7c: fail\n");
|
||||
} else if (strcmp(str, "this is a test") != 0) {
|
||||
printf("7d: fail\n");
|
||||
} else if (Dynscat(&str, " ", "", "and", " ", "so is this", 0) == NULL) {
|
||||
printf("7e: fail\n");
|
||||
} else if (strcmp(str, "this is a test and so is this") != 0) {
|
||||
printf("7f: fail\n");
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
exit(0);
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
char gStrnLibVersion[20] = "@(#) Strn 2.2.0";
|
|
@ -1,144 +0,0 @@
|
|||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# LibNcFTP makefile for the platform @OS@, on the host @host@.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
PKGNAME=libncftp
|
||||
VERSION=3.0.1
|
||||
PREFIX=@prefix@
|
||||
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@
|
||||
#CC=gcc
|
||||
#CFLAGS=-g -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wbad-function-cast -Wwrite-strings -Wconversion
|
||||
VPATH=@srcdir@
|
||||
CPPFLAGS=-I. -I../Strn -I../sio @CPPFLAGS@
|
||||
|
||||
LIB=libncftp.a
|
||||
LIBSO=libncftp.so.2
|
||||
LIBSOS=libncftp.so
|
||||
|
||||
# Any -D definitions:
|
||||
DEFS=@DEFS@@NDEFS@
|
||||
|
||||
CFILES=open.c cmds.c util.c rcmd.c ftp.c io.c errno.c linelist.c glob.c
|
||||
OBJS=open.o cmds.o util.o rcmd.o ftp.o io.o errno.o linelist.o glob.o
|
||||
SOBJS=open.so cmds.so util.so rcmd.so ftp.so io.so errno.so linelist.so glob.so
|
||||
|
||||
# LIBSET=@LIBSET@
|
||||
LIBSET=$(LIB)
|
||||
|
||||
SHELL=/bin/sh
|
||||
.SUFFIXES: .c .o .so
|
||||
|
||||
all: $(LIBSET)
|
||||
( cd ../sio ; $(MAKE) )
|
||||
( cd ../Strn ; $(MAKE) )
|
||||
-[ -d ./samples/minincftp ] && cd ./samples/minincftp && $(MAKE)
|
||||
-[ -d ./samples/misc ] && cd ./samples/misc && $(MAKE)
|
||||
-[ -d ./samples/monkey ] && cd ./samples/monkey && $(MAKE)
|
||||
-[ -d ./samples/ncftpget ] && cd ./samples/ncftpget && $(MAKE)
|
||||
-[ -d ./samples/ncftpls ] && cd ./samples/ncftpls && $(MAKE)
|
||||
-[ -d ./samples/ncftpput ] && cd ./samples/ncftpput && $(MAKE)
|
||||
-[ -d ./samples/ncftpsyncput ] && cd ./samples/ncftpsyncput && $(MAKE)
|
||||
@echo 'Done.'
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
-@/bin/rm -f $(LIB)
|
||||
ar rv $(LIB) $(OBJS)
|
||||
-@chmod 644 $(LIB)
|
||||
-@@RANLIB@ $(LIB)
|
||||
@/bin/ls -l $(LIB)
|
||||
|
||||
shared: $(LIBSO)
|
||||
|
||||
so: $(LIBSO)
|
||||
|
||||
$(LIBSO): $(SOBJS)
|
||||
/bin/rm -f $(LIBSO) $(LIBSOS)
|
||||
gcc -shared -Wl,-soname,$(LIBSO) -o $(LIBSO) $(SOBJS)
|
||||
/bin/ln -s $(LIBSO) $(LIBSOS)
|
||||
-@/bin/ls -l $(LIBSOS) $(LIBSO)
|
||||
|
||||
soinstall: $(LIBSO)
|
||||
[ -d "$(PREFIX)/lib" ] || mkdir -m 755 "$(PREFIX)/lib"
|
||||
[ -d "$(PREFIX)/include" ] || mkdir -m 755 "$(PREFIX)/include"
|
||||
cp $(LIBSO) $(PREFIX)/lib/$(LIBSO)
|
||||
( cd $(PREFIX)/lib ; /bin/rm -f $(LIBSOS) ; /bin/ln -s $(LIBSO) $(LIBSOS) )
|
||||
cp ncftp.h ncftp_errno.h $(PREFIX)/include
|
||||
-chmod a+r $(PREFIX)/lib/$(LIBSO) $(PREFIX)/include/ncftp.h $(PREFIX)/include/ncftp_errno.h
|
||||
|
||||
install: $(LIB)
|
||||
[ -d "$(PREFIX)/lib" ] || mkdir -m 755 "$(PREFIX)/lib"
|
||||
[ -d "$(PREFIX)/include" ] || mkdir -m 755 "$(PREFIX)/include"
|
||||
cp $(LIB) $(PREFIX)/lib/$(LIB)
|
||||
cp ncftp.h ncftp_errno.h $(PREFIX)/include
|
||||
-chmod a+r $(LIB) $(PREFIX)/lib/$(LIB) $(PREFIX)/include/ncftp.h $(PREFIX)/include/ncftp_errno.h
|
||||
( cd ../sio ; $(MAKE) "PREFIX=$(PREFIX)" install )
|
||||
( cd ../Strn ; $(MAKE) "PREFIX=$(PREFIX)" install )
|
||||
|
||||
install_samples:
|
||||
( cd ./samples ; $(MAKE) install )
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c
|
||||
|
||||
.c.so:
|
||||
$(CC) -fpic $(CFLAGS) $(CPPFLAGS) $(DEFS) $*.c -c -o $*.so
|
||||
|
||||
test: test.c $(OBJS)
|
||||
$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) test.c $(OBJS) -o test $(LDFLAGS) $(LIBS)
|
||||
|
||||
### Archiving #################################################################
|
||||
|
||||
TARDIR=libncftp-$(VERSION)
|
||||
TMPDIR=/tmp
|
||||
STGZFILE=libncftp-$(VERSION)-src.tar.gz
|
||||
|
||||
gz sgz: $(PACKAGE)
|
||||
./mksrctar.sh $(TARDIR) $(STGZFILE)
|
||||
|
||||
### Cleaning supplies ########################################################
|
||||
|
||||
clean:
|
||||
-/bin/rm -f $(OBJS) $(SOBJS) core $(LIB) $(LIBSO) $(LIBSOS)
|
||||
-[ -d ./samples/minincftp ] && cd ./samples/minincftp && $(MAKE) clean
|
||||
-[ -d ./samples/monkey ] && cd ./samples/monkey && $(MAKE) clean
|
||||
-[ -d ./samples/ncftpget ] && cd ./samples/ncftpget && $(MAKE) clean
|
||||
-[ -d ./samples/ncftpls ] && cd ./samples/ncftpls && $(MAKE) clean
|
||||
-[ -d ./samples/ncftpput ] && cd ./samples/ncftpput && $(MAKE) clean
|
||||
-[ -d ./samples/ncftpsyncput ] && cd ./samples/ncftpsyncput && $(MAKE) clean
|
||||
( sleep 2 ; cd ../sio ; $(MAKE) clean )
|
||||
( sleep 2 ; cd ../Strn ; $(MAKE) clean )
|
||||
|
||||
### Dependencies #############################################################
|
||||
|
||||
dep:
|
||||
gcc -MM $(CPPFLAGS) $(CFILES)
|
||||
|
||||
open.o: open.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
open.so: open.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
|
||||
cmds.o: cmds.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
cmds.so: cmds.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
|
||||
util.o: util.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
||||
util.so: util.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
||||
|
||||
rcmd.o: rcmd.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
rcmd.so: rcmd.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
|
||||
ftp.o: ftp.c syshdrs.h ncftp.h ncftp_errno.h ftp.h util.h
|
||||
ftp.so: ftp.c syshdrs.h ncftp.h ncftp_errno.h ftp.h util.h
|
||||
|
||||
io.o: io.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
io.so: io.c syshdrs.h ncftp.h ncftp_errno.h util.h ftp.h
|
||||
|
||||
errno.o: errno.c syshdrs.h ncftp.h ncftp_errno.h
|
||||
errno.so: errno.c syshdrs.h ncftp.h ncftp_errno.h
|
||||
|
||||
linelist.o: linelist.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
||||
linelist.so: linelist.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
||||
|
||||
glob.o: glob.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
||||
glob.so: glob.c syshdrs.h ncftp.h ncftp_errno.h util.h
|
|
@ -1,73 +0,0 @@
|
|||
Since you have the source distribution, you will need to compile the
|
||||
libraries before you can install them.
|
||||
|
||||
UNIX INSTRUCTIONS:
|
||||
------------------
|
||||
|
||||
Go to the source directory you extracted (here). There is a script you
|
||||
must run which will checks your system for certain features, so that the
|
||||
library can be compiled on a variety of UNIX systems. Run this script
|
||||
by typing "./configure" in that directory. After that, you can look at
|
||||
the Makefile it made if you like, and then you run "make" to create the
|
||||
"libncftp.a" and "libStrn.a" library files.
|
||||
|
||||
Finally, install the libraries and headers, by doing "make install".
|
||||
|
||||
View the libncftp.html file for the rest of the documentation. An easy
|
||||
way to do that is use a URL of file://Localhost/path/to/libncftp.html
|
||||
with your favorite browser.
|
||||
|
||||
|
||||
WINDOWS INSTRUCTIONS:
|
||||
---------------------
|
||||
|
||||
You will need Visual C++ 6.0 or greater to build the library and sample
|
||||
programs. This version includes two supplementary libraries which you
|
||||
must build and link with your applications: a string utility library
|
||||
(Strn) and a Winsock utility library (sio). Unlike the UNIX version of
|
||||
LibNcFTP, where the library can be built with or without the sio library,
|
||||
the sio library is required for the Windows version.
|
||||
|
||||
Keep the source hierarchy intact, so that the samples and libraries
|
||||
build without problems. Build the Strn library first, then the sio
|
||||
library, and then the LibNcFTP library. To do that, open the appropriate
|
||||
.dsw file within Visual Studio, and then select "Rebuild All" from the
|
||||
"Build" menu. Be sure to build both the Debug and the Release versions
|
||||
for each library.
|
||||
|
||||
When that is complete you should be able to build the sample programs,
|
||||
which are in the libncftp\samples directory.
|
||||
|
||||
View the libncftp.html file for the rest of the documentation. An easy
|
||||
way to do that is use a URL of file://Localhost/path/to/libncftp.html
|
||||
with your favorite browser. Note that there may be UNIX-specific
|
||||
instructions which you should ignore.
|
||||
|
||||
To build your own applications using LibNcFTP, you'll need to make sure
|
||||
you configure your project to find the header files and library files.
|
||||
|
||||
Your application may not use the sio or Strn libraries directly, but
|
||||
you still need to link with them. For example, the "simpleget" sample
|
||||
uses "..\..\Debug,..\..\..\Strn\Debug,..\..\..\sio\Debug" in the
|
||||
project option for additional library paths for the linker, and
|
||||
"kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib
|
||||
ws2_32.lib Strn.lib sio.lib libncftp.lib" for the list of libraries
|
||||
to link with. Note that LibNcFTP uses advapi32 and shell32, in
|
||||
addition to the usual "kernel32.lib user32.lib gdi32.lib". Of course,
|
||||
it also needs to link with Winsock (ws2_32.lib).
|
||||
|
||||
Similarly, you'll need to make sure one of your additional include
|
||||
directories points to the LibNcFTP directory containing ncftp.h. The
|
||||
"simpleget" sample uses "..\.." since it is in a subdirectory of the
|
||||
library itself. If you actually use functions from Strn or sio (as
|
||||
some of the samples do), you'll need to have your project look in
|
||||
their directories for their headers as well.
|
||||
|
||||
About Winsock2: This version of the library was designed for use with
|
||||
Winsock version 2. Note that older versions of Windows 95 do not include
|
||||
Winsock version 2, but can be upgraded by getting the updater from
|
||||
Microsoft: http://www.microsoft.com/windows95/downloads/contents/wuadmintools/s_wunetworkingtools/w95sockets2/default.asp
|
||||
|
||||
However, the library should also work with Winsock 1.1. That is left as
|
||||
an exercise to the coder to change the Winsock initialization to use 1.1
|
||||
and to link with the 1.1 library (wsock32.lib).
|
File diff suppressed because it is too large
Load diff
|
@ -1,207 +0,0 @@
|
|||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
#undef CAN_USE_SYS_SELECT_H
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
#undef const
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define if your compiler supports the "long long" integral type. */
|
||||
#undef HAVE_LONG_LONG
|
||||
|
||||
/* Define if you have a _res global variable used by resolve routines. */
|
||||
#undef HAVE__RES_DEFDNAME
|
||||
|
||||
/* Define if you have sigsetjmp and siglongjmp. */
|
||||
#undef HAVE_SIGSETJMP
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define to `long' if <sys/types.h> doesn't define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Format string for the printf() family for 64 bit integers. */
|
||||
#undef PRINTF_LONG_LONG
|
||||
|
||||
/* Define if printing a "long long" with "%lld" works . */
|
||||
#undef PRINTF_LONG_LONG_LLD
|
||||
|
||||
/* Define if printing a "long long" with "%qd" works . */
|
||||
#undef PRINTF_LONG_LONG_QD
|
||||
|
||||
/* Format string for the scanf() family for 64 bit integers. */
|
||||
#undef SCANF_LONG_LONG
|
||||
|
||||
/* Define if scanning a "long long" with "%lld" works. */
|
||||
#undef SCANF_LONG_LONG_LLD
|
||||
|
||||
/* Define if scanning a "long long" with "%qd" works. */
|
||||
#undef SCANF_LONG_LONG_QD
|
||||
|
||||
|
||||
/* Define to the type of arg1 for select(). */
|
||||
#undef SELECT_TYPE_ARG1
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for select(). */
|
||||
#undef SELECT_TYPE_ARG234
|
||||
|
||||
/* Define to the type of arg5 for select(). */
|
||||
#undef SELECT_TYPE_ARG5
|
||||
|
||||
/* Define if the setvbuf function takes the buffering type as its second
|
||||
argument and the buffer pointer as the third, as on System V
|
||||
before release 3. */
|
||||
#undef SETVBUF_REVERSED
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to the full path of the Tar program, if you have it. */
|
||||
#undef TAR
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Result of "uname -a" */
|
||||
#undef UNAME
|
||||
|
||||
/* Define if you have the fstat64 function. */
|
||||
#undef HAVE_FSTAT64
|
||||
|
||||
/* Define if you have the getcwd function. */
|
||||
#undef HAVE_GETCWD
|
||||
|
||||
/* Define if you have the getdomainname function. */
|
||||
#undef HAVE_GETDOMAINNAME
|
||||
|
||||
/* Define if you have the gethostname function. */
|
||||
#undef HAVE_GETHOSTNAME
|
||||
|
||||
/* Define if you have the getpass function. */
|
||||
#undef HAVE_GETPASS
|
||||
|
||||
/* Define if you have the getwd function. */
|
||||
#undef HAVE_GETWD
|
||||
|
||||
/* Define if you have the inet_ntop function. */
|
||||
#undef HAVE_INET_NTOP
|
||||
|
||||
/* Define if you have the llseek function. */
|
||||
#undef HAVE_LLSEEK
|
||||
|
||||
/* Define if you have the lseek64 function. */
|
||||
#undef HAVE_LSEEK64
|
||||
|
||||
/* Define if you have the lstat64 function. */
|
||||
#undef HAVE_LSTAT64
|
||||
|
||||
/* Define if you have the mktime function. */
|
||||
#undef HAVE_MKTIME
|
||||
|
||||
/* Define if you have the open64 function. */
|
||||
#undef HAVE_OPEN64
|
||||
|
||||
/* Define if you have the res_init function. */
|
||||
#undef HAVE_RES_INIT
|
||||
|
||||
/* Define if you have the sigaction function. */
|
||||
#undef HAVE_SIGACTION
|
||||
|
||||
/* Define if you have the snprintf function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define if you have the socket function. */
|
||||
#undef HAVE_SOCKET
|
||||
|
||||
/* Define if you have the stat64 function. */
|
||||
#undef HAVE_STAT64
|
||||
|
||||
/* Define if you have the strcasecmp function. */
|
||||
#undef HAVE_STRCASECMP
|
||||
|
||||
/* Define if you have the strerror function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#undef HAVE_STRSTR
|
||||
|
||||
/* Define if you have the strtoq function. */
|
||||
#undef HAVE_STRTOQ
|
||||
|
||||
/* Define if you have the symlink function. */
|
||||
#undef HAVE_SYMLINK
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define if you have the waitpid function. */
|
||||
#undef HAVE_WAITPID
|
||||
|
||||
/* Define if you have the <arpa/nameser.h> header file. */
|
||||
#undef HAVE_ARPA_NAMESER_H
|
||||
|
||||
/* Define if you have the <nserve.h> header file. */
|
||||
#undef HAVE_NSERVE_H
|
||||
|
||||
/* Define if you have the <resolv.h> header file. */
|
||||
#undef HAVE_RESOLV_H
|
||||
|
||||
/* Define if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
/* Define if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
/* Define if you have the 44bsd library (-l44bsd). */
|
||||
#undef HAVE_LIB44BSD
|
||||
|
||||
/* Define if you have the com_err library (-lcom_err). */
|
||||
#undef HAVE_LIBCOM_ERR
|
||||
|
||||
/* Define if you have the crypto library (-lcrypto). */
|
||||
#undef HAVE_LIBCRYPTO
|
||||
|
||||
/* Define if you have the db library (-ldb). */
|
||||
#undef HAVE_LIBDB
|
||||
|
||||
/* Define if you have the gen library (-lgen). */
|
||||
#undef HAVE_LIBGEN
|
||||
|
||||
/* Define if you have the gssapi_krb5 library (-lgssapi_krb5). */
|
||||
#undef HAVE_LIBGSSAPI_KRB5
|
||||
|
||||
/* Define if you have the isode library (-lisode). */
|
||||
#undef HAVE_LIBISODE
|
||||
|
||||
/* Define if you have the krb5 library (-lkrb5). */
|
||||
#undef HAVE_LIBKRB5
|
||||
|
||||
/* Define if you have the nsl library (-lnsl). */
|
||||
#undef HAVE_LIBNSL
|
||||
|
||||
/* Define if you have the resolv library (-lresolv). */
|
||||
#undef HAVE_LIBRESOLV
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
#undef HAVE_LIBSOCKET
|
||||
|
||||
/* Define if you have the socks5 library (-lsocks5). */
|
||||
#undef HAVE_LIBSOCKS5
|
|
@ -1,292 +0,0 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(rcmd.c)
|
||||
AC_PREREQ(2.4)
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
nc_cv_socks5=no
|
||||
no_signals=yes
|
||||
|
||||
AC_ARG_ENABLE(socks5,[ --enable-socks5 try to find and use the socks5 library],nc_cv_socks5=yes,nc_cv_socks5=no)
|
||||
AC_ARG_ENABLE(signals,[ --enable-signals allow use of signal handling],[no_signals=no])
|
||||
|
||||
|
||||
wi_OS_VAR
|
||||
|
||||
changequote(<<, >>)dnl
|
||||
MAINDIR=`pwd`
|
||||
if test -f "$MAINDIR/dos2unix.sh" ; then
|
||||
chmod u+rwx $MAINDIR/dos2unix.sh
|
||||
for dir in . ../sio ../Strn ; do
|
||||
if [ -d "$dir" ] ; then
|
||||
dir=`cd "$dir" ; pwd`
|
||||
find "$dir" -name '*.in' -exec "$MAINDIR/dos2unix.sh" {} \;
|
||||
find "$dir" -name '*.h' -exec "$MAINDIR/dos2unix.sh" {} \;
|
||||
find "$dir" -name '*.c' -exec "$MAINDIR/dos2unix.sh" {} \;
|
||||
fi
|
||||
done
|
||||
fi
|
||||
MAKE=make
|
||||
STATIC=""
|
||||
BDYNAMIC="# -Wl,-Bdynamic"
|
||||
BSTATIC="# -Wl,-Bstatic"
|
||||
LIBSET='$(LIB)'
|
||||
Z31=''
|
||||
Z32=''
|
||||
Z33=''
|
||||
Z34=''
|
||||
REDWING='no'
|
||||
SFLAG='-s'
|
||||
|
||||
case "$host" in
|
||||
redwing*) CC=cc
|
||||
LDFLAGS=''
|
||||
STATIC=''
|
||||
Z31=' -@mv $(STGZFILE) newbin/'
|
||||
Z32=' -@mv $(DTGZFILE) newbin/'
|
||||
Z33=' -@mv $(MTGZFILE) newbin/'
|
||||
Z34=' -@mv $(PTGZFILE) newbin/'
|
||||
REDWING='yes'
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$os" in
|
||||
linux)
|
||||
BDYNAMIC="-Wl,-Bdynamic"
|
||||
BSTATIC="-Wl,-Bstatic"
|
||||
if [ "$MAKEWORLD_SH" = "" ] ; then
|
||||
LIBSET='$(LIBSO) $(LIB)'
|
||||
fi
|
||||
;;
|
||||
freebsd)
|
||||
BDYNAMIC="-Wl,-Bdynamic"
|
||||
BSTATIC="-Wl,-Bstatic"
|
||||
;;
|
||||
macosx*|rhapsody)
|
||||
SFLAG='-Wl,-x'
|
||||
;;
|
||||
esac
|
||||
|
||||
changequote([, ])dnl
|
||||
|
||||
AC_SUBST(CC)
|
||||
AC_SUBST(CFLAGS)
|
||||
AC_SUBST(CPPFLAGS)
|
||||
AC_SUBST(LDFLAGS)
|
||||
AC_SUBST(STATIC)
|
||||
AC_SUBST(SFLAG)
|
||||
AC_SUBST(LIBS)
|
||||
AC_SUBST(DEFS)
|
||||
AC_SUBST(MAKE)
|
||||
AC_SUBST(Z31)
|
||||
AC_SUBST(Z32)
|
||||
AC_SUBST(Z33)
|
||||
AC_SUBST(Z34)
|
||||
AC_SUBST(LIBSET)
|
||||
AC_SUBST(BDYNAMIC)
|
||||
AC_SUBST(BSTATIC)
|
||||
AC_SUBST(MAINDIR)
|
||||
|
||||
if test -f ./samples/ncftpput2probe.c ; then
|
||||
PROBE="ncftpget2probe ncftpput2probe"
|
||||
else
|
||||
PROBE=""
|
||||
fi
|
||||
AC_SUBST(PROBE)
|
||||
|
||||
AC_PROG_CC
|
||||
wi_REQUEST_NO_Y2K_WARNINGS
|
||||
wi_CFLAGS_LFS64
|
||||
wi_DEFINE_UNAME
|
||||
|
||||
if test -f /usr/src/include/eos.h ; then
|
||||
if test "$REDWING" = no ; then
|
||||
prefix=/usr/src
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$wi_cv_prototypes" = no ; then
|
||||
AC_WARN([Your compiler is probably won't be able to compile the package.])
|
||||
AC_WARN([Get gcc, or any compiler that supports function prototypes.])
|
||||
fi
|
||||
|
||||
dnl # See if we should add -I/usr/local/include -L/usr/local/lib, etc.
|
||||
dnl wi_EXTRA_DIRS(yes, /usr/local /usr/ccs, -)
|
||||
|
||||
dnl For the sample programs.
|
||||
wi_NET_LIBS
|
||||
|
||||
if test "$nc_cv_socks5" = yes ; then
|
||||
# Look for the "SOCKS" library for use with Firewalls/Gateways.
|
||||
savelibs="$LIBS"
|
||||
AC_CHECK_LIB(db, main)
|
||||
AC_CHECK_LIB(isode, main)
|
||||
AC_CHECK_LIB(com_err, main)
|
||||
AC_CHECK_LIB(crypto, main)
|
||||
AC_CHECK_LIB(krb5, main)
|
||||
AC_CHECK_LIB(gssapi_krb5, main)
|
||||
AC_CHECK_LIB(socks5,SOCKSinit)
|
||||
if test "$ac_cv_lib_socks5" = yes ; then
|
||||
nc_cv_socks=no
|
||||
else
|
||||
LIBS="$savelibs"
|
||||
fi
|
||||
else
|
||||
ac_cv_lib_socks5=no
|
||||
fi
|
||||
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(sys/time.h unistd.h utime.h nserve.h resolv.h arpa/nameser.h)
|
||||
AC_TIME_WITH_SYS_TIME
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_OFF_T
|
||||
AC_TYPE_MODE_T
|
||||
AC_TYPE_PID_T
|
||||
AC_TYPE_UID_T
|
||||
wi__RES_DEFDNAME
|
||||
wi_USE_LONG_LONG
|
||||
|
||||
dnl Checks for library functions.
|
||||
if test "$SYS" != sunos ; then
|
||||
# Use getwd on SunOS -- getcwd does a "popen("/bin/pwd")" -- aaaccck.
|
||||
#
|
||||
AC_CHECK_FUNCS(getcwd)
|
||||
fi
|
||||
AC_CHECK_FUNCS(getwd gethostname socket strerror strstr)
|
||||
AC_CHECK_FUNCS(getpass strcasecmp getdomainname mktime symlink inet_ntop)
|
||||
AC_CHECK_FUNCS(res_init snprintf vsnprintf strtoq sigaction waitpid)
|
||||
AC_CHECK_FUNCS(open64 stat64 fstat64 lstat64 lseek64 llseek)
|
||||
wi_FUNC_SIGSETJMP
|
||||
AC_FUNC_SETVBUF_REVERSED
|
||||
|
||||
wi_HEADER_SYS_SELECT_H
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
|
||||
if test -f ../sio/sio.h ; then
|
||||
ldir=`cd ../sio ; pwd`
|
||||
LDFLAGS="$LDFLAGS -L${ldir}"
|
||||
CPPFLAGS="$CPPFLAGS -I${ldir}"
|
||||
LIBS="$LIBS -lsio"
|
||||
fi
|
||||
|
||||
if test -f ../Strn/Strn.h ; then
|
||||
ldir=`cd ../Strn ; pwd`
|
||||
LDFLAGS="$LDFLAGS -L${ldir}"
|
||||
CPPFLAGS="$CPPFLAGS -I${ldir}"
|
||||
LIBS="$LIBS -lStrn"
|
||||
fi
|
||||
|
||||
if test $ac_cv_func_getcwd = no && test $ac_cv_func_getwd = no ; then
|
||||
AC_WARN(This system does not have either getwd or getcwd?)
|
||||
AC_WARN(I find that a little hard to believe.)
|
||||
AC_WARN(You may want to try -DHAVE_GETWD anyway.)
|
||||
AC_WARN([
|
||||
This could also mean that your compiler isn't working])
|
||||
AC_WARN(with this configure script. Check the ./config.log)
|
||||
AC_WARN(and look for anomalies.)
|
||||
fi
|
||||
|
||||
wi_PROG_TAR
|
||||
AC_PROG_RANLIB
|
||||
|
||||
if test "$LONGEST_INT" = "long long" ; then
|
||||
if sed 's/^#define longest_int.*/#define longest_int long long/;
|
||||
s/^#define longest_uint.*/#define longest_uint unsigned long long/' ncftp.h > temp.h ; then
|
||||
mv temp.h ncftp.h
|
||||
chmod a+r ncftp.h
|
||||
fi
|
||||
else
|
||||
if sed 's/^#define longest_int.*/#define longest_int long/;
|
||||
s/^#define longest_uint.*/#define longest_uint unsigned long/' ncftp.h > temp.h ; then
|
||||
mv temp.h ncftp.h
|
||||
chmod a+r ncftp.h
|
||||
fi
|
||||
fi
|
||||
|
||||
CPPFLAGS="-I$MAINDIR $CPPFLAGS"
|
||||
|
||||
if test "$no_signals" = no ; then
|
||||
dv1='# if 0'
|
||||
dv2='#if 0'
|
||||
else
|
||||
dv1='# if 1'
|
||||
dv2='#if 1'
|
||||
fi
|
||||
|
||||
if sed "s!^.*/. %config1!${dv1} /* %config1!;s!^.*/. %config2!${dv2} /* %config2!" ncftp.h > temp.h ; then
|
||||
mv temp.h ncftp.h
|
||||
chmod a+r ncftp.h
|
||||
fi
|
||||
|
||||
if sed "s!^.*/. %config1!${dv1} /* %config1!;s!^.*/. %config2!${dv2} /* %config2!" syshdrs.h > temp.h ; then
|
||||
mv temp.h syshdrs.h
|
||||
chmod a+r syshdrs.h
|
||||
fi
|
||||
|
||||
changequote(<<, >>)dnl
|
||||
#
|
||||
# Configure sio specially, like it would do.
|
||||
#
|
||||
if [ -d ../sio ] ; then
|
||||
if sed "s!^.*/. %config1!${dv1} /* %config1!;s!^.*/. %config2!${dv2} /* %config2!" ../sio/sio.h > temp.h ; then
|
||||
mv temp.h ../sio/sio.h
|
||||
chmod a+r ../sio/sio.h
|
||||
fi
|
||||
if sed "s!^.*/. %config1!${dv1} /* %config1!;s!^.*/. %config2!${dv2} /* %config2!" ../sio/usio.h > temp.h ; then
|
||||
mv temp.h ../sio/usio.h
|
||||
chmod a+r ../sio/usio.h
|
||||
fi
|
||||
|
||||
patterns1=""
|
||||
patterns2=""
|
||||
if [ "$SYS" = solaris ] ; then
|
||||
patterns1='s!/. %configure%.*!#define SAccept SAcceptS!'
|
||||
patterns2='s!/. %configure%.*!#define UAccept UAcceptS!'
|
||||
fi
|
||||
|
||||
if [ "$patterns1" != "" ] ; then
|
||||
sed "$patterns1" < ../sio/sio.h > tmpfile
|
||||
if [ $? -eq 0 ] ; then
|
||||
mv tmpfile ../sio/sio.h
|
||||
chmod 644 ../sio/sio.h
|
||||
else
|
||||
/bin/rm tmpfile
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$patterns2" != "" ] ; then
|
||||
sed "$patterns2" < ../sio/usio.h > tmpfile
|
||||
if [ $? -eq 0 ] ; then
|
||||
mv tmpfile ../sio/usio.h
|
||||
chmod 644 ../sio/usio.h
|
||||
else
|
||||
/bin/rm tmpfile
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
changequote([, ])dnl
|
||||
|
||||
if test -d bin.only ; then
|
||||
binonly="bin.only/Makefile bin.only/samples/Makefile"
|
||||
else
|
||||
binonly=""
|
||||
fi
|
||||
|
||||
LIBS=`echo "$LIBS" | sed 's/^ *//;s/ *$//;s/ */ /g'`
|
||||
LDFLAGS=`echo "$LDFLAGS" | sed 's/^ *//;s/ *$//;s/ */ /g'`
|
||||
CPPFLAGS=`echo "$CPPFLAGS" | sed 's/^ *//;s/ *$//;s/ */ /g'`
|
||||
CFLAGS=`echo "$CFLAGS" | sed 's/^ *//;s/ *$//;s/ */ /g'`
|
||||
DEFS=`echo "$DEFS" | sed 's/^ *//;s/ *$//;s/ */ /g'`
|
||||
|
||||
samples=''
|
||||
for sample in minincftp monkey ncftpget ncftpput ncftpls simpleget ncftpsyncput misc ; do
|
||||
if test -f samples/$sample/Makefile.in ; then
|
||||
samples="$samples samples/$sample/Makefile"
|
||||
fi
|
||||
done
|
||||
|
||||
AC_OUTPUT([Makefile ../Strn/Makefile ../sio/Makefile $samples $binonly])
|
|
@ -1,33 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
es=1
|
||||
if [ $# -eq 0 ] ; then
|
||||
exec tr -d '\015\032'
|
||||
elif [ ! -f "$1" ] ; then
|
||||
echo "Not found: $1" 1>&2
|
||||
else
|
||||
for f in "$@" ; do
|
||||
if tr -d '\015\032' < "$f" > "$f.tmp" ; then
|
||||
if cmp "$f" "$f.tmp" > /dev/null ; then
|
||||
rm -f "$f.tmp"
|
||||
else
|
||||
touch -r "$f" "$f.tmp"
|
||||
if mv "$f" "$f.bak" ; then
|
||||
if mv "$f.tmp" "$f" ; then
|
||||
rm -f "$f.bak"
|
||||
es=$?
|
||||
echo " converted $f"
|
||||
else
|
||||
rm -f "$f.tmp"
|
||||
fi
|
||||
else
|
||||
rm -f "$f.tmp"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
rm -f "$f.tmp"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
exit $es
|
|
@ -1,163 +0,0 @@
|
|||
/* errno.c
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _libncftp_errno_c_ 1
|
||||
#include "syshdrs.h"
|
||||
|
||||
static const char *gErrList[kErrLast - kErrFirst + 2] = {
|
||||
"gethostname() failed", /* -100 */
|
||||
"hostname does not include domain name", /* -101 */
|
||||
"could not set linger mode", /* -102 */
|
||||
"could not set type of service", /* -103 */
|
||||
"could not enable out-of-band data inline", /* -104 */
|
||||
"unknown host", /* -105 */
|
||||
"could not get a new stream socket", /* -106 */
|
||||
"could not duplicate a socket", /* -107 */
|
||||
"fdopen for reading failed", /* -108 */
|
||||
"fdopen for writing failed", /* -109 */
|
||||
"getsockname failed", /* -110 */
|
||||
"could not bind the data socket", /* -111 */
|
||||
"could not listen on the data socket", /* -112 */
|
||||
"passive mode failed", /* -113 */
|
||||
"server sent bogus port number", /* -114 */
|
||||
"could not connect data socket", /* -115 */
|
||||
"could not accept data socket", /* -116 */
|
||||
"could not set restart point", /* -117 */
|
||||
"could not connect to remote host", /* -118 */
|
||||
"could not connect to remote host, but can try again", /* -119 */
|
||||
"remote host refused connection", /* -120 */
|
||||
"bad transfer type", /* -121 */
|
||||
"invalid directory parameter", /* -122 */
|
||||
"malloc failed", /* -123 */
|
||||
"PWD failed", /* -124 */
|
||||
"remote chdir failed", /* -125 */
|
||||
"remote rmdir failed", /* -126 */
|
||||
"bad line list", /* -127 */
|
||||
"unimplemented option", /* -128 */
|
||||
"unimplemented function", /* -129 */
|
||||
"remote directory listing failed", /* -130 */
|
||||
"could not retrieve remote file", /* -131 */
|
||||
"could not send file to remote host", /* -132 */
|
||||
"file write error", /* -133 */
|
||||
"file read error", /* -134 */
|
||||
"socket write error", /* -135 */
|
||||
"socket read error", /* -136 */
|
||||
"could not open file", /* -137 */
|
||||
"bad magic number in FTP library structure", /* -138 */
|
||||
"bad parameter given to library", /* -139 */
|
||||
"remote mkdir failed", /* -140 */
|
||||
"remote cd .. failed", /* -141 */
|
||||
"remote chmod failed", /* -142 */
|
||||
"remote umask failed", /* -143 */
|
||||
"remote delete failed", /* -144 */
|
||||
"remote file size inquiry failed", /* -145 */
|
||||
"remote file timestamp inquiry failed", /* -146 */
|
||||
"remote transfer type change failed", /* -147 */
|
||||
"file size inquiries not understood by remote server", /* -148 */
|
||||
"file timestamp inquiries not understood by remote server", /* -149 */
|
||||
"could not rename remote file", /* -150 */
|
||||
"could not do remote wildcard expansion", /* -151 */
|
||||
"could not set keepalive option", /* -152 */
|
||||
"remote host disconnected during login", /* -153 */
|
||||
"username was not accepted for login", /* -154 */
|
||||
"username and/or password was not accepted for login", /* -155 */
|
||||
"login failed", /* -156 */
|
||||
"invalid reply from server", /* -157 */
|
||||
"remote host closed control connection", /* -158 */
|
||||
"not connected", /* -159 */
|
||||
"could not start data transfer", /* -160 */
|
||||
"data transfer failed", /* -161 */
|
||||
"PORT failed", /* -162 */
|
||||
"PASV failed", /* -163 */
|
||||
"UTIME failed", /* -164 */
|
||||
"utime requests not understood by remote server", /* -165 */
|
||||
"HELP failed", /* -166 */
|
||||
"file deletion on local host failed", /* -167 */
|
||||
"lseek failed", /* -168 */
|
||||
"data transfer aborted by local user", /* -169 */
|
||||
"SYMLINK failed", /* -170 */
|
||||
"symlink requests not understood by remote server", /* -171 */
|
||||
"no match", /* -172 */
|
||||
"server features request failed", /* -173 */
|
||||
"no valid files were specified", /* -174 */
|
||||
"file transfer buffer has not been allocated", /* -175 */
|
||||
"will not overwrite local file with older remote file", /* -176 */
|
||||
"will not overwrite remote file with older local file", /* -177 */
|
||||
"local file appears to be the same as the remote file, no transfer necessary", /* -178 */
|
||||
"could not get extended directory information (MLSD)", /* -179 */
|
||||
"could not get extended file or directory information (MLST)", /* -180 */
|
||||
"could not parse extended file or directory information", /* -181 */
|
||||
"server does not support extended file or directory information", /* -182 */
|
||||
"server does not support extended directory information", /* -183 */
|
||||
"could not get information about specified file", /* -184 */
|
||||
"server does not support file or directory information", /* -185 */
|
||||
"could not get directory information about specified file", /* -186 */
|
||||
"server does not support directory information", /* -187 */
|
||||
"no such file or directory", /* -188 */
|
||||
"server provides no way to determine file existence", /* -189 */
|
||||
"item exists, but cannot tell if it is a file or directory", /* -190 */
|
||||
"not a directory", /* -191 */
|
||||
"directory recursion limit reached", /* -192 */
|
||||
"timed out while waiting for server response", /* -193 */
|
||||
"data transfer timed out", /* -194 */
|
||||
"canceled by user", /* -195 */
|
||||
NULL,
|
||||
};
|
||||
|
||||
int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = 0;
|
||||
|
||||
const char *
|
||||
FTPStrError(int e)
|
||||
{
|
||||
if (e == kErrGeneric) {
|
||||
return ("miscellaneous error");
|
||||
} else if (e == kNoErr) {
|
||||
return ("no error");
|
||||
} else {
|
||||
if (e < 0)
|
||||
e = -e;
|
||||
if ((e >= kErrFirst) && (e <= kErrLast)) {
|
||||
return (gErrList[e - kErrFirst]);
|
||||
}
|
||||
}
|
||||
return ("unrecognized error number");
|
||||
} /* FTPStrError */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
FTPPerror(const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2)
|
||||
{
|
||||
if (err != kNoErr) {
|
||||
if (err == eerr) {
|
||||
if ((s2 == NULL) || (s2[0] == '\0')) {
|
||||
if ((s1 == NULL) || (s1[0] == '\0')) {
|
||||
(void) fprintf(stderr, "server said: %s\n", cip->lastFTPCmdResultStr);
|
||||
} else {
|
||||
(void) fprintf(stderr, "%s: server said: %s\n", s1, cip->lastFTPCmdResultStr);
|
||||
}
|
||||
} else if ((s1 == NULL) || (s1[0] == '\0')) {
|
||||
(void) fprintf(stderr, "%s: server said: %s\n", s2, cip->lastFTPCmdResultStr);
|
||||
} else {
|
||||
(void) fprintf(stderr, "%s %s: server said: %s\n", s1, s2, cip->lastFTPCmdResultStr);
|
||||
}
|
||||
} else {
|
||||
if ((s2 == NULL) || (s2[0] == '\0')) {
|
||||
if ((s1 == NULL) || (s1[0] == '\0')) {
|
||||
(void) fprintf(stderr, "%s.\n", FTPStrError(cip->errNo));
|
||||
} else {
|
||||
(void) fprintf(stderr, "%s: %s.\n", s1, FTPStrError(cip->errNo));
|
||||
}
|
||||
} else if ((s1 == NULL) || (s1[0] == '\0')) {
|
||||
(void) fprintf(stderr, "%s: %s.\n", s2, FTPStrError(cip->errNo));
|
||||
} else {
|
||||
(void) fprintf(stderr, "%s %s: %s.\n", s1, s2, FTPStrError(cip->errNo));
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* FTPPerror */
|
File diff suppressed because it is too large
Load diff
|
@ -1,22 +0,0 @@
|
|||
/* FTP.h
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/* FTP.c */
|
||||
void MyInetAddr(char *, size_t, char **, int);
|
||||
int GetOurHostName(char *, size_t);
|
||||
void CloseControlConnection(const FTPCIPtr);
|
||||
int SetKeepAlive(const FTPCIPtr, int);
|
||||
int SetLinger(const FTPCIPtr, int, int);
|
||||
int SetTypeOfService(const FTPCIPtr, int, int);
|
||||
int SetInlineOutOfBandData(const FTPCIPtr, int);
|
||||
int OpenControlConnection(const FTPCIPtr, char *, unsigned int);
|
||||
void CloseDataConnection(const FTPCIPtr);
|
||||
int SetStartOffset(const FTPCIPtr, longest_int);
|
||||
int OpenDataConnection(const FTPCIPtr, int);
|
||||
int AcceptDataConnection(const FTPCIPtr);
|
||||
void HangupOnServer(const FTPCIPtr);
|
||||
void SendTelnetInterrupt(const FTPCIPtr);
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,160 +0,0 @@
|
|||
# Microsoft Developer Studio Project File - Name="libncftp" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=libncftp - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "libncftp.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "libncftp.mak" CFG="libncftp - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "libncftp - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "libncftp - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "libncftp - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W4 /GX /O2 /Ob1 /I "..\Strn" /I "..\sio" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "libncftp - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\Strn" /I "..\sio" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "libncftp - Win32 Release"
|
||||
# Name "libncftp - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cmds.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\errno.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ftp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\glob.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\io.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\linelist.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mksrczip.bat
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\open.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\rcmd.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\util.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\util2.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ftp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ncftp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ncftp_errno.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\syshdrs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\util.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wincfg.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
|
@ -1,29 +0,0 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "libncftp"=.\libncftp.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
|
@ -1,783 +0,0 @@
|
|||
/* linelist.c
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
/* Dynamically make a copy of a string. */
|
||||
char *
|
||||
StrDup(const char *buf)
|
||||
{
|
||||
char *cp;
|
||||
size_t len;
|
||||
|
||||
if (buf == NULL)
|
||||
return (NULL);
|
||||
|
||||
len = strlen(buf) + 1;
|
||||
cp = (char *) malloc(len);
|
||||
if (cp != NULL)
|
||||
(void) memcpy(cp, buf, len);
|
||||
return (cp);
|
||||
} /* StrDup */
|
||||
|
||||
|
||||
|
||||
/* Disposes each node of a LineList. Does a few extra things
|
||||
* so the disposed memory won't be very useful after it is freed.
|
||||
*/
|
||||
void
|
||||
DisposeLineListContents(LineListPtr list)
|
||||
{
|
||||
LinePtr lp, lp2;
|
||||
|
||||
for (lp = list->first; lp != NULL; ) {
|
||||
lp2 = lp;
|
||||
lp = lp->next;
|
||||
if (lp2->line != NULL) {
|
||||
lp2->line[0] = '\0';
|
||||
free(lp2->line);
|
||||
}
|
||||
free(lp2);
|
||||
}
|
||||
/* Same as InitLineList. */
|
||||
(void) memset(list, 0, sizeof(LineList));
|
||||
} /* DisposeLineListContents */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
InitLineList(LineListPtr list)
|
||||
{
|
||||
(void) memset(list, 0, sizeof(LineList));
|
||||
} /* InitLineList */
|
||||
|
||||
|
||||
|
||||
|
||||
LinePtr
|
||||
RemoveLine(LineListPtr list, LinePtr killMe)
|
||||
{
|
||||
LinePtr nextLine, prevLine;
|
||||
|
||||
nextLine = killMe->next;
|
||||
prevLine = killMe->prev;
|
||||
if (killMe->line != NULL) {
|
||||
killMe->line[0] = '\0'; /* Make it useless just in case. */
|
||||
free(killMe->line);
|
||||
}
|
||||
|
||||
if (list->first == killMe)
|
||||
list->first = nextLine;
|
||||
if (list->last == killMe)
|
||||
list->last = prevLine;
|
||||
|
||||
if (nextLine != NULL)
|
||||
nextLine->prev = prevLine;
|
||||
if (prevLine != NULL)
|
||||
prevLine->next = nextLine;
|
||||
|
||||
free(killMe);
|
||||
list->nLines--;
|
||||
return (nextLine);
|
||||
} /* RemoveLine */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Adds a string to the LineList specified. */
|
||||
LinePtr
|
||||
AddLine(LineListPtr list, const char *buf1)
|
||||
{
|
||||
LinePtr lp;
|
||||
char *buf;
|
||||
|
||||
lp = (LinePtr) malloc(sizeof(Line));
|
||||
if (lp != NULL) {
|
||||
buf = StrDup(buf1);
|
||||
if (buf == NULL) {
|
||||
free(lp);
|
||||
lp = NULL;
|
||||
} else {
|
||||
lp->line = buf;
|
||||
lp->next = NULL;
|
||||
if (list->first == NULL) {
|
||||
list->first = list->last = lp;
|
||||
lp->prev = NULL;
|
||||
list->nLines = 1;
|
||||
} else {
|
||||
lp->prev = list->last;
|
||||
list->last->next = lp;
|
||||
list->last = lp;
|
||||
list->nLines++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lp;
|
||||
} /* AddLine */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
CopyLineList(LineListPtr dst, LineListPtr src)
|
||||
{
|
||||
LinePtr lp, lp2;
|
||||
|
||||
InitLineList(dst);
|
||||
for (lp = src->first; lp != NULL; ) {
|
||||
lp2 = lp;
|
||||
lp = lp->next;
|
||||
if (lp2->line != NULL) {
|
||||
if (AddLine(dst, lp2->line) == NULL) {
|
||||
DisposeLineListContents(dst);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
} /* CopyLineList */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Disposes each node of a FileInfoList. Does a few extra things
|
||||
* so the disposed memory won't be very useful after it is freed.
|
||||
*/
|
||||
void
|
||||
DisposeFileInfoListContents(FileInfoListPtr list)
|
||||
{
|
||||
FileInfoPtr lp, lp2;
|
||||
|
||||
for (lp = list->first; lp != NULL; ) {
|
||||
lp2 = lp;
|
||||
lp = lp->next;
|
||||
if (lp2->relname != NULL) {
|
||||
lp2->relname[0] = '\0';
|
||||
free(lp2->relname);
|
||||
}
|
||||
if (lp2->lname != NULL) {
|
||||
lp2->lname[0] = '\0';
|
||||
free(lp2->lname);
|
||||
}
|
||||
if (lp2->rname != NULL) {
|
||||
lp2->rname[0] = '\0';
|
||||
free(lp2->rname);
|
||||
}
|
||||
if (lp2->rlinkto != NULL) {
|
||||
lp2->rlinkto[0] = '\0';
|
||||
free(lp2->rlinkto);
|
||||
}
|
||||
if (lp2->plug != NULL) {
|
||||
lp2->plug[0] = '\0';
|
||||
free(lp2->plug);
|
||||
}
|
||||
free(lp2);
|
||||
}
|
||||
|
||||
if (list->vec != NULL)
|
||||
free(list->vec);
|
||||
|
||||
/* Same as InitFileInfoList. */
|
||||
(void) memset(list, 0, sizeof(FileInfoList));
|
||||
} /* DisposeFileInfoListContents */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
InitFileInfoList(FileInfoListPtr list)
|
||||
{
|
||||
(void) memset(list, 0, sizeof(FileInfoList));
|
||||
} /* InitFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
TimeCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
if ((**fipb).mdtm == (**fipa).mdtm)
|
||||
return (0);
|
||||
else if ((**fipb).mdtm < (**fipa).mdtm)
|
||||
return (-1);
|
||||
return (1);
|
||||
} /* TimeCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
ReverseTimeCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
if ((**fipa).mdtm == (**fipb).mdtm)
|
||||
return (0);
|
||||
else if ((**fipa).mdtm < (**fipb).mdtm)
|
||||
return (-1);
|
||||
return (1);
|
||||
} /* ReverseTimeCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
SizeCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
if ((**fipb).size == (**fipa).size)
|
||||
return (0);
|
||||
else if ((**fipb).size < (**fipa).size)
|
||||
return (-1);
|
||||
return (1);
|
||||
} /* SizeCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
ReverseSizeCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
if ((**fipa).size == (**fipb).size)
|
||||
return (0);
|
||||
else if ((**fipa).size < (**fipb).size)
|
||||
return (-1);
|
||||
return (1);
|
||||
} /* ReverseSizeCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
ReverseNameCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
#ifdef HAVE_SETLOCALE
|
||||
return (strcoll((**fipb).relname, (**fipa).relname));
|
||||
#else
|
||||
return (strcmp((**fipb).relname, (**fipa).relname));
|
||||
#endif
|
||||
} /* ReverseNameCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
NameCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
#ifdef HAVE_SETLOCALE
|
||||
return (strcoll((**fipa).relname, (**fipb).relname));
|
||||
#else
|
||||
return (strcmp((**fipa).relname, (**fipb).relname));
|
||||
#endif
|
||||
} /* NameCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
BreadthFirstCmp(const void *a, const void *b)
|
||||
{
|
||||
FileInfoPtr *fipa, *fipb;
|
||||
char *cp, *cpa, *cpb;
|
||||
int depth, deptha, depthb;
|
||||
int c;
|
||||
|
||||
fipa = (FileInfoPtr *) a;
|
||||
fipb = (FileInfoPtr *) b;
|
||||
|
||||
cpa = (**fipa).relname;
|
||||
cpb = (**fipb).relname;
|
||||
|
||||
for (cp = cpa, depth = 0;;) {
|
||||
c = *cp++;
|
||||
if (c == '\0')
|
||||
break;
|
||||
if ((c == '/') || (c == '\\')) {
|
||||
depth++;
|
||||
}
|
||||
}
|
||||
deptha = depth;
|
||||
|
||||
for (cp = cpb, depth = 0;;) {
|
||||
c = *cp++;
|
||||
if (c == '\0')
|
||||
break;
|
||||
if ((c == '/') || (c == '\\')) {
|
||||
depth++;
|
||||
}
|
||||
}
|
||||
depthb = depth;
|
||||
|
||||
if (deptha < depthb)
|
||||
return (-1);
|
||||
else if (deptha > depthb)
|
||||
return (1);
|
||||
|
||||
#ifdef HAVE_SETLOCALE
|
||||
return (strcoll(cpa, cpb));
|
||||
#else
|
||||
return (strcmp(cpa, cpb));
|
||||
#endif
|
||||
} /* BreadthFirstCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SortFileInfoList(FileInfoListPtr list, int sortKey, int sortOrder)
|
||||
{
|
||||
FileInfoVec fiv;
|
||||
FileInfoPtr fip;
|
||||
int i, j, n, n2;
|
||||
|
||||
fiv = list->vec;
|
||||
if (fiv == NULL)
|
||||
return;
|
||||
|
||||
if (list->sortKey == sortKey) {
|
||||
if (list->sortOrder == sortOrder)
|
||||
return; /* Already sorted they you want. */
|
||||
|
||||
/* Reverse the sort. */
|
||||
n = list->nFileInfos;
|
||||
if (n > 1) {
|
||||
n2 = n / 2;
|
||||
for (i=0; i<n2; i++) {
|
||||
j = n - i - 1;
|
||||
fip = fiv[i];
|
||||
fiv[i] = fiv[j];
|
||||
fiv[j] = fip;
|
||||
}
|
||||
}
|
||||
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 'n') && (sortOrder == 'a')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
NameCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 'n') && (sortOrder == 'd')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
ReverseNameCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 't') && (sortOrder == 'a')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
TimeCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 't') && (sortOrder == 'd')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
ReverseTimeCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 's') && (sortOrder == 'a')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
SizeCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if ((sortKey == 's') && (sortOrder == 'd')) {
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
ReverseSizeCmp);
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
} else if (sortKey == 'b') {
|
||||
/* This is different from the rest. */
|
||||
list->sortKey = sortKey;
|
||||
list->sortOrder = sortOrder;
|
||||
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
|
||||
BreadthFirstCmp);
|
||||
}
|
||||
} /* SortFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
VectorizeFileInfoList(FileInfoListPtr list)
|
||||
{
|
||||
FileInfoVec fiv;
|
||||
FileInfoPtr fip;
|
||||
int i;
|
||||
|
||||
fiv = (FileInfoVec) calloc((size_t) (list->nFileInfos + 1), sizeof(FileInfoPtr));
|
||||
if (fiv != (FileInfoVec) 0) {
|
||||
for (i = 0, fip = list->first; fip != NULL; fip = fip->next, i++)
|
||||
fiv[i] = fip;
|
||||
list->vec = fiv;
|
||||
}
|
||||
} /* VectorizeFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
UnvectorizeFileInfoList(FileInfoListPtr list)
|
||||
{
|
||||
FileInfoVec fiv;
|
||||
FileInfoPtr fip;
|
||||
int i, n;
|
||||
|
||||
fiv = list->vec;
|
||||
if (fiv != (FileInfoVec) 0) {
|
||||
list->first = fiv[0];
|
||||
n = list->nFileInfos;
|
||||
if (n > 0) {
|
||||
list->last = fiv[n - 1];
|
||||
fip = fiv[0];
|
||||
fip->prev = NULL;
|
||||
fip->next = fiv[1];
|
||||
for (i = 1; i < n; i++) {
|
||||
fip = fiv[i];
|
||||
fip->prev = fiv[i - 1];
|
||||
fip->next = fiv[i + 1];
|
||||
}
|
||||
}
|
||||
free(fiv);
|
||||
list->vec = (FileInfoVec) 0;
|
||||
}
|
||||
} /* UnvectorizeFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
InitFileInfo(FileInfoPtr fip)
|
||||
{
|
||||
(void) memset(fip, 0, sizeof(FileInfo));
|
||||
fip->type = '-';
|
||||
fip->size = kSizeUnknown;
|
||||
fip->mdtm = kModTimeUnknown;
|
||||
} /* InitFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
FileInfoPtr
|
||||
RemoveFileInfo(FileInfoListPtr list, FileInfoPtr killMe)
|
||||
{
|
||||
FileInfoPtr nextFileInfo, prevFileInfo;
|
||||
|
||||
nextFileInfo = killMe->next;
|
||||
prevFileInfo = killMe->prev;
|
||||
if (killMe->lname != NULL) {
|
||||
killMe->lname[0] = '\0'; /* Make it useless just in case. */
|
||||
free(killMe->lname);
|
||||
}
|
||||
if (killMe->relname != NULL) {
|
||||
killMe->relname[0] = '\0';
|
||||
free(killMe->relname);
|
||||
}
|
||||
if (killMe->rname != NULL) {
|
||||
killMe->rname[0] = '\0';
|
||||
free(killMe->rname);
|
||||
}
|
||||
if (killMe->rlinkto != NULL) {
|
||||
killMe->rlinkto[0] = '\0';
|
||||
free(killMe->rlinkto);
|
||||
}
|
||||
if (killMe->plug != NULL) {
|
||||
killMe->plug[0] = '\0';
|
||||
free(killMe->plug);
|
||||
}
|
||||
|
||||
if (list->first == killMe)
|
||||
list->first = nextFileInfo;
|
||||
if (list->last == killMe)
|
||||
list->last = prevFileInfo;
|
||||
|
||||
if (nextFileInfo != NULL)
|
||||
nextFileInfo->prev = prevFileInfo;
|
||||
if (prevFileInfo != NULL)
|
||||
prevFileInfo->next = nextFileInfo;
|
||||
|
||||
free(killMe);
|
||||
list->nFileInfos--;
|
||||
return (nextFileInfo);
|
||||
} /* RemoveFileInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Adds a string to the FileInfoList specified. */
|
||||
FileInfoPtr
|
||||
AddFileInfo(FileInfoListPtr list, FileInfoPtr src)
|
||||
{
|
||||
FileInfoPtr lp;
|
||||
|
||||
lp = (FileInfoPtr) malloc(sizeof(FileInfo));
|
||||
if (lp != NULL) {
|
||||
(void) memcpy(lp, src, sizeof(FileInfo));
|
||||
lp->next = NULL;
|
||||
if (list->first == NULL) {
|
||||
list->first = list->last = lp;
|
||||
lp->prev = NULL;
|
||||
list->nFileInfos = 1;
|
||||
} else {
|
||||
lp->prev = list->last;
|
||||
list->last->next = lp;
|
||||
list->last = lp;
|
||||
list->nFileInfos++;
|
||||
}
|
||||
}
|
||||
return lp;
|
||||
} /* AddFileInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
ConcatFileInfoList(FileInfoListPtr dst, FileInfoListPtr src)
|
||||
{
|
||||
FileInfoPtr lp, lp2;
|
||||
FileInfo newfi;
|
||||
|
||||
for (lp = src->first; lp != NULL; lp = lp2) {
|
||||
lp2 = lp->next;
|
||||
newfi = *lp;
|
||||
newfi.relname = StrDup(lp->relname);
|
||||
newfi.lname = StrDup(lp->lname);
|
||||
newfi.rname = StrDup(lp->rname);
|
||||
newfi.rlinkto = StrDup(lp->rlinkto);
|
||||
newfi.plug = StrDup(lp->plug);
|
||||
if (AddFileInfo(dst, &newfi) == NULL)
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
} /* ConcatFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
ComputeRNames(FileInfoListPtr dst, const char *dstdir, int pflag, int nochop)
|
||||
{
|
||||
FileInfoPtr lp, lp2;
|
||||
char *buf;
|
||||
char *cp;
|
||||
|
||||
if (dstdir == NULL)
|
||||
dstdir = ".";
|
||||
|
||||
for (lp = dst->first; lp != NULL; lp = lp2) {
|
||||
lp2 = lp->next;
|
||||
|
||||
buf = NULL;
|
||||
if (nochop != 0) {
|
||||
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
|
||||
if (Dynscat(&buf, dstdir, "/", lp->relname, 0) == NULL)
|
||||
goto memerr;
|
||||
|
||||
if (pflag != 0) {
|
||||
/* Init lname to parent dir name of remote dir */
|
||||
cp = strrchr(dstdir, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(dstdir, '\\');
|
||||
if (cp != NULL) {
|
||||
if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
|
||||
goto memerr;
|
||||
TVFSPathToLocalPath(lp->lname);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Dynscat(&buf, lp->relname, 0) == NULL)
|
||||
goto memerr;
|
||||
}
|
||||
} else {
|
||||
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
|
||||
cp = strrchr(lp->relname, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(lp->relname, '\\');
|
||||
if (cp != NULL) {
|
||||
cp++;
|
||||
} else {
|
||||
cp = lp->relname;
|
||||
}
|
||||
if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
|
||||
goto memerr;
|
||||
|
||||
if (pflag != 0) {
|
||||
/* Init lname to parent dir name of remote dir */
|
||||
cp = strrchr(dstdir, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(dstdir, '\\');
|
||||
if (cp != NULL) {
|
||||
if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
|
||||
goto memerr;
|
||||
TVFSPathToLocalPath(lp->lname);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cp = strrchr(lp->relname, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(lp->relname, '\\');
|
||||
if (cp != NULL) {
|
||||
cp++;
|
||||
} else {
|
||||
cp = lp->relname;
|
||||
}
|
||||
if (Dynscat(&buf, cp, 0) == NULL)
|
||||
goto memerr;
|
||||
}
|
||||
}
|
||||
lp->rname = buf;
|
||||
if (lp->rname == NULL) {
|
||||
memerr:
|
||||
return (-1);
|
||||
}
|
||||
LocalPathToTVFSPath(lp->rname);
|
||||
}
|
||||
return (0);
|
||||
} /* ComputeRNames */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
ComputeLNames(FileInfoListPtr dst, const char *srcdir, const char *dstdir, int nochop)
|
||||
{
|
||||
FileInfoPtr lp, lp2;
|
||||
char *buf;
|
||||
char *cp;
|
||||
|
||||
if (srcdir != NULL) {
|
||||
cp = strrchr(srcdir, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(srcdir, '\\');
|
||||
if (cp != NULL)
|
||||
srcdir = cp + 1;
|
||||
}
|
||||
if (dstdir == NULL)
|
||||
dstdir = ".";
|
||||
|
||||
for (lp = dst->first; lp != NULL; lp = lp2) {
|
||||
lp2 = lp->next;
|
||||
|
||||
buf = NULL;
|
||||
if (nochop != 0) {
|
||||
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
|
||||
if (Dynscat(&buf, dstdir, "/", 0) == NULL)
|
||||
goto memerr;
|
||||
}
|
||||
if (lp->lname != NULL) {
|
||||
if (Dynscat(&buf, lp->lname, "/", 0) == NULL)
|
||||
goto memerr;
|
||||
} else if (srcdir != NULL) {
|
||||
if (Dynscat(&buf, srcdir, "/", 0) == NULL)
|
||||
goto memerr;
|
||||
}
|
||||
if (Dynscat(&buf, lp->relname, 0) == NULL)
|
||||
goto memerr;
|
||||
} else {
|
||||
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
|
||||
cp = strrchr(lp->relname, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(lp->relname, '\\');
|
||||
if (cp == NULL) {
|
||||
cp = lp->relname;
|
||||
} else {
|
||||
cp++;
|
||||
}
|
||||
if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
|
||||
goto memerr;
|
||||
} else {
|
||||
cp = strrchr(lp->relname, '/');
|
||||
if (cp == NULL)
|
||||
cp = strrchr(lp->relname, '\\');
|
||||
if (cp == NULL) {
|
||||
cp = lp->relname;
|
||||
} else {
|
||||
cp++;
|
||||
}
|
||||
if (Dynscat(&buf, cp, 0) == NULL)
|
||||
goto memerr;
|
||||
}
|
||||
}
|
||||
if (buf == NULL) {
|
||||
memerr:
|
||||
return (-1);
|
||||
}
|
||||
if (lp->lname != NULL) {
|
||||
free(lp->lname);
|
||||
lp->lname = NULL;
|
||||
}
|
||||
lp->lname = buf;
|
||||
TVFSPathToLocalPath(lp->lname);
|
||||
}
|
||||
return (0);
|
||||
} /* ComputeLNames */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
ConcatFileToFileInfoList(FileInfoListPtr dst, char *rfile)
|
||||
{
|
||||
FileInfo newfi;
|
||||
|
||||
InitFileInfo(&newfi); /* Use defaults. */
|
||||
newfi.relname = StrDup(rfile);
|
||||
newfi.rname = NULL;
|
||||
newfi.lname = NULL;
|
||||
|
||||
if (AddFileInfo(dst, &newfi) == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
} /* ConcatFileToFileInfoList */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
LineListToFileInfoList(LineListPtr src, FileInfoListPtr dst)
|
||||
{
|
||||
LinePtr lp, lp2;
|
||||
|
||||
InitFileInfoList(dst);
|
||||
for (lp = src->first; lp != NULL; lp = lp2) {
|
||||
lp2 = lp->next;
|
||||
if (ConcatFileToFileInfoList(dst, lp->line) < 0)
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
} /* LineListToFileList */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
LineToFileInfoList(LinePtr lp, FileInfoListPtr dst)
|
||||
{
|
||||
InitFileInfoList(dst);
|
||||
if (ConcatFileToFileInfoList(dst, lp->line) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
} /* LineToFileInfoList */
|
||||
|
||||
/* eof */
|
|
@ -1,97 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -f rcmd.c ] ; then
|
||||
cd ..
|
||||
fi
|
||||
wd=`pwd`
|
||||
for f in libncftp sio Strn doc ; do
|
||||
if [ ! -f "$f" ] && [ ! -d "$f" ] ; then
|
||||
echo "Missing directory $f ?" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
( cd libncftp ; make clean )
|
||||
|
||||
TMPDIR=/tmp
|
||||
if [ "$#" -lt 2 ] ; then
|
||||
TARDIR="libncftp"
|
||||
STGZFILE="$TARDIR.tar.gz"
|
||||
else
|
||||
TARDIR="$1"
|
||||
STGZFILE="$2"
|
||||
fi
|
||||
|
||||
rm -rf $TMPDIR/TAR
|
||||
mkdir -p -m755 $TMPDIR/TAR/$TARDIR 2>/dev/null
|
||||
|
||||
chmod 755 configure sh/* install-sh 2>/dev/null
|
||||
|
||||
find . -depth -follow -type f | sed '
|
||||
/sio\/configure$/d
|
||||
/Strn\/configure$/d
|
||||
/\.o$/d
|
||||
/\.so$/d
|
||||
/\.a$/d
|
||||
/\.lib$/d
|
||||
/\.ncb$/d
|
||||
/\.pdb$/d
|
||||
/\.idb$/d
|
||||
/\.pch$/d
|
||||
/\.ilk$/d
|
||||
/\.res$/d
|
||||
/\.aps$/d
|
||||
/\.opt$/d
|
||||
/\.plg$/d
|
||||
/\.obj$/d
|
||||
/\.exe$/d
|
||||
/\.zip$/d
|
||||
/\.gz$/d
|
||||
/\.tgz$/d
|
||||
/\.tar$/d
|
||||
/\.swp$/d
|
||||
/\.orig$/d
|
||||
/\.rej$/d
|
||||
/\/Makefile\.bin$/p
|
||||
/\.bin$/d
|
||||
/\/bin/d
|
||||
/\/core$/d
|
||||
/\/^[Rr]elease$/d
|
||||
/\/^[Dd]ebug$/d
|
||||
/\/sio\/.*\//d
|
||||
/shit/d
|
||||
/\/upload/d
|
||||
/\/config\.h\.in$/p
|
||||
/\/config\./d
|
||||
/\/Makefile$/d
|
||||
/\/OLD/d
|
||||
/\/old/d' | cut -c3- | tee "$wd/doc/manifest.txt" | cpio -Lpdm $TMPDIR/TAR/$TARDIR
|
||||
|
||||
( cd "$TMPDIR/TAR/$TARDIR" ; ln -s doc/README.txt README )
|
||||
|
||||
x=`tar --help 2>&1 | sed -n 's/.*owner=NAME.*/owner=NAME/g;/owner=NAME/p'`
|
||||
case "$x" in
|
||||
*owner=NAME*)
|
||||
TARFLAGS="-c --owner=bin --group=bin --verbose -f"
|
||||
TAR=tar
|
||||
;;
|
||||
*)
|
||||
TARFLAGS="cvf"
|
||||
TAR=tar
|
||||
x2=`gtar --help 2>&1 | sed -n 's/.*owner=NAME.*/owner=NAME/g;/owner=NAME/p'`
|
||||
case "$x2" in
|
||||
*owner=NAME*)
|
||||
TARFLAGS="-c --owner=bin --group=bin --verbose -f"
|
||||
TAR=gtar
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
( cd $TMPDIR/TAR ; $TAR $TARFLAGS - $TARDIR | gzip -c > $STGZFILE )
|
||||
cp $TMPDIR/TAR/$STGZFILE .
|
||||
chmod 644 $STGZFILE
|
||||
rm -rf $TMPDIR/TAR
|
||||
ls -l $STGZFILE 2>/dev/null
|
||||
mv $TGZFILE newbin/ 2>/dev/null
|
||||
exit 0
|
|
@ -1,19 +0,0 @@
|
|||
@echo off
|
||||
|
||||
IF NOT EXIST ncftp.h GOTO ERR:
|
||||
|
||||
cd ..
|
||||
erase \temp\libncftp.zip >NUL
|
||||
pkzip25.exe -add -204 -dir=current -excl=*.lib -excl=*.exe -excl=*.zip -excl=*.gz -excl=*.tar -excl=*.o -excl=*.obj -excl=*.pch -excl=*.ilk -excl=*.ncb -excl=*.opt -excl=*.pdb -excl=*.idb -excl=*.plg -excl=config.* -excl=*.so -excl=*.a -excl=Makefile -excl=core \temp\libncftp.zip libncftp\*.*
|
||||
pkzip25.exe -add -204 -dir=current -excl=*.lib -excl=*.exe -excl=*.zip -excl=*.gz -excl=*.tar -excl=*.o -excl=*.obj -excl=*.pch -excl=*.ilk -excl=*.ncb -excl=*.opt -excl=*.pdb -excl=*.idb -excl=*.plg -excl=config.* -excl=*.so -excl=*.a -excl=Makefile -excl=core \temp\libncftp.zip sio\*.*
|
||||
pkzip25.exe -add -204 -dir=current -excl=*.lib -excl=*.exe -excl=*.zip -excl=*.gz -excl=*.tar -excl=*.o -excl=*.obj -excl=*.pch -excl=*.ilk -excl=*.ncb -excl=*.opt -excl=*.pdb -excl=*.idb -excl=*.plg -excl=config.* -excl=*.so -excl=*.a -excl=Makefile -excl=core \temp\libncftp.zip Strn\*.*
|
||||
|
||||
cd libncftp
|
||||
dir \temp\libncftp.zip
|
||||
|
||||
GOTO DONE:
|
||||
|
||||
:ERR
|
||||
echo Please cd to the source directory and then run this script.
|
||||
|
||||
:DONE
|
|
@ -1,691 +0,0 @@
|
|||
/* ncftp.h
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ncftp_h_
|
||||
#define _ncftp_h_ 1
|
||||
|
||||
#define kLibraryVersion "@(#) LibNcFTP 3.0.6 (April 14, 2001)"
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define longest_int LONGLONG
|
||||
# define longest_uint ULONGLONG
|
||||
# ifndef HAVE_LONG_LONG
|
||||
# define HAVE_LONG_LONG 1
|
||||
# endif
|
||||
# ifndef SCANF_LONG_LONG
|
||||
# define SCANF_LONG_LONG "%I64d"
|
||||
# endif
|
||||
# ifndef PRINTF_LONG_LONG
|
||||
# define PRINTF_LONG_LONG "%I64d"
|
||||
# endif
|
||||
# ifndef PRINTF_LONG_LONG_I64D
|
||||
# define PRINTF_LONG_LONG_I64D 1
|
||||
# endif
|
||||
# ifndef SCANF_LONG_LONG_I64D
|
||||
# define SCANF_LONG_LONG_I64D 1
|
||||
# endif
|
||||
# ifndef USE_SIO
|
||||
# define USE_SIO 1
|
||||
# endif
|
||||
# ifndef NO_SIGNALS
|
||||
# define NO_SIGNALS 1
|
||||
# endif
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <sys/time.h>
|
||||
# if !defined(__ultrix) || !defined(XTI)
|
||||
# include <sys/socket.h>
|
||||
# endif
|
||||
# include <netinet/in.h>
|
||||
# if 1 /* %config1% -- set by configure script -- do not modify */
|
||||
# ifndef USE_SIO
|
||||
# define USE_SIO 1
|
||||
# endif
|
||||
# ifndef NO_SIGNALS
|
||||
# define NO_SIGNALS 1
|
||||
# endif
|
||||
# else
|
||||
# ifndef USE_SIO
|
||||
# define USE_SIO 0
|
||||
# endif
|
||||
/* #undef NO_SIGNALS */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "ncftp_errno.h"
|
||||
|
||||
/* This is used to verify validty of the data passed in.
|
||||
* It also specifies the minimum version that is binary-compatibile with
|
||||
* this version. (So this may not necessarily be kLibraryVersion.)
|
||||
*/
|
||||
#define kLibraryMagic "LibNcFTP 3.0.6"
|
||||
|
||||
#ifndef longest_int
|
||||
#define longest_int long long
|
||||
#define longest_uint unsigned long long
|
||||
#endif
|
||||
|
||||
#ifndef forever
|
||||
# define forever for ( ; ; )
|
||||
#endif
|
||||
|
||||
typedef void (*FTPSigProc)(int);
|
||||
|
||||
typedef struct Line *LinePtr;
|
||||
typedef struct Line {
|
||||
LinePtr prev, next;
|
||||
char *line;
|
||||
} Line;
|
||||
|
||||
typedef struct LineList {
|
||||
LinePtr first, last;
|
||||
int nLines;
|
||||
} LineList, *LineListPtr;
|
||||
|
||||
typedef struct Response {
|
||||
LineList msg;
|
||||
int codeType;
|
||||
int code;
|
||||
int printMode;
|
||||
int eofOkay;
|
||||
int hadEof;
|
||||
} Response, *ResponsePtr;
|
||||
|
||||
#if USE_SIO && !defined(_SReadlineInfo_)
|
||||
#define _SReadlineInfo_ 1
|
||||
typedef struct SReadlineInfo {
|
||||
char *buf; /* Pointer to beginning of buffer. */
|
||||
char *bufPtr; /* Pointer to current position in buffer. */
|
||||
char *bufLim; /* Pointer to end of buffer. */
|
||||
size_t bufSize; /* Current size of buffer block. */
|
||||
size_t bufSizeMax; /* Maximum size available for buffer. */
|
||||
int malloc; /* If non-zero, malloc() was used for buf. */
|
||||
int fd; /* File descriptor to use for I/O. */
|
||||
int timeoutLen; /* Timeout to use, in seconds. */
|
||||
int requireEOLN; /* When buffer is full, continue reading and discarding until \n? */
|
||||
} SReadlineInfo;
|
||||
#endif
|
||||
|
||||
typedef struct FTPLibraryInfo {
|
||||
char magic[16]; /* Don't modify this field. */
|
||||
int init; /* Don't modify this field. */
|
||||
int socksInit; /* Don't modify this field. */
|
||||
unsigned int defaultPort; /* Don't modify this field. */
|
||||
char ourHostName[64]; /* Don't modify this field. */
|
||||
int hresult; /* Don't modify this field. */
|
||||
int htried; /* Don't modify this field. */
|
||||
char defaultAnonPassword[80]; /* You may set this after init. */
|
||||
} FTPLibraryInfo, *FTPLIPtr;
|
||||
|
||||
typedef struct FTPConnectionInfo *FTPCIPtr;
|
||||
typedef void (*FTPProgressMeterProc)(const FTPCIPtr, int);
|
||||
typedef void (*FTPLogProc)(const FTPCIPtr, char *);
|
||||
typedef void (*FTPConnectMessageProc)(const FTPCIPtr, ResponsePtr);
|
||||
typedef void (*FTPLoginMessageProc)(const FTPCIPtr, ResponsePtr);
|
||||
typedef void (*FTPRedialStatusProc)(const FTPCIPtr, int, int);
|
||||
typedef void (*FTPPrintResponseProc)(const FTPCIPtr, ResponsePtr);
|
||||
typedef int (*FTPFtwProc)(const FTPCIPtr cip, const char *fn, int flag);
|
||||
typedef void (*FTPGetPassphraseProc)(const FTPCIPtr, LineListPtr pwPrompt, char *pass, size_t dsize);
|
||||
|
||||
typedef struct FTPConnectionInfo {
|
||||
char magic[16]; /* Don't modify this field. */
|
||||
char host[64]; /* REQUIRED input parameter. */
|
||||
char user[64]; /* OPTIONAL input parameter. */
|
||||
char pass[64]; /* OPTIONAL input parameter. */
|
||||
char acct[64]; /* OPTIONAL input parameter. */
|
||||
unsigned int port; /* OPTIONAL input parameter. */
|
||||
unsigned int xferTimeout; /* OPTIONAL input parameter. */
|
||||
unsigned int connTimeout; /* OPTIONAL input parameter. */
|
||||
unsigned int ctrlTimeout; /* OPTIONAL input parameter. */
|
||||
unsigned int abortTimeout; /* OPTIONAL input parameter. */
|
||||
FILE *debugLog; /* OPTIONAL input parameter. */
|
||||
FILE *errLog; /* OPTIONAL input parameter. */
|
||||
FTPLogProc debugLogProc; /* OPTIONAL input parameter. */
|
||||
FTPLogProc errLogProc; /* OPTIONAL input parameter. */
|
||||
FTPLIPtr lip; /* Do not modify this field. */
|
||||
int maxDials; /* OPTIONAL input parameter. */
|
||||
int redialDelay; /* OPTIONAL input parameter. */
|
||||
int dataPortMode; /* OPTIONAL input parameter. */
|
||||
char actualHost[64]; /* Do not modify this field. */
|
||||
char ip[32]; /* Do not modify this field. */
|
||||
int connected; /* Do not modify this field. */
|
||||
int loggedIn; /* Do not modify this field. */
|
||||
int curTransferType; /* Do not modify this field. */
|
||||
char *startingWorkingDirectory; /* Use, but do not modify. */
|
||||
longest_int startPoint; /* Do not modify this field. */
|
||||
int hasPASV; /* Do not modify this field. */
|
||||
int hasSIZE; /* Do not modify this field. */
|
||||
int hasMDTM; /* Do not modify this field. */
|
||||
int hasREST; /* Do not modify this field. */
|
||||
int hasNLST_d; /* Do not modify this field. */
|
||||
int hasUTIME; /* Do not modify this field. */
|
||||
int hasFEAT; /* Do not modify this field. */
|
||||
int hasMLSD; /* Do not modify this field. */
|
||||
int hasMLST; /* Do not modify this field. */
|
||||
int usedMLS; /* Do not modify this field. */
|
||||
int hasCLNT; /* Do not modify this field. */
|
||||
int hasRETRBUFSIZE; /* Do not modify this field. */
|
||||
int hasRBUFSIZ; /* Do not modify this field. */
|
||||
int hasRBUFSZ; /* Do not modify this field. */
|
||||
int hasSTORBUFSIZE; /* Do not modify this field. */
|
||||
int hasSBUFSIZ; /* Do not modify this field. */
|
||||
int hasSBUFSZ; /* Do not modify this field. */
|
||||
int hasBUFSIZE; /* Do not modify this field. */
|
||||
int mlsFeatures; /* Do not modify this field. */
|
||||
int STATfileParamWorks; /* Do not modify this field. */
|
||||
int NLSTfileParamWorks; /* Do not modify this field. */
|
||||
struct sockaddr_in servCtlAddr; /* Do not modify this field. */
|
||||
struct sockaddr_in servDataAddr; /* Do not modify this field. */
|
||||
struct sockaddr_in ourCtlAddr; /* Do not modify this field. */
|
||||
struct sockaddr_in ourDataAddr; /* Do not modify this field. */
|
||||
int netMode; /* Do not use or modify. */
|
||||
char *buf; /* Do not modify this field. */
|
||||
size_t bufSize; /* Do not modify this field. */
|
||||
FILE *cin; /* Do not use or modify. */
|
||||
FILE *cout; /* Do not use or modify. */
|
||||
int ctrlSocketR; /* You may use but not modify/close. */
|
||||
int ctrlSocketW; /* You may use but not modify/close. */
|
||||
int dataSocket; /* You may use but not modify/close. */
|
||||
int errNo; /* You may modify this if you want. */
|
||||
unsigned short ephemLo; /* You may modify this if you want. */
|
||||
unsigned short ephemHi; /* You may modify this if you want. */
|
||||
int cancelXfer; /* You may modify this. */
|
||||
longest_int bytesTransferred; /* Do not modify this field. */
|
||||
FTPProgressMeterProc progress; /* You may modify this if you want. */
|
||||
int useProgressMeter; /* Used internally. */
|
||||
int leavePass; /* You may modify this. */
|
||||
double sec; /* Do not modify this field. */
|
||||
double secLeft; /* Do not modify this field. */
|
||||
double kBytesPerSec; /* Do not modify this field. */
|
||||
double percentCompleted; /* Do not modify this field. */
|
||||
longest_int expectedSize; /* Do not modify this field. */
|
||||
time_t mdtm; /* Do not modify this field. */
|
||||
time_t nextProgressUpdate; /* Do not modify this field. */
|
||||
const char *rname; /* Do not modify this field. */
|
||||
const char *lname; /* Do not modify this field. */
|
||||
struct timeval t0; /* Do not modify this field. */
|
||||
int stalled; /* Do not modify this field. */
|
||||
int dataTimedOut; /* Do not modify this field. */
|
||||
int eofOkay; /* Do not use or modify. */
|
||||
char lastFTPCmdResultStr[128]; /* You may modify this if you want. */
|
||||
LineList lastFTPCmdResultLL; /* Use, but do not modify. */
|
||||
int lastFTPCmdResultNum; /* You may modify this if you want. */
|
||||
char firewallHost[64]; /* You may modify this. */
|
||||
char firewallUser[64]; /* You may modify this. */
|
||||
char firewallPass[64]; /* You may modify this. */
|
||||
unsigned int firewallPort; /* You may modify this. */
|
||||
int firewallType; /* You may modify this. */
|
||||
int require20; /* You may modify this. */
|
||||
int usingTAR; /* Use, but do not modify. */
|
||||
FTPConnectMessageProc onConnectMsgProc; /* You may modify this. */
|
||||
FTPRedialStatusProc redialStatusProc; /* You may modify this. */
|
||||
FTPPrintResponseProc printResponseProc; /* You may modify this. */
|
||||
FTPLoginMessageProc onLoginMsgProc; /* You may modify this. */
|
||||
size_t ctrlSocketRBufSize; /* You may modify this. */
|
||||
size_t ctrlSocketSBufSize; /* You may modify this. */
|
||||
size_t dataSocketRBufSize; /* You may modify this. */
|
||||
size_t dataSocketSBufSize; /* You may modify this. */
|
||||
int serverType; /* Do not use or modify. */
|
||||
int ietfCompatLevel; /* Do not use or modify. */
|
||||
int numDownloads; /* Do not use or modify. */
|
||||
int numUploads; /* Do not use or modify. */
|
||||
int numListings; /* Do not use or modify. */
|
||||
int doNotGetStartingWorkingDirectory; /* You may modify this. */
|
||||
#if USE_SIO
|
||||
char srlBuf[768];
|
||||
SReadlineInfo ctrlSrl; /* Do not use or modify. */
|
||||
#endif
|
||||
FTPGetPassphraseProc passphraseProc; /* You may modify this. */
|
||||
int iUser; /* Scratch integer field you can use. */
|
||||
void *pUser; /* Scratch pointer field you can use. */
|
||||
longest_int llUser; /* Scratch long long field you can use. */
|
||||
const char *asciiFilenameExtensions; /* You may assign this. */
|
||||
int reserved[32]; /* Do not use or modify. */
|
||||
} FTPConnectionInfo;
|
||||
|
||||
typedef struct FileInfo *FileInfoPtr, **FileInfoVec;
|
||||
typedef struct FileInfo {
|
||||
FileInfoPtr prev, next;
|
||||
char *relname;
|
||||
char *rname;
|
||||
char *rlinkto;
|
||||
char *lname;
|
||||
char *plug; /* permissions, links, user, group */
|
||||
int type;
|
||||
time_t mdtm;
|
||||
longest_int size;
|
||||
size_t relnameLen;
|
||||
} FileInfo;
|
||||
|
||||
typedef struct FileInfoList {
|
||||
FileInfoPtr first, last;
|
||||
FileInfoVec vec;
|
||||
size_t maxFileLen;
|
||||
size_t maxPlugLen;
|
||||
int nFileInfos;
|
||||
int sortKey;
|
||||
int sortOrder;
|
||||
} FileInfoList, *FileInfoListPtr;
|
||||
|
||||
/* Used with UnMlsT() */
|
||||
typedef struct MLstItem{
|
||||
char fname[512];
|
||||
char linkto[512];
|
||||
int ftype;
|
||||
longest_int fsize;
|
||||
time_t ftime;
|
||||
int mode; /* "UNIX.mode" fact */
|
||||
int uid; /* "UNIX.uid" fact */
|
||||
int gid; /* "UNIX.gid" fact */
|
||||
char perm[16]; /* "perm" fact */
|
||||
char owner[16]; /* "UNIX.owner" fact */
|
||||
char group[16]; /* "UNIX.group" fact */
|
||||
} MLstItem, *MLstItemPtr;
|
||||
|
||||
/* Messages we pass to the current progress meter function. */
|
||||
#define kPrInitMsg 1
|
||||
#define kPrUpdateMsg 2
|
||||
#define kPrEndMsg 3
|
||||
|
||||
/* Parameter for OpenDataConnection() */
|
||||
#define kSendPortMode 0
|
||||
#define kPassiveMode 1
|
||||
#define kFallBackToSendPortMode 2
|
||||
|
||||
/* Parameter for AcceptDataConnection() */
|
||||
#define kAcceptForWriting 00100
|
||||
#define kAcceptForReading 00101
|
||||
#define kNetWriting kAcceptForWriting
|
||||
#define kNetReading kAcceptForReading
|
||||
|
||||
/* Value for printMode field of Response structure.
|
||||
* Generally, don't worry about this.
|
||||
*/
|
||||
#define kResponseNoPrint 00001
|
||||
#define kResponseNoSave 00002
|
||||
#define kResponseNoProc 00002
|
||||
|
||||
#define kDefaultFTPPort 21
|
||||
|
||||
#define kDefaultFTPBufSize 32768
|
||||
|
||||
#ifdef USE_SIO
|
||||
/* This version of the library can handle timeouts without
|
||||
* a user-installed signal handler.
|
||||
*/
|
||||
#define kDefaultXferTimeout 600
|
||||
#define kDefaultConnTimeout 30
|
||||
#define kDefaultCtrlTimeout 135
|
||||
#define kDefaultAbortTimeout 10
|
||||
#else
|
||||
/* The library doesn't use timeouts by default because it would
|
||||
* break apps that don't have a SIGALRM handler.
|
||||
*/
|
||||
#define kDefaultXferTimeout (0) /* No timeout. */
|
||||
#define kDefaultConnTimeout (0) /* No timeout. */
|
||||
#define kDefaultCtrlTimeout (0) /* No timeout. */
|
||||
#define kDefaultAbortTimeout 10
|
||||
#endif
|
||||
|
||||
|
||||
/* Suggested timeout values, in seconds, if you use timeouts. */
|
||||
#define kSuggestedDefaultXferTimeout (0) /* No timeout on data blocks. */
|
||||
#define kSuggestedDefaultConnTimeout 30
|
||||
#define kSuggestedDefaultCtrlTimeout 135 /* 2*MSL, + slop */
|
||||
#define kSuggestedAbortTimeout 10
|
||||
|
||||
#define kDefaultMaxDials 3
|
||||
#define kDefaultRedialDelay 20 /* seconds */
|
||||
|
||||
#define kDefaultDataPortMode kSendPortMode
|
||||
|
||||
#define kRedialStatusDialing 0
|
||||
#define kRedialStatusSleeping 1
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
# define INADDR_NONE (0xffffffff) /* <netinet/in.h> should have it. */
|
||||
#endif
|
||||
|
||||
#define kTypeAscii 'A'
|
||||
#define kTypeBinary 'I'
|
||||
#define kTypeEbcdic 'E'
|
||||
|
||||
#define kGlobChars "[*?"
|
||||
#define GLOBCHARSINSTR(a) (strpbrk(a, kGlobChars) != NULL)
|
||||
|
||||
#define kGlobYes 1
|
||||
#define kGlobNo 0
|
||||
#define kRecursiveYes 1
|
||||
#define kRecursiveNo 0
|
||||
#define kAppendYes 1
|
||||
#define kAppendNo 0
|
||||
#define kResumeYes 1
|
||||
#define kResumeNo 0
|
||||
#define kDeleteYes 1
|
||||
#define kDeleteNo 0
|
||||
#define kTarYes 1
|
||||
#define kTarNo 0
|
||||
|
||||
#define UNIMPLEMENTED_CMD(a) ((a == 500) || (a == 502) || (a == 504))
|
||||
|
||||
/* Possible values returned by GetDateAndTime. */
|
||||
#define kSizeUnknown ((longest_int) (-1))
|
||||
#define kModTimeUnknown ((time_t) (-1))
|
||||
|
||||
#define kCommandAvailabilityUnknown (-1)
|
||||
#define kCommandAvailable 1
|
||||
#define kCommandNotAvailable 0
|
||||
|
||||
/* Values returned by FTPDecodeURL. */
|
||||
#define kNotURL (-1)
|
||||
#define kMalformedURL (-2)
|
||||
|
||||
/* Values for the firewall/proxy open. */
|
||||
#define kFirewallNotInUse 0
|
||||
#define kFirewallUserAtSite 1
|
||||
#define kFirewallLoginThenUserAtSite 2
|
||||
#define kFirewallSiteSite 3
|
||||
#define kFirewallOpenSite 4
|
||||
#define kFirewallUserAtUserPassAtPass 5
|
||||
#define kFirewallFwuAtSiteFwpUserPass 6
|
||||
#define kFirewallUserAtSiteFwuPassFwp 7
|
||||
#define kFirewallLastType kFirewallUserAtSiteFwuPassFwp
|
||||
|
||||
/* For MLSD, MLST, and STAT. */
|
||||
#define kPreferredMlsOpts (kMlsOptType | kMlsOptSize | kMlsOptModify | kMlsOptUNIXmode | kMlsOptUNIXowner | kMlsOptUNIXgroup | kMlsOptUNIXuid | kMlsOptUNIXgid | kMlsOptPerm)
|
||||
|
||||
#define kMlsOptType 00001
|
||||
#define kMlsOptSize 00002
|
||||
#define kMlsOptModify 00004
|
||||
#define kMlsOptUNIXmode 00010
|
||||
#define kMlsOptUNIXowner 00020
|
||||
#define kMlsOptUNIXgroup 00040
|
||||
#define kMlsOptPerm 00100
|
||||
#define kMlsOptUNIXuid 00200
|
||||
#define kMlsOptUNIXgid 00400
|
||||
#define kMlsOptUnique 01000
|
||||
|
||||
/* For FTPFtw(). */
|
||||
#define kFtwFile 0
|
||||
#define kFtwDir 1
|
||||
|
||||
/* For FTPChdir3(). */
|
||||
#define kChdirOnly 00000
|
||||
#define kChdirAndMkdir 00001
|
||||
#define kChdirAndGetCWD 00002
|
||||
#define kChdirOneSubdirAtATime 00004
|
||||
|
||||
/* Return codes for custom ConfirmResumeDownloadProcs. */
|
||||
#define kConfirmResumeProcNotUsed 0
|
||||
#define kConfirmResumeProcSaidSkip 1
|
||||
#define kConfirmResumeProcSaidResume 2
|
||||
#define kConfirmResumeProcSaidOverwrite 3
|
||||
#define kConfirmResumeProcSaidAppend 4
|
||||
#define kConfirmResumeProcSaidBestGuess 5
|
||||
#define kConfirmResumeProcSaidCancel 6
|
||||
|
||||
typedef int (*ConfirmResumeDownloadProc)(
|
||||
const char *volatile *localpath,
|
||||
volatile longest_int localsize,
|
||||
volatile time_t localmtime,
|
||||
const char *volatile remotepath,
|
||||
volatile longest_int remotesize,
|
||||
volatile time_t remotetime,
|
||||
volatile longest_int *volatile startPoint
|
||||
);
|
||||
|
||||
typedef int (*ConfirmResumeUploadProc)(
|
||||
const char *volatile localpath,
|
||||
volatile longest_int localsize,
|
||||
volatile time_t localmtime,
|
||||
const char *volatile *remotepath,
|
||||
volatile longest_int remotesize,
|
||||
volatile time_t remotetime,
|
||||
volatile longest_int *volatile startPoint
|
||||
);
|
||||
|
||||
#define NoConfirmResumeDownloadProc ((ConfirmResumeDownloadProc) 0)
|
||||
#define NoConfirmResumeUploadProc ((ConfirmResumeUploadProc) 0)
|
||||
#define NoGetPassphraseProc ((FTPGetPassphraseProc) 0)
|
||||
|
||||
/* Types of FTP server software.
|
||||
*
|
||||
* We try to recognize a few of these, for information
|
||||
* only, and occasional uses to determine some additional
|
||||
* or broken functionality.
|
||||
*/
|
||||
#define kServerTypeUnknown 0
|
||||
#define kServerTypeWuFTPd 1
|
||||
#define kServerTypeNcFTPd 2
|
||||
#define kServerTypeProFTPD 3
|
||||
#define kServerTypeMicrosoftFTP 4
|
||||
#define kServerTypeWarFTPd 5
|
||||
#define kServerTypeServ_U 6
|
||||
#define kServerTypeWFTPD 7
|
||||
#define kServerTypeVFTPD 8
|
||||
#define kServerTypeFTP_Max 9
|
||||
#define kServerTypeRoxen 10
|
||||
#define kServerTypeNetWareFTP 11
|
||||
#define kServerTypeWS_FTP 12
|
||||
|
||||
|
||||
#if !defined(WIN32) && !defined(_WINDOWS) && !defined(closesocket)
|
||||
# define closesocket close
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(_WINDOWS) && !defined(ioctlsocket)
|
||||
# define ioctlsocket ioctl
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define LOCAL_PATH_DELIM '\\'
|
||||
# define LOCAL_PATH_DELIM_STR "\\"
|
||||
# define LOCAL_PATH_ALTDELIM '/'
|
||||
# define IsLocalPathDelim(c) ((c == LOCAL_PATH_DELIM) || (c == LOCAL_PATH_ALTDELIM))
|
||||
# define UNC_PATH_PREFIX "\\\\"
|
||||
# define IsUNCPrefixed(s) (IsLocalPathDelim(s[0]) && IsLocalPathDelim(s[1]))
|
||||
#else
|
||||
# define LOCAL_PATH_DELIM '/'
|
||||
# define LOCAL_PATH_DELIM_STR "/"
|
||||
# define StrFindLocalPathDelim(a) strchr(a, LOCAL_PATH_DELIM)
|
||||
# define StrRFindLocalPathDelim(a) strrchr(a, LOCAL_PATH_DELIM)
|
||||
# define StrRemoveTrailingLocalPathDelim StrRemoveTrailingSlashes
|
||||
# define IsLocalPathDelim(c) (c == LOCAL_PATH_DELIM)
|
||||
# define TVFSPathToLocalPath(s)
|
||||
# define LocalPathToTVFSPath(s)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef _libncftp_ftp_c_
|
||||
extern char gLibNcFTPVersion[64];
|
||||
#endif
|
||||
|
||||
#ifndef _libncftp_errno_c_
|
||||
extern int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings;
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
# ifndef UNUSED
|
||||
# define UNUSED(a) a __attribute__ ((unused))
|
||||
# endif
|
||||
# define LIBNCFTP_USE_VAR(a)
|
||||
#else
|
||||
# define LIBNCFTP_USE_VAR(a) gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
|
||||
# ifndef UNUSED
|
||||
# define UNUSED(a) a
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Public routines */
|
||||
void FTPAbortDataTransfer(const FTPCIPtr cip);
|
||||
int FTPChdir(const FTPCIPtr cip, const char *const cdCwd);
|
||||
int FTPChdirAndGetCWD(const FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize);
|
||||
int FTPChdir3(FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize, int flags);
|
||||
int FTPChmod(const FTPCIPtr cip, const char *const pattern, const char *const mode, const int doGlob);
|
||||
int FTPCloseHost(const FTPCIPtr cip);
|
||||
int FTPCmd(const FTPCIPtr cip, const char *const cmdspec, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
int FTPDecodeURL(const FTPCIPtr cip, char *const url, LineListPtr cdlist, char *const fn, const size_t fnsize, int *const xtype, int *const wantnlst);
|
||||
int FTPDelete(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
|
||||
int FTPFileExists(const FTPCIPtr cip, const char *const file);
|
||||
int FTPFileModificationTime(const FTPCIPtr cip, const char *const file, time_t *const mdtm);
|
||||
int FTPFileSize(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type);
|
||||
int FTPFileSizeAndModificationTime(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type, time_t *const mdtm);
|
||||
int FTPFileType(const FTPCIPtr cip, const char *const file, int *const ftype);
|
||||
int FTPGetCWD(const FTPCIPtr cip, char *const newCwd, const size_t newCwdSize);
|
||||
int FTPGetFiles3(const FTPCIPtr cip, const char *pattern, const char *const dstdir, const int recurse, int doGlob, const int xtype, const int resumeflag, int appendflag, const int deleteflag, const int tarflag, const ConfirmResumeDownloadProc resumeProc, int reserved);
|
||||
int FTPGetOneFile3(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag, const int deleteflag, const ConfirmResumeDownloadProc resumeProc, int reserved);
|
||||
int FTPInitConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip, size_t bufsize);
|
||||
int FTPInitLibrary(const FTPLIPtr lip);
|
||||
int FTPIsDir(const FTPCIPtr cip, const char *const dir);
|
||||
int FTPIsRegularFile(const FTPCIPtr cip, const char *const file);
|
||||
int FTPList(const FTPCIPtr cip, const int outfd, const int longMode, const char *const lsflag);
|
||||
int FTPListToMemory(const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags);
|
||||
int FTPLocalGlob(FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob);
|
||||
int FTPLoginHost(const FTPCIPtr cip);
|
||||
int FTPMkdir(const FTPCIPtr cip, const char *const newDir, const int recurse);
|
||||
int FTPMkdir2(const FTPCIPtr cip, const char *const newDir, const int recurse, const char *const curDir);
|
||||
int FTPOpenHost(const FTPCIPtr cip);
|
||||
int FTPOpenHostNoLogin(const FTPCIPtr cip);
|
||||
void FTPPerror(const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2);
|
||||
int FTPPutOneFile3(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int appendflag, const char *const tmppfx, const char *const tmpsfx, const int resumeflag, const int deleteflag, const ConfirmResumeUploadProc resumeProc, int reserved);
|
||||
int FTPPutFiles3(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, int appendflag, const char *const tmppfx, const char *const tmpsfx, const int resumeflag, const int deleteflag, const ConfirmResumeUploadProc resumeProc, int reserved);
|
||||
int FTPRemoteGlob(FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob);
|
||||
int FTPRename(const FTPCIPtr cip, const char *const oldname, const char *const newname);
|
||||
int FTPRmdir(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
|
||||
void FTPShutdownHost(const FTPCIPtr cip);
|
||||
const char *FTPStrError(int e);
|
||||
int FTPSymlink(const FTPCIPtr cip, const char *const lfrom, const char *const lto);
|
||||
int FTPUmask(const FTPCIPtr cip, const char *const umsk);
|
||||
int FTPUtime(const FTPCIPtr cip, const char *const file, time_t actime, time_t modtime, time_t crtime);
|
||||
|
||||
/* LineList routines */
|
||||
int CopyLineList(LineListPtr, LineListPtr);
|
||||
void DisposeLineListContents(LineListPtr);
|
||||
void InitLineList(LineListPtr);
|
||||
LinePtr RemoveLine(LineListPtr, LinePtr);
|
||||
LinePtr AddLine(LineListPtr, const char *);
|
||||
|
||||
/* Other routines that might be useful. */
|
||||
char *StrDup(const char *);
|
||||
char *FGets(char *, size_t, FILE *);
|
||||
void GetHomeDir(char *, size_t);
|
||||
void GetUsrName(char *, size_t);
|
||||
void Scramble(unsigned char *dst, size_t dsize, unsigned char *src, char *key);
|
||||
time_t UnMDTMDate(char *);
|
||||
int MkDirs(const char *const, int mode1);
|
||||
char *GetPass(const char *const prompt);
|
||||
int FilenameExtensionIndicatesASCII(const char *const pathName, const char *const extnList);
|
||||
void StrRemoveTrailingSlashes(char *dst);
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
char *StrFindLocalPathDelim(const char *src);
|
||||
char *StrRFindLocalPathDelim(const char *src);
|
||||
void StrRemoveTrailingLocalPathDelim(char *dst);
|
||||
void TVFSPathToLocalPath(char *dst);
|
||||
void LocalPathToTVFSPath(char *dst);
|
||||
int gettimeofday(struct timeval *const tp, void *junk);
|
||||
void WinSleep(unsigned int seconds);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
void (*NcSignal(int signum, void (*handler)(int)))(int);
|
||||
#elif !defined(NcSignal)
|
||||
# define NcSignal signal
|
||||
#endif
|
||||
|
||||
/* Obselete routines. */
|
||||
int FTPGetOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
|
||||
int FTPGetOneFile2(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag);
|
||||
int FTPGetFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
|
||||
int FTPGetFiles2(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int resumeflag, const int appendflag);
|
||||
int FTPGetOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
|
||||
int FTPGetFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
|
||||
int FTPPutOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
|
||||
int FTPPutOneFile2(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int appendflag, const char *const tmppfx, const char *const tmpsfx);
|
||||
int FTPPutFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
|
||||
int FTPPutFiles2(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int appendflag, const char *const tmppfx, const char *const tmpsfx);
|
||||
int FTPPutOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
|
||||
int FTPPutFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
|
||||
|
||||
/* Private routines, or stuff for testing */
|
||||
char *FTPGetLocalCWD(char *buf, size_t size);
|
||||
int FTPQueryFeatures(const FTPCIPtr);
|
||||
int FTPMListOneFile(const FTPCIPtr cip, const char *const file, const MLstItemPtr mlip);
|
||||
void FTPInitializeOurHostName(const FTPLIPtr);
|
||||
void FTPInitializeAnonPassword(const FTPLIPtr);
|
||||
int FTPListToMemory2(const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags, const int blanklines, int *const tryMLSD);
|
||||
void FTPInitIOTimer(const FTPCIPtr);
|
||||
int FTPStartDataCmd(const FTPCIPtr, int, int, longest_int, const char *,...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 5, 6)))
|
||||
#endif
|
||||
;
|
||||
void FTPStartIOTimer(const FTPCIPtr);
|
||||
void FTPStopIOTimer(const FTPCIPtr);
|
||||
void FTPUpdateIOTimer(const FTPCIPtr);
|
||||
int FTPSetTransferType(const FTPCIPtr, int);
|
||||
int FTPEndDataCmd(const FTPCIPtr, int);
|
||||
int FTPRemoteHelp(const FTPCIPtr, const char *const, const LineListPtr);
|
||||
int FTPCmdNoResponse(const FTPCIPtr, const char *const cmdspec,...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
int WaitResponse(const FTPCIPtr, unsigned int);
|
||||
int FTPLocalRecursiveFileList(FTPCIPtr, LineListPtr, FileInfoListPtr);
|
||||
int FTPLocalRecursiveFileList2(FTPCIPtr cip, LineListPtr fileList, FileInfoListPtr files, int erelative);
|
||||
int FTPRemoteRecursiveFileList(FTPCIPtr, LineListPtr, FileInfoListPtr);
|
||||
int FTPRemoteRecursiveFileList1(FTPCIPtr, char *const, FileInfoListPtr);
|
||||
int FTPRebuildConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip);
|
||||
int FTPFileExistsStat(const FTPCIPtr cip, const char *const file);
|
||||
int FTPFileExistsNlst(const FTPCIPtr cip, const char *const file);
|
||||
int FTPFileExists2(const FTPCIPtr cip, const char *const file, const int tryMDTM, const int trySIZE, const int tryMLST, const int trySTAT, const int tryNLST);
|
||||
int FTPFtw(const FTPCIPtr cip, const char *const dir, FTPFtwProc proc, int maxdepth);
|
||||
int BufferGets(char *, size_t, int, char *, char **, char **, size_t);
|
||||
void DisposeFileInfoListContents(FileInfoListPtr);
|
||||
void InitFileInfoList(FileInfoListPtr);
|
||||
void InitFileInfo(FileInfoPtr);
|
||||
FileInfoPtr RemoveFileInfo(FileInfoListPtr, FileInfoPtr);
|
||||
FileInfoPtr AddFileInfo(FileInfoListPtr, FileInfoPtr);
|
||||
void SortFileInfoList(FileInfoListPtr, int, int);
|
||||
void VectorizeFileInfoList(FileInfoListPtr);
|
||||
void UnvectorizeFileInfoList(FileInfoListPtr);
|
||||
int ComputeRNames(FileInfoListPtr, const char *, int, int);
|
||||
int ComputeLNames(FileInfoListPtr, const char *, const char *, int);
|
||||
int ConcatFileInfoList(FileInfoListPtr, FileInfoListPtr);
|
||||
int ConcatFileToFileInfoList(FileInfoListPtr, char *);
|
||||
int LineListToFileInfoList(LineListPtr, FileInfoListPtr);
|
||||
int LineToFileInfoList(LinePtr, FileInfoListPtr);
|
||||
void URLCopyToken(char *, size_t, const char *, size_t);
|
||||
int UnMlsT(const char *const, const MLstItemPtr);
|
||||
int UnMlsD(FileInfoListPtr, LineListPtr);
|
||||
int UnLslR(FileInfoListPtr, LineListPtr, int);
|
||||
void TraceResponse(const FTPCIPtr, ResponsePtr);
|
||||
void PrintResponse(const FTPCIPtr, LineListPtr);
|
||||
void DoneWithResponse(const FTPCIPtr, ResponsePtr);
|
||||
ResponsePtr InitResponse(void);
|
||||
void ReInitResponse(const FTPCIPtr, ResponsePtr);
|
||||
int GetTelnetString(const FTPCIPtr, char *, size_t, FILE *, FILE *);
|
||||
int GetResponse(const FTPCIPtr, ResponsePtr);
|
||||
int RCmd(const FTPCIPtr, ResponsePtr, const char *, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 3, 4)))
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ncftp_h_ */
|
|
@ -1,113 +0,0 @@
|
|||
/* ncftp_errno.h
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef kNoErr
|
||||
# define kNoErr 0
|
||||
#endif
|
||||
|
||||
#ifndef kErrGeneric
|
||||
# define kErrGeneric (-1)
|
||||
#endif
|
||||
|
||||
#define kErrFirst (100)
|
||||
#define kErrGetHostNameFailed (-100)
|
||||
#define kErrHostWithoutDomain (-101)
|
||||
#define kErrSetLinger (-102)
|
||||
#define kErrSetTypeOfService (-103)
|
||||
#define kErrSetOutOfBandInline (-104)
|
||||
#define kErrHostUnknown (-105)
|
||||
#define kErrNewStreamSocket (-106)
|
||||
#define kErrDupSocket (-107)
|
||||
#define kErrFdopenR (-108)
|
||||
#define kErrFdopenW (-109)
|
||||
#define kErrGetSockName (-110)
|
||||
#define kErrBindDataSocket (-111)
|
||||
#define kErrListenDataSocket (-112)
|
||||
#define kErrPassiveModeFailed (-113)
|
||||
#define kErrServerSentBogusPortNumber (-114)
|
||||
#define kErrConnectDataSocket (-115)
|
||||
#define kErrAcceptDataSocket (-116)
|
||||
#define kErrSetStartPoint (-117)
|
||||
#define kErrConnectMiscErr (-118)
|
||||
#define kErrConnectRetryableErr (-119)
|
||||
#define kErrConnectRefused (-120)
|
||||
#define kErrBadTransferType (-121)
|
||||
#define kErrInvalidDirParam (-122)
|
||||
#define kErrMallocFailed (-123)
|
||||
#define kErrPWDFailed (-124)
|
||||
#define kErrCWDFailed (-125)
|
||||
#define kErrRMDFailed (-126)
|
||||
#define kErrBadLineList (-127)
|
||||
#define kErrUnimplementedOption (-128)
|
||||
#define kErrUnimplementedFunction (-129)
|
||||
#define kErrLISTFailed (-130)
|
||||
#define kErrRETRFailed (-131)
|
||||
#define kErrSTORFailed (-132)
|
||||
#define kErrWriteFailed (-133)
|
||||
#define kErrReadFailed (-134)
|
||||
#define kErrSocketWriteFailed (-135)
|
||||
#define kErrSocketReadFailed (-136)
|
||||
#define kErrOpenFailed (-137)
|
||||
#define kErrBadMagic (-138)
|
||||
#define kErrBadParameter (-139)
|
||||
#define kErrMKDFailed (-140)
|
||||
#define kErrCannotGoToPrevDir (-141)
|
||||
#define kErrChmodFailed (-142)
|
||||
#define kErrUmaskFailed (-143)
|
||||
#define kErrDELEFailed (-144)
|
||||
#define kErrSIZEFailed (-145)
|
||||
#define kErrMDTMFailed (-146)
|
||||
#define kErrTYPEFailed (-147)
|
||||
#define kErrSIZENotAvailable (-148)
|
||||
#define kErrMDTMNotAvailable (-149)
|
||||
#define kErrRenameFailed (-150)
|
||||
#define kErrGlobFailed (-151)
|
||||
#define kErrSetKeepAlive (-152)
|
||||
#define kErrHostDisconnectedDuringLogin (-153)
|
||||
#define kErrBadRemoteUser (-154)
|
||||
#define kErrBadRemoteUserOrPassword (-155)
|
||||
#define kErrLoginFailed (-156)
|
||||
#define kErrInvalidReplyFromServer (-157)
|
||||
#define kErrRemoteHostClosedConnection (-158)
|
||||
#define kErrNotConnected (-159)
|
||||
#define kErrCouldNotStartDataTransfer (-160)
|
||||
#define kErrDataTransferFailed (-161)
|
||||
#define kErrPORTFailed (-162)
|
||||
#define kErrPASVFailed (-163)
|
||||
#define kErrUTIMEFailed (-164)
|
||||
#define kErrUTIMENotAvailable (-165)
|
||||
#define kErrHELPFailed (-166)
|
||||
#define kErrLocalDeleteFailed (-167)
|
||||
#define kErrLseekFailed (-168)
|
||||
#define kErrDataTransferAborted (-169)
|
||||
#define kErrSYMLINKFailed (-170)
|
||||
#define kErrSYMLINKNotAvailable (-171)
|
||||
#define kErrGlobNoMatch (-172)
|
||||
#define kErrFEATNotAvailable (-173)
|
||||
#define kErrNoValidFilesSpecified (-174)
|
||||
#define kErrNoBuf (-175)
|
||||
#define kErrLocalFileNewer (-176)
|
||||
#define kErrRemoteFileNewer (-177)
|
||||
#define kErrLocalSameAsRemote (-178)
|
||||
#define kErrMLSDFailed (-179)
|
||||
#define kErrMLSTFailed (-180)
|
||||
#define kErrInvalidMLSTResponse (-181)
|
||||
#define kErrMLSTNotAvailable (-182)
|
||||
#define kErrMLSDNotAvailable (-183)
|
||||
#define kErrSTATFailed (-184)
|
||||
#define kErrSTATwithFileNotAvailable (-185)
|
||||
#define kErrNLSTFailed (-186)
|
||||
#define kErrNLSTwithFileNotAvailable (-187)
|
||||
#define kErrNoSuchFileOrDirectory (-188)
|
||||
#define kErrCantTellIfFileExists (-189)
|
||||
#define kErrFileExistsButCannotDetermineType (-190)
|
||||
#define kErrNotADirectory (-191)
|
||||
#define kErrRecursionLimitReached (-192)
|
||||
#define kErrControlTimedOut (-193)
|
||||
#define kErrDataTimedOut (-194)
|
||||
#define kErrUserCanceled (-195)
|
||||
#define kErrLast (195)
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,237 +0,0 @@
|
|||
/* syshdrs.h
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# include "wincfg.h"
|
||||
# include <winsock2.h> /* Includes <windows.h> */
|
||||
//# include <shlobj.h>
|
||||
# ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# include <errno.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
# endif
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <stdarg.h>
|
||||
# include <time.h>
|
||||
# include <io.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# define sleep WinSleep
|
||||
# ifndef S_ISREG
|
||||
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
||||
# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
||||
# endif
|
||||
# ifndef open
|
||||
# define open _open
|
||||
# define write _write
|
||||
# define read _read
|
||||
# define close _close
|
||||
# define lseek _lseek
|
||||
# define stat _stat
|
||||
# define lstat _stat
|
||||
# define fstat _fstat
|
||||
# define dup _dup
|
||||
# define utime _utime
|
||||
# define utimbuf _utimbuf
|
||||
# endif
|
||||
# ifndef unlink
|
||||
# define unlink remove
|
||||
# endif
|
||||
# define NO_SIGNALS 1
|
||||
# define USE_SIO 1
|
||||
#else /* UNIX */
|
||||
|
||||
#if defined(AIX) || defined(_AIX)
|
||||
# define _ALL_SOURCE 1
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#if !defined(HAVE_GETCWD) && defined(HAVE_GETWD)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/telnet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <pwd.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_NET_ERRNO_H
|
||||
# include <net/errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#endif
|
||||
#ifdef HAVE_NSERVE_H
|
||||
# include <nserve.h>
|
||||
#endif
|
||||
#ifdef HAVE_RESOLV_H
|
||||
# include <resolv.h>
|
||||
#endif
|
||||
#ifdef CAN_USE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETCWD
|
||||
# ifndef HAVE_UNISTD_H
|
||||
extern char *getcwd();
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAVE_GETWD
|
||||
# include <sys/param.h>
|
||||
# ifndef MAXPATHLEN
|
||||
# define MAXPATHLEN 1024
|
||||
# endif
|
||||
extern char *getwd(char *);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* UNIX */
|
||||
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_OPEN64)
|
||||
# define Open open64
|
||||
#else
|
||||
# define Open open
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_STAT64) && defined(HAVE_STRUCT_STAT64)
|
||||
# define Stat stat64
|
||||
# ifdef HAVE_FSTAT64
|
||||
# define Fstat fstat64
|
||||
# else
|
||||
# define Fstat fstat
|
||||
# endif
|
||||
# ifdef HAVE_LSTAT64
|
||||
# define Lstat lstat64
|
||||
# else
|
||||
# define Lstat lstat
|
||||
# endif
|
||||
#else
|
||||
# define Stat stat
|
||||
# define Fstat fstat
|
||||
# define Lstat lstat
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_LSEEK64)
|
||||
# define Lseek(a,b,c) lseek64(a, (longest_int) b, c)
|
||||
#elif defined(HAVE_LONG_LONG) && defined(HAVE_LLSEEK)
|
||||
# if 1
|
||||
# if defined(LINUX) && (LINUX <= 23000)
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
# else
|
||||
# define Lseek(a,b,c) llseek(a, (longest_int) b, c)
|
||||
# endif
|
||||
# else
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
# endif
|
||||
#else
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef IAC
|
||||
|
||||
/*
|
||||
* Definitions for the TELNET protocol.
|
||||
*/
|
||||
#define IAC 255 /* interpret as command: */
|
||||
#define DONT 254 /* you are not to use option */
|
||||
#define DO 253 /* please, you use option */
|
||||
#define WONT 252 /* I won't use option */
|
||||
#define WILL 251 /* I will use option */
|
||||
#define SB 250 /* interpret as subnegotiation */
|
||||
#define GA 249 /* you may reverse the line */
|
||||
#define EL 248 /* erase the current line */
|
||||
#define EC 247 /* erase the current character */
|
||||
#define AYT 246 /* are you there */
|
||||
#define AO 245 /* abort output--but let prog finish */
|
||||
#define IP 244 /* interrupt process--permanently */
|
||||
#define BREAK 243 /* break */
|
||||
#define DM 242 /* data mark--for connect. cleaning */
|
||||
#define NOP 241 /* nop */
|
||||
#define SE 240 /* end sub negotiation */
|
||||
#define EOR 239 /* end of record (transparent mode) */
|
||||
#define ABORT 238 /* Abort process */
|
||||
#define SUSP 237 /* Suspend process */
|
||||
#define xEOF 236 /* End of file: EOF is already used... */
|
||||
|
||||
#define SYNCH 242 /* for telfunc calls */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTIME_H
|
||||
# include <utime.h>
|
||||
#else
|
||||
struct utimbuf { time_t actime, modtime; };
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_LIBSOCKS5
|
||||
# define SOCKS 5
|
||||
# include <socks.h>
|
||||
#endif
|
||||
|
||||
#if 1 /* %config2% -- set by configure script -- do not modify */
|
||||
# ifndef USE_SIO
|
||||
# define USE_SIO 1
|
||||
# endif
|
||||
# ifndef NO_SIGNALS
|
||||
# define NO_SIGNALS 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef USE_SIO
|
||||
# define USE_SIO 0
|
||||
# endif
|
||||
/* #undef NO_SIGNALS */
|
||||
#endif
|
||||
|
||||
#if USE_SIO
|
||||
# include "sio\sio.h" /* Library header. */
|
||||
#endif
|
||||
|
||||
#include "Strn\Strn.h" /* Library header. */
|
||||
#include "ncftp.h" /* Library header. */
|
||||
|
||||
#include "util.h"
|
||||
#include "ftp.h"
|
||||
|
||||
/* eof */
|
File diff suppressed because it is too large
Load diff
|
@ -1,108 +0,0 @@
|
|||
/* Util.h
|
||||
*
|
||||
* Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _util_h_
|
||||
#define _util_h_ 1
|
||||
|
||||
typedef char string[160], str16[16], str32[32], str64[64];
|
||||
typedef char longstring[512];
|
||||
typedef char pathname[512];
|
||||
|
||||
#ifndef PTRZERO
|
||||
# define PTRZERO(p,siz) (void) memset(p, 0, (size_t) (siz))
|
||||
#endif
|
||||
|
||||
#define ZERO(a) PTRZERO(&(a), sizeof(a))
|
||||
#define STREQ(a,b) (strcmp(a,b) == 0)
|
||||
#define STRNEQ(a,b,s) (strncmp(a,b,(size_t)(s)) == 0)
|
||||
|
||||
#ifndef ISTRCMP
|
||||
# ifdef HAVE_STRCASECMP
|
||||
# define ISTRCMP strcasecmp
|
||||
# define ISTRNCMP strncasecmp
|
||||
# else
|
||||
# define ISTRCMP strcmp
|
||||
# define ISTRNCMP strncmp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define ISTREQ(a,b) (ISTRCMP(a,b) == 0)
|
||||
#define ISTRNEQ(a,b,s) (ISTRNCMP(a,b,(size_t)(s)) == 0)
|
||||
|
||||
typedef int (*cmp_t)(const void *, const void *);
|
||||
#define QSORT(base,n,s,cmp) \
|
||||
qsort(base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
|
||||
|
||||
#define BSEARCH(key,base,n,s,cmp) \
|
||||
bsearch(key, base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
|
||||
|
||||
/* For Error(): */
|
||||
#define kDoPerror 1
|
||||
#define kDontPerror 0
|
||||
|
||||
#define kClosedFileDescriptor (-1)
|
||||
|
||||
#define SZ(a) ((size_t) (a))
|
||||
|
||||
#ifndef F_OK
|
||||
# define F_OK 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_REMOVE
|
||||
# define UNLINK remove
|
||||
#else
|
||||
# define UNLINK unlink
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0
|
||||
# define SEEK_CUR 1
|
||||
# define SEEK_END 2
|
||||
#endif /* SEEK_SET */
|
||||
|
||||
#ifdef SETVBUF_REVERSED
|
||||
# define SETVBUF(a,b,c,d) setvbuf(a,c,b,d)
|
||||
#else
|
||||
# define SETVBUF setvbuf
|
||||
#endif
|
||||
|
||||
|
||||
/* Util.c */
|
||||
char *FGets(char *, size_t, FILE *);
|
||||
struct passwd *GetPwByName(void);
|
||||
void GetHomeDir(char *, size_t);
|
||||
void GetUsrName(char *, size_t);
|
||||
void CloseFile(FILE **);
|
||||
void PrintF(const FTPCIPtr cip, const char *const fmt, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
void Error(const FTPCIPtr cip, const int pError, const char *const fmt, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 3, 4)))
|
||||
#endif
|
||||
;
|
||||
int GetSockBufSize(int sockfd, size_t *rsize, size_t *ssize);
|
||||
int SetSockBufSize(int sockfd, size_t rsize, size_t ssize);
|
||||
time_t UnMDTMDate(char *);
|
||||
void Scramble(unsigned char *dst, size_t dsize, unsigned char *src, char *key);
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
char *StrFindLocalPathDelim(const char *src);
|
||||
char *StrRFindLocalPathDelim(const char *src);
|
||||
void TVFSPathToLocalPath(char *dst);
|
||||
void LocalPathToTVFSPath(char *dst);
|
||||
int gettimeofday(struct timeval *const tp, void *junk);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
void (*NcSignal(int signum, void (*handler)(int)))(int);
|
||||
#elif !defined(NcSignal)
|
||||
# define NcSignal signal
|
||||
#endif
|
||||
|
||||
#endif /* _util_h_ */
|
|
@ -1,34 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
|
||||
extern "C" void
|
||||
GetSpecialDir(char *dst, size_t size, int whichDir)
|
||||
{
|
||||
LPITEMIDLIST idl;
|
||||
LPMALLOC shl;
|
||||
char path[MAX_PATH + 1];
|
||||
HRESULT hResult;
|
||||
|
||||
memset(dst, 0, size);
|
||||
hResult = SHGetMalloc(&shl);
|
||||
if (SUCCEEDED(hResult)) {
|
||||
hResult = SHGetSpecialFolderLocation(
|
||||
NULL,
|
||||
CSIDL_PERSONAL,
|
||||
&idl
|
||||
);
|
||||
|
||||
if (SUCCEEDED(hResult)) {
|
||||
if(SHGetPathFromIDList(idl, path)) {
|
||||
(void) strncpy(dst, path, size - 1);
|
||||
dst[size - 1] = '\0';
|
||||
}
|
||||
shl->Free(idl);
|
||||
}
|
||||
shl->Release();
|
||||
}
|
||||
} // GetSpecialDir
|
||||
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for select(). */
|
||||
#define SELECT_TYPE_ARG234 (fd_set *)
|
||||
|
||||
/* Define to the type of arg5 for select(). */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if you have the gethostname function. */
|
||||
#define HAVE_GETHOSTNAME 1
|
||||
|
||||
/* Define if you have the mktime function. */
|
||||
#define HAVE_MKTIME 1
|
||||
|
||||
/* Define if you have the socket function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* #define HAVE_STRCASECMP 1 */
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
/* #define HAVE_UNISTD_H 1 */
|
||||
|
||||
#define HAVE_LONG_LONG 1
|
||||
#define SCANF_LONG_LONG "%I64d"
|
||||
#define PRINTF_LONG_LONG "%I64d"
|
||||
#define PRINTF_LONG_LONG_I64D 1
|
||||
#define SCANF_LONG_LONG_I64D 1
|
|
@ -1,89 +0,0 @@
|
|||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# NcFTP makefile for the platform @OS@, on the host @host@.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@
|
||||
#CC=gcc
|
||||
#CFLAGS=-O2 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wbad-function-cast -Wwrite-strings -Wconversion
|
||||
VPATH=@srcdir@
|
||||
CPPFLAGS=@CPPFLAGS@ -I. -I../libncftp -I../Strn -I../sio
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
BINDIR=@bindir@
|
||||
|
||||
LIBS=@LIBS@
|
||||
STRIP=strip
|
||||
LDFLAGS=-L../libncftp -L../Strn -L../sio @LDFLAGS@
|
||||
|
||||
# Any -D definitions:
|
||||
BETA=# -DBETA=20
|
||||
DEFS=-Dncftp $(BETA) -DBINDIR=\"$(BINDIR)\" @DEFS@
|
||||
|
||||
OBJS=cmds.@OBJEXT@ cmdlist.@OBJEXT@ getopt.@OBJEXT@ ls.@OBJEXT@ main.@OBJEXT@ version.@OBJEXT@ shell.@OBJEXT@ util.@OBJEXT@ readln.@OBJEXT@ progress.@OBJEXT@ bookmark.@OBJEXT@ pref.@OBJEXT@ preffw.@OBJEXT@ trace.@OBJEXT@ spool.@OBJEXT@ log.@OBJEXT@ getline.@OBJEXT@
|
||||
|
||||
DPROGS=../bin/ncftp@EXEEXT@
|
||||
|
||||
all: $(DPROGS)
|
||||
-@echo 'Done making NcFTP.'
|
||||
|
||||
../bin/ncftp@EXEEXT@: $(OBJS) ../libncftp/libncftp.a
|
||||
@Z30@
|
||||
$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $(OBJS) -o ../bin/ncftp@EXEEXT@ $(LDFLAGS) -lncftp -lStrn -lsio $(LIBS)
|
||||
-@$(STRIP) ../bin/ncftp@EXEEXT@
|
||||
|
||||
clean:
|
||||
/bin/rm -f $(DPROGS) $(OBJS)
|
||||
|
||||
SHELL=/bin/sh
|
||||
.SUFFIXES: .c .@OBJEXT@
|
||||
|
||||
.c.@OBJEXT@:
|
||||
$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c
|
||||
|
||||
PACKAGE=Makefile.in bookmark.c bookmark.h cmdlist.c \
|
||||
cmds.c cmds.h getopt.c getopt.h \
|
||||
ls.c ls.h main.c main.h \
|
||||
pref.c pref.h progress.c progress.h \
|
||||
readln.c readln.h shell.c shell.h \
|
||||
spool.c spool.h syshdrs.h trace.c \
|
||||
trace.h util.c util.h version.c \
|
||||
preffw.c log.c log.h getline.c \
|
||||
getline.h
|
||||
|
||||
TMPDIR=/tmp
|
||||
TARDIR=ncftp
|
||||
|
||||
tarcp:
|
||||
-@mkdir -p $(TMPDIR)/TAR/$(TARDIR)
|
||||
-@chmod ga+r $(PACKAGE)
|
||||
-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
|
||||
cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)
|
||||
|
||||
### Dependencies #############################################################
|
||||
|
||||
version.@OBJEXT@: version.c
|
||||
$(CC) $(CFLAGS) -DOS=\"@OS@\" $< -c
|
||||
|
||||
bookmark.@OBJEXT@: bookmark.c syshdrs.h bookmark.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
cmdlist.@OBJEXT@: cmdlist.c syshdrs.h shell.h bookmark.h cmds.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
cmds.@OBJEXT@: cmds.c syshdrs.h shell.h util.h ls.h bookmark.h cmds.h main.h \
|
||||
trace.h pref.h spool.h getopt.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
getopt.@OBJEXT@: getopt.c getopt.h
|
||||
ls.@OBJEXT@: ls.c syshdrs.h util.h ls.h trace.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
main.@OBJEXT@: main.c syshdrs.h ls.h bookmark.h cmds.h main.h shell.h \
|
||||
getopt.h progress.h pref.h readln.h trace.h spool.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
pref.@OBJEXT@: pref.c syshdrs.h pref.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
preffw.@OBJEXT@: preffw.c syshdrs.h pref.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
progress.@OBJEXT@: progress.c syshdrs.h util.h progress.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
readln.@OBJEXT@: readln.c syshdrs.h shell.h util.h bookmark.h cmds.h ls.h \
|
||||
readln.h getline.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
shell.@OBJEXT@: shell.c syshdrs.h shell.h util.h bookmark.h cmds.h readln.h \
|
||||
trace.h main.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
spool.@OBJEXT@: spool.c syshdrs.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
trace.@OBJEXT@: trace.c syshdrs.h trace.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
util.@OBJEXT@: util.c syshdrs.h shell.h trace.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
log.@OBJEXT@: log.c syshdrs.h log.h util.h ../libncftp/ncftp.h ../libncftp/ncftp_errno.h
|
||||
getline.@OBJEXT@: getline.c syshdrs.h getline.h
|
|
@ -1,845 +0,0 @@
|
|||
/* bookmark.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "bookmark.h"
|
||||
#include "util.h"
|
||||
|
||||
/*
|
||||
* The ~/.ncftp/bookmarks file contains a list of sites
|
||||
* the user wants to remember.
|
||||
*
|
||||
* Unlike previous versions of the program, we now open/close
|
||||
* the file every time we need it; That way we can have
|
||||
* multiple ncftp processes changing the file. There is still
|
||||
* a possibility that two different processes could be modifying
|
||||
* the file at the same time.
|
||||
*/
|
||||
|
||||
Bookmark gBm;
|
||||
int gLoadedBm = 0;
|
||||
int gBookmarkMatchMode = 0;
|
||||
int gNumBookmarks = 0;
|
||||
BookmarkPtr gBookmarkTable = NULL;
|
||||
|
||||
extern char gOurDirectoryPath[];
|
||||
|
||||
/* Converts a pre-loaded Bookmark structure into a RFC 1738
|
||||
* Uniform Resource Locator.
|
||||
*/
|
||||
void
|
||||
BookmarkToURL(BookmarkPtr bmp, char *url, size_t urlsize)
|
||||
{
|
||||
char pbuf[32];
|
||||
|
||||
/* //<user>:<password>@<host>:<port>/<url-path> */
|
||||
/* Note that if an absolute path is given,
|
||||
* you need to escape the first entry, i.e. /pub -> %2Fpub
|
||||
*/
|
||||
(void) Strncpy(url, "ftp://", urlsize);
|
||||
if (bmp->user[0] != '\0') {
|
||||
(void) Strncat(url, bmp->user, urlsize);
|
||||
if (bmp->pass[0] != '\0') {
|
||||
(void) Strncat(url, ":", urlsize);
|
||||
(void) Strncat(url, "PASSWORD", urlsize);
|
||||
}
|
||||
(void) Strncat(url, "@", urlsize);
|
||||
}
|
||||
(void) Strncat(url, bmp->name, urlsize);
|
||||
if (bmp->port != 21) {
|
||||
(void) sprintf(pbuf, ":%u", (unsigned int) bmp->port);
|
||||
(void) Strncat(url, pbuf, urlsize);
|
||||
}
|
||||
if (bmp->dir[0] == '/') {
|
||||
/* Absolute URL path, must escape first slash. */
|
||||
(void) Strncat(url, "/%2F", urlsize);
|
||||
(void) Strncat(url, bmp->dir + 1, urlsize);
|
||||
(void) Strncat(url, "/", urlsize);
|
||||
} else if (bmp->dir[0] != '\0') {
|
||||
(void) Strncat(url, "/", urlsize);
|
||||
(void) Strncat(url, bmp->dir, urlsize);
|
||||
(void) Strncat(url, "/", urlsize);
|
||||
}
|
||||
} /* BookmarkToURL */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetBookmarkDefaults(BookmarkPtr bmp)
|
||||
{
|
||||
(void) memset(bmp, 0, sizeof(Bookmark));
|
||||
|
||||
bmp->xferType = 'I';
|
||||
bmp->xferMode = 'S'; /* Use FTP protocol default as ours too. */
|
||||
bmp->hasSIZE = kCommandAvailabilityUnknown;
|
||||
bmp->hasMDTM = kCommandAvailabilityUnknown;
|
||||
bmp->hasUTIME = kCommandAvailabilityUnknown;
|
||||
bmp->hasPASV = kCommandAvailabilityUnknown;
|
||||
bmp->isUnix = 1;
|
||||
bmp->lastCall = (time_t) 0;
|
||||
bmp->deleted = 0;
|
||||
} /* SetBookmarkDefaults */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Used when converting hex strings to integral types. */
|
||||
static int
|
||||
HexCharToNibble(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
return (c - '0');
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
return (c - 'a' + 10);
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'E':
|
||||
case 'F':
|
||||
return (c - 'A' + 10);
|
||||
|
||||
}
|
||||
return (-1); /* Error. */
|
||||
} /* HexCharToNibble */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Fills in a Bookmark structure based off of a line from the NcFTP
|
||||
* "bookmarks" file.
|
||||
*/
|
||||
int
|
||||
ParseHostLine(char *line, BookmarkPtr bmp)
|
||||
{
|
||||
char token[128];
|
||||
char pass[128];
|
||||
char *s, *d;
|
||||
char *tokenend;
|
||||
long L;
|
||||
int i;
|
||||
int result;
|
||||
int n, n1, n2;
|
||||
|
||||
SetBookmarkDefaults(bmp);
|
||||
s = line;
|
||||
tokenend = token + sizeof(token) - 1;
|
||||
result = -1;
|
||||
for (i=1; ; i++) {
|
||||
if (*s == '\0')
|
||||
break;
|
||||
/* Some tokens may need to have a comma in them. Since this is a
|
||||
* field delimiter, these fields use \, to represent a comma, and
|
||||
* \\ for a backslash. This chunk gets the next token, paying
|
||||
* attention to the escaped stuff.
|
||||
*/
|
||||
for (d = token; *s != '\0'; ) {
|
||||
if ((*s == '\\') && (s[1] != '\0')) {
|
||||
if (d < tokenend)
|
||||
*d++ = s[1];
|
||||
s += 2;
|
||||
} else if (*s == ',') {
|
||||
++s;
|
||||
break;
|
||||
} else if ((*s == '$') && (s[1] != '\0') && (s[2] != '\0')) {
|
||||
n1 = HexCharToNibble(s[1]);
|
||||
n2 = HexCharToNibble(s[2]);
|
||||
if ((n1 >= 0) && (n2 >= 0)) {
|
||||
n = (n1 << 4) | n2;
|
||||
if (d < tokenend)
|
||||
*(unsigned char *)d++ = (unsigned int) n;
|
||||
}
|
||||
s += 3;
|
||||
} else {
|
||||
if (d < tokenend)
|
||||
*d++ = *s;
|
||||
++s;
|
||||
}
|
||||
}
|
||||
*d = '\0';
|
||||
switch(i) {
|
||||
case 1: (void) STRNCPY(bmp->bookmarkName, token); break;
|
||||
case 2: (void) STRNCPY(bmp->name, token); break;
|
||||
case 3: (void) STRNCPY(bmp->user, token); break;
|
||||
case 4: (void) STRNCPY(bmp->pass, token); break;
|
||||
case 5: (void) STRNCPY(bmp->acct, token); break;
|
||||
case 6: (void) STRNCPY(bmp->dir, token);
|
||||
result = 0; /* Good enough to have these fields. */
|
||||
break;
|
||||
case 7:
|
||||
if (token[0] != '\0')
|
||||
bmp->xferType = (int) token[0];
|
||||
break;
|
||||
case 8:
|
||||
/* Most of the time, we won't have a port. */
|
||||
if (token[0] == '\0')
|
||||
bmp->port = (unsigned int) kDefaultFTPPort;
|
||||
else
|
||||
bmp->port = (unsigned int) atoi(token);
|
||||
break;
|
||||
case 9:
|
||||
(void) sscanf(token, "%lx", &L);
|
||||
bmp->lastCall = (time_t) L;
|
||||
break;
|
||||
case 10: bmp->hasSIZE = atoi(token); break;
|
||||
case 11: bmp->hasMDTM = atoi(token); break;
|
||||
case 12: bmp->hasPASV = atoi(token); break;
|
||||
case 13: bmp->isUnix = atoi(token);
|
||||
result = 3; /* Version 3 had all fields to here. */
|
||||
break;
|
||||
case 14: (void) STRNCPY(bmp->lastIP, token); break;
|
||||
case 15: (void) STRNCPY(bmp->comment, token); break;
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
break;
|
||||
case 20: bmp->xferMode = token[0];
|
||||
result = 7; /* Version 7 has all fields to here. */
|
||||
break;
|
||||
case 21: bmp->hasUTIME = atoi(token);
|
||||
break;
|
||||
case 22: (void) STRNCPY(bmp->ldir, token);
|
||||
result = 8; /* Version 8 has all fields to here. */
|
||||
break;
|
||||
default:
|
||||
result = 99; /* Version >8 ? */
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
|
||||
/* Decode password, if it was base-64 encoded. */
|
||||
if (strncmp(bmp->pass, kPasswordMagic, kPasswordMagicLen) == 0) {
|
||||
FromBase64(pass, bmp->pass + kPasswordMagicLen, strlen(bmp->pass + kPasswordMagicLen), 1);
|
||||
(void) STRNCPY(bmp->pass, pass);
|
||||
}
|
||||
return (result);
|
||||
} /* ParseHostLine */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
CloseBookmarkFile(FILE *fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
(void) fclose(fp);
|
||||
} /* CloseBookmarkFile */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
GetNextBookmark(FILE *fp, Bookmark *bmp)
|
||||
{
|
||||
char line[512];
|
||||
|
||||
while (FGets(line, sizeof(line), fp) != NULL) {
|
||||
if (ParseHostLine(line, bmp) >= 0)
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
} /* GetNextBookmark */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Opens a NcFTP 2.x or 3.x style bookmarks file, and sets the file pointer
|
||||
* so that it is ready to read the first data line.
|
||||
*/
|
||||
FILE *
|
||||
OpenBookmarkFile(int *numBookmarks0)
|
||||
{
|
||||
char pathName[256], path2[256];
|
||||
char line[256];
|
||||
FILE *fp;
|
||||
int version;
|
||||
int numBookmarks;
|
||||
Bookmark junkbm;
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return NULL; /* Don't create in root directory. */
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kBookmarkFileName);
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp == NULL) {
|
||||
/* See if it exists under the old name. */
|
||||
(void) OurDirectoryPath(path2, sizeof(path2), kOldBookmarkFileName);
|
||||
if (rename(path2, pathName) == 0) {
|
||||
/* Rename succeeded, now open it. */
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
}
|
||||
return NULL; /* Okay to not have one yet. */
|
||||
}
|
||||
|
||||
(void) chmod(pathName, 00600);
|
||||
if (FGets(line, sizeof(line), fp) == NULL) {
|
||||
(void) fprintf(stderr, "%s: invalid format.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Sample line we're looking for:
|
||||
* "NcFTP bookmark-file version: 8"
|
||||
*/
|
||||
version = -1;
|
||||
(void) sscanf(line, "%*s %*s %*s %d", &version);
|
||||
if (version < kBookmarkMinVersion) {
|
||||
if (version < 0) {
|
||||
(void) fprintf(stderr, "%s: invalid format, or bad version.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
(void) STRNCPY(path2, pathName);
|
||||
(void) sprintf(line, ".v%d", version);
|
||||
(void) STRNCAT(path2, line);
|
||||
(void) rename(pathName, path2);
|
||||
(void) fprintf(stderr, "%s: old version.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Sample line we're looking for:
|
||||
* "Number of entries: 28" or "# # # 1"
|
||||
*/
|
||||
numBookmarks = -1;
|
||||
|
||||
/* At the moment, we can't trust the number stored in the
|
||||
* file. It's there for future use.
|
||||
*/
|
||||
if (FGets(line, sizeof(line), fp) == NULL) {
|
||||
(void) fprintf(stderr, "%s: invalid format.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (numBookmarks0 == (int *) 0) {
|
||||
/* If the caller doesn't care how many bookmarks are *really*
|
||||
* in the file, then we can return now.
|
||||
*/
|
||||
return(fp);
|
||||
}
|
||||
|
||||
/* Otherwise, we have to read through the whole file because
|
||||
* unfortunately the header line can't be trusted.
|
||||
*/
|
||||
for (numBookmarks = 0; ; numBookmarks++) {
|
||||
if (GetNextBookmark(fp, &junkbm) < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Now we have to re-open and re-position the file.
|
||||
* We don't use rewind() because it doesn't always work.
|
||||
* This introduces a race condition, but the bookmark
|
||||
* functionality wasn't designed to be air-tight.
|
||||
*/
|
||||
CloseBookmarkFile(fp);
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp == NULL)
|
||||
return (NULL);
|
||||
if (FGets(line, sizeof(line), fp) == NULL) {
|
||||
(void) fprintf(stderr, "%s: invalid format.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (FGets(line, sizeof(line), fp) == NULL) {
|
||||
(void) fprintf(stderr, "%s: invalid format.\n", pathName);
|
||||
(void) fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* NOW we're done. */
|
||||
*numBookmarks0 = numBookmarks;
|
||||
return (fp);
|
||||
} /* OpenBookmarkFile */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Looks for a saved bookmark by the abbreviation given. */
|
||||
int
|
||||
GetBookmark(const char *const bmabbr, Bookmark *bmp)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[512];
|
||||
Bookmark byHostName;
|
||||
Bookmark byHostAbbr;
|
||||
Bookmark byBmAbbr;
|
||||
size_t byBmNameFlag = 0;
|
||||
size_t byBmAbbrFlag = 0;
|
||||
size_t byHostNameFlag = 0;
|
||||
size_t byHostAbbrFlag = 0;
|
||||
int result = -1;
|
||||
int exactMatch = 0;
|
||||
size_t bmabbrLen;
|
||||
char *cp;
|
||||
|
||||
fp = OpenBookmarkFile(NULL);
|
||||
if (fp == NULL)
|
||||
return (-1);
|
||||
|
||||
bmabbrLen = strlen(bmabbr);
|
||||
while (FGets(line, sizeof(line), fp) != NULL) {
|
||||
if (ParseHostLine(line, bmp) < 0)
|
||||
continue;
|
||||
if (ISTREQ(bmp->bookmarkName, bmabbr)) {
|
||||
/* Exact match, done. */
|
||||
byBmNameFlag = bmabbrLen;
|
||||
exactMatch = 1;
|
||||
break;
|
||||
} else if (ISTRNEQ(bmp->bookmarkName, bmabbr, bmabbrLen)) {
|
||||
/* Remember this one, it matched an abbreviated
|
||||
* bookmark name.
|
||||
*/
|
||||
byBmAbbr = *bmp;
|
||||
byBmAbbrFlag = bmabbrLen;
|
||||
} else if (ISTREQ(bmp->name, bmabbr)) {
|
||||
/* Remember this one, it matched a full
|
||||
* host name.
|
||||
*/
|
||||
byHostName = *bmp;
|
||||
byHostNameFlag = bmabbrLen;
|
||||
} else if ((cp = strchr(bmp->name, '.')) != NULL) {
|
||||
/* See if it matched part of the hostname. */
|
||||
if (ISTRNEQ(bmp->name, "ftp", 3)) {
|
||||
cp = cp + 1;
|
||||
} else if (ISTRNEQ(bmp->name, "www", 3)) {
|
||||
cp = cp + 1;
|
||||
} else {
|
||||
cp = bmp->name;
|
||||
}
|
||||
if (ISTRNEQ(cp, bmabbr, bmabbrLen)) {
|
||||
/* Remember this one, it matched a full
|
||||
* host name.
|
||||
*/
|
||||
byHostAbbr = *bmp;
|
||||
byHostAbbrFlag = bmabbrLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gBookmarkMatchMode == 0) {
|
||||
/* Only use a bookmark when the exact
|
||||
* bookmark name was used.
|
||||
*/
|
||||
if (exactMatch != 0) {
|
||||
result = 0;
|
||||
}
|
||||
} else {
|
||||
/* Pick the best match, if any. */
|
||||
if (byBmNameFlag != 0) {
|
||||
/* *bmp is already set. */
|
||||
result = 0;
|
||||
} else if (byBmAbbrFlag != 0) {
|
||||
result = 0;
|
||||
*bmp = byBmAbbr;
|
||||
} else if (byHostNameFlag != 0) {
|
||||
result = 0;
|
||||
*bmp = byHostName;
|
||||
} else if (byHostAbbrFlag != 0) {
|
||||
result = 0;
|
||||
*bmp = byHostAbbr;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
memset(bmp, 0, sizeof(Bookmark));
|
||||
|
||||
CloseBookmarkFile(fp);
|
||||
return (result);
|
||||
} /* GetBookmark */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
BookmarkSortProc(const void *a, const void *b)
|
||||
{
|
||||
return (ISTRCMP((*(Bookmark *)a).bookmarkName, (*(Bookmark *)b).bookmarkName));
|
||||
} /* BookmarkSortProc */
|
||||
|
||||
|
||||
|
||||
static int
|
||||
BookmarkSearchProc(const void *key, const void *b)
|
||||
{
|
||||
return (ISTRCMP((char *) key, (*(Bookmark *)b).bookmarkName));
|
||||
} /* BookmarkSearchProc */
|
||||
|
||||
|
||||
|
||||
BookmarkPtr
|
||||
SearchBookmarkTable(const char *key)
|
||||
{
|
||||
return ((BookmarkPtr) bsearch(key, gBookmarkTable, (size_t) gNumBookmarks, sizeof(Bookmark), BookmarkSearchProc));
|
||||
} /* SearchBookmarkTable */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SortBookmarks(void)
|
||||
{
|
||||
if ((gBookmarkTable == NULL) || (gNumBookmarks < 2))
|
||||
return;
|
||||
|
||||
/* Sorting involves swapping entire Bookmark structures.
|
||||
* Normally the proper thing to do is to use an array
|
||||
* of pointers to Bookmarks and sort them, but even
|
||||
* these days a large bookmark list can be sorted in
|
||||
* the blink of an eye.
|
||||
*/
|
||||
qsort(gBookmarkTable, (size_t) gNumBookmarks, sizeof(Bookmark), BookmarkSortProc);
|
||||
} /* SortBookmarks */
|
||||
|
||||
|
||||
|
||||
int
|
||||
LoadBookmarkTable(void)
|
||||
{
|
||||
int i, nb;
|
||||
FILE *infp;
|
||||
|
||||
infp = OpenBookmarkFile(&nb);
|
||||
if (infp == NULL) {
|
||||
nb = 0;
|
||||
}
|
||||
if ((nb != gNumBookmarks) && (gBookmarkTable != NULL)) {
|
||||
/* Re-loading the table from disk. */
|
||||
gBookmarkTable = (Bookmark *) realloc(gBookmarkTable, (size_t) (nb + 1) * sizeof(Bookmark));
|
||||
memset(gBookmarkTable, 0, (nb + 1) * sizeof(Bookmark));
|
||||
} else {
|
||||
gBookmarkTable = calloc((size_t) (nb + 1), (size_t) sizeof(Bookmark));
|
||||
}
|
||||
|
||||
if (gBookmarkTable == NULL) {
|
||||
CloseBookmarkFile(infp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (i=0; i<nb; i++) {
|
||||
if (GetNextBookmark(infp, gBookmarkTable + i) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
gNumBookmarks = i;
|
||||
|
||||
CloseBookmarkFile(infp);
|
||||
SortBookmarks();
|
||||
return (0);
|
||||
} /* LoadBookmarkTable */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Some characters need to be escaped so the file is editable and can
|
||||
* be parsed correctly the next time it is read.
|
||||
*/
|
||||
static char *
|
||||
BmEscapeTok(char *dst, size_t dsize, char *src)
|
||||
{
|
||||
char *dlim = dst + dsize - 1;
|
||||
char *dst0 = dst;
|
||||
int c;
|
||||
|
||||
while ((c = *src) != '\0') {
|
||||
src++;
|
||||
if ((c == '\\') || (c == ',') || (c == '$')) {
|
||||
/* These need to be escaped. */
|
||||
if ((dst + 1) < dlim) {
|
||||
*dst++ = '\\';
|
||||
*dst++ = c;
|
||||
}
|
||||
} else if (!isprint(c)) {
|
||||
/* Escape non-printing characters. */
|
||||
if ((dst + 2) < dlim) {
|
||||
(void) sprintf(dst, "$%02x", c);
|
||||
dst += 3;
|
||||
}
|
||||
} else {
|
||||
if (dst < dlim)
|
||||
*dst++ = c;
|
||||
}
|
||||
}
|
||||
*dst = '\0';
|
||||
return (dst0);
|
||||
} /* BmEscapeTok */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Converts a Bookmark into a text string, and writes it to the saved
|
||||
* bookmarks file.
|
||||
*/
|
||||
static int
|
||||
WriteBmLine(Bookmark *bmp, FILE *outfp, int savePassword)
|
||||
{
|
||||
char tok[256];
|
||||
char pass[160];
|
||||
|
||||
if (fprintf(outfp, "%s", bmp->bookmarkName) < 0) return (-1) ;/*1*/
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->name)) < 0) return (-1) ;/*2*/
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->user)) < 0) return (-1) ;/*3*/
|
||||
if ((bmp->pass[0] != '\0') && (savePassword == 1)) {
|
||||
(void) memcpy(pass, kPasswordMagic, kPasswordMagicLen);
|
||||
ToBase64(pass + kPasswordMagicLen, bmp->pass, strlen(bmp->pass), 1);
|
||||
if (fprintf(outfp, ",%s", pass) < 0) return (-1) ;/*4*/
|
||||
} else {
|
||||
if (fprintf(outfp, ",%s", "") < 0) return (-1) ;/*4*/
|
||||
}
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->acct)) < 0) return (-1) ;/*5*/
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->dir)) < 0) return (-1) ;/*6*/
|
||||
if (fprintf(outfp, ",%c", bmp->xferType) < 0) return (-1) ;/*7*/
|
||||
if (fprintf(outfp, ",%u", (unsigned int) bmp->port) < 0) return (-1) ;/*8*/
|
||||
if (fprintf(outfp, ",%lu", (unsigned long) bmp->lastCall) < 0) return (-1) ;/*9*/
|
||||
if (fprintf(outfp, ",%d", bmp->hasSIZE) < 0) return (-1) ;/*10*/
|
||||
if (fprintf(outfp, ",%d", bmp->hasMDTM) < 0) return (-1) ;/*11*/
|
||||
if (fprintf(outfp, ",%d", bmp->hasPASV) < 0) return (-1) ;/*12*/
|
||||
if (fprintf(outfp, ",%d", bmp->isUnix) < 0) return (-1) ;/*13*/
|
||||
if (fprintf(outfp, ",%s", bmp->lastIP) < 0) return (-1) ;/*14*/
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->comment)) < 0) return (-1) ;/*15*/
|
||||
if (fprintf(outfp, ",%s", "") < 0) return (-1) ;/*16*/
|
||||
if (fprintf(outfp, ",%s", "") < 0) return (-1) ;/*17*/
|
||||
if (fprintf(outfp, ",%s", "") < 0) return (-1) ;/*18*/
|
||||
if (fprintf(outfp, ",%s", "") < 0) return (-1) ;/*19*/
|
||||
if (fprintf(outfp, ",%c", bmp->xferMode) < 0) return (-1) ;/*20*/
|
||||
if (fprintf(outfp, ",%d", bmp->hasUTIME) < 0) return (-1) ;/*21*/
|
||||
if (fprintf(outfp, ",%s", BmEscapeTok(tok, sizeof(tok), bmp->ldir)) < 0) return (-1) ;/*22*/
|
||||
if (fprintf(outfp, "\n") < 0) return (-1) ;
|
||||
if (fflush(outfp) < 0) return (-1);
|
||||
return (0);
|
||||
} /* WriteBmLine */
|
||||
|
||||
|
||||
|
||||
static int
|
||||
SwapBookmarkFiles(void)
|
||||
{
|
||||
char pidStr[32];
|
||||
char pathName[256], path2[256];
|
||||
|
||||
(void) OurDirectoryPath(path2, sizeof(path2), kBookmarkFileName);
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kTmpBookmarkFileName);
|
||||
(void) sprintf(pidStr, "-%u.txt", (unsigned int) getpid());
|
||||
(void) STRNCAT(pathName, pidStr);
|
||||
|
||||
(void) remove(path2);
|
||||
if (rename(pathName, path2) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
} /* SwapBookmarkFiles */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Saves a Bookmark structure into the bookmarks file. */
|
||||
FILE *
|
||||
OpenTmpBookmarkFile(int nb)
|
||||
{
|
||||
FILE *outfp;
|
||||
char pidStr[32];
|
||||
char pathName[256], path2[256];
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return (NULL); /* Don't create in root directory. */
|
||||
|
||||
(void) OurDirectoryPath(path2, sizeof(path2), kBookmarkFileName);
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kTmpBookmarkFileName);
|
||||
(void) sprintf(pidStr, "-%u.txt", (unsigned int) getpid());
|
||||
(void) STRNCAT(pathName, pidStr);
|
||||
|
||||
outfp = fopen(pathName, FOPEN_WRITE_TEXT);
|
||||
if (outfp == NULL) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror(pathName);
|
||||
return (NULL);
|
||||
}
|
||||
(void) chmod(pathName, 00600);
|
||||
if (nb > 0) {
|
||||
if (fprintf(outfp, "NcFTP bookmark-file version: %d\nNumber of bookmarks: %d\n", kBookmarkVersion, nb) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror(pathName);
|
||||
(void) fclose(outfp);
|
||||
return (NULL);
|
||||
}
|
||||
} else {
|
||||
if (fprintf(outfp, "NcFTP bookmark-file version: %d\nNumber of bookmarks: ??\n", kBookmarkVersion) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror(pathName);
|
||||
(void) fclose(outfp);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return (outfp);
|
||||
} /* OpenTmpBookmarkFile */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SaveBookmarkTable(void)
|
||||
{
|
||||
int i;
|
||||
FILE *outfp;
|
||||
int nb;
|
||||
|
||||
if ((gNumBookmarks < 1) || (gBookmarkTable == NULL))
|
||||
return (0); /* Nothing to save. */
|
||||
|
||||
/* Get a count of live bookmarks. */
|
||||
for (i=0, nb=0; i<gNumBookmarks; i++) {
|
||||
if (gBookmarkTable[i].deleted == 0)
|
||||
nb++;
|
||||
}
|
||||
outfp = OpenTmpBookmarkFile(nb);
|
||||
if (outfp == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (i=0; i<gNumBookmarks; i++) {
|
||||
if (gBookmarkTable[i].deleted == 0) {
|
||||
if (WriteBmLine(gBookmarkTable + i, outfp, 1) < 0) {
|
||||
CloseBookmarkFile(outfp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseBookmarkFile(outfp);
|
||||
if (SwapBookmarkFiles() < 0) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
} /* SaveBookmarkTable */
|
||||
|
||||
|
||||
|
||||
/* Saves a Bookmark structure into the bookmarks file. */
|
||||
int
|
||||
PutBookmark(Bookmark *bmp, int savePassword)
|
||||
{
|
||||
FILE *infp, *outfp;
|
||||
char line[256];
|
||||
char bmAbbr[64];
|
||||
int replaced = 0;
|
||||
size_t len;
|
||||
|
||||
outfp = OpenTmpBookmarkFile(0);
|
||||
if (outfp == NULL)
|
||||
return (-1);
|
||||
|
||||
(void) STRNCPY(bmAbbr, bmp->bookmarkName);
|
||||
(void) STRNCAT(bmAbbr, ",");
|
||||
len = strlen(bmAbbr);
|
||||
|
||||
/* This may fail the first time we ever save a bookmark. */
|
||||
infp = OpenBookmarkFile(NULL);
|
||||
if (infp != NULL) {
|
||||
while (FGets(line, sizeof(line), infp) != NULL) {
|
||||
if (strncmp(line, bmAbbr, len) == 0) {
|
||||
/* Replace previous entry. */
|
||||
if (WriteBmLine(bmp, outfp, savePassword) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror("reason");
|
||||
(void) fclose(outfp);
|
||||
}
|
||||
replaced = 1;
|
||||
} else {
|
||||
if (fprintf(outfp, "%s\n", line) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror("reason");
|
||||
(void) fclose(outfp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseBookmarkFile(infp);
|
||||
}
|
||||
|
||||
if (replaced == 0) {
|
||||
/* Add it as a new bookmark. */
|
||||
if (WriteBmLine(bmp, outfp, savePassword) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror("reason");
|
||||
(void) fclose(outfp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(outfp) < 0) {
|
||||
(void) fprintf(stderr, "Could not save bookmark.\n");
|
||||
perror("reason");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (SwapBookmarkFiles() < 0) {
|
||||
(void) fprintf(stderr, "Could not rename bookmark file.\n");
|
||||
perror("reason");
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
} /* PutBookmark */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Tries to generate a bookmark abbreviation based off of the hostname. */
|
||||
void
|
||||
DefaultBookmarkName(char *dst, size_t siz, char *src)
|
||||
{
|
||||
char str[128];
|
||||
const char *token;
|
||||
const char *cp;
|
||||
|
||||
(void) STRNCPY(str, src);
|
||||
|
||||
/* Pick the first "significant" part of the hostname. Usually
|
||||
* this is the first word in the name, but if it's something like
|
||||
* ftp.unl.edu, we would want to choose "unl" and not "ftp."
|
||||
*/
|
||||
token = str;
|
||||
if ((token = strtok(str, ".")) == NULL)
|
||||
token = str;
|
||||
else if ((ISTRNEQ(token, "ftp", 3)) || (ISTRNEQ(token, "www", 3))) {
|
||||
if ((token = strtok(NULL, ".")) == NULL)
|
||||
token = "";
|
||||
}
|
||||
for (cp = token; ; cp++) {
|
||||
if (*cp == '\0') {
|
||||
/* Token was all digits, like an IP address perhaps. */
|
||||
token = "";
|
||||
}
|
||||
if (!isdigit((int) *cp))
|
||||
break;
|
||||
}
|
||||
(void) Strncpy(dst, token, siz);
|
||||
} /* DefaultBookmarkName */
|
|
@ -1,59 +0,0 @@
|
|||
/* bookmark.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct Bookmark *BookmarkPtr;
|
||||
typedef struct Bookmark {
|
||||
char bookmarkName[16];
|
||||
char name[64];
|
||||
char user[64];
|
||||
char pass[64];
|
||||
char acct[64];
|
||||
char dir[160];
|
||||
char ldir[160];
|
||||
int xferType;
|
||||
unsigned int port;
|
||||
time_t lastCall;
|
||||
int hasSIZE;
|
||||
int hasMDTM;
|
||||
int hasPASV;
|
||||
int isUnix;
|
||||
char lastIP[32];
|
||||
char comment[128];
|
||||
int xferMode;
|
||||
int hasUTIME;
|
||||
|
||||
int deleted;
|
||||
} Bookmark;
|
||||
|
||||
#define kBookmarkVersion 8
|
||||
#define kBookmarkMinVersion 3
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kBookmarkFileName "bookmarks.txt"
|
||||
#else
|
||||
# define kBookmarkFileName "bookmarks"
|
||||
#endif
|
||||
#define kTmpBookmarkFileName "bookmarks-tmp"
|
||||
#define kOldBookmarkFileName "hosts"
|
||||
#define kBookmarkBupFileName "bookmarks.old"
|
||||
|
||||
#define BMTINDEX(p) ((int) ((char *) p - (char *) gBookmarkTable) / (int) sizeof(Bookmark))
|
||||
|
||||
/* bookmark.c */
|
||||
void BookmarkToURL(BookmarkPtr, char *, size_t);
|
||||
void SetBookmarkDefaults(BookmarkPtr);
|
||||
int ParseHostLine(char *, BookmarkPtr);
|
||||
void CloseBookmarkFile(FILE *);
|
||||
FILE *OpenBookmarkFile(int *);
|
||||
FILE *OpenTmpBookmarkFile(int);
|
||||
int SaveBookmarkTable(void);
|
||||
int GetNextBookmark(FILE *, Bookmark *);
|
||||
int GetBookmark(const char *const, Bookmark *);
|
||||
int PutBookmark(Bookmark *, int);
|
||||
int LoadBookmarkTable(void);
|
||||
BookmarkPtr SearchBookmarkTable(const char *);
|
||||
void SortBookmarks(void);
|
||||
void DefaultBookmarkName(char *, size_t, char *);
|
|
@ -1,527 +0,0 @@
|
|||
/* cmdlist.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
#include "shell.h"
|
||||
#include "bookmark.h"
|
||||
#include "cmds.h"
|
||||
|
||||
/* These will be sorted lexiographically when the program is run, but
|
||||
* they should already be listed that way.
|
||||
*/
|
||||
Command gCommands[] = {
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
{ "!",
|
||||
ShellCmd,
|
||||
"[arguments]",
|
||||
"Runs a subshell",
|
||||
kCmdHidden,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
#endif
|
||||
{ "?",
|
||||
HelpCmd,
|
||||
"[optional commands]",
|
||||
"shows commands, or detailed help on specified commands",
|
||||
kCmdHidden,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "ascii",
|
||||
TypeCmd,
|
||||
"",
|
||||
"sets the file transfer type to ASCII text",
|
||||
kCmdMustBeConnected,
|
||||
0, 0,
|
||||
},
|
||||
{ "bgget",
|
||||
SpoolGetCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-R : Recursive. Useful for fetching whole directories.\n\
|
||||
-z : Get the remote file X, and name it to Y.\n\
|
||||
-@ <time> : Wait until <time> to do the transfer.\n\
|
||||
It must be expressed as one of the following:\n\
|
||||
YYYYMMDDHHMMSS\n\
|
||||
\"now + N hours|min|sec|days\"\n\
|
||||
HH:MM",
|
||||
"collects items to download later from the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "bgput",
|
||||
SpoolPutCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-z : Send the local file X, and name the remote copy to Y.\n\
|
||||
-R : Recursive. Useful for sending whole directories.\n\
|
||||
-@ <time> : Wait until <time> to do the transfer.\n\
|
||||
It must be expressed as one of the following:\n\
|
||||
YYYYMMDDHHMMSS\n\
|
||||
\"now + N hours|min|sec|days\"\n\
|
||||
HH:MM",
|
||||
"collects items to upload later to the remote host",
|
||||
kCmdMustBeConnected | kCompleteLocalFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "bgstart",
|
||||
BGStartCmd,
|
||||
"[n]",
|
||||
"starts a ncftpbatch process to process spooled files",
|
||||
0,
|
||||
0, 1,
|
||||
},
|
||||
{ "binary",
|
||||
TypeCmd,
|
||||
"",
|
||||
"sets the file transfer type to binary/image",
|
||||
kCmdMustBeConnected,
|
||||
0, 0,
|
||||
},
|
||||
{ "bookmark",
|
||||
BookmarkCmd,
|
||||
"[bookmark-name-to-save-as]",
|
||||
"Creates or updates a bookmark using the current host and directory",
|
||||
kCmdMustBeConnected | kCompleteBookmark,
|
||||
0, 1,
|
||||
},
|
||||
{ "bookmarks",
|
||||
(CmdProc) HostsCmd,
|
||||
"[-l]",
|
||||
"lets you edit the settings for each bookmark",
|
||||
0,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "bye",
|
||||
(CmdProc) QuitCmd,
|
||||
"",
|
||||
"exits NcFTP",
|
||||
kCmdHidden,
|
||||
0, 0,
|
||||
},
|
||||
{ "cat",
|
||||
CatCmd,
|
||||
"file1 [file2...]",
|
||||
"views a file from the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "cd",
|
||||
ChdirCmd,
|
||||
"<directory>",
|
||||
"changes remote working directory",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
0, 1,
|
||||
},
|
||||
{ "chmod",
|
||||
ChmodCmd,
|
||||
"mode file1 [file2...]",
|
||||
"changes permissions for files on the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
2, kNoMax,
|
||||
},
|
||||
{ "close",
|
||||
(CmdProc) CloseCmd,
|
||||
"",
|
||||
"closes the connection to the remote host",
|
||||
kCmdMustBeConnected,
|
||||
0, 0,
|
||||
},
|
||||
{ "debug",
|
||||
DebugCmd,
|
||||
"[debug level]",
|
||||
"sets debug mode to level x",
|
||||
0,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "delete",
|
||||
DeleteCmd,
|
||||
"file1 [file2...]",
|
||||
"deletes files from the remote host",
|
||||
kCmdMustBeConnected | kCmdHidden | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "dir",
|
||||
ListCmd,
|
||||
"[items to list]",
|
||||
"prints a verbose directory listing",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "echo",
|
||||
EchoCmd,
|
||||
"[items to echo]",
|
||||
"echos back to screen",
|
||||
kCmdHidden,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "exit",
|
||||
(CmdProc) QuitCmd,
|
||||
"",
|
||||
"quits NcFTP",
|
||||
kCmdHidden,
|
||||
0, 0,
|
||||
},
|
||||
{ "get",
|
||||
GetCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-R : Recursive. Useful for fetching whole directories.\n\
|
||||
-z : Get the remote file X, and name it to Y.\n\
|
||||
-a : Get files using ASCII mode.\n\
|
||||
-A : Append entire remote file to the local file.\n\
|
||||
-f : Force overwrite (do not try to auto-resume transfers).\n\
|
||||
Examples:\n\
|
||||
get README\n\
|
||||
get README.*\n\
|
||||
get \"**Name with stars and spaces in it**\"\n\
|
||||
get -R new-files-directory\n\
|
||||
get -z WIN.INI ~/junk/windows-init-file",
|
||||
"fetches files from the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "help",
|
||||
HelpCmd,
|
||||
"[optional commands]",
|
||||
"shows commands, or detailed help on specified commands",
|
||||
0,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "hosts",
|
||||
(CmdProc) HostsCmd,
|
||||
"",
|
||||
"lets you edit the settings for each remote host",
|
||||
kCmdMustBeDisconnected | kCmdHidden,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
{ "jobs",
|
||||
(CmdProc) JobsCmd,
|
||||
"",
|
||||
"shows status of background NcFTP tasks",
|
||||
0,
|
||||
0, 0,
|
||||
},
|
||||
#endif
|
||||
{ "lcd",
|
||||
LocalChdirCmd,
|
||||
"<directory>",
|
||||
"changes local working directory",
|
||||
kCompleteLocalDir,
|
||||
kNoMin, 1,
|
||||
},
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
{ "lchmod",
|
||||
LocalChmodCmd,
|
||||
"mode file1 [file2...]",
|
||||
"changes permissions for files on the local host",
|
||||
kCompleteLocalFile | kCompleteLocalDir,
|
||||
2, kNoMax,
|
||||
},
|
||||
#endif
|
||||
{ "less",
|
||||
PageCmd,
|
||||
"file1 [file2...]",
|
||||
"views a file from the remote host one page at a time.",
|
||||
kCmdMustBeConnected | kCmdHidden | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "lls",
|
||||
LocalListCmd,
|
||||
"[items to list]",
|
||||
"prints a local directory listing",
|
||||
kCompleteLocalDir,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "lmkdir",
|
||||
(CmdProc) LocalMkdirCmd,
|
||||
"[directories]",
|
||||
"creates directories on the local host",
|
||||
0,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "lookup",
|
||||
LookupCmd,
|
||||
"<host or IP number> [<more hosts or IP numbers>]",
|
||||
"looks up information in the host database",
|
||||
0,
|
||||
1, kNoMax,
|
||||
},
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
{ "lpage",
|
||||
LocalPageCmd,
|
||||
"file1 [file2...]",
|
||||
"views a file on the local host one page at a time.",
|
||||
kCompleteLocalFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
#endif
|
||||
{ "lpwd",
|
||||
(CmdProc) LocalPwdCmd,
|
||||
"",
|
||||
"Prints the current local working directory",
|
||||
0,
|
||||
0, 0,
|
||||
},
|
||||
{ "lrename",
|
||||
LocalRenameCmd,
|
||||
"oldname newname",
|
||||
"changes the name of a file on the local host",
|
||||
kCompleteLocalFile | kCompleteLocalDir,
|
||||
2, 2,
|
||||
},
|
||||
{ "lrm",
|
||||
(CmdProc) LocalRmCmd,
|
||||
"[files]",
|
||||
"removes files on the local host",
|
||||
kCompleteLocalFile | kCompleteLocalDir,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "lrmdir",
|
||||
(CmdProc) LocalRmdirCmd,
|
||||
"[directories]",
|
||||
"removes directories on the local host",
|
||||
kCompleteLocalDir,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "ls",
|
||||
ListCmd,
|
||||
"[items to list]",
|
||||
"prints a remote directory listing",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "mget",
|
||||
GetCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-R : Recursive. Useful for fetching whole directories.\n\
|
||||
-z : Get the remote file X, and name it to Y.\n\
|
||||
-a : Get files using ASCII mode.\n\
|
||||
-A : Append entire remote file to the local file.\n\
|
||||
-f : Force overwrite (do not try to auto-resume transfers).\n\
|
||||
Examples:\n\
|
||||
get README\n\
|
||||
get README.*\n\
|
||||
get \"**Name with stars and spaces in it**\"\n\
|
||||
get -R new-files-directory\n\
|
||||
get -z WIN.INI ~/junk/windows-init-file",
|
||||
"fetches files from the remote host",
|
||||
kCmdMustBeConnected | kCmdHidden | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "mkdir",
|
||||
MkdirCmd,
|
||||
"dir1 [dir2...]",
|
||||
"creates directories on the remote host",
|
||||
kCmdMustBeConnected,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "mls",
|
||||
MlsCmd,
|
||||
"[<directory to list> | -d <single item to list>]",
|
||||
"prints a machine-readable directory listing",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir | kCmdHidden,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "more",
|
||||
PageCmd,
|
||||
"file1 [file2...]",
|
||||
"views a file from the remote host one page at a time.",
|
||||
kCmdMustBeConnected | kCmdHidden | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "mput",
|
||||
PutCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-z : Send the local file X, and name the remote copy to Y.\n\
|
||||
-f : Force overwrite (do not try to auto-resume transfers).\n\
|
||||
-a : Send files using ASCII mode.\n\
|
||||
-A : Append entire local file to the remote file.\n\
|
||||
-R : Recursive. Useful for sending whole directories.\n\
|
||||
Examples:\n\
|
||||
put README\n\
|
||||
put -z ~/junk/windows-init-file WIN.INI",
|
||||
"sends files to the remote host",
|
||||
kCmdMustBeConnected | kCompleteLocalFile | kCmdHidden,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "page",
|
||||
PageCmd,
|
||||
"file1 [file2...]",
|
||||
"views a file from the remote host one page at a time.",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "open",
|
||||
OpenCmd,
|
||||
"[-flags] [sitename]\n\
|
||||
Flags:\n\
|
||||
-a : Open anonymously.\n\
|
||||
-u XX : Login with username XX.\n\
|
||||
-p XX : Login with password XX.\n\
|
||||
-j XX : Login with account XX.\n\
|
||||
-P XX : Use port number X when opening.\n\
|
||||
Examples:\n\
|
||||
open sphygmomanometer.unl.edu\n\
|
||||
open -u mario bowser.nintendo.co.jp\n",
|
||||
"connects to a remote host",
|
||||
kCompleteBookmark,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "pdir",
|
||||
ListCmd,
|
||||
"[items to list]",
|
||||
"views a directory listing through your pager",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "pls",
|
||||
ListCmd,
|
||||
"[items to list]",
|
||||
"views a directory listing through your pager",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "prefs",
|
||||
(CmdProc) SetCmd,
|
||||
"",
|
||||
"shows the program's settings",
|
||||
kCmdHidden,
|
||||
0, 0,
|
||||
},
|
||||
{ "put",
|
||||
PutCmd,
|
||||
"[-flags] file1 [file2...]\n\
|
||||
Flags:\n\
|
||||
-z : Send the local file X, and name the remote copy to Y.\n\
|
||||
-f : Force overwrite (do not try to auto-resume transfers).\n\
|
||||
-a : Send files using ASCII mode.\n\
|
||||
-A : Append entire local file to the remote file.\n\
|
||||
-R : Recursive. Useful for sending whole directories.\n\
|
||||
Examples:\n\
|
||||
put README\n\
|
||||
put -z ~/junk/windows-init-file WIN.INI",
|
||||
"sends a file to the remote host",
|
||||
kCmdMustBeConnected | kCompleteLocalFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "pwd",
|
||||
(CmdProc) PwdCmd,
|
||||
"",
|
||||
"Prints the current remote working directory",
|
||||
kCmdMustBeConnected,
|
||||
0, 0,
|
||||
},
|
||||
{ "quit",
|
||||
(CmdProc) QuitCmd,
|
||||
"",
|
||||
"take a wild guess",
|
||||
0,
|
||||
0, 0,
|
||||
},
|
||||
{ "quote",
|
||||
QuoteCmd,
|
||||
"command-string",
|
||||
"sends an FTP command to the remote server",
|
||||
kCmdMustBeConnected,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "rename",
|
||||
RenameCmd,
|
||||
"oldname newname",
|
||||
"changes the name of a file on the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
2, 2,
|
||||
},
|
||||
{ "rglob",
|
||||
RGlobCmd,
|
||||
"regex",
|
||||
"tests remote filename wildcard matching",
|
||||
kCmdMustBeConnected | kCmdHidden,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "rhelp",
|
||||
RmtHelpCmd,
|
||||
"[help string]",
|
||||
"requests help from the remote server",
|
||||
kCmdMustBeConnected,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
{ "rm",
|
||||
DeleteCmd,
|
||||
"[-r] file1 [file2...]",
|
||||
"deletes files from the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "rmdir",
|
||||
RmdirCmd,
|
||||
"dir1 [dir2...]",
|
||||
"deletes directories from the remote host",
|
||||
kCmdMustBeConnected | kCompleteRemoteDir,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "set",
|
||||
SetCmd,
|
||||
"[option [newvalue]]",
|
||||
"lets you configure a program setting from the command line",
|
||||
kCompletePrefOpt,
|
||||
0, 2,
|
||||
},
|
||||
{ "show",
|
||||
(CmdProc) SetCmd,
|
||||
"[option]",
|
||||
"shows one or more the program's settings",
|
||||
kCompletePrefOpt,
|
||||
0, 1,
|
||||
},
|
||||
{ "site",
|
||||
SiteCmd,
|
||||
"command-string",
|
||||
"sends a host-specific FTP command to the remote server",
|
||||
kCmdMustBeConnected,
|
||||
1, kNoMax,
|
||||
},
|
||||
{ "symlink",
|
||||
SymlinkCmd,
|
||||
"existing-item link-item",
|
||||
"creates a symbolic link on the remote host",
|
||||
kCmdHidden | kCmdMustBeConnected | kCompleteRemoteFile,
|
||||
2, 2,
|
||||
},
|
||||
{ "type",
|
||||
TypeCmd,
|
||||
"[ascii | binary | image]",
|
||||
"sets file transfer type (one of 'ascii' or 'binary')",
|
||||
kCmdMustBeConnected,
|
||||
0, 1,
|
||||
},
|
||||
{ "umask",
|
||||
UmaskCmd,
|
||||
"mask",
|
||||
"sets the process umask on remote host",
|
||||
kCmdMustBeConnected,
|
||||
1, 1,
|
||||
},
|
||||
{ "version",
|
||||
(CmdProc) VersionCmd,
|
||||
"",
|
||||
"prints version information",
|
||||
0,
|
||||
kNoMin, kNoMax,
|
||||
},
|
||||
};
|
||||
|
||||
size_t gNumCommands = ((size_t) (sizeof(gCommands) / sizeof(Command)));
|
||||
|
||||
/* eof */
|
File diff suppressed because it is too large
Load diff
|
@ -1,63 +0,0 @@
|
|||
/* cmds.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/* cmds.c */
|
||||
int PromptForBookmarkName(BookmarkPtr);
|
||||
void CurrentURL(char *, size_t, int);
|
||||
void FillBookmarkInfo(BookmarkPtr);
|
||||
void SaveCurrentAsBookmark(void);
|
||||
void SaveUnsavedBookmark(void);
|
||||
void BookmarkCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void CatCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void PrintResp(LineListPtr);
|
||||
int nFTPChdirAndGetCWD(const FTPCIPtr, const char *, const int);
|
||||
int Chdirs(FTPCIPtr cip, const char *const cdCwd);
|
||||
void BGStartCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void ChdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void ChmodCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void CloseCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void DebugCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void DeleteCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void EchoCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void InitTransferType(void);
|
||||
void GetCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void HelpCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void HostsCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void JobsCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void ListCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalChdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalListCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalChmodCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalMkdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalPageCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalRenameCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalRmCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalRmdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LocalPwdCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void LookupCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void MkdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void MlsCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
int DoOpen(void);
|
||||
void OpenCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void PageCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void PutCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void PwdCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void QuitCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void QuoteCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void RGlobCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void RenameCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void RmdirCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void RmtHelpCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void SetCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void ShellCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void SiteCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void SpoolGetCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void SpoolPutCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void SymlinkCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void TypeCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void UmaskCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
||||
void VersionCmd(const int, const char **const, const CommandPtr, const ArgvInfoPtr);
|
File diff suppressed because it is too large
Load diff
|
@ -1,50 +0,0 @@
|
|||
#ifndef GETLINE_H
|
||||
#define GETLINE_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
*/
|
||||
|
||||
#define GL_BUF_SIZE 1024
|
||||
|
||||
/* Result codes available for gl_get_result() */
|
||||
#define GL_OK 0 /* Valid line of input entered */
|
||||
#define GL_EOF (-1) /* End of input */
|
||||
#define GL_INTERRUPT (-2) /* User hit Ctrl+C */
|
||||
|
||||
typedef size_t (*gl_strwidth_proc)(char *);
|
||||
typedef int (*gl_in_hook_proc)(char *);
|
||||
typedef int (*gl_out_hook_proc)(char *);
|
||||
typedef int (*gl_tab_hook_proc)(char *, int, int *, size_t);
|
||||
typedef size_t (*gl_strlen_proc)(const char *);
|
||||
typedef char * (*gl_tab_completion_proc)(const char *, int);
|
||||
|
||||
char *getline(char *); /* read a line of input */
|
||||
void gl_setwidth(int); /* specify width of screen */
|
||||
void gl_setheight(int); /* specify height of screen */
|
||||
void gl_histadd(char *); /* adds entries to hist */
|
||||
void gl_strwidth(gl_strwidth_proc); /* to bind gl_strlen */
|
||||
void gl_tab_completion(gl_tab_completion_proc);
|
||||
char *gl_local_filename_completion_proc(const char *, int);
|
||||
void gl_set_home_dir(const char *homedir);
|
||||
void gl_histsavefile(const char *const path);
|
||||
void gl_histloadfile(const char *const path);
|
||||
char *gl_getpass(const char *const prompt, char *const pass, int dsize);
|
||||
int gl_get_result(void);
|
||||
|
||||
#ifndef _getline_c_
|
||||
|
||||
extern gl_in_hook_proc gl_in_hook;
|
||||
extern gl_out_hook_proc gl_out_hook;
|
||||
extern gl_tab_hook_proc gl_tab_hook;
|
||||
extern gl_strlen_proc gl_strlen;
|
||||
extern gl_tab_completion_proc gl_completion_proc;
|
||||
extern int gl_filename_quoting_desired;
|
||||
extern const char *gl_filename_quote_characters;
|
||||
extern int gl_ellipses_during_completion;
|
||||
extern int gl_completion_exact_match_extra_char;
|
||||
extern char gl_buf[GL_BUF_SIZE];
|
||||
|
||||
#endif /* ! _getline_c_ */
|
||||
|
||||
#endif /* GETLINE_H */
|
|
@ -1,82 +0,0 @@
|
|||
/* getopt.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
int gOptErr = 1; /* if error message should be printed */
|
||||
int gOptInd = 1; /* index into parent argv vector */
|
||||
int gOptOpt; /* character checked for validity */
|
||||
const char *gOptArg; /* argument associated with option */
|
||||
const char *gOptPlace = kGetoptErrMsg; /* saved position in an arg */
|
||||
|
||||
/* This must be called before each Getopt. */
|
||||
void
|
||||
GetoptReset(void)
|
||||
{
|
||||
gOptInd = 1;
|
||||
gOptPlace = kGetoptErrMsg;
|
||||
} /* GetoptReset */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
NextOption(const char *const ostr)
|
||||
{
|
||||
if ((gOptOpt = (int) *gOptPlace++) == (int) ':')
|
||||
return 0;
|
||||
return strchr(ostr, gOptOpt);
|
||||
} /* NextOption */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
Getopt(int nargc, const char **const nargv, const char *const ostr)
|
||||
{
|
||||
const char *oli; /* Option letter list index */
|
||||
|
||||
if (!*gOptPlace) { /* update scanning pointer */
|
||||
if (gOptInd >= nargc || *(gOptPlace = nargv[gOptInd]) != '-')
|
||||
return (EOF);
|
||||
if (gOptPlace[1] && *++gOptPlace == '-') { /* found "--" */
|
||||
++gOptInd;
|
||||
return (EOF);
|
||||
}
|
||||
} /* Option letter okay? */
|
||||
oli = NextOption(ostr);
|
||||
if (oli == NULL) {
|
||||
if (!*gOptPlace)
|
||||
++gOptInd;
|
||||
if (gOptErr)
|
||||
(void) fprintf(stderr, "%s%s%c\n", *nargv, ": illegal option -- ", gOptOpt);
|
||||
return(kGetoptBadChar);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
gOptArg = NULL;
|
||||
if (!*gOptPlace)
|
||||
++gOptInd;
|
||||
} else { /* need an argument */
|
||||
if (*gOptPlace) /* no white space */
|
||||
gOptArg = gOptPlace;
|
||||
else if (nargc <= ++gOptInd) { /* no arg */
|
||||
gOptPlace = kGetoptErrMsg;
|
||||
if (gOptErr)
|
||||
(void) fprintf(stderr, "%s%s%c\n", *nargv, ": option requires an argument -- ", gOptOpt);
|
||||
return(kGetoptBadChar);
|
||||
} else /* white space */
|
||||
gOptArg = nargv[gOptInd];
|
||||
gOptPlace = kGetoptErrMsg;
|
||||
++gOptInd;
|
||||
}
|
||||
return (gOptOpt); /* dump back Option letter */
|
||||
} /* Getopt */
|
||||
|
||||
/* eof */
|
|
@ -1,12 +0,0 @@
|
|||
/* getopt.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#define kGetoptBadChar ((int) '?')
|
||||
#define kGetoptErrMsg ""
|
||||
|
||||
void GetoptReset(void);
|
||||
int Getopt(int nargc, const char **const nargv, const char *const ostr);
|
|
@ -1,124 +0,0 @@
|
|||
/* log.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
extern int gMaxLogSize;
|
||||
char gLogFileName[256];
|
||||
|
||||
extern char gOurDirectoryPath[];
|
||||
|
||||
|
||||
void
|
||||
InitLog(void)
|
||||
{
|
||||
OurDirectoryPath(gLogFileName, sizeof(gLogFileName), kLogFileName);
|
||||
} /* InitLog */
|
||||
|
||||
|
||||
|
||||
void
|
||||
LogXfer(const char *const mode, const char *const url)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if (gMaxLogSize == 0)
|
||||
return; /* Don't log */
|
||||
|
||||
fp = fopen(gLogFileName, FOPEN_APPEND_TEXT);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, " %s %s\n", mode, url);
|
||||
(void) fclose(fp);
|
||||
}
|
||||
} /* LogOpen */
|
||||
|
||||
|
||||
|
||||
void
|
||||
LogOpen(const char *const host)
|
||||
{
|
||||
time_t now;
|
||||
FILE *fp;
|
||||
|
||||
if (gMaxLogSize == 0)
|
||||
return; /* Don't log */
|
||||
|
||||
time(&now);
|
||||
fp = fopen(gLogFileName, FOPEN_APPEND_TEXT);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s at %s", host, ctime(&now));
|
||||
(void) fclose(fp);
|
||||
}
|
||||
} /* LogOpen */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
EndLog(void)
|
||||
{
|
||||
FILE *new, *old;
|
||||
struct Stat st;
|
||||
long fat;
|
||||
char str[512];
|
||||
char tmpLog[256];
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return; /* Don't create in root directory. */
|
||||
|
||||
/* If the user wants to, s/he can specify the maximum size of the log file,
|
||||
* so it doesn't waste too much disk space. If the log is too fat, trim the
|
||||
* older lines (at the top) until we're under the limit.
|
||||
*/
|
||||
if ((gMaxLogSize <= 0) || (Stat(gLogFileName, &st) < 0))
|
||||
return; /* Never trim, or no log. */
|
||||
|
||||
if ((size_t)st.st_size < (size_t)gMaxLogSize)
|
||||
return; /* Log size not over limit yet. */
|
||||
|
||||
if ((old = fopen(gLogFileName, FOPEN_READ_TEXT)) == NULL)
|
||||
return;
|
||||
|
||||
/* Want to make it so we're about 30% below capacity.
|
||||
* That way we won't trim the log each time we run the program.
|
||||
*/
|
||||
fat = (long) st.st_size - (long) gMaxLogSize + (long) (0.30 * gMaxLogSize);
|
||||
while (fat > 0L) {
|
||||
if (fgets(str, (int) sizeof(str), old) == NULL)
|
||||
return;
|
||||
fat -= (long) strlen(str);
|
||||
}
|
||||
/* skip lines until a new site was opened */
|
||||
for (;;) {
|
||||
if (fgets(str, (int) sizeof(str), old) == NULL) {
|
||||
(void) fclose(old);
|
||||
(void) remove(gLogFileName);
|
||||
return; /* Nothing left, start anew next time. */
|
||||
}
|
||||
if (! isspace(*str))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy the remaining lines in "old" to "new" */
|
||||
OurDirectoryPath(tmpLog, sizeof(tmpLog), "log.tmp");
|
||||
if ((new = fopen(tmpLog, FOPEN_WRITE_TEXT)) == NULL) {
|
||||
(void) fclose(old);
|
||||
return;
|
||||
}
|
||||
(void) fputs(str, new);
|
||||
while (fgets(str, (int) sizeof(str), old) != NULL)
|
||||
(void) fputs(str, new);
|
||||
(void) fclose(old);
|
||||
(void) fclose(new);
|
||||
if (remove(gLogFileName) < 0)
|
||||
return;
|
||||
if (rename(tmpLog, gLogFileName) < 0)
|
||||
return;
|
||||
} /* EndLog */
|
|
@ -1,18 +0,0 @@
|
|||
/* log.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kLogFileName "log.txt"
|
||||
#else
|
||||
# define kLogFileName "log"
|
||||
#endif
|
||||
|
||||
/* trace.c */
|
||||
void EndLog(void);
|
||||
void InitLog(void);
|
||||
void LogOpen(const char *const host);
|
||||
void LogXfer(const char *const mode, const char *const url);
|
|
@ -1,779 +0,0 @@
|
|||
/* ls.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
#include "util.h"
|
||||
#include "ls.h"
|
||||
#include "trace.h"
|
||||
|
||||
/* The program keeps a timestamp of 6 months ago and an hour from now, because
|
||||
* the standard /bin/ls command will print the time (i.e. "Nov 8 09:20")
|
||||
* instead of the year (i.e. "Oct 27 1996") if a file's timestamp is within
|
||||
* this period.
|
||||
*/
|
||||
time_t gNowMinus6Mon, gNowPlus1Hr;
|
||||
|
||||
/* An array of month name abbreviations. This may not be in English. */
|
||||
char gLsMon[13][4];
|
||||
|
||||
/* The program keeps its own cache of directory listings, so it doesn't
|
||||
* need to re-request them from the server.
|
||||
*/
|
||||
LsCacheItem gLsCache[kLsCacheSize];
|
||||
int gOldestLsCacheItem;
|
||||
int gLsCacheItemLifetime = kLsCacheItemLifetime;
|
||||
|
||||
extern FTPConnectionInfo gConn;
|
||||
extern char gRemoteCWD[512];
|
||||
extern int gScreenColumns, gDebug;
|
||||
|
||||
|
||||
void
|
||||
InitLsCache(void)
|
||||
{
|
||||
(void) memset(gLsCache, 0, sizeof(gLsCache));
|
||||
gOldestLsCacheItem = 0;
|
||||
} /* InitLsCache */
|
||||
|
||||
|
||||
|
||||
/* Creates the ls monthname abbreviation array, so we don't have to
|
||||
* re-calculate them each time.
|
||||
*/
|
||||
void InitLsMonths(void)
|
||||
{
|
||||
time_t now;
|
||||
struct tm *ltp;
|
||||
int i;
|
||||
|
||||
(void) time(&now);
|
||||
ltp = localtime(&now); /* Fill up the structure. */
|
||||
ltp->tm_mday = 15;
|
||||
ltp->tm_hour = 12;
|
||||
for (i=0; i<12; i++) {
|
||||
ltp->tm_mon = i;
|
||||
(void) strftime(gLsMon[i], sizeof(gLsMon[i]), "%b", ltp);
|
||||
gLsMon[i][sizeof(gLsMon[i]) - 1] = '\0';
|
||||
}
|
||||
(void) strcpy(gLsMon[i], "BUG");
|
||||
} /* InitLsMonths */
|
||||
|
||||
|
||||
|
||||
|
||||
void InitLs(void)
|
||||
{
|
||||
InitLsCache();
|
||||
InitLsMonths();
|
||||
} /* InitLs */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Deletes an item from the ls cache. */
|
||||
static void
|
||||
FlushLsCacheItem(int i)
|
||||
{
|
||||
Trace(1, "flush ls cache item: %s\n", gLsCache[i].itempath);
|
||||
if (gLsCache[i].itempath != NULL)
|
||||
free(gLsCache[i].itempath);
|
||||
gLsCache[i].itempath = NULL;
|
||||
gLsCache[i].expiration = (time_t) 0;
|
||||
DisposeFileInfoListContents(&gLsCache[i].fil);
|
||||
} /* FlushLsCacheItem */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Clears all items from the ls cache. */
|
||||
void
|
||||
FlushLsCache(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<kLsCacheSize; i++) {
|
||||
if (gLsCache[i].expiration != (time_t) 0) {
|
||||
FlushLsCacheItem(i);
|
||||
}
|
||||
}
|
||||
} /* FlushLsCache */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Checks the cache for a directory listing for the given path. */
|
||||
int
|
||||
LsCacheLookup(const char *const itempath)
|
||||
{
|
||||
int i, j;
|
||||
time_t now;
|
||||
|
||||
(void) time(&now);
|
||||
for (i=0, j=gOldestLsCacheItem; i<kLsCacheSize; i++) {
|
||||
if (--j < 0)
|
||||
j = kLsCacheSize - 1;
|
||||
if ((gLsCache[j].expiration != (time_t) 0) && (gLsCache[j].itempath != NULL)) {
|
||||
if (strcmp(itempath, gLsCache[j].itempath) == 0) {
|
||||
if (now > gLsCache[j].expiration) {
|
||||
/* Found it, but it was expired. */
|
||||
FlushLsCacheItem(j);
|
||||
return (-1);
|
||||
}
|
||||
gLsCache[j].hits++;
|
||||
return (j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (-1);
|
||||
} /* LsCacheLookup */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Saves a directory listing from the given path into the cache. */
|
||||
static void
|
||||
LsCacheAdd(const char *const itempath, FileInfoListPtr files)
|
||||
{
|
||||
char *cp;
|
||||
int j;
|
||||
|
||||
/* Never cache empty listings in case of errors */
|
||||
if (files->nFileInfos == 0)
|
||||
return;
|
||||
|
||||
j = LsCacheLookup(itempath);
|
||||
if (j >= 0) {
|
||||
/* Directory was already in there;
|
||||
* Replace it with the new
|
||||
* contents.
|
||||
*/
|
||||
FlushLsCacheItem(j);
|
||||
}
|
||||
|
||||
cp = StrDup(itempath);
|
||||
if (cp == NULL)
|
||||
return;
|
||||
|
||||
j = gOldestLsCacheItem;
|
||||
(void) memcpy(&gLsCache[j].fil, files, sizeof(FileInfoList));
|
||||
(void) time(&gLsCache[j].expiration);
|
||||
gLsCache[j].expiration += gLsCacheItemLifetime;
|
||||
gLsCache[j].hits = 0;
|
||||
gLsCache[j].itempath = cp;
|
||||
Trace(1, "ls cache add: %s\n", itempath);
|
||||
|
||||
/* Increment the pointer. This is a circular array, so if it
|
||||
* hits the end it wraps over to the other side.
|
||||
*/
|
||||
gOldestLsCacheItem++;
|
||||
if (gOldestLsCacheItem >= kLsCacheSize)
|
||||
gOldestLsCacheItem = 0;
|
||||
} /* LsCacheAdd */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Does "ls -C", or the nice columnized /bin/ls-style format. */
|
||||
static void
|
||||
LsC(FileInfoListPtr dirp, int endChars, FILE *stream)
|
||||
{
|
||||
char buf[400];
|
||||
char buf2[400];
|
||||
int ncol, nrow;
|
||||
int i, j, k, l;
|
||||
int colw;
|
||||
int n;
|
||||
FileInfoVec itemv;
|
||||
FileInfoPtr itemp;
|
||||
char *cp1, *cp2, *lim;
|
||||
int screenColumns;
|
||||
|
||||
screenColumns = gScreenColumns;
|
||||
if (screenColumns > 400)
|
||||
screenColumns = 400;
|
||||
ncol = (screenColumns - 1) / ((int) dirp->maxFileLen + 2 + /*1or0*/ endChars);
|
||||
if (ncol < 1)
|
||||
ncol = 1;
|
||||
colw = (screenColumns - 1) / ncol;
|
||||
n = dirp->nFileInfos;
|
||||
nrow = n / ncol;
|
||||
if ((n % ncol) != 0)
|
||||
nrow++;
|
||||
|
||||
for (i=0; i<(int) sizeof(buf2); i++)
|
||||
buf2[i] = ' ';
|
||||
|
||||
itemv = dirp->vec;
|
||||
|
||||
for (j=0; j<nrow; j++) {
|
||||
(void) memcpy(buf, buf2, sizeof(buf));
|
||||
for (i=0, k=j, l=0; i<ncol; i++, k += nrow, l += colw) {
|
||||
if (k >= n)
|
||||
continue;
|
||||
itemp = itemv[k];
|
||||
cp1 = buf + l;
|
||||
lim = cp1 + (int) (itemp->relnameLen);
|
||||
cp2 = itemp->relname;
|
||||
while (cp1 < lim)
|
||||
*cp1++ = *cp2++;
|
||||
if (endChars != 0) {
|
||||
if (itemp->type == 'l') {
|
||||
/* Regular ls always uses @
|
||||
* for a symlink tail, even if
|
||||
* the linked item is a directory.
|
||||
*/
|
||||
*cp1++ = '@';
|
||||
} else if (itemp->type == 'd') {
|
||||
*cp1++ = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
for (cp1 = buf + sizeof(buf); *--cp1 == ' '; ) {}
|
||||
++cp1;
|
||||
*cp1++ = '\n';
|
||||
*cp1 = '\0';
|
||||
(void) fprintf(stream, "%s", buf);
|
||||
Trace(0, "%s", buf);
|
||||
}
|
||||
} /* LsC */
|
||||
|
||||
|
||||
|
||||
/* Converts a timestamp into a recent date string ("May 27 06:33"), or an
|
||||
* old (or future) date string (i.e. "Oct 27 1996").
|
||||
*/
|
||||
void
|
||||
LsDate(char *dstr, time_t ts)
|
||||
{
|
||||
struct tm *gtp;
|
||||
|
||||
if (ts == kModTimeUnknown) {
|
||||
(void) strcpy(dstr, " ");
|
||||
return;
|
||||
}
|
||||
gtp = localtime(&ts);
|
||||
if (gtp == NULL) {
|
||||
(void) strcpy(dstr, "Jan 0 1900");
|
||||
return;
|
||||
}
|
||||
if ((ts > gNowPlus1Hr) || (ts < gNowMinus6Mon)) {
|
||||
(void) sprintf(dstr, "%s %2d %4d",
|
||||
gLsMon[gtp->tm_mon],
|
||||
gtp->tm_mday,
|
||||
gtp->tm_year + 1900
|
||||
);
|
||||
} else {
|
||||
(void) sprintf(dstr, "%s %2d %02d:%02d",
|
||||
gLsMon[gtp->tm_mon],
|
||||
gtp->tm_mday,
|
||||
gtp->tm_hour,
|
||||
gtp->tm_min
|
||||
);
|
||||
}
|
||||
} /* LsDate */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Does "ls -l", or the detailed /bin/ls-style, one file per line . */
|
||||
void
|
||||
LsL(FileInfoListPtr dirp, int endChars, int linkedTo, FILE *stream)
|
||||
{
|
||||
FileInfoPtr diritemp;
|
||||
FileInfoVec diritemv;
|
||||
int i;
|
||||
char fTail[2];
|
||||
int fType;
|
||||
const char *l1, *l2;
|
||||
char datestr[16];
|
||||
char sizestr[32];
|
||||
char plugspec[16];
|
||||
char plugstr[64];
|
||||
const char *expad;
|
||||
|
||||
fTail[0] = '\0';
|
||||
fTail[1] = '\0';
|
||||
|
||||
(void) time(&gNowPlus1Hr);
|
||||
gNowMinus6Mon = gNowPlus1Hr - 15552000;
|
||||
gNowPlus1Hr += 3600;
|
||||
|
||||
diritemv = dirp->vec;
|
||||
#ifdef HAVE_SNPRINTF
|
||||
(void) snprintf(
|
||||
plugspec,
|
||||
sizeof(plugspec) - 1,
|
||||
#else
|
||||
(void) sprintf(
|
||||
plugspec,
|
||||
#endif
|
||||
"%%-%ds",
|
||||
(int) dirp->maxPlugLen
|
||||
);
|
||||
|
||||
if (dirp->maxPlugLen < 29) {
|
||||
/* We have some extra space to work with,
|
||||
* so we can space out the columns a little.
|
||||
*/
|
||||
expad = " ";
|
||||
} else {
|
||||
expad = "";
|
||||
}
|
||||
|
||||
for (i=0; ; i++) {
|
||||
diritemp = diritemv[i];
|
||||
if (diritemp == NULL)
|
||||
break;
|
||||
|
||||
fType = (int) diritemp->type;
|
||||
if (endChars != 0) {
|
||||
if (fType == 'd')
|
||||
fTail[0] = '/';
|
||||
else
|
||||
fTail[0] = '\0';
|
||||
}
|
||||
|
||||
if (diritemp->rlinkto != NULL) {
|
||||
if (linkedTo != 0) {
|
||||
l1 = "";
|
||||
l2 = "";
|
||||
} else {
|
||||
l1 = " -> ";
|
||||
l2 = diritemp->rlinkto;
|
||||
}
|
||||
} else {
|
||||
l1 = "";
|
||||
l2 = "";
|
||||
}
|
||||
|
||||
LsDate(datestr, diritemp->mdtm);
|
||||
|
||||
if (diritemp->size == kSizeUnknown) {
|
||||
*sizestr = '\0';
|
||||
} else {
|
||||
#ifdef HAVE_SNPRINTF
|
||||
(void) snprintf(
|
||||
sizestr,
|
||||
sizeof(sizestr) - 1,
|
||||
#else
|
||||
(void) sprintf(
|
||||
sizestr,
|
||||
#endif
|
||||
#if defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG)
|
||||
PRINTF_LONG_LONG,
|
||||
#else
|
||||
"%ld",
|
||||
#endif
|
||||
(longest_int) diritemp->size
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SNPRINTF
|
||||
(void) snprintf(
|
||||
plugstr,
|
||||
sizeof(plugstr) - 1,
|
||||
#else
|
||||
(void) sprintf(
|
||||
plugstr,
|
||||
#endif
|
||||
plugspec,
|
||||
diritemp->plug
|
||||
);
|
||||
|
||||
(void) fprintf(stream, "%s %12s %s%s %s%s%s%s%s\n",
|
||||
plugstr,
|
||||
sizestr,
|
||||
expad,
|
||||
datestr,
|
||||
expad,
|
||||
diritemp->relname,
|
||||
l1,
|
||||
l2,
|
||||
fTail
|
||||
);
|
||||
Trace(0, "%s %12s %s%s %s%s%s%s%s\n",
|
||||
plugstr,
|
||||
sizestr,
|
||||
expad,
|
||||
datestr,
|
||||
expad,
|
||||
diritemp->relname,
|
||||
l1,
|
||||
l2,
|
||||
fTail
|
||||
);
|
||||
}
|
||||
} /* LsL */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Does "ls -1", or the simple single-column /bin/ls-style format, with
|
||||
* one file per line.
|
||||
*/
|
||||
void
|
||||
Ls1(FileInfoListPtr dirp, int endChars, FILE *stream)
|
||||
{
|
||||
char fTail[2];
|
||||
int i;
|
||||
int fType;
|
||||
FileInfoVec diritemv;
|
||||
FileInfoPtr diritemp;
|
||||
|
||||
fTail[0] = '\0';
|
||||
fTail[1] = '\0';
|
||||
diritemv = dirp->vec;
|
||||
|
||||
for (i=0; ; i++) {
|
||||
diritemp = diritemv[i];
|
||||
if (diritemp == NULL)
|
||||
break;
|
||||
|
||||
fType = (int) diritemp->type;
|
||||
if (endChars != 0) {
|
||||
if (fType == 'd')
|
||||
fTail[0] = '/';
|
||||
else
|
||||
fTail[0] = '\0';
|
||||
}
|
||||
|
||||
(void) fprintf(stream, "%s%s\n",
|
||||
diritemp->relname,
|
||||
fTail
|
||||
);
|
||||
|
||||
Trace(0, "%s%s\n",
|
||||
diritemp->relname,
|
||||
fTail
|
||||
);
|
||||
}
|
||||
} /* Ls1 */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Prints a directory listing in the specified format on the specified
|
||||
* output stream. It may or may not need to request it from the remote
|
||||
* server, depending on whether it was cached.
|
||||
*/
|
||||
void
|
||||
Ls(const char *const item, int listmode, const char *const options, FILE *stream)
|
||||
{
|
||||
char itempath[512];
|
||||
FileInfoList fil;
|
||||
FileInfoListPtr filp;
|
||||
LinePtr linePtr, nextLinePtr;
|
||||
LineList dirContents;
|
||||
int parsed;
|
||||
int linkedTo;
|
||||
int endChars;
|
||||
int rlisted;
|
||||
int opt;
|
||||
const char *cp;
|
||||
int sortBy;
|
||||
int sortOrder;
|
||||
int unknownOpts;
|
||||
char optstr[32];
|
||||
char unoptstr[32];
|
||||
int doNotUseCache;
|
||||
int wasInCache;
|
||||
int mlsd;
|
||||
int ci;
|
||||
|
||||
InitLineList(&dirContents);
|
||||
InitFileInfoList(&fil);
|
||||
|
||||
sortBy = 'n'; /* Sort by filename. */
|
||||
sortOrder = 'a'; /* Sort in ascending order. */
|
||||
linkedTo = 0;
|
||||
endChars = (listmode == 'C') ? 1 : 0;
|
||||
unknownOpts = 0;
|
||||
memset(unoptstr, 0, sizeof(unoptstr));
|
||||
unoptstr[0] = '-';
|
||||
doNotUseCache = 0;
|
||||
rlisted = 0;
|
||||
|
||||
for (cp = options; *cp != '\0'; cp++) {
|
||||
opt = *cp;
|
||||
switch (opt) {
|
||||
case 't':
|
||||
sortBy = 't'; /* Sort by modification time. */
|
||||
break;
|
||||
case 'S':
|
||||
sortBy = 's'; /* Sort by size. */
|
||||
break;
|
||||
case 'r':
|
||||
sortOrder = 'd'; /* descending order */
|
||||
break;
|
||||
case 'L':
|
||||
linkedTo = 1;
|
||||
break;
|
||||
case 'f':
|
||||
doNotUseCache = 1;
|
||||
break;
|
||||
case 'F':
|
||||
case 'p':
|
||||
endChars = 1;
|
||||
break;
|
||||
case '1':
|
||||
case 'C':
|
||||
case 'l':
|
||||
listmode = opt;
|
||||
break;
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
if (unknownOpts < ((int) sizeof(unoptstr) - 2))
|
||||
unoptstr[unknownOpts + 1] = opt;
|
||||
unknownOpts++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a possibly relative path into an absolute path. */
|
||||
PathCat(itempath, sizeof(itempath), gRemoteCWD,
|
||||
(item == NULL) ? "." : item);
|
||||
|
||||
if (unknownOpts > 0) {
|
||||
/* Can't handle these -- pass them through
|
||||
* to the server.
|
||||
*/
|
||||
|
||||
Trace(0, "ls caching not used because of ls flags: %s\n", unoptstr);
|
||||
optstr[0] = '-';
|
||||
optstr[1] = listmode;
|
||||
optstr[2] = '\0';
|
||||
(void) STRNCAT(optstr, options);
|
||||
if ((FTPListToMemory2(&gConn, (item == NULL) ? "" : item, &dirContents, optstr, 1, 0)) < 0) {
|
||||
if (stream != NULL)
|
||||
(void) fprintf(stderr, "List failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rlisted = 1;
|
||||
parsed = -1;
|
||||
wasInCache = 0;
|
||||
filp = NULL;
|
||||
} else if ((doNotUseCache != 0) || ((ci = LsCacheLookup(itempath)) < 0)) {
|
||||
/* Not in cache. */
|
||||
wasInCache = 0;
|
||||
|
||||
mlsd = 1;
|
||||
if ((FTPListToMemory2(&gConn, (item == NULL) ? "" : item, &dirContents, "-l", 1, &mlsd)) < 0) {
|
||||
if (stream != NULL)
|
||||
(void) fprintf(stderr, "List failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rlisted = 1;
|
||||
filp = &fil;
|
||||
if (mlsd != 0) {
|
||||
parsed = UnMlsD(filp, &dirContents);
|
||||
if (parsed < 0) {
|
||||
Trace(0, "UnMlsD: %d\n", parsed);
|
||||
}
|
||||
} else {
|
||||
parsed = UnLslR(filp, &dirContents, gConn.serverType);
|
||||
if (parsed < 0) {
|
||||
Trace(0, "UnLslR: %d\n", parsed);
|
||||
}
|
||||
}
|
||||
if (parsed >= 0) {
|
||||
VectorizeFileInfoList(filp);
|
||||
if (filp->vec == NULL) {
|
||||
if (stream != NULL)
|
||||
(void) fprintf(stderr, "List processing failed.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filp = &gLsCache[ci].fil;
|
||||
wasInCache = 1;
|
||||
parsed = 1;
|
||||
Trace(0, "ls cache hit: %s\n", itempath);
|
||||
}
|
||||
|
||||
if (rlisted != 0) {
|
||||
Trace(0, "Remote listing contents {\n");
|
||||
for (linePtr = dirContents.first;
|
||||
linePtr != NULL;
|
||||
linePtr = nextLinePtr)
|
||||
{
|
||||
nextLinePtr = linePtr->next;
|
||||
Trace(0, " %s\n", linePtr->line);
|
||||
}
|
||||
Trace(0, "}\n");
|
||||
}
|
||||
|
||||
if (parsed >= 0) {
|
||||
SortFileInfoList(filp, sortBy, sortOrder);
|
||||
if (stream != NULL) {
|
||||
if (listmode == 'l')
|
||||
LsL(filp, endChars, linkedTo, stream);
|
||||
else if (listmode == '1')
|
||||
Ls1(filp, endChars, stream);
|
||||
else
|
||||
LsC(filp, endChars, stream);
|
||||
}
|
||||
if (wasInCache == 0) {
|
||||
LsCacheAdd(itempath, filp);
|
||||
}
|
||||
} else if (stream != NULL) {
|
||||
for (linePtr = dirContents.first;
|
||||
linePtr != NULL;
|
||||
linePtr = nextLinePtr)
|
||||
{
|
||||
nextLinePtr = linePtr->next;
|
||||
(void) fprintf(stream, "%s\n", linePtr->line);
|
||||
Trace(0, " %s\n", linePtr->line);
|
||||
}
|
||||
}
|
||||
|
||||
DisposeLineListContents(&dirContents);
|
||||
} /* Ls */
|
||||
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
/* Prints a local directory listing in the specified format on the specified
|
||||
* output stream.
|
||||
*/
|
||||
void
|
||||
LLs(const char *const item, int listmode, const char *const options, FILE *stream)
|
||||
{
|
||||
char itempath[512];
|
||||
int linkedTo;
|
||||
int endChars;
|
||||
int opt;
|
||||
const char *cp;
|
||||
int sortBy;
|
||||
int sortOrder;
|
||||
int unknownOpts;
|
||||
char unoptstr[32];
|
||||
LineList ll;
|
||||
FileInfoPtr fip, fip2;
|
||||
FileInfoList fil;
|
||||
struct Stat st;
|
||||
int result;
|
||||
size_t len;
|
||||
|
||||
InitLineList(&ll);
|
||||
InitFileInfoList(&fil);
|
||||
|
||||
sortBy = 'n'; /* Sort by filename. */
|
||||
sortOrder = 'a'; /* Sort in ascending order. */
|
||||
linkedTo = 0;
|
||||
endChars = (listmode == 'C') ? 1 : 0;
|
||||
unknownOpts = 0;
|
||||
memset(unoptstr, 0, sizeof(unoptstr));
|
||||
unoptstr[0] = '-';
|
||||
|
||||
for (cp = options; *cp != '\0'; cp++) {
|
||||
opt = *cp;
|
||||
switch (opt) {
|
||||
case 't':
|
||||
sortBy = 't'; /* Sort by modification time. */
|
||||
break;
|
||||
case 'S':
|
||||
sortBy = 's'; /* Sort by size. */
|
||||
break;
|
||||
case 'r':
|
||||
sortOrder = 'd'; /* descending order */
|
||||
break;
|
||||
case 'L':
|
||||
linkedTo = 1;
|
||||
break;
|
||||
case 'f':
|
||||
break;
|
||||
case 'F':
|
||||
case 'p':
|
||||
endChars = 1;
|
||||
break;
|
||||
case '1':
|
||||
case 'C':
|
||||
case 'l':
|
||||
listmode = opt;
|
||||
break;
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
if (unknownOpts < ((int) sizeof(unoptstr) - 2))
|
||||
unoptstr[unknownOpts + 1] = opt;
|
||||
unknownOpts++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((item == NULL) || (strcmp(item, ".") == 0))
|
||||
STRNCPY(itempath, "*.*");
|
||||
else {
|
||||
STRNCPY(itempath, item);
|
||||
if (strpbrk(itempath, "*?") == NULL)
|
||||
STRNCAT(itempath, "\\*.*");
|
||||
}
|
||||
|
||||
InitLineList(&ll);
|
||||
result = FTPLocalGlob(&gConn, &ll, itempath, kGlobYes);
|
||||
if (result < 0) {
|
||||
FTPPerror(&gConn, result, kErrGlobFailed, "local glob", itempath);
|
||||
DisposeLineListContents(&ll);
|
||||
return;
|
||||
}
|
||||
if (LineListToFileInfoList(&ll, &fil) < 0)
|
||||
return;
|
||||
DisposeLineListContents(&ll);
|
||||
|
||||
for (fip = fil.first; fip != NULL; fip = fip2) {
|
||||
fip2 = fip->next;
|
||||
if (Stat(fip->relname, &st) < 0) {
|
||||
fip2 = RemoveFileInfo(&fil, fip);
|
||||
continue;
|
||||
}
|
||||
cp = StrRFindLocalPathDelim(fip->relname);
|
||||
if (cp != NULL) {
|
||||
/* FTPLocalGlob will tack on the pathnames too,
|
||||
* which we don't want for this hack.
|
||||
*/
|
||||
cp++;
|
||||
len = strlen(cp);
|
||||
memmove(fip->relname, cp, len + 1);
|
||||
} else {
|
||||
len = strlen(fip->relname);
|
||||
}
|
||||
if (len > fil.maxFileLen)
|
||||
fil.maxFileLen = len;
|
||||
fip->relnameLen = len;
|
||||
fip->rname = StrDup(fip->relname);
|
||||
fip->lname = StrDup(fip->relname);
|
||||
fip->plug = StrDup("---------- 1 user group");
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
fip->type = 'd';
|
||||
fip->plug[0] = 'd';
|
||||
} else {
|
||||
fip->type = '-';
|
||||
fip->size = st.st_size;
|
||||
}
|
||||
fip->mdtm = st.st_mtime;
|
||||
}
|
||||
fil.maxPlugLen = strlen("---------- 1 user group");
|
||||
|
||||
VectorizeFileInfoList(&fil);
|
||||
SortFileInfoList(&fil, sortBy, sortOrder);
|
||||
if (stream != NULL) {
|
||||
if (listmode == 'l')
|
||||
LsL(&fil, endChars, linkedTo, stream);
|
||||
else if (listmode == '1')
|
||||
Ls1(&fil, endChars, stream);
|
||||
else
|
||||
LsC(&fil, endChars, stream);
|
||||
}
|
||||
|
||||
DisposeFileInfoListContents(&fil);
|
||||
} /* LLs */
|
||||
#endif
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/* ls.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#define kLsCacheItemLifetime 900 /* seconds */
|
||||
|
||||
typedef struct LsCacheItem {
|
||||
char *itempath;
|
||||
FileInfoList fil;
|
||||
time_t expiration;
|
||||
int hits;
|
||||
} LsCacheItem;
|
||||
|
||||
#define kLsCacheSize 32
|
||||
|
||||
/* ls.c */
|
||||
void InitLsCache(void);
|
||||
void InitLsMonths(void);
|
||||
void InitLs(void);
|
||||
void FlushLsCache(void);
|
||||
int LsCacheLookup(const char *const);
|
||||
void LsDate(char *, time_t);
|
||||
void LsL(FileInfoListPtr, int, int, FILE *);
|
||||
void Ls1(FileInfoListPtr, int, FILE *);
|
||||
void Ls(const char *const, int, const char *const, FILE *);
|
||||
void LLs(const char *const, int, const char *const, FILE *);
|
|
@ -1,477 +0,0 @@
|
|||
/* main.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
#include "ls.h"
|
||||
#include "bookmark.h"
|
||||
#include "shell.h"
|
||||
#include "cmds.h"
|
||||
#include "main.h"
|
||||
#include "getopt.h"
|
||||
#include "progress.h"
|
||||
#include "pref.h"
|
||||
#include "readln.h"
|
||||
#include "trace.h"
|
||||
#include "log.h"
|
||||
#include "spool.h"
|
||||
#include "util.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
WSADATA wsaData;
|
||||
int wsaInit = 0;
|
||||
|
||||
__inline void DisposeWinsock(int aUNUSED) { if (wsaInit > 0) WSACleanup(); wsaInit--; }
|
||||
#else
|
||||
# define DisposeWinsock(a)
|
||||
#endif
|
||||
|
||||
int gStartupUrlParameterGiven = 0;
|
||||
int gIsTTY, gIsTTYr;
|
||||
int gScreenColumns;
|
||||
|
||||
FTPLibraryInfo gLib;
|
||||
FTPConnectionInfo gConn;
|
||||
LineList gStartupURLCdList;
|
||||
int gTransferTypeInitialized = 0;
|
||||
int gTransferType;
|
||||
int gURLMode = 0;
|
||||
extern int gUnprocessedJobs;
|
||||
char gLocalCWD[512], gPrevLocalCWD[512];
|
||||
|
||||
extern char *gOptArg;
|
||||
extern int gOptInd;
|
||||
extern char gRemoteCWD[512], gPrevRemoteCWD[512];
|
||||
extern Bookmark gBm;
|
||||
extern int gLoadedBm;
|
||||
extern int gFirstTimeUser;
|
||||
extern int gFirewallType;
|
||||
extern char gAutoAscii[];
|
||||
extern char gFirewallHost[64];
|
||||
extern char gFirewallUser[32];
|
||||
extern char gFirewallPass[32];
|
||||
extern char gFirewallExceptionList[];
|
||||
extern char gCopyright[], gVersion[];
|
||||
extern unsigned int gFirewallPort;
|
||||
extern int gConnTimeout, gXferTimeout, gCtrlTimeout;
|
||||
extern int gDataPortMode, gRedialDelay;
|
||||
extern int gDebug;
|
||||
extern int gNumProgramRuns, gDoNotDisplayAds;
|
||||
extern int gSOBufsize;
|
||||
extern FTPProgressMeterProc gProgressMeter;
|
||||
|
||||
static void
|
||||
Usage(void)
|
||||
{
|
||||
FILE *fp;
|
||||
#ifdef UNAME
|
||||
char s[80];
|
||||
#endif
|
||||
|
||||
fp = stderr;
|
||||
(void) fprintf(fp, "\nUsage: ncftp [flags] [<host> | <directory URL to browse>]\n");
|
||||
(void) fprintf(fp, "\nFlags:\n\
|
||||
-u XX Use username XX instead of anonymous.\n\
|
||||
-p XX Use password XX with the username.\n\
|
||||
-P XX Use port number XX instead of the default FTP service port (21).\n\
|
||||
-j XX Use account XX with the username (rarely needed).\n\
|
||||
-F Dump a sample $HOME/.ncftp/firewall prefs file to stdout and exit.\n");
|
||||
|
||||
(void) fprintf(fp, "\nProgram version: %s\nLibrary version: %s\n", gVersion + 5, gLibNcFTPVersion + 5);
|
||||
#ifdef UNAME
|
||||
AbbrevStr(s, UNAME, 60, 1);
|
||||
(void) fprintf(fp, "System: %s\n", s);
|
||||
#endif
|
||||
(void) fprintf(fp, "\nThis is a freeware program by Mike Gleason (ncftp@ncftp.com).\n");
|
||||
(void) fprintf(fp, "Use ncftpget and ncftpput for command-line FTP.\n\n");
|
||||
exit(2);
|
||||
} /* Usage */
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
DumpFirewallPrefsTemplate(void)
|
||||
{
|
||||
WriteDefaultFirewallPrefs(stdout);
|
||||
} /* DumpFirewallPrefsTemplate */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This resets our state information whenever we are ready to open a new
|
||||
* host.
|
||||
*/
|
||||
void
|
||||
InitConnectionInfo(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = FTPInitConnectionInfo(&gLib, &gConn, kDefaultFTPBufSize);
|
||||
if (result < 0) {
|
||||
(void) fprintf(stderr, "ncftp: init connection info error %d (%s).\n", result, FTPStrError(result));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gConn.debugLog = NULL;
|
||||
gConn.errLog = stderr;
|
||||
SetDebug(gDebug);
|
||||
UseTrace();
|
||||
(void) STRNCPY(gConn.user, "anonymous");
|
||||
gConn.host[0] = '\0';
|
||||
gConn.progress = gProgressMeter;
|
||||
gTransferTypeInitialized = 0;
|
||||
gTransferType = kTypeBinary;
|
||||
gConn.leavePass = 1; /* Don't let the lib zap it. */
|
||||
gConn.connTimeout = gConnTimeout;
|
||||
gConn.xferTimeout = gXferTimeout;
|
||||
gConn.ctrlTimeout = gCtrlTimeout;
|
||||
gConn.dataPortMode = gDataPortMode;
|
||||
gConn.maxDials = (-1); /* Dial forever, until they hit ^C. */
|
||||
gUnprocessedJobs = 0;
|
||||
gPrevRemoteCWD[0] = '\0';
|
||||
gConn.dataSocketRBufSize = gConn.dataSocketSBufSize = gSOBufsize;
|
||||
if (gRedialDelay >= 10)
|
||||
gConn.redialDelay = gRedialDelay;
|
||||
if ((gAutoAscii[0] == '\0') || (ISTREQ(gAutoAscii, "no")) || (ISTREQ(gAutoAscii, "off")) || (ISTREQ(gAutoAscii, "false"))) {
|
||||
gConn.asciiFilenameExtensions = NULL;
|
||||
} else {
|
||||
gConn.asciiFilenameExtensions = gAutoAscii;
|
||||
}
|
||||
} /* InitConnectionInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This lets us do things with our state information just before the
|
||||
* host is closed.
|
||||
*/
|
||||
void
|
||||
CloseHost(void)
|
||||
{
|
||||
if (gConn.connected != 0) {
|
||||
if (gConn.loggedIn != 0) {
|
||||
SaveUnsavedBookmark();
|
||||
}
|
||||
RunBatchIfNeeded(&gConn);
|
||||
}
|
||||
gConn.ctrlTimeout = 3;
|
||||
(void) FTPCloseHost(&gConn);
|
||||
} /* CloseHost */
|
||||
|
||||
|
||||
|
||||
|
||||
/* If the user specified a URL on the command-line, this initializes
|
||||
* our state information based upon it.
|
||||
*/
|
||||
static void
|
||||
SetStartupURL(const char *const urlgiven)
|
||||
{
|
||||
int rc;
|
||||
char url[256];
|
||||
char urlfile[128];
|
||||
|
||||
gLoadedBm = 0;
|
||||
(void) STRNCPY(url, urlgiven);
|
||||
|
||||
rc = DecodeDirectoryURL(&gConn, url, &gStartupURLCdList, urlfile, sizeof(urlfile));
|
||||
if (rc == kMalformedURL) {
|
||||
(void) fprintf(stderr, "Malformed URL: %s\n", url);
|
||||
exit(1);
|
||||
} else if (rc == kNotURL) {
|
||||
/* This is what should happen most of the time. */
|
||||
(void) STRNCPY(gConn.host, urlgiven);
|
||||
gURLMode = 2;
|
||||
if (GetBookmark(gConn.host, &gBm) >= 0) {
|
||||
gLoadedBm = 1;
|
||||
(void) STRNCPY(gConn.host, gBm.name);
|
||||
(void) STRNCPY(gConn.user, gBm.user);
|
||||
(void) STRNCPY(gConn.pass, gBm.pass);
|
||||
(void) STRNCPY(gConn.acct, gBm.acct);
|
||||
gConn.hasSIZE = gBm.hasSIZE;
|
||||
gConn.hasMDTM = gBm.hasMDTM;
|
||||
gConn.hasPASV = gBm.hasPASV;
|
||||
gConn.hasUTIME = gBm.hasUTIME;
|
||||
gConn.port = gBm.port;
|
||||
} else {
|
||||
SetBookmarkDefaults(&gBm);
|
||||
}
|
||||
|
||||
if (MayUseFirewall(gConn.host, gFirewallType, gFirewallExceptionList) != 0) {
|
||||
gConn.firewallType = gFirewallType;
|
||||
(void) STRNCPY(gConn.firewallHost, gFirewallHost);
|
||||
(void) STRNCPY(gConn.firewallUser, gFirewallUser);
|
||||
(void) STRNCPY(gConn.firewallPass, gFirewallPass);
|
||||
gConn.firewallPort = gFirewallPort;
|
||||
}
|
||||
} else {
|
||||
/* URL okay */
|
||||
if (urlfile[0] != '\0') {
|
||||
/* It was obviously not a directory */
|
||||
(void) fprintf(stderr, "Use ncftpget or ncftpput to handle file URLs.\n");
|
||||
exit(1);
|
||||
}
|
||||
gURLMode = 1;
|
||||
if (MayUseFirewall(gConn.host, gFirewallType, gFirewallExceptionList) != 0) {
|
||||
gConn.firewallType = gFirewallType;
|
||||
(void) STRNCPY(gConn.firewallHost, gFirewallHost);
|
||||
(void) STRNCPY(gConn.firewallUser, gFirewallUser);
|
||||
(void) STRNCPY(gConn.firewallPass, gFirewallPass);
|
||||
gConn.firewallPort = gFirewallPort;
|
||||
}
|
||||
}
|
||||
} /* SetStartupURL */
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
OpenURL(void)
|
||||
{
|
||||
LinePtr lp;
|
||||
int result;
|
||||
|
||||
if (gURLMode == 1) {
|
||||
SetBookmarkDefaults(&gBm);
|
||||
if (DoOpen() >= 0) {
|
||||
for (lp = gStartupURLCdList.first; lp != NULL; lp = lp->next) {
|
||||
result = FTPChdir(&gConn, lp->line);
|
||||
if (result != kNoErr) {
|
||||
FTPPerror(&gConn, result, kErrCWDFailed, "Could not chdir to", lp->line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = FTPGetCWD(&gConn, gRemoteCWD, sizeof(gRemoteCWD));
|
||||
if (result != kNoErr) {
|
||||
FTPPerror(&gConn, result, kErrPWDFailed, NULL, NULL);
|
||||
} else {
|
||||
(void) printf("Current remote directory is %s.\n", gRemoteCWD);
|
||||
}
|
||||
}
|
||||
} else if (gURLMode == 2) {
|
||||
(void) DoOpen();
|
||||
}
|
||||
} /* OpenURL */
|
||||
|
||||
|
||||
|
||||
|
||||
/* These things are done first, before we even parse the command-line
|
||||
* options.
|
||||
*/
|
||||
static void
|
||||
PreInit(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
|
||||
fprintf(stderr, "could not initialize winsock\n");
|
||||
exit(1);
|
||||
}
|
||||
wsaInit++;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETLOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
gIsTTY = 1;
|
||||
gIsTTYr = 1;
|
||||
#else
|
||||
gIsTTY = ((isatty(2) != 0) && (getppid() > 1)) ? 1 : 0;
|
||||
gIsTTYr = ((isatty(0) != 0) && (getppid() > 1)) ? 1 : 0;
|
||||
#endif
|
||||
#ifdef SIGPOLL
|
||||
(void) NcSignal(SIGPOLL, (FTPSigProc) SIG_IGN);
|
||||
#endif
|
||||
InitUserInfo();
|
||||
result = FTPInitLibrary(&gLib);
|
||||
if (result < 0) {
|
||||
(void) fprintf(stderr, "ncftp: init library error %d (%s).\n", result, FTPStrError(result));
|
||||
exit(1);
|
||||
}
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
srand((unsigned int) (GetTickCount() & 0x7FFF));
|
||||
#else
|
||||
srand((unsigned int) getpid());
|
||||
#endif
|
||||
InitLineList(&gStartupURLCdList);
|
||||
CheckForNewV3User();
|
||||
InitLog();
|
||||
InitPrefs();
|
||||
LoadFirewallPrefs(0);
|
||||
LoadPrefs();
|
||||
InitConnectionInfo();
|
||||
InitCommandList();
|
||||
InitLs();
|
||||
TruncBatchLog();
|
||||
GetoptReset();
|
||||
GetScreenColumns();
|
||||
} /* PreInit */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* These things are done at startup, but after we parse the command-line
|
||||
* options.
|
||||
*/
|
||||
static void
|
||||
PostInit(void)
|
||||
{
|
||||
PostInitPrefs();
|
||||
OpenTrace();
|
||||
InitTermcap();
|
||||
InitReadline();
|
||||
(void) FTPGetLocalCWD(gLocalCWD, sizeof(gLocalCWD));
|
||||
gPrevLocalCWD[0] = '\0';
|
||||
PrintStartupBanner();
|
||||
if (gNumProgramRuns <= 1)
|
||||
(void) printf("\n%s\n", gCopyright + 5);
|
||||
|
||||
Trace(0, "Fw: %s Type: %d User: %s Pass: %s Port: %u\n",
|
||||
gFirewallHost,
|
||||
gFirewallType,
|
||||
gFirewallUser,
|
||||
(gFirewallPass[0] == '\0') ? "(none)" : "********",
|
||||
gFirewallPort
|
||||
);
|
||||
Trace(0, "FwExceptions: %s\n", gFirewallExceptionList);
|
||||
if (strchr(gLib.ourHostName, '.') == NULL) {
|
||||
Trace(0, "NOTE: Your domain name could not be detected.\n");
|
||||
if (gConn.firewallType != kFirewallNotInUse) {
|
||||
Trace(0, " Make sure you manually add your domain name to firewall-exception-list.\n");
|
||||
}
|
||||
}
|
||||
} /* PostInit */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Try to get the user to evaluate my commercial offerings. */
|
||||
static void
|
||||
Plug(void)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
/* NcFTPd hasn't been ported to Windows. */
|
||||
#else
|
||||
if ((gDoNotDisplayAds == 0) && ((gNumProgramRuns % 7) == 2)) {
|
||||
(void) printf("\n\n\n\tThank you for using NcFTP Client.\n\tAsk your system administrator to try NcFTPd Server!\n\thttp://www.ncftpd.com\n\n\n\n");
|
||||
}
|
||||
#endif
|
||||
} /* Plug */
|
||||
|
||||
|
||||
|
||||
|
||||
/* These things are just before the program exits. */
|
||||
static void
|
||||
PostShell(void)
|
||||
{
|
||||
SetXtermTitle("RESTORE");
|
||||
CloseHost();
|
||||
DisposeReadline();
|
||||
CloseTrace();
|
||||
SavePrefs();
|
||||
EndLog();
|
||||
Plug();
|
||||
DisposeWinsock(0);
|
||||
} /* PostShell */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char **const argv)
|
||||
{
|
||||
int c;
|
||||
int n;
|
||||
|
||||
PreInit();
|
||||
while ((c = Getopt(argc, argv, "P:u:p:J:rd:g:FVLD")) > 0) switch(c) {
|
||||
case 'P':
|
||||
case 'u':
|
||||
case 'p':
|
||||
case 'J':
|
||||
gStartupUrlParameterGiven = 1;
|
||||
break;
|
||||
case 'r':
|
||||
case 'g':
|
||||
case 'd':
|
||||
case 'V':
|
||||
case 'L':
|
||||
case 'D':
|
||||
case 'F':
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
}
|
||||
|
||||
if (gOptInd < argc) {
|
||||
LoadFirewallPrefs(0);
|
||||
SetStartupURL(argv[gOptInd]);
|
||||
} else if (gStartupUrlParameterGiven != 0) {
|
||||
/* One of the flags they specified
|
||||
* requires a URL or hostname to
|
||||
* open.
|
||||
*/
|
||||
Usage();
|
||||
}
|
||||
|
||||
GetoptReset();
|
||||
/* Allow command-line parameters to override
|
||||
* bookmark settings.
|
||||
*/
|
||||
|
||||
while ((c = Getopt(argc, argv, "P:u:p:j:J:rd:g:FVLD")) > 0) switch(c) {
|
||||
case 'P':
|
||||
gConn.port = atoi(gOptArg);
|
||||
break;
|
||||
case 'u':
|
||||
(void) STRNCPY(gConn.user, gOptArg);
|
||||
break;
|
||||
case 'p':
|
||||
(void) STRNCPY(gConn.pass, gOptArg); /* Don't recommend doing this! */
|
||||
break;
|
||||
case 'J':
|
||||
case 'j':
|
||||
(void) STRNCPY(gConn.acct, gOptArg);
|
||||
break;
|
||||
case 'r':
|
||||
/* redial is always on */
|
||||
break;
|
||||
case 'g':
|
||||
gConn.maxDials = atoi(gOptArg);
|
||||
break;
|
||||
case 'd':
|
||||
n = atoi(gOptArg);
|
||||
if (n >= 10)
|
||||
gConn.redialDelay = n;
|
||||
break;
|
||||
case 'F':
|
||||
DumpFirewallPrefsTemplate();
|
||||
exit(0);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
case 'V':
|
||||
/*FALLTHROUGH*/
|
||||
case 'L':
|
||||
/*FALLTHROUGH*/
|
||||
case 'D':
|
||||
/* silently ignore these legacy options */
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
}
|
||||
|
||||
PostInit();
|
||||
OpenURL();
|
||||
CommandShell();
|
||||
PostShell();
|
||||
exit(0);
|
||||
} /* main */
|
|
@ -1,11 +0,0 @@
|
|||
/* main.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/* main.c */
|
||||
void InitConnectionInfo(void);
|
||||
void CloseHost(void);
|
||||
int main(int, const char **const);
|
|
@ -1,791 +0,0 @@
|
|||
/* pref.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#ifdef ncftp
|
||||
#include "progress.h"
|
||||
#endif
|
||||
|
||||
#include "pref.h"
|
||||
#include "util.h"
|
||||
|
||||
/* How many times they've run this program. */
|
||||
extern int gNumProgramRuns;
|
||||
|
||||
/* Their $PAGER. */
|
||||
char gPager[128];
|
||||
|
||||
/* These correspond to the various timeouts from LibNcFTP. */
|
||||
int gConnTimeout, gXferTimeout, gCtrlTimeout;
|
||||
|
||||
/* Active or passive FTP? (PORT or PASV?) Or both? */
|
||||
extern int gDataPortMode, gFwDataPortMode;
|
||||
|
||||
/* When the destination file already exists, resume transfer or ask user? */
|
||||
int gAutoResume;
|
||||
|
||||
/* "Save a bookmark to this site before closing?" */
|
||||
int gConfirmClose;
|
||||
|
||||
/* Should we update the bookmark for the user? */
|
||||
int gAutoSaveChangesToExistingBookmarks;
|
||||
|
||||
/* "Save your password with the bookmark?" */
|
||||
int gSavePasswords;
|
||||
|
||||
int gMaySetXtermTitle;
|
||||
|
||||
/* Number of seconds between connection attempts. */
|
||||
int gRedialDelay;
|
||||
|
||||
/* Some messages we only want to bug the user about once, ever. */
|
||||
char gOneTimeMessagesSeen[256];
|
||||
|
||||
/* Tune the size of the socket buffer using SO_RCVBUF or SO_SNDBUF? */
|
||||
int gSOBufsize;
|
||||
|
||||
/* Size of the user log before we trim it. 0 means do not log at all. */
|
||||
int gMaxLogSize;
|
||||
|
||||
/* Use ASCII mode automatically for files with these extensions. */
|
||||
char gAutoAscii[512];
|
||||
|
||||
#ifdef ncftp
|
||||
/* Which meter to use. */
|
||||
FTPProgressMeterProc gProgressMeter;
|
||||
#endif
|
||||
|
||||
/* Allow us to plug our other products? */
|
||||
int gDoNotDisplayAds;
|
||||
|
||||
/* Do we need to save the prefs, or can we skip it? */
|
||||
int gPrefsDirty = 0;
|
||||
|
||||
extern FTPLibraryInfo gLib;
|
||||
extern FTPConnectionInfo gConn;
|
||||
extern char gOurDirectoryPath[], gUser[], gVersion[];
|
||||
|
||||
PrefOpt gPrefOpts[] = {
|
||||
{ "anonopen", PREFOBSELETE },
|
||||
{ "anonpass", SetAnonPass, kPrefOptObselete },
|
||||
{ "anon-password", SetAnonPass, 1 },
|
||||
{ "auto-ascii", SetAutoAscii, 1 },
|
||||
{ "auto-resume", SetAutoResume, 1 },
|
||||
{ "autosave-bookmark-changes", SetAutoSaveChangesToExistingBookmarks, 1 },
|
||||
{ "blank-lines", PREFOBSELETE },
|
||||
{ "confirm-close", SetConfirmClose, 1 },
|
||||
{ "connect-timeout", SetConnTimeout, 1 },
|
||||
{ "control-timeout", SetCtrlTimeout, 1 },
|
||||
{ "logsize", SetLogSize, 1 },
|
||||
{ "maxbookmarks", PREFOBSELETE },
|
||||
{ "one-time-messages-seen", SetOneTimeMessages, 0 },
|
||||
{ "pager", SetPager, 1 },
|
||||
{ "passive", SetPassive, 1 },
|
||||
{ "progress-meter", SetProgressMeter, 1 },
|
||||
{ "redial-delay", SetRedialDelay, 1 },
|
||||
{ "remote-msgs", PREFOBSELETE },
|
||||
{ "restore-lcwd", PREFOBSELETE },
|
||||
{ "save-passwords", SetSavePasswords, 1 },
|
||||
{ "show-trailing-space", PREFOBSELETE },
|
||||
{ "show-status-in-xterm-titlebar", SetXtTitle, 1 },
|
||||
#ifdef SO_RCVBUF
|
||||
{ "so-bufsize", SetSOBufsize, 1 },
|
||||
#endif
|
||||
{ "startup-lcwd", PREFOBSELETE },
|
||||
{ "startup-msgs", PREFOBSELETE },
|
||||
{ "timeout", PREFOBSELETE },
|
||||
{ "total-runs", PREFOBSELETE },
|
||||
{ "total-xfer-hundredths-of-seconds", PREFOBSELETE },
|
||||
{ "total-xfer-kbytes", PREFOBSELETE },
|
||||
{ "trace", PREFOBSELETE },
|
||||
{ "utime", PREFOBSELETE },
|
||||
{ "visual", PREFOBSELETE },
|
||||
{ "xfer-timeout", SetXferTimeout, 1 },
|
||||
{ "yes-i-know-about-NcFTPd", SetNoAds, 1 },
|
||||
{ NULL, (PrefProc) 0, kPrefOptInvisible, },
|
||||
};
|
||||
|
||||
int gNumPrefOpts = ((int)(sizeof(gPrefOpts) / sizeof(PrefOpt)) - 1);
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetAnonPass(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", gLib.defaultAnonPassword);
|
||||
} else {
|
||||
(void) STRNCPY(gLib.defaultAnonPassword, val);
|
||||
}
|
||||
} /* SetAnonPass */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetAutoAscii(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", gAutoAscii);
|
||||
} else {
|
||||
(void) STRNCPY(gAutoAscii, val);
|
||||
if ((gAutoAscii[0] == '\0') || (ISTREQ(gAutoAscii, "no")) || (ISTREQ(gAutoAscii, "off")) || (ISTREQ(gAutoAscii, "false"))) {
|
||||
gConn.asciiFilenameExtensions = NULL;
|
||||
} else {
|
||||
gConn.asciiFilenameExtensions = gAutoAscii;
|
||||
}
|
||||
}
|
||||
} /* SetAutoAscii */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetAutoResume(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", YESNO(gAutoResume));
|
||||
} else {
|
||||
gAutoResume = StrToBool(val);
|
||||
}
|
||||
} /* SetAutoResume */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetAutoSaveChangesToExistingBookmarks(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", YESNO(gAutoSaveChangesToExistingBookmarks));
|
||||
} else {
|
||||
gAutoSaveChangesToExistingBookmarks = StrToBool(val);
|
||||
}
|
||||
} /* SetAutoSaveChangesToExistingBookmarks */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetConfirmClose(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", YESNO(gConfirmClose));
|
||||
} else {
|
||||
gConfirmClose = StrToBool(val);
|
||||
}
|
||||
} /* SetConfirmClose */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetConnTimeout(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gConnTimeout);
|
||||
} else {
|
||||
gConn.connTimeout = gConnTimeout = atoi(val);
|
||||
}
|
||||
} /* SetConnTimeout */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetCtrlTimeout(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gCtrlTimeout);
|
||||
} else {
|
||||
gConn.ctrlTimeout = gCtrlTimeout = atoi(val);
|
||||
}
|
||||
} /* SetCtrlTimeout */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetLogSize(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gMaxLogSize);
|
||||
} else {
|
||||
gMaxLogSize = atoi(val);
|
||||
}
|
||||
} /* SetLogSize */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetNoAds(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", YESNO(gDoNotDisplayAds));
|
||||
} else {
|
||||
gDoNotDisplayAds = StrToBool(val);
|
||||
}
|
||||
} /* SetNoAds */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetOneTimeMessages(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", gOneTimeMessagesSeen);
|
||||
} else {
|
||||
(void) STRNCPY(gOneTimeMessagesSeen, val);
|
||||
}
|
||||
} /* SetOneTimeMessages */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetPager(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", gPager);
|
||||
} else {
|
||||
(void) STRNCPY(gPager, val);
|
||||
}
|
||||
} /* SetPager */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetPassive(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
int m;
|
||||
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
m = (gFwDataPortMode >= 0) ? gFwDataPortMode : gDataPortMode;
|
||||
if (m == kSendPortMode) {
|
||||
(void) fprintf(fp, "%s", "off");
|
||||
} else if (m == kPassiveMode) {
|
||||
(void) fprintf(fp, "%s", "on");
|
||||
} else {
|
||||
(void) fprintf(fp, "%s", "optional");
|
||||
}
|
||||
} else {
|
||||
if (gFwDataPortMode >= 0) {
|
||||
gDataPortMode = gFwDataPortMode;
|
||||
return;
|
||||
}
|
||||
if (ISTRNEQ(val, "opt", 3))
|
||||
gDataPortMode = kFallBackToSendPortMode;
|
||||
else if (ISTREQ(val, "on"))
|
||||
gDataPortMode = kPassiveMode;
|
||||
else if ((int) isdigit(val[0]))
|
||||
gDataPortMode = atoi(val);
|
||||
else
|
||||
gDataPortMode = kSendPortMode;
|
||||
gConn.dataPortMode = gDataPortMode;
|
||||
}
|
||||
} /* SetPassive */
|
||||
|
||||
|
||||
|
||||
#ifdef ncftp
|
||||
void
|
||||
SetProgressMeter(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
if (gProgressMeter == PrStatBar) {
|
||||
(void) fprintf(fp, "%s", "2 (statbar)");
|
||||
} else if (gProgressMeter == PrPhilBar) {
|
||||
(void) fprintf(fp, "%s", "1 (philbar)");
|
||||
} else {
|
||||
(void) fprintf(fp, "%s", "0 (simple)");
|
||||
}
|
||||
} else {
|
||||
if ((val[0] == '0') || (ISTRNEQ(val, "simple", 6)))
|
||||
gProgressMeter = PrSizeAndRateMeter;
|
||||
else if ((val[0] == '1') || (ISTRNEQ(val, "phil", 4)))
|
||||
gProgressMeter = PrPhilBar;
|
||||
else
|
||||
gProgressMeter = PrStatBar;
|
||||
gConn.progress = gProgressMeter;
|
||||
}
|
||||
} /* SetProgressMeter */
|
||||
#else
|
||||
void
|
||||
SetProgressMeter(int UNUSED(t), const char *const UNUSED(val), FILE *const UNUSED(fp))
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
LIBNCFTP_USE_VAR(val);
|
||||
LIBNCFTP_USE_VAR(fp);
|
||||
} /* SetProgressMeter */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetRedialDelay(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
int i;
|
||||
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gRedialDelay);
|
||||
} else {
|
||||
i = atoi(val);
|
||||
if (i < 10)
|
||||
i = 10;
|
||||
gRedialDelay = atoi(val);
|
||||
}
|
||||
} /* SetRedialDelay */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetSavePasswords(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
if (gSavePasswords < 0)
|
||||
(void) fprintf(fp, "%s", "ask");
|
||||
else
|
||||
(void) fprintf(fp, "%s", YESNO(gSavePasswords));
|
||||
} else {
|
||||
if (ISTREQ(val, "ask"))
|
||||
gSavePasswords = -1;
|
||||
else
|
||||
gSavePasswords = StrToBool(val);
|
||||
}
|
||||
} /* SetSavePasswords */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetSOBufsize(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gSOBufsize);
|
||||
if (gSOBufsize <= 0)
|
||||
(void) fprintf(fp, "%s", " (use system default)");
|
||||
} else {
|
||||
gConn.dataSocketRBufSize = gConn.dataSocketSBufSize = gSOBufsize = atoi(val);
|
||||
}
|
||||
} /* SetSOBufsize */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetXferTimeout(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%d", gXferTimeout);
|
||||
} else {
|
||||
gConn.xferTimeout = gXferTimeout = atoi(val);
|
||||
}
|
||||
} /* SetXferTimeout */
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetXtTitle(int UNUSED(t), const char *const val, FILE *const fp)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(t);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "%s", YESNO(gMaySetXtermTitle));
|
||||
} else {
|
||||
gMaySetXtermTitle = StrToBool(val);
|
||||
}
|
||||
} /* SetXtTitle */
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
Show1(int t)
|
||||
{
|
||||
PrefOpt *p = &gPrefOpts[t];
|
||||
|
||||
(void) printf("%-30s ", p->varname);
|
||||
if (p->proc != (PrefProc) 0)
|
||||
(*p->proc)(t, NULL, stdout);
|
||||
(void) printf("\n");
|
||||
} /* Show1 */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Modify or display the program's configuration. */
|
||||
void
|
||||
Set(const char *const tok1, const char *const tok2)
|
||||
{
|
||||
int t;
|
||||
|
||||
if ((tok1 == NULL) || (ISTREQ(tok1, "all"))) {
|
||||
/* Show all. */
|
||||
for (t=0; t<gNumPrefOpts; t++) {
|
||||
if (gPrefOpts[t].visible == kPrefOptVisible)
|
||||
Show1(t);
|
||||
}
|
||||
} else if (tok2 == NULL) {
|
||||
/* Show one. */
|
||||
for (t=0; t<gNumPrefOpts; t++) {
|
||||
if (ISTREQ(tok1, gPrefOpts[t].varname)) {
|
||||
if (gPrefOpts[t].visible == kPrefOptObselete) {
|
||||
(void) printf("The \"%s\" option is obselete or not implemented.\n", tok1);
|
||||
} else {
|
||||
Show1(t);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= gNumPrefOpts) {
|
||||
(void) printf("Unknown option \"%s\" -- try \"show all\" to list available options.\n", tok1);
|
||||
}
|
||||
} else {
|
||||
/* Set one. */
|
||||
for (t=0; t<gNumPrefOpts; t++) {
|
||||
if (ISTREQ(tok1, gPrefOpts[t].varname)) {
|
||||
if (gPrefOpts[t].visible == kPrefOptObselete) {
|
||||
(void) printf("The \"%s\" option is obselete or not implemented.\n", tok1);
|
||||
} else if (gPrefOpts[t].proc != (PrefProc) 0) {
|
||||
(*gPrefOpts[t].proc)(t, tok2, NULL);
|
||||
gPrefsDirty++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= gNumPrefOpts) {
|
||||
(void) printf("Unknown option \"%s\" -- try \"show all\" to list available options.\n", tok1);
|
||||
}
|
||||
}
|
||||
} /* Set */
|
||||
|
||||
|
||||
|
||||
int
|
||||
HasSeenOneTimeMessage(const char *const msg)
|
||||
{
|
||||
char buf[256];
|
||||
char *a, *b;
|
||||
|
||||
memcpy(buf, gOneTimeMessagesSeen, sizeof(buf));
|
||||
for (a = buf; (b = strtok(a, ",\n")) != NULL; a = NULL) {
|
||||
if (strcmp(msg, b) == 0)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
} /* HasSeenOneTimeMessage */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetSeenOneTimeMessage(const char *const msg)
|
||||
{
|
||||
gPrefsDirty++;
|
||||
if (gOneTimeMessagesSeen[0] == '\0')
|
||||
STRNCPY(gOneTimeMessagesSeen, msg);
|
||||
else {
|
||||
STRNCAT(gOneTimeMessagesSeen, ",");
|
||||
STRNCAT(gOneTimeMessagesSeen, msg);
|
||||
}
|
||||
} /* SetSeenOneTimeMessage */
|
||||
|
||||
|
||||
|
||||
int
|
||||
OneTimeMessage(const char *const msg)
|
||||
{
|
||||
if (HasSeenOneTimeMessage(msg))
|
||||
return (0);
|
||||
SetSeenOneTimeMessage(msg);
|
||||
return (1);
|
||||
} /* OneTimeMessage */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
ProcessPrefsFile(FILE *const fp)
|
||||
{
|
||||
char line[1024];
|
||||
char *tok1, *tok2;
|
||||
int t;
|
||||
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
while (fgets(line, sizeof(line) - 1, fp) != NULL) {
|
||||
tok1 = strtok(line, " =\t\r\n");
|
||||
if ((tok1 == NULL) || (tok1[0] == '#'))
|
||||
continue;
|
||||
tok2 = strtok(NULL, "\r\n");
|
||||
if (tok2 == NULL)
|
||||
continue;
|
||||
|
||||
for (t=0; t<gNumPrefOpts; t++) {
|
||||
if (ISTREQ(tok1, gPrefOpts[t].varname)) {
|
||||
if (gPrefOpts[t].visible == kPrefOptObselete) {
|
||||
/* Probably converting an
|
||||
* old 2.4.2 file.
|
||||
*/
|
||||
gPrefsDirty++;
|
||||
} else if (gPrefOpts[t].proc != (PrefProc) 0) {
|
||||
(*gPrefOpts[t].proc)(t, tok2, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* ProcessPrefsFile */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Read the saved configuration settings from a preferences file. */
|
||||
void
|
||||
LoadPrefs(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char pathName[256];
|
||||
|
||||
/* As with the firewall preference file, there can be
|
||||
* site-wide preferences and user-specific preferences.
|
||||
* The user pref file is of course kept in the user's
|
||||
* NcFTP home directory.
|
||||
*
|
||||
* The way we do this is we first look for a global
|
||||
* preferences file. We then process the user's pref
|
||||
* file, which could override the global prefs. Finally,
|
||||
* we open a "global fixed" prefs file which then
|
||||
* overrides anything the user may have done.
|
||||
*/
|
||||
|
||||
fp = fopen(kGlobalPrefFileName, FOPEN_READ_TEXT);
|
||||
if (fp != NULL) {
|
||||
/* Opened the global (but user-overridable) prefs file. */
|
||||
ProcessPrefsFile(fp);
|
||||
(void) fclose(fp);
|
||||
}
|
||||
|
||||
if (gOurDirectoryPath[0] != '\0') {
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kPrefFileName);
|
||||
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp == NULL) {
|
||||
/* Try loading the version 2 prefs.
|
||||
* There will be options we no longer recognize, but
|
||||
* we'd like to import the prefs when possible.
|
||||
*/
|
||||
gPrefsDirty++;
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kPrefFileNameV2);
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
}
|
||||
|
||||
if (fp == NULL) {
|
||||
/* Write a new one when we're done. */
|
||||
gPrefsDirty++;
|
||||
} else {
|
||||
/* Opened the preferences file. */
|
||||
ProcessPrefsFile(fp);
|
||||
(void) fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
fp = fopen(kGlobalFixedPrefFileName, FOPEN_READ_TEXT);
|
||||
if (fp != NULL) {
|
||||
/* Opened the global (and not overridable) prefs file. */
|
||||
ProcessPrefsFile(fp);
|
||||
(void) fclose(fp);
|
||||
}
|
||||
} /* LoadPrefs */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Initialize the configuration settings, in case the user does not set them. */
|
||||
void
|
||||
InitPrefs(void)
|
||||
{
|
||||
char *tok1;
|
||||
|
||||
/* Set default values. */
|
||||
gPager[0] = '\0';
|
||||
memset(gOneTimeMessagesSeen, 0, sizeof(gOneTimeMessagesSeen));
|
||||
gXferTimeout = 3600;
|
||||
gConnTimeout = 20;
|
||||
gCtrlTimeout = 135;
|
||||
gDataPortMode = kFallBackToSendPortMode;
|
||||
gConn.dataPortMode = gDataPortMode;
|
||||
gAutoResume = 0;
|
||||
gSOBufsize = 0;
|
||||
gMaxLogSize = 10240;
|
||||
gConfirmClose = 1;
|
||||
gAutoSaveChangesToExistingBookmarks = 0;
|
||||
gRedialDelay = kDefaultRedialDelay;
|
||||
STRNCPY(gAutoAscii, "|.txt|.asc|.html|.htm|.css|.xml|.ini|.sh|.pl|.hqx|.cfg|.c|.h|.cpp|.hpp|.bat|.m3u|.pls|");
|
||||
|
||||
/* PLEASE do not change the default from 0, and please
|
||||
* don't hack out the portion in main.c which displays
|
||||
* a plug every 7th time you run the program. This is
|
||||
* not much to ask for all the work I've put into this
|
||||
* since 1991.
|
||||
*/
|
||||
gDoNotDisplayAds = 0;
|
||||
|
||||
#if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
|
||||
gMaySetXtermTitle = 1;
|
||||
#else
|
||||
gMaySetXtermTitle = 0;
|
||||
#endif
|
||||
|
||||
gSavePasswords = -1;
|
||||
#ifdef ncftp
|
||||
gProgressMeter = PrStatBar;
|
||||
#endif
|
||||
|
||||
tok1 = getenv("PAGER");
|
||||
if ((tok1 != NULL) && (tok1[0] != '\0')) {
|
||||
#ifdef HAVE_STRSTR
|
||||
/* I prefer "less", but it doesn't work well here
|
||||
* because it clears the screen after it finishes,
|
||||
* and the default at EOF is to stay in less
|
||||
* instead of exiting.
|
||||
*/
|
||||
if (strstr(gPager, "less") != NULL)
|
||||
(void) STRNCPY(gPager, "more");
|
||||
else
|
||||
(void) STRNCPY(gPager, tok1);
|
||||
#else
|
||||
(void) STRNCPY(gPager, tok1);
|
||||
#endif
|
||||
} else {
|
||||
(void) STRNCPY(gPager, "more");
|
||||
}
|
||||
} /* InitPrefs */
|
||||
|
||||
|
||||
|
||||
|
||||
/* After reading the preferences, do some additional initialization. */
|
||||
void
|
||||
PostInitPrefs(void)
|
||||
{
|
||||
if (gLib.defaultAnonPassword[0] == '\0') {
|
||||
FTPInitializeAnonPassword(&gLib);
|
||||
gPrefsDirty++;
|
||||
}
|
||||
if (gFwDataPortMode >= 0)
|
||||
gConn.dataPortMode = gFwDataPortMode;
|
||||
} /* PostInitPrefs */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Write the configuration settings to a preferences file. */
|
||||
void
|
||||
SavePrefs(void)
|
||||
{
|
||||
char pathName[256];
|
||||
char pathName2[256];
|
||||
char tName[32];
|
||||
int t;
|
||||
FILE *fp;
|
||||
|
||||
if (gPrefsDirty == 0)
|
||||
return; /* Don't need to save -- no changes made. */
|
||||
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kPrefFileName);
|
||||
|
||||
(void) sprintf(tName, "tpref%06u.txt", (unsigned int) getpid());
|
||||
(void) OurDirectoryPath(pathName2, sizeof(pathName2), tName);
|
||||
|
||||
fp = fopen(pathName2, FOPEN_WRITE_TEXT);
|
||||
if (fp == NULL) {
|
||||
perror("could not save preferences file");
|
||||
} else {
|
||||
(void) fprintf(fp, "%s", "# NcFTP 3 preferences file\n# This file is loaded and overwritten each time NcFTP is run.\n#\n");
|
||||
for (t=0; t<gNumPrefOpts; t++) {
|
||||
if (gPrefOpts[t].visible != kPrefOptObselete) {
|
||||
(void) fprintf(fp, "%s=", gPrefOpts[t].varname);
|
||||
(*gPrefOpts[t].proc)(t, NULL, fp);
|
||||
(void) fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
(void) fclose(fp);
|
||||
(void) unlink(pathName);
|
||||
if (rename(pathName2, pathName) < 0) {
|
||||
perror("could not finish saving preferences file");
|
||||
(void) unlink(pathName2);
|
||||
};
|
||||
}
|
||||
} /* SavePrefs */
|
||||
|
||||
|
||||
|
||||
/* This maintains the little counter file that is used by version 3.0
|
||||
* to do things based on how many times the program was run.
|
||||
*/
|
||||
void
|
||||
CheckForNewV3User(void)
|
||||
{
|
||||
FILE *fp;
|
||||
struct stat st;
|
||||
char pathName[256];
|
||||
char line[256];
|
||||
|
||||
gNumProgramRuns = 0;
|
||||
|
||||
/* Don't create in root directory. */
|
||||
if (gOurDirectoryPath[0] != '\0') {
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kFirstFileName);
|
||||
|
||||
if ((stat(pathName, &st) < 0) && (errno == ENOENT)) {
|
||||
gNumProgramRuns = 1;
|
||||
gPrefsDirty++;
|
||||
|
||||
/* Create a blank one. */
|
||||
fp = fopen(pathName, FOPEN_WRITE_TEXT);
|
||||
if (fp == NULL)
|
||||
return;
|
||||
(void) fprintf(fp, "# NcFTP uses this file to mark that you have run it before, and that you do not\n# need any special first-time instructions or setup.\n#\nruns=%d\n", gNumProgramRuns);
|
||||
(void) fclose(fp);
|
||||
} else {
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp != NULL) {
|
||||
while (fgets(line, sizeof(line) - 1, fp) != NULL) {
|
||||
if (strncmp(line, "runs=", 5) == 0) {
|
||||
(void) sscanf(line + 5, "%d",
|
||||
&gNumProgramRuns);
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void) fclose(fp);
|
||||
}
|
||||
|
||||
/* Increment the count of program runs. */
|
||||
gNumProgramRuns++;
|
||||
if (gNumProgramRuns == 1)
|
||||
gPrefsDirty++;
|
||||
|
||||
/* Race condition between other ncftp processes.
|
||||
* This isn't a big deal because this counter isn't
|
||||
* critical.
|
||||
*/
|
||||
|
||||
fp = fopen(pathName, FOPEN_WRITE_TEXT);
|
||||
if (fp != NULL) {
|
||||
(void) fprintf(fp, "# NcFTP uses this file to mark that you have run it before, and that you do not\n# need any special first-time instructions or setup.\n#\nruns=%d\n", gNumProgramRuns);
|
||||
(void) fclose(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* CheckForNewV3User */
|
|
@ -1,74 +0,0 @@
|
|||
/* pref.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kFirewallPrefFileName "firewall.txt"
|
||||
# define kGlobalFirewallPrefFileName "..\\..\\firewall.txt"
|
||||
# define kGlobalFixedFirewallPrefFileName "..\\..\\firewall_fixed.txt"
|
||||
# define kGlobalPrefFileName "..\\..\\prefs_v3.txt"
|
||||
# define kGlobalFixedPrefFileName "..\\..\\prefs_v3_fixed.txt"
|
||||
# define kPrefFileName "prefs_v3.txt"
|
||||
# define kPrefFileNameV2 "prefs"
|
||||
# define kFirstFileName "init_v3.txt"
|
||||
#else
|
||||
# define kFirewallPrefFileName "firewall"
|
||||
# define kGlobalFirewallPrefFileName "/etc/ncftp.firewall"
|
||||
# define kGlobalFixedFirewallPrefFileName "/etc/ncftp.firewall.fixed"
|
||||
# define kGlobalPrefFileName "/etc/ncftp.prefs_v3"
|
||||
# define kGlobalFixedPrefFileName "/etc/ncftp.prefs_v3.fixed"
|
||||
# define kPrefFileName "prefs_v3"
|
||||
# define kPrefFileNameV2 "prefs"
|
||||
# define kFirstFileName "init_v3"
|
||||
#endif
|
||||
|
||||
#define kOpenSelectedBookmarkFileName "bm2open"
|
||||
|
||||
typedef void (*PrefProc)(int i, const char *const, FILE *const fp);
|
||||
typedef struct PrefOpt {
|
||||
const char *varname;
|
||||
PrefProc proc;
|
||||
int visible;
|
||||
} PrefOpt;
|
||||
|
||||
#define kPrefOptObselete (-1)
|
||||
#define kPrefOptInvisible 0
|
||||
#define kPrefOptVisible 1
|
||||
|
||||
#define PREFOBSELETE (PrefProc) 0, kPrefOptObselete,
|
||||
|
||||
/* pref.c */
|
||||
void SetAnonPass(int, const char *const, FILE *const);
|
||||
void SetAutoAscii(int t, const char *const val, FILE *const fp);
|
||||
void SetAutoResume(int, const char *const, FILE *const);
|
||||
void SetAutoSaveChangesToExistingBookmarks(int t, const char *const val, FILE *const fp);
|
||||
void SetConfirmClose(int, const char *const, FILE *const);
|
||||
void SetConnTimeout(int, const char *const, FILE *const);
|
||||
void SetCtrlTimeout(int, const char *const, FILE *const);
|
||||
void SetLogSize(int t, const char *const val, FILE *const fp);
|
||||
void SetNoAds(int t, const char *const val, FILE *const fp);
|
||||
void SetOneTimeMessages(int t, const char *const val, FILE *const);
|
||||
void SetPager(int, const char *const, FILE *const);
|
||||
void SetPassive(int, const char *const, FILE *const);
|
||||
void SetProgressMeter(int, const char *const, FILE *const);
|
||||
void SetRedialDelay(int t, const char *const val, FILE *const fp);
|
||||
void SetSavePasswords(int, const char *const, FILE *const);
|
||||
void SetSOBufsize(int t, const char *const val, FILE *const fp);
|
||||
void SetXferTimeout(int, const char *const, FILE *const);
|
||||
void SetXtTitle(int, const char *const, FILE *const);
|
||||
void Set(const char *const, const char *const);
|
||||
void ProcessPrefsFile(FILE *const fp);
|
||||
void LoadPrefs(void);
|
||||
void InitPrefs(void);
|
||||
void PostInitPrefs(void);
|
||||
void SavePrefs(void);
|
||||
void WriteDefaultFirewallPrefs(FILE *);
|
||||
void ProcessFirewallPrefFile(FILE *);
|
||||
void LoadFirewallPrefs(int);
|
||||
void CheckForNewV3User(void);
|
||||
int HasSeenOneTimeMessage(const char *const msg);
|
||||
void SetSeenOneTimeMessage(const char *const msg);
|
||||
int OneTimeMessage(const char *const msg);
|
|
@ -1,338 +0,0 @@
|
|||
/* preffw.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "pref.h"
|
||||
#include "util.h"
|
||||
|
||||
/* How many times they've run this program. */
|
||||
int gNumProgramRuns = 0;
|
||||
|
||||
/* Firewall/proxy configuration parameters. */
|
||||
int gFirewallType;
|
||||
char gFirewallHost[64];
|
||||
char gFirewallUser[32];
|
||||
char gFirewallPass[32];
|
||||
char gFirewallExceptionList[256];
|
||||
unsigned int gFirewallPort;
|
||||
int gFirewallPrefsLoaded = 0;
|
||||
|
||||
/* Active or passive FTP? (PORT or PASV?) Or both? */
|
||||
int gDataPortMode;
|
||||
|
||||
/* Hack so the user/admin can set passive in the firewall
|
||||
* prefs file.
|
||||
*/
|
||||
int gFwDataPortMode = -1;
|
||||
|
||||
extern FTPLibraryInfo gLib;
|
||||
extern char gOurDirectoryPath[], gUser[], gVersion[];
|
||||
|
||||
|
||||
/* Save a sample configuration file for the firewall/proxy setup. */
|
||||
void
|
||||
WriteDefaultFirewallPrefs(FILE *fp)
|
||||
{
|
||||
char *cp;
|
||||
time_t now;
|
||||
|
||||
FTPInitializeOurHostName(&gLib);
|
||||
cp = strchr(gLib.ourHostName, '.');
|
||||
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# NcFTP firewall preferences\n\
|
||||
# ==========================\n\
|
||||
#\n\
|
||||
");
|
||||
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# If you need to use a proxy for FTP, you can configure it below.\n\
|
||||
# If you do not need one, leave the ``firewall-type'' variable set\n\
|
||||
# to 0. Any line that does not begin with the ``#'' character is\n\
|
||||
# considered a configuration command line.\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
# NOTE: NcFTP does NOT support HTTP proxies that do FTP, such as \"squid\"\n\
|
||||
# or Netscape Proxy Server. Why? Because you have to communicate with\n\
|
||||
# them using HTTP, and this is a FTP only program.\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
# Types of firewalls:\n\
|
||||
# ------------------\n\
|
||||
#\n\
|
||||
# type 1: Connect to firewall host, but send \"USER user@real.host.name\"\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# type 2: Connect to firewall, login with \"USER fwuser\" and\n\
|
||||
# \"PASS fwpassword\", and then \"USER user@real.host.name\"\n\
|
||||
#\n\
|
||||
# type 3: Connect to and login to firewall, and then use\n\
|
||||
# \"SITE real.host.name\", followed by the regular USER and PASS.\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# type 4: Connect to and login to firewall, and then use\n\
|
||||
# \"OPEN real.host.name\", followed by the regular USER and PASS.\n\
|
||||
#\n\
|
||||
# type 5: Connect to firewall host, but send\n\
|
||||
# \"USER user@fwuser@real.host.name\" and\n\
|
||||
# \"PASS pass@fwpass\" to login.\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# type 6: Connect to firewall host, but send\n\
|
||||
# \"USER fwuser@real.host.name\" and\n\
|
||||
# \"PASS fwpass\" followed by a regular\n\
|
||||
# \"USER user\" and\n\
|
||||
# \"PASS pass\" to complete the login.\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# type 7: Connect to firewall host, but send\n\
|
||||
# \"USER user@real.host.name fwuser\" and\n\
|
||||
# \"PASS pass\" followed by\n\
|
||||
# \"ACCT fwpass\" to complete the login.\n\
|
||||
#\n\
|
||||
# type 0: Do NOT use a firewall (most users will choose this).\n\
|
||||
#\n\
|
||||
firewall-type=0\n\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# The ``firewall-host'' variable should be the IP address or hostname of\n\
|
||||
# your firewall server machine.\n\
|
||||
#\n\
|
||||
");
|
||||
|
||||
if (cp == NULL) {
|
||||
(void) fprintf(fp, "firewall-host=firewall.domain.com\n");
|
||||
} else {
|
||||
(void) fprintf(fp, "firewall-host=firewall%s\n", cp);
|
||||
}
|
||||
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# The ``firewall-user'' variable tells NcFTP what to use as the user ID\n\
|
||||
# when it logs in to the firewall before connecting to the outside world.\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "firewall-user=%s\n", gUser);
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# The ``firewall-password'' variable is the password associated with\n\
|
||||
# the firewall-user ID. If you set this here, be sure to change the\n\
|
||||
# permissions on this file so that no one (except the superuser) can\n\
|
||||
# see your password. You may also leave this commented out, and then\n\
|
||||
# NcFTP will prompt you each time for the password.\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
firewall-password=fwpass\n\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# Your firewall may require you to connect to a non-standard port for\n\
|
||||
# outside FTP services, instead of the internet standard port number (21).\n\
|
||||
#\n\
|
||||
firewall-port=21\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# You probably do not want to FTP to the firewall for hosts on your own\n\
|
||||
# domain. You can set ``firewall-exception-list'' to a list of domains\n\
|
||||
# or hosts where the firewall should not be used. For example, if your\n\
|
||||
# domain was ``probe.net'' you could set this to ``.probe.net''.\n\
|
||||
#\n\
|
||||
");
|
||||
(void) fprintf(fp, "%s", "\
|
||||
# If you leave this commented out, the default behavior is to attempt to\n\
|
||||
# lookup the current domain, and exclude hosts for it. Otherwise, set it\n\
|
||||
# to a list of comma-delimited domains or hostnames. The special token\n\
|
||||
# ``localdomain'' is used for unqualified hostnames, so if you want hosts\n\
|
||||
# without explicit domain names to avoid the firewall, be sure to include\n\
|
||||
# that in your list.\n\
|
||||
#\n\
|
||||
");
|
||||
|
||||
if (cp != NULL) {
|
||||
(void) fprintf(fp, "firewall-exception-list=%s,localhost,localdomain\n", cp);
|
||||
} else {
|
||||
(void) fprintf(fp, "firewall-exception-list=.probe.net,localhost,foo.bar.com,localdomain\n");
|
||||
}
|
||||
|
||||
(void) fprintf(fp, "%s", "\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# You may also specify passive mode here. Normally this is set in the\n\
|
||||
# regular $HOME/.ncftp/prefs file. This must be set to one of\n\
|
||||
# \"on\", \"off\", or \"optional\", which mean always use PASV,\n\
|
||||
# always use PORT, and try PASV then PORT, respectively.\n\
|
||||
#\n\
|
||||
#passive=on\n");
|
||||
|
||||
time(&now);
|
||||
(void) fprintf(fp, "\
|
||||
#\n\
|
||||
#\n\
|
||||
#\n\
|
||||
# NOTE: This file was created for you on %s\
|
||||
# by NcFTP %.5s. Removing this file will cause the next run of NcFTP\n\
|
||||
# to generate a new one, possibly with more configurable options.\n",
|
||||
ctime(&now),
|
||||
gVersion + 11);
|
||||
(void) fprintf(fp, "\
|
||||
#\n\
|
||||
# ALSO: A %s file, if present, is processed before this file,\n\
|
||||
# and a %s file, if present, is processed after.\n",
|
||||
kGlobalFirewallPrefFileName,
|
||||
kGlobalFixedFirewallPrefFileName
|
||||
);
|
||||
} /* CreateDefaultFirewallPrefs */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
ProcessFirewallPrefFile(FILE *fp)
|
||||
{
|
||||
char line[256];
|
||||
char *tok1, *tok2;
|
||||
int n;
|
||||
|
||||
/* Opened the firewall preferences file. */
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
while (fgets(line, sizeof(line) - 1, fp) != NULL) {
|
||||
tok1 = strtok(line, " =\t\r\n");
|
||||
if ((tok1 == NULL) || (tok1[0] == '#'))
|
||||
continue;
|
||||
tok2 = strtok(NULL, "\r\n");
|
||||
if (tok2 == NULL)
|
||||
continue;
|
||||
if (ISTREQ(tok1, "firewall-type")) {
|
||||
n = atoi(tok2);
|
||||
if ((n > 0) && (n <= kFirewallLastType))
|
||||
gFirewallType = n;
|
||||
} else if (ISTREQ(tok1, "firewall-host")) {
|
||||
(void) STRNCPY(gFirewallHost, tok2);
|
||||
} else if (ISTREQ(tok1, "firewall-port")) {
|
||||
n = atoi(tok2);
|
||||
if (n > 0)
|
||||
gFirewallPort = (unsigned int) n;
|
||||
} else if (ISTREQ(tok1, "firewall-user")) {
|
||||
(void) STRNCPY(gFirewallUser, tok2);
|
||||
} else if (ISTREQ(tok1, "firewall-pass")) {
|
||||
(void) STRNCPY(gFirewallPass, tok2);
|
||||
} else if (ISTREQ(tok1, "firewall-password")) {
|
||||
(void) STRNCPY(gFirewallPass, tok2);
|
||||
} else if (ISTREQ(tok1, "firewall-exception-list")) {
|
||||
(void) STRNCPY(gFirewallExceptionList, tok2);
|
||||
} else if (ISTREQ(tok1, "passive")) {
|
||||
if (ISTREQ(tok2, "optional")) {
|
||||
gDataPortMode = gFwDataPortMode = kFallBackToSendPortMode;
|
||||
} else if (ISTREQ(tok2, "on")) {
|
||||
gDataPortMode = gFwDataPortMode = kPassiveMode;
|
||||
} else if (ISTREQ(tok2, "off")) {
|
||||
gDataPortMode = gFwDataPortMode = kSendPortMode;
|
||||
} else if ((int) isdigit(tok2[0])) {
|
||||
gDataPortMode = gFwDataPortMode = atoi(tok2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* ProcessFirewallPrefFile */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Load those options specific to the firewall/proxy settings. These are
|
||||
* kept in a different file so that other programs can read it and not
|
||||
* have to worry about the other junk in the prefs file.
|
||||
*/
|
||||
void
|
||||
LoadFirewallPrefs(int forceReload)
|
||||
{
|
||||
FILE *fp, *fp2;
|
||||
char pathName[256];
|
||||
char *cp;
|
||||
int userFile = 0;
|
||||
int sysFile = 0;
|
||||
|
||||
if ((gFirewallPrefsLoaded != 0) && (forceReload == 0))
|
||||
return;
|
||||
gFirewallPrefsLoaded = 1;
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return; /* Don't create in root directory. */
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kFirewallPrefFileName);
|
||||
|
||||
/* Set default values. */
|
||||
gFirewallType = kFirewallNotInUse;
|
||||
gFirewallPort = 0;
|
||||
gFirewallHost[0] = '\0';
|
||||
gFirewallUser[0] = '\0';
|
||||
gFirewallPass[0] = '\0';
|
||||
gFirewallExceptionList[0] = '\0';
|
||||
|
||||
fp2 = fopen(kGlobalFirewallPrefFileName, FOPEN_READ_TEXT);
|
||||
if (fp2 != NULL) {
|
||||
/* Initialize to system-wide defaults. */
|
||||
ProcessFirewallPrefFile(fp2);
|
||||
(void) fclose(fp2);
|
||||
sysFile++;
|
||||
}
|
||||
|
||||
fp = fopen(pathName, FOPEN_READ_TEXT);
|
||||
if (fp != NULL) {
|
||||
/* Do user's firewall file. */
|
||||
ProcessFirewallPrefFile(fp);
|
||||
(void) fclose(fp);
|
||||
userFile = 1;
|
||||
}
|
||||
|
||||
fp2 = fopen(kGlobalFixedFirewallPrefFileName, FOPEN_READ_TEXT);
|
||||
if (fp2 != NULL) {
|
||||
/* Override with system-wide settings. */
|
||||
ProcessFirewallPrefFile(fp2);
|
||||
(void) fclose(fp2);
|
||||
sysFile++;
|
||||
}
|
||||
|
||||
if ((userFile == 0) && (sysFile == 0)) {
|
||||
/* Create a blank one, if
|
||||
* there were no system-wide files.
|
||||
*/
|
||||
fp = fopen(pathName, FOPEN_WRITE_TEXT);
|
||||
if (fp != NULL) {
|
||||
WriteDefaultFirewallPrefs(fp);
|
||||
(void) fclose(fp);
|
||||
(void) chmod(pathName, 00600);
|
||||
gNumProgramRuns = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (gFirewallExceptionList[0] == '\0') {
|
||||
FTPInitializeOurHostName(&gLib);
|
||||
cp = strchr(gLib.ourHostName, '.');
|
||||
|
||||
if (cp != NULL) {
|
||||
(void) STRNCPY(gFirewallExceptionList, cp);
|
||||
(void) STRNCAT(gFirewallExceptionList, ",localdomain");
|
||||
}
|
||||
}
|
||||
} /* LoadFirewallPrefs */
|
|
@ -1,498 +0,0 @@
|
|||
/* progress.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "trace.h"
|
||||
#include "progress.h"
|
||||
#include "readln.h"
|
||||
|
||||
#ifdef ncftp
|
||||
# include "log.h"
|
||||
# include "pref.h"
|
||||
#endif /* ncftp */
|
||||
|
||||
extern const char *tcap_normal;
|
||||
extern const char *tcap_boldface;
|
||||
extern const char *tcap_underline;
|
||||
extern const char *tcap_reverse;
|
||||
extern int gScreenColumns;
|
||||
|
||||
#ifdef ncftp
|
||||
extern char gRemoteCWD[];
|
||||
#endif /* ncftp */
|
||||
|
||||
|
||||
double
|
||||
FileSize(const double size, const char **uStr0, double *const uMult0)
|
||||
{
|
||||
double uMult, uTotal;
|
||||
const char *uStr;
|
||||
|
||||
/* The comparisons below may look odd, but the reason
|
||||
* for them is that we only want a maximum of 3 digits
|
||||
* before the decimal point. (I.e., we don't want to
|
||||
* see "1017.2 kB", instead we want "0.99 MB".
|
||||
*/
|
||||
if (size > (999.5 * kGigabyte)) {
|
||||
uStr = "TB";
|
||||
uMult = kTerabyte;
|
||||
} else if (size > (999.5 * kMegabyte)) {
|
||||
uStr = "GB";
|
||||
uMult = kGigabyte;
|
||||
} else if (size > (999.5 * kKilobyte)) {
|
||||
uStr = "MB";
|
||||
uMult = kMegabyte;
|
||||
} else if (size > 999.5) {
|
||||
uStr = "kB";
|
||||
uMult = 1024;
|
||||
} else {
|
||||
uStr = "B";
|
||||
uMult = 1;
|
||||
}
|
||||
if (uStr0 != NULL)
|
||||
*uStr0 = uStr;
|
||||
if (uMult0 != NULL)
|
||||
*uMult0 = uMult;
|
||||
uTotal = size / ((double) uMult);
|
||||
if (uTotal < 0.0)
|
||||
uTotal = 0.0;
|
||||
return (uTotal);
|
||||
} /* FileSize */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
PrSizeAndRateMeter(const FTPCIPtr cip, int mode)
|
||||
{
|
||||
double rate = 0.0;
|
||||
const char *rStr;
|
||||
static const char *uStr;
|
||||
static double uMult;
|
||||
char localName[32];
|
||||
char line[128];
|
||||
int i;
|
||||
|
||||
switch (mode) {
|
||||
case kPrInitMsg:
|
||||
if (cip->expectedSize != kSizeUnknown) {
|
||||
cip->progress = PrStatBar;
|
||||
PrStatBar(cip, mode);
|
||||
return;
|
||||
}
|
||||
(void) FileSize((double) cip->expectedSize, &uStr, &uMult);
|
||||
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
AbbrevStr(localName, cip->lname, sizeof(localName) - 2, 0);
|
||||
if ((cip->usingTAR) && (strlen(localName) < (sizeof(localName) - 6))) {
|
||||
STRNCAT(localName, " (TAR)");
|
||||
}
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
if (cip->useProgressMeter) {
|
||||
#ifdef ncftp
|
||||
if (cip->usingTAR) {
|
||||
if (OneTimeMessage("tar") != 0) {
|
||||
(void) fprintf(stderr, "\n\
|
||||
Note: NcFTP is using on-the-fly TAR on the remote server, which retrieves the\n\
|
||||
entire directory as one operation. This allows you to preserve exact file\n\
|
||||
timestamps, ownerships, and permissions, as well as a slight performance\n\
|
||||
boost.\n\
|
||||
\n\
|
||||
If you would rather retrieve each file individually, use the \"-T\" flag with\n\
|
||||
\"get\". TAR mode cannot be resumed if the transfer fails, so if that happens\n\
|
||||
try \"get -T\" to resume the directory transfer.\n\n");
|
||||
}
|
||||
}
|
||||
#endif /* ncftp */
|
||||
(void) fprintf(stderr, "%-32s", localName);
|
||||
}
|
||||
break;
|
||||
|
||||
case kPrUpdateMsg:
|
||||
rate = FileSize(cip->kBytesPerSec * 1024.0, &rStr, NULL);
|
||||
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
AbbrevStr(localName, cip->lname, sizeof(localName) - 2, 0);
|
||||
if ((cip->usingTAR) && (strlen(localName) < (sizeof(localName) - 6))) {
|
||||
STRNCAT(localName, " (TAR)");
|
||||
}
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_LLD)
|
||||
(void) sprintf(line, "%-32s %10lld bytes %6.2f %s/s",
|
||||
localName,
|
||||
(longest_int) (cip->bytesTransferred + cip->startPoint),
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_QD)
|
||||
(void) sprintf(line, "%-32s %10qd bytes %6.2f %s/s",
|
||||
localName,
|
||||
(longest_int) (cip->bytesTransferred + cip->startPoint),
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_I64D)
|
||||
(void) sprintf(line, "%-32s %10I64d bytes %6.2f %s/s",
|
||||
localName,
|
||||
(longest_int) (cip->bytesTransferred + cip->startPoint),
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
#else
|
||||
(void) sprintf(line, "%-32s %10ld bytes %6.2f %s/s",
|
||||
localName,
|
||||
(long) (cip->bytesTransferred + cip->startPoint),
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
#endif
|
||||
|
||||
/* Pad the rest of the line with spaces, to erase any
|
||||
* stuff that might have been left over from the last
|
||||
* update.
|
||||
*/
|
||||
for (i = (int) strlen(line); i < 80 - 2; i++)
|
||||
line[i] = ' ';
|
||||
line[i] = '\0';
|
||||
|
||||
/* Print the updated information. */
|
||||
(void) fprintf(stderr, "\r%s", line);
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_LLD)
|
||||
SetXtermTitle("%s - [%lld bytes]", cip->lname, (longest_int) (cip->bytesTransferred + cip->startPoint));
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_QD)
|
||||
SetXtermTitle("%s - [%qd bytes]", cip->lname, (longest_int) (cip->bytesTransferred + cip->startPoint));
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_I64D)
|
||||
SetXtermTitle("%s - [%I64d bytes]", cip->lname, (longest_int) (cip->bytesTransferred + cip->startPoint));
|
||||
#else
|
||||
SetXtermTitle("%s - [%ld bytes]", cip->lname, (long) (cip->bytesTransferred + cip->startPoint));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kPrEndMsg:
|
||||
(void) fprintf(stderr, "\n\r");
|
||||
#ifdef ncftp
|
||||
if (cip->rname != NULL) {
|
||||
char url[256];
|
||||
|
||||
FileToURL(url, sizeof(url), cip->rname, gRemoteCWD, cip->startingWorkingDirectory, cip->user, cip->pass, cip->host, cip->port);
|
||||
LogXfer((cip->netMode == kNetReading) ? "get" : "put", url);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
} /* PrSizeAndRateMeter */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
PrStatBar(const FTPCIPtr cip, int mode)
|
||||
{
|
||||
double rate, done;
|
||||
int secLeft, minLeft;
|
||||
const char *rStr;
|
||||
static const char *uStr;
|
||||
static double uTotal, uMult;
|
||||
const char *stall;
|
||||
char localName[80];
|
||||
char line[128];
|
||||
int i;
|
||||
|
||||
switch (mode) {
|
||||
case kPrInitMsg:
|
||||
fflush(stdout);
|
||||
if (cip->expectedSize == kSizeUnknown) {
|
||||
cip->progress = PrSizeAndRateMeter;
|
||||
PrSizeAndRateMeter(cip, mode);
|
||||
return;
|
||||
}
|
||||
uTotal = FileSize((double) cip->expectedSize, &uStr, &uMult);
|
||||
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
/* Leave room for a ':' and '\0'. */
|
||||
AbbrevStr(localName, cip->lname, sizeof(localName) - 2, 0);
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
|
||||
if (cip->useProgressMeter)
|
||||
(void) fprintf(stderr, "%-32s", localName);
|
||||
break;
|
||||
|
||||
case kPrUpdateMsg:
|
||||
secLeft = (int) (cip->secLeft + 0.5);
|
||||
minLeft = secLeft / 60;
|
||||
secLeft = secLeft - (minLeft * 60);
|
||||
if (minLeft > 999) {
|
||||
minLeft = 999;
|
||||
secLeft = 59;
|
||||
}
|
||||
|
||||
rate = FileSize(cip->kBytesPerSec * 1024.0, &rStr, NULL);
|
||||
done = (double) (cip->bytesTransferred + cip->startPoint) / uMult;
|
||||
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
AbbrevStr(localName, cip->lname, 31, 0);
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
|
||||
if (cip->stalled < 2)
|
||||
stall = " ";
|
||||
else if (cip->stalled < 15)
|
||||
stall = "-";
|
||||
else
|
||||
stall = "=";
|
||||
|
||||
(void) sprintf(line, "%-32s ETA: %3d:%02d %6.2f/%6.2f %.2s %6.2f %.2s/s %.1s",
|
||||
localName,
|
||||
minLeft,
|
||||
secLeft,
|
||||
done,
|
||||
uTotal,
|
||||
uStr,
|
||||
rate,
|
||||
rStr,
|
||||
stall
|
||||
);
|
||||
|
||||
/* Print the updated information. */
|
||||
(void) fprintf(stderr, "\r%s", line);
|
||||
|
||||
SetXtermTitle("%s - [%.1f%%]", cip->lname, cip->percentCompleted);
|
||||
break;
|
||||
|
||||
case kPrEndMsg:
|
||||
|
||||
rate = FileSize(cip->kBytesPerSec * 1024.0, &rStr, NULL);
|
||||
done = (double) (cip->bytesTransferred + cip->startPoint) / uMult;
|
||||
|
||||
if (cip->expectedSize == (cip->bytesTransferred + cip->startPoint)) {
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
AbbrevStr(localName, cip->lname, 52, 0);
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
|
||||
(void) sprintf(line, "%-53s %6.2f %.2s %6.2f %.2s/s ",
|
||||
localName,
|
||||
uTotal,
|
||||
uStr,
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
} else {
|
||||
if (cip->lname == NULL) {
|
||||
localName[0] = '\0';
|
||||
} else {
|
||||
AbbrevStr(localName, cip->lname, 45, 0);
|
||||
(void) STRNCAT(localName, ":");
|
||||
}
|
||||
|
||||
(void) sprintf(line, "%-46s %6.2f/%6.2f %.2s %6.2f %.2s/s ",
|
||||
localName,
|
||||
done,
|
||||
uTotal,
|
||||
uStr,
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
}
|
||||
|
||||
/* Pad the rest of the line with spaces, to erase any
|
||||
* stuff that might have been left over from the last
|
||||
* update.
|
||||
*/
|
||||
for (i = (int) strlen(line); i < 80 - 2; i++)
|
||||
line[i] = ' ';
|
||||
line[i] = '\0';
|
||||
|
||||
/* Print the updated information. */
|
||||
(void) fprintf(stderr, "\r%s\n\r", line);
|
||||
#ifdef ncftp
|
||||
if (cip->rname != NULL) {
|
||||
char url[256];
|
||||
|
||||
FileToURL(url, sizeof(url), cip->rname, gRemoteCWD, cip->startingWorkingDirectory, cip->user, cip->pass, cip->host, cip->port);
|
||||
LogXfer((cip->netMode == kNetReading) ? "get" : "put", url);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
} /* PrStatBar */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This one is the brainchild of my comrade, Phil Dietz. It shows the
|
||||
* progress as a fancy bar graph.
|
||||
*/
|
||||
void
|
||||
PrPhilBar(const FTPCIPtr cip, int mode)
|
||||
{
|
||||
int perc;
|
||||
longest_int s;
|
||||
int curBarLen;
|
||||
static int maxBarLen;
|
||||
char spec1[64], spec3[64];
|
||||
static char bar[256];
|
||||
int i;
|
||||
int secsLeft, minLeft;
|
||||
static const char *uStr;
|
||||
static double uMult;
|
||||
double rate;
|
||||
const char *rStr;
|
||||
|
||||
switch (mode) {
|
||||
case kPrInitMsg:
|
||||
if (cip->expectedSize == kSizeUnknown) {
|
||||
cip->progress = PrSizeAndRateMeter;
|
||||
PrSizeAndRateMeter(cip, mode);
|
||||
return;
|
||||
}
|
||||
(void) FileSize((double) cip->expectedSize, &uStr, &uMult);
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s file: %s \n",
|
||||
(cip->netMode == kNetReading) ? "Receiving" : "Sending",
|
||||
cip->lname
|
||||
);
|
||||
|
||||
for (i=0; i < (int) sizeof(bar) - 1; i++)
|
||||
bar[i] = '=';
|
||||
bar[i] = '\0';
|
||||
|
||||
/* Compute the size of the bar itself. This sits between
|
||||
* two numbers, one on each side of the screen. So the
|
||||
* bar length will vary, depending on how many digits we
|
||||
* need to display the size of the file.
|
||||
*/
|
||||
maxBarLen = gScreenColumns - 1 - 28;
|
||||
for (s = cip->expectedSize; s > 0; s /= 10L)
|
||||
maxBarLen--;
|
||||
|
||||
/* Create a specification we can hand to printf. */
|
||||
#if defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_LLD)
|
||||
(void) sprintf(spec1, " 0 %%%ds %%lld bytes. ETA: --:--", maxBarLen);
|
||||
|
||||
/* Print the first invocation, which is an empty graph
|
||||
* plus the other stuff.
|
||||
*/
|
||||
fprintf(stderr, spec1, " ", cip->expectedSize);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_QD)
|
||||
(void) sprintf(spec1, " 0 %%%ds %%qd bytes. ETA: --:--", maxBarLen);
|
||||
fprintf(stderr, spec1, " ", cip->expectedSize);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_I64D)
|
||||
(void) sprintf(spec1, " 0 %%%ds %%I64d bytes. ETA: --:--", maxBarLen);
|
||||
fprintf(stderr, spec1, " ", cip->expectedSize);
|
||||
#else
|
||||
(void) sprintf(spec1, " 0 %%%ds %%ld bytes. ETA: --:--", maxBarLen);
|
||||
fprintf(stderr, spec1, " ", (long) cip->expectedSize);
|
||||
#endif
|
||||
fflush(stdout);
|
||||
break;
|
||||
|
||||
case kPrUpdateMsg:
|
||||
/* Compute how much of the bar should be colored in. */
|
||||
curBarLen = (int) (cip->percentCompleted * 0.01 * (double)maxBarLen);
|
||||
|
||||
/* Colored portion must be at least one character so
|
||||
* the spec isn't '%0s' which would screw the right side
|
||||
* of the indicator.
|
||||
*/
|
||||
if (curBarLen < 1)
|
||||
curBarLen = 1;
|
||||
|
||||
bar[curBarLen - 1] = '>';
|
||||
bar[curBarLen] = '\0';
|
||||
|
||||
/* Make the spec, so we can print the bar and the other stuff. */
|
||||
STRNCPY(spec1, "\r%3d%% 0 ");
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_LLD)
|
||||
(void) sprintf(spec3, "%%%ds %%lld bytes. %s%%3d:%%02d",
|
||||
maxBarLen - curBarLen,
|
||||
"ETA:"
|
||||
);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_QD)
|
||||
(void) sprintf(spec3, "%%%ds %%qd bytes. %s%%3d:%%02d",
|
||||
maxBarLen - curBarLen,
|
||||
"ETA:"
|
||||
);
|
||||
#elif defined(HAVE_LONG_LONG) && defined(PRINTF_LONG_LONG_I64D)
|
||||
(void) sprintf(spec3, "%%%ds %%I64d bytes. %s%%3d:%%02d",
|
||||
maxBarLen - curBarLen,
|
||||
"ETA:"
|
||||
);
|
||||
#else
|
||||
(void) sprintf(spec3, "%%%ds %%ld bytes. %s%%3d:%%02d",
|
||||
maxBarLen - curBarLen,
|
||||
"ETA:"
|
||||
);
|
||||
#endif
|
||||
|
||||
/* We also show the percentage as a number at the left side. */
|
||||
perc = (int) (cip->percentCompleted);
|
||||
secsLeft = (int) (cip->secLeft);
|
||||
minLeft = secsLeft / 60;
|
||||
secsLeft = secsLeft - (minLeft * 60);
|
||||
if (minLeft > 999) {
|
||||
minLeft = 999;
|
||||
secsLeft = 59;
|
||||
}
|
||||
|
||||
/* Print the updated information. */
|
||||
fprintf(stderr, spec1, perc);
|
||||
fprintf(stderr, "%s%s%s", tcap_reverse, bar, tcap_normal);
|
||||
fprintf(stderr, spec3,
|
||||
"",
|
||||
cip->expectedSize,
|
||||
minLeft,
|
||||
secsLeft
|
||||
);
|
||||
|
||||
bar[curBarLen - 1] = '=';
|
||||
bar[curBarLen] = '=';
|
||||
fflush(stdout);
|
||||
|
||||
SetXtermTitle("%s - [%.1f%%]", cip->lname, cip->percentCompleted);
|
||||
break;
|
||||
case kPrEndMsg:
|
||||
printf("\n");
|
||||
rate = FileSize(cip->kBytesPerSec * 1024.0, &rStr, NULL);
|
||||
|
||||
(void) fprintf(stderr, "%s: finished in %ld:%02ld:%02ld, %.2f %s/s\n",
|
||||
(cip->lname == NULL) ? "remote" : cip->lname,
|
||||
(long) cip->sec / 3600L,
|
||||
((long) cip->sec / 60L) % 60L,
|
||||
((long) cip->sec % 60L),
|
||||
rate,
|
||||
rStr
|
||||
);
|
||||
#ifdef ncftp
|
||||
if (cip->rname != NULL) {
|
||||
char url[256];
|
||||
|
||||
FileToURL(url, sizeof(url), cip->rname, gRemoteCWD, cip->startingWorkingDirectory, cip->user, cip->pass, cip->host, cip->port);
|
||||
LogXfer((cip->netMode == kNetReading) ? "get" : "put", url);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
} /* PrPhilBar */
|
|
@ -1,17 +0,0 @@
|
|||
/* progress.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#define kKilobyte 1024
|
||||
#define kMegabyte (kKilobyte * 1024)
|
||||
#define kGigabyte ((long) kMegabyte * 1024L)
|
||||
#define kTerabyte ((double) kGigabyte * 1024.0)
|
||||
|
||||
/* progress.c */
|
||||
double FileSize(const double size, const char **uStr0, double *const uMult0);
|
||||
void PrSizeAndRateMeter(const FTPCIPtr, int);
|
||||
void PrStatBar(const FTPCIPtr, int);
|
||||
void PrPhilBar(const FTPCIPtr, int);
|
|
@ -1,831 +0,0 @@
|
|||
/* rdline.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Note: It should still be simple to backport the old GNU Readline
|
||||
* support in here. Feel free to do that if you hate NcFTP's built-in
|
||||
* implementation.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "util.h"
|
||||
#include "bookmark.h"
|
||||
#include "cmds.h"
|
||||
#include "pref.h"
|
||||
#include "ls.h"
|
||||
#include "readln.h"
|
||||
#include "getline.h"
|
||||
|
||||
const char *tcap_normal = "";
|
||||
const char *tcap_boldface = "";
|
||||
const char *tcap_underline = "";
|
||||
const char *tcap_reverse = "";
|
||||
const char *gTerm;
|
||||
int gXterm;
|
||||
int gXtermTitle; /* Idea by forsberg@lysator.liu.se */
|
||||
char gCurXtermTitleStr[256];
|
||||
|
||||
#if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
|
||||
char gSavedConsoleTitle[64];
|
||||
#endif
|
||||
|
||||
extern int gEventNumber;
|
||||
extern int gMaySetXtermTitle;
|
||||
extern LsCacheItem gLsCache[kLsCacheSize];
|
||||
extern FTPConnectionInfo gConn;
|
||||
extern char gRemoteCWD[512];
|
||||
extern char gOurDirectoryPath[];
|
||||
extern char gVersion[];
|
||||
extern int gNumBookmarks;
|
||||
extern BookmarkPtr gBookmarkTable;
|
||||
extern PrefOpt gPrefOpts[];
|
||||
extern int gNumPrefOpts;
|
||||
extern int gScreenColumns;
|
||||
extern int gIsTTYr;
|
||||
extern int gUid;
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
GetScreenColumns(void)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
|
||||
gScreenColumns = (int) csbi.dwSize.X;
|
||||
if (gScreenColumns < 80)
|
||||
gScreenColumns = 80;
|
||||
}
|
||||
#else /* Unix */
|
||||
#ifdef BINDIR
|
||||
char ncftpbookmarks[256];
|
||||
FILE *infp;
|
||||
vsigproc_t osigpipe;
|
||||
int columns;
|
||||
#endif /* BINDIR */
|
||||
char *cp;
|
||||
|
||||
if ((cp = (char *) getenv("COLUMNS")) == NULL) {
|
||||
gScreenColumns = 80;
|
||||
} else {
|
||||
gScreenColumns = atoi(cp);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TIOCGWINSZ
|
||||
{
|
||||
struct winsize felix;
|
||||
|
||||
memset(&felix, 0, sizeof(felix));
|
||||
if (ioctl(0, TIOCGWINSZ, &felix) == 0) {
|
||||
columns = felix.ws_col;
|
||||
if ((columns > 0) && (columns < GL_BUF_SIZE))
|
||||
gScreenColumns = columns;
|
||||
else
|
||||
gScreenColumns = 80;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BINDIR
|
||||
/* Don't run things as root unless really necessary. */
|
||||
if (gUid == 0)
|
||||
return;
|
||||
|
||||
/* This is a brutal hack where we've hacked a
|
||||
* special command line option into ncftp_bookmarks
|
||||
* (which is linked with curses) so that it computes
|
||||
* the screen size and prints it to stdout.
|
||||
*
|
||||
* This function runs ncftp_bookmarks and gets
|
||||
* that information. The reason we do this is that
|
||||
* we may or may not have a sane installation of
|
||||
* curses/termcap, and we don't want to increase
|
||||
* NcFTP's complexity by the curses junk just to
|
||||
* get the screen size. Instead, we delegate this
|
||||
* to ncftp_bookmarks which already deals with the
|
||||
* ugliness of curses.
|
||||
*/
|
||||
|
||||
STRNCPY(ncftpbookmarks, BINDIR);
|
||||
STRNCAT(ncftpbookmarks, "/");
|
||||
STRNCAT(ncftpbookmarks, "ncftpbookmarks");
|
||||
|
||||
if (access(ncftpbookmarks, X_OK) < 0)
|
||||
return;
|
||||
|
||||
STRNCAT(ncftpbookmarks, " --dimensions-terse");
|
||||
|
||||
osigpipe = NcSignal(SIGPIPE, SIG_IGN);
|
||||
infp = popen(ncftpbookmarks, "r");
|
||||
if (infp != NULL) {
|
||||
columns = 0;
|
||||
(void) fscanf(infp, "%d", &columns);
|
||||
while (getc(infp) != EOF) {}
|
||||
(void) pclose(infp);
|
||||
|
||||
if ((columns > 0) && (columns < GL_BUF_SIZE))
|
||||
gScreenColumns = columns;
|
||||
}
|
||||
(void) NcSignal(SIGPIPE, (sigproc_t) osigpipe);
|
||||
#endif /* BINDIR */
|
||||
#endif /* Windows */
|
||||
} /* GetScreenColumns */
|
||||
|
||||
|
||||
|
||||
/* For a few selected terminal types, we'll print in boldface, etc.
|
||||
* This isn't too important, though.
|
||||
*/
|
||||
void
|
||||
InitTermcap(void)
|
||||
{
|
||||
#if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
|
||||
gXterm = gXtermTitle = 0;
|
||||
gCurXtermTitleStr[0] = '\0';
|
||||
|
||||
tcap_normal = "";
|
||||
tcap_boldface = "";
|
||||
tcap_underline = "";
|
||||
tcap_reverse = "";
|
||||
|
||||
gTerm = "MS-DOS Prompt";
|
||||
ZeroMemory(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle));
|
||||
GetConsoleTitle(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle) - 1);
|
||||
SetConsoleTitle("NcFTP");
|
||||
gXterm = gXtermTitle = 1;
|
||||
#else
|
||||
const char *term;
|
||||
|
||||
gXterm = gXtermTitle = 0;
|
||||
gCurXtermTitleStr[0] = '\0';
|
||||
|
||||
if ((gTerm = getenv("TERM")) == NULL) {
|
||||
tcap_normal = "";
|
||||
tcap_boldface = "";
|
||||
tcap_underline = "";
|
||||
tcap_reverse = "";
|
||||
return;
|
||||
}
|
||||
|
||||
term = gTerm;
|
||||
if ( (strstr(term, "xterm") != NULL) ||
|
||||
(strstr(term, "rxvt") != NULL) ||
|
||||
(strstr(term, "dtterm") != NULL) ||
|
||||
(ISTRCMP(term, "scoterm") == 0)
|
||||
) {
|
||||
gXterm = gXtermTitle = 1;
|
||||
}
|
||||
|
||||
if ( (gXterm != 0) ||
|
||||
(strcmp(term, "vt100") == 0) ||
|
||||
(strcmp(term, "linux") == 0) ||
|
||||
(strcmp(term, "vt220") == 0) ||
|
||||
(strcmp(term, "vt102") == 0)
|
||||
) {
|
||||
tcap_normal = "\033[0m"; /* Default ANSI escapes */
|
||||
tcap_boldface = "\033[1m";
|
||||
tcap_underline = "\033[4m";
|
||||
tcap_reverse = "\033[7m";
|
||||
} else {
|
||||
tcap_normal = "";
|
||||
tcap_boldface = "";
|
||||
tcap_underline = "";
|
||||
tcap_reverse = "";
|
||||
}
|
||||
#endif
|
||||
} /* InitTermcap */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
FindStartOfCurrentCommand(void)
|
||||
{
|
||||
char *scp;
|
||||
char *start;
|
||||
int qc;
|
||||
|
||||
for (scp = gl_buf;;) {
|
||||
start = scp;
|
||||
for (;;) {
|
||||
if (*scp == '\0')
|
||||
goto done;
|
||||
if (!isspace((int) *scp))
|
||||
break;
|
||||
scp++;
|
||||
}
|
||||
start = scp;
|
||||
|
||||
for (;;) {
|
||||
if (*scp == '\0') {
|
||||
goto done;
|
||||
} else if ((*scp == '"') || (*scp == '\'')) {
|
||||
qc = *scp++;
|
||||
|
||||
for (;;) {
|
||||
if (*scp == '\0') {
|
||||
goto done;
|
||||
} else if (*scp == '\\') {
|
||||
scp++;
|
||||
if (*scp == '\0')
|
||||
goto done;
|
||||
scp++;
|
||||
} else if (*scp == qc) {
|
||||
scp++;
|
||||
break;
|
||||
} else {
|
||||
scp++;
|
||||
}
|
||||
}
|
||||
} else if (*scp == '\\') {
|
||||
scp++;
|
||||
if (*scp == '\0')
|
||||
goto done;
|
||||
scp++;
|
||||
} else if ((*scp == ';') || (*scp == '\n')) {
|
||||
/* command ended */
|
||||
scp++;
|
||||
if (*scp == '\0')
|
||||
goto done;
|
||||
break;
|
||||
} else {
|
||||
scp++;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
return (start);
|
||||
} /* FindStartOfCurrentCommand */
|
||||
|
||||
|
||||
|
||||
static FileInfoListPtr
|
||||
GetLsCacheFileList(const char *const item)
|
||||
{
|
||||
int ci;
|
||||
int sortBy;
|
||||
int sortOrder;
|
||||
FileInfoListPtr filp;
|
||||
|
||||
ci = LsCacheLookup(item);
|
||||
if (ci < 0) {
|
||||
/* This dir was not in the
|
||||
* cache -- go get it.
|
||||
*/
|
||||
Ls(item, 'l', "", NULL);
|
||||
ci = LsCacheLookup(item);
|
||||
if (ci < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sortBy = 'n'; /* Sort by filename. */
|
||||
sortOrder = 'a'; /* Sort in ascending order. */
|
||||
filp = &gLsCache[ci].fil;
|
||||
SortFileInfoList(filp, sortBy, sortOrder);
|
||||
return filp;
|
||||
} /* GetLsCacheFileList */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
RemoteCompletionFunction(const char *text, int state, int fTypeFilter)
|
||||
{
|
||||
char rpath[256];
|
||||
char *cp;
|
||||
char *cp2;
|
||||
const char *textbasename;
|
||||
int fType;
|
||||
FileInfoPtr diritemp;
|
||||
FileInfoListPtr filp;
|
||||
int textdirlen;
|
||||
size_t tbnlen;
|
||||
size_t flen, mlen;
|
||||
static FileInfoVec diritemv;
|
||||
static int i;
|
||||
|
||||
textbasename = strrchr(text, '/');
|
||||
if (textbasename == NULL) {
|
||||
textbasename = text;
|
||||
textdirlen = -1;
|
||||
} else {
|
||||
textdirlen = (int) (textbasename - text);
|
||||
textbasename++;
|
||||
}
|
||||
tbnlen = strlen(textbasename);
|
||||
|
||||
if (state == 0) {
|
||||
if (text[0] == '\0') {
|
||||
/* Special case when they do "get <TAB><TAB> " */
|
||||
STRNCPY(rpath, gRemoteCWD);
|
||||
} else {
|
||||
PathCat(rpath, sizeof(rpath), gRemoteCWD, text);
|
||||
if (text[strlen(text) - 1] == '/') {
|
||||
/* Special case when they do "get /dir1/dir2/<TAB><TAB>" */
|
||||
STRNCAT(rpath, "/");
|
||||
}
|
||||
cp2 = strrchr(rpath, '/');
|
||||
if (cp2 == NULL) {
|
||||
return NULL;
|
||||
} else if (cp2 == rpath) {
|
||||
/* Item in root directory. */
|
||||
cp2++;
|
||||
}
|
||||
*cp2 = '\0';
|
||||
}
|
||||
|
||||
filp = GetLsCacheFileList(rpath);
|
||||
if (filp == NULL)
|
||||
return NULL;
|
||||
|
||||
diritemv = filp->vec;
|
||||
if (diritemv == NULL)
|
||||
return NULL;
|
||||
|
||||
i = 0;
|
||||
}
|
||||
|
||||
for ( ; ; ) {
|
||||
diritemp = diritemv[i];
|
||||
if (diritemp == NULL)
|
||||
break;
|
||||
|
||||
i++;
|
||||
fType = (int) diritemp->type;
|
||||
if ((fTypeFilter == 0) || (fType == fTypeFilter) || (fType == /* symlink */ 'l')) {
|
||||
if (strncmp(textbasename, diritemp->relname, tbnlen) == 0) {
|
||||
flen = strlen(diritemp->relname);
|
||||
if (textdirlen < 0) {
|
||||
mlen = flen + 2;
|
||||
cp = (char *) malloc(mlen);
|
||||
if (cp == NULL)
|
||||
return (NULL);
|
||||
(void) memcpy(cp, diritemp->relname, mlen);
|
||||
} else {
|
||||
mlen = textdirlen + 1 + flen + 2;
|
||||
cp = (char *) malloc(mlen);
|
||||
if (cp == NULL)
|
||||
return (NULL);
|
||||
(void) memcpy(cp, text, (size_t) textdirlen);
|
||||
cp[textdirlen] = '/';
|
||||
(void) strcpy(cp + textdirlen + 1, diritemp->relname);
|
||||
}
|
||||
if (fType == 'd') {
|
||||
gl_completion_exact_match_extra_char = '/';
|
||||
} else {
|
||||
gl_completion_exact_match_extra_char = ' ';
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
} /* RemoteCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
RemoteFileCompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
cp = RemoteCompletionFunction(text, state, 0);
|
||||
return cp;
|
||||
} /* RemoteFileCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
RemoteDirCompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
cp = RemoteCompletionFunction(text, state, 'd');
|
||||
return cp;
|
||||
} /* RemoteDirCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
BookmarkCompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
size_t textlen;
|
||||
int i, matches;
|
||||
|
||||
if ((gBookmarkTable == NULL) || (state >= gNumBookmarks))
|
||||
return (NULL);
|
||||
|
||||
textlen = strlen(text);
|
||||
if (textlen == 0) {
|
||||
cp = StrDup(gBookmarkTable[state].bookmarkName);
|
||||
} else {
|
||||
cp = NULL;
|
||||
for (i=0, matches=0; i<gNumBookmarks; i++) {
|
||||
if (ISTRNCMP(gBookmarkTable[i].bookmarkName, text, textlen) == 0) {
|
||||
if (matches >= state) {
|
||||
cp = StrDup(gBookmarkTable[i].bookmarkName);
|
||||
break;
|
||||
}
|
||||
matches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
} /* BookmarkCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
CommandCompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
size_t textlen;
|
||||
int i, matches;
|
||||
CommandPtr cmdp;
|
||||
|
||||
textlen = strlen(text);
|
||||
if (textlen == 0) {
|
||||
cp = NULL;
|
||||
} else {
|
||||
cp = NULL;
|
||||
for (i=0, matches=0; ; i++) {
|
||||
cmdp = GetCommandByIndex(i);
|
||||
if (cmdp == kNoCommand)
|
||||
break;
|
||||
if (ISTRNCMP(cmdp->name, text, textlen) == 0) {
|
||||
if (matches >= state) {
|
||||
cp = StrDup(cmdp->name);
|
||||
break;
|
||||
}
|
||||
matches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
} /* CommandCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
PrefOptCompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
size_t textlen;
|
||||
int i, matches;
|
||||
|
||||
if (state >= gNumPrefOpts)
|
||||
return (NULL);
|
||||
|
||||
textlen = strlen(text);
|
||||
if (textlen == 0) {
|
||||
cp = StrDup(gPrefOpts[state].varname);
|
||||
} else {
|
||||
cp = NULL;
|
||||
for (i=0, matches=0; i<gNumPrefOpts; i++) {
|
||||
if (ISTRNCMP(gPrefOpts[i].varname, text, textlen) == 0) {
|
||||
if (matches >= state) {
|
||||
cp = StrDup(gPrefOpts[i].varname);
|
||||
break;
|
||||
}
|
||||
matches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
} /* PrefOptCompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
ReCacheBookmarks(void)
|
||||
{
|
||||
(void) LoadBookmarkTable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
HaveCommandNameOnly(char *cmdstart)
|
||||
{
|
||||
char *cp;
|
||||
for (cp = cmdstart; *cp != '\0'; cp++) {
|
||||
if (isspace((int) *cp))
|
||||
return (0); /* At least one argument in progress. */
|
||||
}
|
||||
return (1);
|
||||
} /* HaveCommandNameOnly */
|
||||
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
CompletionFunction(const char *text, int state)
|
||||
{
|
||||
char *cp;
|
||||
char *cmdstart;
|
||||
ArgvInfo ai;
|
||||
int bUsed;
|
||||
CommandPtr cmdp;
|
||||
static int flags;
|
||||
|
||||
if (state == 0) {
|
||||
flags = -1;
|
||||
cmdstart = FindStartOfCurrentCommand();
|
||||
if (cmdstart == NULL)
|
||||
return NULL;
|
||||
if (HaveCommandNameOnly(cmdstart)) {
|
||||
flags = -2; /* special case */
|
||||
cp = CommandCompletionFunction(text, state);
|
||||
return cp;
|
||||
}
|
||||
|
||||
(void) memset(&ai, 0, sizeof(ai));
|
||||
bUsed = MakeArgv(cmdstart, &ai.cargc, ai.cargv,
|
||||
(int) (sizeof(ai.cargv) / sizeof(char *)),
|
||||
ai.argbuf, sizeof(ai.argbuf),
|
||||
ai.noglobargv, 1);
|
||||
if (bUsed <= 0)
|
||||
return NULL;
|
||||
if (ai.cargc == 0)
|
||||
return NULL;
|
||||
|
||||
cmdp = GetCommandByName(ai.cargv[0], 0);
|
||||
if (cmdp == kAmbiguousCommand) {
|
||||
return NULL;
|
||||
} else if (cmdp == kNoCommand) {
|
||||
return NULL;
|
||||
}
|
||||
flags = cmdp->flags;
|
||||
}
|
||||
if (flags == (-2)) {
|
||||
cp = CommandCompletionFunction(text, state);
|
||||
return cp;
|
||||
}
|
||||
if (flags < 0)
|
||||
return NULL;
|
||||
if ((flags & (kCompleteLocalFile|kCompleteLocalDir)) != 0) {
|
||||
cp = gl_local_filename_completion_proc(text, state);
|
||||
return cp;
|
||||
} else if ((flags & kCompleteRemoteFile) != 0) {
|
||||
gl_filename_quoting_desired = 1;
|
||||
cp = RemoteFileCompletionFunction(text, state);
|
||||
return cp;
|
||||
} else if ((flags & kCompleteRemoteDir) != 0) {
|
||||
gl_filename_quoting_desired = 1;
|
||||
cp = RemoteDirCompletionFunction(text, state);
|
||||
return cp;
|
||||
} else if ((flags & kCompleteBookmark) != 0) {
|
||||
cp = BookmarkCompletionFunction(text, state);
|
||||
return cp;
|
||||
} else if ((flags & kCompletePrefOpt) != 0) {
|
||||
cp = PrefOptCompletionFunction(text, state);
|
||||
return cp;
|
||||
}
|
||||
return NULL;
|
||||
} /* CompletionFunction */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
LoadHistory(void)
|
||||
{
|
||||
char pathName[256];
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return;
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kHistoryFileName);
|
||||
|
||||
gl_histloadfile(pathName);
|
||||
} /* LoadHistory */
|
||||
|
||||
|
||||
|
||||
static size_t
|
||||
Vt100VisibleStrlen(const char *src)
|
||||
{
|
||||
const char *cp;
|
||||
size_t esc;
|
||||
|
||||
for (esc = 0, cp = src; *cp != '\0'; cp++) {
|
||||
if (*cp == '\033')
|
||||
esc++;
|
||||
}
|
||||
|
||||
/* The VT100 escape codes we use are all in the form "\033[7m"
|
||||
* These aren't visible, so subtract them from the count.
|
||||
*/
|
||||
return ((size_t) (cp - src) - (esc * 4));
|
||||
} /* Vt100VisibleStrlen */
|
||||
|
||||
|
||||
|
||||
/* Save the commands they typed in a history file, then they can use
|
||||
* readline to go through them again next time.
|
||||
*/
|
||||
void
|
||||
SaveHistory(void)
|
||||
{
|
||||
char pathName[256];
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return; /* Don't create in root directory. */
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), kHistoryFileName);
|
||||
|
||||
gl_strlen = Vt100VisibleStrlen;
|
||||
gl_histsavefile(pathName);
|
||||
(void) chmod(pathName, 00600);
|
||||
} /* SaveHistory */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
InitReadline(void)
|
||||
{
|
||||
gl_completion_proc = CompletionFunction;
|
||||
gl_setwidth(gScreenColumns);
|
||||
LoadHistory();
|
||||
ReCacheBookmarks();
|
||||
} /* InitReadline */
|
||||
|
||||
|
||||
|
||||
|
||||
char *
|
||||
Readline(char *prompt)
|
||||
{
|
||||
char *linecopy, *line, *cp;
|
||||
char lbuf[256];
|
||||
|
||||
if (gIsTTYr) {
|
||||
line = getline(prompt);
|
||||
} else {
|
||||
line = fgets(lbuf, sizeof(lbuf) - 1, stdin);
|
||||
if (line != NULL) {
|
||||
cp = line + strlen(line) - 1;
|
||||
if (*cp == '\n')
|
||||
*cp = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (line != NULL) {
|
||||
if (line[0] == '\0')
|
||||
return NULL; /* EOF */
|
||||
linecopy = StrDup(line);
|
||||
line = linecopy;
|
||||
}
|
||||
return (line);
|
||||
} /* Readline */
|
||||
|
||||
|
||||
|
||||
void
|
||||
AddHistory(char *line)
|
||||
{
|
||||
gl_histadd(line);
|
||||
} /* AddHistory */
|
||||
|
||||
|
||||
|
||||
void
|
||||
DisposeReadline(void)
|
||||
{
|
||||
SaveHistory();
|
||||
} /* DisposeReadline */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*VARARGS*/
|
||||
void
|
||||
SetXtermTitle(const char *const fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[256];
|
||||
|
||||
if ((gXtermTitle != 0) && (gMaySetXtermTitle != 0)) {
|
||||
if ((fmt == NULL) || (ISTRCMP(fmt, "RESTORE") == 0)) {
|
||||
#if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
|
||||
STRNCPY(buf, gSavedConsoleTitle);
|
||||
#else
|
||||
STRNCPY(buf, gTerm);
|
||||
#endif
|
||||
} else if (ISTRCMP(fmt, "DEFAULT") == 0) {
|
||||
(void) Strncpy(buf, gVersion + 5, 12);
|
||||
} else {
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_VSNPRINTF
|
||||
(void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
#else
|
||||
(void) vsprintf(buf, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
}
|
||||
if (buf[0] != '\0') {
|
||||
#if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
|
||||
SetConsoleTitle(buf);
|
||||
#else
|
||||
if (strcmp(gCurXtermTitleStr, buf) != 0) {
|
||||
fprintf(stderr, "\033]0;%s\007", buf);
|
||||
STRNCPY(gCurXtermTitleStr, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} /* SetXtermTitle */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
PrintStartupBanner(void)
|
||||
{
|
||||
char v[80], *cp;
|
||||
char vdate[32];
|
||||
|
||||
/* Print selected information from the version ID. */
|
||||
vdate[0] = '\0';
|
||||
(void) STRNCPY(v, gVersion + 5);
|
||||
cp = strchr(v, ',');
|
||||
if (cp != NULL) {
|
||||
*cp = '\0';
|
||||
cp[-5] = '\0';
|
||||
(void) STRNCPY(vdate, " (");
|
||||
(void) STRNCAT(vdate, v + 16);
|
||||
(void) STRNCAT(vdate, ", ");
|
||||
(void) STRNCAT(vdate, cp - 4);
|
||||
(void) STRNCAT(vdate, ")");
|
||||
}
|
||||
|
||||
#if defined(BETA) && (BETA > 0)
|
||||
(void) fprintf(stdout, "%s%.11s beta %d%s%s by Mike Gleason (ncftp@ncftp.com).\n",
|
||||
tcap_boldface,
|
||||
gVersion + 5,
|
||||
BETA,
|
||||
tcap_normal,
|
||||
vdate
|
||||
);
|
||||
#else
|
||||
(void) fprintf(stdout, "%s%.11s%s%s by Mike Gleason (ncftp@ncftp.com).\n",
|
||||
tcap_boldface,
|
||||
gVersion + 5,
|
||||
tcap_normal,
|
||||
vdate
|
||||
);
|
||||
#endif
|
||||
(void) fflush(stdout);
|
||||
} /* PrintStartupBanner */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Print the command shell's prompt. */
|
||||
void
|
||||
MakePrompt(char *dst, size_t dsize)
|
||||
{
|
||||
char acwd[64];
|
||||
|
||||
# ifdef HAVE_SNPRINTF
|
||||
if (gConn.loggedIn != 0) {
|
||||
AbbrevStr(acwd, gRemoteCWD, 25, 0);
|
||||
snprintf(dst, dsize, "%sncftp%s %s %s>%s ",
|
||||
tcap_boldface, tcap_normal, acwd,
|
||||
tcap_boldface, tcap_normal);
|
||||
} else {
|
||||
snprintf(dst, dsize, "%sncftp%s> ",
|
||||
tcap_boldface, tcap_normal);
|
||||
}
|
||||
# else /* HAVE_SNPRINTF */
|
||||
(void) Strncpy(dst, tcap_boldface, dsize);
|
||||
(void) Strncat(dst, "ncftp", dsize);
|
||||
(void) Strncat(dst, tcap_normal, dsize);
|
||||
if (gConn.loggedIn != 0) {
|
||||
AbbrevStr(acwd, gRemoteCWD, 25, 0);
|
||||
(void) Strncat(dst, " ", dsize);
|
||||
(void) Strncat(dst, acwd, dsize);
|
||||
(void) Strncat(dst, " ", dsize);
|
||||
}
|
||||
(void) Strncat(dst, tcap_boldface, dsize);
|
||||
(void) Strncat(dst, ">", dsize);
|
||||
(void) Strncat(dst, tcap_normal, dsize);
|
||||
(void) Strncat(dst, " ", dsize);
|
||||
# endif /* HAVE_SNPRINTF */
|
||||
} /* MakePrompt */
|
|
@ -1,31 +0,0 @@
|
|||
/* readln.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kHistoryFileName "history.txt"
|
||||
#else
|
||||
# define kHistoryFileName "history"
|
||||
#endif
|
||||
|
||||
/* readln.c */
|
||||
void GetScreenColumns(void);
|
||||
void InitTermcap(void);
|
||||
void InitReadline(void);
|
||||
void ReCacheBookmarks(void);
|
||||
char *Readline(char *);
|
||||
void AddHistory(char *);
|
||||
void PrintStartupBanner(void);
|
||||
void SetXtermTitle(const char *const fmt, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 1, 2)))
|
||||
#endif
|
||||
;
|
||||
void MakePrompt(char *, size_t);
|
||||
void SaveHistory(void);
|
||||
void LoadHistory(void);
|
||||
void InitReadline(void);
|
||||
void DisposeReadline(void);
|
|
@ -1,16 +0,0 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by rc.rc
|
||||
//
|
||||
#define IDI_NCFTP_ICON 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
|
@ -1,607 +0,0 @@
|
|||
/* shell.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "util.h"
|
||||
#include "bookmark.h"
|
||||
#include "cmds.h"
|
||||
#include "readln.h"
|
||||
#include "trace.h"
|
||||
#include "main.h"
|
||||
|
||||
/* We keep running the command line interpreter until gDoneApplication
|
||||
* is non-zero.
|
||||
*/
|
||||
int gDoneApplication = 0;
|
||||
|
||||
/* Track how many times they use ^C. */
|
||||
int gNumInterruptions = 0;
|
||||
|
||||
/* Keep a count of the number of commands the user has entered. */
|
||||
int gEventNumber = 0;
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#elif defined(HAVE_SIGSETJMP)
|
||||
/* A command function can set this to have a user generated signal
|
||||
* cause execution to jump here.
|
||||
*/
|
||||
sigjmp_buf gCancelJmp;
|
||||
|
||||
/* This is used by the shell so that an unexpected signal can have
|
||||
* execution come back to the main shell prompt.
|
||||
*/
|
||||
sigjmp_buf gBackToTopJmp;
|
||||
#else /* HAVE_SIGSETJMP */
|
||||
/* A command function can set this to have a user generated signal
|
||||
* cause execution to jump here.
|
||||
*/
|
||||
jmp_buf gCancelJmp;
|
||||
|
||||
/* This is used by the shell so that an unexpected signal can have
|
||||
* execution come back to the main shell prompt.
|
||||
*/
|
||||
jmp_buf gBackToTopJmp;
|
||||
#endif /* HAVE_SIGSETJMP */
|
||||
|
||||
/* Flag specifying whether the jmp has been set. */
|
||||
int gMayCancelJmp = 0;
|
||||
|
||||
/* Flag specifying whether the jmp has been set. */
|
||||
int gMayBackToTopJmp = 0;
|
||||
|
||||
/* Save the last signal number. */
|
||||
int gGotSig = 0;
|
||||
|
||||
/* If the shell is running one of our commands, this is set to non-zero. */
|
||||
int gRunningCommand = 0;
|
||||
|
||||
/* If set, we need to abort the current session. */
|
||||
int gCancelCtrl = 0;
|
||||
|
||||
extern Command gCommands[];
|
||||
extern size_t gNumCommands;
|
||||
extern int gStartupUrlParameterGiven;
|
||||
extern FTPLibraryInfo gLib;
|
||||
extern FTPConnectionInfo gConn;
|
||||
extern LineList gStartupURLCdList;
|
||||
extern int gNumProgramRuns;
|
||||
extern char gCopyright[];
|
||||
|
||||
|
||||
/* This is used as the comparison function when we sort the name list. */
|
||||
static int
|
||||
CommandSortCmp(const CommandPtr a, const CommandPtr b)
|
||||
{
|
||||
return (strcmp((*a).name, (*b).name));
|
||||
} /* CommandSortCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Sort the command list, in case it wasn't hard-coded that way. */
|
||||
void
|
||||
InitCommandList(void)
|
||||
{
|
||||
qsort(gCommands, gNumCommands, sizeof(Command), (qsort_proc_t) CommandSortCmp);
|
||||
} /* InitCommandList */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This is used as the comparison function when we lookup something
|
||||
* in the command list, and when we want an exact match.
|
||||
*/
|
||||
static int
|
||||
CommandExactSearchCmp(const char *const key, const CommandPtr b)
|
||||
{
|
||||
return (strcmp(key, (*b).name));
|
||||
} /* CommandExactSearchCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This is used as the comparison function when we lookup something
|
||||
* in the command list, and when the key can be just the first few
|
||||
* letters of one or more commands. So a key of "qu" might would match
|
||||
* "quit" and "quote" for example.
|
||||
*/
|
||||
static int
|
||||
CommandSubSearchCmp(const char *const key, const CommandPtr a)
|
||||
{
|
||||
register const char *kcp, *cp;
|
||||
int d;
|
||||
|
||||
for (cp = (*a).name, kcp = key; ; ) {
|
||||
if (*kcp == 0)
|
||||
break;
|
||||
d = *kcp++ - *cp++;
|
||||
if (d)
|
||||
return d;
|
||||
}
|
||||
return (0);
|
||||
} /* CommandSubSearchCmp */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This returns a pointer to a Command, if the name supplied was long
|
||||
* enough to be a unique name. We return a 0 CommandPtr if we did not
|
||||
* find any matches, a -1 CommandPtr if we found more than one match,
|
||||
* or the unique CommandPtr.
|
||||
*/
|
||||
CommandPtr
|
||||
GetCommandByIndex(const int i)
|
||||
{
|
||||
if ((i < 0) || (i >= (int) gNumCommands))
|
||||
return (kNoCommand);
|
||||
return (&gCommands[i]);
|
||||
} /* GetCommandByIndex */
|
||||
|
||||
|
||||
|
||||
|
||||
/* This returns a pointer to a Command, if the name supplied was long
|
||||
* enough to be a unique name. We return a 0 CommandPtr if we did not
|
||||
* find any matches, a -1 CommandPtr if we found more than one match,
|
||||
* or the unique CommandPtr.
|
||||
*/
|
||||
CommandPtr
|
||||
GetCommandByName(const char *const name, int wantExactMatch)
|
||||
{
|
||||
CommandPtr canp, canp2;
|
||||
|
||||
/* First check for an exact match. Otherwise if you if asked for
|
||||
* 'cd', it would match both 'cd' and 'cdup' and return an
|
||||
* ambiguous name error, despite having the exact name for 'cd.'
|
||||
*/
|
||||
canp = (CommandPtr) bsearch(name, gCommands, gNumCommands, sizeof(Command), (bsearch_proc_t) CommandExactSearchCmp);
|
||||
|
||||
if (canp == kNoCommand && !wantExactMatch) {
|
||||
/* Now see if the user typed an abbreviation unique enough
|
||||
* to match only one name in the list.
|
||||
*/
|
||||
canp = (CommandPtr) bsearch(name, gCommands, gNumCommands, sizeof(Command), (bsearch_proc_t) CommandSubSearchCmp);
|
||||
|
||||
if (canp != kNoCommand) {
|
||||
/* Check the entry above us and see if the name we're looking
|
||||
* for would match that, too.
|
||||
*/
|
||||
if (canp != &gCommands[0]) {
|
||||
canp2 = canp - 1;
|
||||
if (CommandSubSearchCmp(name, canp2) == 0)
|
||||
return kAmbiguousCommand;
|
||||
}
|
||||
/* Check the entry below us and see if the name we're looking
|
||||
* for would match that one.
|
||||
*/
|
||||
if (canp != &gCommands[gNumCommands - 1]) {
|
||||
canp2 = canp + 1;
|
||||
if (CommandSubSearchCmp(name, canp2) == 0)
|
||||
return kAmbiguousCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
return canp;
|
||||
} /* GetCommandByName */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Print the help string for the command specified. */
|
||||
|
||||
void
|
||||
PrintCmdHelp(CommandPtr c)
|
||||
{
|
||||
(void) printf("%s: %s.\n", c->name, c->help);
|
||||
} /* PrintCmdHelp */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Print the usage string for the command specified. */
|
||||
void
|
||||
PrintCmdUsage(CommandPtr c)
|
||||
{
|
||||
if (c->usage != NULL)
|
||||
(void) printf("Usage: %s %s\n", c->name, c->usage);
|
||||
} /* PrintCmdUsage */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Parse a command line into an array of arguments. */
|
||||
int
|
||||
MakeArgv(char *line, int *cargc, const char **cargv, int cargcmax, char *dbuf, size_t dbufsize, int *noglobargv, int readlineHacks)
|
||||
{
|
||||
int c;
|
||||
int retval;
|
||||
char *dlim;
|
||||
char *dcp;
|
||||
char *scp;
|
||||
char *arg;
|
||||
|
||||
*cargc = 0;
|
||||
scp = line;
|
||||
dlim = dbuf + dbufsize - 1;
|
||||
dcp = dbuf;
|
||||
|
||||
for (*cargc = 0; *cargc < cargcmax; ) {
|
||||
/* Eat preceding junk. */
|
||||
for ( ; ; scp++) {
|
||||
c = *scp;
|
||||
if (c == '\0')
|
||||
goto done;
|
||||
if (isspace(c))
|
||||
continue;
|
||||
if ((c == ';') || (c == '\n')) {
|
||||
scp++;
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
arg = dcp;
|
||||
cargv[*cargc] = arg;
|
||||
noglobargv[*cargc] = 0;
|
||||
(*cargc)++;
|
||||
|
||||
/* Special hack so that "!cmd" is always split into "!" "cmd" */
|
||||
if ((*cargc == 1) && (*scp == '!')) {
|
||||
if (scp[1] == '!') {
|
||||
scp[1] = '\0';
|
||||
} else if ((scp[1] != '\0') && (!isspace((int) scp[1]))) {
|
||||
cargv[0] = "!";
|
||||
scp++;
|
||||
arg = dcp;
|
||||
cargv[*cargc] = arg;
|
||||
noglobargv[*cargc] = 0;
|
||||
(*cargc)++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add characters to the new argument. */
|
||||
for ( ; ; ) {
|
||||
c = *scp;
|
||||
if (c == '\0')
|
||||
break;
|
||||
if (isspace(c))
|
||||
break;
|
||||
if ((c == ';') || (c == '\n')) {
|
||||
break;
|
||||
}
|
||||
|
||||
scp++;
|
||||
|
||||
if (c == '\'') {
|
||||
for ( ; ; ) {
|
||||
c = *scp++;
|
||||
if (c == '\0') {
|
||||
if (readlineHacks != 0)
|
||||
break;
|
||||
/* Syntax error */
|
||||
(void) fprintf(stderr, "Error: Unbalanced quotes.\n");
|
||||
return (-1);
|
||||
}
|
||||
if (c == '\'')
|
||||
break;
|
||||
|
||||
/* Add char. */
|
||||
if (dcp >= dlim)
|
||||
goto toolong;
|
||||
*dcp++ = c;
|
||||
|
||||
if (strchr(kGlobChars, c) != NULL) {
|
||||
/* User quoted glob characters,
|
||||
* so mark this argument for
|
||||
* noglob.
|
||||
*/
|
||||
noglobargv[*cargc - 1] = 1;
|
||||
}
|
||||
}
|
||||
} else if (c == '"') {
|
||||
for ( ; ; ) {
|
||||
c = *scp++;
|
||||
if (c == '\0') {
|
||||
if (readlineHacks != 0)
|
||||
break;
|
||||
/* Syntax error */
|
||||
(void) fprintf(stderr, "Error: Unbalanced quotes.\n");
|
||||
return (-1);
|
||||
}
|
||||
if (c == '"')
|
||||
break;
|
||||
|
||||
/* Add char. */
|
||||
if (dcp >= dlim)
|
||||
goto toolong;
|
||||
*dcp++ = c;
|
||||
|
||||
if (strchr(kGlobChars, c) != NULL) {
|
||||
/* User quoted glob characters,
|
||||
* so mark this argument for
|
||||
* noglob.
|
||||
*/
|
||||
noglobargv[*cargc - 1] = 1;
|
||||
}
|
||||
}
|
||||
} else
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
if (c == '|') {
|
||||
#else
|
||||
if (c == '\\') {
|
||||
#endif
|
||||
/* Add next character, verbatim. */
|
||||
c = *scp++;
|
||||
if (c == '\0')
|
||||
break;
|
||||
|
||||
/* Add char. */
|
||||
if (dcp >= dlim)
|
||||
goto toolong;
|
||||
*dcp++ = c;
|
||||
} else {
|
||||
/* Add char. */
|
||||
if (dcp >= dlim)
|
||||
goto toolong;
|
||||
*dcp++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
*dcp++ = '\0';
|
||||
}
|
||||
|
||||
(void) fprintf(stderr, "Error: Argument list too long.\n");
|
||||
*cargc = 0;
|
||||
cargv[*cargc] = NULL;
|
||||
return (-1);
|
||||
|
||||
done:
|
||||
retval = (int) (scp - line);
|
||||
cargv[*cargc] = NULL;
|
||||
return (retval);
|
||||
|
||||
toolong:
|
||||
(void) fprintf(stderr, "Error: Line too long.\n");
|
||||
*cargc = 0;
|
||||
cargv[*cargc] = NULL;
|
||||
return (-1);
|
||||
} /* MakeArgv */
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
DoCommand(const ArgvInfoPtr aip)
|
||||
{
|
||||
CommandPtr cmdp;
|
||||
int flags;
|
||||
int cargc, cargcm1;
|
||||
|
||||
cmdp = GetCommandByName(aip->cargv[0], 0);
|
||||
if (cmdp == kAmbiguousCommand) {
|
||||
(void) printf("%s: ambiguous command name.\n", aip->cargv[0]);
|
||||
return (-1);
|
||||
} else if (cmdp == kNoCommand) {
|
||||
(void) printf("%s: no such command.\n", aip->cargv[0]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cargc = aip->cargc;
|
||||
cargcm1 = cargc - 1;
|
||||
flags = cmdp->flags;
|
||||
|
||||
if (((flags & kCmdMustBeConnected) != 0) && (gConn.connected == 0)) {
|
||||
(void) printf("%s: must be connected to do that.\n", aip->cargv[0]);
|
||||
} else if (((flags & kCmdMustBeDisconnected) != 0) && (gConn.connected != 0)) {
|
||||
(void) printf("%s: must be disconnected to do that.\n", aip->cargv[0]);
|
||||
} else if ((cmdp->minargs != kNoMin) && (cmdp->minargs > cargcm1)) {
|
||||
PrintCmdUsage(cmdp);
|
||||
} else if ((cmdp->maxargs != kNoMax) && (cmdp->maxargs < cargcm1)) {
|
||||
PrintCmdUsage(cmdp);
|
||||
} else {
|
||||
(*cmdp->proc)(cargc, aip->cargv, cmdp, aip);
|
||||
}
|
||||
return (0);
|
||||
} /* DoCommand */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Allows the user to cancel a data transfer. */
|
||||
void
|
||||
XferCanceller(int sigNum)
|
||||
{
|
||||
gGotSig = sigNum;
|
||||
if (gConn.cancelXfer > 0) {
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
signal(SIGINT, SIG_DFL);
|
||||
#else
|
||||
/* User already tried it once, they
|
||||
* must think it's locked up.
|
||||
*
|
||||
* Jump back to the top, and
|
||||
* close down the current session.
|
||||
*/
|
||||
gCancelCtrl = 1;
|
||||
if (gMayBackToTopJmp > 0) {
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
siglongjmp(gBackToTopJmp, 1);
|
||||
#else /* HAVE_SIGSETJMP */
|
||||
longjmp(gBackToTopJmp, 1);
|
||||
#endif /* HAVE_SIGSETJMP */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
gConn.cancelXfer++;
|
||||
} /* XferCanceller */
|
||||
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
|
||||
/* Allows the user to cancel a long operation and get back to the shell. */
|
||||
void
|
||||
BackToTop(int sigNum)
|
||||
{
|
||||
gGotSig = sigNum;
|
||||
if (sigNum == SIGPIPE) {
|
||||
if (gRunningCommand == 1) {
|
||||
(void) fprintf(stderr, "Unexpected broken pipe.\n");
|
||||
gRunningCommand = 0;
|
||||
} else {
|
||||
SetXtermTitle("RESTORE");
|
||||
exit(1);
|
||||
}
|
||||
} else if (sigNum == SIGINT) {
|
||||
if (gRunningCommand == 0)
|
||||
gDoneApplication = 1;
|
||||
}
|
||||
if (gMayBackToTopJmp > 0) {
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
siglongjmp(gBackToTopJmp, 1);
|
||||
#else /* HAVE_SIGSETJMP */
|
||||
longjmp(gBackToTopJmp, 1);
|
||||
#endif /* HAVE_SIGSETJMP */
|
||||
}
|
||||
} /* BackToTop */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Some commands may want to jump back to the start too. */
|
||||
void
|
||||
Cancel(int sigNum)
|
||||
{
|
||||
if (gMayCancelJmp != 0) {
|
||||
gGotSig = sigNum;
|
||||
gMayCancelJmp = 0;
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
siglongjmp(gCancelJmp, 1);
|
||||
#else /* HAVE_SIGSETJMP */
|
||||
longjmp(gCancelJmp, 1);
|
||||
#endif /* HAVE_SIGSETJMP */
|
||||
}
|
||||
} /* Cancel */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void
|
||||
CommandShell(void)
|
||||
{
|
||||
int tUsed, bUsed;
|
||||
ArgvInfo ai;
|
||||
char prompt[64];
|
||||
char *lineRead;
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
int sj;
|
||||
#endif
|
||||
time_t cmdStart, cmdStop;
|
||||
|
||||
/* Execution may jump back to this point to restart the shell. */
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
|
||||
#elif defined(HAVE_SIGSETJMP)
|
||||
sj = sigsetjmp(gBackToTopJmp, 1);
|
||||
#else /* HAVE_SIGSETJMP */
|
||||
sj = setjmp(gBackToTopJmp);
|
||||
#endif /* HAVE_SIGSETJMP */
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
if (sj != 0) {
|
||||
Trace(0, "Caught signal %d, back at top.\n", gGotSig);
|
||||
if (gGotSig == SIGALRM) {
|
||||
(void) printf("\nRemote host was not responding, closing down the session.");
|
||||
FTPShutdownHost(&gConn);
|
||||
} else{
|
||||
(void) printf("\nInterrupted.\n");
|
||||
if (gCancelCtrl != 0) {
|
||||
gCancelCtrl = 0;
|
||||
(void) printf("Closing down the current FTP session: ");
|
||||
FTPShutdownHost(&gConn);
|
||||
(void) sleep(1);
|
||||
(void) printf("done.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gMayBackToTopJmp = 1;
|
||||
#endif
|
||||
|
||||
|
||||
++gEventNumber;
|
||||
|
||||
while (gDoneApplication == 0) {
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
(void) NcSignal(SIGINT, BackToTop);
|
||||
(void) NcSignal(SIGPIPE, BackToTop);
|
||||
(void) NcSignal(SIGALRM, BackToTop);
|
||||
#endif
|
||||
|
||||
MakePrompt(prompt, sizeof(prompt));
|
||||
|
||||
if (gConn.connected == 0) {
|
||||
SetXtermTitle("DEFAULT");
|
||||
} else {
|
||||
SetXtermTitle("%s - NcFTP", gConn.host);
|
||||
}
|
||||
|
||||
lineRead = Readline(prompt);
|
||||
if (lineRead == NULL) {
|
||||
/* EOF, Control-D */
|
||||
(void) printf("\n");
|
||||
break;
|
||||
}
|
||||
Trace(0, "> %s\n", lineRead);
|
||||
AddHistory(lineRead);
|
||||
for (tUsed = 0;;) {
|
||||
(void) memset(&ai, 0, sizeof(ai));
|
||||
bUsed = MakeArgv(lineRead + tUsed, &ai.cargc, ai.cargv,
|
||||
(int) (sizeof(ai.cargv) / sizeof(char *)),
|
||||
ai.argbuf, sizeof(ai.argbuf),
|
||||
ai.noglobargv, 0);
|
||||
if (bUsed <= 0)
|
||||
break;
|
||||
tUsed += bUsed;
|
||||
if (ai.cargc == 0)
|
||||
continue;
|
||||
gRunningCommand = 1;
|
||||
(void) time(&cmdStart);
|
||||
if (DoCommand(&ai) < 0) {
|
||||
(void) time(&cmdStop);
|
||||
gRunningCommand = 0;
|
||||
break;
|
||||
}
|
||||
(void) time(&cmdStop);
|
||||
gRunningCommand = 0;
|
||||
if ((cmdStop - cmdStart) > kBeepAfterCmdTime) {
|
||||
/* Let the user know that a time-consuming
|
||||
* operation has completed.
|
||||
*/
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
MessageBeep(MB_OK);
|
||||
#else
|
||||
(void) fprintf(stderr, "\007");
|
||||
#endif
|
||||
}
|
||||
++gEventNumber;
|
||||
}
|
||||
|
||||
free(lineRead);
|
||||
}
|
||||
|
||||
CloseHost();
|
||||
gMayBackToTopJmp = 0;
|
||||
} /* Shell */
|
|
@ -1,78 +0,0 @@
|
|||
/* shell.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct ArgvInfo {
|
||||
const char *cargv[64];
|
||||
int noglobargv[64];
|
||||
int cargc;
|
||||
char argbuf[256];
|
||||
} ArgvInfo, *ArgvInfoPtr;
|
||||
|
||||
/* How often to no-op the remote site if the user is idle, in seconds. */
|
||||
#define kIdleInterval 20
|
||||
|
||||
/* If the user has been idle this many seconds, start their background
|
||||
* jobs.
|
||||
*/
|
||||
#define kIdleBatchLaunch 180
|
||||
|
||||
/* If a command (like a transfer) took longer than this many seconds, beep
|
||||
* at the user to notify them that it completed.
|
||||
*/
|
||||
#define kBeepAfterCmdTime 15
|
||||
|
||||
typedef struct Command *CommandPtr;
|
||||
typedef void (*CmdProc)(const int argc, const char **const argv, const CommandPtr cmdp, const ArgvInfoPtr aip);
|
||||
|
||||
/* These are used in the command table, to specify that a command
|
||||
* doesn't require an exact number of parameters.
|
||||
*/
|
||||
#define kNoMax (-1)
|
||||
#define kNoMin (-1)
|
||||
|
||||
/* Structure of the command table. We keep some extra stuff in the
|
||||
* table, so each command doesn't have to check the number of
|
||||
* arguments and print it's own usage messages if it doesn't want to.
|
||||
*/
|
||||
typedef struct Command {
|
||||
const char *name;
|
||||
CmdProc proc;
|
||||
const char *usage, *help;
|
||||
int flags;
|
||||
int minargs, maxargs;
|
||||
} Command;
|
||||
|
||||
/* Parameter to GetCommandOrMacro(). */
|
||||
#define kAbbreviatedMatchAllowed 0
|
||||
#define kExactMatchRequired 1
|
||||
|
||||
/* These can be returned by the GetCommand() routine. */
|
||||
#define kAmbiguousCommand ((CommandPtr) -1)
|
||||
#define kNoCommand ((CommandPtr) 0)
|
||||
|
||||
/* Command flag bits. */
|
||||
#define kCmdHidden 00001
|
||||
#define kCmdMustBeConnected 00002
|
||||
#define kCmdMustBeDisconnected 00004
|
||||
#define kCompleteRemoteFile 00010
|
||||
#define kCompleteRemoteDir 00020
|
||||
#define kCompleteLocalFile 00040
|
||||
#define kCompleteLocalDir 00100
|
||||
#define kCompleteBookmark 00200
|
||||
#define kCompletePrefOpt 00400
|
||||
|
||||
/* shell.c */
|
||||
void InitCommandList(void);
|
||||
CommandPtr GetCommandByIndex(const int);
|
||||
CommandPtr GetCommandByName(const char *const, int);
|
||||
void PrintCmdHelp(CommandPtr);
|
||||
void PrintCmdUsage(CommandPtr);
|
||||
int MakeArgv(char *, int *, const char **, int, char *, size_t, int *, int);
|
||||
void XferCanceller(int);
|
||||
void BackToTop(int);
|
||||
void Cancel(int);
|
||||
void CommandShell(void);
|
|
@ -1,496 +0,0 @@
|
|||
/* spool.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#ifdef HAVE_LONG_FILE_NAMES
|
||||
|
||||
#include "spool.h"
|
||||
#ifdef ncftp
|
||||
# include "trace.h"
|
||||
#endif
|
||||
#include "util.h"
|
||||
|
||||
int gSpoolSerial = 0;
|
||||
int gUnprocessedJobs = 0;
|
||||
int gJobs = 0;
|
||||
int gHaveSpool = -1;
|
||||
|
||||
extern FTPLibraryInfo gLib;
|
||||
extern char gOurDirectoryPath[], gOurInstallationPath[];
|
||||
extern void CloseControlConnection(const FTPCIPtr);
|
||||
|
||||
|
||||
|
||||
void
|
||||
TruncBatchLog(void)
|
||||
{
|
||||
char f[256];
|
||||
struct stat st;
|
||||
time_t t;
|
||||
int fd;
|
||||
|
||||
if (gOurDirectoryPath[0] != '\0') {
|
||||
time(&t);
|
||||
t -= 86400;
|
||||
(void) OurDirectoryPath(f, sizeof(f), kSpoolLog);
|
||||
if ((stat(f, &st) == 0) && (st.st_mtime < t)) {
|
||||
/* Truncate old log file.
|
||||
* Do not remove it, since a process
|
||||
* could still conceivably be going.
|
||||
*/
|
||||
fd = open(f, O_WRONLY|O_TRUNC, 00600);
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
} /* TruncBatchLog */
|
||||
|
||||
|
||||
|
||||
int
|
||||
MkSpoolDir(char *sdir, size_t size)
|
||||
{
|
||||
struct stat st;
|
||||
*sdir = '\0';
|
||||
|
||||
/* Don't create in root directory. */
|
||||
if (gOurDirectoryPath[0] != '\0') {
|
||||
(void) OurDirectoryPath(sdir, size, kSpoolDir);
|
||||
if ((stat(sdir, &st) < 0) && (MkDirs(sdir, 00700) < 0)) {
|
||||
perror(sdir);
|
||||
return (-1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (-1);
|
||||
} /* MkSpoolDir */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SpoolName(const char *const sdir, char *sp, size_t size, int flag, int serial, time_t when)
|
||||
{
|
||||
char sname[64];
|
||||
char dstr[32];
|
||||
struct tm *ltp;
|
||||
|
||||
if ((when == (time_t) 0) || (when == (time_t) -1))
|
||||
(void) time(&when);
|
||||
ltp = localtime(&when);
|
||||
if (ltp == NULL) {
|
||||
/* impossible */
|
||||
(void) Strncpy(dstr, "19700101-000000", size);
|
||||
} else {
|
||||
(void) strftime(dstr, sizeof(dstr), "%Y%m%d-%H%M%S", ltp);
|
||||
}
|
||||
(void) Strncpy(sp, sdir, size);
|
||||
(void) sprintf(sname, "/%c-%010u-%04x-%s",
|
||||
flag,
|
||||
(unsigned int) getpid(),
|
||||
(serial % (16 * 16 * 16 * 16)),
|
||||
dstr
|
||||
);
|
||||
(void) Strncat(sp, sname, size);
|
||||
} /* SpoolName */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
HaveSpool(void)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
char ncftpbatch[260];
|
||||
|
||||
if (gHaveSpool < 0) {
|
||||
gHaveSpool = 0;
|
||||
if (gOurInstallationPath[0] != '\0') {
|
||||
OurInstallationPath(ncftpbatch, sizeof(ncftpbatch), "ncftpbatch.exe");
|
||||
gHaveSpool = (access(ncftpbatch, F_OK) == 0) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
#elif defined(BINDIR)
|
||||
char ncftpbatch[256];
|
||||
|
||||
if (gHaveSpool < 0) {
|
||||
STRNCPY(ncftpbatch, BINDIR);
|
||||
STRNCAT(ncftpbatch, "/");
|
||||
STRNCAT(ncftpbatch, "ncftpbatch");
|
||||
gHaveSpool = (access(ncftpbatch, X_OK) == 0) ? 1 : 0;
|
||||
}
|
||||
#else /* BINDIR */
|
||||
if (gHaveSpool < 0) {
|
||||
if (geteuid() == 0) {
|
||||
gHaveSpool = (access("/usr/bin/ncftpbatch", X_OK) == 0) ? 1 : 0;
|
||||
} else {
|
||||
gHaveSpool = (system("ncftpbatch -X") == 0) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
#endif /* BINDIR */
|
||||
|
||||
return (gHaveSpool);
|
||||
} /* HaveSpool */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
CanSpool(void)
|
||||
{
|
||||
char sdir[256];
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0') {
|
||||
return (-1);
|
||||
}
|
||||
if (MkSpoolDir(sdir, sizeof(sdir)) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
} /* CanSpool */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SpoolX(
|
||||
const char *const op,
|
||||
const char *const rfile,
|
||||
const char *const rdir,
|
||||
const char *const lfile,
|
||||
const char *const ldir,
|
||||
const char *const host,
|
||||
const char *const ip,
|
||||
const unsigned int port,
|
||||
const char *const user,
|
||||
const char *const passclear,
|
||||
int xtype,
|
||||
int recursive,
|
||||
int delete,
|
||||
int passive,
|
||||
const char *const precmd,
|
||||
const char *const perfilecmd,
|
||||
const char *const postcmd,
|
||||
time_t when)
|
||||
{
|
||||
char sdir[256];
|
||||
char pass[160];
|
||||
char spathname[256];
|
||||
char spathname2[256];
|
||||
char ldir2[256];
|
||||
FILE *fp;
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
mode_t um;
|
||||
#endif
|
||||
|
||||
if (MkSpoolDir(sdir, sizeof(sdir)) < 0)
|
||||
return (-1);
|
||||
|
||||
gSpoolSerial++;
|
||||
SpoolName(sdir, spathname2, sizeof(spathname2), op[0], gSpoolSerial, when);
|
||||
SpoolName(sdir, spathname, sizeof(spathname), 'z', gSpoolSerial, when);
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
fp = fopen(spathname, FOPEN_WRITE_TEXT);
|
||||
#else
|
||||
um = umask(077);
|
||||
fp = fopen(spathname, FOPEN_WRITE_TEXT);
|
||||
(void) umask(um);
|
||||
#endif
|
||||
if (fp == NULL)
|
||||
return (-1);
|
||||
|
||||
if (fprintf(fp, "# This is a NcFTP spool file entry.\n# Run the \"ncftpbatch\" program to process the spool directory.\n#\n") < 0)
|
||||
goto err;
|
||||
if (fprintf(fp, "op=%s\n", op) < 0)
|
||||
goto err;
|
||||
if (fprintf(fp, "hostname=%s\n", host) < 0)
|
||||
goto err;
|
||||
if ((ip != NULL) && (ip[0] != '\0') && (fprintf(fp, "host-ip=%s\n", ip) < 0))
|
||||
goto err;
|
||||
if ((port > 0) && (port != (unsigned int) kDefaultFTPPort) && (fprintf(fp, "port=%u\n", port) < 0))
|
||||
goto err;
|
||||
if ((user != NULL) && (user[0] != '\0') && (strcmp(user, "anonymous") != 0) && (fprintf(fp, "user=%s\n", user) < 0))
|
||||
goto err;
|
||||
if ((strcmp(user, "anonymous") != 0) && (passclear != NULL) && (passclear[0] != '\0')) {
|
||||
(void) memcpy(pass, kPasswordMagic, kPasswordMagicLen);
|
||||
ToBase64(pass + kPasswordMagicLen, passclear, strlen(passclear), 1);
|
||||
if (fprintf(fp, "pass=%s\n", pass) < 0)
|
||||
goto err;
|
||||
} else if ((strcmp(user, "anonymous") == 0) && (gLib.defaultAnonPassword[0] != '\0')) {
|
||||
if (fprintf(fp, "anon-pass=%s\n", gLib.defaultAnonPassword) < 0)
|
||||
goto err;
|
||||
}
|
||||
if (fprintf(fp, "xtype=%c\n", xtype) < 0)
|
||||
goto err;
|
||||
if ((recursive != 0) && (fprintf(fp, "recursive=%s\n", YESNO(recursive)) < 0))
|
||||
goto err;
|
||||
if ((delete != 0) && (fprintf(fp, "delete=%s\n", YESNO(delete)) < 0))
|
||||
goto err;
|
||||
if (fprintf(fp, "passive=%d\n", passive) < 0)
|
||||
goto err;
|
||||
if (fprintf(fp, "remote-dir=%s\n", rdir) < 0)
|
||||
goto err;
|
||||
if ((ldir == NULL) || (ldir[0] == '\0') || (strcmp(ldir, ".") == 0)) {
|
||||
/* Use current process' working directory. */
|
||||
FTPGetLocalCWD(ldir2, sizeof(ldir2));
|
||||
if (fprintf(fp, "local-dir=%s\n", ldir2) < 0)
|
||||
goto err;
|
||||
} else {
|
||||
if (fprintf(fp, "local-dir=%s\n", ldir) < 0)
|
||||
goto err;
|
||||
}
|
||||
if (fprintf(fp, "remote-file=%s\n", rfile) < 0)
|
||||
goto err;
|
||||
if (fprintf(fp, "local-file=%s\n", lfile) < 0)
|
||||
goto err;
|
||||
if ((precmd != NULL) && (precmd[0] != '\0') && (fprintf(fp, "pre-command=%s\n", precmd) < 0))
|
||||
goto err;
|
||||
if ((perfilecmd != NULL) && (perfilecmd[0] != '\0') && (fprintf(fp, "per-file-command=%s\n", perfilecmd) < 0))
|
||||
goto err;
|
||||
if ((postcmd != NULL) && (postcmd[0] != '\0') && (fprintf(fp, "post-command=%s\n", postcmd) < 0))
|
||||
goto err;
|
||||
|
||||
if (fclose(fp) < 0)
|
||||
goto err2;
|
||||
|
||||
/* Move the spool file into its "live" name. */
|
||||
if (rename(spathname, spathname2) < 0) {
|
||||
perror("rename spoolfile failed");
|
||||
goto err3;
|
||||
}
|
||||
gUnprocessedJobs++;
|
||||
return (0);
|
||||
|
||||
err:
|
||||
(void) fclose(fp);
|
||||
err2:
|
||||
perror("write to spool file failed");
|
||||
err3:
|
||||
(void) unlink(spathname);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
static int
|
||||
PWrite(int sfd, const char *const buf0, size_t size)
|
||||
{
|
||||
int nleft;
|
||||
const char *buf = buf0;
|
||||
int nwrote;
|
||||
|
||||
nleft = (int) size;
|
||||
for (;;) {
|
||||
nwrote = (int) write(sfd, buf, nleft);
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = (int) size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
return (nwrote);
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
}
|
||||
nwrote = (int) size - nleft;
|
||||
return (nwrote);
|
||||
} /* PWrite */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void
|
||||
Jobs(void)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
assert(0); // Not supported
|
||||
#else
|
||||
char *argv[8];
|
||||
pid_t pid;
|
||||
#ifdef BINDIR
|
||||
char ncftpbatch[256];
|
||||
|
||||
STRNCPY(ncftpbatch, BINDIR);
|
||||
STRNCAT(ncftpbatch, "/");
|
||||
STRNCAT(ncftpbatch, "ncftpbatch");
|
||||
#endif /* BINDIR */
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
} else if (pid == 0) {
|
||||
argv[0] = (char *) "ncftpbatch";
|
||||
argv[1] = (char *) "-l";
|
||||
argv[2] = NULL;
|
||||
|
||||
#ifdef BINDIR
|
||||
(void) execv(ncftpbatch, argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
|
||||
#else /* BINDIR */
|
||||
(void) execvp(argv[0], argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
|
||||
#endif /* BINDIR */
|
||||
perror(argv[0]);
|
||||
exit(1);
|
||||
} else {
|
||||
#ifdef HAVE_WAITPID
|
||||
(void) waitpid(pid, NULL, 0);
|
||||
#else
|
||||
(void) wait(NULL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
} /* Jobs */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
RunBatch(int Xstruct, const FTPCIPtr cip)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
char ncftpbatch[260];
|
||||
const char *prog;
|
||||
int winExecResult;
|
||||
|
||||
if (gOurInstallationPath[0] == '\0') {
|
||||
(void) fprintf(stderr, "Cannot find path to %s. Please re-run Setup.\n", "ncftpbatch.exe");
|
||||
return;
|
||||
}
|
||||
prog = ncftpbatch;
|
||||
OurInstallationPath(ncftpbatch, sizeof(ncftpbatch), "ncftpbatch.exe");
|
||||
|
||||
winExecResult = WinExec(prog, SW_SHOWNORMAL);
|
||||
if (winExecResult <= 31) switch (winExecResult) {
|
||||
case ERROR_BAD_FORMAT:
|
||||
fprintf(stderr, "Could not run %s: %s\n", prog, "The .EXE file is invalid");
|
||||
return;
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
fprintf(stderr, "Could not run %s: %s\n", prog, "The specified file was not found.");
|
||||
return;
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
fprintf(stderr, "Could not run %s: %s\n", prog, "The specified path was not found.");
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr, "Could not run %s: Unknown error #%d.\n", prog, winExecResult);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int pfd[2];
|
||||
char pfdstr[32];
|
||||
char *argv[8];
|
||||
pid_t pid = 0;
|
||||
#ifdef BINDIR
|
||||
char ncftpbatch[256];
|
||||
|
||||
STRNCPY(ncftpbatch, BINDIR);
|
||||
STRNCAT(ncftpbatch, "/");
|
||||
STRNCAT(ncftpbatch, "ncftpbatch");
|
||||
#endif /* BINDIR */
|
||||
|
||||
if (Xstruct != 0) {
|
||||
if (pipe(pfd) < 0) {
|
||||
perror("pipe");
|
||||
}
|
||||
|
||||
(void) sprintf(pfdstr, "%d", pfd[0]);
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
(void) close(pfd[0]);
|
||||
(void) close(pfd[1]);
|
||||
perror("fork");
|
||||
} else if (pid == 0) {
|
||||
(void) close(pfd[1]); /* Child closes write end. */
|
||||
argv[0] = (char *) "ncftpbatch";
|
||||
#ifdef DEBUG_NCFTPBATCH
|
||||
argv[1] = (char *) "-SD";
|
||||
#else
|
||||
argv[1] = (char *) "-d";
|
||||
#endif
|
||||
argv[2] = (char *) "-|";
|
||||
argv[3] = pfdstr;
|
||||
argv[4] = NULL;
|
||||
|
||||
#ifdef BINDIR
|
||||
(void) execv(ncftpbatch, argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
|
||||
#else /* BINDIR */
|
||||
(void) execvp(argv[0], argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
|
||||
#endif /* BINDIR */
|
||||
perror(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
(void) close(pfd[0]); /* Parent closes read end. */
|
||||
(void) PWrite(pfd[1], (const char *) cip->lip, sizeof(FTPLibraryInfo));
|
||||
(void) PWrite(pfd[1], (const char *) cip, sizeof(FTPConnectionInfo));
|
||||
(void) close(pfd[1]); /* Parent closes read end. */
|
||||
|
||||
/* Close it now, or else this process would send
|
||||
* the server a QUIT message. This will cause it
|
||||
* to think it already has.
|
||||
*/
|
||||
CloseControlConnection(cip);
|
||||
} else {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
} else if (pid == 0) {
|
||||
argv[0] = (char *) "ncftpbatch";
|
||||
argv[1] = (char *) "-d";
|
||||
argv[2] = NULL;
|
||||
#ifdef BINDIR
|
||||
(void) execv(ncftpbatch, argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
|
||||
#else /* BINDIR */
|
||||
(void) execvp(argv[0], argv);
|
||||
(void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
|
||||
#endif /* BINDIR */
|
||||
perror(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (pid > 1) {
|
||||
#ifdef HAVE_WAITPID
|
||||
(void) waitpid(pid, NULL, 0);
|
||||
#else
|
||||
(void) wait(NULL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
} /* RunBatch */
|
||||
|
||||
|
||||
|
||||
void
|
||||
RunBatchIfNeeded(const FTPCIPtr cip)
|
||||
{
|
||||
if (gUnprocessedJobs > 0) {
|
||||
#ifdef ncftp
|
||||
Trace(0, "Running ncftp_batch for %d job%s.\n", gUnprocessedJobs, gUnprocessedJobs > 0 ? "s" : "");
|
||||
gUnprocessedJobs = 0;
|
||||
RunBatch(1, cip);
|
||||
#else
|
||||
gUnprocessedJobs = 0;
|
||||
RunBatch(0, cip);
|
||||
#endif
|
||||
}
|
||||
} /* RunBatchIfNeeded */
|
||||
|
||||
#endif /* HAVE_LONG_FILE_NAMES */
|
|
@ -1,24 +0,0 @@
|
|||
/* spool.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#define kSpoolDir "spool"
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kSpoolLog "batchlog.txt"
|
||||
#else
|
||||
# define kSpoolLog "batchlog"
|
||||
#endif
|
||||
|
||||
/* spool.c */
|
||||
void TruncBatchLog(void);
|
||||
int MkSpoolDir(char *, size_t);
|
||||
void SpoolName(const char *const, char *, size_t, int, int, time_t);
|
||||
int CanSpool(void);
|
||||
int HaveSpool(void);
|
||||
int SpoolX(const char *const, const char *const, const char *const, const char *const, const char *const, const char *const, const char *const, const unsigned int, const char *const, const char *const, int, int, int, int, const char *const, const char *const, const char *const, time_t);
|
||||
void RunBatch(int, const FTPCIPtr);
|
||||
void Jobs(void);
|
||||
void RunBatchIfNeeded(const FTPCIPtr);
|
|
@ -1,194 +0,0 @@
|
|||
/* syshdrs.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define SELECT_TYPE_ARG1 int
|
||||
# define SELECT_TYPE_ARG234 (fd_set *)
|
||||
# define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
# define STDC_HEADERS 1
|
||||
# define HAVE_GETHOSTNAME 1
|
||||
# define HAVE_MKTIME 1
|
||||
# define HAVE_SOCKET 1
|
||||
# define HAVE_STRSTR 1
|
||||
# define HAVE_MEMMOVE 1
|
||||
# define HAVE_LONG_FILE_NAMES 1
|
||||
# include <winsock2.h> /* Includes <windows.h> */
|
||||
//# include <shlobj.h>
|
||||
# ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# include <errno.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
# endif
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <stdarg.h>
|
||||
# include <time.h>
|
||||
# include <io.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
# include <signal.h>
|
||||
# include <assert.h>
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# define sleep WinSleep
|
||||
# ifndef S_ISREG
|
||||
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
||||
# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
||||
# endif
|
||||
# ifndef open
|
||||
# define open _open
|
||||
# define write _write
|
||||
# define read _read
|
||||
# define close _close
|
||||
# define lseek _lseek
|
||||
# define stat _stat
|
||||
# define lstat _stat
|
||||
# define fstat _fstat
|
||||
# define dup _dup
|
||||
# define utime _utime
|
||||
# define utimbuf _utimbuf
|
||||
# define chdir _chdir
|
||||
# define rmdir _rmdir
|
||||
# define getpid _getpid
|
||||
# define popen _popen
|
||||
# define pclose _pclose
|
||||
# endif
|
||||
# ifndef unlink
|
||||
# define unlink remove
|
||||
# endif
|
||||
# define uid_t int
|
||||
# define NO_SIGNALS 1
|
||||
# define USE_SIO 1
|
||||
# ifndef FOPEN_READ_TEXT
|
||||
# define FOPEN_READ_TEXT "rt"
|
||||
# define FOPEN_WRITE_TEXT "wt"
|
||||
# define FOPEN_APPEND_TEXT "at"
|
||||
# endif
|
||||
#else /* UNIX */
|
||||
# if defined(AIX) || defined(_AIX)
|
||||
# define _ALL_SOURCE 1
|
||||
# endif
|
||||
# ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/wait.h>
|
||||
# ifdef CAN_USE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
# endif
|
||||
# if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
|
||||
# include <sys/utsname.h>
|
||||
# endif
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <netdb.h>
|
||||
# include <errno.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
# endif
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <setjmp.h>
|
||||
# include <stdarg.h>
|
||||
# include <assert.h>
|
||||
# include <time.h>
|
||||
# include <pwd.h>
|
||||
# include <fcntl.h>
|
||||
# if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H)
|
||||
# include <sys/ioctl.h>
|
||||
# include <termios.h>
|
||||
# endif
|
||||
# ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
# endif
|
||||
# ifdef HAVE_GETCWD
|
||||
# ifndef HAVE_UNISTD_H
|
||||
extern char *getcwd();
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAVE_GETWD
|
||||
# include <sys/param.h>
|
||||
# ifndef MAXPATHLEN
|
||||
# define MAXPATHLEN 1024
|
||||
# endif
|
||||
extern char *getwd(char *);
|
||||
# endif
|
||||
# endif
|
||||
# ifndef FOPEN_READ_TEXT
|
||||
# define FOPEN_READ_TEXT "r"
|
||||
# define FOPEN_WRITE_TEXT "w"
|
||||
# define FOPEN_APPEND_TEXT "a"
|
||||
# endif
|
||||
#endif /* UNIX */
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO 0
|
||||
# define STDOUT_FILENO 1
|
||||
# define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
#define NDEBUG 1 /* For assertions. */
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_OPEN64)
|
||||
# define Open open64
|
||||
#else
|
||||
# define Open open
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_STAT64) && defined(HAVE_STRUCT_STAT64)
|
||||
# define Stat stat64
|
||||
# ifdef HAVE_FSTAT64
|
||||
# define Fstat fstat64
|
||||
# else
|
||||
# define Fstat fstat
|
||||
# endif
|
||||
# ifdef HAVE_LSTAT64
|
||||
# define Lstat lstat64
|
||||
# else
|
||||
# define Lstat lstat
|
||||
# endif
|
||||
#else
|
||||
# define Stat stat
|
||||
# define Fstat fstat
|
||||
# define Lstat lstat
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LONG_LONG) && defined(HAVE_LSEEK64)
|
||||
# define Lseek(a,b,c) lseek64(a, (longest_int) b, c)
|
||||
#elif defined(HAVE_LONG_LONG) && defined(HAVE_LLSEEK)
|
||||
# if 1
|
||||
# if defined(LINUX) && (LINUX <= 23000)
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
# else
|
||||
# define Lseek(a,b,c) llseek(a, (longest_int) b, c)
|
||||
# endif
|
||||
# else
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
# endif
|
||||
#else
|
||||
# define Lseek(a,b,c) lseek(a, (off_t) b, c)
|
||||
#endif
|
||||
|
||||
|
||||
#include "Strn\Strn.h" /* Library header. */
|
||||
#include "libncftp\ncftp.h" /* Library header. */
|
|
@ -1,178 +0,0 @@
|
|||
/* trace.c
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syshdrs.h"
|
||||
|
||||
#include "trace.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Saves their session in a ~/.ncftp/trace file.
|
||||
* This is nice for me when I need to diagnose problems.
|
||||
*/
|
||||
time_t gTraceTime;
|
||||
FILE *gTraceFile = NULL;
|
||||
char gTraceLBuf[256];
|
||||
int gDebug = 0;
|
||||
|
||||
extern FTPLibraryInfo gLib;
|
||||
extern FTPConnectionInfo gConn;
|
||||
extern char gVersion[], gOS[];
|
||||
extern char gOurDirectoryPath[];
|
||||
|
||||
|
||||
|
||||
/*VARARGS*/
|
||||
void
|
||||
Trace(const int level, const char *const fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[512];
|
||||
struct tm *ltp;
|
||||
|
||||
if ((gDebug >= level) || (level > 8)) {
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_VSNPRINTF
|
||||
(void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
#else
|
||||
(void) vsprintf(buf, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
(void) time(&gTraceTime);
|
||||
ltp = localtime(&gTraceTime);
|
||||
if ((gTraceFile != NULL) && (ltp != NULL)) {
|
||||
(void) fprintf(gTraceFile , "%02d:%02d:%02d %s",
|
||||
ltp->tm_hour,
|
||||
ltp->tm_min,
|
||||
ltp->tm_sec,
|
||||
buf
|
||||
);
|
||||
}
|
||||
if (gDebug > level) {
|
||||
(void) fprintf(stdout, "%s", buf);
|
||||
}
|
||||
}
|
||||
} /* Trace */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
ErrorHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
|
||||
|
||||
/* Will also get Trace'd. */
|
||||
(void) fprintf(stdout, "%s", msg);
|
||||
} /* ErrorHook */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
DebugHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
|
||||
{
|
||||
LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
|
||||
Trace(0, "%s", msg);
|
||||
} /* DebugHook */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SetDebug(int i)
|
||||
{
|
||||
gDebug = i;
|
||||
} /* SetDebug */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
UseTrace(void)
|
||||
{
|
||||
gConn.debugLogProc = DebugHook;
|
||||
gConn.debugLog = NULL;
|
||||
gConn.errLogProc = ErrorHook;
|
||||
gConn.errLog = NULL;
|
||||
} /* UseTrace */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
OpenTrace(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char pathName[256];
|
||||
char tName[32];
|
||||
int pid;
|
||||
const char *cp;
|
||||
#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
|
||||
struct utsname u;
|
||||
#endif
|
||||
|
||||
if (gOurDirectoryPath[0] == '\0')
|
||||
return; /* Don't create in root directory. */
|
||||
|
||||
(void) sprintf(tName, "trace.%u", (unsigned int) (pid = getpid()));
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), tName);
|
||||
|
||||
fp = fopen(pathName, FOPEN_WRITE_TEXT);
|
||||
if (fp != NULL) {
|
||||
(void) chmod(pathName, 00600);
|
||||
#ifdef HAVE_SETVBUF
|
||||
(void) setvbuf(fp, gTraceLBuf, _IOLBF, sizeof(gTraceLBuf));
|
||||
#endif /* HAVE_SETVBUF */
|
||||
/* Opened the trace file. */
|
||||
(void) time(&gTraceTime);
|
||||
(void) fprintf(fp, "SESSION STARTED at: %s", ctime(&gTraceTime));
|
||||
(void) fprintf(fp, " Program Version: %s\n", gVersion + 5);
|
||||
(void) fprintf(fp, " Library Version: %s\n", gLibNcFTPVersion + 5);
|
||||
(void) fprintf(fp, " Process ID: %u\n", pid);
|
||||
if (gOS[0] != '\0')
|
||||
(void) fprintf(fp, " Platform: %s\n", gOS);
|
||||
#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
|
||||
if (uname(&u) == 0) {
|
||||
(void) fprintf(fp, " Uname: %.63s|%.63s|%.63s|%.63s|%.63s\r\n", u.sysname, u.nodename, u.release, u.version, u.machine);
|
||||
}
|
||||
#endif /* UNAME */
|
||||
FTPInitializeOurHostName(&gLib);
|
||||
(void) fprintf(fp, " Hostname: %s (rc=%d)\n", gLib.ourHostName, gLib.hresult);
|
||||
cp = (const char *) getenv("TERM");
|
||||
if (cp == NULL)
|
||||
cp = "unknown?";
|
||||
(void) fprintf(fp, " Terminal: %s\n", cp);
|
||||
gTraceFile = fp;
|
||||
}
|
||||
} /* OpenTrace */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
CloseTrace(void)
|
||||
{
|
||||
char pathName[256];
|
||||
char pathName2[256];
|
||||
char tName[32];
|
||||
|
||||
if ((gOurDirectoryPath[0] == '\0') || (gTraceFile == NULL))
|
||||
return;
|
||||
|
||||
(void) sprintf(tName, "trace.%u", (unsigned int) getpid());
|
||||
(void) OurDirectoryPath(pathName, sizeof(pathName), tName);
|
||||
(void) OurDirectoryPath(pathName2, sizeof(pathName2), kTraceFileName);
|
||||
|
||||
(void) time(&gTraceTime);
|
||||
(void) fprintf(gTraceFile, "SESSION ENDED at: %s", ctime(&gTraceTime));
|
||||
(void) fclose(gTraceFile);
|
||||
|
||||
(void) unlink(pathName2);
|
||||
(void) rename(pathName, pathName2);
|
||||
} /* CloseTrace */
|
|
@ -1,25 +0,0 @@
|
|||
/* trace.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kTraceFileName "trace.txt"
|
||||
#else
|
||||
# define kTraceFileName "trace"
|
||||
#endif
|
||||
|
||||
/* trace.c */
|
||||
void Trace(const int, const char *const, ...)
|
||||
#if (defined(__GNUC__)) && (__GNUC__ >= 2)
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
void ErrorHook(const FTPCIPtr, char *);
|
||||
void DebugHook(const FTPCIPtr, char *);
|
||||
void SetDebug(int);
|
||||
void UseTrace(void);
|
||||
void OpenTrace(void);
|
||||
void CloseTrace(void);
|
File diff suppressed because it is too large
Load diff
|
@ -1,84 +0,0 @@
|
|||
/* util.h
|
||||
*
|
||||
* Copyright (c) 1992-2001 by Mike Gleason.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef int (*qsort_proc_t)(const void *, const void *);
|
||||
typedef int (*bsearch_proc_t)(const void *, const void *);
|
||||
typedef void (*sigproc_t)(int);
|
||||
typedef volatile sigproc_t vsigproc_t;
|
||||
|
||||
#define STREQ(a,b) (strcmp(a,b) == 0)
|
||||
#define STRNEQ(a,b,s) (strncmp(a,b,(size_t)(s)) == 0)
|
||||
|
||||
#ifndef ISTRCMP
|
||||
# ifdef HAVE_STRCASECMP
|
||||
# define ISTRCMP strcasecmp
|
||||
# define ISTRNCMP strncasecmp
|
||||
# else
|
||||
# define ISTRCMP strcmp
|
||||
# define ISTRNCMP strncmp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define ISTREQ(a,b) (ISTRCMP(a,b) == 0)
|
||||
#define ISTRNEQ(a,b,s) (ISTRNCMP(a,b,(size_t)(s)) == 0)
|
||||
#define YESNO(i) ((i == 0) ? "no" : "yes")
|
||||
#define ONOFF(i) ((i == 0) ? "off" : "on")
|
||||
#define TRUEFALSE(i) ((i == 0) ? "false" : "true")
|
||||
|
||||
#ifndef HAVE_STRCOLL
|
||||
# ifndef strcoll
|
||||
# define strcoll strcmp
|
||||
# endif
|
||||
# ifndef strncoll
|
||||
# define strncoll strncmp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef F_OK
|
||||
# define F_OK 0
|
||||
#endif
|
||||
|
||||
#define kOurDirectoryName ".ncftp"
|
||||
|
||||
#define kPasswordMagic "*encoded*"
|
||||
#define kPasswordMagicLen 9
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
# define kNcFTPBookmarksMailslot "\\\\.\\mailslot\\ncftpbm.slt"
|
||||
# define kNcFTPBookmarksMailslotMsgSize 128
|
||||
#endif
|
||||
|
||||
/* util.c */
|
||||
void ToBase64(void *, const void *, size_t, int);
|
||||
void FromBase64(void *, const void *, size_t, int);
|
||||
void OutOfMemory(void);
|
||||
void *Realloc(void *, size_t);
|
||||
char *GetCWD(char *, size_t);
|
||||
void MyInetAddr(char *, size_t, char **, int);
|
||||
struct hostent *GetHostEntry(const char *, struct in_addr *);
|
||||
void CompressPath(char *const dst, const char *const src, const size_t dsize);
|
||||
void PathCat(char *const dst, const size_t dsize, const char *const cwd, const char *const src);
|
||||
char *FileToURL(char *url, size_t urlsize, const char *const fn, const char *const rcwd, const char *const startdir, const char *const user, const char *const pass, const char *const hname, const unsigned int port);
|
||||
void AbbrevStr(char *, const char *, size_t, int);
|
||||
char *Path(char *const dst, const size_t siz, const char *const parent, const char *const fname);
|
||||
char *OurDirectoryPath(char *const dst, const size_t siz, const char *const fname);
|
||||
void InitOurDirectory(void);
|
||||
void InitUserInfo(void);
|
||||
int MayUseFirewall(const char *const, int, const char *const);
|
||||
int StrToBool(const char *const);
|
||||
void AbsoluteToRelative(char *const, const size_t, const char *const, const char *const, const size_t);
|
||||
int GetHostByName(char *const volatile, size_t, const char *const, int);
|
||||
time_t UnDate(char *dstr);
|
||||
int DecodeDirectoryURL(const FTPCIPtr, char *, LineListPtr, char *, size_t);
|
||||
char *OurInstallationPath(char *const dst, const size_t siz, const char *const fname);
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
void SysPerror(const char *const errMsg);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRCOLL) && !defined(HAVE_STRNCOLL)
|
||||
int strncoll(const char *a, const char *b, size_t n);
|
||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||
/******************************************************************************/
|
||||
|
||||
char gVersion[] = "@(#) NcFTP 3.0.3/635 April 15 2001, 05:49 PM ";
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef OS
|
||||
char gOS[] = OS;
|
||||
#elif defined(WIN32) || defined(_WINDOWS)
|
||||
char gOS[] = "Windows";
|
||||
#else
|
||||
char gOS[] = "";
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
char gCopyright[] = "@(#) \
|
||||
Copyright (c) 1992-2001 by Mike Gleason.\n\
|
||||
All rights reserved.\n\
|
||||
";
|
||||
|
||||
/******************************************************************************/
|
|
@ -1,194 +0,0 @@
|
|||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# SocketIO makefile for the platform @OS@, on the host @host@.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
VER=6.0.2
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@
|
||||
#CFLAGS=-O2 -g -W -Wall -Wimplicit -Wstrict-prototypes -Wmissing-prototypes
|
||||
VPATH=@srcdir@
|
||||
CPPFLAGS=@CPPFLAGS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
LIBS=@LIBS@
|
||||
DEFS=@DEFS@@NDEFS@
|
||||
PREFIX=@prefix@
|
||||
LIB=libsio.a
|
||||
LIBSO=libsio.so.5
|
||||
LIBSOS=libsio.so
|
||||
STRIP=strip
|
||||
|
||||
OBJS=\
|
||||
PRead.o PWrite.o SAcceptA.o SAcceptS.o \
|
||||
SBind.o SClose.o SConnect.o SConnectByName.o \
|
||||
SNew.o SRead.o SReadline.o SRecv.o \
|
||||
SRecvfrom.o SRecvmsg.o SSelect.o SSend.o \
|
||||
SSendto.o SSendtoByName.o SWrite.o SocketUtil.o \
|
||||
StrAddr.o UAcceptA.o UAcceptS.o UBind.o \
|
||||
UConnect.o UConnectByName.o UNew.o URecvfrom.o \
|
||||
USendto.o USendtoByName.o SError.o main.o \
|
||||
SWait.o
|
||||
|
||||
SOBJS=\
|
||||
PRead.so PWrite.so SAcceptA.so SAcceptS.so \
|
||||
SBind.so SClose.so SConnect.so SConnectByName.so \
|
||||
SNew.so SRead.so SReadline.so SRecv.so \
|
||||
SRecvfrom.so SRecvmsg.so SSelect.so SSend.so \
|
||||
SSendto.so SSendtoByName.so SWrite.so SocketUtil.so \
|
||||
StrAddr.so UAcceptA.so UAcceptS.so UBind.so \
|
||||
UConnect.so UConnectByName.so UNew.so URecvfrom.so \
|
||||
USendto.so USendtoByName.so SError.so main.so \
|
||||
SWait.so
|
||||
|
||||
all: $(LIB)
|
||||
-@/bin/ls -l $(LIB)
|
||||
-@echo 'Done.'
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
/bin/rm -f $(LIB)
|
||||
ar rv $(LIB) $(OBJS)
|
||||
-@RANLIB@ $(LIB)
|
||||
chmod a+r $(LIB) sio.h usio.h
|
||||
|
||||
install: $(LIB)
|
||||
cp $(LIB) $(PREFIX)/lib/$(LIB)
|
||||
cp sio.h usio.h $(PREFIX)/include
|
||||
chmod a+r $(PREFIX)/lib/$(LIB) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
|
||||
-@/bin/ls -l $(PREFIX)/lib/$(LIB) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
|
||||
|
||||
shared: $(LIBSO)
|
||||
|
||||
so: $(LIBSO)
|
||||
|
||||
$(LIBSO): $(SOBJS)
|
||||
/bin/rm -f $(LIBSO)
|
||||
gcc -shared -Wl,-soname,$(LIBSO) -o $(LIBSO) $(SOBJS)
|
||||
chmod a+r $(LIB) sio.h usio.h
|
||||
-@/bin/ls -l $(LIBSO)
|
||||
|
||||
soinstall: $(LIBSO)
|
||||
cp $(LIBSO) $(PREFIX)/lib/$(LIBSO)
|
||||
/bin/rm -f $(PREFIX)/lib/$(LIBSOS)
|
||||
( cd $(PREFIX)/lib ; /bin/ln -s $(LIBSO) $(LIBSOS) )
|
||||
cp sio.h usio.h $(PREFIX)/include
|
||||
chmod a+r $(PREFIX)/lib/$(LIBSO) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
|
||||
-@/bin/ls -l $(PREFIX)/lib/$(LIBSO) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
|
||||
|
||||
ucase_c: ucase_c/ucase_c.c $(LIB)
|
||||
( cd ucase_c ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )
|
||||
|
||||
ucase_s: ucase_s/ucase_s.c $(LIB)
|
||||
( cd ucase_s ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )
|
||||
|
||||
srltest: srltest/srltest.c $(LIB)
|
||||
( cd srltest ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )
|
||||
|
||||
time_c: time_c/time_c.c $(LIB)
|
||||
( cd time_c ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )
|
||||
|
||||
time_s: time_s/time_s.c $(LIB)
|
||||
( cd time_s ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )
|
||||
|
||||
samples: ucase_c ucase_s time_c time_s srltest
|
||||
|
||||
SHELL=/bin/sh
|
||||
.SUFFIXES: .c .o .so
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $< -c
|
||||
|
||||
.c.so:
|
||||
$(CC) -fpic $(CFLAGS) $(CPPFLAGS) $(DEFS) $*.c -c -o $*.so
|
||||
|
||||
### Cleaning supplies ########################################################
|
||||
|
||||
clean:
|
||||
-/bin/rm -f $(OBJS) $(SOBJS) $(LIB) $(LIBSO) ucase_c/ucase_c ucase_s/ucase_s time_c/time_c time_s/time_s
|
||||
|
||||
distclean: clean
|
||||
-/bin/rm -f config.h Makefile config.status config.cache config.log
|
||||
|
||||
### Archiving #################################################################
|
||||
|
||||
CFILES=\
|
||||
PRead.c PWrite.c SAcceptA.c SAcceptS.c \
|
||||
SBind.c SClose.c SConnect.c SConnectByName.c \
|
||||
SNew.c SRead.c SReadline.c SRecv.c \
|
||||
SRecvfrom.c SRecvmsg.c SSelect.c SSend.c \
|
||||
SSendto.c SSendtoByName.c SWrite.c SocketUtil.c \
|
||||
StrAddr.c UAcceptA.c UAcceptS.c UBind.c \
|
||||
UConnect.c UConnectByName.c UNew.c URecvfrom.c \
|
||||
USendto.c USendtoByName.c SWait.c main.c
|
||||
|
||||
HFILES=sio.h usio.h
|
||||
|
||||
DOCFILES=sio.html
|
||||
CFGFILES=config.h.in configure.in configure Makefile.in
|
||||
CFGJUNK=config.h Makefile config.*
|
||||
MOREJUNK=
|
||||
|
||||
# This is everything that is copied when you make a shar or tar.
|
||||
PACKAGE=$(DOCFILES) $(HFILES) $(CFGFILES) $(MOREJUNK) $(CFILES)
|
||||
|
||||
TMPDIR=/tmp
|
||||
TARDIR=sio-$(VER)
|
||||
TARFILE=$(TARDIR).tar
|
||||
TGZFILE=$(TARDIR).tar.gz
|
||||
|
||||
tarcp:
|
||||
-@mkdir -p $(TMPDIR)/TAR/$(TARDIR)
|
||||
-@chmod ga+r $(PACKAGE)
|
||||
-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
|
||||
cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)
|
||||
|
||||
tar: $(PACKAGE)
|
||||
-@mkdir $(TMPDIR)/TAR
|
||||
-@mkdir $(TMPDIR)/TAR/$(TARDIR)
|
||||
-@chmod ga+r $(PACKAGE)
|
||||
find . -depth -type f -print | cut -c3- | grep -v '.o$$' | grep -v '.so$$' | grep -v 'core$$' | grep -v 'Makefile$$' | grep -v 'config.log$$' | grep -v 'config.h$$' | grep -v 'config.cache$$' | grep -v 'config.status$$' | grep -v '.a$$' | grep -v '.lib$$' | grep -v '.ncb$$' | grep -v '.opt$$' | grep -v '.zip$$' | grep -v '.gz$$' | grep -v '.swp$$' | grep -v '.tar$$' | cpio -pdm $(TMPDIR)/TAR/$(TARDIR)
|
||||
( cd $(TMPDIR)/TAR ; tar cf $(TARFILE) $(TARDIR) )
|
||||
cp $(TMPDIR)/TAR/$(TARFILE) .
|
||||
-@chmod 644 $(TARFILE)
|
||||
-@rm -rf $(TMPDIR)/TAR
|
||||
-@ls -l $(TARFILE)
|
||||
|
||||
gz: tar
|
||||
gzip -c $(TARFILE) > $(TGZFILE)
|
||||
-@rm $(TARFILE)
|
||||
-@chmod 644 $(TGZFILE)
|
||||
-@ls -l $(TGZFILE)
|
||||
|
||||
### Dependencies #############################################################
|
||||
|
||||
PRead.o: PRead.c sio.h
|
||||
PWrite.o: PWrite.c sio.h
|
||||
SAcceptA.o: SAcceptA.c sio.h
|
||||
SAcceptS.o: SAcceptS.c sio.h
|
||||
SBind.o: SBind.c sio.h
|
||||
SClose.o: SClose.c sio.h
|
||||
SConnect.o: SConnect.c sio.h
|
||||
SConnectByName.o: SConnectByName.c sio.h
|
||||
SNew.o: SNew.c sio.h
|
||||
SRead.o: SRead.c sio.h
|
||||
SReadline.o: SReadline.c sio.h
|
||||
SRecv.o: SRecv.c sio.h
|
||||
SRecvfrom.o: SRecvfrom.c sio.h
|
||||
SRecvmsg.o: SRecvmsg.c sio.h
|
||||
SSelect.o: SSelect.c sio.h
|
||||
SSend.o: SSend.c sio.h
|
||||
SSendto.o: SSendto.c sio.h
|
||||
SSendtoByName.o: SSendtoByName.c sio.h
|
||||
SWrite.o: SWrite.c sio.h
|
||||
SWait.o: SWait.c sio.h
|
||||
SocketUtil.o: SocketUtil.c sio.h
|
||||
StrAddr.o: StrAddr.c sio.h
|
||||
UAcceptA.o: UAcceptA.c sio.h usio.h
|
||||
UAcceptS.o: UAcceptS.c sio.h usio.h
|
||||
UBind.o: UBind.c sio.h usio.h
|
||||
UConnect.o: UConnect.c sio.h usio.h
|
||||
UConnectByName.o: UConnectByName.c sio.h usio.h
|
||||
UNew.o: UNew.c sio.h usio.h
|
||||
URecvfrom.o: URecvfrom.c sio.h usio.h
|
||||
USendto.o: USendto.c sio.h usio.h
|
||||
USendtoByName.o: USendtoByName.c sio.h usio.h
|
||||
main.o: main.c sio.h
|
|
@ -1,71 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
/* Read up to "size" bytes on sfd.
|
||||
*
|
||||
* If "retry" is on, after a successful read of less than "size"
|
||||
* bytes, it will attempt to read more, upto "size."
|
||||
*
|
||||
* Although "retry" would seem to indicate you may want to always
|
||||
* read "size" bytes or else it is an error, even with that on you
|
||||
* may get back a value < size. Set "retry" to 0 when you want to
|
||||
* return as soon as there is a chunk of data whose size is <= "size".
|
||||
*/
|
||||
|
||||
int
|
||||
PRead(int sfd, char *const buf0, size_t size, int retry)
|
||||
{
|
||||
int nread;
|
||||
volatile int nleft;
|
||||
char *volatile buf = buf0;
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
vsio_sigproc_t sigpipe;
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nread = size - nleft;
|
||||
if (nread > 0)
|
||||
return (nread);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
#endif
|
||||
errno = 0;
|
||||
|
||||
nleft = (int) size;
|
||||
forever {
|
||||
nread = read(sfd, buf, nleft);
|
||||
if (nread <= 0) {
|
||||
if (nread == 0) {
|
||||
/* EOF */
|
||||
nread = size - nleft;
|
||||
goto done;
|
||||
} else if (errno != EINTR) {
|
||||
nread = size - nleft;
|
||||
if (nread == 0)
|
||||
nread = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nread = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nread;
|
||||
if ((nleft <= 0) || (retry == 0))
|
||||
break;
|
||||
buf += nread;
|
||||
}
|
||||
nread = size - nleft;
|
||||
|
||||
done:
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
#endif
|
||||
return (nread);
|
||||
} /* PRead */
|
|
@ -1,55 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
int
|
||||
PWrite(int sfd, const char *const buf0, size_t size)
|
||||
{
|
||||
volatile int nleft;
|
||||
const char *volatile buf = buf0;
|
||||
int nwrote;
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
vsio_sigproc_t sigpipe;
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
#endif
|
||||
|
||||
nleft = (int) size;
|
||||
forever {
|
||||
nwrote = write(sfd, buf, nleft);
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
}
|
||||
nwrote = size - nleft;
|
||||
|
||||
done:
|
||||
#if !defined(NO_SIGNALS) && defined(SIGPIPE)
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
#endif
|
||||
|
||||
return (nwrote);
|
||||
} /* PWrite */
|
|
@ -1,52 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
int
|
||||
SAcceptA(int sfd, struct sockaddr_in *const addr, int tlen)
|
||||
{
|
||||
int result;
|
||||
#ifndef NO_SIGNALS
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
#endif
|
||||
size_t size;
|
||||
|
||||
if (tlen < 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
size = sizeof(struct sockaddr_in);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
|
||||
if ((result >= 0) || (errno != EINTR))
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
#ifndef NO_SIGNALS
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIG_IGN);
|
||||
alarm((unsigned int) tlen);
|
||||
|
||||
errno = 0;
|
||||
do {
|
||||
size = sizeof(struct sockaddr_in);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
return (result);
|
||||
#else
|
||||
return (-1);
|
||||
#endif
|
||||
} /* SAcceptA */
|
|
@ -1,47 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
int
|
||||
SAcceptS(int sfd, struct sockaddr_in *const addr, int tlen)
|
||||
{
|
||||
int result;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
size_t size;
|
||||
|
||||
if (tlen <= 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
size = sizeof(struct sockaddr_in);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
|
||||
if ((result >= 0) || (errno != EINTR))
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
size = sizeof(struct sockaddr_in);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
return (result);
|
||||
} /* SAcceptS */
|
|
@ -1,63 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
int
|
||||
SBind(int sockfd, const int port, const int nTries, const int reuseFlag)
|
||||
{
|
||||
unsigned int i;
|
||||
int on;
|
||||
int onsize;
|
||||
struct sockaddr_in localAddr;
|
||||
|
||||
localAddr.sin_family = AF_INET;
|
||||
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
localAddr.sin_port = htons((unsigned short) port);
|
||||
|
||||
if (reuseFlag != kReUseAddrNo) {
|
||||
/* This is mostly so you can quit the server and re-run it
|
||||
* again right away. If you don't do this, the OS may complain
|
||||
* that the address is still in use.
|
||||
*/
|
||||
on = 1;
|
||||
onsize = (int) sizeof(on);
|
||||
(void) setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &on, onsize);
|
||||
|
||||
#ifdef SO_REUSEPORT
|
||||
/* Tells kernel that it's okay to have more
|
||||
* than one process originating from this
|
||||
* local port.
|
||||
*/
|
||||
on = 1;
|
||||
onsize = (int) sizeof(on);
|
||||
(void) setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT,
|
||||
(char *) &on, onsize);
|
||||
#endif /* SO_REUSEPORT */
|
||||
}
|
||||
|
||||
for (i=1; ; i++) {
|
||||
/* Try binding a few times, in case we get Address in Use
|
||||
* errors.
|
||||
*/
|
||||
if (bind(sockfd, (struct sockaddr *) &localAddr, sizeof(struct sockaddr_in)) == 0) {
|
||||
break;
|
||||
}
|
||||
if ((int) i == nTries) {
|
||||
return (-1);
|
||||
}
|
||||
/* Give the OS time to clean up the old socket,
|
||||
* and then try again.
|
||||
*/
|
||||
sleep(i * 3);
|
||||
}
|
||||
|
||||
return (0);
|
||||
} /* SBind */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SListen(int sfd, int backlog)
|
||||
{
|
||||
return (listen(sfd, (unsigned int) backlog));
|
||||
} /* SListen */
|
|
@ -1,217 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
int
|
||||
SClose(int sfd, int tlen)
|
||||
{
|
||||
#ifndef NO_SIGNALS
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (tlen < 1) {
|
||||
/* Don't time it, shut it down now. */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
return (closesocket(sfd));
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
return (shutdown(sfd, 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
return closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIG_IGN);
|
||||
|
||||
alarm((unsigned int) tlen);
|
||||
for (;;) {
|
||||
if (closesocket(sfd) == 0) {
|
||||
errno = 0;
|
||||
break;
|
||||
}
|
||||
if (errno != EINTR)
|
||||
break;
|
||||
}
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
|
||||
if ((errno != 0) && (errno != EBADF)) {
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
(void) closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
}
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return ((errno == 0) ? 0 : (-1));
|
||||
#else
|
||||
struct timeval tv;
|
||||
int result;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (tlen < 1) {
|
||||
/* Don't time it, shut it down now. */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
return (closesocket(sfd));
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
return (shutdown(sfd, 2));
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait until the socket is ready for writing (usually easy). */
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
|
||||
forever {
|
||||
tlen = done - now;
|
||||
if (tlen <= 0) {
|
||||
/* timeout */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
(void) closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
(void) closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
/* Error, done. This end may have been shutdown. */
|
||||
break;
|
||||
}
|
||||
time(&now);
|
||||
}
|
||||
|
||||
/* Wait until the socket is ready for reading. */
|
||||
forever {
|
||||
tlen = done - now;
|
||||
if (tlen <= 0) {
|
||||
/* timeout */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
(void) closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
if (SetSocketLinger(sfd, 0, 0) == 0) {
|
||||
/* Linger disabled, so close()
|
||||
* should not block.
|
||||
*/
|
||||
(void) closesocket(sfd);
|
||||
} else {
|
||||
/* This will result in a fd leak,
|
||||
* but it's either that or hang forever.
|
||||
*/
|
||||
(void) shutdown(sfd, 2);
|
||||
}
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
/* Error, done. This end may have been shutdown. */
|
||||
break;
|
||||
}
|
||||
time(&now);
|
||||
}
|
||||
|
||||
/* If we get here, close() won't block. */
|
||||
return closesocket(sfd);
|
||||
#endif
|
||||
} /* SClose */
|
|
@ -1,196 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
int
|
||||
SConnect(int sfd, const struct sockaddr_in *const addr, int tlen)
|
||||
{
|
||||
#ifndef NO_SIGNALS
|
||||
int result;
|
||||
vsio_sigproc_t sigalrm;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
alarm((unsigned int) tlen);
|
||||
|
||||
errno = 0;
|
||||
do {
|
||||
result = connect(sfd, (struct sockaddr *) addr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
return (result);
|
||||
#else /* NO_SIGNALS */
|
||||
unsigned long opt;
|
||||
fd_set ss, xx;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
int cErrno;
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
int wsaErrno;
|
||||
int soerr, soerrsize;
|
||||
#else
|
||||
int optval;
|
||||
int optlen;
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
if (tlen <= 0) {
|
||||
do {
|
||||
result = connect(sfd, (struct sockaddr *) addr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
SETERRNO
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
return (result);
|
||||
}
|
||||
|
||||
#ifdef FIONBIO
|
||||
opt = 1;
|
||||
if (ioctlsocket(sfd, FIONBIO, &opt) != 0) {
|
||||
SETERRNO
|
||||
return (-1);
|
||||
}
|
||||
#else
|
||||
if (fcntl(sfd, F_GETFL, &opt) < 0) {
|
||||
SETERRNO
|
||||
return (-1);
|
||||
} else if (fcntl(sfd, F_SETFL, opt | O_NONBLOCK) < 0) {
|
||||
SETERRNO
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
result = connect(sfd, (struct sockaddr *) addr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
if (result == 0)
|
||||
return 0; /* Already?!? */
|
||||
|
||||
if ((result < 0)
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
&& ((wsaErrno = WSAGetLastError()) != WSAEWOULDBLOCK)
|
||||
&& (wsaErrno != WSAEINPROGRESS)
|
||||
#else
|
||||
&& (errno != EWOULDBLOCK) && (errno != EINPROGRESS)
|
||||
#endif
|
||||
) {
|
||||
SETERRNO
|
||||
shutdown(sfd, 2);
|
||||
return (-1);
|
||||
}
|
||||
cErrno = errno;
|
||||
|
||||
forever {
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
WSASetLastError(0);
|
||||
#endif
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
xx = ss;
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, SELECT_TYPE_ARG234 &xx, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
/* Don't bother turning off FIONBIO */
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
/* Don't bother turning off FIONBIO */
|
||||
SETERRNO
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Supposedly once the select() returns with a writable
|
||||
* descriptor, it is connected and we don't need to
|
||||
* recall connect(). When select() returns an exception,
|
||||
* the connection failed -- we can get the connect error
|
||||
* doing a write on the socket which will err out.
|
||||
*/
|
||||
|
||||
if (FD_ISSET(sfd, &xx)) {
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
errno = 0;
|
||||
soerr = 0;
|
||||
soerrsize = sizeof(soerr);
|
||||
result = getsockopt(sfd, SOL_SOCKET, SO_ERROR, (char *) &soerr, &soerrsize);
|
||||
if ((result >= 0) && (soerr != 0)) {
|
||||
errno = soerr;
|
||||
} else {
|
||||
errno = 0;
|
||||
(void) send(sfd, "\0", 1, 0);
|
||||
SETERRNO
|
||||
}
|
||||
#else
|
||||
errno = 0;
|
||||
(void) send(sfd, "\0", 1, 0);
|
||||
#endif
|
||||
result = errno;
|
||||
shutdown(sfd, 2);
|
||||
errno = result;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#else
|
||||
if (cErrno == EINPROGRESS) {
|
||||
/*
|
||||
* [from Linux connect(2) page]
|
||||
*
|
||||
* EINPROGRESS
|
||||
*
|
||||
* The socket is non-blocking and the connection can
|
||||
* not be completed immediately. It is possible to
|
||||
* select(2) or poll(2) for completion by selecting
|
||||
* the socket for writing. After select indicates
|
||||
* writability, use getsockopt(2) to read the
|
||||
* SO_ERROR option at level SOL_SOCKET to determine
|
||||
* whether connect completed successfully (SO_ERROR
|
||||
* is zero) or unsuccessfully (SO_ERROR is one of the
|
||||
* usual error codes listed above, explaining the
|
||||
* reason for the failure).
|
||||
*/
|
||||
optval = 0;
|
||||
optlen = sizeof(optval);
|
||||
if (getsockopt(sfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) == 0) {
|
||||
errno = optval;
|
||||
if (errno != 0)
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FIONBIO
|
||||
opt = 0;
|
||||
if (ioctlsocket(sfd, FIONBIO, &opt) != 0) {
|
||||
SETERRNO
|
||||
shutdown(sfd, 2);
|
||||
return (-1);
|
||||
}
|
||||
#else
|
||||
if (fcntl(sfd, F_SETFL, opt) < 0) {
|
||||
SETERRNO
|
||||
shutdown(sfd, 2);
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
#endif /* NO_SIGNALS */
|
||||
} /* SConnect */
|
|
@ -1,13 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
int
|
||||
SConnectByName(int sfd, const char * const addrStr, const int tlen)
|
||||
{
|
||||
int result;
|
||||
struct sockaddr_in remoteAddr;
|
||||
|
||||
if ((result = AddrStrToAddr(addrStr, &remoteAddr, -1)) == 0) {
|
||||
result = SConnect(sfd, &remoteAddr, tlen);
|
||||
}
|
||||
return (result);
|
||||
} /* SConnectByName */
|
|
@ -1,171 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
|
||||
const char *wsaerrlist[128] = {
|
||||
/* 0 */ "Unknown error #0",
|
||||
/* 1 */ "Unknown error #1",
|
||||
/* 2 */ "Unknown error #2",
|
||||
/* 3 */ "Unknown error #3",
|
||||
/* 4 */ "Interrupted system call",
|
||||
/* 5 */ "Unknown error #5",
|
||||
/* 6 */ "Unknown error #6",
|
||||
/* 7 */ "Unknown error #7",
|
||||
/* 8 */ "Unknown error #8",
|
||||
/* 9 */ "Bad file descriptor",
|
||||
/* 10 */ "Unknown error #10",
|
||||
/* 11 */ "Unknown error #11",
|
||||
/* 12 */ "Unknown error #12",
|
||||
/* 13 */ "Permission denied",
|
||||
/* 14 */ "Bad address",
|
||||
/* 15 */ "Unknown error #15",
|
||||
/* 16 */ "Unknown error #16",
|
||||
/* 17 */ "Unknown error #17",
|
||||
/* 18 */ "Unknown error #18",
|
||||
/* 19 */ "Unknown error #19",
|
||||
/* 20 */ "Unknown error #20",
|
||||
/* 21 */ "Unknown error #21",
|
||||
/* 22 */ "Invalid argument",
|
||||
/* 23 */ "Unknown error #23",
|
||||
/* 24 */ "Too many open files",
|
||||
/* 25 */ "Unknown error #25",
|
||||
/* 26 */ "Unknown error #26",
|
||||
/* 27 */ "Unknown error #27",
|
||||
/* 28 */ "Unknown error #28",
|
||||
/* 29 */ "Unknown error #29",
|
||||
/* 30 */ "Unknown error #30",
|
||||
/* 31 */ "Unknown error #31",
|
||||
/* 32 */ "Unknown error #32",
|
||||
/* 33 */ "Unknown error #33",
|
||||
/* 34 */ "Unknown error #34",
|
||||
/* 35 */ "Resource temporarily unavailable",
|
||||
/* 36 */ "Operation now in progress",
|
||||
/* 37 */ "Operation already in progress",
|
||||
/* 38 */ "Socket operation on non-socket",
|
||||
/* 39 */ "Destination address required",
|
||||
/* 40 */ "Message too long",
|
||||
/* 41 */ "Protocol wrong type for socket",
|
||||
/* 42 */ "Protocol not available",
|
||||
/* 43 */ "Protocol not supported",
|
||||
/* 44 */ "Socket type not supported",
|
||||
/* 45 */ "Operation not supported",
|
||||
/* 46 */ "Protocol family not supported",
|
||||
/* 47 */ "Address family not supported by protocol",
|
||||
/* 48 */ "Address already in use",
|
||||
/* 49 */ "Cannot assign requested address",
|
||||
/* 50 */ "Network is down",
|
||||
/* 51 */ "Network is unreachable",
|
||||
/* 52 */ "Network dropped connection on reset",
|
||||
/* 53 */ "Software caused connection abort",
|
||||
/* 54 */ "Connection reset by peer",
|
||||
/* 55 */ "No buffer space available",
|
||||
/* 56 */ "Transport endpoint is already connected",
|
||||
/* 57 */ "Transport endpoint is not connected",
|
||||
/* 58 */ "Cannot send after transport endpoint shutdown",
|
||||
/* 59 */ "Too many references: cannot splice",
|
||||
/* 60 */ "Connection timed out",
|
||||
/* 61 */ "Connection refused",
|
||||
/* 62 */ "Too many levels of symbolic links",
|
||||
/* 63 */ "File name too long",
|
||||
/* 64 */ "Host is down",
|
||||
/* 65 */ "No route to host",
|
||||
/* 66 */ "Directory not empty",
|
||||
/* 67 */ "WSAEPROCLIM error",
|
||||
/* 68 */ "Too many users",
|
||||
/* 69 */ "Disc quota exceeded",
|
||||
/* 70 */ "Stale NFS file handle",
|
||||
/* 71 */ "Object is remote",
|
||||
/* 72 */ "Unknown error #72",
|
||||
/* 73 */ "Unknown error #73",
|
||||
/* 74 */ "Unknown error #74",
|
||||
/* 75 */ "Unknown error #75",
|
||||
/* 76 */ "Unknown error #76",
|
||||
/* 77 */ "Unknown error #77",
|
||||
/* 78 */ "Unknown error #78",
|
||||
/* 79 */ "Unknown error #79",
|
||||
/* 80 */ "Unknown error #80",
|
||||
/* 81 */ "Unknown error #81",
|
||||
/* 82 */ "Unknown error #82",
|
||||
/* 83 */ "Unknown error #83",
|
||||
/* 84 */ "Unknown error #84",
|
||||
/* 85 */ "Unknown error #85",
|
||||
/* 86 */ "Unknown error #86",
|
||||
/* 87 */ "Unknown error #87",
|
||||
/* 88 */ "Unknown error #88",
|
||||
/* 89 */ "Unknown error #89",
|
||||
/* 90 */ "Unknown error #90",
|
||||
/* 91 */ "WSASYSNOTREADY error",
|
||||
/* 92 */ "Version not supported",
|
||||
/* 93 */ "Winsock not initialised",
|
||||
/* 94 */ "Unknown error #94",
|
||||
/* 95 */ "Unknown error #95",
|
||||
/* 96 */ "Unknown error #96",
|
||||
/* 97 */ "Unknown error #97",
|
||||
/* 98 */ "Unknown error #98",
|
||||
/* 99 */ "Unknown error #99",
|
||||
/* 100 */ "Unknown error #100",
|
||||
/* 101 */ "WSAEDISCON error",
|
||||
/* 102 */ "Unknown error #102",
|
||||
/* 103 */ "Unknown error #103",
|
||||
/* 104 */ "Unknown error #104",
|
||||
/* 105 */ "Unknown error #105",
|
||||
/* 106 */ "Unknown error #106",
|
||||
/* 107 */ "Unknown error #107",
|
||||
/* 108 */ "Unknown error #108",
|
||||
/* 109 */ "Unknown error #109",
|
||||
/* 110 */ "Unknown error #110",
|
||||
/* 111 */ "Unknown error #111",
|
||||
/* 112 */ "Unknown error #112",
|
||||
/* 113 */ "Unknown error #113",
|
||||
/* 114 */ "Unknown error #114",
|
||||
/* 115 */ "Unknown error #115",
|
||||
/* 116 */ "Unknown error #116",
|
||||
/* 117 */ "Unknown error #117",
|
||||
/* 118 */ "Unknown error #118",
|
||||
/* 119 */ "Unknown error #119",
|
||||
/* 120 */ "Unknown error #120",
|
||||
/* 121 */ "Unknown error #121",
|
||||
/* 122 */ "Unknown error #122",
|
||||
/* 123 */ "Unknown error #123",
|
||||
/* 124 */ "Unknown error #124",
|
||||
/* 125 */ "Unknown error #125",
|
||||
/* 126 */ "Unknown error #126",
|
||||
/* 127 */ "Unknown error #127",
|
||||
};
|
||||
|
||||
#endif /* Windows */
|
||||
|
||||
|
||||
|
||||
const char *
|
||||
SError(int e)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
const char *cp;
|
||||
static char estr[32];
|
||||
|
||||
if (e == 0)
|
||||
e = WSAGetLastError();
|
||||
|
||||
if ((e >= WSABASEERR) && (e < (WSABASEERR + (sizeof(wsaerrlist) / sizeof(const char *))))) {
|
||||
return wsaerrlist[e - WSABASEERR];
|
||||
}
|
||||
|
||||
cp = strerror(e);
|
||||
if ((cp == NULL) || (cp[0] == '\0') || (strcmp(cp, "Unknown error") == 0)) {
|
||||
wsprintf(estr, "Error #%d", e);
|
||||
cp = estr;
|
||||
}
|
||||
return cp;
|
||||
#elif defined(HAVE_STRERROR)
|
||||
if (e == 0)
|
||||
e = errno;
|
||||
return strerror(e);
|
||||
#else
|
||||
static char estr[32];
|
||||
if (e == 0)
|
||||
e = errno;
|
||||
sprintf(estr, "Error #%d", e);
|
||||
return (estr);
|
||||
#endif
|
||||
} /* SError */
|
|
@ -1,81 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
int
|
||||
SNewStreamClient(void)
|
||||
{
|
||||
int sfd;
|
||||
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sfd < 0)
|
||||
return kSNewFailed;
|
||||
|
||||
return (sfd);
|
||||
} /* SNewStreamClient */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SNewDatagramClient(void)
|
||||
{
|
||||
int sfd;
|
||||
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sfd < 0)
|
||||
return kSNewFailed;
|
||||
|
||||
return (sfd);
|
||||
} /* SNewDatagramClient */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SNewStreamServer(const int port, const int nTries, const int reuseFlag, int listenQueueSize)
|
||||
{
|
||||
int oerrno;
|
||||
int sfd;
|
||||
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sfd < 0)
|
||||
return kSNewFailed;
|
||||
|
||||
if (SBind(sfd, port, nTries, reuseFlag) < 0) {
|
||||
oerrno = errno;
|
||||
(void) closesocket(sfd);
|
||||
errno = oerrno;
|
||||
return kSBindFailed;
|
||||
}
|
||||
|
||||
if (SListen(sfd, listenQueueSize) < 0) {
|
||||
oerrno = errno;
|
||||
(void) closesocket(sfd);
|
||||
errno = oerrno;
|
||||
return kSListenFailed;
|
||||
}
|
||||
|
||||
return (sfd);
|
||||
} /* SNewStreamServer */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SNewDatagramServer(const int port, const int nTries, const int reuseFlag)
|
||||
{
|
||||
int oerrno;
|
||||
int sfd;
|
||||
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sfd < 0)
|
||||
return kSNewFailed;
|
||||
|
||||
if (SBind(sfd, port, nTries, reuseFlag) < 0) {
|
||||
oerrno = errno;
|
||||
(void) closesocket(sfd);
|
||||
errno = oerrno;
|
||||
return kSBindFailed;
|
||||
}
|
||||
|
||||
return (sfd);
|
||||
} /* SNewDatagramServer */
|
|
@ -1,213 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
static char UNUSED(gSioVersion[]) = "@(#) sio 6.0.3 ** Copyright 1992-2001 Mike Gleason. All rights reserved.";
|
||||
|
||||
#ifdef NO_SIGNALS
|
||||
static char UNUSED(gNoSignalsMarker[]) = "@(#) sio - NO_SIGNALS";
|
||||
#else
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
/* Read up to "size" bytes on sfd before "tlen" seconds.
|
||||
*
|
||||
* If "retry" is on, after a successful read of less than "size"
|
||||
* bytes, it will attempt to read more, upto "size."
|
||||
*
|
||||
* If the timer elapses and one or more bytes were read, it returns
|
||||
* that number, otherwise a timeout error is returned.
|
||||
*
|
||||
* Although "retry" would seem to indicate you may want to always
|
||||
* read "size" bytes or else it is an error, even with that on you
|
||||
* may get back a value < size. Set "retry" to 0 when you want to
|
||||
* return as soon as there is a chunk of data whose size is <= "size".
|
||||
*/
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SRead(int sfd, char *const buf0, size_t size, int tlen, int retry)
|
||||
{
|
||||
int nread;
|
||||
volatile int nleft;
|
||||
char *volatile buf = buf0;
|
||||
int tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0))
|
||||
return (nread);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0))
|
||||
return (nread);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
errno = 0;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = size - nleft;
|
||||
if ((nread == 0) || ((retry & (kFullBufferRequired)) != 0)) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nread = read(sfd, (char *) buf, nleft);
|
||||
(void) alarm(0);
|
||||
if (nread <= 0) {
|
||||
if (nread == 0) {
|
||||
/* EOF */
|
||||
if (retry == ((retry & (kFullBufferRequiredExceptLast)) != 0))
|
||||
nread = size - nleft;
|
||||
goto done;
|
||||
} else if (errno != EINTR) {
|
||||
nread = size - nleft;
|
||||
if (nread == 0)
|
||||
nread = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nread = 0;
|
||||
/* Try again. */
|
||||
|
||||
/* Ignore this line... */
|
||||
LIBSIO_USE_VAR(gSioVersion);
|
||||
}
|
||||
}
|
||||
nleft -= nread;
|
||||
if ((nleft <= 0) || (((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0) && (nleft != (int) size)))
|
||||
break;
|
||||
buf += nread;
|
||||
time(&now);
|
||||
}
|
||||
nread = size - nleft;
|
||||
|
||||
done:
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nread);
|
||||
} /* SRead */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SRead(int sfd, char *const buf0, size_t size, int tlen, int retry)
|
||||
{
|
||||
int nread;
|
||||
volatile int nleft;
|
||||
char *buf = buf0;
|
||||
int tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result, firstRead;
|
||||
|
||||
errno = 0;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
firstRead = 1;
|
||||
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = size - nleft;
|
||||
if ((nread == 0) || ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) != 0)) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!firstRead || ((retry & kNoFirstSelect) == 0)) {
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && ((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0))
|
||||
return (nread);
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
firstRead = 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
nread = recv(sfd, (char *) buf, nleft, 0);
|
||||
#else
|
||||
nread = read(sfd, (char *) buf, nleft);
|
||||
#endif
|
||||
|
||||
if (nread <= 0) {
|
||||
if (nread == 0) {
|
||||
/* EOF */
|
||||
if (retry == ((retry & (kFullBufferRequiredExceptLast)) != 0))
|
||||
nread = size - nleft;
|
||||
goto done;
|
||||
} else if (errno != EINTR) {
|
||||
nread = size - nleft;
|
||||
if (nread == 0)
|
||||
nread = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nread = 0;
|
||||
/* Try again. */
|
||||
|
||||
/* Ignore these two lines */
|
||||
LIBSIO_USE_VAR(gSioVersion);
|
||||
LIBSIO_USE_VAR(gNoSignalsMarker);
|
||||
}
|
||||
}
|
||||
nleft -= nread;
|
||||
if ((nleft <= 0) || (((retry & (kFullBufferRequired|kFullBufferRequiredExceptLast)) == 0) && (nleft != (int) size)))
|
||||
break;
|
||||
buf += nread;
|
||||
time(&now);
|
||||
}
|
||||
nread = size - nleft;
|
||||
|
||||
done:
|
||||
return (nread);
|
||||
} /* SRead */
|
||||
|
||||
#endif
|
|
@ -1,157 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
void
|
||||
FlushSReadlineInfo(SReadlineInfo *srl)
|
||||
{
|
||||
/* Discards any input left in the current buffer,
|
||||
* and resets the buffer and its pointer.
|
||||
*/
|
||||
srl->bufSize = srl->bufSizeMax;
|
||||
memset(srl->buf, 0, srl->bufSize);
|
||||
srl->bufLim = srl->buf + srl->bufSizeMax;
|
||||
|
||||
/* This line sets the buffer pointer
|
||||
* so that the first thing to do is reset and fill the buffer
|
||||
* using real I/O.
|
||||
*/
|
||||
srl->bufPtr = srl->bufLim;
|
||||
} /* FlushSReadlineInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
InitSReadlineInfo(SReadlineInfo *srl, int fd, char *buf, size_t bsize, int tlen, int requireEOLN)
|
||||
{
|
||||
if (buf == NULL) {
|
||||
if (bsize < 512)
|
||||
bsize = 512; /* Pointless, otherwise. */
|
||||
buf = (char *) malloc(bsize);
|
||||
if (buf == NULL)
|
||||
return (-1);
|
||||
srl->malloc = 1;
|
||||
} else {
|
||||
srl->malloc = 0;
|
||||
}
|
||||
memset(buf, 0, bsize);
|
||||
srl->buf = buf;
|
||||
srl->bufSize = bsize;
|
||||
srl->bufSizeMax = bsize;
|
||||
srl->bufLim = srl->buf + bsize;
|
||||
srl->fd = fd;
|
||||
srl->timeoutLen = tlen;
|
||||
srl->requireEOLN = requireEOLN;
|
||||
|
||||
/* This line sets the buffer pointer
|
||||
* so that the first thing to do is reset and fill the buffer
|
||||
* using real I/O.
|
||||
*/
|
||||
srl->bufPtr = srl->bufLim;
|
||||
return (0);
|
||||
} /* InitSReadlineInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
DisposeSReadlineInfo(SReadlineInfo *srl)
|
||||
{
|
||||
memset(srl->buf, 0, srl->bufSizeMax);
|
||||
if (srl->malloc != 0)
|
||||
free(srl->buf);
|
||||
memset(srl, 0, sizeof(SReadlineInfo));
|
||||
|
||||
/* Note: it does not close(srl->fd). */
|
||||
} /* DisposeSReadlineInfo */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Returns the number of bytes read, including the newline which is
|
||||
* also appended to the buffer. If you don't want that newline,
|
||||
* set buf[nread - 1] = '\0', if nread > 0.
|
||||
*/
|
||||
|
||||
int
|
||||
SReadline(SReadlineInfo *srl, char *const linebuf, size_t linebufsize)
|
||||
{
|
||||
int err;
|
||||
char *src;
|
||||
char *dst;
|
||||
char *dstlim;
|
||||
int len;
|
||||
int nr;
|
||||
int requireEOLN;
|
||||
int illegals;
|
||||
|
||||
illegals = 0;
|
||||
err = 0;
|
||||
dst = linebuf;
|
||||
dstlim = dst + linebufsize - 1; /* Leave room for NUL. */
|
||||
src = srl->bufPtr;
|
||||
requireEOLN = srl->requireEOLN;
|
||||
if (requireEOLN)
|
||||
dstlim--;
|
||||
if (dstlim <= dst)
|
||||
return (-1); /* Buffer too small. */
|
||||
|
||||
forever {
|
||||
if ((requireEOLN == 0) && (dst >= dstlim))
|
||||
break;
|
||||
if (src >= srl->bufLim) {
|
||||
/* Fill the buffer. */
|
||||
if (illegals > 1) {
|
||||
/* Probable DOS -- return now and give you an
|
||||
* opportunity to handle bogus input.
|
||||
*/
|
||||
goto done;
|
||||
}
|
||||
nr = SRead(srl->fd, srl->buf, srl->bufSizeMax, srl->timeoutLen, 0);
|
||||
if (nr == 0) {
|
||||
/* EOF. */
|
||||
goto done;
|
||||
} else if (nr < 0) {
|
||||
/* Error. */
|
||||
err = nr;
|
||||
goto done;
|
||||
}
|
||||
srl->bufPtr = src = srl->buf;
|
||||
srl->bufLim = srl->buf + nr;
|
||||
}
|
||||
if (*src == '\0') {
|
||||
++src;
|
||||
illegals++;
|
||||
} else if (*src == '\r') {
|
||||
++src;
|
||||
/* If the next character is a \n that is valid,
|
||||
* otherwise treat a stray \r as an illegal character.
|
||||
*/
|
||||
if ((src < srl->bufLim) && (*src != '\n'))
|
||||
illegals++;
|
||||
} else {
|
||||
if (*src == '\n') {
|
||||
if (dst < dstlim)
|
||||
*dst++ = *src++;
|
||||
else
|
||||
src++;
|
||||
goto done;
|
||||
}
|
||||
if (dst < dstlim)
|
||||
*dst++ = *src++;
|
||||
else
|
||||
src++;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
srl->bufPtr = src;
|
||||
if ((requireEOLN != 0) && (dst != linebuf) && (dst[-1] != '\n'))
|
||||
*dst++ = '\n';
|
||||
if ((requireEOLN != 0) && (dst == linebuf) && (illegals > 0))
|
||||
*dst++ = '\n';
|
||||
*dst = '\0';
|
||||
len = (int) (dst - linebuf);
|
||||
if (err < 0)
|
||||
return (err);
|
||||
return (len);
|
||||
} /* SReadline */
|
|
@ -1,184 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SRecv(int sfd, char *const buf0, size_t size, int fl, int tlen, int retry)
|
||||
{
|
||||
int nread;
|
||||
volatile int nleft;
|
||||
char *volatile buf = buf0;
|
||||
int tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && (retry == kFullBufferNotRequired))
|
||||
return (nread);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && (retry == kFullBufferNotRequired))
|
||||
return (nread);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
errno = 0;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = size - nleft;
|
||||
if ((nread == 0) || (retry == kFullBufferRequired)) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nread = recv(sfd, (char *) buf, nleft, fl);
|
||||
(void) alarm(0);
|
||||
if (nread <= 0) {
|
||||
if (nread == 0) {
|
||||
/* EOF */
|
||||
if (retry == kFullBufferRequiredExceptLast)
|
||||
nread = size - nleft;
|
||||
goto done;
|
||||
} else if (errno != EINTR) {
|
||||
nread = size - nleft;
|
||||
if (nread == 0)
|
||||
nread = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nread = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nread;
|
||||
if ((nleft <= 0) || ((retry == 0) && (nleft != (int) size)))
|
||||
break;
|
||||
buf += nread;
|
||||
time(&now);
|
||||
}
|
||||
nread = size - nleft;
|
||||
|
||||
done:
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nread);
|
||||
} /* SRecv */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SRecv(int sfd, char *const buf0, size_t size, int fl, int tlen, int retry)
|
||||
{
|
||||
int nread;
|
||||
int nleft;
|
||||
char *buf = buf0;
|
||||
int tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
errno = 0;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = size - nleft;
|
||||
if ((nread == 0) || (retry == kFullBufferRequired)) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
nread = size - nleft;
|
||||
if ((nread > 0) && (retry == kFullBufferNotRequired))
|
||||
return (nread);
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
nread = recv(sfd, (char *) buf, nleft, fl);
|
||||
#else
|
||||
nread = recv(sfd, (char *) buf, nleft, fl);
|
||||
#endif
|
||||
|
||||
if (nread <= 0) {
|
||||
if (nread == 0) {
|
||||
/* EOF */
|
||||
if (retry == kFullBufferRequiredExceptLast)
|
||||
nread = size - nleft;
|
||||
goto done;
|
||||
} else if (errno != EINTR) {
|
||||
nread = size - nleft;
|
||||
if (nread == 0)
|
||||
nread = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nread = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nread;
|
||||
if ((nleft <= 0) || ((retry == 0) && (nleft != (int) size)))
|
||||
break;
|
||||
buf += nread;
|
||||
time(&now);
|
||||
}
|
||||
nread = size - nleft;
|
||||
|
||||
done:
|
||||
return (nread);
|
||||
} /* SRecv */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SRecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_in *const fromAddr, int tlen)
|
||||
{
|
||||
int nread, tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
int alen;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
forever {
|
||||
alen = sizeof(struct sockaddr_in);
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nread = recvfrom(sfd, buf, size, fl,
|
||||
(struct sockaddr *) fromAddr, &alen);
|
||||
(void) alarm(0);
|
||||
if (nread >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nread);
|
||||
} /* SRecvfrom */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SRecvfrom(int sfd, char *const buf, size_t size, int fl, struct sockaddr_in *const fromAddr, int tlen)
|
||||
{
|
||||
int nread, tleft;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
time_t done, now;
|
||||
int alen;
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
nread = 0;
|
||||
forever {
|
||||
alen = sizeof(struct sockaddr_in);
|
||||
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
nread = recvfrom(sfd, buf, size, fl,
|
||||
(struct sockaddr *) fromAddr, &alen);
|
||||
|
||||
if (nread >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (nread);
|
||||
} /* SRecvfrom */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SRecvmsg(int sfd, void *const msg, int fl, int tlen)
|
||||
{
|
||||
int nread, tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (tlen < 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
nread = recvmsg(sfd, (struct msghdr *) msg, fl);
|
||||
if ((nread >= 0) || (errno != EINTR))
|
||||
return (nread);
|
||||
}
|
||||
}
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
forever {
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nread = recvmsg(sfd, (struct msghdr *) msg, fl);
|
||||
(void) alarm(0);
|
||||
if (nread >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nread);
|
||||
} /* SRecvmsg */
|
||||
|
||||
#elif defined(HAVE_RECVMSG)
|
||||
|
||||
int
|
||||
SRecvmsg(int sfd, void *const msg, int fl, int tlen)
|
||||
{
|
||||
int nread, tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
if (tlen < 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
nread = recvmsg(sfd, (struct msghdr *) msg, fl);
|
||||
if ((nread >= 0) || (errno != EINTR))
|
||||
return (nread);
|
||||
}
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
forever {
|
||||
|
||||
for (;;) {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
nread = recvmsg(sfd, (struct msghdr *) msg, fl);
|
||||
|
||||
if (nread >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nread = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (nread);
|
||||
} /* SRecvmsg */
|
||||
|
||||
#endif
|
|
@ -1,74 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
void
|
||||
SelectSetInit(SelectSetPtr const ssp, const double timeout)
|
||||
{
|
||||
double i;
|
||||
long l;
|
||||
|
||||
/* Inititalize SelectSet, which will clear the fd_set, the
|
||||
* timeval, and the maxfd and numfds to 0.
|
||||
*/
|
||||
memset(ssp, 0, sizeof(SelectSet));
|
||||
l = (long) timeout;
|
||||
i = (double) l;
|
||||
ssp->timeout.tv_sec = l;
|
||||
ssp->timeout.tv_usec = (long) ((timeout - i) * 1000000.0);
|
||||
} /* SelectSetInit */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SelectSetAdd(SelectSetPtr const ssp, const int fd)
|
||||
{
|
||||
if (fd >= 0) {
|
||||
FD_SET(fd, &ssp->fds);
|
||||
if (ssp->maxfd < (fd + 1))
|
||||
ssp->maxfd = (fd + 1);
|
||||
++ssp->numfds;
|
||||
}
|
||||
} /* SelectSetAdd */
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SelectSetRemove(SelectSetPtr const ssp, const int fd)
|
||||
{
|
||||
if ((fd >= 0) && (FD_ISSET(fd, &ssp->fds))) {
|
||||
FD_CLR(fd, &ssp->fds);
|
||||
/* Note that maxfd is left alone, even if maxfd was
|
||||
* this one. That is okay.
|
||||
*/
|
||||
--ssp->numfds;
|
||||
}
|
||||
} /* SelectSetRemove */
|
||||
|
||||
|
||||
|
||||
int
|
||||
SelectW(SelectSetPtr ssp, SelectSetPtr resultssp)
|
||||
{
|
||||
int rc;
|
||||
|
||||
do {
|
||||
memcpy(resultssp, ssp, sizeof(SelectSet));
|
||||
rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
|
||||
} while ((rc < 0) && (errno == EINTR));
|
||||
return (rc);
|
||||
} /* SelectW */
|
||||
|
||||
|
||||
|
||||
int
|
||||
SelectR(SelectSetPtr ssp, SelectSetPtr resultssp)
|
||||
{
|
||||
int rc;
|
||||
|
||||
do {
|
||||
memcpy(resultssp, ssp, sizeof(SelectSet));
|
||||
rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
|
||||
} while ((rc < 0) && (errno == EINTR));
|
||||
return (rc);
|
||||
} /* SelectR */
|
|
@ -1,172 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SSend(int sfd, char *buf0, size_t size, int fl, int tlen)
|
||||
{
|
||||
volatile int nleft;
|
||||
char *volatile buf = buf0;
|
||||
int nwrote, tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nwrote = send(sfd, buf, size, fl);
|
||||
(void) alarm(0);
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
time(&now);
|
||||
}
|
||||
nwrote = size - nleft;
|
||||
|
||||
done:
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nwrote);
|
||||
} /* SSend */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SSend(int sfd, char *buf0, size_t size, int fl, int tlen)
|
||||
{
|
||||
int nleft;
|
||||
char *buf = buf0;
|
||||
int nwrote, tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
/* Unfortunately this doesn't help when the
|
||||
* send buffer fills during the time we're
|
||||
* writing to it, so you could still be
|
||||
* blocked after breaking this loop and starting
|
||||
* the write.
|
||||
*/
|
||||
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
nwrote = send(sfd, buf, size, fl);
|
||||
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
time(&now);
|
||||
}
|
||||
nwrote = size - nleft;
|
||||
|
||||
done:
|
||||
return (nwrote);
|
||||
} /* SSend */
|
||||
|
||||
#endif
|
|
@ -1,137 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SSendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_in *const toAddr, int tlen)
|
||||
{
|
||||
int nwrote, tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
forever {
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nwrote = sendto(sfd, buf, size, fl,
|
||||
(struct sockaddr *) toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
(void) alarm(0);
|
||||
if (nwrote >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nwrote);
|
||||
} /* SSendto */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SSendto(int sfd, const char *const buf, size_t size, int fl, const struct sockaddr_in *const toAddr, int tlen)
|
||||
{
|
||||
int nwrote, tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
nwrote = 0;
|
||||
forever {
|
||||
forever {
|
||||
if (now >= done) {
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
time(&now);
|
||||
}
|
||||
|
||||
nwrote = sendto(sfd, buf, size, fl,
|
||||
(struct sockaddr *) toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
|
||||
if (nwrote >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
}
|
||||
|
||||
return (nwrote);
|
||||
} /* SSendto */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
Sendto(int sfd, const char *const buf, size_t size, const struct sockaddr_in *const toAddr)
|
||||
{
|
||||
int result;
|
||||
|
||||
do {
|
||||
result = sendto(sfd, buf, size, 0,
|
||||
(struct sockaddr *) toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
return (result);
|
||||
} /* Sendto */
|
|
@ -1,149 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SSendtoByName(int sfd, const char *const buf, size_t size, int fl, const char *const toAddrStr, int tlen)
|
||||
{
|
||||
int nwrote, tleft, result;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
struct sockaddr_in toAddr;
|
||||
|
||||
if ((result = AddrStrToAddr(toAddrStr, &toAddr, -1)) < 0) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = (int) (done - now);
|
||||
forever {
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nwrote = sendto(sfd, buf, size, fl,
|
||||
(struct sockaddr *) &toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
(void) alarm(0);
|
||||
if (nwrote >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
errno = 0;
|
||||
time(&now);
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nwrote);
|
||||
} /* SSendtoByName */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SSendtoByName(int sfd, const char *const buf, size_t size, int fl, const char *const toAddrStr, int tlen)
|
||||
{
|
||||
int nwrote, tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
struct sockaddr_in toAddr;
|
||||
|
||||
if ((result = AddrStrToAddr(toAddrStr, &toAddr, -1)) < 0) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
nwrote = 0;
|
||||
forever {
|
||||
forever {
|
||||
if (now >= done) {
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
time(&now);
|
||||
}
|
||||
|
||||
nwrote = sendto(sfd, buf, size, fl,
|
||||
(struct sockaddr *) &toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
|
||||
if (nwrote >= 0)
|
||||
break;
|
||||
if (errno != EINTR)
|
||||
break; /* Fatal error. */
|
||||
}
|
||||
|
||||
return (nwrote);
|
||||
} /* SSendto */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int
|
||||
SendtoByName(int sfd, const char *const buf, size_t size, const char *const toAddrStr)
|
||||
{
|
||||
int result;
|
||||
struct sockaddr_in toAddr;
|
||||
|
||||
if ((result = AddrStrToAddr(toAddrStr, &toAddr, -1)) < 0) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
do {
|
||||
result = sendto(sfd, buf, size, 0,
|
||||
(struct sockaddr *) &toAddr,
|
||||
(int) sizeof(struct sockaddr_in));
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
return (result);
|
||||
} /* SendtoByName */
|
|
@ -1,108 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
/*
|
||||
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
|
||||
*/
|
||||
int
|
||||
SWaitUntilReadyForReading(const int sfd, const int tlen)
|
||||
{
|
||||
fd_set ss, ss2;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
int tleft;
|
||||
time_t now, done;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (0);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = tlen;
|
||||
|
||||
forever {
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
ss2 = ss;
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG234 &ss2, &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
return (1);
|
||||
} else if (result < 0) {
|
||||
if (errno != EINTR) {
|
||||
/* error */
|
||||
return (0);
|
||||
}
|
||||
/* try again */
|
||||
time(&now);
|
||||
if (now > done) {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
} else {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
} /* SWaitUntilReadyForReading */
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return zero if the operation timed-out or erred-out, otherwise non-zero.
|
||||
*/
|
||||
int
|
||||
SWaitUntilReadyForWriting(const int sfd, const int tlen)
|
||||
{
|
||||
fd_set ss, ss2;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
int tleft;
|
||||
time_t now, done;
|
||||
|
||||
if (sfd < 0) {
|
||||
errno = EBADF;
|
||||
return (0);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
tleft = tlen;
|
||||
|
||||
forever {
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
ss2 = ss;
|
||||
tv.tv_sec = tleft;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, SELECT_TYPE_ARG234 &ss2, &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
return (1);
|
||||
} else if (result < 0) {
|
||||
if (errno != EINTR) {
|
||||
/* error */
|
||||
return (0);
|
||||
}
|
||||
/* try again */
|
||||
time(&now);
|
||||
if (now > done) {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
tleft = (int) (done - now);
|
||||
} else {
|
||||
/* timed-out */
|
||||
errno = ETIMEDOUT;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
} /* SWaitUntilReadyForWriting */
|
|
@ -1,180 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SIGNALS
|
||||
|
||||
int
|
||||
SWrite(int sfd, const char *const buf0, size_t size, int tlen, int swopts)
|
||||
{
|
||||
volatile int nleft;
|
||||
const char *volatile buf = buf0;
|
||||
int nwrote, tleft;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
time_t done, now;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
if (SSetjmp(gPipeJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = EPIPE;
|
||||
return (kBrokenPipeErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler);
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
(void) alarm((unsigned int) tleft);
|
||||
nwrote = write(sfd, buf, nleft);
|
||||
(void) alarm(0);
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
time(&now);
|
||||
}
|
||||
nwrote = size - nleft;
|
||||
|
||||
done:
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
|
||||
return (nwrote);
|
||||
} /* SWrite */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
SWrite(int sfd, const char *const buf0, size_t size, int tlen, int swopts)
|
||||
{
|
||||
int nleft;
|
||||
const char *buf = buf0;
|
||||
int nwrote, tleft;
|
||||
time_t done, now;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
int result, firstWrite;
|
||||
|
||||
nleft = (int) size;
|
||||
time(&now);
|
||||
done = now + tlen;
|
||||
firstWrite = 1;
|
||||
|
||||
forever {
|
||||
tleft = (int) (done - now);
|
||||
if (tleft < 1) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0) {
|
||||
nwrote = kTimeoutErr;
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
/* Unfortunately this doesn't help when the
|
||||
* send buffer fills during the time we're
|
||||
* writing to it, so you could still be
|
||||
* blocked after breaking this loop and starting
|
||||
* the write.
|
||||
*/
|
||||
if (!firstWrite || ((swopts & kNoFirstSelect) == 0)) {
|
||||
forever {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, NULL, SELECT_TYPE_ARG234 &ss, NULL, SELECT_TYPE_ARG5 &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
nwrote = size - nleft;
|
||||
if (nwrote > 0)
|
||||
return (nwrote);
|
||||
errno = ETIMEDOUT;
|
||||
SETWSATIMEOUTERR
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
firstWrite = 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
nwrote = send(sfd, buf, size, 0);
|
||||
#else
|
||||
nwrote = write(sfd, buf, size);
|
||||
#endif
|
||||
|
||||
if (nwrote < 0) {
|
||||
if (errno != EINTR) {
|
||||
nwrote = size - nleft;
|
||||
if (nwrote == 0)
|
||||
nwrote = -1;
|
||||
goto done;
|
||||
} else {
|
||||
errno = 0;
|
||||
nwrote = 0;
|
||||
/* Try again. */
|
||||
}
|
||||
}
|
||||
nleft -= nwrote;
|
||||
if (nleft <= 0)
|
||||
break;
|
||||
buf += nwrote;
|
||||
time(&now);
|
||||
}
|
||||
nwrote = size - nleft;
|
||||
|
||||
done:
|
||||
return (nwrote);
|
||||
} /* SWrite */
|
||||
|
||||
#endif
|
|
@ -1,203 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef SO_RCVBUF
|
||||
int
|
||||
GetSocketBufSize(int UNUSED(sockfd), size_t *const rsize, size_t *const ssize)
|
||||
{
|
||||
LIBSIO_USE_VAR(sockfd);
|
||||
if (ssize != NULL)
|
||||
*ssize = 0;
|
||||
if (rsize != NULL)
|
||||
*rsize = 0;
|
||||
return (-1);
|
||||
} /* GetSocketBufSize */
|
||||
#else
|
||||
int
|
||||
GetSocketBufSize(int sockfd, size_t *const rsize, size_t *const ssize)
|
||||
{
|
||||
int rc = -1;
|
||||
int opt;
|
||||
int optsize;
|
||||
|
||||
if (ssize != NULL) {
|
||||
opt = 0;
|
||||
optsize = sizeof(opt);
|
||||
rc = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &opt, &optsize);
|
||||
if (rc == 0)
|
||||
*ssize = (size_t) opt;
|
||||
else
|
||||
*ssize = 0;
|
||||
}
|
||||
if (rsize != NULL) {
|
||||
opt = 0;
|
||||
optsize = sizeof(opt);
|
||||
rc = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &opt, &optsize);
|
||||
if (rc == 0)
|
||||
*rsize = (size_t) opt;
|
||||
else
|
||||
*rsize = 0;
|
||||
}
|
||||
return (rc);
|
||||
} /* GetSocketBufSize */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef SO_RCVBUF
|
||||
int
|
||||
SetSocketBufSize(int UNUSED(sockfd), size_t UNUSED(rsize), size_t UNUSED(ssize))
|
||||
{
|
||||
LIBSIO_USE_VAR(sockfd);
|
||||
LIBSIO_USE_VAR(rsize);
|
||||
LIBSIO_USE_VAR(ssize);
|
||||
return (-1);
|
||||
} /* SetSocketBufSize */
|
||||
#else
|
||||
int
|
||||
SetSocketBufSize(int sockfd, size_t rsize, size_t ssize)
|
||||
{
|
||||
int rc = -1;
|
||||
int opt;
|
||||
int optsize;
|
||||
|
||||
if (ssize > 0) {
|
||||
opt = (int) ssize;
|
||||
optsize = sizeof(opt);
|
||||
rc = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &opt, optsize);
|
||||
if (rc < 0)
|
||||
return (rc);
|
||||
}
|
||||
if (rsize > 0) {
|
||||
opt = (int) rsize;
|
||||
optsize = sizeof(opt);
|
||||
rc = setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &opt, optsize);
|
||||
if (rc < 0)
|
||||
return (rc);
|
||||
}
|
||||
return (0);
|
||||
} /* SetSocketBufSize */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TCP_NODELAY
|
||||
int
|
||||
GetSocketNagleAlgorithm(const int UNUSED(fd))
|
||||
{
|
||||
LIBSIO_USE_VAR(fd);
|
||||
return (-1);
|
||||
} /* GetSocketNagleAlgorithm */
|
||||
#else
|
||||
int
|
||||
GetSocketNagleAlgorithm(const int fd)
|
||||
{
|
||||
int optsize;
|
||||
int opt;
|
||||
|
||||
opt = -2;
|
||||
optsize = (int) sizeof(opt);
|
||||
if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &opt, &optsize) < 0)
|
||||
return (-1);
|
||||
return (opt);
|
||||
} /* GetSocketNagleAlgorithm */
|
||||
#endif /* TCP_NODELAY */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TCP_NODELAY
|
||||
int
|
||||
SetSocketNagleAlgorithm(const int UNUSED(fd), const int UNUSED(onoff))
|
||||
{
|
||||
LIBSIO_USE_VAR(fd);
|
||||
LIBSIO_USE_VAR(onoff);
|
||||
return (-1);
|
||||
} /* SetSocketNagleAlgorithm */
|
||||
#else
|
||||
int
|
||||
SetSocketNagleAlgorithm(const int fd, const int onoff)
|
||||
{
|
||||
int optsize;
|
||||
int opt;
|
||||
|
||||
opt = onoff;
|
||||
optsize = (int) sizeof(opt);
|
||||
return (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &opt, optsize));
|
||||
} /* SetSocketNagleAlgorithm */
|
||||
#endif /* TCP_NODELAY */
|
||||
|
||||
|
||||
|
||||
#ifndef SO_LINGER
|
||||
int
|
||||
GetSocketLinger(const int UNUSED(fd), int *const UNUSED(lingertime))
|
||||
{
|
||||
LIBSIO_USE_VAR(fd);
|
||||
LIBSIO_USE_VAR(lingertime);
|
||||
return (-1);
|
||||
} /* GetSocketLinger */
|
||||
#else
|
||||
int
|
||||
GetSocketLinger(const int fd, int *const lingertime)
|
||||
{
|
||||
int optsize;
|
||||
struct linger opt;
|
||||
|
||||
optsize = (int) sizeof(opt);
|
||||
opt.l_onoff = 0;
|
||||
opt.l_linger = 0;
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &opt, &optsize) < 0)
|
||||
return (-1);
|
||||
if (lingertime != NULL)
|
||||
*lingertime = opt.l_linger;
|
||||
return (opt.l_onoff);
|
||||
} /* GetSocketLinger */
|
||||
#endif /* SO_LINGER */
|
||||
|
||||
|
||||
|
||||
#ifndef SO_LINGER
|
||||
int
|
||||
SetSocketLinger(const int UNUSED(fd), const int UNUSED(l_onoff), const int UNUSED(l_linger))
|
||||
{
|
||||
LIBSIO_USE_VAR(fd);
|
||||
LIBSIO_USE_VAR(l_onoff);
|
||||
LIBSIO_USE_VAR(l_linger);
|
||||
return (-1);
|
||||
} /* SetSocketLinger */
|
||||
#else
|
||||
int
|
||||
SetSocketLinger(const int fd, const int l_onoff, const int l_linger)
|
||||
{
|
||||
struct linger opt;
|
||||
int optsize;
|
||||
/*
|
||||
* From hpux:
|
||||
*
|
||||
* Structure used for manipulating linger option.
|
||||
*
|
||||
* if l_onoff == 0:
|
||||
* close(2) returns immediately; any buffered data is sent later
|
||||
* (default)
|
||||
*
|
||||
* if l_onoff != 0:
|
||||
* if l_linger == 0, close(2) returns after discarding any unsent data
|
||||
* if l_linger != 0, close(2) does not return until buffered data is sent
|
||||
*/
|
||||
#if 0
|
||||
struct linger {
|
||||
int l_onoff; /* 0 = do not wait to send data */
|
||||
/* non-0 = see l_linger */
|
||||
int l_linger; /* 0 = discard unsent data */
|
||||
/* non-0 = wait to send data */
|
||||
};
|
||||
#endif
|
||||
opt.l_onoff = l_onoff;
|
||||
opt.l_linger = l_linger;
|
||||
optsize = (int) sizeof(opt);
|
||||
return (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &opt, optsize));
|
||||
} /* SetSocketLinger */
|
||||
#endif /* SO_LINGER */
|
|
@ -1,221 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#ifndef INADDR_ANY
|
||||
# define INADDR_ANY ((unsigned long int) 0x00000000)
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
# define INADDR_NONE ((unsigned long int) 0xffffffff)
|
||||
#endif
|
||||
|
||||
/* Linux libc 5.3.x has a bug that causes isalnum() to not work! */
|
||||
#define ISALNUM(c) ( (((c) >= 'A') && ((c) <= 'Z')) || (((c) >= 'a') && ((c) <= 'z')) || (((c) >= '0') && ((c) <= '9')) )
|
||||
|
||||
static unsigned int
|
||||
ServiceNameToPortNumber(const char *const s)
|
||||
{
|
||||
char str[64];
|
||||
char *cp;
|
||||
struct servent *sp;
|
||||
|
||||
strncpy(str, s, sizeof(str) - 1);
|
||||
str[sizeof(str) - 1] = '\0';
|
||||
cp = str;
|
||||
if (isdigit(*cp)) {
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
*cp = '\0';
|
||||
return (atoi(str));
|
||||
}
|
||||
for (;; cp++) {
|
||||
if ((*cp == '\0')
|
||||
|| ((!ISALNUM(*cp)) && (*cp != '-') && (*cp != '_')))
|
||||
break;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
sp = getservbyname(str, "tcp");
|
||||
if (sp != NULL) {
|
||||
/* endservent(); */
|
||||
return ((unsigned int) ntohs((unsigned short) sp->s_port));
|
||||
}
|
||||
sp = getservbyname(str, "udp");
|
||||
if (sp != NULL) {
|
||||
/* endservent(); */
|
||||
return ((unsigned int) ntohs((unsigned short) sp->s_port));
|
||||
}
|
||||
return (0); /* error */
|
||||
} /* ServiceNameToPortNumber */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
AddrStrToAddr(const char * const s, struct sockaddr_in * const sa, const int defaultport)
|
||||
{
|
||||
char portstr[128];
|
||||
unsigned long ipnum;
|
||||
unsigned int port;
|
||||
struct hostent *hp;
|
||||
char *hostcp, *atsign, *colon, *cp, *p2;
|
||||
|
||||
memset(sa, 0, sizeof(struct sockaddr_in));
|
||||
strncpy(portstr, s, sizeof(portstr));
|
||||
portstr[sizeof(portstr) - 1] = '\0';
|
||||
|
||||
if ((colon = strchr(portstr, ':')) != NULL) {
|
||||
/* Does it look like a URL? http://host ? */
|
||||
if ((colon[1] == '/') && (colon[2] == '/')) {
|
||||
*colon = '\0';
|
||||
port = 0;
|
||||
hostcp = colon + 3;
|
||||
for (cp = hostcp; *cp != '\0'; cp++) {
|
||||
if ((!ISALNUM(*cp)) && (*cp != '.')) {
|
||||
/* http://host:port */
|
||||
if ((*cp == ':') && (isdigit(cp[1]))) {
|
||||
*cp++ = '\0';
|
||||
p2 = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
*cp = '\0';
|
||||
port = atoi(p2);
|
||||
}
|
||||
*cp = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (port == 0)
|
||||
port = ServiceNameToPortNumber(portstr);
|
||||
} else {
|
||||
/* Look for host.name.domain:port */
|
||||
*colon = '\0';
|
||||
hostcp = portstr;
|
||||
port = (unsigned int) atoi(colon + 1);
|
||||
}
|
||||
} else if ((atsign = strchr(portstr, '@')) != NULL) {
|
||||
/* Look for port@host.name.domain */
|
||||
*atsign = '\0';
|
||||
hostcp = atsign + 1;
|
||||
port = (unsigned int) atoi(portstr);
|
||||
} else if (defaultport > 0) {
|
||||
/* Have just host.name.domain, use that w/ default port. */
|
||||
port = (unsigned int) defaultport;
|
||||
hostcp = portstr;
|
||||
} else {
|
||||
/* If defaultport <= 0, they must supply a port number
|
||||
* in the host/port string.
|
||||
*/
|
||||
errno = EADDRNOTAVAIL;
|
||||
return (kAddrStrToAddrMiscErr);
|
||||
}
|
||||
|
||||
sa->sin_port = htons((short) port);
|
||||
|
||||
ipnum = inet_addr(hostcp);
|
||||
if (ipnum != INADDR_NONE) {
|
||||
sa->sin_family = AF_INET;
|
||||
sa->sin_addr.s_addr = ipnum;
|
||||
} else {
|
||||
errno = 0;
|
||||
hp = gethostbyname(hostcp);
|
||||
if (hp == NULL) {
|
||||
if (errno == 0)
|
||||
errno = ENOENT;
|
||||
return (kAddrStrToAddrBadHost);
|
||||
}
|
||||
sa->sin_family = hp->h_addrtype;
|
||||
memcpy(&sa->sin_addr.s_addr, hp->h_addr_list[0],
|
||||
(size_t) hp->h_length);
|
||||
}
|
||||
return (0);
|
||||
} /* AddrStrToAddr */
|
||||
|
||||
|
||||
|
||||
char *
|
||||
AddrToAddrStr(char *const dst, size_t dsize, struct sockaddr_in * const saddrp, int dns, const char *fmt)
|
||||
{
|
||||
const char *addrNamePtr;
|
||||
struct hostent *hp;
|
||||
char str[128];
|
||||
char *dlim, *dp;
|
||||
const char *cp;
|
||||
struct servent *pp;
|
||||
|
||||
if (dns == 0) {
|
||||
addrNamePtr = inet_ntoa(saddrp->sin_addr);
|
||||
} else {
|
||||
hp = gethostbyaddr((char *) &saddrp->sin_addr, (int) sizeof(struct in_addr), AF_INET);
|
||||
if ((hp != NULL) && (hp->h_name != NULL) && (hp->h_name[0] != '\0')) {
|
||||
addrNamePtr = hp->h_name;
|
||||
} else {
|
||||
addrNamePtr = inet_ntoa(saddrp->sin_addr);
|
||||
}
|
||||
}
|
||||
if (fmt == NULL)
|
||||
fmt = "%h:%p";
|
||||
for (dp = dst, dlim = dp + dsize - 1; ; fmt++) {
|
||||
if (*fmt == '\0') {
|
||||
break; /* done */
|
||||
} else if (*fmt == '%') {
|
||||
fmt++;
|
||||
if (*fmt == '%') {
|
||||
if (dp < dlim)
|
||||
*dp++ = '%';
|
||||
} else if (*fmt == 'p') {
|
||||
sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
|
||||
for (cp = str; *cp != '\0'; cp++)
|
||||
if (dp < dlim)
|
||||
*dp++ = *cp;
|
||||
*dp = '\0';
|
||||
} else if (*fmt == 'h') {
|
||||
if (addrNamePtr != NULL) {
|
||||
cp = addrNamePtr;
|
||||
} else {
|
||||
cp = "unknown";
|
||||
}
|
||||
for ( ; *cp != '\0'; cp++)
|
||||
if (dp < dlim)
|
||||
*dp++ = *cp;
|
||||
*dp = '\0';
|
||||
} else if (*fmt == 's') {
|
||||
pp = getservbyport((int) (saddrp->sin_port), "tcp");
|
||||
if (pp == NULL)
|
||||
pp = getservbyport((int) (saddrp->sin_port), "udp");
|
||||
if (pp == NULL) {
|
||||
sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
|
||||
cp = str;
|
||||
} else {
|
||||
cp = pp->s_name;
|
||||
}
|
||||
for ( ; *cp != '\0'; cp++)
|
||||
if (dp < dlim)
|
||||
*dp++ = *cp;
|
||||
/* endservent(); */
|
||||
*dp = '\0';
|
||||
} else if ((*fmt == 't') || (*fmt == 'u')) {
|
||||
pp = getservbyport((int) (saddrp->sin_port), (*fmt == 'u') ? "udp" : "tcp");
|
||||
if (pp == NULL) {
|
||||
sprintf(str, "%u", (unsigned int) ntohs(saddrp->sin_port));
|
||||
cp = str;
|
||||
} else {
|
||||
cp = pp->s_name;
|
||||
}
|
||||
for ( ; *cp != '\0'; cp++)
|
||||
if (dp < dlim)
|
||||
*dp++ = *cp;
|
||||
/* endservent(); */
|
||||
*dp = '\0';
|
||||
} else if (*fmt == '\0') {
|
||||
break;
|
||||
} else {
|
||||
if (dp < dlim)
|
||||
*dp++ = *fmt;
|
||||
}
|
||||
} else if (dp < dlim) {
|
||||
*dp++ = *fmt;
|
||||
}
|
||||
}
|
||||
*dp = '\0';
|
||||
return (dst);
|
||||
} /* AddrToAddrStr */
|
|
@ -1,49 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_UNIX_DOMAIN_SOCKETS) && !defined(NO_SIGNALS)
|
||||
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
|
||||
int
|
||||
UAcceptA(int sfd, struct sockaddr_un *const addr, int *ualen, int tlen)
|
||||
{
|
||||
int result;
|
||||
vsio_sigproc_t sigalrm, sigpipe;
|
||||
|
||||
if (tlen < 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
*ualen = (int) sizeof(struct sockaddr_un);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) ualen);
|
||||
if ((result >= 0) || (errno != EINTR))
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIG_IGN);
|
||||
alarm((unsigned int) tlen);
|
||||
|
||||
errno = 0;
|
||||
do {
|
||||
*ualen = (int) sizeof(struct sockaddr_un);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) ualen);
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
(void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
|
||||
return (result);
|
||||
} /* UAcceptA */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_UNIX_DOMAIN_SOCKETS)
|
||||
|
||||
int
|
||||
UAcceptS(int sfd, struct sockaddr_un *const addr, int *ualen, int tlen)
|
||||
{
|
||||
int result;
|
||||
fd_set ss;
|
||||
struct timeval tv;
|
||||
|
||||
if (tlen < 0) {
|
||||
errno = 0;
|
||||
for (;;) {
|
||||
*ualen = (int) sizeof(struct sockaddr_un);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) ualen);
|
||||
if ((result >= 0) || (errno != EINTR))
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
errno = 0;
|
||||
FD_ZERO(&ss);
|
||||
FD_SET(sfd, &ss);
|
||||
tv.tv_sec = tlen;
|
||||
tv.tv_usec = 0;
|
||||
result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, &tv);
|
||||
if (result == 1) {
|
||||
/* ready */
|
||||
break;
|
||||
} else if (result == 0) {
|
||||
/* timeout */
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
} else if (errno != EINTR) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
*ualen = (int) sizeof(struct sockaddr_un);
|
||||
result = accept(sfd, (struct sockaddr *) addr, (int *) ualen);
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
return (result);
|
||||
} /* UAcceptS */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_UNIX_DOMAIN_SOCKETS)
|
||||
|
||||
int
|
||||
UBind(int sockfd, const char *const astr, const int nTries, const int reuseFlag)
|
||||
{
|
||||
unsigned int i;
|
||||
int on;
|
||||
int onsize;
|
||||
struct sockaddr_un localAddr;
|
||||
int ualen;
|
||||
|
||||
ualen = MakeSockAddrUn(&localAddr, astr);
|
||||
(void) unlink(localAddr.sun_path);
|
||||
|
||||
if (reuseFlag != kReUseAddrNo) {
|
||||
/* This is mostly so you can quit the server and re-run it
|
||||
* again right away. If you don't do this, the OS may complain
|
||||
* that the address is still in use.
|
||||
*/
|
||||
on = 1;
|
||||
onsize = (int) sizeof(on);
|
||||
(void) setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &on, onsize);
|
||||
}
|
||||
|
||||
for (i=1; ; i++) {
|
||||
/* Try binding a few times, in case we get Address in Use
|
||||
* errors.
|
||||
*/
|
||||
if (bind(sockfd, (struct sockaddr *) &localAddr, ualen) == 0) {
|
||||
break;
|
||||
}
|
||||
if (i == (unsigned int) nTries) {
|
||||
return (-1);
|
||||
}
|
||||
/* Give the OS time to clean up the old socket,
|
||||
* and then try again.
|
||||
*/
|
||||
sleep(i * 3);
|
||||
}
|
||||
|
||||
return (0);
|
||||
} /* UBind */
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
UListen(int sfd, int backlog)
|
||||
{
|
||||
return (listen(sfd, backlog));
|
||||
} /* UListen */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#include "syshdrs.h"
|
||||
|
||||
#if !defined(NO_UNIX_DOMAIN_SOCKETS) && !defined(NO_SIGNALS)
|
||||
|
||||
extern volatile Sjmp_buf gNetTimeoutJmp;
|
||||
extern volatile Sjmp_buf gPipeJmp;
|
||||
|
||||
int
|
||||
UConnect(int sfd, const struct sockaddr_un *const addr, int ualen, int tlen)
|
||||
{
|
||||
int result;
|
||||
vsio_sigproc_t sigalrm;
|
||||
|
||||
if (SSetjmp(gNetTimeoutJmp) != 0) {
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
errno = ETIMEDOUT;
|
||||
return (kTimeoutErr);
|
||||
}
|
||||
|
||||
sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler);
|
||||
alarm((unsigned int) tlen);
|
||||
|
||||
errno = 0;
|
||||
do {
|
||||
result = connect(sfd, (struct sockaddr *) addr, ualen);
|
||||
} while ((result < 0) && (errno == EINTR));
|
||||
|
||||
alarm(0);
|
||||
(void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm);
|
||||
return (result);
|
||||
} /* UConnect */
|
||||
|
||||
#endif
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue