You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/05/13 06:48:51 UTC

svn commit: r1337777 - /subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c

Author: gstein
Date: Sun May 13 04:48:50 2012
New Revision: 1337777

URL: http://svn.apache.org/viewvc?rev=1337777&view=rev
Log:
Switch over to the new xml parsing context.

* subversion/libsvn_ra_serf/get_deleted_rev.c:
  (drev_state_e): drop the typedef. rename NONE to INITIAL. add REPORT.
  (drev_context_t): remove POOL and DONE members
  (getdrev_ttable): new transition table
  (push_state, start_getdrev, end_getdrev, cdata_getdrev): removed; obsolete.
  (getdrev_closed): new callback to collect the data
  (svn_ra_serf__get_deleted_rev): drop the old parsing stuff and
    switch to the new v2 system. switch to run_one()

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c?rev=1337777&r1=1337776&r2=1337777&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/get_deleted_rev.c Sun May 13 04:48:50 2012
@@ -35,14 +35,13 @@
 /*
  * This enum represents the current state of our XML parsing for a REPORT.
  */
-typedef enum drev_state_e {
-  NONE = 0,
+enum drev_state_e {
+  INITIAL = 0,
+  REPORT,
   VERSION_NAME
-} drev_state_e;
+};
 
 typedef struct drev_context_t {
-  apr_pool_t *pool;
-
   const char *path;
   svn_revnum_t peg_revision;
   svn_revnum_t end_revision;
@@ -51,92 +50,41 @@ typedef struct drev_context_t {
      the range PEG_REVISION-END-END_REVISION? */
   svn_revnum_t *revision_deleted;
 
-  /* are we done? */
-  svn_boolean_t done;
-
 } drev_context_t;
 
-
-static void
-push_state(svn_ra_serf__xml_parser_t *parser,
-           drev_context_t *drev_ctx,
-           drev_state_e state)
-{
-  svn_ra_serf__xml_push_state(parser, state);
-
-  if (state == VERSION_NAME)
-    parser->state->private = NULL;
-}
-
-static svn_error_t *
-start_getdrev(svn_ra_serf__xml_parser_t *parser,
-              svn_ra_serf__dav_props_t name,
-              const char **attrs,
-              apr_pool_t *scratch_pool)
-{
-  drev_context_t *drev_ctx = parser->user_data;
-  drev_state_e state;
-
-  state = parser->state->current_state;
+#define D_ "DAV:"
+#define S_ SVN_XML_NAMESPACE
+static const svn_ra_serf__xml_transition_t getdrev_ttable[] = {
+  { INITIAL, S_, "get-deleted-rev-report", REPORT,
+    FALSE, { NULL }, FALSE, FALSE },
 
-  if (state == NONE &&
-      strcmp(name.name, SVN_DAV__VERSION_NAME) == 0)
-    {
-      push_state(parser, drev_ctx, VERSION_NAME);
-    }
+  { REPORT, D_, SVN_DAV__VERSION_NAME, VERSION_NAME,
+    TRUE, { NULL }, FALSE, TRUE },
 
-  return SVN_NO_ERROR;
-}
-
-static svn_error_t *
-end_getdrev(svn_ra_serf__xml_parser_t *parser,
-            svn_ra_serf__dav_props_t name,
-            apr_pool_t *scratch_pool)
-{
-  drev_context_t *drev_ctx = parser->user_data;
-  drev_state_e state;
-  svn_string_t *info;
-
-  state = parser->state->current_state;
-  info = parser->state->private;
-
-  if (state == VERSION_NAME &&
-      strcmp(name.name, SVN_DAV__VERSION_NAME) == 0 &&
-      info)
-    {
-      *drev_ctx->revision_deleted = SVN_STR_TO_REV(info->data);
-      svn_ra_serf__xml_pop_state(parser);
-    }
-
-  return SVN_NO_ERROR;
-}
+  { 0 }
+};
 
+
+/* Conforms to svn_ra_serf__xml_closed_t  */
 static svn_error_t *
-cdata_getdrev(svn_ra_serf__xml_parser_t *parser,
-              const char *data,
-              apr_size_t len,
-              apr_pool_t *scratch_pool)
+getdrev_closed(svn_ra_serf__xml_estate_t *xes,
+               void *baton,
+               int leaving_state,
+               const svn_string_t *cdata,
+               apr_hash_t *attrs,
+               apr_pool_t *scratch_pool)
 {
-  drev_context_t *drev_ctx = parser->user_data;
-  drev_state_e state;
+  drev_context_t *drev_ctx = baton;
 
-  UNUSED_CTX(drev_ctx);
+  SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
+  SVN_ERR_ASSERT(cdata != NULL);
 
-  state = parser->state->current_state;
-  switch (state)
-    {
-    case VERSION_NAME:
-        /* ### wrong. we might not have all the cdata!  */
-        parser->state->private = svn_string_ncreate(data, len,
-                                                    parser->state->pool);
-        break;
-    default:
-        break;
-    }
+  *drev_ctx->revision_deleted = SVN_STR_TO_REV(cdata->data);
 
   return SVN_NO_ERROR;
 }
 
+
 /* Implements svn_ra_serf__request_body_delegate_t */
 static svn_error_t *
 create_getdrev_body(serf_bucket_t **body_bkt,
@@ -187,7 +135,7 @@ svn_ra_serf__get_deleted_rev(svn_ra_sess
   drev_context_t *drev_ctx;
   svn_ra_serf__session_t *ras = session->priv;
   svn_ra_serf__handler_t *handler;
-  svn_ra_serf__xml_parser_t *parser_ctx;
+  svn_ra_serf__xml_context_t *xmlctx;
   const char *req_url;
   svn_error_t *err;
 
@@ -195,38 +143,27 @@ svn_ra_serf__get_deleted_rev(svn_ra_sess
   drev_ctx->path = path;
   drev_ctx->peg_revision = peg_revision;
   drev_ctx->end_revision = end_revision;
-  drev_ctx->pool = pool;
   drev_ctx->revision_deleted = revision_deleted;
-  drev_ctx->done = FALSE;
 
   SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
                                       ras, NULL /* conn */,
                                       NULL /* url */, peg_revision,
                                       pool, pool));
 
-  parser_ctx = apr_pcalloc(pool, sizeof(*parser_ctx));
-  parser_ctx->pool = pool;
-  parser_ctx->user_data = drev_ctx;
-  parser_ctx->start = start_getdrev;
-  parser_ctx->end = end_getdrev;
-  parser_ctx->cdata = cdata_getdrev;
-  parser_ctx->done = &drev_ctx->done;
+  xmlctx = svn_ra_serf__xml_context_create(getdrev_ttable,
+                                           NULL, getdrev_closed, drev_ctx,
+                                           pool);
+  handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
 
-  handler = apr_pcalloc(pool, sizeof(*handler));
-  handler->handler_pool = pool;
   handler->method = "REPORT";
   handler->path = req_url;
   handler->body_type = "text/xml";
-  handler->response_handler = svn_ra_serf__handle_xml_parser;
   handler->body_delegate = create_getdrev_body;
   handler->body_delegate_baton = drev_ctx;
   handler->conn = ras->conns[0];
   handler->session = ras;
-  handler->response_baton = parser_ctx;
 
-  svn_ra_serf__request_create(handler);
-
-  err = svn_ra_serf__context_run_wait(&drev_ctx->done, ras, pool);
+  err = svn_ra_serf__context_run_one(handler, pool);
 
   /* Map status 501: Method Not Implemented to our not implemented error.
      1.5.x servers and older don't support this report. */
@@ -235,5 +172,6 @@ svn_ra_serf__get_deleted_rev(svn_ra_sess
                              _("'%s' REPORT not implemented"),
                              "get-deleted-rev");
   SVN_ERR(err);
+
   return SVN_NO_ERROR;
 }