[579] | 1 | /* |
---|
[1] | 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[392] | 4 | * Copyright (c) 2009-2013 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_INTERNAL_H |
---|
| 26 | #define ZOO_SERVICE_INTERNAL_H 1 |
---|
| 27 | |
---|
| 28 | #pragma once |
---|
| 29 | |
---|
[579] | 30 | /** |
---|
| 31 | * The default service url (overriden by serverAddress) |
---|
| 32 | */ |
---|
[34] | 33 | #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/" |
---|
[579] | 34 | /** |
---|
| 35 | * The time size |
---|
| 36 | */ |
---|
[1] | 37 | #define TIME_SIZE 40 |
---|
| 38 | |
---|
[34] | 39 | #include <libintl.h> |
---|
| 40 | #include <locale.h> |
---|
[579] | 41 | /** |
---|
| 42 | * ZOO-Kernel internal messages translation function |
---|
| 43 | */ |
---|
[34] | 44 | #define _(String) dgettext ("zoo-kernel",String) |
---|
[579] | 45 | /** |
---|
| 46 | * ZOO-Services messages translation function |
---|
| 47 | */ |
---|
[34] | 48 | #define _ss(String) dgettext ("zoo-services",String) |
---|
| 49 | |
---|
[579] | 50 | /** |
---|
| 51 | * ZOO-Kernel was unable to create a lock |
---|
| 52 | */ |
---|
[507] | 53 | #define ZOO_LOCK_CREATE_FAILED -4 |
---|
[579] | 54 | /** |
---|
| 55 | * ZOO-Kernel was unable to acquire a lock |
---|
| 56 | */ |
---|
[507] | 57 | #define ZOO_LOCK_ACQUIRE_FAILED -5 |
---|
[579] | 58 | /** |
---|
| 59 | * ZOO-Kernel was unable to release a lock |
---|
| 60 | */ |
---|
[507] | 61 | #define ZOO_LOCK_RELEASE_FAILED -6 |
---|
| 62 | |
---|
[26] | 63 | #include <sys/stat.h> |
---|
[1] | 64 | #include <sys/types.h> |
---|
[478] | 65 | #include "cgic.h" |
---|
[216] | 66 | #ifndef WIN32 |
---|
[26] | 67 | #include <sys/ipc.h> |
---|
| 68 | #include <sys/shm.h> |
---|
[507] | 69 | #include <sys/sem.h> |
---|
[216] | 70 | #else |
---|
| 71 | #include <direct.h> |
---|
| 72 | #endif |
---|
[26] | 73 | #include <stdio.h> |
---|
[1] | 74 | #include <time.h> |
---|
| 75 | #include <ctype.h> |
---|
[453] | 76 | #ifdef WIN32 |
---|
| 77 | #ifndef USE_RUBY |
---|
| 78 | #include <unistd.h> |
---|
| 79 | #endif |
---|
| 80 | #endif |
---|
[1] | 81 | #ifndef WIN32 |
---|
| 82 | #include <xlocale.h> |
---|
| 83 | #endif |
---|
[490] | 84 | #include "ulinet.h" |
---|
| 85 | |
---|
[1] | 86 | #include "service.h" |
---|
| 87 | #include <openssl/sha.h> |
---|
[291] | 88 | #include <openssl/md5.h> |
---|
[1] | 89 | #include <openssl/hmac.h> |
---|
| 90 | #include <openssl/evp.h> |
---|
| 91 | #include <openssl/bio.h> |
---|
| 92 | #include <openssl/buffer.h> |
---|
| 93 | |
---|
[114] | 94 | extern int conf_read(const char*,maps*); |
---|
[1] | 95 | |
---|
[26] | 96 | #ifdef USE_JS |
---|
[364] | 97 | #ifdef WIN32 |
---|
| 98 | #define XP_WIN 1 |
---|
| 99 | #else |
---|
[26] | 100 | #define XP_UNIX 0 |
---|
[364] | 101 | #endif |
---|
[26] | 102 | #include "service_internal_js.h" |
---|
| 103 | #endif |
---|
| 104 | |
---|
[453] | 105 | |
---|
[1] | 106 | #ifdef __cplusplus |
---|
| 107 | extern "C" { |
---|
| 108 | #endif |
---|
| 109 | #include <libxml/parser.h> |
---|
[280] | 110 | #include <libxml/xpath.h> |
---|
| 111 | |
---|
[579] | 112 | /** |
---|
| 113 | * Maximum number of XML namespaces |
---|
| 114 | */ |
---|
| 115 | #define ZOO_NS_MAX 10 |
---|
| 116 | /** |
---|
| 117 | * Maximum number of XML docs |
---|
| 118 | */ |
---|
| 119 | #define ZOO_DOC_MAX 20 |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Global char* to store the serverAddress value of the mmmmmain section |
---|
| 123 | */ |
---|
[1] | 124 | static char* SERVICE_URL; |
---|
[579] | 125 | /** |
---|
| 126 | * Array of xmlNsPtr storing all used XML namespace |
---|
| 127 | */ |
---|
| 128 | static xmlNsPtr usedNs[ZOO_NS_MAX]; |
---|
| 129 | /** |
---|
| 130 | * Array storing names of the used XML namespace |
---|
| 131 | */ |
---|
| 132 | static char* nsName[ZOO_NS_MAX]; |
---|
| 133 | /** |
---|
| 134 | * Number of XML namespaces |
---|
| 135 | */ |
---|
[9] | 136 | static int nbNs=0; |
---|
[579] | 137 | /** |
---|
| 138 | * Array of xmlDocPtr storing XML docs |
---|
| 139 | */ |
---|
| 140 | static xmlDocPtr iDocs[ZOO_DOC_MAX]; |
---|
| 141 | /** |
---|
| 142 | * Number of XML docs |
---|
| 143 | */ |
---|
[490] | 144 | static int nbDocs=0; |
---|
[1] | 145 | |
---|
[465] | 146 | int getServiceFromYAML(maps*,char*,service**,char *name); |
---|
| 147 | int readServiceFile(maps*, char*,service**,char *); |
---|
[501] | 148 | int isValidLang(maps*,const char*); |
---|
[576] | 149 | void addLangAttr(xmlNodePtr,maps*); |
---|
[465] | 150 | |
---|
[375] | 151 | void printHeaders(maps*); |
---|
[216] | 152 | void unhandleStatus(maps*); |
---|
[471] | 153 | int _updateStatus(maps*); |
---|
[507] | 154 | char* _getStatus(maps*,int); |
---|
[26] | 155 | char* getStatus(int); |
---|
[507] | 156 | int removeShmLock(maps*, int); |
---|
[579] | 157 | /** |
---|
| 158 | * Cross platform type used for Lock identifier |
---|
| 159 | */ |
---|
[507] | 160 | #ifndef WIN32 |
---|
| 161 | #define semid int |
---|
| 162 | #else |
---|
| 163 | #define semid HANDLE |
---|
| 164 | #endif |
---|
| 165 | semid getShmLockId(maps*,int); |
---|
| 166 | int lockShm(semid); |
---|
| 167 | int unlockShm(semid); |
---|
[9] | 168 | |
---|
[26] | 169 | #ifdef USE_JS |
---|
| 170 | #endif |
---|
| 171 | |
---|
[550] | 172 | void readGeneratedFile(maps*,map*,char*); |
---|
| 173 | |
---|
[1] | 174 | void URLDecode(char *); |
---|
| 175 | char *url_encode(char *); |
---|
[328] | 176 | char *url_decode(char *); |
---|
[9] | 177 | char* getEncoding(maps*); |
---|
| 178 | |
---|
[114] | 179 | int zooXmlSearchForNs(const char*); |
---|
| 180 | int zooXmlAddNs(xmlNodePtr,const char*,const char*); |
---|
[9] | 181 | void zooXmlCleanupNs(); |
---|
[490] | 182 | |
---|
| 183 | int zooXmlAddDoc(xmlNodePtr,const char*,const char*); |
---|
| 184 | void zooXmlCleanupDocs(); |
---|
[1] | 185 | |
---|
| 186 | void printExceptionReportResponse(maps*,map*); |
---|
[26] | 187 | xmlNodePtr createExceptionReportNode(maps*,map*,int); |
---|
[114] | 188 | void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*); |
---|
[576] | 189 | xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*); |
---|
| 190 | xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*); |
---|
[1] | 191 | void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*); |
---|
[469] | 192 | void printDescribeProcessForProcess(maps*,xmlNodePtr,service*); |
---|
[490] | 193 | void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNodePtr); |
---|
[9] | 194 | void printDocument(maps*,xmlDocPtr,int); |
---|
[114] | 195 | void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*); |
---|
| 196 | void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); |
---|
| 197 | map* parseBoundingBox(const char*); |
---|
[76] | 198 | void printBoundingBox(xmlNsPtr,xmlNodePtr,map*); |
---|
| 199 | void printBoundingBoxDocument(maps*,maps*,FILE*); |
---|
[576] | 200 | void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); |
---|
| 201 | |
---|
[1] | 202 | void outputResponse(service*,maps*,maps*,map*,int,maps*,int); |
---|
| 203 | |
---|
[216] | 204 | char *base64(const char*,int); |
---|
| 205 | char *base64d(const char*,int,int*); |
---|
[88] | 206 | void ensureDecodedBase64(maps**); |
---|
[576] | 207 | void checkValidValue(map*,map**,const char*,const char**,int); |
---|
| 208 | char* addDefaultValues(maps**,elements*,maps*,int,map**); |
---|
[1] | 209 | |
---|
[459] | 210 | int errorException(maps *, const char *, const char *, const char*); |
---|
[9] | 211 | |
---|
[576] | 212 | xmlNodePtr soapEnvelope(maps*,xmlNodePtr); |
---|
[280] | 213 | int checkForSoapEnvelope(xmlDocPtr); |
---|
[587] | 214 | |
---|
| 215 | void addToCache(maps*,char*,char*,char*,int,char*,size_t); |
---|
[280] | 216 | char* isInCache(maps*,char*); |
---|
[492] | 217 | int runHttpRequests(maps**,maps**,HINTERNET*); |
---|
| 218 | int loadRemoteFile(maps**,map**,HINTERNET*,char*); |
---|
[392] | 219 | |
---|
[469] | 220 | char *readVSIFile(maps*,const char*); |
---|
| 221 | void parseIdentifier(maps*,char*,char*,char*); |
---|
[471] | 222 | int updateStatus( maps*,const int,const char*); |
---|
| 223 | char* getInputValue( maps*,const char*,size_t*); |
---|
| 224 | int setOutputValue( maps*, const char*, char*, size_t); |
---|
[578] | 225 | |
---|
| 226 | char* getLastErrorMessage(); |
---|
[1] | 227 | #ifdef __cplusplus |
---|
| 228 | } |
---|
| 229 | #endif |
---|
| 230 | |
---|
| 231 | #endif |
---|