]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/pcache.c
don't search max CSN if don't have a value; try the operational_attrs if entryCSN...
[openldap] / servers / slapd / overlays / pcache.c
index 0eca802cbe4a3d9fe4f40430f879deffa85b7af8..c2998332fb8f43863fb41621f523f249ab50703a 100644 (file)
@@ -68,7 +68,7 @@ typedef struct query_template_s {
        CachedQuery*    query_last;     /* oldest query cached for the template */
 
        int             no_of_queries;  /* Total number of queries in the template */
-       long            ttl;            /* TTL for the queries of this template */
+       time_t          ttl;            /* TTL for the queries of this template */
         ldap_pvt_thread_rdwr_t t_rwlock; /* Rd/wr lock for accessing queries in the template */
 } QueryTemplate;
 
@@ -127,7 +127,7 @@ typedef struct cache_manager_s {
 #define PCACHE_RESPONSE_CB_HEAD        0
 #define PCACHE_RESPONSE_CB_TAIL        1
 
-       int     cc_period;              /* interval between successive consistency checks (sec) */
+       time_t  cc_period;              /* interval between successive consistency checks (sec) */
        int     cc_paused;
        void    *cc_arg;
 
@@ -1086,7 +1086,7 @@ cache_entries(
 }
 
 static int
-proxy_cache_response(
+pcache_response(
        Operation       *op,
        SlapReply       *rs )
 {
@@ -1218,7 +1218,7 @@ add_filter_attrs(
  * performing the pagedResults search only within the client
  * and the proxy.  This requires pcache to understand pagedResults. */
 static int
-proxy_cache_chk_controls(
+pcache_chk_controls(
        Operation       *op,
        SlapReply       *rs )
 {
@@ -1249,7 +1249,7 @@ proxy_cache_chk_controls(
 }
 
 static int
-proxy_cache_search(
+pcache_op_search(
        Operation       *op,
        SlapReply       *rs )
 {
@@ -1377,7 +1377,7 @@ proxy_cache_search(
                add_filter_attrs(op, &op->ors_attrs, query.attrs, filter_attrs);
 
                cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx);
-               cb->sc_response = proxy_cache_response;
+               cb->sc_response = pcache_response;
                cb->sc_cleanup = NULL;
                cb->sc_private = (cb+1);
                si = cb->sc_private;
@@ -1717,21 +1717,22 @@ 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;
                switch( c->type ) {
                case PC_MAIN:
-                       bv.bv_len = snprintf( c->msg, sizeof( c->msg ), "%s %d %d %d %d",
+                       bv.bv_len = snprintf( c->msg, sizeof( c->msg ), "%s %d %d %d %ld",
                                cm->db.bd_info->bi_type, cm->max_entries, cm->numattrsets,
                                cm->num_entries_limit, cm->cc_period );
                        bv.bv_val = c->msg;
@@ -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 = (time_t)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 = (time_t)t;
 
                temp->no_of_queries = 0;
 
@@ -2003,7 +1988,7 @@ pc_cf_gen( ConfigArgs *c )
 }
 
 static int
-proxy_cache_config(
+pcache_db_config(
        BackendDB       *be,
        const char      *fname,
        int             lineno,
@@ -2022,7 +2007,7 @@ proxy_cache_config(
 }
 
 static int
-proxy_cache_init(
+pcache_db_init(
        BackendDB *be
 )
 {
@@ -2067,7 +2052,7 @@ proxy_cache_init(
 }
 
 static int
-proxy_cache_open(
+pcache_db_open(
        BackendDB *be
 )
 {
@@ -2124,7 +2109,7 @@ proxy_cache_open(
                if ( BER_BVISNULL( &cm->db.be_rootndn )
                                || BER_BVISEMPTY( &cm->db.be_rootndn ) )
                {
-                       Debug( LDAP_DEBUG_ANY, "proxy_cache_open(): "
+                       Debug( LDAP_DEBUG_ANY, "pcache_db_open(): "
                                "underlying database of type \"%s\"\n"
                                "    serving naming context \"%s\"\n"
                                "    has no \"rootdn\", required by \"proxycache\".\n",
@@ -2138,7 +2123,7 @@ proxy_cache_open(
 }
 
 static int
-proxy_cache_close(
+pcache_db_close(
        BackendDB *be
 )
 {
@@ -2180,7 +2165,7 @@ proxy_cache_close(
 }
 
 static int
-proxy_cache_destroy(
+pcache_db_destroy(
        BackendDB *be
 )
 {
@@ -2209,9 +2194,14 @@ proxy_cache_destroy(
        return 0;
 }
 
-static slap_overinst proxy_cache;
+static slap_overinst pcache;
 
-int pcache_init()
+static char *obsolete_names[] = {
+       "proxycache",
+       NULL
+};
+
+int pcache_initialize()
 {
        LDAPAttributeType *at;
        int code;
@@ -2221,7 +2211,7 @@ int pcache_init()
                LDAP_SCHEMA_ALLOW_ALL );
        if ( !at ) {
                Debug( LDAP_DEBUG_ANY,
-                       "pcache_init: ldap_str2attributetype failed %s %s\n",
+                       "pcache_initialize: ldap_str2attributetype failed %s %s\n",
                        ldap_scherr2str(code), err, 0 );
                return code;
        }
@@ -2232,32 +2222,34 @@ int pcache_init()
        ldap_memfree( at );
        if ( code ) {
                Debug( LDAP_DEBUG_ANY,
-                       "pcache_init: at_add failed %s %s\n",
+                       "pcache_initialize: at_add failed %s %s\n",
                        scherr2str(code), err, 0 );
                return code;
        }
 
-       proxy_cache.on_bi.bi_type = "pcache";
-       proxy_cache.on_bi.bi_db_init = proxy_cache_init;
-       proxy_cache.on_bi.bi_db_config = proxy_cache_config;
-       proxy_cache.on_bi.bi_db_open = proxy_cache_open;
-       proxy_cache.on_bi.bi_db_close = proxy_cache_close;
-       proxy_cache.on_bi.bi_db_destroy = proxy_cache_destroy;
-       proxy_cache.on_bi.bi_op_search = proxy_cache_search;
+       pcache.on_bi.bi_type = "pcache";
+       pcache.on_bi.bi_obsolete_names = obsolete_names;
+       pcache.on_bi.bi_db_init = pcache_db_init;
+       pcache.on_bi.bi_db_config = pcache_db_config;
+       pcache.on_bi.bi_db_open = pcache_db_open;
+       pcache.on_bi.bi_db_close = pcache_db_close;
+       pcache.on_bi.bi_db_destroy = pcache_db_destroy;
+
+       pcache.on_bi.bi_op_search = pcache_op_search;
 
-       proxy_cache.on_bi.bi_chk_controls = proxy_cache_chk_controls;
+       pcache.on_bi.bi_chk_controls = pcache_chk_controls;
 
-       proxy_cache.on_bi.bi_cf_ocs = pcocs;
+       pcache.on_bi.bi_cf_ocs = pcocs;
 
        code = config_register_schema( pccfg, pcocs );
        if ( code ) return code;
 
-       return overlay_register( &proxy_cache );
+       return overlay_register( &pcache );
 }
 
 #if SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC
 int init_module(int argc, char *argv[]) {
-       return pcache_init();
+       return pcache_initialize();
 }
 #endif