1 | /* |
---|
2 | * Author : Gérald FENOY |
---|
3 | * |
---|
4 | * Copyright (c) 2009-2015 GeoLabs SARL |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef ZOO_SERVICE_H |
---|
26 | #define ZOO_SERVICE_H 1 |
---|
27 | |
---|
28 | #pragma once |
---|
29 | |
---|
30 | #ifdef WIN32 |
---|
31 | #ifndef USE_MS |
---|
32 | #define strncasecmp _strnicmp |
---|
33 | #define strcasecmp _stricmp |
---|
34 | #endif |
---|
35 | #ifndef snprintf |
---|
36 | #define snprintf sprintf_s |
---|
37 | #endif |
---|
38 | #define zStrdup _strdup |
---|
39 | #define zMkdir _mkdir |
---|
40 | #define zOpen _open |
---|
41 | #define zWrite _write |
---|
42 | #define zSleep Sleep |
---|
43 | #include <sys/timeb.h> |
---|
44 | struct ztimeval { |
---|
45 | long tv_sec; /* seconds */ |
---|
46 | long tv_usec; /* and microseconds */ |
---|
47 | }; |
---|
48 | static int zGettimeofday(struct ztimeval* tp, void* tzp) |
---|
49 | { |
---|
50 | if (tp == 0) { |
---|
51 | return -1; |
---|
52 | } |
---|
53 | |
---|
54 | struct _timeb theTime; |
---|
55 | _ftime(&theTime); |
---|
56 | tp->tv_sec = theTime.time; |
---|
57 | tp->tv_usec = theTime.millitm * 1000; |
---|
58 | |
---|
59 | return 0; // The gettimeofday() function shall return 0 on success |
---|
60 | } |
---|
61 | #else |
---|
62 | /** |
---|
63 | * The crossplatform strdup alias |
---|
64 | */ |
---|
65 | #define zStrdup strdup |
---|
66 | /** |
---|
67 | * The crossplatform mkdir alias |
---|
68 | */ |
---|
69 | #define zMkdir mkdir |
---|
70 | /** |
---|
71 | * The crossplatform open alias |
---|
72 | */ |
---|
73 | #define zOpen open |
---|
74 | /** |
---|
75 | * The crossplatform write alias |
---|
76 | */ |
---|
77 | #define zWrite write |
---|
78 | /** |
---|
79 | * The crossplatform sleep alias |
---|
80 | */ |
---|
81 | #define zSleep sleep |
---|
82 | /** |
---|
83 | * The crossplatform gettimeofday alias |
---|
84 | */ |
---|
85 | #define zGettimeofday gettimeofday |
---|
86 | /** |
---|
87 | * The crossplatform timeval alias |
---|
88 | */ |
---|
89 | #define ztimeval timeval |
---|
90 | #endif |
---|
91 | |
---|
92 | #ifdef __cplusplus |
---|
93 | extern "C" { |
---|
94 | #endif |
---|
95 | |
---|
96 | #ifdef WIN32 |
---|
97 | #ifdef USE_MS |
---|
98 | #include <mapserver.h> |
---|
99 | #endif |
---|
100 | #endif |
---|
101 | #include <stdlib.h> |
---|
102 | #include <ctype.h> |
---|
103 | #include <stdio.h> |
---|
104 | #include <string.h> |
---|
105 | #ifndef WIN32 |
---|
106 | #include <ctype.h> |
---|
107 | #ifndef bool |
---|
108 | #define bool int |
---|
109 | #endif |
---|
110 | #ifndef true |
---|
111 | /** |
---|
112 | * Local true definition |
---|
113 | */ |
---|
114 | #define true 1 |
---|
115 | /** |
---|
116 | * Local false definition |
---|
117 | */ |
---|
118 | #define false 0 |
---|
119 | #endif |
---|
120 | #endif |
---|
121 | |
---|
122 | /** |
---|
123 | * The global accepted status for a service |
---|
124 | */ |
---|
125 | #define SERVICE_ACCEPTED 0 |
---|
126 | /** |
---|
127 | * The global started status for a service |
---|
128 | */ |
---|
129 | #define SERVICE_STARTED 1 |
---|
130 | /** |
---|
131 | * The global paused status for a service |
---|
132 | */ |
---|
133 | #define SERVICE_PAUSED 2 |
---|
134 | /** |
---|
135 | * The global succeeded status for a service |
---|
136 | */ |
---|
137 | #define SERVICE_SUCCEEDED 3 |
---|
138 | /** |
---|
139 | * The global failed status for a service |
---|
140 | */ |
---|
141 | #define SERVICE_FAILED 4 |
---|
142 | |
---|
143 | /** |
---|
144 | * The memory size to create an elements |
---|
145 | */ |
---|
146 | #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*))) |
---|
147 | /** |
---|
148 | * The memory size to create a map |
---|
149 | */ |
---|
150 | #define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) |
---|
151 | /** |
---|
152 | * The memory size to create an iotype |
---|
153 | */ |
---|
154 | #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) |
---|
155 | /** |
---|
156 | * The memory size to create a maps |
---|
157 | */ |
---|
158 | #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE |
---|
159 | /** |
---|
160 | * The memory size to create a service |
---|
161 | */ |
---|
162 | #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)+sizeof(char*)+sizeof(char*) |
---|
163 | /** |
---|
164 | * The memory size to create a services |
---|
165 | */ |
---|
166 | #define SERVICES_SIZE SERVICE_SIZE+sizeof(services*) |
---|
167 | /** |
---|
168 | * The memory size to create a registry |
---|
169 | */ |
---|
170 | #define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*) |
---|
171 | |
---|
172 | #define SHMSZ 27 |
---|
173 | |
---|
174 | #include "version.h" |
---|
175 | |
---|
176 | #ifdef DEBUG_STACK |
---|
177 | void debugStack(const char* file,const int line){ |
---|
178 | int stack; |
---|
179 | fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line); |
---|
180 | } |
---|
181 | #endif |
---|
182 | |
---|
183 | /** |
---|
184 | * KVP linked list |
---|
185 | */ |
---|
186 | typedef struct map{ |
---|
187 | char* name; //!< the key |
---|
188 | char* value; //!< the value |
---|
189 | struct map* next; //!< the pointer to the next map if any or NULL |
---|
190 | } map; |
---|
191 | |
---|
192 | #ifdef WIN32 |
---|
193 | #define NULLMAP ((map*) 0) |
---|
194 | #else |
---|
195 | #define NULLMAP NULL |
---|
196 | #endif |
---|
197 | |
---|
198 | /** |
---|
199 | * linked list of map pointer |
---|
200 | * |
---|
201 | * Small object to store WPS KVP set. |
---|
202 | */ |
---|
203 | typedef struct maps{ |
---|
204 | char* name; //!< the maps name |
---|
205 | struct map* content; //!< the content map |
---|
206 | struct maps* next; //!< the pointer to the next maps if any or NULL |
---|
207 | } maps; |
---|
208 | |
---|
209 | /** |
---|
210 | * Not named linked list |
---|
211 | * |
---|
212 | * Used to store informations about formats, such as mimeType, encoding ... |
---|
213 | */ |
---|
214 | typedef struct iotype{ |
---|
215 | struct map* content; //!< the content map |
---|
216 | struct iotype* next; //!< the pointer to the next iotype if any or NULL |
---|
217 | } iotype; |
---|
218 | |
---|
219 | /** |
---|
220 | * Metadata information about input or output. |
---|
221 | * |
---|
222 | * The elements are used to store metadata informations defined in the ZCFG. |
---|
223 | */ |
---|
224 | typedef struct elements{ |
---|
225 | char* name; //!< the name |
---|
226 | struct map* content; //!< the content map |
---|
227 | struct map* metadata; //!< the metadata map |
---|
228 | char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData |
---|
229 | struct iotype* defaults; //!< the default iotype |
---|
230 | struct iotype* supported; //!< the supported iotype |
---|
231 | struct elements* child; //!< the pointer to the children element if any (or NULL) |
---|
232 | struct elements* next; //!< the pointer to the next element if any (or NULL) |
---|
233 | } elements; |
---|
234 | |
---|
235 | /** |
---|
236 | * Metadata informations about a full Service. |
---|
237 | */ |
---|
238 | typedef struct service{ |
---|
239 | char* name; //!< the name |
---|
240 | char* identifier; //!< service identifier Ex: zcfg = /var/www/zoo/cgi-bin/gdal/ndvi/ExtractNDVI.zcfg ===> identifier = gdal.ndvi.ExtractNDVI |
---|
241 | char * zcfg; // path to zcfg file |
---|
242 | struct map* content; //!< the content map |
---|
243 | struct map* metadata; //!< the metadata map |
---|
244 | struct elements* inputs; //!< the inputs elements |
---|
245 | struct elements* outputs; //!< the outputs elements |
---|
246 | } service; |
---|
247 | |
---|
248 | /** |
---|
249 | * Services chained list. |
---|
250 | */ |
---|
251 | typedef struct services{ |
---|
252 | struct service* content; //!< the content service pointer |
---|
253 | struct services* next; //!< the pointer to the next services* |
---|
254 | } services; |
---|
255 | |
---|
256 | /** |
---|
257 | * Profile registry. |
---|
258 | */ |
---|
259 | typedef struct registry{ |
---|
260 | char *name; //!< the name |
---|
261 | struct services* content; //!< the content services pointer |
---|
262 | struct registry* next; //!< the next registry pointer |
---|
263 | } registry; |
---|
264 | |
---|
265 | |
---|
266 | void _dumpMap(map*); |
---|
267 | void dumpMap(map*); |
---|
268 | void dumpMapToFile(map*,FILE*); |
---|
269 | void dumpMaps(maps* m); |
---|
270 | void dumpMapsToFile(maps*,char*); |
---|
271 | map* createMap(const char*,const char*); |
---|
272 | int count(map*); |
---|
273 | bool hasKey(map*,const char*); |
---|
274 | maps* getMaps(maps*,const char*); |
---|
275 | map* getMap(map*,const char*); |
---|
276 | map* getLastMap(map*); |
---|
277 | map* getMapFromMaps(maps*,const char*,const char*); |
---|
278 | void freeMap(map**); |
---|
279 | void freeMaps(maps** mo); |
---|
280 | |
---|
281 | |
---|
282 | bool hasElement(elements*,const char*); |
---|
283 | elements* getElements(elements*,char*); |
---|
284 | void freeIOType(iotype**); |
---|
285 | void freeElements(elements**); |
---|
286 | void freeService(service**); |
---|
287 | void addToMap(map*,const char*,const char*); |
---|
288 | void addIntToMap(map*,const char*,const int); |
---|
289 | void addToMapWithSize(map*,const char*,const char*,int); |
---|
290 | void addMapToMap(map**,map*); |
---|
291 | void addMapToIoType(iotype**,map*); |
---|
292 | map* getMapOrFill(map**,const char*,const char*); |
---|
293 | bool contains(map*,map*); |
---|
294 | iotype* getIoTypeFromElement(elements*,char*, map*); |
---|
295 | void loadMapBinary(map**,map*,int); |
---|
296 | void loadMapBinaries(map**,map*); |
---|
297 | maps* dupMaps(maps**); |
---|
298 | void addMapsToMaps(maps**,maps*); |
---|
299 | map* getMapArray(map*,const char*,int); |
---|
300 | void setMapArray(map*,const char*,int,const char*); |
---|
301 | map* getMapType(map*); |
---|
302 | int addMapsArrayToMaps(maps**,maps*,char*); |
---|
303 | void setMapInMaps(maps*,const char*,const char*,const char*); |
---|
304 | void dumpElements(elements*); |
---|
305 | void dumpElementsAsYAML(elements*); |
---|
306 | elements* dupElements(elements*); |
---|
307 | void addToElements(elements**,elements*); |
---|
308 | void dumpService(service*); |
---|
309 | void dumpServiceAsYAML(service*); |
---|
310 | service* dupService(service*); |
---|
311 | void dumpRegistry(registry*); |
---|
312 | bool addServiceToRegistry(registry**,char*,service*); |
---|
313 | void freeRegistry(registry**); |
---|
314 | service* getServiceFromRegistry(registry*,char*,char*); |
---|
315 | void inheritMap(map**,map*); |
---|
316 | void inheritIOType(iotype**,iotype*); |
---|
317 | void inheritElements(elements**,elements*); |
---|
318 | void inheritance(registry*,service**); |
---|
319 | void mapsToCharXXX(maps*,char***); |
---|
320 | void charxxxToMaps(char***,maps**); |
---|
321 | #ifdef WIN32 |
---|
322 | extern char *url_encode(char *); |
---|
323 | char* getMapsAsKVP(maps*,int,int); |
---|
324 | #endif |
---|
325 | |
---|
326 | #ifdef __cplusplus |
---|
327 | } |
---|
328 | #endif |
---|
329 | |
---|
330 | #endif |
---|