home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xafp1.exe
/
XAFP1.C
next >
Wrap
Text File
|
1994-08-30
|
9KB
|
338 lines
/****************************************************************************
** File: XAFP1.C
**
** Desc: Example of AFP file access.
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
**
** QMK386 options used:
**
** /ip - Appletalk
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 08-24-94 ABJ First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdlib.h> /* exit() */
#include <stdio.h> /* printf() */
#include <string.h> /* strlen(), strchr() strrchr() */
#include <io.h> /* close(), read() */
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwafp.h> /* AFPOpenFileFork() */
#include <nwconn.h> /* GetFileServerID() */
#include <nwenvrn.h> /* GetFileServerName() */
#include <nwdir.h> /* GetVolumeNumber(); */
#include <errno.h> /* ESUCCESS */
#include <niterror.h>/* UNKNOWN_FILE_SERVER */
/*------------------------------------------------------------------------
** xafp2
*/
#define AFP_MODE_READ 0x01
#define AFP_MODE_WRITE 0x02
#define AFP_MODE_DENYREAD 0x04
#define AFP_MODE_DENYWRITE 0x08
#define AFP_SEARCH_HIDDEN 0x02
#define AFP_SEARCH_SYSTEM 0x04
#define AFP_SEARCH_DIR 0x08
#define AFP_SEARCH_FILES 0x10
#define AFP_REQUEST_ALL 0x3FFF
#define AFP_ENTRYID_VOLROOT 0x00000001L
#define AFP_DATA_FORK 0x00
#define AFP_RESOURCE_FORK 0x01
/****************************************************************************
** Global storage
*/
/****************************************************************************
** Convert a DOS style path to a Apple style path.
**
** Shifts string right one byte, NOT including NULL terminator.
** (terminator not needed in an apple string.)
** Inserts length of string in first byte.
** Converts slashes to '\0's.
**
** Return values:
**
** 0 Success.
** 1 String too long.
*/
int StrDOStoAFP(char *outStr, char *inStr)
{
char *oldStr = NULL;
int cCode;
int sLen;
char *cp;
/*------------------------------------------------------------------------
** Determine length of string and verify length bounds.
*/
sLen=strlen(inStr);
if(sLen > 254)
{
cCode = 1;
goto END;
}
/*------------------------------------------------------------------------
** Set string length and move string back to origional buffer (+1).
*/
*outStr = (char)sLen;
++outStr;
strncpy(outStr, inStr, sLen);
/*------------------------------------------------------------------------
** Convert forward slashes to backslashes,
** then back slashes to 0x00 from the right side first.
*/
while((cp=strchr(outStr, '/')) != NULL) *cp = '\\';
while((cp=strrchr(outStr, '\\')) != NULL) *cp = '\0';
cCode=0;
END:
/*------------------------------------------------------------------------
** Return temp buffer to OS.
*/
if(oldStr != NULL) free(oldStr);
return(cCode);
}
/****************************************************************************
** Copy the data portion of a file to the screen.
*/
int AFP_TypeFile(WORD fileServerID, int volumeNumber, char *afpPathString)
{
int cCode;
int fileHandle;
LONG bytesRead;
char buffer[256];
/*------------------------------------------------------------------------
** Open the file.
*/
cCode=AFPOpenFileFork(
/* I- fileServerID */ fileServerID,
/* I- volumeNum */ volumeNumber,
/* I- AFPEntryID */ AFP_ENTRYID_VOLROOT,
/* I- forkIndicator */ AFP_DATA_FORK,
/* I- accessMode */ AFP_MODE_READ,
/* I- AFPPathString */ afpPathString,
/* -O fileID */ NULL,
/* -O forkLength */ NULL,
/* -O NetWareHandle */ NULL,
/* -O fileHandle */ &fileHandle
);
switch(cCode)
{
case ESUCCESS:
break;
case ERR_INVALID_PATH:
default:
goto END;
}
/*------------------------------------------------------------------------
** Copy file to screen.
*/
do {
bytesRead=read(
/* I- handle */ fileHandle,
/* -O buffer */ buffer,
/* I- len */ sizeof(buffer)
);
printf("%*.*s", bytesRead, bytesRead, buffer);
} while(bytesRead == sizeof(buffer));
if(bytesRead == (-1))
{
cCode=errno;
goto END;
}
/*------------------------------------------------------------------------
** Close the file.
*/
cCode=close(fileHandle);
if(cCode) cCode=errno;
END:
return(cCode);
}
/****************************************************************************
** Print program's usage (help screen).
*/
void Usage(void)
{
printf("\n");
printf("USAGE: LOAD xafp1 \"{volumeName}:{path}\\{filename}\"\n");
printf("\n");
printf(" volumeName Name of a volume where file is located.\n");
printf("\n");
printf(" path Directory path where file is located.\n");
printf("\n");
printf(" fileName Name of file type to display.\n");
printf("\n");
printf("NOTE: Be aware that the MAC name space allows spaces in the path\n");
printf(" and filename. Therefore, the entire (arg[1]) must be in quotes\n");
printf(" so that if it contains spaces, NetWare will not parse it into\n");
printf(" multiple args.\n");
printf("\n");
return;
}
/****************************************************************************
** Program start.
*/
void main(int argC, char *argV[])
{
int cCode;
WORD fileServerID = 0; /* Assume local file server. */
char *nwVol;
int volumeNumber;
char *nwPath;
char afpPath[255+1];
/*------------------------------------------------------------------------
** Determine if AFP calls are supported on fileserver.
*/
cCode=AFPSupported(fileServerID);
if(cCode == FALSE)
{
printf("ERROR: AFP system calls are not supported on this file server.\n");
goto END;
}
/*------------------------------------------------------------------------
** Parse and validate command line args.
*/
if(argC != 2) /* make sure we have an arg. */
{
Usage();
goto END;
}
nwVol=argV[1];
if((nwPath=strchr(nwVol, ':')) == NULL) /* make sure we have a volume name. */
{
Usage();
goto END;
}
*nwPath='\0';
++nwPath;
if(strlen(nwVol) > 15) /* make sure volume name is 15 chars or less */
{
Usage();
goto END;
}
/*------------------------------------------------------------------------
** Get the specified volume number.
*/
cCode=GetVolumeNumber(
/* I- volumeName */ nwVol,
/* -O volumeNumber */ &volumeNumber
);
switch(cCode)
{
case ESUCCESS:
break;
case ERR_VOLUME_DOES_NOT_EXIST:
printf("ERROR: Volume %s: does not exist.\n", nwVol);
goto END;
default:
printf("ERROR: Unknown error returned by GetVolumeNumber(): %d\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Convert DOS style path to AFP path.
*/
cCode=StrDOStoAFP(afpPath, nwPath);
switch(cCode)
{
case 0:
break;
case 1:
printf("ERROR: StrDOStoAFP() reports that path [%s] is too long.\n", nwPath);
goto END;
default:
printf("ERROR: Unknown error returned by STRDOStoAFP(): %d\n", cCode);
goto END;
}
cCode=AFP_TypeFile(fileServerID, volumeNumber, afpPath);
switch(cCode)
{
case ESUCCESS:
break;
case ERR_INVALID_PATH:
printf("ERROR: AFP_TypeFile() reports: Invalid path.\n");
goto END;
case EBADF:
printf("ERROR: Bad file handle reported by AFP_TypeFile[close()].\n");
break;
default:
printf("ERROR: AFP_TypeFile() returned unknown error: %d.\n", cCode);
goto END;
}
END:
exit(0);
}