Switch to multi protocol from branch remote

This commit is contained in:
Guillaume BIENKOWSKI 2014-03-25 09:03:56 +01:00
parent 29cca9bfe9
commit bb59a61e71
11 changed files with 715 additions and 639 deletions

View file

@ -88,30 +88,40 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
[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){
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"];
[self setString: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;
}
[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"];
}
} else {
[self setInteger: lp_config_get_int(linphone_core_get_config(lc),"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 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:lp_config_get_int(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "pushnotification_preference", 0) forKey:@"pushnotification_preference"];
{
LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed(lc);
@ -140,38 +150,24 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
}
}
{
[self setInteger: linphone_core_get_upload_bandwidth(lc) forKey:@"upload_bandwidth_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"];
[self setFloat:linphone_core_get_mic_gain_db(lc) forKey:@"microphone_gain_preference"];
}
{
LCSipTransports tp;
const char *tname = "udp";
int port = 5060;
linphone_core_get_sip_transports(lc, &tp);
if (tp.udp_port>0) {
tname = "udp";
port = tp.udp_port;
} else if (tp.tcp_port>0) {
tname = "tcp";
port = tp.tcp_port;
} else if (tp.tls_port>0) {
tname = "tls";
port = tp.tls_port;
}
[self setString:tname forKey:@"transport_preference"];
int port = lp_config_get_int(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "port_preference", 5060);
[self setInteger:port forKey:@"port_preference"];
[self setInteger:lp_config_get_int(linphone_core_get_config(lc),"sip","sip_random_port", 1) forKey:@"random_port_preference"];
[self setInteger:lp_config_get_int(linphone_core_get_config(lc),LINPHONERC_APPLICATION_KEY,"random_port_preference", 1) 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
}
}
{
@ -201,14 +197,9 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
LinphoneMediaEncryption menc=linphone_core_get_media_encryption(lc);
const char *val;
switch(menc){
case LinphoneMediaEncryptionSRTP:
val="SRTP";
break;
case LinphoneMediaEncryptionZRTP:
val="ZRTP";
break;
default:
val="None";
case LinphoneMediaEncryptionSRTP: val="SRTP"; break;
case LinphoneMediaEncryptionZRTP: val="ZRTP"; break;
default: val="None"; break;
}
[self setString:val forKey:@"media_encryption_preference"];
}
@ -291,6 +282,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
- (void)synchronizeAccount {
LinphoneCore *lc = [LinphoneManager getLc];
LpConfig* conf = linphone_core_get_config(lc);
LinphoneManager* lLinphoneMgr = [LinphoneManager instance];
LinphoneProxyConfig* proxyCfg = NULL;
/* unregister before modifying any settings */
@ -312,43 +304,22 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
}
}
NSString* transport = [self stringForKey:@"transport_preference"];
int port_preference = [self integerForKey:@"port_preference"];
BOOL random_port_preference = [self boolForKey:@"random_port_preference"];
lp_config_set_int(linphone_core_get_config(lc),"sip","sip_random_port", random_port_preference);
lp_config_set_int(linphone_core_get_config(lc),"sip","sip_tcp_random_port", random_port_preference);
lp_config_set_int(linphone_core_get_config(lc),"sip","sip_tls_random_port", random_port_preference);
if(random_port_preference) {
port_preference = (0xDFFF&random())+1024;
[self setInteger:port_preference forKey:@"port_preference"]; // Update back preference
port_preference = -1;
}
LCSipTransports transportValue={0};
if (transport!=nil) {
if (linphone_core_get_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot get current transport"];
}
// Only one port can be set at one time, the others's value is 0
if ([transport isEqualToString:@"tcp"]) {
transportValue.tcp_port=port_preference;
transportValue.udp_port=0;
transportValue.tls_port=0;
} else if ([transport isEqualToString:@"udp"]){
transportValue.udp_port=port_preference;
transportValue.tcp_port=0;
transportValue.tls_port=0;
} else if ([transport isEqualToString:@"tls"]){
transportValue.tls_port=port_preference;
transportValue.tcp_port=0;
transportValue.udp_port=0;
} else {
[LinphoneLogger logc:LinphoneLoggerError format:"unexpected transport [%s]",[transport cStringUsingEncoding:[NSString defaultCStringEncoding]]];
}
if (linphone_core_set_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"];
}
}
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)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"];
}
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(linphone_core_get_config(lc), "sip", "use_ipv6", enable_ipv6);
@ -357,20 +328,21 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
linphone_core_enable_ipv6(lc, enable_ipv6);
}
//configure sip account
//mandatory parameters
NSString* username = [self stringForKey:@"username_preference"];
NSString* domain = [self stringForKey:@"domain_preference"];
NSString* username = [self stringForKey:@"username_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 isOutboundProxy = [self boolForKey:@"outbound_proxy_preference"];
//clear auth info list
linphone_core_clear_all_auth_info(lc);
//clear existing proxy config
linphone_core_clear_proxy_config(lc);
if (username && [username length] >0 && domain && [domain length]>0) {
NSString* proxyAddress = [self stringForKey:@"proxy_preference"];
if ((!proxyAddress || [proxyAddress length] <1 ) && domain) {
@ -379,10 +351,19 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
proxyAddress = [NSString stringWithFormat:@"sip:%@",proxyAddress] ;
}
const char* proxy = [proxyAddress cStringUsingEncoding:[NSString defaultCStringEncoding]];
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;
linphone_address_set_transport(proxy_addr, type);
ms_free(proxy);
proxy = linphone_address_as_string_uri_only(proxy_addr);
}
//possible valid config detected
proxyCfg = linphone_core_create_proxy_config(lc);
char normalizedUserName[256];
@ -392,6 +373,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
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]];
// configure proxy entries
linphone_proxy_config_set_identity(proxyCfg, identity);
@ -402,13 +384,10 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
LinphoneAddress *from = linphone_address_new(identity);
LinphoneAuthInfo *info;
if (from != 0){
info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,linphone_proxy_config_get_domain(proxyCfg));
info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,ha1,NULL,linphone_proxy_config_get_domain(proxyCfg));
linphone_core_add_auth_info(lc,info);
linphone_address_destroy(from);
}
int expire = [self integerForKey:@"expire_preference"];
linphone_proxy_config_expires(proxyCfg,expire);
@ -445,6 +424,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
linphone_core_set_default_proxy(lc,proxyCfg);
linphone_address_destroy(linphoneAddress);
ms_free(proxy);
}
[[[LinphoneManager instance] fastAddressBook] reload];
}
@ -496,7 +476,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
BOOL account_changed;
account_changed=[self valueChangedForKey:@"username_preference"]
|| [self valueChangedForKey:@"password_preference"]
|| [self valueChangedForKey:@"password_preference"]
|| [self valueChangedForKey:@"domain_preference"]
|| [self valueChangedForKey:@"expire_preference"]
|| [self valueChangedForKey:@"proxy_preference"]

View file

@ -68,7 +68,7 @@ static PhoneMainView* phoneMainViewInstance=nil;
[self initPhoneMainView];
}
return self;
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
@ -514,7 +514,7 @@ static PhoneMainView* phoneMainViewInstance=nil;
}
return view;
}
- (UIViewController*)popCurrentView {
[LinphoneLogger logc:LinphoneLoggerLog format:"PhoneMainView: Pop view"];
if([viewStack count] > 1) {

View file

@ -667,7 +667,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[hiddenKeys addObjectsFromArray:[[LinphoneManager unsupportedCodecs] allObjects]];
if(lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]),"sip","sip_random_port",0)==1) {
if(lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]),"app","random_port_preference",0)==1) {
[hiddenKeys addObject:@"port_preference"];
}

View file

@ -196,11 +196,8 @@ static UICompositeViewDescription *compositeDescription = nil;
[[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"pushnotification_preference"];
LinphoneCore *lc = [LinphoneManager getLc];
LCSipTransports transportValue={0};
transportValue.udp_port=5060;
transportValue.tls_port=0;
transportValue.tcp_port=0;
LCSipTransports transportValue={5060,5060,-1,-1};
if (linphone_core_set_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"];
}
@ -310,7 +307,7 @@ static UICompositeViewDescription *compositeDescription = nil;
placement_done = YES;
}
if (!show_extern && !show_logo) {
// no option to create or specify a custom account: go to
// no option to create or specify a custom account: go to connect view directly
view = connectAccountView;
}
}
@ -349,42 +346,25 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)setDefaultSettings:(LinphoneProxyConfig*)proxyCfg {
BOOL pushnotification = [[LinphoneManager instance] lpConfigBoolForKey:@"push_notification" forSection:@"wizard"];
[[LinphoneManager instance] lpConfigSetBool:pushnotification forKey:@"pushnotification_preference"];
if(pushnotification) {
[[LinphoneManager instance] addPushTokenToProxyConfig:proxyCfg];
}
int expires = [[LinphoneManager instance] lpConfigIntForKey:@"expires" forSection:@"wizard"];
linphone_proxy_config_expires(proxyCfg, expires);
NSString* transport = [[LinphoneManager instance] lpConfigStringForKey:@"transport" forSection:@"wizard"];
LinphoneManager* lm = [LinphoneManager instance];
LinphoneCore *lc = [LinphoneManager getLc];
LCSipTransports transportValue={0};
if (transport!=nil) {
if (linphone_core_get_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot get current transport"];
}
// Only one port can be set at one time, the others's value is 0
if ([transport isEqualToString:@"tcp"]) {
transportValue.tcp_port=transportValue.tcp_port|transportValue.udp_port|transportValue.tls_port;
transportValue.udp_port=0;
transportValue.tls_port=0;
} else if ([transport isEqualToString:@"udp"]){
transportValue.udp_port=transportValue.tcp_port|transportValue.udp_port|transportValue.tls_port;
transportValue.tcp_port=0;
transportValue.tls_port=0;
} else if ([transport isEqualToString:@"tls"]){
transportValue.tls_port=transportValue.tcp_port|transportValue.udp_port|transportValue.tls_port;
transportValue.tcp_port=0;
transportValue.udp_port=0;
} else {
[LinphoneLogger logc:LinphoneLoggerError format:"unexpected transport [%s]",[transport cStringUsingEncoding:[NSString defaultCStringEncoding]]];
}
if (linphone_core_set_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"];
}
}
BOOL pushnotification = [lm lpConfigBoolForKey:@"push_notification" forSection:@"wizard"];
[lm lpConfigSetBool:pushnotification forKey:@"pushnotification_preference"];
if(pushnotification) {
[lm addPushTokenToProxyConfig:proxyCfg];
}
int expires = [lm lpConfigIntForKey:@"expires" forSection:@"wizard"];
linphone_proxy_config_expires(proxyCfg, expires);
NSString* section = [NSString stringWithUTF8String:LINPHONERC_APPLICATION_KEY];
int port = [lm lpConfigBoolForKey:@"random_port_preference" forSection:section] ? -1 : [lm lpConfigIntForKey:@"port_preference" forSection:section];
LCSipTransports transportValue={port,port,-1,-1};
if (linphone_core_set_sip_transports(lc, &transportValue)) {
[LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"];
}
NSString* sharing_server = [[LinphoneManager instance] lpConfigStringForKey:@"sharing_server" forSection:@"wizard"];
[[LinphoneManager instance] lpConfigSetString:sharing_server forKey:@"sharing_server_preference"];
@ -521,6 +501,13 @@ static UICompositeViewDescription *compositeDescription = nil;
}
}
- (void)loadWizardConfig:(NSString*)rcFilename {
NSString* fullPath = [LinphoneManager bundleFile:rcFilename];
LpConfig* current_conf = linphone_core_get_config([LinphoneManager getLc]);
if( lp_config_read_file(current_conf, [fullPath cStringUsingEncoding:[NSString defaultCStringEncoding]]) != 0 ){
[LinphoneLogger log:LinphoneLoggerError format:@"Couldn't push wizard file %@ to the Linphone config"];
}
}
#pragma mark - UITextFieldDelegate Functions
@ -562,7 +549,6 @@ static UICompositeViewDescription *compositeDescription = nil;
}
return YES;
}
- (void)hideError:(NSTimer*)timer {
UILabel* error_label =[WizardViewController findLabel:ViewElement_Username_Error view:contentView];
if( error_label ) {
@ -596,15 +582,18 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onCreateAccountClick:(id)sender {
[self loadWizardConfig:@"wizard_linphone_create.rc"];
[self changeView:createAccountView back:FALSE animation:TRUE];
}
- (IBAction)onConnectAccountClick:(id)sender {
[self loadWizardConfig:@"wizard_linphone_existing.rc"];
[self changeView:connectAccountView back:FALSE animation:TRUE];
}
- (IBAction)onExternalAccountClick:(id)sender {
[self loadWizardConfig:@"wizard_external_sip.rc"];
[self changeView:externalAccountView back:FALSE animation:TRUE];
}
@ -876,7 +865,6 @@ static UICompositeViewDescription *compositeDescription = nil;
}
#pragma mark - TPMultiLayoutViewController Functions
- (NSDictionary*)attributesForView:(UIView*)view {

View file

@ -0,0 +1,19 @@
[proxy_default_values]
reg_proxy=
reg_route=
reg_identity=
reg_expires=3600
reg_sendregister=1
publish=0
dial_escape_plus=0
[wizard]
service_url=
[app]
push_notification_preference=0
sharing_server_preference=
ice_preference=
stun_preference=

View file

@ -0,0 +1,19 @@
[proxy_default_values]
reg_proxy=<sip:sip.linphone.org:5223;transport=tls>
reg_route=<sip:sip.linphone.org:5223;transport=tls>
reg_identity=sip:?@sip.linphone.org
reg_expires=604800
reg_sendregister=1
publish=0
dial_escape_plus=0
[wizard]
service_url=https://www.linphone.org/wizard.php
[app]
push_notification_preference=1
sharing_server_preference=https://www.linphone.org:444/upload.php
ice_preference=1
stun_preference=stun.linphone.org

View file

@ -0,0 +1,19 @@
[proxy_default_values]
reg_proxy=<sip:sip.linphone.org:5223;transport=tls>
reg_route=<sip:sip.linphone.org:5223;transport=tls>
reg_identity=sip:?@sip.linphone.org
reg_expires=604800
reg_sendregister=1
publish=0
dial_escape_plus=0
[wizard]
service_url=https://www.linphone.org/wizard.php
[app]
push_notification_preference=1
sharing_server_preference=https://www.linphone.org:444/upload.php
ice_preference=1
stun_preference=stun.linphone.org

View file

@ -0,0 +1,19 @@
[proxy_default_values]
reg_proxy=
reg_route=
reg_identity=
reg_expires=3600
reg_sendregister=1
publish=0
dial_escape_plus=0
[wizard]
service_url=
[app]
push_notification_preference=0
sharing_server_preference=
ice_preference=
stun_preference=

View file

@ -5,12 +5,12 @@
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Title</key>
<string>Edge optimization</string>
<key>DefaultValue</key>
<false/>
<key>Key</key>
<string>edge_opt_preference</string>
<key>Title</key>
<string>Edge optimization</string>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
</dict>
@ -102,28 +102,6 @@
<key>IASKTextAlignment</key>
<string>IASKUITextAlignmentRight</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>udp</string>
<key>Key</key>
<string>transport_preference</string>
<key>Title</key>
<string>Transport</string>
<key>Titles</key>
<array>
<string>UDP</string>
<string>TCP</string>
<string>TLS</string>
</array>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Values</key>
<array>
<string>udp</string>
<string>tcp</string>
<string>tls</string>
</array>
</dict>
<dict>
<key>Title</key>
<string>Use IPv6</string>

View file

@ -90,6 +90,28 @@
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>udp</string>
<key>Key</key>
<string>transport_preference</string>
<key>Title</key>
<string>Transport</string>
<key>Titles</key>
<array>
<string>UDP</string>
<string>TCP</string>
<string>TLS</string>
</array>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Values</key>
<array>
<string>udp</string>
<string>tcp</string>
<string>tls</string>
</array>
</dict>
<dict>
<key>DefaultValue</key>
<false/>

File diff suppressed because it is too large Load diff