Split XMPPSRVEnumerator into XMPPSRVLookup and XMPPSRVEnumerator.
This commit is contained in:
parent
1337fdded1
commit
d15fd9971c
5 changed files with 55 additions and 28 deletions
|
@ -16,7 +16,7 @@ SRCS = XMPPAuthenticator.m \
|
|||
XMPPRoster.m \
|
||||
XMPPRosterItem.m \
|
||||
XMPPSCRAMAuth.m \
|
||||
XMPPSRVEnumerator.m \
|
||||
XMPPSRVLookup.m \
|
||||
XMPPStanza.m
|
||||
|
||||
INCLUDES = ${SRCS:.m=.h} \
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#import <ObjOpenSSL/SSLSocket.h>
|
||||
|
||||
#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]];
|
||||
|
|
|
@ -62,23 +62,30 @@
|
|||
- (OFString*)target;
|
||||
@end
|
||||
|
||||
@interface XMPPSRVEnumerator: OFEnumerator
|
||||
@interface XMPPSRVLookup: OFObject <OFEnumerating>
|
||||
{
|
||||
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
|
|
@ -30,7 +30,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#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;
|
Loading…
Add table
Add a link
Reference in a new issue