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

Function http_read_chunk

cups/http.c:4302–4360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4300 */
4301
4302static ssize_t /* O - Number of bytes read or -1 on error */
4303http_read_chunk(http_t *http, /* I - HTTP connection */
4304 char *buffer, /* I - Buffer */
4305 size_t length) /* I - Maximum bytes to read */
4306{
4307 DEBUG_printf(("7http_read_chunk(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer, CUPS_LLCAST length));
4308
4309 if (http->data_remaining <= 0)
4310 {
4311 char len[32]; /* Length string */
4312
4313 if (!httpGets(len, sizeof(len), http))
4314 {
4315 DEBUG_puts("8http_read_chunk: Could not get chunk length.");
4316 return (0);
4317 }
4318
4319 if (!len[0])
4320 {
4321 DEBUG_puts("8http_read_chunk: Blank chunk length, trying again...");
4322 if (!httpGets(len, sizeof(len), http))
4323 {
4324 DEBUG_puts("8http_read_chunk: Could not get chunk length.");
4325 return (0);
4326 }
4327 }
4328
4329 http->data_remaining = strtoll(len, NULL, 16);
4330
4331 if (http->data_remaining < 0)
4332 {
4333 DEBUG_printf(("8http_read_chunk: Negative chunk length \"%s\" ("
4334 CUPS_LLFMT ")", len, CUPS_LLCAST http->data_remaining));
4335 return (0);
4336 }
4337
4338 DEBUG_printf(("8http_read_chunk: Got chunk length \"%s\" (" CUPS_LLFMT ")",
4339 len, CUPS_LLCAST http->data_remaining));
4340
4341 if (http->data_remaining == 0)
4342 {
4343 /*
4344 * 0-length chunk, grab trailing blank line...
4345 */
4346
4347 httpGets(len, sizeof(len), http);
4348 }
4349 }
4350
4351 DEBUG_printf(("8http_read_chunk: data_remaining=" CUPS_LLFMT,
4352 CUPS_LLCAST http->data_remaining));
4353
4354 if (http->data_remaining <= 0)
4355 return (0);
4356 else if (length > (size_t)http->data_remaining)
4357 length = (size_t)http->data_remaining;
4358
4359 return (http_read_buffered(http, buffer, length));

Callers 1

httpRead2Function · 0.85

Calls 2

httpGetsFunction · 0.85
http_read_bufferedFunction · 0.85

Tested by

no test coverage detected