Skip to content

Commit

Permalink
global: Replaced all i_stream_read_data() with _more() and _bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed May 18, 2016
1 parent d868a04 commit 651f981
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/imap-hibernate/imap-client.c
Expand Up @@ -239,8 +239,8 @@ static void imap_client_input_idle_cmd(struct imap_client *client)

/* we should read either DONE or disconnection. also handle if client
sends DONE\nIDLE simply to recreate the IDLE. */
ret = i_stream_read_data(client->input, &data, &size,
client->next_read_threshold);
ret = i_stream_read_bytes(client->input, &data, &size,
client->next_read_threshold + 1);
if (size == 0) {
if (ret < 0)
imap_client_disconnected(&client);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-compression/compression.c
Expand Up @@ -35,7 +35,7 @@ static bool is_compressed_zlib(struct istream *input)
(based on its header). This also means that users can try to exploit
security holes in the uncompression library by APPENDing a specially
crafted mail. So let's hope zlib is free of holes. */
if (i_stream_read_data(input, &data, &size, 1) <= 0)
if (i_stream_read_bytes(input, &data, &size, 2) <= 0)
return FALSE;
i_assert(size >= 2);

Expand Down
4 changes: 2 additions & 2 deletions src/lib-compression/istream-zlib.c
Expand Up @@ -72,8 +72,8 @@ static int i_stream_zlib_read_header(struct istream_private *stream)
unsigned int pos, fextra_size;
int ret;

ret = i_stream_read_data(stream->parent, &data, &size,
zstream->prev_size);
ret = i_stream_read_bytes(stream->parent, &data, &size,
zstream->prev_size + 1);
if (size == zstream->prev_size) {
stream->istream.stream_errno = stream->parent->stream_errno;
if (ret == -1 && stream->istream.stream_errno == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib-http/http-request-parser.c
Expand Up @@ -282,8 +282,8 @@ static int http_request_parse_request_line(struct http_request_parser *parser,
size_t size, old_bytes = 0;
int ret;

while ((ret = i_stream_read_data(_parser->input, &begin, &size,
old_bytes)) > 0) {
while ((ret = i_stream_read_bytes(_parser->input, &begin, &size,
old_bytes + 1)) > 0) {
_parser->cur = begin;
_parser->end = _parser->cur + size;

Expand Down
4 changes: 2 additions & 2 deletions src/lib-http/http-response-parser.c
Expand Up @@ -233,8 +233,8 @@ http_response_parse_status_line(struct http_response_parser *parser)
size_t size, old_bytes = 0;
int ret;

while ((ret = i_stream_read_data(_parser->input, &begin, &size,
old_bytes)) > 0) {
while ((ret = i_stream_read_bytes(_parser->input, &begin, &size,
old_bytes + 1)) > 0) {
_parser->cur = begin;
_parser->end = _parser->cur + size;

Expand Down
18 changes: 8 additions & 10 deletions src/lib-http/test-http-payload.c
Expand Up @@ -634,17 +634,16 @@ test_client_download_payload_input(struct test_client_request *tcreq)
off_t ret;

/* read payload */
while ((ret=i_stream_read_data
(payload, &pdata, &psize, 0)) > 0) {
while ((ret=i_stream_read_more(payload, &pdata, &psize)) > 0) {
if (debug) {
i_debug("test client: download: "
"got data for [%u] (size=%d)",
tcreq->files_idx, (int)psize);
}
/* compare with file on disk */
pleft = psize;
while ((ret=i_stream_read_data
(tcreq->file, &fdata, &fsize, 0)) > 0 && pleft > 0) {
while ((ret=i_stream_read_more
(tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
fsize = (fsize > pleft ? pleft : fsize);
if (memcmp(pdata, fdata, fsize) != 0) {
i_fatal("test client: download: "
Expand Down Expand Up @@ -677,7 +676,7 @@ test_client_download_payload_input(struct test_client_request *tcreq)
"failed to read request payload: %s",
i_stream_get_error(payload));
} if (i_stream_have_bytes_left(tcreq->file)) {
if (i_stream_read_data(tcreq->file, &fdata, &fsize, 0) <= 0)
if (i_stream_read_more(tcreq->file, &fdata, &fsize) <= 0)
fsize = 0;
i_fatal("test client: download: "
"payload ended prematurely "
Expand Down Expand Up @@ -863,17 +862,16 @@ test_client_echo_payload_input(struct test_client_request *tcreq)
off_t ret;

/* read payload */
while ((ret=i_stream_read_data
(payload, &pdata, &psize, 0)) > 0) {
while ((ret=i_stream_read_more(payload, &pdata, &psize)) > 0) {
if (debug) {
i_debug("test client: echo: "
"got data for [%u] (size=%d)",
tcreq->files_idx, (int)psize);
}
/* compare with file on disk */
pleft = psize;
while ((ret=i_stream_read_data
(tcreq->file, &fdata, &fsize, 0)) > 0 && pleft > 0) {
while ((ret=i_stream_read_more
(tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
fsize = (fsize > pleft ? pleft : fsize);
if (memcmp(pdata, fdata, fsize) != 0) {
i_fatal("test client: echo: "
Expand Down Expand Up @@ -906,7 +904,7 @@ test_client_echo_payload_input(struct test_client_request *tcreq)
"failed to read request payload: %s",
i_stream_get_error(payload));
} if (i_stream_have_bytes_left(tcreq->file)) {
if (i_stream_read_data(tcreq->file, &fdata, &fsize, 0) <= 0)
if (i_stream_read_more(tcreq->file, &fdata, &fsize) <= 0)
fsize = 0;
i_fatal("test client: echo: "
"payload ended prematurely "
Expand Down
2 changes: 1 addition & 1 deletion src/lib-mail/message-header-parser.c
Expand Up @@ -79,7 +79,7 @@ int message_parse_header_next(struct message_header_parser_ctx *ctx,
continues = FALSE;

for (startpos = 0;;) {
ret = i_stream_read_data(ctx->input, &msg, &size, startpos+1);
ret = i_stream_read_bytes(ctx->input, &msg, &size, startpos+2);
if (ret >= 0) {
/* we want to know one byte in advance to find out
if it's multiline header */
Expand Down
4 changes: 2 additions & 2 deletions src/lib-mail/message-parser.c
Expand Up @@ -133,8 +133,8 @@ static int message_parser_read_more(struct message_parser_ctx *ctx,
}

*full_r = FALSE;
ret = i_stream_read_data(ctx->input, &block_r->data,
&block_r->size, ctx->want_count);
ret = i_stream_read_bytes(ctx->input, &block_r->data,
&block_r->size, ctx->want_count + 1);
if (ret <= 0) {
switch (ret) {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions src/lib-mail/message-size.c
Expand Up @@ -16,7 +16,7 @@ int message_get_header_size(struct istream *input, struct message_size *hdr,
*has_nuls_r = FALSE;

missing_cr_count = 0; startpos = 0;
while (i_stream_read_data(input, &msg, &size, startpos) > 0) {
while (i_stream_read_bytes(input, &msg, &size, startpos + 1) > 0) {
for (i = startpos; i < size; i++) {
if (msg[i] != '\n') {
if (msg[i] == '\0')
Expand Down Expand Up @@ -102,7 +102,7 @@ int message_get_body_size(struct istream *input, struct message_size *body,
/* leave the last character, it may be \r */
i_stream_skip(input, i - 1);
body->physical_size += i - 1;
} while (i_stream_read_data(input, &msg, &size, 1) > 0);
} while (i_stream_read_bytes(input, &msg, &size, 2) > 0);

ret = input->stream_errno != 0 ? -1 : 0;

Expand Down
6 changes: 3 additions & 3 deletions src/lib-storage/index/mbox/istream-raw-mbox.c
Expand Up @@ -464,7 +464,7 @@ static int istream_raw_mbox_is_valid_from(struct raw_mbox_istream *rstream)
int tz;

/* minimal: "From x Thu Nov 29 22:33:52 2001" = 31 chars */
(void)i_stream_read_data(rstream->istream.parent, &data, &size, 30);
(void)i_stream_read_bytes(rstream->istream.parent, &data, &size, 31);

if ((size == 1 && data[0] == '\n') ||
(size == 2 && data[0] == '\r' && data[1] == '\n')) {
Expand All @@ -483,8 +483,8 @@ static int istream_raw_mbox_is_valid_from(struct raw_mbox_istream *rstream)
}

while (memchr(data, '\n', size) == NULL) {
if (i_stream_read_data(rstream->istream.parent,
&data, &size, size) < 0)
if (i_stream_read_bytes(rstream->istream.parent,
&data, &size, size+1) < 0)
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/login-common/login-proxy.c
Expand Up @@ -168,7 +168,7 @@ static void proxy_client_input(struct login_proxy *proxy)
return;
}

if (i_stream_read_data(proxy->client_input, &data, &size, 0) < 0) {
if (i_stream_read_more(proxy->client_input, &data, &size) < 0) {
const char *errstr = i_stream_get_error(proxy->client_input);
login_proxy_free_errstr(&proxy, errstr, FALSE);
return;
Expand Down

0 comments on commit 651f981

Please sign in to comment.