upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / dav / main / std_liveprop.c
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 "util_xml.h"
19 #include "apr_strings.h"
20
21 #include "mod_dav.h"
22
23 /* forward-declare */
24 static const dav_hooks_liveprop dav_core_hooks_liveprop;
25
26 /*
27 ** The namespace URIs that we use. There will only ever be "DAV:".
28 */
29 static const char * const dav_core_namespace_uris[] =
30 {
31     "DAV:",
32     NULL        /* sentinel */
33 };
34
35 /*
36 ** Define each of the core properties that this provider will handle.
37 ** Note that all of them are in the DAV: namespace, which has a
38 ** provider-local index of 0.
39 */
40 static const dav_liveprop_spec dav_core_props[] =
41 {
42     { 0, "comment",              DAV_PROPID_comment,              1 },
43     { 0, "creator-displayname",  DAV_PROPID_creator_displayname,  1 },
44     { 0, "displayname",          DAV_PROPID_displayname,          1 },
45     { 0, "resourcetype",         DAV_PROPID_resourcetype,         0 },
46     { 0, "source",               DAV_PROPID_source,               1 },
47
48     { 0 }        /* sentinel */
49 };
50
51 static const dav_liveprop_group dav_core_liveprop_group =
52 {
53     dav_core_props,
54     dav_core_namespace_uris,
55     &dav_core_hooks_liveprop
56 };
57
58 static dav_prop_insert dav_core_insert_prop(const dav_resource *resource,
59                                             int propid, dav_prop_insert what,
60                                             apr_text_header *phdr)
61 {
62     const char *value;
63     const char *s;
64     apr_pool_t *p = resource->pool;
65     const dav_liveprop_spec *info;
66     int global_ns;
67
68     switch (propid)
69     {
70     case DAV_PROPID_resourcetype:
71         switch (resource->type) {
72         case DAV_RESOURCE_TYPE_VERSION:
73             if (resource->baselined) {
74                 value = "<D:baseline/>";
75                 break;
76             }
77             /* fall through */
78         case DAV_RESOURCE_TYPE_REGULAR:
79         case DAV_RESOURCE_TYPE_WORKING:
80             if (resource->collection) {
81                 value = "<D:collection/>";
82             }
83             else {
84                 /* ### should we denote lock-null resources? */
85
86                 value = "";        /* becomes: <D:resourcetype/> */
87             }
88             break;
89         case DAV_RESOURCE_TYPE_HISTORY:
90             value = "<D:version-history/>";
91             break;
92         case DAV_RESOURCE_TYPE_WORKSPACE:
93             value = "<D:collection/>";
94             break;
95         case DAV_RESOURCE_TYPE_ACTIVITY:
96             value = "<D:activity/>";
97             break;
98
99         default:
100             /* ### bad juju */
101             return DAV_PROP_INSERT_NOTDEF;
102         }
103         break;
104
105     case DAV_PROPID_comment:
106     case DAV_PROPID_creator_displayname:
107     case DAV_PROPID_displayname:
108     case DAV_PROPID_source:
109     default:
110         /*
111         ** This property is known, but not defined as a liveprop. However,
112         ** it may be a dead property.
113         */
114         return DAV_PROP_INSERT_NOTDEF;
115     }
116
117     /* assert: value != NULL */
118
119     /* get the information and global NS index for the property */
120     global_ns = dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
121
122     /* assert: info != NULL && info->name != NULL */
123
124     if (what == DAV_PROP_INSERT_SUPPORTED) {
125         s = apr_psprintf(p,
126                          "<D:supported-live-property D:name=\"%s\" "
127                          "D:namespace=\"%s\"/>" DEBUG_CR,
128                          info->name, dav_core_namespace_uris[info->ns]);
129     }
130     else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
131         s = apr_psprintf(p, "<lp%d:%s>%s</lp%d:%s>" DEBUG_CR,
132                          global_ns, info->name, value, global_ns, info->name);
133     }
134     else {
135         s = apr_psprintf(p, "<lp%d:%s/>" DEBUG_CR, global_ns, info->name);
136     }
137     apr_text_append(p, phdr, s);
138
139     /* we inserted what was asked for */
140     return what;
141 }
142
143 static int dav_core_is_writable(const dav_resource *resource, int propid)
144 {
145     const dav_liveprop_spec *info;
146
147     (void) dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
148     return info->is_writable;
149 }
150
151 static dav_error * dav_core_patch_validate(const dav_resource *resource,
152                                            const apr_xml_elem *elem,
153                                            int operation, void **context,
154                                            int *defer_to_dead)
155 {
156     /* all of our writable props go in the dead prop database */
157     *defer_to_dead = 1;
158
159     return NULL;
160 }
161
162 static const dav_hooks_liveprop dav_core_hooks_liveprop = {
163     dav_core_insert_prop,
164     dav_core_is_writable,
165     dav_core_namespace_uris,
166     dav_core_patch_validate,
167     NULL,       /* patch_exec */
168     NULL,       /* patch_commit */
169     NULL,       /* patch_rollback */
170 };
171
172 DAV_DECLARE_NONSTD(int) dav_core_find_liveprop(
173     const dav_resource *resource,
174     const char *ns_uri, const char *name,
175     const dav_hooks_liveprop **hooks)
176 {
177     return dav_do_find_liveprop(ns_uri, name, &dav_core_liveprop_group, hooks);
178 }
179
180 DAV_DECLARE_NONSTD(void) dav_core_insert_all_liveprops(
181     request_rec *r,
182     const dav_resource *resource,
183     dav_prop_insert what,
184     apr_text_header *phdr)
185 {
186     (void) dav_core_insert_prop(resource, DAV_PROPID_resourcetype,
187                                 what, phdr);
188 }
189
190 DAV_DECLARE_NONSTD(void) dav_core_register_uris(apr_pool_t *p)
191 {
192     /* register the namespace URIs */
193     dav_register_liveprop_group(p, &dav_core_liveprop_group);
194 }