1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ b215ee8)
// DO NOT EDIT

use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// Base class for filters used by `StreamFilter`.
    ///
    /// # Implements
    ///
    /// [`FilterExt`](trait.FilterExt.html)
    pub struct Filter(Object<ffi::GMimeFilter, ffi::GMimeFilterClass>);

    match fn {
        get_type => || ffi::g_mime_filter_get_type(),
    }
}

/// Trait containing all `Filter` methods.
///
/// # Implementors
///
/// [`FilterBasic`](struct.FilterBasic.html), [`FilterBest`](struct.FilterBest.html), [`FilterCharset`](struct.FilterCharset.html), [`FilterDos2Unix`](struct.FilterDos2Unix.html), [`FilterEnriched`](struct.FilterEnriched.html), [`FilterFrom`](struct.FilterFrom.html), [`FilterGZip`](struct.FilterGZip.html), [`FilterHTML`](struct.FilterHTML.html), [`FilterOpenPGP`](struct.FilterOpenPGP.html), [`FilterSmtpData`](struct.FilterSmtpData.html), [`FilterStrip`](struct.FilterStrip.html), [`FilterUnix2Dos`](struct.FilterUnix2Dos.html), [`FilterWindows`](struct.FilterWindows.html), [`FilterYenc`](struct.FilterYenc.html), [`Filter`](struct.Filter.html)
pub trait FilterExt {
    /// Sets number of bytes backed up on the input, new calls replace
    /// previous ones
    /// ## `data`
    /// data to backup
    /// ## `length`
    /// length of `data`
    fn backup(&self, data: &[u8]);

    /// Completes the filtering.
    /// ## `inbuf`
    /// input buffer
    /// ## `inlen`
    /// input buffer length
    /// ## `prespace`
    /// prespace buffer length
    /// ## `outbuf`
    ///
    ///  pointer to output buffer
    /// ## `outlen`
    /// pointer to output length
    /// ## `outprespace`
    /// pointer to output prespace buffer length
    fn complete(&self, inbuf: &[u8], prespace: usize) -> (Vec<u8>, usize);

    /// Copies `self` into a new `Filter` object.
    ///
    /// # Returns
    ///
    /// a duplicate of `self`.
    fn copy(&self) -> Option<Filter>;

    /// Filters the input data and writes it to `out`.
    /// ## `inbuf`
    /// input buffer
    /// ## `inlen`
    /// input buffer length
    /// ## `prespace`
    /// prespace buffer length
    /// ## `outbuf`
    ///
    ///  pointer to output buffer
    /// ## `outlen`
    /// pointer to output length
    /// ## `outprespace`
    /// pointer to output prespace buffer length
    fn filter(&self, inbuf: &[u8], prespace: usize) -> (Vec<u8>, usize);

    /// Resets the filter.
    fn reset(&self);

    /// Ensure this much size is available for filter output (if required)
    /// ## `size`
    /// requested size for the output buffer
    /// ## `keep`
    /// `true` if existing data in the output buffer should be kept
    fn set_size(&self, size: usize, keep: bool);
}

impl<O: IsA<Filter>> FilterExt for O {
    fn backup(&self, data: &[u8]) {
        let length = data.len() as usize;
        unsafe {
            ffi::g_mime_filter_backup(self.to_glib_none().0, data.to_glib_none().0, length);
        }
    }

    fn complete(&self, inbuf: &[u8], prespace: usize) -> (Vec<u8>, usize) {
        let inlen = inbuf.len() as usize;
        unsafe {
            let mut outbuf = ptr::null_mut();
            let mut outlen = mem::uninitialized();
            let mut outprespace = mem::uninitialized();
            ffi::g_mime_filter_complete(self.to_glib_none().0, inbuf.to_glib_none().0, inlen, prespace, &mut outbuf, &mut outlen, &mut outprespace);
            (FromGlibContainer::from_glib_none_num(outbuf, outlen as usize), outprespace)
        }
    }

    fn copy(&self) -> Option<Filter> {
        unsafe {
            from_glib_full(ffi::g_mime_filter_copy(self.to_glib_none().0))
        }
    }

    fn filter(&self, inbuf: &[u8], prespace: usize) -> (Vec<u8>, usize) {
        let inlen = inbuf.len() as usize;
        unsafe {
            let mut outbuf = ptr::null_mut();
            let mut outlen = mem::uninitialized();
            let mut outprespace = mem::uninitialized();
            ffi::g_mime_filter_filter(self.to_glib_none().0, inbuf.to_glib_none().0, inlen, prespace, &mut outbuf, &mut outlen, &mut outprespace);
            (FromGlibContainer::from_glib_none_num(outbuf, outlen as usize), outprespace)
        }
    }

    fn reset(&self) {
        unsafe {
            ffi::g_mime_filter_reset(self.to_glib_none().0);
        }
    }

    fn set_size(&self, size: usize, keep: bool) {
        unsafe {
            ffi::g_mime_filter_set_size(self.to_glib_none().0, size, keep.to_glib());
        }
    }
}