1100203Sgad/* 2100203Sgad * ------+---------+---------+---------+---------+---------+---------+---------* 3100203Sgad * Copyright (c) 2002 - Garance Alistair Drosehn <gad@FreeBSD.org>. 4100203Sgad * All rights reserved. 5100203Sgad * 6100203Sgad * Redistribution and use in source and binary forms, with or without 7100203Sgad * modification, are permitted provided that the following conditions 8100203Sgad * are met: 9100203Sgad * 1. Redistributions of source code must retain the above copyright 10100203Sgad * notice, this list of conditions and the following disclaimer. 11100203Sgad * 2. Redistributions in binary form must reproduce the above copyright 12100203Sgad * notice, this list of conditions and the following disclaimer in the 13100203Sgad * documentation and/or other materials provided with the distribution. 14100203Sgad * 15100203Sgad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16100203Sgad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17100203Sgad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18100203Sgad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19100203Sgad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20100203Sgad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21100203Sgad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22100203Sgad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23100203Sgad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24100203Sgad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25100203Sgad * SUCH DAMAGE. 26100203Sgad * 27100203Sgad * The views and conclusions contained in the software and documentation 28100203Sgad * are those of the authors and should not be interpreted as representing 29100203Sgad * official policies, either expressed or implied, of the FreeBSD Project 30100203Sgad * or FreeBSD, Inc. 31100203Sgad * 32100203Sgad * ------+---------+---------+---------+---------+---------+---------+---------* 33100203Sgad * $FreeBSD$ 34100203Sgad * ------+---------+---------+---------+---------+---------+---------+---------* 35100203Sgad */ 36100203Sgad 37100203Sgad#include <sys/queue.h> 38100203Sgad 39100203Sgad/* 40100203Sgad * The "matcheduser" field is *only* valid during the call to the 41100203Sgad * given "doentry()" routine, and is only set if the specification 42100203Sgad * included a userid. 43100203Sgad */ 44100203Sgadstruct jobspec { 45100203Sgad STAILQ_ENTRY(jobspec) nextjs; 46100203Sgad char *wantedhost; 47100203Sgad char *wanteduser; 48100203Sgad char *matcheduser; /* only valid for "doentry()" */ 49100203Sgad char *fmtoutput; /* set by format_jobspec() */ 50100203Sgad long startnum; 51100203Sgad long endrange; 52100203Sgad int pluralfmt; /* boolean set by format_jobspec() */ 53100203Sgad uint matchcnt; 54100203Sgad}; 55100203SgadSTAILQ_HEAD(jobspec_hdr, jobspec); 56100203Sgad 57100203Sgad/* 58100203Sgad * Format options for format_jobspec. 59100203Sgad */ 60100203Sgad#define FMTJS_TERSE 1 /* user:jobrange@host */ 61100203Sgad#define FMTJS_VERBOSE 2 /* jobrange from user@host */ 62100203Sgad 63100203Sgad/* 64100203Sgad * Options for scanq_jobspec. 65100203Sgad * 66100203Sgad * The caller must choose the order that entries should be scanned: 67100203Sgad * 1) JSORDER: Matched jobs are processed (by calling the "doentry()" 68100203Sgad * routine) in the order that the user specified those jobs. 69100203Sgad * 2) QORDER: Matched jobs are processed in the order that the jobs are 70100203Sgad * listed the queue. This guarantees that the "doentry()" routine 71100203Sgad * will be called only once per job. 72100203Sgad * 73100203Sgad * There is a "job_matched" variable in struct jobqueue, which is used 74100203Sgad * to make sure that the "doentry()" will only be called once for any 75100203Sgad * given job in JSORDER processing. The "doentry()" routine can turn 76100203Sgad * that off, if it does want to be called multiple times when the job 77100203Sgad * is matched by multiple specifiers. 78100203Sgad * 79100203Sgad * The JSORDER processing will also call the "doentry()" routine once 80100203Sgad * after each scan of the queue, with the jobqueue set to null. This 81100203Sgad * provides a way for the caller to print out a summary message for 82100203Sgad * each jobspec that was given. 83100203Sgad */ 84100203Sgad#define SCQ_JSORDER 0x0001 /* follow the user-specified order */ 85100203Sgad#define SCQ_QORDER 0x0002 /* the order of jobs in the queue */ 86100203Sgad 87117541Sgad#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ 88117541Sgad 89100203Sgad__BEGIN_DECLS 90100203Sgadstruct jobqueue; 91100203Sgad 92100203Sgadtypedef int process_jqe(void *_myinfo, struct jobqueue *_jq, 93100203Sgad struct jobspec *_jspec); 94100203Sgad 95100203Sgadvoid format_jobspec(struct jobspec *_jspec, int _fmt_wanted); 96100203Sgadvoid free_jobspec(struct jobspec_hdr *_js_hdr); 97100203Sgadint scanq_jobspec(int _qitems, struct jobqueue **_squeue, int _sopts, 98100203Sgad struct jobspec_hdr *_js_hdr, process_jqe _doentry, 99100203Sgad void *_doentryinfo); 100100203Sgadint parse_jobspec(char *_jobstr, struct jobspec_hdr *_js_hdr); 101100203Sgad__END_DECLS 102100203Sgad 103