|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2012 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #include <time.h> |
|
30 #include <stdio.h> |
|
31 #include <stdlib.h> |
|
32 #include <string.h> |
|
33 #include <ucx/string.h> |
|
34 |
|
35 #include "utils.h" |
|
36 |
|
37 |
|
38 time_t parse_creationdate(char *str) { |
|
39 // TODO |
|
40 return 1234; |
|
41 } |
|
42 |
|
43 time_t parse_lastmodified(char *str) { |
|
44 // TODO |
|
45 return 1234; |
|
46 } |
|
47 |
|
48 |
|
49 char* util_url_path(char *url) { |
|
50 char *path = NULL; |
|
51 int slashcount = 0; |
|
52 char c; |
|
53 int i = 0; |
|
54 while((c = url[i]) != 0) { |
|
55 if(c == '/') { |
|
56 slashcount++; |
|
57 if(slashcount == 3) { |
|
58 path = url + i; |
|
59 break; |
|
60 } |
|
61 } |
|
62 i++; |
|
63 } |
|
64 return path; |
|
65 } |
|
66 |
|
67 char* util_resource_name(char *url) { |
|
68 int si = 0; |
|
69 int osi = 0; |
|
70 int i = 0; |
|
71 char c; |
|
72 while((c = url[i]) != 0) { |
|
73 if(c == '/') { |
|
74 osi = si; |
|
75 si = i; |
|
76 } |
|
77 i++; |
|
78 } |
|
79 |
|
80 char *name = url + si + 1;; |
|
81 if(name[0] == 0) { |
|
82 name = url + osi + 1; |
|
83 if(name[0 == 0]) { |
|
84 return url; |
|
85 } |
|
86 } |
|
87 |
|
88 return name; |
|
89 } |
|
90 |
|
91 char* util_child_url(char *base, char *path) { |
|
92 char *basepath = util_url_path(base); |
|
93 int baselen = basepath - base; |
|
94 int pathlen = strlen(path); |
|
95 |
|
96 int len = baselen + pathlen + 1; |
|
97 char *url = malloc(len); |
|
98 url[len - 1] = 0; |
|
99 url[len - 2] = 0; |
|
100 |
|
101 if(url == NULL) { |
|
102 return NULL; |
|
103 } |
|
104 |
|
105 memcpy(url, base, baselen); |
|
106 memcpy(url + baselen, path, pathlen); |
|
107 |
|
108 return url; |
|
109 } |