From: helge Date: Sun, 16 Oct 2005 21:01:15 +0000 (+0000) Subject: fixed usec timeout field X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb1c37afca8a5daea0ad4d1c63fbfceec861aac6;p=sope fixed usec timeout field added accessor for timeout minor cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1167 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-ldap/NGLdap/ChangeLog b/sope-ldap/NGLdap/ChangeLog index eecd02bf..87157f23 100644 --- a/sope-ldap/NGLdap/ChangeLog +++ b/sope-ldap/NGLdap/ChangeLog @@ -1,3 +1,14 @@ +2005-10-16 Helge Hess + + * v4.5.26 + + * NGLdapSearchResultEnumerator.m: minor code improvements + +2005-10-16 Jean-Alexis Montignies + + * NGLdapSearchResultEnumerator.m: properly set microseconds field of + timeout, added accessors for fetch-timeout (OGo bug #1588) + 2005-08-27 Helge Hess * GNUmakefile: added PCH support (v4.5.25) diff --git a/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.h b/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.h index a62cf027..07904f35 100644 --- a/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.h +++ b/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.h @@ -25,11 +25,17 @@ #import #import +/* + NGLdapSearchResultEnumerator + + TODO: document +*/ + @class NGLdapConnection; @interface NGLdapSearchResultEnumerator : NSEnumerator { -@public +@public // TODO: required to be public?! NGLdapConnection *connection; void *handle; int msgid; @@ -40,10 +46,17 @@ - (id)initWithConnection:(NGLdapConnection *)_con messageID:(int)_mid; +/* accessors */ + - (int)messageID; - (NSTimeInterval)duration; - (unsigned)index; +- (void)setTimeout:(NSTimeInterval)_value; +- (NSTimeInterval)timeout; + +/* operations */ + - (void)cancel; @end diff --git a/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.m b/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.m index ab282d0e..68e3d00c 100644 --- a/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.m +++ b/sope-ldap/NGLdap/NGLdapSearchResultEnumerator.m @@ -30,13 +30,21 @@ @implementation NGLdapSearchResultEnumerator - (id)initWithConnection:(NGLdapConnection *)_con messageID:(int)_mid { - self->connection = [_con retain]; - self->handle = [_con ldapHandle]; - self->msgid = _mid; - self->startTime = [[NSDate date] timeIntervalSince1970]; + if ((self = [super init]) != nil) { + self->connection = [_con retain]; + self->handle = [_con ldapHandle]; + self->msgid = _mid; + + // TODO: -timeIntervalSince1970 deprecated on Cocoa + self->startTime = [[NSDate date] timeIntervalSince1970]; + } return self; } +- (id)init { + return [self initWithConnection:NULL messageID:-1]; +} + - (void)dealloc { [self->connection release]; [super dealloc]; @@ -49,6 +57,7 @@ } - (NSTimeInterval)duration { + // TODO: -timeIntervalSince1970 deprecated on Cocoa return [[NSDate date] timeIntervalSince1970] - self->startTime; } @@ -56,6 +65,13 @@ return self->index; } +- (void)setTimeout:(NSTimeInterval)_value { + self->timeout = _value; +} +- (NSTimeInterval)timeout { + return self->timeout; +} + /* enumerator */ - (void)cancel { @@ -165,126 +181,135 @@ top = NULL; if (self->timeout > 0) { to.tv_sec = self->timeout; - to.tv_sec = (long)(self->timeout * 1000.0) - (to.tv_sec * 1000); + to.tv_usec = (long)(self->timeout * 1000.0) - (to.tv_sec * 1000); top = &to; } - + res = ldap_result(self->handle, self->msgid, 0, top, &msg); + if (msg == NULL) + return nil; - if (msg) { - switch(res) { + switch(res) { #if defined(LDAP_RES_SEARCH_REFERENCE) - case LDAP_RES_SEARCH_REFERENCE: { - int rres; - char **rptr; - LDAPControl **ctrl; - - rres = ldap_parse_reference(self->handle, msg, &rptr, &ctrl, - 0 /* don't free msg */); - if (rres == LDAP_SUCCESS) { - } - else { - /* error */ - NSLog(@"%s: couldn't parse result reference ..", __PRETTY_FUNCTION__); - } - - NSLog(@"WARNING: doesn't support result references yet .."); + case LDAP_RES_SEARCH_REFERENCE: { + int rres; + char **rptr; + LDAPControl **ctrl; + + rres = ldap_parse_reference(self->handle, msg, &rptr, &ctrl, + 0 /* don't free msg */); + if (rres == LDAP_SUCCESS) { + } + else { + /* error */ + NSLog(@"%s: couldn't parse result reference ..", __PRETTY_FUNCTION__); + } + + NSLog(@"ERROR(%s): does not support result references yet ..", + __PRETTY_FUNCTION__); - if (rptr) ldap_value_free(rptr); - if (ctrl) ldap_controls_free(ctrl); + if (rptr != NULL) ldap_value_free(rptr); + if (ctrl != NULL) ldap_controls_free(ctrl); - break; - } + break; + } #endif - case LDAP_RES_SEARCH_ENTRY: { - int resultCount; + case LDAP_RES_SEARCH_ENTRY: { + int resultCount; - if ((resultCount = ldap_count_entries(self->handle, msg)) == -1) { - /* failed */ - int err; + if ((resultCount = ldap_count_entries(self->handle, msg)) == -1) { + /* failed */ + int err; - err = ldap_result2error(self->handle, msg, 1 /* free msg */); + err = ldap_result2error(self->handle, msg, 1 /* free msg */); - [[self->connection _exceptionForErrorCode:err - operation:@"count-fetch" - userInfo:nil] - raise]; - return nil; - } - else if (resultCount == 1) { - LDAPMessage *result; - NSString *dn = nil; - char *tmp; - NSArray *attributes; + [[self->connection _exceptionForErrorCode:err + operation:@"count-fetch" + userInfo:nil] + raise]; + return nil; + } + + if (resultCount == 1) { + LDAPMessage *result; + NSString *dn = nil; + char *tmp; + NSArray *attributes; - if ((result = ldap_first_entry(self->handle, msg)) == NULL) { - /* could not get entry */ - int err; + if ((result = ldap_first_entry(self->handle, msg)) == NULL) { + /* could not get entry */ + int err; - err = ldap_result2error(self->handle, msg, 1 /* free msg */); + err = ldap_result2error(self->handle, msg, 1 /* free msg */); - [[self->connection _exceptionForErrorCode:resultCount - operation:@"fetch" - userInfo:nil] - raise]; + [[self->connection _exceptionForErrorCode:resultCount + operation:@"fetch" + userInfo:nil] + raise]; - return nil; - } + return nil; + } - /* get distinguished name */ + /* get distinguished name */ - if ((tmp = ldap_get_dn(self->handle, result))) { - NS_DURING { - dn = [[[NSString alloc] initWithUTF8String:tmp] autorelease]; - } - NS_HANDLER { - fprintf(stderr, "Got exception %s while NSUTF8StringEncoding, " - "use defaultCStringEncoding", - [[localException description] cString]); - dn = nil; - } - NS_ENDHANDLER; - - if (dn == nil) - dn = [[[NSString alloc] initWithCString:tmp] autorelease]; - - free(tmp); - } - /* get all attributes */ + if ((tmp = ldap_get_dn(self->handle, result)) != NULL) { + // TODO: slow ..., somehow fix that. + + /* try UTF-8 (as per spec?) */ + + NS_DURING { + dn = [[[NSString alloc] initWithUTF8String:tmp] autorelease]; + } + NS_HANDLER { + fprintf(stderr, "Got exception %s while NSUTF8StringEncoding, " + "use defaultCStringEncoding", + [[localException description] cString]); + dn = nil; + } + NS_ENDHANDLER; + + /* try system encoding (Latin-1 on libFoundation) */ + + if (dn == nil) // TODO: print a warning? + dn = [[[NSString alloc] initWithCString:tmp] autorelease]; + + if (tmp != NULL) free(tmp); + } + + /* get all attributes */ - attributes = [self _attributesFromResult:result]; + attributes = [self _attributesFromResult:result]; - if (result) { - // TODO: ldap_msgfree(result); // do not release result-msg ??? - result = NULL; - } - - record = [[NGLdapEntry alloc] initWithDN:dn attributes:attributes]; - - [attributes release]; attributes = nil; - } - else if (resultCount == 0) { - /* no more results */ - record = nil; - } - break; + if (result != NULL) { + // TODO: ldap_msgfree(result); // do not release result-msg ??? + result = NULL; } + + record = [[NGLdapEntry alloc] initWithDN:dn attributes:attributes]; + + [attributes release]; attributes = nil; + } + else if (resultCount == 0) { + /* no more results */ + record = nil; + } + break; + } - case LDAP_RES_SEARCH_RESULT: - self->handle = NULL; - [self->connection release]; self->connection = nil; - break; + case LDAP_RES_SEARCH_RESULT: + self->handle = NULL; + [self->connection release]; self->connection = nil; + break; - default: - NSLog(@"unexpected msg-code: %X", res); - break; - } - if (msg) - ldap_msgfree(msg); + default: + NSLog(@"NGLdap(%s): unexpected msg-code: %X", __PRETTY_FUNCTION__,res); + break; } + if (msg != NULL) + ldap_msgfree(msg); - if (record) + if (record != nil) self->index++; return [record autorelease]; @@ -294,7 +319,7 @@ - (NSString *)description { NSMutableString *s; - + s = [NSMutableString stringWithCapacity:100]; [s appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; diff --git a/sope-ldap/NGLdap/Version b/sope-ldap/NGLdap/Version index 85b2c4bc..2ed5f2f7 100644 --- a/sope-ldap/NGLdap/Version +++ b/sope-ldap/NGLdap/Version @@ -2,4 +2,4 @@ MAJOR_VERSION=4 MINOR_VERSION=5 -SUBMINOR_VERSION:=25 +SUBMINOR_VERSION:=26