Patch #: 118 Type: operational change Priority: none Modification: make lwsrv handle multiple printers Submitted: William Roberts, ex. Queen Mary College Archived: munnari.OZ.AU mac/cap.patches/cap60.patch118 Application: 'cd cap60; patch -p < cap60.patches/cap60.patch118' Summary: use multiple pairs of -n and -p flags File: cap60/applications/lwsrv/lwsrv.c *** applications/lwsrv/lwsrv.c.orig Wed Jul 15 19:39:14 1992 --- applications/lwsrv/lwsrv.c Thu Jul 16 16:56:21 1992 *************** *** 1,6 **** ! static char rcsid[] = "$Author: djh $ $Date: 1992/07/15 09:38:40 $"; ! static char rcsident[] = "$Header: /mac/src/cap60/applications/lwsrv/RCS/lwsrv.c,v 2.22 1992/07/15 09:38:40 djh Rel djh $"; ! static char revision[] = "$Revision: 2.22 $"; /* * lwsrv - UNIX AppleTalk spooling program: act as a laserwriter --- 1,6 ---- ! static char rcsid[] = "$Author: djh $ $Date: 1992/07/16 06:56:11 $"; ! static char rcsident[] = "$Header: /mac/src/cap60/applications/lwsrv/RCS/lwsrv.c,v 2.23 1992/07/16 06:56:11 djh Rel djh $"; ! static char revision[] = "$Revision: 2.23 $"; /* * lwsrv - UNIX AppleTalk spooling program: act as a laserwriter *************** *** 45,54 **** --- 45,56 ---- #include #endif xenix5 #include + #include #include /* include appletalk definitions */ #include #include + #include "../../lib/cap/abpap.h" /* urk, puke, etc */ #ifdef USESTRINGDOTH # include *************** *** 66,75 **** #if defined (LWSRV_AUFS_SECURITY) | defined (RUN_AS_USER) #include #endif LWSRV_AUFS_SECURITY | RUN_AS_USER - #ifdef AUTHENTICATE - #include - #include "../../lib/cap/abpap.h" /* urk, puke, etc */ - #endif AUTHENTICATE #ifdef RUN_AS_USER #ifndef USER_FILE #define USER_FILE "/usr/local/lib/cap/macusers" --- 68,73 ---- *************** *** 91,103 **** private int rflag = FALSE; /* remove print file */ private int hflag = TRUE; /* default to print banner */ private int singlefork = FALSE; export int capture = TRUE; ! export PAPStatusRec statbuff; /* status buffer */ #ifdef PAGECOUNT export int pagecount; export int pcopies; #endif PAGECOUNT - export int verbose = 0; private char username[128],jobname[1024]; private char buf[1024]; --- 89,101 ---- private int rflag = FALSE; /* remove print file */ private int hflag = TRUE; /* default to print banner */ private int singlefork = FALSE; + private PAPStatusRec *statbuffp; /* status buffer */ export int capture = TRUE; ! export int verbose = 0; #ifdef PAGECOUNT export int pagecount; export int pcopies; #endif PAGECOUNT private char username[128],jobname[1024]; private char buf[1024]; *************** *** 107,125 **** # define TEMPFILE "/tmp/lwsrvXXXXXX" /* temporary file holds job */ #endif TEMPFILE #ifdef LWSRV_AUFS_SECURITY private int requid, reqgid; private char *aufsdb = NULL; /* budd */ #endif LWSRV_AUFS_SECURITY #ifdef LWSRV_LPR_LOG private char *requname = NULL; #endif LWSRV_LPR_LOG - #define RFLOWQ atpMaxNum - #define BUFMAX (PAPSegSize*RFLOWQ)+10 - #ifdef LWSRV_AUFS_SECURITY - int tempbinlen; - char *bin, *tempbin; - #endif LWSRV_AUFS_SECURITY #ifdef NeXT char *nextdpi = NULL; /* NeXT printer resolution */ #endif NeXT --- 105,122 ---- # define TEMPFILE "/tmp/lwsrvXXXXXX" /* temporary file holds job */ #endif TEMPFILE + #define RFLOWQ atpMaxNum + #define BUFMAX (PAPSegSize*RFLOWQ)+10 + #ifdef LWSRV_AUFS_SECURITY private int requid, reqgid; private char *aufsdb = NULL; /* budd */ + char *bin, *tempbin; + int tempbinlen; #endif LWSRV_AUFS_SECURITY #ifdef LWSRV_LPR_LOG private char *requname = NULL; #endif LWSRV_LPR_LOG #ifdef NeXT char *nextdpi = NULL; /* NeXT printer resolution */ #endif NeXT *************** *** 145,150 **** --- 142,159 ---- private char **lprargs = lprargsbuf; #endif LPRARGS + private struct printer_instance { + char *prtname; /* NBP registered printername */ + char *unixpname; /* UNIX printer name */ + char *tracefile; /* .. individual tracefile option */ + PAPStatusRec statbuf; + int srefnum; /* returned by SLInit */ + char nbpbuf[128]; /* registered name:type@zone */ + int rcomp; /* flag: waiting for job? */ + int cno; /* connection number of next job */ + } prtlist[NUMSPAP], *prtp; + private int nprt = 0; + private void usage(s,err) char *s,*err; *************** *** 203,208 **** --- 212,234 ---- } private void + inc_nprt(progname) + char *progname; + { + + if (prtp->unixpname == NULL) + usage(progname,"Missing Unix Printer Name"); + if (prtp->prtname == NULL) + usage(progname,"Missing AppleTalk Printer Name"); + + if (++nprt >= NUMSPAP) + usage("lwsrv","too many printers"); + + prtp++; + unixpname = tracefile = prtname = NULL; + } + + private void doargs(argc,argv) int argc; char **argv; *************** *** 225,230 **** --- 251,259 ---- #ifdef NeXT strcat(optlist, "R:"); #endif NeXT + + nprt = 0; prtp = prtlist; + while ((c = getopt(argc,argv,optlist)) != EOF) { switch (c) { case 'a': *************** *** 245,254 **** logfile = optarg; break; case 'n': /* lwsrv printer name */ ! prtname = optarg; break; case 'p': /* -p unix printer name */ ! unixpname = optarg; break; case 'k': /* no DDP checksum */ dochecksum = 0; --- 274,287 ---- logfile = optarg; break; case 'n': /* lwsrv printer name */ ! if (prtname != NULL) ! inc_nprt(argv[0]); ! prtp->prtname = prtname = optarg; break; case 'p': /* -p unix printer name */ ! if (unixpname != NULL) ! inc_nprt(argv[0]); ! prtp->unixpname = unixpname = optarg; break; case 'k': /* no DDP checksum */ dochecksum = 0; *************** *** 260,266 **** rflag = TRUE; break; case 't': /* -t tracefile */ ! tracefile = optarg; break; case 'e': setflag_encrypted_instream(TRUE); /* maybe "eexec" in code */ --- 293,299 ---- rflag = TRUE; break; case 't': /* -t tracefile */ ! prtp->tracefile = tracefile = optarg; break; case 'e': setflag_encrypted_instream(TRUE); /* maybe "eexec" in code */ *************** *** 318,327 **** usage(argv[0], NULL); } ! if (unixpname == NULL) ! usage(argv[0],"No Unix Printer Name"); ! if (prtname == NULL) ! usage(argv[0],"No AppleTalk Printer Name"); if (fontfile == NULL) usage(argv[0],"No FontFile specified"); #ifdef LPRARGS --- 351,358 ---- usage(argv[0], NULL); } ! inc_nprt(argv[0]); ! if (fontfile == NULL) usage(argv[0],"No FontFile specified"); #ifdef LPRARGS *************** *** 328,335 **** --- 359,378 ---- *lprargs = NULL; lprargs = lprargsbuf; #endif LPRARGS + } + void + set_printer(p) + struct printer_instance *p; + { + prtname = p->prtname; + unixpname = p->unixpname; + tracefile = p->tracefile; + statbuffp = &(p->statbuf); + srefnum = p->srefnum; + } + private void childdone() { *************** *** 348,359 **** * delete the NBP name */ private int cleanup() { SLClose(srefnum); /* close server for child */ ! PAPRemName(srefnum, buf); ! exit(0); } openlogfile() --- 391,412 ---- * delete the NBP name */ + private int is_child = 0; + private int cleanup() { + int i; + + if (is_child) + exit(0); + + for (i=0; inbpbuf,"%s:%s@*",prtp->prtname,prttype); + cpyc2pstr(prtp->statbuf.StatusStr,"status: idle"); + err = SLInit(&(prtp->srefnum), prtp->nbpbuf, 8, &(prtp->statbuf)); + if (err != noErr) { + fprintf(stderr,"lwsrv: SLInit %s failed: %d\n", prtp->nbpbuf, err); + errcount++; + } + /* GetNextJob is asynchronous, so call it for each printer */ + err = GetNextJob(prtp->srefnum, &(prtp->cno), &(prtp->rcomp)); + if (err != noErr) { + fprintf(stderr,"lwsrv: GetNextJob %s failed: %d\n",prtp->prtname,err); + errcount++; + } + fprintf(stderr, "lwsrv: %s ready and waiting\n", prtp->nbpbuf); + } + + if (errcount == nprt) { + fprintf(stderr, "lwsrv: no printers successful registered!\n"); + exit(1); + } + + prtno = 0; prtcount = 0; while (TRUE) { #ifdef LWSRV_AUFS_SECURITY AddrBlock addr; /* budd */ *************** *** 482,494 **** #endif LWSRV_AUFS_SECURITY openlogfile(); NewStatus("idle"); ! err = GetNextJob(srefnum, &cno, &rcomp); if (err != noErr) { ! fprintf(stderr,"lwsrv: GetNextJob failed: %d\n",err); ! exit(1); } ! while (rcomp > 0) ! abSleep(20,TRUE); fprintf(stderr,"lwsrv: Starting print job for %s\n",prtname); #ifdef LWSRV_AUFS_SECURITY /*** budd.... */ --- 553,582 ---- #endif LWSRV_AUFS_SECURITY openlogfile(); NewStatus("idle"); ! ! /* scan each printer in turn, processing each one as "normal" if there ! * is work available. If no work was available then abSleep for a while ! */ ! while (prtno 0) prtno++; ! if (prtno == nprt) { ! if (prtcount == 0) { ! abSleep(20,TRUE); /* wait for some work */ ! } ! prtno = 0; /* start scan again */ ! continue; ! } ! ! prtp = &prtlist[prtno]; ! set_printer(prtp); /* set the global variables etc */ ! cno = prtp->cno; ! ! /* GetNextJob is asynchronous, so announce readiness for more work */ ! /* WTR: is this right - should it depend on singlefork? */ ! err = GetNextJob(prtp->srefnum, &(prtp->cno), &(prtp->rcomp)); if (err != noErr) { ! fprintf(stderr,"lwsrv: GetNextJob %s failed: %d\n",prtp->prtname,err); } ! fprintf(stderr,"lwsrv: Starting print job for %s\n",prtname); #ifdef LWSRV_AUFS_SECURITY /*** budd.... */ *************** *** 1053,1059 **** jobname,username,status); else sprintf(tmp,"status: %s",status); ! cpyc2pstr(statbuff.StatusStr, tmp); abSleep(0,TRUE); /* make sure protocol runs */ } --- 1141,1147 ---- jobname,username,status); else sprintf(tmp,"status: %s",status); ! cpyc2pstr(statbuffp->StatusStr, tmp); abSleep(0,TRUE); /* make sure protocol runs */ } *** lib/cap/abpap.h.orig Thu Feb 28 23:42:57 1991 --- lib/cap/abpap.h Thu Jul 16 16:52:29 1992 *************** *** 1,7 **** /* ! * $Author: djh $ $Date: 91/02/15 22:48:46 $ ! * $Header: abpap.h,v 2.1 91/02/15 22:48:46 djh Rel $ ! * $Revision: 2.1 $ */ /* --- 1,7 ---- /* ! * $Author: djh $ $Date: 1992/07/16 06:52:20 $ ! * $Header: /mac/src/cap60/lib/cap/RCS/abpap.h,v 2.2 1992/07/16 06:52:20 djh Rel djh $ ! * $Revision: 2.2 $ */ /* *************** *** 142,150 **** u_short transID; /* atp transid of papopen */ } PAPSOCKET; ! #define NUMPAP 2 /* 2 connections allowed at once */ ! ! #define NUMSPAP 1 /* Number of servers allowed */ #define PAP_UNUSED -1 #define PAP_BLOCKED 0 --- 142,150 ---- u_short transID; /* atp transid of papopen */ } PAPSOCKET; ! /* It does not make sense for NUMSPAP to be less than NUMPAP */ ! #define NUMPAP 12 /* 12 connections allowed at once */ ! #define NUMSPAP 10 /* Number of servers allowed */ #define PAP_UNUSED -1 #define PAP_BLOCKED 0 *** lib/cap/abpaps.c.orig Thu Feb 28 23:42:58 1991 --- lib/cap/abpaps.c Thu Jul 16 16:54:14 1992 *************** *** 1,7 **** /* ! * $Author: djh $ $Date: 91/02/15 22:48:57 $ ! * $Header: abpaps.c,v 2.1 91/02/15 22:48:57 djh Rel $ ! * $Revision: 2.1 $ */ /* --- 1,7 ---- /* ! * $Author: djh $ $Date: 1992/07/16 06:54:04 $ ! * $Header: /mac/src/cap60/lib/cap/RCS/abpaps.c,v 2.2 1992/07/16 06:54:04 djh Rel djh $ ! * $Revision: 2.2 $ */ /* *************** *** 84,91 **** * and to register the server's name on this service listening socket. * The client can also provide an inital status string. * ! * Multiple SLInit call implies that the server actually handle multiple ! * printer - not supported at present * * call parameters: entity name, flow quantum, status string * returned: result code, server refnum --- 84,91 ---- * and to register the server's name on this service listening socket. * The client can also provide an inital status string. * ! * Multiple SLInit call implies that the server can handle multiple ! * printers - the maximum number is compiled in as NUMSPAP * * call parameters: entity name, flow quantum, status string * returned: result code, server refnum *************** *** 109,115 **** if (cno==NUMSPAP) return(-1); /* not enough server processes */ ! *refnum = cno; /* assume zero'th socket for now */ papslist[cno].active = TRUE; papslist[cno].state = PAP_BLOCKED; papslist[cno].flowq = flowquantum; --- 109,115 ---- if (cno==NUMSPAP) return(-1); /* not enough server processes */ ! *refnum = cno; papslist[cno].active = TRUE; papslist[cno].state = PAP_BLOCKED; papslist[cno].flowq = flowquantum; *************** *** 157,162 **** --- 157,164 ---- cno = ppgetskt(&useaddr); *refnum = cno; ps = cnotopapskt(cno); + if (cno < 0 || ps == NULL) + return(-1); ps->flowq = pss->flowq; ps->state = PAP_GNJOPENING; ps->comp = compstate; *** lib/cap/abversion.c.orig Thu Jul 16 00:07:29 1992 --- lib/cap/abversion.c Thu Jul 16 16:57:09 1992 *************** *** 1,7 **** /* ! * $Author: djh $ $Date: 1992/07/15 14:07:23 $ ! * $Header: /mac/src/cap60/lib/cap/RCS/abversion.c,v 2.17 1992/07/15 14:07:23 djh Rel djh $ ! * $Revision: 2.17 $ */ /* --- 1,7 ---- /* ! * $Author: djh $ $Date: 1992/07/16 06:57:02 $ ! * $Header: /mac/src/cap60/lib/cap/RCS/abversion.c,v 2.18 1992/07/16 06:57:02 djh Rel djh $ ! * $Revision: 2.18 $ */ /* *************** *** 31,37 **** myversion.cv_name = "CAP"; myversion.cv_version = 6; myversion.cv_subversion = 0; ! myversion.cv_patchlevel = 117; myversion.cv_rmonth = "July"; myversion.cv_ryear = "1992"; switch (lap_proto) { --- 31,37 ---- myversion.cv_name = "CAP"; myversion.cv_version = 6; myversion.cv_subversion = 0; ! myversion.cv_patchlevel = 118; myversion.cv_rmonth = "July"; myversion.cv_ryear = "1992"; switch (lap_proto) { *** README.orig Thu Jul 16 00:08:24 1992 --- README Thu Jul 16 16:57:56 1992 *************** *** 2,8 **** CAP - Columbia AppleTalk Package for UNIX o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 117, July 1992 Notice ------ --- 2,8 ---- CAP - Columbia AppleTalk Package for UNIX o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 118, July 1992 Notice ------