changeset 20:bf731fa9c758

argh, sendmail is a pos. some major fudge to store keys as strings
author Simon Horman <horms@verge.net.au>
date Thu, 16 May 2002 17:41:20 +0900
parents 168009f3e66f
children 932d22ff55b5
files pbs/pbs.c pbs/pbs_record_db.c
diffstat 2 files changed, 31 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/pbs/pbs.c	Thu May 16 16:48:16 2002 +0900
+++ b/pbs/pbs.c	Thu May 16 17:41:20 2002 +0900
@@ -547,12 +547,8 @@
 
 static int do_mode_list(pbs_db_t *db, const char **key, const char *prefix) {
 	size_t width;
-	time_t *time;
-	size_t len;
-	size_t buf_len = 0;
+	time_t time;
 	const char **k;
-	const char *k_fixed;
-	char *buf = NULL;
 
 	width = pbs_key_width(prefix);
 
@@ -572,24 +568,15 @@
 
 
 	for(k = key ; *k != NULL; k++) {
-		k_fixed = pbs_record_fix_key(*k, prefix, &buf, &buf_len);
-		if(k_fixed == NULL) {
-			PBS_DEBUG("pbs_record_fix_key");
-			return(-1);
-		}
-		if(pbs_db_get(db, (char *)k_fixed, strlen(k_fixed)+1, 
-				(void **)&time, &len) < 0) {
+		if(pbs_record_db_get(db, *k, prefix, &time, 
+					NULL, NULL) < 0) {
 			pbs_record_show_str((char *)*k, "Not found", width);
 		}
 		else {
-			pbs_record_show((char *)*k, *time, width);
+			pbs_record_show((char *)*k, time, width);
 		}
 	}
 
-	if(buf != NULL) {
-		free(buf);
-	}
-
 	return(0);
 }
 
@@ -598,10 +585,7 @@
 static int do_mode_remove(pbs_db_t *db, const char **key, const char *prefix,
 		int quiet) {
 	size_t width;
-	size_t buf_len = 0;
 	const char **k;
-	const char *k_fixed;
-	char *buf = NULL;
 	char *response;
 
 	if(key == NULL) {
@@ -617,13 +601,7 @@
 	}
 
 	for(k = key ; *k != NULL; k++) {
-
-		k_fixed = pbs_record_fix_key(*k, prefix, &buf, &buf_len);
-		if(k_fixed == NULL) {
-			PBS_DEBUG("pbs_record_fix_key");
-			return(-1);
-		}
-		if(pbs_db_del(db, (char *)k_fixed, strlen(k_fixed)+1) < 0) {
+		if(pbs_record_db_del(db, *k, prefix) < 0) {
 			response = "Not found";
 		}
 		else {
@@ -634,10 +612,6 @@
 		}
 	}
 
-	if(buf != NULL) {
-		free(buf);
-	}
-
 	return(0);
 }
 
@@ -705,7 +679,6 @@
 	char *buf = NULL;
 	time_t expire;
 	time_t now;
-	size_t len;
 	size_t buf_len = 0;
 
 	if(argv == NULL) {
@@ -735,12 +708,11 @@
 	}
 
 	now = time(NULL);
-	if(pbs_db_get(db, (char *)peername_str_fixed, 
-			strlen(peername_str_fixed)+1, 
-			(void **)&expire, &len) < 0) {
+	if(pbs_record_db_get(db, peername_str_fixed, prefix,
+			&expire, NULL, NULL) < 0) {
 		PBS_INFO_UNSAFE("No (Not in database): %s", peername_str);
 	}
-	else if (difftime(now, expire) < 0) {
+	else if (difftime(now, expire) > 0) {
 		PBS_INFO_UNSAFE("No (Expired): %s", peername_str);
 	}
 	else {
--- a/pbs/pbs_record_db.c	Thu May 16 16:48:16 2002 +0900
+++ b/pbs/pbs_record_db.c	Thu May 16 17:41:20 2002 +0900
@@ -82,7 +82,8 @@
 	const char *ip_fixed;
 	char *time_ip = NULL;
 	size_t buf_len = 0;
-	size_t dummy;
+	size_t dummy_len;
+	time_t *dummy;
 	char *buf = NULL;
 	int exit_status = -1;
 
@@ -92,25 +93,29 @@
 		goto leave;
 	}
 
-	time_ip = pbs_record_prefix_key(ip_fixed, PBS_TIME_PREFIX);
-	if(time_ip == NULL) {
-		PBS_DEBUG("pbs_record_prefix_key");
-		goto leave;
+	if(status != NULL && status_len != NULL) {
+		if(pbs_db_get(db, (void *)ip_fixed, strlen(ip_fixed)+1,
+					(void **)status, status_len) < 0) {
+			PBS_DEBUG("pbs_db_get");
+			goto leave;
+		}
+		if(*status_len > 0) {
+			*status_len=*status_len-1;
+		}
 	}
 
-	if(pbs_db_get(db, (void *)ip_fixed, strlen(ip_fixed)+1,
-				(void **)status, status_len) < 0) {
-		PBS_DEBUG("pbs_db_get");
-		goto leave;
-	}
-	if(*status_len > 0) {
-		*status_len=*status_len-1;
-	}
-
-	if(pbs_db_get(db, (void *)time_ip, strlen(time_ip)+1,
-				(void **)expire, &dummy) < 0) {
-		PBS_DEBUG("pbs_db_get");
-		goto leave;
+	if(expire != NULL) {
+		time_ip = pbs_record_prefix_key(ip_fixed, PBS_TIME_PREFIX);
+		if(time_ip == NULL) {
+			PBS_DEBUG("pbs_record_prefix_key");
+			goto leave;
+		}
+		if(pbs_db_get(db, (void *)time_ip, strlen(time_ip)+1,
+					(void **)&dummy, &dummy_len) < 0) {
+			PBS_DEBUG("pbs_db_get");
+			goto leave;
+		}
+		*expire = *dummy;
 	}
 
 	exit_status = 0;