istream-base64-encoder.c revision 032964c7cc6788188b63ae6270fc26cbd4a3ca26
/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "base64.h"
#include "istream-private.h"
#include "istream-base64-encoder.h"
struct base64_encoder_istream {
struct istream_private istream;
/* current encoded line length. */
unsigned int cur_line_len;
unsigned int chars_per_line;
bool crlf;
};
{
if (size >= 4)
return 1;
/* we have less than one base64 block.
see if there is more data available. */
if (ret <= 0) {
}
return 1;
}
static bool
{
const unsigned char *data;
if (size == 0)
return FALSE;
/* @UNSAFE: end of line, add newline */
return FALSE;
bstream->cur_line_len = 0;
}
/* can't fit everything to destination buffer.
write as much as we can. */
/* encode 3 chars at a time, so base64_encode() doesn't
add '=' characters in the middle of the stream */
}
if (size == 0)
return FALSE;
}
return TRUE;
}
{
struct base64_encoder_istream *bstream =
(struct base64_encoder_istream *)stream;
int ret;
do {
if (ret <= 0)
return ret;
/* encode as many lines as fits into destination buffer */
while (i_stream_base64_try_encode_line(bstream)) ;
if (pre_count == post_count) {
return -2;
}
return post_count - pre_count;
}
static const struct stat *
{
if (exact) {
/* too much trouble to implement until it's actually needed */
i_panic("istream-base64-encoder: "
"stat() doesn't support getting exact size");
}
}
static void
{
struct base64_encoder_istream *bstream =
(struct base64_encoder_istream *)stream;
/* seeking backwards - go back to beginning and seek
forward from there. */
bstream->cur_line_len = 0;
}
}
struct istream *
unsigned int chars_per_line, bool crlf)
{
struct base64_encoder_istream *bstream;
}