Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge https://github.com/eofster/Telephone

Conflicts:
	Telephone.xcodeproj/project.pbxproj
  • Loading branch information...
commit d8138a2e7097e67146bf1e7e9163e3f1aff5b601 2 parents 1afb53d + 88df035
@mike42 authored
Showing with 7,814 additions and 9,632 deletions.
  1. +26 −36 Classes/AKABAddressBook+Localizing.m
  2. +27 −29 Classes/AKABRecord+Querying.m
  3. +7 −9 Classes/AKActiveCallView.h
  4. +24 −29 Classes/AKActiveCallView.m
  5. +5 −10 Classes/AKKeychain.h
  6. +69 −74 Classes/AKKeychain.m
  7. +5 −5 Classes/AKNSString+Creating.m
  8. +4 −6 Classes/AKNSString+Escaping.h
  9. +16 −20 Classes/AKNSString+Escaping.m
  10. +4 −5 Classes/AKNSString+PJSUA.m
  11. +2 −2 Classes/AKNSString+Scanning.h
  12. +14 −20 Classes/AKNSString+Scanning.m
  13. +3 −6 Classes/AKNSWindow+Resizing.h
  14. +23 −25 Classes/AKNSWindow+Resizing.m
  15. +3 −4 Classes/AKNetworkReachability.h
  16. +59 −87 Classes/AKNetworkReachability.m
  17. +3 −8 Classes/AKResponsiveProgressIndicator.h
  18. +1 −4 Classes/AKResponsiveProgressIndicator.m
  19. +11 −30 Classes/AKSIPAccount.h
  20. +172 −220 Classes/AKSIPAccount.m
  21. +28 −45 Classes/AKSIPCall.h
  22. +265 −318 Classes/AKSIPCall.m
  23. +4 −22 Classes/AKSIPURI.h
  24. +97 −148 Classes/AKSIPURI.m
  25. +5 −11 Classes/AKSIPURIFormatter.h
  26. +116 −132 Classes/AKSIPURIFormatter.m
  27. +30 −56 Classes/AKSIPUserAgent.h
  28. +906 −1,095 Classes/AKSIPUserAgent.m
  29. +7 −12 Classes/AKTelephoneNumberFormatter.h
  30. +227 −241 Classes/AKTelephoneNumberFormatter.m
  31. +25 −56 Classes/AccountController.h
  32. +825 −961 Classes/AccountController.m
  33. +19 −41 Classes/AccountPreferencesViewController.h
  34. +564 −657 Classes/AccountPreferencesViewController.m
  35. +13 −25 Classes/AccountSetupController.h
  36. +71 −106 Classes/AccountSetupController.m
  37. +1 −3 Classes/ActiveAccountTransferViewController.h
  38. +23 −26 Classes/ActiveAccountTransferViewController.m
  39. +5 −11 Classes/ActiveAccountViewController.h
  40. +756 −853 Classes/ActiveAccountViewController.m
  41. +2 −5 Classes/ActiveCallTransferViewController.h
  42. +14 −21 Classes/ActiveCallTransferViewController.m
  43. +13 −26 Classes/ActiveCallViewController.h
  44. +156 −199 Classes/ActiveCallViewController.m
  45. +20 −51 Classes/AppController.h
  46. +1,659 −1,993 Classes/AppController.m
  47. +8 −18 Classes/AuthenticationFailureController.h
  48. +77 −104 Classes/AuthenticationFailureController.m
  49. +14 −36 Classes/CallController.h
  50. +474 −574 Classes/CallController.m
  51. +1 −6 Classes/CallTransferController.h
  52. +107 −128 Classes/CallTransferController.m
  53. +1 −3 Classes/EndedCallTransferViewController.h
  54. +4 −4 Classes/EndedCallTransferViewController.m
  55. +6 −14 Classes/EndedCallViewController.h
  56. +17 −39 Classes/EndedCallViewController.m
  57. +1 −3 Classes/GeneralPreferencesViewController.h
  58. +6 −7 Classes/GeneralPreferencesViewController.m
  59. +7 −16 Classes/IncomingCallViewController.h
  60. +21 −42 Classes/IncomingCallViewController.m
  61. +9 −20 Classes/NetworkPreferencesViewController.h
  62. +157 −208 Classes/NetworkPreferencesViewController.m
  63. +12 −23 Classes/PreferencesController.h
  64. +132 −170 Classes/PreferencesController.m
  65. +6 −13 Classes/SoundPreferencesViewController.h
  66. +116 −144 Classes/SoundPreferencesViewController.m
  67. +4 −4 Classes/XSViewController.h
  68. +3 −9 Classes/XSViewController.m
  69. +2 −0  Classes/XSWindowController.h
  70. +2 −8 Classes/XSWindowController.m
  71. +10 −19 PlugIns/AddressBook/AKAddressBookPhonePlugIn.h
  72. +66 −81 PlugIns/AddressBook/AKAddressBookPhonePlugIn.m
  73. +11 −21 PlugIns/AddressBook/AKAddressBookSIPAddressPlugIn.h
  74. +74 −92 PlugIns/AddressBook/AKAddressBookSIPAddressPlugIn.m
  75. +6 −3 README.md
  76. +131 −80 Telephone.xcodeproj/project.pbxproj
View
62 Classes/AKABAddressBook+Localizing.m
@@ -36,42 +36,32 @@
@implementation ABAddressBook (AKAddressBookLocalizingAdditions)
- (NSString *)ak_localizedLabel:(NSString *)label {
- NSString *theString;
-
- if ([label isEqualToString:kABPhoneWorkLabel]) {
- theString = NSLocalizedStringFromTable(@"work", @"AddressBookLabels",
- @"Work phone number.");
- } else if ([label isEqualToString:kABPhoneHomeLabel]) {
- theString = NSLocalizedStringFromTable(@"home", @"AddressBookLabels",
- @"Home phone number.");
- } else if ([label isEqualToString:kABPhoneMobileLabel]) {
- theString = NSLocalizedStringFromTable(@"mobile", @"AddressBookLabels",
- @"Mobile phone number.");
- } else if ([label isEqualToString:kABPhoneMainLabel]) {
- theString = NSLocalizedStringFromTable(@"main", @"AddressBookLabels",
- @"Main phone number.");
- } else if ([label isEqualToString:kABPhoneHomeFAXLabel]) {
- theString = NSLocalizedStringFromTable(@"home fax", @"AddressBookLabels",
- @"Home FAX number.");
- } else if ([label isEqualToString:kABPhoneWorkFAXLabel]) {
- theString = NSLocalizedStringFromTable(@"work fax", @"AddressBookLabels",
- @"Work FAX number.");
- } else if ([label isEqualToString:kABPhonePagerLabel]) {
- theString = NSLocalizedStringFromTable(@"pager", @"AddressBookLabels",
- @"Pager number.");
- } else if ([label isEqualToString:kABOtherLabel]) {
- theString = NSLocalizedStringFromTable(@"other", @"AddressBookLabels",
- @"Other number.");
- } else if ([label isEqualToString:@"sip"]) {
- theString = NSLocalizedStringFromTable(@"sip", @"AddressBookLabels",
- @"SIP address.");
- } else {
- CFStringRef localizedLabel
- = ABCopyLocalizedPropertyOrLabel((CFStringRef)label);
- theString = [(NSString *)localizedLabel autorelease];
- }
-
- return theString;
+ NSString *theString;
+
+ if ([label isEqualToString:kABPhoneWorkLabel]) {
+ theString = NSLocalizedStringFromTable(@"work", @"AddressBookLabels", @"Work phone number.");
+ } else if ([label isEqualToString:kABPhoneHomeLabel]) {
+ theString = NSLocalizedStringFromTable(@"home", @"AddressBookLabels", @"Home phone number.");
+ } else if ([label isEqualToString:kABPhoneMobileLabel]) {
+ theString = NSLocalizedStringFromTable(@"mobile", @"AddressBookLabels", @"Mobile phone number.");
+ } else if ([label isEqualToString:kABPhoneMainLabel]) {
+ theString = NSLocalizedStringFromTable(@"main", @"AddressBookLabels", @"Main phone number.");
+ } else if ([label isEqualToString:kABPhoneHomeFAXLabel]) {
+ theString = NSLocalizedStringFromTable(@"home fax", @"AddressBookLabels", @"Home FAX number.");
+ } else if ([label isEqualToString:kABPhoneWorkFAXLabel]) {
+ theString = NSLocalizedStringFromTable(@"work fax", @"AddressBookLabels", @"Work FAX number.");
+ } else if ([label isEqualToString:kABPhonePagerLabel]) {
+ theString = NSLocalizedStringFromTable(@"pager", @"AddressBookLabels", @"Pager number.");
+ } else if ([label isEqualToString:kABOtherLabel]) {
+ theString = NSLocalizedStringFromTable(@"other", @"AddressBookLabels", @"Other number.");
+ } else if ([label isEqualToString:@"sip"]) {
+ theString = NSLocalizedStringFromTable(@"sip", @"AddressBookLabels", @"SIP address.");
+ } else {
+ CFStringRef localizedLabel = ABCopyLocalizedPropertyOrLabel((__bridge CFStringRef)label);
+ theString = (__bridge_transfer NSString *)localizedLabel;
+ }
+
+ return theString;
}
@end
View
56 Classes/AKABRecord+Querying.m
@@ -33,38 +33,36 @@
@implementation ABRecord (AKRecordQueryingAdditions)
-@dynamic ak_fullName;
-
- (NSString *)ak_fullName {
- NSString *firstName = [self valueForProperty:kABFirstNameProperty];
- NSString *lastName = [self valueForProperty:kABLastNameProperty];
- NSString *company = [self valueForProperty:kABOrganizationProperty];
- NSInteger personFlags = [[self valueForProperty:kABPersonFlags] integerValue];
- BOOL isPerson = (personFlags & kABShowAsMask) == kABShowAsPerson;
- BOOL isCompany = (personFlags & kABShowAsMask) == kABShowAsCompany;
-
- ABAddressBook *AB = [ABAddressBook sharedAddressBook];
- NSString *theString = nil;
- if (isPerson) {
- if ([firstName length] > 0 && [lastName length] > 0) {
- if ([AB defaultNameOrdering] == kABFirstNameFirst) {
- theString = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
- } else {
- theString = [NSString stringWithFormat:@"%@ %@", lastName, firstName];
- }
- } else if ([firstName length] > 0) {
- theString = firstName;
- } else if ([lastName length] > 0) {
- theString = lastName;
- }
+ NSString *firstName = [self valueForProperty:kABFirstNameProperty];
+ NSString *lastName = [self valueForProperty:kABLastNameProperty];
+ NSString *company = [self valueForProperty:kABOrganizationProperty];
+ NSInteger personFlags = [[self valueForProperty:kABPersonFlags] integerValue];
+ BOOL isPerson = (personFlags & kABShowAsMask) == kABShowAsPerson;
+ BOOL isCompany = (personFlags & kABShowAsMask) == kABShowAsCompany;
- } else if (isCompany) {
- if ([company length] > 0) {
- theString = company;
+ ABAddressBook *AB = [ABAddressBook sharedAddressBook];
+ NSString *theString = nil;
+ if (isPerson) {
+ if ([firstName length] > 0 && [lastName length] > 0) {
+ if ([AB defaultNameOrdering] == kABFirstNameFirst) {
+ theString = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
+ } else {
+ theString = [NSString stringWithFormat:@"%@ %@", lastName, firstName];
+ }
+ } else if ([firstName length] > 0) {
+ theString = firstName;
+ } else if ([lastName length] > 0) {
+ theString = lastName;
+ }
+
+ } else if (isCompany) {
+ if ([company length] > 0) {
+ theString = company;
+ }
}
- }
-
- return theString;
+
+ return theString;
}
@end
View
16 Classes/AKActiveCallView.h
@@ -33,16 +33,15 @@
@protocol AKActiveCallViewDelegate;
-// The AKActiveCallView class receives DTMF digits |0123456789*#| and control
-// characters |mh| from the keyboard. It gives its delegate a chance to get
-// those DTMF digits and it sends control characters further.
-@interface AKActiveCallView : NSView {
- @private
- id <AKActiveCallViewDelegate> delegate_;
-}
+// The AKActiveCallView class receives DTMF digits |0123456789*#| and control characters |mh| from the keyboard. It
+// gives its delegate a chance to get those DTMF digits and it sends control characters further.
+@interface AKActiveCallView : NSView
// The receiver's delegate.
+// |assign| instead of |weak| because possible candidates for delegate, i.e. NSWindowController and NSViewController,
+// don't support weak references in 10.7.
@property (nonatomic, assign) IBOutlet id <AKActiveCallViewDelegate> delegate;
+
@end
// Declares the interface that AKActiveCallView delegates must implement.
@@ -50,6 +49,5 @@
@optional
// Sent when a view receives text input from the keyboard.
// Now it handles only DTMF digits |0123456789*#|.
-- (void)activeCallView:(AKActiveCallView *)sender
- didReceiveText:(NSString *)aString;
+- (void)activeCallView:(AKActiveCallView *)sender didReceiveText:(NSString *)aString;
@end
View
53 Classes/AKActiveCallView.m
@@ -33,43 +33,38 @@
@implementation AKActiveCallView
-@synthesize delegate = delegate_;
-
- (BOOL)acceptsFirstResponder {
- return YES;
+ return YES;
}
- (void)keyDown:(NSEvent *)theEvent {
- NSCharacterSet *DTMFCharacterSet
- = [NSCharacterSet characterSetWithCharactersInString:@"0123456789*#"];
- NSCharacterSet *commandsCharacterSet
- = [NSCharacterSet characterSetWithCharactersInString:@"mh"];
-
- unichar firstCharacter = [[theEvent characters] characterAtIndex:0];
- if ([DTMFCharacterSet characterIsMember:firstCharacter]) {
- if (![theEvent isARepeat]) {
- // We want to get DTMF string as text.
- [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
- }
- } else if ([commandsCharacterSet characterIsMember:firstCharacter]) {
- if (![theEvent isARepeat]) {
- // Pass call control commands further so that main menu will catch them.
- // The corresponding key equivalents must be set in the main menu.
- // We need this because we have key equivalents without modifiers,
- // in which case NSApplication can't recognize them and can't dispatch
- // appropriate events before we even get here.
- [super keyDown:theEvent];
+ NSCharacterSet *DTMFCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789*#"];
+ NSCharacterSet *commandsCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"mh"];
+
+ unichar firstCharacter = [[theEvent characters] characterAtIndex:0];
+ if ([DTMFCharacterSet characterIsMember:firstCharacter]) {
+ if (![theEvent isARepeat]) {
+ // We want to get DTMF string as text.
+ [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+ }
+ } else if ([commandsCharacterSet characterIsMember:firstCharacter]) {
+ if (![theEvent isARepeat]) {
+ // Pass call control commands further so that main menu will catch them.
+ // The corresponding key equivalents must be set in the main menu.
+ // We need this because we have key equivalents without modifiers,
+ // in which case NSApplication can't recognize them and can't dispatch
+ // appropriate events before we even get here.
+ [super keyDown:theEvent];
+ }
+ } else {
+ [super keyDown:theEvent];
}
- } else {
- [super keyDown:theEvent];
- }
}
- (void)insertText:(id)aString {
- if ([[self delegate] respondsToSelector:
- @selector(activeCallView:didReceiveText:)]) {
- [[self delegate] activeCallView:self didReceiveText:aString];
- }
+ if ([[self delegate] respondsToSelector:@selector(activeCallView:didReceiveText:)]) {
+ [[self delegate] activeCallView:self didReceiveText:aString];
+ }
}
@end
View
15 Classes/AKKeychain.h
@@ -32,18 +32,13 @@
// A Keychain Services wrapper.
-@interface AKKeychain : NSObject {
-
-}
+@interface AKKeychain : NSObject
-// Returns password for the first Keychain item with a specified service name
-// and account name.
-+ (NSString *)passwordForServiceName:(NSString *)serviceName
- accountName:(NSString *)accountName;
+// Returns password for the first Keychain item with a specified service name and account name.
++ (NSString *)passwordForServiceName:(NSString *)serviceName accountName:(NSString *)accountName;
-// Adds an item to the Keychain with a specified service name, account name,
-// and password. If the same item already exists, its password will be replaced
-// with the new one.
+// Adds an item to the Keychain with a specified service name, account name, and password. If the same item already
+// exists, its password will be replaced with the new one.
+ (BOOL)addItemWithServiceName:(NSString *)serviceName
accountName:(NSString *)accountName
password:(NSString *)password;
View
143 Classes/AKKeychain.m
@@ -33,88 +33,83 @@
@implementation AKKeychain
-+ (NSString *)passwordForServiceName:(NSString *)serviceName
- accountName:(NSString *)accountName {
-
- void *passwordData = nil;
- UInt32 passwordLength;
- OSStatus findStatus;
-
- findStatus = SecKeychainFindGenericPassword(
- NULL, // Default keychain.
- [serviceName length],
- [serviceName UTF8String],
- [accountName length],
- [accountName UTF8String],
- &passwordLength,
- &passwordData,
- NULL); // Keychain item reference.
-
- if (findStatus != noErr)
- return nil;
-
- NSString *password = [[[NSString alloc] initWithBytes:passwordData
- length:passwordLength
- encoding:NSUTF8StringEncoding]
- autorelease];
-
- SecKeychainItemFreeContent(NULL, passwordData);
-
- return password;
++ (NSString *)passwordForServiceName:(NSString *)serviceName accountName:(NSString *)accountName {
+ void *passwordData = nil;
+ UInt32 passwordLength;
+ OSStatus findStatus;
+
+ findStatus = SecKeychainFindGenericPassword(NULL, // Default keychain.
+ [serviceName length],
+ [serviceName UTF8String],
+ [accountName length],
+ [accountName UTF8String],
+ &passwordLength,
+ &passwordData,
+ NULL); // Keychain item reference.
+
+ if (findStatus != noErr) {
+ return nil;
+ }
+
+ NSString *password = [[NSString alloc] initWithBytes:passwordData
+ length:passwordLength
+ encoding:NSUTF8StringEncoding];
+
+ SecKeychainItemFreeContent(NULL, passwordData);
+
+ return password;
}
+ (BOOL)addItemWithServiceName:(NSString *)serviceName
accountName:(NSString *)accountName
password:(NSString *)password {
-
- SecKeychainItemRef keychainItemRef = nil;
- OSStatus addStatus, findStatus, modifyStatus;
- BOOL success = NO;
-
- // Add item to keychain.
- addStatus = SecKeychainAddGenericPassword(
- NULL, // NULL for default keychain.
- [serviceName length],
- [serviceName UTF8String],
- [accountName length],
- [accountName UTF8String],
- [password length],
- [password UTF8String],
- NULL); // Don't need keychain item reference.
-
- if (addStatus == noErr) {
- success = YES;
- } else if (addStatus == errSecDuplicateItem) {
- // Get the pointer to the duplicate item.
- findStatus = SecKeychainFindGenericPassword(
- NULL, // Default keychain.
- [serviceName length],
- [serviceName UTF8String],
- [accountName length],
- [accountName UTF8String],
- NULL,
- NULL,
- &keychainItemRef); // Pointer to the duplicate item.
- if (findStatus == noErr) {
- // Modify password in the duplicate item.
- modifyStatus = SecKeychainItemModifyAttributesAndData(
- keychainItemRef,
- NULL, // No changes in attributes.
- [password length],
- [password UTF8String]);
-
- if (modifyStatus == noErr) {
+ SecKeychainItemRef keychainItemRef = nil;
+ OSStatus addStatus, findStatus, modifyStatus;
+ BOOL success = NO;
+
+ // Add item to keychain.
+ addStatus = SecKeychainAddGenericPassword(NULL, // NULL for default keychain.
+ [serviceName length],
+ [serviceName UTF8String],
+ [accountName length],
+ [accountName UTF8String],
+ [password length],
+ [password UTF8String],
+ NULL); // Don't need keychain item reference.
+
+ if (addStatus == noErr) {
success = YES;
- }
+
+ } else if (addStatus == errSecDuplicateItem) {
+ // Get the pointer to the duplicate item.
+ findStatus = SecKeychainFindGenericPassword(NULL, // Default keychain.
+ [serviceName length],
+ [serviceName UTF8String],
+ [accountName length],
+ [accountName UTF8String],
+ NULL,
+ NULL,
+ &keychainItemRef); // Pointer to the duplicate item.
+
+ if (findStatus == noErr) {
+ // Modify password in the duplicate item.
+ modifyStatus = SecKeychainItemModifyAttributesAndData(keychainItemRef,
+ NULL, // No changes in attributes.
+ [password length],
+ [password UTF8String]);
+
+ if (modifyStatus == noErr) {
+ success = YES;
+ }
+ }
}
- }
-
- if (keychainItemRef != nil) {
- CFRelease(keychainItemRef);
- }
-
- return success;
+
+ if (keychainItemRef != nil) {
+ CFRelease(keychainItemRef);
+ }
+
+ return success;
}
@end
View
10 Classes/AKNSString+Creating.m
@@ -32,11 +32,11 @@
@implementation NSString (AKStringCreatingAdditions)
+ (NSString *)ak_uuidString {
- CFUUIDRef theUUID = CFUUIDCreate(NULL);
- CFStringRef string = CFUUIDCreateString(NULL, theUUID);
- CFRelease(theUUID);
-
- return [(NSString *)string autorelease];
+ CFUUIDRef theUUID = CFUUIDCreate(NULL);
+ CFStringRef string = CFUUIDCreateString(NULL, theUUID);
+ CFRelease(theUUID);
+
+ return (__bridge_transfer NSString *)string;
}
@end
View
10 Classes/AKNSString+Escaping.h
@@ -32,16 +32,14 @@
// A category for escaping strings.
@interface NSString (AKStringEscapingAdditions)
-// Returns a new string created from the receiver where every occurrence of the
-// first character from a given string is escaped with a backslash.
+// Returns a new string created from the receiver where every occurrence of the first character from a given string is
+// escaped with a backslash.
- (NSString *)ak_escapeFirstCharacterFromString:(NSString *)string;
-// Returns a new string created from the receiver where every quote character,
-// i.e. |"|, is escaped with a backslash.
+// Returns a new string created from the receiver where every quote character, i.e. |"|, is escaped with a backslash.
- (NSString *)ak_escapeQuotes;
-// Returns a new string created from the receiver where every parenthesis, i.e.
-// |(| or |)|, is escaped with a backslash.
+// Returns a new string created from the receiver where every parenthesis, i.e. |(| or |)|, is escaped with a backslash.
- (NSString *)ak_escapeParentheses;
@end
View
36 Classes/AKNSString+Escaping.m
@@ -32,32 +32,28 @@
@implementation NSString (AKStringEscapingAdditions)
- (NSString *)ak_escapeFirstCharacterFromString:(NSString *)string {
- NSMutableString *newString = [NSMutableString stringWithString:self];
- NSString *escapeCharacterString
- = [string substringWithRange:NSMakeRange(0, 1)];
- NSRange escapeCharacterRange
- = [newString rangeOfString:escapeCharacterString];
- while (escapeCharacterRange.location != NSNotFound) {
- [newString insertString:@"\\" atIndex:escapeCharacterRange.location];
- NSRange searchRange;
- searchRange.location = escapeCharacterRange.location + 2;
- searchRange.length = [newString length] - searchRange.location;
- escapeCharacterRange = [newString rangeOfString:escapeCharacterString
- options:0
- range:searchRange];
- }
-
- return [[newString copy] autorelease];
+ NSMutableString *newString = [NSMutableString stringWithString:self];
+ NSString *escapeCharacterString = [string substringWithRange:NSMakeRange(0, 1)];
+ NSRange escapeCharacterRange = [newString rangeOfString:escapeCharacterString];
+ while (escapeCharacterRange.location != NSNotFound) {
+ [newString insertString:@"\\" atIndex:escapeCharacterRange.location];
+ NSRange searchRange;
+ searchRange.location = escapeCharacterRange.location + 2;
+ searchRange.length = [newString length] - searchRange.location;
+ escapeCharacterRange = [newString rangeOfString:escapeCharacterString options:0 range:searchRange];
+ }
+
+ return [newString copy];
}
- (NSString *)ak_escapeQuotes {
- return [self ak_escapeFirstCharacterFromString:@"\""];
+ return [self ak_escapeFirstCharacterFromString:@"\""];
}
- (NSString *)ak_escapeParentheses {
- NSString *returnString = [self ak_escapeFirstCharacterFromString:@")"];
-
- return [returnString ak_escapeFirstCharacterFromString:@"("];
+ NSString *returnString = [self ak_escapeFirstCharacterFromString:@")"];
+
+ return [returnString ak_escapeFirstCharacterFromString:@"("];
}
@end
View
9 Classes/AKNSString+PJSUA.m
@@ -34,14 +34,13 @@
@implementation NSString (AKStringPJSUAAdditions)
+ (NSString *)stringWithPJString:(pj_str_t)pjString {
- return [[[NSString alloc] initWithBytes:pjString.ptr
- length:(NSUInteger)pjString.slen
- encoding:NSUTF8StringEncoding]
- autorelease];
+ return [[NSString alloc] initWithBytes:pjString.ptr
+ length:(NSUInteger)pjString.slen
+ encoding:NSUTF8StringEncoding];
}
- (pj_str_t)pjString {
- return pj_str((char *)[self cStringUsingEncoding:NSUTF8StringEncoding]);
+ return pj_str((char *)[self cStringUsingEncoding:NSUTF8StringEncoding]);
}
@end
View
4 Classes/AKNSString+Scanning.h
@@ -34,8 +34,8 @@
// A category for scanning strings.
@interface NSString (AKStringScanningAdditions)
-// A Boolean value indicating whether the receiver is a telephone number, e.g.
-// it consists of contiguous digits with an optional leading plus character.
+// A Boolean value indicating whether the receiver is a telephone number, e.g. it consists of contiguous digits with
+// an optional leading plus character.
@property (nonatomic, readonly, assign) BOOL ak_isTelephoneNumber;
// A Boolean value indicating whether the receiver consists only of a-z or A-Z.
View
34 Classes/AKNSString+Scanning.m
@@ -33,33 +33,27 @@
@implementation NSString (AKStringScanningAdditions)
-@dynamic ak_isTelephoneNumber;
-@dynamic ak_hasLetters;
-@dynamic ak_isIPAddress;
-
- (BOOL)ak_isTelephoneNumber {
- NSPredicate *telephoneNumberPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES '\\\\+?\\\\d+'"];
-
- return ([telephoneNumberPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *telephoneNumberPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '\\\\+?\\\\d+'"];
+
+ return ([telephoneNumberPredicate evaluateWithObject:self]) ? YES : NO;
}
- (BOOL)ak_hasLetters {
- NSPredicate *containsLettersPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*[a-zA-Z].*'"];
-
- return ([containsLettersPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *containsLettersPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*[a-zA-Z].*'"];
+
+ return ([containsLettersPredicate evaluateWithObject:self]) ? YES : NO;
}
- (BOOL)ak_isIPAddress {
- NSPredicate *IPAddressPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES "
- "'\\\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\b'"];
-
- return ([IPAddressPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *IPAddressPredicate
+ = [NSPredicate predicateWithFormat:@"SELF MATCHES "
+ "'\\\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\b'"];
+
+ return ([IPAddressPredicate evaluateWithObject:self]) ? YES : NO;
}
@end
View
9 Classes/AKNSWindow+Resizing.h
@@ -34,13 +34,10 @@
// A category for window resizing.
@interface NSWindow (AKWindowResizingAdditions)
-// Sets |aView| content view for the receiver and resizes the receiver with
-// optional animation.
-- (void)ak_resizeAndSwapToContentView:(NSView *)aView
- animate:(BOOL)performAnimation;
+// Sets |aView| content view for the receiver and resizes the receiver with optional animation.
+- (void)ak_resizeAndSwapToContentView:(NSView *)aView animate:(BOOL)performAnimation;
-// Calls |ak_resizeAndSwapToContentView:animate:| with |performAnimation| set
-// to NO.
+// Calls |ak_resizeAndSwapToContentView:animate:| with |performAnimation| set to NO.
- (void)ak_resizeAndSwapToContentView:(NSView *)aView;
@end
View
48 Classes/AKNSWindow+Resizing.m
@@ -33,34 +33,32 @@
@implementation NSWindow (AKWindowResizingAdditions)
-- (void)ak_resizeAndSwapToContentView:(NSView *)aView
- animate:(BOOL)performAnimation {
- // Compute view size delta.
- NSSize currentSize = [[self contentView] frame].size;
- NSSize newSize = [aView frame].size;
- CGFloat deltaWidth = newSize.width - currentSize.width;
- CGFloat deltaHeight = newSize.height - currentSize.height;
-
- // Compute new window size.
- NSRect windowFrame = [self frame];
- windowFrame.size.height += deltaHeight;
- windowFrame.origin.y -= deltaHeight;
- windowFrame.size.width += deltaWidth;
-
- // Show temp view while changing views.
- NSView *tempView = [[NSView alloc] initWithFrame:[[self contentView] frame]];
- [self setContentView:tempView];
- [tempView release];
-
- // Set new window frame.
- [self setFrame:windowFrame display:YES animate:performAnimation];
-
- // Swap to the new view.
- [self setContentView:aView];
+- (void)ak_resizeAndSwapToContentView:(NSView *)aView animate:(BOOL)performAnimation {
+ // Compute view size delta.
+ NSSize currentSize = [[self contentView] frame].size;
+ NSSize newSize = [aView frame].size;
+ CGFloat deltaWidth = newSize.width - currentSize.width;
+ CGFloat deltaHeight = newSize.height - currentSize.height;
+
+ // Compute new window size.
+ NSRect windowFrame = [self frame];
+ windowFrame.size.height += deltaHeight;
+ windowFrame.origin.y -= deltaHeight;
+ windowFrame.size.width += deltaWidth;
+
+ // Show temp view while changing views.
+ NSView *tempView = [[NSView alloc] initWithFrame:[[self contentView] frame]];
+ [self setContentView:tempView];
+
+ // Set new window frame.
+ [self setFrame:windowFrame display:YES animate:performAnimation];
+
+ // Swap to the new view.
+ [self setContentView:aView];
}
- (void)ak_resizeAndSwapToContentView:(NSView *)aView {
- [self ak_resizeAndSwapToContentView:aView animate:NO];
+ [self ak_resizeAndSwapToContentView:aView animate:NO];
}
@end
View
7 Classes/AKNetworkReachability.h
@@ -42,10 +42,9 @@ extern NSString * const AKNetworkReachabilityDidBecomeUnreachableNotification;
// Wrapper for SCNetworkReachability.
@interface AKNetworkReachability : NSObject {
- @private
- SCNetworkReachabilityRef reachability_; // Strong.
- SCNetworkReachabilityContext context_;
- NSString *host_;
+ @private
+ SCNetworkReachabilityRef _reachability; // Strong.
+ SCNetworkReachabilityContext _context;
}
// Host name or address of the target host.
View
146 Classes/AKNetworkReachability.m
@@ -36,15 +36,11 @@
#import "AKNSString+Scanning.h"
-NSString * const AKNetworkReachabilityDidBecomeReachableNotification
- = @"AKNetworkReachabilityDidBecomeReachable";
-NSString * const AKNetworkReachabilityDidBecomeUnreachableNotification
- = @"AKNetworkReachabilityDidBecomeUnreachable";
+NSString * const AKNetworkReachabilityDidBecomeReachableNotification = @"AKNetworkReachabilityDidBecomeReachable";
+NSString * const AKNetworkReachabilityDidBecomeUnreachableNotification = @"AKNetworkReachabilityDidBecomeUnreachable";
// SCNetworkReachability callback.
-static void AKReachabilityChanged(SCNetworkReachabilityRef target,
- SCNetworkConnectionFlags flags,
- void *info);
+static void AKReachabilityChanged(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void *info);
@interface AKNetworkReachability ()
@@ -56,102 +52,78 @@ @interface AKNetworkReachability ()
@implementation AKNetworkReachability
-@synthesize host = host_;
-@dynamic reachable;
-
- (BOOL)isReachable {
- SCNetworkConnectionFlags flags;
- Boolean flagsValid = SCNetworkReachabilityGetFlags(reachability_, &flags);
-
- return (flagsValid && (flags & kSCNetworkFlagsReachable)) ? YES : NO;
+ SCNetworkConnectionFlags flags;
+ Boolean flagsValid = SCNetworkReachabilityGetFlags(_reachability, &flags);
+
+ return (flagsValid && (flags & kSCNetworkFlagsReachable)) ? YES : NO;
}
+ (AKNetworkReachability *)networkReachabilityWithHost:(NSString *)nameOrAddress {
- return [[[self alloc] initWithHost:nameOrAddress] autorelease];
+ return [[self alloc] initWithHost:nameOrAddress];
}
- (id)initWithHost:(NSString *)nameOrAddress {
- self = [super init];
- if (self == nil) {
- return nil;
- }
-
- if ([nameOrAddress length] == 0) {
- [self release];
- return nil;
- }
-
- if ([nameOrAddress ak_isIPAddress]) {
- struct sockaddr_in sin;
- bzero(&sin, sizeof(sin));
- sin.sin_len = sizeof(sin);
- sin.sin_family = AF_INET;
- inet_aton([nameOrAddress UTF8String], &sin.sin_addr);
- reachability_
- = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault,
- (struct sockaddr *)&sin);
- } else {
- reachability_
- = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault,
- [nameOrAddress UTF8String]);
- }
-
- context_.info = self;
- Boolean callbackSet = SCNetworkReachabilitySetCallback(reachability_,
- &AKReachabilityChanged,
- &context_);
- if (!callbackSet) {
- [self release];
- return nil;
- }
-
- Boolean scheduled
- = SCNetworkReachabilityScheduleWithRunLoop(reachability_,
- CFRunLoopGetMain(),
- kCFRunLoopDefaultMode);
- if (!scheduled) {
- [self release];
- return nil;
- }
-
- [self setHost:nameOrAddress];
-
- return self;
+ self = [super init];
+ if (self == nil) {
+ return nil;
+ }
+
+ if ([nameOrAddress length] == 0) {
+ return nil;
+ }
+
+ if ([nameOrAddress ak_isIPAddress]) {
+ struct sockaddr_in sin;
+ bzero(&sin, sizeof(sin));
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ inet_aton([nameOrAddress UTF8String], &sin.sin_addr);
+ _reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr *)&sin);
+ } else {
+ _reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [nameOrAddress UTF8String]);
+ }
+
+ _context.info = (__bridge void *)(self);
+ Boolean callbackSet = SCNetworkReachabilitySetCallback(_reachability, &AKReachabilityChanged, &_context);
+ if (!callbackSet) {
+ return nil;
+ }
+
+ Boolean scheduled = SCNetworkReachabilityScheduleWithRunLoop(_reachability,
+ CFRunLoopGetMain(),
+ kCFRunLoopDefaultMode);
+ if (!scheduled) {
+ return nil;
+ }
+
+ [self setHost:nameOrAddress];
+
+ return self;
}
- (void)dealloc {
- SCNetworkReachabilityUnscheduleFromRunLoop(reachability_,
- CFRunLoopGetMain(),
- kCFRunLoopDefaultMode);
- if (reachability_ != NULL) {
- CFRelease(reachability_);
- }
-
- [host_ release];
-
- [super dealloc];
+ SCNetworkReachabilityUnscheduleFromRunLoop(_reachability, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
+ if (_reachability != NULL) {
+ CFRelease(_reachability);
+ }
}
- (NSString *)description {
- return [NSString stringWithFormat:@"%@ reachability", [self host]];
+ return [NSString stringWithFormat:@"%@ reachability", [self host]];
}
@end
-static void AKReachabilityChanged(SCNetworkReachabilityRef target,
- SCNetworkConnectionFlags flags,
- void *info) {
-
- AKNetworkReachability *networkReachability = (AKNetworkReachability *)info;
-
- if (flags & kSCNetworkFlagsReachable) {
- [[NSNotificationCenter defaultCenter]
- postNotificationName:AKNetworkReachabilityDidBecomeReachableNotification
- object:networkReachability];
- } else {
- [[NSNotificationCenter defaultCenter]
- postNotificationName:AKNetworkReachabilityDidBecomeUnreachableNotification
- object:networkReachability];
- }
+static void AKReachabilityChanged(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void *info) {
+ AKNetworkReachability *networkReachability = (__bridge AKNetworkReachability *)info;
+
+ if (flags & kSCNetworkFlagsReachable) {
+ [[NSNotificationCenter defaultCenter] postNotificationName:AKNetworkReachabilityDidBecomeReachableNotification
+ object:networkReachability];
+ } else {
+ [[NSNotificationCenter defaultCenter] postNotificationName:AKNetworkReachabilityDidBecomeUnreachableNotification
+ object:networkReachability];
+ }
}
View
11 Classes/AKResponsiveProgressIndicator.h
@@ -31,16 +31,11 @@
#import <Cocoa/Cocoa.h>
-// Allows progress indicator to send an action message to a target on mouse-up
-// events.
-@interface AKResponsiveProgressIndicator : NSProgressIndicator {
- @private
- id target_;
- SEL action_;
-}
+// Allows progress indicator to send an action message to a target on mouse-up events.
+@interface AKResponsiveProgressIndicator : NSProgressIndicator
// The receiver's target.
-@property (nonatomic, assign) id target;
+@property (nonatomic, weak) id target;
// The receiver's action-message selector.
@property (nonatomic, assign) SEL action;
View
5 Classes/AKResponsiveProgressIndicator.m
@@ -33,11 +33,8 @@
@implementation AKResponsiveProgressIndicator
-@synthesize target = target_;
-@synthesize action = action_;
-
- (void)mouseUp:(NSEvent *)theEvent {
- [NSApp sendAction:[self action] to:[self target] from:self];
+ [NSApp sendAction:[self action] to:[self target] from:self];
}
@end
View
41 Classes/AKSIPAccount.h
@@ -55,34 +55,17 @@ extern NSString * const AKSIPAccountWillMakeCallNotification;
@class AKSIPURI;
-// A class representing a SIP account. It contains a list of calls and maintains
-// SIP registration. You can use this class to make and receive calls.
-@interface AKSIPAccount : NSObject {
- @private
- NSObject <AKSIPAccountDelegate> *delegate_;
-
- AKSIPURI *registrationURI_;
-
- NSString *fullName_;
- NSString *SIPAddress_;
- NSString *registrar_;
- NSString *realm_;
- NSString *username_;
- NSString *proxyHost_;
- NSUInteger proxyPort_;
- NSUInteger reregistrationTime_;
-
- NSInteger identifier_;
-
- NSMutableArray *calls_;
-}
+// A class representing a SIP account. It contains a list of calls and maintains SIP registration. You can use this
+// class to make and receive calls.
+@interface AKSIPAccount : NSObject
// The receiver's delegate.
+// |assign| instead of |weak| because possible candidates for delegate, i.e. NSWindowController and NSViewController,
+// don't support weak references in 10.7.
@property (nonatomic, assign) NSObject <AKSIPAccountDelegate> *delegate;
// The URI for SIP registration.
-// It is composed of |fullName| and |SIPAddress|,
-// e.g. "John Smith" <john@company.com>
+// It is composed of |fullName| and |SIPAddress|, e.g. "John Smith" <john@company.com>
// TODO(eofster): strange property. Do we need this?
@property (nonatomic, copy) AKSIPURI *registrationURI;
@@ -95,8 +78,7 @@ extern NSString * const AKSIPAccountWillMakeCallNotification;
// Registrar.
@property (nonatomic, copy) NSString *registrar;
-// Realm. Pass nil to make a credential that can be used to authenticate against
-// any challenges.
+// Realm. Pass nil to make a credential that can be used to authenticate against any challenges.
@property (nonatomic, copy) NSString *realm;
// Authentication user name.
@@ -136,10 +118,10 @@ extern NSString * const AKSIPAccountWillMakeCallNotification;
@property (nonatomic, readonly, copy) NSString *onlineStatusText;
// Calls that belong to the receiver.
-@property (readonly, retain) NSMutableArray *calls;
+@property (readonly, strong) NSMutableArray *calls;
-// Creates and returns an AKSIPAccount object initialized with a given full
-// name, SIP address, registrar, realm, and user name.
+// Creates and returns an AKSIPAccount object initialized with a given full name, SIP address, registrar, realm, and
+// user name.
+ (id)SIPAccountWithFullName:(NSString *)aFullName
SIPAddress:(NSString *)aSIPAddress
registrar:(NSString *)aRegistrar
@@ -147,8 +129,7 @@ extern NSString * const AKSIPAccountWillMakeCallNotification;
username:(NSString *)aUsername;
// Designated initializer.
-// Initializes an AKSIPAccount object with a given full name, SIP address,
-// registrar, realm, and user name.
+// Initializes an AKSIPAccount object with a given full name, SIP address, registrar, realm, and user name.
- (id)initWithFullName:(NSString *)aFullName
SIPAddress:(NSString *)aSIPAddress
registrar:(NSString *)aRegistrar
View
392 Classes/AKSIPAccount.m
@@ -39,187 +39,164 @@
const NSInteger kAKSIPAccountDefaultSIPProxyPort = 5060;
const NSInteger kAKSIPAccountDefaultReregistrationTime = 300;
-NSString * const AKSIPAccountRegistrationDidChangeNotification
- = @"AKSIPAccountRegistrationDidChange";
-NSString * const AKSIPAccountWillMakeCallNotification
- = @"AKSIPAccountWillMakeCall";
+NSString * const AKSIPAccountRegistrationDidChangeNotification = @"AKSIPAccountRegistrationDidChange";
+NSString * const AKSIPAccountWillMakeCallNotification = @"AKSIPAccountWillMakeCall";
@implementation AKSIPAccount
-@synthesize delegate = delegate_;
-@synthesize registrationURI = registrationURI_;
-@synthesize fullName = fullName_;
-@synthesize SIPAddress = SIPAddress_;
-@synthesize registrar = registrar_;
-@synthesize realm = realm_;
-@synthesize username = username_;
-@synthesize proxyHost = proxyHost_;
-@synthesize proxyPort = proxyPort_;
-@synthesize reregistrationTime = reregistrationTime_;
-@synthesize identifier = identifier_;
-@dynamic registered;
-@dynamic registrationStatus;
-@dynamic registrationStatusText;
-@dynamic registrationExpireTime;
-@dynamic online;
-@dynamic onlineStatusText;
-@synthesize calls = calls_;
-
- (void)setDelegate:(NSObject <AKSIPAccountDelegate> *)aDelegate {
- if (delegate_ == aDelegate)
- return;
-
- NSNotificationCenter *notificationCenter
- = [NSNotificationCenter defaultCenter];
-
- if (delegate_ != nil)
- [notificationCenter removeObserver:delegate_ name:nil object:self];
-
- if (aDelegate != nil) {
- if ([aDelegate respondsToSelector:
- @selector(SIPAccountRegistrationDidChange:)]) {
- [notificationCenter
- addObserver:aDelegate
- selector:@selector(SIPAccountRegistrationDidChange:)
- name:AKSIPAccountRegistrationDidChangeNotification
- object:self];
+ if (_delegate == aDelegate) {
+ return;
+ }
+
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+
+ if (_delegate != nil) {
+ [notificationCenter removeObserver:_delegate name:nil object:self];
+ }
+
+ if (aDelegate != nil) {
+ if ([aDelegate respondsToSelector:@selector(SIPAccountRegistrationDidChange:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPAccountRegistrationDidChange:)
+ name:AKSIPAccountRegistrationDidChangeNotification
+ object:self];
+ }
}
- }
-
- delegate_ = aDelegate;
+
+ _delegate = aDelegate;
}
- (void)setProxyPort:(NSUInteger)port {
- if (port > 0 && port < 65535) {
- proxyPort_ = port;
- } else {
- proxyPort_ = kAKSIPAccountDefaultSIPProxyPort;
- }
+ if (port > 0 && port < 65535) {
+ _proxyPort = port;
+ } else {
+ _proxyPort = kAKSIPAccountDefaultSIPProxyPort;
+ }
}
- (void)setReregistrationTime:(NSUInteger)seconds {
- const NSInteger reregistrationTimeMin = 60;
- const NSInteger reregistrationTimeMax = 3600;
- if (seconds == 0) {
- reregistrationTime_ = kAKSIPAccountDefaultReregistrationTime;
- } else if (seconds < reregistrationTimeMin) {
- reregistrationTime_ = reregistrationTimeMin;
- } else if (seconds > reregistrationTimeMax) {
- reregistrationTime_ = reregistrationTimeMax;
- } else {
- reregistrationTime_ = seconds;
- }
+ const NSInteger reregistrationTimeMin = 60;
+ const NSInteger reregistrationTimeMax = 3600;
+ if (seconds == 0) {
+ _reregistrationTime = kAKSIPAccountDefaultReregistrationTime;
+ } else if (seconds < reregistrationTimeMin) {
+ _reregistrationTime = reregistrationTimeMin;
+ } else if (seconds > reregistrationTimeMax) {
+ _reregistrationTime = reregistrationTimeMax;
+ } else {
+ _reregistrationTime = seconds;
+ }
}
- (BOOL)isRegistered {
- return ([self registrationStatus] / 100 == 2) &&
- ([self registrationExpireTime] > 0);
+ return ([self registrationStatus] / 100 == 2) && ([self registrationExpireTime] > 0);
}
- (void)setRegistered:(BOOL)value {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return;
- }
-
- if (value) {
- pjsua_acc_set_registration([self identifier], PJ_TRUE);
- [self setOnline:YES];
- } else {
- [self setOnline:NO];
- pjsua_acc_set_registration([self identifier], PJ_FALSE);
- }
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return;
+ }
+
+ if (value) {
+ pjsua_acc_set_registration([self identifier], PJ_TRUE);
+ [self setOnline:YES];
+ } else {
+ [self setOnline:NO];
+ pjsua_acc_set_registration([self identifier], PJ_FALSE);
+ }
}
- (NSInteger)registrationStatus {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return 0;
- }
-
- pjsua_acc_info accountInfo;
- pj_status_t status;
-
- status = pjsua_acc_get_info([self identifier], &accountInfo);
- if (status != PJ_SUCCESS) {
- return 0;
- }
-
- return accountInfo.status;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return 0;
+ }
+
+ pjsua_acc_info accountInfo;
+ pj_status_t status;
+
+ status = pjsua_acc_get_info([self identifier], &accountInfo);
+ if (status != PJ_SUCCESS) {
+ return 0;
+ }
+
+ return accountInfo.status;
}
- (NSString *)registrationStatusText {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return nil;
- }
-
- pjsua_acc_info accountInfo;
- pj_status_t status;
-
- status = pjsua_acc_get_info([self identifier], &accountInfo);
- if (status != PJ_SUCCESS) {
- return nil;
- }
-
- return [NSString stringWithPJString:accountInfo.status_text];
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return nil;
+ }
+
+ pjsua_acc_info accountInfo;
+ pj_status_t status;
+
+ status = pjsua_acc_get_info([self identifier], &accountInfo);
+ if (status != PJ_SUCCESS) {
+ return nil;
+ }
+
+ return [NSString stringWithPJString:accountInfo.status_text];
}
- (NSInteger)registrationExpireTime {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return -1;
- }
-
- pjsua_acc_info accountInfo;
- pj_status_t status;
-
- status = pjsua_acc_get_info([self identifier], &accountInfo);
- if (status != PJ_SUCCESS) {
- return -1;
- }
-
- return accountInfo.expires;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return -1;
+ }
+
+ pjsua_acc_info accountInfo;
+ pj_status_t status;
+
+ status = pjsua_acc_get_info([self identifier], &accountInfo);
+ if (status != PJ_SUCCESS) {
+ return -1;
+ }
+
+ return accountInfo.expires;
}
- (BOOL)isOnline {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- pjsua_acc_info accountInfo;
- pj_status_t status;
-
- status = pjsua_acc_get_info([self identifier], &accountInfo);
- if (status != PJ_SUCCESS) {
- return NO;
- }
-
- return (accountInfo.online_status == PJ_TRUE) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ pjsua_acc_info accountInfo;
+ pj_status_t status;
+
+ status = pjsua_acc_get_info([self identifier], &accountInfo);
+ if (status != PJ_SUCCESS) {
+ return NO;
+ }
+
+ return (accountInfo.online_status == PJ_TRUE) ? YES : NO;
}
- (void)setOnline:(BOOL)value {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return;
- }
-
- if (value) {
- pjsua_acc_set_online_status([self identifier], PJ_TRUE);
- } else {
- pjsua_acc_set_online_status([self identifier], PJ_FALSE);
- }
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return;
+ }
+
+ if (value) {
+ pjsua_acc_set_online_status([self identifier], PJ_TRUE);
+ } else {
+ pjsua_acc_set_online_status([self identifier], PJ_FALSE);
+ }
}
- (NSString *)onlineStatusText {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return nil;
- }
-
- pjsua_acc_info accountInfo;
- pj_status_t status;
-
- status = pjsua_acc_get_info([self identifier], &accountInfo);
- if (status != PJ_SUCCESS) {
- return nil;
- }
-
- return [NSString stringWithPJString:accountInfo.online_status_text];
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return nil;
+ }
+
+ pjsua_acc_info accountInfo;
+ pj_status_t status;
+
+ status = pjsua_acc_get_info([self identifier], &accountInfo);
+ if (status != PJ_SUCCESS) {
+ return nil;
+ }
+
+ return [NSString stringWithPJString:accountInfo.online_status_text];
}
+ (id)SIPAccountWithFullName:(NSString *)aFullName
@@ -227,13 +204,12 @@ + (id)SIPAccountWithFullName:(NSString *)aFullName
registrar:(NSString *)aRegistrar
realm:(NSString *)aRealm
username:(NSString *)aUsername {
-
- return [[[AKSIPAccount alloc] initWithFullName:aFullName
- SIPAddress:aSIPAddress
- registrar:aRegistrar
- realm:aRealm
- username:aUsername]
- autorelease];
+
+ return [[AKSIPAccount alloc] initWithFullName:aFullName
+ SIPAddress:aSIPAddress
+ registrar:aRegistrar
+ realm:aRealm
+ username:aUsername];
}
- (id)initWithFullName:(NSString *)aFullName
@@ -241,86 +217,62 @@ - (id)initWithFullName:(NSString *)aFullName
registrar:(NSString *)aRegistrar
realm:(NSString *)aRealm
username:(NSString *)aUsername {
-
- self = [super init];
- if (self == nil) {
- return nil;
- }
-
- [self setRegistrationURI:[AKSIPURI SIPURIWithString:
- [NSString stringWithFormat:@"\"%@\" <sip:%@>",
- aFullName, aSIPAddress]]];
-
- [self setFullName:aFullName];
- [self setSIPAddress:aSIPAddress];
- [self setRegistrar:aRegistrar];
- [self setRealm:aRealm];
- [self setUsername:aUsername];
- [self setProxyPort:kAKSIPAccountDefaultSIPProxyPort];
- [self setReregistrationTime:kAKSIPAccountDefaultReregistrationTime];
- [self setIdentifier:kAKSIPUserAgentInvalidIdentifier];
-
- calls_ = [[NSMutableArray alloc] init];
-
- return self;
+
+ self = [super init];
+ if (self == nil) {
+ return nil;
+ }
+
+ [self setRegistrationURI:[AKSIPURI SIPURIWithString:[NSString stringWithFormat:@"\"%@\" <sip:%@>",
+ aFullName, aSIPAddress]]];
+
+ [self setFullName:aFullName];
+ [self setSIPAddress:aSIPAddress];
+ [self setRegistrar:aRegistrar];
+ [self setRealm:aRealm];
+ [self setUsername:aUsername];
+ [self setProxyPort:kAKSIPAccountDefaultSIPProxyPort];
+ [self setReregistrationTime:kAKSIPAccountDefaultReregistrationTime];
+ [self setIdentifier:kAKSIPUserAgentInvalidIdentifier];
+
+ _calls = [[NSMutableArray alloc] init];
+
+ return self;
}
- (id)init {
- return [self initWithFullName:nil
- SIPAddress:nil
- registrar:nil
- realm:nil
- username:nil];
+ return [self initWithFullName:nil SIPAddress:nil registrar:nil realm:nil username:nil];
}
- (void)dealloc {
- [self setDelegate:nil];
-
- [registrationURI_ release];
-
- [fullName_ release];
- [SIPAddress_ release];
- [registrar_ release];
- [realm_ release];
- [username_ release];
- [proxyHost_ release];
-
- [calls_ release];
-
- [super dealloc];
+ [self setDelegate:nil];
}
- (NSString *)description {
- return [self SIPAddress];
+ return [self SIPAddress];
}
- (AKSIPCall *)makeCallTo:(AKSIPURI *)destinationURI {
- [[NSNotificationCenter defaultCenter]
- postNotificationName:AKSIPAccountWillMakeCallNotification
- object:self];
-
- pjsua_call_id callIdentifier;
- pj_str_t uri = [[destinationURI description] pjString];
-
- pj_status_t status = pjsua_call_make_call([self identifier],
- &uri,
- 0,
- NULL,
- NULL,
- &callIdentifier);
- AKSIPCall *theCall = nil;
- if (status == PJ_SUCCESS) {
- for (AKSIPCall *aCall in [[[self calls] copy] autorelease]) {
- if ([aCall identifier] == callIdentifier) {
- theCall = [[aCall retain] autorelease];
- break;
- }
+ [[NSNotificationCenter defaultCenter] postNotificationName:AKSIPAccountWillMakeCallNotification
+ object:self];
+
+ pjsua_call_id callIdentifier;
+ pj_str_t uri = [[destinationURI description] pjString];
+
+ pj_status_t status = pjsua_call_make_call([self identifier], &uri, 0, NULL, NULL, &callIdentifier);
+ AKSIPCall *theCall = nil;
+ if (status == PJ_SUCCESS) {
+ for (AKSIPCall *aCall in [self calls]) {
+ if ([aCall identifier] == callIdentifier) {
+ theCall = aCall;
+ break;
+ }
+ }
+ } else {
+ NSLog(@"Error making call to %@ via account %@", destinationURI, self);
}
- } else {
- NSLog(@"Error making call to %@ via account %@", destinationURI, self);
- }
-
- return theCall;
+
+ return theCall;
}
@end
View
73 Classes/AKSIPCall.h
@@ -35,26 +35,26 @@
extern const NSInteger kAKSIPCallsMax;
enum {
- // Before INVITE is sent or received.
- kAKSIPCallNullState = PJSIP_INV_STATE_NULL,
-
- // After INVITE is sent.
- kAKSIPCallCallingState = PJSIP_INV_STATE_CALLING,
-
- // After INVITE is received.
- kAKSIPCallIncomingState = PJSIP_INV_STATE_INCOMING,
-
- // After response with To tag.
- kAKSIPCallEarlyState = PJSIP_INV_STATE_EARLY,
-
- // After 2xx is sent/received.
- kAKSIPCallConnectingState = PJSIP_INV_STATE_CONNECTING,
-
- // After ACK is sent/received.
- kAKSIPCallConfirmedState = PJSIP_INV_STATE_CONFIRMED,
-
- // Session is terminated.
- kAKSIPCallDisconnectedState = PJSIP_INV_STATE_DISCONNECTED
+ // Before INVITE is sent or received.
+ kAKSIPCallNullState = PJSIP_INV_STATE_NULL,
+
+ // After INVITE is sent.
+ kAKSIPCallCallingState = PJSIP_INV_STATE_CALLING,
+
+ // After INVITE is received.
+ kAKSIPCallIncomingState = PJSIP_INV_STATE_INCOMING,
+
+ // After response with To tag.
+ kAKSIPCallEarlyState = PJSIP_INV_STATE_EARLY,
+
+ // After 2xx is sent/received.
+ kAKSIPCallConnectingState = PJSIP_INV_STATE_CONNECTING,
+
+ // After ACK is sent/received.
+ kAKSIPCallConfirmedState = PJSIP_INV_STATE_CONFIRMED,
+
+ // Session is terminated.
+ kAKSIPCallDisconnectedState = PJSIP_INV_STATE_DISCONNECTED
};
typedef NSUInteger AKSIPCallState;
@@ -68,7 +68,7 @@ extern NSString * const AKSIPCallCallingNotification;
extern NSString * const AKSIPCallIncomingNotification;
//
// Early. After response with To tag.
-// Keys: // @"AKSIPEventCode", @"AKSIPEventReason".
+// Keys: @"AKSIPEventCode", @"AKSIPEventReason".
extern NSString * const AKSIPCallEarlyNotification;
//
// Connecting. After 2xx is sent/received.
@@ -96,27 +96,11 @@ extern NSString * const AKSIPCallTransferStatusDidChangeNotification;
@class AKSIPAccount, AKSIPURI;
// A class representing a SIP call.
-@interface AKSIPCall : NSObject {
- @private
- id delegate_;
-
- NSInteger identifier_;
- AKSIPURI *localURI_;
- AKSIPURI *remoteURI_;
- AKSIPCallState state_;
- NSString *stateText_;
- NSInteger lastStatus_;
- NSString *lastStatusText_;
- NSInteger transferStatus_;
- NSString *transferStatusText_;
- BOOL incoming_;
- BOOL microphoneMuted_;
-
- // Account the call belongs to.
- AKSIPAccount *account_;
-}
+@interface AKSIPCall : NSObject
// The receiver's delegate.
+// |assign| instead of |weak| because possible candidates for delegate, i.e. NSWindowController and NSViewController,
+// don't support weak references in 10.7.
@property (nonatomic, assign) id delegate;
// The receiver's identifier.
@@ -169,7 +153,7 @@ extern NSString * const AKSIPCallTransferStatusDidChangeNotification;
@property (nonatomic, readonly, assign, getter=isOnRemoteHold) BOOL onRemoteHold;
// The account the call belongs to.
-@property (nonatomic, assign) AKSIPAccount *account;
+@property (nonatomic, weak) AKSIPAccount *account;
// Designated initializer.
// Initializes a AKSIPCall object with a given SIP account and identifier.
@@ -182,10 +166,9 @@ extern NSString * const AKSIPCallTransferStatusDidChangeNotification;
// Hangs-up the call.
- (void)hangUp;
-// Attended call transfer. Sends REFER request to the receiver's remote party
-// to initiate new INVITE session to the URL of |destinationCall|. The party
-// at |destinationCall| then should replace the call with us with the new call
-// from the REFER recipient.
+// Attended call transfer. Sends REFER request to the receiver's remote party to initiate new INVITE session to the URL
+// of |destinationCall|. The party at |destinationCall| then should replace the call with us with the new call from the
+// REFER recipient.
- (void)attendedTransferToCall:(AKSIPCall *)destinationCall;
// Sends ringing notification to another party.
View
583 Classes/AKSIPCall.m
@@ -46,415 +46,362 @@
NSString * const AKSIPCallConnectingNotification = @"AKSIPCallConnecting";
NSString * const AKSIPCallDidConfirmNotification = @"AKSIPCallDidConfirm";
NSString * const AKSIPCallDidDisconnectNotification = @"AKSIPCallDidDisconnect";
-NSString * const AKSIPCallMediaDidBecomeActiveNotification
- = @"AKSIPCallMediaDidBecomeActive";
+NSString * const AKSIPCallMediaDidBecomeActiveNotification = @"AKSIPCallMediaDidBecomeActive";
NSString * const AKSIPCallDidLocalHoldNotification = @"AKSIPCallDidLocalHold";
NSString * const AKSIPCallDidRemoteHoldNotification = @"AKSIPCallDidRemoteHold";
-NSString * const AKSIPCallTransferStatusDidChangeNotification
- = @"AKSIPCallTransferStatusDidChange";
+NSString * const AKSIPCallTransferStatusDidChangeNotification = @"AKSIPCallTransferStatusDidChange";
@implementation AKSIPCall
-@synthesize delegate = delegate_;
-@synthesize identifier = identifier_;
-@synthesize localURI = localURI_;
-@synthesize remoteURI = remoteURI_;
-@synthesize state = state_;
-@synthesize stateText = stateText_;
-@synthesize lastStatus = lastStatus_;
-@synthesize lastStatusText = lastStatusText_;
-@synthesize transferStatus = transferStatus_;
-@synthesize transferStatusText = transferStatusText_;
-@dynamic active;
-@dynamic hasMedia;
-@dynamic hasActiveMedia;
-@synthesize incoming = incoming_;
-@synthesize microphoneMuted = microphoneMuted_;
-@dynamic onLocalHold;
-@dynamic onRemoteHold;
-@synthesize account = account_;
-
- (void)setDelegate:(id)aDelegate {
- if (delegate_ == aDelegate) {
- return;
- }
-
- NSNotificationCenter *notificationCenter
- = [NSNotificationCenter defaultCenter];
-
- if (delegate_ != nil) {
- [notificationCenter removeObserver:delegate_ name:nil object:self];
- }
-
- if (aDelegate != nil) {
- // Subscribe to notifications
- if ([aDelegate respondsToSelector:@selector(SIPCallCalling:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallCalling:)
- name:AKSIPCallCallingNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallIncoming:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallIncoming:)
- name:AKSIPCallIncomingNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallEarly:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallEarly:)
- name:AKSIPCallEarlyNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallConnecting:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallConnecting:)
- name:AKSIPCallConnectingNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallDidConfirm:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallDidConfirm:)
- name:AKSIPCallDidConfirmNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallDidDisconnect:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallDidDisconnect:)
- name:AKSIPCallDidDisconnectNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:
- @selector(SIPCallMediaDidBecomeActive:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallMediaDidBecomeActive:)
- name:AKSIPCallMediaDidBecomeActiveNotification
- object:self];
- }
- if ([aDelegate respondsToSelector:@selector(SIPCallDidLocalHold:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallDidLocalHold:)
- name:AKSIPCallDidLocalHoldNotification
- object:self];
+ if (_delegate == aDelegate) {
+ return;
}
- if ([aDelegate respondsToSelector:@selector(SIPCallDidRemoteHold:)]) {
- [notificationCenter addObserver:aDelegate
- selector:@selector(SIPCallDidRemoteHold:)
- name:AKSIPCallDidRemoteHoldNotification
- object:self];
+
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+
+ if (_delegate != nil) {
+ [notificationCenter removeObserver:_delegate name:nil object:self];
}
- if ([aDelegate respondsToSelector:
- @selector(SIPCallTransferStatusDidChange:)]) {
- [notificationCenter
- addObserver:aDelegate
- selector:@selector(SIPCallTransferStatusDidChange:)
- name:AKSIPCallTransferStatusDidChangeNotification
- object:self];
+
+ if (aDelegate != nil) {
+ // Subscribe to notifications
+ if ([aDelegate respondsToSelector:@selector(SIPCallCalling:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallCalling:)
+ name:AKSIPCallCallingNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallIncoming:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallIncoming:)
+ name:AKSIPCallIncomingNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallEarly:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallEarly:)
+ name:AKSIPCallEarlyNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallConnecting:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallConnecting:)
+ name:AKSIPCallConnectingNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallDidConfirm:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallDidConfirm:)
+ name:AKSIPCallDidConfirmNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallDidDisconnect:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallDidDisconnect:)
+ name:AKSIPCallDidDisconnectNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallMediaDidBecomeActive:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallMediaDidBecomeActive:)
+ name:AKSIPCallMediaDidBecomeActiveNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallDidLocalHold:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallDidLocalHold:)
+ name:AKSIPCallDidLocalHoldNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallDidRemoteHold:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallDidRemoteHold:)
+ name:AKSIPCallDidRemoteHoldNotification
+ object:self];
+ }
+ if ([aDelegate respondsToSelector:@selector(SIPCallTransferStatusDidChange:)]) {
+ [notificationCenter addObserver:aDelegate
+ selector:@selector(SIPCallTransferStatusDidChange:)
+ name:AKSIPCallTransferStatusDidChangeNotification
+ object:self];
+ }
}
- }
-
- delegate_ = aDelegate;
+
+ _delegate = aDelegate;
}
- (BOOL)isActive {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- return (pjsua_call_is_active([self identifier])) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ return (pjsua_call_is_active([self identifier])) ? YES : NO;
}
- (BOOL)hasMedia {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- return (pjsua_call_has_media([self identifier])) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ return (pjsua_call_has_media([self identifier])) ? YES : NO;
}
- (BOOL)hasActiveMedia {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- pjsua_call_info callInfo;
- pjsua_call_get_info([self identifier], &callInfo);
-
- return (callInfo.media_status == PJSUA_CALL_MEDIA_ACTIVE) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ pjsua_call_info callInfo;
+ pjsua_call_get_info([self identifier], &callInfo);
+
+ return (callInfo.media_status == PJSUA_CALL_MEDIA_ACTIVE) ? YES : NO;
}
- (BOOL)isOnLocalHold {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- pjsua_call_info callInfo;
- pjsua_call_get_info([self identifier], &callInfo);
-
- return (callInfo.media_status == PJSUA_CALL_MEDIA_LOCAL_HOLD) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ pjsua_call_info callInfo;
+ pjsua_call_get_info([self identifier], &callInfo);
+
+ return (callInfo.media_status == PJSUA_CALL_MEDIA_LOCAL_HOLD) ? YES : NO;
}
- (BOOL)isOnRemoteHold {
- if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return NO;
- }
-
- pjsua_call_info callInfo;
- pjsua_call_get_info([self identifier], &callInfo);
-
- return (callInfo.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) ? YES : NO;
+ if ([self identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return NO;
+ }
+
+ pjsua_call_info callInfo;
+ pjsua_call_get_info([self identifier], &callInfo);
+
+ return (callInfo.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) ? YES : NO;
}
#pragma mark -
-- (id)initWithSIPAccount:(AKSIPAccount *)anAccount
- identifier:(NSInteger)anIdentifier {
-
- self = [super init];
- if (self == nil) {
- return nil;
- }
-
- [self setIdentifier:anIdentifier];
- [self setAccount:anAccount];
-
- pjsua_call_info callInfo;
- pj_status_t status = pjsua_call_get_info(anIdentifier, &callInfo);
- if (status == PJ_SUCCESS) {
- [self setState:callInfo.state];
- [self setStateText:[NSString stringWithPJString:callInfo.state_text]];
- [self setLastStatus:callInfo.last_status];
- [self setLastStatusText:
- [NSString stringWithPJString:callInfo.last_status_text]];
- [self setRemoteURI:[AKSIPURI SIPURIWithString:
- [NSString stringWithPJString:callInfo.remote_info]]];
- [self setLocalURI:[AKSIPURI SIPURIWithString:
- [NSString stringWithPJString:callInfo.local_info]]];
+- (id)initWithSIPAccount:(AKSIPAccount *)anAccount identifier:(NSInteger)anIdentifier {
+ self = [super init];
+ if (self == nil) {
+ return nil;
+ }
+
+ [self setIdentifier:anIdentifier];
+ [self setAccount:anAccount];
- if (callInfo.state == kAKSIPCallIncomingState) {
- [self setIncoming:YES];
+ pjsua_call_info callInfo;
+ pj_status_t status = pjsua_call_get_info(anIdentifier, &callInfo);
+ if (status == PJ_SUCCESS) {
+ [self setState:callInfo.state];
+ [self setStateText:[NSString stringWithPJString:callInfo.state_text]];
+ [self setLastStatus:callInfo.last_status];
+ [self setLastStatusText:[NSString stringWithPJString:callInfo.last_status_text]];
+ [self setRemoteURI:[AKSIPURI SIPURIWithString:[NSString stringWithPJString:callInfo.remote_info]]];
+ [self setLocalURI:[AKSIPURI SIPURIWithString:[NSString stringWithPJString:callInfo.local_info]]];
+
+ if (callInfo.state == kAKSIPCallIncomingState) {
+ [self setIncoming:YES];
+ } else {
+ [self setIncoming:NO];
+ }
+
} else {
- [self setIncoming:NO];
+ [self setState:kAKSIPCallNullState];
+ [self setIncoming:NO];
}
- } else {
- [self setState:kAKSIPCallNullState];
- [self setIncoming:NO];
- }
-
- return self;
+ return self;
}
- (id)init {
- return [self initWithSIPAccount:nil
- identifier:kAKSIPUserAgentInvalidIdentifier];
+ return [self initWithSIPAccount:nil identifier:kAKSIPUserAgentInvalidIdentifier];
}
- (void)dealloc {
- if ([[AKSIPUserAgent sharedUserAgent] isStarted]) {
- [self hangUp];
- }
-
- [self setDelegate:nil];
-
- [localURI_ release];
- [remoteURI_ release];
- [stateText_ release];
- [lastStatusText_ release];
- [transferStatusText_ release];
-
- [super dealloc];
+ if ([[AKSIPUserAgent sharedUserAgent] isStarted]) {
+ [self hangUp];
+ }
+
+ [self setDelegate:nil];
}
- (NSString *)description {
- return [NSString stringWithFormat:@"%@ <=> %@", [self localURI],
- [self remoteURI]];
+ return [NSString stringWithFormat:@"%@ <=> %@", [self localURI], [self remoteURI]];
}
- (void)answer {
- pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_OK,
- NULL, NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error answering call %@", self);
- }
+ pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_OK, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error answering call %@", self);
+ }
}
- (void)hangUp {
- if (([self identifier] == kAKSIPUserAgentInvalidIdentifier) ||
- ([self state] == kAKSIPCallDisconnectedState)) {
- return;
- }
-
- pj_status_t status = pjsua_call_hangup([self identifier], 0, NULL, NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error hanging up call %@", self);
- }
+ if (([self identifier] == kAKSIPUserAgentInvalidIdentifier) || ([self state] == kAKSIPCallDisconnectedState)) {
+ return;
+ }
+
+ pj_status_t status = pjsua_call_hangup([self identifier], 0, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error hanging up call %@", self);
+ }
}
- (void)attendedTransferToCall:(AKSIPCall *)destinationCall {
- [self setTransferStatus:kAKSIPUserAgentInvalidIdentifier];
- [self setTransferStatusText:nil];
- pj_status_t status
- = pjsua_call_xfer_replaces([self identifier],
- [destinationCall identifier],
- PJSUA_XFER_NO_REQUIRE_REPLACES,
- NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error transfering call %@", self);
- }
+ [self setTransferStatus:kAKSIPUserAgentInvalidIdentifier];
+ [self setTransferStatusText:nil];
+ pj_status_t status = pjsua_call_xfer_replaces([self identifier],
+ [destinationCall identifier],
+ PJSUA_XFER_NO_REQUIRE_REPLACES,
+ NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error transfering call %@", self);
+ }
}
- (void)sendRingingNotification {
- pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_RINGING,
- NULL, NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error sending ringing notification in call %@", self);
- }
+ pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_RINGING, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error sending ringing notification in call %@", self);
+ }
}
- (void)replyWithTemporarilyUnavailable {
- pj_status_t status = pjsua_call_answer([self identifier],
- PJSIP_SC_TEMPORARILY_UNAVAILABLE,
- NULL, NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error replying with 480 Temporarily Unavailable");
- }
+ pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_TEMPORARILY_UNAVAILABLE, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error replying with 480 Temporarily Unavailable");
+ }
}
- (void)replyWithBusyHere {
- pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_BUSY_HERE,
- NULL, NULL);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error replying with 486 Busy Here");
- }
+ pj_status_t status = pjsua_call_answer([self identifier], PJSIP_SC_BUSY_HERE, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error replying with 486 Busy Here");
+ }
}
- (void)ringbackStart {
- AKSIPUserAgent *userAgent = [AKSIPUserAgent sharedUserAgent];
-
- // Use dot syntax for properties to prevent square bracket clutter.
- if (userAgent.callData[self.identifier].ringbackOn) {
- return;
- }
-
- userAgent.callData[self.identifier].ringbackOn = PJ_TRUE;
-
- [userAgent setRingbackCount:[userAgent ringbackCount] + 1];
- if ([userAgent ringbackCount] == 1 &&
- [userAgent ringbackSlot] != kAKSIPUserAgentInvalidIdentifier) {
- pjsua_conf_connect([userAgent ringbackSlot], 0);
- }
+ AKSIPUserAgent *userAgent = [AKSIPUserAgent sharedUserAgent];
+
+ // Use dot syntax for properties to prevent square bracket clutter.
+ if (userAgent.callData[self.identifier].ringbackOn) {
+ return;
+ }
+
+ userAgent.callData[self.identifier].ringbackOn = PJ_TRUE;
+
+ [userAgent setRingbackCount:[userAgent ringbackCount] + 1];
+ if ([userAgent ringbackCount] == 1 && [userAgent ringbackSlot] != kAKSIPUserAgentInvalidIdentifier) {
+ pjsua_conf_connect([userAgent ringbackSlot], 0);
+ }
}
- (void)ringbackStop {
- AKSIPUserAgent *userAgent = [AKSIPUserAgent sharedUserAgent];
-
- // Use dot syntax for properties to prevent square bracket clutter.
- if (userAgent.callData[self.identifier].ringbackOn) {
- userAgent.callData[self.identifier].ringbackOn = PJ_FALSE;
+ AKSIPUserAgent *userAgent = [AKSIPUserAgent sharedUserAgent];
- pj_assert([userAgent ringbackCount] > 0);
-
- [userAgent setRingbackCount:[userAgent ringbackCount] - 1];
- if ([userAgent ringbackCount] == 0 &&
- [userAgent ringbackSlot] != kAKSIPUserAgentInvalidIdentifier) {
- pjsua_conf_disconnect([userAgent ringbackSlot], 0);
- pjmedia_tonegen_rewind([userAgent ringbackPort]);
+ // Use dot syntax for properties to prevent square bracket clutter.
+ if (userAgent.callData[self.identifier].ringbackOn) {
+ userAgent.callData[self.identifier].ringbackOn = PJ_FALSE;
+
+ pj_assert([userAgent ringbackCount] > 0);
+
+ [userAgent setRingbackCount:[userAgent ringbackCount] - 1];
+ if ([userAgent ringbackCount] == 0 &&
+ [userAgent ringbackSlot] != kAKSIPUserAgentInvalidIdentifier) {
+ pjsua_conf_disconnect([userAgent ringbackSlot], 0);
+ pjmedia_tonegen_rewind([userAgent ringbackPort]);
+ }
}
- }
}
- (void)sendDTMFDigits:(NSString *)digits {
- pj_status_t status;
- pj_str_t pjDigits = [digits pjString];
-
- // Try to send RFC2833 DTMF first.
- status = pjsua_call_dial_dtmf([self identifier], &pjDigits);
-
- if (status != PJ_SUCCESS) { // Okay, that didn't work. Send INFO DTMF.
- const pj_str_t kSIPINFO = pj_str("INFO");
+ pj_status_t status;
+ pj_str_t pjDigits = [digits pjString];
+
+ // Try to send RFC2833 DTMF first.
+ status = pjsua_call_dial_dtmf([self identifier], &pjDigits);
- for (NSUInteger i = 0; i < [digits length]; ++i) {
- pjsua_msg_data messageData;
- pjsua_msg_data_init(&messageData);
- messageData.content_type = pj_str("application/dtmf-relay");
-
- NSString *messageBody
- = [NSString stringWithFormat:@"Signal=%C\r\nDuration=300",
- [digits characterAtIndex:i]];
- messageData.msg_body = [messageBody pjString];
-
- status = pjsua_call_send_request([self identifier],
- &kSIPINFO,
- &messageData);
- if (status != PJ_SUCCESS) {
- NSLog(@"Error sending DTMF");
- }
+ if (status != PJ_SUCCESS) { // Okay, that didn't work. Send INFO DTMF.
+ const pj_str_t kSIPINFO = pj_str("INFO");
+
+ for (NSUInteger i = 0; i < [digits length]; ++i) {
+ pjsua_msg_data messageData;
+ pjsua_msg_data_init(&messageData);
+ messageData.content_type = pj_str("application/dtmf-relay");
+
+ NSString *messageBody = [NSString stringWithFormat:@"Signal=%C\r\nDuration=300",
+ [digits characterAtIndex:i]];
+ messageData.msg_body = [messageBody pjString];
+
+ status = pjsua_call_send_request([self identifier], &kSIPINFO, &messageData);
+ if (status != PJ_SUCCESS) {
+ NSLog(@"Error sending DTMF");
+ }
+ }
}
- }
}
- (void)muteMicrophone {
- if ([self isMicrophoneMuted] ||
- [self state] != kAKSIPCallConfirmedState) {
- return;
- }
-
- pjsua_call_info callInfo;
- pjsua_call_get_info([self identifier], &callInfo);
-
- pj_status_t status = pjsua_conf_disconnect(0, callInfo.conf_slot);
- if (status == PJ_SUCCESS) {
- [self setMicrophoneMuted:YES];
- } else {
- NSLog(@"Error muting microphone in call %@", self);
- }
+ if ([self isMicrophoneMuted] || [self state] != kAKSIPCallConfirmedState) {
+ return;
+ }
+
+ pjsua_call_info callInfo;
+ pjsua_call_get_info([self identifier], &callInfo);
+
+ pj_status_t status = pjsua_conf_disconnect(0, callInfo.conf_slot);
+ if (status == PJ_SUCCESS) {
+ [self setMicrophoneMuted:YES];
+ } else {