UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2018 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 <stdio.h> 30 #include <stdlib.h> 31 32 #include <libidav/utils.h> 33 34 #include "error.h" 35 36 void print_resource_error(DavSession *sn, const char *path) { 37 print_resource_error_to_file(stderr, sn, path); 38 } 39 40 void print_resource_error_to_file(FILE *file, DavSession *sn, const char *path) { 41 char *res_url = util_concat_path(sn->base_url, path); 42 switch(sn->error) { 43 default: { 44 fprintf(file, "Operation failed for resource %s.\n", res_url); 45 if(sn->errorstr) { 46 fprintf(file, "%s\n", sn->errorstr); 47 } 48 break; 49 } 50 case DAV_NOT_FOUND: { 51 fprintf(file, "Resource %s not found.\n", res_url); 52 break; 53 } 54 case DAV_UNAUTHORIZED: { 55 fprintf(file, "Authentication required.\n"); 56 break; 57 } 58 case DAV_PROXY_AUTH_REQUIRED: { 59 fprintf(file, "Proxy authentication required.\n"); 60 break; 61 } 62 case DAV_NET_AUTH_REQUIRED: { 63 fprintf(file, "Network authentication required.\n"); 64 break; 65 } 66 case DAV_FORBIDDEN: { 67 fprintf(file, "Access forbidden.\n"); 68 break; 69 } 70 case DAV_METHOD_NOT_ALLOWED: { 71 fprintf(file, "Method not allowed.\n"); 72 break; 73 } 74 case DAV_CONFLICT: { 75 fprintf( 76 stderr, 77 "Missing intermediate collections for resource %s.\n", 78 res_url); 79 break; 80 } 81 case DAV_LOCKED: { 82 fprintf( 83 stderr, 84 "Resource is locked.\n"); 85 break; 86 } 87 case DAV_UNSUPPORTED_PROTOCOL: { 88 fprintf(file, "Unsupported protocol.\n"); 89 if(sn->errorstr) { 90 fprintf(file, "%s\n", sn->errorstr); 91 } 92 break; 93 } 94 case DAV_COULDNT_RESOLVE_PROXY: { 95 fprintf(file, "Cannot resolve proxy host.\n"); 96 break; 97 } 98 case DAV_COULDNT_RESOLVE_HOST: { 99 fprintf(file, "Cannot resolve host name.\n"); 100 break; 101 } 102 case DAV_COULDNT_CONNECT: { 103 fprintf(file, "Cannot connect to host.\n"); 104 break; 105 } 106 case DAV_TIMEOUT: { 107 fprintf(file, "Operation timed out.\n"); 108 break; 109 } 110 case DAV_SSL_ERROR: { 111 fprintf(file, "SSL error.\n"); 112 if(sn->errorstr) { 113 fprintf(file, "%s\n", sn->errorstr); 114 } 115 break; 116 } 117 case DAV_CONTENT_VERIFICATION_ERROR: { 118 fprintf( 119 file, 120 "Content checksum verification failed for resource %s.\n", 121 res_url); 122 break; 123 } 124 case DAV_REQUEST_ENTITY_TOO_LARGE: { 125 fprintf(file, "Request entity too large.\n"); 126 break; 127 } 128 case DAV_REQUEST_URL_TOO_LONG: { 129 fprintf(file, "Request URL too long.\n"); 130 break; 131 } 132 } 133 free(res_url); 134 } 135