]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
2 | * "$Id: gziptoany.c 4494 2005-02-18 02:18:11Z mike $" | |
3 | * | |
4 | * GZIP pre-filter for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1993-2005 by Easy Software Products. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * This file is subject to the Apple OS-Developed Software exception. | |
25 | * | |
26 | * Contents: | |
27 | * | |
28 | * main() - Uncompress gzip'd files and send them to stdout... | |
29 | */ | |
30 | ||
31 | /* | |
32 | * Include necessary headers... | |
33 | */ | |
34 | ||
35 | #include <cups/string.h> | |
36 | #include <stdlib.h> | |
37 | #include <errno.h> | |
38 | ||
39 | #ifdef HAVE_LIBZ | |
40 | # include <zlib.h> | |
41 | #endif /* HAVE_LIBZ */ | |
42 | ||
43 | ||
44 | /* | |
45 | * 'main()' - Uncompress gzip'd files and send them to stdout... | |
46 | */ | |
47 | ||
48 | int /* O - Exit status */ | |
49 | main(int argc, /* I - Number of command-line arguments */ | |
50 | char *argv[]) /* I - Command-line arguments */ | |
51 | { | |
52 | #ifdef HAVE_LIBZ | |
53 | gzFile fp; /* GZIP'd file */ | |
54 | char buffer[8192]; /* Data buffer */ | |
55 | int bytes; /* Number of bytes read/written */ | |
56 | int copies; /* Number of copies */ | |
57 | const char *content_type; /* Content type for file... */ | |
58 | ||
59 | ||
60 | /* | |
61 | * Check command-line... | |
62 | */ | |
63 | ||
64 | if (argc != 7) | |
65 | { | |
66 | fputs("ERROR: gziptoany job-id user title copies options file\n", stderr); | |
67 | return (1); | |
68 | } | |
69 | ||
70 | /* | |
71 | * Get the copy count; if the MIME type is "application/vnd.cups-raw" then | |
72 | * make copies since the file is going straight to a backend... | |
73 | */ | |
74 | ||
75 | if ((content_type = getenv("CONTENT_TYPE")) != NULL && | |
76 | !strcasecmp(content_type, "application/vnd.cups-raw")) | |
77 | copies = atoi(argv[4]); | |
78 | else | |
79 | copies = 1; | |
80 | ||
81 | /* | |
82 | * Open the gzip file... | |
83 | */ | |
84 | ||
85 | if ((fp = gzopen(argv[6], "rb")) == NULL) | |
86 | { | |
87 | fprintf(stderr, "ERROR: Unable to open GZIP file: %s\n", strerror(errno)); | |
88 | return (1); | |
89 | } | |
90 | ||
91 | /* | |
92 | * Copy the gzip file to stdout... | |
93 | */ | |
94 | ||
95 | setbuf(stdout, NULL); | |
96 | ||
97 | while (copies > 0) | |
98 | { | |
99 | gzrewind(fp); | |
100 | ||
101 | while ((bytes = gzread(fp, buffer, sizeof(buffer))) > 0) | |
102 | if (fwrite(buffer, 1, bytes, stdout) < bytes) | |
103 | { | |
104 | fprintf(stderr, "ERROR: Unable to write uncompressed document data: %s\n", | |
105 | strerror(ferror(stdout))); | |
106 | gzclose(fp); | |
107 | ||
108 | return (1); | |
109 | } | |
110 | ||
111 | copies --; | |
112 | } | |
113 | ||
114 | /* | |
115 | * Close the file and return... | |
116 | */ | |
117 | ||
118 | gzclose(fp); | |
119 | ||
120 | return (0); | |
121 | #else | |
122 | fputs("INFO: Hint: recompile CUPS with ZLIB.\n", stderr); | |
123 | fputs("ERROR: GZIP compression support not compiled in!\n", stderr); | |
124 | return (1); | |
125 | #endif /* HAVE_LIBZ */ | |
126 | } | |
127 | ||
128 | ||
129 | /* | |
130 | * End of "$Id: gziptoany.c 4494 2005-02-18 02:18:11Z mike $". | |
131 | */ |