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

« back to all changes in this revision

Viewing changes to src/lib/ostream-hash.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) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "hash-method.h"
 
5
#include "ostream-private.h"
 
6
#include "ostream-hash.h"
 
7
 
 
8
struct hash_ostream {
 
9
        struct ostream_private ostream;
 
10
        const struct hash_method *method;
 
11
        void *hash_context;
 
12
};
 
13
 
 
14
static ssize_t
 
15
o_stream_hash_sendv(struct ostream_private *stream,
 
16
                    const struct const_iovec *iov, unsigned int iov_count)
 
17
{
 
18
        struct hash_ostream *hstream = (struct hash_ostream *)stream;
 
19
        unsigned int i;
 
20
        size_t bytes_left, block_len;
 
21
        ssize_t ret;
 
22
 
 
23
        if ((ret = o_stream_sendv(stream->parent, iov, iov_count)) < 0) {
 
24
                o_stream_copy_error_from_parent(stream);
 
25
                return -1;
 
26
        }
 
27
        if (ret > 0) {
 
28
                bytes_left = ret;
 
29
                for (i = 0; i < iov_count && bytes_left > 0; i++) {
 
30
                        block_len = iov[i].iov_len <= bytes_left ?
 
31
                                iov[i].iov_len : bytes_left;
 
32
                        hstream->method->loop(hstream->hash_context,
 
33
                                              iov[i].iov_base, block_len);
 
34
                        bytes_left -= block_len;
 
35
                }
 
36
        }
 
37
 
 
38
        stream->ostream.offset += ret;
 
39
        return ret;
 
40
}
 
41
 
 
42
struct ostream *
 
43
o_stream_create_hash(struct ostream *output, const struct hash_method *method,
 
44
                     void *hash_context)
 
45
{
 
46
        struct hash_ostream *hstream;
 
47
 
 
48
        hstream = i_new(struct hash_ostream, 1);
 
49
        hstream->ostream.sendv = o_stream_hash_sendv;
 
50
        hstream->method = method;
 
51
        hstream->hash_context = hash_context;
 
52
 
 
53
        return o_stream_create(&hstream->ostream, output,
 
54
                               o_stream_get_fd(output));
 
55
}