dav/error.c

Sun, 05 Jul 2020 11:47:24 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 05 Jul 2020 11:47:24 +0200
branch
feature/dav-edit
changeset 721
c401f4af44b1
parent 364
3769ba002fd1
child 747
efbd59642577
permissions
-rw-r--r--

adds support for option terminator '--'

also adds support for option arguments within the same cmd arg
e.g. -omyoutfile does now work

191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
364
3769ba002fd1 updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
32 #include <libidav/utils.h>
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "error.h"
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 void print_resource_error(DavSession *sn, char *path) {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 char *res_url = util_concat_path(sn->base_url, path);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 switch(sn->error) {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 default: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 fprintf(stderr, "Operation failed for resource %s.\n", res_url);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 if(sn->errorstr) {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 fprintf(stderr, "%s\n", sn->errorstr);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 case DAV_NOT_FOUND: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 fprintf(stderr, "Resource %s not found.\n", res_url);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 case DAV_UNAUTHORIZED: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 fprintf(stderr, "Authentication required.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 }
238
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
54 case DAV_PROXY_AUTH_REQUIRED: {
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
55 fprintf(stderr, "Proxy authentication required.\n");
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
56 break;
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
57 }
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
58 case DAV_NET_AUTH_REQUIRED: {
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
59 fprintf(stderr, "Network authentication required.\n");
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
60 break;
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
61 }
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 case DAV_FORBIDDEN: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 fprintf(stderr, "Access forbidden.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 case DAV_METHOD_NOT_ALLOWED: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 fprintf(stderr, "Method not allowed.\n");
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
68 break;
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 case DAV_CONFLICT: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 fprintf(
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 stderr,
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 "Missing intermediate collections for resource %s.\n",
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 res_url);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
75 break;
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
77 case DAV_LOCKED: {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
78 fprintf(
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
79 stderr,
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
80 "Resource is locked.\n");
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
81 break;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
82 }
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 case DAV_UNSUPPORTED_PROTOCOL: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 fprintf(stderr, "Unsupported protocol.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 if(sn->errorstr) {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 fprintf(stderr, "%s\n", sn->errorstr);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 case DAV_COULDNT_RESOLVE_PROXY: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 fprintf(stderr, "Cannot resolve proxy host.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 case DAV_COULDNT_RESOLVE_HOST: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 fprintf(stderr, "Cannot resolve host name.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 case DAV_COULDNT_CONNECT: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 fprintf(stderr, "Cannot connect to host.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 case DAV_TIMEOUT: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 fprintf(stderr, "Operation timed out.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 break;
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 case DAV_SSL_ERROR: {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 fprintf(stderr, "SSL error.\n");
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 if(sn->errorstr) {
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 fprintf(stderr, "%s\n", sn->errorstr);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
111 break;
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
113 case DAV_CONTENT_VERIFICATION_ERROR: {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
114 fprintf(
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
115 stderr,
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
116 "Content checksum verification failed for resource %s.\n",
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
117 res_url);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
118 break;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
119 }
238
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
120 case DAV_REQUEST_ENTITY_TOO_LARGE: {
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
121 fprintf(stderr, "Request entity too large.\n");
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
122 break;
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
123 }
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
124 case DAV_REQUEST_URL_TOO_LONG: {
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
125 fprintf(stderr, "Request URL too long.\n");
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
126 break;
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
127 }
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 free(res_url);
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }

mercurial