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

« back to all changes in this revision

Viewing changes to src/lib/istream-limit.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) 2003-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2003-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "istream-private.h"
31
31
        ssize_t ret;
32
32
        size_t pos;
33
33
 
 
34
        i_stream_seek(stream->parent, lstream->istream.parent_start_offset +
 
35
                      stream->istream.v_offset);
 
36
 
34
37
        if (stream->istream.v_offset +
35
38
            (stream->pos - stream->skip) >= lstream->v_size) {
36
39
                stream->istream.eof = TRUE;
37
40
                return -1;
38
41
        }
39
42
 
40
 
        i_stream_seek(stream->parent, lstream->istream.parent_start_offset +
41
 
                      stream->istream.v_offset);
42
 
 
43
43
        stream->pos -= stream->skip;
44
44
        stream->skip = 0;
45
45
 
71
71
        return ret;
72
72
}
73
73
 
74
 
static void i_stream_limit_seek(struct istream_private *stream, uoff_t v_offset,
75
 
                                bool mark ATTR_UNUSED)
76
 
{
77
 
        stream->istream.v_offset = v_offset;
78
 
        stream->skip = stream->pos = 0;
79
 
}
80
 
 
81
 
static const struct stat *
 
74
static int
82
75
i_stream_limit_stat(struct istream_private *stream, bool exact)
83
76
{
84
77
        struct limit_istream *lstream = (struct limit_istream *) stream;
85
78
        const struct stat *st;
86
79
 
87
 
        st = i_stream_stat(stream->parent, exact);
88
 
        if (st == NULL)
89
 
                return NULL;
 
80
        if (i_stream_stat(stream->parent, exact, &st) < 0)
 
81
                return -1;
90
82
 
91
83
        stream->statbuf = *st;
92
84
        if (lstream->v_size != (uoff_t)-1)
93
85
                stream->statbuf.st_size = lstream->v_size;
94
 
        return &stream->statbuf;
 
86
        return 0;
95
87
}
96
88
 
97
89
static int i_stream_limit_get_size(struct istream_private *stream,
105
97
                return 1;
106
98
        }
107
99
 
108
 
        st = i_stream_stat(&stream->istream, exact);
109
 
        if (st == NULL)
 
100
        if (i_stream_stat(&stream->istream, exact, &st) < 0)
110
101
                return -1;
111
102
        if (st->st_size == -1)
112
103
                return 0;
124
115
        lstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
125
116
 
126
117
        lstream->istream.iostream.destroy = i_stream_limit_destroy;
127
 
        lstream->istream.parent = input;
128
118
        lstream->istream.read = i_stream_limit_read;
129
 
        lstream->istream.seek = i_stream_limit_seek;
130
119
        lstream->istream.stat = i_stream_limit_stat;
131
120
        lstream->istream.get_size = i_stream_limit_get_size;
132
121
 
136
125
        return i_stream_create(&lstream->istream, input,
137
126
                               i_stream_get_fd(input));
138
127
}
 
128
 
 
129
struct istream *i_stream_create_range(struct istream *input,
 
130
                                      uoff_t v_offset, uoff_t v_size)
 
131
{
 
132
        uoff_t orig_offset = input->v_offset;
 
133
        struct istream *ret;
 
134
 
 
135
        input->v_offset = v_offset;
 
136
        ret = i_stream_create_limit(input, v_size);
 
137
        input->v_offset = orig_offset;
 
138
        return ret;
 
139
}