dav/main.c

changeset 13
8a0cc4d90de7
parent 12
493128ef1b12
child 14
d1a43035d3a2
equal deleted inserted replaced
12:493128ef1b12 13:8a0cc4d90de7
130 130
131 *root = strdup(url); 131 *root = strdup(url);
132 *path = strdup("/"); 132 *path = strdup("/");
133 } 133 }
134 134
135 void print_resource_error(DavSession *sn, DavResource *res) {
136 char *res_url = util_concat_path(sn->base_url, res->path);
137 switch(sn->error) {
138 default: {
139 fprintf(stderr, "Cannot get resource %s.\n", res_url);
140 break;
141 }
142 case DAV_NOT_FOUND: {
143 fprintf(stderr, "Resource %s not found.\n", res_url);
144 break;
145 }
146 case DAV_UNAUTHORIZED: {
147 fprintf(stderr, "Authentication required.\n");
148 break;
149 }
150 case DAV_FORBIDDEN: {
151 fprintf(stderr, "Access forbidden.\n");
152 break;
153 }
154 }
155 free(res_url);
156 }
157
135 158
136 int cmd_list(CmdArgs *a) { 159 int cmd_list(CmdArgs *a) {
137 if(a->argc == 0) { 160 if(a->argc == 0) {
138 return -1; 161 return -1;
139 } 162 }
153 176
154 //printf("baseurl: %s\n", sn->base_url); 177 //printf("baseurl: %s\n", sn->base_url);
155 178
156 DavResource *ls = dav_get(sn, path, NULL); 179 DavResource *ls = dav_get(sn, path, NULL);
157 if(!ls) { 180 if(!ls) {
158 fprintf(stderr, "error\n"); 181 print_resource_error(sn, ls);
159 return -1; 182 return -1;
160 } 183 }
161 DavResource *child = ls->children; 184 DavResource *child = ls->children;
162 while(child) { 185 while(child) {
163 printf("%s\n", child->name); 186 printf("%s\n", child->name);
185 sn = dav_session_new(ctx, root); 208 sn = dav_session_new(ctx, root);
186 } 209 }
187 210
188 DavResource *res = dav_get(sn, path, "U:crypto-key"); 211 DavResource *res = dav_get(sn, path, "U:crypto-key");
189 if(!res) { 212 if(!res) {
190 fprintf(stderr, "error\n"); 213 print_resource_error(sn, res);
191 return -1; 214 return -1;
192 } 215 }
193 216
194 /* 217 /*
195 * determine the output file 218 * determine the output file
314 } else { 337 } else {
315 dav_set_content(res, in, (dav_read_func)fread); 338 dav_set_content(res, in, (dav_read_func)fread);
316 } 339 }
317 340
318 if(dav_store(res)) { 341 if(dav_store(res)) {
319 fprintf(stderr, "cannot upload file\n"); 342 print_resource_error(sn, res);
343 fprintf(stderr, "Cannot upload file.\n");
320 fclose(in); 344 fclose(in);
321 return -1; 345 return -1;
322 } 346 }
323 if(enc) { 347 if(enc) {
324 aes_encrypter_close(enc); 348 aes_encrypter_close(enc);

mercurial