本文整理汇总了C++中i_stream_skip函数的典型用法代码示例。如果您正苦于以下问题:C++ i_stream_skip函数的具体用法?C++ i_stream_skip怎么用?C++ i_stream_skip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i_stream_skip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_compress_file
static void test_compress_file(const char *in_path, const char *out_path)
{
const struct compression_handler *handler;
struct istream *input, *file_input;
struct ostream *output, *file_output;
int fd_in, fd_out;
struct sha1_ctxt sha1;
unsigned char output_sha1[SHA1_RESULTLEN], input_sha1[SHA1_RESULTLEN];
const unsigned char *data;
size_t size;
ssize_t ret;
handler = compression_lookup_handler_from_ext(out_path);
if (handler == NULL)
i_fatal("Can't detect compression algorithm from path %s", out_path);
if (handler->create_ostream == NULL)
i_fatal("Support not compiled in for %s", handler->name);
/* write the compressed output file */
fd_in = open(in_path, O_RDONLY);
if (fd_in == -1)
i_fatal("open(%s) failed: %m", in_path);
fd_out = open(out_path, O_TRUNC | O_CREAT | O_RDWR, 0600);
if (fd_out == -1)
i_fatal("creat(%s) failed: %m", out_path);
sha1_init(&sha1);
file_output = o_stream_create_fd_file(fd_out, 0, FALSE);
output = handler->create_ostream(file_output, 1);
input = i_stream_create_fd_autoclose(&fd_in, IO_BLOCK_SIZE);
while (i_stream_read_data(input, &data, &size, 0) > 0) {
sha1_loop(&sha1, data, size);
o_stream_nsend(output, data, size);
i_stream_skip(input, size);
}
if (o_stream_nfinish(output) < 0) {
i_fatal("write(%s) failed: %s",
out_path, o_stream_get_error(output));
}
i_stream_destroy(&input);
o_stream_destroy(&output);
o_stream_destroy(&file_output);
sha1_result(&sha1, output_sha1);
/* verify that we can read the compressed file */
sha1_init(&sha1);
file_input = i_stream_create_fd(fd_out, IO_BLOCK_SIZE, FALSE);
input = handler->create_istream(file_input, FALSE);
while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
sha1_loop(&sha1, data, size);
i_stream_skip(input, size);
}
i_stream_destroy(&input);
i_stream_destroy(&file_input);
sha1_result(&sha1, input_sha1);
if (memcmp(input_sha1, output_sha1, sizeof(input_sha1)) != 0)
i_fatal("Decompression couldn't get the original input");
i_close_fd(&fd_out);
}
示例2: i_stream_default_seek_nonseekable
void i_stream_default_seek_nonseekable(struct istream_private *stream,
uoff_t v_offset, bool mark ATTR_UNUSED)
{
size_t available;
if (stream->istream.v_offset > v_offset)
i_panic("stream %s doesn't support seeking backwards",
i_stream_get_name(&stream->istream));
while (stream->istream.v_offset < v_offset) {
(void)i_stream_read(&stream->istream);
available = stream->pos - stream->skip;
if (available == 0) {
if (stream->istream.stream_errno != 0) {
/* read failed */
return;
}
io_stream_set_error(&stream->iostream,
"Can't seek to offset %"PRIuUOFF_T
", because we have data only up to offset %"
PRIuUOFF_T" (eof=%d)", v_offset,
stream->istream.v_offset, stream->istream.eof ? 1 : 0);
stream->istream.stream_errno = ESPIPE;
return;
}
if (available <= v_offset - stream->istream.v_offset)
i_stream_skip(&stream->istream, available);
else {
i_stream_skip(&stream->istream,
v_offset - stream->istream.v_offset);
}
}
}
示例3: test_istream_base64_encoder_seek
static void
test_istream_base64_encoder_seek(const char *textin, const char *textout)
{
unsigned int offset, len = strlen(textout);
struct istream *input, *input_data;
const unsigned char *data;
size_t size;
ssize_t ret;
input_data = i_stream_create_from_data(textin, strlen(textin));
input = i_stream_create_base64_encoder(input_data, 4, TRUE);
while (i_stream_read(input) > 0) ;
i_stream_skip(input, i_stream_get_data_size(input));
for (offset = 0; offset < len; offset++) {
i_stream_seek(input, offset);
while ((ret = i_stream_read(input)) > 0) ;
test_assert(ret == -1);
data = i_stream_get_data(input, &size);
test_assert(size == len-offset);
test_assert(memcmp(data, textout+offset, size) == 0);
i_stream_skip(input, size);
}
i_stream_unref(&input);
i_stream_unref(&input_data);
}
示例4: message_get_header_size
int message_get_header_size(struct istream *input, struct message_size *hdr,
bool *has_nuls_r)
{
const unsigned char *msg;
size_t i, size, startpos, missing_cr_count;
int ret;
memset(hdr, 0, sizeof(struct message_size));
*has_nuls_r = FALSE;
missing_cr_count = 0; startpos = 0;
while ((ret = i_stream_read_bytes(input, &msg, &size, startpos + 1)) > 0) {
for (i = startpos; i < size; i++) {
if (msg[i] != '\n') {
if (msg[i] == '\0')
*has_nuls_r = TRUE;
continue;
}
hdr->lines++;
if (i == 0 || msg[i-1] != '\r') {
/* missing CR */
missing_cr_count++;
}
if (i == 0 || (i == 1 && msg[i-1] == '\r')) {
/* no headers at all */
break;
}
if ((i > 0 && msg[i-1] == '\n') ||
(i > 1 && msg[i-2] == '\n' && msg[i-1] == '\r')) {
/* \n\n or \n\r\n - end of headers */
break;
}
}
if (i < size) {
/* end of header */
startpos = i+1;
break;
}
/* leave the last two characters, they may be \r\n */
startpos = size == 1 ? 1 : 2;
i_stream_skip(input, i - startpos);
hdr->physical_size += i - startpos;
}
i_assert(ret == -1 || ret > 0);
ret = input->stream_errno != 0 ? -1 : 0;
i_stream_skip(input, startpos);
hdr->physical_size += startpos;
hdr->virtual_size = hdr->physical_size + missing_cr_count;
i_assert(hdr->virtual_size >= hdr->physical_size);
return ret;
}
示例5: i_stream_zlib_seek
static void
i_stream_zlib_seek(struct istream_private *stream, uoff_t v_offset, bool mark)
{
struct zlib_istream *zstream = (struct zlib_istream *) stream;
uoff_t start_offset = stream->istream.v_offset - stream->skip;
if (v_offset < start_offset) {
/* have to seek backwards */
i_stream_zlib_reset(zstream);
start_offset = 0;
} else if (zstream->high_pos != 0) {
stream->pos = zstream->high_pos;
zstream->high_pos = 0;
}
if (v_offset <= start_offset + stream->pos) {
/* seeking backwards within what's already cached */
stream->skip = v_offset - start_offset;
stream->istream.v_offset = v_offset;
zstream->high_pos = stream->pos;
stream->pos = stream->skip;
} else {
/* read and cache forward */
ssize_t ret;
do {
size_t avail = stream->pos - stream->skip;
if (stream->istream.v_offset + avail >= v_offset) {
i_stream_skip(&stream->istream,
v_offset -
stream->istream.v_offset);
ret = -1;
break;
}
i_stream_skip(&stream->istream, avail);
} while ((ret = i_stream_read(&stream->istream)) > 0);
i_assert(ret == -1);
if (stream->istream.v_offset != v_offset) {
/* some failure, we've broken it */
if (stream->istream.stream_errno != 0) {
i_error("zlib_istream.seek(%s) failed: %s",
i_stream_get_name(&stream->istream),
strerror(stream->istream.stream_errno));
i_stream_close(&stream->istream);
} else {
/* unexpected EOF. allow it since we may just
want to check if there's anything.. */
i_assert(stream->istream.eof);
}
}
}
if (mark)
zstream->marked = TRUE;
}
示例6: managesieve_parser_read_literal_data
static int managesieve_parser_read_literal_data(struct managesieve_parser *parser,
const unsigned char *data,
size_t data_size)
{
if (parser->literal_skip_crlf) {
/* skip \r\n or \n, anything else gives an error */
if (data_size == 0)
return FALSE;
if (*data == '\r') {
parser->line_size++;
data++; data_size--;
i_stream_skip(parser->input, 1);
if (data_size == 0)
return FALSE;
}
if (*data != '\n') {
parser->error = "Missing LF after literal size";
return FALSE;
}
parser->line_size++;
data++; data_size--;
i_stream_skip(parser->input, 1);
parser->literal_skip_crlf = FALSE;
i_assert(parser->cur_pos == 0);
}
if ((parser->flags & MANAGESIEVE_PARSE_FLAG_STRING_STREAM) == 0) {
/* now we just wait until we've read enough data */
if (data_size < parser->literal_size) {
return FALSE;
} else {
if ( !uni_utf8_data_is_valid
(data, (size_t)parser->literal_size) ) {
parser->error = "Invalid UTF-8 character in literal string.";
return FALSE;
}
managesieve_parser_save_arg(parser, data,
(size_t)parser->literal_size);
parser->cur_pos = (size_t)parser->literal_size;
return TRUE;
}
} else {
/* we don't read the data; we just create a stream for the literal */
parser->eol = TRUE;
parser->str_stream = i_stream_create_limit
(parser->input, parser->literal_size);
managesieve_parser_save_arg(parser, NULL, 0);
return TRUE;
}
}
示例7: test_istream_children
static void test_istream_children(void)
{
struct istream *parent, *child1, *child2;
const unsigned char *data;
size_t size;
test_begin("istream children");
parent = test_istream_create_data("123456789", 9);
test_istream_set_max_buffer_size(parent, 3);
child1 = i_stream_create_limit(parent, (uoff_t)-1);
child2 = i_stream_create_limit(parent, (uoff_t)-1);
/* child1 read beginning */
test_assert(i_stream_read(child1) == 3);
data = i_stream_get_data(child1, &size);
test_assert(size == 3 && memcmp(data, "123", 3) == 0);
i_stream_skip(child1, 3);
/* child1 read middle.. */
test_assert(i_stream_read(child1) == 3);
data = i_stream_get_data(child1, &size);
test_assert(size == 3 && memcmp(data, "456", 3) == 0);
/* child2 read beginning.. */
test_assert(i_stream_read(child2) == 3);
data = i_stream_get_data(child2, &size);
test_assert(size == 3 && memcmp(data, "123", 3) == 0);
/* child1 check middle again.. the parent has been modified,
so it can't return the original data (without some code changes). */
data = i_stream_get_data(child1, &size);
test_assert(size == 0);
i_stream_skip(child1, 3);
/* child1 read end */
test_assert(i_stream_read(child1) == 3);
data = i_stream_get_data(child1, &size);
test_assert(size == 3 && memcmp(data, "789", 3) == 0);
i_stream_skip(child1, 3);
test_assert(i_stream_read(child1) == -1);
/* child2 check beginning again.. */
data = i_stream_get_data(child2, &size);
test_assert(size == 0);
i_stream_skip(child2, 3);
/* child2 read middle */
test_assert(i_stream_read(child2) == 3);
data = i_stream_get_data(child2, &size);
test_assert(size == 3 && memcmp(data, "456", 3) == 0);
i_stream_skip(child2, 3);
i_stream_destroy(&child1);
i_stream_destroy(&child2);
i_stream_destroy(&parent);
test_end();
}
示例8: message_get_body_size
int message_get_body_size(struct istream *input, struct message_size *body,
bool *has_nuls_r)
{
const unsigned char *msg;
size_t i, size, missing_cr_count;
int ret;
memset(body, 0, sizeof(struct message_size));
*has_nuls_r = FALSE;
missing_cr_count = 0;
if ((ret = i_stream_read_more(input, &msg, &size)) <= 0) {
i_assert(ret == -1);
return ret < 0 && input->stream_errno != 0 ? -1 : 0;
}
if (msg[0] == '\n')
missing_cr_count++;
do {
for (i = 1; i < size; i++) {
if (msg[i] > '\n')
continue;
if (msg[i] == '\n') {
if (msg[i-1] != '\r') {
/* missing CR */
missing_cr_count++;
}
/* increase after making sure we didn't break
at virtual \r */
body->lines++;
} else if (msg[i] == '\0') {
*has_nuls_r = TRUE;
}
}
/* leave the last character, it may be \r */
i_stream_skip(input, i - 1);
body->physical_size += i - 1;
} while ((ret = i_stream_read_bytes(input, &msg, &size, 2)) > 0);
i_assert(ret == -1);
ret = input->stream_errno != 0 ? -1 : 0;
i_stream_skip(input, 1);
body->physical_size++;
body->virtual_size = body->physical_size + missing_cr_count;
i_assert(body->virtual_size >= body->physical_size);
return ret;
}
示例9: fd_set_nonblock
static struct istream *mail_raw_create_stream
(struct mail_user *ruser, int fd, time_t *mtime_r, const char **sender)
{
struct istream *input, *input2, *input_list[2];
const unsigned char *data;
size_t i, size;
int ret, tz;
char *env_sender = NULL;
*mtime_r = (time_t)-1;
fd_set_nonblock(fd, FALSE);
input = i_stream_create_fd(fd, 4096, FALSE);
input->blocking = TRUE;
/* If input begins with a From-line, drop it */
ret = i_stream_read_data(input, &data, &size, 5);
if (ret > 0 && size >= 5 && memcmp(data, "From ", 5) == 0) {
/* skip until the first LF */
i_stream_skip(input, 5);
while ( i_stream_read_data(input, &data, &size, 0) > 0 ) {
for (i = 0; i < size; i++) {
if (data[i] == '\n')
break;
}
if (i != size) {
(void)mbox_from_parse(data, i, mtime_r, &tz, &env_sender);
i_stream_skip(input, i + 1);
break;
}
i_stream_skip(input, size);
}
}
if (env_sender != NULL && sender != NULL) {
*sender = t_strdup(env_sender);
}
i_free(env_sender);
if (input->v_offset == 0) {
input2 = input;
i_stream_ref(input2);
} else {
input2 = i_stream_create_limit(input, (uoff_t)-1);
}
i_stream_unref(&input);
input_list[0] = input2; input_list[1] = NULL;
input = i_stream_create_seekable(input_list, MAIL_MAX_MEMORY_BUFFER,
seekable_fd_callback, (void*)ruser);
i_stream_unref(&input2);
return input;
}
示例10: imap_parser_read_literal_data
static bool imap_parser_read_literal_data(struct imap_parser *parser,
const unsigned char *data,
size_t data_size)
{
if (parser->literal_skip_crlf) {
/* skip \r\n or \n, anything else gives an error */
if (data_size == 0)
return FALSE;
if (*data == '\r') {
parser->line_size++;
data++; data_size--;
i_stream_skip(parser->input, 1);
if (data_size == 0)
return FALSE;
}
if (*data != '\n') {
parser->error = IMAP_PARSE_ERROR_BAD_SYNTAX;
parser->error_msg = "Missing LF after literal size";
return FALSE;
}
parser->line_size++;
data++; data_size--;
i_stream_skip(parser->input, 1);
parser->literal_skip_crlf = FALSE;
i_assert(parser->cur_pos == 0);
}
if ((parser->flags & IMAP_PARSE_FLAG_LITERAL_SIZE) == 0 ||
parser->cur_type == ARG_PARSE_LITERAL_DATA_FORCED) {
/* now we just wait until we've read enough data */
if (data_size < parser->literal_size)
return FALSE;
else {
imap_parser_save_arg(parser, data,
(size_t)parser->literal_size);
parser->cur_pos = (size_t)parser->literal_size;
return TRUE;
}
} else {
/* we want to save only literal size, not the literal itself. */
parser->literal_size_return = TRUE;
imap_parser_save_arg(parser, uchar_empty_ptr, 0);
return FALSE;
}
}
示例11: i_stream_seekable_stat
static int
i_stream_seekable_stat(struct istream_private *stream, bool exact)
{
struct seekable_istream *sstream = (struct seekable_istream *)stream;
const struct stat *st;
uoff_t old_offset;
ssize_t ret;
if (sstream->size != (uoff_t)-1) {
/* we've already reached EOF and know the size */
stream->statbuf.st_size = sstream->size;
return 0;
}
if (sstream->membuf != NULL) {
/* we want to know the full size of the file, so read until
we're finished */
old_offset = stream->istream.v_offset;
do {
i_stream_skip(&stream->istream,
stream->pos - stream->skip);
} while ((ret = i_stream_seekable_read(stream)) > 0);
if (ret == 0) {
i_panic("i_stream_stat() used for non-blocking "
"seekable stream %s offset %"PRIuUOFF_T,
i_stream_get_name(sstream->cur_input),
sstream->cur_input->v_offset);
}
i_stream_skip(&stream->istream, stream->pos - stream->skip);
i_stream_seek(&stream->istream, old_offset);
unref_streams(sstream);
}
if (stream->istream.stream_errno != 0)
return -1;
if (sstream->fd_input != NULL) {
/* using a file backed buffer, we can use real fstat() */
if (i_stream_stat(sstream->fd_input, exact, &st) < 0)
return -1;
stream->statbuf = *st;
} else {
/* buffer is completely in memory */
i_assert(sstream->membuf != NULL);
stream->statbuf.st_size = sstream->membuf->used;
}
return 0;
}
示例12: imap_zlib_client_skip_line
static void imap_zlib_client_skip_line(struct client *client)
{
const unsigned char *data;
size_t data_size;
data = i_stream_get_data(client->input, &data_size);
i_assert(data_size > 0);
if (data[0] == '\n')
i_stream_skip(client->input, 1);
else if (data[0] == '\r' && data_size > 1 && data[1] == '\n')
i_stream_skip(client->input, 2);
else
i_unreached();
client->input_skip_line = FALSE;
}
示例13: server_handle_input
static void
server_handle_input(struct server_connection *conn,
const unsigned char *data, size_t size)
{
string_t *str;
size_t i, start;
if (printing_conn == conn) {
/* continue printing */
} else if (printing_conn == NULL) {
printing_conn = conn;
} else {
/* someone else is printing. don't continue until it
goes away */
io_remove(&conn->io);
return;
}
if (data[size-1] == '\001') {
/* last character is an escape */
size--;
}
str = t_str_new(128);
for (i = start = 0; i < size; i++) {
if (data[i] == '\n') {
if (i != start) {
i_error("doveadm server sent broken print input");
server_connection_destroy(&conn);
return;
}
conn->state = SERVER_REPLY_STATE_RET;
i_stream_skip(conn->input, i + 1);
print_connection_released();
return;
}
if (data[i] == '\t') {
server_flush_field(conn, str, data + start, i - start);
start = i + 1;
}
}
if (start != size) {
conn->streaming = TRUE;
stream_data(str, data + start, size - start);
}
i_stream_skip(conn->input, size);
}
示例14: mdbox_file_read_metadata_hdr
static int
mdbox_file_read_metadata_hdr(struct dbox_file *file,
struct dbox_metadata_header *meta_hdr_r)
{
const unsigned char *data;
size_t size;
int ret;
ret = i_stream_read_data(file->input, &data, &size,
sizeof(*meta_hdr_r));
if (ret <= 0) {
i_assert(ret == -1);
if (file->input->stream_errno == 0) {
dbox_file_set_corrupted(file, "missing metadata");
return 0;
}
mail_storage_set_critical(&file->storage->storage,
"read(%s) failed: %m", file->cur_path);
return -1;
}
memcpy(meta_hdr_r, data, sizeof(*meta_hdr_r));
if (memcmp(meta_hdr_r->magic_post, DBOX_MAGIC_POST,
sizeof(meta_hdr_r->magic_post)) != 0) {
dbox_file_set_corrupted(file, "invalid metadata magic");
return 0;
}
i_stream_skip(file->input, sizeof(*meta_hdr_r));
return 1;
}
示例15: i_stream_lzma_stat
static int
i_stream_lzma_stat(struct istream_private *stream, bool exact)
{
struct lzma_istream *zstream = (struct lzma_istream *) stream;
const struct stat *st;
size_t size;
if (i_stream_stat(stream->parent, exact, &st) < 0) {
stream->istream.stream_errno = stream->parent->stream_errno;
return -1;
}
stream->statbuf = *st;
/* when exact=FALSE always return the parent stat's size, even if we
know the exact value. this is necessary because otherwise e.g. mbox
code can see two different values and think that a compressed mbox
file keeps changing. */
if (!exact)
return 0;
if (zstream->stream_size == (uoff_t)-1) {
uoff_t old_offset = stream->istream.v_offset;
do {
size = i_stream_get_data_size(&stream->istream);
i_stream_skip(&stream->istream, size);
} while (i_stream_read(&stream->istream) > 0);
i_stream_seek(&stream->istream, old_offset);
if (zstream->stream_size == (uoff_t)-1)
return -1;
}
stream->statbuf.st_size = zstream->stream_size;
return 0;
}