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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
// 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::{Cookie, DateFormat, HTTPVersion, Message, MessageHeaders};
use glib::translate::*;
/// Like `CHECK_VERSION()`, but the check for soup_check_version is
/// at runtime instead of compile time.
///
/// This is useful for compiling against older versions of libsoup, but using
/// features from newer versions.
/// ## `major`
/// the major version to check
/// ## `minor`
/// the minor version to check
/// ## `micro`
/// the micro version to check
///
/// # Returns
///
/// [`true`] if the version of the libsoup currently loaded
/// is the same as or newer than the passed-in version.
#[doc(alias = "soup_check_version")]
pub fn check_version(major: u32, minor: u32, micro: u32) -> bool {
assert_initialized_main_thread!();
unsafe { from_glib(ffi::soup_check_version(major, minor, micro)) }
}
/// Parses @msg's Cookie request header and returns a [`glib::SList`][crate::glib::SList] of
/// `SoupCookie`s.
///
/// As the "Cookie" header, unlike "Set-Cookie", only contains cookie names and
/// values, none of the other #SoupCookie fields will be filled in. (Thus, you
/// can't generally pass a cookie returned from this method directly to
/// `cookies_to_response()`.)
/// ## `msg`
/// a #SoupMessage containing a "Cookie" request header
///
/// # Returns
///
/// a #GSList of
/// `SoupCookie`s, which can be freed with `Cookie::free()`.
#[doc(alias = "soup_cookies_from_request")]
pub fn cookies_from_request(msg: &Message) -> Vec<Cookie> {
skip_assert_initialized!();
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_cookies_from_request(msg.to_glib_none().0))
}
}
/// Parses @msg's Set-Cookie response headers and returns a [`glib::SList`][crate::glib::SList]
/// of `SoupCookie`s.
///
/// Cookies that do not specify "path" or "domain" attributes will have their
/// values defaulted from @msg.
/// ## `msg`
/// a #SoupMessage containing a "Set-Cookie" response header
///
/// # Returns
///
/// a #GSList of
/// `SoupCookie`s, which can be freed with `Cookie::free()`.
#[doc(alias = "soup_cookies_from_response")]
pub fn cookies_from_response(msg: &Message) -> Vec<Cookie> {
skip_assert_initialized!();
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_cookies_from_response(msg.to_glib_none().0))
}
}
/// Parses @date_string and tries to extract a date from it.
///
/// This recognizes all of the "HTTP-date" formats from RFC 2616, RFC 2822 dates,
/// and reasonable approximations thereof. (Eg, it is lenient about whitespace,
/// leading "0"s, etc.)
/// ## `date_string`
/// The date as a string
///
/// # Returns
///
/// a new #GDateTime, or [`None`] if @date_string
/// could not be parsed.
#[doc(alias = "soup_date_time_new_from_http_string")]
pub fn date_time_new_from_http_string(date_string: &str) -> Option<glib::DateTime> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_date_time_new_from_http_string(
date_string.to_glib_none().0,
))
}
}
/// Converts @date to a string in the format described by @format.
/// ## `date`
/// a #GDateTime
/// ## `format`
/// the format to generate the date in
///
/// # Returns
///
/// @date as a string or [`None`]
#[doc(alias = "soup_date_time_to_string")]
pub fn date_time_to_string(date: &glib::DateTime, format: DateFormat) -> Option<glib::GString> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_date_time_to_string(
date.to_glib_none().0,
format.into_glib(),
))
}
}
//#[doc(alias = "soup_form_decode")]
//pub fn form_decode(encoded_form: &str) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:soup_form_decode() }
//}
//#[doc(alias = "soup_form_decode_multipart")]
//pub fn form_decode_multipart(multipart: &mut Multipart, file_control_name: Option<&str>) -> (/*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, glib::GString, glib::GString, glib::Bytes) {
// unsafe { TODO: call ffi:soup_form_decode_multipart() }
//}
//#[doc(alias = "soup_form_encode")]
//pub fn form_encode(first_field: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Option<glib::GString> {
// unsafe { TODO: call ffi:soup_form_encode() }
//}
//#[doc(alias = "soup_form_encode_datalist")]
//pub fn form_encode_datalist(form_data_set: /*Ignored*/&mut glib::Data) -> Option<glib::GString> {
// unsafe { TODO: call ffi:soup_form_encode_datalist() }
//}
//#[doc(alias = "soup_form_encode_hash")]
//pub fn form_encode_hash(form_data_set: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) -> Option<glib::GString> {
// unsafe { TODO: call ffi:soup_form_encode_hash() }
//}
//#[doc(alias = "soup_form_encode_valist")]
//pub fn form_encode_valist(first_field: &str, args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> Option<glib::GString> {
// unsafe { TODO: call ffi:soup_form_encode_valist() }
//}
/// Returns the major version number of the libsoup library.
///
/// e.g. in libsoup version 2.42.0 this is 2.
///
/// This function is in the library, so it represents the libsoup library
/// your code is running against. Contrast with the #SOUP_MAJOR_VERSION
/// macro, which represents the major version of the libsoup headers you
/// have included when compiling your code.
///
/// # Returns
///
/// the major version number of the libsoup library
#[doc(alias = "soup_get_major_version")]
#[doc(alias = "get_major_version")]
pub fn major_version() -> u32 {
assert_initialized_main_thread!();
unsafe { ffi::soup_get_major_version() }
}
/// Returns the micro version number of the libsoup library.
///
/// e.g. in libsoup version 2.42.0 this is 0.
///
/// This function is in the library, so it represents the libsoup library
/// your code is running against. Contrast with the #SOUP_MICRO_VERSION
/// macro, which represents the micro version of the libsoup headers you
/// have included when compiling your code.
///
/// # Returns
///
/// the micro version number of the libsoup library
#[doc(alias = "soup_get_micro_version")]
#[doc(alias = "get_micro_version")]
pub fn micro_version() -> u32 {
assert_initialized_main_thread!();
unsafe { ffi::soup_get_micro_version() }
}
/// Returns the minor version number of the libsoup library.
///
/// e.g. in libsoup version 2.42.0 this is 42.
///
/// This function is in the library, so it represents the libsoup library
/// your code is running against. Contrast with the #SOUP_MINOR_VERSION
/// macro, which represents the minor version of the libsoup headers you
/// have included when compiling your code.
///
/// # Returns
///
/// the minor version number of the libsoup library
#[doc(alias = "soup_get_minor_version")]
#[doc(alias = "get_minor_version")]
pub fn minor_version() -> u32 {
assert_initialized_main_thread!();
unsafe { ffi::soup_get_minor_version() }
}
/// Parses @header to see if it contains the token @token (matched
/// case-insensitively).
///
/// Note that this can't be used with lists that have qvalues.
/// ## `header`
/// An HTTP header suitable for parsing with
/// [`header_parse_list()`][crate::header_parse_list()]
/// ## `token`
/// a token
///
/// # Returns
///
/// whether or not @header contains @token
#[doc(alias = "soup_header_contains")]
pub fn header_contains(header: &str, token: &str) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::soup_header_contains(
header.to_glib_none().0,
token.to_glib_none().0,
))
}
}
//#[doc(alias = "soup_header_free_list")]
//pub fn header_free_list(list: /*Unimplemented*/&[&Basic: Pointer]) {
// unsafe { TODO: call ffi:soup_header_free_list() }
//}
//#[doc(alias = "soup_header_free_param_list")]
//pub fn header_free_param_list(param_list: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) {
// unsafe { TODO: call ffi:soup_header_free_param_list() }
//}
//#[doc(alias = "soup_header_g_string_append_param")]
//pub fn header_g_string_append_param(string: /*Ignored*/&mut glib::String, name: &str, value: Option<&str>) {
// unsafe { TODO: call ffi:soup_header_g_string_append_param() }
//}
//#[doc(alias = "soup_header_g_string_append_param_quoted")]
//pub fn header_g_string_append_param_quoted(string: /*Ignored*/&mut glib::String, name: &str, value: &str) {
// unsafe { TODO: call ffi:soup_header_g_string_append_param_quoted() }
//}
/// Parses a header whose content is described by RFC2616 as `#something`.
///
/// "something" does not itself contain commas, except as part of quoted-strings.
/// ## `header`
/// a header value
///
/// # Returns
///
/// a #GSList of
/// list elements, as allocated strings
#[doc(alias = "soup_header_parse_list")]
pub fn header_parse_list(header: &str) -> Vec<glib::GString> {
assert_initialized_main_thread!();
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_header_parse_list(header.to_glib_none().0))
}
}
//#[doc(alias = "soup_header_parse_param_list")]
//pub fn header_parse_param_list(header: &str) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:soup_header_parse_param_list() }
//}
//#[doc(alias = "soup_header_parse_param_list_strict")]
//pub fn header_parse_param_list_strict(header: &str) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:soup_header_parse_param_list_strict() }
//}
//#[doc(alias = "soup_header_parse_quality_list")]
//pub fn header_parse_quality_list(header: &str, unacceptable: /*Unimplemented*/Vec<glib::GString>) -> Vec<glib::GString> {
// unsafe { TODO: call ffi:soup_header_parse_quality_list() }
//}
//#[doc(alias = "soup_header_parse_semi_param_list")]
//pub fn header_parse_semi_param_list(header: &str) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:soup_header_parse_semi_param_list() }
//}
//#[doc(alias = "soup_header_parse_semi_param_list_strict")]
//pub fn header_parse_semi_param_list_strict(header: &str) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:soup_header_parse_semi_param_list_strict() }
//}
/// Parses the headers of an HTTP request or response in @str and
/// stores the results in @dest.
///
/// Beware that @dest may be modified even on failure.
///
/// This is a low-level method; normally you would use
/// [`headers_parse_request()`][crate::headers_parse_request()] or [`headers_parse_response()`][crate::headers_parse_response()].
/// ## `str`
/// the header string (including the Request-Line or Status-Line,
/// but not the trailing blank line)
/// ## `len`
/// length of @str
/// ## `dest`
/// #SoupMessageHeaders to store the header values in
///
/// # Returns
///
/// success or failure
#[doc(alias = "soup_headers_parse")]
pub fn headers_parse(str: &str, dest: &MessageHeaders) -> bool {
assert_initialized_main_thread!();
let len = str.len() as _;
unsafe {
from_glib(ffi::soup_headers_parse(
str.to_glib_none().0,
len,
dest.to_glib_none().0,
))
}
}
/// Parses the headers of an HTTP request in @str and stores the
/// results in @req_method, @req_path, @ver, and @req_headers.
///
/// Beware that @req_headers may be modified even on failure.
/// ## `str`
/// the headers (up to, but not including, the trailing blank line)
/// ## `len`
/// length of @str
/// ## `req_headers`
/// #SoupMessageHeaders to store the header values in
///
/// # Returns
///
/// [`Status::Ok`][crate::Status::Ok] if the headers could be parsed, or an
/// HTTP error to be returned to the client if they could not be.
///
/// ## `req_method`
/// if non-[`None`], will be filled in with the
/// request method
///
/// ## `req_path`
/// if non-[`None`], will be filled in with the
/// request path
///
/// ## `ver`
/// if non-[`None`], will be filled in with the HTTP
/// version
#[doc(alias = "soup_headers_parse_request")]
pub fn headers_parse_request(
str: &str,
req_headers: &MessageHeaders,
) -> (u32, glib::GString, glib::GString, HTTPVersion) {
assert_initialized_main_thread!();
let len = str.len() as _;
unsafe {
let mut req_method = std::ptr::null_mut();
let mut req_path = std::ptr::null_mut();
let mut ver = std::mem::MaybeUninit::uninit();
let ret = ffi::soup_headers_parse_request(
str.to_glib_none().0,
len,
req_headers.to_glib_none().0,
&mut req_method,
&mut req_path,
ver.as_mut_ptr(),
);
(
ret,
from_glib_full(req_method),
from_glib_full(req_path),
from_glib(ver.assume_init()),
)
}
}
/// Parses the headers of an HTTP response in @str and stores the
/// results in @ver, @status_code, @reason_phrase, and @headers.
///
/// Beware that @headers may be modified even on failure.
/// ## `str`
/// the headers (up to, but not including, the trailing blank line)
/// ## `len`
/// length of @str
/// ## `headers`
/// #SoupMessageHeaders to store the header values in
///
/// # Returns
///
/// success or failure.
///
/// ## `ver`
/// if non-[`None`], will be filled in with the HTTP
/// version
///
/// ## `status_code`
/// if non-[`None`], will be filled in with
/// the status code
///
/// ## `reason_phrase`
/// if non-[`None`], will be filled in with
/// the reason phrase
#[doc(alias = "soup_headers_parse_response")]
pub fn headers_parse_response(
str: &str,
headers: &MessageHeaders,
) -> Option<(HTTPVersion, u32, glib::GString)> {
assert_initialized_main_thread!();
let len = str.len() as _;
unsafe {
let mut ver = std::mem::MaybeUninit::uninit();
let mut status_code = std::mem::MaybeUninit::uninit();
let mut reason_phrase = std::ptr::null_mut();
let ret = from_glib(ffi::soup_headers_parse_response(
str.to_glib_none().0,
len,
headers.to_glib_none().0,
ver.as_mut_ptr(),
status_code.as_mut_ptr(),
&mut reason_phrase,
));
if ret {
Some((
from_glib(ver.assume_init()),
status_code.assume_init(),
from_glib_full(reason_phrase),
))
} else {
None
}
}
}
/// Parses the HTTP Status-Line string in @status_line into @ver,
/// @status_code, and @reason_phrase.
///
/// @status_line must be terminated by either "\0" or "\r\n".
/// ## `status_line`
/// an HTTP Status-Line
///
/// # Returns
///
/// [`true`] if @status_line was parsed successfully.
///
/// ## `ver`
/// if non-[`None`], will be filled in with the HTTP
/// version
///
/// ## `status_code`
/// if non-[`None`], will be filled in with
/// the status code
///
/// ## `reason_phrase`
/// if non-[`None`], will be filled in with
/// the reason phrase
#[doc(alias = "soup_headers_parse_status_line")]
pub fn headers_parse_status_line(status_line: &str) -> Option<(HTTPVersion, u32, glib::GString)> {
assert_initialized_main_thread!();
unsafe {
let mut ver = std::mem::MaybeUninit::uninit();
let mut status_code = std::mem::MaybeUninit::uninit();
let mut reason_phrase = std::ptr::null_mut();
let ret = from_glib(ffi::soup_headers_parse_status_line(
status_line.to_glib_none().0,
ver.as_mut_ptr(),
status_code.as_mut_ptr(),
&mut reason_phrase,
));
if ret {
Some((
from_glib(ver.assume_init()),
status_code.assume_init(),
from_glib_full(reason_phrase),
))
} else {
None
}
}
}
/// Looks whether the @domain passed as argument is a public domain
/// suffix (.org, .com, .co.uk, etc) or not.
///
/// Prior to libsoup 2.46, this function required that @domain be in
/// UTF-8 if it was an IDN. From 2.46 on, the name can be in either
/// UTF-8 or ASCII format.
/// ## `domain`
/// a domain name
///
/// # Returns
///
/// [`true`] if it is a public domain, [`false`] otherwise.
#[doc(alias = "soup_tld_domain_is_public_suffix")]
pub fn tld_domain_is_public_suffix(domain: &str) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::soup_tld_domain_is_public_suffix(
domain.to_glib_none().0,
))
}
}
/// Finds the base domain for a given @hostname
///
/// The base domain is composed by the top level domain (such as .org, .com,
/// .co.uk, etc) plus the second level domain, for example for
/// myhost.mydomain.com it will return mydomain.com.
///
/// Note that [`None`] will be returned for private URLs (those not ending
/// with any well known TLD) because choosing a base domain for them
/// would be totally arbitrary.
///
/// Prior to libsoup 2.46, this function required that @hostname be in
/// UTF-8 if it was an IDN. From 2.46 on, the name can be in either
/// UTF-8 or ASCII format (and the return value will be in the same
/// format).
/// ## `hostname`
/// a hostname
///
/// # Returns
///
/// a pointer to the start of the base domain in @hostname. If
/// an error occurs, [`None`] will be returned and @error set.
#[doc(alias = "soup_tld_get_base_domain")]
pub fn tld_get_base_domain(hostname: &str) -> Result<glib::GString, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::soup_tld_get_base_domain(hostname.to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_none(ret))
} else {
Err(from_glib_full(error))
}
}
}
//#[doc(alias = "soup_uri_copy")]
//pub fn uri_copy(uri: &glib::Uri, first_component: URIComponent, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Option<glib::Uri> {
// unsafe { TODO: call ffi:soup_uri_copy() }
//}
/// Decodes the given data URI and returns its contents and @content_type.
/// ## `uri`
/// a data URI, in string form
///
/// # Returns
///
/// a #GBytes with the contents of @uri,
/// or [`None`] if @uri is not a valid data URI
///
/// ## `content_type`
/// location to store content type
#[doc(alias = "soup_uri_decode_data_uri")]
pub fn uri_decode_data_uri(uri: &str) -> (glib::Bytes, Option<glib::GString>) {
assert_initialized_main_thread!();
unsafe {
let mut content_type = std::ptr::null_mut();
let ret = from_glib_full(ffi::soup_uri_decode_data_uri(
uri.to_glib_none().0,
&mut content_type,
));
(ret, from_glib_full(content_type))
}
}
#[doc(alias = "soup_uri_equal")]
pub fn uri_equal(uri1: &glib::Uri, uri2: &glib::Uri) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::soup_uri_equal(
uri1.to_glib_none().0,
uri2.to_glib_none().0,
))
}
}
//#[doc(alias = "soup_websocket_client_prepare_handshake")]
//pub fn websocket_client_prepare_handshake(msg: &Message, origin: Option<&str>, protocols: &[&str], supported_extensions: /*Ignored*/&[&glib::TypeClass]) {
// unsafe { TODO: call ffi:soup_websocket_client_prepare_handshake() }
//}
//#[doc(alias = "soup_websocket_client_verify_handshake")]
//pub fn websocket_client_verify_handshake(msg: &Message, supported_extensions: /*Ignored*/&[&glib::TypeClass], accepted_extensions: /*Unimplemented*/Vec<WebsocketExtension>) -> Result<(), glib::Error> {
// unsafe { TODO: call ffi:soup_websocket_client_verify_handshake() }
//}
//#[doc(alias = "soup_websocket_server_check_handshake")]
//pub fn websocket_server_check_handshake(msg: &ServerMessage, origin: Option<&str>, protocols: &[&str], supported_extensions: /*Ignored*/&[&glib::TypeClass]) -> Result<(), glib::Error> {
// unsafe { TODO: call ffi:soup_websocket_server_check_handshake() }
//}
//#[doc(alias = "soup_websocket_server_process_handshake")]
//pub fn websocket_server_process_handshake(msg: &ServerMessage, expected_origin: Option<&str>, protocols: &[&str], supported_extensions: /*Ignored*/&[&glib::TypeClass], accepted_extensions: /*Unimplemented*/Vec<WebsocketExtension>) -> bool {
// unsafe { TODO: call ffi:soup_websocket_server_process_handshake() }
//}