tinyows 1.2.2
wfs_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
24#include <stdlib.h>
25#include <stdio.h>
26#include <assert.h>
27
28#include "../ows/ows.h"
29
30
31/*
32 * Transform an error code into an error message
33 */
35{
36 switch (code) {
38 return "InvalidVersion";
40 return "OutputFormatNotSupported";
42 return "LayerNotDefined";
44 return "ExclusiveParameters";
46 return "LayerNotRetrievable";
48 return "LayerNotWritable";
50 return "IncorrectSizeParameter";
52 return "NoMatching";
54 return "InvalidParameterValue";
56 return "MissingParameterValue";
57 }
58
59 assert(0); /* Should not happen */
60}
61
62
63/*
64 * Return a ServiceExceptionReport as specified in WFS 1.0.0 specification
65 */
66static void wfs_error_100(ows * o, wfs_request * wf, enum wfs_error_code code, char *message, char *locator)
67{
68 assert(o);
69 assert(wf);
70 assert(message);
71 assert(locator);
72
73 assert(!o->exit);
74 o->exit = true;
75
76 ows_log(o, 1, message);
77
78 fprintf(o->output, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", o->encoding->buf);
79 fprintf(o->output, "<ServiceExceptionReport\n");
80 fprintf(o->output, " xmlns=\"http://www.opengis.net/ogc\"\n");
81 fprintf(o->output, " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
82 fprintf(o->output, " xsi:schemaLocation=\"http://www.opengis.net/ogc");
83 fprintf(o->output, " http://schemas.opengis.net/wms/1.1.1/OGC-exception.xsd\"\n");
84 fprintf(o->output, "version=\"1.2.0\">\n");
85 fprintf(o->output, "<ServiceException code=\"%s\"", wfs_error_code_string(code));
86 fprintf(o->output, " locator=\"%s\">\n%s", locator, message);
87 fprintf(o->output, "</ServiceException>\n");
88 fprintf(o->output, "</ServiceExceptionReport>\n");
89}
90
91
92/*
93 * Return an ExceptionReport as specified in WFS 1.1.0 specification
94 */
95static void wfs_error_110(ows * o, wfs_request * wf, enum wfs_error_code code, char *message, char *locator)
96{
97 assert(o);
98 assert(wf);
99 assert(message);
100 assert(locator);
101
102 assert(!o->exit);
103 o->exit = true;
104
105 ows_log(o, 1, message);
106
107 fprintf(o->output, "<?xml version='1.0' encoding='UTF-8'?>\n");
108 fprintf(o->output, "<ExceptionReport\n");
109 fprintf(o->output, " xmlns='http://www.opengis.net/ows'\n");
110 fprintf(o->output, " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n");
111 fprintf(o->output, " xsi:schemaLocation='http://www.opengis.net/ows");
112 fprintf(o->output, " http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd'\n");
113 fprintf(o->output, " version='1.0.0' language='en'>\n");
114 fprintf(o->output, " <Exception exceptionCode='%s' locator='%s'>\n", wfs_error_code_string(code), locator);
115 fprintf(o->output, " <ExceptionText>%s</ExceptionText>\n", message);
116 fprintf(o->output, " </Exception>\n");
117 fprintf(o->output, "</ExceptionReport>\n");
118}
119
120
121/*
122 * Call the right function according to version
123 */
124void wfs_error(ows * o, wfs_request * wf, enum wfs_error_code code, char *message, char *locator)
125{
126 int version;
127
128 assert(o);
129 assert(wf);
130 assert(message);
131 assert(locator);
132
133 version = ows_version_get(o->request->version);
134 fprintf(o->output, "Content-Type: application/xml\n\n");
135
136 switch (version) {
137 case 100:
138 wfs_error_100(o, wf, code, message, locator);
139 break;
140 case 110:
141 wfs_error_110(o, wf, code, message, locator);
142 break;
143 }
144}
145
146
147/*
148 * vim: expandtab sw=4 ts=4
149 */
void ows_log(ows *o, int log_level, const char *log)
Definition ows.c:235
int ows_version_get(ows_version *v)
wfs_error_code
Definition ows_struct.h:256
@ WFS_ERROR_INVALID_VERSION
Definition ows_struct.h:257
@ WFS_ERROR_EXCLUSIVE_PARAMETERS
Definition ows_struct.h:262
@ WFS_ERROR_INVALID_PARAMETER
Definition ows_struct.h:265
@ WFS_ERROR_INCORRECT_SIZE_PARAMETER
Definition ows_struct.h:263
@ WFS_ERROR_NO_MATCHING
Definition ows_struct.h:264
@ WFS_ERROR_LAYER_NOT_WRITABLE
Definition ows_struct.h:261
@ WFS_ERROR_MISSING_PARAMETER
Definition ows_struct.h:266
@ WFS_ERROR_OUTPUT_FORMAT_NOT_SUPPORTED
Definition ows_struct.h:258
@ WFS_ERROR_LAYER_NOT_RETRIEVABLE
Definition ows_struct.h:260
@ WFS_ERROR_LAYER_NOT_DEFINED
Definition ows_struct.h:259
wfs_request
Definition ows_struct.h:269
char * buf
size to next realloc
Definition ows_struct.h:39
ows_version * version
Definition ows_struct.h:353
ows_request * request
Definition ows_struct.h:403
bool exit
Definition ows_struct.h:368
buffer * encoding
Definition ows_struct.h:375
FILE * output
Definition ows_struct.h:382
static char * wfs_error_code_string(enum wfs_error_code code)
Definition wfs_error.c:34
static void wfs_error_100(ows *o, wfs_request *wf, enum wfs_error_code code, char *message, char *locator)
Definition wfs_error.c:66
void wfs_error(ows *o, wfs_request *wf, enum wfs_error_code code, char *message, char *locator)
Definition wfs_error.c:124
static void wfs_error_110(ows *o, wfs_request *wf, enum wfs_error_code code, char *message, char *locator)
Definition wfs_error.c:95

Generated for tinyows by doxygen 1.9.7