dav/utils.c

Fri, 30 Nov 2012 21:18:13 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 30 Nov 2012 21:18:13 +0100
changeset 1
1bcaac272cdf
child 3
323689ada09d
permissions
-rw-r--r--

added existing source code

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2012 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 <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucx/string.h>

#include "utils.h"


time_t parse_creationdate(char *str) {
    // TODO
    return 1234;
}

time_t parse_lastmodified(char *str) {
    // TODO
    return 1234;
}


char* util_url_path(char *url) { 
    char *path = NULL;
    int slashcount = 0;
    char c;
    int i = 0;
    while((c = url[i]) != 0) {
        if(c == '/') {
            slashcount++;
            if(slashcount == 3) {
                path = url + i;
                break;
            }
        }
        i++;
    } 
    return path;
}

char* util_resource_name(char *url) {
    int si = 0;
    int osi = 0;
    int i = 0;
    char c;
    while((c = url[i]) != 0) {
        if(c == '/') {
            osi = si;
            si = i;
        }
        i++;
    }
    
    char *name = url + si + 1;;
    if(name[0] == 0) {
        name = url + osi + 1;
        if(name[0 == 0]) {
            return url;
        }
    }
    
    return name;
}

char* util_child_url(char *base, char *path) {
    char *basepath = util_url_path(base);
    int baselen = basepath - base;
    int pathlen = strlen(path);
    
    int len = baselen + pathlen + 1;
    char *url = malloc(len);
    url[len - 1] = 0;
    url[len - 2] = 0;
    
    if(url == NULL) {
        return NULL;
    }
    
    memcpy(url, base, baselen);
    memcpy(url + baselen, path, pathlen);
    
    return url;
}

mercurial