Lines Matching +full:break +full:- +full:control
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * ------+---------+---------+---------+---------+---------+---------+---------*
5 * Copyright (c) 2001,2011 - Garance Alistair Drosehn <gad@FreeBSD.org>.
33 * ------+---------+---------+---------+---------+---------+---------+---------*
36 #include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */
38 * ctlinfo - This collection of routines will know everything there is to
39 * know about the information inside a control file ('cf*') which is used
41 * will be the ONLY source file to know what's inside these control-files.
47 * a per-spool-directory basis.
87 #define OTHER_USERID_CHARS "-_" /* special chars valid in a userid */
89 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
93 * in a control-file, including the leading 'command id', a trailing '\n'
133 * Control-files (cf*) have the following format.
135 * Each control-file describes a single job. It will list one or more
138 * informal and out-of-date description of lpr/lpd circa 1990.
144 * but may be multiple bytes (obviously it would be best if multi-byte ids
145 * started with some letter not already used as a single-byte id!).
155 * than once in a control file. Only the 'H' and 'P' lines are required
158 * ! A - [used by lprNG]
159 * B - As far as I know, this is never used as a single-byte id.
160 * Therefore, I intend to use it for multi-byte id codes.
161 * C - "class name" to display on banner page (this is sometimes
163 * ! D - [in lprNG, "timestamp" of when the job was submitted]
164 * ! E - "environment variables" to set [some versions of linux]
165 * H - "host name" of machine where the original 'lpr' was done
166 * I - "indent", the amount to indent output
167 * J - "job name" to display on banner page
168 * L - "literal" user's name as it should be displayed on the
171 * M - "mail", userid to mail to when done printing (with email
173 * P - "person", the user's login name (e.g. for accounting)
174 * ! Q - [used by lprNG for queue-name]
175 * R - "resolution" in dpi, for some laser printer queues
176 * T - "title" for files sent thru 'pr'
177 * W - "width" to use for printing plain-text files
178 * Z - In BSD, "locale" to use for datafiles sent thru 'pr'.
180 * [in lprNG - this line holds the "Z options"]
181 * 1 - "R font file" for files sent thru troff
182 * 2 - "I font file" for files sent thru troff
183 * 3 - "B font file" for files sent thru troff
184 * 4 - "S font file" for files sent thru troff
187 * appear multiple times in a control file (once per datafile):
189 * N - "name" of file (for display purposes, used by 'lpq')
190 * S - "stat() info" used for symbolic link ('lpr -s')
195 * control file. Note that ALL ids with lowercase letters are expected
198 * c - "file name", cifplot file to print. This action appears
199 * when the user has requested 'lpr -c'.
200 * d - "file name", dvi file to print, user requested 'lpr -d'
201 * f - "file name", a plain-text file to print = "standard"
202 * g - "file name", plot(1G) file to print, ie 'lpr -g'
203 * l - "file name", text file with control chars which should
204 * be printed literally, ie 'lpr -l' (note: some printers
208 * n - "file name", ditroff(1) file to print, ie 'lpr -n'
209 * o - "file name", a postscript file to print. This id is
211 * done with it. This 'lpr' does not generate control
212 * lines with 'o'-actions, but lpd's printjob processing
214 * p - "file name", text file to print with pr(1), ie 'lpr -p'
215 * t - "file name", troff(1) file to print, ie 'lpr -t'
216 * v - "file name", plain raster file to print
218 * U - "file name" of datafile to unlink (ie, remove file
237 cpriv = cjinf->cji_priv; in ctl_freeinf()
238 if ((cpriv == NULL) || (cpriv != cpriv->pub.cji_priv)) { in ctl_freeinf()
244 FREESTR(cpriv->pub.cji_accthost); in ctl_freeinf()
245 FREESTR(cpriv->pub.cji_acctuser); in ctl_freeinf()
246 FREESTR(cpriv->pub.cji_class); in ctl_freeinf()
247 FREESTR(cpriv->pub.cji_curqueue); in ctl_freeinf()
248 /* [cpriv->pub.cji_fname is part of cpriv-malloced area] */ in ctl_freeinf()
249 FREESTR(cpriv->pub.cji_jobname); in ctl_freeinf()
250 FREESTR(cpriv->pub.cji_mailto); in ctl_freeinf()
251 FREESTR(cpriv->pub.cji_headruser); in ctl_freeinf()
253 if (cpriv->cji_fstream != NULL) { in ctl_freeinf()
254 fclose(cpriv->cji_fstream); in ctl_freeinf()
255 cpriv->cji_fstream = NULL; in ctl_freeinf()
258 cjinf->cji_priv = NULL; in ctl_freeinf()
299 cpriv->pub.cji_priv = cpriv; in ctl_readcf()
301 cpriv->pub.cji_fname = (char *)cstart + sroom; in ctl_readcf()
302 strcpy(cpriv->pub.cji_fname, cfname); in ctl_readcf()
303 cpriv->cji_buff = (char *)cstart + sroom2; in ctl_readcf()
304 cpriv->cji_buffsize = (int)(msize - sroom2); in ctl_readcf()
305 cpriv->cji_eobuff = (char *)cstart + msize - 1; in ctl_readcf()
307 cpriv->cji_fstream = cfile; in ctl_readcf()
308 cpriv->pub.cji_curqueue = strdup(ptrname); in ctl_readcf()
314 if (id != -1) { in ctl_readcf()
319 fprintf(ctl_dbgfile, "%s: s=%p r=%ld e=%p %p->%s\n", in ctl_readcf()
321 cpriv->cji_eobuff, cpriv->pub.cji_fname, in ctl_readcf()
322 cpriv->pub.cji_fname); in ctl_readcf()
327 * Copy job-attribute values from control file to the struct of in ctl_readcf()
329 * value to be a null-string, so that is ignored. in ctl_readcf()
331 cjinf = &(cpriv->pub); in ctl_readcf()
337 cpriv->pub.cji_class = strdup(lbuff); in ctl_readcf()
338 break; in ctl_readcf()
341 break; in ctl_readcf()
342 cpriv->pub.cji_accthost = strdup(lbuff); in ctl_readcf()
343 break; in ctl_readcf()
345 cpriv->pub.cji_jobname = strdup(lbuff); in ctl_readcf()
346 break; in ctl_readcf()
348 cpriv->pub.cji_headruser = strdup(lbuff); in ctl_readcf()
349 break; in ctl_readcf()
352 * No valid mail-to address would start with a minus. in ctl_readcf()
356 if (*lbuff == '-') in ctl_readcf()
357 break; in ctl_readcf()
359 break; in ctl_readcf()
360 cpriv->pub.cji_mailto = strdup(lbuff); in ctl_readcf()
361 break; in ctl_readcf()
364 break; in ctl_readcf()
366 if (*lbuff == '-') in ctl_readcf()
368 cpriv->pub.cji_acctuser = strdup(lbuff); in ctl_readcf()
369 break; in ctl_readcf()
372 cpriv->pub.cji_dfcount++; in ctl_readcf()
374 break; in ctl_readcf()
380 if (cpriv->pub.cji_accthost == NULL) in ctl_readcf()
381 cpriv->pub.cji_accthost = strdup(".na."); in ctl_readcf()
382 if (cpriv->pub.cji_acctuser == NULL) in ctl_readcf()
383 cpriv->pub.cji_acctuser = strdup(".na."); in ctl_readcf()
387 if (cpriv->cji_dumpit) in ctl_readcf()
388 ctl_dumpcji(ctl_dbgfile, "end readcf", &(cpriv->pub)); in ctl_readcf()
393 return &(cpriv->pub); in ctl_readcf()
397 * This routine renames the temporary control file as received from some
400 * for the control file. Now if you read the RFC, you would think that all
401 * control filenames start with `cfA*'. However, it seems there are some
402 * implementations which send control filenames which start with `cf'
411 * of that control file. It is partially meant to protect against people
418 * lpr, particularly since we may want to use some values from the control
423 * lpr or lprNG define the contents of various lines in a control file.
426 * Error messages which are RETURNED (as opposed to syslog-ed) do not include
427 * the printer-queue name. Let the caller add that if it is wanted.
442 if (res == -1) { in ctl_renametf()
445 * then do the exact same steps that the pre-ctlinfo code had in ctl_renametf()
481 * gives us greater control over file-creation issues. in ctl_renametf()
486 if (newfd == -1) { in ctl_renametf()
502 * Do extra sanity checks on some key job-attribute fields, and in ctl_renametf()
507 * Some lpr implementations on PC's set a null-string for their in ctl_renametf()
515 if (cjinf->cji_accthost == NULL) in ctl_renametf()
517 else if (strcmp(cjinf->cji_accthost, ".na.") == 0) in ctl_renametf()
519 else if (strcmp(cjinf->cji_accthost, "localhost") == 0) in ctl_renametf()
522 for (cp = cjinf->cji_accthost; *cp != '\0'; cp++) { in ctl_renametf()
525 break; in ctl_renametf()
532 fprintf(newcf, "H%s\n", cjinf->cji_accthost); in ctl_renametf()
537 * to be present in a control file. in ctl_renametf()
542 * implementations send a null-string for a value. Various Mac in ctl_renametf()
547 if (cjinf->cji_acctuser == NULL) in ctl_renametf()
549 else if (strcmp(cjinf->cji_acctuser, ".na.") == 0) in ctl_renametf()
553 cp = cjinf->cji_acctuser; in ctl_renametf()
554 if (*cp == '-') in ctl_renametf()
574 if (has_uc && (getpwnam(cjinf->cji_acctuser) == NULL)) { in ctl_renametf()
575 for (cp = cjinf->cji_acctuser; *cp != '\0'; cp++) { in ctl_renametf()
584 fprintf(newcf, "P%s\n", cjinf->cji_acctuser); in ctl_renametf()
587 if (cjinf->cji_class != NULL) in ctl_renametf()
588 fprintf(newcf, "C%s\n", cjinf->cji_class); in ctl_renametf()
589 if (cjinf->cji_jobname != NULL) in ctl_renametf()
590 fprintf(newcf, "J%s\n", cjinf->cji_jobname); in ctl_renametf()
591 if (cjinf->cji_headruser != NULL) in ctl_renametf()
592 fprintf(newcf, "L%s\n", cjinf->cji_headruser); in ctl_renametf()
602 if (cjinf->cji_mailto == NULL) in ctl_renametf()
605 for (cp = cjinf->cji_mailto; *cp != '\0'; cp++) { in ctl_renametf()
608 break; in ctl_renametf()
613 fprintf(newcf, "M%s\n", cjinf->cji_mailto); in ctl_renametf()
616 * Now go thru the old control file, copying all information which in ctl_renametf()
630 break; in ctl_renametf()
633 if (cjinf->cji_dfcount == 0) { in ctl_renametf()
635 break; in ctl_renametf()
638 break; in ctl_renametf()
642 * host had to process 'lpr -s -r', but it did not in ctl_renametf()
643 * remove the Unlink line from the control file. in ctl_renametf()
651 break; /* skip this line */ in ctl_renametf()
660 * screwed-up control file, fix it here. in ctl_renametf()
662 if (cjinf->cji_dfcount == 0) { in ctl_renametf()
669 break; in ctl_renametf()
672 break; in ctl_renametf()
675 break; in ctl_renametf()
754 cpriv = cjinf->cji_priv; in ctl_rewindcf()
755 if ((cpriv == NULL) || (cpriv != cpriv->pub.cji_priv)) { in ctl_rewindcf()
761 rewind(cpriv->cji_fstream); /* assume no errors... :-) */ in ctl_rewindcf()
784 break; in ctl_rmjob()
786 break; in ctl_rmjob()
788 break; in ctl_rmjob()
814 fprintf(dbg_stream, "%p -> %s\n", astr, astr) in ctl_dumpcji()
825 cpriv = cjinf->cji_priv; in ctl_dumpcji()
827 fprintf(dbg_stream, "ctl_dumpcji: Dump '%s' of cjobinfo at %p->%p\n", in ctl_dumpcji()
828 heading, (void *)cjinf, cpriv->cji_buff); in ctl_dumpcji()
830 PRINTSTR("accthost.H", cpriv->pub.cji_accthost); in ctl_dumpcji()
831 PRINTSTR("acctuser.P", cpriv->pub.cji_acctuser); in ctl_dumpcji()
832 PRINTSTR("class.C", cpriv->pub.cji_class); in ctl_dumpcji()
833 PRINTSTR("cf-qname", cpriv->pub.cji_curqueue); in ctl_dumpcji()
834 PRINTSTR("cf-fname", cpriv->pub.cji_fname); in ctl_dumpcji()
835 PRINTSTR("jobname.J", cpriv->pub.cji_jobname); in ctl_dumpcji()
836 PRINTSTR("mailto.M", cpriv->pub.cji_mailto); in ctl_dumpcji()
837 PRINTSTR("headruser.L", cpriv->pub.cji_headruser); in ctl_dumpcji()
841 if (cpriv->pub.cji_priv == NULL) in ctl_dumpcji()
844 fprintf(dbg_stream, "%p\n", (void *)cpriv->pub.cji_priv); in ctl_dumpcji()
846 fprintf(dbg_stream, "|- - - - --> Dump '%s' complete\n", heading); in ctl_dumpcji()
848 /* flush output for the benefit of anyone doing a 'tail -f' */ in ctl_dumpcji()
855 * This routine reads in the next line from the control-file, and removes
858 * Historical note: Earlier versions of this routine did tab-expansion for
860 * in a control file. For the lines where tab-expansion is useful, it will
871 cpriv = cjinf->cji_priv; in ctl_getline()
872 if ((cpriv == NULL) || (cpriv != cpriv->pub.cji_priv)) { in ctl_getline()
879 strp = fgets(cpriv->cji_buff, cpriv->cji_buffsize, cpriv->cji_fstream); in ctl_getline()
883 cpriv->pub.cji_curqueue, cpriv->pub.cji_fname, in ctl_getline()
909 cpriv->cji_dumpit++; in ctl_getline()
911 cpriv->pub.cji_fname, tabcnt, cpriv->cji_buff); in ctl_getline()