xref: /openbsd-src/usr.sbin/lpd/lp.h (revision 3b188dab47094e37e38dcd2dcd35528ab7a95e4d)
1*3b188dabSeric /*	$OpenBSD: lp.h,v 1.1.1.1 2018/04/27 16:14:36 eric Exp $	*/
2*3b188dabSeric 
3*3b188dabSeric /*
4*3b188dabSeric  * Copyright (c) 2017 Eric Faurot <eric@openbsd.org>
5*3b188dabSeric  *
6*3b188dabSeric  * Permission to use, copy, modify, and distribute this software for any
7*3b188dabSeric  * purpose with or without fee is hereby granted, provided that the above
8*3b188dabSeric  * copyright notice and this permission notice appear in all copies.
9*3b188dabSeric  *
10*3b188dabSeric  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*3b188dabSeric  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*3b188dabSeric  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*3b188dabSeric  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*3b188dabSeric  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*3b188dabSeric  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*3b188dabSeric  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*3b188dabSeric  */
18*3b188dabSeric 
19*3b188dabSeric #include <sys/stat.h>
20*3b188dabSeric 
21*3b188dabSeric #include <paths.h>
22*3b188dabSeric #include <stdio.h>
23*3b188dabSeric 
24*3b188dabSeric #define _PATH_PRINTCAP	"/etc/printcap"
25*3b188dabSeric #define _PATH_HOSTSLPD	"/etc/hosts.lpd"
26*3b188dabSeric 
27*3b188dabSeric #define DEFAULT_FF	"\f"
28*3b188dabSeric #define DEFAULT_LF	_PATH_CONSOLE
29*3b188dabSeric #define DEFAULT_LO	"lock"
30*3b188dabSeric #define DEFAULT_LP	"/dev/lp"
31*3b188dabSeric #define DEFAULT_PC	200
32*3b188dabSeric #define DEFAULT_PL	66
33*3b188dabSeric #define DEFAULT_PW	132
34*3b188dabSeric #define DEFAULT_RP	"lp"
35*3b188dabSeric #define DEFAULT_SD	"/var/spool/output"
36*3b188dabSeric #define DEFAULT_ST	"status"
37*3b188dabSeric 
38*3b188dabSeric #define LP_MAXALIASES	32
39*3b188dabSeric #define LP_MAXUSERS	50
40*3b188dabSeric #define LP_MAXREQUESTS	50
41*3b188dabSeric 
42*3b188dabSeric #define LPR_ACK		0
43*3b188dabSeric #define LPR_NACK	1	/* only for sending */
44*3b188dabSeric 
45*3b188dabSeric #define PRN_LOCAL	0	/* local printer */
46*3b188dabSeric #define PRN_NET		1	/* printer listening directly on a port */
47*3b188dabSeric #define PRN_LPR		2	/* some lpr daemon */
48*3b188dabSeric 
49*3b188dabSeric #define LPQ_PRINTER_DOWN 	0x1
50*3b188dabSeric #define LPQ_QUEUE_OFF		0x2
51*3b188dabSeric #define LPQ_QUEUE_UPDATED	0x4
52*3b188dabSeric 
53*3b188dabSeric #define LP_FF(p) (((p)->lp_ff) ? ((p)->lp_ff) : DEFAULT_FF)
54*3b188dabSeric #define LP_LF(p) (((p)->lp_lf) ? ((p)->lp_lf) : DEFAULT_LF)
55*3b188dabSeric #define LP_LO(p) (((p)->lp_lo) ? ((p)->lp_lo) : DEFAULT_LO)
56*3b188dabSeric #define LP_LP(p) (((p)->lp_lp) ? ((p)->lp_lp) : DEFAULT_LP)
57*3b188dabSeric #define LP_RP(p) (((p)->lp_rp) ? ((p)->lp_rp) : DEFAULT_RP)
58*3b188dabSeric #define LP_SD(p) (((p)->lp_sd) ? ((p)->lp_sd) : DEFAULT_SD)
59*3b188dabSeric #define LP_ST(p) (((p)->lp_st) ? ((p)->lp_st) : DEFAULT_ST)
60*3b188dabSeric 
61*3b188dabSeric #define LP_JOBNUM(cf) (100*((cf)[3]-'0') + 10*((cf)[4]-'0') + ((cf)[5]-'0'))
62*3b188dabSeric #define LP_JOBHOST(cf) ((cf) + 6)
63*3b188dabSeric 
64*3b188dabSeric struct lp_printer {
65*3b188dabSeric 	int	 lp_type;
66*3b188dabSeric 	char	*lp_name;
67*3b188dabSeric 	char	*lp_aliases[LP_MAXALIASES];
68*3b188dabSeric 	int	 lp_aliascount;
69*3b188dabSeric 
70*3b188dabSeric 	char	*lp_host; /* if remote */
71*3b188dabSeric 	char	*lp_port;
72*3b188dabSeric 
73*3b188dabSeric 	FILE	*lp_lock; /* currently held lock file */
74*3b188dabSeric 
75*3b188dabSeric 	char	*lp_af;	/* name of accounting file */
76*3b188dabSeric 	long	 lp_br;	/* if lp is a tty, set baud rate (ioctl(2) call) */
77*3b188dabSeric 	char	*lp_cf;	/* cifplot data filter */
78*3b188dabSeric 	char	*lp_df;	/* tex data filter (DVI format) */
79*3b188dabSeric 	char	*lp_ff;	/* string to send for a form feed */
80*3b188dabSeric 	short	 lp_fo;	/* print a form feed when device is opened */
81*3b188dabSeric 	char	*lp_gf;	/* graph data filter (plot(3) format) */
82*3b188dabSeric 	short	 lp_hl;	/* print the burst header page last */
83*3b188dabSeric 	short	 lp_ic;	/* supports non-standard ioctl to indent printout */
84*3b188dabSeric 	char	*lp_if;	/* name of text filter which does accounting */
85*3b188dabSeric 	char	*lp_lf;	/* error logging file name */
86*3b188dabSeric 	char	*lp_lo;	/* name of lock file */
87*3b188dabSeric 	char	*lp_lp;	/* local printer device, or port@host for remote */
88*3b188dabSeric 	long	 lp_mc;	/* maximum number of copies allowed; 0=unlimited */
89*3b188dabSeric 	char	*lp_ms;	/* if lp is a tty, a comma-separated, stty(1)-like list
90*3b188dabSeric 			   describing the tty modes */
91*3b188dabSeric 	long	 lp_mx;	/* max file size (in BUFSIZ blocks); 0=unlimited */
92*3b188dabSeric 	char	*lp_nd;	/* next directory for queues list (unimplemented) */
93*3b188dabSeric 	char	*lp_nf;	/* ditroff data filter (device independent troff) */
94*3b188dabSeric 	char	*lp_of;	/* name of output filtering program */
95*3b188dabSeric 	long	 lp_pc;	/* price per foot or page in hundredths of cents */
96*3b188dabSeric 	long	 lp_pl;	/* page length (in lines) */
97*3b188dabSeric 	long	 lp_pw;	/* page width (in characters) */
98*3b188dabSeric 	long	 lp_px;	/* page width in pixels (horizontal) */
99*3b188dabSeric 	long	 lp_py;	/* page length in pixels (vertical) */
100*3b188dabSeric 	char	*lp_rf;	/* filter for printing FORTRAN style text files */
101*3b188dabSeric 	char	*lp_rg;	/* restricted group-only group members can access */
102*3b188dabSeric 	char	*lp_rm;	/* machine name for remote printer */
103*3b188dabSeric 	char	*lp_rp;	/* remote printer name argument */
104*3b188dabSeric 	short	 lp_rs;	/* remote users must have a local account */
105*3b188dabSeric 	short	 lp_rw;	/* open printer device for reading and writing */
106*3b188dabSeric 	short	 lp_sb;	/* short banner (one line only) */
107*3b188dabSeric 	short	 lp_sc;	/* suppress multiple copies */
108*3b188dabSeric 	char	*lp_sd;	/* spool directory */
109*3b188dabSeric 	short	 lp_sf;	/* suppress form feeds */
110*3b188dabSeric 	short	 lp_sh;	/* suppress printing of burst page header */
111*3b188dabSeric 	char	*lp_st;	/* status file name */
112*3b188dabSeric 	char	*lp_tf;	/* troff data filter (cat phototypesetter) */
113*3b188dabSeric 	char	*lp_tr;	/* trailer string to print when queue empties */
114*3b188dabSeric 	char	*lp_vf;	/* raster image filter */
115*3b188dabSeric };
116*3b188dabSeric 
117*3b188dabSeric struct lp_queue {
118*3b188dabSeric 	int	  count;
119*3b188dabSeric 	char	**cfname;
120*3b188dabSeric };
121*3b188dabSeric 
122*3b188dabSeric struct lp_jobfilter {
123*3b188dabSeric 	const char	*hostfrom;
124*3b188dabSeric 	int		 nuser;
125*3b188dabSeric 	const char	*users[LP_MAXUSERS];
126*3b188dabSeric 	int		 njob;
127*3b188dabSeric 	int		 jobs[LP_MAXREQUESTS];
128*3b188dabSeric };
129*3b188dabSeric 
130*3b188dabSeric extern char *lpd_hostname;
131*3b188dabSeric 
132*3b188dabSeric /* lp.c */
133*3b188dabSeric int   lp_getprinter(struct lp_printer *, const char *);
134*3b188dabSeric int   lp_scanprinters(struct lp_printer *);
135*3b188dabSeric void  lp_clearprinter(struct lp_printer *);
136*3b188dabSeric int   lp_readqueue(struct lp_printer *, struct lp_queue *);
137*3b188dabSeric void  lp_clearqueue(struct lp_queue *);
138*3b188dabSeric FILE* lp_fopen(struct lp_printer *, const char *);
139*3b188dabSeric int   lp_stat(struct lp_printer *, const char *, struct stat *);
140*3b188dabSeric int   lp_unlink(struct lp_printer *, const char *);
141*3b188dabSeric int   lp_lock(struct lp_printer *);
142*3b188dabSeric void  lp_unlock(struct lp_printer *);
143*3b188dabSeric int   lp_getqueuestate(struct lp_printer *, int, int *);
144*3b188dabSeric int   lp_getcurrtask(struct lp_printer *, pid_t *, char *, size_t);
145*3b188dabSeric void  lp_setcurrtask(struct lp_printer *, const char *);
146*3b188dabSeric int   lp_getstatus(struct lp_printer *, char *, size_t);
147*3b188dabSeric void  lp_setstatus(struct lp_printer *, const char *, ...)
148*3b188dabSeric 	__attribute__((__format__ (printf, 2, 3)));
149*3b188dabSeric int   lp_validfilename(const char *, int);
150*3b188dabSeric int   lp_create(struct lp_printer *, int, size_t, const char *);
151*3b188dabSeric int   lp_commit(struct lp_printer *, const char *);
152*3b188dabSeric 
153*3b188dabSeric /* lp_banner.c */
154*3b188dabSeric int   lp_banner(int, char *, int);
155*3b188dabSeric 
156*3b188dabSeric /* lp_displayq.c */
157*3b188dabSeric void  lp_displayq(int, struct lp_printer *, int, struct lp_jobfilter *);
158*3b188dabSeric 
159*3b188dabSeric /* lp_rmjob */
160*3b188dabSeric int   lp_rmjob(int, struct lp_printer *, const char *, struct lp_jobfilter *);
161*3b188dabSeric 
162*3b188dabSeric /* lp_stty.c */
163*3b188dabSeric void  lp_stty(struct lp_printer *, int);
164