dbm.c revision 6f15570e3adc0faf87bf55f70857028276fc9e32
* 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see ** DAV extension module for Apache 2.0.* ** - Database support using DBM-style databases, ** part of the filesystem repository implementation ** This implementation uses a SDBM database per file and directory to ** record the properties. These databases are kept in a subdirectory (of ** the directory in question or the directory that holds the file in ** question) named by the macro DAV_FS_STATE_DIR (.DAV). The filename of the ** database is equivalent to the target filename, and is ** DAV_FS_STATE_FILE_FOR_DIR (.state_for_dir) for the directory itself. /* when used as a property database: */ int version;
/* *minor* version of this db */ short ns_count;
/* number of entries in table */ /* ------------------------------------------------------------------------- * For the most part, this just uses the APR DBM functions. They are wrapped * a bit with some error handling (using the mod_dav error functions). /* There might not be a <db> if we had problems creating it. */ errstr =
"Could not open property database.";
/* ensure that our state subdirectory is present */ /* ### do we need to deal with the umask? */ /* just try to make it, ignoring any resulting errors */ /* dav_dbm_open_direct: Opens a *dbm database specified by path. * ro = boolean read-only flag. /* ### do something with 'status' */ /* we can't continue if we couldn't open the file /* may be NULL if we tried to open a non-existent db as read-only */ /* we have an open database... return it */ /* Get directory and filename for resource */ /* ### should test this result value... */ /* If not opening read-only, ensure the state dir exists */ /* ### what are the perf implications of always checking this? */ /* ### readers cannot open while a writer has this open; we should ### perform a few retries with random pauses. */ /* ### do we need to deal with the umask? */ /* ------------------------------------------------------------------------- * PROPERTY DATABASE FUNCTIONS ** Prior versions could have keys or values with invalid ** namespace prefixes as a result of the xmlns="" form not ** resetting the default namespace to be "no namespace". The ** namespace would be set to "" which is invalid; it should ** be set to "no namespace". ** Prior versions could have values with invalid namespace ** prefixes due to an incorrect mapping of input to propdb ** namespace indices. Version bumped to obsolete the old ** This introduced the xml:lang value into the property value's ** Internal function to build a key ** WARNING: returns a pointer to a "static" buffer holding the key. The ** value must be copied or no longer used if this function is * Convert namespace ID to a string. "no namespace" is an empty string, * so the keys will have the form ":name". Otherwise, the keys will * have the form "#:name". /* the namespace was not found(!) */ /* build the database key */ /* skip past the xml:lang value */ /* the property is an empty value */ /* "no namespace" case */ else if (*
lang !=
'\0') {
/* "no namespace" case */ /* "no namespace" case */ ** Return if an error occurred, or there is no database. ** NOTE: db could be NULL if we attempted to open a readonly ** database that doesn't exist. If we require read/write ** access, then a database was created and opened. /* ### push a higher-level description? */ ** If there is no METADATA key, then the database may be ** from versions 0.9.0 .. 0.9.4 (which would be incompatible). ** These can be identified by the presence of an NS_TABLE entry. /* call it a major version error */ "Prop database has the wrong major " "version number and cannot be used.");
/* initialize a new metadata structure */ "Prop database has the wrong major " "version number and cannot be used.");
/* create db->uri_index */ /* we must copy the key, in case ns_table.buf moves */ /* fill in the metadata that we store into the prop db. */ /* ### what to do with the error? */ /* within the prop values, we use "ns%d" for prefixes... register them */ /* Empty URIs signify the empty namespace. These do not get a namespace prefix. when we generate the value, we will simply leave off the prefix, which is defined by mod_dav to be the /* ns_table.buf can move, so copy its value (we want the values to last as long as the provided dav_xmlns_info). */ ** Iterate over the provided namespaces. If a namespace already appears ** in our internal map of URI -> ns_id, then store that in the map. If ** we don't know the namespace yet, then add it to the map and to our ** table of known namespaces. /* copy the uri in case the passed-in namespaces changes in /* 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 */ /* generate a text blob for the xml:lang plus the contents */ /* free the previous key. note: if the loop is aborted, then the DBM will toss the key (via pool cleanup) */ /* skip past the METADATA key */ /* skip past the METADATA key */ /* don't fail if the thing isn't really there. */