diff --git a/Classes/LinphoneCoreSettingsStore.h b/Classes/LinphoneCoreSettingsStore.h index ee73e33ea..224b8f679 100644 --- a/Classes/LinphoneCoreSettingsStore.h +++ b/Classes/LinphoneCoreSettingsStore.h @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import #import "IASKSettingsStore.h" @@ -28,7 +28,6 @@ NSDictionary *changedDict; } -- (void)synchronizeAccount; - (void)transformLinphoneCoreToKeys; @end diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 471fa9d3a..35ffcf31d 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -18,6 +18,7 @@ */ #import "LinphoneCoreSettingsStore.h" +#import "DTAlertView.h" #include "linphone/lpconfig.h" @@ -27,7 +28,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); - (id)init { self = [super init]; - if (self){ + if (self) { dict = [[NSMutableDictionary alloc] init]; changedDict = [[NSMutableDictionary alloc] init]; [self transformLinphoneCoreToKeys]; @@ -35,192 +36,187 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); return self; } - -- (void)transformKeysToLinphoneCore { - //LinphoneCore *lc=[LinphoneManager getLc]; - -} - -- (void)setString:(const char*)value forKey:(NSString*)key { - id obj=Nil; - if (value) obj=[[NSString alloc] initWithCString:value encoding:[NSString defaultCStringEncoding] ]; +- (void)setCString:(const char *)value forKey:(NSString *)key { + id obj = Nil; + if (value) + obj = [[NSString alloc] initWithCString:value encoding:[NSString defaultCStringEncoding]]; [self setObject:obj forKey:key]; } -- (NSString*)stringForKey:(NSString*) key { - return [self objectForKey: key]; +- (NSString *)stringForKey:(NSString *)key { + return [self objectForKey:key]; } -- (void)transformCodecsToKeys: (const MSList *)codecs { - LinphoneCore *lc=[LinphoneManager getLc]; - const MSList *elem=codecs; - for(;elem!=NULL;elem=elem->next){ - PayloadType *pt=(PayloadType*)elem->data; - NSString *pref=[LinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate]; - if (pref){ - bool_t value = linphone_core_payload_type_enabled(lc,pt); - [self setBool:value forKey: pref]; - }else{ - LOGW(@"Codec %s/%i supported by core is not shown in iOS app config view.", - pt->mime_type,pt->clock_rate); +- (void)setObject:(id)value forKey:(NSString *)key { + [dict setValue:value forKey:key]; + [changedDict setValue:[NSNumber numberWithBool:TRUE] forKey:key]; +} + +- (id)objectForKey:(NSString *)key { + return [dict valueForKey:key]; +} + +- (BOOL)valueChangedForKey:(NSString *)key { + return [[changedDict valueForKey:key] boolValue]; +} + ++ (int)validPort:(int)port { + if (port < 0) { + return 0; + } + if (port > 65535) { + return 65535; + } + return port; +} + ++ (BOOL)parsePortRange:(NSString *)text minPort:(int *)minPort maxPort:(int *)maxPort { + NSError *error = nil; + *minPort = -1; + *maxPort = -1; + NSRegularExpression *regex = + [NSRegularExpression regularExpressionWithPattern:@"([0-9]+)(([^0-9]+)([0-9]+))?" options:0 error:&error]; + if (error != NULL) + return FALSE; + NSArray *matches = [regex matchesInString:text options:0 range:NSMakeRange(0, [text length])]; + if ([matches count] == 1) { + NSTextCheckingResult *match = [matches objectAtIndex:0]; + bool range = [match rangeAtIndex:2].length > 0; + if (!range) { + NSRange rangeMinPort = [match rangeAtIndex:1]; + *minPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMinPort] intValue]]; + *maxPort = *minPort; + return TRUE; + } else { + NSRange rangeMinPort = [match rangeAtIndex:1]; + *minPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMinPort] intValue]]; + NSRange rangeMaxPort = [match rangeAtIndex:4]; + *maxPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMaxPort] intValue]]; + if (*minPort > *maxPort) { + *minPort = *maxPort; + } + return TRUE; + } + } + return FALSE; +} + +- (void)transformCodecsToKeys:(const MSList *)codecs { + LinphoneCore *lc = [LinphoneManager getLc]; + + const MSList *elem = codecs; + for (; elem != NULL; elem = elem->next) { + PayloadType *pt = (PayloadType *)elem->data; + NSString *pref = [LinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate]; + if (pref) { + bool_t value = linphone_core_payload_type_enabled(lc, pt); + [self setBool:value forKey:pref]; + } else { + LOGW(@"Codec %s/%i supported by core is not shown in iOS app config view.", pt->mime_type, pt->clock_rate); } } } - (void)transformLinphoneCoreToKeys { - LinphoneCore *lc=[LinphoneManager getLc]; - LinphoneProxyConfig *cfg=NULL; - LpConfig* conf = linphone_core_get_config(lc); - linphone_core_get_default_proxy(lc,&cfg); - if (cfg){ - const char *identity=linphone_proxy_config_get_identity(cfg); - LinphoneAddress *addr=linphone_address_new(identity); - if (addr){ - const char *proxy=linphone_proxy_config_get_addr(cfg); - LinphoneAddress *proxy_addr=linphone_address_new(proxy); - int port=linphone_address_get_port(proxy_addr); + LinphoneManager *lm = [LinphoneManager instance]; + LinphoneCore *lc = [LinphoneManager getLc]; - [self setString: linphone_address_get_username(addr) forKey:@"username_preference"]; - [self setString: linphone_address_get_domain(addr) forKey:@"domain_preference"]; - [self setInteger: linphone_proxy_config_get_expires(cfg) forKey:@"expire_preference"]; - [self setString: linphone_proxy_config_get_dial_prefix(cfg) forKey:@"prefix_preference"]; - if (strcmp(linphone_address_get_domain(addr),linphone_address_get_domain(proxy_addr))!=0 || port>0){ - char tmp[256]={0}; - if (port>0) { - snprintf(tmp,sizeof(tmp)-1,"%s:%i",linphone_address_get_domain(proxy_addr),port); - }else snprintf(tmp,sizeof(tmp)-1,"%s",linphone_address_get_domain(proxy_addr)); - [self setString:tmp forKey:@"proxy_preference"]; + // root section + { + LinphoneProxyConfig *cfg = NULL; + linphone_core_get_default_proxy(lc, &cfg); + if (cfg) { + const char *identity = linphone_proxy_config_get_identity(cfg); + LinphoneAddress *addr = linphone_address_new(identity); + if (addr) { + const char *proxy = linphone_proxy_config_get_addr(cfg); + LinphoneAddress *proxy_addr = linphone_address_new(proxy); + int port = linphone_address_get_port(proxy_addr); + + [self setCString:linphone_address_get_username(addr) forKey:@"username_preference"]; + [self setCString:linphone_address_get_domain(addr) forKey:@"domain_preference"]; + if (strcmp(linphone_address_get_domain(addr), linphone_address_get_domain(proxy_addr)) != 0 || + port > 0) { + char tmp[256] = {0}; + if (port > 0) { + snprintf(tmp, sizeof(tmp) - 1, "%s:%i", linphone_address_get_domain(proxy_addr), port); + } else + snprintf(tmp, sizeof(tmp) - 1, "%s", linphone_address_get_domain(proxy_addr)); + [self setCString:tmp forKey:@"proxy_preference"]; + } + const char *tname = "udp"; + switch (linphone_address_get_transport(proxy_addr)) { + case LinphoneTransportTcp: + tname = "tcp"; + break; + case LinphoneTransportTls: + tname = "tls"; + break; + default: + break; + } + linphone_address_destroy(addr); + linphone_address_destroy(proxy_addr); + + [self setCString:tname forKey:@"transport_preference"]; + [self setBool:(linphone_proxy_config_get_route(cfg) != NULL)forKey:@"outbound_proxy_preference"]; + [self setBool:linphone_proxy_config_avpf_enabled(cfg) forKey:@"avpf_preference"]; + [self setBool:linphone_core_video_enabled(lc) forKey:@"enable_video_preference"]; + + // actually in Advanced section but proxy config dependent + [self setInteger:linphone_proxy_config_get_expires(cfg) forKey:@"expire_preference"]; + // actually in Call section but proxy config dependent + [self setCString:linphone_proxy_config_get_dial_prefix(cfg) forKey:@"prefix_preference"]; + // actually in Call section but proxy config dependent + [self setBool:linphone_proxy_config_get_dial_escape_plus(cfg) forKey:@"substitute_+_by_00_preference"]; } - - const char* tname = "udp"; - switch (linphone_address_get_transport(proxy_addr)) { - case LinphoneTransportTcp: tname = "tcp"; break; - case LinphoneTransportTls: tname = "tls"; break; - default: break; - } - [self setString:tname forKey:@"transport_preference"]; - - linphone_address_destroy(addr); - linphone_address_destroy(proxy_addr); - - [self setBool:(linphone_proxy_config_get_route(cfg)!=NULL) forKey:@"outbound_proxy_preference"]; - [self setBool:linphone_proxy_config_get_dial_escape_plus(cfg) forKey:@"substitute_+_by_00_preference"]; - [self setBool:linphone_proxy_config_avpf_enabled(cfg) forKey:@"avpf_preference"]; - + } else { + [self setObject:@"" forKey:@"username_preference"]; + [self setObject:@"" forKey:@"password_preference"]; + [self setObject:@"" forKey:@"domain_preference"]; + [self setObject:@"" forKey:@"proxy_preference"]; + [self setCString:"udp" forKey:@"transport_preference"]; + [self setBool:FALSE forKey:@"outbound_proxy_preference"]; + [self setBool:FALSE forKey:@"avpf_preference"]; + // actually in Advanced section but proxy config dependent + [self setInteger:[lm lpConfigIntForKey:@"reg_expires" forSection:@"default_values" withDefault:600] + forKey:@"expire_preference"]; } - } else { - [self setInteger: lp_config_get_int(conf,"default_values","reg_expires", 600) forKey:@"expire_preference"]; - [self setObject:@"" forKey:@"username_preference"]; - [self setObject:@"" forKey:@"domain_preference"]; - [self setObject:@"" forKey:@"proxy_preference"]; - [self setObject:@"" forKey:@"password_preference"]; - [self setBool:FALSE forKey:@"outbound_proxy_preference"]; - [self setString:"udp" forKey:@"transport_preference"]; - [self setBool:FALSE forKey:@"avpf_preference"]; - } - - [self setBool:lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "pushnotification_preference", 0) forKey:@"pushnotification_preference"]; - { - LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed(lc); - if(parsed != NULL) { - [self setString: linphone_address_get_display_name(parsed) forKey:@"primary_displayname_preference"]; - [self setString: linphone_address_get_username(parsed) forKey:@"primary_username_preference"]; - } - linphone_address_destroy(parsed); - } - { - { - int minPort, maxPort; - linphone_core_get_audio_port_range(lc, &minPort, &maxPort); - if(minPort != maxPort) - [self setObject:[NSString stringWithFormat:@"%d-%d", minPort, maxPort] forKey:@"audio_port_preference"]; - else - [self setObject:[NSString stringWithFormat:@"%d", minPort] forKey:@"audio_port_preference"]; - } - { - int minPort, maxPort; - linphone_core_get_video_port_range(lc, &minPort, &maxPort); - if(minPort != maxPort) - [self setObject:[NSString stringWithFormat:@"%d-%d", minPort, maxPort] forKey:@"video_port_preference"]; - else - [self setObject:[NSString stringWithFormat:@"%d", minPort] forKey:@"video_port_preference"]; - } - } - { - [self setInteger: linphone_core_get_upload_bandwidth(lc) forKey:@"upload_bandwidth_preference"]; - [self setInteger: linphone_core_get_download_bandwidth(lc) forKey:@"download_bandwidth_preference"]; - } - { - [self setFloat:linphone_core_get_playback_gain_db(lc) forKey:@"playback_gain_preference"]; - [self setFloat:linphone_core_get_mic_gain_db(lc) forKey:@"microphone_gain_preference"]; - } - { - int port = lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "port_preference", 5060); - [self setInteger:port forKey:@"port_preference"]; - int random_port_preference = lp_config_get_int(conf,LINPHONERC_APPLICATION_KEY,"random_port_preference", 1); - [self setInteger:random_port_preference forKey:@"random_port_preference"]; - } - { LinphoneAuthInfo *ai; - const MSList *elem=linphone_core_get_auth_info_list(lc); - if (elem && (ai=(LinphoneAuthInfo*)elem->data)){ - [self setString: linphone_auth_info_get_passwd(ai) forKey:@"password_preference"]; - [self setString: linphone_auth_info_get_ha1(ai) forKey:@"ha1_preference"]; // hidden but useful if provisioned - [self setString:linphone_auth_info_get_userid(ai) forKey:@"userid_preference"]; + const MSList *elem = linphone_core_get_auth_info_list(lc); + if (elem && (ai = (LinphoneAuthInfo *)elem->data)) { + [self setCString:linphone_auth_info_get_userid(ai) forKey:@"userid_preference"]; + [self setCString:linphone_auth_info_get_passwd(ai) forKey:@"password_preference"]; + // hidden but useful if provisioned + [self setCString:linphone_auth_info_get_ha1(ai) forKey:@"ha1_preference"]; } - } - { - [self setString: linphone_core_get_stun_server(lc) forKey:@"stun_preference"]; - [self setBool:linphone_core_get_firewall_policy(lc)==LinphonePolicyUseIce forKey:@"ice_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"advanced_account_preference"] forKey:@"advanced_account_preference"]; } + // audio section { - [self transformCodecsToKeys: linphone_core_get_audio_codecs(lc)]; - [self transformCodecsToKeys: linphone_core_get_video_codecs(lc)]; - [self setBool:linphone_core_adaptive_rate_control_enabled(lc) forKey:@"adaptive_rate_control_preference"]; - [self setString:linphone_core_get_adaptive_rate_algorithm(lc) forKey:@"adaptive_rate_algorithm_preference"]; - - [self setInteger:lp_config_get_int(conf, "audio", "codec_bitrate_limit", kLinphoneAudioVbrCodecDefaultBitrate) forKey:@"audio_codec_bitrate_limit_preference"]; - [self setInteger:lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "voiceproc_preference", 1) forKey:@"voiceproc_preference"]; - [self setInteger:lp_config_get_int(conf, "sound", "eq_active", 0) forKey:@"eq_active"]; + [self transformCodecsToKeys:linphone_core_get_audio_codecs(lc)]; + [self setFloat:linphone_core_get_playback_gain_db(lc) forKey:@"playback_gain_preference"]; + [self setFloat:linphone_core_get_mic_gain_db(lc) forKey:@"microphone_gain_preference"]; + [self setInteger:[lm lpConfigIntForKey:@"codec_bitrate_limit" + forSection:@"audio" + withDefault:kLinphoneAudioVbrCodecDefaultBitrate] + forKey:@"audio_codec_bitrate_limit_preference"]; + [self setInteger:[lm lpConfigIntForKey:@"voiceproc_preference" withDefault:1] forKey:@"voiceproc_preference"]; + [self setInteger:[lm lpConfigIntForKey:@"eq_active" forSection:@"sound" withDefault:0] forKey:@"eq_active"]; } - [self setBool:lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "advanced_account_preference", 0) forKey:@"advanced_account_preference"]; - + // video section { - LinphoneMediaEncryption menc=linphone_core_get_media_encryption(lc); - const char *val; - switch(menc){ - case LinphoneMediaEncryptionSRTP: val="SRTP"; break; - case LinphoneMediaEncryptionZRTP: val="ZRTP"; break; - case LinphoneMediaEncryptionDTLS: val="DTLS"; break; - case LinphoneMediaEncryptionNone: val="None"; break; - } - [self setString:val forKey:@"media_encryption_preference"]; - } - [self setBool: lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "edge_opt_preference", 0) forKey:@"edge_opt_preference"]; - [self setBool: lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "enable_first_login_view_preference", 0) forKey:@"enable_first_login_view_preference"]; - [self setBool: lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "debugenable_preference", 0) forKey:@"debugenable_preference"]; - [self setBool: lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "animations_preference", 1) forKey:@"animations_preference"]; - [self setBool: lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "wifi_only_preference", 0) forKey:@"wifi_only_preference"]; - [self setString: lp_config_get_string(conf, LINPHONERC_APPLICATION_KEY, "sharing_server_preference", NULL) forKey:@"sharing_server_preference"]; - [self setBool:lp_config_get_int(conf, "sip", "use_ipv6", 0) forKey:@"use_ipv6"]; + [self transformCodecsToKeys:linphone_core_get_video_codecs(lc)]; - - [self setBool: lp_config_get_int(conf,LINPHONERC_APPLICATION_KEY,"start_at_boot_preference",1) forKey:@"start_at_boot_preference"]; - [self setBool: lp_config_get_int(conf,LINPHONERC_APPLICATION_KEY,"backgroundmode_preference",1) forKey:@"backgroundmode_preference"]; - [self setBool: lp_config_get_int(conf,LINPHONERC_APPLICATION_KEY,"autoanswer_notif_preference",1) forKey:@"autoanswer_notif_preference"]; - - - { const LinphoneVideoPolicy *pol; - [self setBool: linphone_core_video_enabled(lc) forKey:@"enable_video_preference"]; - pol=linphone_core_get_video_policy(lc); - [self setBool:(pol->automatically_initiate) forKey:@"start_video_preference"]; - [self setBool:(pol->automatically_accept) forKey:@"accept_video_preference"]; + pol = linphone_core_get_video_policy(lc); + [self setBool:(pol->automatically_initiate)forKey:@"start_video_preference"]; + [self setBool:(pol->automatically_accept)forKey:@"accept_video_preference"]; [self setBool:linphone_core_self_view_enabled(lc) forKey:@"self_video_preference"]; - BOOL previewEnabled=lp_config_get_int(conf,LINPHONERC_APPLICATION_KEY,"preview_preference",1); + BOOL previewEnabled = [lm lpConfigBoolForKey:@"preview_preference" withDefault:YES]; [self setBool:previewEnabled forKey:@"preview_preference"]; MSVideoSize vsize = linphone_core_get_preferred_video_size(lc); int index; @@ -233,6 +229,8 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } [self setInteger:index forKey:@"video_preferred_size_preference"]; } + + // call section { [self setBool:linphone_core_get_use_info_for_dtmf(lc) forKey:@"sipinfo_dtmf_preference"]; [self setBool:linphone_core_get_use_rfc2833_for_dtmf(lc) forKey:@"rfc_dtmf_preference"]; @@ -241,21 +239,96 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); [self setInteger:linphone_core_get_in_call_timeout(lc) forKey:@"in_call_timeout_preference"]; } - // Tunnel - if (linphone_core_tunnel_available()){ + // network section + { + [self setBool:[lm lpConfigBoolForKey:@"edge_opt_preference" withDefault:NO] forKey:@"edge_opt_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"wifi_only_preference" withDefault:NO] forKey:@"wifi_only_preference"]; + [self setCString:linphone_core_get_stun_server(lc) forKey:@"stun_preference"]; + [self setBool:linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce forKey:@"ice_preference"]; + int random_port_preference = [lm lpConfigIntForKey:@"random_port_preference" withDefault:1]; + [self setInteger:random_port_preference forKey:@"random_port_preference"]; + int port = [lm lpConfigIntForKey:@"port_preference" withDefault:5060]; + [self setInteger:port forKey:@"port_preference"]; + { + int minPort, maxPort; + linphone_core_get_audio_port_range(lc, &minPort, &maxPort); + if (minPort != maxPort) + [self setObject:[NSString stringWithFormat:@"%d-%d", minPort, maxPort] forKey:@"audio_port_preference"]; + else + [self setObject:[NSString stringWithFormat:@"%d", minPort] forKey:@"audio_port_preference"]; + } + { + int minPort, maxPort; + linphone_core_get_video_port_range(lc, &minPort, &maxPort); + if (minPort != maxPort) + [self setObject:[NSString stringWithFormat:@"%d-%d", minPort, maxPort] forKey:@"video_port_preference"]; + else + [self setObject:[NSString stringWithFormat:@"%d", minPort] forKey:@"video_port_preference"]; + } + [self setBool:[lm lpConfigBoolForKey:@"use_ipv6" withDefault:NO] forKey:@"use_ipv6"]; + LinphoneMediaEncryption menc = linphone_core_get_media_encryption(lc); + const char *val; + switch (menc) { + case LinphoneMediaEncryptionSRTP: + val = "SRTP"; + break; + case LinphoneMediaEncryptionZRTP: + val = "ZRTP"; + break; + case LinphoneMediaEncryptionDTLS: + val = "DTLS"; + break; + case LinphoneMediaEncryptionNone: + val = "None"; + break; + } + [self setCString:val forKey:@"media_encryption_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"pushnotification_preference" withDefault:NO] + forKey:@"pushnotification_preference"]; + [self setInteger:linphone_core_get_upload_bandwidth(lc) forKey:@"upload_bandwidth_preference"]; + [self setInteger:linphone_core_get_download_bandwidth(lc) forKey:@"download_bandwidth_preference"]; + [self setBool:linphone_core_adaptive_rate_control_enabled(lc) forKey:@"adaptive_rate_control_preference"]; + [self setCString:linphone_core_get_adaptive_rate_algorithm(lc) forKey:@"adaptive_rate_algorithm_preference"]; + } + + // tunnel section + if (linphone_core_tunnel_available()) { LinphoneTunnel *tunnel = linphone_core_get_tunnel([LinphoneManager getLc]); - [self setString:lp_config_get_string(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "tunnel_mode_preference", "off") forKey:@"tunnel_mode_preference"]; - const MSList* configs = linphone_tunnel_get_servers(tunnel); - if(configs != NULL) { + [self setObject:[lm lpConfigStringForKey:@"tunnel_mode_preference" withDefault:@"off"] + forKey:@"tunnel_mode_preference"]; + const MSList *configs = linphone_tunnel_get_servers(tunnel); + if (configs != NULL) { LinphoneTunnelConfig *ltc = (LinphoneTunnelConfig *)configs->data; - [self setString:linphone_tunnel_config_get_host(ltc) forKey:@"tunnel_address_preference"]; + [self setCString:linphone_tunnel_config_get_host(ltc) forKey:@"tunnel_address_preference"]; [self setInteger:linphone_tunnel_config_get_port(ltc) forKey:@"tunnel_port_preference"]; } else { - [self setString:"" forKey:@"tunnel_address_preference"]; + [self setCString:"" forKey:@"tunnel_address_preference"]; [self setInteger:443 forKey:@"tunnel_port_preference"]; } } + // advanced section + { + [self setBool:[lm lpConfigBoolForKey:@"debugenable_preference" withDefault:NO] + forKey:@"debugenable_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"animations_preference" withDefault:NO] forKey:@"animations_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"backgroundmode_preference" withDefault:NO] + forKey:@"backgroundmode_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"start_at_boot_preference" withDefault:NO] + forKey:@"start_at_boot_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"autoanswer_notif_preference" withDefault:NO] + forKey:@"autoanswer_notif_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"enable_first_login_view_preference" withDefault:NO] + forKey:@"enable_first_login_view_preference"]; + LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed(lc); + if (parsed != NULL) { + [self setCString:linphone_address_get_display_name(parsed) forKey:@"primary_displayname_preference"]; + [self setCString:linphone_address_get_username(parsed) forKey:@"primary_username_preference"]; + } + linphone_address_destroy(parsed); + [self setObject:[lm lpConfigStringForKey:@"sharing_server_preference"] forKey:@"sharing_server_preference"]; + } + changedDict = [[NSMutableDictionary alloc] init]; // Post event @@ -263,48 +336,31 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneLogsUpdate object:self userInfo:eventDic]; } -- (void)setObject:(id)value forKey:(NSString *)key { - [dict setValue:value forKey:key]; - [changedDict setValue:[NSNumber numberWithBool:TRUE] forKey:key]; -} - -- (id)objectForKey:(NSString*)key { - return [dict valueForKey:key]; -} - -- (BOOL)valueChangedForKey:(NSString*)key { - return [[changedDict valueForKey:key] boolValue]; -} - -- (void)alertAccountError:(NSString*)error { - UIAlertView* alertview = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) +- (void)alertAccountError:(NSString *)error { + UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:error delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) - otherButtonTitles: nil]; + otherButtonTitles:nil]; [alertview show]; } -+ (BOOL)hasSipPrefix:(NSString*)str { - return [str hasPrefix:@"sip:"] || [str hasPrefix:@"sips:"]; -} - - (void)synchronizeAccount { + LinphoneManager *lm = [LinphoneManager instance]; LinphoneCore *lc = [LinphoneManager getLc]; - LpConfig* conf = linphone_core_get_config(lc); - LinphoneProxyConfig* proxyCfg = NULL; + LinphoneProxyConfig *proxyCfg = NULL; BOOL isEditing = FALSE; - NSString* error = nil; + NSString *error = nil; int port_preference = [self integerForKey:@"port_preference"]; BOOL random_port_preference = [self boolForKey:@"random_port_preference"]; - lp_config_set_int(conf, LINPHONERC_APPLICATION_KEY, "random_port_preference", random_port_preference); - if(random_port_preference) { + [lm lpConfigSetInt:random_port_preference forKey:@"random_port_preference"]; + if (random_port_preference) { port_preference = -1; } - LCSipTransports transportValue={ port_preference, port_preference, -1, -1 }; + LCSipTransports transportValue = {port_preference, port_preference, -1, -1}; // will also update the sip_*_port section of the config if (linphone_core_set_sip_transports(lc, &transportValue)) { @@ -314,54 +370,55 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); port_preference = linphone_core_get_sip_port(lc); [self setInteger:port_preference forKey:@"port_preference"]; // Update back preference - BOOL enable_ipv6 = [self boolForKey:@"use_ipv6"]; - lp_config_set_int(conf, "sip", "use_ipv6", enable_ipv6); - if( linphone_core_ipv6_enabled(lc) != enable_ipv6){ - LOGD(@"%@ IPV6", enable_ipv6?@"ENABLING":@"DISABLING"); + [lm lpConfigSetBool:enable_ipv6 forKey:@"use_ipv6" forSection:@"sip"]; + if (linphone_core_ipv6_enabled(lc) != enable_ipv6) { + LOGD(@"%@ IPV6", enable_ipv6 ? @"ENABLING" : @"DISABLING"); linphone_core_enable_ipv6(lc, enable_ipv6); } + // configure sip account - //configure sip account + // mandatory parameters + NSString *username = [self stringForKey:@"username_preference"]; + NSString *userID = [self stringForKey:@"userid_preference"]; + NSString *domain = [self stringForKey:@"domain_preference"]; + NSString *transport = [self stringForKey:@"transport_preference"]; + NSString *accountHa1 = [self stringForKey:@"ha1_preference"]; + NSString *accountPassword = [self stringForKey:@"password_preference"]; + bool isOutboundProxy = [self boolForKey:@"outbound_proxy_preference"]; + BOOL use_avpf = [self boolForKey:@"avpf_preference"]; - //mandatory parameters - NSString* username = [self stringForKey:@"username_preference"]; - NSString* userID = [self stringForKey:@"userid_preference"]; - NSString* domain = [self stringForKey:@"domain_preference"]; - NSString* transport = [self stringForKey:@"transport_preference"]; - NSString* accountHa1 = [self stringForKey:@"ha1_preference"]; - NSString* accountPassword = [self stringForKey:@"password_preference"]; - bool isOutboundProxy = [self boolForKey:@"outbound_proxy_preference"]; - BOOL use_avpf = [self boolForKey:@"avpf_preference"]; + if (username && [username length] > 0 && domain && [domain length] > 0) { + int expire = [self integerForKey:@"expire_preference"]; + BOOL isWifiOnly = [self boolForKey:@"wifi_only_preference"]; + BOOL pushnotification = [self boolForKey:@"pushnotification_preference"]; + NSString *prefix = [self stringForKey:@"prefix_preference"]; + NSString *proxyAddress = [self stringForKey:@"proxy_preference"]; - if (username && [username length] >0 && domain && [domain length]>0) { - int expire = [self integerForKey:@"expire_preference"]; - BOOL isWifiOnly = [self boolForKey:@"wifi_only_preference"]; - BOOL pushnotification = [self boolForKey:@"pushnotification_preference"]; - NSString* prefix = [self stringForKey:@"prefix_preference"]; - NSString* proxyAddress = [self stringForKey:@"proxy_preference"]; + LinphoneAuthInfo *info = NULL; + const char *route = NULL; - LinphoneAuthInfo *info = NULL; - const char* route = NULL; + if (isWifiOnly && [LinphoneManager instance].connectivity == wwan) + expire = 0; - if( isWifiOnly && [LinphoneManager instance].connectivity == wwan ) expire = 0; - - if ((!proxyAddress || [proxyAddress length] <1 ) && domain) { + if ((!proxyAddress || [proxyAddress length] < 1) && domain) { proxyAddress = domain; - } - - if( ![LinphoneCoreSettingsStore hasSipPrefix:proxyAddress] ) { - proxyAddress = [NSString stringWithFormat:@"sip:%@",proxyAddress]; } - char* proxy = ms_strdup([proxyAddress cStringUsingEncoding:[NSString defaultCStringEncoding]]); - LinphoneAddress* proxy_addr = linphone_address_new(proxy); + if (![proxyAddress hasPrefix:@"sip:"] && ![proxyAddress hasPrefix:@"sips:"]) { + proxyAddress = [NSString stringWithFormat:@"sip:%@", proxyAddress]; + } - if( proxy_addr ){ + char *proxy = ms_strdup([proxyAddress cStringUsingEncoding:[NSString defaultCStringEncoding]]); + LinphoneAddress *proxy_addr = linphone_address_new(proxy); + + if (proxy_addr) { LinphoneTransportType type = LinphoneTransportUdp; - if ( [transport isEqualToString:@"tcp"] ) type = LinphoneTransportTcp; - else if ( [transport isEqualToString:@"tls"] ) type = LinphoneTransportTls; + if ([transport isEqualToString:@"tcp"]) + type = LinphoneTransportTcp; + else if ([transport isEqualToString:@"tls"]) + type = LinphoneTransportTls; linphone_address_set_transport(proxy_addr, type); ms_free(proxy); @@ -369,11 +426,11 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } // use proxy as route if outbound_proxy is enabled - route = isOutboundProxy? proxy : NULL; + route = isOutboundProxy ? proxy : NULL; - //possible valid config detected, try to modify current proxy or create new one if none existing + // possible valid config detected, try to modify current proxy or create new one if none existing linphone_core_get_default_proxy(lc, &proxyCfg); - if( proxyCfg == NULL ){ + if (proxyCfg == NULL) { proxyCfg = linphone_core_create_proxy_config(lc); } else { isEditing = TRUE; @@ -381,30 +438,41 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } char normalizedUserName[256]; - LinphoneAddress* linphoneAddress = linphone_address_new("sip:user@domain.com"); - linphone_proxy_config_normalize_number(proxyCfg, [username cStringUsingEncoding:[NSString defaultCStringEncoding]], normalizedUserName, sizeof(normalizedUserName)); + LinphoneAddress *linphoneAddress = linphone_address_new("sip:user@domain.com"); + linphone_proxy_config_normalize_number(proxyCfg, + [username cStringUsingEncoding:[NSString defaultCStringEncoding]], + normalizedUserName, sizeof(normalizedUserName)); linphone_address_set_username(linphoneAddress, normalizedUserName); linphone_address_set_domain(linphoneAddress, [domain cStringUsingEncoding:[NSString defaultCStringEncoding]]); - const char* identity = linphone_address_as_string_uri_only(linphoneAddress); - const char* password = [accountPassword cStringUsingEncoding:[NSString defaultCStringEncoding]]; - const char* ha1 = [accountHa1 cStringUsingEncoding:[NSString defaultCStringEncoding]]; + const char *identity = linphone_address_as_string_uri_only(linphoneAddress); + const char *password = [accountPassword cStringUsingEncoding:[NSString defaultCStringEncoding]]; + const char *ha1 = [accountHa1 cStringUsingEncoding:[NSString defaultCStringEncoding]]; + if (linphone_proxy_config_set_identity(proxyCfg, identity) == -1) { + error = NSLocalizedString(@"Invalid username or domain", nil); + goto bad_proxy; + } + if (linphone_proxy_config_set_server_addr(proxyCfg, proxy) == -1) { + error = NSLocalizedString(@"Invalid proxy address", nil); + goto bad_proxy; + } + if (linphone_proxy_config_set_route(proxyCfg, route) == -1) { + error = NSLocalizedString(@"Invalid route", nil); + goto bad_proxy; + } - if( linphone_proxy_config_set_identity(proxyCfg, identity) == -1 ) { error = NSLocalizedString(@"Invalid username or domain",nil); goto bad_proxy;} - if( linphone_proxy_config_set_server_addr(proxyCfg, proxy) == -1 ) { error = NSLocalizedString(@"Invalid proxy address", nil); goto bad_proxy; } - if( linphone_proxy_config_set_route(proxyCfg, route) == -1 ) { error = NSLocalizedString(@"Invalid route", nil); goto bad_proxy; } - - if ([prefix length]>0) { - linphone_proxy_config_set_dial_prefix(proxyCfg, [prefix cStringUsingEncoding:[NSString defaultCStringEncoding]]); + if ([prefix length] > 0) { + linphone_proxy_config_set_dial_prefix(proxyCfg, + [prefix cStringUsingEncoding:[NSString defaultCStringEncoding]]); } if ([self objectForKey:@"substitute_+_by_00_preference"]) { bool substitute_plus_by_00 = [self boolForKey:@"substitute_+_by_00_preference"]; - linphone_proxy_config_set_dial_escape_plus(proxyCfg,substitute_plus_by_00); + linphone_proxy_config_set_dial_escape_plus(proxyCfg, substitute_plus_by_00); } - lp_config_set_int(conf, LINPHONERC_APPLICATION_KEY, "pushnotification_preference", pushnotification); + [lm lpConfigSetInt:pushnotification forKey:@"pushnotification_preference"]; [[LinphoneManager instance] configurePushTokenForProxyConfig:proxyCfg]; linphone_proxy_config_enable_register(proxyCfg, true); @@ -413,9 +481,10 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); // setup auth info LinphoneAddress *from = linphone_address_new(identity); - if (from != 0){ - const char* userid_str = (userID != nil)? [userID UTF8String] : NULL; - info=linphone_auth_info_new(linphone_address_get_username(from),userid_str,password,ha1,NULL,linphone_proxy_config_get_domain(proxyCfg)); + if (from != 0) { + const char *userid_str = (userID != nil) ? [userID UTF8String] : NULL; + info = linphone_auth_info_new(linphone_address_get_username(from), userid_str, password, ha1, NULL, + linphone_proxy_config_get_domain(proxyCfg)); linphone_address_destroy(from); } @@ -423,178 +492,120 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); // add auth info linphone_core_clear_all_auth_info(lc); - if( info ) { linphone_core_add_auth_info(lc,info); } + if (info) { + linphone_core_add_auth_info(lc, info); + } // setup new proxycfg - if( isEditing ){ + if (isEditing) { linphone_proxy_config_done(proxyCfg); } else { // was a new proxy config, add it linphone_core_add_proxy_config(lc, proxyCfg); - linphone_core_set_default_proxy_config(lc,proxyCfg); + linphone_core_set_default_proxy_config(lc, proxyCfg); } bad_proxy: - if( linphoneAddress) + if (linphoneAddress) linphone_address_destroy(linphoneAddress); - if( proxy) + if (proxy) ms_free(proxy); - if( info ) + if (info) linphone_auth_info_destroy(info); // in case of error, show an alert to the user - if( error != nil ){ - if( isEditing ) linphone_proxy_config_done(proxyCfg); - else linphone_proxy_config_destroy(proxyCfg); + if (error != nil) { + if (isEditing) + linphone_proxy_config_done(proxyCfg); + else + linphone_proxy_config_destroy(proxyCfg); - [self alertAccountError:error]; + [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) + message:error + delegate:nil + cancelButtonTitle:NSLocalizedString(@"OK", nil) + otherButtonTitles:nil] show]; } } [[[LinphoneManager instance] fastAddressBook] reload]; } -+ (int)validPort:(int)port { - if(port < 0) { - return 0; - } - if(port > 65535) { - return 65535; - } - return port; -} - -+ (BOOL)parsePortRange:(NSString*)text minPort:(int*)minPort maxPort:(int*)maxPort { - NSError* error = nil; - *minPort = -1; - *maxPort = -1; - NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"([0-9]+)(([^0-9]+)([0-9]+))?" options:0 error:&error]; - if(error != NULL) - return FALSE; - NSArray* matches = [regex matchesInString:text options:0 range:NSMakeRange(0, [text length])]; - if([matches count] == 1) { - NSTextCheckingResult *match = [matches objectAtIndex:0]; - bool range = [match rangeAtIndex:2].length > 0; - if(!range) { - NSRange rangeMinPort = [match rangeAtIndex:1]; - *minPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMinPort] intValue]]; - *maxPort = *minPort; - return TRUE; - } else { - NSRange rangeMinPort = [match rangeAtIndex:1]; - *minPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMinPort] intValue]]; - NSRange rangeMaxPort = [match rangeAtIndex:4]; - *maxPort = [LinphoneCoreSettingsStore validPort:[[text substringWithRange:rangeMaxPort] intValue]]; - if(*minPort > *maxPort) { - *minPort = *maxPort; - } - return TRUE; - } - } - return FALSE; -} - -- (BOOL)synchronize { - LinphoneCore *lc=[LinphoneManager getLc]; - - BOOL account_changed; - - account_changed=[self valueChangedForKey:@"username_preference"] - || [self valueChangedForKey:@"password_preference"] - || [self valueChangedForKey:@"domain_preference"] - || [self valueChangedForKey:@"expire_preference"] - || [self valueChangedForKey:@"proxy_preference"] - || [self valueChangedForKey:@"outbound_proxy_preference"] - || [self valueChangedForKey:@"transport_preference"] - || [self valueChangedForKey:@"port_preference"] - || [self valueChangedForKey:@"random_port_preference"] - || [self valueChangedForKey:@"prefix_preference"] - || [self valueChangedForKey:@"substitute_+_by_00_preference"] - || [self valueChangedForKey:@"use_ipv6"] - || [self valueChangedForKey:@"avpf_preference"] - || [self valueChangedForKey:@"pushnotification_preference"]; - - if (account_changed) - [self synchronizeAccount]; - - //Configure Codecs - +- (void)synchronizeCodecs:(const MSList *)codecs { + LinphoneCore *lc = [LinphoneManager getLc]; PayloadType *pt; const MSList *elem; - for (elem=linphone_core_get_audio_codecs(lc);elem!=NULL;elem=elem->next){ - pt=(PayloadType*)elem->data; - NSString *pref=[LinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate]; - linphone_core_enable_payload_type(lc,pt,[self boolForKey: pref]); + for (elem = codecs; elem != NULL; elem = elem->next) { + pt = (PayloadType *)elem->data; + NSString *pref = [LinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate]; + linphone_core_enable_payload_type(lc, pt, [self boolForKey:pref]); + } +} + +- (BOOL)synchronize { + LinphoneManager *lm = [LinphoneManager instance]; + LinphoneCore *lc = [LinphoneManager getLc]; + // root section + { + BOOL account_changed = + [self valueChangedForKey:@"username_preference"] || [self valueChangedForKey:@"password_preference"] || + [self valueChangedForKey:@"domain_preference"] || [self valueChangedForKey:@"expire_preference"] || + [self valueChangedForKey:@"proxy_preference"] || [self valueChangedForKey:@"outbound_proxy_preference"] || + [self valueChangedForKey:@"transport_preference"] || [self valueChangedForKey:@"port_preference"] || + [self valueChangedForKey:@"random_port_preference"] || [self valueChangedForKey:@"prefix_preference"] || + [self valueChangedForKey:@"substitute_+_by_00_preference"] || [self valueChangedForKey:@"use_ipv6"] || + [self valueChangedForKey:@"avpf_preference"] || [self valueChangedForKey:@"pushnotification_preference"]; + if (account_changed) + [self synchronizeAccount]; + + bool enableVideo = [self boolForKey:@"enable_video_preference"]; + linphone_core_enable_video(lc, enableVideo, enableVideo); } - for (elem=linphone_core_get_video_codecs(lc);elem!=NULL;elem=elem->next){ - pt=(PayloadType*)elem->data; - NSString *pref=[LinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate]; - linphone_core_enable_payload_type(lc,pt,[self boolForKey: pref]); - } + // audio section + { + [self synchronizeCodecs:linphone_core_get_audio_codecs(lc)]; - LpConfig *config = linphone_core_get_config(lc); - lp_config_set_int(config, "audio", "codec_bitrate_limit", [self integerForKey:@"audio_codec_bitrate_limit_preference"]); - [[LinphoneManager instance] configureVbrCodecs]; - linphone_core_enable_adaptive_rate_control(lc, [self boolForKey:@"adaptive_rate_control_preference"]); - linphone_core_set_adaptive_rate_algorithm(lc, [ - [self stringForKey:@"adaptive_rate_algorithm_preference"] cStringUsingEncoding:[NSString defaultCStringEncoding] - ]); + float playback_gain = [self floatForKey:@"playback_gain_preference"]; + linphone_core_set_playback_gain_db(lc, playback_gain); - // Voice processing - BOOL voice_processing = [self boolForKey:@"voiceproc_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "voiceproc_preference", voice_processing); - NSString* au_device = @"AU: Audio Unit Receiver"; - if( !voice_processing ){ au_device = @"AU: Audio Unit NoVoiceProc"; } - linphone_core_set_capture_device(lc, [au_device UTF8String]); - linphone_core_set_playback_device(lc, [au_device UTF8String]); + float mic_gain = [self floatForKey:@"microphone_gain_preference"]; + linphone_core_set_mic_gain_db(lc, mic_gain); - BOOL equalizer = [self boolForKey:@"eq_active"]; - lp_config_set_int(config, "sound", "eq_active", equalizer); + [lm lpConfigSetInt:[self integerForKey:@"audio_codec_bitrate_limit_preference"] + forKey:@"codec_bitrate_limit" + forSection:@"audio"]; - linphone_core_set_use_info_for_dtmf(lc, [self boolForKey:@"sipinfo_dtmf_preference"]); - linphone_core_set_use_rfc2833_for_dtmf(lc, [self boolForKey:@"rfc_dtmf_preference"]); - linphone_core_set_inc_timeout(lc, [self integerForKey:@"incoming_call_timeout_preference"]); - linphone_core_set_in_call_timeout(lc, [self integerForKey:@"in_call_timeout_preference"]); - lp_config_set_string(config, "app", "voice_mail_uri", [[self stringForKey:@"voice_mail_uri_preference"] UTF8String]); + BOOL voice_processing = [self boolForKey:@"voiceproc_preference"]; + [lm lpConfigSetInt:voice_processing forKey:@"voiceproc_preference"]; - bool enableVideo = [self boolForKey:@"enable_video_preference"]; - linphone_core_enable_video(lc, enableVideo, enableVideo); + BOOL equalizer = [self boolForKey:@"eq_active"]; + [lm lpConfigSetBool:equalizer forKey:@"eq_active" forSection:@"sound"]; - NSString *menc = [self stringForKey:@"media_encryption_preference"]; - if (menc && [menc compare:@"SRTP"] == NSOrderedSame) - linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionSRTP); - else if (menc && [menc compare:@"ZRTP"] == NSOrderedSame) - linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionZRTP); - else if (menc && [menc compare:@"DTLS"] == NSOrderedSame) - linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionDTLS); - else - linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionNone); + [[LinphoneManager instance] configureVbrCodecs]; - NSString* stun_server = [self stringForKey:@"stun_preference"]; - if ([stun_server length] > 0){ - linphone_core_set_stun_server(lc, [stun_server UTF8String]); - BOOL ice_preference = [self boolForKey:@"ice_preference"]; - if(ice_preference) { - linphone_core_set_firewall_policy(lc, LinphonePolicyUseIce); - } else { - linphone_core_set_firewall_policy(lc, LinphonePolicyUseStun); + NSString *au_device = @"AU: Audio Unit Receiver"; + if (!voice_processing) { + au_device = @"AU: Audio Unit NoVoiceProc"; } - } else { - linphone_core_set_stun_server(lc, NULL); - linphone_core_set_firewall_policy(lc, LinphonePolicyNoFirewall); + linphone_core_set_capture_device(lc, [au_device UTF8String]); + linphone_core_set_playback_device(lc, [au_device UTF8String]); } - LinphoneVideoPolicy policy; - policy.automatically_accept = [self boolForKey:@"accept_video_preference"]; - policy.automatically_initiate = [self boolForKey:@"start_video_preference"]; - linphone_core_set_video_policy(lc, &policy); - linphone_core_enable_self_view(lc, [self boolForKey:@"self_video_preference"]); - BOOL preview_preference=[self boolForKey:@"preview_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "preview_preference", preview_preference); - MSVideoSize vsize; - int bw; - switch ([self integerForKey:@"video_preferred_size_preference"]) { + // video section + { + [self synchronizeCodecs:linphone_core_get_video_codecs(lc)]; + + LinphoneVideoPolicy policy; + policy.automatically_initiate = [self boolForKey:@"start_video_preference"]; + policy.automatically_accept = [self boolForKey:@"accept_video_preference"]; + linphone_core_set_video_policy(lc, &policy); + linphone_core_enable_self_view(lc, [self boolForKey:@"self_video_preference"]); + BOOL preview_preference = [self boolForKey:@"preview_preference"]; + [lm lpConfigSetInt:preview_preference forKey:@"preview_preference"]; + int bw; + MSVideoSize vsize; + switch ([self integerForKey:@"video_preferred_size_preference"]) { case 0: MS_VIDEO_SIZE_ASSIGN(vsize, 720P); // 128 = margin for audio, the BW includes both video and audio @@ -611,124 +622,152 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); MS_VIDEO_SIZE_ASSIGN(vsize, QVGA); bw = 380; break; - } - linphone_core_set_preferred_video_size(lc, vsize); - [self setInteger: bw forKey:@"upload_bandwidth_preference"]; - [self setInteger: bw forKey:@"download_bandwidth_preference"]; - - // Primary contact - NSString* displayname = [self stringForKey:@"primary_displayname_preference"]; - NSString* username = [self stringForKey:@"primary_username_preference"]; - LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed(lc); - if(parsed != NULL) { - linphone_address_set_display_name(parsed,[displayname cStringUsingEncoding:[NSString defaultCStringEncoding]]); - linphone_address_set_username(parsed,[username cStringUsingEncoding:[NSString defaultCStringEncoding]]); - char *contact = linphone_address_as_string(parsed); - linphone_core_set_primary_contact(lc, contact); - ms_free(contact); - linphone_address_destroy(parsed); + } + [self setInteger:bw forKey:@"upload_bandwidth_preference"]; + [self setInteger:bw forKey:@"download_bandwidth_preference"]; + linphone_core_set_preferred_video_size(lc, vsize); } - - // Audio & Video Port + // call section { - NSString *audio_port_preference = [self stringForKey:@"audio_port_preference"]; - int minPort, maxPort; - [LinphoneCoreSettingsStore parsePortRange:audio_port_preference minPort:&minPort maxPort:&maxPort]; - linphone_core_set_audio_port_range(lc, minPort, maxPort); + linphone_core_set_use_rfc2833_for_dtmf(lc, [self boolForKey:@"rfc_dtmf_preference"]); + linphone_core_set_use_info_for_dtmf(lc, [self boolForKey:@"sipinfo_dtmf_preference"]); + linphone_core_set_inc_timeout(lc, [self integerForKey:@"incoming_call_timeout_preference"]); + linphone_core_set_in_call_timeout(lc, [self integerForKey:@"in_call_timeout_preference"]); + [[LinphoneManager instance] lpConfigSetString:[self stringForKey:@"voice_mail_uri_preference"] + forKey:@"voice_mail_uri"]; } + + // network section { - NSString *video_port_preference = [self stringForKey:@"video_port_preference"]; - int minPort, maxPort; - [LinphoneCoreSettingsStore parsePortRange:video_port_preference minPort:&minPort maxPort:&maxPort]; - linphone_core_set_video_port_range(lc, minPort, maxPort); - } + BOOL edgeOpt = [self boolForKey:@"edge_opt_preference"]; + [lm lpConfigSetInt:edgeOpt forKey:@"edge_opt_preference"]; - int upload_bandwidth = [self integerForKey:@"upload_bandwidth_preference"]; - linphone_core_set_upload_bandwidth(lc, upload_bandwidth); - - int download_bandwidth = [self integerForKey:@"download_bandwidth_preference"]; - linphone_core_set_download_bandwidth(lc, download_bandwidth); - - float playback_gain = [self floatForKey:@"playback_gain_preference"]; - linphone_core_set_playback_gain_db(lc, playback_gain); - - float mic_gain = [self floatForKey:@"microphone_gain_preference"]; - linphone_core_set_mic_gain_db(lc, mic_gain); - - UIDevice* device = [UIDevice currentDevice]; - bool backgroundSupported = false; - if ([device respondsToSelector:@selector(isMultitaskingSupported)]) - backgroundSupported = [device isMultitaskingSupported]; - BOOL isbackgroundModeEnabled; - if (backgroundSupported) { - isbackgroundModeEnabled = [self boolForKey:@"backgroundmode_preference"]; - } else { - isbackgroundModeEnabled = false; - } - - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "backgroundmode_preference", isbackgroundModeEnabled); - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "start_at_boot_preference", [self boolForKey:@"start_at_boot_preference"]); - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "autoanswer_notif_preference", [self boolForKey:@"autoanswer_notif_preference"]); - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "advanced_account_preference", [self boolForKey:@"advanced_account_preference"]); - - BOOL firstloginview = [self boolForKey:@"enable_first_login_view_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "enable_first_login_view_preference", firstloginview); - - BOOL edgeOpt = [self boolForKey:@"edge_opt_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "edge_opt_preference", edgeOpt); - - BOOL debugmode = [self boolForKey:@"debugenable_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "debugenable_preference", debugmode); - [[LinphoneManager instance] setLogsEnabled:debugmode]; - - BOOL animations = [self boolForKey:@"animations_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "animations_preference", animations); - - BOOL wifiOnly = [self boolForKey:@"wifi_only_preference"]; - lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "wifi_only_preference", wifiOnly); - if([self valueChangedForKey:@"wifi_only_preference"]) { - [[LinphoneManager instance] setupNetworkReachabilityCallback]; - } - - NSString* sharing_server = [self stringForKey:@"sharing_server_preference"]; - [[LinphoneManager instance] lpConfigSetString:sharing_server forKey:@"sharing_server_preference"]; - linphone_core_set_file_transfer_server(lc, [sharing_server UTF8String]); - - //Tunnel - if (linphone_core_tunnel_available()){ - NSString* lTunnelPrefMode = [self stringForKey:@"tunnel_mode_preference"]; - NSString* lTunnelPrefAddress = [self stringForKey:@"tunnel_address_preference"]; - int lTunnelPrefPort = [self integerForKey:@"tunnel_port_preference"]; - LinphoneTunnel *tunnel = linphone_core_get_tunnel([LinphoneManager getLc]); - TunnelMode mode = tunnel_off; - int lTunnelPort = 443; - if (lTunnelPrefPort) { - lTunnelPort = lTunnelPrefPort; + BOOL wifiOnly = [self boolForKey:@"wifi_only_preference"]; + [lm lpConfigSetInt:wifiOnly forKey:@"wifi_only_preference"]; + if ([self valueChangedForKey:@"wifi_only_preference"]) { + [[LinphoneManager instance] setupNetworkReachabilityCallback]; } - linphone_tunnel_clean_servers(tunnel); - if (lTunnelPrefAddress && [lTunnelPrefAddress length]) { - LinphoneTunnelConfig *ltc = linphone_tunnel_config_new(); - linphone_tunnel_config_set_host(ltc, [lTunnelPrefAddress UTF8String]); - linphone_tunnel_config_set_port(ltc, lTunnelPort); - linphone_tunnel_add_server(tunnel, ltc); - - if ([lTunnelPrefMode isEqualToString:@"off"]) { - mode = tunnel_off; - } else if ([lTunnelPrefMode isEqualToString:@"on"]) { - mode = tunnel_on; - } else if ([lTunnelPrefMode isEqualToString:@"wwan"]) { - mode = tunnel_wwan; - } else if ([lTunnelPrefMode isEqualToString:@"auto"]) { - mode = tunnel_auto; + NSString *stun_server = [self stringForKey:@"stun_preference"]; + if ([stun_server length] > 0) { + linphone_core_set_stun_server(lc, [stun_server UTF8String]); + BOOL ice_preference = [self boolForKey:@"ice_preference"]; + if (ice_preference) { + linphone_core_set_firewall_policy(lc, LinphonePolicyUseIce); } else { - LOGE(@"Unexpected tunnel mode [%s]",[lTunnelPrefMode cStringUsingEncoding:[NSString defaultCStringEncoding]]); + linphone_core_set_firewall_policy(lc, LinphonePolicyUseStun); } + } else { + linphone_core_set_stun_server(lc, NULL); + linphone_core_set_firewall_policy(lc, LinphonePolicyNoFirewall); } - lp_config_set_string(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "tunnel_mode_preference", [lTunnelPrefMode UTF8String]); - [[LinphoneManager instance] setTunnelMode:mode]; + { + NSString *audio_port_preference = [self stringForKey:@"audio_port_preference"]; + int minPort, maxPort; + [LinphoneCoreSettingsStore parsePortRange:audio_port_preference minPort:&minPort maxPort:&maxPort]; + linphone_core_set_audio_port_range(lc, minPort, maxPort); + } + { + NSString *video_port_preference = [self stringForKey:@"video_port_preference"]; + int minPort, maxPort; + [LinphoneCoreSettingsStore parsePortRange:video_port_preference minPort:&minPort maxPort:&maxPort]; + linphone_core_set_video_port_range(lc, minPort, maxPort); + } + + NSString *menc = [self stringForKey:@"media_encryption_preference"]; + if (menc && [menc compare:@"SRTP"] == NSOrderedSame) + linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionSRTP); + else if (menc && [menc compare:@"ZRTP"] == NSOrderedSame) + linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionZRTP); + else if (menc && [menc compare:@"DTLS"] == NSOrderedSame) + linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionDTLS); + else + linphone_core_set_media_encryption(lc, LinphoneMediaEncryptionNone); + + linphone_core_enable_adaptive_rate_control(lc, [self boolForKey:@"adaptive_rate_control_preference"]); + linphone_core_set_adaptive_rate_algorithm(lc, [[self stringForKey:@"adaptive_rate_algorithm_preference"] + cStringUsingEncoding:[NSString defaultCStringEncoding]]); + } + + // tunnel section + { + if (linphone_core_tunnel_available()) { + NSString *lTunnelPrefMode = [self stringForKey:@"tunnel_mode_preference"]; + NSString *lTunnelPrefAddress = [self stringForKey:@"tunnel_address_preference"]; + int lTunnelPrefPort = [self integerForKey:@"tunnel_port_preference"]; + LinphoneTunnel *tunnel = linphone_core_get_tunnel([LinphoneManager getLc]); + TunnelMode mode = tunnel_off; + int lTunnelPort = 443; + if (lTunnelPrefPort) { + lTunnelPort = lTunnelPrefPort; + } + + linphone_tunnel_clean_servers(tunnel); + if (lTunnelPrefAddress && [lTunnelPrefAddress length]) { + LinphoneTunnelConfig *ltc = linphone_tunnel_config_new(); + linphone_tunnel_config_set_host(ltc, [lTunnelPrefAddress UTF8String]); + linphone_tunnel_config_set_port(ltc, lTunnelPort); + linphone_tunnel_add_server(tunnel, ltc); + + if ([lTunnelPrefMode isEqualToString:@"off"]) { + mode = tunnel_off; + } else if ([lTunnelPrefMode isEqualToString:@"on"]) { + mode = tunnel_on; + } else if ([lTunnelPrefMode isEqualToString:@"wwan"]) { + mode = tunnel_wwan; + } else if ([lTunnelPrefMode isEqualToString:@"auto"]) { + mode = tunnel_auto; + } else { + LOGE(@"Unexpected tunnel mode [%s]", + [lTunnelPrefMode cStringUsingEncoding:[NSString defaultCStringEncoding]]); + } + } + + [lm lpConfigSetString:lTunnelPrefMode forKey:@"tunnel_mode_preference"]; + [[LinphoneManager instance] setTunnelMode:mode]; + } + } + + // advanced section + { + BOOL debugmode = [self boolForKey:@"debugenable_preference"]; + [lm lpConfigSetInt:debugmode forKey:@"debugenable_preference"]; + [[LinphoneManager instance] setLogsEnabled:debugmode]; + + BOOL animations = [self boolForKey:@"animations_preference"]; + [lm lpConfigSetInt:animations forKey:@"animations_preference"]; + + UIDevice *device = [UIDevice currentDevice]; + bool backgroundSupported = + [device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]; + BOOL isbackgroundModeEnabled = backgroundSupported && [self boolForKey:@"backgroundmode_preference"]; + [lm lpConfigSetInt:isbackgroundModeEnabled forKey:@"backgroundmode_preference"]; + + [lm lpConfigSetInt:[self integerForKey:@"start_at_boot_preference"] forKey:@"start_at_boot_preference"]; + [lm lpConfigSetInt:[self integerForKey:@"autoanswer_notif_preference"] forKey:@"autoanswer_notif_preference"]; + + BOOL firstloginview = [self boolForKey:@"enable_first_login_view_preference"]; + [lm lpConfigSetInt:firstloginview forKey:@"enable_first_login_view_preference"]; + + NSString *displayname = [self stringForKey:@"primary_displayname_preference"]; + NSString *username = [self stringForKey:@"primary_username_preference"]; + LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed(lc); + if (parsed != NULL) { + linphone_address_set_display_name(parsed, + [displayname cStringUsingEncoding:[NSString defaultCStringEncoding]]); + linphone_address_set_username(parsed, [username cStringUsingEncoding:[NSString defaultCStringEncoding]]); + char *contact = linphone_address_as_string(parsed); + linphone_core_set_primary_contact(lc, contact); + ms_free(contact); + linphone_address_destroy(parsed); + } + + [lm lpConfigSetInt:[self integerForKey:@"advanced_account_preference"] forKey:@"advanced_account_preference"]; + + NSString *sharing_server = [self stringForKey:@"sharing_server_preference"]; + [[LinphoneManager instance] lpConfigSetString:sharing_server forKey:@"sharing_server_preference"]; } changedDict = [[NSMutableDictionary alloc] init]; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 08f868929..5ad82797f 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -36,7 +36,7 @@ #include "linphone/linphonecore.h" #include "linphone/linphone_tunnel.h" -extern const char *const LINPHONERC_APPLICATION_KEY; +extern NSString *const LINPHONERC_APPLICATION_KEY; extern NSString *const kLinphoneCoreUpdate; extern NSString *const kLinphoneDisplayStatusUpdate; @@ -169,18 +169,26 @@ typedef struct _LinphoneManagerSounds { +(void)setValueInMessageAppData:(id)value forKey:(NSString*)key inMessage:(LinphoneChatMessage*)msg; - (void)lpConfigSetString:(NSString*)value forKey:(NSString*)key; -- (NSString*)lpConfigStringForKey:(NSString*)key; -- (NSString*)lpConfigStringForKey:(NSString*)key withDefault:(NSString*)value; - (void)lpConfigSetString:(NSString*)value forKey:(NSString*)key forSection:(NSString*)section; +- (NSString *)lpConfigStringForKey:(NSString *)key; - (NSString*)lpConfigStringForKey:(NSString*)key forSection:(NSString*)section; -- (void)lpConfigSetInt:(NSInteger)value forKey:(NSString*)key; -- (NSInteger)lpConfigIntForKey:(NSString*)key; -- (void)lpConfigSetInt:(NSInteger)value forKey:(NSString*)key forSection:(NSString*)section; -- (NSInteger)lpConfigIntForKey:(NSString*)key forSection:(NSString*)section; +- (NSString *)lpConfigStringForKey:(NSString *)key withDefault:(NSString *)value; +- (NSString *)lpConfigStringForKey:(NSString *)key forSection:(NSString *)section withDefault:(NSString *)value; + +- (void)lpConfigSetInt:(int)value forKey:(NSString *)key; +- (void)lpConfigSetInt:(int)value forKey:(NSString *)key forSection:(NSString *)section; +- (int)lpConfigIntForKey:(NSString *)key; +- (int)lpConfigIntForKey:(NSString *)key forSection:(NSString *)section; +- (int)lpConfigIntForKey:(NSString *)key withDefault:(int)value; +- (int)lpConfigIntForKey:(NSString *)key forSection:(NSString *)section withDefault:(int)value; + - (void)lpConfigSetBool:(BOOL)value forKey:(NSString*)key; -- (BOOL)lpConfigBoolForKey:(NSString*)key; - (void)lpConfigSetBool:(BOOL)value forKey:(NSString*)key forSection:(NSString*)section; +- (BOOL)lpConfigBoolForKey:(NSString *)key; - (BOOL)lpConfigBoolForKey:(NSString*)key forSection:(NSString*)section; +- (BOOL)lpConfigBoolForKey:(NSString *)key withDefault:(BOOL)value; +- (BOOL)lpConfigBoolForKey:(NSString *)key forSection:(NSString *)section withDefault:(BOOL)value; + - (void)silentPushFailed:(NSTimer*)timer; @property (readonly) BOOL isTesting; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index db9bc07f3..fd59f4de9 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -52,7 +52,7 @@ static void audioRouteChangeListenerCallback ( static LinphoneCore* theLinphoneCore = nil; static LinphoneManager* theLinphoneManager = nil; -const char *const LINPHONERC_APPLICATION_KEY = "app"; +NSString *const LINPHONERC_APPLICATION_KEY = @"app"; NSString *const kLinphoneCoreUpdate = @"LinphoneCoreUpdate"; NSString *const kLinphoneDisplayStatusUpdate = @"LinphoneDisplayStatusUpdate"; @@ -285,7 +285,7 @@ struct codec_name_pref_table codec_pref_table[]={ [self overrideDefaultSettings]; //set default values for first boot - if (lp_config_get_string(configDb,LINPHONERC_APPLICATION_KEY,"debugenable_preference",NULL)==NULL){ + if ([self lpConfigStringForKey:@"debugenable_preference"] == nil) { #ifdef DEBUG [self lpConfigSetBool:TRUE forKey:@"debugenable_preference"]; #else @@ -449,11 +449,11 @@ exit_dbmigration: } - (void)migrateFromUserPrefs { - static const char* migration_flag = "userpref_migration_done"; + static NSString *migration_flag = @"userpref_migration_done"; if( configDb == nil ) return; - if( lp_config_get_int(configDb, LINPHONERC_APPLICATION_KEY, migration_flag, 0) ){ + if ([self lpConfigIntForKey:migration_flag withDefault:0]) { LOGI(@"UserPrefs migration already performed, skip"); return; } @@ -470,12 +470,12 @@ exit_dbmigration: for( NSString* userpref in values ){ if( [defaults_keys containsObject:userpref] ){ LOGI(@"Migrating %@ from user preferences: %d", userpref, [[defaults objectForKey:userpref] boolValue]); - lp_config_set_int(configDb, LINPHONERC_APPLICATION_KEY, [userpref UTF8String], [[defaults objectForKey:userpref] boolValue]); + [self lpConfigSetBool:[[defaults objectForKey:userpref] boolValue] forKey:userpref]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:userpref]; shouldSync = TRUE; - } else if ( lp_config_get_string(configDb, LINPHONERC_APPLICATION_KEY, [userpref UTF8String], NULL) == NULL ){ + } else if ([self lpConfigStringForKey:userpref] == nil) { // no default value found in our linphonerc, we need to add them - lp_config_set_int(configDb, LINPHONERC_APPLICATION_KEY, [userpref UTF8String], [[values objectForKey:userpref] boolValue]); + [self lpConfigSetBool:[[values objectForKey:userpref] boolValue] forKey:userpref]; } } @@ -484,7 +484,7 @@ exit_dbmigration: [[NSUserDefaults standardUserDefaults] synchronize]; } // don't get back here in the future - lp_config_set_int(configDb, LINPHONERC_APPLICATION_KEY, migration_flag, 1); + [self lpConfigSetBool:YES forKey:migration_flag]; } @@ -1048,7 +1048,7 @@ static void networkReachabilityNotification(CFNotificationCenterRef center, void void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* nilCtx){ showNetworkFlags(flags); - LinphoneManager* lLinphoneMgr = [LinphoneManager instance]; + LinphoneManager *lm = [LinphoneManager instance]; SCNetworkReachabilityFlags networkDownFlags=kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand; if (theLinphoneCore != nil) { @@ -1058,30 +1058,28 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach struct NetworkReachabilityContext* ctx = nilCtx ? ((struct NetworkReachabilityContext*)nilCtx) : 0; if ((flags == 0) || (flags & networkDownFlags)) { linphone_core_set_network_reachable(theLinphoneCore, false); - lLinphoneMgr.connectivity = none; + lm.connectivity = none; [LinphoneManager kickOffNetworkConnection]; } else { LinphoneTunnel *tunnel = linphone_core_get_tunnel([LinphoneManager getLc]); Connectivity newConnectivity; - BOOL isWifiOnly = lp_config_get_int(lLinphoneMgr.configDb, LINPHONERC_APPLICATION_KEY, "wifi_only_preference",FALSE); + BOOL isWifiOnly = [lm lpConfigBoolForKey:@"wifi_only_preference" withDefault:FALSE]; if (!ctx || ctx->testWWan) newConnectivity = flags & kSCNetworkReachabilityFlagsIsWWAN ? wwan:wifi; else newConnectivity = wifi; - if (newConnectivity == wwan - && proxy - && isWifiOnly - && (lLinphoneMgr.connectivity == newConnectivity || lLinphoneMgr.connectivity == none)) { + if (newConnectivity == wwan && proxy && isWifiOnly && + (lm.connectivity == newConnectivity || lm.connectivity == none)) { linphone_proxy_config_expires(proxy, 0); } else if (proxy){ - NSInteger defaultExpire = [[LinphoneManager instance] lpConfigIntForKey:@"default_expires"]; + NSInteger defaultExpire = [lm lpConfigIntForKey:@"default_expires"]; if (defaultExpire>=0) linphone_proxy_config_expires(proxy, (int)defaultExpire); //else keep default value from linphonecore } - if (lLinphoneMgr.connectivity != newConnectivity) { + if (lm.connectivity != newConnectivity) { if (tunnel) linphone_tunnel_reconnect(tunnel); // connectivity has changed linphone_core_set_network_reachable(theLinphoneCore,false); @@ -1092,10 +1090,10 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach linphone_core_iterate(theLinphoneCore); LOGI(@"Network connectivity changed to type [%s]",(newConnectivity==wifi?"wifi":"wwan")); } - lLinphoneMgr.connectivity=newConnectivity; - switch (lLinphoneMgr.tunnelMode) { + lm.connectivity = newConnectivity; + switch (lm.tunnelMode) { case tunnel_wwan: - linphone_tunnel_enable(tunnel,lLinphoneMgr.connectivity == wwan); + linphone_tunnel_enable(tunnel, lm.connectivity == wwan); break; case tunnel_auto: linphone_tunnel_auto_detect(tunnel); @@ -1106,7 +1104,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } } if (ctx && ctx->networkStateChanged) { - (*ctx->networkStateChanged)(lLinphoneMgr.connectivity); + (*ctx->networkStateChanged)(lm.connectivity); } } } @@ -2103,63 +2101,70 @@ static void audioRouteChangeListenerCallback ( #pragma mark - LPConfig Functions - (void)lpConfigSetString:(NSString*)value forKey:(NSString*)key { - [self lpConfigSetString:value forKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; + [self lpConfigSetString:value forKey:key forSection:LINPHONERC_APPLICATION_KEY]; } - - (void)lpConfigSetString:(NSString*)value forKey:(NSString*)key forSection:(NSString *)section { if (!key) return; lp_config_set_string(configDb, [section UTF8String], [key UTF8String], value?[value UTF8String]:NULL); } - - (NSString*)lpConfigStringForKey:(NSString*)key { - return [self lpConfigStringForKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; + return [self lpConfigStringForKey:key withDefault:nil]; } - (NSString*)lpConfigStringForKey:(NSString*)key withDefault:(NSString*)defaultValue { - NSString* value = [self lpConfigStringForKey:key]; - return value?value:defaultValue; + return [self lpConfigStringForKey:key forSection:LINPHONERC_APPLICATION_KEY withDefault:defaultValue]; } - - (NSString*)lpConfigStringForKey:(NSString*)key forSection:(NSString *)section { - if (!key) return nil; + return [self lpConfigStringForKey:key forSection:section withDefault:nil]; +} +- (NSString *)lpConfigStringForKey:(NSString *)key forSection:(NSString *)section withDefault:(NSString *)defaultValue { + if (!key) + return defaultValue; const char* value = lp_config_get_string(configDb, [section UTF8String], [key UTF8String], NULL); - if (value) - return [NSString stringWithUTF8String:value]; - else - return nil; + return value ? [NSString stringWithUTF8String:value] : defaultValue; } -- (void)lpConfigSetInt:(NSInteger)value forKey:(NSString*)key { - [self lpConfigSetInt:value forKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; +- (void)lpConfigSetInt:(int)value forKey:(NSString *)key { + [self lpConfigSetInt:value forKey:key forSection:LINPHONERC_APPLICATION_KEY]; } - -- (void)lpConfigSetInt:(NSInteger)value forKey:(NSString*)key forSection:(NSString *)section { +- (void)lpConfigSetInt:(int)value forKey:(NSString *)key forSection:(NSString *)section { if (!key) return; - lp_config_set_int(configDb, [section UTF8String], [key UTF8String], (int)value ); + lp_config_set_int(configDb, [section UTF8String], [key UTF8String], (int)value); } - -- (NSInteger)lpConfigIntForKey:(NSString*)key { - return [self lpConfigIntForKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; +- (int)lpConfigIntForKey:(NSString *)key { + return [self lpConfigIntForKey:key withDefault:-1]; } - -- (NSInteger)lpConfigIntForKey:(NSString*)key forSection:(NSString *)section { - if (!key) return -1; - return lp_config_get_int(configDb, [section UTF8String], [key UTF8String], -1); +- (int)lpConfigIntForKey:(NSString *)key withDefault:(int)defaultValue { + return [self lpConfigIntForKey:key forSection:LINPHONERC_APPLICATION_KEY withDefault:defaultValue]; +} +- (int)lpConfigIntForKey:(NSString *)key forSection:(NSString *)section { + return [self lpConfigIntForKey:key forSection:section withDefault:-1]; +} +- (int)lpConfigIntForKey:(NSString *)key forSection:(NSString *)section withDefault:(int)defaultValue { + if (!key) + return defaultValue; + return lp_config_get_int(configDb, [section UTF8String], [key UTF8String], (int)defaultValue); } - (void)lpConfigSetBool:(BOOL)value forKey:(NSString*)key { - [self lpConfigSetBool:value forKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; + [self lpConfigSetBool:value forKey:key forSection:LINPHONERC_APPLICATION_KEY]; } - - (void)lpConfigSetBool:(BOOL)value forKey:(NSString*)key forSection:(NSString *)section { - return [self lpConfigSetInt:(NSInteger)(value == TRUE) forKey:key forSection:section]; + [self lpConfigSetInt:(int)(value == TRUE)forKey:key forSection:section]; } - - (BOOL)lpConfigBoolForKey:(NSString*)key { - return [self lpConfigBoolForKey:key forSection:[NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY]]; + return [self lpConfigBoolForKey:key withDefault:FALSE]; +} +- (BOOL)lpConfigBoolForKey:(NSString *)key withDefault:(BOOL)defaultValue { + return [self lpConfigBoolForKey:key forSection:LINPHONERC_APPLICATION_KEY withDefault:defaultValue]; } - - (BOOL)lpConfigBoolForKey:(NSString*)key forSection:(NSString *)section { - return [self lpConfigIntForKey:key forSection:section] == 1; + return [self lpConfigBoolForKey:key forSection:section withDefault:FALSE]; +} +- (BOOL)lpConfigBoolForKey:(NSString *)key forSection:(NSString *)section withDefault:(BOOL)defaultValue { + if (!key) + return defaultValue; + int val = [self lpConfigIntForKey:key forSection:section withDefault:-1]; + return (val != -1) ? (val == 1) : defaultValue; } #pragma mark - GSM management diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index 9fab910a9..347c91582 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -605,8 +605,6 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"microphone_gain_preference"]; [hiddenKeys addObject:@"network_limit_group"]; - [hiddenKeys addObject:@"upload_bandwidth_preference"]; - [hiddenKeys addObject:@"download_bandwidth_preference"]; [hiddenKeys addObject:@"incoming_call_timeout_preference"]; [hiddenKeys addObject:@"in_call_timeout_preference"]; diff --git a/Settings/InAppSettings.bundle/Audio.plist b/Settings/InAppSettings.bundle/Audio.plist index b9b3278f4..e61a70df2 100644 --- a/Settings/InAppSettings.bundle/Audio.plist +++ b/Settings/InAppSettings.bundle/Audio.plist @@ -218,36 +218,6 @@ IASKTextAlignment IASKUITextAlignmentRight - - DefaultValue - - Key - adaptive_rate_control_preference - Title - Adaptive rate control - Type - PSToggleSwitchSpecifier - - - DefaultValue - Simple - Key - adaptive_rate_algorithm_preference - Title - Adaptive rate algorithm - Titles - - Simple - Stateful - - Type - PSMultiValueSpecifier - Values - - Simple - Stateful - - DefaultValue 36 diff --git a/Settings/InAppSettings.bundle/Network.plist b/Settings/InAppSettings.bundle/Network.plist index 4eb893d65..e97766b92 100644 --- a/Settings/InAppSettings.bundle/Network.plist +++ b/Settings/InAppSettings.bundle/Network.plist @@ -156,31 +156,41 @@ Key - upload_bandwidth_preference + adaptive_rate_control_group Title - Upload bandwidth + Adaptive rate control Type - PSTextFieldSpecifier - KeyboardType - NumberPad - DefaultValue - 0 - IASKTextAlignment - IASKUITextAlignmentRight + PSGroupSpecifier - Key - download_bandwidth_preference - Title - Download bandwidth - Type - PSTextFieldSpecifier - KeyboardType - NumberPad DefaultValue - 0 - IASKTextAlignment - IASKUITextAlignmentRight + + Key + adaptive_rate_control_preference + Title + Adaptive rate control + Type + PSToggleSwitchSpecifier + + + DefaultValue + Simple + Key + adaptive_rate_algorithm_preference + Title + Adaptive rate algorithm + Titles + + Simple + Stateful + + Type + PSMultiValueSpecifier + Values + + Simple + Stateful + diff --git a/Settings/InAppSettings.bundle/Root.plist b/Settings/InAppSettings.bundle/Root.plist index 90c75b377..dedc25c2d 100644 --- a/Settings/InAppSettings.bundle/Root.plist +++ b/Settings/InAppSettings.bundle/Root.plist @@ -268,7 +268,7 @@ Key release_button Title - Exit + Release core Type IASKButtonSpecifier