1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.11 */ 32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ 33 34 #include "stdio.h" 35 #include "string.h" 36 #include "errno.h" 37 #include "sys/types.h" 38 #include "sys/utsname.h" 39 #include "stdlib.h" 40 41 #include "lp.h" 42 #include "requests.h" 43 44 extern struct { 45 char *v; 46 short len; 47 } reqheadings[]; 48 49 /** 50 ** putrequest() - WRITE REQUEST STRUCTURE TO DISK FILE 51 **/ 52 53 int 54 #if defined(__STDC__) 55 putrequest ( 56 char * file, 57 REQUEST * reqbufp 58 ) 59 #else 60 putrequest (file, reqbufp) 61 char *file; 62 REQUEST *reqbufp; 63 #endif 64 { 65 char **pp, 66 *path; 67 68 int fd; 69 70 int fld; 71 72 /* 73 * First go through the structure and see if we have 74 * anything strange. 75 */ 76 if ( 77 reqbufp->copies <= 0 78 || !(reqbufp->destination) 79 || !reqbufp->file_list || !*(reqbufp->file_list) 80 || (reqbufp->actions & (ACT_MAIL|ACT_WRITE)) 81 && (reqbufp->alert && *(reqbufp->alert)) 82 || reqbufp->priority < -1 || 39 < reqbufp->priority 83 ) { 84 errno = EINVAL; 85 return (-1); 86 } 87 88 /* 89 * Now open the file and write out the request. 90 */ 91 92 /* 93 * Full pathname? If so the file must lie in LP's 94 * regular temporary directory. 95 */ 96 if (*file == '/') { 97 if (!STRNEQU(file, Lp_Tmp, strlen(Lp_Tmp))) { 98 errno = EINVAL; 99 return (-1); 100 } 101 path = Strdup(file); 102 103 /* 104 * A relative pathname (such as system/name)? 105 * If so we'll locate it under LP's regular temporary 106 * directory. 107 */ 108 } else if (strchr(file, '/')) { 109 if (!(path = makepath(Lp_Tmp, file, (char *)0))) 110 return (-1); 111 112 /* 113 * If must be a simple name. Locate this under the 114 * special temporary directory that is linked to the 115 * regular place for the local system. 116 */ 117 } else if (!(path = makepath(Lp_Temp, file, (char *)0))) 118 return (-1); 119 120 if ((fd = open_locked(path, "w", MODE_NOREAD)) < 0) { 121 Free (path); 122 return (-1); 123 } 124 Free (path); 125 126 for (fld = 0; fld < RQ_MAX; fld++) switch (fld) { 127 128 #define HEAD reqheadings[fld].v 129 130 case RQ_COPIES: 131 (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->copies); 132 break; 133 134 case RQ_DEST: 135 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->destination); 136 break; 137 138 case RQ_FILE: 139 for (pp = reqbufp->file_list; *pp; pp++) 140 (void)fdprintf(fd, "%s%s\n", HEAD, *pp); 141 break; 142 143 case RQ_FORM: 144 if (reqbufp->form) 145 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->form); 146 break; 147 148 case RQ_HANDL: 149 if ((reqbufp->actions & ACT_SPECIAL) == ACT_IMMEDIATE) 150 (void)fdprintf(fd, "%s%s\n", HEAD, NAME_IMMEDIATE); 151 else if ((reqbufp->actions & ACT_SPECIAL) == ACT_RESUME) 152 (void)fdprintf(fd, "%s%s\n", HEAD, NAME_RESUME); 153 else if ((reqbufp->actions & ACT_SPECIAL) == ACT_HOLD) 154 (void)fdprintf(fd, "%s%s\n", HEAD, NAME_HOLD); 155 break; 156 157 case RQ_NOTIFY: 158 if (reqbufp->actions & ACT_MAIL) 159 (void)fdprintf(fd, "%sM\n", HEAD); 160 else if (reqbufp->actions & ACT_WRITE) 161 (void)fdprintf(fd, "%sW\n", HEAD); 162 else if (reqbufp->actions & ACT_NOTIFY) 163 (void)fdprintf(fd, "%sN\n", HEAD); 164 else if (reqbufp->alert && *(reqbufp->alert)) 165 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->alert); 166 break; 167 168 case RQ_OPTS: 169 if (reqbufp->options) 170 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->options); 171 break; 172 173 case RQ_PRIOR: 174 if (reqbufp->priority != -1) 175 (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->priority); 176 break; 177 178 case RQ_PAGES: 179 if (reqbufp->pages) 180 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->pages); 181 break; 182 183 case RQ_CHARS: 184 if (reqbufp->charset) 185 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->charset); 186 break; 187 188 case RQ_TITLE: 189 if (reqbufp->title) 190 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->title); 191 break; 192 193 case RQ_MODES: 194 if (reqbufp->modes) 195 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->modes); 196 break; 197 198 case RQ_TYPE: 199 if (reqbufp->input_type) 200 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->input_type); 201 break; 202 203 case RQ_USER: 204 if (reqbufp->user) 205 (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->user); 206 break; 207 208 case RQ_RAW: 209 if (reqbufp->actions & ACT_RAW) 210 (void)fdprintf(fd, "%s\n", HEAD); 211 break; 212 213 case RQ_FAST: 214 if (reqbufp->actions & ACT_FAST) 215 (void)fdprintf(fd, "%s\n", HEAD); 216 break; 217 218 case RQ_STAT: 219 (void)fdprintf(fd, "%s%#6.4x\n", HEAD, reqbufp->outcome); 220 break; 221 222 case RQ_VERSION: 223 (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->version); 224 break; 225 226 } 227 228 close(fd); 229 return (0); 230 } 231