Initial revision

This commit is contained in:
hsn 2003-09-09 15:53:39 +00:00
parent 86c16ecb3a
commit 23589d8959
6 changed files with 529 additions and 0 deletions

185
client/lib.c Normal file
View File

@ -0,0 +1,185 @@
/*********************************************************************\
* Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) *
* *
* You may copy or modify this file in any manner you wish, provided *
* that this notice is always included, and that you hold the author *
* harmless for any loss or damage resulting from the installation or *
* use of this software. *
\*********************************************************************/
#include "tweak.h"
#include "client_def.h"
#include "c_extern.h"
#include "co_extern.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
static int myfd;
static struct sockaddr_in server_addr;
static unsigned short myseq = 0;
static unsigned short key;
int client_trace = 0;
int client_intr_state = 0;
unsigned long target_delay = MIN_DELAY; /* expected max delay */
unsigned long busy_delay = MIN_DELAY; /* busy retransmit timer */
unsigned long idle_delay = MIN_DELAY; /* idle retransmit timer */
unsigned long udp_sent_time;
UBUF *client_interact PROTO6(unsigned char, cmd, unsigned long, pos,
unsigned int, l1, unsigned const char *, p1,
unsigned int, l2, unsigned const char *, p2)
{
struct sockaddr_in from;
UBUF sbuf;
static UBUF rbuf;
unsigned char *s, *t, *d, seq0, seq1;
unsigned u, n, sum, mlen, rlen;
fd_set mask;
int retval, bytes, retry_send, retry_recv;
unsigned long w_delay;
FD_ZERO(&mask);
sbuf.cmd = cmd;
#ifdef DEBUG
printf("sbuf.cmd = %u\n",sbuf.cmd);
#endif
BB_WRITE2(sbuf.bb_len,l1);
BB_WRITE4(sbuf.bb_pos,pos);
client_intr_state = 1;
for(u = l1, d = (unsigned char *) sbuf.buf; u--; *d++ = *p1++);
for(u = l2; u--; *d++ = *p2++);
mlen = d - (unsigned char *) &sbuf;
key = client_get_key();
for(retry_send = 0; ; retry_send++) {
BB_WRITE2(sbuf.bb_key,key);
sbuf.bb_seq[0] = seq0 = (myseq >> 8) & 0xff;
sbuf.bb_seq[1] = seq1 = (myseq & 0xfc) | (retry_send & 0x0003);
sbuf.sum = 0;
for(t = (unsigned char *) &sbuf, sum = n = mlen; n--; sum += *t++);
sbuf.sum = sum + (sum >> 8);
switch(retry_send) { /* adaptive retry delay adjustments */
case 0:
busy_delay = (target_delay+(busy_delay<<3)-busy_delay)>>3;
w_delay = busy_delay;
break;
case 1:
busy_delay = busy_delay * 3 / 2;
w_delay = busy_delay;
if(client_trace) write(2,"R",1); break;
default:
#ifdef CLIENT_TIMEOUT
if (!pos && retry_send >= env_timeout ) {
fprintf(stderr, "\rRemote server not responding.\n");
exit(1);
}
#endif
if(idle_delay < 3*60*1000) idle_delay = idle_delay * 3 / 2;
w_delay = idle_delay;
if(client_trace) write(2,"I",1);
break;
}
if(sendto(myfd,(const char*)&sbuf,mlen,0,(struct sockaddr *)&server_addr,
sizeof(server_addr)) == -1) {
perror("sendto");
exit(1);
}
udp_sent_time = time((time_t *) 0);
FD_SET(myfd,&mask);
for(retry_recv = 0; ; retry_recv++) {
if(retry_recv && client_trace) write(2,"E",1);
retval = _x_select(&mask, w_delay);
if((retval == -1) && (errno == EINTR)) continue;
if(retval == 1) { /* an incoming message is waiting */
bytes = sizeof(from);
if((bytes = recvfrom(myfd,(char*)&rbuf,sizeof(rbuf),0,
(struct sockaddr *)&from, &bytes)) < UBUF_HSIZE)
continue;
s = (unsigned char *) &rbuf;
d = s + bytes;
u = rbuf.sum; rbuf.sum = 0;
for(t = s, sum = 0; t < d; sum += *t++);
sum = (sum + (sum >> 8)) & 0xff;
if(sum != u) continue; /* wrong check sum */
rlen = BB_READ2(rbuf.bb_len);
if( (rbuf.bb_seq[0] ^ seq0) ||
((rbuf.bb_seq[1] ^ seq1)&0xfc)) continue; /* wrong seq # */
if((int) (rlen+UBUF_HSIZE) > bytes) continue; /* truncated. */
myseq = (myseq + 0x0004) & 0xfffc; /* seq for next request */
key = BB_READ2(rbuf.bb_key); /* key for next request */
client_set_key(key);
if(client_intr_state == 2) {
if(!key_persists) client_done();
exit(1);
}
#ifdef DEBUG
printf("rbuf.cmd = %u\n",rbuf.cmd);
#endif
return(&rbuf);
} else break; /* go back to re-transmit buffer again */
}
}
}
static RETSIGTYPE client_intr PROTO1(int, signum)
{
switch(client_intr_state) {
case 0: exit(2);
case 1: client_intr_state = 2; break;
case 2: exit(3);
}
#ifndef RELIABLE_SIGNALS
signal(SIGINT,client_intr);
#endif
}
void init_client PROTO3(const char *, host, unsigned short, port, unsigned short, myport)
{
busy_delay = idle_delay = target_delay;
if((myfd = _x_udp(&myport)) == -1) {
perror("socket open");
exit(1);
}
if(_x_adr(host,port,&server_addr) == -1) {
perror("server addr");
exit(1);
}
client_init_key(server_addr.sin_addr.s_addr,port,getpid());
signal(SIGINT,client_intr);
}
int client_done PROTO0((void))
{
(void) client_interact(CC_BYE, 0L, 0, (unsigned char *)NULLP, 0,
(unsigned char *)NULLP);
return(0);
}

63
clients/fcdcmd.c Normal file
View File

@ -0,0 +1,63 @@
/*********************************************************************\
* Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) *
* *
* You may copy or modify this file in any manner you wish, provided *
* that this notice is always included, and that you hold the author *
* harmless for any loss or damage resulting from the installation or *
* use of this software. *
\*********************************************************************/
#include "tweak.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "client_def.h"
#include "c_extern.h"
#include "bsd_extern.h"
#include "my-string.h"
#include "printpro.h"
static int f_cd PROTO1(const char *, p)
{
UBUF *ub;
ub = client_interact(CC_GET_PRO,0L, strlen(p), (unsigned const char *)p+1, 0,
(unsigned char *)NULLP);
if(ub->cmd == CC_ERR) {
fprintf(stderr, "ERR: %s\n",ub->buf);
return(0);
} else {
fprintf(stderr, "directory %s\nmode: ",p);
print_pro(ub,stderr);
return(1);
}
}
int main PROTO2(int, argc, char **, argv)
{
char *np;
char **av, *av2[2];
env_client();
if(argc == 1) {
f_cd("/");
puts("/");
} else {
if(!(av = glob(argv[1]))) {
av = av2;
av2[0] = *argv;
av2[1] = 0;
}
np = util_abs_path(*av);
if(f_cd(np))puts(np);
else {
puts(env_dir);
}
}
client_done();
exit(0);
}

119
clients/fducmd.c Normal file
View File

@ -0,0 +1,119 @@
/******************************************************************************
* This file is Copyright 1992 by Philip G. Richards. All Rights Reserved.
* See the file README that came with this distribution for permissions on
* code usage, copying, and distribution. It comes with absolutely no warranty.
* email: <pgr@prg.ox.ac.uk>
******************************************************************************/
/*****************************************************************************
* reprogrammed as a stand alone client by Michael Meskes
* <meskes@ulysses.informatik.rwth-aachen.de>
******************************************************************************/
#include "tweak.h"
#include "client_def.h"
#include "c_extern.h"
#include "bsd_extern.h"
#include "my-string.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/*************************************************************************
* The following global variables are used by fdu *
* Added 5. Apr. 93 by M.Meskes *
*************************************************************************/
#define RECURSIVE 1
#define SUM 2
#define EACH 4
static u_long total_file_size;
static void add_file_size PROTO4(char *, name, struct stat *, sbufp,
int, mode, int, level)
{
register u_long file_size;
file_size = (sbufp->st_size + 1023) / 1024;
total_file_size += file_size;
if(((mode & EACH) && (mode & RECURSIVE)) ||
((mode & EACH) && level < 2)) printf("%-7ld %s\n", file_size, name);
}
static int start_dir PROTO3(char *, name, struct stat *, sbufp, u_long *, sum)
{
*sum = total_file_size;
return(0);
}
static void end_dir PROTO4(char *, path, int, mode, u_long, sum, int, level)
{
/* directories are printed as default */
/* but, check recursion level */
if(((mode & RECURSIVE) && !(mode & SUM)) ||
((level == 1) && (!(mode & SUM) || (mode & EACH))) ||
!level) {
sum = total_file_size - sum; /* this is the real value */
printf("%-7ld %s\n", sum, path);
}
}
/* ARGSUSED */
int main PROTO2(int, argc, char **, argv)
{
int mode=0;
int filcnt = 0;
static const char *wild[2] = { ".", 0 };
char **files, *singlefile[2];
int optletter;
env_client();
while ((optletter=getopt(argc, argv,"ras")) != EOF)
switch (optletter) {
case 'r':
mode |= RECURSIVE; /* recursively read all subdirectories */
break;
case 's':
mode |= SUM; /* print sums only */
break;
case 'a':
mode |= EACH; /* print an entry for each file */
break;
default:
fprintf(stderr,"Usage: du [-r|a|s] directory name.\n");
exit(0);
}
/* special case `du' without file arguments -- becomes `du .' */
if (argc == optind) {
argv=wild;
optind=0;
}
for ( ; argv[optind]; optind++) {
if (!(files = glob(argv[optind]))) {
files = singlefile;
singlefile[0] = argv[optind];
singlefile[1] = 0;
}
for ( ; *files; files++) {
util_process_file(*files, mode, add_file_size, start_dir, end_dir, 0);
filcnt++;
}
}
if (filcnt > 1) {
fprintf(stdout, "--------:------\n");
fprintf(stdout, "%-7ld TOTAL\n", total_file_size);
}
client_done();
return 0;
}

91
clients/fprocmd.c Normal file
View File

@ -0,0 +1,91 @@
/*********************************************************************\
* Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) *
* *
* You may copy or modify this file in any manner you wish, provided *
* that this notice is always included, and that you hold the author *
* harmless for any loss or damage resulting from the installation or *
* use of this software. *
\*********************************************************************/
#include "tweak.h"
#include "client_def.h"
#include "c_extern.h"
#include "bsd_extern.h"
#include "my-string.h"
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "printpro.h"
static int get_pro PROTO1(const char *, p)
{
char *op;
UBUF *ub;
op = util_abs_path(p);
ub = client_interact(CC_GET_PRO,0L, strlen(op), (unsigned char *)op+1, 0,
(unsigned char *)NULLP);
if(ub->cmd == CC_ERR) {
fprintf(stderr, "ERR: %s\n",ub->buf);
return(1);
}
printf("%s\n",p);
print_pro(ub,stdout);
return(0);
}
static int set_pro PROTO2(char *, p, char *, key)
{
char *op;
UBUF *ub;
op = util_abs_path(p);
ub = client_interact(CC_SET_PRO,0L, strlen(op), (unsigned char *)op+1,
strlen(key)+1, (unsigned char *)key);
if(ub->cmd == CC_ERR) {
fprintf(stderr, "ERR: %s\n",ub->buf);
return(1);
}
printf("%s\n",p);
print_pro(ub,stdout);
return(0);
}
int main PROTO2(int, argc, char **, argv)
{
char **av, *av2[2], *key;
env_client();
if(argv[1] && (argv[1][0] == '+' || argv[1][0] == '-') && !argv[1][2]) {
key = *++argv;
while(*++argv) {
if(!(av = glob(*argv))) {
av = av2;
av2[0] = *argv;
av2[1] = 0;
}
while(*av) set_pro(*av++,key);
}
} else {
if(argv[1]) while(*++argv) {
if(!(av = glob(*argv))) {
av = av2;
av2[0] = *argv;
av2[1] = 0;
}
while(*av) get_pro(*av++);
} else get_pro(env_dir);
}
client_done();
exit(0);
}

42
include/c_extern.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef _FSP_C_EXTERN_H_
#define _FSP_C_EXTERN_H_ 1
/* lib.c */
extern int client_trace;
extern unsigned long udp_sent_time,target_delay;
UBUF *client_interact PROTO0((unsigned char, unsigned long, unsigned int,
unsigned const char *, unsigned int,
unsigned const char *));
void init_client PROTO0((const char *, unsigned short, unsigned short));
int client_done PROTO0((void));
/* lock.c */
extern int key_persists;
unsigned short client_get_key PROTO0((void));
void client_set_key PROTO0((unsigned short));
void client_init_key PROTO0((unsigned long, unsigned long,
unsigned short));
/* util.c */
extern const char *env_dir,*env_passwd,*env_local_dir,*env_port,*env_myport,*env_host;
extern int env_timeout;
extern unsigned short client_buf_len,client_net_len;
char *util_abs_path PROTO0((const char *));
char *util_getwd PROTO0((char *));
int util_download PROTO0((char *, FILE *, unsigned long));
int util_grab_file PROTO0((char *, FILE *, unsigned long));
int util_upload PROTO0((char *, FILE *, time_t));
void env_client PROTO0((void));
RDIR *util_opendir PROTO0((char *));
void util_closedir PROTO0((RDIR *));
rdirent *util_readdir PROTO0((RDIR *));
int util_stat PROTO0((char *, struct stat *));
int util_cd PROTO0((char *));
int util_cd2 PROTO0((char *));
void util_process_file PROTO0((char *, int,
void (*)PROTO0((char *,struct stat *,int,int)),
int (*)PROTO0((char *,struct stat *,u_long *)),
void (*)PROTO0((char *,int,u_long,int)),
int));
#endif /* _FSP_C_EXTERN_H_ */

29
include/proto.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef _FSP_PROTO_H_
#define _FSP_PROTO_H_ 1
/* #ifdef UNDERSTANDS_PROTOTYPES */
#ifdef PROTOTYPES
#define PROTO0(a) a
#define PROTO1(a, b) (a b)
#define PROTO2(a, b, c, d) (a b, c d)
#define PROTO3(a, b, c, d, e, f) (a b, c d, e f)
#define PROTO4(a, b, c, d, e, f, g, h) (a b, c d, e f, g h)
#define PROTO5(a, b, c, d, e, f, g, h, i, j) (a b, c d, e f, g h, i j)
#define PROTO6(a, b, c, d, e, f, g, h, i, j, k, l) (a b, c d, e f, g h, i j, k l)
#define PROTO7(a, b, c, d, e, f, g, h, i, j, k, l, m, n) (a b, c d, e f, g h, i j, k l, m n)
#else
#define PROTO0(a) ()
#define PROTO1(a, b) (b) a b;
#define PROTO2(a, b, c, d) (b, d) a b; c d;
#define PROTO3(a, b, c, d, e, f) (b, d, f) a b; c d; e f;
#define PROTO4(a, b, c, d, e, f, g, h) (b, d, f, h) a b; c d; e f; g h;
#define PROTO5(a, b, c, d, e, f, g, h, i, j) (b, d, f, h, j) \
a b; c d; e f; g h; i j;
#define PROTO6(a, b, c, d, e, f, g, h, i, j, k, l) (b, d, f, h, j, l) \
a b; c d; e f; g h; i j; k l;
#define PROTO6(a, b, c, d, e, f, g, h, i, j, k, l, m, n) (b, d, f, h, j, l) \
a b; c d; e f; g h; i j; k l;m n;
#endif /* UNDERSTANDS_PROTOTYPES */
#endif