◎위챗 : speedseoul
linphone_iphone_popup_password_request
LinphoneManager.m
createLinphoneCore
https://github.com/BelledonneCommunications/linphone-iphone/blob/e10cb36cad2051de4690c6740bc9a54904cb84a1/Classes/LinphoneManager.m
- (void)createLinphoneCore {
linphone_core_cbs_set_authentication_requested(cbs, linphone_iphone_popup_password_request);
//LinphoneManager.m
linphone_iphone_popup_password_request
linphone_core_cbs_set_authentication_requested(cbs, linphone_iphone_popup_password_request);
https://github.com/BelledonneCommunications/linphone-iphone/blob/e10cb36cad2051de4690c6740bc9a54904cb84a1/Classes/LinphoneManager.m
#pragma mark - Auth info Function
static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAuthInfo *auth_info, LinphoneAuthMethod method) {
// let the wizard handle its own errors
if ([PhoneMainView.instance currentView] != AssistantView.compositeViewDescription) {
const char * realmC = linphone_auth_info_get_realm(auth_info);
const char * usernameC = linphone_auth_info_get_username(auth_info) ? : "";
const char * domainC = linphone_auth_info_get_domain(auth_info) ? : "";
static UIAlertController *alertView = nil;
// InstantMessageDeliveryNotifications from previous accounts can trigger some pop-up spam asking for indentification
// Try to filter the popup password request to avoid displaying those that do not matter and can be handled through a simple warning
const MSList *accountList = linphone_core_get_account_list(LC);
bool foundMatchingConfig = false;
while (accountList && !foundMatchingConfig) {
LinphoneAccountParams const *accountParams = linphone_account_get_params(accountList->data);
const char * configUsername = linphone_address_get_username(linphone_account_params_get_identity_address(accountParams));
const char * configDomain = linphone_account_params_get_domain(accountParams);
foundMatchingConfig = (strcmp(configUsername, usernameC) == 0) && (strcmp(configDomain, domainC) == 0);
accountList = accountList->next;
}
if (!foundMatchingConfig) {
LOGW(@"Received an authentication request from %s@%s, but ignored it did not match any current user", usernameC, domainC);
return;
}
// avoid having multiple popups
[PhoneMainView.instance dismissViewControllerAnimated:YES completion:nil];
// dont pop up if we are in background, in any case we will refresh registers when entering
// the application again
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
return;
}
NSString *realm = [NSString stringWithUTF8String:realmC?:domainC];
NSString *username = [NSString stringWithUTF8String:usernameC];
NSString *domain = [NSString stringWithUTF8String:domainC];
alertView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Authentification needed", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"Connection failed because authentication is "
@"missing or invalid for %@@%@.\nYou can "
@"provide password again, or check your "
@"account configuration in the settings.", nil), username, realm]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = NSLocalizedString(@"Password", nil);
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.secureTextEntry = YES;
}];
UIAlertAction* continueAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Confirm password", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSString *password = alertView.textFields[0].text;
LinphoneAuthInfo *info =
linphone_auth_info_new(username.UTF8String, NULL, password.UTF8String, NULL,
realm.UTF8String, domain.UTF8String);
linphone_core_add_auth_info(LC, info);
[LinphoneManager.instance refreshRegisters];
}];
UIAlertAction* settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Go to settings", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[PhoneMainView.instance changeCurrentView:SettingsView.compositeViewDescription];
}];
[alertView addAction:defaultAction];
[alertView addAction:continueAction];
[alertView addAction:settingsAction];
[PhoneMainView.instance presentViewController:alertView animated:YES completion:nil];
}
}
liblinphone/coreapi/linphonecore.c
linphone_core_cbs_set_authentication_requested
https://github.com/BelledonneCommunications/liblinphone/blob/d73e31d6ae2e9ba4a909430b2f1ab52d004a5906/coreapi/linphonecore.c
void linphone_core_cbs_set_authentication_requested(LinphoneCoreCbs *cbs, LinphoneCoreCbsAuthenticationRequestedCb cb) {
cbs->vtable->authentication_requested = cb;
}