131492Swollman/*
231492Swollman * Copyright 1997 Massachusetts Institute of Technology
331492Swollman *
431492Swollman * Permission to use, copy, modify, and distribute this software and
531492Swollman * its documentation for any purpose and without fee is hereby
631492Swollman * granted, provided that both the above copyright notice and this
731492Swollman * permission notice appear in all copies, that both the above
831492Swollman * copyright notice and this permission notice appear in all
931492Swollman * supporting documentation, and that the name of M.I.T. not be used
1031492Swollman * in advertising or publicity pertaining to distribution of the
1131492Swollman * software without specific, written prior permission.  M.I.T. makes
1231492Swollman * no representations about the suitability of this software for any
1331492Swollman * purpose.  It is provided "as is" without express or implied
1431492Swollman * warranty.
1531492Swollman *
1631492Swollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
1731492Swollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
1831492Swollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1931492Swollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
2031492Swollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2131492Swollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2231492Swollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2331492Swollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2431492Swollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2531492Swollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2631492Swollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2731492Swollman * SUCH DAMAGE.
2831492Swollman */
2931492Swollman
3031492Swollmanstatic const char copyright[] =
3131492Swollman	"Copyright (C) 1997, Massachusetts Institute of Technology\r\n";
32117592Sgad
33117541Sgad#include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
34117541Sgad__FBSDID("$FreeBSD$");
3531492Swollman
3631492Swollman#include <sys/types.h>
3731492Swollman#include <sys/stat.h>
3831492Swollman
3931492Swollman#include <stdlib.h>
4031492Swollman#include <unistd.h>
4131492Swollman
4231492Swollman#include <sys/param.h>		/* needed for lp.h but not used here */
4331492Swollman#include <dirent.h>		/* ditto */
4431492Swollman#include <stdio.h>		/* ditto */
4531492Swollman#include "lp.h"
4631492Swollman#include "lp.local.h"
4731492Swollman
4831492Swollmanvoid
4931492Swollmaninit_request(struct request *rp)
5031492Swollman{
5131492Swollman	static struct request zero;
5231492Swollman
5331492Swollman	*rp = zero;
5431492Swollman	TAILQ_INIT(&rp->users);
5531492Swollman	TAILQ_INIT(&rp->jobids);
5631492Swollman}
5731492Swollman
5831492Swollmanvoid
5931492Swollmanfree_request(struct request *rp)
6031492Swollman{
6131492Swollman	struct req_user *ru;
6231492Swollman	struct req_jobid *rj;
6331492Swollman
6431492Swollman	if (rp->logname)
6531492Swollman		free(rp->logname);
6631492Swollman	if (rp->authname)
6731492Swollman		free(rp->authname);
6831492Swollman	if (rp->prettyname)
6931492Swollman		free(rp->prettyname);
7031492Swollman	if (rp->authinfo)
7131492Swollman		free(rp->authinfo);
7270520Sphk	while ((ru = TAILQ_FIRST(&rp->users)) != 0) {
7331492Swollman		TAILQ_REMOVE(&rp->users, ru, ru_link);
7431492Swollman		free(ru);
7531492Swollman	}
7670520Sphk	while ((rj = TAILQ_FIRST(&rp->jobids)) != 0) {
7731492Swollman		TAILQ_REMOVE(&rp->jobids, rj, rj_link);
7831492Swollman		free(rj);
7931492Swollman	}
8031492Swollman	init_request(rp);
8131492Swollman}
82