On Thu, 26 Jan 2006 jerenkrantz@tigris.org wrote:
> Modified: trunk/subversion/libsvn_ra_serf/serf.c
> Url: http://svn.collab.net/viewcvs/svn/trunk/subversion/libsvn_ra_serf/serf.c?rev=18245&p1=trunk/subversion/libsvn_ra_serf/serf.c&p2=trunk/subversion/libsvn_ra_serf/serf.c&r1=18244&r2=18245
> ==============================================================================
> --- trunk/subversion/libsvn_ra_serf/serf.c (original)
> +++ trunk/subversion/libsvn_ra_serf/serf.c Thu Jan 26 01:45:11 2006
> @@ -20,6 +20,8 @@
>
> #include <apr_uri.h>
>
> +#include <expat.h>
> +
> #include <serf.h>
>
> #include "svn_pools.h"
> @@ -168,6 +170,12 @@
> const char *name;
> } dav_props_t;
>
> +typedef struct ns {
We usually use the same name for the struct tag and the typedef.
> + const char *namespace;
> + const char *val;
There is no documentation, but I guess the namespace field is the
namespace identifier (i.e. DAV in DAV:blah) and the val field is the
namespace URI. Is that correct?
> + struct ns *next;
> +} ns_t;
> +
> static const char *
> fetch_prop (apr_hash_t *props,
> const char *path,
> @@ -265,9 +273,127 @@
> const dav_props_t *find_props;
> apr_hash_t *ret_props;
>
> + XML_Parser xmlp;
> + ns_t *ns_list;
We have a wrapper for expat in svn_xml.h that gives us some error
handling. Maybe use that (and extend it with namespace support)?
> +
> +static void XMLCALL
> +start_propfind(void *userData, const char *name, const char **attrs)
> +{
> + propfind_context_t *ctx = userData;
> + const char *ns;
> + char *colon;
> +
> + /* check for new namespaces */
> + while (*attrs)
> + {
> + if (strncmp(*attrs, "xmlns", 5) == 0)
> + {
> + const char *attr, *attr_val;
> + attr = attrs[0] + 6;
Woops, this will point at garbage if the attribute name is just xmlns.
> + attr_val = attrs[1];
> + define_ns(ctx, attr, attr_val);
OK, so val is the URI. Might choose a better name.
> + }
> + attrs += 2;
> + }
> +
> + colon = strchr(name, ':');
> + if (colon)
> + {
> + /* look up name space */
> + *colon = '\0';
> + ns = expand_ns(ctx, name);
> + if (!ns)
> + {
> + abort();
> + }
> + name = colon + 1;
> + }
> + else
> + {
> + /* default namespace */
> + ns = "";
Do DAV prohibit declaring another default namespace or something?
> + }
> +
> + if (ctx->in_prop && !ctx->name)
> + {
> + ctx->ns = ns;
> + ctx->name = apr_pstrdup(ctx->pool, name);
> + /* we want to flag the cdata handler to pick up what's next. */
> + ctx->collect_cdata = 1;
s/1/TRUE/
> + }
> +
> + /* check for 'prop' */
> + if (!ctx->in_prop && strcasecmp(name, "prop") == 0)
No my DAV ingorance shines through:-(, but are names case-insensitive in
DAV?
> + {
> + ctx->in_prop = 1;
Same about the bool. Here and further down, so I don't note them all.
> + }
> +}
> +
> +static void XMLCALL
> +end_propfind(void *userData, const char *name)
> +{
> + propfind_context_t *ctx = userData;
> + if (ctx->collect_cdata)
> + {
> + if (ctx->val)
> + {
> + set_prop(ctx->ret_props, ctx->path, ctx->ns, ctx->name, ctx->val,
> + ctx->pool);
> + }
> + ctx->collect_cdata = 0;
> + ctx->name = NULL;
> + ctx->val = NULL;
> + }
> +}
> +
To be correct, you need to pop the namespaces of this element, but you
know that. (I also saw the comment about the state of this code in the
log message about check-pointing).
> +static void XMLCALL
> +cdata_propfind(void *userData, const char *data, int len)
> +{
> + propfind_context_t *ctx = userData;
> + if (ctx->collect_cdata)
> + {
> + ctx->val = apr_pstrndup(ctx->pool, data, len);
> + }
> +
expat doesn't guarantee that CDATA in an element come in one chunk, so you
need to collect the CDATA from consecutive calls.
> +}
> +
Best,
//Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Jan 26 16:50:03 2006