** dav_fs_save_lock_record: Saves the lock information specified in the ** direct and indirect lock lists about path into the lock database. ** If direct and indirect == NULL, the key is removed. */
| 412 | ** If direct and indirect == NULL, the key is removed. |
| 413 | */ |
| 414 | static dav_error * dav_fs_save_lock_record(dav_lockdb *lockdb, apr_datum_t key, |
| 415 | dav_lock_discovery *direct, |
| 416 | dav_lock_indirect *indirect) |
| 417 | { |
| 418 | dav_error *err; |
| 419 | apr_datum_t val = { 0 }; |
| 420 | char *ptr; |
| 421 | dav_lock_discovery *dp = direct; |
| 422 | dav_lock_indirect *ip = indirect; |
| 423 | |
| 424 | #if DAV_DEBUG |
| 425 | if (lockdb->ro) { |
| 426 | return dav_new_error(lockdb->info->pool, |
| 427 | HTTP_INTERNAL_SERVER_ERROR, 0, 0, |
| 428 | "INTERNAL DESIGN ERROR: the lockdb was opened " |
| 429 | "readonly, but an attempt to save locks was " |
| 430 | "performed."); |
| 431 | } |
| 432 | #endif |
| 433 | |
| 434 | if ((err = dav_fs_really_open_lockdb(lockdb)) != NULL) { |
| 435 | /* ### add a higher-level error? */ |
| 436 | return err; |
| 437 | } |
| 438 | |
| 439 | /* If nothing to save, delete key */ |
| 440 | if (dp == NULL && ip == NULL) { |
| 441 | /* don't fail if the key is not present */ |
| 442 | /* ### but what about other errors? */ |
| 443 | (void) dav_dbm_delete(lockdb->info->db, key); |
| 444 | return NULL; |
| 445 | } |
| 446 | |
| 447 | while(dp) { |
| 448 | val.dsize += dav_size_direct(dp); |
| 449 | dp = dp->next; |
| 450 | } |
| 451 | while(ip) { |
| 452 | val.dsize += dav_size_indirect(ip); |
| 453 | ip = ip->next; |
| 454 | } |
| 455 | |
| 456 | /* ### can this be apr_palloc() ? */ |
| 457 | /* ### hmmm.... investigate the use of a buffer here */ |
| 458 | ptr = val.dptr = apr_pcalloc(lockdb->info->pool, val.dsize); |
| 459 | dp = direct; |
| 460 | ip = indirect; |
| 461 | |
| 462 | while(dp) { |
| 463 | *ptr++ = DAV_LOCK_DIRECT; /* Direct lock - lock_discovery struct follows */ |
| 464 | memcpy(ptr, dp, sizeof(dp->f)); /* Fixed portion of struct */ |
| 465 | ptr += sizeof(dp->f); |
| 466 | memcpy(ptr, dp->locktoken, sizeof(*dp->locktoken)); |
| 467 | ptr += sizeof(*dp->locktoken); |
| 468 | if (dp->owner == NULL) { |
| 469 | *ptr++ = '\0'; |
| 470 | } |
| 471 | else { |
no test coverage detected