Followup to r29625: fix getopt tests.
[svn.git] / subversion / libsvn_ra_neon / options.c
blob7a6ac958d10f889100c41f4770e6139f2b447d24
1 /*
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"
27 #include "ra_neon.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 },
36 { NULL }
39 typedef struct {
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;
45 apr_pool_t *pool;
46 svn_string_t *activity_coll;
47 } options_ctx_t;
51 static int
52 validate_element(svn_ra_neon__xml_elmid parent, svn_ra_neon__xml_elmid child)
54 switch (parent)
56 case ELEM_root:
57 if (child == ELEM_options_response)
58 return child;
59 else
60 return SVN_RA_NEON__XML_INVALID;
62 case ELEM_options_response:
63 if (child == ELEM_activity_coll_set)
64 return child;
65 else
66 return SVN_RA_NEON__XML_DECLINE; /* not concerned with other response */
68 case ELEM_activity_coll_set:
69 if (child == ELEM_href)
70 return child;
71 else
72 return SVN_RA_NEON__XML_DECLINE; /* not concerned with unknown crud */
74 default:
75 return SVN_RA_NEON__XML_DECLINE;
78 /* NOTREACHED */
81 static svn_error_t *
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 */
91 return SVN_NO_ERROR;
93 if (elm->id == ELEM_href)
94 oc->want_cdata = oc->cdata;
95 else
96 oc->want_cdata = NULL;
98 return SVN_NO_ERROR;
101 static svn_error_t *
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);
110 return SVN_NO_ERROR;
113 svn_error_t *
114 svn_ra_neon__get_activity_collection(const svn_string_t **activity_coll,
115 svn_ra_neon__session_t *ras,
116 const char *url,
117 apr_pool_t *pool)
119 options_ctx_t oc = { 0 };
121 #if 0
122 ne_add_response_header_handler(req, "dav",
123 ne_duplicate_header, &dav_header);
124 #endif
126 oc.pool = pool;
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,
135 start_element,
136 svn_ra_neon__xml_collect_cdata,
137 end_element, &oc,
138 NULL, NULL, FALSE, pool));
140 if (oc.activity_coll == NULL)
142 /* ### error */
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;
152 return SVN_NO_ERROR;