]> err.no Git - sope/commitdiff
fixed usec timeout field
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sun, 16 Oct 2005 21:01:15 +0000 (21:01 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sun, 16 Oct 2005 21:01:15 +0000 (21:01 +0000)
added accessor for timeout
minor cleanups

git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1167 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-ldap/NGLdap/ChangeLog
sope-ldap/NGLdap/NGLdapSearchResultEnumerator.h
sope-ldap/NGLdap/NGLdapSearchResultEnumerator.m
sope-ldap/NGLdap/Version

index eecd02bfbc6da7677e45d89d62e6e6cfcd2fdfa9..87157f230ff19852888f8c79976b3f4b3ebb6828 100644 (file)
@@ -1,3 +1,14 @@
+2005-10-16  Helge Hess  <helge.hess@opengroupware.org>
+
+       * v4.5.26
+
+       * NGLdapSearchResultEnumerator.m: minor code improvements
+
+2005-10-16  Jean-Alexis Montignies  <ja@sente.ch>
+
+       * NGLdapSearchResultEnumerator.m: properly set microseconds field of
+         timeout, added accessors for fetch-timeout (OGo bug #1588)
+
 2005-08-27  Helge Hess  <helge.hess@opengroupware.org>
 
        * GNUmakefile: added PCH support (v4.5.25)
index a62cf02734d1154577802358ee8b2005c01894b1..07904f3549020386604e9b4eda381521ab928c44 100644 (file)
 #import <Foundation/NSEnumerator.h>
 #import <Foundation/NSDate.h>
 
+/*
+  NGLdapSearchResultEnumerator
+  
+  TODO: document
+*/
+
 @class NGLdapConnection;
 
 @interface NGLdapSearchResultEnumerator : NSEnumerator
 {
-@public
+@public // TODO: required to be public?!
   NGLdapConnection *connection;
   void             *handle;
   int              msgid;
 
 - (id)initWithConnection:(NGLdapConnection *)_con messageID:(int)_mid;
 
+/* accessors */
+
 - (int)messageID;
 - (NSTimeInterval)duration;
 - (unsigned)index;
 
+- (void)setTimeout:(NSTimeInterval)_value;
+- (NSTimeInterval)timeout;
+
+/* operations */
+
 - (void)cancel;
 
 @end
index ab282d0e97438fe8b92403916228ed5746049d4d..68e3d00cc5bbc485d7e167ba83e5d07b74d1c6fd 100644 (file)
 @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;
 }
 
   return self->index;
 }
 
+- (void)setTimeout:(NSTimeInterval)_value {
+  self->timeout = _value;
+}
+- (NSTimeInterval)timeout {
+  return self->timeout;
+}
+
 /* enumerator */
 
 - (void)cancel {
   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];
 
 - (NSString *)description {
   NSMutableString *s;
-
+  
   s = [NSMutableString stringWithCapacity:100];
   [s appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
 
index 85b2c4bcc5810a3d687630c6c613f1d621722e5b..2ed5f2f708025a832a1c3e28e826d84b91777c40 100644 (file)
@@ -2,4 +2,4 @@
 
 MAJOR_VERSION=4
 MINOR_VERSION=5
-SUBMINOR_VERSION:=25
+SUBMINOR_VERSION:=26