~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib-mail/istream-nonuls.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007-2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "istream-private.h"
 
5
#include "istream-nonuls.h"
 
6
 
 
7
struct nonuls_istream {
 
8
        struct istream_private istream;
 
9
        char replace_chr;
 
10
};
 
11
 
 
12
static int i_stream_read_parent(struct istream_private *stream)
 
13
{
 
14
        ssize_t ret;
 
15
 
 
16
        if (i_stream_get_data_size(stream->parent) > 0)
 
17
                return 1;
 
18
 
 
19
        ret = i_stream_read(stream->parent);
 
20
        if (ret <= 0) {
 
21
                stream->istream.stream_errno = stream->parent->stream_errno;
 
22
                stream->istream.eof = stream->parent->eof;
 
23
                return ret;
 
24
        }
 
25
        i_assert(i_stream_get_data_size(stream->parent) != 0);
 
26
        return 1;
 
27
}
 
28
 
 
29
static ssize_t i_stream_nonuls_read(struct istream_private *stream)
 
30
{
 
31
        struct nonuls_istream *nstream = (struct nonuls_istream *)stream;
 
32
        const unsigned char *data, *p;
 
33
        size_t i, size, avail_size;
 
34
        int ret;
 
35
 
 
36
        if ((ret = i_stream_read_parent(stream)) <= 0)
 
37
                return ret;
 
38
 
 
39
        data = i_stream_get_data(stream->parent, &size);
 
40
        if (!i_stream_try_alloc(stream, size, &avail_size))
 
41
                return -2;
 
42
        if (size > avail_size)
 
43
                size = avail_size;
 
44
        i_assert(size > 0);
 
45
 
 
46
        p = memchr(data, '\0', size);
 
47
        if (p == NULL) {
 
48
                /* no NULs in this block */
 
49
                memcpy(stream->w_buffer+stream->pos, data, size);
 
50
        } else {
 
51
                i = p-data;
 
52
                memcpy(stream->w_buffer+stream->pos, data, i);
 
53
                for (; i < size; i++) {
 
54
                        stream->w_buffer[stream->pos+i] = data[i] == '\0' ?
 
55
                                nstream->replace_chr : data[i];
 
56
                }
 
57
        }
 
58
        stream->pos += size;
 
59
        i_stream_skip(stream->parent, size);
 
60
        return size;
 
61
}
 
62
 
 
63
struct istream *i_stream_create_nonuls(struct istream *input, char replace_chr)
 
64
{
 
65
        struct nonuls_istream *nstream;
 
66
 
 
67
        nstream = i_new(struct nonuls_istream, 1);
 
68
        nstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
69
        nstream->istream.stream_size_passthrough = TRUE;
 
70
 
 
71
        nstream->istream.read = i_stream_nonuls_read;
 
72
 
 
73
        nstream->istream.istream.readable_fd = FALSE;
 
74
        nstream->istream.istream.blocking = input->blocking;
 
75
        nstream->istream.istream.seekable = FALSE;
 
76
        nstream->replace_chr = replace_chr;
 
77
        return i_stream_create(&nstream->istream, input,
 
78
                               i_stream_get_fd(input));
 
79
}