[579] | 1 | /* |
---|
[1] | 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[576] | 4 | * Copyright (c) 2009-2015 GeoLabs SARL |
---|
[1] | 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 | |
---|
[216] | 30 | #ifdef WIN32 |
---|
[444] | 31 | #ifndef USE_MS |
---|
[375] | 32 | #define strncasecmp _strnicmp |
---|
| 33 | #define strcasecmp _stricmp |
---|
[444] | 34 | #endif |
---|
[375] | 35 | #ifndef snprintf |
---|
[216] | 36 | #define snprintf sprintf_s |
---|
[453] | 37 | #endif |
---|
| 38 | #define zStrdup _strdup |
---|
| 39 | #define zMkdir _mkdir |
---|
| 40 | #define zOpen _open |
---|
| 41 | #define zWrite _write |
---|
[507] | 42 | #define zSleep Sleep |
---|
[514] | 43 | #include <sys/timeb.h> |
---|
| 44 | struct ztimeval { |
---|
| 45 | long tv_sec; /* seconds */ |
---|
| 46 | long tv_usec; /* and microseconds */ |
---|
| 47 | }; |
---|
[554] | 48 | static int zGettimeofday(struct ztimeval* tp, void* tzp) |
---|
[514] | 49 | { |
---|
[554] | 50 | if (tp == 0) { |
---|
| 51 | return -1; |
---|
| 52 | } |
---|
| 53 | |
---|
[514] | 54 | struct _timeb theTime; |
---|
| 55 | _ftime(&theTime); |
---|
| 56 | tp->tv_sec = theTime.time; |
---|
| 57 | tp->tv_usec = theTime.millitm * 1000; |
---|
[554] | 58 | |
---|
| 59 | return 0; // The gettimeofday() function shall return 0 on success |
---|
[514] | 60 | } |
---|
[379] | 61 | #else |
---|
[579] | 62 | /** |
---|
| 63 | * The crossplatform strdup alias |
---|
| 64 | */ |
---|
[453] | 65 | #define zStrdup strdup |
---|
[579] | 66 | /** |
---|
| 67 | * The crossplatform mkdir alias |
---|
| 68 | */ |
---|
[453] | 69 | #define zMkdir mkdir |
---|
[579] | 70 | /** |
---|
| 71 | * The crossplatform open alias |
---|
| 72 | */ |
---|
[454] | 73 | #define zOpen open |
---|
[579] | 74 | /** |
---|
| 75 | * The crossplatform write alias |
---|
| 76 | */ |
---|
[454] | 77 | #define zWrite write |
---|
[579] | 78 | /** |
---|
| 79 | * The crossplatform sleep alias |
---|
| 80 | */ |
---|
[507] | 81 | #define zSleep sleep |
---|
[579] | 82 | /** |
---|
| 83 | * The crossplatform gettimeofday alias |
---|
| 84 | */ |
---|
[514] | 85 | #define zGettimeofday gettimeofday |
---|
[579] | 86 | /** |
---|
| 87 | * The crossplatform timeval alias |
---|
| 88 | */ |
---|
[514] | 89 | #define ztimeval timeval |
---|
[216] | 90 | #endif |
---|
| 91 | |
---|
[1] | 92 | #ifdef __cplusplus |
---|
| 93 | extern "C" { |
---|
| 94 | #endif |
---|
| 95 | |
---|
[444] | 96 | #ifdef WIN32 |
---|
| 97 | #ifdef USE_MS |
---|
| 98 | #include <mapserver.h> |
---|
| 99 | #endif |
---|
| 100 | #endif |
---|
[1] | 101 | #include <stdlib.h> |
---|
| 102 | #include <ctype.h> |
---|
| 103 | #include <stdio.h> |
---|
| 104 | #include <string.h> |
---|
[364] | 105 | #ifndef WIN32 |
---|
[618] | 106 | #include <ctype.h> |
---|
[490] | 107 | #ifndef bool |
---|
[1] | 108 | #define bool int |
---|
[490] | 109 | #endif |
---|
| 110 | #ifndef true |
---|
[579] | 111 | /** |
---|
| 112 | * Local true definition |
---|
| 113 | */ |
---|
[1] | 114 | #define true 1 |
---|
[579] | 115 | /** |
---|
| 116 | * Local false definition |
---|
| 117 | */ |
---|
[618] | 118 | #define false 0 |
---|
[490] | 119 | #endif |
---|
[364] | 120 | #endif |
---|
[9] | 121 | |
---|
[579] | 122 | /** |
---|
| 123 | * The global accepted status for a service |
---|
| 124 | */ |
---|
[1] | 125 | #define SERVICE_ACCEPTED 0 |
---|
[579] | 126 | /** |
---|
| 127 | * The global started status for a service |
---|
| 128 | */ |
---|
[1] | 129 | #define SERVICE_STARTED 1 |
---|
[579] | 130 | /** |
---|
| 131 | * The global paused status for a service |
---|
| 132 | */ |
---|
[1] | 133 | #define SERVICE_PAUSED 2 |
---|
[579] | 134 | /** |
---|
| 135 | * The global succeeded status for a service |
---|
| 136 | */ |
---|
[1] | 137 | #define SERVICE_SUCCEEDED 3 |
---|
[579] | 138 | /** |
---|
| 139 | * The global failed status for a service |
---|
| 140 | */ |
---|
[1] | 141 | #define SERVICE_FAILED 4 |
---|
[9] | 142 | |
---|
[579] | 143 | /** |
---|
| 144 | * The memory size to create an elements |
---|
| 145 | */ |
---|
[640] | 146 | #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*))) |
---|
[579] | 147 | /** |
---|
| 148 | * The memory size to create a map |
---|
| 149 | */ |
---|
[9] | 150 | #define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) |
---|
[579] | 151 | /** |
---|
| 152 | * The memory size to create an iotype |
---|
| 153 | */ |
---|
[9] | 154 | #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) |
---|
[579] | 155 | /** |
---|
| 156 | * The memory size to create a maps |
---|
| 157 | */ |
---|
[9] | 158 | #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE |
---|
[579] | 159 | /** |
---|
| 160 | * The memory size to create a service |
---|
| 161 | */ |
---|
[677] | 162 | #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)+sizeof(char*)+sizeof(char*) |
---|
[607] | 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*) |
---|
[1] | 171 | |
---|
[26] | 172 | #define SHMSZ 27 |
---|
[1] | 173 | |
---|
[465] | 174 | #include "version.h" |
---|
[1] | 175 | |
---|
[375] | 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 | |
---|
[9] | 183 | /** |
---|
[579] | 184 | * KVP linked list |
---|
[9] | 185 | */ |
---|
[1] | 186 | typedef struct map{ |
---|
[607] | 187 | char* name; //!< the key |
---|
| 188 | char* value; //!< the value |
---|
| 189 | struct map* next; //!< the pointer to the next map if any or NULL |
---|
[1] | 190 | } map; |
---|
| 191 | |
---|
| 192 | #ifdef WIN32 |
---|
| 193 | #define NULLMAP ((map*) 0) |
---|
| 194 | #else |
---|
| 195 | #define NULLMAP NULL |
---|
| 196 | #endif |
---|
| 197 | |
---|
[114] | 198 | /** |
---|
[579] | 199 | * linked list of map pointer |
---|
[114] | 200 | * |
---|
| 201 | * Small object to store WPS KVP set. |
---|
| 202 | */ |
---|
| 203 | typedef struct maps{ |
---|
[607] | 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 |
---|
[114] | 207 | } maps; |
---|
[601] | 208 | |
---|
[579] | 209 | /** |
---|
| 210 | * Not named linked list |
---|
[114] | 211 | * |
---|
| 212 | * Used to store informations about formats, such as mimeType, encoding ... |
---|
| 213 | */ |
---|
[1] | 214 | typedef struct iotype{ |
---|
[607] | 215 | struct map* content; //!< the content map |
---|
| 216 | struct iotype* next; //!< the pointer to the next iotype if any or NULL |
---|
[1] | 217 | } iotype; |
---|
| 218 | |
---|
[114] | 219 | /** |
---|
[579] | 220 | * Metadata information about input or output. |
---|
[114] | 221 | * |
---|
| 222 | * The elements are used to store metadata informations defined in the ZCFG. |
---|
| 223 | */ |
---|
[1] | 224 | typedef struct elements{ |
---|
[607] | 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 |
---|
[640] | 231 | struct elements* child; //!< the pointer to the children element if any (or NULL) |
---|
[607] | 232 | struct elements* next; //!< the pointer to the next element if any (or NULL) |
---|
[1] | 233 | } elements; |
---|
| 234 | |
---|
[579] | 235 | /** |
---|
| 236 | * Metadata informations about a full Service. |
---|
| 237 | */ |
---|
[1] | 238 | typedef struct service{ |
---|
[607] | 239 | char* name; //!< the name |
---|
[677] | 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 |
---|
[607] | 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 |
---|
[1] | 246 | } service; |
---|
| 247 | |
---|
[579] | 248 | /** |
---|
[607] | 249 | * Services chained list. |
---|
[579] | 250 | */ |
---|
[1] | 251 | typedef struct services{ |
---|
[607] | 252 | struct service* content; //!< the content service pointer |
---|
| 253 | struct services* next; //!< the pointer to the next services* |
---|
[1] | 254 | } services; |
---|
| 255 | |
---|
[579] | 256 | /** |
---|
[607] | 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 | |
---|
[1] | 265 | |
---|
[640] | 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); |
---|
[550] | 280 | |
---|
| 281 | |
---|
[640] | 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**); |
---|
[458] | 321 | #ifdef WIN32 |
---|
| 322 | extern char *url_encode(char *); |
---|
[640] | 323 | char* getMapsAsKVP(maps*,int,int); |
---|
[458] | 324 | #endif |
---|
| 325 | |
---|
[1] | 326 | #ifdef __cplusplus |
---|
| 327 | } |
---|
| 328 | #endif |
---|
| 329 | |
---|
| 330 | #endif |
---|