1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "httpd.h" 18#include "http_config.h" 19#include "apr_strings.h" 20#include "ap_provider.h" 21 22#include "mod_dav.h" 23#include "locks.h" 24 25/* per-dir configuration */ 26typedef struct { 27 const char *lockdb_path; 28} dav_lock_dir_conf; 29 30extern const dav_hooks_locks dav_hooks_locks_generic; 31 32extern module AP_MODULE_DECLARE_DATA dav_lock_module; 33 34const char *dav_generic_get_lockdb_path(const request_rec *r) 35{ 36 dav_lock_dir_conf *conf; 37 38 conf = ap_get_module_config(r->per_dir_config, &dav_lock_module); 39 return conf->lockdb_path; 40} 41 42static void *dav_lock_create_dir_config(apr_pool_t *p, char *dir) 43{ 44 return apr_pcalloc(p, sizeof(dav_lock_dir_conf)); 45} 46 47static void *dav_lock_merge_dir_config(apr_pool_t *p, 48 void *base, void *overrides) 49{ 50 dav_lock_dir_conf *parent = base; 51 dav_lock_dir_conf *child = overrides; 52 dav_lock_dir_conf *newconf; 53 54 newconf = apr_pcalloc(p, sizeof(*newconf)); 55 56 newconf->lockdb_path = 57 child->lockdb_path ? child->lockdb_path : parent->lockdb_path; 58 59 return newconf; 60} 61 62/* 63 * Command handler for the DAVGenericLockDB directive, which is TAKE1 64 */ 65static const char *dav_lock_cmd_davlockdb(cmd_parms *cmd, void *config, 66 const char *arg1) 67{ 68 dav_lock_dir_conf *conf = config; 69 70 conf->lockdb_path = ap_server_root_relative(cmd->pool, arg1); 71 72 if (!conf->lockdb_path) { 73 return apr_pstrcat(cmd->pool, "Invalid DAVGenericLockDB path ", 74 arg1, NULL); 75 } 76 77 return NULL; 78} 79 80static const command_rec dav_lock_cmds[] = 81{ 82 /* per server */ 83 AP_INIT_TAKE1("DAVGenericLockDB", dav_lock_cmd_davlockdb, NULL, ACCESS_CONF, 84 "specify a lock database"), 85 86 { NULL } 87}; 88 89static void register_hooks(apr_pool_t *p) 90{ 91 ap_register_provider(p, "dav-lock", "generic", "0", 92 &dav_hooks_locks_generic); 93} 94 95module AP_MODULE_DECLARE_DATA dav_lock_module = 96{ 97 STANDARD20_MODULE_STUFF, 98 dav_lock_create_dir_config, /* dir config creater */ 99 dav_lock_merge_dir_config, /* dir merger --- default is to override */ 100 NULL, /* server config */ 101 NULL, /* merge server config */ 102 dav_lock_cmds, /* command table */ 103 register_hooks, /* register hooks */ 104}; 105