svn commit: samba r18311 - in branches/SAMBA_3_0/source/lib: .

vlendec at samba.org vlendec at samba.org
Sat Sep 9 21:31:57 GMT 2006


Author: vlendec
Date: 2006-09-09 21:31:56 +0000 (Sat, 09 Sep 2006)
New Revision: 18311

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18311

Log:
Simplify gencache_get by using strtol instead of sscanf
Modified:
   branches/SAMBA_3_0/source/lib/gencache.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/gencache.c
===================================================================
--- branches/SAMBA_3_0/source/lib/gencache.c	2006-09-09 21:05:51 UTC (rev 18310)
+++ branches/SAMBA_3_0/source/lib/gencache.c	2006-09-09 21:31:56 UTC (rev 18311)
@@ -180,6 +180,8 @@
 BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
 {
 	TDB_DATA keybuf, databuf;
+	time_t t;
+	char *endptr;
 
 	/* fail completely if get null pointers passed */
 	SMB_ASSERT(keystr);
@@ -191,68 +193,44 @@
 	keybuf.dptr = CONST_DISCARD(char *, keystr);
 	keybuf.dsize = strlen(keystr)+1;
 	databuf = tdb_fetch(cache, keybuf);
-	
-	if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) {
-		char* entry_buf = SMB_STRNDUP(databuf.dptr, databuf.dsize);
-		char *v;
-		time_t t;
-		unsigned u;
-		int status;
-		char *fmt;
 
-		v = (char *)SMB_MALLOC(databuf.dsize + 1 - TIMEOUT_LEN);
-		if (!v) {
-			return False;
-		}
+	if (databuf.dptr == NULL) {
+		DEBUG(10, ("Cache entry with key = %s couldn't be found\n",
+			   keystr));
+		return False;
+	}
 
+	t = strtol(databuf.dptr, &endptr, 10);
+
+	if ((endptr == NULL) || (*endptr != '/')) {
+		DEBUG(2, ("Invalid gencache data format: %s\n", databuf.dptr));
 		SAFE_FREE(databuf.dptr);
+		return False;
+	}
 
-		asprintf(&fmt, READ_CACHE_DATA_FMT_TEMPLATE, (unsigned int)databuf.dsize - TIMEOUT_LEN);
-		if (!fmt) {
-			SAFE_FREE(v);
+	DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, "
+		   "timeout = %s", t > time(NULL) ? "valid" :
+		   "expired", keystr, endptr+1, ctime(&t)));
+
+	if (valstr) {
+		*valstr = SMB_STRDUP(endptr+1);
+		if (*valstr == NULL) {
+			SAFE_FREE(databuf.dptr);
+			DEBUG(0, ("strdup failed\n"));
 			return False;
 		}
-
-		status = sscanf(entry_buf, fmt, &u, v);
-		SAFE_FREE(fmt);
-
-		if ( status != 2 ) {
-			DEBUG(0, ("gencache_get: Invalid return %d from sscanf\n", status ));
-		}
-		t = u;
-		SAFE_FREE(entry_buf);
-
-		DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, "
-			   "timeout = %s", t > time(NULL) ? "valid" :
-			   "expired", keystr, v, ctime(&t)));
-
-		if (valstr) {
-			*valstr = v;
-		} else {
-			SAFE_FREE(v);
-		}
-
-		if (timeout) {
-			*timeout = t;
-		}
-
-		return t > time(NULL);
-
-	} 
-
+	}
+	
 	SAFE_FREE(databuf.dptr);
 
-	if (valstr) {
-		*valstr = NULL;
-	}
 	if (timeout) {
-		timeout = NULL;
+		*timeout = t;
 	}
 
-	DEBUG(10, ("Cache entry with key = %s couldn't be found\n", keystr));
-	return False;
-}
+	return t > time(NULL);
+} 
 
+
 /**
  * Iterate through all entries which key matches to specified pattern
  *



More information about the samba-cvs mailing list