diff options
author | Damian Minkov <damencho@jitsi.org> | 2011-12-22 15:34:28 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2011-12-22 15:34:28 +0000 |
commit | 9e9e357c9b462facbf44e3807021b68b6c6e0330 (patch) | |
tree | 908cdbbd5a42161b8671eddd2cb68f9aec8895fc /src | |
parent | fcb4f90800eb1da8c1cf5fbf3bbc4f4e5addceca (diff) | |
download | jitsi-9e9e357c9b462facbf44e3807021b68b6c6e0330.zip jitsi-9e9e357c9b462facbf44e3807021b68b6c6e0330.tar.gz jitsi-9e9e357c9b462facbf44e3807021b68b6c6e0330.tar.bz2 |
Adds dns change detection on macosx.
Diffstat (limited to 'src')
8 files changed, 100 insertions, 3 deletions
diff --git a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h index 8b586b8..885035e 100644 --- a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h +++ b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h @@ -27,6 +27,8 @@ extern "C" { #define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED 8L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE 9L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE 10L
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
diff --git a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.m b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.m index d9e2ce6..6faac97 100644 --- a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.m +++ b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.m @@ -128,6 +128,11 @@ static CFRunLoopSourceRef rlSrc; [self notify:net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE]; } +-(void) dnsChange: (NSNotification *) notification +{ + [self notify:net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE]; +} + void scCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) { NSAutoreleasePool* localPool = [NSAutoreleasePool new]; @@ -138,6 +143,16 @@ void scCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) [localPool drain]; } +void scDnsCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) +{ + NSAutoreleasePool* localPool = [NSAutoreleasePool new]; + + [[NSNotificationCenter defaultCenter] postNotificationName + :@"DnsConfigurationDidChangeNotification" object:(id)info]; + + [localPool drain]; +} + - (void)setDelegate:(jobject) delegate inJNIEnv:(JNIEnv *)jniEnv { if (self->delegateObject) @@ -203,8 +218,11 @@ void scCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) [[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(netChange:) name:@"NetworkConfigurationDidChangeNotification" object:NULL]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector: @selector(dnsChange:) + name:@"DnsConfigurationDidChangeNotification" object:NULL]; - + { SCDynamicStoreRef dynStore; SCDynamicStoreContext context = {0, NULL, NULL, NULL, NULL}; @@ -241,6 +259,46 @@ void scCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) CFRunLoopAddSource( CFRunLoopGetCurrent(), rlSrc, kCFRunLoopDefaultMode); CFRelease(rlSrc); + } + + { + SCDynamicStoreRef dynStore; + + SCDynamicStoreContext context = {0, NULL, NULL, NULL, NULL}; + + dynStore = SCDynamicStoreCreate(kCFAllocatorDefault, + CFBundleGetIdentifier(CFBundleGetMainBundle()), + scDnsCallback, + &context); + + const CFStringRef keys[1] = { + CFSTR("State:/Network/Global/DNS") + }; + CFArrayRef watchedKeys = CFArrayCreate(kCFAllocatorDefault, + (const void **)keys, + 1, + &kCFTypeArrayCallBacks); + if (!SCDynamicStoreSetNotificationKeys(dynStore, + NULL, + watchedKeys)) + { + CFRelease(watchedKeys); + fprintf(stderr, "SCDynamicStoreSetNotificationKeys() failed: %s", + SCErrorString(SCError())); + CFRelease(dynStore); + dynStore = NULL; + + return; + } + CFRelease(watchedKeys); + + + rlSrc = SCDynamicStoreCreateRunLoopSource( + kCFAllocatorDefault, dynStore, 0); + CFRunLoopAddSource( + CFRunLoopGetCurrent(), rlSrc, kCFRunLoopDefaultMode); + CFRelease(rlSrc); + } } } } diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java b/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java index 27d4c95..8e26e1c 100644 --- a/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java +++ b/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java @@ -346,6 +346,18 @@ public class NetworkConfigurationWatcher logger.error("Error checking network interfaces", e); } } + else if(event.getEventID() == SystemActivityEvent.EVENT_DNS_CHANGE) + { + try + { + eventDispatcher.fireChangeEvent( + new ChangeEvent(event.getSource(), ChangeEvent.DNS_CHANGE)); + } + catch(Throwable t) + { + logger.error("Error dispatching dns change."); + } + } } /** diff --git a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotifications.java b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotifications.java index 9f58820..b7682c5 100644 --- a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotifications.java +++ b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotifications.java @@ -64,6 +64,11 @@ public class SystemActivityNotifications public static final int NOTIFY_NETWORK_CHANGE = 9;
/**
+ * A change in dns configuration has occurred.
+ */
+ public static final int NOTIFY_DNS_CHANGE = 10;
+
+ /**
* The logger.
*/
private static Logger logger = Logger.getLogger(
diff --git a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java index a800254..705d2ea 100644 --- a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java +++ b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java @@ -263,6 +263,12 @@ public class SystemActivityNotificationsServiceImpl SystemActivityEvent.EVENT_NETWORK_CHANGE);
break;
}
+ case SystemActivityNotifications.NOTIFY_DNS_CHANGE :
+ {
+ evt = new SystemActivityEvent(this,
+ SystemActivityEvent.EVENT_DNS_CHANGE);
+ break;
+ }
}
if(evt != null)
diff --git a/src/net/java/sip/communicator/service/netaddr/event/ChangeEvent.java b/src/net/java/sip/communicator/service/netaddr/event/ChangeEvent.java index ca3d3eb..262cf03 100644 --- a/src/net/java/sip/communicator/service/netaddr/event/ChangeEvent.java +++ b/src/net/java/sip/communicator/service/netaddr/event/ChangeEvent.java @@ -42,6 +42,11 @@ public class ChangeEvent public static final int ADDRESS_UP = 3; /** + * Event type for dns change. + */ + public static final int DNS_CHANGE = 4; + + /** * The type of the current event. */ private int type = -1; @@ -161,11 +166,13 @@ public class ChangeEvent case IFACE_UP: buff.append("Interface up"); break; case ADDRESS_DOWN : buff.append("Address down"); break; case ADDRESS_UP : buff.append("Address up"); break; + case DNS_CHANGE : buff.append("Dns has changed"); break; } buff.append(", standby=" + standby) .append(", source=" + source) - .append(", address=" + address); + .append(", address=" + address) + .append(", isInitial=" + initial); return buff.toString(); } diff --git a/src/net/java/sip/communicator/service/sysactivity/event/SystemActivityEvent.java b/src/net/java/sip/communicator/service/sysactivity/event/SystemActivityEvent.java index ad8709b..a9fbcb4 100644 --- a/src/net/java/sip/communicator/service/sysactivity/event/SystemActivityEvent.java +++ b/src/net/java/sip/communicator/service/sysactivity/event/SystemActivityEvent.java @@ -77,6 +77,11 @@ public class SystemActivityEvent public static final int EVENT_SYSTEM_IDLE_END = 11;
/**
+ * A change in dns configuration has occurred.
+ */
+ public static final int EVENT_DNS_CHANGE = 12;
+
+ /**
* The type of the event.
*/
private final int eventID;
diff --git a/src/net/java/sip/communicator/util/NetworkUtils.java b/src/net/java/sip/communicator/util/NetworkUtils.java index 04d2dfc..7f1aabc 100644 --- a/src/net/java/sip/communicator/util/NetworkUtils.java +++ b/src/net/java/sip/communicator/util/NetworkUtils.java @@ -1373,7 +1373,9 @@ public class NetworkUtils */ public void configurationChanged(ChangeEvent event) { - if(event.getType() == ChangeEvent.IFACE_UP && !event.isInitial()) + if((event.getType() == ChangeEvent.IFACE_UP + || event.getType() == ChangeEvent.DNS_CHANGE) + && !event.isInitial()) { reloadDnsResolverConfig(); } |