-- Route66QueryP2233V1ServerImpl.Mesa
-- Russ Atkinson (RRA) June 15, 1992 12:29 pm PDT
	-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
	-- Generated by BJackson.pa at July 15, 1988 4:26:26 pm PDT
	--  using Sirocco [2.0] of January 31, 1987 1:52:42 am PST
	
DIRECTORY
	CrRPC,
	AuthenticationP14V2,
	BulkDataP0V1,
	Route66QueryP2233V1;

Route66QueryP2233V1ServerImpl: CEDAR PROGRAM
	IMPORTS CrRPC, Route66QueryP2233V1 ~ {
	OPEN Route66QueryP2233V1;

LogoffCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	session: Session;
	
	{
		session.token ← CrRPC.GetCard32[s];
		session.verifier ← UProc11[h, s];
		};
	
	[] ← Logoff[h, session];
	
	beginReturn[h];
	
	};
	
LogonCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	service: ROPE;
	credentials: AuthenticationP14V2.Credentials;
	verifier: AuthenticationP14V2.SeqWords;
	newSession: Session;
	
	{
		service ← CrRPC.GetRope[s];
		};
	{
		credentials.type ← VAL[CrRPC.GetCard16[s]];
		credentials.value ← UProc11[h, s];
		};
	{
		verifier ← UProc11[h, s];
		};
	
	[newSession] ← Logon[h, service, credentials, verifier];
	
	beginReturn[h];
	
	{
		CrRPC.PutCard32[s, newSession.token];
		MProc12[h, s, newSession.verifier];
		};
	};
	
RetrieveCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	oldSession: Session;
	file: FileLocation;
	content: CrRPC.BulkDataSink;
	newSession: Session;
	
	{
		oldSession.token ← CrRPC.GetCard32[s];
		oldSession.verifier ← UProc11[h, s];
		};
	{
		file.fileServer ← CrRPC.GetRope[s];
		file.fileName ← CrRPC.GetRope[s];
		file.fileFormat ← CrRPC.GetRope[s];
		file.startByte ← CrRPC.GetInt32[s];
		file.numBytes ← CrRPC.GetInt32[s];
		file.timeLimit ← CrRPC.GetCard32[s];
		};
	TRUSTED {
		content ← CrRPC.GetBulkDataSink[h, s];
		};
	
	[newSession] ← Retrieve[h, oldSession, file, content];
	
	beginReturn[h];
	
	{
		CrRPC.PutCard32[s, newSession.token];
		MProc12[h, s, newSession.verifier];
		};
	};
	
ReleaseOpHandleCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	service: ROPE;
	oldOp: OpHandle;
	
	{
		service ← CrRPC.GetRope[s];
		};
	{
		oldOp.operation ← CrRPC.GetCard32[s];
		oldOp.sequence ← CrRPC.GetCard32[s];
		};
	
	[] ← ReleaseOpHandle[h, service, oldOp];
	
	beginReturn[h];
	
	};
	
LocateMoreCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	service: ROPE;
	oldOp: OpHandle;
	bufferSize: INT32;
	resultType: ResultType;
	progress: ProgressReport;
	matches: INT32;
	newOp: OpHandle;
	idLocs: IdLocList;
	
	{
		service ← CrRPC.GetRope[s];
		};
	{
		oldOp.operation ← CrRPC.GetCard32[s];
		oldOp.sequence ← CrRPC.GetCard32[s];
		};
	{
		bufferSize ← CrRPC.GetInt32[s];
		};
	{
		resultType ← VAL[CrRPC.GetCard16[s]];
		};
	
	[progress, matches, newOp, idLocs] ← LocateMore[h, service, oldOp, bufferSize, resultType];
	
	beginReturn[h];
	
	{
		CrRPC.PutInt32[s, progress.workDone];
		CrRPC.PutInt32[s, progress.workPending];
		CrRPC.PutInt32[s, progress.timePending];
		CrRPC.PutInt32[s, progress.timeWait];
		};
	{
		CrRPC.PutInt32[s, matches];
		};
	{
		CrRPC.PutCard32[s, newOp.operation];
		CrRPC.PutCard32[s, newOp.sequence];
		};
	{
		MProc13[h, s, idLocs];
		};
	};
	
LocateCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	service: ROPE;
	userName: ROPE;
	locateSpec: StringList;
	docId: ROPE;
	fileLocFilter: FileLocFilter;
	bufferSize: INT32;
	resultType: ResultType;
	progress: ProgressReport;
	matches: INT32;
	newOp: OpHandle;
	idLocs: IdLocList;
	
	{
		service ← CrRPC.GetRope[s];
		};
	{
		userName ← CrRPC.GetRope[s];
		};
	{
		locateSpec ← UProc14[h, s];
		};
	{
		docId ← CrRPC.GetRope[s];
		};
	{
		fileLocFilter.servers ← UProc14[h, s];
		fileLocFilter.formats ← UProc14[h, s];
		fileLocFilter.timeLimit ← CrRPC.GetCard32[s];
		};
	{
		bufferSize ← CrRPC.GetInt32[s];
		};
	{
		resultType ← VAL[CrRPC.GetCard16[s]];
		};
	
	[progress, matches, newOp, idLocs] ← Locate[h, service, userName, locateSpec, docId, fileLocFilter, bufferSize, resultType];
	
	beginReturn[h];
	
	{
		CrRPC.PutInt32[s, progress.workDone];
		CrRPC.PutInt32[s, progress.workPending];
		CrRPC.PutInt32[s, progress.timePending];
		CrRPC.PutInt32[s, progress.timeWait];
		};
	{
		CrRPC.PutInt32[s, matches];
		};
	{
		CrRPC.PutCard32[s, newOp.operation];
		CrRPC.PutCard32[s, newOp.sequence];
		};
	{
		MProc13[h, s, idLocs];
		};
	};
	
NullCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	service: ROPE;
	
	{
		service ← CrRPC.GetRope[s];
		};
	
	[] ← Null[h, service];
	
	beginReturn[h];
	
	};
	
StoreCaller: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, beginReturn: CrRPC.BeginReturnProc] ~ {
	oldSession: Session;
	file: FileLocation;
	content: CrRPC.BulkDataSource;
	newSession: Session;
	
	{
		oldSession.token ← CrRPC.GetCard32[s];
		oldSession.verifier ← UProc11[h, s];
		};
	{
		file.fileServer ← CrRPC.GetRope[s];
		file.fileName ← CrRPC.GetRope[s];
		file.fileFormat ← CrRPC.GetRope[s];
		file.startByte ← CrRPC.GetInt32[s];
		file.numBytes ← CrRPC.GetInt32[s];
		file.timeLimit ← CrRPC.GetCard32[s];
		};
	TRUSTED {
		content ← CrRPC.GetBulkDataSource[h, s];
		};
	
	[newSession] ← Store[h, oldSession, file, content];
	
	beginReturn[h];
	
	{
		CrRPC.PutCard32[s, newSession.token];
		MProc12[h, s, newSession.verifier];
		};
	};
	
Server: CrRPC.ServerProc ~ {
	-- [h: Handle, s: STREAM, pgm: CARD32, pgmVersion: CARD16, proc: CARD16, beginReturn: BeginReturnProc, beginError: BeginErrorProc, beginReject: BeginRejectProc]
	
	ENABLE {
		Route66QueryP2233V1.Error => { -- (1 )
			beginError[h, 1 ];
			CrRPC.PutRope[s, message];
			GOTO Finished;
			};
		};
	
	IF (pgmVersion # 1) THEN {
		beginReject[h, CrRPC.noSuchVersion];
		CrRPC.PutCard16[s, 1]; --low
		CrRPC.PutCard16[s, 1]; --high
		RETURN
		};
	
	SELECT proc FROM
		11  => LogoffCaller[h, s, beginReturn];
		10  => LogonCaller[h, s, beginReturn];
		12  => RetrieveCaller[h, s, beginReturn];
		3  => ReleaseOpHandleCaller[h, s, beginReturn];
		2  => LocateMoreCaller[h, s, beginReturn];
		1  => LocateCaller[h, s, beginReturn];
		0  => NullCaller[h, s, beginReturn];
		13  => StoreCaller[h, s, beginReturn];
		ENDCASE => {
			beginReject[h, CrRPC.noSuchProcedure];
			};
	
	EXITS
		Finished => { NULL };
	};

	-- Unmarshal / Marshal Procs --
		
		
		MProc13: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, val: IdLocList] ~ {
			CrRPC.PutCard16[s, val.length];
			FOR i15: CARDINAL IN [0..val.length) DO
				CrRPC.PutRope[s, val.body[i15].docId];
				CrRPC.PutRope[s, val.body[i15].fileLocation.fileServer];
				CrRPC.PutRope[s, val.body[i15].fileLocation.fileName];
				CrRPC.PutRope[s, val.body[i15].fileLocation.fileFormat];
				CrRPC.PutInt32[s, val.body[i15].fileLocation.startByte];
				CrRPC.PutInt32[s, val.body[i15].fileLocation.numBytes];
				CrRPC.PutCard32[s, val.body[i15].fileLocation.timeLimit];
				ENDLOOP;
			};
		
		MProc12: PROC [h: CrRPC.Handle, s: CrRPC.STREAM, val: AuthenticationP14V2.SeqWords] ~ {
			CrRPC.PutCard16[s, val.length];
			FOR i16: CARDINAL IN [0..val.length) DO
				CrRPC.PutCard16[s, val.body[i16]];
				ENDLOOP;
			};
		
		UProc14: PROC [h: CrRPC.Handle, s: CrRPC.STREAM] RETURNS [res: StringList] ~ {
			{
				length18: CARDINAL ~ CrRPC.GetCard16[s];
				res ←  NEW[StringListObject[length18]];
				FOR i17: CARDINAL IN [0..length18) DO
					res.body[i17] ← CrRPC.GetRope[s];
					ENDLOOP;
				};
			};
		
		UProc11: PROC [h: CrRPC.Handle, s: CrRPC.STREAM] RETURNS [res: AuthenticationP14V2.SeqWords] ~ {
			{
				length20: CARDINAL ~ CrRPC.GetCard16[s];
				res ←  NEW[AuthenticationP14V2.SeqWordsObject[length20]];
				FOR i19: CARDINAL IN [0..length20) DO
					res.body[i19] ← CrRPC.GetCard16[s];
					ENDLOOP;
				};
			};
		

	CrRPC.RegisterServerProcs[pgm~2233, pgmLoVersion: 1, pgmHiVersion: 1, serverProc~Server];
	CrRPC.EnsureListener[class~$SPP];
}...