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