subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r1337779 - /subversion/trunk/subversion/libsvn_ra_serf/getdate.c
Date Sun, 13 May 2012 05:09:39 GMT
Author: gstein
Date: Sun May 13 05:09:38 2012
New Revision: 1337779

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

* subversion/libsvn_ra_serf/getdate.c:
  (date_state_e): drop the typedef. rename NONE to INITIAL. add the
    REPORT state.
  (date_context_t): drop the DONE member
  (date_ttable): new transition table
  (start_getdate, end_getdata, cdata_getdate): removed. obsolete.
  (svn_ra_serf__get_dated_revision): drop old parsing stuff. switch to
    the new parser. use run_one().

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

Modified: subversion/trunk/subversion/libsvn_ra_serf/getdate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/getdate.c?rev=1337779&r1=1337778&r2=1337779&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/getdate.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/getdate.c Sun May 13 05:09:38 2012
@@ -43,10 +43,11 @@
 /*
  * This enum represents the current state of our XML parsing for a REPORT.
  */
-typedef enum date_state_e {
-  NONE = 0,
+enum date_state_e {
+  INITIAL = 0,
+  REPORT,
   VERSION_NAME
-} date_state_e;
+};
 
 
 typedef struct date_context_t {
@@ -56,79 +57,41 @@ typedef struct date_context_t {
   /* What was the youngest revision at that time? */
   svn_revnum_t *revision;
 
-  /* are we done? */
-  svn_boolean_t done;
-
 } date_context_t;
 
+#define D_ "DAV:"
+#define S_ SVN_XML_NAMESPACE
+static const svn_ra_serf__xml_transition_t date_ttable[] = {
+  { INITIAL, S_, "dated-rev-report", REPORT,
+    FALSE, { NULL }, FALSE, FALSE },
 
-static svn_error_t *
-start_getdate(svn_ra_serf__xml_parser_t *parser,
-              svn_ra_serf__dav_props_t name,
-              const char **attrs,
-              apr_pool_t *scratch_pool)
-{
-  date_context_t *date_ctx = parser->user_data;
-  date_state_e state = parser->state->current_state;
+  { REPORT, D_, SVN_DAV__VERSION_NAME, VERSION_NAME,
+    TRUE, { NULL }, FALSE, TRUE },
 
-  UNUSED_CTX(date_ctx);
+  { 0 }
+};
 
-  if (state == NONE &&
-      strcmp(name.name, SVN_DAV__VERSION_NAME) == 0)
-    {
-      svn_ra_serf__xml_push_state(parser, VERSION_NAME);
-
-      parser->state->private = svn_stringbuf_create_empty(parser->state->pool);
-    }
-
-  return SVN_NO_ERROR;
-}
 
+/* Conforms to svn_ra_serf__xml_closed_t  */
 static svn_error_t *
-end_getdate(svn_ra_serf__xml_parser_t *parser,
-            svn_ra_serf__dav_props_t name,
+date_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)
 {
-  date_context_t *date_ctx = parser->user_data;
-  date_state_e state = parser->state->current_state;
-
-  if (state == VERSION_NAME &&
-      strcmp(name.name, SVN_DAV__VERSION_NAME) == 0)
-    {
-      const svn_stringbuf_t *datebuf = parser->state->private;
-
-      *date_ctx->revision = SVN_STR_TO_REV(datebuf->data);
-      svn_ra_serf__xml_pop_state(parser);
-    }
+  date_context_t *date_ctx = baton;
 
-  return SVN_NO_ERROR;
-}
+  SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
+  SVN_ERR_ASSERT(cdata != NULL);
 
-static svn_error_t *
-cdata_getdate(svn_ra_serf__xml_parser_t *parser,
-              const char *data,
-              apr_size_t len,
-              apr_pool_t *scratch_pool)
-{
-  date_context_t *date_ctx = parser->user_data;
-  date_state_e state = parser->state->current_state;
-  svn_stringbuf_t *datebuf;
-
-  UNUSED_CTX(date_ctx);
-
-  switch (state)
-    {
-    case VERSION_NAME:
-        datebuf = parser->state->private;
-        svn_stringbuf_appendbytes(datebuf, data, len);
-        break;
-    default:
-        break;
-    }
+  *date_ctx->revision = SVN_STR_TO_REV(cdata->data);
 
   return SVN_NO_ERROR;
 }
 
+
 /* Implements svn_ra_serf__request_body_delegate_t */
 static svn_error_t *
 create_getdate_body(serf_bucket_t **body_bkt,
@@ -166,45 +129,32 @@ svn_ra_serf__get_dated_revision(svn_ra_s
   date_context_t *date_ctx;
   svn_ra_serf__session_t *session = ra_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 *report_target;
 
   date_ctx = apr_palloc(pool, sizeof(*date_ctx));
   date_ctx->time = tm;
   date_ctx->revision = revision;
-  date_ctx->done = FALSE;
 
   SVN_ERR(svn_ra_serf__report_resource(&report_target, session, NULL, pool));
 
-  handler = apr_pcalloc(pool, sizeof(*handler));
+  xmlctx = svn_ra_serf__xml_context_create(date_ttable,
+                                           NULL, date_closed, date_ctx,
+                                           pool);
+  handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
 
-  handler->handler_pool = pool;
   handler->method = "REPORT";
   handler->path = report_target;
   handler->body_type = "text/xml";
   handler->conn = session->conns[0];
   handler->session = session;
 
-  parser_ctx = apr_pcalloc(pool, sizeof(*parser_ctx));
-
-  parser_ctx->pool = pool;
-  parser_ctx->user_data = date_ctx;
-  parser_ctx->start = start_getdate;
-  parser_ctx->end = end_getdate;
-  parser_ctx->cdata = cdata_getdate;
-  parser_ctx->done = &date_ctx->done;
-
   handler->body_delegate = create_getdate_body;
   handler->body_delegate_baton = date_ctx;
 
-  handler->response_handler = svn_ra_serf__handle_xml_parser;
-  handler->response_baton = parser_ctx;
-
-  svn_ra_serf__request_create(handler);
-
   *date_ctx->revision = SVN_INVALID_REVNUM;
 
   /* ### use svn_ra_serf__error_on_status() ?  */
 
-  return svn_ra_serf__context_run_wait(&date_ctx->done, session, pool);
+  return svn_error_trace(svn_ra_serf__context_run_one(handler, pool));
 }



Mime
View raw message