** dav_lock_parse_lockinfo: Validates the given xml_doc to contain a ** lockinfo XML element, then populates a dav_lock structure ** with its contents. */
| 168 | ** with its contents. |
| 169 | */ |
| 170 | DAV_DECLARE(dav_error *) dav_lock_parse_lockinfo(request_rec *r, |
| 171 | const dav_resource *resource, |
| 172 | dav_lockdb *lockdb, |
| 173 | const apr_xml_doc *doc, |
| 174 | dav_lock **lock_request) |
| 175 | { |
| 176 | apr_pool_t *p = r->pool; |
| 177 | dav_error *err; |
| 178 | apr_xml_elem *child; |
| 179 | dav_lock *lock; |
| 180 | |
| 181 | if (!dav_validate_root(doc, "lockinfo")) { |
| 182 | return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, |
| 183 | "The request body contains an unexpected " |
| 184 | "XML root element."); |
| 185 | } |
| 186 | |
| 187 | if ((err = (*lockdb->hooks->create_lock)(lockdb, resource, |
| 188 | &lock)) != NULL) { |
| 189 | return dav_push_error(p, err->status, 0, |
| 190 | "Could not parse the lockinfo due to an " |
| 191 | "internal problem creating a lock structure.", |
| 192 | err); |
| 193 | } |
| 194 | |
| 195 | lock->depth = dav_get_depth(r, DAV_INFINITY); |
| 196 | if (lock->depth == -1) { |
| 197 | return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, |
| 198 | "An invalid Depth header was specified."); |
| 199 | } |
| 200 | lock->timeout = dav_get_timeout(r); |
| 201 | |
| 202 | /* Parse elements in the XML body */ |
| 203 | for (child = doc->root->first_child; child; child = child->next) { |
| 204 | if (strcmp(child->name, "locktype") == 0 |
| 205 | && child->first_child |
| 206 | && lock->type == DAV_LOCKTYPE_UNKNOWN) { |
| 207 | if (strcmp(child->first_child->name, "write") == 0) { |
| 208 | lock->type = DAV_LOCKTYPE_WRITE; |
| 209 | continue; |
| 210 | } |
| 211 | } |
| 212 | if (strcmp(child->name, "lockscope") == 0 |
| 213 | && child->first_child |
| 214 | && lock->scope == DAV_LOCKSCOPE_UNKNOWN) { |
| 215 | if (strcmp(child->first_child->name, "exclusive") == 0) |
| 216 | lock->scope = DAV_LOCKSCOPE_EXCLUSIVE; |
| 217 | else if (strcmp(child->first_child->name, "shared") == 0) |
| 218 | lock->scope = DAV_LOCKSCOPE_SHARED; |
| 219 | if (lock->scope != DAV_LOCKSCOPE_UNKNOWN) |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | if (strcmp(child->name, "owner") == 0 && lock->owner == NULL) { |
| 224 | const char *text; |
| 225 | |
| 226 | /* quote all the values in the <DAV:owner> element */ |
| 227 | apr_xml_quote_elem(p, child); |
no test coverage detected