17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0a44ef6dSjacobs * Common Development and Distribution License (the "License").
6*0a44ef6dSjacobs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*0a44ef6dSjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
30*0a44ef6dSjacobs #pragma ident "%Z%%M% %I% %E% SMI"
317c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include "stdio.h"
347c478bd9Sstevel@tonic-gate #include "string.h"
357c478bd9Sstevel@tonic-gate #include "errno.h"
367c478bd9Sstevel@tonic-gate #include "sys/types.h"
377c478bd9Sstevel@tonic-gate #include "sys/utsname.h"
387c478bd9Sstevel@tonic-gate #include "stdlib.h"
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include "lp.h"
417c478bd9Sstevel@tonic-gate #include "requests.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate extern struct {
447c478bd9Sstevel@tonic-gate char *v;
457c478bd9Sstevel@tonic-gate short len;
467c478bd9Sstevel@tonic-gate } reqheadings[];
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate /**
497c478bd9Sstevel@tonic-gate ** putrequest() - WRITE REQUEST STRUCTURE TO DISK FILE
507c478bd9Sstevel@tonic-gate **/
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate int
537c478bd9Sstevel@tonic-gate #if defined(__STDC__)
putrequest(char * file,REQUEST * reqbufp)547c478bd9Sstevel@tonic-gate putrequest (
557c478bd9Sstevel@tonic-gate char * file,
567c478bd9Sstevel@tonic-gate REQUEST * reqbufp
577c478bd9Sstevel@tonic-gate )
587c478bd9Sstevel@tonic-gate #else
597c478bd9Sstevel@tonic-gate putrequest (file, reqbufp)
607c478bd9Sstevel@tonic-gate char *file;
617c478bd9Sstevel@tonic-gate REQUEST *reqbufp;
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate char **pp,
657c478bd9Sstevel@tonic-gate *path;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate int fd;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate int fld;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate * First go through the structure and see if we have
737c478bd9Sstevel@tonic-gate * anything strange.
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate if (
767c478bd9Sstevel@tonic-gate reqbufp->copies <= 0
777c478bd9Sstevel@tonic-gate || !(reqbufp->destination)
787c478bd9Sstevel@tonic-gate || !reqbufp->file_list || !*(reqbufp->file_list)
797c478bd9Sstevel@tonic-gate || (reqbufp->actions & (ACT_MAIL|ACT_WRITE))
807c478bd9Sstevel@tonic-gate && (reqbufp->alert && *(reqbufp->alert))
817c478bd9Sstevel@tonic-gate || reqbufp->priority < -1 || 39 < reqbufp->priority
827c478bd9Sstevel@tonic-gate ) {
837c478bd9Sstevel@tonic-gate errno = EINVAL;
847c478bd9Sstevel@tonic-gate return (-1);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate * Now open the file and write out the request.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate * Full pathname? If so the file must lie in LP's
937c478bd9Sstevel@tonic-gate * regular temporary directory.
947c478bd9Sstevel@tonic-gate */
957c478bd9Sstevel@tonic-gate if (*file == '/') {
967c478bd9Sstevel@tonic-gate if (!STRNEQU(file, Lp_Tmp, strlen(Lp_Tmp))) {
977c478bd9Sstevel@tonic-gate errno = EINVAL;
987c478bd9Sstevel@tonic-gate return (-1);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate path = Strdup(file);
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate * A relative pathname (such as system/name)?
1047c478bd9Sstevel@tonic-gate * If so we'll locate it under LP's regular temporary
1057c478bd9Sstevel@tonic-gate * directory.
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate } else if (strchr(file, '/')) {
1087c478bd9Sstevel@tonic-gate if (!(path = makepath(Lp_Tmp, file, (char *)0)))
1097c478bd9Sstevel@tonic-gate return (-1);
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate * If must be a simple name. Locate this under the
1137c478bd9Sstevel@tonic-gate * special temporary directory that is linked to the
1147c478bd9Sstevel@tonic-gate * regular place for the local system.
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate } else if (!(path = makepath(Lp_Temp, file, (char *)0)))
1177c478bd9Sstevel@tonic-gate return (-1);
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate if ((fd = open_locked(path, "w", MODE_NOREAD)) < 0) {
1207c478bd9Sstevel@tonic-gate Free (path);
1217c478bd9Sstevel@tonic-gate return (-1);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate Free (path);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate for (fld = 0; fld < RQ_MAX; fld++) switch (fld) {
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate #define HEAD reqheadings[fld].v
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate case RQ_COPIES:
1307c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->copies);
1317c478bd9Sstevel@tonic-gate break;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate case RQ_DEST:
1347c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->destination);
1357c478bd9Sstevel@tonic-gate break;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate case RQ_FILE:
1387c478bd9Sstevel@tonic-gate for (pp = reqbufp->file_list; *pp; pp++)
1397c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, *pp);
1407c478bd9Sstevel@tonic-gate break;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate case RQ_FORM:
1437c478bd9Sstevel@tonic-gate if (reqbufp->form)
1447c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->form);
1457c478bd9Sstevel@tonic-gate break;
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate case RQ_HANDL:
1487c478bd9Sstevel@tonic-gate if ((reqbufp->actions & ACT_SPECIAL) == ACT_IMMEDIATE)
1497c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_IMMEDIATE);
1507c478bd9Sstevel@tonic-gate else if ((reqbufp->actions & ACT_SPECIAL) == ACT_RESUME)
1517c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_RESUME);
1527c478bd9Sstevel@tonic-gate else if ((reqbufp->actions & ACT_SPECIAL) == ACT_HOLD)
1537c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_HOLD);
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate case RQ_NOTIFY:
1577c478bd9Sstevel@tonic-gate if (reqbufp->actions & ACT_MAIL)
1587c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%sM\n", HEAD);
1597c478bd9Sstevel@tonic-gate else if (reqbufp->actions & ACT_WRITE)
1607c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%sW\n", HEAD);
1617c478bd9Sstevel@tonic-gate else if (reqbufp->actions & ACT_NOTIFY)
1627c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%sN\n", HEAD);
1637c478bd9Sstevel@tonic-gate else if (reqbufp->alert && *(reqbufp->alert))
1647c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->alert);
1657c478bd9Sstevel@tonic-gate break;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate case RQ_OPTS:
1687c478bd9Sstevel@tonic-gate if (reqbufp->options)
1697c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->options);
1707c478bd9Sstevel@tonic-gate break;
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate case RQ_PRIOR:
1737c478bd9Sstevel@tonic-gate if (reqbufp->priority != -1)
1747c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->priority);
1757c478bd9Sstevel@tonic-gate break;
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate case RQ_PAGES:
1787c478bd9Sstevel@tonic-gate if (reqbufp->pages)
1797c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->pages);
1807c478bd9Sstevel@tonic-gate break;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate case RQ_CHARS:
1837c478bd9Sstevel@tonic-gate if (reqbufp->charset)
1847c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->charset);
1857c478bd9Sstevel@tonic-gate break;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate case RQ_TITLE:
1887c478bd9Sstevel@tonic-gate if (reqbufp->title)
1897c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->title);
1907c478bd9Sstevel@tonic-gate break;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate case RQ_MODES:
1937c478bd9Sstevel@tonic-gate if (reqbufp->modes)
1947c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->modes);
1957c478bd9Sstevel@tonic-gate break;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate case RQ_TYPE:
1987c478bd9Sstevel@tonic-gate if (reqbufp->input_type)
1997c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->input_type);
2007c478bd9Sstevel@tonic-gate break;
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate case RQ_USER:
2037c478bd9Sstevel@tonic-gate if (reqbufp->user)
2047c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->user);
2057c478bd9Sstevel@tonic-gate break;
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate case RQ_RAW:
2087c478bd9Sstevel@tonic-gate if (reqbufp->actions & ACT_RAW)
2097c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s\n", HEAD);
2107c478bd9Sstevel@tonic-gate break;
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate case RQ_FAST:
2137c478bd9Sstevel@tonic-gate if (reqbufp->actions & ACT_FAST)
2147c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s\n", HEAD);
2157c478bd9Sstevel@tonic-gate break;
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate case RQ_STAT:
2187c478bd9Sstevel@tonic-gate (void)fdprintf(fd, "%s%#6.4x\n", HEAD, reqbufp->outcome);
2197c478bd9Sstevel@tonic-gate break;
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate close(fd);
2247c478bd9Sstevel@tonic-gate return (0);
2257c478bd9Sstevel@tonic-gate }
226