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 | #define ZOO_DLL_EXPORT __declspec( dllexport ) |
---|
32 | #else |
---|
33 | #define ZOO_DLL_EXPORT |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifdef WIN32 |
---|
37 | #ifndef USE_MS |
---|
38 | ZOO_DLL_EXPORT char *strcasestr (char const *,char const *); |
---|
39 | #endif |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifdef WIN32 |
---|
43 | #define strncasecmp _strnicmp |
---|
44 | #define strcasecmp _stricmp |
---|
45 | #define strtok_r strtok_s |
---|
46 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
---|
47 | #define snprintf _snprintf |
---|
48 | #endif |
---|
49 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
---|
50 | #define false 0 |
---|
51 | #define true 1 |
---|
52 | #define bool int |
---|
53 | #endif |
---|
54 | #define zStrdup _strdup |
---|
55 | #define zMkdir _mkdir |
---|
56 | #define zOpen _open |
---|
57 | #define zWrite _write |
---|
58 | #define zSleep Sleep |
---|
59 | #include <sys/timeb.h> |
---|
60 | struct ztimeval { |
---|
61 | long tv_sec; /* seconds */ |
---|
62 | long tv_usec; /* and microseconds */ |
---|
63 | }; |
---|
64 | static int zGettimeofday(struct ztimeval* tp, void* tzp) |
---|
65 | { |
---|
66 | struct _timeb theTime; |
---|
67 | if (tp == 0) { |
---|
68 | return -1; |
---|
69 | } |
---|
70 | |
---|
71 | _ftime(&theTime); |
---|
72 | tp->tv_sec = theTime.time; |
---|
73 | tp->tv_usec = theTime.millitm * 1000; |
---|
74 | |
---|
75 | return 0; // The gettimeofday() function shall return 0 on success |
---|
76 | } |
---|
77 | |
---|
78 | #else |
---|
79 | /** |
---|
80 | * The crossplatform strdup alias |
---|
81 | */ |
---|
82 | #define zStrdup strdup |
---|
83 | /** |
---|
84 | * The crossplatform mkdir alias |
---|
85 | */ |
---|
86 | #define zMkdir mkdir |
---|
87 | /** |
---|
88 | * The crossplatform open alias |
---|
89 | */ |
---|
90 | #define zOpen open |
---|
91 | /** |
---|
92 | * The crossplatform write alias |
---|
93 | */ |
---|
94 | #define zWrite write |
---|
95 | /** |
---|
96 | * The crossplatform sleep alias |
---|
97 | */ |
---|
98 | #define zSleep sleep |
---|
99 | /** |
---|
100 | * The crossplatform gettimeofday alias |
---|
101 | */ |
---|
102 | #define zGettimeofday gettimeofday |
---|
103 | /** |
---|
104 | * The crossplatform timeval alias |
---|
105 | */ |
---|
106 | #define ztimeval timeval |
---|
107 | #endif |
---|
108 | |
---|
109 | #ifdef __cplusplus |
---|
110 | extern "C" { |
---|
111 | #endif |
---|
112 | |
---|
113 | #ifdef WIN32 |
---|
114 | #ifdef USE_MS |
---|
115 | #include <mapserver.h> |
---|
116 | #endif |
---|
117 | #endif |
---|
118 | #include <stdlib.h> |
---|
119 | #include <ctype.h> |
---|
120 | |
---|
121 | #include <stdio.h> |
---|
122 | |
---|
123 | #include <string.h> |
---|
124 | #ifndef WIN32 |
---|
125 | #include <ctype.h> |
---|
126 | #include <stdbool.h> |
---|
127 | #endif |
---|
128 | |
---|
129 | /** |
---|
130 | * The global accepted status for a service |
---|
131 | */ |
---|
132 | #define SERVICE_ACCEPTED 0 |
---|
133 | /** |
---|
134 | * The global started status for a service |
---|
135 | */ |
---|
136 | #define SERVICE_STARTED 1 |
---|
137 | /** |
---|
138 | * The global paused status for a service |
---|
139 | */ |
---|
140 | #define SERVICE_PAUSED 2 |
---|
141 | /** |
---|
142 | * The global succeeded status for a service |
---|
143 | */ |
---|
144 | #define SERVICE_SUCCEEDED 3 |
---|
145 | /** |
---|
146 | * The global failed status for a service |
---|
147 | */ |
---|
148 | #define SERVICE_FAILED 4 |
---|
149 | |
---|
150 | /** |
---|
151 | * The memory size to create an elements |
---|
152 | */ |
---|
153 | #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*))) |
---|
154 | /** |
---|
155 | * The memory size to create a map |
---|
156 | */ |
---|
157 | //#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) // knut: size of NULL pointer may be different from regular pointer (platform dependent) |
---|
158 | #define MAP_SIZE (2*sizeof(char*))+sizeof(map*) |
---|
159 | /** |
---|
160 | * The memory size to create an iotype |
---|
161 | */ |
---|
162 | //#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) |
---|
163 | #define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*) |
---|
164 | /** |
---|
165 | * The memory size to create a maps |
---|
166 | */ |
---|
167 | //#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE |
---|
168 | #define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*)) |
---|
169 | /** |
---|
170 | * The memory size to create a service |
---|
171 | */ |
---|
172 | //#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) |
---|
173 | #define SERVICE_SIZE sizeof(char*) + 2*sizeof(map*) + 2*sizeof(elements*) |
---|
174 | /** |
---|
175 | * The memory size to create a services |
---|
176 | */ |
---|
177 | //#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*) |
---|
178 | #define SERVICES_SIZE sizeof(service*)+sizeof(services*) |
---|
179 | /** |
---|
180 | * The memory size to create a registry |
---|
181 | */ |
---|
182 | //#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*) |
---|
183 | #define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*) |
---|
184 | |
---|
185 | #define SHMSZ 27 |
---|
186 | |
---|
187 | #include "version.h" |
---|
188 | |
---|
189 | #ifdef DEBUG_STACK |
---|
190 | void debugStack(const char* file,const int line){ |
---|
191 | int stack; |
---|
192 | fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line); |
---|
193 | } |
---|
194 | #endif |
---|
195 | |
---|
196 | /** |
---|
197 | * KVP linked list |
---|
198 | */ |
---|
199 | typedef struct map{ |
---|
200 | char* name; //!< the key |
---|
201 | char* value; //!< the value |
---|
202 | struct map* next; //!< the pointer to the next map if any or NULL |
---|
203 | } map; |
---|
204 | |
---|
205 | #ifdef WIN32 |
---|
206 | #define NULLMAP ((map*) 0) |
---|
207 | #else |
---|
208 | #define NULLMAP NULL |
---|
209 | #endif |
---|
210 | |
---|
211 | /** |
---|
212 | * linked list of map pointer |
---|
213 | * |
---|
214 | * Small object to store WPS KVP set. |
---|
215 | */ |
---|
216 | typedef struct maps{ |
---|
217 | char* name; //!< the maps name |
---|
218 | struct map* content; //!< the content map |
---|
219 | struct maps* child; //!< the child maps |
---|
220 | struct maps* next; //!< the pointer to the next maps if any or NULL |
---|
221 | } maps; |
---|
222 | |
---|
223 | /** |
---|
224 | * Not named linked list |
---|
225 | * |
---|
226 | * Used to store information about formats, such as mimeType, encoding ... |
---|
227 | */ |
---|
228 | typedef struct iotype{ |
---|
229 | struct map* content; //!< the content map |
---|
230 | struct iotype* next; //!< the pointer to the next iotype if any or NULL |
---|
231 | } iotype; |
---|
232 | |
---|
233 | /** |
---|
234 | * Metadata information about input or output. |
---|
235 | * |
---|
236 | * The elements are used to store metadata information defined in the ZCFG. |
---|
237 | */ |
---|
238 | typedef struct elements{ |
---|
239 | char* name; //!< the name |
---|
240 | struct map* content; //!< the content map |
---|
241 | struct map* metadata; //!< the metadata map |
---|
242 | char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData |
---|
243 | struct iotype* defaults; //!< the default iotype |
---|
244 | struct iotype* supported; //!< the supported iotype |
---|
245 | struct elements* child; //!< the pointer to the children element if any (or NULL) |
---|
246 | struct elements* next; //!< the pointer to the next element if any (or NULL) |
---|
247 | } elements; |
---|
248 | |
---|
249 | /** |
---|
250 | * Metadata information about a full Service. |
---|
251 | */ |
---|
252 | typedef struct service{ |
---|
253 | char* name; //!< the name |
---|
254 | struct map* content; //!< the content map |
---|
255 | struct map* metadata; //!< the metadata map |
---|
256 | struct elements* inputs; //!< the inputs elements |
---|
257 | struct elements* outputs; //!< the outputs elements |
---|
258 | } service; |
---|
259 | |
---|
260 | /** |
---|
261 | * Services chained list. |
---|
262 | */ |
---|
263 | typedef struct services{ |
---|
264 | struct service* content; //!< the content service pointer |
---|
265 | struct services* next; //!< the pointer to the next services* |
---|
266 | } services; |
---|
267 | |
---|
268 | /** |
---|
269 | * Profile registry. |
---|
270 | */ |
---|
271 | typedef struct registry{ |
---|
272 | char *name; //!< the name |
---|
273 | struct services* content; //!< the content services pointer |
---|
274 | struct registry* next; //!< the next registry pointer |
---|
275 | } registry; |
---|
276 | |
---|
277 | ZOO_DLL_EXPORT void _dumpMap(map*); |
---|
278 | ZOO_DLL_EXPORT void dumpMap(map*); |
---|
279 | ZOO_DLL_EXPORT void dumpMaps(maps* m); |
---|
280 | ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally) |
---|
281 | ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int); |
---|
282 | ZOO_DLL_EXPORT map* createMap(const char*,const char*); |
---|
283 | ZOO_DLL_EXPORT maps* createMaps(const char*); |
---|
284 | ZOO_DLL_EXPORT int count(map*); |
---|
285 | ZOO_DLL_EXPORT bool hasKey(map*,const char*); |
---|
286 | ZOO_DLL_EXPORT maps* getMaps(maps*,const char*); |
---|
287 | ZOO_DLL_EXPORT map* getMap(map*,const char*); |
---|
288 | ZOO_DLL_EXPORT map* getLastMap(map*); |
---|
289 | ZOO_DLL_EXPORT map* getMapFromMaps(maps*,const char*,const char*); |
---|
290 | ZOO_DLL_EXPORT void freeMap(map**); |
---|
291 | ZOO_DLL_EXPORT void freeMaps(maps** mo); |
---|
292 | |
---|
293 | |
---|
294 | ZOO_DLL_EXPORT elements* createEmptyElements(); |
---|
295 | ZOO_DLL_EXPORT elements* createElements(char*); |
---|
296 | ZOO_DLL_EXPORT void setElementsName(elements**,char*); |
---|
297 | ZOO_DLL_EXPORT bool hasElement(elements*,const char*); |
---|
298 | ZOO_DLL_EXPORT elements* getElements(elements*,char*); |
---|
299 | ZOO_DLL_EXPORT void freeIOType(iotype**); |
---|
300 | ZOO_DLL_EXPORT void freeElements(elements**); |
---|
301 | ZOO_DLL_EXPORT void setServiceName(service**,char*); |
---|
302 | ZOO_DLL_EXPORT void freeService(service**); |
---|
303 | ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*); |
---|
304 | ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int); |
---|
305 | ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int); |
---|
306 | ZOO_DLL_EXPORT void addMapToMap(map**,map*); |
---|
307 | ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*); |
---|
308 | ZOO_DLL_EXPORT map* getMapOrFill(map**,const char*,const char*); |
---|
309 | ZOO_DLL_EXPORT bool contains(map*,map*); |
---|
310 | ZOO_DLL_EXPORT iotype* getIoTypeFromElement(elements*,char*, map*); |
---|
311 | ZOO_DLL_EXPORT void loadMapBinary(map**,map*,int); |
---|
312 | ZOO_DLL_EXPORT void loadMapBinaries(map**,map*); |
---|
313 | ZOO_DLL_EXPORT maps* dupMaps(maps**); |
---|
314 | ZOO_DLL_EXPORT void addMapsToMaps(maps**,maps*); |
---|
315 | ZOO_DLL_EXPORT map* getMapArray(map*,const char*,int); |
---|
316 | ZOO_DLL_EXPORT void setMapArray(map*,const char*,int,const char*); |
---|
317 | ZOO_DLL_EXPORT map* getMapType(map*); |
---|
318 | ZOO_DLL_EXPORT int addMapsArrayToMaps(maps**,maps*,char*); |
---|
319 | ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*); |
---|
320 | ZOO_DLL_EXPORT void dumpElements(elements*); |
---|
321 | ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int); |
---|
322 | ZOO_DLL_EXPORT elements* dupElements(elements*); |
---|
323 | ZOO_DLL_EXPORT void addToElements(elements**,elements*); |
---|
324 | ZOO_DLL_EXPORT void dumpService(service*); |
---|
325 | ZOO_DLL_EXPORT void dumpServiceAsYAML(service*); |
---|
326 | ZOO_DLL_EXPORT service* dupService(service*); |
---|
327 | ZOO_DLL_EXPORT void dumpRegistry(registry*); |
---|
328 | ZOO_DLL_EXPORT bool addServiceToRegistry(registry**,char*,service*); |
---|
329 | ZOO_DLL_EXPORT void freeRegistry(registry**); |
---|
330 | ZOO_DLL_EXPORT service* getServiceFromRegistry(registry*,char*,char*); |
---|
331 | ZOO_DLL_EXPORT void inheritMap(map**,map*); |
---|
332 | ZOO_DLL_EXPORT void inheritIOType(iotype**,iotype*); |
---|
333 | ZOO_DLL_EXPORT void inheritElements(elements**,elements*); |
---|
334 | ZOO_DLL_EXPORT void inheritance(registry*,service**); |
---|
335 | ZOO_DLL_EXPORT void mapsToCharXXX(maps*,char***); |
---|
336 | ZOO_DLL_EXPORT void charxxxToMaps(char***,maps**); |
---|
337 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
---|
338 | // snprintf for Visual Studio compiler; |
---|
339 | // it is also used by services (e.g., GetStatus), therefore exported to shared library |
---|
340 | ZOO_DLL_EXPORT int snprintf(char *buffer, size_t n, const char *format, ...); |
---|
341 | #endif |
---|
342 | #ifdef __cplusplus |
---|
343 | } |
---|
344 | #endif |
---|
345 | |
---|
346 | #endif |
---|