From 9a47e3c81aac1f132c6bcb24df37b9a753372d06 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 24 Nov 2005 01:44:29 +0000 Subject: [PATCH] use lutil_ato*() whenever appropriate --- servers/slapd/overlays/pcache.c | 41 ++++++++++---------------------- tests/scripts/test020-proxycache | 2 +- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 0eca802cbe..1e488649e4 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -1717,15 +1717,16 @@ pc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca ) static int pc_cf_gen( ConfigArgs *c ) { - slap_overinst *on = (slap_overinst *)c->bi; + slap_overinst *on = (slap_overinst *)c->bi; cache_manager* cm = on->on_bi.bi_private; query_manager* qm = cm->qm; QueryTemplate* temp; AttributeName* attr_name; AttributeName* attrarray; const char* text=NULL; - int i, num, rc = 0; - char *ptr, *next; + int i, num, rc = 0; + char *ptr; + unsigned long t; if ( c->op == SLAP_CONFIG_EMIT ) { struct berval bv; @@ -1806,8 +1807,7 @@ pc_cf_gen( ConfigArgs *c ) return( 1 ); } - cm->numattrsets = strtol( c->argv[3], &next, 10 ); - if ( next == c->argv[3] || next[0] != '\0' ) { + if ( lutil_atoi( &cm->numattrsets, c->argv[3] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse num attrsets=\"%s\" (arg #3)", c->argv[3] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); @@ -1830,8 +1830,7 @@ pc_cf_gen( ConfigArgs *c ) return( 1 ); } - cm->max_entries = strtol( c->argv[2], &next, 10 ); - if ( next == c->argv[2] || next[ 0 ] != '\0' ) { + if ( lutil_atoi( &cm->max_entries, c->argv[2] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse max entries=\"%s\" (arg #2)", c->argv[2] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); @@ -1843,8 +1842,7 @@ pc_cf_gen( ConfigArgs *c ) return( 1 ); } - cm->num_entries_limit = strtol( c->argv[4], &next, 10 ); - if ( next == c->argv[4] || next[ 0 ] != '\0' ) { + if ( lutil_atoi( &cm->num_entries_limit, c->argv[4] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse entry limit=\"%s\" (arg #4)", c->argv[4] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); @@ -1861,19 +1859,13 @@ pc_cf_gen( ConfigArgs *c ) return( 1 ); } - cm->cc_period = strtol( c->argv[5], &next, 10 ); - if ( next == c->argv[5] || next[ 0 ] != '\0' ) { + if ( lutil_parse_time( c->argv[5], &t ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse period=\"%s\" (arg #5)", c->argv[5] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); return( 1 ); } - if ( cm->cc_period <= 0 ) { - snprintf( c->msg, sizeof( c->msg ), "period (arg #5) must be positive" ); - Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); - return( 1 ); - } - + cm->cc_period = t; Debug( LDAP_DEBUG_TRACE, "Total # of attribute sets to be cached = %d.\n", cm->numattrsets, 0, 0 ); @@ -1886,8 +1878,7 @@ pc_cf_gen( ConfigArgs *c ) Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); return( 1 ); } - num = strtol( c->argv[1], &next, 10 ); - if ( next == c->argv[1] || next[ 0 ] != '\0' ) { + if ( lutil_atoi( &num, c->argv[1] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse attrset #=\"%s\"", c->argv[1] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); @@ -1932,8 +1923,7 @@ pc_cf_gen( ConfigArgs *c ) Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); return( 1 ); } - i = strtol( c->argv[2], &next, 10 ); - if ( next == c->argv[2] || next[ 0 ] != '\0' ) { + if ( lutil_atoi( &i, c->argv[2] ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse template #=\"%s\"", c->argv[2] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); @@ -1954,18 +1944,13 @@ pc_cf_gen( ConfigArgs *c ) temp = qm->templates + num; ldap_pvt_thread_rdwr_init( &temp->t_rwlock ); temp->query = temp->query_last = NULL; - temp->ttl = strtol( c->argv[3], &next, 10 ); - if ( next == c->argv[3] || next[ 0 ] != '\0' ) { + if ( lutil_parse_time( c->argv[3], &t ) != 0 ) { snprintf( c->msg, sizeof( c->msg ), "unable to parse template ttl=\"%s\"", c->argv[3] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); return( 1 ); } - if ( temp->ttl <= 0 ) { - snprintf( c->msg, sizeof( c->msg ), "template ttl must be positive" ); - Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 ); - return( 1 ); - } + temp->ttl = (long)t; temp->no_of_queries = 0; diff --git a/tests/scripts/test020-proxycache b/tests/scripts/test020-proxycache index 5775a43361..c6ec3db525 100755 --- a/tests/scripts/test020-proxycache +++ b/tests/scripts/test020-proxycache @@ -13,7 +13,7 @@ ## top-level directory of the distribution or, alternatively, at ## . -CACHETTL=60 +CACHETTL="1m" CACHE_ENTRY_LIMIT=10 . $SRCDIR/scripts/defines.sh -- 2.39.5