MCPcopy Create free account
hub / github.com/OpenPrinting/cups / ppdxWriteData

Function ppdxWriteData

examples/ppdx.c:180–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178 */
179
180extern void
181ppdxWriteData(const char *name, /* I - Base name of keyword */
182 const void *data, /* I - Data to write */
183 size_t datasize) /* I - Number of bytes in data */
184{
185 char buffer[PPDX_MAX_CHUNK], /* Chunk buffer */
186 encoded[PPDX_MAX_VALUE + 1],
187 /* Encoded data */
188 pair[PPD_MAX_LINE], /* name=value pair */
189 line[PPDX_MAX_STATUS], /* Line buffer */
190 *lineptr, /* Current position in line buffer */
191 *lineend; /* End of line buffer */
192 unsigned chunk = 0; /* Current chunk number */
193 int len; /* Length of current chunk */
194 z_stream comp; /* Compressor stream */
195 int error; /* Error/status from deflate() */
196
197
198 /*
199 * Range check input...
200 */
201
202 if (!name || (!data && datasize > 0) || datasize > PPDX_MAX_DATA)
203 return;
204
205 strlcpy(line, "PPD:", sizeof(line));
206 lineptr = line + 4;
207 lineend = line + sizeof(line) - 2;
208
209 if (datasize > 0)
210 {
211 /*
212 * Compress and encode output...
213 */
214
215 memset(&comp, 0, sizeof(comp));
216 comp.next_in = (Bytef *)data;
217 comp.avail_in = datasize;
218
219 deflateInit(&comp, 9);
220
221 do
222 {
223 /*
224 * Compress a chunk...
225 */
226
227 comp.next_out = buffer;
228 comp.avail_out = sizeof(buffer);
229
230 if ((error = deflate(&comp, Z_FINISH)) < Z_OK)
231 {
232 fprintf(stderr, "ERROR: deflate returned %d (%s)\n", error, comp.msg);
233 break;
234 }
235
236 /*
237 * Write a chunk...

Callers 1

mainFunction · 0.85

Calls 1

httpEncode64_2Function · 0.85

Tested by 1

mainFunction · 0.68