adium 2768:6ba5f8f8102a: Add an observer for both AF_INET (IPv4)...

commits at adium.im commits at adium.im
Sat Oct 24 16:31:45 UTC 2009


details:	http://hg.adium.im/adium/rev/6ba5f8f8102a
revision:	2768:6ba5f8f8102a
author:		Zachary West <zacw at adium.im>
date:		Sat Oct 24 11:32:51 2009 -0400

Add an observer for both AF_INET (IPv4) and AF_INET6 (IPv6) DNS records for connection hosts. Fixes #12632.

When we're determining reachability, we consult all entries for a host, instead of the one that changed. We only add one observer for each record type.
Subject: adium 2769:28fc8d5dd66c: Truth in changed methods.

details:	http://hg.adium.im/adium/rev/28fc8d5dd66c
revision:	2769:28fc8d5dd66c
author:		Zachary West <zacw at adium.im>
date:		Sat Oct 24 11:35:35 2009 -0400

Truth in changed methods.
Subject: adium 2770:b52dcb3742cc: Replace %dateOpened% with the user's long localized date display. Fixes #12692.

details:	http://hg.adium.im/adium/rev/b52dcb3742cc
revision:	2770:b52dcb3742cc
author:		Zachary West <zacw at adium.im>
date:		Sat Oct 24 12:01:59 2009 -0400

Replace %dateOpened% with the user's long localized date display. Fixes #12692.
Subject: adium 2771:7e41d8e52be8: Add %senderColor% to the header keywords. Fixes #12666.

details:	http://hg.adium.im/adium/rev/7e41d8e52be8
revision:	2771:7e41d8e52be8
author:		Zachary West <zacw at adium.im>
date:		Sat Oct 24 12:13:13 2009 -0400

Add %senderColor% to the header keywords. Fixes #12666.

diffs (169 lines):

diff -r ea08449f2408 -r 7e41d8e52be8 Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m
--- a/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m	Fri Oct 23 17:31:47 2009 -0500
+++ b/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m	Sat Oct 24 12:13:13 2009 -0400
@@ -196,9 +196,8 @@
  * @brief A host's reachability changed
  *
  * @param reachability The SCNetworkReachabilityRef for the host which changed
- * @param isReachable YES if the host is now reachable; NO if it is not reachable
  */
-- (void)reachability:(SCNetworkReachabilityRef)reachability changedToReachable:(BOOL)isReachable
+- (void)reachabilityChanged:(SCNetworkReachabilityRef)reachability
 {
 	[hostAndObserverListLock lock];
 
@@ -207,7 +206,26 @@
 		NSString *host = [hosts objectAtIndex:i];
 		id <AIHostReachabilityObserver> observer = [observers objectAtIndex:i];
 		
-		if (isReachable) {
+		BOOL anyHostsReachable = NO;
+		
+		// If we have multiple host <-> IP links (AAAA record and an A record), we need to check agreement.
+		for (NSUInteger index = 0; index < hosts.count; index++) {
+			if (![host isEqualToString:[hosts objectAtIndex:index]])
+				continue;
+			
+			SCNetworkReachabilityRef otherReachability = (SCNetworkReachabilityRef)[reachabilities objectAtIndex:index];
+			SCNetworkConnectionFlags flags;
+
+			if (SCNetworkReachabilityGetFlags(otherReachability, &flags)
+				&& (flags & kSCNetworkFlagsReachable)
+				&& !(flags & kSCNetworkFlagsConnectionRequired)) {
+				anyHostsReachable = YES;
+				break;
+			}
+		}
+		
+		// Return reachability based on any reachability response.
+		if (anyHostsReachable) {
 			[observer hostReachabilityMonitor:self hostIsReachable:host];
 		} else {
 			[observer hostReachabilityMonitor:self hostIsNotReachable:host];
@@ -224,9 +242,6 @@
  */
 static void hostReachabilityChangedCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void *info)
 {
-	BOOL reachable =  (flags & kSCNetworkFlagsReachable)			&&
-					 !(flags & kSCNetworkFlagsConnectionRequired);
-
 #if CONNECTIVITY_DEBUG
 	NSLog(@"*** hostReachabilityChangedCallback got flags: %c%c%c%c%c%c%c \n",  
  	      (flags & kSCNetworkFlagsTransientConnection)  ? 't' : '-',  
@@ -237,9 +252,9 @@
  	      (flags & kSCNetworkFlagsIsLocalAddress)       ? 'l' : '-',  
  	      (flags & kSCNetworkFlagsIsDirect)             ? 'd' : '-');
 #endif
-
+	
 	AIHostReachabilityMonitor *self = info;
-	[self reachability:target changedToReachable:reachable];
+	[self reachabilityChanged:target];
 }
 
 /*
@@ -255,8 +270,34 @@
 	NSString					*host = [infoDict objectForKey:@"host"];
 
 	if (typeInfo == kCFHostAddresses) {
+		//CFHostGetAddressing returns a CFArrayRef of CFDataRefs which wrap struct sockaddr
 		CFArrayRef addresses = CFHostGetAddressing(theHost, NULL);
-		if (addresses && CFArrayGetCount(addresses)) {
+		
+		if (!CFArrayGetCount(addresses)) {
+			/* We were not able to resolve the host name to an IP address.  This is most likely because we have no
+			 * Internet connection or because the user is attempting to connect to MSN.
+			 *
+			 * Add to unconfiguredHostsAndObservers so we can try configuring again later.
+			 */
+			[self addUnconfiguredHost:host
+							 observer:observer];
+		}
+		
+		// Only add 1 observer for IPv6 and one for IPv4.
+		BOOL addedIPv4 = NO, addedIPv6 = NO;
+		
+		for (NSData *saData in (NSArray *)addresses) {
+			struct sockaddr							*remoteAddr = (struct sockaddr *)saData.bytes;
+			
+			if ((remoteAddr->sa_family == AF_INET && addedIPv4) || (remoteAddr->sa_family == AF_INET6 && addedIPv6)) {
+				continue;
+			}
+			
+			if (remoteAddr->sa_family == AF_INET)
+				addedIPv4 = YES;
+			if (remoteAddr->sa_family == AF_INET6)
+				addedIPv6 = YES;
+						
 			SCNetworkReachabilityRef		reachabilityRef;
 			SCNetworkReachabilityContext	reachabilityContext = {
 				.version         = 0,
@@ -267,7 +308,6 @@
 			};
 			SCNetworkConnectionFlags				flags;
 			struct sockaddr_in						localAddr;
-			struct sockaddr							*remoteAddr;
 			
 			/* Create a reachability reference pair with localhost and the remote host */
 			
@@ -277,10 +317,6 @@
 			localAddr.sin_family = AF_INET;
 			inet_aton("127.0.0.1", &localAddr.sin_addr);
 			
-			//CFHostGetAddressing returns a CFArrayRef of CFDataRefs which wrap struct sockaddr
-			CFDataRef saData = (CFDataRef)CFArrayGetValueAtIndex(addresses, 0);
-			remoteAddr = (struct sockaddr *)CFDataGetBytePtr(saData);
-			
 			//Create the pair
 			reachabilityRef = SCNetworkReachabilityCreateWithAddressPair(NULL, 
 																		 (struct sockaddr *)&localAddr, 
@@ -303,9 +339,9 @@
 
 			if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
 				//We already have valid flags for the reachabilityRef
-#if CONNECTIVITY_DEBUG
+		#if CONNECTIVITY_DEBUG
 				NSLog(@"Immediate reachability info for %@", reachabilityRef);
-#endif
+		#endif
 				hostReachabilityChangedCallback(reachabilityRef,
 												flags,
 												self);
@@ -335,14 +371,6 @@
 										  NULL);
 			}
 
-		} else {
-			/* We were not able to resolve the host name to an IP address.  This is most likely because we have no
-			* Internet connection or because the user is attempting to connect to MSN.
-			*
-			* Add to unconfiguredHostsAndObservers so we can try configuring again later.
-			*/
-			[self addUnconfiguredHost:host
-							 observer:observer];
 		}
 		
 	} else if (typeInfo == kCFHostReachability) {
diff -r ea08449f2408 -r 7e41d8e52be8 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Fri Oct 23 17:31:47 2009 -0500
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Sat Oct 24 12:13:13 2009 -0400
@@ -1156,6 +1156,9 @@
 	AIListContact	*listObject = chat.listObject;
 	NSString		*iconPath = nil;
 	
+	[inString replaceKeyword:@"%senderColor%"
+				  withString:[NSColor representedColorForObject:listObject.UID withValidColors:validSenderColors]];
+	
 	if (listObject) {
 		iconPath = [listObject valueForProperty:KEY_WEBKIT_USER_ICON];
 		if (!iconPath) {
@@ -1219,6 +1222,9 @@
 		}
 	} while (range.location != NSNotFound);
 	
+	[inString replaceKeyword:@"%dateOpened%"
+				  withString:[[NSDateFormatter localizedDateFormatter] stringFromDate:[chat dateOpened]]];
+	
 	//Background
 	{
 		range = [inString rangeOfString:@"==bodyBackground=="];




More information about the commits mailing list