From d15fd9971c6cfdb2cd2fa1cb365e6cb6470eb6db Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Thu, 26 May 2011 22:23:02 +0200 Subject: [PATCH] Split XMPPSRVEnumerator into XMPPSRVLookup and XMPPSRVEnumerator. --- ObjXMPP.xcodeproj/project.pbxproj | 16 ++++----- src/Makefile | 2 +- src/XMPPConnection.m | 10 +++--- src/{XMPPSRVEnumerator.h => XMPPSRVLookup.h} | 21 ++++++++---- src/{XMPPSRVEnumerator.m => XMPPSRVLookup.m} | 34 ++++++++++++++++---- 5 files changed, 55 insertions(+), 28 deletions(-) rename src/{XMPPSRVEnumerator.h => XMPPSRVLookup.h} (93%) rename src/{XMPPSRVEnumerator.m => XMPPSRVLookup.m} (93%) diff --git a/ObjXMPP.xcodeproj/project.pbxproj b/ObjXMPP.xcodeproj/project.pbxproj index 66fbbef..25ba762 100644 --- a/ObjXMPP.xcodeproj/project.pbxproj +++ b/ObjXMPP.xcodeproj/project.pbxproj @@ -11,8 +11,8 @@ 4B1295EF1337BD5F00154B25 /* test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B1295EE1337BD5F00154B25 /* test.m */; }; 4B1295F11337C37E00154B25 /* ObjXMPP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559911337A65400E345C7 /* ObjXMPP.framework */; }; 4B1295F21337C3CF00154B25 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559D61337ABD300E345C7 /* ObjFW.framework */; }; - 4B4844F5138BBC7500EB48A5 /* XMPPSRVEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4844F3138BBC7400EB48A5 /* XMPPSRVEnumerator.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4B4844F6138BBC7500EB48A5 /* XMPPSRVEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4844F4138BBC7500EB48A5 /* XMPPSRVEnumerator.m */; }; + 4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */; }; 4B484501138BBEEB00EB48A5 /* libresolv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B484500138BBEEB00EB48A5 /* libresolv.dylib */; }; 4BC559D71337ABD300E345C7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559D61337ABD300E345C7 /* ObjFW.framework */; }; 4BC559EC1337AC0900E345C7 /* XMPPAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC559DA1337AC0900E345C7 /* XMPPAuthenticator.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -59,8 +59,8 @@ 4B01D01F137C7E7D005624EA /* namespaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = namespaces.h; path = src/namespaces.h; sourceTree = SOURCE_ROOT; }; 4B1295E01337BD2D00154B25 /* ObjXMPPTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ObjXMPPTests; sourceTree = BUILT_PRODUCTS_DIR; }; 4B1295EE1337BD5F00154B25 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/test.m; sourceTree = SOURCE_ROOT; }; - 4B4844F3138BBC7400EB48A5 /* XMPPSRVEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPSRVEnumerator.h; path = src/XMPPSRVEnumerator.h; sourceTree = SOURCE_ROOT; }; - 4B4844F4138BBC7500EB48A5 /* XMPPSRVEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPSRVEnumerator.m; path = src/XMPPSRVEnumerator.m; sourceTree = SOURCE_ROOT; }; + 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPSRVLookup.h; path = src/XMPPSRVLookup.h; sourceTree = SOURCE_ROOT; }; + 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPSRVLookup.m; path = src/XMPPSRVLookup.m; sourceTree = SOURCE_ROOT; }; 4B484500138BBEEB00EB48A5 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; }; 4BC559911337A65400E345C7 /* ObjXMPP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjXMPP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4BC559D61337ABD300E345C7 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ../../../../Library/Frameworks/ObjFW.framework; sourceTree = ""; }; @@ -186,8 +186,8 @@ 4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */, 4BC559EA1337AC0900E345C7 /* XMPPSCRAMAuth.h */, 4BC559FD1337AC1800E345C7 /* XMPPSCRAMAuth.m */, - 4B4844F3138BBC7400EB48A5 /* XMPPSRVEnumerator.h */, - 4B4844F4138BBC7500EB48A5 /* XMPPSRVEnumerator.m */, + 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */, + 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */, 4BC559FE1337AC1800E345C7 /* XMPPStanza.h */, 4BC559FF1337AC1800E345C7 /* XMPPStanza.m */, 4B01D01F137C7E7D005624EA /* namespaces.h */, @@ -222,7 +222,7 @@ 4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */, 4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */, 4BC559FC1337AC0900E345C7 /* XMPPSCRAMAuth.h in Headers */, - 4B4844F5138BBC7500EB48A5 /* XMPPSRVEnumerator.h in Headers */, + 4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */, 4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */, 4B01D020137C7E7D005624EA /* namespaces.h in Headers */, ); @@ -324,7 +324,7 @@ 4BC55A021337AC1800E345C7 /* XMPPStanza.m in Sources */, 4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */, 4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */, - 4B4844F6138BBC7500EB48A5 /* XMPPSRVEnumerator.m in Sources */, + 4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/Makefile b/src/Makefile index f7ae021..a0005eb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,7 +16,7 @@ SRCS = XMPPAuthenticator.m \ XMPPRoster.m \ XMPPRosterItem.m \ XMPPSCRAMAuth.m \ - XMPPSRVEnumerator.m \ + XMPPSRVLookup.m \ XMPPStanza.m INCLUDES = ${SRCS:.m=.h} \ diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index ad81f88..719c373 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -31,7 +31,7 @@ #import #import "XMPPConnection.h" -#import "XMPPSRVEnumerator.h" +#import "XMPPSRVLookup.h" #import "XMPPSCRAMAuth.h" #import "XMPPPLAINAuth.h" #import "XMPPStanza.h" @@ -197,13 +197,11 @@ - (void)connect { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - XMPPSRVEnumerator *SRVEnumerator = - [XMPPSRVEnumerator enumeratorWithDomain: server]; + XMPPSRVLookup *SRVLookup = [XMPPSRVLookup lookupWithDomain: server]; + OFEnumerator *enumerator = [SRVLookup objectEnumerator]; XMPPSRVEntry *candidate; - [SRVEnumerator lookUpEntries]; - - while ((candidate = [SRVEnumerator nextObject]) != nil) { + while ((candidate = [enumerator nextObject]) != nil) { @try { [sock connectToHost: [candidate target] onPort: [candidate port]]; diff --git a/src/XMPPSRVEnumerator.h b/src/XMPPSRVLookup.h similarity index 93% rename from src/XMPPSRVEnumerator.h rename to src/XMPPSRVLookup.h index d6b904b..bf1b931 100644 --- a/src/XMPPSRVEnumerator.h +++ b/src/XMPPSRVLookup.h @@ -62,23 +62,30 @@ - (OFString*)target; @end -@interface XMPPSRVEnumerator: OFEnumerator +@interface XMPPSRVLookup: OFObject { OFString *domain; struct __res_state resState; OFList *list; - of_list_object_t *listIter; - OFList *subListCopy; - BOOL done; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *domain; #endif -+ enumeratorWithDomain: (OFString*)domain; ++ lookupWithDomain: (OFString*)domain; - initWithDomain: (OFString*)domain; -- (OFString*)domain; -- (void)lookUpEntries; +- (void)XMPP_lookup; - (void)XMPP_addEntry: (XMPPSRVEntry*)item; @end + +@interface XMPPSRVEnumerator: OFEnumerator +{ + OFList *list; + of_list_object_t *listIter; + OFList *subListCopy; + BOOL done; +} + +- initWithList: (OFList*)list; +@end diff --git a/src/XMPPSRVEnumerator.m b/src/XMPPSRVLookup.m similarity index 93% rename from src/XMPPSRVEnumerator.m rename to src/XMPPSRVLookup.m index 62d6d79..01e2676 100644 --- a/src/XMPPSRVEnumerator.m +++ b/src/XMPPSRVLookup.m @@ -30,7 +30,7 @@ #include #include -#import "XMPPSRVEnumerator.h" +#import "XMPPSRVLookup.h" @implementation XMPPSRVEntry + entryWithPriority: (uint16_t)priority @@ -153,10 +153,10 @@ } @end -@implementation XMPPSRVEnumerator -+ enumeratorWithDomain: (OFString*)domain_ +@implementation XMPPSRVLookup ++ lookupWithDomain: (OFString*)domain { - return [[[self alloc] initWithDomain: domain_] autorelease]; + return [[[self alloc] initWithDomain: domain] autorelease]; } - initWithDomain: (OFString*)domain_ @@ -166,6 +166,8 @@ @try { list = [[OFList alloc] init]; domain = [domain_ copy]; + + [self XMPP_lookup]; } @catch (id e) { [self release]; @throw e; @@ -178,7 +180,6 @@ { [list release]; [domain release]; - [subListCopy release]; [super dealloc]; } @@ -188,7 +189,7 @@ OF_GETTER(domain, YES) } -- (void)lookUpEntries +- (void)XMPP_lookup { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; unsigned char *answer = NULL; @@ -284,6 +285,27 @@ [pool release]; } +- (OFEnumerator*)objectEnumerator +{ + return [[[XMPPSRVEnumerator alloc] initWithList: list] autorelease]; +} +@end + +@implementation XMPPSRVEnumerator +- initWithList: (OFList*)list_ +{ + self = [super init]; + + @try { + list = [list_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + - (id)nextObject { XMPPSRVEntry *ret;