add after_login_hint, refine ffi

This commit is contained in:
B. Petersen
2020-01-26 23:27:36 +01:00
parent aaa6497659
commit 63043cb45d
2 changed files with 36 additions and 4 deletions

View File

@@ -3708,7 +3708,9 @@ dc_provider_t* dc_provider_new_from_email (const dc_context_t*, cons
*
* @memberof dc_provider_t
* @param provider The dc_provider_t struct.
* @return A string which must be released using dc_str_unref().
* @return String with a fully-qualified URL,
* if there is no such URL, an empty string is returned, NULL is never returned.
* The returned value must be released using dc_str_unref().
*/
char* dc_provider_get_overview_page (const dc_provider_t* provider);
@@ -3723,7 +3725,9 @@ char* dc_provider_get_overview_page (const dc_provider_t* prov
*
* @memberof dc_provider_t
* @param provider The dc_provider_t struct.
* @return A string which must be released using dc_str_unref().
* @return A string with the hint to show to the user, may contain multiple lines,
* if there is no such hint, an empty string is returned, NULL is never returned.
* The returned value must be released using dc_str_unref().
*/
char* dc_provider_get_before_login_hint (const dc_provider_t* provider);

View File

@@ -46,17 +46,18 @@ pub struct Provider {
pub domains: &'static str,
pub status: Status,
pub before_login_hint: &'static str,
pub after_login_hint: &'static str,
pub overview_page: &'static str,
pub server: Vec<Server>, // this seems to be okay
pub server: Vec<Server>,
}
// TODO: the database will be auto-generated from the provider-db
lazy_static::lazy_static! {
static ref DATABASE: Vec<Provider> = vec![
Provider {
domains: "nauta.cu",
status: Status::OK,
before_login_hint: "",
after_login_hint: "",
overview_page: "",
server: vec![
Server { protocol: IMAP, socket: STARTTLS, server: "imap.nauta.cu", port: 143, username_pattern: EMAIL },
@@ -71,6 +72,7 @@ lazy_static::lazy_static! {
Hopefully sooner or later there will be a fix; \
for now, we suggest to use another e-mail-address \
or try Delta Chat again when the issue is fixed.",
after_login_hint: "",
overview_page: "https://provider.delta.chat/outlook.com",
server: vec![
],
@@ -82,6 +84,7 @@ lazy_static::lazy_static! {
if you have \"2-Step Verification\" enabled. \
If this setting is not available, \
you need to enable \"Less secure apps\".",
after_login_hint: "",
overview_page: "https://provider.delta.chat/gmail.com",
server: vec![
],
@@ -106,3 +109,28 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> {
None
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_provider_info() {
let provider = get_provider_info("user@unexistant.org");
assert!(provider.is_none());
let provider = get_provider_info("nauta.cu"); // this is no email address
assert!(provider.is_none());
let provider = get_provider_info("user@nauta.cu").unwrap();
assert!(provider.status == Status::OK);
let provider = get_provider_info("user@gmail.com").unwrap();
assert!(provider.status == Status::PREPARATION);
assert!(!provider.before_login_hint.is_empty());
assert!(!provider.overview_page.is_empty());
let provider = get_provider_info("user@googlemail.com").unwrap();
assert!(provider.status == Status::PREPARATION);
}
}