xref: /freebsd/usr.sbin/lpr/common_source/matchjobs.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * ------+---------+---------+---------+---------+---------+---------+---------*
5  * Copyright (c) 2002  - Garance Alistair Drosehn <gad@FreeBSD.org>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *   1. Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *   2. Redistributions in binary form must reproduce the above copyright
14  *      notice, this list of conditions and the following disclaimer in the
15  *      documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and documentation
30  * are those of the authors and should not be interpreted as representing
31  * official policies, either expressed or implied, of the FreeBSD Project
32  * or FreeBSD, Inc.
33  *
34  * ------+---------+---------+---------+---------+---------+---------+---------*
35  * $FreeBSD$
36  * ------+---------+---------+---------+---------+---------+---------+---------*
37  */
38 
39 #include <sys/queue.h>
40 
41 /*
42  * The "matcheduser" field is *only* valid during the call to the
43  * given "doentry()" routine, and is only set if the specification
44  * included a userid.
45  */
46 struct jobspec {
47 	STAILQ_ENTRY(jobspec) nextjs;
48 	char	*wantedhost;
49 	char	*wanteduser;
50 	char	*matcheduser;		/* only valid for "doentry()" */
51 	char	*fmtoutput;		/* set by format_jobspec() */
52 	long	 startnum;
53 	long	 endrange;
54 	int	 pluralfmt;		/* boolean set by format_jobspec() */
55 	uint	 matchcnt;
56 };
57 STAILQ_HEAD(jobspec_hdr, jobspec);
58 
59 /*
60  * Format options for format_jobspec.
61  */
62 #define FMTJS_TERSE	1		/* user:jobrange@host */
63 #define FMTJS_VERBOSE	2		/* jobrange from user@host */
64 
65 /*
66  * Options for scanq_jobspec.
67  *
68  * The caller must choose the order that entries should be scanned:
69  * 1) JSORDER: Matched jobs are processed (by calling the "doentry()"
70  *    routine) in the order that the user specified those jobs.
71  * 2) QORDER: Matched jobs are processed in the order that the jobs are
72  *    listed the queue.  This guarantees that the "doentry()" routine
73  *    will be called only once per job.
74  *
75  * There is a "job_matched" variable in struct jobqueue, which is used
76  * to make sure that the "doentry()" will only be called once for any
77  * given job in JSORDER processing.  The "doentry()" routine can turn
78  * that off, if it does want to be called multiple times when the job
79  * is matched by multiple specifiers.
80  *
81  * The JSORDER processing will also call the "doentry()" routine once
82  * after each scan of the queue, with the jobqueue set to null.  This
83  * provides a way for the caller to print out a summary message for
84  * each jobspec that was given.
85  */
86 #define SCQ_JSORDER	0x0001		/* follow the user-specified order */
87 #define SCQ_QORDER	0x0002		/* the order of jobs in the queue */
88 
89 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
90 
91 __BEGIN_DECLS
92 struct	 jobqueue;
93 
94 typedef	int	 process_jqe(void *_myinfo, struct jobqueue *_jq,
95 		    struct jobspec *_jspec);
96 
97 void	 format_jobspec(struct jobspec *_jspec, int _fmt_wanted);
98 void	 free_jobspec(struct jobspec_hdr *_js_hdr);
99 int	 scanq_jobspec(int _qitems, struct jobqueue **_squeue, int _sopts,
100 	    struct jobspec_hdr *_js_hdr, process_jqe _doentry,
101 	    void *_doentryinfo);
102 int	 parse_jobspec(char *_jobstr, struct jobspec_hdr *_js_hdr);
103 __END_DECLS
104 
105