Sat, 02 May 2015 10:59:02 +0200
improved error messages
dav/main.c | file | annotate | diff | comparison | revisions | |
libidav/Makefile | file | annotate | diff | comparison | revisions | |
libidav/methods.c | file | annotate | diff | comparison | revisions | |
libidav/resource.c | file | annotate | diff | comparison | revisions | |
libidav/session.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.h | file | annotate | diff | comparison | revisions |
--- a/dav/main.c Sat Apr 04 20:37:03 2015 +0200 +++ b/dav/main.c Sat May 02 10:59:02 2015 +0200 @@ -132,11 +132,12 @@ fprintf( stderr, " set-property [-pc] [-n <uri>] <url> <property> [value]\n"); + fprintf(stderr, " info [-pc] <url>\n"); fprintf(stderr, " date [url]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, - " -k <key> Key to use for encryption or decryption\n"); + " -k <key> Key to use for encryption\n"); fprintf(stderr, " -p Don't encrypt or decrypt files\n"); fprintf(stderr, " -c Enable full encryption\n"); fprintf(stderr, @@ -233,10 +234,13 @@ if(url[ulen-1] == '/') { repo->url = strdup(url); *path = strdup("/"); - } else { + } else if (strchr(url, '/')) { repo->url = util_parent_path(url); // TODO: check/fix *path = strdup(util_resource_name(url)-1); + } else { + repo->url = strdup(url); + *path = strdup("/"); } } @@ -248,6 +252,9 @@ switch(sn->error) { default: { fprintf(stderr, "Operation failed for resource %s.\n", res_url); + if(sn->errorstr) { + fprintf(stderr, "%s\n", sn->errorstr); + } break; } case DAV_NOT_FOUND: { @@ -271,6 +278,35 @@ "Missing intermediate collections for resource %s.\n", res_url); } + case DAV_UNSUPPORTED_PROTOCOL: { + fprintf(stderr, "Unsupported protocol.\n"); + if(sn->errorstr) { + fprintf(stderr, "%s\n", sn->errorstr); + } + break; + } + case DAV_COULDNT_RESOLVE_PROXY: { + fprintf(stderr, "Cannot resolve proxy host.\n"); + break; + } + case DAV_COULDNT_RESOLVE_HOST: { + fprintf(stderr, "Cannot resolve host name.\n"); + break; + } + case DAV_COULDNT_CONNECT: { + fprintf(stderr, "Cannot connect to host.\n"); + break; + } + case DAV_TIMEOUT: { + fprintf(stderr, "Operation timed out.\n"); + break; + } + case DAV_SSL_ERROR: { + fprintf(stderr, "SSL error.\n"); + if(sn->errorstr) { + fprintf(stderr, "%s\n", sn->errorstr); + } + } } free(res_url); }
--- a/libidav/Makefile Sat Apr 04 20:37:03 2015 +0200 +++ b/libidav/Makefile Sat May 02 10:59:02 2015 +0200 @@ -35,6 +35,7 @@ SRC += methods.c SRC += utils.c SRC += davqlparser.c +SRC += davqlexec.c SRC += davql.c SRC += crypto.c
--- a/libidav/methods.c Sat Apr 04 20:37:03 2015 +0200 +++ b/libidav/methods.c Sat May 02 10:59:02 2015 +0200 @@ -52,8 +52,6 @@ headers = curl_slist_append(headers, "Depth: 1"); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); curl_easy_setopt(handle, CURLOPT_READDATA, request); @@ -443,8 +441,6 @@ headers = curl_slist_append(headers, "Content-Type: text/xml"); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); curl_easy_setopt(handle, CURLOPT_READDATA, request); @@ -611,7 +607,6 @@ curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); curl_easy_setopt(handle, CURLOPT_PUT, 1L); curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); // clear headers struct curl_slist *headers = NULL; @@ -653,7 +648,6 @@ curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(handle, CURLOPT_PUT, 0L); curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); @@ -669,7 +663,6 @@ curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); curl_easy_setopt(handle, CURLOPT_PUT, 0L); curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); @@ -683,7 +676,6 @@ curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD"); curl_easy_setopt(handle, CURLOPT_PUT, 0L); curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(handle, CURLOPT_NOBODY, 1L); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
--- a/libidav/resource.c Sat Apr 04 20:37:03 2015 +0200 +++ b/libidav/resource.c Sat May 02 10:59:02 2015 +0200 @@ -532,7 +532,6 @@ } curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); curl_easy_setopt(handle, CURLOPT_PUT, 0L); curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
--- a/libidav/session.c Sat Apr 04 20:37:03 2015 +0200 +++ b/libidav/session.c Sat May 02 10:59:02 2015 +0200 @@ -65,6 +65,8 @@ } sn->handle = curl_easy_init(); curl_easy_setopt(sn->handle, CURLOPT_FOLLOWLOCATION, 1L); + + curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); // TODO: remove // set proxy DavProxy *proxy = sstrprefix(url, S("https")) ? context->https_proxy @@ -137,7 +139,12 @@ void dav_session_set_error(DavSession *sn, CURLcode c, int status) { if(status > 0) { switch(status) { - default: sn->error = DAV_ERROR; break; + default: { + switch(c) { + default: sn->error = DAV_ERROR; + } + break; + } case 401: sn->error = DAV_UNAUTHORIZED; break; case 403: sn->error = DAV_FORBIDDEN; break; case 404: sn->error = DAV_NOT_FOUND; break; @@ -145,7 +152,25 @@ case 409: sn->error = DAV_CONFLICT; break; } } else { - sn->error = DAV_ERROR; + switch(c) { + case CURLE_UNSUPPORTED_PROTOCOL: sn->error = DAV_UNSUPPORTED_PROTOCOL; break; + case CURLE_COULDNT_RESOLVE_PROXY: sn->error = DAV_COULDNT_RESOLVE_PROXY; break; + case CURLE_COULDNT_RESOLVE_HOST: sn->error = DAV_COULDNT_RESOLVE_HOST; break; + case CURLE_COULDNT_CONNECT: sn->error = DAV_COULDNT_CONNECT; break; + case CURLE_OPERATION_TIMEDOUT: sn->error = DAV_TIMEOUT; break; + case CURLE_SSL_CONNECT_ERROR: + case CURLE_PEER_FAILED_VERIFICATION: + case CURLE_SSL_ENGINE_NOTFOUND: + case CURLE_SSL_ENGINE_SETFAILED: + case CURLE_SSL_CERTPROBLEM: + case CURLE_SSL_CIPHER: + case CURLE_SSL_CACERT: + case CURLE_SSL_CACERT_BADFILE: + case CURLE_SSL_SHUTDOWN_FAILED: + case CURLE_SSL_CRL_BADFILE: + case CURLE_SSL_ISSUER_ERROR: sn->error = DAV_SSL_ERROR; break; + default: sn->error = DAV_ERROR; break; + } } if(c != CURLE_OK) { sn->errorstr = curl_easy_strerror(c);
--- a/libidav/webdav.h Sat Apr 04 20:37:03 2015 +0200 +++ b/libidav/webdav.h Sat May 02 10:59:02 2015 +0200 @@ -63,7 +63,13 @@ DAV_UNAUTHORIZED, DAV_FORBIDDEN, DAV_METHOD_NOT_ALLOWED, - DAV_CONFLICT + DAV_CONFLICT, + DAV_UNSUPPORTED_PROTOCOL, + DAV_COULDNT_RESOLVE_PROXY, + DAV_COULDNT_RESOLVE_HOST, + DAV_COULDNT_CONNECT, + DAV_TIMEOUT, + DAV_SSL_ERROR }; typedef enum DavError DavError;