-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmod_dav.h
More file actions
2759 lines (2389 loc) · 101 KB
/
mod_dav.h
File metadata and controls
2759 lines (2389 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file mod_dav.h
* @brief DAV extension module for Apache 2.0.*
*
* @defgroup MOD_DAV mod_dav
* @ingroup APACHE_MODS
* @{
*/
#ifndef _MOD_DAV_H_
#define _MOD_DAV_H_
#include "apr_hooks.h"
#include "apr_hash.h"
#include "apr_dbm.h"
#include "apr_tables.h"
#include "httpd.h"
#include "util_filter.h"
#include "util_xml.h"
#include <limits.h> /* for INT_MAX */
#include <time.h> /* for time_t */
#ifdef __cplusplus
extern "C" {
#endif
#define DAV_VERSION AP_SERVER_BASEREVISION
#define DAV_XML_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
#define DAV_XML_CONTENT_TYPE "text/xml; charset=\"utf-8\""
#define DAV_READ_BLOCKSIZE 2048 /* used for reading input blocks */
#define DAV_RESPONSE_BODY_1 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<meta name=\"color-scheme\" content=\"light dark\" />\n<title>"
#define DAV_RESPONSE_BODY_2 "</title>\n</head><body>\n<h1>"
#define DAV_RESPONSE_BODY_3 "</h1>\n<p>"
#define DAV_RESPONSE_BODY_4 "</p>\n"
#define DAV_RESPONSE_BODY_5 "</body></html>\n"
#define DAV_DO_COPY 0
#define DAV_DO_MOVE 1
#if 1
#define DAV_DEBUG 1
#define DEBUG_CR "\n"
#define DBG0(f) ap_log_error(APLOG_MARK, \
APLOG_ERR, 0, NULL, (f))
#define DBG1(f,a1) ap_log_error(APLOG_MARK, \
APLOG_ERR, 0, NULL, f, a1)
#define DBG2(f,a1,a2) ap_log_error(APLOG_MARK, \
APLOG_ERR, 0, NULL, f, a1, a2)
#define DBG3(f,a1,a2,a3) ap_log_error(APLOG_MARK, \
APLOG_ERR, 0, NULL, f, a1, a2, a3)
#else
#undef DAV_DEBUG
#define DEBUG_CR ""
#endif
#define DAV_INFINITY INT_MAX /* for the Depth: header */
/* Create a set of DAV_DECLARE(type), DAV_DECLARE_NONSTD(type) and
* DAV_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define DAV_DECLARE(type) type
#define DAV_DECLARE_NONSTD(type) type
#define DAV_DECLARE_DATA
#elif defined(DAV_DECLARE_STATIC)
#define DAV_DECLARE(type) type __stdcall
#define DAV_DECLARE_NONSTD(type) type
#define DAV_DECLARE_DATA
#elif defined(DAV_DECLARE_EXPORT)
#define DAV_DECLARE(type) __declspec(dllexport) type __stdcall
#define DAV_DECLARE_NONSTD(type) __declspec(dllexport) type
#define DAV_DECLARE_DATA __declspec(dllexport)
#else
#define DAV_DECLARE(type) __declspec(dllimport) type __stdcall
#define DAV_DECLARE_NONSTD(type) __declspec(dllimport) type
#define DAV_DECLARE_DATA __declspec(dllimport)
#endif
/* --------------------------------------------------------------------
**
** ERROR MANAGEMENT
*/
/*
** dav_error structure.
**
** In most cases, mod_dav uses a pointer to a dav_error structure. If the
** pointer is NULL, then no error has occurred.
**
** In certain cases, a dav_error structure is directly used. In these cases,
** a status value of 0 means that an error has not occurred.
**
** Note: this implies that status != 0 whenever an error occurs.
**
** The desc field is optional (it may be NULL). When NULL, it typically
** implies that Apache has a proper description for the specified status.
*/
typedef struct dav_error {
int status; /* suggested HTTP status (0 for no error) */
int error_id; /* DAV-specific error ID */
const char *desc; /* DAV:responsedescription and error log */
apr_status_t aprerr; /* APR error if any, or 0/APR_SUCCESS */
const char *namespace; /* [optional] namespace of error */
const char *tagname; /* name of error-tag */
struct dav_error *prev; /* previous error (in stack) */
const char *childtags; /* error-tag may have children */
} dav_error;
/*
** Create a new error structure. save_errno will be filled with the current
** errno value.
*/
DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status,
int error_id, apr_status_t aprerr,
const char *desc);
/*
** Create a new error structure with tagname and (optional) namespace;
** namespace may be NULL, which means "DAV:".
*/
DAV_DECLARE(dav_error*) dav_new_error_tag(apr_pool_t *p, int status,
int error_id, apr_status_t aprerr,
const char *desc,
const char *namespace,
const char *tagname);
/*
** Push a new error description onto the stack of errors.
**
** This function is used to provide an additional description to an existing
** error.
**
** <status> should contain the caller's view of what the current status is,
** given the underlying error. If it doesn't have a better idea, then the
** caller should pass prev->status.
**
** <error_id> can specify a new error_id since the topmost description has
** changed.
*/
DAV_DECLARE(dav_error*) dav_push_error(apr_pool_t *p, int status, int error_id,
const char *desc, dav_error *prev);
/*
** Join two errors together.
**
** This function is used to add a new error stack onto an existing error so
** that subsequent errors can be reported after the first error. It returns
** the correct error stack to use so that the caller can blindly call it
** without checking that both dest and src are not NULL.
**
** <dest> is the error stack that the error will be added to.
**
** <src> is the error stack that will be appended.
*/
DAV_DECLARE(dav_error*) dav_join_error(dav_error* dest, dav_error* src);
typedef struct dav_response dav_response;
/*
** dav_handle_err()
**
** Handle the standard error processing. <err> must be non-NULL.
**
** <response> is set by the following:
** - dav_validate_request()
** - dav_add_lock()
** - repos_hooks->remove_resource
** - repos_hooks->move_resource
** - repos_hooks->copy_resource
** - vsn_hooks->update
*/
DAV_DECLARE(int) dav_handle_err(request_rec *r, dav_error *err,
dav_response *response);
/* error ID values... */
/* IF: header errors */
#define DAV_ERR_IF_PARSE 100 /* general parsing error */
#define DAV_ERR_IF_MULTIPLE_NOT 101 /* multiple "Not" found */
#define DAV_ERR_IF_UNK_CHAR 102 /* unknown char in header */
#define DAV_ERR_IF_ABSENT 103 /* no locktokens given */
#define DAV_ERR_IF_TAGGED 104 /* in parsing tagged-list */
#define DAV_ERR_IF_UNCLOSED_PAREN 105 /* in no-tagged-list */
/* Prop DB errors */
#define DAV_ERR_PROP_BAD_MAJOR 200 /* major version was wrong */
#define DAV_ERR_PROP_READONLY 201 /* prop is read-only */
#define DAV_ERR_PROP_NO_DATABASE 202 /* writable db not avail */
#define DAV_ERR_PROP_NOT_FOUND 203 /* prop not found */
#define DAV_ERR_PROP_BAD_LOCKDB 204 /* could not open lockdb */
#define DAV_ERR_PROP_OPENING 205 /* problem opening propdb */
#define DAV_ERR_PROP_EXEC 206 /* problem exec'ing patch */
/* Predefined DB errors */
/* ### any to define?? */
/* Predefined locking system errors */
#define DAV_ERR_LOCK_OPENDB 400 /* could not open lockdb */
#define DAV_ERR_LOCK_NO_DB 401 /* no database defined */
#define DAV_ERR_LOCK_CORRUPT_DB 402 /* DB is corrupt */
#define DAV_ERR_LOCK_UNK_STATE_TOKEN 403 /* unknown State-token */
#define DAV_ERR_LOCK_PARSE_TOKEN 404 /* bad opaquelocktoken */
#define DAV_ERR_LOCK_SAVE_LOCK 405 /* err saving locks */
/*
** Some comments on Error ID values:
**
** The numbers do not necessarily need to be unique. Uniqueness simply means
** that two errors that have not been predefined above can be distinguished
** from each other. At the moment, mod_dav does not use this distinguishing
** feature, but it could be used in the future to collapse <response> elements
** into groups based on the error ID (and associated responsedescription).
**
** If a compute_desc is provided, then the error ID should be unique within
** the context of the compute_desc function (so the function can figure out
** what to filled into the desc).
**
** Basically, subsystems can ignore defining new error ID values if they want
** to. The subsystems *do* need to return the predefined errors when
** appropriate, so that mod_dav can figure out what to do. Subsystems can
** simply leave the error ID field unfilled (zero) if there isn't an error
** that must be placed there.
*/
/* --------------------------------------------------------------------
**
** HOOK STRUCTURES
**
** These are here for forward-declaration purposes. For more info, see
** the section title "HOOK HANDLING" for more information, plus each
** structure definition.
*/
/* forward-declare this structure */
typedef struct dav_hooks_propdb dav_hooks_propdb;
typedef struct dav_hooks_locks dav_hooks_locks;
typedef struct dav_hooks_vsn dav_hooks_vsn;
typedef struct dav_hooks_repository dav_hooks_repository;
typedef struct dav_hooks_liveprop dav_hooks_liveprop;
typedef struct dav_hooks_binding dav_hooks_binding;
typedef struct dav_hooks_search dav_hooks_search;
/* ### deprecated name */
typedef dav_hooks_propdb dav_hooks_db;
/* --------------------------------------------------------------------
**
** RESOURCE HANDLING
*/
/*
** Resource Types:
** The base protocol defines only file and collection resources.
** The versioning protocol defines several additional resource types
** to represent artifacts of a version control system.
**
** This enumeration identifies the type of URL used to identify the
** resource. Since the same resource may have more than one type of
** URL which can identify it, dav_resource_type cannot be used
** alone to determine the type of the resource; attributes of the
** dav_resource object must also be consulted.
*/
typedef enum {
DAV_RESOURCE_TYPE_UNKNOWN,
DAV_RESOURCE_TYPE_REGULAR, /* file or collection; could be
* unversioned, or version selector,
* or baseline selector */
DAV_RESOURCE_TYPE_VERSION, /* version or baseline URL */
DAV_RESOURCE_TYPE_HISTORY, /* version or baseline history URL */
DAV_RESOURCE_TYPE_WORKING, /* working resource URL */
DAV_RESOURCE_TYPE_WORKSPACE, /* workspace URL */
DAV_RESOURCE_TYPE_ACTIVITY, /* activity URL */
DAV_RESOURCE_TYPE_PRIVATE /* repository-private type */
} dav_resource_type;
/*
** Opaque, repository-specific information for a resource.
*/
typedef struct dav_resource_private dav_resource_private;
typedef struct dav_acl_provider dav_acl_provider;
/*
** Resource descriptor, generated by a repository provider.
**
** Note: the lock-null state is not explicitly represented here,
** since it may be expensive to compute. Use dav_get_resource_state()
** to determine whether a non-existent resource is a lock-null resource.
**
** A quick explanation of how the flags can apply to different resources:
**
** unversioned file or collection:
** type = DAV_RESOURCE_TYPE_REGULAR
** exists = ? (1 if exists)
** collection = ? (1 if collection)
** versioned = 0
** baselined = 0
** working = 0
**
** version-controlled resource or configuration:
** type = DAV_RESOURCE_TYPE_REGULAR
** exists = 1
** collection = ? (1 if collection)
** versioned = 1
** baselined = ? (1 if configuration)
** working = ? (1 if checked out)
**
** version/baseline history:
** type = DAV_RESOURCE_TYPE_HISTORY
** exists = 1
** collection = 0
** versioned = 0
** baselined = 0
** working = 0
**
** version/baseline:
** type = DAV_RESOURCE_TYPE_VERSION
** exists = 1
** collection = ? (1 if collection)
** versioned = 1
** baselined = ? (1 if baseline)
** working = 0
**
** working resource:
** type = DAV_RESOURCE_TYPE_WORKING
** exists = 1
** collection = ? (1 if collection)
** versioned = 1
** baselined = 0
** working = 1
**
** workspace:
** type = DAV_RESOURCE_TYPE_WORKSPACE
** exists = ? (1 if exists)
** collection = 1
** versioned = ? (1 if version-controlled)
** baselined = ? (1 if baseline-controlled)
** working = ? (1 if checked out)
**
** activity:
** type = DAV_RESOURCE_TYPE_ACTIVITY
** exists = ? (1 if exists)
** collection = 0
** versioned = 0
** baselined = 0
** working = 0
*/
typedef struct dav_resource {
dav_resource_type type;
int exists; /* 0 => null resource */
int collection; /* 0 => file; can be 1 for
* REGULAR, VERSION, and WORKING resources,
* and is always 1 for WORKSPACE */
int versioned; /* 0 => unversioned; can be 1 for
* REGULAR and WORKSPACE resources,
* and is always 1 for VERSION and WORKING */
int baselined; /* 0 => not baselined; can be 1 for
* REGULAR, VERSION, and WORKSPACE resources;
* versioned == 1 when baselined == 1 */
int working; /* 0 => not checked out; can be 1 for
* REGULAR and WORKSPACE resources,
* and is always 1 for WORKING */
const char *uri; /* the URI for this resource;
* currently has an ABI flaw where sometimes it is
* assumed to be encoded and sometimes not */
dav_resource_private *info; /* the provider's private info */
const dav_hooks_repository *hooks; /* hooks used for this resource */
/* When allocating items related specifically to this resource, the
following pool should be used. Its lifetime will be at least as
long as the dav_resource structure. */
apr_pool_t *pool;
const dav_acl_provider *acls; /* acls used for this resource */
void *ctx; /* additional parameter */
} dav_resource;
/*
** Lock token type. Lock providers define the details of a lock token.
** However, all providers are expected to at least be able to parse
** the "opaquelocktoken" scheme, which is represented by a uuid_t.
*/
typedef struct dav_locktoken dav_locktoken;
DAV_DECLARE(dav_error *) dav_get_resource(request_rec *r, int label_allowed,
int use_checked_in, dav_resource **res_p);
/*
** If DavBasePath is configured for the request location, return the
** configured path, otherwise NULL.
*/
DAV_DECLARE(const char *) dav_get_base_path(request_rec *r);
/* --------------------------------------------------------------------
**
** BUFFER HANDLING
**
** These buffers are used as a lightweight buffer reuse mechanism. Apache
** provides sub-pool creation and destruction to much the same effect, but
** the sub-pools are a bit more general and heavyweight than these buffers.
*/
/* buffer for reuse; can grow to accommodate needed size */
typedef struct
{
apr_size_t alloc_len; /* how much has been allocated */
apr_size_t cur_len; /* how much is currently being used */
char *buf; /* buffer contents */
} dav_buffer;
#define DAV_BUFFER_MINSIZE 256 /* minimum size for buffer */
#define DAV_BUFFER_PAD 64 /* amount of pad when growing */
/* set the cur_len to the given size and ensure space is available */
DAV_DECLARE(void) dav_set_bufsize(apr_pool_t *p, dav_buffer *pbuf,
apr_size_t size);
/* initialize a buffer and copy the specified (null-term'd) string into it */
DAV_DECLARE(void) dav_buffer_init(apr_pool_t *p, dav_buffer *pbuf,
const char *str);
/* check that the buffer can accommodate <extra_needed> more bytes */
DAV_DECLARE(void) dav_check_bufsize(apr_pool_t *p, dav_buffer *pbuf,
apr_size_t extra_needed);
/* append a string to the end of the buffer, adjust length */
DAV_DECLARE(void) dav_buffer_append(apr_pool_t *p, dav_buffer *pbuf,
const char *str);
/* place a string on the end of the buffer, do NOT adjust length */
DAV_DECLARE(void) dav_buffer_place(apr_pool_t *p, dav_buffer *pbuf,
const char *str);
/* place some memory on the end of a buffer; do NOT adjust length */
DAV_DECLARE(void) dav_buffer_place_mem(apr_pool_t *p, dav_buffer *pbuf,
const void *mem, apr_size_t amt,
apr_size_t pad);
/* --------------------------------------------------------------------
**
** HANDY UTILITIES
*/
/* contains results from one of the getprop functions */
typedef struct
{
apr_text * propstats; /* <propstat> element text */
apr_text * xmlns; /* namespace decls for <response> elem */
} dav_get_props_result;
/* holds the contents of a <response> element */
struct dav_response
{
const char *href; /* always */
const char *desc; /* optional description at <response> level */
/* use status if propresult.propstats is NULL. */
dav_get_props_result propresult;
int status;
struct dav_response *next;
};
typedef struct
{
request_rec *rnew; /* new subrequest */
dav_error err; /* potential error response */
} dav_lookup_result;
DAV_DECLARE(dav_lookup_result) dav_lookup_uri(const char *uri, request_rec *r,
int must_be_absolute);
/* defines type of property info a provider is to return */
typedef enum {
DAV_PROP_INSERT_NOTDEF, /* property is defined by this provider,
but nothing was inserted because the
(live) property is not defined for this
resource (it may be present as a dead
property). */
DAV_PROP_INSERT_NOTSUPP, /* property is recognized by this provider,
but it is not supported, and cannot be
treated as a dead property */
DAV_PROP_INSERT_NAME, /* a property name (empty elem) was
inserted into the text block */
DAV_PROP_INSERT_VALUE, /* a property name/value pair was inserted
into the text block */
DAV_PROP_INSERT_SUPPORTED /* a supported live property was added to
the text block as a
<DAV:supported-live-property> element */
} dav_prop_insert;
/* ### this stuff is private to dav/fs/repos.c; move it... */
/* format a time string (buf must be at least DAV_TIMEBUF_SIZE chars) */
#define DAV_STYLE_ISO8601 1
#define DAV_STYLE_RFC822 2
#define DAV_TIMEBUF_SIZE 30
/* Write a complete RESPONSE object out as a <DAV:response> xml
* element. Data is sent into brigade BB, which is auto-flushed into
* the output filter stack for request R. Use POOL for any temporary
* allocations.
*
* [Presumably the <multistatus> tag has already been written; this
* routine is shared by dav_send_multistatus and dav_stream_response.]
*/
DAV_DECLARE(void) dav_send_one_response(dav_response *response,
apr_bucket_brigade *bb,
request_rec *r,
apr_pool_t *pool);
/* Factorized helper function: prep request_rec R for a multistatus
* response and write <multistatus> tag into BB, destined for
* R->output_filters. Use xml NAMESPACES in initial tag, if
* non-NULL.
*/
DAV_DECLARE(void) dav_begin_multistatus(apr_bucket_brigade *bb,
request_rec *r, int status,
apr_array_header_t *namespaces);
/* Finish a multistatus response started by dav_begin_multistatus: */
DAV_DECLARE(apr_status_t) dav_finish_multistatus(request_rec *r,
apr_bucket_brigade *bb);
/* Send a multistatus response */
DAV_DECLARE(void) dav_send_multistatus(request_rec *r, int status,
dav_response *first,
apr_array_header_t *namespaces);
DAV_DECLARE(apr_text *) dav_failed_proppatch(apr_pool_t *p,
apr_array_header_t *prop_ctx);
DAV_DECLARE(apr_text *) dav_success_proppatch(apr_pool_t *p,
apr_array_header_t *prop_ctx);
DAV_DECLARE(int) dav_get_depth(request_rec *r, int def_depth);
DAV_DECLARE(int) dav_validate_root(const apr_xml_doc *doc,
const char *tagname);
DAV_DECLARE(int) dav_validate_root_ns(const apr_xml_doc *doc,
int ns, const char *tagname);
DAV_DECLARE(apr_xml_elem *) dav_find_child(const apr_xml_elem *elem,
const char *tagname);
DAV_DECLARE(apr_xml_elem *) dav_find_child_ns(const apr_xml_elem *elem,
int ns, const char *tagname);
DAV_DECLARE(apr_xml_elem *) dav_find_next_ns(const apr_xml_elem *elem,
int ns, const char *tagname);
/* find and return the attribute with a name in the given namespace */
DAV_DECLARE(apr_xml_attr *) dav_find_attr_ns(const apr_xml_elem *elem,
int ns, const char *attrname);
/* find and return the attribute with a given DAV: tagname */
DAV_DECLARE(apr_xml_attr *) dav_find_attr(const apr_xml_elem *elem,
const char *attrname);
/* gather up all the CDATA into a single string */
DAV_DECLARE(const char *) dav_xml_get_cdata(const apr_xml_elem *elem, apr_pool_t *pool,
int strip_white);
/*
** XML namespace handling
**
** This structure tracks namespace declarations (xmlns:prefix="URI").
** It maintains a one-to-many relationship of URIs-to-prefixes. In other
** words, one URI may be defined by many prefixes, but any specific
** prefix will specify only one URI.
**
** Prefixes using the "g###" pattern can be generated automatically if
** the caller does not have specific prefix requirements.
*/
typedef struct {
apr_pool_t *pool;
apr_hash_t *uri_prefix; /* map URIs to an available prefix */
apr_hash_t *prefix_uri; /* map all prefixes to their URIs */
int count; /* counter for "g###" prefixes */
} dav_xmlns_info;
/* create an empty dav_xmlns_info structure */
DAV_DECLARE(dav_xmlns_info *) dav_xmlns_create(apr_pool_t *pool);
/* add a specific prefix/URI pair. the prefix/uri should have a lifetime
at least that of xmlns->pool */
DAV_DECLARE(void) dav_xmlns_add(dav_xmlns_info *xi,
const char *prefix, const char *uri);
/* add a URI (if not present); any prefix is acceptable and is returned.
the uri should have a lifetime at least that xmlns->pool */
DAV_DECLARE(const char *) dav_xmlns_add_uri(dav_xmlns_info *xi,
const char *uri);
/* return the URI for a specified prefix (or NULL if the prefix is unknown) */
DAV_DECLARE(const char *) dav_xmlns_get_uri(dav_xmlns_info *xi,
const char *prefix);
/* return an available prefix for a specified URI (or NULL if the URI
is unknown) */
DAV_DECLARE(const char *) dav_xmlns_get_prefix(dav_xmlns_info *xi,
const char *uri);
/* generate xmlns declarations (appending into the given text) */
DAV_DECLARE(void) dav_xmlns_generate(dav_xmlns_info *xi,
apr_text_header *phdr);
/* --------------------------------------------------------------------
**
** DAV PLUGINS
*/
/* ### docco ... */
/*
** dav_provider
**
** This structure wraps up all of the hooks that a mod_dav provider can
** supply. The provider MUST supply <repos> and <propdb>. The rest are
** optional and should contain NULL if that feature is not supplied.
**
** Note that a provider cannot pick and choose portions from various
** underlying implementations (which was theoretically possible in
** mod_dav 1.0). There are too many dependencies between a dav_resource
** (defined by <repos>) and the other functionality.
**
** Live properties and report extensions are not part of the dav_provider
** structure because they are handled through the APR_HOOK interface (to
** allow for multiple providers). The core always provides some
** properties, and then a given provider will add more properties.
**
** Some providers may need to associate a context with the dav_provider
** structure -- the ctx field is available for storing this context. Just
** leave it NULL if it isn't required.
*/
typedef struct {
const dav_hooks_repository *repos;
const dav_hooks_propdb *propdb;
const dav_hooks_locks *locks;
const dav_hooks_vsn *vsn;
const dav_hooks_binding *binding;
const dav_hooks_search *search;
void *ctx;
} dav_provider;
/*
** gather_propsets: gather all live property propset-URIs
**
** The hook implementor should push one or more URIs into the specified
** array. These URIs are returned in the DAV: header to let clients know
** what sets of live properties are supported by the installation. mod_dav
** will place open/close angle brackets around each value (much like
** a Coded-URL); quotes and brackets should not be in the value.
**
** Example: http://apache.org/dav/props/
**
** (of course, use your own domain to ensure a unique value)
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, gather_propsets,
(apr_array_header_t *uris))
/*
** find_liveprop: find a live property, returning a non-zero, unique,
** opaque identifier.
**
** If the hook implementor determines the specified URI/name refers to
** one of its properties, then it should fill in HOOKS and return a
** non-zero value. The returned value is the "property ID" and will
** be passed to the various liveprop hook functions.
**
** Return 0 if the property is not defined by the hook implementor.
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, int, find_liveprop,
(const dav_resource *resource,
const char *ns_uri, const char *name,
const dav_hooks_liveprop **hooks))
/*
** insert_all_liveprops: insert all (known) live property names/values.
**
** The hook implementor should append XML text to PHDR, containing liveprop
** names. If INSVALUE is true, then the property values should also be
** inserted into the output XML stream.
**
** The liveprop provider should insert *all* known and *defined* live
** properties on the specified resource. If a particular liveprop is
** not defined for this resource, then it should not be inserted.
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, insert_all_liveprops,
(request_rec *r, const dav_resource *resource,
dav_prop_insert what, apr_text_header *phdr))
/*
** deliver_report: given a parsed report request, process the request
** an deliver the resulting report.
**
** The hook implementer should decide whether it should handle the given
** report, and if so, write the response to the output filter. If the
** report is not relevant, return DECLINED.
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, int, deliver_report,
(request_rec *r,
const dav_resource *resource,
const apr_xml_doc *doc,
ap_filter_t *output, dav_error **err))
/*
** gather_reports: get all reports.
**
** The hook implementor should push one or more dav_report_elem structures
** containing report names into the specified array. These names are returned
** in the DAV:supported-reports-set property to let clients know
** what reports are supported by the installation.
**
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, gather_reports,
(request_rec *r, const dav_resource *resource,
apr_array_header_t *reports, dav_error **err))
/*
** method_precondition: check method preconditions.
**
** If a WebDAV extension needs to set any preconditions on a method, this
** hook is where to do it. If the precondition fails, return an error
** response with the tagname set to the value of the failed precondition.
**
** If the method requires an XML body, this will be read and provided as
** the doc value. If not, doc is NULL. An extension that needs to verify
** the non-XML body of a request should register an input filter to do so
** within this hook.
**
** Methods like PUT will supply a single src resource, and the dst will
** be NULL.
**
** Methods like COPY or MOVE will trigger this hook twice. The first
** invocation will supply just the source resource. The second invocation
** will supply a source and destination. This allows preconditions on the
** source resource to be verified before making an attempt to get the
** destination resource.
**
** Methods like PROPFIND and LABEL will trigger this hook initially for
** the src resource, and then subsequently for each resource that has
** been walked during processing, with the walked resource passed in dst,
** and NULL passed in src.
**
** As a rule, the src resource originates from a request that has passed
** through httpd's authn/authz hooks, while the dst resource has not.
*/
APR_DECLARE_EXTERNAL_HOOK(dav, DAV, int, method_precondition,
(request_rec *r,
dav_resource *src, const dav_resource *dst,
const apr_xml_doc *doc, dav_error **err))
DAV_DECLARE(const dav_hooks_locks *) dav_get_lock_hooks(request_rec *r);
DAV_DECLARE(const dav_hooks_propdb *) dav_get_propdb_hooks(request_rec *r);
DAV_DECLARE(const dav_hooks_vsn *) dav_get_vsn_hooks(request_rec *r);
DAV_DECLARE(const dav_hooks_binding *) dav_get_binding_hooks(request_rec *r);
DAV_DECLARE(const dav_hooks_search *) dav_get_search_hooks(request_rec *r);
DAV_DECLARE(void) dav_register_provider(apr_pool_t *p, const char *name,
const dav_provider *hooks);
DAV_DECLARE(const dav_provider *) dav_lookup_provider(const char *name);
DAV_DECLARE(const char *) dav_get_provider_name(request_rec *r);
DAV_DECLARE(const dav_provider *) dav_get_provider(request_rec *r);
/* ### deprecated */
#define DAV_GET_HOOKS_PROPDB(r) dav_get_propdb_hooks(r)
#define DAV_GET_HOOKS_LOCKS(r) dav_get_lock_hooks(r)
#define DAV_GET_HOOKS_VSN(r) dav_get_vsn_hooks(r)
#define DAV_GET_HOOKS_BINDING(r) dav_get_binding_hooks(r)
#define DAV_GET_HOOKS_SEARCH(r) dav_get_search_hooks(r)
/* --------------------------------------------------------------------
**
** IF HEADER PROCESSING
**
** Here is the definition of the If: header from RFC 2518, S9.4:
**
** If = "If" ":" (1*No-tag-list | 1*Tagged-list)
** No-tag-list = List
** Tagged-list = Resource 1*List
** Resource = Coded-URL
** List = "(" 1*(["Not"](State-token | "[" entity-tag "]")) ")"
** State-token = Coded-URL
** Coded-URL = "<" absoluteURI ">" ; absoluteURI from RFC 2616
**
** List corresponds to dav_if_state_list. No-tag-list corresponds to
** dav_if_header with uri==NULL. Tagged-list corresponds to a sequence of
** dav_if_header structures with (duplicate) uri==Resource -- one
** dav_if_header per state_list. A second Tagged-list will start a new
** sequence of dav_if_header structures with the new URI.
**
** A summary of the semantics, mapped into our structures:
** - Chained dav_if_headers: OR
** - Chained dav_if_state_lists: AND
** - NULL uri matches all resources
*/
typedef enum
{
dav_if_etag,
dav_if_opaquelock,
dav_if_unknown /* the "unknown" state type; always matches false. */
} dav_if_state_type;
typedef struct dav_if_state_list
{
dav_if_state_type type;
int condition;
#define DAV_IF_COND_NORMAL 0
#define DAV_IF_COND_NOT 1 /* "Not" was applied */
const char *etag;
dav_locktoken *locktoken;
struct dav_if_state_list *next;
} dav_if_state_list;
typedef struct dav_if_header
{
const char *uri;
apr_size_t uri_len;
struct dav_if_state_list *state;
struct dav_if_header *next;
int dummy_header; /* used internally by the lock/etag validation */
} dav_if_header;
typedef struct dav_locktoken_list
{
dav_locktoken *locktoken;
struct dav_locktoken_list *next;
} dav_locktoken_list;
DAV_DECLARE(dav_error *) dav_get_locktoken_list(request_rec *r,
dav_locktoken_list **ltl);
/* --------------------------------------------------------------------
**
** LIVE PROPERTY HANDLING
*/
/* opaque type for PROPPATCH rollback information */
typedef struct dav_liveprop_rollback dav_liveprop_rollback;
struct dav_hooks_liveprop
{
/*
** Insert property information into a text block. The property to
** insert is identified by the propid value. The information to insert
** is identified by the "what" argument, as follows:
** DAV_PROP_INSERT_NAME
** property name, as an empty XML element
** DAV_PROP_INSERT_VALUE
** property name/value, as an XML element
** DAV_PROP_INSERT_SUPPORTED
** if the property is defined on the resource, then
** a DAV:supported-live-property element, as defined
** by the DeltaV extensions to RFC2518.
**
** Providers should return DAV_PROP_INSERT_NOTDEF if the property is
** known and not defined for this resource, so should be handled as a
** dead property. If a provider recognizes, but does not support, a
** property, and does not want it handled as a dead property, it should
** return DAV_PROP_INSERT_NOTSUPP.
**
** Some DAV extensions, like CalDAV, specify both document elements
** and property elements that need to be taken into account when
** generating a property. The document element and property element
** are made available in the dav_liveprop_elem structure under the
** resource, accessible as follows:
**
** dav_get_liveprop_element(resource);
**
** Returns one of DAV_PROP_INSERT_* based on what happened.
**
** ### we may need more context... ie. the lock database
*/
dav_prop_insert (*insert_prop)(const dav_resource *resource,
int propid, dav_prop_insert what,
apr_text_header *phdr);
/*
** Determine whether a given property is writable.
**
** ### we may want a different semantic. i.e. maybe it should be
** ### "can we write <value> into this property?"
**
** Returns 1 if the live property can be written, 0 if read-only.
*/
int (*is_writable)(const dav_resource *resource, int propid);
/*
** This member defines the set of namespace URIs that the provider
** uses for its properties. When insert_all is called, it will be
** passed a list of integers that map from indices into this list
** to namespace IDs for output generation.
**
** The last entry in this list should be a NULL value (sentinel).
*/
const char * const * namespace_uris;
/*
** ### this is not the final design. we want an open-ended way for
** ### liveprop providers to attach *new* properties. To this end,
** ### we'll have a "give me a list of the props you define", a way
** ### to check for a prop's existence, a way to validate a set/remove
** ### of a prop, and a way to execute/commit/rollback that change.
*/
/*
** Validate that the live property can be assigned a value, and that
** the provided value is valid.
**
** elem will point to the XML element that names the property. For
** example:
** <lp1:executable>T</lp1:executable>
**
** The provider can access the cdata fields and the child elements
** to extract the relevant pieces.
**
** operation is one of DAV_PROP_OP_SET or _DELETE.
**
** The provider may return a value in *context which will be passed
** to each of the exec/commit/rollback functions. For example, this
** may contain an internal value which has been processed from the
** input element.
**
** The provider must set defer_to_dead to true (non-zero) or false.
** If true, then the set/remove is deferred to the dead property
** database. Note: it will be set to zero on entry.
*/
dav_error * (*patch_validate)(const dav_resource *resource,
const apr_xml_elem *elem,
int operation,
void **context,
int *defer_to_dead);
/* ### doc... */
dav_error * (*patch_exec)(const dav_resource *resource,
const apr_xml_elem *elem,
int operation,
void *context,
dav_liveprop_rollback **rollback_ctx);
/* ### doc... */