📄 courier.tbl.me
字号:
.nf/* * Sample proram to print a file remotely using trivial remote print * protocol. * Usage: remoteprint filename * */#include <stdio.h>#include <sys/types.h>#include <netns/ns.h> /* for XNS addresses */#include "PrintFile_defs.h"static FILE * source; /* communicate from main to SendSource */main(argc, argv) int argc; char *argv[];{ CourierConnection *connection; struct ns_addr *destaddr; if (argc < 3 || (destaddr = getXNSaddr(argv[1])) == NULL)) { fprintf(stderr,"Usage: %s machine file ...\en",argv[0]); exit(1); } if ((connection = CourierOpen(destaddr)) == NULL) { fprintf(stderr,"Can't open connection to %s\en",argv[1]); exit(1); } argv++; while (argc-- > 2) { argv++; if (strcmp(argv[0],"-") == 0) source = stdin; else source = fopen(argv[0],"r"); if (source == NULL) fprintf(stderr,"Can't open %s\en",argv[0]); else DURING RPrint(connection,SendSource,immediateSource); HANDLER fprintf(stderr,"Call to RPrint failed.\en"); END_HANDLER; fclose(source); } CourierClose(connection);}SendSource(bdtconnection)CourierConnection *bdtconnection;{ int count; char buffer[SPPMAXDATA]; while ( (count = fread(buffer,1,SPPMAXDATA,source)) > 0 && BDTwrite(bdtconnection,buffer,count) >= 0 ) ; if (count <= 0) BDTclosewrite(bdtconnection); /* last packet with EOM set */ else BDTabort(bdtconnection);}.fi.sp 2.sh 2 "Server (PrintFile.c)".sp 1.nf#include <stdio.h>#include <sys/types.h>#include <netxns/ns.h>#include "PrintFile_defs.h"RPrintResultRprint(source,CourierBDTProc,s) CourierConnection *source, CourierBDTProc; BulkData1_Source s;{ FILE *printpipe; char sppdata[SPPMAXDATA]; switch (s.designator) case active: case passive: raise(CantPrint); /*NOTREACHED*/ case null: system("print /dev/null"); /* print a null file */ return; case immediate: if ((printpipe = popen("print","w")) == NULL) { raise(CantPrint); /*NOTREACHED*/ } count = BDTread(source, sppdata, SPPMAXDATA); while (count > 0) { /* actually read data */ if (fwrite(sppdata, 1, count, printpipe) == 0) { BDTabort(source); break; } count = BDTread(source, sppdata, SPPMAXDATA); } if (pclose(printpipe) == 0 && count == 0) return; else raise(CantPrint);}.fi.sh 1 "One Final Example".ppFinally, we present a slightly more useful example, a program to print an Interpressfile on a Services-8 printer. It depends on the standard Xerox Printingspecification, program 4 version 3. For an even better example, lookat the printing client, xnsprint, provided with the XNS Courier distributionas.i "./examples/print/xnsprint.c" ..sp 2.nf#include <stdio.h>#include <sys/types.h>#include <netns/ns.h>#include "Printing_defs.h"#include <except.h>static FILE *ipfile = NULL;SendSource(bdtconnection)CourierConnection *bdtconnection;{ int count; char buffer[SPPMAXDATA]; while ( (count = fread(buffer,1,SPPMAXDATA,ipfile)) > 0 && BDTwrite(bdtconnection,buffer,count) >= 0 ) ; if (count <= 0) BDTclosewrite(bdtconnection); /* last packet with EOM set */ else BDTabort(bdtconnection);}main(argc, argv) int argc; char *argv[];{ PrintResults result; struct ns_addr *destaddr; CourierConnection *conn; extern struct ns_addr *getXNSaddr(); PrintAttributes attributes; PrintOptions options; /* use Cornell print server, CornellS1 (slander) */ destaddr = getXNSaddr("2-273#2-852-159-207"); attributes.length = 0; options.length = 0; if (argc != 2 || ((ipfile = fopen(argv[1],"r")) == NULL)) { fprintf(stderr,"Usage: %s file\en",argv[0]); exit(1); } if ((conn = CourierOpen(destaddr)) == NULL) { fprintf(stderr,"Can't open connection to %s\en",xnshost); exit(1); } DURING result = Print(conn, SendSource, BulkData1_immediateSource, attributes, options); HANDLER { switch (Exception.Code) { case Busy: fprintf(stderr,"Busy\en"); break; case ConnectionError: fprintf(stderr,"Connection error, %d\en", CourierErrArgs(ConnectionErrorArgs,problem)); break; case InsufficientSpoolSpace: case SpoolingQueueFull: fprintf(stderr,"Insufficient spool space\en"); break; case SpoolingDisabled: fprintf(stderr,"Spooling disabled\en"); break; case MasterTooLarge: case TooManyClients: case ServiceUnavailable: case SystemError: case InvalidPrintParameters: case MediumUnavailable: case TransferError: fprintf(stderr,"Some Printing error, number %d\en", Exception.code-ERROR_OFFSET); break; case Undefined: fprintf(stderr,"Undefined error, number %d\en", CourierErrArgs(UndefinedArgs,problem)); break; case REJECT_ERROR: fprintf(stderr,"REJECT: type = %d\en", CourierErrArgs(rejectionDetails, designator)); break; default: fprintf(stderr,"Some random error, code %d\en", Exception.Code); break; } exit(1); } END_HANDLER; CourierClose(conn); printf("Done. Request ID %x %x %x %x %x\en", result.printRequestID[0], result.printRequestID[1], result.printRequestID[2], result.printRequestID[3], result.printRequestID[4]);}.fi.bp.sh 1 "Final Notes".ppThe issues of authentication and protection aredifficult.They are only touched upon in this implementation.Currently, each Courier program must perform any authentication(presumably using the Authentication protocol)if this is desired. A few routines exist to allow cleints and serversto perform simple Authentication; no support for strong Authenticationhas yet been written..ppThis implementation is fairly inefficient, especially inthe implementation of servers. Courier calls require substantialextra copying of courier arguments and results. More significantly,the requirement that each call spawn a unique process is very expensivein UNIX, and should be reconsidered.A sequence of RPCs on the same SPP stream that specifies the same programand version number uses the same process, but in all other cases a newprocess must be spawned for each individual RPC..ppThis implementation defines a number of reserved identifiers..b ">>>should list them here<<<".sh 1 "Appendix".ppThis appendix contains the grammar for the Courier language.It is similar to the YACC specification usedby the Courier compiler..sp.ps -2p.vs -2p.nf.TSl l l l l.%token identifier number string ARRAY BEGIN BOOLEAN CARDINAL CHOICE DEPENDS END ERROR FALSE INTEGER LONG OF PROCEDURE PROGRAM RECORD REPORTS RETURNS SEQUENCE STRING TRUE TYPE UNSPECIFIED UPON VERSION.TE%%Program : identifier ':' PROGRAM number VERSION number '=' BEGIN DependencyList DeclarationList END '.' | identifier ':' PROGRAM '=' BEGIN DependencyList DeclarationList END '.' ;DependencyList : /* empty */ | DEPENDS UPON ReferencedProgramList ';' ;ReferencedProgramList : ReferencedProgram | ReferencedProgramList ',' ReferencedProgram ;ReferencedProgram : identifier '(' number ')' VERSION number ;DeclarationList : /* empty */ | DeclarationList Declaration ;Declaration : identifier ':' TYPE '=' Type ';' | identifier ':' Type '=' Constant ';' ;Type : PredefinedType | ConstructedType | ReferencedType ;PredefinedType : BOOLEAN | CARDINAL | LONG CARDINAL | INTEGER | LONG INTEGER | STRING | UNSPECIFIED | LONG UNSPECIFIED ;ConstructedType : '{' CorrespondenceList '}' | ARRAY NumericValue OF Type | SEQUENCE MaximumNumber OF Type | RECORD '[' FieldList ']' | RECORD '[' ']' | CHOICE DesignatorType OF '{' CandidateList '}' | PROCEDURE ArgumentList ResultList ErrorList | ERROR ArgumentList ;ReferencedType : identifier | identifier '.' identifier ;CorrespondenceList : Correspondence | CorrespondenceList ',' Correspondence ;Correspondence : identifier '(' NumericValue ')' ;MaximumNumber : NumericValue | /* empty */ ;NumericValue : number | ReferencedConstant ;DesignatorType : /* empty */ | ReferencedType ;CandidateList : Candidate | CandidateList ',' Candidate ;Candidate : DesignatorList '=''>' Type ;DesignatorList : Designator | DesignatorList ',' Designator ;Designator : identifier | Correspondence ;ArgumentList : /* empty */ | '[' FieldList ']' ;ResultList : /* empty */ | RETURNS '[' FieldList ']' ;ErrorList : /* empty */ | REPORTS '[' NameList ']' ;FieldList : Field | FieldList ',' Field ;Field : NameList ':' Type ;Constant : PredefinedConstant | ConstructedConstant | ReferencedConstant ;PredefinedConstant : TRUE | FALSE | number | '-' number | '"' string '"' ;ConstructedConstant : identifier | '[' ElementList ']' | '[' ComponentList ']' | '['']' | identifier Constant | number ;ReferencedConstant : identifier | identifier '.' identifier ;ElementList : Constant | ElementList ',' Constant ;ComponentList : Component | ComponentList ',' Component ;Component : NameList ':' Constant ;NameList : identifier | NameList ',' identifier ;.fi.vs.ps
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -