int main(int argc,char **argv) { apr_initialize(); apr_pool_t *pool; apr_pool_create(&pool,NULL); apr_status_t st; apr_dbm_t *dbm; st=apr_dbm_open(&dbm,"friends",APR_DBM_RWCREATE,APR_OS_DEFAULT ,pool); apr_datum_t key,value; key.dptr="laomeng"; key.dsize=strlen(key.dptr); value.dptr="*****@*****.**"; value.dsize=strlen(value.dptr); st=apr_dbm_store(dbm,key,value); apr_datum_t pvalue; st=apr_dbm_fetch(dbm,key,&pvalue); char *pstr=apr_pstrndup(pool,pvalue.dptr,pvalue.dsize); printf("value => %s\n",pstr); apr_dbm_close(dbm); apr_pool_destroy(pool); apr_terminate(); return 0; }
/* dav_dbm_open_direct: Opens a *dbm database specified by path. * ro = boolean read-only flag. */ dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro, dav_db **pdb) { apr_status_t status; apr_dbm_t *file; *pdb = NULL; if ((status = apr_dbm_open(&file, pathname, ro ? APR_DBM_READONLY : APR_DBM_RWCREATE, APR_OS_DEFAULT, p)) != APR_SUCCESS && !ro) { /* ### do something with 'status' */ /* we can't continue if we couldn't open the file and we need to write */ return dav_fs_dbm_error(NULL, p, status); } /* may be NULL if we tried to open a non-existent db as read-only */ if (file != NULL) { /* we have an open database... return it */ *pdb = apr_pcalloc(p, sizeof(**pdb)); (*pdb)->pool = p; (*pdb)->file = file; } return NULL; }
/* * dav_generic_really_open_lockdb: * * If the database hasn't been opened yet, then open the thing. */ static dav_error * dav_generic_really_open_lockdb(dav_lockdb *lockdb) { dav_error *err; apr_status_t status; if (lockdb->info->opened) { return NULL; } status = apr_dbm_open(&lockdb->info->db, lockdb->info->lockdb_path, lockdb->ro ? APR_DBM_READONLY : APR_DBM_RWCREATE, APR_OS_DEFAULT, lockdb->info->pool); if (status) { err = dav_generic_dbm_new_error(lockdb->info->db, lockdb->info->pool, status); return dav_push_error(lockdb->info->pool, HTTP_INTERNAL_SERVER_ERROR, DAV_ERR_LOCK_OPENDB, "Could not open the lock database.", err); } /* all right. it is opened now. */ lockdb->info->opened = 1; return NULL; }
static void openDb(apr_dbm_t **userDbm, const char *dbFilename, request_rec *r) { apr_status_t rv; ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r, LOG_PREFIX "Opening db ..."); rv = apr_dbm_open(userDbm, dbFilename, APR_DBM_RWCREATE, APR_FPROT_OS_DEFAULT, r->pool); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, LOG_PREFIX "Error opening db %s ...", dbFilename); } }