Revision: 27877
http://sourceforge.net/p/bibdesk/svn/27877
Author: hofman
Date: 2022-09-09 09:33:51 +0000 (Fri, 09 Sep 2022)
Log Message:
-----------
Don't bother to observe TXTRecord changes from NSNetService as we never change
it. Don't make flags derived from it atomic.
Modified Paths:
--------------
trunk/bibdesk/BDSKSharingClient.m
Modified: trunk/bibdesk/BDSKSharingClient.m
===================================================================
--- trunk/bibdesk/BDSKSharingClient.m 2022-09-09 06:30:17 UTC (rev 27876)
+++ trunk/bibdesk/BDSKSharingClient.m 2022-09-09 09:33:51 UTC (rev 27877)
@@ -46,17 +46,17 @@
static NSString *BDSKClientServiceNameForKeychain = @"BibDesk Sharing Access";
typedef struct _BDSKSharingClientFlags {
+ BOOL needsAuthentication;
+ BOOL legacyServer;
_Atomic(BOOL) authenticationFailed;
_Atomic(BOOL) canceledAuthentication;
- _Atomic(BOOL) needsAuthentication;
- _Atomic(BOOL) legacyServer;
_Atomic(BOOL) failedDownload;
} BDSKSharingClientFlags;
// private class for async object. We have it as a separate object so we don't
get a retain loop, we remove it from the thread runloop in the client's dealloc
-@interface BDSKAsyncSharingClient : BDSKAsyncObject <NSNetServiceDelegate,
NSConnectionDelegate> {
+@interface BDSKAsyncSharingClient : BDSKAsyncObject <NSConnectionDelegate> {
NSNetService *service; // service with information about the
remote server (BDSKSharingServer)
- BDSKSharingClient *client; // the owner of the local server
(BDSKSharingClient)
+ BDSKSharingClient *client; // the owner of the async client
(BDSKSharingClient)
id remoteServer; // proxy for the remote sharing server to
which we connect
BDSKSharingClientFlags flags; // state variables
NSString *uniqueIdentifier; // used by the remote server
@@ -180,17 +180,16 @@
service = [aService retain];
- // monitor changes to the TXT data
- [service setDelegate:self];
- [service startMonitoring];
-
// set up flags
memset(&flags, 0, sizeof(flags));
// set up the authentication flag
NSData *TXTData = [service TXTRecordData];
- if(TXTData)
- [self netService:service didUpdateTXTRecordData:TXTData];
+ if(TXTData){
+ NSDictionary *dict = [NSNetService
dictionaryFromTXTRecordData:TXTData];
+ flags.needsAuthentication = [[[[NSString alloc] initWithData:[dict
objectForKey:BDSKTXTAuthenticateKey] encoding:NSUTF8StringEncoding]
autorelease] boolValue];
+ flags.legacyServer = [[dict objectForKey:BDSKTXTVersionKey]
isEqual:[@"0" dataUsingEncoding:NSUTF8StringEncoding]];
+ }
// test this to see if we've registered with the remote host
uniqueIdentifier = nil;
@@ -204,7 +203,6 @@
- (void)dealloc;
{
- [service setDelegate:nil];
BDSKDESTROY(service);
BDSKDESTROY(uniqueIdentifier);
BDSKDESTROY(errorMessage);
@@ -221,7 +219,7 @@
}
- (BOOL)needsAuthentication {
- return atomic_load(&flags.needsAuthentication) == YES;
+ return flags.needsAuthentication;
}
- (BOOL)authenticationFailed {
@@ -272,7 +270,7 @@
- (BOOL)authenticateIfNeeded:(BOOL)isNew {
// authenticate to a server of version 1+
- if (atomic_load(&flags.needsAuthentication) == NO ||
atomic_load(&flags.legacyServer) == YES || (isNew == NO &&
atomic_load(&flags.canceledAuthentication) == NO &&
atomic_load(&flags.authenticationFailed) == NO)) {
+ if (flags.needsAuthentication == NO || flags.legacyServer == YES || (isNew
== NO && atomic_load(&flags.canceledAuthentication) == NO &&
atomic_load(&flags.authenticationFailed) == NO)) {
// no need to authenticate, or legacy server, or we already
authenticated
return YES;
}
@@ -293,7 +291,7 @@
password = [self passwordFromPanel];
if (password == nil) {
- // cancceled by user
+ // canceled by user
atomic_store(&flags.canceledAuthentication, YES);
return NO;
} else {
@@ -333,7 +331,7 @@
// this can be called from any thread
- (NSData *)authenticationDataForComponents:(NSArray *)components;
{
- if (atomic_load(&flags.needsAuthentication) == YES &&
atomic_load(&flags.legacyServer) == YES) {
+ if (flags.needsAuthentication && flags.legacyServer) {
// legacy server of version 0 expect authentication through this method
NSString *password = nil;
@@ -373,20 +371,6 @@
}
}
-// monitor the TXT record in case the server changes password requirements
-- (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData
*)data;
-{
- BDSKASSERT(sender == service);
- BDSKASSERT(data != nil);
- if(data){
- NSDictionary *dict = [NSNetService dictionaryFromTXTRecordData:data];
- BOOL val = [[[[NSString alloc] initWithData:[dict
objectForKey:BDSKTXTAuthenticateKey] encoding:NSUTF8StringEncoding]
autorelease] boolValue];
- atomic_store(&flags.needsAuthentication, val);
- val = [[dict objectForKey:BDSKTXTVersionKey] isEqual:[@"0"
dataUsingEncoding:NSUTF8StringEncoding]];
- atomic_store(&flags.legacyServer, val);
- }
-}
-
#pragma mark Proxies
- (id <BDSKSharingServer>)remoteServer;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit