tinyows 1.2.2
ows_error.c
Go to the documentation of this file.
1/*
2 Copyright (c) <2007-2012> <Barbara Philippot - Olivier Courtin>
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 IN THE SOFTWARE.
21*/
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <assert.h>
26
27#include "ows.h"
28
29
30/*
31 * Transform an error code into an error message
32 */
34{
35 switch (code) {
37 return "OperationNotSupported";
39 return "MissingParameterValue";
41 return "InvalidParameterValue";
43 return "VersionNegotiationFailed";
45 return "InvalidUpdateSequence";
47 return "NoApplicableCode";
49 return "ConnectionFailed";
51 return "ErrorConfigFile";
53 return "RequestSqlFailed";
55 return "RequestHTTPNotValid";
57 return "ForbiddenCharacter";
59 return "MissingMetadata";
61 return "NoSrsDefined";
62 }
63
64 assert(0); /* Should not happen */
65}
66
67
68/*
69 * Return an ExceptionReport as specified in OWS 1.1.0 specification
70 */
71void ows_error(ows * o, enum ows_error_code code, char *message, char *locator)
72{
73 assert(o);
74 assert(message);
75 assert(locator);
76
77 assert(!o->exit);
78 o->exit = true;
79
80 ows_log(o, 1, message);
81
82#if TINYOWS_FCGI
83 if ((o->init && FCGI_Accept() >= 0) || !o->init) {
84#endif
85 fprintf(o->output, "Content-Type: application/xml\n\n");
86 fprintf(o->output, "<?xml version='1.0' encoding='UTF-8'?>\n");
87 fprintf(o->output, "<ows:ExceptionReport\n");
88 fprintf(o->output, " xmlns='http://www.opengis.net/ows'\n");
89 fprintf(o->output, " xmlns:ows='http://www.opengis.net/ows'\n");
90 fprintf(o->output, " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n");
91 fprintf(o->output, " xsi:schemaLocation='http://www.opengis.net/ows");
92 fprintf(o->output, " http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd'\n");
93 fprintf(o->output, " version='1.1.0' language='en'>\n");
94 fprintf(o->output, " <ows:Exception exceptionCode='%s' locator='%s'>\n",
95 ows_error_code_string(code), locator);
96 fprintf(o->output, " <ows:ExceptionText>%s</ows:ExceptionText>\n", message);
97 fprintf(o->output, " </ows:Exception>\n");
98 fprintf(o->output, "</ows:ExceptionReport>\n");
99
100#if TINYOWS_FCGI
101 fflush(o->output);
102 }
103#endif
104}
void ows_log(ows *o, int log_level, const char *log)
Definition ows.c:235
static char * ows_error_code_string(enum ows_error_code code)
Definition ows_error.c:33
void ows_error(ows *o, enum ows_error_code code, char *message, char *locator)
Definition ows_error.c:71
struct Ows ows
ows_error_code
Definition ows_struct.h:156
@ OWS_ERROR_OPERATION_NOT_SUPPORTED
Definition ows_struct.h:157
@ OWS_ERROR_REQUEST_HTTP
Definition ows_struct.h:167
@ OWS_ERROR_CONNECTION_FAILED
Definition ows_struct.h:164
@ OWS_ERROR_NO_SRS_DEFINED
Definition ows_struct.h:170
@ OWS_ERROR_NO_APPLICABLE_CODE
Definition ows_struct.h:162
@ OWS_ERROR_VERSION_NEGOTIATION_FAILED
Definition ows_struct.h:160
@ OWS_ERROR_MISSING_PARAMETER_VALUE
Definition ows_struct.h:158
@ OWS_ERROR_INVALID_PARAMETER_VALUE
Definition ows_struct.h:159
@ OWS_ERROR_INVALID_UPDATE_SEQUENCE
Definition ows_struct.h:161
@ OWS_ERROR_FORBIDDEN_CHARACTER
Definition ows_struct.h:168
@ OWS_ERROR_REQUEST_SQL_FAILED
Definition ows_struct.h:166
@ OWS_ERROR_CONFIG_FILE
Definition ows_struct.h:165
@ OWS_ERROR_MISSING_METADATA
Definition ows_struct.h:169
bool exit
Definition ows_struct.h:368
bool init
Definition ows_struct.h:367
FILE * output
Definition ows_struct.h:382

Generated for tinyows by doxygen 1.13.2