rfa.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 1,200 行 · 第 1/3 页

C
1,200
字号
/* * RFA - Remote File Access * * Access and Management for a partial file system tree that exists * at two sites either as master files or slave files * * rfa.c : initiator for RFA commands * * Contributed by Oliver Wenzel, GMD Berlin, 1990 * * $Header: /xtel/isode/isode/others/rfa/RCS/rfa.c,v 9.0 1992/06/16 12:47:25 isode Rel $ * * $Log: rfa.c,v $ * Revision 9.0  1992/06/16  12:47:25  isode * Release 8.0 * */#ifndef       lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/rfa/RCS/rfa.c,v 9.0 1992/06/16 12:47:25 isode Rel $";#endif/* *                              NOTICE * *    Acquisition, use, and distribution of this module and related *    materials are subject to the restrictions of a license agreement. *    Consult the Preface in the User's Manual for the full terms of *    this agreement. * */#include <ctype.h>#include "general.h" #include <stdio.h>#include <pwd.h>#include <sys/types.h>#include <sys/stat.h>#include "logger.h"#include "RFA-ops.h"	#include "RFA-types.h"	#include "rfa.h"#include "rfainfo.h"#define START		retcode=OK#define RETURN		return retcode#define CONT(r)		{retcode=(r); continue;}extern char *fsBase;extern char *isodesbinpath;extern char *isodetcpath;extern char *strtok();extern char *getRfaContext();char *myname;int connected = 0;FILE *err, *out;char cwd_remote[512];int interactive = 1;extern int commandMode;int retcode;int quit_command = 0;/*--------------------------------------------------------------*//*  getLocalFileRfaInfo						*//*--------------------------------------------------------------*/int getLocalRfaInfo(fn, rfap, rfalp, reg)    char **fn;    struct RfaInfo **rfap, **rfalp;    int reg;{    int rc;    /*--- expand symbolic links in fn ---*/    if((*fn = getRfaContext(cwd_remote, *fn)) == NULL) {	fprintf(err,		"*** local file access error : not within RFA subtree %s ***\n"		, fsBase);	return NOTOK_OUTOFSUBTREE;    }    if ((*fn = expandSymLinks(*fn)) == NULL) {	fprintf(err, "*** local file access error : %s ***\n", rfaErrStr);	return NOTOK_OUTOFSUBTREE;    }    /*--- get file Info ---*/    if ((rc = getRfaInfoList(dirname(*fn), rfalp, basename(*fn), 1)) != OK) {	fprintf(err,	    "*** local file access error : %s ***\n", errMsg(rc));	return NOTOK_FILEACCESS;    }    if ((*rfap = findRfaInfo(basename(*fn), *rfalp)) == NULL) {	releaseRfaInfoList(*fn,*rfalp);	*rfalp = NULL;	fprintf(err,"*** local file access error : %s does not exist ***\n",		*fn);	return NOTOK_FILEACCESS;    }    /*--- check if regular file ---*/    if (reg)	if (((*rfap)->ri_mode & S_IFMT) != S_IFREG) {	    releaseRfaInfoList(*fn,*rfalp);	    fprintf(err,"*** status error : not a regular file ***\n");	    *rfalp = NULL;	    return NOTOK_NOTREGULAR;	}    return OK;}/*--------------------------------------------------------------*//*  Local List Dir						*//*--------------------------------------------------------------*/do_localListDir(av)    char **av;{    struct RfaInfo *rfa, *rfalist;    char *fn;    int rc;    if (*av == NULL) {	*av = "";	*(av+1) = NULL;    }    START;    for(; *av; av++) {	if((fn = getRfaContext(cwd_remote, *av)) == NULL) {	    fprintf(err,		"*** local file access error : not within RFA subtree %s ***\n",		fsBase);	    CONT(NOTOK_OUTOFSUBTREE);	}	if ((rc = getRfaInfoList(fn, &rfalist, NULLCP, 0)) != OK) {	    fprintf(err, "*** local file access error : %s ***\n", errMsg(rc));	    CONT(NOTOK_FILEACCESS);	}	sortRfaInfoList(&rfalist);	for (rfa = rfalist; rfa; rfa = rfa->ri_next)	    fprintf(out, "%s\n", (char *)rfa2ls(rfa));	freeRfaInfoList(rfalist);    }    RETURN;}/*--------------------------------------------------------------*//*  List Dir							*//*--------------------------------------------------------------*/do_listDir(av)    char **av;{    struct RfaInfo *rfa, *rfalist;    int rc;    char *fn;    if (*av == NULL) {	*av = "";	*(av+1) = NULL;    }    START;    for(; *av; av++) {	if((fn = getRfaContext(cwd_remote, *av)) == NULL) {	    fprintf(err,		"*** local file access error : not within RFA subtree %s ***\n",		fsBase);	    CONT(NOTOK_OUTOFSUBTREE);	}	if ((rc= getRemoteRfaInfoList(fn, &rfalist)) != OK) 	    CONT(rc);	(void)sortRfaInfoList(&rfalist);	for (rfa = rfalist; rfa; rfa = rfa->ri_next)		fprintf(out, "%s\n", (char *)rfa2ls(rfa));	freeRfaInfoList(rfa);    }    RETURN;}/*--------------------------------------------------------------*//*  getRemoteRfaInfoList/*--------------------------------------------------------------*/getRemoteRfaInfoList(fn, rfap)    char *fn;    struct RfaInfo **rfap;{    struct type_RFA_FileName *arg;    struct type_RFA_FileInfoList *fil;    int res, rc;    if (getConnection() != OK)  	return NOTOK_REMOTE_ERROR;    arg = str2qb(fn, strlen(fn), 1);    if (invoke(operation_RFA_listDir, (caddr_t)arg, (caddr_t *)&fil, &res) == NOTOK) {	fprintf(err, "*** remote operation invocation failed ***\n");	qb_free(arg);	return NOTOK_REMOTE_ERROR;    }    qb_free(arg);    if (res != RY_RESULT) { 	printError(res, (caddr_t)fil, &rc);	return rc;    }    if ((*rfap = fi2rfa(fil)) == NULL) {	fprintf(err,"*** local error : no memory ***\n");	return NOTOK_LOCAL_ERROR;    }     return OK;}/*--------------------------------------------------------------*//*  Get File							*//*--------------------------------------------------------------*/do_getFile(av)    char **av;{    int rc, new = 0;    struct RfaInfo *rfalist, *rfa;    char *fn, buf[512];    int rmode = 0;    START;    for(; *av; av++) {	if((fn = getRfaContext(cwd_remote, *av)) == NULL) {	    fprintf(err,		"*** local file access error : not within RFA subtree %s ***\n",		fsBase);	    CONT(NOTOK_OUTOFSUBTREE);	}	/*--- expand symbolic links in fn ---*/	if ((fn = expandSymLinks(fn)) == NULL) {	    fprintf(err, "*** local file access error : %s ***", rfaErrStr);	    CONT(NOTOK_OUTOFSUBTREE);	}	/*--- get file Info ---*/	if ((rc=getRfaInfoList(dirname(fn),&rfalist,basename(fn), 1)) != OK)	{	    fprintf(err,		"*** local file access error : can't read rfainfo (%s) ***\n",		errMsg(rc));	    CONT(NOTOK_FILEACCESS);	}	if ((rfa = findRfaInfo(basename(fn), rfalist)) == NULL) {	    /*--- file does locally not exist, get it from master  ---*/	    if ((rfa = mallocRfaInfo(strdup(basename(fn)))) == NULL) {		releaseRfaInfoList(dirname(fn), rfalist);		fprintf(err, "*** local error : %s ***\n", rfaErrStr);		CONT(NOTOK_LOCAL_ERROR);	    }	    SET_STATUS(rfa->ri_status, RI_SLAVE);	    SET_LOCKINFO(rfa->ri_status, RI_UNLOCKED);	    SET_TRANSFER(rfa->ri_status, default_transfer);	    time(&(rfa->ri_lastChange));	    rfa->ri_modTime = 0L;	    rfa->ri_next = rfalist;	    rfalist = rfa;	    new++;	}	/*--- check if file is master ---*/	if (IS_MASTER(rfa->ri_status)) {	    releaseRfaInfoList(dirname(fn), rfalist);	    fprintf(err,"*** local file %s is master version ***\n", fn );	    CONT(NOTOK_GETMASTER);	}	/*--- check if file is unregistered ---*/	if (IS_UNREGISTERED(rfa->ri_status)) {	    if(interactive) {		fprintf(err,		"unregistered local version of %s exists, overwrite ? (y/n) : ",		fn); 		gets(buf);		if ((*buf != 'y') && (*buf != 'Y')) {		    releaseRfaInfoList(dirname(fn), rfalist);		    CONT(NOTOK_UNREG_LOCAL_FILE);		} else {		    SET_LOCKINFO(rfa->ri_status, RI_UNLOCKED);		    /*--- will be set in getfile_aux acc. to remote state ---*/		    SET_STATUS(rfa->ri_status, RI_SLAVE);		    SET_TRANSFER(rfa->ri_status, default_transfer);		    time(&(rfa->ri_lastChange));		    rfa->ri_modTime = 0L;		    new++;		}	    } else {		fprintf(err, 		    "*** unregistered local version of %s exists ***\n", fn); 		releaseRfaInfoList(dirname(fn), rfalist);		CONT(NOTOK_UNREG_LOCAL_FILE);	    }	}	/*--- otherwise we are slave or unregistered file, get from master ---*/	if ((rc = getfile_aux(fn, rfa, &rmode)) != OK) {	    releaseRfaInfoList(dirname(fn), rfalist);	    CONT(rc);	}	if(new) 	    if ((rc = putRfaInfoList(dirname(fn), rfalist)) != OK) {		fprintf(err, "*** local file access error : %s ***\n",		    errMsg(rc));		releaseRfaInfoList(dirname(fn), rfalist);		CONT(NOTOK_FILEACCESS);	    }	releaseRfaInfoList(dirname(fn), rfalist);    }    RETURN;}/*--------------------------------------------------------------*//*  unlockFile							*//*--------------------------------------------------------------*/do_unlockFile(av)    char **av;{    int rc;    struct RfaInfo *rfalist, *rfa;    char *fn;    START;    for(; *av; av++) {	/*--- get file Info ---*/	fn = *av;	if ((rc = getLocalRfaInfo(&fn, &rfa, &rfalist, 0)) != OK) 	    CONT(rc);	/*--- check if we are master ---*/	if (IS_SLAVE(rfa->ri_status)) {	    releaseRfaInfoList(dirname(fn), rfalist);	    fprintf(err,"*** local file %s is slave version ***\n", fn);	    CONT(NOTOK_IS_SLAVE);	}	if (!IS_LOCKED(rfa->ri_status)) {	    releaseRfaInfoList(dirname(fn), rfalist);	    fprintf(err,"*** local file %s not locked ***\n", fn);	    CONT(NOTOK_NOTLOCKED);	}	SET_LOCKINFO(rfa->ri_status, RI_UNLOCKED);	rfa->ri_lcksince = NULL;	free(rfa->ri_lckname);	rfa->ri_lckname = "NONE";	if ((rc = putRfaInfoList(dirname(fn), rfalist)) != OK) {	    releaseRfaInfoList(dirname(fn), rfalist);	    fprintf(err, "*** local file access error : %s ***\n", errMsg(rc));	    CONT(NOTOK_FILEACCESS);	}	releaseRfaInfoList(dirname(fn), rfalist);	if (interactive)	    fprintf(out,"unlocked file %s\n", fn);    }    RETURN;}/*--------------------------------------------------------------*//*  lockFile							*//*--------------------------------------------------------------*/do_lockFile(av)    char **av;{    struct type_RFA_RequestMasterRes *rmr;    struct type_RFA_RequestMasterArg *rma;    int res, rc;    struct RfaInfo *rfalist, *rfa;    char *fn, *shortTime();    int rmode = 0;    START;    for(; *av; av++) {	/*--- get file Info ---*/	fn = *av;	if ((rc = getLocalRfaInfo(&fn, &rfa, &rfalist, 0)) != OK) 	    CONT(rc);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?