*
* HTTP routines for CUPS.
*
- * Copyright 2007-2013 by Apple Inc.
+ * Copyright 2007-2014 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* This file contains Kerberos support code, copyright 2006 by
int /* O - Bytes written or -1 on error */
httpFlushWrite(http_t *http) /* I - HTTP connection */
{
- int bytes; /* Bytes written */
+ ssize_t bytes; /* Bytes written */
DEBUG_printf(("httpFlushWrite(http=%p) data_encoding=%d", http,
- http ? http->data_encoding : -1));
+ http ? http->data_encoding : 100));
if (!http || !http->wused)
{
}
if (http->data_encoding == HTTP_ENCODING_CHUNKED)
- bytes = http_write_chunk(http, http->wbuffer, http->wused);
+ bytes = http_write_chunk(http, http->wbuffer, (size_t)http->wused);
else
- bytes = http_write(http, http->wbuffer, http->wused);
+ bytes = http_write(http, http->wbuffer, (size_t)http->wused);
http->wused = 0;
- DEBUG_printf(("1httpFlushWrite: Returning %d, errno=%d.", bytes, errno));
+ DEBUG_printf(("1httpFlushWrite: Returning %d, errno=%d.", (int)bytes, errno));
- return (bytes);
+ return ((int)bytes);
}
size_t /* O - Number of bytes buffered */
httpGetPending(http_t *http) /* I - HTTP connection */
{
- return (http ? http->wused : 0);
+ return (http ? (size_t)http->wused : 0);
}
if (!http)
return (0);
else if (http->used > 0)
- return (http->used);
+ return ((size_t)http->used);
#ifdef HAVE_SSL
else if (http->tls)
return (http_tls_pending(http));
size_t /* O - Remaining bytes */
httpGetRemaining(http_t *http) /* I - HTTP connection */
{
- return (http ? http->data_remaining : 0);
+ return (http ? (size_t)http->data_remaining : 0);
}
int length, /* I - Max length of buffer */
http_t *http) /* I - HTTP connection */
{
- char *lineptr, /* Pointer into line */
- *lineend, /* End of line */
- *bufptr, /* Pointer into input buffer */
- *bufend; /* Pointer to end of buffer */
- int bytes, /* Number of bytes read */
- eol; /* End-of-line? */
+ char *lineptr, /* Pointer into line */
+ *lineend, /* End of line */
+ *bufptr, /* Pointer into input buffer */
+ *bufend; /* Pointer to end of buffer */
+ ssize_t bytes; /* Number of bytes read */
+ int eol; /* End-of-line? */
DEBUG_printf(("2httpGets(line=%p, length=%d, http=%p)", line, length, http));
return (NULL);
}
- bytes = http_read(http, http->buffer + http->used,
- HTTP_MAX_BUFFER - http->used);
+ bytes = http_read(http, http->buffer + http->used, (size_t)(HTTP_MAX_BUFFER - http->used));
- DEBUG_printf(("4httpGets: read %d bytes.", bytes));
+ DEBUG_printf(("4httpGets: read " CUPS_LLFMT " bytes.", CUPS_LLCAST bytes));
if (bytes < 0)
{
* Yup, update the amount used...
*/
- http->used += bytes;
+ http->used += (int)bytes;
}
/*
}
}
- if (http->data_remaining > sizeof(http->buffer))
+ if ((size_t)http->data_remaining > sizeof(http->buffer))
buflen = sizeof(http->buffer);
else
- buflen = http->data_remaining;
+ buflen = (ssize_t)http->data_remaining;
DEBUG_printf(("2httpPeek: Reading %d bytes into buffer.", (int)buflen));
- bytes = http_read(http, http->buffer, buflen);
+ bytes = http_read(http, http->buffer, (size_t)buflen);
DEBUG_printf(("2httpPeek: Read " CUPS_LLFMT " bytes into buffer.",
CUPS_LLCAST bytes));
http_debug_hex("httpPeek", http->buffer, (int)bytes);
#endif /* DEBUG */
- http->used = bytes;
+ http->used = (int)bytes;
}
}
http->stream.next_in = http->dbuffer;
- if (buflen > http->data_remaining)
- buflen = http->data_remaining;
+ if (buflen > (size_t)http->data_remaining)
+ buflen = (size_t)http->data_remaining;
- if (buflen > http->used)
- buflen = http->used;
+ if (buflen > (size_t)http->used)
+ buflen = (size_t)http->used;
DEBUG_printf(("1httpPeek: Copying %d more bytes of data into "
"decompression buffer.", (int)buflen));
}
stream.next_out = (Bytef *)buffer;
- stream.avail_out = length;
+ stream.avail_out = (uInt)length;
zerr = inflate(&stream, Z_SYNC_FLUSH);
inflateEnd(&stream);
{
DEBUG_printf(("2httpPeek: zerr=%d", zerr));
#ifdef DEBUG
- http_debug_hex("2httpPeek", (char *)http->dbuffer,
- http->stream.avail_in);
+ http_debug_hex("2httpPeek", (char *)http->dbuffer, (int)http->stream.avail_in);
#endif /* DEBUG */
http->error = EIO;
return (-1);
}
- bytes = length - http->stream.avail_out;
+ bytes = (ssize_t)(length - http->stream.avail_out);
# else
DEBUG_puts("2httpPeek: No inflateCopy on this platform, httpPeek does not "
const char *format, /* I - printf-style format string */
...) /* I - Additional args as needed */
{
- int bytes; /* Number of bytes to write */
+ ssize_t bytes; /* Number of bytes to write */
char buf[16384]; /* Buffer for formatted string */
va_list ap; /* Variable argument pointer */
bytes = vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap);
- DEBUG_printf(("3httpPrintf: (%d bytes) %s", bytes, buf));
+ DEBUG_printf(("3httpPrintf: (" CUPS_LLFMT " bytes) %s", CUPS_LLCAST bytes, buf));
if (http->data_encoding == HTTP_ENCODING_FIELDS)
- return (httpWrite2(http, buf, bytes));
+ return ((int)httpWrite2(http, buf, (size_t)bytes));
else
{
if (http->wused)
return (-1);
}
- return (http_write(http, buf, bytes));
+ return ((int)http_write(http, buf, (size_t)bytes));
}
}
char *buffer, /* I - Buffer for data */
int length) /* I - Maximum number of bytes */
{
- return ((int)httpRead2(http, buffer, length));
+ return ((int)httpRead2(http, buffer, (size_t)length));
}
(int)http->stream.avail_in, (int)length));
http->stream.next_out = (Bytef *)buffer;
- http->stream.avail_out = length;
+ http->stream.avail_out = (uInt)length;
if ((zerr = inflate(&(http->stream), Z_SYNC_FLUSH)) < Z_OK)
{
DEBUG_printf(("2httpRead2: zerr=%d", zerr));
#ifdef DEBUG
- http_debug_hex("2httpRead2", (char *)http->dbuffer,
- http->stream.avail_in);
+ http_debug_hex("2httpRead2", (char *)http->dbuffer, (int)http->stream.avail_in);
#endif /* DEBUG */
http->error = EIO;
return (-1);
}
- bytes = length - http->stream.avail_out;
+ bytes = (ssize_t)(length - http->stream.avail_out);
DEBUG_printf(("2httpRead2: avail_in=%d, avail_out=%d, bytes=%d",
http->stream.avail_in, http->stream.avail_out,
if (bytes == 0)
{
- ssize_t buflen = HTTP_MAX_BUFFER - http->stream.avail_in;
+ ssize_t buflen = HTTP_MAX_BUFFER - (ssize_t)http->stream.avail_in;
/* Additional bytes for buffer */
if (buflen > 0)
if (http->data_remaining > 0)
{
if (buflen > http->data_remaining)
- buflen = http->data_remaining;
+ buflen = (ssize_t)http->data_remaining;
- bytes = http_read_buffered(http,
- (char *)http->dbuffer +
- http->stream.avail_in, buflen);
+ bytes = http_read_buffered(http, (char *)http->dbuffer + http->stream.avail_in, (size_t)buflen);
}
else if (http->data_encoding == HTTP_ENCODING_CHUNKED)
- bytes = http_read_chunk(http,
- (char *)http->dbuffer +
- http->stream.avail_in, buflen);
+ bytes = http_read_chunk(http, (char *)http->dbuffer + http->stream.avail_in, (size_t)buflen);
else
bytes = 0;
"decompression buffer.", CUPS_LLCAST bytes));
http->data_remaining -= bytes;
- http->stream.avail_in += bytes;
+ http->stream.avail_in += (uInt)bytes;
if (http->data_remaining <= 0 &&
http->data_encoding == HTTP_ENCODING_CHUNKED)
* Set the current authorization string...
*/
- int len = (int)strlen(scheme) + (data ? (int)strlen(data) + 1 : 0) + 1;
+ size_t len = strlen(scheme) + (data ? strlen(data) + 1 : 0) + 1;
char *temp;
- if (len > (int)sizeof(http->_authstring))
+ if (len > sizeof(http->_authstring))
{
if ((temp = malloc(len)) == NULL)
len = sizeof(http->_authstring);
const char *buffer, /* I - Buffer for data */
int length) /* I - Number of bytes to write */
{
- return ((int)httpWrite2(http, buffer, length));
+ return ((int)httpWrite2(http, buffer, (size_t)length));
}
else
{
http->stream.next_in = (Bytef *)buffer;
- http->stream.avail_in = length;
+ http->stream.avail_in = (uInt)length;
http->stream.next_out = (Bytef *)http->wbuffer + http->wused;
- http->stream.avail_out = sizeof(http->wbuffer) - http->wused;
+ http->stream.avail_out = (uInt)(sizeof(http->wbuffer) - (size_t)http->wused);
while (deflate(&(http->stream), Z_NO_FLUSH) == Z_OK)
{
- http->wused = sizeof(http->wbuffer) - http->stream.avail_out;
+ http->wused = (int)(sizeof(http->wbuffer) - (size_t)http->stream.avail_out);
if (http->stream.avail_out == 0)
{
}
}
- http->wused = sizeof(http->wbuffer) - http->stream.avail_out;
- bytes = length;
+ http->wused = (int)(sizeof(http->wbuffer) - (size_t)http->stream.avail_out);
+ bytes = (ssize_t)length;
}
}
else
#endif /* HAVE_LIBZ */
if (length > 0)
{
- if (http->wused && (length + http->wused) > sizeof(http->wbuffer))
+ if (http->wused && (length + (size_t)http->wused) > sizeof(http->wbuffer))
{
DEBUG_printf(("2httpWrite2: Flushing buffer (wused=%d, length="
CUPS_LLFMT ")", http->wused, CUPS_LLCAST length));
httpFlushWrite(http);
}
- if ((length + http->wused) <= sizeof(http->wbuffer) &&
- length < sizeof(http->wbuffer))
+ if ((length + (size_t)http->wused) <= sizeof(http->wbuffer) && length < sizeof(http->wbuffer))
{
/*
* Write to buffer...
CUPS_LLCAST length));
if (http->data_encoding == HTTP_ENCODING_CHUNKED)
- bytes = (ssize_t)http_write_chunk(http, buffer, (int)length);
+ bytes = (ssize_t)http_write_chunk(http, buffer, length);
else
- bytes = (ssize_t)http_write(http, buffer, (int)length);
+ bytes = (ssize_t)http_write(http, buffer, length);
DEBUG_printf(("2httpWrite2: Wrote " CUPS_LLFMT " bytes...",
CUPS_LLCAST bytes));
do
{
http->stream.next_out = (Bytef *)http->wbuffer + http->wused;
- http->stream.avail_out = sizeof(http->wbuffer) - http->wused;
+ http->stream.avail_out = (uInt)(sizeof(http->wbuffer) - (size_t)http->wused);
zerr = deflate(&(http->stream), Z_FINISH);
- http->wused = sizeof(http->wbuffer) - http->stream.avail_out;
+ http->wused = (int)(sizeof(http->wbuffer) - (size_t)http->stream.avail_out);
if (http->wused == sizeof(http->wbuffer))
httpFlushWrite(http);
}
if (ch < ' ' || ch >= 127)
ch = '.';
- *ptr++ = ch;
+ *ptr++ = (char)ch;
}
*ptr = '\0';
{
#ifdef HAVE_SSL
if (http->tls)
- bytes = http_tls_read(http, buffer, length);
+ bytes = http_tls_read(http, buffer, (int)length);
else
#endif /* HAVE_SSL */
bytes = recv(http->fd, buffer, length, 0);
if (http->used > 0)
{
if (length > (size_t)http->used)
- bytes = (size_t)http->used;
+ bytes = (ssize_t)http->used;
else
- bytes = length;
+ bytes = (ssize_t)length;
DEBUG_printf(("2http_read: Grabbing %d bytes from input buffer.",
(int)bytes));
http->data_remaining = remaining;
if (remaining <= INT_MAX)
- http->_data_remaining = remaining;
+ http->_data_remaining = (int)remaining;
else
http->_data_remaining = INT_MAX;
}
#ifdef HAVE_SSL
if (http->tls)
- bytes = http_tls_write(http, buffer, length);
+ bytes = http_tls_write(http, buffer, (int)length);
else
#endif /* HAVE_SSL */
bytes = send(http->fd, buffer, length, 0);
buffer += bytes;
tbytes += bytes;
- length -= bytes;
+ length -= (size_t)bytes;
}
#ifdef DEBUG
- http_debug_hex("http_write", buffer - tbytes, tbytes);
+ http_debug_hex("http_write", buffer - tbytes, (int)tbytes);
#endif /* DEBUG */
DEBUG_printf(("3http_write: Returning " CUPS_LLFMT ".", CUPS_LLCAST tbytes));