| 1954 | */ |
| 1955 | |
| 1956 | ssize_t /* O - Number of bytes read */ |
| 1957 | httpRead2(http_t *http, /* I - HTTP connection */ |
| 1958 | char *buffer, /* I - Buffer for data */ |
| 1959 | size_t length) /* I - Maximum number of bytes */ |
| 1960 | { |
| 1961 | ssize_t bytes; /* Bytes read */ |
| 1962 | |
| 1963 | |
| 1964 | #ifdef HAVE_LIBZ |
| 1965 | DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") coding=%d data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http ? http->coding : 0, http ? http->data_encoding : 0, CUPS_LLCAST (http ? http->data_remaining : -1))); |
| 1966 | #else |
| 1967 | DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http ? http->data_encoding : 0, CUPS_LLCAST (http ? http->data_remaining : -1))); |
| 1968 | #endif /* HAVE_LIBZ */ |
| 1969 | |
| 1970 | if (http == NULL || buffer == NULL) |
| 1971 | return (-1); |
| 1972 | |
| 1973 | http->activity = time(NULL); |
| 1974 | http->error = 0; |
| 1975 | |
| 1976 | if (length <= 0) |
| 1977 | return (0); |
| 1978 | |
| 1979 | #ifdef HAVE_LIBZ |
| 1980 | if (http->coding >= _HTTP_CODING_GUNZIP) |
| 1981 | { |
| 1982 | do |
| 1983 | { |
| 1984 | if (((z_stream *)http->stream)->avail_in > 0) |
| 1985 | { |
| 1986 | int zerr; /* Decompressor error */ |
| 1987 | |
| 1988 | DEBUG_printf(("2httpRead2: avail_in=%d, avail_out=%d", |
| 1989 | (int)((z_stream *)http->stream)->avail_in, (int)length)); |
| 1990 | |
| 1991 | ((z_stream *)http->stream)->next_out = (Bytef *)buffer; |
| 1992 | ((z_stream *)http->stream)->avail_out = (uInt)length; |
| 1993 | |
| 1994 | if ((zerr = inflate((z_stream *)http->stream, Z_SYNC_FLUSH)) < Z_OK) |
| 1995 | { |
| 1996 | DEBUG_printf(("2httpRead2: zerr=%d", zerr)); |
| 1997 | #ifdef DEBUG |
| 1998 | http_debug_hex("2httpRead2", (char *)http->sbuffer, (int)((z_stream *)http->stream)->avail_in); |
| 1999 | #endif /* DEBUG */ |
| 2000 | |
| 2001 | http->error = EIO; |
| 2002 | return (-1); |
| 2003 | } |
| 2004 | |
| 2005 | bytes = (ssize_t)(length - ((z_stream *)http->stream)->avail_out); |
| 2006 | |
| 2007 | DEBUG_printf(("2httpRead2: avail_in=%d, avail_out=%d, bytes=%d", |
| 2008 | ((z_stream *)http->stream)->avail_in, ((z_stream *)http->stream)->avail_out, |
| 2009 | (int)bytes)); |
| 2010 | } |
| 2011 | else |
| 2012 | bytes = 0; |
| 2013 | |