Mercurial > illumos > onarm
annotate usr/src/cmd/fmli/oeu/oeu.c @ 4:1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
author | Koji Uno <koji.uno@sun.com> |
---|---|
date | Mon, 31 Aug 2009 14:38:03 +0900 |
parents | c9caec207d52 |
children |
rev | line source |
---|---|
0 | 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 /* | |
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | |
25 * Use is subject to license terms. | |
26 */ | |
27 | |
28 /* Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ | |
29 /* All Rights Reserved */ | |
30 | |
31 | |
4
1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
Koji Uno <koji.uno@sun.com>
parents:
0
diff
changeset
|
32 #pragma ident "%Z%%M% %I% %E% SMI" |
0 | 33 |
34 #include <stdio.h> | |
35 #include <string.h> | |
36 #include <ctype.h> | |
37 #include <sys/types.h> /* EFT abs k16 */ | |
38 #include "wish.h" | |
39 #include "io.h" | |
40 #include "retcds.h" | |
41 #include "parse.h" | |
42 #include "smdef.h" | |
43 #include "typetab.h" | |
44 #include "mail.h" | |
45 #include "partabdefs.h" | |
46 #include "terror.h" | |
47 #include "sizes.h" | |
48 | |
49 | |
50 #define NOFIELDS 20 | |
51 #define PARTFIELDS 13 | |
52 static int look_ahead = 0; | |
53 char *uptokwd(); | |
54 long getnum(); | |
55 int skipspace(); | |
56 static int stopit(); | |
57 extern int skip(); /* >>>> CHANGED FROM "static" <<<< */ | |
58 static int obj_num(); | |
59 static int obj_name(); | |
60 static int obj_type(); | |
61 static void encrytest(); | |
62 static int par_count(); | |
63 static struct parsetab { | |
64 char *testring; | |
65 int (*func)(); | |
66 } Parsetab[NOFIELDS] = | |
67 { | |
68 { "type:", obj_type }, | |
69 { "application:", skip }, | |
70 { "format:", skip }, | |
71 { "product-id:", skip }, | |
72 { "object-number:", obj_num }, | |
73 { "count:", par_count }, | |
74 { "name:", obj_name }, | |
75 { "cdate:", skip }, | |
76 { "moddate:", skip }, | |
77 { "author:", skip }, | |
78 { "folder:", skip }, | |
79 { "keywords:", skip }, | |
80 { "subject:", skip }, | |
81 { "product-info:", skip }, | |
82 { "part-type:", stopit }, | |
83 { "encrypted:", stopit }, | |
84 { "encryption-test:", stopit }, | |
85 { "part-encoding:", stopit }, | |
86 { "encoding-algorithm:",stopit }, | |
87 { "part-length:", stopit } | |
88 }; | |
89 | |
90 static int | |
91 stopit(fp, p) | |
92 FILE *fp; | |
93 struct oeh *p; | |
94 { | |
95 look_ahead = TRUE; | |
96 return (0); | |
97 } | |
98 int | |
99 #ifndef JUSTCHECK | |
100 oeuparse(from, p, unpack) | |
101 #else | |
102 oeucheck(from, p, unpack) | |
103 #endif /* JUSTCHECK */ | |
104 char *from; | |
105 struct oeh *p; | |
106 int unpack; | |
107 { | |
108 struct opt_entry *parts, *obj_to_parts(); | |
109 struct one_part *apart, *opt_next_part(); | |
110 FILE *fp, *fp2; | |
111 char *enc, *type ,*filename(); | |
112 int c, kwd, i /* , place */; /* abs: vaiable unused */ | |
113 long length; | |
114 char partname[PATHSIZ], fullname[PATHSIZ]; | |
115 char buf[STR_SIZE]; | |
116 | |
117 if ((fp = fopen(from, "r")) == NULL) { | |
118 warn(NOPEN, from); | |
119 return(OEH_BAD); | |
120 } | |
121 p->name = p->num = NULL; | |
122 p->encrytest = NULL; | |
123 p->count = 1; | |
124 while ((kwd = nextkwd(fp, buf)) == PDONE); | |
125 if (kwd == EOF) { | |
126 fclose(fp); | |
127 return(OEH_BAD); | |
128 } | |
129 if (strcmp(buf, "version:") && strcmp(buf, "content-version:")) { | |
130 fclose(fp); | |
131 return(OEH_NOT); | |
132 } | |
133 skiptokwd(fp); | |
134 look_ahead = FALSE; | |
135 while ((kwd = nextkwd(fp, buf)) == KEYWORD) { | |
136 for (i = 0; i < NOFIELDS; i++) | |
137 if (strcmp(buf, Parsetab[i].testring) == 0) { | |
138 (*(Parsetab[i].func))(fp, p); | |
139 break; | |
140 } | |
141 if (i == NOFIELDS) | |
142 skiptokwd(fp); | |
143 if (i > PARTFIELDS) | |
144 break; | |
145 } | |
146 if (((parts = obj_to_parts(p->num)) == NULL) && ((unpack == NUM_CHECK) || (p->count > 1))) { | |
147 fclose(fp); | |
148 return(OBJ_UNK); | |
149 } | |
150 if ((unpack == NUM_CHECK) && (parts->int_class & CL_OEU)) { | |
151 fclose(fp); | |
152 return(OBJ_OEU); | |
153 } | |
154 if (parts->int_class & CL_OEU) | |
155 parts = NULL; | |
156 if (!look_ahead) | |
157 while ((kwd = nextkwd(fp, buf)) == PDONE); | |
158 if (kwd == EOF) { | |
159 fclose(fp); | |
160 return(OEH_BAD); | |
161 } | |
162 while (kwd == KEYWORD) { | |
163 if (strcmp(buf, "part-type:") == 0) { | |
164 type = uptokwd(fp); | |
165 kwd = nextkwd(fp, buf); | |
166 } | |
167 else if (strcmp(buf, "encrypted:") == 0) { | |
168 skiptokwd(fp); | |
169 kwd = nextkwd(fp, buf); | |
170 } | |
171 else if (strcmp(buf, "encryption-test:") == 0) { | |
172 encrytest(fp, p); | |
173 kwd = nextkwd(fp, buf); | |
174 } | |
175 else if (strcmp(buf, "part-encoding:") == 0) { | |
176 enc = uptokwd(fp); | |
177 if (strncmp(enc, "ascii", 5) && strncmp(enc, "binary", 6)) { | |
178 fclose(fp); | |
179 return(ENC_BAD); | |
180 } | |
181 kwd = nextkwd(fp, buf); | |
182 } | |
183 else if (strcmp(buf, "encoding-algorithm:") == 0) { | |
184 char *encod; | |
185 | |
186 encod = uptokwd(fp); | |
187 if (strncmp(encod, "btoa", 4) || strncmp(enc, "binary", 6)) { | |
188 fclose(fp); | |
189 return(ENC_BAD); | |
190 } | |
191 kwd = nextkwd(fp, buf); | |
192 } | |
193 else if (strcmp(buf, "part-length:") == 0) { | |
194 length = getnum(fp, SKIP); | |
195 if ((unpack == READ_HEADER) || ((unpack == NUM_CHECK) && p->encrytest)) | |
196 break; | |
197 #ifndef JUSTCHECK | |
198 if (!parts) { | |
199 if (strcmp(enc, "binary") == 0) | |
200 rm_atob(fp, p->file); | |
201 else { | |
202 if ((fp2 = fopen(p->file, "w")) == NULL) { | |
203 warn(NOPEN, p->file); | |
204 fclose(fp); | |
205 return(OEH_BAD); | |
206 }; | |
207 for (i = 0; (i < length) && ((c = getc(fp)) != EOF); i++) | |
208 putc(c, fp2); | |
209 fclose(fp2); | |
210 } | |
211 while ((kwd = nextkwd(fp, buf)) == PDONE); | |
212 continue; | |
213 | |
214 } | |
215 if (parts->numparts > 1) { | |
216 if (type) | |
217 for (apart = opt_next_part(parts), i = 0; | |
218 (i < MAXPARTS) && (strcmp(apart->part_name, type) != 0) &&apart; | |
219 i++, apart = opt_next_part(NULL)); | |
220 if (!type || i == MAXPARTS) { | |
221 fclose(fp); | |
222 return(PART_BAD); | |
223 } | |
224 } | |
225 else | |
226 apart = opt_next_part(parts); | |
227 sprintf(partname, apart->part_template, filename(p->file)); | |
228 strcpy(fullname, p->file); | |
229 strcpy(filename(fullname), partname); | |
230 if ((apart->part_flags & PRT_BIN) || p->encrytest) { | |
231 rm_atob(fp, fullname); | |
232 } | |
233 else { | |
234 if ((fp2 = fopen(fullname, "w")) == NULL) { | |
235 warn(NOPEN, fullname); | |
236 fclose(fp); | |
237 return(OEH_BAD); | |
238 } | |
239 for (i = 0; (i < length) && ((c = getc(fp)) != EOF); i++) | |
240 putc(c, fp2); | |
241 fclose(fp2); | |
242 } | |
243 while ((kwd = nextkwd(fp, buf)) == PDONE); | |
244 #endif /* JUSTCHECK */ | |
245 } | |
246 else { | |
247 skiptokwd(fp); | |
248 kwd = nextkwd(fp, buf); | |
249 } | |
250 } | |
251 fclose(fp); | |
252 return(0); | |
253 } | |
254 static void | |
255 encrytest(fp, p) | |
256 FILE *fp; | |
257 struct oeh *p; | |
258 { | |
259 p->encrytest = uptokwd(fp); | |
260 } | |
261 static int | |
262 obj_num(fp, p) | |
263 FILE *fp; | |
264 struct oeh *p; | |
265 { | |
266 if (skipspace(fp) == KEYWORD) | |
267 p->num = NULL; | |
268 else | |
269 p->num = uptokwd(fp); | |
270 return(KEYWORD); | |
271 } | |
272 static int | |
273 obj_type(fp, p) | |
274 FILE *fp; | |
275 struct oeh *p; | |
276 { | |
277 if (skipspace(fp) == KEYWORD) | |
278 p->name = NULL; | |
279 else | |
280 p->type = uptokwd(fp); | |
281 return(KEYWORD); | |
282 } | |
283 static int | |
284 obj_name(fp, p) | |
285 FILE *fp; | |
286 struct oeh *p; | |
287 { | |
288 if (skipspace(fp) == KEYWORD) | |
289 p->name = NULL; | |
290 else | |
291 p->name = uptokwd(fp); | |
292 return(KEYWORD); | |
293 } | |
294 static int | |
295 par_count(fp, p) | |
296 FILE *fp; | |
297 struct oeh *p; | |
298 { | |
299 p->count = (int) getnum(fp, SKIP); | |
300 return(KEYWORD); | |
301 } |