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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::MessageHeaders;
use glib::translate::*;
glib::wrapper! {
/// Represents a multipart HTTP message body, parsed according to the
/// syntax of RFC 2046.
///
/// Of particular interest to HTTP are `multipart/byte-ranges` and
/// `multipart/form-data`,
///
/// Although the headers of a #SoupMultipart body part will contain the
/// full headers from that body part, libsoup does not interpret them
/// according to MIME rules. For example, each body part is assumed to
/// have "binary" Content-Transfer-Encoding, even if its headers
/// explicitly state otherwise. In other words, don't try to use
/// #SoupMultipart for handling real MIME multiparts.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Multipart(Boxed<ffi::SoupMultipart>);
match fn {
copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::soup_multipart_get_type(), ptr as *mut _) as *mut ffi::SoupMultipart,
free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::soup_multipart_get_type(), ptr as *mut _),
type_ => || ffi::soup_multipart_get_type(),
}
}
impl Multipart {
/// Creates a new empty #SoupMultipart with a randomly-generated
/// boundary string.
///
/// Note that @mime_type must be the full MIME type, including "multipart/".
///
/// See also: [`Message::from_multipart()`][crate::Message::from_multipart()].
/// ## `mime_type`
/// the MIME type of the multipart to create.
///
/// # Returns
///
/// a new empty #SoupMultipart of the given @mime_type
#[doc(alias = "soup_multipart_new")]
pub fn new(mime_type: &str) -> Multipart {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::soup_multipart_new(mime_type.to_glib_none().0)) }
}
/// Parses @headers and @body to form a new #SoupMultipart
/// ## `headers`
/// the headers of the HTTP message to parse
/// ## `body`
/// the body of the HTTP message to parse
///
/// # Returns
///
/// a new #SoupMultipart (or [`None`] if the
/// message couldn't be parsed or wasn't multipart).
#[doc(alias = "soup_multipart_new_from_message")]
#[doc(alias = "new_from_message")]
pub fn from_message(headers: &MessageHeaders, body: &glib::Bytes) -> Option<Multipart> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_multipart_new_from_message(
headers.to_glib_none().0,
body.to_glib_none().0,
))
}
}
/// Adds a new MIME part containing @body to @self
///
/// Uses "Content-Disposition: form-data", as per the HTML forms specification.
/// ## `control_name`
/// the name of the control associated with this file
/// ## `filename`
/// the name of the file, or [`None`] if not known
/// ## `content_type`
/// the MIME type of the file, or [`None`] if not known
/// ## `body`
/// the file data
#[doc(alias = "soup_multipart_append_form_file")]
pub fn append_form_file(
&mut self,
control_name: &str,
filename: Option<&str>,
content_type: Option<&str>,
body: &glib::Bytes,
) {
unsafe {
ffi::soup_multipart_append_form_file(
self.to_glib_none_mut().0,
control_name.to_glib_none().0,
filename.to_glib_none().0,
content_type.to_glib_none().0,
body.to_glib_none().0,
);
}
}
/// Adds a new MIME part containing @data to @self.
///
/// Uses "Content-Disposition: form-data", as per the HTML forms specification.
/// ## `control_name`
/// the name of the control associated with @data
/// ## `data`
/// the body data
#[doc(alias = "soup_multipart_append_form_string")]
pub fn append_form_string(&mut self, control_name: &str, data: &str) {
unsafe {
ffi::soup_multipart_append_form_string(
self.to_glib_none_mut().0,
control_name.to_glib_none().0,
data.to_glib_none().0,
);
}
}
/// Adds a new MIME part to @self with the given headers and body.
///
/// (The multipart will make its own copies of @headers and @body, so
/// you should free your copies if you are not using them for anything
/// else.)
/// ## `headers`
/// the MIME part headers
/// ## `body`
/// the MIME part body
#[doc(alias = "soup_multipart_append_part")]
pub fn append_part(&mut self, headers: &MessageHeaders, body: &glib::Bytes) {
unsafe {
ffi::soup_multipart_append_part(
self.to_glib_none_mut().0,
headers.to_glib_none().0,
body.to_glib_none().0,
);
}
}
/// Gets the number of body parts in @self.
///
/// # Returns
///
/// the number of body parts in @self
#[doc(alias = "soup_multipart_get_length")]
#[doc(alias = "get_length")]
pub fn length(&mut self) -> i32 {
unsafe { ffi::soup_multipart_get_length(self.to_glib_none_mut().0) }
}
/// Gets the indicated body part from @self.
/// ## `part`
/// the part number to get (counting from 0)
///
/// # Returns
///
/// [`true`] on success, [`false`] if @part is out of range (in
/// which case @headers and @body won't be set)
///
/// ## `headers`
/// return location for the MIME part
/// headers
///
/// ## `body`
/// return location for the MIME part
/// body
#[doc(alias = "soup_multipart_get_part")]
#[doc(alias = "get_part")]
pub fn part(&mut self, part: i32) -> Option<(MessageHeaders, glib::Bytes)> {
unsafe {
let mut headers = std::ptr::null_mut();
let mut body = std::ptr::null_mut();
let ret = from_glib(ffi::soup_multipart_get_part(
self.to_glib_none_mut().0,
part,
&mut headers,
&mut body,
));
if ret {
Some((from_glib_none(headers), from_glib_none(body)))
} else {
None
}
}
}
/// Serializes @self to @dest_headers and @dest_body.
/// ## `dest_headers`
/// the headers of the HTTP message to serialize @self to
///
/// # Returns
///
///
/// ## `dest_body`
/// the body of the HTTP message to serialize @self to
#[doc(alias = "soup_multipart_to_message")]
pub fn to_message(&mut self, dest_headers: &MessageHeaders) -> glib::Bytes {
unsafe {
let mut dest_body = std::ptr::null_mut();
ffi::soup_multipart_to_message(
self.to_glib_none_mut().0,
dest_headers.to_glib_none().0,
&mut dest_body,
);
from_glib_full(dest_body)
}
}
}