/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
dav_buffer ns_table; /* table of namespace URIs */ short ns_count; /* number of entries in table */ int ns_table_dirty; /* ns_table was modified */
apr_hash_t *uri_index; /* map URIs to (1-based) table indices */
dav_buffer wb_key; /* work buffer for dav_gdbm_key */
/* There might not be a <db> if we had problems creating it. */ if (db == NULL) {
errcode = 1;
errstr = "Could not open database."; if (APR_STATUS_IS_EDSOOPEN(status))
ap_log_error(APLOG_MARK, APLOG_CRIT, status, ap_server_conf, APLOGNO(00576) "The DBM driver could not be loaded");
} else {
(void) apr_dbm_geterror(db->file, &errcode, errbuf, sizeof(errbuf));
errstr = apr_pstrdup(p, errbuf);
}
/* ensure that our state subdirectory is present */ /* ### does this belong here or in dav_fs_repos.c ?? */ void dav_fs_ensure_state_dir(apr_pool_t * p, constchar *dirname)
{ constchar *pathname = apr_pstrcat(p, dirname, "/" DAV_FS_STATE_DIR, NULL);
/* ### do we need to deal with the umask? */
/* just try to make it, ignoring any resulting errors */
(void) apr_dir_make(pathname, APR_OS_DEFAULT, p);
}
#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 7) if ((status = apr_dbm_get_driver(&driver, NULL, &err, p)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, status, ap_server_conf, APLOGNO(10289) "mod_dav_fs: The DBM library '%s' could not be loaded: %s",
err->reason, err->msg); return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 1, status, "Could not load library for database.");
} if ((status = apr_dbm_open2(&file, driver, pathname,
ro ? APR_DBM_READONLY : APR_DBM_RWCREATE,
APR_OS_DEFAULT, p))
!= APR_SUCCESS && !ro) { return dav_fs_dbm_error(NULL, p, status);
} #else 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);
} #endif
/* 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;
}
/* Get directory and filename for resource */ /* ### should test this result value... */
(void) dav_fs_dir_file_name(resource, &dirpath, &fname);
/* If not opening read-only, ensure the state dir exists */ if (!ro) { /* ### what are the perf implications of always checking this? */
dav_fs_ensure_state_dir(p, dirpath);
}
if (!key.dptr) { /* no key could be created (namespace not known) => no value */
memset(pvalue, 0, sizeof(*pvalue));
status = APR_SUCCESS;
} else {
status = apr_dbm_fetch(db->file, key, pvalue);
}
/* call it a major version error */ return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_PROP_BAD_MAJOR, 0, "Prop database has the wrong major " "version number and cannot be used.");
}
/* initialize a new metadata structure */
dav_set_bufsize(pool, &db->ns_table, sizeof(m));
memcpy(db->ns_table.buf, &m, sizeof(m));
} else {
dav_propdb_metadata m; long ns; constchar *uri;
memcpy(&m, value.dptr, sizeof(m)); if (m.major != DAV_DBVSN_MAJOR) {
dav_dbm_close(db);
return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_PROP_BAD_MAJOR, 0, "Prop database has the wrong major " "version number and cannot be used.");
}
db->version = m.minor;
db->ns_count = ntohs(m.ns_count);
dav_dbm_freedatum(db, value);
/* create db->uri_index */ for (ns = 0, uri = db->ns_table.buf + sizeof(dav_propdb_metadata);
ns++ < db->ns_count;
uri += strlen(uri) + 1) {
/* we must copy the key, in case ns_table.buf moves */
apr_hash_set(db->uri_index,
apr_pstrdup(pool, uri), APR_HASH_KEY_STRING,
(void *)ns);
}
}
*pdb = db; return NULL;
}
staticvoid dav_propdb_close(dav_db *db)
{
if (db->ns_table_dirty) {
dav_propdb_metadata m;
apr_datum_t key;
apr_datum_t value;
dav_error *err;
/* fill in the metadata that we store into the prop db. */
m.major = DAV_DBVSN_MAJOR;
m.minor = db->version; /* ### keep current minor version? */
m.ns_count = htons(db->ns_count);
/* within the prop values, we use "ns%d" for prefixes... register them */ for (ns = 0; ns < db->ns_count; ++ns, uri += strlen(uri) + 1) {
/* Empty URIs signify the empty namespace. These do not get a namespaceprefix.whenwegeneratethevalue,wewillsimply leaveofftheprefix,whichisdefinedbymod_davtobethe
empty namespace. */ if (*uri == '\0') continue;
/* ns_table.buf can move, so copy its value (we want the values to
last as long as the provided dav_xmlns_info). */
dav_xmlns_add(xi,
apr_psprintf(xi->pool, "ns%d", ns),
apr_pstrdup(xi->pool, uri));
}
/* copy the uri in case the passed-in namespaces changes in
some way. */
apr_hash_set(db->uri_index, apr_pstrdup(db->pool, uri), uri_len,
(void *)((long)(db->ns_count + 1)));
/* Note: mapping->ns_map was set up in dav_propdb_map_namespaces() */
/* ### use a db- subpool for these values? clear on exit? */
/* quote all the values in the element */ /* ### be nice to do this without affecting the element itself */ /* ### of course, the cast indicates Badness is occurring here */
apr_xml_quote_elem(db->pool, (apr_xml_elem *)elem);
/* generate a text blob for the xml:lang plus the contents */
apr_xml_to_text(db->pool, elem, APR_XML_X2T_LANG_INNER, NULL,
mapping->ns_map,
(constchar **)&value.dptr, &value.dsize);
/* free the previous key. note: if the loop is aborted, then the DBM
will toss the key (via pool cleanup) */ if (db->iter.dptr != NULL)
dav_dbm_freedatum(db, db->iter);
if ((err = dav_dbm_nextkey(db, &db->iter)) != NULL) return err;
/* skip past the METADATA key */ if (db->iter.dptr != NULL && *db->iter.dptr == 'M') return dav_propdb_next_name(db, pname);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.