[Mod-auth-commit] mod_dbi_pool/src mod_dbi_pool.c,1.6,1.7
Brought to you by:
firechipmunk,
honx
From: <fir...@us...> - 2004-03-03 07:26:04
|
Update of /cvsroot/mod-auth/mod_dbi_pool/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12349/src Modified Files: mod_dbi_pool.c Log Message: indent w/ apache style. I must remember todo this before commiting. Index: mod_dbi_pool.c =================================================================== RCS file: /cvsroot/mod-auth/mod_dbi_pool/src/mod_dbi_pool.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- mod_dbi_pool.c 3 Mar 2004 05:42:56 -0000 1.6 +++ mod_dbi_pool.c 3 Mar 2004 07:05:49 -0000 1.7 @@ -46,6 +46,7 @@ dbi_config *create_new_conf(conn_id conn_id, apr_pool_t * p) { dbi_config *conf; + conf = (dbi_config *) apr_pcalloc(p, sizeof(dbi_config)); if (conf == NULL) { return NULL; @@ -61,18 +62,19 @@ conf->rec.conn_ttl = DFLT_CONN_TTL; apr_hash_set(dbi_pool_config, conn_id, APR_HASH_KEY_STRING, conf); ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, - "[mod_dbi_pool.c] Creating Config for %s", conn_id); + "[mod_dbi_pool.c] Creating Config for %s", conn_id); return conf; } static apr_status_t get_or_create_dbi_conf(const char *conn_id, - apr_pool_t * p, - dbi_config ** confname) + apr_pool_t * p, dbi_config ** confname) { dbi_config *temp; unsigned int c; - /* some sanity checks on conn_id..limits are liberal and are more or less random */ + /* + * some sanity checks on conn_id..limits are liberal and are more or less random + */ if (strlen(conn_id) > 255) { return APR_EGENERAL; } @@ -83,7 +85,9 @@ } temp = apr_hash_get(dbi_pool_config, conn_id, APR_HASH_KEY_STRING); if (temp == NULL) { - /* no such server yet... */ + /* + * no such server yet... + */ temp = create_new_conf(conn_id, p); } *confname = temp; @@ -91,16 +95,19 @@ } static const char *set_dbi_switch_conf(cmd_parms * cmd, void *config, - const char *conn_id, const char *value) + const char *conn_id, const char *value) { apr_ssize_t pos = (apr_ssize_t) cmd->info; dbi_config *temp; + if ((get_or_create_dbi_conf(conn_id, cmd->pool, &temp)) == APR_SUCCESS) { - /* Overwriting an existing value technically is a memory leak, since the pconf pool is only - * destroyed at the termination of the whole apache process. Otoh, when processing htaccess, - * we get handed the request-pool instead which is freed afterwards, so we should be fine. */ + /* + * Overwriting an existing value technically is a memory leak, since the pconf pool is only + * * destroyed at the termination of the whole apache process. Otoh, when processing htaccess, + * * we get handed the request-pool instead which is freed afterwards, so we should be fine. + */ // XXXX: Since mod_pool_dbi will be around alot longer, this needs to be fixed! switch (pos) { @@ -140,35 +147,37 @@ } static const command_rec dbi_pool_cmds[] = { - /* global config items */ + /* + * global config items + */ AP_INIT_TAKE2("PoolDbiDriver", set_dbi_switch_conf, - (void *) CONF_DBI_DRIVER, RSRC_CONF, - "The DBI Driver"), - AP_INIT_TAKE2("PoolDbiHost", set_dbi_switch_conf, (void *) CONF_DBI_HOST, - RSRC_CONF, - "The host for the database connection"), + (void *)CONF_DBI_DRIVER, RSRC_CONF, + "The DBI Driver"), + AP_INIT_TAKE2("PoolDbiHost", set_dbi_switch_conf, (void *)CONF_DBI_HOST, + RSRC_CONF, + "The host for the database connection"), AP_INIT_TAKE2("PoolDbiUsername", set_dbi_switch_conf, - (void *) CONF_DBI_USERNAME, RSRC_CONF, - "The username for the database connection"), + (void *)CONF_DBI_USERNAME, RSRC_CONF, + "The username for the database connection"), AP_INIT_TAKE2("PoolDbiPassword", set_dbi_switch_conf, - (void *) CONF_DBI_PASSWORD, RSRC_CONF, - "The password for the database connection"), + (void *)CONF_DBI_PASSWORD, RSRC_CONF, + "The password for the database connection"), AP_INIT_TAKE2("PoolDbiDBName", set_dbi_switch_conf, - (void *) CONF_DBI_DBNAME, - RSRC_CONF, - "The name of the database containing the tables"), + (void *)CONF_DBI_DBNAME, + RSRC_CONF, + "The name of the database containing the tables"), AP_INIT_TAKE2("PoolDbiConnMin", set_dbi_switch_conf, - (void *) CONF_DBI_CONN_MIN, RSRC_CONF, - "The Minimum Number of Database Connections"), + (void *)CONF_DBI_CONN_MIN, RSRC_CONF, + "The Minimum Number of Database Connections"), AP_INIT_TAKE2("PoolDbiConnSoftMax", set_dbi_switch_conf, - (void *) CONF_DBI_CONN_SOFTMAX, RSRC_CONF, - "The Soft Maximum Number of Database Connections"), + (void *)CONF_DBI_CONN_SOFTMAX, RSRC_CONF, + "The Soft Maximum Number of Database Connections"), AP_INIT_TAKE2("PoolDbiConnHardMax", set_dbi_switch_conf, - (void *) CONF_DBI_CONN_HARDMAX, RSRC_CONF, - "The Hard Maximum Number of Database Connections"), + (void *)CONF_DBI_CONN_HARDMAX, RSRC_CONF, + "The Hard Maximum Number of Database Connections"), AP_INIT_TAKE2("PoolDbiConnTTL", set_dbi_switch_conf, - (void *) CONF_DBI_CONN_TTL, RSRC_CONF, - "The Database Pool Time To Live for Each Connection."), + (void *)CONF_DBI_CONN_TTL, RSRC_CONF, + "The Database Pool Time To Live for Each Connection."), {NULL} }; @@ -178,7 +187,7 @@ /* an apr_reslist_constructor for DBI connections */ static apr_status_t dbipool_construct(void **db, void *params, - apr_pool_t * pool) + apr_pool_t * pool) { dbi_config_rec *conf = params; int err_num = 0; @@ -187,7 +196,7 @@ *db = dbi_conn_new(conf->dbi_driver); // Test for a Fatal Error on Creating the Driver - if(*db == NULL) { + if (*db == NULL) { ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, pool, "[mod_dbi_pool.c] DBI Connection Failed. dbi_conn_new returned NULL. Insufficient memory or invalid DBD?"); /** @@ -204,26 +213,27 @@ if (dbi_conn_connect(*db) != 0) { err_num = dbi_conn_error(*db, &err_str); - /* Connetion Failed */ + /* + * Connetion Failed + */ ap_log_perror(APLOG_MARK, APLOG_CRIT, 0, pool, - "[mod_dbi_pool.c] DBI Connection to %s://%s@%s/%s Failed. Error: (%d) %s", - conf->dbi_driver, conf->dbi_user, - conf->dbi_host, conf->dbi_dbname, - err_num, err_str); + "[mod_dbi_pool.c] DBI Connection to %s://%s@%s/%s Failed. Error: (%d) %s", + conf->dbi_driver, conf->dbi_user, + conf->dbi_host, conf->dbi_dbname, err_num, err_str); return APR_EGENERAL; } return APR_SUCCESS; } static apr_status_t dbipool_destruct(void *sql, void *params, - apr_pool_t * pool) + apr_pool_t * pool) { dbi_conn_close((dbi_conn *) sql); return APR_SUCCESS; } static int dbi_pool_post_config(apr_pool_t * p, apr_pool_t * plog, - apr_pool_t * ptemp, server_rec * s) + apr_pool_t * ptemp, server_rec * s) { int rval; apr_hash_index_t *idx; @@ -235,60 +245,66 @@ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { - apr_pool_userdata_set((const void *) 1, userdata_key, - apr_pool_cleanup_null, s->process->pool); + apr_pool_userdata_set((const void *)1, userdata_key, + apr_pool_cleanup_null, s->process->pool); return OK; } ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, - "[mod_dbi_pool.c] Running DBI Pool Init"); + "[mod_dbi_pool.c] Running DBI Pool Init"); if ((rval = dbi_initialize(NULL)) > 0) { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, - "[mod_dbi_pool.c] Initialization of libdbi found %d drivers in default driver directory", - rval); - } - else { /* An error was returned or libdbi found 0 drivers */ + "[mod_dbi_pool.c] Initialization of libdbi found %d drivers in default driver directory", + rval); + } + else { /* An error was returned or libdbi found 0 drivers */ ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, - "[mod_dbi_pool.c] - Initlialization of libdbi with default driver directory failed"); + "[mod_dbi_pool.c] - Initlialization of libdbi with default driver directory failed"); return APR_EDSOOPEN; } - /* loop the hashed config stuff... */ + /* + * loop the hashed config stuff... + */ for (idx = apr_hash_first(p, dbi_pool_config); idx; - idx = apr_hash_next(idx)) { - apr_hash_this(idx, (void *) &key, &len, (void *) &val); - if(apr_reslist_create(&val->pool, val->rec.conn_min, /* hard minimum */ - val->rec.conn_soft, /* soft maximum */ - val->rec.conn_max, /* hard maximum */ - val->rec.conn_ttl, /* Time to live -- dbi server might override/disconnect! */ - dbipool_construct, /* Make a New Connection */ - dbipool_destruct, /* Kill Old Connection */ - (void *) &val->rec, p) != APR_SUCCESS) - ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, - "[mod_dbi_pool.c] - Creation of dbi connection pool failed for config set %s", - key); - /* XXX: If no new connection could be opened, the reslist will not - contain any resources and reslist_create will fail, giving - val->pool the value NULL and making it unusable. The configuration - set is not really recoverable in this case. For now we log this condition - and the authentication functions protect themselves against this - condition. A much better way would be to free the configuration - set completely. But to do this other changes are necessary, so for - now this is basically a workaround. This has to be fixed before - 1.0 */ + idx = apr_hash_next(idx)) { + apr_hash_this(idx, (void *)&key, &len, (void *)&val); + if (apr_reslist_create(&val->pool, val->rec.conn_min, /* hard minimum */ + val->rec.conn_soft, /* soft maximum */ + val->rec.conn_max, /* hard maximum */ + val->rec.conn_ttl, /* Time to live -- dbi server might override/disconnect! */ + dbipool_construct, /* Make a New Connection */ + dbipool_destruct, /* Kill Old Connection */ + (void *)&val->rec, p) != APR_SUCCESS) + ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, + "[mod_dbi_pool.c] - Creation of dbi connection pool failed for config set %s", + key); + /* + * XXX: If no new connection could be opened, the reslist will not + * contain any resources and reslist_create will fail, giving + * val->pool the value NULL and making it unusable. The configuration + * set is not really recoverable in this case. For now we log this condition + * and the authentication functions protect themselves against this + * condition. A much better way would be to free the configuration + * set completely. But to do this other changes are necessary, so for + * now this is basically a workaround. This has to be fixed before + * 1.0 + */ apr_hash_set(dbi_pool_config, key, APR_HASH_KEY_STRING, val); } + ap_add_version_component(p, "mod_dbi_pool/0.1.0"); return OK; } static apr_status_t dbi_pool_pre_config(apr_pool_t * pconf, - apr_pool_t * plog, - apr_pool_t * ptemp) + apr_pool_t * plog, apr_pool_t * ptemp) { apr_status_t rv = APR_SUCCESS; - /* create our globalish config var */ + /* + * create our globalish config var + */ dbi_pool_config = apr_hash_make(pconf); return rv; } @@ -314,19 +330,20 @@ - close releases it back in to the pool */ -dbi_conn *dbipool_open(conn_id* id) +dbi_conn *dbipool_open(conn_id * id) { dbi_conn *ret = NULL; dbi_config *conf = apr_hash_get(dbi_pool_config, id, APR_HASH_KEY_STRING); - if (apr_reslist_acquire(conf->pool, (void **) &ret) != APR_SUCCESS) { + if (apr_reslist_acquire(conf->pool, (void **)&ret) != APR_SUCCESS) { return NULL; } return ret; } -void dbipool_close(conn_id* id, dbi_conn* conn) { +void dbipool_close(conn_id * id, dbi_conn * conn) +{ dbi_config *conf = apr_hash_get(dbi_pool_config, id, APR_HASH_KEY_STRING); - apr_reslist_release(conf->pool, (void **) conn); -} + apr_reslist_release(conf->pool, (void **)conn); +} |