~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_ra_serf/getlocations.c

  • Committer: Package Import Robot
  • Author(s): James McCoy, Peter Samuelson, James McCoy
  • Date: 2014-01-12 19:48:33 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20140112194833-w3axfwksn296jn5x
Tags: 1.8.5-1
[ Peter Samuelson ]
* New upstream release.  (Closes: #725787) Rediff patches:
  - Remove apr-abi1 (applied upstream), rename apr-abi2 to apr-abi
  - Remove loosen-sqlite-version-check (shouldn't be needed)
  - Remove java-osgi-metadata (applied upstream)
  - svnmucc prompts for a changelog if none is provided. (Closes: #507430)
  - Remove fix-bdb-version-detection, upstream uses "apu-config --dbm-libs"
  - Remove ruby-test-wc (applied upstream)
  - Fix “svn diff -r N file” when file has svn:mime-type set.
    (Closes: #734163)
  - Support specifying an encoding for mod_dav_svn's environment in which
    hooks are run.  (Closes: #601544)
  - Fix ordering of “svnadmin dump” paths with certain APR versions.
    (Closes: #687291)
  - Provide a better error message when authentication fails with an
    svn+ssh:// URL.  (Closes: #273874)
  - Updated Polish translations.  (Closes: #690815)

[ James McCoy ]
* Remove all traces of libneon, replaced by libserf.
* patches/sqlite_3.8.x_workaround: Upstream fix for wc-queries-test test
  failurse.
* Run configure with --with-apache-libexecdir, which allows removing part of
  patches/rpath.
* Re-enable auth-test as upstream has fixed the problem of picking up
  libraries from the environment rather than the build tree.
  (Closes: #654172)
* Point LD_LIBRARY_PATH at the built auth libraries when running the svn
  command during the build.  (Closes: #678224)
* Add a NEWS entry describing how to configure mod_dav_svn to understand
  UTF-8.  (Closes: #566148)
* Remove ancient transitional package, libsvn-ruby.
* Enable compatibility with Sqlite3 versions back to Wheezy.
* Enable hardening flags.  (Closes: #734918)
* patches/build-fixes: Enable verbose build logs.
* Build against the default ruby version.  (Closes: #722393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include <serf.h>
29
29
 
 
30
#include "svn_hash.h"
30
31
#include "svn_path.h"
31
32
#include "svn_pools.h"
32
33
#include "svn_ra.h"
41
42
/*
42
43
 * This enum represents the current state of our XML parsing for a REPORT.
43
44
 */
44
 
typedef enum loc_state_e {
 
45
enum loc_state_e {
 
46
  INITIAL = 0,
45
47
  REPORT,
46
48
  LOCATION
47
 
} loc_state_e;
48
 
 
49
 
typedef struct loc_state_list_t {
50
 
  /* The current state that we are in now. */
51
 
  loc_state_e state;
52
 
 
53
 
  /* The previous state we were in. */
54
 
  struct loc_state_list_t *prev;
55
 
} loc_state_list_t;
 
49
};
56
50
 
57
51
typedef struct loc_context_t {
58
52
  /* pool to allocate memory from */
66
60
  /* Returned location hash */
67
61
  apr_hash_t *paths;
68
62
 
69
 
  /* Current state we're in */
70
 
  loc_state_list_t *state;
71
 
  loc_state_list_t *free_state;
72
 
 
73
 
  int status_code;
74
 
 
75
 
  svn_boolean_t done;
76
63
} loc_context_t;
77
64
 
 
65
#define D_ "DAV:"
 
66
#define S_ SVN_XML_NAMESPACE
 
67
static const svn_ra_serf__xml_transition_t getloc_ttable[] = {
 
68
  { INITIAL, S_, "get-locations-report", REPORT,
 
69
    FALSE, { NULL }, FALSE },
 
70
 
 
71
  { REPORT, S_, "location", LOCATION,
 
72
    FALSE, { "?rev", "?path", NULL }, TRUE },
 
73
 
 
74
  { 0 }
 
75
};
 
76
 
78
77
 
79
 
static void
80
 
push_state(loc_context_t *loc_ctx, loc_state_e state)
81
 
{
82
 
  loc_state_list_t *new_state;
83
 
 
84
 
  if (!loc_ctx->free_state)
85
 
    {
86
 
      new_state = apr_palloc(loc_ctx->pool, sizeof(*loc_ctx->state));
87
 
    }
88
 
  else
89
 
    {
90
 
      new_state = loc_ctx->free_state;
91
 
      loc_ctx->free_state = loc_ctx->free_state->prev;
92
 
    }
93
 
  new_state->state = state;
94
 
 
95
 
  /* Add it to the state chain. */
96
 
  new_state->prev = loc_ctx->state;
97
 
  loc_ctx->state = new_state;
98
 
}
99
 
 
100
 
static void pop_state(loc_context_t *loc_ctx)
101
 
{
102
 
  loc_state_list_t *free_state;
103
 
  free_state = loc_ctx->state;
104
 
  /* advance the current state */
105
 
  loc_ctx->state = loc_ctx->state->prev;
106
 
  free_state->prev = loc_ctx->free_state;
107
 
  loc_ctx->free_state = free_state;
108
 
}
109
 
 
110
 
static svn_error_t *
111
 
start_getloc(svn_ra_serf__xml_parser_t *parser,
112
 
             void *userData,
113
 
             svn_ra_serf__dav_props_t name,
114
 
             const char **attrs)
115
 
{
116
 
  loc_context_t *loc_ctx = userData;
117
 
 
118
 
  if (!loc_ctx->state && strcmp(name.name, "get-locations-report") == 0)
119
 
    {
120
 
      push_state(loc_ctx, REPORT);
121
 
    }
122
 
  else if (loc_ctx->state &&
123
 
           loc_ctx->state->state == REPORT &&
124
 
           strcmp(name.name, "location") == 0)
125
 
    {
126
 
      svn_revnum_t rev = SVN_INVALID_REVNUM;
127
 
      const char *revstr, *path;
128
 
 
129
 
      revstr = svn_xml_get_attr_value("rev", attrs);
130
 
      if (revstr)
131
 
        {
132
 
          rev = SVN_STR_TO_REV(revstr);
133
 
        }
134
 
 
135
 
      path = svn_xml_get_attr_value("path", attrs);
136
 
 
137
 
      if (SVN_IS_VALID_REVNUM(rev) && path)
138
 
        {
139
 
          apr_hash_set(loc_ctx->paths,
140
 
                       apr_pmemdup(loc_ctx->pool, &rev, sizeof(rev)),
141
 
                       sizeof(rev),
142
 
                       apr_pstrdup(loc_ctx->pool, path));
143
 
        }
144
 
    }
145
 
 
146
 
  return SVN_NO_ERROR;
147
 
}
148
 
 
149
 
static svn_error_t *
150
 
end_getloc(svn_ra_serf__xml_parser_t *parser,
151
 
           void *userData,
152
 
           svn_ra_serf__dav_props_t name)
153
 
{
154
 
  loc_context_t *loc_ctx = userData;
155
 
  loc_state_list_t *cur_state;
156
 
 
157
 
  if (!loc_ctx->state)
158
 
    {
159
 
      return SVN_NO_ERROR;
160
 
    }
161
 
 
162
 
  cur_state = loc_ctx->state;
163
 
 
164
 
  if (cur_state->state == REPORT &&
165
 
      strcmp(name.name, "get-locations-report") == 0)
166
 
    {
167
 
      pop_state(loc_ctx);
168
 
    }
169
 
  else if (cur_state->state == LOCATION &&
170
 
           strcmp(name.name, "location") == 0)
171
 
    {
172
 
      pop_state(loc_ctx);
173
 
    }
174
 
 
175
 
  return SVN_NO_ERROR;
176
 
}
 
78
/* Conforms to svn_ra_serf__xml_closed_t  */
 
79
static svn_error_t *
 
80
getloc_closed(svn_ra_serf__xml_estate_t *xes,
 
81
              void *baton,
 
82
              int leaving_state,
 
83
              const svn_string_t *cdata,
 
84
              apr_hash_t *attrs,
 
85
              apr_pool_t *scratch_pool)
 
86
{
 
87
  loc_context_t *loc_ctx = baton;
 
88
  const char *revstr;
 
89
  const char *path;
 
90
 
 
91
  SVN_ERR_ASSERT(leaving_state == LOCATION);
 
92
 
 
93
  revstr = svn_hash_gets(attrs, "rev");
 
94
  path = svn_hash_gets(attrs, "path");
 
95
  if (revstr != NULL && path != NULL)
 
96
    {
 
97
      svn_revnum_t rev = SVN_STR_TO_REV(revstr);
 
98
      apr_hash_set(loc_ctx->paths,
 
99
                   apr_pmemdup(loc_ctx->pool, &rev, sizeof(rev)), sizeof(rev),
 
100
                   apr_pstrdup(loc_ctx->pool, path));
 
101
    }
 
102
 
 
103
  return SVN_NO_ERROR;
 
104
}
 
105
 
177
106
 
178
107
/* Implements svn_ra_serf__request_body_delegate_t */
179
108
static svn_error_t *
228
157
  loc_context_t *loc_ctx;
229
158
  svn_ra_serf__session_t *session = ra_session->priv;
230
159
  svn_ra_serf__handler_t *handler;
231
 
  svn_ra_serf__xml_parser_t *parser_ctx;
232
 
  const char *relative_url, *basecoll_url, *req_url;
 
160
  svn_ra_serf__xml_context_t *xmlctx;
 
161
  const char *req_url;
233
162
  svn_error_t *err;
234
163
 
235
164
  loc_ctx = apr_pcalloc(pool, sizeof(*loc_ctx));
237
166
  loc_ctx->path = path;
238
167
  loc_ctx->peg_revision = peg_revision;
239
168
  loc_ctx->location_revisions = location_revisions;
240
 
  loc_ctx->done = FALSE;
241
169
  loc_ctx->paths = apr_hash_make(loc_ctx->pool);
242
170
 
243
171
  *locations = loc_ctx->paths;
244
172
 
245
 
  SVN_ERR(svn_ra_serf__get_baseline_info(&basecoll_url, &relative_url, session,
246
 
                                         NULL, NULL, peg_revision, NULL,
247
 
                                         pool));
248
 
 
249
 
  req_url = svn_path_url_add_component2(basecoll_url, relative_url, pool);
250
 
 
251
 
  handler = apr_pcalloc(pool, sizeof(*handler));
 
173
  SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
 
174
                                      session, NULL /* conn */,
 
175
                                      NULL /* url */, peg_revision,
 
176
                                      pool, pool));
 
177
 
 
178
  xmlctx = svn_ra_serf__xml_context_create(getloc_ttable,
 
179
                                           NULL, getloc_closed, NULL,
 
180
                                           loc_ctx,
 
181
                                           pool);
 
182
  handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
252
183
 
253
184
  handler->method = "REPORT";
254
185
  handler->path = req_url;
258
189
  handler->conn = session->conns[0];
259
190
  handler->session = session;
260
191
 
261
 
  parser_ctx = apr_pcalloc(pool, sizeof(*parser_ctx));
262
 
 
263
 
  parser_ctx->pool = pool;
264
 
  parser_ctx->user_data = loc_ctx;
265
 
  parser_ctx->start = start_getloc;
266
 
  parser_ctx->end = end_getloc;
267
 
  parser_ctx->status_code = &loc_ctx->status_code;
268
 
  parser_ctx->done = &loc_ctx->done;
269
 
 
270
 
  handler->response_handler = svn_ra_serf__handle_xml_parser;
271
 
  handler->response_baton = parser_ctx;
272
 
 
273
 
  svn_ra_serf__request_create(handler);
274
 
 
275
 
  err = svn_ra_serf__context_run_wait(&loc_ctx->done, session, pool);
 
192
  err = svn_ra_serf__context_run_one(handler, pool);
276
193
 
277
194
  SVN_ERR(svn_error_compose_create(
278
 
              svn_ra_serf__error_on_status(loc_ctx->status_code,
 
195
              svn_ra_serf__error_on_status(handler->sline,
279
196
                                           req_url,
280
 
                                           parser_ctx->location),
 
197
                                           handler->location),
281
198
              err));
282
199
 
283
200
  return SVN_NO_ERROR;