mod_dav.h 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  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. * @file mod_dav.h
  18. * @brief DAV extension module for Apache 2.0.*
  19. *
  20. * @defgroup MOD_DAV mod_dav
  21. * @ingroup APACHE_MODS
  22. * @{
  23. */
  24. #ifndef _MOD_DAV_H_
  25. #define _MOD_DAV_H_
  26. #include "apr_hooks.h"
  27. #include "apr_hash.h"
  28. #include "apr_dbm.h"
  29. #include "apr_tables.h"
  30. #include "httpd.h"
  31. #include "util_filter.h"
  32. #include "util_xml.h"
  33. #include <limits.h> /* for INT_MAX */
  34. #include <time.h> /* for time_t */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #define DAV_VERSION AP_SERVER_BASEREVISION
  39. #define DAV_XML_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  40. #define DAV_XML_CONTENT_TYPE "text/xml; charset=\"utf-8\""
  41. #define DAV_READ_BLOCKSIZE 2048 /* used for reading input blocks */
  42. #define DAV_RESPONSE_BODY_1 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>"
  43. #define DAV_RESPONSE_BODY_2 "</title>\n</head><body>\n<h1>"
  44. #define DAV_RESPONSE_BODY_3 "</h1>\n<p>"
  45. #define DAV_RESPONSE_BODY_4 "</p>\n"
  46. #define DAV_RESPONSE_BODY_5 "</body></html>\n"
  47. #define DAV_DO_COPY 0
  48. #define DAV_DO_MOVE 1
  49. #if 1
  50. #define DAV_DEBUG 1
  51. #define DEBUG_CR "\n"
  52. #define DBG0(f) ap_log_error(APLOG_MARK, \
  53. APLOG_ERR, 0, NULL, (f))
  54. #define DBG1(f,a1) ap_log_error(APLOG_MARK, \
  55. APLOG_ERR, 0, NULL, f, a1)
  56. #define DBG2(f,a1,a2) ap_log_error(APLOG_MARK, \
  57. APLOG_ERR, 0, NULL, f, a1, a2)
  58. #define DBG3(f,a1,a2,a3) ap_log_error(APLOG_MARK, \
  59. APLOG_ERR, 0, NULL, f, a1, a2, a3)
  60. #else
  61. #undef DAV_DEBUG
  62. #define DEBUG_CR ""
  63. #endif
  64. #define DAV_INFINITY INT_MAX /* for the Depth: header */
  65. /* Create a set of DAV_DECLARE(type), DAV_DECLARE_NONSTD(type) and
  66. * DAV_DECLARE_DATA with appropriate export and import tags for the platform
  67. */
  68. #if !defined(WIN32)
  69. #define DAV_DECLARE(type) type
  70. #define DAV_DECLARE_NONSTD(type) type
  71. #define DAV_DECLARE_DATA
  72. #elif defined(DAV_DECLARE_STATIC)
  73. #define DAV_DECLARE(type) type __stdcall
  74. #define DAV_DECLARE_NONSTD(type) type
  75. #define DAV_DECLARE_DATA
  76. #elif defined(DAV_DECLARE_EXPORT)
  77. #define DAV_DECLARE(type) __declspec(dllexport) type __stdcall
  78. #define DAV_DECLARE_NONSTD(type) __declspec(dllexport) type
  79. #define DAV_DECLARE_DATA __declspec(dllexport)
  80. #else
  81. #define DAV_DECLARE(type) __declspec(dllimport) type __stdcall
  82. #define DAV_DECLARE_NONSTD(type) __declspec(dllimport) type
  83. #define DAV_DECLARE_DATA __declspec(dllimport)
  84. #endif
  85. /* --------------------------------------------------------------------
  86. **
  87. ** ERROR MANAGEMENT
  88. */
  89. /*
  90. ** dav_error structure.
  91. **
  92. ** In most cases, mod_dav uses a pointer to a dav_error structure. If the
  93. ** pointer is NULL, then no error has occurred.
  94. **
  95. ** In certain cases, a dav_error structure is directly used. In these cases,
  96. ** a status value of 0 means that an error has not occurred.
  97. **
  98. ** Note: this implies that status != 0 whenever an error occurs.
  99. **
  100. ** The desc field is optional (it may be NULL). When NULL, it typically
  101. ** implies that Apache has a proper description for the specified status.
  102. */
  103. typedef struct dav_error {
  104. int status; /* suggested HTTP status (0 for no error) */
  105. int error_id; /* DAV-specific error ID */
  106. const char *desc; /* DAV:responsedescription and error log */
  107. apr_status_t aprerr; /* APR error if any, or 0/APR_SUCCESS */
  108. const char *namespace; /* [optional] namespace of error */
  109. const char *tagname; /* name of error-tag */
  110. struct dav_error *prev; /* previous error (in stack) */
  111. const char *childtags; /* error-tag may have children */
  112. } dav_error;
  113. /*
  114. ** Create a new error structure. save_errno will be filled with the current
  115. ** errno value.
  116. */
  117. DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status,
  118. int error_id, apr_status_t aprerr,
  119. const char *desc);
  120. /*
  121. ** Create a new error structure with tagname and (optional) namespace;
  122. ** namespace may be NULL, which means "DAV:".
  123. */
  124. DAV_DECLARE(dav_error*) dav_new_error_tag(apr_pool_t *p, int status,
  125. int error_id, apr_status_t aprerr,
  126. const char *desc,
  127. const char *namespace,
  128. const char *tagname);
  129. /*
  130. ** Push a new error description onto the stack of errors.
  131. **
  132. ** This function is used to provide an additional description to an existing
  133. ** error.
  134. **
  135. ** <status> should contain the caller's view of what the current status is,
  136. ** given the underlying error. If it doesn't have a better idea, then the
  137. ** caller should pass prev->status.
  138. **
  139. ** <error_id> can specify a new error_id since the topmost description has
  140. ** changed.
  141. */
  142. DAV_DECLARE(dav_error*) dav_push_error(apr_pool_t *p, int status, int error_id,
  143. const char *desc, dav_error *prev);
  144. /*
  145. ** Join two errors together.
  146. **
  147. ** This function is used to add a new error stack onto an existing error so
  148. ** that subsequent errors can be reported after the first error. It returns
  149. ** the correct error stack to use so that the caller can blindly call it
  150. ** without checking that both dest and src are not NULL.
  151. **
  152. ** <dest> is the error stack that the error will be added to.
  153. **
  154. ** <src> is the error stack that will be appended.
  155. */
  156. DAV_DECLARE(dav_error*) dav_join_error(dav_error* dest, dav_error* src);
  157. typedef struct dav_response dav_response;
  158. /*
  159. ** dav_handle_err()
  160. **
  161. ** Handle the standard error processing. <err> must be non-NULL.
  162. **
  163. ** <response> is set by the following:
  164. ** - dav_validate_request()
  165. ** - dav_add_lock()
  166. ** - repos_hooks->remove_resource
  167. ** - repos_hooks->move_resource
  168. ** - repos_hooks->copy_resource
  169. ** - vsn_hooks->update
  170. */
  171. DAV_DECLARE(int) dav_handle_err(request_rec *r, dav_error *err,
  172. dav_response *response);
  173. /* error ID values... */
  174. /* IF: header errors */
  175. #define DAV_ERR_IF_PARSE 100 /* general parsing error */
  176. #define DAV_ERR_IF_MULTIPLE_NOT 101 /* multiple "Not" found */
  177. #define DAV_ERR_IF_UNK_CHAR 102 /* unknown char in header */
  178. #define DAV_ERR_IF_ABSENT 103 /* no locktokens given */
  179. #define DAV_ERR_IF_TAGGED 104 /* in parsing tagged-list */
  180. #define DAV_ERR_IF_UNCLOSED_PAREN 105 /* in no-tagged-list */
  181. /* Prop DB errors */
  182. #define DAV_ERR_PROP_BAD_MAJOR 200 /* major version was wrong */
  183. #define DAV_ERR_PROP_READONLY 201 /* prop is read-only */
  184. #define DAV_ERR_PROP_NO_DATABASE 202 /* writable db not avail */
  185. #define DAV_ERR_PROP_NOT_FOUND 203 /* prop not found */
  186. #define DAV_ERR_PROP_BAD_LOCKDB 204 /* could not open lockdb */
  187. #define DAV_ERR_PROP_OPENING 205 /* problem opening propdb */
  188. #define DAV_ERR_PROP_EXEC 206 /* problem exec'ing patch */
  189. /* Predefined DB errors */
  190. /* ### any to define?? */
  191. /* Predefined locking system errors */
  192. #define DAV_ERR_LOCK_OPENDB 400 /* could not open lockdb */
  193. #define DAV_ERR_LOCK_NO_DB 401 /* no database defined */
  194. #define DAV_ERR_LOCK_CORRUPT_DB 402 /* DB is corrupt */
  195. #define DAV_ERR_LOCK_UNK_STATE_TOKEN 403 /* unknown State-token */
  196. #define DAV_ERR_LOCK_PARSE_TOKEN 404 /* bad opaquelocktoken */
  197. #define DAV_ERR_LOCK_SAVE_LOCK 405 /* err saving locks */
  198. /*
  199. ** Some comments on Error ID values:
  200. **
  201. ** The numbers do not necessarily need to be unique. Uniqueness simply means
  202. ** that two errors that have not been predefined above can be distinguished
  203. ** from each other. At the moment, mod_dav does not use this distinguishing
  204. ** feature, but it could be used in the future to collapse <response> elements
  205. ** into groups based on the error ID (and associated responsedescription).
  206. **
  207. ** If a compute_desc is provided, then the error ID should be unique within
  208. ** the context of the compute_desc function (so the function can figure out
  209. ** what to filled into the desc).
  210. **
  211. ** Basically, subsystems can ignore defining new error ID values if they want
  212. ** to. The subsystems *do* need to return the predefined errors when
  213. ** appropriate, so that mod_dav can figure out what to do. Subsystems can
  214. ** simply leave the error ID field unfilled (zero) if there isn't an error
  215. ** that must be placed there.
  216. */
  217. /* --------------------------------------------------------------------
  218. **
  219. ** HOOK STRUCTURES
  220. **
  221. ** These are here for forward-declaration purposes. For more info, see
  222. ** the section title "HOOK HANDLING" for more information, plus each
  223. ** structure definition.
  224. */
  225. /* forward-declare this structure */
  226. typedef struct dav_hooks_propdb dav_hooks_propdb;
  227. typedef struct dav_hooks_locks dav_hooks_locks;
  228. typedef struct dav_hooks_vsn dav_hooks_vsn;
  229. typedef struct dav_hooks_repository dav_hooks_repository;
  230. typedef struct dav_hooks_liveprop dav_hooks_liveprop;
  231. typedef struct dav_hooks_binding dav_hooks_binding;
  232. typedef struct dav_hooks_search dav_hooks_search;
  233. /* ### deprecated name */
  234. typedef dav_hooks_propdb dav_hooks_db;
  235. /* --------------------------------------------------------------------
  236. **
  237. ** RESOURCE HANDLING
  238. */
  239. /*
  240. ** Resource Types:
  241. ** The base protocol defines only file and collection resources.
  242. ** The versioning protocol defines several additional resource types
  243. ** to represent artifacts of a version control system.
  244. **
  245. ** This enumeration identifies the type of URL used to identify the
  246. ** resource. Since the same resource may have more than one type of
  247. ** URL which can identify it, dav_resource_type cannot be used
  248. ** alone to determine the type of the resource; attributes of the
  249. ** dav_resource object must also be consulted.
  250. */
  251. typedef enum {
  252. DAV_RESOURCE_TYPE_UNKNOWN,
  253. DAV_RESOURCE_TYPE_REGULAR, /* file or collection; could be
  254. * unversioned, or version selector,
  255. * or baseline selector */
  256. DAV_RESOURCE_TYPE_VERSION, /* version or baseline URL */
  257. DAV_RESOURCE_TYPE_HISTORY, /* version or baseline history URL */
  258. DAV_RESOURCE_TYPE_WORKING, /* working resource URL */
  259. DAV_RESOURCE_TYPE_WORKSPACE, /* workspace URL */
  260. DAV_RESOURCE_TYPE_ACTIVITY, /* activity URL */
  261. DAV_RESOURCE_TYPE_PRIVATE /* repository-private type */
  262. } dav_resource_type;
  263. /*
  264. ** Opaque, repository-specific information for a resource.
  265. */
  266. typedef struct dav_resource_private dav_resource_private;
  267. /*
  268. ** Resource descriptor, generated by a repository provider.
  269. **
  270. ** Note: the lock-null state is not explicitly represented here,
  271. ** since it may be expensive to compute. Use dav_get_resource_state()
  272. ** to determine whether a non-existent resource is a lock-null resource.
  273. **
  274. ** A quick explanation of how the flags can apply to different resources:
  275. **
  276. ** unversioned file or collection:
  277. ** type = DAV_RESOURCE_TYPE_REGULAR
  278. ** exists = ? (1 if exists)
  279. ** collection = ? (1 if collection)
  280. ** versioned = 0
  281. ** baselined = 0
  282. ** working = 0
  283. **
  284. ** version-controlled resource or configuration:
  285. ** type = DAV_RESOURCE_TYPE_REGULAR
  286. ** exists = 1
  287. ** collection = ? (1 if collection)
  288. ** versioned = 1
  289. ** baselined = ? (1 if configuration)
  290. ** working = ? (1 if checked out)
  291. **
  292. ** version/baseline history:
  293. ** type = DAV_RESOURCE_TYPE_HISTORY
  294. ** exists = 1
  295. ** collection = 0
  296. ** versioned = 0
  297. ** baselined = 0
  298. ** working = 0
  299. **
  300. ** version/baseline:
  301. ** type = DAV_RESOURCE_TYPE_VERSION
  302. ** exists = 1
  303. ** collection = ? (1 if collection)
  304. ** versioned = 1
  305. ** baselined = ? (1 if baseline)
  306. ** working = 0
  307. **
  308. ** working resource:
  309. ** type = DAV_RESOURCE_TYPE_WORKING
  310. ** exists = 1
  311. ** collection = ? (1 if collection)
  312. ** versioned = 1
  313. ** baselined = 0
  314. ** working = 1
  315. **
  316. ** workspace:
  317. ** type = DAV_RESOURCE_TYPE_WORKSPACE
  318. ** exists = ? (1 if exists)
  319. ** collection = 1
  320. ** versioned = ? (1 if version-controlled)
  321. ** baselined = ? (1 if baseline-controlled)
  322. ** working = ? (1 if checked out)
  323. **
  324. ** activity:
  325. ** type = DAV_RESOURCE_TYPE_ACTIVITY
  326. ** exists = ? (1 if exists)
  327. ** collection = 0
  328. ** versioned = 0
  329. ** baselined = 0
  330. ** working = 0
  331. */
  332. typedef struct dav_resource {
  333. dav_resource_type type;
  334. int exists; /* 0 => null resource */
  335. int collection; /* 0 => file; can be 1 for
  336. * REGULAR, VERSION, and WORKING resources,
  337. * and is always 1 for WORKSPACE */
  338. int versioned; /* 0 => unversioned; can be 1 for
  339. * REGULAR and WORKSPACE resources,
  340. * and is always 1 for VERSION and WORKING */
  341. int baselined; /* 0 => not baselined; can be 1 for
  342. * REGULAR, VERSION, and WORKSPACE resources;
  343. * versioned == 1 when baselined == 1 */
  344. int working; /* 0 => not checked out; can be 1 for
  345. * REGULAR and WORKSPACE resources,
  346. * and is always 1 for WORKING */
  347. const char *uri; /* the URI for this resource;
  348. * currently has an ABI flaw where sometimes it is
  349. * assumed to be encoded and sometimes not */
  350. dav_resource_private *info; /* the provider's private info */
  351. const dav_hooks_repository *hooks; /* hooks used for this resource */
  352. /* When allocating items related specifically to this resource, the
  353. following pool should be used. Its lifetime will be at least as
  354. long as the dav_resource structure. */
  355. apr_pool_t *pool;
  356. } dav_resource;
  357. /*
  358. ** Lock token type. Lock providers define the details of a lock token.
  359. ** However, all providers are expected to at least be able to parse
  360. ** the "opaquelocktoken" scheme, which is represented by a uuid_t.
  361. */
  362. typedef struct dav_locktoken dav_locktoken;
  363. /* --------------------------------------------------------------------
  364. **
  365. ** BUFFER HANDLING
  366. **
  367. ** These buffers are used as a lightweight buffer reuse mechanism. Apache
  368. ** provides sub-pool creation and destruction to much the same effect, but
  369. ** the sub-pools are a bit more general and heavyweight than these buffers.
  370. */
  371. /* buffer for reuse; can grow to accommodate needed size */
  372. typedef struct
  373. {
  374. apr_size_t alloc_len; /* how much has been allocated */
  375. apr_size_t cur_len; /* how much is currently being used */
  376. char *buf; /* buffer contents */
  377. } dav_buffer;
  378. #define DAV_BUFFER_MINSIZE 256 /* minimum size for buffer */
  379. #define DAV_BUFFER_PAD 64 /* amount of pad when growing */
  380. /* set the cur_len to the given size and ensure space is available */
  381. DAV_DECLARE(void) dav_set_bufsize(apr_pool_t *p, dav_buffer *pbuf,
  382. apr_size_t size);
  383. /* initialize a buffer and copy the specified (null-term'd) string into it */
  384. DAV_DECLARE(void) dav_buffer_init(apr_pool_t *p, dav_buffer *pbuf,
  385. const char *str);
  386. /* check that the buffer can accommodate <extra_needed> more bytes */
  387. DAV_DECLARE(void) dav_check_bufsize(apr_pool_t *p, dav_buffer *pbuf,
  388. apr_size_t extra_needed);
  389. /* append a string to the end of the buffer, adjust length */
  390. DAV_DECLARE(void) dav_buffer_append(apr_pool_t *p, dav_buffer *pbuf,
  391. const char *str);
  392. /* place a string on the end of the buffer, do NOT adjust length */
  393. DAV_DECLARE(void) dav_buffer_place(apr_pool_t *p, dav_buffer *pbuf,
  394. const char *str);
  395. /* place some memory on the end of a buffer; do NOT adjust length */
  396. DAV_DECLARE(void) dav_buffer_place_mem(apr_pool_t *p, dav_buffer *pbuf,
  397. const void *mem, apr_size_t amt,
  398. apr_size_t pad);
  399. /* --------------------------------------------------------------------
  400. **
  401. ** HANDY UTILITIES
  402. */
  403. /* contains results from one of the getprop functions */
  404. typedef struct
  405. {
  406. apr_text * propstats; /* <propstat> element text */
  407. apr_text * xmlns; /* namespace decls for <response> elem */
  408. } dav_get_props_result;
  409. /* holds the contents of a <response> element */
  410. struct dav_response
  411. {
  412. const char *href; /* always */
  413. const char *desc; /* optional description at <response> level */
  414. /* use status if propresult.propstats is NULL. */
  415. dav_get_props_result propresult;
  416. int status;
  417. struct dav_response *next;
  418. };
  419. typedef struct
  420. {
  421. request_rec *rnew; /* new subrequest */
  422. dav_error err; /* potential error response */
  423. } dav_lookup_result;
  424. DAV_DECLARE(dav_lookup_result) dav_lookup_uri(const char *uri, request_rec *r,
  425. int must_be_absolute);
  426. /* defines type of property info a provider is to return */
  427. typedef enum {
  428. DAV_PROP_INSERT_NOTDEF, /* property is defined by this provider,
  429. but nothing was inserted because the
  430. (live) property is not defined for this
  431. resource (it may be present as a dead
  432. property). */
  433. DAV_PROP_INSERT_NOTSUPP, /* property is recognized by this provider,
  434. but it is not supported, and cannot be
  435. treated as a dead property */
  436. DAV_PROP_INSERT_NAME, /* a property name (empty elem) was
  437. inserted into the text block */
  438. DAV_PROP_INSERT_VALUE, /* a property name/value pair was inserted
  439. into the text block */
  440. DAV_PROP_INSERT_SUPPORTED /* a supported live property was added to
  441. the text block as a
  442. <DAV:supported-live-property> element */
  443. } dav_prop_insert;
  444. /* ### this stuff is private to dav/fs/repos.c; move it... */
  445. /* format a time string (buf must be at least DAV_TIMEBUF_SIZE chars) */
  446. #define DAV_STYLE_ISO8601 1
  447. #define DAV_STYLE_RFC822 2
  448. #define DAV_TIMEBUF_SIZE 30
  449. /* Write a complete RESPONSE object out as a <DAV:response> xml
  450. * element. Data is sent into brigade BB, which is auto-flushed into
  451. * the output filter stack for request R. Use POOL for any temporary
  452. * allocations.
  453. *
  454. * [Presumably the <multistatus> tag has already been written; this
  455. * routine is shared by dav_send_multistatus and dav_stream_response.]
  456. */
  457. DAV_DECLARE(void) dav_send_one_response(dav_response *response,
  458. apr_bucket_brigade *bb,
  459. request_rec *r,
  460. apr_pool_t *pool);
  461. /* Factorized helper function: prep request_rec R for a multistatus
  462. * response and write <multistatus> tag into BB, destined for
  463. * R->output_filters. Use xml NAMESPACES in initial tag, if
  464. * non-NULL.
  465. */
  466. DAV_DECLARE(void) dav_begin_multistatus(apr_bucket_brigade *bb,
  467. request_rec *r, int status,
  468. apr_array_header_t *namespaces);
  469. /* Finish a multistatus response started by dav_begin_multistatus: */
  470. DAV_DECLARE(apr_status_t) dav_finish_multistatus(request_rec *r,
  471. apr_bucket_brigade *bb);
  472. /* Send a multistatus response */
  473. DAV_DECLARE(void) dav_send_multistatus(request_rec *r, int status,
  474. dav_response *first,
  475. apr_array_header_t *namespaces);
  476. DAV_DECLARE(apr_text *) dav_failed_proppatch(apr_pool_t *p,
  477. apr_array_header_t *prop_ctx);
  478. DAV_DECLARE(apr_text *) dav_success_proppatch(apr_pool_t *p,
  479. apr_array_header_t *prop_ctx);
  480. DAV_DECLARE(int) dav_get_depth(request_rec *r, int def_depth);
  481. DAV_DECLARE(int) dav_validate_root(const apr_xml_doc *doc,
  482. const char *tagname);
  483. DAV_DECLARE(apr_xml_elem *) dav_find_child(const apr_xml_elem *elem,
  484. const char *tagname);
  485. /* gather up all the CDATA into a single string */
  486. DAV_DECLARE(const char *) dav_xml_get_cdata(const apr_xml_elem *elem, apr_pool_t *pool,
  487. int strip_white);
  488. /*
  489. ** XML namespace handling
  490. **
  491. ** This structure tracks namespace declarations (xmlns:prefix="URI").
  492. ** It maintains a one-to-many relationship of URIs-to-prefixes. In other
  493. ** words, one URI may be defined by many prefixes, but any specific
  494. ** prefix will specify only one URI.
  495. **
  496. ** Prefixes using the "g###" pattern can be generated automatically if
  497. ** the caller does not have specific prefix requirements.
  498. */
  499. typedef struct {
  500. apr_pool_t *pool;
  501. apr_hash_t *uri_prefix; /* map URIs to an available prefix */
  502. apr_hash_t *prefix_uri; /* map all prefixes to their URIs */
  503. int count; /* counter for "g###" prefixes */
  504. } dav_xmlns_info;
  505. /* create an empty dav_xmlns_info structure */
  506. DAV_DECLARE(dav_xmlns_info *) dav_xmlns_create(apr_pool_t *pool);
  507. /* add a specific prefix/URI pair. the prefix/uri should have a lifetime
  508. at least that of xmlns->pool */
  509. DAV_DECLARE(void) dav_xmlns_add(dav_xmlns_info *xi,
  510. const char *prefix, const char *uri);
  511. /* add a URI (if not present); any prefix is acceptable and is returned.
  512. the uri should have a lifetime at least that xmlns->pool */
  513. DAV_DECLARE(const char *) dav_xmlns_add_uri(dav_xmlns_info *xi,
  514. const char *uri);
  515. /* return the URI for a specified prefix (or NULL if the prefix is unknown) */
  516. DAV_DECLARE(const char *) dav_xmlns_get_uri(dav_xmlns_info *xi,
  517. const char *prefix);
  518. /* return an available prefix for a specified URI (or NULL if the URI
  519. is unknown) */
  520. DAV_DECLARE(const char *) dav_xmlns_get_prefix(dav_xmlns_info *xi,
  521. const char *uri);
  522. /* generate xmlns declarations (appending into the given text) */
  523. DAV_DECLARE(void) dav_xmlns_generate(dav_xmlns_info *xi,
  524. apr_text_header *phdr);
  525. /* --------------------------------------------------------------------
  526. **
  527. ** DAV PLUGINS
  528. */
  529. /* ### docco ... */
  530. /*
  531. ** dav_provider
  532. **
  533. ** This structure wraps up all of the hooks that a mod_dav provider can
  534. ** supply. The provider MUST supply <repos> and <propdb>. The rest are
  535. ** optional and should contain NULL if that feature is not supplied.
  536. **
  537. ** Note that a provider cannot pick and choose portions from various
  538. ** underlying implementations (which was theoretically possible in
  539. ** mod_dav 1.0). There are too many dependencies between a dav_resource
  540. ** (defined by <repos>) and the other functionality.
  541. **
  542. ** Live properties are not part of the dav_provider structure because they
  543. ** are handled through the APR_HOOK interface (to allow for multiple liveprop
  544. ** providers). The core always provides some properties, and then a given
  545. ** provider will add more properties.
  546. **
  547. ** Some providers may need to associate a context with the dav_provider
  548. ** structure -- the ctx field is available for storing this context. Just
  549. ** leave it NULL if it isn't required.
  550. */
  551. typedef struct {
  552. const dav_hooks_repository *repos;
  553. const dav_hooks_propdb *propdb;
  554. const dav_hooks_locks *locks;
  555. const dav_hooks_vsn *vsn;
  556. const dav_hooks_binding *binding;
  557. const dav_hooks_search *search;
  558. void *ctx;
  559. } dav_provider;
  560. /*
  561. ** gather_propsets: gather all live property propset-URIs
  562. **
  563. ** The hook implementor should push one or more URIs into the specified
  564. ** array. These URIs are returned in the DAV: header to let clients know
  565. ** what sets of live properties are supported by the installation. mod_dav
  566. ** will place open/close angle brackets around each value (much like
  567. ** a Coded-URL); quotes and brackets should not be in the value.
  568. **
  569. ** Example: http://apache.org/dav/props/
  570. **
  571. ** (of course, use your own domain to ensure a unique value)
  572. */
  573. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, gather_propsets,
  574. (apr_array_header_t *uris))
  575. /*
  576. ** find_liveprop: find a live property, returning a non-zero, unique,
  577. ** opaque identifier.
  578. **
  579. ** If the hook implementor determines the specified URI/name refers to
  580. ** one of its properties, then it should fill in HOOKS and return a
  581. ** non-zero value. The returned value is the "property ID" and will
  582. ** be passed to the various liveprop hook functions.
  583. **
  584. ** Return 0 if the property is not defined by the hook implementor.
  585. */
  586. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, int, find_liveprop,
  587. (const dav_resource *resource,
  588. const char *ns_uri, const char *name,
  589. const dav_hooks_liveprop **hooks))
  590. /*
  591. ** insert_all_liveprops: insert all (known) live property names/values.
  592. **
  593. ** The hook implementor should append XML text to PHDR, containing liveprop
  594. ** names. If INSVALUE is true, then the property values should also be
  595. ** inserted into the output XML stream.
  596. **
  597. ** The liveprop provider should insert *all* known and *defined* live
  598. ** properties on the specified resource. If a particular liveprop is
  599. ** not defined for this resource, then it should not be inserted.
  600. */
  601. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, insert_all_liveprops,
  602. (request_rec *r, const dav_resource *resource,
  603. dav_prop_insert what, apr_text_header *phdr))
  604. DAV_DECLARE(const dav_hooks_locks *) dav_get_lock_hooks(request_rec *r);
  605. DAV_DECLARE(const dav_hooks_propdb *) dav_get_propdb_hooks(request_rec *r);
  606. DAV_DECLARE(const dav_hooks_vsn *) dav_get_vsn_hooks(request_rec *r);
  607. DAV_DECLARE(const dav_hooks_binding *) dav_get_binding_hooks(request_rec *r);
  608. DAV_DECLARE(const dav_hooks_search *) dav_get_search_hooks(request_rec *r);
  609. DAV_DECLARE(void) dav_register_provider(apr_pool_t *p, const char *name,
  610. const dav_provider *hooks);
  611. DAV_DECLARE(const dav_provider *) dav_lookup_provider(const char *name);
  612. DAV_DECLARE(const char *) dav_get_provider_name(request_rec *r);
  613. /* ### deprecated */
  614. #define DAV_GET_HOOKS_PROPDB(r) dav_get_propdb_hooks(r)
  615. #define DAV_GET_HOOKS_LOCKS(r) dav_get_lock_hooks(r)
  616. #define DAV_GET_HOOKS_VSN(r) dav_get_vsn_hooks(r)
  617. #define DAV_GET_HOOKS_BINDING(r) dav_get_binding_hooks(r)
  618. #define DAV_GET_HOOKS_SEARCH(r) dav_get_search_hooks(r)
  619. /* --------------------------------------------------------------------
  620. **
  621. ** IF HEADER PROCESSING
  622. **
  623. ** Here is the definition of the If: header from RFC 2518, S9.4:
  624. **
  625. ** If = "If" ":" (1*No-tag-list | 1*Tagged-list)
  626. ** No-tag-list = List
  627. ** Tagged-list = Resource 1*List
  628. ** Resource = Coded-URL
  629. ** List = "(" 1*(["Not"](State-token | "[" entity-tag "]")) ")"
  630. ** State-token = Coded-URL
  631. ** Coded-URL = "<" absoluteURI ">" ; absoluteURI from RFC 2616
  632. **
  633. ** List corresponds to dav_if_state_list. No-tag-list corresponds to
  634. ** dav_if_header with uri==NULL. Tagged-list corresponds to a sequence of
  635. ** dav_if_header structures with (duplicate) uri==Resource -- one
  636. ** dav_if_header per state_list. A second Tagged-list will start a new
  637. ** sequence of dav_if_header structures with the new URI.
  638. **
  639. ** A summary of the semantics, mapped into our structures:
  640. ** - Chained dav_if_headers: OR
  641. ** - Chained dav_if_state_lists: AND
  642. ** - NULL uri matches all resources
  643. */
  644. typedef enum
  645. {
  646. dav_if_etag,
  647. dav_if_opaquelock,
  648. dav_if_unknown /* the "unknown" state type; always matches false. */
  649. } dav_if_state_type;
  650. typedef struct dav_if_state_list
  651. {
  652. dav_if_state_type type;
  653. int condition;
  654. #define DAV_IF_COND_NORMAL 0
  655. #define DAV_IF_COND_NOT 1 /* "Not" was applied */
  656. const char *etag;
  657. dav_locktoken *locktoken;
  658. struct dav_if_state_list *next;
  659. } dav_if_state_list;
  660. typedef struct dav_if_header
  661. {
  662. const char *uri;
  663. apr_size_t uri_len;
  664. struct dav_if_state_list *state;
  665. struct dav_if_header *next;
  666. int dummy_header; /* used internally by the lock/etag validation */
  667. } dav_if_header;
  668. typedef struct dav_locktoken_list
  669. {
  670. dav_locktoken *locktoken;
  671. struct dav_locktoken_list *next;
  672. } dav_locktoken_list;
  673. DAV_DECLARE(dav_error *) dav_get_locktoken_list(request_rec *r,
  674. dav_locktoken_list **ltl);
  675. /* --------------------------------------------------------------------
  676. **
  677. ** LIVE PROPERTY HANDLING
  678. */
  679. /* opaque type for PROPPATCH rollback information */
  680. typedef struct dav_liveprop_rollback dav_liveprop_rollback;
  681. struct dav_hooks_liveprop
  682. {
  683. /*
  684. ** Insert property information into a text block. The property to
  685. ** insert is identified by the propid value. The information to insert
  686. ** is identified by the "what" argument, as follows:
  687. ** DAV_PROP_INSERT_NAME
  688. ** property name, as an empty XML element
  689. ** DAV_PROP_INSERT_VALUE
  690. ** property name/value, as an XML element
  691. ** DAV_PROP_INSERT_SUPPORTED
  692. ** if the property is defined on the resource, then
  693. ** a DAV:supported-live-property element, as defined
  694. ** by the DeltaV extensions to RFC2518.
  695. **
  696. ** Providers should return DAV_PROP_INSERT_NOTDEF if the property is
  697. ** known and not defined for this resource, so should be handled as a
  698. ** dead property. If a provider recognizes, but does not support, a
  699. ** property, and does not want it handled as a dead property, it should
  700. ** return DAV_PROP_INSERT_NOTSUPP.
  701. **
  702. ** Returns one of DAV_PROP_INSERT_* based on what happened.
  703. **
  704. ** ### we may need more context... ie. the lock database
  705. */
  706. dav_prop_insert (*insert_prop)(const dav_resource *resource,
  707. int propid, dav_prop_insert what,
  708. apr_text_header *phdr);
  709. /*
  710. ** Determine whether a given property is writable.
  711. **
  712. ** ### we may want a different semantic. i.e. maybe it should be
  713. ** ### "can we write <value> into this property?"
  714. **
  715. ** Returns 1 if the live property can be written, 0 if read-only.
  716. */
  717. int (*is_writable)(const dav_resource *resource, int propid);
  718. /*
  719. ** This member defines the set of namespace URIs that the provider
  720. ** uses for its properties. When insert_all is called, it will be
  721. ** passed a list of integers that map from indices into this list
  722. ** to namespace IDs for output generation.
  723. **
  724. ** The last entry in this list should be a NULL value (sentinel).
  725. */
  726. const char * const * namespace_uris;
  727. /*
  728. ** ### this is not the final design. we want an open-ended way for
  729. ** ### liveprop providers to attach *new* properties. To this end,
  730. ** ### we'll have a "give me a list of the props you define", a way
  731. ** ### to check for a prop's existence, a way to validate a set/remove
  732. ** ### of a prop, and a way to execute/commit/rollback that change.
  733. */
  734. /*
  735. ** Validate that the live property can be assigned a value, and that
  736. ** the provided value is valid.
  737. **
  738. ** elem will point to the XML element that names the property. For
  739. ** example:
  740. ** <lp1:executable>T</lp1:executable>
  741. **
  742. ** The provider can access the cdata fields and the child elements
  743. ** to extract the relevant pieces.
  744. **
  745. ** operation is one of DAV_PROP_OP_SET or _DELETE.
  746. **
  747. ** The provider may return a value in *context which will be passed
  748. ** to each of the exec/commit/rollback functions. For example, this
  749. ** may contain an internal value which has been processed from the
  750. ** input element.
  751. **
  752. ** The provider must set defer_to_dead to true (non-zero) or false.
  753. ** If true, then the set/remove is deferred to the dead property
  754. ** database. Note: it will be set to zero on entry.
  755. */
  756. dav_error * (*patch_validate)(const dav_resource *resource,
  757. const apr_xml_elem *elem,
  758. int operation,
  759. void **context,
  760. int *defer_to_dead);
  761. /* ### doc... */
  762. dav_error * (*patch_exec)(const dav_resource *resource,
  763. const apr_xml_elem *elem,
  764. int operation,
  765. void *context,
  766. dav_liveprop_rollback **rollback_ctx);
  767. /* ### doc... */
  768. void (*patch_commit)(const dav_resource *resource,
  769. int operation,
  770. void *context,
  771. dav_liveprop_rollback *rollback_ctx);
  772. /* ### doc... */
  773. dav_error * (*patch_rollback)(const dav_resource *resource,
  774. int operation,
  775. void *context,
  776. dav_liveprop_rollback *rollback_ctx);
  777. /*
  778. ** If a provider needs a context to associate with this hooks structure,
  779. ** then this field may be used. In most cases, it will just be NULL.
  780. */
  781. void *ctx;
  782. };
  783. /*
  784. ** dav_liveprop_spec: specify a live property
  785. **
  786. ** This structure is used as a standard way to determine if a particular
  787. ** property is a live property. Its use is not part of the mandated liveprop
  788. ** interface, but can be used by liveprop providers in conjunction with the
  789. ** utility routines below.
  790. **
  791. ** spec->name == NULL is the defined end-sentinel for a list of specs.
  792. */
  793. typedef struct {
  794. int ns; /* provider-local namespace index */
  795. const char *name; /* name of the property */
  796. int propid; /* provider-local property ID */
  797. int is_writable; /* is the property writable? */
  798. } dav_liveprop_spec;
  799. /*
  800. ** dav_liveprop_group: specify a group of liveprops
  801. **
  802. ** This structure specifies a group of live properties, their namespaces,
  803. ** and how to handle them.
  804. */
  805. typedef struct {
  806. const dav_liveprop_spec *specs;
  807. const char * const *namespace_uris;
  808. const dav_hooks_liveprop *hooks;
  809. } dav_liveprop_group;
  810. /* ### docco */
  811. DAV_DECLARE(int) dav_do_find_liveprop(const char *ns_uri, const char *name,
  812. const dav_liveprop_group *group,
  813. const dav_hooks_liveprop **hooks);
  814. /* ### docco */
  815. DAV_DECLARE(long) dav_get_liveprop_info(int propid,
  816. const dav_liveprop_group *group,
  817. const dav_liveprop_spec **info);
  818. /* ### docco */
  819. DAV_DECLARE(void) dav_register_liveprop_group(apr_pool_t *pool,
  820. const dav_liveprop_group *group);
  821. /* ### docco */
  822. DAV_DECLARE(long) dav_get_liveprop_ns_index(const char *uri);
  823. /* ### docco */
  824. DAV_DECLARE(long) dav_get_liveprop_ns_count(void);
  825. /* ### docco */
  826. DAV_DECLARE(void) dav_add_all_liveprop_xmlns(apr_pool_t *p,
  827. apr_text_header *phdr);
  828. /*
  829. ** The following three functions are part of mod_dav's internal handling
  830. ** for the core WebDAV properties. They are not part of mod_dav's API.
  831. */
  832. DAV_DECLARE_NONSTD(int) dav_core_find_liveprop(
  833. const dav_resource *resource,
  834. const char *ns_uri,
  835. const char *name,
  836. const dav_hooks_liveprop **hooks);
  837. DAV_DECLARE_NONSTD(void) dav_core_insert_all_liveprops(
  838. request_rec *r,
  839. const dav_resource *resource,
  840. dav_prop_insert what,
  841. apr_text_header *phdr);
  842. DAV_DECLARE_NONSTD(void) dav_core_register_uris(apr_pool_t *p);
  843. /*
  844. ** Standard WebDAV Property Identifiers
  845. **
  846. ** A live property provider does not need to use these; they are simply
  847. ** provided for convenience.
  848. **
  849. ** Property identifiers need to be unique within a given provider, but not
  850. ** *across* providers (note: this uniqueness constraint was different in
  851. ** older versions of mod_dav).
  852. **
  853. ** The identifiers start at 20000 to make it easier for providers to avoid
  854. ** conflicts with the standard properties. The properties are arranged
  855. ** alphabetically, and may be reordered from time to time (as properties
  856. ** are introduced).
  857. **
  858. ** NOTE: there is no problem with reordering (e.g. binary compat) since the
  859. ** identifiers are only used within a given provider, which would pick up
  860. ** the entire set of changes upon a recompile.
  861. */
  862. enum {
  863. DAV_PROPID_BEGIN = 20000,
  864. /* Standard WebDAV properties (RFC 2518) */
  865. DAV_PROPID_creationdate,
  866. DAV_PROPID_displayname,
  867. DAV_PROPID_getcontentlanguage,
  868. DAV_PROPID_getcontentlength,
  869. DAV_PROPID_getcontenttype,
  870. DAV_PROPID_getetag,
  871. DAV_PROPID_getlastmodified,
  872. DAV_PROPID_lockdiscovery,
  873. DAV_PROPID_resourcetype,
  874. DAV_PROPID_source,
  875. DAV_PROPID_supportedlock,
  876. /* DeltaV properties (from the I-D (#14)) */
  877. DAV_PROPID_activity_checkout_set,
  878. DAV_PROPID_activity_set,
  879. DAV_PROPID_activity_version_set,
  880. DAV_PROPID_auto_merge_set,
  881. DAV_PROPID_auto_version,
  882. DAV_PROPID_baseline_collection,
  883. DAV_PROPID_baseline_controlled_collection,
  884. DAV_PROPID_baseline_controlled_collection_set,
  885. DAV_PROPID_checked_in,
  886. DAV_PROPID_checked_out,
  887. DAV_PROPID_checkin_fork,
  888. DAV_PROPID_checkout_fork,
  889. DAV_PROPID_checkout_set,
  890. DAV_PROPID_comment,
  891. DAV_PROPID_creator_displayname,
  892. DAV_PROPID_current_activity_set,
  893. DAV_PROPID_current_workspace_set,
  894. DAV_PROPID_default_variant,
  895. DAV_PROPID_eclipsed_set,
  896. DAV_PROPID_label_name_set,
  897. DAV_PROPID_merge_set,
  898. DAV_PROPID_precursor_set,
  899. DAV_PROPID_predecessor_set,
  900. DAV_PROPID_root_version,
  901. DAV_PROPID_subactivity_set,
  902. DAV_PROPID_subbaseline_set,
  903. DAV_PROPID_successor_set,
  904. DAV_PROPID_supported_method_set,
  905. DAV_PROPID_supported_live_property_set,
  906. DAV_PROPID_supported_report_set,
  907. DAV_PROPID_unreserved,
  908. DAV_PROPID_variant_set,
  909. DAV_PROPID_version_controlled_binding_set,
  910. DAV_PROPID_version_controlled_configuration,
  911. DAV_PROPID_version_history,
  912. DAV_PROPID_version_name,
  913. DAV_PROPID_workspace,
  914. DAV_PROPID_workspace_checkout_set,
  915. DAV_PROPID_END
  916. };
  917. /*
  918. ** Property Identifier Registration
  919. **
  920. ** At the moment, mod_dav requires live property providers to ensure that
  921. ** each property returned has a unique value. For now, this is done through
  922. ** central registration (there are no known providers other than the default,
  923. ** so this remains manageable).
  924. **
  925. ** WARNING: the TEST ranges should never be "shipped".
  926. */
  927. #define DAV_PROPID_CORE 10000 /* ..10099. defined by mod_dav */
  928. #define DAV_PROPID_FS 10100 /* ..10299.
  929. mod_dav filesystem provider. */
  930. #define DAV_PROPID_TEST1 10300 /* ..10399 */
  931. #define DAV_PROPID_TEST2 10400 /* ..10499 */
  932. #define DAV_PROPID_TEST3 10500 /* ..10599 */
  933. /* Next: 10600 */
  934. /* --------------------------------------------------------------------
  935. **
  936. ** DATABASE FUNCTIONS
  937. */
  938. typedef struct dav_db dav_db;
  939. typedef struct dav_namespace_map dav_namespace_map;
  940. typedef struct dav_deadprop_rollback dav_deadprop_rollback;
  941. typedef struct {
  942. const char *ns; /* "" signals "no namespace" */
  943. const char *name;
  944. } dav_prop_name;
  945. /* hook functions to enable pluggable databases */
  946. struct dav_hooks_propdb
  947. {
  948. dav_error * (*open)(apr_pool_t *p, const dav_resource *resource, int ro,
  949. dav_db **pdb);
  950. void (*close)(dav_db *db);
  951. /*
  952. ** In bulk, define any namespaces that the values and their name
  953. ** elements may need.
  954. **
  955. ** Note: sometimes mod_dav will defer calling this until output_value
  956. ** returns found==1. If the output process needs the dav_xmlns_info
  957. ** filled for its work, then it will need to fill it on demand rather
  958. ** than depending upon this hook to fill in the structure.
  959. **
  960. ** Note: this will *always* be called during an output sequence. Thus,
  961. ** the provider may rely solely on using this to fill the xmlns info.
  962. */
  963. dav_error * (*define_namespaces)(dav_db *db, dav_xmlns_info *xi);
  964. /*
  965. ** Output the value from the database (i.e. add an element name and
  966. ** the value into *phdr). Set *found based on whether the name/value
  967. ** was found in the propdb.
  968. **
  969. ** Note: it is NOT an error for the key/value pair to not exist.
  970. **
  971. ** The dav_xmlns_info passed to define_namespaces() is also passed to
  972. ** each output_value() call so that namespaces can be added on-demand.
  973. ** It can also be used to look up prefixes or URIs during the output
  974. ** process.
  975. */
  976. dav_error * (*output_value)(dav_db *db, const dav_prop_name *name,
  977. dav_xmlns_info *xi,
  978. apr_text_header *phdr, int *found);
  979. /*
  980. ** Build a mapping from "global" namespaces (stored in apr_xml_*)
  981. ** into provider-local namespace identifiers.
  982. **
  983. ** This mapping should be done once per set of namespaces, and the
  984. ** resulting mapping should be passed into the store() hook function.
  985. **
  986. ** Note: usually, there is just a single document/namespaces for all
  987. ** elements passed. However, the generality of creating multiple
  988. ** mappings and passing them to store() is provided here.
  989. **
  990. ** Note: this is only in preparation for a series of store() calls.
  991. ** As a result, the propdb must be open for read/write access when
  992. ** this function is called.
  993. */
  994. dav_error * (*map_namespaces)(dav_db *db,
  995. const apr_array_header_t *namespaces,
  996. dav_namespace_map **mapping);
  997. /*
  998. ** Store a property value for a given name. The value->combined field
  999. ** MUST be set for this call.
  1000. **
  1001. ** ### WARNING: current providers will quote the text within ELEM.
  1002. ** ### this implies you can call this function only once with a given
  1003. ** ### element structure (a second time will quote it again).
  1004. */
  1005. dav_error * (*store)(dav_db *db, const dav_prop_name *name,
  1006. const apr_xml_elem *elem,
  1007. dav_namespace_map *mapping);
  1008. /* remove a given property */
  1009. dav_error * (*remove)(dav_db *db, const dav_prop_name *name);
  1010. /* returns 1 if the record specified by "key" exists; 0 otherwise */
  1011. int (*exists)(dav_db *db, const dav_prop_name *name);
  1012. /*
  1013. ** Iterate over the property names in the database.
  1014. **
  1015. ** iter->name.ns == iter->name.name == NULL when there are no more names.
  1016. **
  1017. ** Note: only one iteration may occur over the propdb at a time.
  1018. */
  1019. dav_error * (*first_name)(dav_db *db, dav_prop_name *pname);
  1020. dav_error * (*next_name)(dav_db *db, dav_prop_name *pname);
  1021. /*
  1022. ** Rollback support: get rollback context, and apply it.
  1023. **
  1024. ** struct dav_deadprop_rollback is a provider-private structure; it
  1025. ** should remember the name, and the name's old value (or the fact that
  1026. ** the value was not present, and should be deleted if a rollback occurs).
  1027. */
  1028. dav_error * (*get_rollback)(dav_db *db, const dav_prop_name *name,
  1029. dav_deadprop_rollback **prollback);
  1030. dav_error * (*apply_rollback)(dav_db *db,
  1031. dav_deadprop_rollback *rollback);
  1032. /*
  1033. ** If a provider needs a context to associate with this hooks structure,
  1034. ** then this field may be used. In most cases, it will just be NULL.
  1035. */
  1036. void *ctx;
  1037. };
  1038. /* --------------------------------------------------------------------
  1039. **
  1040. ** LOCK FUNCTIONS
  1041. */
  1042. /* Used to represent a Timeout header of "Infinity" */
  1043. #define DAV_TIMEOUT_INFINITE 0
  1044. DAV_DECLARE(time_t) dav_get_timeout(request_rec *r);
  1045. /*
  1046. ** Opaque, provider-specific information for a lock database.
  1047. */
  1048. typedef struct dav_lockdb_private dav_lockdb_private;
  1049. /*
  1050. ** Opaque, provider-specific information for a lock record.
  1051. */
  1052. typedef struct dav_lock_private dav_lock_private;
  1053. /*
  1054. ** Lock database type. Lock providers are urged to implement a "lazy" open, so
  1055. ** doing an "open" is cheap until something is actually needed from the DB.
  1056. */
  1057. typedef struct
  1058. {
  1059. const dav_hooks_locks *hooks; /* the hooks used for this lockdb */
  1060. int ro; /* was it opened readonly? */
  1061. dav_lockdb_private *info;
  1062. } dav_lockdb;
  1063. typedef enum {
  1064. DAV_LOCKSCOPE_UNKNOWN,
  1065. DAV_LOCKSCOPE_EXCLUSIVE,
  1066. DAV_LOCKSCOPE_SHARED
  1067. } dav_lock_scope;
  1068. typedef enum {
  1069. DAV_LOCKTYPE_UNKNOWN,
  1070. DAV_LOCKTYPE_WRITE
  1071. } dav_lock_type;
  1072. typedef enum {
  1073. DAV_LOCKREC_DIRECT, /* lock asserted on this resource */
  1074. DAV_LOCKREC_INDIRECT, /* lock inherited from a parent */
  1075. DAV_LOCKREC_INDIRECT_PARTIAL /* most info is not filled in */
  1076. } dav_lock_rectype;
  1077. /*
  1078. ** dav_lock: hold information about a lock on a resource.
  1079. **
  1080. ** This structure is used for both direct and indirect locks. A direct lock
  1081. ** is a lock applied to a specific resource by the client. An indirect lock
  1082. ** is one that is inherited from a parent resource by virtue of a non-zero
  1083. ** Depth: header when the lock was applied.
  1084. **
  1085. ** mod_dav records both types of locks in the lock database, managing their
  1086. ** addition/removal as resources are moved about the namespace.
  1087. **
  1088. ** Note that the lockdb is free to marshal this structure in any form that
  1089. ** it likes.
  1090. **
  1091. ** For a "partial" lock, the <rectype> and <locktoken> fields must be filled
  1092. ** in. All other (user) fields should be zeroed. The lock provider will
  1093. ** usually fill in the <info> field, and the <next> field may be used to
  1094. ** construct a list of partial locks.
  1095. **
  1096. ** The lock provider MUST use the info field to store a value such that a
  1097. ** dav_lock structure can locate itself in the underlying lock database.
  1098. ** This requirement is needed for refreshing: when an indirect dav_lock is
  1099. ** refreshed, its reference to the direct lock does not specify the direct's
  1100. ** resource, so the only way to locate the (refreshed, direct) lock in the
  1101. ** database is to use the info field.
  1102. **
  1103. ** Note that <is_locknull> only refers to the resource where this lock was
  1104. ** found.
  1105. ** ### hrm. that says the abstraction is wrong. is_locknull may disappear.
  1106. */
  1107. typedef struct dav_lock
  1108. {
  1109. dav_lock_rectype rectype; /* type of lock record */
  1110. int is_locknull; /* lock establishes a locknull resource */
  1111. /* ### put the resource in here? */
  1112. dav_lock_scope scope; /* scope of the lock */
  1113. dav_lock_type type; /* type of lock */
  1114. int depth; /* depth of the lock */
  1115. time_t timeout; /* when the lock will timeout */
  1116. const dav_locktoken *locktoken; /* the token that was issued */
  1117. const char *owner; /* (XML) owner of the lock */
  1118. const char *auth_user; /* auth'd username owning lock */
  1119. dav_lock_private *info; /* private to the lockdb */
  1120. struct dav_lock *next; /* for managing a list of locks */
  1121. } dav_lock;
  1122. /* Property-related public lock functions */
  1123. DAV_DECLARE(const char *)dav_lock_get_activelock(request_rec *r,
  1124. dav_lock *locks,
  1125. dav_buffer *pbuf);
  1126. /* LockDB-related public lock functions */
  1127. DAV_DECLARE(dav_error *) dav_lock_parse_lockinfo(request_rec *r,
  1128. const dav_resource *resrouce,
  1129. dav_lockdb *lockdb,
  1130. const apr_xml_doc *doc,
  1131. dav_lock **lock_request);
  1132. DAV_DECLARE(int) dav_unlock(request_rec *r,
  1133. const dav_resource *resource,
  1134. const dav_locktoken *locktoken);
  1135. DAV_DECLARE(dav_error *) dav_add_lock(request_rec *r,
  1136. const dav_resource *resource,
  1137. dav_lockdb *lockdb, dav_lock *request,
  1138. dav_response **response);
  1139. DAV_DECLARE(dav_error *) dav_notify_created(request_rec *r,
  1140. dav_lockdb *lockdb,
  1141. const dav_resource *resource,
  1142. int resource_state,
  1143. int depth);
  1144. DAV_DECLARE(dav_error*) dav_lock_query(dav_lockdb *lockdb,
  1145. const dav_resource *resource,
  1146. dav_lock **locks);
  1147. DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r,
  1148. dav_resource *resource,
  1149. int depth,
  1150. dav_locktoken *locktoken,
  1151. dav_response **response,
  1152. int flags,
  1153. dav_lockdb *lockdb);
  1154. /*
  1155. ** flags:
  1156. ** 0x0F -- reserved for <dav_lock_scope> values
  1157. **
  1158. ** other flags, detailed below
  1159. */
  1160. #define DAV_VALIDATE_RESOURCE 0x0010 /* validate just the resource */
  1161. #define DAV_VALIDATE_PARENT 0x0020 /* validate resource AND its parent */
  1162. #define DAV_VALIDATE_ADD_LD 0x0040 /* add DAV:lockdiscovery into
  1163. the 424 DAV:response */
  1164. #define DAV_VALIDATE_USE_424 0x0080 /* return 424 status, not 207 */
  1165. #define DAV_VALIDATE_IS_PARENT 0x0100 /* for internal use */
  1166. #define DAV_VALIDATE_NO_MODIFY 0x0200 /* resource is not being modified
  1167. so allow even if lock token
  1168. is not provided */
  1169. /* Lock-null related public lock functions */
  1170. DAV_DECLARE(int) dav_get_resource_state(request_rec *r,
  1171. const dav_resource *resource);
  1172. /* Lock provider hooks. Locking is optional, so there may be no
  1173. * lock provider for a given repository.
  1174. */
  1175. struct dav_hooks_locks
  1176. {
  1177. /* Return the supportedlock property for a resource */
  1178. const char * (*get_supportedlock)(
  1179. const dav_resource *resource
  1180. );
  1181. /* Parse a lock token URI, returning a lock token object allocated
  1182. * in the given pool.
  1183. */
  1184. dav_error * (*parse_locktoken)(
  1185. apr_pool_t *p,
  1186. const char *char_token,
  1187. dav_locktoken **locktoken_p
  1188. );
  1189. /* Format a lock token object into a URI string, allocated in
  1190. * the given pool.
  1191. *
  1192. * Always returns non-NULL.
  1193. */
  1194. const char * (*format_locktoken)(
  1195. apr_pool_t *p,
  1196. const dav_locktoken *locktoken
  1197. );
  1198. /* Compare two lock tokens.
  1199. *
  1200. * Result < 0 => lt1 < lt2
  1201. * Result == 0 => lt1 == lt2
  1202. * Result > 0 => lt1 > lt2
  1203. */
  1204. int (*compare_locktoken)(
  1205. const dav_locktoken *lt1,
  1206. const dav_locktoken *lt2
  1207. );
  1208. /* Open the provider's lock database.
  1209. *
  1210. * The provider may or may not use a "real" database for locks
  1211. * (a lock could be an attribute on a resource, for example).
  1212. *
  1213. * The provider may choose to use the value of the DAVLockDB directive
  1214. * (as returned by dav_get_lockdb_path()) to decide where to place
  1215. * any storage it may need.
  1216. *
  1217. * The request storage pool should be associated with the lockdb,
  1218. * so it can be used in subsequent operations.
  1219. *
  1220. * If ro != 0, only readonly operations will be performed.
  1221. * If force == 0, the open can be "lazy"; no subsequent locking operations
  1222. * may occur.
  1223. * If force != 0, locking operations will definitely occur.
  1224. */
  1225. dav_error * (*open_lockdb)(
  1226. request_rec *r,
  1227. int ro,
  1228. int force,
  1229. dav_lockdb **lockdb
  1230. );
  1231. /* Indicates completion of locking operations */
  1232. void (*close_lockdb)(
  1233. dav_lockdb *lockdb
  1234. );
  1235. /* Take a resource out of the lock-null state. */
  1236. dav_error * (*remove_locknull_state)(
  1237. dav_lockdb *lockdb,
  1238. const dav_resource *resource
  1239. );
  1240. /*
  1241. ** Create a (direct) lock structure for the given resource. A locktoken
  1242. ** will be created.
  1243. **
  1244. ** The lock provider may store private information into lock->info.
  1245. */
  1246. dav_error * (*create_lock)(dav_lockdb *lockdb,
  1247. const dav_resource *resource,
  1248. dav_lock **lock);
  1249. /*
  1250. ** Get the locks associated with the specified resource.
  1251. **
  1252. ** If resolve_locks is true (non-zero), then any indirect locks are
  1253. ** resolved to their actual, direct lock (i.e. the reference to followed
  1254. ** to the original lock).
  1255. **
  1256. ** The locks, if any, are returned as a linked list in no particular
  1257. ** order. If no locks are present, then *locks will be NULL.
  1258. */
  1259. dav_error * (*get_locks)(dav_lockdb *lockdb,
  1260. const dav_resource *resource,
  1261. int calltype,
  1262. dav_lock **locks);
  1263. #define DAV_GETLOCKS_RESOLVED 0 /* resolve indirects to directs */
  1264. #define DAV_GETLOCKS_PARTIAL 1 /* leave indirects partially filled */
  1265. #define DAV_GETLOCKS_COMPLETE 2 /* fill out indirect locks */
  1266. /*
  1267. ** Find a particular lock on a resource (specified by its locktoken).
  1268. **
  1269. ** *lock will be set to NULL if the lock is not found.
  1270. **
  1271. ** Note that the provider can optimize the unmarshalling -- only one
  1272. ** lock (or none) must be constructed and returned.
  1273. **
  1274. ** If partial_ok is true (non-zero), then an indirect lock can be
  1275. ** partially filled in. Otherwise, another lookup is done and the
  1276. ** lock structure will be filled out as a DAV_LOCKREC_INDIRECT.
  1277. */
  1278. dav_error * (*find_lock)(dav_lockdb *lockdb,
  1279. const dav_resource *resource,
  1280. const dav_locktoken *locktoken,
  1281. int partial_ok,
  1282. dav_lock **lock);
  1283. /*
  1284. ** Quick test to see if the resource has *any* locks on it.
  1285. **
  1286. ** This is typically used to determine if a non-existent resource
  1287. ** has a lock and is (therefore) a locknull resource.
  1288. **
  1289. ** WARNING: this function may return TRUE even when timed-out locks
  1290. ** exist (i.e. it may not perform timeout checks).
  1291. */
  1292. dav_error * (*has_locks)(dav_lockdb *lockdb,
  1293. const dav_resource *resource,
  1294. int *locks_present);
  1295. /*
  1296. ** Append the specified lock(s) to the set of locks on this resource.
  1297. **
  1298. ** If "make_indirect" is true (non-zero), then the specified lock(s)
  1299. ** should be converted to an indirect lock (if it is a direct lock)
  1300. ** before appending. Note that the conversion to an indirect lock does
  1301. ** not alter the passed-in lock -- the change is internal the
  1302. ** append_locks function.
  1303. **
  1304. ** Multiple locks are specified using the lock->next links.
  1305. */
  1306. dav_error * (*append_locks)(dav_lockdb *lockdb,
  1307. const dav_resource *resource,
  1308. int make_indirect,
  1309. const dav_lock *lock);
  1310. /*
  1311. ** Remove any lock that has the specified locktoken.
  1312. **
  1313. ** If locktoken == NULL, then ALL locks are removed.
  1314. */
  1315. dav_error * (*remove_lock)(dav_lockdb *lockdb,
  1316. const dav_resource *resource,
  1317. const dav_locktoken *locktoken);
  1318. /*
  1319. ** Refresh all locks, found on the specified resource, which has a
  1320. ** locktoken in the provided list.
  1321. **
  1322. ** If the lock is indirect, then the direct lock is referenced and
  1323. ** refreshed.
  1324. **
  1325. ** Each lock that is updated is returned in the <locks> argument.
  1326. ** Note that the locks will be fully resolved.
  1327. */
  1328. dav_error * (*refresh_locks)(dav_lockdb *lockdb,
  1329. const dav_resource *resource,
  1330. const dav_locktoken_list *ltl,
  1331. time_t new_time,
  1332. dav_lock **locks);
  1333. /*
  1334. ** Look up the resource associated with a particular locktoken.
  1335. **
  1336. ** The search begins at the specified <start_resource> and the lock
  1337. ** specified by <locktoken>.
  1338. **
  1339. ** If the resource/token specifies an indirect lock, then the direct
  1340. ** lock will be looked up, and THAT resource will be returned. In other
  1341. ** words, this function always returns the resource where a particular
  1342. ** lock (token) was asserted.
  1343. **
  1344. ** NOTE: this function pointer is allowed to be NULL, indicating that
  1345. ** the provider does not support this type of functionality. The
  1346. ** caller should then traverse up the repository hierarchy looking
  1347. ** for the resource defining a lock with this locktoken.
  1348. */
  1349. dav_error * (*lookup_resource)(dav_lockdb *lockdb,
  1350. const dav_locktoken *locktoken,
  1351. const dav_resource *start_resource,
  1352. const dav_resource **resource);
  1353. /*
  1354. ** If a provider needs a context to associate with this hooks structure,
  1355. ** then this field may be used. In most cases, it will just be NULL.
  1356. */
  1357. void *ctx;
  1358. };
  1359. /* what types of resources can be discovered by dav_get_resource_state() */
  1360. #define DAV_RESOURCE_LOCK_NULL 10 /* resource lock-null */
  1361. #define DAV_RESOURCE_NULL 11 /* resource null */
  1362. #define DAV_RESOURCE_EXISTS 12 /* resource exists */
  1363. #define DAV_RESOURCE_ERROR 13 /* an error occurred */
  1364. /* --------------------------------------------------------------------
  1365. **
  1366. ** PROPERTY HANDLING
  1367. */
  1368. typedef struct dav_propdb dav_propdb;
  1369. DAV_DECLARE(dav_error *) dav_open_propdb(
  1370. request_rec *r,
  1371. dav_lockdb *lockdb,
  1372. const dav_resource *resource,
  1373. int ro,
  1374. apr_array_header_t *ns_xlate,
  1375. dav_propdb **propdb);
  1376. DAV_DECLARE(dav_error *) dav_popen_propdb(
  1377. apr_pool_t *p,
  1378. request_rec *r,
  1379. dav_lockdb *lockdb,
  1380. const dav_resource *resource,
  1381. int ro,
  1382. apr_array_header_t *ns_xlate,
  1383. dav_propdb **propdb);
  1384. DAV_DECLARE(void) dav_close_propdb(dav_propdb *db);
  1385. DAV_DECLARE(dav_get_props_result) dav_get_props(
  1386. dav_propdb *db,
  1387. apr_xml_doc *doc);
  1388. DAV_DECLARE(dav_get_props_result) dav_get_allprops(
  1389. dav_propdb *db,
  1390. dav_prop_insert what);
  1391. DAV_DECLARE(void) dav_get_liveprop_supported(
  1392. dav_propdb *propdb,
  1393. const char *ns_uri,
  1394. const char *propname,
  1395. apr_text_header *body);
  1396. /*
  1397. ** 3-phase property modification.
  1398. **
  1399. ** 1) validate props. readable? unlocked? ACLs allow access?
  1400. ** 2) execute operation (set/delete)
  1401. ** 3) commit or rollback
  1402. **
  1403. ** ### eventually, auth must be available. a ref to the request_rec (which
  1404. ** ### contains the auth info) should be in the shared context struct.
  1405. **
  1406. ** Each function may alter the error values and information contained within
  1407. ** the context record. This should be done as an "increasing" level of
  1408. ** error, rather than overwriting any previous error.
  1409. **
  1410. ** Note that commit() cannot generate errors. It should simply free the
  1411. ** rollback information.
  1412. **
  1413. ** rollback() may generate additional errors because the rollback operation
  1414. ** can sometimes fail(!).
  1415. **
  1416. ** The caller should allocate an array of these, one per operation. It should
  1417. ** be zero-initialized, then the db, operation, and prop fields should be
  1418. ** filled in before calling dav_prop_validate. Note that the set/delete
  1419. ** operations are order-dependent. For a given (logical) context, the same
  1420. ** pointer must be passed to each phase.
  1421. **
  1422. ** error_type is an internal value, but will have the same numeric value
  1423. ** for each possible "desc" value. This allows the caller to group the
  1424. ** descriptions via the error_type variable, rather than through string
  1425. ** comparisons. Note that "status" does not provide enough granularity to
  1426. ** differentiate/group the "desc" values.
  1427. **
  1428. ** Note that the propdb will maintain some (global) context across all
  1429. ** of the property change contexts. This implies that you can have only
  1430. ** one open transaction per propdb.
  1431. */
  1432. typedef struct dav_prop_ctx
  1433. {
  1434. dav_propdb *propdb;
  1435. apr_xml_elem *prop; /* property to affect */
  1436. int operation;
  1437. #define DAV_PROP_OP_SET 1 /* set a property value */
  1438. #define DAV_PROP_OP_DELETE 2 /* delete a prop value */
  1439. /* ### add a GET? */
  1440. /* private items to the propdb */
  1441. int is_liveprop;
  1442. void *liveprop_ctx;
  1443. struct dav_rollback_item *rollback; /* optional rollback info */
  1444. dav_error *err; /* error (if any) */
  1445. /* private to mod_dav.c */
  1446. request_rec *r;
  1447. } dav_prop_ctx;
  1448. DAV_DECLARE_NONSTD(void) dav_prop_validate(dav_prop_ctx *ctx);
  1449. DAV_DECLARE_NONSTD(void) dav_prop_exec(dav_prop_ctx *ctx);
  1450. DAV_DECLARE_NONSTD(void) dav_prop_commit(dav_prop_ctx *ctx);
  1451. DAV_DECLARE_NONSTD(void) dav_prop_rollback(dav_prop_ctx *ctx);
  1452. #define DAV_PROP_CTX_HAS_ERR(dpc) ((dpc).err && (dpc).err->status >= 300)
  1453. /* --------------------------------------------------------------------
  1454. **
  1455. ** WALKER STRUCTURE
  1456. */
  1457. enum {
  1458. DAV_CALLTYPE_MEMBER = 1, /* called for a member resource */
  1459. DAV_CALLTYPE_COLLECTION, /* called for a collection */
  1460. DAV_CALLTYPE_LOCKNULL /* called for a locknull resource */
  1461. };
  1462. typedef struct
  1463. {
  1464. /* the client-provided context */
  1465. void *walk_ctx;
  1466. /* pool to use for allocations in the callback */
  1467. apr_pool_t *pool;
  1468. /* the current resource */
  1469. const dav_resource *resource;
  1470. /* OUTPUT: add responses to this */
  1471. dav_response *response;
  1472. } dav_walk_resource;
  1473. typedef struct
  1474. {
  1475. int walk_type;
  1476. #define DAV_WALKTYPE_AUTH 0x0001 /* limit to authorized files */
  1477. #define DAV_WALKTYPE_NORMAL 0x0002 /* walk normal files */
  1478. #define DAV_WALKTYPE_LOCKNULL 0x0004 /* walk locknull resources */
  1479. /* callback function and a client context for the walk */
  1480. dav_error * (*func)(dav_walk_resource *wres, int calltype);
  1481. void *walk_ctx;
  1482. /* what pool to use for allocations needed by walk logic */
  1483. apr_pool_t *pool;
  1484. /* beginning root of the walk */
  1485. const dav_resource *root;
  1486. /* lock database to enable walking LOCKNULL resources */
  1487. dav_lockdb *lockdb;
  1488. } dav_walk_params;
  1489. /* directory tree walking context */
  1490. typedef struct dav_walker_ctx
  1491. {
  1492. /* input: */
  1493. dav_walk_params w;
  1494. /* ### client data... phasing out this big glom */
  1495. /* this brigade buffers data being sent to r->output_filters */
  1496. apr_bucket_brigade *bb;
  1497. /* a scratch pool, used to stream responses and iteratively cleared. */
  1498. apr_pool_t *scratchpool;
  1499. request_rec *r; /* original request */
  1500. /* for PROPFIND operations */
  1501. apr_xml_doc *doc;
  1502. int propfind_type;
  1503. #define DAV_PROPFIND_IS_ALLPROP 1
  1504. #define DAV_PROPFIND_IS_PROPNAME 2
  1505. #define DAV_PROPFIND_IS_PROP 3
  1506. apr_text *propstat_404; /* (cached) propstat giving a 404 error */
  1507. const dav_if_header *if_header; /* for validation */
  1508. const dav_locktoken *locktoken; /* for UNLOCK */
  1509. const dav_lock *lock; /* for LOCK */
  1510. int skip_root; /* for dav_inherit_locks() */
  1511. int flags;
  1512. dav_buffer work_buf; /* for dav_validate_request() */
  1513. } dav_walker_ctx;
  1514. DAV_DECLARE(void) dav_add_response(dav_walk_resource *wres,
  1515. int status,
  1516. dav_get_props_result *propstats);
  1517. /* --------------------------------------------------------------------
  1518. **
  1519. ** "STREAM" STRUCTURE
  1520. **
  1521. ** mod_dav uses this abstraction for interacting with the repository
  1522. ** while fetching/storing resources. mod_dav views resources as a stream
  1523. ** of bytes.
  1524. **
  1525. ** Note that the structure is opaque -- it is private to the repository
  1526. ** that created the stream in the repository's "open" function.
  1527. **
  1528. ** ### THIS STUFF IS GOING AWAY ... GET/read requests are handled by
  1529. ** ### having the provider jam stuff straight into the filter stack.
  1530. ** ### this is only left for handling PUT/write requests.
  1531. */
  1532. typedef struct dav_stream dav_stream;
  1533. typedef enum {
  1534. DAV_MODE_WRITE_TRUNC, /* truncate and open for writing */
  1535. DAV_MODE_WRITE_SEEKABLE /* open for writing; random access */
  1536. } dav_stream_mode;
  1537. /* --------------------------------------------------------------------
  1538. **
  1539. ** REPOSITORY FUNCTIONS
  1540. */
  1541. /* Repository provider hooks */
  1542. struct dav_hooks_repository
  1543. {
  1544. /* Flag for whether repository requires special GET handling.
  1545. * If resources in the repository are not visible in the
  1546. * filesystem location which URLs map to, then special handling
  1547. * is required to first fetch a resource from the repository,
  1548. * respond to the GET request, then free the resource copy.
  1549. */
  1550. int handle_get;
  1551. /* Get a resource descriptor for the URI in a request. A descriptor
  1552. * should always be returned even if the resource does not exist. This
  1553. * repository has been identified as handling the resource given by
  1554. * the URI, so an answer must be given. If there is a problem with the
  1555. * URI or accessing the resource or whatever, then an error should be
  1556. * returned.
  1557. *
  1558. * root_dir:
  1559. * the root of the directory for which this repository is configured.
  1560. *
  1561. * label:
  1562. * if a Label: header is present (and allowed), this is the label
  1563. * to use to identify a version resource from the resource's
  1564. * corresponding version history. Otherwise, it will be NULL.
  1565. *
  1566. * use_checked_in:
  1567. * use the DAV:checked-in property of the resource identified by the
  1568. * Request-URI to identify and return a version resource
  1569. *
  1570. * The provider may associate the request storage pool with the resource
  1571. * (in the resource->pool field), to use in other operations on that
  1572. * resource.
  1573. */
  1574. dav_error * (*get_resource)(
  1575. request_rec *r,
  1576. const char *root_dir,
  1577. const char *label,
  1578. int use_checked_in,
  1579. dav_resource **resource
  1580. );
  1581. /* Get a resource descriptor for the parent of the given resource.
  1582. * The resources need not exist. NULL is returned if the resource
  1583. * is the root collection.
  1584. *
  1585. * An error should be returned only if there is a fatal error in
  1586. * fetching information about the parent resource.
  1587. */
  1588. dav_error * (*get_parent_resource)(
  1589. const dav_resource *resource,
  1590. dav_resource **parent_resource
  1591. );
  1592. /* Determine whether two resource descriptors refer to the same resource.
  1593. *
  1594. * Result != 0 => the resources are the same.
  1595. */
  1596. int (*is_same_resource)(
  1597. const dav_resource *res1,
  1598. const dav_resource *res2
  1599. );
  1600. /* Determine whether one resource is a parent (immediate or otherwise)
  1601. * of another.
  1602. *
  1603. * Result != 0 => res1 is a parent of res2.
  1604. */
  1605. int (*is_parent_resource)(
  1606. const dav_resource *res1,
  1607. const dav_resource *res2
  1608. );
  1609. /*
  1610. ** Open a stream for this resource, using the specified mode. The
  1611. ** stream will be returned in *stream.
  1612. */
  1613. dav_error * (*open_stream)(const dav_resource *resource,
  1614. dav_stream_mode mode,
  1615. dav_stream **stream);
  1616. /*
  1617. ** Close the specified stream.
  1618. **
  1619. ** mod_dav will (ideally) make sure to call this. For safety purposes,
  1620. ** a provider should (ideally) register a cleanup function with the
  1621. ** request pool to get this closed and cleaned up.
  1622. **
  1623. ** Note the possibility of an error from the close -- it is entirely
  1624. ** feasible that the close does a "commit" of some kind, which can
  1625. ** produce an error.
  1626. **
  1627. ** commit should be TRUE (non-zero) or FALSE (0) if the stream was
  1628. ** opened for writing. This flag states whether to retain the file
  1629. ** or not.
  1630. ** Note: the commit flag is ignored for streams opened for reading.
  1631. */
  1632. dav_error * (*close_stream)(dav_stream *stream, int commit);
  1633. /*
  1634. ** Write data to the stream.
  1635. **
  1636. ** All of the bytes must be written, or an error should be returned.
  1637. */
  1638. dav_error * (*write_stream)(dav_stream *stream,
  1639. const void *buf, apr_size_t bufsize);
  1640. /*
  1641. ** Seek to an absolute position in the stream. This is used to support
  1642. ** Content-Range in a GET/PUT.
  1643. **
  1644. ** NOTE: if this function is NULL (which is allowed), then any
  1645. ** operations using Content-Range will be refused.
  1646. */
  1647. dav_error * (*seek_stream)(dav_stream *stream, apr_off_t abs_position);
  1648. /*
  1649. ** If a GET is processed using a stream (open_stream, read_stream)
  1650. ** rather than via a sub-request (on get_pathname), then this function
  1651. ** is used to provide the repository with a way to set the headers
  1652. ** in the response.
  1653. **
  1654. ** This function may be called without a following deliver(), to
  1655. ** handle a HEAD request.
  1656. **
  1657. ** This may be NULL if handle_get is FALSE.
  1658. */
  1659. dav_error * (*set_headers)(request_rec *r,
  1660. const dav_resource *resource);
  1661. /*
  1662. ** The provider should deliver the resource into the specified filter.
  1663. ** Basically, this is the response to the GET method.
  1664. **
  1665. ** Note that this is called for all resources, including collections.
  1666. ** The provider should determine what has content to deliver or not.
  1667. **
  1668. ** set_headers will be called prior to this function, allowing the
  1669. ** provider to set the appropriate response headers.
  1670. **
  1671. ** This may be NULL if handle_get is FALSE.
  1672. ** ### maybe toss handle_get and just use this function as the marker
  1673. */
  1674. dav_error * (*deliver)(const dav_resource *resource,
  1675. ap_filter_t *output);
  1676. /* Create a collection resource. The resource must not already exist.
  1677. *
  1678. * Result == NULL if the collection was created successfully. Also, the
  1679. * resource object is updated to reflect that the resource exists, and
  1680. * is a collection.
  1681. */
  1682. dav_error * (*create_collection)(
  1683. dav_resource *resource
  1684. );
  1685. /* Copy one resource to another. The destination may exist, if it is
  1686. * versioned.
  1687. * Handles both files and collections. Properties are copied as well.
  1688. * If the destination exists and is versioned, the provider must update
  1689. * the destination to have identical content to the source,
  1690. * recursively for collections.
  1691. * The depth argument is ignored for a file, and can be either 0 or
  1692. * DAV_INFINITY for a collection.
  1693. * If an error occurs in a child resource, then the return value is
  1694. * non-NULL, and *response is set to a multistatus response.
  1695. * If the copy is successful, the dst resource object is
  1696. * updated to reflect that the resource exists.
  1697. */
  1698. dav_error * (*copy_resource)(
  1699. const dav_resource *src,
  1700. dav_resource *dst,
  1701. int depth,
  1702. dav_response **response
  1703. );
  1704. /* Move one resource to another. The destination must not exist.
  1705. * Handles both files and collections. Properties are moved as well.
  1706. * If an error occurs in a child resource, then the return value is
  1707. * non-NULL, and *response is set to a multistatus response.
  1708. * If the move is successful, the src and dst resource objects are
  1709. * updated to reflect that the source no longer exists, and the
  1710. * destination does.
  1711. */
  1712. dav_error * (*move_resource)(
  1713. dav_resource *src,
  1714. dav_resource *dst,
  1715. dav_response **response
  1716. );
  1717. /* Remove a resource. Handles both files and collections.
  1718. * Removes any associated properties as well.
  1719. * If an error occurs in a child resource, then the return value is
  1720. * non-NULL, and *response is set to a multistatus response.
  1721. * If the delete is successful, the resource object is updated to
  1722. * reflect that the resource no longer exists.
  1723. */
  1724. dav_error * (*remove_resource)(
  1725. dav_resource *resource,
  1726. dav_response **response
  1727. );
  1728. /* Walk a resource hierarchy.
  1729. *
  1730. * Iterates over the resource hierarchy specified by params->root.
  1731. * Control of the walk and the callback are specified by 'params'.
  1732. *
  1733. * An error may be returned. *response will contain multistatus
  1734. * responses (if any) suitable for the body of the error. It is also
  1735. * possible to return NULL, yet still have multistatus responses.
  1736. * In this case, typically the caller should return a 207 (Multistatus)
  1737. * and the responses (in the body) as the HTTP response.
  1738. */
  1739. dav_error * (*walk)(const dav_walk_params *params, int depth,
  1740. dav_response **response);
  1741. /* Get the entity tag for a resource */
  1742. const char * (*getetag)(const dav_resource *resource);
  1743. /*
  1744. ** If a provider needs a context to associate with this hooks structure,
  1745. ** then this field may be used. In most cases, it will just be NULL.
  1746. */
  1747. void *ctx;
  1748. /* Get the request rec for a resource */
  1749. request_rec * (*get_request_rec)(const dav_resource *resource);
  1750. /* Get the pathname for a resource */
  1751. const char * (*get_pathname)(const dav_resource *resource);
  1752. };
  1753. /* --------------------------------------------------------------------
  1754. **
  1755. ** VERSIONING FUNCTIONS
  1756. */
  1757. /* dav_add_vary_header
  1758. *
  1759. * If there were any headers in the request which require a Vary header
  1760. * in the response, add it.
  1761. */
  1762. DAV_DECLARE(void) dav_add_vary_header(request_rec *in_req,
  1763. request_rec *out_req,
  1764. const dav_resource *resource);
  1765. /*
  1766. ** Flags specifying auto-versioning behavior, returned by
  1767. ** the auto_versionable hook. The value returned depends
  1768. ** on both the state of the resource and the value of the
  1769. ** DAV:auto-versioning property for the resource.
  1770. **
  1771. ** If the resource does not exist (null or lock-null),
  1772. ** DAV_AUTO_VERSION_ALWAYS causes creation of a new version-controlled resource
  1773. **
  1774. ** If the resource is checked in,
  1775. ** DAV_AUTO_VERSION_ALWAYS causes it to be checked out always,
  1776. ** DAV_AUTO_VERSION_LOCKED causes it to be checked out only when locked
  1777. **
  1778. ** If the resource is checked out,
  1779. ** DAV_AUTO_VERSION_ALWAYS causes it to be checked in always,
  1780. ** DAV_AUTO_VERSION_LOCKED causes it to be checked in when unlocked
  1781. ** (note: a provider should allow auto-checkin only for resources which
  1782. ** were automatically checked out)
  1783. **
  1784. ** In all cases, DAV_AUTO_VERSION_NEVER results in no auto-versioning behavior.
  1785. */
  1786. typedef enum {
  1787. DAV_AUTO_VERSION_NEVER,
  1788. DAV_AUTO_VERSION_ALWAYS,
  1789. DAV_AUTO_VERSION_LOCKED
  1790. } dav_auto_version;
  1791. /*
  1792. ** This structure is used to record what auto-versioning operations
  1793. ** were done to make a resource writable, so that they can be undone
  1794. ** at the end of a request.
  1795. */
  1796. typedef struct {
  1797. int resource_versioned; /* 1 => resource was auto-version-controlled */
  1798. int resource_checkedout; /* 1 => resource was auto-checked-out */
  1799. int parent_checkedout; /* 1 => parent was auto-checked-out */
  1800. dav_resource *parent_resource; /* parent resource, if it was needed */
  1801. } dav_auto_version_info;
  1802. /* Ensure that a resource is writable. If there is no versioning
  1803. * provider, then this is essentially a no-op. Versioning repositories
  1804. * require explicit resource creation and checkout before they can
  1805. * be written to. If a new resource is to be created, or an existing
  1806. * resource deleted, the parent collection must be checked out as well.
  1807. *
  1808. * Set the parent_only flag to only make the parent collection writable.
  1809. * Otherwise, both parent and child are made writable as needed. If the
  1810. * child does not exist, then a new versioned resource is created and
  1811. * checked out.
  1812. *
  1813. * If auto-versioning is not enabled for a versioned resource, then an error is
  1814. * returned, since the resource cannot be modified.
  1815. *
  1816. * The dav_auto_version_info structure is filled in with enough information
  1817. * to restore both parent and child resources to the state they were in
  1818. * before the auto-versioning operations occurred.
  1819. */
  1820. DAV_DECLARE(dav_error *) dav_auto_checkout(
  1821. request_rec *r,
  1822. dav_resource *resource,
  1823. int parent_only,
  1824. dav_auto_version_info *av_info);
  1825. /* Revert the writability of resources back to what they were
  1826. * before they were modified. If undo == 0, then the resource
  1827. * modifications are maintained (i.e. they are checked in).
  1828. * If undo != 0, then resource modifications are discarded
  1829. * (i.e. they are unchecked out).
  1830. *
  1831. * Set the unlock flag to indicate that the resource is about
  1832. * to be unlocked; it will be checked in if the resource
  1833. * auto-versioning property indicates it should be. In this case,
  1834. * av_info is ignored, so it can be NULL.
  1835. *
  1836. * The resource argument may be NULL if only the parent resource
  1837. * was checked out (i.e. the parent_only was != 0 in the
  1838. * dav_auto_checkout call).
  1839. */
  1840. DAV_DECLARE(dav_error *) dav_auto_checkin(
  1841. request_rec *r,
  1842. dav_resource *resource,
  1843. int undo,
  1844. int unlock,
  1845. dav_auto_version_info *av_info);
  1846. /*
  1847. ** This structure is used to describe available reports
  1848. **
  1849. ** "nmspace" should be valid XML and URL-quoted. mod_dav will place
  1850. ** double-quotes around it and use it in an xmlns declaration.
  1851. */
  1852. typedef struct {
  1853. const char *nmspace; /* namespace of the XML report element */
  1854. const char *name; /* element name for the XML report */
  1855. } dav_report_elem;
  1856. /* Versioning provider hooks */
  1857. struct dav_hooks_vsn
  1858. {
  1859. /*
  1860. ** MANDATORY HOOKS
  1861. ** The following hooks are mandatory for all versioning providers;
  1862. ** they define the functionality needed to implement "core" versioning.
  1863. */
  1864. /* Return supported versioning options.
  1865. * Each dav_text item in the list will be returned as a separate
  1866. * DAV header. Providers are advised to limit the length of an
  1867. * individual text item to 63 characters, to conform to the limit
  1868. * used by MS Web Folders.
  1869. */
  1870. void (*get_vsn_options)(apr_pool_t *p, apr_text_header *phdr);
  1871. /* Get the value of a specific option for an OPTIONS request.
  1872. * The option being requested is given by the parsed XML
  1873. * element object "elem". The value of the option should be
  1874. * appended to the "option" text object.
  1875. */
  1876. dav_error * (*get_option)(const dav_resource *resource,
  1877. const apr_xml_elem *elem,
  1878. apr_text_header *option);
  1879. /* Determine whether a non-versioned (or non-existent) resource
  1880. * is versionable. Returns != 0 if resource can be versioned.
  1881. */
  1882. int (*versionable)(const dav_resource *resource);
  1883. /* Determine whether auto-versioning is enabled for a resource
  1884. * (which may not exist, or may not be versioned). If the resource
  1885. * is a checked-out resource, the provider must only enable
  1886. * auto-checkin if the resource was automatically checked out.
  1887. *
  1888. * The value returned depends on both the state of the resource
  1889. * and the value of its DAV:auto-version property. See the description
  1890. * of the dav_auto_version enumeration above for the details.
  1891. */
  1892. dav_auto_version (*auto_versionable)(const dav_resource *resource);
  1893. /* Put a resource under version control. If the resource already
  1894. * exists unversioned, then it becomes the initial version of the
  1895. * new version history, and it is replaced by a version selector
  1896. * which targets the new version.
  1897. *
  1898. * If the resource does not exist, then a new version-controlled
  1899. * resource is created which either targets an existing version (if the
  1900. * "target" argument is not NULL), or the initial, empty version
  1901. * in a new history resource (if the "target" argument is NULL).
  1902. *
  1903. * If successful, the resource object state is updated appropriately
  1904. * (that is, changed to refer to the new version-controlled resource).
  1905. */
  1906. dav_error * (*vsn_control)(dav_resource *resource,
  1907. const char *target);
  1908. /* Checkout a resource. If successful, the resource
  1909. * object state is updated appropriately.
  1910. *
  1911. * The auto_checkout flag will be set if this checkout is being
  1912. * done automatically, as part of some method which modifies
  1913. * the resource. The provider must remember that the resource
  1914. * was automatically checked out, so it can determine whether it
  1915. * can be automatically checked in. (Auto-checkin should only be
  1916. * enabled for resources which were automatically checked out.)
  1917. *
  1918. * If the working resource has a different URL from the
  1919. * target resource, a dav_resource descriptor is returned
  1920. * for the new working resource. Otherwise, the original
  1921. * resource descriptor will refer to the working resource.
  1922. * The working_resource argument can be NULL if the caller
  1923. * is not interested in the working resource.
  1924. *
  1925. * If the client has specified DAV:unreserved or DAV:fork-ok in the
  1926. * checkout request, then the corresponding flags are set. If
  1927. * DAV:activity-set has been specified, then create_activity is set
  1928. * if DAV:new was specified; otherwise, the DAV:href elements' CDATA
  1929. * (the actual href text) is passed in the "activities" array (each
  1930. * element of the array is a const char *). activities will be NULL
  1931. * no DAV:activity-set was provided or when create_activity is set.
  1932. */
  1933. dav_error * (*checkout)(dav_resource *resource,
  1934. int auto_checkout,
  1935. int is_unreserved, int is_fork_ok,
  1936. int create_activity,
  1937. apr_array_header_t *activities,
  1938. dav_resource **working_resource);
  1939. /* Uncheckout a checked-out resource. If successful, the resource
  1940. * object state is updated appropriately.
  1941. */
  1942. dav_error * (*uncheckout)(dav_resource *resource);
  1943. /* Checkin a checked-out resource. If successful, the resource
  1944. * object state is updated appropriately, and the
  1945. * version_resource descriptor will refer to the new version.
  1946. * The version_resource argument can be NULL if the caller
  1947. * is not interested in the new version resource.
  1948. *
  1949. * If the client has specified DAV:keep-checked-out in the checkin
  1950. * request, then the keep_checked_out flag is set. The provider
  1951. * should create a new version, but keep the resource in the
  1952. * checked-out state.
  1953. */
  1954. dav_error * (*checkin)(dav_resource *resource,
  1955. int keep_checked_out,
  1956. dav_resource **version_resource);
  1957. /*
  1958. ** Return the set of reports available at this resource.
  1959. **
  1960. ** An array of report elements should be returned, with an end-marker
  1961. ** element containing namespace==NULL. The value of the
  1962. ** DAV:supported-report-set property will be constructed and
  1963. ** returned.
  1964. */
  1965. dav_error * (*avail_reports)(const dav_resource *resource,
  1966. const dav_report_elem **reports);
  1967. /*
  1968. ** Determine whether a Label header can be used
  1969. ** with a particular report. The dav_xml_doc structure
  1970. ** contains the parsed report request body.
  1971. ** Returns 0 if the Label header is not allowed.
  1972. */
  1973. int (*report_label_header_allowed)(const apr_xml_doc *doc);
  1974. /*
  1975. ** Generate a report on a resource. Since a provider is free
  1976. ** to define its own reports, and the value of request headers
  1977. ** may affect the interpretation of a report, the request record
  1978. ** must be passed to this routine.
  1979. **
  1980. ** The dav_xml_doc structure contains the parsed report request
  1981. ** body. The report response should be generated into the specified
  1982. ** output filter.
  1983. **
  1984. ** If an error occurs, and a response has not yet been generated,
  1985. ** then an error can be returned from this function. mod_dav will
  1986. ** construct an appropriate error response. Once some output has
  1987. ** been placed into the filter, however, the provider should not
  1988. ** return an error -- there is no way that mod_dav can deliver it
  1989. ** properly.
  1990. **
  1991. ** ### maybe we need a way to signal an error anyways, and then
  1992. ** ### apache can abort the connection?
  1993. */
  1994. dav_error * (*deliver_report)(request_rec *r,
  1995. const dav_resource *resource,
  1996. const apr_xml_doc *doc,
  1997. ap_filter_t *output);
  1998. /*
  1999. ** OPTIONAL HOOKS
  2000. ** The following hooks are optional; if not defined, then the
  2001. ** corresponding protocol methods will be unsupported.
  2002. */
  2003. /*
  2004. ** Set the state of a checked-in version-controlled resource.
  2005. **
  2006. ** If the request specified a version, the version resource
  2007. ** represents that version. If the request specified a label,
  2008. ** then "version" is NULL, and "label" is the label.
  2009. **
  2010. ** The depth argument is ignored for a file, and can be 0, 1, or
  2011. ** DAV_INFINITY for a collection. The depth argument only applies
  2012. ** with a label, not a version.
  2013. **
  2014. ** If an error occurs in a child resource, then the return value is
  2015. ** non-NULL, and *response is set to a multistatus response.
  2016. **
  2017. ** This hook is optional; if not defined, then the UPDATE method
  2018. ** will not be supported.
  2019. */
  2020. dav_error * (*update)(const dav_resource *resource,
  2021. const dav_resource *version,
  2022. const char *label,
  2023. int depth,
  2024. dav_response **response);
  2025. /*
  2026. ** Add a label to a version. The resource is either a specific
  2027. ** version, or a version selector, in which case the label should
  2028. ** be added to the current target of the version selector. The
  2029. ** version selector cannot be checked out.
  2030. **
  2031. ** If replace != 0, any existing label by the same name is
  2032. ** effectively deleted first. Otherwise, it is an error to
  2033. ** attempt to add a label which already exists on some version
  2034. ** of the same history resource.
  2035. **
  2036. ** This hook is optional; if not defined, then the LABEL method
  2037. ** will not be supported. If it is defined, then the remove_label
  2038. ** hook must be defined also.
  2039. */
  2040. dav_error * (*add_label)(const dav_resource *resource,
  2041. const char *label,
  2042. int replace);
  2043. /*
  2044. ** Remove a label from a version. The resource is either a specific
  2045. ** version, or a version selector, in which case the label should
  2046. ** be added to the current target of the version selector. The
  2047. ** version selector cannot be checked out.
  2048. **
  2049. ** It is an error if no such label exists on the specified version.
  2050. **
  2051. ** This hook is optional, but if defined, the add_label hook
  2052. ** must be defined also.
  2053. */
  2054. dav_error * (*remove_label)(const dav_resource *resource,
  2055. const char *label);
  2056. /*
  2057. ** Determine whether a null resource can be created as a workspace.
  2058. ** The provider may restrict workspaces to certain locations.
  2059. ** Returns 0 if the resource cannot be a workspace.
  2060. **
  2061. ** This hook is optional; if the provider does not support workspaces,
  2062. ** it should be set to NULL.
  2063. */
  2064. int (*can_be_workspace)(const dav_resource *resource);
  2065. /*
  2066. ** Create a workspace resource. The resource must not already
  2067. ** exist. Any <DAV:mkworkspace> element is passed to the provider
  2068. ** in the "doc" structure; it may be empty.
  2069. **
  2070. ** If workspace creation is successful, the state of the resource
  2071. ** object is updated appropriately.
  2072. **
  2073. ** This hook is optional; if the provider does not support workspaces,
  2074. ** it should be set to NULL.
  2075. */
  2076. dav_error * (*make_workspace)(dav_resource *resource,
  2077. apr_xml_doc *doc);
  2078. /*
  2079. ** Determine whether a null resource can be created as an activity.
  2080. ** The provider may restrict activities to certain locations.
  2081. ** Returns 0 if the resource cannot be an activity.
  2082. **
  2083. ** This hook is optional; if the provider does not support activities,
  2084. ** it should be set to NULL.
  2085. */
  2086. int (*can_be_activity)(const dav_resource *resource);
  2087. /*
  2088. ** Create an activity resource. The resource must not already
  2089. ** exist.
  2090. **
  2091. ** If activity creation is successful, the state of the resource
  2092. ** object is updated appropriately.
  2093. **
  2094. ** This hook is optional; if the provider does not support activities,
  2095. ** it should be set to NULL.
  2096. */
  2097. dav_error * (*make_activity)(dav_resource *resource);
  2098. /*
  2099. ** Merge a resource (tree) into target resource (tree).
  2100. **
  2101. ** ### more doc...
  2102. **
  2103. ** This hook is optional; if the provider does not support merging,
  2104. ** then this should be set to NULL.
  2105. */
  2106. dav_error * (*merge)(dav_resource *target, dav_resource *source,
  2107. int no_auto_merge, int no_checkout,
  2108. apr_xml_elem *prop_elem,
  2109. ap_filter_t *output);
  2110. /*
  2111. ** If a provider needs a context to associate with this hooks structure,
  2112. ** then this field may be used. In most cases, it will just be NULL.
  2113. */
  2114. void *ctx;
  2115. };
  2116. /* --------------------------------------------------------------------
  2117. **
  2118. ** BINDING FUNCTIONS
  2119. */
  2120. /* binding provider hooks */
  2121. struct dav_hooks_binding {
  2122. /* Determine whether a resource can be the target of a binding.
  2123. * Returns 0 if the resource cannot be a binding target.
  2124. */
  2125. int (*is_bindable)(const dav_resource *resource);
  2126. /* Create a binding to a resource.
  2127. * The resource argument is the target of the binding;
  2128. * the binding argument must be a resource which does not already
  2129. * exist.
  2130. */
  2131. dav_error * (*bind_resource)(const dav_resource *resource,
  2132. dav_resource *binding);
  2133. /*
  2134. ** If a provider needs a context to associate with this hooks structure,
  2135. ** then this field may be used. In most cases, it will just be NULL.
  2136. */
  2137. void *ctx;
  2138. };
  2139. /* --------------------------------------------------------------------
  2140. **
  2141. ** SEARCH(DASL) FUNCTIONS
  2142. */
  2143. /* search provider hooks */
  2144. struct dav_hooks_search {
  2145. /* Set header for a OPTION method
  2146. * An error may be returned.
  2147. * To set a hadder, this function might call
  2148. * apr_table_setn(r->headers_out, "DASL", dasl_optin1);
  2149. *
  2150. * Examples:
  2151. * DASL: <DAV:basicsearch>
  2152. * DASL: <http://foo.bar.com/syntax1>
  2153. * DASL: <http://akuma.com/syntax2>
  2154. */
  2155. dav_error * (*set_option_head)(request_rec *r);
  2156. /* Search resources
  2157. * An error may be returned. *response will contain multistatus
  2158. * responses (if any) suitable for the body of the error. It is also
  2159. * possible to return NULL, yet still have multistatus responses.
  2160. * In this case, typically the caller should return a 207 (Multistatus)
  2161. * and the responses (in the body) as the HTTP response.
  2162. */
  2163. dav_error * (*search_resource)(request_rec *r,
  2164. dav_response **response);
  2165. /*
  2166. ** If a provider needs a context to associate with this hooks structure,
  2167. ** then this field may be used. In most cases, it will just be NULL.
  2168. */
  2169. void *ctx;
  2170. };
  2171. /* --------------------------------------------------------------------
  2172. **
  2173. ** MISCELLANEOUS STUFF
  2174. */
  2175. typedef struct {
  2176. int propid; /* live property ID */
  2177. const dav_hooks_liveprop *provider; /* the provider defining this prop */
  2178. } dav_elem_private;
  2179. /* --------------------------------------------------------------------
  2180. **
  2181. ** DAV OPTIONS
  2182. */
  2183. #define DAV_OPTIONS_EXTENSION_GROUP "dav_options"
  2184. typedef struct dav_options_provider
  2185. {
  2186. dav_error* (*dav_header)(request_rec *r,
  2187. const dav_resource *resource,
  2188. apr_text_header *phdr);
  2189. dav_error* (*dav_method)(request_rec *r,
  2190. const dav_resource *resource,
  2191. apr_text_header *phdr);
  2192. void *ctx;
  2193. } dav_options_provider;
  2194. extern DAV_DECLARE(const dav_options_provider *) dav_get_options_providers(const char *name);
  2195. extern DAV_DECLARE(void) dav_options_provider_register(apr_pool_t *p,
  2196. const char *name,
  2197. const dav_options_provider *provider);
  2198. /* --------------------------------------------------------------------
  2199. **
  2200. ** DAV RESOURCE TYPE HOOKS
  2201. */
  2202. typedef struct dav_resource_type_provider
  2203. {
  2204. int (*get_resource_type)(const dav_resource *resource,
  2205. const char **name,
  2206. const char **uri);
  2207. } dav_resource_type_provider;
  2208. #define DAV_RESOURCE_TYPE_GROUP "dav_resource_type"
  2209. DAV_DECLARE(void) dav_resource_type_provider_register(apr_pool_t *p,
  2210. const char *name,
  2211. const dav_resource_type_provider *provider);
  2212. DAV_DECLARE(const dav_resource_type_provider *) dav_get_resource_type_providers(const char *name);
  2213. #ifdef __cplusplus
  2214. }
  2215. #endif
  2216. #endif /* _MOD_DAV_H_ */
  2217. /** @} */