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