src/server/webdav/saxhandler.cpp

Sun, 26 Feb 2012 19:51:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 26 Feb 2012 19:51:14 +0100
changeset 26
37ff8bf54b89
parent 25
5dee29c7c530
child 29
e8619defde14
permissions
-rw-r--r--

Minimal webdav support

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2011 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../ucx/string.h"
#include "../ucx/dlist.h"
#include "../util/pool.h"

#include "saxhandler.h"

using namespace std;

PropfindHandler::PropfindHandler(PropfindRequest *rq, pool_handle_t *p) {
    davrq = rq;
    pool  = p;

    davPropTag = false;
    property = NULL;
}

PropfindHandler::~PropfindHandler() {
    
}

void PropfindHandler::startElement(
        const XMLCh *const uri,
        const XMLCh* const localname,
        const XMLCh* const qname,
        const Attributes& attrs)
{
    char *ns  = XMLString::transcode(uri);
    char *name = XMLString::transcode(localname);
    
    if(!strcmp(ns, "DAV:") && !strcmp(name, "prop")) {
        davPropTag = true;
    } else if(davPropTag && property == NULL) {
        //property = (DavProperty*)pool_malloc(pool, sizeof(DavProperty));
        property = (DavProperty*)malloc(sizeof(DavProperty));
        /* Ultra TODO: pool_malloc makes big mistakes!! */

        size_t nslen = strlen(ns);
        size_t namelen = strlen(name);
        if(nslen > 0) {
            property->xmlns = (char*)pool_malloc(pool, nslen + 1);
            property->xmlns[nslen] = 0;
            memcpy(property->xmlns, ns, nslen);
        } else {
            property->xmlns = NULL;
        }

        if(namelen > 0) {
            property->name = (char*)pool_malloc(pool, namelen + 1);
            property->name[namelen] = 0;
            memcpy(property->name, name, namelen);
        } else {
            property->name = NULL;
        }
    }

    XMLString::release(&ns);
    XMLString::release(&name);
}


void PropfindHandler::endElement(
        const XMLCh* const   uri,
        const XMLCh* const   localname,
        const XMLCh* const   qname)
{
    char *ns  = XMLString::transcode(uri);
    char *name = XMLString::transcode(localname);

    if(property != NULL) {
        const char *xmlns = (property->xmlns) ? property->xmlns : "";
        
        if(!strcmp(ns, xmlns) && !strcmp(name, property->name)) {
            // add property to DavRequest
            UcxDlist *elm = (UcxDlist*)pool_malloc(pool, sizeof(UcxDlist));
            elm->prev = NULL;
            elm->next = NULL;
            elm->data = property;
            //printf("saxhandler: add property: {%s}\n", property->name);
            davrq->properties = ucx_dlist_concat(davrq->properties, elm);
            
            property = NULL;
        }
    }

    XMLString::release(&ns);
    XMLString::release(&name);
}

void PropfindHandler::startDocument() {
    
}

void PropfindHandler::endDocument() {

}

mercurial