2 * options.c : routines for performing OPTIONS server requests
4 * ====================================================================
5 * Copyright (c) 2000-2006 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
21 #include <apr_pools.h>
23 #include "svn_error.h"
25 #include "svn_private_config.h"
30 static const svn_ra_neon__xml_elm_t options_elements
[] =
32 { "DAV:", "activity-collection-set", ELEM_activity_coll_set
, 0 },
33 { "DAV:", "href", ELEM_href
, SVN_RA_NEON__XML_CDATA
},
34 { "DAV:", "options-response", ELEM_options_response
, 0 },
40 /*WARNING: WANT_CDATA should stay the first element in the baton:
41 svn_ra_neon__xml_collect_cdata() assumes the baton starts with a stringbuf.
43 svn_stringbuf_t
*want_cdata
;
44 svn_stringbuf_t
*cdata
;
46 svn_string_t
*activity_coll
;
52 validate_element(svn_ra_neon__xml_elmid parent
, svn_ra_neon__xml_elmid child
)
57 if (child
== ELEM_options_response
)
60 return SVN_RA_NEON__XML_INVALID
;
62 case ELEM_options_response
:
63 if (child
== ELEM_activity_coll_set
)
66 return SVN_RA_NEON__XML_DECLINE
; /* not concerned with other response */
68 case ELEM_activity_coll_set
:
69 if (child
== ELEM_href
)
72 return SVN_RA_NEON__XML_DECLINE
; /* not concerned with unknown crud */
75 return SVN_RA_NEON__XML_DECLINE
;
82 start_element(int *elem
, void *baton
, int parent
,
83 const char *nspace
, const char *name
, const char **atts
)
85 options_ctx_t
*oc
= baton
;
86 const svn_ra_neon__xml_elm_t
*elm
87 = svn_ra_neon__lookup_xml_elem(options_elements
, nspace
, name
);
89 *elem
= elm
? validate_element(parent
, elm
->id
) : SVN_RA_NEON__XML_DECLINE
;
90 if (*elem
< 1) /* Not a valid element */
93 if (elm
->id
== ELEM_href
)
94 oc
->want_cdata
= oc
->cdata
;
96 oc
->want_cdata
= NULL
;
102 end_element(void *baton
, int state
,
103 const char *nspace
, const char *name
)
105 options_ctx_t
*oc
= baton
;
107 if (state
== ELEM_href
)
108 oc
->activity_coll
= svn_string_create_from_buf(oc
->cdata
, oc
->pool
);
114 svn_ra_neon__get_activity_collection(const svn_string_t
**activity_coll
,
115 svn_ra_neon__session_t
*ras
,
119 options_ctx_t oc
= { 0 };
122 ne_add_response_header_handler(req
, "dav",
123 ne_duplicate_header
, &dav_header
);
127 oc
.cdata
= svn_stringbuf_create("", pool
);
129 SVN_ERR(svn_ra_neon__parsed_request(ras
, "OPTIONS", url
,
130 "<?xml version=\"1.0\" "
131 "encoding=\"utf-8\"?>"
132 "<D:options xmlns:D=\"DAV:\">"
133 "<D:activity-collection-set/>"
134 "</D:options>", 0, NULL
,
136 svn_ra_neon__xml_collect_cdata
,
138 NULL
, NULL
, FALSE
, pool
));
140 if (oc
.activity_coll
== NULL
)
143 return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED
, NULL
,
144 _("The OPTIONS response did not include the "
145 "requested activity-collection-set; "
146 "this often means that "
147 "the URL is not WebDAV-enabled"));
150 *activity_coll
= oc
.activity_coll
;