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 #ifndef OWS_STRUCT_H
25 #define OWS_STRUCT_H
26 
27 #include <stdio.h>    /* FILE prototype */
28 
29 
30 /* ========= Structures ========= */
31 
32 enum Bool {
33   false,
34   true
35 };
36 
37 typedef enum Bool bool;
38 
39 #define BUFFER_SIZE_INIT   256
40 
41 typedef struct Buffer {
42   size_t use;     /** size used for data */
43   size_t size;    /** memory available */
44   size_t realloc;   /** size to next realloc */
45   char * buf;     /** data */
46 } buffer;
47 
48 
49 typedef struct List_node {
50   buffer * value;
51   struct List_node * next;
52   struct List_node * prev;
53 } list_node;
54 
55 typedef struct List {
56   list_node * first;
57   list_node * last;
58   unsigned int size;
59 } list;
60 
61 
62 typedef struct Mlist_node {
63   list * value;
64   struct Mlist_node * next;
65   struct Mlist_node * prev;
66 } mlist_node;
67 
68 typedef struct Mlist {
69   mlist_node * first;
70   mlist_node * last;
71   unsigned int size;
72 } mlist;
73 
74 
75 typedef struct Alist_node {
76   buffer * key;
77   list * value;
78   struct Alist_node * next;
79 } alist_node;
80 
81 typedef struct Alist {
82   alist_node * first;
83   alist_node * last;
84 } alist;
85 
86 
87 typedef struct Array_node {
88   buffer * key;
89   buffer * value;
90   struct Array_node * next;
91 } array_node;
92 
93 typedef struct Array {
94   array_node * first;
95   array_node * last;
96 } array;
97 
98 
99 /* ========= OWS Common ========= */
100 
101 typedef struct Ows_layer_storage {
102   buffer * schema;
103   buffer * table;
104   list * geom_columns;
105   list * not_null_columns;
106   int srid;
107   buffer * pkey;
108   buffer * pkey_sequence;
109   buffer * pkey_default;
110   int pkey_column_number;
111   bool is_degree;
112   array * attributes;
113 } ows_layer_storage;
114 
115 typedef struct Ows_srs {
116   int srid;
117   buffer * auth_name;
118   int auth_srid;
119   bool is_degree;
120   bool is_reverse_axis;
121   bool is_eastern_axis;
122   bool is_long;
123 } ows_srs;
124 
125 
126 typedef struct Ows_bbox {
127   double xmin;
128   double ymin;
129   double xmax;
130   double ymax;
131   ows_srs * srs;
132 } ows_bbox;
133 
134 typedef struct Ows_geobbox {
135   double east;
136   double west;
137   double south;
138   double north;
139 } ows_geobbox;
140 
141 typedef struct Ows_version {
142   int major;
143   int minor;
144   int release;
145 } ows_version;
146 
147 /*cf table 19 in OWS specification*/
148 enum ows_error_code {
149   OWS_ERROR_OPERATION_NOT_SUPPORTED,
150   OWS_ERROR_MISSING_PARAMETER_VALUE,
151   OWS_ERROR_INVALID_PARAMETER_VALUE,
152   OWS_ERROR_VERSION_NEGOTIATION_FAILED,
153   OWS_ERROR_INVALID_UPDATE_SEQUENCE,
154   OWS_ERROR_NO_APPLICABLE_CODE,
155   /* Add-on to the spec on the same way */
156   OWS_ERROR_CONNECTION_FAILED,
157   OWS_ERROR_CONFIG_FILE,
158   OWS_ERROR_REQUEST_SQL_FAILED,
159   OWS_ERROR_REQUEST_HTTP,
160   OWS_ERROR_FORBIDDEN_CHARACTER,
161   OWS_ERROR_MISSING_METADATA,
162   OWS_ERROR_NO_SRS_DEFINED
163 };
164 
165 
166 typedef struct Ows_layer {
167   struct Ows_layer * parent;
168   int depth;
169   buffer * name;
170   buffer * name_prefix;
171   buffer * name_no_uri;
172   buffer * title;
173   bool retrievable;
174   bool writable;
175   list * srid;
176   ows_geobbox * geobbox;
177   buffer * abstract;
178   list * keywords;
179   list * exclude_items;
180   list * include_items;
181   buffer * pkey;
182   list * gml_ns;
183   buffer * ns_prefix;
184   buffer * ns_uri;
185   buffer * encoding;
186   ows_layer_storage * storage;
187 } ows_layer;
188 
189 typedef struct Ows_layer_node {
190   ows_layer * layer;
191   struct Ows_layer_node * next;
192   struct Ows_layer_node * prev;
193 } ows_layer_node;
194 
195 typedef struct Ows_layer_list {
196   ows_layer_node * first;
197   ows_layer_node * last;
198   unsigned int size;
199 } ows_layer_list;
200 
201 
202 typedef struct Ows_meta {
203   buffer * type;
204   list * versions;
205   buffer * name;
206   buffer * title;
207   buffer * abstract;
208   list * keywords;
209   buffer * fees;
210   buffer * access_constraints;
211 } ows_meta;
212 
213 typedef struct Ows_contact {
214   buffer * name;
215   buffer * site;
216   buffer * indiv_name;
217   buffer * position;
218   buffer * phone;
219   buffer * fax;
220   buffer * online_resource;
221   buffer * address;
222   buffer * postcode;
223   buffer * city;
224   buffer * state;
225   buffer * country;
226   buffer * email;
227   buffer * hours;
228   buffer * instructions;
229 } ows_contact;
230 
231 enum ows_service {
232   WMS,
233   WFS,
234   OWS_SERVICE_UNKNOWN
235 };
236 
237 enum ows_method {
238   OWS_METHOD_UNKNOWN,
239   OWS_METHOD_KVP,
240   OWS_METHOD_XML
241 };
242 
243 
244 /* ========= WFS ========= */
245 
246 
247 enum wfs_error_code {
248   WFS_ERROR_INVALID_VERSION,
249   WFS_ERROR_OUTPUT_FORMAT_NOT_SUPPORTED,
250   WFS_ERROR_LAYER_NOT_DEFINED,
251   WFS_ERROR_LAYER_NOT_RETRIEVABLE,
252   WFS_ERROR_LAYER_NOT_WRITABLE,
253   WFS_ERROR_EXCLUSIVE_PARAMETERS,
254   WFS_ERROR_INCORRECT_SIZE_PARAMETER,
255   WFS_ERROR_NO_MATCHING,
256   WFS_ERROR_INVALID_PARAMETER,
257   WFS_ERROR_MISSING_PARAMETER
258 };
259 
260 enum wfs_request {
261   WFS_REQUEST_UNKNOWN,
262   WFS_GET_CAPABILITIES,
263   WFS_DESCRIBE_FEATURE_TYPE,
264   WFS_GET_FEATURE,
265   WFS_TRANSACTION
266 };
267 
268 enum wfs_format {
269   WFS_FORMAT_UNKNOWN,
270   WFS_XML_SCHEMA,
271   WFS_GML212,
272   WFS_GML311,
273   WFS_GML321,
274   WFS_GEOJSON,
275   WFS_TEXT_XML,
276   WFS_APPLICATION_XML
277 };
278 
279 enum wfs_insert_idgen {
280   WFS_GENERATE_NEW,
281   WFS_USE_EXISTING,
282   WFS_REPLACE_DUPLICATE
283 };
284 
285 enum ows_schema_type {
286   WFS_SCHEMA_TYPE_100,
287   WFS_SCHEMA_TYPE_110
288 };
289 
290 typedef struct Wfs_request {
291   enum wfs_request request;
292   enum wfs_format format;
293   list * typename;
294   ows_bbox * bbox;
295   mlist * propertyname;
296   int maxfeatures;
297   ows_srs * srs;
298   mlist * featureid;
299   list * filter;
300   buffer * operation;
301   list * handle;
302   buffer * resulttype;
303   buffer * sortby;
304   list * sections;
305 
306   alist * insert_results;
307   int delete_results;
308   int update_results;
309 
310 } wfs_request;
311 
312 
313 /* ========= FE ========= */
314 
315 
316 enum fe_error_code {
317   FE_NO_ERROR,
318   FE_ERROR_FEATUREID,
319   FE_ERROR_FILTER,
320   FE_ERROR_BBOX,
321   FE_ERROR_PROPERTYNAME,
322   FE_ERROR_GEOM_PROPERTYNAME,
323   FE_ERROR_UNITS,
324   FE_ERROR_GEOMETRY,
325   FE_ERROR_FID,
326   FE_ERROR_SRS,
327   FE_ERROR_FUNCTION,
328   FE_ERROR_NAMESPACE
329 };
330 
331 typedef struct Filter_encoding {
332   bool in_not;
333   bool is_numeric;
334   buffer * sql;
335   enum fe_error_code error_code;
336 } filter_encoding;
337 
338 
339 /* ========= OWS Request & Main ========= */
340 
341 typedef struct Ows_request {
342   ows_version * version;
343   enum ows_method method;
344   enum ows_service service;
345   union {
346     wfs_request * wfs;
347   } request;
348 } ows_request;
349 
350 #define OWS_DEFAULT_XML_ENCODING "UTF-8"
351 #define OWS_DEFAULT_DB_ENCODING "UTF8"
352 
353 #define OWS_MAX_DOUBLE 1e15  /* %f vs %g */
354 
355 typedef struct Ows {
356   bool init;
357   bool exit;
358   PGconn * pg;
359   bool mapfile;
360   buffer * config_file;
361   buffer * schema_dir;
362   buffer * online_resource;
363   buffer * pg_dsn;
364   buffer * encoding;
365   buffer * db_encoding;
366 
367   FILE* log;
368   int log_level;
369   buffer * log_file;
370 
371   FILE* output;
372 
373   ows_meta * metadata;
374   ows_contact * contact;
375 
376   int degree_precision;
377   int meter_precision;
378 
379   int max_features;
380   ows_geobbox * max_geobbox;
381 
382   bool display_bbox;
383   bool expose_pk;
384   bool estimated_extent;
385 
386   bool check_schema;
387   bool check_valid_geom;
388 
389   array * cgi;
390   list * psql_requests;
391   ows_layer_list * layers;
392   ows_request * request;
393   ows_version * wfs_default_version;
394   ows_version * postgis_version;
395 
396   xmlSchemaPtr  schema_wfs_100;
397   xmlSchemaPtr  schema_wfs_110;
398 } ows;
399 
400 #endif /* OWS_STRUCT_H */
401 
402 
403 /*
404  * vim: expandtab sw=4 ts=4
405  */
406