[PATCH] Make WebDAV XML parser namespace aware

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previous implementation ignored the XML namespaces, considering only
the local name.

Signed-off-by: Gabriel Corona <gabriel.corona@xxxxxxxxxxxxxxxx>
---
 http-push.c |   45 ++++++++++++++++-----------------------------
 1 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/http-push.c b/http-push.c
index c9bcd11..4ec3304 100644
--- a/http-push.c
+++ b/http-push.c
@@ -42,15 +42,15 @@ enum XML_Status {
 #define DAV_LOCK_OK (1u << 2)
 
 /* DAV XML properties */
-#define DAV_CTX_LOCKENTRY ".multistatus.response.propstat.prop.supportedlock.lockentry"
-#define DAV_CTX_LOCKTYPE_WRITE ".multistatus.response.propstat.prop.supportedlock.lockentry.locktype.write"
-#define DAV_CTX_LOCKTYPE_EXCLUSIVE ".multistatus.response.propstat.prop.supportedlock.lockentry.lockscope.exclusive"
-#define DAV_ACTIVELOCK_OWNER ".prop.lockdiscovery.activelock.owner.href"
-#define DAV_ACTIVELOCK_TIMEOUT ".prop.lockdiscovery.activelock.timeout"
-#define DAV_ACTIVELOCK_TOKEN ".prop.lockdiscovery.activelock.locktoken.href"
-#define DAV_PROPFIND_RESP ".multistatus.response"
-#define DAV_PROPFIND_NAME ".multistatus.response.href"
-#define DAV_PROPFIND_COLLECTION ".multistatus.response.propstat.prop.resourcetype.collection"
+#define DAV_CTX_LOCKENTRY "\tDAV: multistatus\tDAV: response\tDAV: propstat\tDAV: prop\tDAV: supportedlock\tDAV: lockentry"
+#define DAV_CTX_LOCKTYPE_WRITE "\tDAV: multistatus\tDAV: response\tDAV: propstat\tDAV: prop\tDAV: supportedlock\tDAV: lockentry\tDAV: locktype\tDAV: write"
+#define DAV_CTX_LOCKTYPE_EXCLUSIVE "\tDAV: multistatus\tDAV: response\tDAV: propstat\tDAV: prop\tDAV: supportedlock\tDAV: lockentry\tDAV: lockscope\tDAV: exclusive"
+#define DAV_ACTIVELOCK_OWNER "\tDAV: prop\tDAV: lockdiscovery\tDAV: activelock\tDAV: owner\tDAV: href"
+#define DAV_ACTIVELOCK_TIMEOUT "\tDAV: prop\tDAV: lockdiscovery\tDAV: activelock\tDAV: timeout"
+#define DAV_ACTIVELOCK_TOKEN "\tDAV: prop\tDAV: lockdiscovery\tDAV: activelock\tDAV: locktoken\tDAV: href"
+#define DAV_PROPFIND_RESP "\tDAV: multistatus\tDAV: response"
+#define DAV_PROPFIND_NAME "\tDAV: multistatus\tDAV: response\tDAV: href"
+#define DAV_PROPFIND_COLLECTION "\tDAV: multistatus\tDAV: response\tDAV: propstat\tDAV: prop\tDAV: resourcetype\tDAV: collection"
 
 /* DAV request body templates */
 #define PROPFIND_SUPPORTEDLOCK_REQUEST "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<D:propfind xmlns:D=\"DAV:\">\n<D:prop xmlns:R=\"%s\">\n<D:supportedlock/>\n</D:prop>\n</D:propfind>"
@@ -808,22 +808,16 @@ static void
 xml_start_tag(void *userData, const char *name, const char **atts)
 {
 	struct xml_ctx *ctx = (struct xml_ctx *)userData;
-	const char *c = strchr(name, ':');
 	int new_len;
 
-	if (c == NULL)
-		c = name;
-	else
-		c++;
-
-	new_len = strlen(ctx->name) + strlen(c) + 2;
+	new_len = strlen(ctx->name) + strlen(name) + 2;
 
 	if (new_len > ctx->len) {
 		ctx->name = xrealloc(ctx->name, new_len);
 		ctx->len = new_len;
 	}
-	strcat(ctx->name, ".");
-	strcat(ctx->name, c);
+	strcat(ctx->name, "\t");
+	strcat(ctx->name, name);
 
 	free(ctx->cdata);
 	ctx->cdata = NULL;
@@ -835,17 +829,10 @@ static void
 xml_end_tag(void *userData, const char *name)
 {
 	struct xml_ctx *ctx = (struct xml_ctx *)userData;
-	const char *c = strchr(name, ':');
 	char *ep;
 
 	ctx->userFunc(ctx, 1);
-
-	if (c == NULL)
-		c = name;
-	else
-		c++;
-
-	ep = ctx->name + strlen(ctx->name) - strlen(c) - 1;
+	ep = ctx->name + strlen(ctx->name) - strlen(name) - 1;
 	*ep = 0;
 }
 
@@ -934,7 +921,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
 	if (start_active_slot(slot)) {
 		run_active_slot(slot);
 		if (results.curl_result == CURLE_OK) {
-			XML_Parser parser = XML_ParserCreate(NULL);
+			XML_Parser parser = XML_ParserCreateNS(NULL, ' ');
 			enum XML_Status result;
 			ctx.name = xcalloc(10, 1);
 			ctx.len = 0;
@@ -1177,7 +1164,7 @@ static void remote_ls(const char *path, int flags,
 	if (start_active_slot(slot)) {
 		run_active_slot(slot);
 		if (results.curl_result == CURLE_OK) {
-			XML_Parser parser = XML_ParserCreate(NULL);
+			XML_Parser parser = XML_ParserCreateNS(NULL, ' ');
 			enum XML_Status result;
 			ctx.name = xcalloc(10, 1);
 			ctx.len = 0;
@@ -1260,7 +1247,7 @@ static int locking_available(void)
 	if (start_active_slot(slot)) {
 		run_active_slot(slot);
 		if (results.curl_result == CURLE_OK) {
-			XML_Parser parser = XML_ParserCreate(NULL);
+			XML_Parser parser = XML_ParserCreateNS(NULL, ' ');
 			enum XML_Status result;
 			ctx.name = xcalloc(10, 1);
 			ctx.len = 0;
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]