]> granicus.if.org Git - apache/blob - server/apreq_error.c
As discussed at AC NA 2011
[apache] / server / apreq_error.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "apreq_error.h"
18 #include "apr_strings.h"
19
20 /*
21  * stuffbuffer - like apr_cpystrn() but returns the address of the
22  * dest buffer instead of the address of the terminating '\0'
23  */
24 static char *stuffbuffer(char *buf, apr_size_t bufsize, const char *s)
25 {
26     apr_cpystrn(buf,s,bufsize);
27     return buf;
28 }
29
30 static const char *apreq_error_string(apr_status_t statcode)
31 {
32     switch (statcode) {
33
34
35 /* 0's: generic error status codes */
36
37     case APREQ_ERROR_GENERAL:
38         return "Internal apreq error";
39
40     case APREQ_ERROR_TAINTED:
41         return "Attempt to perform unsafe action with tainted data";
42
43
44 /* 10's: malformed input */
45
46     case APREQ_ERROR_BADDATA:
47         return "Malformed input data";
48
49     case APREQ_ERROR_BADCHAR:
50         return "Invalid character";
51
52     case APREQ_ERROR_BADSEQ:
53         return "Invalid byte sequence";
54
55     case APREQ_ERROR_BADATTR:
56         return "Unrecognized attribute";
57
58     case APREQ_ERROR_BADHEADER:
59         return "Malformed header string";
60
61
62 /* 20's: missing input */
63
64     case APREQ_ERROR_NODATA:
65         return "Missing input data";
66
67     case APREQ_ERROR_NOTOKEN:
68         return "Expected token not present";
69
70     case APREQ_ERROR_NOATTR:
71         return "Missing attribute";
72
73     case APREQ_ERROR_NOHEADER:
74         return "Missing header";
75
76     case APREQ_ERROR_NOPARSER:
77         return "Missing parser";
78
79
80 /* 30's: configuration conflicts */
81
82     case APREQ_ERROR_MISMATCH:
83         return "Conflicting information";
84
85     case APREQ_ERROR_OVERLIMIT:
86         return "Exceeds configured maximum limit";
87
88     case APREQ_ERROR_NOTEMPTY:
89         return "Setting already configured";
90
91
92     default:
93         return "Error string not yet specified by apreq";
94     }
95 }
96
97
98 APREQ_DECLARE(char *) apreq_strerror(apr_status_t statcode, char *buf,
99                                  apr_size_t bufsize)
100 {
101     if (statcode < APR_OS_START_USERERR || statcode >= APR_OS_START_EAIERR)
102         return apr_strerror(statcode, buf, bufsize);
103     return stuffbuffer(buf, bufsize, apreq_error_string(statcode));
104 }
105