From 54f89df2084a610afa4ef104c9180525d69e61cf Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 3 Jun 2013 16:13:03 +0200 Subject: [PATCH] fix contact management + update liblinphone --- Classes/ContactDetailsTableViewController.m | 132 +++++++++++--------- Classes/LinphoneManager.m | 5 +- Resources/linphonerc-factory | 4 +- submodules/linphone | 2 +- 4 files changed, 77 insertions(+), 66 deletions(-) diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index 7b64c2990..42332e723 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -253,6 +253,68 @@ static const int contactSections[ContactSections_MAX] = {ContactSections_None, C [self.tableView reloadData]; } +-(Entry *) setOrCreateSipContactEntry:(Entry *)entry withValue:(NSString*)value { + ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); + ABMutableMultiValueRef lMap; + if(lcMap != NULL) { + lMap = ABMultiValueCreateMutableCopy(lcMap); + CFRelease(lcMap); + } else { + lMap = ABMultiValueCreateMutable(kABStringPropertyType); + } + ABMultiValueIdentifier index; + NSError* error = NULL; + + CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey}; + CFTypeRef values[] = { [value copy], [LinphoneManager instance].contactSipField }; + CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); + if (entry) { + index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); + ABMultiValueReplaceValueAtIndex(lMap, lDict, index); + } else { + + CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0]; + ABMultiValueAddValueAndLabel(lMap, lDict, label, &index); + } + if (!ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) { + [LinphoneLogger log:LinphoneLoggerLog format:@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]]; + } else { + if (entry == nil) { + entry = [[Entry alloc] initWithData:index]; + } + CFRelease(lDict); + /*check if message type is kept or not*/ + lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); + lMap = ABMultiValueCreateMutableCopy(lcMap); + CFRelease(lcMap); + index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); + lDict = ABMultiValueCopyValueAtIndex(lMap,index); + if(!CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) { + /*too bad probably a gtalk number, storing uri*/ + NSString* username = CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey); + LinphoneAddress* address = linphone_core_interpret_url([LinphoneManager getLc] + ,[username UTF8String]); + char* uri = linphone_address_as_string_uri_only(address); + CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey}; + CFTypeRef values[] = { [NSString stringWithCString:uri encoding:[NSString defaultCStringEncoding]], [LinphoneManager instance].contactSipField }; + CFDictionaryRef lDict2 = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); + ABMultiValueReplaceValueAtIndex(lMap, lDict2, index); + if (!ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) { + [LinphoneLogger log:LinphoneLoggerLog format:@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]]; + } + CFRelease(lDict2); + linphone_address_destroy(address); + ms_free(uri); + } + CFRelease(lMap); + } + CFRelease(lDict); + + return entry; +} +-(void) setSipContactEntry:(Entry *)entry withValue:(NSString*)value { + [self setOrCreateSipContactEntry:entry withValue:value]; +} - (void)addEntry:(UITableView*)tableview section:(NSInteger)section animated:(BOOL)animated { [self addEntry:tableview section:section animated:animated value:@""]; } @@ -287,33 +349,15 @@ static const int contactSections[ContactSections_MAX] = {ContactSections_None, C } CFRelease(lMap); } else if(contactSections[section] == ContactSections_Sip) { - ABMultiValueIdentifier identifier; - ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); - ABMutableMultiValueRef lMap; - if(lcMap != NULL) { - lMap = ABMultiValueCreateMutableCopy(lcMap); - CFRelease(lcMap); - } else { - lMap = ABMultiValueCreateMutable(kABDictionaryPropertyType); - } - CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey }; - CFTypeRef values[] = { [value copy], [LinphoneManager instance].contactSipField }; - CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 1, NULL, NULL); - CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0]; - if(!ABMultiValueAddValueAndLabel(lMap, lDict, label, &identifier)) { - added = false; - } - CFRelease(lDict); - - if(added && ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) { - Entry *entry = [[Entry alloc] initWithData:identifier]; - [sectionArray addObject:entry]; - [entry release]; - } else { - added = false; - [LinphoneLogger log:LinphoneLoggerError format:@"Can't add entry: %@", [error localizedDescription]]; - } - CFRelease(lMap); + Entry *entry = [self setOrCreateSipContactEntry:nil withValue:value]; + if (entry) { + [sectionArray addObject:entry]; + [entry release]; + added=true; + } else { + added=false; + [LinphoneLogger log:LinphoneLoggerError format:@"Can't add entry for value: %@", value]; + } } else if(contactSections[section] == ContactSections_Email) { ABMultiValueIdentifier identifier; ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonEmailProperty); @@ -842,39 +886,7 @@ static const int contactSections[ContactSections_MAX] = {ContactSections_None, C ABRecordSetValue(contact, kABPersonPhoneProperty, lMap, nil); CFRelease(lMap); } else if(contactSections[[path section]] == ContactSections_Sip) { - ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); - ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); - CFRelease(lcMap); - int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); - CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey}; - CFTypeRef values[] = { [value copy], [LinphoneManager instance].contactSipField }; - CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); - ABMultiValueReplaceValueAtIndex(lMap, lDict, index); - ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, nil); - CFRelease(lDict); - /*check if message type is kept or not*/ - lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); - lMap = ABMultiValueCreateMutableCopy(lcMap); - CFRelease(lcMap); - index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); - lDict = ABMultiValueCopyValueAtIndex(lMap,index); - if(!CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) { - /*too bad probably a gtalk number, storing uri*/ - NSString* username = CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey); - LinphoneAddress* address = linphone_core_interpret_url([LinphoneManager getLc] - ,[username UTF8String]); - char* uri = linphone_address_as_string_uri_only(address); - CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey}; - CFTypeRef values[] = { [NSString stringWithCString:uri encoding:[NSString defaultCStringEncoding]], [LinphoneManager instance].contactSipField }; - CFDictionaryRef lDict2 = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); - ABMultiValueReplaceValueAtIndex(lMap, lDict2, index); - ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, nil); - CFRelease(lDict2); - linphone_address_destroy(address); - ms_free(uri); - } - CFRelease(lDict); - CFRelease(lMap); + [self setSipContactEntry:entry withValue:value]; } else if(contactSections[[path section]] == ContactSections_Email) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonEmailProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 882dae154..bd1cdf406 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -842,10 +842,9 @@ static LinphoneCoreVTable linphonec_vtable = { ,self); linphone_core_set_user_agent(theLinphoneCore,"LinphoneIPhone", [[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] UTF8String]); + [_contactSipField release]; + _contactSipField = [[self lpConfigStringForKey:@"contact_im_type_value" withDefault:@"SIP"] retain]; - _contactSipField = [self lpConfigStringForKey:@"contact_im_type_value"]; - if (_contactSipField == nil) - _contactSipField =@"SIP"; fastAddressBook = [[FastAddressBook alloc] init]; diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index cc6384010..92e740b16 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -49,5 +49,5 @@ stun=stun.linphone.org display_filter_auto_rotate=0 [app] -#contact_display_username_only=1 -#contact_filter_on_default_domain=1 +contact_display_username_only=1 +contact_filter_on_default_domain=1 diff --git a/submodules/linphone b/submodules/linphone index 5355e3775..f1eb0ec07 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 5355e37750d8c32fbd978161966ba80390a8bec0 +Subproject commit f1eb0ec07fda4221722ef1de098824299c85fd0a