29 #include <time.h> |
29 #include <time.h> |
30 #include <stdio.h> |
30 #include <stdio.h> |
31 #include <stdlib.h> |
31 #include <stdlib.h> |
32 #include <string.h> |
32 #include <string.h> |
33 #include <ucx/string.h> |
33 #include <ucx/string.h> |
|
34 #include <libxml/tree.h> |
|
35 #include <curl/curl.h> |
34 |
36 |
35 #include "utils.h" |
37 #include "utils.h" |
36 |
38 |
37 |
39 |
38 time_t parse_creationdate(char *str) { |
40 time_t util_parse_creationdate(char *str) { |
39 // example: 2012-11-29T21:35:35Z |
41 // example: 2012-11-29T21:35:35Z |
40 |
42 if(!str) { |
|
43 return 0; |
|
44 } |
41 // TODO |
45 // TODO |
42 return 1234; |
46 return 0; |
43 } |
47 } |
44 |
48 |
45 time_t parse_lastmodified(char *str) { |
49 time_t util_parse_lastmodified(char *str) { |
46 // example: Thu, 29 Nov 2012 21:35:35 GMT |
50 // example: Thu, 29 Nov 2012 21:35:35 GMT |
47 |
51 if(!str) { |
48 // TODO |
52 return 0; |
49 return 1234; |
53 } else { |
|
54 return curl_getdate(str, NULL); |
|
55 } |
50 } |
56 } |
51 |
57 |
|
58 int util_getboolean(char *v) { |
|
59 if(v[0] == 'T' || v[0] == 't') { |
|
60 return 1; |
|
61 } |
|
62 return 0; |
|
63 } |
52 |
64 |
53 char* util_url_path(char *url) { |
65 char* util_url_path(char *url) { |
54 char *path = NULL; |
66 char *path = NULL; |
55 int slashcount = 0; |
67 int slashcount = 0; |
56 char c; |
68 char c; |
90 } |
102 } |
91 |
103 |
92 return name; |
104 return name; |
93 } |
105 } |
94 |
106 |
95 char* util_child_url(char *base, char *path) { |
107 char* util_concat_path(char *url_base, char *p) { |
96 char *basepath = util_url_path(base); |
108 sstr_t base = sstr(url_base); |
97 int baselen = basepath - base; |
109 sstr_t path; |
98 int pathlen = strlen(path); |
110 if(p) { |
99 |
111 path = sstr(p); |
100 int len = baselen + pathlen + 1; |
112 } else { |
101 char *url = malloc(len); |
113 path = sstrn("", 0); |
102 url[len - 1] = 0; |
|
103 url[len - 2] = 0; |
|
104 |
|
105 if(url == NULL) { |
|
106 return NULL; |
|
107 } |
114 } |
108 |
115 |
109 memcpy(url, base, baselen); |
116 int add_separator = 0; |
110 memcpy(url + baselen, path, pathlen); |
117 if(base.ptr[base.length-1] == '/') { |
111 |
118 if(path.ptr[0] == '/') { |
112 return url; |
119 base.length--; |
113 } |
120 } |
114 |
121 } else { |
115 char* util_upload_url(char *url, char *filepath) { |
122 if(path.length == 0 || path.ptr[0] != '/') { |
116 int urllen = strlen(url); |
123 add_separator = 1; |
117 int filepathlen = strlen(filepath); |
|
118 |
|
119 for(int i=filepathlen-1;i>=0;i--) { |
|
120 if(filepath[i] == '/') { |
|
121 filepath = filepath + i + 1; |
|
122 break; |
|
123 } |
124 } |
124 } |
125 } |
125 |
126 |
126 int pathlen = urllen + filepathlen; |
127 sstr_t url; |
127 char *path = malloc(pathlen + 2); |
128 url.length = base.length + path.length + add_separator; |
|
129 url.ptr = malloc(url.length + 1); |
|
130 url.ptr[url.length] = '\0'; |
128 |
131 |
129 int j = urllen; |
132 if(add_separator) { |
130 memcpy(path, url, urllen); |
133 url = sstrncat(url, 3, base, sstr("/"), path); |
131 if(url[urllen - 1] != '/') { |
134 } else { |
132 path[j] = '/'; |
135 url = sstrncat(url, 2, base, path); |
133 j++; |
|
134 } |
136 } |
135 memcpy(path + j, filepath, filepathlen); |
|
136 j += filepathlen; |
|
137 path[j] = 0; |
|
138 |
137 |
139 return path; |
138 return url.ptr; |
140 } |
139 } |
141 |
140 |
|
141 |
|
142 char* util_xml_get_text(xmlNode *elm) { |
|
143 xmlNode *node = elm->children; |
|
144 while(node) { |
|
145 if(node->type == XML_TEXT_NODE) { |
|
146 return (char*)node->content; |
|
147 } |
|
148 node = node->next; |
|
149 } |
|
150 return NULL; |
|
151 } |
|
152 |