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