tinyows 1.2.2
ows_metadata.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.h"
29
30
31/*
32 * Initialize an ows contact structure
33 */
35{
36 ows_contact *contact;
37 contact = malloc(sizeof(ows_contact));
38
39 assert(contact);
40
41 contact->name = NULL;
42 contact->site = NULL;
43 contact->indiv_name = NULL;
44 contact->position = NULL;
45 contact->phone = NULL;
46 contact->fax = NULL;
47 contact->online_resource = NULL;
48 contact->address = NULL;
49 contact->postcode = NULL;
50 contact->city = NULL;
51 contact->state = NULL;
52 contact->country = NULL;
53 contact->email = NULL;
54 contact->hours = NULL;
55 contact->instructions = NULL;
56
57 return contact;
58}
59
60
61/*
62 * Free an ows contact structure
63 */
65{
66 assert(contact);
67
68 if (contact->name) buffer_free(contact->name);
69 if (contact->site) buffer_free(contact->site);
70 if (contact->indiv_name) buffer_free(contact->indiv_name);
71 if (contact->position) buffer_free(contact->position);
72 if (contact->phone) buffer_free(contact->phone);
73 if (contact->fax) buffer_free(contact->fax);
74 if (contact->online_resource) buffer_free(contact->online_resource);
75 if (contact->address) buffer_free(contact->address);
76 if (contact->postcode) buffer_free(contact->postcode);
77 if (contact->city) buffer_free(contact->city);
78 if (contact->state) buffer_free(contact->state);
79 if (contact->country) buffer_free(contact->country);
80 if (contact->email) buffer_free(contact->email);
81 if (contact->hours) buffer_free(contact->hours);
82 if (contact->instructions) buffer_free(contact->instructions);
83
84 free(contact);
85 contact = NULL;
86}
87
88
89/*
90 * Initialize an ows metadata structure
91 */
93{
94 ows_meta *metadata;
95
96 metadata = malloc(sizeof(ows_meta));
97 assert(metadata);
98
99 metadata->name = NULL;
100 metadata->type = NULL;
101 metadata->versions = NULL;
102 metadata->title = NULL;
103 metadata->abstract = NULL;
104 metadata->keywords = NULL;
105 metadata->fees = NULL;
106 metadata->access_constraints = NULL;
107
108 return metadata;
109}
110
111
112/*
113 * Free an ows metadata structure
114 */
116{
117 assert(metadata);
118
119 if (metadata->name) buffer_free(metadata->name);
120 if (metadata->type) buffer_free(metadata->type);
121 if (metadata->versions) list_free(metadata->versions);
122 if (metadata->title) buffer_free(metadata->title);
123 if (metadata->abstract) buffer_free(metadata->abstract);
124 if (metadata->keywords) list_free(metadata->keywords);
125 if (metadata->fees) buffer_free(metadata->fees);
126 if (metadata->access_constraints) buffer_free(metadata->access_constraints);
127
128 free(metadata);
129 metadata = NULL;
130}
131
132
133/*
134 * Fill the service's metadata
135 */
137{
138 buffer *b;
139
140 assert(o);
141 assert(o->metadata);
142 assert(cgi);
143
144 /* Retrieve the requested service from request */
145 if (array_is_key(cgi, "xmlns")) {
146 b = array_get(cgi, "xmlns");
147 if (buffer_case_cmp(b, "http://www.opengis.net/wfs"))
148 o->metadata->type = buffer_from_str("WFS");
149 } else if (array_is_key(cgi, "service")) {
150 b = array_get(cgi, "service");
151 o->metadata->type = buffer_init();
152 buffer_copy(o->metadata->type, b);
153 } else {
154 ows_error(o, OWS_ERROR_MISSING_PARAMETER_VALUE, "service unknown", "service");
155 return;
156 }
157
158 /* Initialize supported versions from service type */
159 if (o->metadata->type) {
160 if (buffer_case_cmp(o->metadata->type, "WFS")) {
162 o->metadata->type = buffer_from_str("WFS");
164 list_add_str(o->metadata->versions, "1.0.0");
165 list_add_str(o->metadata->versions, "1.1.0");
166 } else if (buffer_case_cmp(o->metadata->type, "WMS")) {
168 o->metadata->type = buffer_from_str("WMS");
170 list_add_str(o->metadata->versions, "1.1.0");
171 list_add_str(o->metadata->versions, "1.3.0");
172 }
173 }
174}
175
176
177/*
178 * Flush an ows contact to a given file
179 * (used for debug purpose)
180 */
181#ifdef OWS_DEBUG
182void ows_contact_flush(ows_contact * contact, FILE * output)
183{
184 assert(contact);
185 assert(output);
186
187 if (contact->name) {
188 fprintf(output, "name: ");
189 buffer_flush(contact->name, output);
190 fprintf(output, "\n");
191 }
192
193 if (contact->site) {
194 fprintf(output, "site: ");
195 buffer_flush(contact->site, output);
196 fprintf(output, "\n");
197 }
198
199 if (contact->indiv_name) {
200 fprintf(output, "individual name: ");
201 buffer_flush(contact->indiv_name, output);
202 fprintf(output, "\n");
203 }
204
205 if (contact->position) {
206 fprintf(output, "position: ");
207 buffer_flush(contact->position, output);
208 fprintf(output, "\n");
209 }
210
211 if (contact->phone) {
212 fprintf(output, "phone: ");
213 buffer_flush(contact->phone, output);
214 fprintf(output, "\n");
215 }
216
217 if (contact->fax) {
218 fprintf(output, "fax: ");
219 buffer_flush(contact->fax, output);
220 fprintf(output, "\n");
221 }
222
223 if (contact->online_resource) {
224 fprintf(output, "online_resource: ");
225 buffer_flush(contact->online_resource, output);
226 fprintf(output, "\n");
227 }
228
229 if (contact->address) {
230 fprintf(output, "address: ");
231 buffer_flush(contact->address, output);
232 fprintf(output, "\n");
233 }
234
235 if (contact->postcode) {
236 fprintf(output, "postcode: ");
237 buffer_flush(contact->postcode, output);
238 fprintf(output, "\n");
239 }
240
241 if (contact->city) {
242 fprintf(output, "city: ");
243 buffer_flush(contact->city, output);
244 fprintf(output, "\n");
245 }
246
247 if (contact->state) {
248 fprintf(output, "administrative_area: ");
249 buffer_flush(contact->city, output);
250 fprintf(output, "\n");
251 }
252
253 if (contact->country) {
254 fprintf(output, "country: ");
255 buffer_flush(contact->country, output);
256 fprintf(output, "\n");
257 }
258
259 if (contact->email) {
260 fprintf(output, "email: ");
261 buffer_flush(contact->email, output);
262 fprintf(output, "\n");
263 }
264
265 if (contact->hours) {
266 fprintf(output, "hours_of_service: ");
267 buffer_flush(contact->hours, output);
268 fprintf(output, "\n");
269 }
270
271 if (contact->instructions) {
272 fprintf(output, "contact_instructions: ");
273 buffer_flush(contact->instructions, output);
274 fprintf(output, "\n");
275 }
276
277}
278#endif
279
280
281/*
282 * Flush an ows metadata to a given file
283 * (used for debug purpose)
284 */
285#ifdef OWS_DEBUG
286void ows_metadata_flush(ows_meta * metadata, FILE * output)
287{
288 assert(metadata);
289 assert(output);
290
291 if (metadata->name) {
292 fprintf(output, "name: ");
293 buffer_flush(metadata->name, output);
294 fprintf(output, "\n");
295 }
296
297 if (metadata->type) {
298 fprintf(output, "type: ");
299 buffer_flush(metadata->type, output);
300 fprintf(output, "\n");
301 }
302
303 if (metadata->versions) {
304 fprintf(output, "version: ");
305 list_flush(metadata->versions, output);
306 fprintf(output, "\n");
307 }
308
309 if (metadata->title) {
310 fprintf(output, "title: ");
311 buffer_flush(metadata->title, output);
312 fprintf(output, "\n");
313 }
314
315 if (metadata->abstract) {
316 fprintf(output, "abstract: ");
317 buffer_flush(metadata->abstract, output);
318 fprintf(output, "\n");
319 }
320
321 if (metadata->keywords) {
322 fprintf(output, "keywords: ");
323 list_flush(metadata->keywords, output);
324 fprintf(output, "\n");
325 }
326
327 if (metadata->fees) {
328 fprintf(output, "fees: ");
329 buffer_flush(metadata->fees, output);
330 fprintf(output, "\n");
331 }
332
333 if (metadata->access_constraints) {
334 fprintf(output, "access_constraints: ");
335 buffer_flush(metadata->access_constraints, output);
336 fprintf(output, "\n");
337 }
338}
339#endif
340
341
342/*
343 * vim: expandtab sw=4 ts=4
344 */
void buffer_copy(buffer *dest, const buffer *src)
Definition buffer.c:350
void list_free(list *l)
Definition list.c:54
void list_flush(const list *l, FILE *output)
list * list_init()
Definition list.c:36
void buffer_flush(buffer *buf, FILE *output)
Definition buffer.c:112
bool buffer_case_cmp(const buffer *buf, const char *str)
Definition buffer.c:330
buffer * array_get(const array *a, const char *key)
Definition array.c:147
void ows_error(ows *o, enum ows_error_code code, char *message, char *locator)
Definition ows_error.c:71
void list_add_str(list *l, char *value)
Definition list.c:102
bool array_is_key(const array *a, const char *key)
Definition array.c:105
buffer * buffer_from_str(const char *str)
Definition buffer.c:202
void buffer_free(buffer *buf)
Definition buffer.c:83
void ows_contact_flush(ows_contact *contact, FILE *output)
buffer * buffer_init()
Definition buffer.c:61
void ows_metadata_flush(ows_meta *metadata, FILE *output)
void ows_contact_free(ows_contact *contact)
void ows_metadata_fill(ows *o, array *cgi)
ows_meta * ows_metadata_init()
ows_contact * ows_contact_init()
void ows_metadata_free(ows_meta *metadata)
@ OWS_ERROR_MISSING_PARAMETER_VALUE
Definition ows_struct.h:158
buffer * instructions
Definition ows_struct.h:237
buffer * phone
Definition ows_struct.h:227
buffer * address
Definition ows_struct.h:230
buffer * state
Definition ows_struct.h:233
buffer * postcode
Definition ows_struct.h:231
buffer * position
Definition ows_struct.h:226
buffer * name
Definition ows_struct.h:223
buffer * indiv_name
Definition ows_struct.h:225
buffer * hours
Definition ows_struct.h:236
buffer * online_resource
Definition ows_struct.h:229
buffer * fax
Definition ows_struct.h:228
buffer * city
Definition ows_struct.h:232
buffer * email
Definition ows_struct.h:235
buffer * country
Definition ows_struct.h:234
buffer * site
Definition ows_struct.h:224
list * keywords
Definition ows_struct.h:217
buffer * abstract
Definition ows_struct.h:216
buffer * type
Definition ows_struct.h:212
buffer * access_constraints
Definition ows_struct.h:219
buffer * name
Definition ows_struct.h:214
buffer * title
Definition ows_struct.h:215
list * versions
Definition ows_struct.h:213
buffer * fees
Definition ows_struct.h:218
ows_meta * metadata
Definition ows_struct.h:384

Generated for tinyows by doxygen 1.10.0