[607] | 1 | /* |
---|
[1] | 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[392] | 4 | * Copyright 2008-2013 GeoLabs SARL. All rights reserved. |
---|
[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 | */ |
---|
[788] | 24 | |
---|
[541] | 25 | extern "C" int yylex (); |
---|
| 26 | extern "C" int crlex (); |
---|
[9] | 27 | |
---|
[822] | 28 | #ifdef META_DB |
---|
| 29 | #include "ogrsf_frmts.h" |
---|
| 30 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 31 | #include <gdal_priv.h> |
---|
| 32 | #endif |
---|
| 33 | #endif |
---|
| 34 | |
---|
[550] | 35 | #ifdef USE_OTB |
---|
| 36 | #include "service_internal_otb.h" |
---|
| 37 | #endif |
---|
| 38 | |
---|
[873] | 39 | #ifdef USE_R |
---|
| 40 | #include "service_internal_r.h" |
---|
| 41 | #endif |
---|
| 42 | |
---|
[822] | 43 | #ifdef USE_HPC |
---|
| 44 | #include "service_internal_hpc.h" |
---|
| 45 | #endif |
---|
| 46 | |
---|
[376] | 47 | #include "cgic.h" |
---|
| 48 | |
---|
[1] | 49 | #include <libxml/tree.h> |
---|
| 50 | #include <libxml/xmlmemory.h> |
---|
| 51 | #include <libxml/parser.h> |
---|
| 52 | #include <libxml/xpath.h> |
---|
| 53 | #include <libxml/xpathInternals.h> |
---|
| 54 | |
---|
| 55 | #include "ulinet.h" |
---|
| 56 | |
---|
[34] | 57 | #include <libintl.h> |
---|
| 58 | #include <locale.h> |
---|
[1] | 59 | #include <string.h> |
---|
| 60 | |
---|
| 61 | #include "service.h" |
---|
[34] | 62 | |
---|
[1] | 63 | #include "service_internal.h" |
---|
[640] | 64 | #include "server_internal.h" |
---|
| 65 | #include "response_print.h" |
---|
[621] | 66 | #include "request_parser.h" |
---|
[640] | 67 | #include "sqlapi.h" |
---|
[680] | 68 | #ifdef WIN32 |
---|
| 69 | #include "caching.h" |
---|
[877] | 70 | extern wchar_t**_wenviron; |
---|
[680] | 71 | #endif |
---|
[33] | 72 | |
---|
[822] | 73 | #ifdef META_DB |
---|
| 74 | #include "meta_sql.h" |
---|
| 75 | #endif |
---|
| 76 | |
---|
[33] | 77 | #ifdef USE_PYTHON |
---|
[1] | 78 | #include "service_internal_python.h" |
---|
[33] | 79 | #endif |
---|
[1] | 80 | |
---|
[634] | 81 | #ifdef USE_SAGA |
---|
| 82 | #include "service_internal_saga.h" |
---|
| 83 | #endif |
---|
| 84 | |
---|
[1] | 85 | #ifdef USE_JAVA |
---|
| 86 | #include "service_internal_java.h" |
---|
| 87 | #endif |
---|
| 88 | |
---|
| 89 | #ifdef USE_PHP |
---|
| 90 | #include "service_internal_php.h" |
---|
| 91 | #endif |
---|
| 92 | |
---|
| 93 | #ifdef USE_JS |
---|
| 94 | #include "service_internal_js.h" |
---|
| 95 | #endif |
---|
| 96 | |
---|
[453] | 97 | #ifdef USE_RUBY |
---|
| 98 | #include "service_internal_ruby.h" |
---|
| 99 | #endif |
---|
| 100 | |
---|
[25] | 101 | #ifdef USE_PERL |
---|
| 102 | #include "service_internal_perl.h" |
---|
| 103 | #endif |
---|
[1] | 104 | |
---|
[794] | 105 | #ifdef USE_MONO |
---|
| 106 | #include "service_internal_mono.h" |
---|
| 107 | #endif |
---|
| 108 | |
---|
[839] | 109 | #include "service_json.h" |
---|
| 110 | #include "service_callback.h" |
---|
| 111 | |
---|
[1] | 112 | #include <dirent.h> |
---|
| 113 | #include <signal.h> |
---|
[877] | 114 | #ifndef WIN32 |
---|
[854] | 115 | #include <execinfo.h> |
---|
[877] | 116 | #endif |
---|
[1] | 117 | #include <unistd.h> |
---|
| 118 | #ifndef WIN32 |
---|
| 119 | #include <dlfcn.h> |
---|
| 120 | #include <libgen.h> |
---|
| 121 | #else |
---|
| 122 | #include <windows.h> |
---|
| 123 | #include <direct.h> |
---|
[364] | 124 | #include <sys/types.h> |
---|
| 125 | #include <sys/stat.h> |
---|
| 126 | #include <unistd.h> |
---|
| 127 | #define pid_t int; |
---|
[1] | 128 | #endif |
---|
| 129 | #include <fcntl.h> |
---|
| 130 | #include <time.h> |
---|
| 131 | #include <stdarg.h> |
---|
| 132 | |
---|
[854] | 133 | #include <libxml/tree.h> |
---|
| 134 | #include <libxml/parser.h> |
---|
| 135 | #include <libxml/xpath.h> |
---|
| 136 | #include <libxml/xpathInternals.h> |
---|
| 137 | |
---|
| 138 | #include <libxslt/xslt.h> |
---|
| 139 | #include <libxslt/xsltInternals.h> |
---|
| 140 | #include <libxslt/transform.h> |
---|
| 141 | #include <libxslt/xsltutils.h> |
---|
| 142 | |
---|
[772] | 143 | #ifndef WIN32 |
---|
| 144 | extern char **environ; |
---|
| 145 | #endif |
---|
| 146 | |
---|
[788] | 147 | |
---|
[364] | 148 | #ifdef WIN32 |
---|
[541] | 149 | extern "C" |
---|
| 150 | { |
---|
| 151 | __declspec (dllexport) char *strcasestr (char const *a, char const *b) |
---|
[370] | 152 | #ifndef USE_MS |
---|
[541] | 153 | { |
---|
| 154 | char *x = zStrdup (a); |
---|
| 155 | char *y = zStrdup (b); |
---|
| 156 | |
---|
| 157 | x = _strlwr (x); |
---|
| 158 | y = _strlwr (y); |
---|
| 159 | char *pos = strstr (x, y); |
---|
| 160 | char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); |
---|
| 161 | free (x); |
---|
| 162 | free (y); |
---|
| 163 | return ret; |
---|
| 164 | }; |
---|
[370] | 165 | #else |
---|
[541] | 166 | ; |
---|
[370] | 167 | #endif |
---|
[364] | 168 | } |
---|
| 169 | #endif |
---|
| 170 | |
---|
[607] | 171 | /** |
---|
| 172 | * Translation function for zoo-kernel |
---|
| 173 | */ |
---|
[34] | 174 | #define _(String) dgettext ("zoo-kernel",String) |
---|
[607] | 175 | /** |
---|
| 176 | * Translation function for zoo-service |
---|
| 177 | */ |
---|
[376] | 178 | #define __(String) dgettext ("zoo-service",String) |
---|
[34] | 179 | |
---|
[582] | 180 | #ifdef WIN32 |
---|
[839] | 181 | #ifndef PROGRAMNAME |
---|
| 182 | #define PROGRAMNAME "zoo_loader.cgi" |
---|
[582] | 183 | #endif |
---|
[839] | 184 | #endif |
---|
[582] | 185 | |
---|
[34] | 186 | |
---|
[607] | 187 | /** |
---|
| 188 | * Replace a char by another one in a string |
---|
| 189 | * |
---|
| 190 | * @param str the string to update |
---|
| 191 | * @param toReplace the char to replace |
---|
| 192 | * @param toReplaceBy the char that will be used |
---|
| 193 | */ |
---|
[541] | 194 | void |
---|
| 195 | translateChar (char *str, char toReplace, char toReplaceBy) |
---|
| 196 | { |
---|
| 197 | int i = 0, len = strlen (str); |
---|
| 198 | for (i = 0; i < len; i++) |
---|
| 199 | { |
---|
| 200 | if (str[i] == toReplace) |
---|
| 201 | str[i] = toReplaceBy; |
---|
| 202 | } |
---|
[34] | 203 | } |
---|
| 204 | |
---|
[607] | 205 | /** |
---|
[765] | 206 | * Dump back the final file fbkp1 to fbkp |
---|
| 207 | * |
---|
| 208 | * @param m the conf maps containing the main.cfg settings |
---|
| 209 | * @param fbkp the string corresponding to the name of the file |
---|
| 210 | * @param fbkp1 the string corresponding to the name of the file |
---|
| 211 | */ |
---|
| 212 | int dumpBackFinalFile(maps* m,char* fbkp,char* fbkp1) |
---|
| 213 | { |
---|
| 214 | FILE *f2 = fopen (fbkp1, "rb"); |
---|
| 215 | #ifndef RELY_ON_DB |
---|
| 216 | semid lid = getShmLockId (m, 1); |
---|
| 217 | if (lid < 0) |
---|
| 218 | return -1; |
---|
| 219 | lockShm (lid); |
---|
| 220 | #endif |
---|
| 221 | FILE *f3 = fopen (fbkp, "wb+"); |
---|
| 222 | free (fbkp); |
---|
| 223 | fseek (f2, 0, SEEK_END); |
---|
| 224 | long flen = ftell (f2); |
---|
| 225 | fseek (f2, 0, SEEK_SET); |
---|
| 226 | char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); |
---|
| 227 | fread (tmps1, flen, 1, f2); |
---|
| 228 | #ifdef WIN32 |
---|
| 229 | char *pchr=strrchr(tmps1,'>'); |
---|
| 230 | flen=strlen(tmps1)-strlen(pchr)+1; |
---|
| 231 | tmps1[flen]=0; |
---|
| 232 | #endif |
---|
| 233 | fwrite (tmps1, 1, flen, f3); |
---|
| 234 | fclose (f2); |
---|
| 235 | fclose (f3); |
---|
[839] | 236 | free(tmps1); |
---|
[765] | 237 | return 1; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /** |
---|
[607] | 241 | * Recursivelly parse zcfg starting from the ZOO-Kernel cwd. |
---|
| 242 | * Call the func function given in arguments after parsing the ZCFG file. |
---|
| 243 | * |
---|
| 244 | * @param m the conf maps containing the main.cfg settings |
---|
| 245 | * @param r the registry containing profiles hierarchy |
---|
| 246 | * @param n the root XML Node to add the sub-elements |
---|
| 247 | * @param conf_dir the location of the main.cfg file (basically cwd) |
---|
| 248 | * @param prefix the current prefix if any, or NULL |
---|
| 249 | * @param saved_stdout the saved stdout identifier |
---|
| 250 | * @param level the current level (number of sub-directories to reach the |
---|
| 251 | * current path) |
---|
[676] | 252 | * @param func a pointer to a function having 4 parameters |
---|
| 253 | * (registry*, maps*, xmlNodePtr and service*). |
---|
[607] | 254 | * @see inheritance, readServiceFile |
---|
| 255 | */ |
---|
| 256 | int |
---|
[839] | 257 | recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, |
---|
[676] | 258 | char *prefix, int saved_stdout, int level, |
---|
[839] | 259 | void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) |
---|
[541] | 260 | { |
---|
[469] | 261 | struct dirent *dp; |
---|
[541] | 262 | int scount = 0; |
---|
[469] | 263 | |
---|
[541] | 264 | if (conf_dir == NULL) |
---|
[469] | 265 | return 1; |
---|
[541] | 266 | DIR *dirp = opendir (conf_dir); |
---|
| 267 | if (dirp == NULL) |
---|
| 268 | { |
---|
| 269 | if (level > 0) |
---|
| 270 | return 1; |
---|
| 271 | else |
---|
| 272 | return -1; |
---|
| 273 | } |
---|
[469] | 274 | char tmp1[25]; |
---|
[541] | 275 | sprintf (tmp1, "sprefix_%d", level); |
---|
[469] | 276 | char levels[17]; |
---|
[541] | 277 | sprintf (levels, "%d", level); |
---|
| 278 | setMapInMaps (m, "lenv", "level", levels); |
---|
| 279 | while ((dp = readdir (dirp)) != NULL) |
---|
| 280 | if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.' |
---|
| 281 | && strstr (dp->d_name, ".") == NULL) |
---|
| 282 | { |
---|
[469] | 283 | |
---|
[541] | 284 | char *tmp = |
---|
| 285 | (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) * |
---|
| 286 | sizeof (char)); |
---|
| 287 | sprintf (tmp, "%s/%s", conf_dir, dp->d_name); |
---|
[469] | 288 | |
---|
[541] | 289 | if (prefix != NULL) |
---|
| 290 | { |
---|
| 291 | prefix = NULL; |
---|
| 292 | } |
---|
| 293 | prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char)); |
---|
| 294 | sprintf (prefix, "%s.", dp->d_name); |
---|
| 295 | |
---|
| 296 | //map* tmpMap=getMapFromMaps(m,"lenv",tmp1); |
---|
| 297 | |
---|
| 298 | int res; |
---|
| 299 | if (prefix != NULL) |
---|
| 300 | { |
---|
| 301 | setMapInMaps (m, "lenv", tmp1, prefix); |
---|
| 302 | char levels1[17]; |
---|
| 303 | sprintf (levels1, "%d", level + 1); |
---|
| 304 | setMapInMaps (m, "lenv", "level", levels1); |
---|
| 305 | res = |
---|
[839] | 306 | recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1, |
---|
[541] | 307 | func); |
---|
| 308 | sprintf (levels1, "%d", level); |
---|
| 309 | setMapInMaps (m, "lenv", "level", levels1); |
---|
| 310 | free (prefix); |
---|
| 311 | prefix = NULL; |
---|
| 312 | } |
---|
| 313 | else |
---|
| 314 | res = -1; |
---|
| 315 | free (tmp); |
---|
| 316 | if (res < 0) |
---|
| 317 | { |
---|
| 318 | return res; |
---|
| 319 | } |
---|
[469] | 320 | } |
---|
[541] | 321 | else |
---|
| 322 | { |
---|
[557] | 323 | char* extn = strstr(dp->d_name, ".zcfg"); |
---|
[850] | 324 | if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6) |
---|
[541] | 325 | { |
---|
| 326 | int t; |
---|
| 327 | char tmps1[1024]; |
---|
| 328 | memset (tmps1, 0, 1024); |
---|
| 329 | snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name); |
---|
[789] | 330 | |
---|
[850] | 331 | char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name); |
---|
| 332 | memset (tmpsn, 0, strlen(dp->d_name)-4); |
---|
| 333 | snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name); |
---|
[789] | 334 | |
---|
| 335 | map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn); |
---|
| 336 | if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block |
---|
| 337 | service *s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 338 | if (s1 == NULL) |
---|
| 339 | { |
---|
| 340 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 341 | errorException (m, _("Unable to allocate memory"), |
---|
| 342 | "InternalError", NULL); |
---|
| 343 | return -1; |
---|
| 344 | } |
---|
[839] | 345 | #ifdef DEBUG |
---|
[789] | 346 | fprintf (stderr, "#################\n%s\n#################\n", |
---|
| 347 | tmps1); |
---|
| 348 | #endif |
---|
| 349 | t = readServiceFile (m, tmps1, &s1, tmpsn); |
---|
| 350 | free (tmpsn); |
---|
| 351 | if (t < 0) |
---|
| 352 | { |
---|
| 353 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 354 | char tmp01[1024]; |
---|
| 355 | if (tmp00 != NULL) |
---|
| 356 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 357 | dp->d_name, tmp00->value); |
---|
| 358 | else |
---|
| 359 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), |
---|
| 360 | dp->d_name); |
---|
| 361 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 362 | errorException (m, tmp01, "InternalError", NULL); |
---|
| 363 | return -1; |
---|
| 364 | } |
---|
| 365 | #ifdef DEBUG |
---|
| 366 | dumpService (s1); |
---|
| 367 | fflush (stdout); |
---|
| 368 | fflush (stderr); |
---|
| 369 | #endif |
---|
[877] | 370 | if(s1!=NULL) |
---|
| 371 | inheritance(r,&s1); |
---|
[839] | 372 | func (r, m, doc, n, s1); |
---|
[789] | 373 | freeService (&s1); |
---|
| 374 | free (s1); |
---|
| 375 | scount++; |
---|
| 376 | } |
---|
[541] | 377 | } |
---|
[469] | 378 | } |
---|
[541] | 379 | (void) closedir (dirp); |
---|
[469] | 380 | return 1; |
---|
| 381 | } |
---|
| 382 | |
---|
[607] | 383 | /** |
---|
| 384 | * Signal handling function which simply call exit(0). |
---|
| 385 | * |
---|
| 386 | * @param sig the signal number |
---|
| 387 | */ |
---|
[541] | 388 | void |
---|
| 389 | donothing (int sig) |
---|
| 390 | { |
---|
[478] | 391 | #ifdef DEBUG |
---|
[605] | 392 | fprintf (stderr, "Signal %d after the ZOO-Kernel returned result!\n", sig); |
---|
[478] | 393 | #endif |
---|
[541] | 394 | exit (0); |
---|
[105] | 395 | } |
---|
| 396 | |
---|
[607] | 397 | /** |
---|
| 398 | * Signal handling function which create an ExceptionReport node containing the |
---|
| 399 | * information message corresponding to the signal number. |
---|
| 400 | * |
---|
| 401 | * @param sig the signal number |
---|
| 402 | */ |
---|
[541] | 403 | void |
---|
| 404 | sig_handler (int sig) |
---|
| 405 | { |
---|
[854] | 406 | |
---|
[9] | 407 | char tmp[100]; |
---|
[114] | 408 | const char *ssig; |
---|
[541] | 409 | switch (sig) |
---|
| 410 | { |
---|
| 411 | case SIGSEGV: |
---|
| 412 | ssig = "SIGSEGV"; |
---|
| 413 | break; |
---|
| 414 | case SIGTERM: |
---|
| 415 | ssig = "SIGTERM"; |
---|
| 416 | break; |
---|
| 417 | case SIGINT: |
---|
| 418 | ssig = "SIGINT"; |
---|
| 419 | break; |
---|
| 420 | case SIGILL: |
---|
| 421 | ssig = "SIGILL"; |
---|
| 422 | break; |
---|
| 423 | case SIGFPE: |
---|
| 424 | ssig = "SIGFPE"; |
---|
| 425 | break; |
---|
| 426 | case SIGABRT: |
---|
| 427 | ssig = "SIGABRT"; |
---|
| 428 | break; |
---|
| 429 | default: |
---|
| 430 | ssig = "UNKNOWN"; |
---|
| 431 | break; |
---|
| 432 | } |
---|
| 433 | sprintf (tmp, |
---|
| 434 | _ |
---|
[854] | 435 | ("ZOO Kernel failed to process your request, receiving signal %d = %s "), |
---|
[541] | 436 | sig, ssig); |
---|
| 437 | errorException (NULL, tmp, "InternalError", NULL); |
---|
[10] | 438 | #ifdef DEBUG |
---|
[541] | 439 | fprintf (stderr, "Not this time!\n"); |
---|
[10] | 440 | #endif |
---|
[541] | 441 | exit (0); |
---|
[1] | 442 | } |
---|
| 443 | |
---|
[607] | 444 | /** |
---|
| 445 | * Load a service provider and run the service function. |
---|
| 446 | * |
---|
| 447 | * @param myMap the conf maps containing the main.cfg settings |
---|
| 448 | * @param s1 the service structure |
---|
| 449 | * @param request_inputs map storing all the request parameters |
---|
| 450 | * @param inputs the inputs maps |
---|
| 451 | * @param ioutputs the outputs maps |
---|
| 452 | * @param eres the result returned by the service execution |
---|
| 453 | */ |
---|
[541] | 454 | void |
---|
| 455 | loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, |
---|
| 456 | maps ** inputs, maps ** ioutputs, int *eres) |
---|
| 457 | { |
---|
[34] | 458 | char tmps1[1024]; |
---|
| 459 | char ntmp[1024]; |
---|
[541] | 460 | maps *m = *myMap; |
---|
| 461 | maps *request_output_real_format = *ioutputs; |
---|
| 462 | maps *request_input_real_format = *inputs; |
---|
[34] | 463 | /** |
---|
| 464 | * Extract serviceType to know what kind of service should be loaded |
---|
| 465 | */ |
---|
[541] | 466 | map *r_inputs = NULL; |
---|
[784] | 467 | map* cwdMap=getMapFromMaps(m,"main","servicePath"); |
---|
| 468 | if(cwdMap!=NULL){ |
---|
| 469 | sprintf(ntmp,"%s",cwdMap->value); |
---|
| 470 | }else{ |
---|
[34] | 471 | #ifndef WIN32 |
---|
[784] | 472 | getcwd (ntmp, 1024); |
---|
[34] | 473 | #else |
---|
[784] | 474 | _getcwd (ntmp, 1024); |
---|
[34] | 475 | #endif |
---|
[784] | 476 | } |
---|
[541] | 477 | r_inputs = getMap (s1->content, "serviceType"); |
---|
[34] | 478 | #ifdef DEBUG |
---|
[541] | 479 | fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value); |
---|
| 480 | fflush (stderr); |
---|
[34] | 481 | #endif |
---|
[605] | 482 | |
---|
| 483 | map* libp = getMapFromMaps(m, "main", "libPath"); |
---|
[712] | 484 | |
---|
[541] | 485 | if (strlen (r_inputs->value) == 1 |
---|
| 486 | && strncasecmp (r_inputs->value, "C", 1) == 0) |
---|
[605] | 487 | { |
---|
| 488 | if (libp != NULL && libp->value != NULL) { |
---|
| 489 | r_inputs = getMap (s1->content, "ServiceProvider"); |
---|
| 490 | sprintf (tmps1, "%s/%s", libp->value, r_inputs->value); |
---|
| 491 | } |
---|
| 492 | else { |
---|
| 493 | r_inputs = getMap (request_inputs, "metapath"); |
---|
| 494 | if (r_inputs != NULL) |
---|
| 495 | sprintf (tmps1, "%s/%s", ntmp, r_inputs->value); |
---|
| 496 | else |
---|
| 497 | sprintf (tmps1, "%s/", ntmp); |
---|
| 498 | |
---|
| 499 | char *altPath = zStrdup (tmps1); |
---|
| 500 | r_inputs = getMap (s1->content, "ServiceProvider"); |
---|
| 501 | sprintf (tmps1, "%s/%s", altPath, r_inputs->value); |
---|
| 502 | free (altPath); |
---|
| 503 | } |
---|
[34] | 504 | #ifdef DEBUG |
---|
[541] | 505 | fprintf (stderr, "Trying to load %s\n", tmps1); |
---|
[34] | 506 | #endif |
---|
| 507 | #ifdef WIN32 |
---|
[541] | 508 | HINSTANCE so = |
---|
| 509 | LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); |
---|
[34] | 510 | #else |
---|
[541] | 511 | void *so = dlopen (tmps1, RTLD_LAZY); |
---|
[34] | 512 | #endif |
---|
[57] | 513 | #ifdef WIN32 |
---|
[578] | 514 | char* errstr = getLastErrorMessage(); |
---|
[34] | 515 | #else |
---|
[541] | 516 | char *errstr; |
---|
| 517 | errstr = dlerror (); |
---|
[34] | 518 | #endif |
---|
[478] | 519 | #ifdef DEBUG |
---|
[578] | 520 | fprintf (stderr, "%s loaded (%s) \n", tmps1, errstr); |
---|
[478] | 521 | #endif |
---|
[541] | 522 | if (so != NULL) |
---|
| 523 | { |
---|
[34] | 524 | #ifdef DEBUG |
---|
[541] | 525 | fprintf (stderr, "Library loaded %s \n", errstr); |
---|
| 526 | fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value); |
---|
[34] | 527 | #endif |
---|
[541] | 528 | r_inputs = getMap (s1->content, "serviceType"); |
---|
[34] | 529 | #ifdef DEBUG |
---|
[541] | 530 | dumpMap (r_inputs); |
---|
| 531 | fprintf (stderr, "%s\n", r_inputs->value); |
---|
| 532 | fflush (stderr); |
---|
[34] | 533 | #endif |
---|
[541] | 534 | if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0) |
---|
| 535 | { |
---|
| 536 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
| 537 | char fname[1024]; |
---|
| 538 | sprintf (fname, "%s_", r_inputs->value); |
---|
[34] | 539 | #ifdef DEBUG |
---|
[541] | 540 | fprintf (stderr, "Try to load function %s\n", fname); |
---|
[34] | 541 | #endif |
---|
| 542 | #ifdef WIN32 |
---|
[541] | 543 | typedef int (CALLBACK * execute_t) (char ***, char ***, |
---|
| 544 | char ***); |
---|
| 545 | execute_t execute = (execute_t) GetProcAddress (so, fname); |
---|
[34] | 546 | #else |
---|
[541] | 547 | typedef int (*execute_t) (char ***, char ***, char ***); |
---|
| 548 | execute_t execute = (execute_t) dlsym (so, fname); |
---|
[34] | 549 | #endif |
---|
| 550 | #ifdef DEBUG |
---|
| 551 | #ifdef WIN32 |
---|
[578] | 552 | errstr = getLastErrorMessage(); |
---|
[34] | 553 | #else |
---|
[541] | 554 | errstr = dlerror (); |
---|
[34] | 555 | #endif |
---|
[541] | 556 | fprintf (stderr, "Function loaded %s\n", errstr); |
---|
| 557 | #endif |
---|
[34] | 558 | |
---|
[541] | 559 | char main_conf[10][30][1024]; |
---|
| 560 | char inputs[10][30][1024]; |
---|
| 561 | char outputs[10][30][1024]; |
---|
| 562 | for (int i = 0; i < 10; i++) |
---|
| 563 | { |
---|
| 564 | for (int j = 0; j < 30; j++) |
---|
| 565 | { |
---|
| 566 | memset (main_conf[i][j], 0, 1024); |
---|
| 567 | memset (inputs[i][j], 0, 1024); |
---|
| 568 | memset (outputs[i][j], 0, 1024); |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | mapsToCharXXX (m, (char ***) main_conf); |
---|
| 572 | mapsToCharXXX (request_input_real_format, (char ***) inputs); |
---|
| 573 | mapsToCharXXX (request_output_real_format, (char ***) outputs); |
---|
| 574 | *eres = |
---|
| 575 | execute ((char ***) &main_conf[0], (char ***) &inputs[0], |
---|
| 576 | (char ***) &outputs[0]); |
---|
[34] | 577 | #ifdef DEBUG |
---|
[541] | 578 | fprintf (stderr, "Function run successfully \n"); |
---|
[34] | 579 | #endif |
---|
[541] | 580 | charxxxToMaps ((char ***) &outputs[0], |
---|
| 581 | &request_output_real_format); |
---|
| 582 | } |
---|
| 583 | else |
---|
| 584 | { |
---|
[34] | 585 | #ifdef DEBUG |
---|
| 586 | #ifdef WIN32 |
---|
[578] | 587 | errstr = getLastErrorMessage(); |
---|
| 588 | fprintf (stderr, "Function %s failed to load because of %s\n", |
---|
[541] | 589 | r_inputs->value, errstr); |
---|
[34] | 590 | #endif |
---|
| 591 | #endif |
---|
[541] | 592 | r_inputs = getMapFromMaps (m, "lenv", "Identifier"); |
---|
[34] | 593 | #ifdef DEBUG |
---|
[541] | 594 | fprintf (stderr, "Try to load function %s\n", r_inputs->value); |
---|
[34] | 595 | #endif |
---|
[541] | 596 | typedef int (*execute_t) (maps **, maps **, maps **); |
---|
[34] | 597 | #ifdef WIN32 |
---|
[541] | 598 | execute_t execute = |
---|
| 599 | (execute_t) GetProcAddress (so, r_inputs->value); |
---|
[34] | 600 | #else |
---|
[541] | 601 | execute_t execute = (execute_t) dlsym (so, r_inputs->value); |
---|
[34] | 602 | #endif |
---|
| 603 | |
---|
[541] | 604 | if (execute == NULL) |
---|
| 605 | { |
---|
[469] | 606 | #ifdef WIN32 |
---|
[578] | 607 | errstr = getLastErrorMessage(); |
---|
[469] | 608 | #else |
---|
[541] | 609 | errstr = dlerror (); |
---|
[469] | 610 | #endif |
---|
[541] | 611 | char *tmpMsg = |
---|
| 612 | (char *) malloc (2048 + strlen (r_inputs->value)); |
---|
| 613 | sprintf (tmpMsg, |
---|
| 614 | _ |
---|
[781] | 615 | ("Error occurred while running the %s function: %s"), |
---|
[541] | 616 | r_inputs->value, errstr); |
---|
| 617 | errorException (m, tmpMsg, "InternalError", NULL); |
---|
| 618 | free (tmpMsg); |
---|
[478] | 619 | #ifdef DEBUG |
---|
[541] | 620 | fprintf (stderr, "Function %s error %s\n", r_inputs->value, |
---|
| 621 | errstr); |
---|
[478] | 622 | #endif |
---|
[541] | 623 | *eres = -1; |
---|
| 624 | return; |
---|
| 625 | } |
---|
[469] | 626 | |
---|
[34] | 627 | #ifdef DEBUG |
---|
| 628 | #ifdef WIN32 |
---|
[578] | 629 | errstr = getLastErrorMessage(); |
---|
[34] | 630 | #else |
---|
[541] | 631 | errstr = dlerror (); |
---|
[34] | 632 | #endif |
---|
[541] | 633 | fprintf (stderr, "Function loaded %s\n", errstr); |
---|
| 634 | #endif |
---|
[34] | 635 | |
---|
| 636 | #ifdef DEBUG |
---|
[541] | 637 | fprintf (stderr, "Now run the function \n"); |
---|
| 638 | fflush (stderr); |
---|
[34] | 639 | #endif |
---|
[541] | 640 | *eres = |
---|
| 641 | execute (&m, &request_input_real_format, |
---|
| 642 | &request_output_real_format); |
---|
[34] | 643 | #ifdef DEBUG |
---|
[541] | 644 | fprintf (stderr, "Function loaded and returned %d\n", eres); |
---|
| 645 | fflush (stderr); |
---|
[34] | 646 | #endif |
---|
[541] | 647 | } |
---|
[216] | 648 | #ifdef WIN32 |
---|
[541] | 649 | *ioutputs = dupMaps (&request_output_real_format); |
---|
| 650 | FreeLibrary (so); |
---|
[216] | 651 | #else |
---|
[541] | 652 | dlclose (so); |
---|
[216] | 653 | #endif |
---|
[541] | 654 | } |
---|
| 655 | else |
---|
| 656 | { |
---|
[34] | 657 | /** |
---|
| 658 | * Unable to load the specified shared library |
---|
| 659 | */ |
---|
[541] | 660 | char tmps[1024]; |
---|
[34] | 661 | #ifdef WIN32 |
---|
[578] | 662 | errstr = getLastErrorMessage(); |
---|
[34] | 663 | #else |
---|
[578] | 664 | errstr = dlerror (); |
---|
[34] | 665 | #endif |
---|
[605] | 666 | sprintf (tmps, _("Unable to load C Library %s"), errstr); |
---|
[576] | 667 | errorException(m,tmps,"InternalError",NULL); |
---|
[541] | 668 | *eres = -1; |
---|
| 669 | } |
---|
[34] | 670 | } |
---|
| 671 | else |
---|
[550] | 672 | |
---|
[822] | 673 | #ifdef USE_HPC |
---|
| 674 | if (strncasecmp (r_inputs->value, "HPC", 3) == 0) |
---|
| 675 | { |
---|
| 676 | *eres = |
---|
| 677 | zoo_hpc_support (&m, request_inputs, s1, |
---|
| 678 | &request_input_real_format, |
---|
| 679 | &request_output_real_format); |
---|
| 680 | } |
---|
| 681 | else |
---|
| 682 | #endif |
---|
| 683 | |
---|
[634] | 684 | #ifdef USE_SAGA |
---|
[822] | 685 | if (strncasecmp (r_inputs->value, "SAGA", 4) == 0) |
---|
[634] | 686 | { |
---|
| 687 | *eres = |
---|
| 688 | zoo_saga_support (&m, request_inputs, s1, |
---|
| 689 | &request_input_real_format, |
---|
| 690 | &request_output_real_format); |
---|
| 691 | } |
---|
| 692 | else |
---|
| 693 | #endif |
---|
| 694 | |
---|
[550] | 695 | #ifdef USE_OTB |
---|
[822] | 696 | if (strncasecmp (r_inputs->value, "OTB", 3) == 0) |
---|
[550] | 697 | { |
---|
| 698 | *eres = |
---|
| 699 | zoo_otb_support (&m, request_inputs, s1, |
---|
| 700 | &request_input_real_format, |
---|
| 701 | &request_output_real_format); |
---|
| 702 | } |
---|
| 703 | else |
---|
| 704 | #endif |
---|
[34] | 705 | #ifdef USE_PYTHON |
---|
[541] | 706 | if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0) |
---|
[712] | 707 | { |
---|
[541] | 708 | *eres = |
---|
| 709 | zoo_python_support (&m, request_inputs, s1, |
---|
| 710 | &request_input_real_format, |
---|
| 711 | &request_output_real_format); |
---|
[34] | 712 | } |
---|
[541] | 713 | else |
---|
[34] | 714 | #endif |
---|
[541] | 715 | |
---|
[873] | 716 | #ifdef USE_R |
---|
| 717 | if (strncasecmp (r_inputs->value, "R", 6) == 0) |
---|
| 718 | { |
---|
| 719 | *eres = |
---|
| 720 | zoo_r_support (&m, request_inputs, s1, |
---|
| 721 | &request_input_real_format, |
---|
| 722 | &request_output_real_format); |
---|
| 723 | } |
---|
| 724 | else |
---|
| 725 | #endif |
---|
| 726 | |
---|
[34] | 727 | #ifdef USE_JAVA |
---|
[541] | 728 | if (strncasecmp (r_inputs->value, "JAVA", 4) == 0) |
---|
| 729 | { |
---|
| 730 | *eres = |
---|
| 731 | zoo_java_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 732 | &request_output_real_format); |
---|
| 733 | } |
---|
| 734 | else |
---|
[34] | 735 | #endif |
---|
| 736 | |
---|
| 737 | #ifdef USE_PHP |
---|
[541] | 738 | if (strncasecmp (r_inputs->value, "PHP", 3) == 0) |
---|
| 739 | { |
---|
| 740 | *eres = |
---|
| 741 | zoo_php_support (&m, request_inputs, s1, &request_input_real_format, |
---|
[788] | 742 | &request_output_real_format); |
---|
[541] | 743 | } |
---|
| 744 | else |
---|
[34] | 745 | #endif |
---|
[541] | 746 | |
---|
| 747 | |
---|
[34] | 748 | #ifdef USE_PERL |
---|
[541] | 749 | if (strncasecmp (r_inputs->value, "PERL", 4) == 0) |
---|
| 750 | { |
---|
| 751 | *eres = |
---|
| 752 | zoo_perl_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 753 | &request_output_real_format); |
---|
| 754 | } |
---|
| 755 | else |
---|
[34] | 756 | #endif |
---|
| 757 | |
---|
| 758 | #ifdef USE_JS |
---|
[541] | 759 | if (strncasecmp (r_inputs->value, "JS", 2) == 0) |
---|
| 760 | { |
---|
| 761 | *eres = |
---|
| 762 | zoo_js_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 763 | &request_output_real_format); |
---|
| 764 | } |
---|
| 765 | else |
---|
[34] | 766 | #endif |
---|
[453] | 767 | |
---|
| 768 | #ifdef USE_RUBY |
---|
[541] | 769 | if (strncasecmp (r_inputs->value, "Ruby", 4) == 0) |
---|
| 770 | { |
---|
| 771 | *eres = |
---|
| 772 | zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 773 | &request_output_real_format); |
---|
| 774 | } |
---|
| 775 | else |
---|
[453] | 776 | #endif |
---|
| 777 | |
---|
[794] | 778 | #ifdef USE_MONO |
---|
| 779 | if (strncasecmp (r_inputs->value, "Mono", 4) == 0) |
---|
[541] | 780 | { |
---|
[794] | 781 | *eres = |
---|
| 782 | zoo_mono_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 783 | &request_output_real_format); |
---|
| 784 | } |
---|
| 785 | else |
---|
| 786 | #endif |
---|
| 787 | |
---|
| 788 | { |
---|
[541] | 789 | char tmpv[1024]; |
---|
| 790 | sprintf (tmpv, |
---|
| 791 | _ |
---|
| 792 | ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"), |
---|
| 793 | r_inputs->value); |
---|
[576] | 794 | errorException (m, tmpv, "InternalError", NULL); |
---|
[541] | 795 | *eres = -1; |
---|
| 796 | } |
---|
| 797 | *myMap = m; |
---|
| 798 | *ioutputs = request_output_real_format; |
---|
[34] | 799 | } |
---|
| 800 | |
---|
[384] | 801 | |
---|
[216] | 802 | #ifdef WIN32 |
---|
| 803 | /** |
---|
| 804 | * createProcess function: create a new process after setting some env variables |
---|
| 805 | */ |
---|
[541] | 806 | void |
---|
| 807 | createProcess (maps * m, map * request_inputs, service * s1, char *opts, |
---|
| 808 | int cpid, maps * inputs, maps * outputs) |
---|
| 809 | { |
---|
[216] | 810 | STARTUPINFO si; |
---|
| 811 | PROCESS_INFORMATION pi; |
---|
[541] | 812 | ZeroMemory (&si, sizeof (si)); |
---|
| 813 | si.cb = sizeof (si); |
---|
| 814 | ZeroMemory (&pi, sizeof (pi)); |
---|
| 815 | char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); |
---|
| 816 | char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); |
---|
| 817 | map *req = getMap (request_inputs, "request"); |
---|
| 818 | map *id = getMap (request_inputs, "identifier"); |
---|
| 819 | map *di = getMap (request_inputs, "DataInputs"); |
---|
[216] | 820 | |
---|
[583] | 821 | // The required size for the dataInputsKVP and dataOutputsKVP buffers |
---|
| 822 | // may exceed cgiContentLength, hence a 2 kb extension. However, a |
---|
| 823 | // better solution would be to have getMapsAsKVP() determine the required |
---|
| 824 | // buffer size before allocating memory. |
---|
| 825 | char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength + 2048, 0); |
---|
| 826 | char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength + 2048, 1); |
---|
[384] | 827 | #ifdef DEBUG |
---|
[541] | 828 | fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP); |
---|
| 829 | fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP); |
---|
[384] | 830 | #endif |
---|
[680] | 831 | map *sid = getMapFromMaps (m, "lenv", "osid"); |
---|
| 832 | map *usid = getMapFromMaps (m, "lenv", "usid"); |
---|
[541] | 833 | map *r_inputs = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 834 | map *r_inputs1 = getMap (request_inputs, "metapath"); |
---|
[605] | 835 | |
---|
[541] | 836 | int hasIn = -1; |
---|
| 837 | if (r_inputs1 == NULL) |
---|
| 838 | { |
---|
| 839 | r_inputs1 = createMap ("metapath", ""); |
---|
| 840 | hasIn = 1; |
---|
| 841 | } |
---|
| 842 | map *r_inputs2 = getMap (request_inputs, "ResponseDocument"); |
---|
| 843 | if (r_inputs2 == NULL) |
---|
| 844 | r_inputs2 = getMap (request_inputs, "RawDataOutput"); |
---|
| 845 | map *tmpPath = getMapFromMaps (m, "lenv", "cwd"); |
---|
[216] | 846 | |
---|
[541] | 847 | map *tmpReq = getMap (request_inputs, "xrequest"); |
---|
[790] | 848 | |
---|
[587] | 849 | if(r_inputs2 != NULL && tmpReq != NULL) { |
---|
[680] | 850 | const char key[] = "rfile="; |
---|
| 851 | char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char)); |
---|
| 852 | char* filepath = kvp + strlen(key); |
---|
| 853 | strncpy(kvp, key, strlen(key)); |
---|
| 854 | addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value), |
---|
[682] | 855 | filepath, FILENAME_MAX); |
---|
[587] | 856 | if (filepath == NULL) { |
---|
[680] | 857 | errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL); |
---|
| 858 | return; |
---|
[587] | 859 | } |
---|
[680] | 860 | sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s&usid=%s\"", |
---|
| 861 | r_inputs1->value,kvp,sid->value,usid->value); |
---|
[587] | 862 | sprintf(tmpq,"metapath=%s&%s", |
---|
[680] | 863 | r_inputs1->value,kvp); |
---|
| 864 | free(kvp); |
---|
[587] | 865 | } |
---|
| 866 | else if (r_inputs2 != NULL) |
---|
[541] | 867 | { |
---|
| 868 | sprintf (tmp, |
---|
[680] | 869 | "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s&usid=%s\"", |
---|
[541] | 870 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
[680] | 871 | r_inputs2->name, dataOutputsKVP, sid->value, usid->value); |
---|
[541] | 872 | sprintf (tmpq, |
---|
| 873 | "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s", |
---|
| 874 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
[587] | 875 | r_inputs2->name, dataOutputsKVP); |
---|
[541] | 876 | } |
---|
| 877 | else |
---|
| 878 | { |
---|
| 879 | sprintf (tmp, |
---|
[680] | 880 | "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s&usid=%s\"", |
---|
[541] | 881 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
[680] | 882 | sid->value, usid->value); |
---|
[541] | 883 | sprintf (tmpq, |
---|
| 884 | "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s", |
---|
| 885 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
[587] | 886 | sid->value); |
---|
[541] | 887 | } |
---|
| 888 | |
---|
| 889 | if (hasIn > 0) |
---|
| 890 | { |
---|
| 891 | freeMap (&r_inputs1); |
---|
| 892 | free (r_inputs1); |
---|
| 893 | } |
---|
| 894 | char *tmp1 = zStrdup (tmp); |
---|
[587] | 895 | sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value); |
---|
[541] | 896 | free (dataInputsKVP); |
---|
| 897 | free (dataOutputsKVP); |
---|
[384] | 898 | #ifdef DEBUG |
---|
[541] | 899 | fprintf (stderr, "REQUEST IS : %s \n", tmp); |
---|
[384] | 900 | #endif |
---|
[554] | 901 | |
---|
[680] | 902 | usid = getMapFromMaps (m, "lenv", "usid"); |
---|
[554] | 903 | if (usid != NULL && usid->value != NULL) { |
---|
| 904 | SetEnvironmentVariable("USID", TEXT (usid->value)); |
---|
| 905 | } |
---|
[541] | 906 | SetEnvironmentVariable ("CGISID", TEXT (sid->value)); |
---|
| 907 | SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq)); |
---|
[682] | 908 | // knut: Prevent REQUEST_METHOD=POST in background process call to cgic:main |
---|
| 909 | // (process hangs when reading cgiIn): |
---|
[587] | 910 | SetEnvironmentVariable("REQUEST_METHOD", "GET"); |
---|
[682] | 911 | SetEnvironmentVariable("CONTENT_TYPE", "text/plain"); |
---|
[587] | 912 | |
---|
[216] | 913 | char clen[1000]; |
---|
[541] | 914 | sprintf (clen, "%d", strlen (tmpq)); |
---|
| 915 | SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen)); |
---|
| 916 | |
---|
[682] | 917 | // ref. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx |
---|
[541] | 918 | if (!CreateProcess (NULL, // No module name (use command line) |
---|
| 919 | TEXT (tmp), // Command line |
---|
| 920 | NULL, // Process handle not inheritable |
---|
| 921 | NULL, // Thread handle not inheritable |
---|
| 922 | FALSE, // Set handle inheritance to FALSE |
---|
| 923 | CREATE_NO_WINDOW, // Apache won't wait until the end |
---|
| 924 | NULL, // Use parent's environment block |
---|
| 925 | NULL, // Use parent's starting directory |
---|
| 926 | &si, // Pointer to STARTUPINFO struct |
---|
| 927 | &pi) // Pointer to PROCESS_INFORMATION struct |
---|
| 928 | ) |
---|
| 929 | { |
---|
[384] | 930 | #ifdef DEBUG |
---|
[541] | 931 | fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ()); |
---|
[384] | 932 | #endif |
---|
[587] | 933 | if (tmp != NULL) { |
---|
| 934 | free(tmp); |
---|
| 935 | } |
---|
| 936 | if (tmpq != NULL) { |
---|
| 937 | free(tmpq); |
---|
| 938 | } |
---|
[541] | 939 | return; |
---|
| 940 | } |
---|
| 941 | else |
---|
| 942 | { |
---|
[384] | 943 | #ifdef DEBUG |
---|
[587] | 944 | fprintf (stderr, "CreateProcess successful (%d).\n\n\n\n", |
---|
[541] | 945 | GetLastError ()); |
---|
[384] | 946 | #endif |
---|
[541] | 947 | } |
---|
| 948 | CloseHandle (pi.hProcess); |
---|
| 949 | CloseHandle (pi.hThread); |
---|
[587] | 950 | |
---|
| 951 | if (tmp != NULL) { |
---|
| 952 | free(tmp); |
---|
| 953 | } |
---|
| 954 | if (tmpq != NULL) { |
---|
| 955 | free(tmpq); |
---|
| 956 | } |
---|
| 957 | |
---|
[384] | 958 | #ifdef DEBUG |
---|
[541] | 959 | fprintf (stderr, "CreateProcess finished !\n"); |
---|
[384] | 960 | #endif |
---|
[216] | 961 | } |
---|
| 962 | #endif |
---|
| 963 | |
---|
[607] | 964 | /** |
---|
| 965 | * Process the request. |
---|
| 966 | * |
---|
| 967 | * @param inputs the request parameters map |
---|
| 968 | * @return 0 on sucess, other value on failure |
---|
| 969 | * @see conf_read,recursReaddirF |
---|
| 970 | */ |
---|
[541] | 971 | int |
---|
| 972 | runRequest (map ** inputs) |
---|
[1] | 973 | { |
---|
[788] | 974 | |
---|
[53] | 975 | #ifndef USE_GDB |
---|
[554] | 976 | #ifndef WIN32 |
---|
[541] | 977 | signal (SIGCHLD, SIG_IGN); |
---|
[554] | 978 | #endif |
---|
[541] | 979 | signal (SIGSEGV, sig_handler); |
---|
| 980 | signal (SIGTERM, sig_handler); |
---|
| 981 | signal (SIGINT, sig_handler); |
---|
| 982 | signal (SIGILL, sig_handler); |
---|
| 983 | signal (SIGFPE, sig_handler); |
---|
| 984 | signal (SIGABRT, sig_handler); |
---|
[53] | 985 | #endif |
---|
[9] | 986 | |
---|
[839] | 987 | |
---|
[541] | 988 | map *r_inputs = NULL; |
---|
| 989 | map *request_inputs = *inputs; |
---|
[839] | 990 | //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN)); |
---|
| 991 | |
---|
[605] | 992 | #ifdef IGNORE_METAPATH |
---|
| 993 | addToMap(request_inputs, "metapath", ""); |
---|
| 994 | #endif |
---|
[541] | 995 | maps *m = NULL; |
---|
| 996 | char *REQUEST = NULL; |
---|
[1] | 997 | /** |
---|
| 998 | * Parsing service specfic configuration file |
---|
| 999 | */ |
---|
[541] | 1000 | m = (maps *) malloc (MAPS_SIZE); |
---|
| 1001 | if (m == NULL) |
---|
| 1002 | { |
---|
[790] | 1003 | return errorException (NULL, _("Unable to allocate memory"), |
---|
[541] | 1004 | "InternalError", NULL); |
---|
| 1005 | } |
---|
[790] | 1006 | m->child=NULL; |
---|
[1] | 1007 | char ntmp[1024]; |
---|
[784] | 1008 | #ifndef ETC_DIR |
---|
[1] | 1009 | #ifndef WIN32 |
---|
[541] | 1010 | getcwd (ntmp, 1024); |
---|
[1] | 1011 | #else |
---|
[541] | 1012 | _getcwd (ntmp, 1024); |
---|
[1] | 1013 | #endif |
---|
[784] | 1014 | #else |
---|
| 1015 | sprintf(ntmp,"%s",ETC_DIR); |
---|
| 1016 | #endif |
---|
[541] | 1017 | r_inputs = getMapOrFill (&request_inputs, "metapath", ""); |
---|
[282] | 1018 | |
---|
[9] | 1019 | char conf_file[10240]; |
---|
[541] | 1020 | snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); |
---|
[784] | 1021 | #ifdef ETC_DIR |
---|
| 1022 | #ifndef WIN32 |
---|
[854] | 1023 | getcwd (ntmp, 1024); |
---|
[784] | 1024 | #else |
---|
[854] | 1025 | _getcwd (ntmp, 1024); |
---|
[784] | 1026 | #endif |
---|
| 1027 | #endif |
---|
[788] | 1028 | |
---|
[541] | 1029 | if (conf_read (conf_file, m) == 2) |
---|
| 1030 | { |
---|
| 1031 | errorException (NULL, _("Unable to load the main.cfg file."), |
---|
| 1032 | "InternalError", NULL); |
---|
| 1033 | free (m); |
---|
| 1034 | return 1; |
---|
| 1035 | } |
---|
[9] | 1036 | #ifdef DEBUG |
---|
[541] | 1037 | fprintf (stderr, "***** BEGIN MAPS\n"); |
---|
| 1038 | dumpMaps (m); |
---|
| 1039 | fprintf (stderr, "***** END MAPS\n"); |
---|
[9] | 1040 | #endif |
---|
| 1041 | |
---|
[541] | 1042 | map *getPath = getMapFromMaps (m, "main", "gettextPath"); |
---|
| 1043 | if (getPath != NULL) |
---|
| 1044 | { |
---|
| 1045 | bindtextdomain ("zoo-kernel", getPath->value); |
---|
| 1046 | bindtextdomain ("zoo-services", getPath->value); |
---|
| 1047 | } |
---|
| 1048 | else |
---|
| 1049 | { |
---|
[784] | 1050 | bindtextdomain ("zoo-kernel", LOCALEDIR); |
---|
| 1051 | bindtextdomain ("zoo-services", LOCALEDIR); |
---|
[541] | 1052 | } |
---|
[364] | 1053 | |
---|
| 1054 | /** |
---|
| 1055 | * Manage our own error log file (usefull to separate standard apache debug |
---|
| 1056 | * messages from the ZOO-Kernel ones but also for IIS users to avoid wrong |
---|
| 1057 | * headers messages returned by the CGI due to wrong redirection of stderr) |
---|
| 1058 | */ |
---|
[541] | 1059 | FILE *fstde = NULL; |
---|
| 1060 | map *fstdem = getMapFromMaps (m, "main", "logPath"); |
---|
| 1061 | if (fstdem != NULL) |
---|
| 1062 | fstde = freopen (fstdem->value, "a+", stderr); |
---|
[364] | 1063 | |
---|
[541] | 1064 | r_inputs = getMap (request_inputs, "language"); |
---|
| 1065 | if (r_inputs == NULL) |
---|
[640] | 1066 | r_inputs = getMap (request_inputs, "AcceptLanguages"); |
---|
| 1067 | if (r_inputs == NULL) |
---|
[541] | 1068 | r_inputs = getMapFromMaps (m, "main", "language"); |
---|
| 1069 | if (r_inputs != NULL) |
---|
| 1070 | { |
---|
| 1071 | if (isValidLang (m, r_inputs->value) < 0) |
---|
| 1072 | { |
---|
| 1073 | char tmp[1024]; |
---|
| 1074 | sprintf (tmp, |
---|
| 1075 | _ |
---|
| 1076 | ("The value %s is not supported for the <language> parameter"), |
---|
| 1077 | r_inputs->value); |
---|
| 1078 | errorException (m, tmp, "InvalidParameterValue", "language"); |
---|
| 1079 | freeMaps (&m); |
---|
| 1080 | free (m); |
---|
| 1081 | free (REQUEST); |
---|
| 1082 | return 1; |
---|
[501] | 1083 | |
---|
[541] | 1084 | } |
---|
| 1085 | char *tmp = zStrdup (r_inputs->value); |
---|
| 1086 | setMapInMaps (m, "main", "language", tmp); |
---|
[466] | 1087 | #ifdef DEB |
---|
[541] | 1088 | char tmp2[12]; |
---|
| 1089 | sprintf (tmp2, "%s.utf-8", tmp); |
---|
| 1090 | translateChar (tmp2, '-', '_'); |
---|
| 1091 | setlocale (LC_ALL, tmp2); |
---|
[466] | 1092 | #else |
---|
[541] | 1093 | translateChar (tmp, '-', '_'); |
---|
| 1094 | setlocale (LC_ALL, tmp); |
---|
[466] | 1095 | #endif |
---|
[444] | 1096 | #ifndef WIN32 |
---|
[541] | 1097 | setenv ("LC_ALL", tmp, 1); |
---|
[444] | 1098 | #else |
---|
[745] | 1099 | char tmp1[13]; |
---|
[541] | 1100 | sprintf (tmp1, "LC_ALL=%s", tmp); |
---|
| 1101 | putenv (tmp1); |
---|
[376] | 1102 | #endif |
---|
[541] | 1103 | free (tmp); |
---|
| 1104 | } |
---|
| 1105 | else |
---|
| 1106 | { |
---|
| 1107 | setlocale (LC_ALL, "en_US"); |
---|
[444] | 1108 | #ifndef WIN32 |
---|
[541] | 1109 | setenv ("LC_ALL", "en_US", 1); |
---|
[444] | 1110 | #else |
---|
[745] | 1111 | char tmp1[13]; |
---|
[541] | 1112 | sprintf (tmp1, "LC_ALL=en_US"); |
---|
| 1113 | putenv (tmp1); |
---|
[376] | 1114 | #endif |
---|
[541] | 1115 | setMapInMaps (m, "main", "language", "en-US"); |
---|
| 1116 | } |
---|
[745] | 1117 | setlocale (LC_NUMERIC, "C"); |
---|
| 1118 | #ifndef WIN32 |
---|
| 1119 | setenv ("LC_NUMERIC", "C", 1); |
---|
| 1120 | #else |
---|
| 1121 | char tmp1[17]; |
---|
| 1122 | sprintf (tmp1, "LC_NUMERIC=C"); |
---|
| 1123 | putenv (tmp1); |
---|
| 1124 | #endif |
---|
[541] | 1125 | bind_textdomain_codeset ("zoo-kernel", "UTF-8"); |
---|
| 1126 | textdomain ("zoo-kernel"); |
---|
| 1127 | bind_textdomain_codeset ("zoo-services", "UTF-8"); |
---|
| 1128 | textdomain ("zoo-services"); |
---|
[34] | 1129 | |
---|
[541] | 1130 | map *lsoap = getMap (request_inputs, "soap"); |
---|
| 1131 | if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0) |
---|
| 1132 | setMapInMaps (m, "main", "isSoap", "true"); |
---|
[280] | 1133 | else |
---|
[541] | 1134 | setMapInMaps (m, "main", "isSoap", "false"); |
---|
[34] | 1135 | |
---|
[584] | 1136 | if(strlen(cgiServerName)>0) |
---|
[654] | 1137 | { |
---|
| 1138 | char tmpUrl[1024]; |
---|
[584] | 1139 | |
---|
[680] | 1140 | if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { |
---|
| 1141 | // Knut: check if non-empty instead of "on"? |
---|
[654] | 1142 | if ( strncmp(cgiServerPort, "443", 3) == 0 ) { |
---|
| 1143 | sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName); |
---|
[584] | 1144 | } |
---|
| 1145 | else { |
---|
[654] | 1146 | sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName); |
---|
[584] | 1147 | } |
---|
[654] | 1148 | } |
---|
| 1149 | else { |
---|
| 1150 | if ( strncmp(cgiServerPort, "80", 2) == 0 ) { |
---|
| 1151 | sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName); |
---|
| 1152 | } |
---|
| 1153 | else { |
---|
| 1154 | sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName); |
---|
| 1155 | } |
---|
| 1156 | } |
---|
[445] | 1157 | #ifdef DEBUG |
---|
[654] | 1158 | fprintf(stderr,"*** %s ***\n",tmpUrl); |
---|
[445] | 1159 | #endif |
---|
[654] | 1160 | setMapInMaps(m,"main","serverAddress",tmpUrl); |
---|
| 1161 | } |
---|
[381] | 1162 | |
---|
[752] | 1163 | // CORS Support |
---|
| 1164 | if(strncasecmp(cgiRequestMethod,"OPTIONS",7)==0){ |
---|
| 1165 | map* cors=getMapFromMaps(m,"main","cors"); |
---|
| 1166 | if(cors!=NULL && strncasecmp(cors->value,"true",4)==0){ |
---|
| 1167 | char *encoding=getEncoding(m); |
---|
| 1168 | printHeaders(m); |
---|
| 1169 | printf("Content-Type: text/plain; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1170 | printf(_("CORS is enabled.\r\n")); |
---|
| 1171 | freeMaps (&m); |
---|
| 1172 | free (m); |
---|
| 1173 | fflush (stdout); |
---|
| 1174 | return 3; |
---|
| 1175 | } |
---|
| 1176 | } |
---|
| 1177 | |
---|
[654] | 1178 | //Check for minimum inputs |
---|
| 1179 | map* version=getMap(request_inputs,"version"); |
---|
| 1180 | if(version==NULL) |
---|
| 1181 | version=getMapFromMaps(m,"main","version"); |
---|
| 1182 | setMapInMaps(m,"main","rversion",version->value); |
---|
| 1183 | int vid=getVersionId(version->value); |
---|
| 1184 | if(vid<0) |
---|
| 1185 | vid=0; |
---|
[576] | 1186 | map* err=NULL; |
---|
[654] | 1187 | const char **vvr=(const char**)requests[vid]; |
---|
| 1188 | checkValidValue(request_inputs,&err,"request",vvr,1); |
---|
[576] | 1189 | const char *vvs[]={ |
---|
| 1190 | "WPS", |
---|
| 1191 | NULL |
---|
| 1192 | }; |
---|
| 1193 | if(err!=NULL){ |
---|
| 1194 | checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); |
---|
| 1195 | printExceptionReportResponse (m, err); |
---|
| 1196 | freeMap(&err); |
---|
| 1197 | free(err); |
---|
| 1198 | if (count (request_inputs) == 1) |
---|
| 1199 | { |
---|
| 1200 | freeMap (&request_inputs); |
---|
| 1201 | free (request_inputs); |
---|
| 1202 | } |
---|
| 1203 | freeMaps (&m); |
---|
| 1204 | free (m); |
---|
| 1205 | return 1; |
---|
| 1206 | } |
---|
| 1207 | checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); |
---|
[640] | 1208 | |
---|
[576] | 1209 | const char *vvv[]={ |
---|
| 1210 | "1.0.0", |
---|
[640] | 1211 | "2.0.0", |
---|
[576] | 1212 | NULL |
---|
| 1213 | }; |
---|
[541] | 1214 | r_inputs = getMap (request_inputs, "Request"); |
---|
[850] | 1215 | if(r_inputs!=NULL) |
---|
| 1216 | REQUEST = zStrdup (r_inputs->value); |
---|
[654] | 1217 | int reqId=-1; |
---|
[576] | 1218 | if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ |
---|
| 1219 | checkValidValue(request_inputs,&err,"version",(const char**)vvv,1); |
---|
[654] | 1220 | int j=0; |
---|
| 1221 | for(j=0;j<nbSupportedRequests;j++){ |
---|
| 1222 | if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){ |
---|
[850] | 1223 | if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ |
---|
[654] | 1224 | checkValidValue(request_inputs,&err,"identifier",NULL,1); |
---|
| 1225 | reqId=j+1; |
---|
| 1226 | break; |
---|
| 1227 | } |
---|
| 1228 | else |
---|
| 1229 | if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && |
---|
[850] | 1230 | strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ |
---|
[654] | 1231 | checkValidValue(request_inputs,&err,"jobid",NULL,1); |
---|
| 1232 | reqId=j+1; |
---|
| 1233 | break; |
---|
| 1234 | } |
---|
| 1235 | }else |
---|
| 1236 | break; |
---|
| 1237 | } |
---|
[576] | 1238 | }else{ |
---|
| 1239 | checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1); |
---|
[658] | 1240 | map* version1=getMap(request_inputs,"AcceptVersions"); |
---|
| 1241 | if(version1!=NULL){ |
---|
| 1242 | if(strstr(version1->value,schemas[1][0])!=NULL) |
---|
[640] | 1243 | addToMap(request_inputs,"version",schemas[1][0]); |
---|
| 1244 | else |
---|
[658] | 1245 | addToMap(request_inputs,"version",version1->value); |
---|
| 1246 | version=getMap(request_inputs,"version"); |
---|
| 1247 | setMapInMaps(m,"main","rversion",version->value); |
---|
| 1248 | vid=getVersionId(version->value); |
---|
[640] | 1249 | } |
---|
[576] | 1250 | } |
---|
| 1251 | if(err!=NULL){ |
---|
| 1252 | printExceptionReportResponse (m, err); |
---|
| 1253 | freeMap(&err); |
---|
| 1254 | free(err); |
---|
| 1255 | if (count (request_inputs) == 1) |
---|
| 1256 | { |
---|
| 1257 | freeMap (&request_inputs); |
---|
| 1258 | free (request_inputs); |
---|
| 1259 | } |
---|
| 1260 | free(REQUEST); |
---|
| 1261 | freeMaps (&m); |
---|
| 1262 | free (m); |
---|
| 1263 | return 1; |
---|
| 1264 | } |
---|
[1] | 1265 | |
---|
[541] | 1266 | r_inputs = getMap (request_inputs, "serviceprovider"); |
---|
| 1267 | if (r_inputs == NULL) |
---|
| 1268 | { |
---|
| 1269 | addToMap (request_inputs, "serviceprovider", ""); |
---|
| 1270 | } |
---|
[1] | 1271 | |
---|
[541] | 1272 | maps *request_output_real_format = NULL; |
---|
| 1273 | map *tmpm = getMapFromMaps (m, "main", "serverAddress"); |
---|
| 1274 | if (tmpm != NULL) |
---|
| 1275 | SERVICE_URL = zStrdup (tmpm->value); |
---|
[1] | 1276 | else |
---|
[541] | 1277 | SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); |
---|
[1] | 1278 | |
---|
[607] | 1279 | |
---|
| 1280 | |
---|
[541] | 1281 | service *s1; |
---|
| 1282 | int scount = 0; |
---|
[1] | 1283 | #ifdef DEBUG |
---|
[541] | 1284 | dumpMap (r_inputs); |
---|
[1] | 1285 | #endif |
---|
| 1286 | char conf_dir[1024]; |
---|
| 1287 | int t; |
---|
| 1288 | char tmps1[1024]; |
---|
| 1289 | |
---|
[541] | 1290 | r_inputs = NULL; |
---|
| 1291 | r_inputs = getMap (request_inputs, "metapath"); |
---|
[784] | 1292 | map* cwdMap0=getMapFromMaps(m,"main","servicePath"); |
---|
[541] | 1293 | if (r_inputs != NULL) |
---|
[784] | 1294 | if(cwdMap0!=NULL) |
---|
| 1295 | snprintf (conf_dir, 1024, "%s/%s", cwdMap0->value, r_inputs->value); |
---|
| 1296 | else |
---|
| 1297 | snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value); |
---|
[9] | 1298 | else |
---|
[784] | 1299 | if(cwdMap0!=NULL) |
---|
| 1300 | snprintf (conf_dir, 1024, "%s", cwdMap0->value); |
---|
| 1301 | else |
---|
| 1302 | snprintf (conf_dir, 1024, "%s", ntmp); |
---|
[607] | 1303 | map* reg = getMapFromMaps (m, "main", "registry"); |
---|
| 1304 | registry* zooRegistry=NULL; |
---|
| 1305 | if(reg!=NULL){ |
---|
| 1306 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1307 | dup2 (fileno (stderr), fileno (stdout)); |
---|
[676] | 1308 | if(createRegistry (m,&zooRegistry,reg->value)<0){ |
---|
| 1309 | map *message=getMapFromMaps(m,"lenv","message"); |
---|
| 1310 | map *type=getMapFromMaps(m,"lenv","type"); |
---|
| 1311 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1312 | errorException (m, message->value, |
---|
| 1313 | type->value, NULL); |
---|
| 1314 | return 0; |
---|
| 1315 | } |
---|
[607] | 1316 | dup2 (saved_stdout, fileno (stdout)); |
---|
[676] | 1317 | close(saved_stdout); |
---|
[607] | 1318 | } |
---|
| 1319 | |
---|
[541] | 1320 | if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) |
---|
| 1321 | { |
---|
[1] | 1322 | #ifdef DEBUG |
---|
[541] | 1323 | dumpMap (r_inputs); |
---|
[1] | 1324 | #endif |
---|
[541] | 1325 | xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); |
---|
[656] | 1326 | xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0")); |
---|
[576] | 1327 | /** |
---|
| 1328 | * Here we need to close stdout to ensure that unsupported chars |
---|
| 1329 | * has been found in the zcfg and then printed on stdout |
---|
| 1330 | */ |
---|
[541] | 1331 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1332 | dup2 (fileno (stderr), fileno (stdout)); |
---|
[789] | 1333 | |
---|
| 1334 | maps* imports = getMaps(m, IMPORTSERVICE); |
---|
| 1335 | if (imports != NULL) { |
---|
| 1336 | map* zcfg = imports->content; |
---|
| 1337 | |
---|
| 1338 | while (zcfg != NULL) { |
---|
| 1339 | if (zcfg->value != NULL) { |
---|
| 1340 | service* svc = (service*) malloc(SERVICE_SIZE); |
---|
| 1341 | if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { |
---|
| 1342 | // pass over silently |
---|
| 1343 | zcfg = zcfg->next; |
---|
| 1344 | continue; |
---|
| 1345 | } |
---|
| 1346 | inheritance(zooRegistry, &svc); |
---|
[839] | 1347 | printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); |
---|
[789] | 1348 | freeService(&svc); |
---|
| 1349 | free(svc); |
---|
| 1350 | } |
---|
| 1351 | zcfg = zcfg->next; |
---|
| 1352 | } |
---|
| 1353 | } |
---|
| 1354 | |
---|
[584] | 1355 | if (int res = |
---|
[839] | 1356 | recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, |
---|
[541] | 1357 | printGetCapabilitiesForProcess) < 0) |
---|
| 1358 | { |
---|
| 1359 | freeMaps (&m); |
---|
| 1360 | free (m); |
---|
[607] | 1361 | if(zooRegistry!=NULL){ |
---|
| 1362 | freeRegistry(&zooRegistry); |
---|
| 1363 | free(zooRegistry); |
---|
| 1364 | } |
---|
[541] | 1365 | free (REQUEST); |
---|
| 1366 | free (SERVICE_URL); |
---|
| 1367 | fflush (stdout); |
---|
| 1368 | return res; |
---|
| 1369 | } |
---|
[656] | 1370 | fflush (stdout); |
---|
[541] | 1371 | dup2 (saved_stdout, fileno (stdout)); |
---|
[822] | 1372 | #ifdef META_DB |
---|
[839] | 1373 | fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); |
---|
| 1374 | close_sql(m,0); |
---|
[822] | 1375 | #endif |
---|
[541] | 1376 | printDocument (m, doc, getpid ()); |
---|
| 1377 | freeMaps (&m); |
---|
| 1378 | free (m); |
---|
[607] | 1379 | if(zooRegistry!=NULL){ |
---|
| 1380 | freeRegistry(&zooRegistry); |
---|
| 1381 | free(zooRegistry); |
---|
| 1382 | } |
---|
[541] | 1383 | free (REQUEST); |
---|
| 1384 | free (SERVICE_URL); |
---|
| 1385 | fflush (stdout); |
---|
[9] | 1386 | return 0; |
---|
[1] | 1387 | } |
---|
[541] | 1388 | else |
---|
| 1389 | { |
---|
[654] | 1390 | r_inputs = getMap (request_inputs, "JobId"); |
---|
| 1391 | if(reqId>nbReqIdentifier){ |
---|
[850] | 1392 | if (strncasecmp (REQUEST, "GetStatus", 9) == 0 || |
---|
| 1393 | strncasecmp (REQUEST, "GetResult", 9) == 0){ |
---|
[654] | 1394 | runGetStatus(m,r_inputs->value,REQUEST); |
---|
[850] | 1395 | #ifdef RELY_ON_DB |
---|
| 1396 | map* dsNb=getMapFromMaps(m,"lenv","ds_nb"); |
---|
| 1397 | if(dsNb!=NULL && atoi(dsNb->value)>1) |
---|
| 1398 | close_sql(m,1); |
---|
| 1399 | close_sql(m,0); |
---|
| 1400 | #endif |
---|
| 1401 | |
---|
[654] | 1402 | freeMaps (&m); |
---|
[839] | 1403 | free(m); |
---|
[607] | 1404 | if(zooRegistry!=NULL){ |
---|
| 1405 | freeRegistry(&zooRegistry); |
---|
| 1406 | free(zooRegistry); |
---|
| 1407 | } |
---|
[654] | 1408 | free (REQUEST); |
---|
| 1409 | free (SERVICE_URL); |
---|
| 1410 | return 0; |
---|
| 1411 | } |
---|
| 1412 | else |
---|
| 1413 | if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){ |
---|
| 1414 | runDismiss(m,r_inputs->value); |
---|
| 1415 | freeMaps (&m); |
---|
| 1416 | free (m); |
---|
| 1417 | if(zooRegistry!=NULL){ |
---|
| 1418 | freeRegistry(&zooRegistry); |
---|
| 1419 | free(zooRegistry); |
---|
| 1420 | } |
---|
| 1421 | free (REQUEST); |
---|
| 1422 | free (SERVICE_URL); |
---|
| 1423 | return 0; |
---|
| 1424 | |
---|
| 1425 | } |
---|
| 1426 | return 0; |
---|
| 1427 | } |
---|
| 1428 | if(reqId<=nbReqIdentifier){ |
---|
| 1429 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
[9] | 1430 | |
---|
[654] | 1431 | struct dirent *dp; |
---|
| 1432 | DIR *dirp = opendir (conf_dir); |
---|
| 1433 | if (dirp == NULL) |
---|
| 1434 | { |
---|
[725] | 1435 | errorException (m, _("The specified path does not exist."), |
---|
[784] | 1436 | "InternalError", NULL); |
---|
[654] | 1437 | freeMaps (&m); |
---|
| 1438 | free (m); |
---|
| 1439 | if(zooRegistry!=NULL){ |
---|
| 1440 | freeRegistry(&zooRegistry); |
---|
| 1441 | free(zooRegistry); |
---|
| 1442 | } |
---|
| 1443 | free (REQUEST); |
---|
| 1444 | free (SERVICE_URL); |
---|
| 1445 | return 0; |
---|
| 1446 | } |
---|
| 1447 | if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) |
---|
| 1448 | { |
---|
| 1449 | /** |
---|
| 1450 | * Loop over Identifier list |
---|
| 1451 | */ |
---|
| 1452 | xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); |
---|
| 1453 | r_inputs = NULL; |
---|
| 1454 | r_inputs = getMap (request_inputs, "version"); |
---|
[877] | 1455 | #ifdef DEBUG |
---|
[854] | 1456 | fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); |
---|
| 1457 | fflush(stderr); |
---|
[877] | 1458 | #endif |
---|
[654] | 1459 | xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", |
---|
[656] | 1460 | root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); |
---|
[469] | 1461 | |
---|
[654] | 1462 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
[503] | 1463 | |
---|
[654] | 1464 | char *orig = zStrdup (r_inputs->value); |
---|
[541] | 1465 | |
---|
[654] | 1466 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1467 | dup2 (fileno (stderr), fileno (stdout)); |
---|
| 1468 | if (strcasecmp ("all", orig) == 0) |
---|
| 1469 | { |
---|
[789] | 1470 | maps* imports = getMaps(m, IMPORTSERVICE); |
---|
| 1471 | if (imports != NULL) { |
---|
| 1472 | map* zcfg = imports->content; |
---|
| 1473 | |
---|
| 1474 | while (zcfg != NULL) { |
---|
| 1475 | if (zcfg->value != NULL) { |
---|
| 1476 | service* svc = (service*) malloc(SERVICE_SIZE); |
---|
| 1477 | if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { |
---|
| 1478 | // pass over silently |
---|
| 1479 | zcfg = zcfg->next; |
---|
| 1480 | continue; |
---|
| 1481 | } |
---|
| 1482 | inheritance(zooRegistry, &svc); |
---|
[839] | 1483 | #ifdef USE_HPC |
---|
| 1484 | addNestedOutputs(&svc); |
---|
| 1485 | #endif |
---|
| 1486 | |
---|
| 1487 | printDescribeProcessForProcess(zooRegistry, m, doc, n, svc); |
---|
[789] | 1488 | freeService(&svc); |
---|
| 1489 | free(svc); |
---|
| 1490 | } |
---|
| 1491 | zcfg = zcfg->next; |
---|
| 1492 | } |
---|
| 1493 | } |
---|
| 1494 | |
---|
[654] | 1495 | if (int res = |
---|
[839] | 1496 | recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, |
---|
[654] | 1497 | printDescribeProcessForProcess) < 0) |
---|
| 1498 | return res; |
---|
[822] | 1499 | #ifdef META_DB |
---|
[839] | 1500 | fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0); |
---|
| 1501 | close_sql(m,0); |
---|
[822] | 1502 | #endif |
---|
| 1503 | |
---|
[654] | 1504 | } |
---|
| 1505 | else |
---|
| 1506 | { |
---|
| 1507 | char *saveptr; |
---|
| 1508 | char *tmps = strtok_r (orig, ",", &saveptr); |
---|
[541] | 1509 | |
---|
[654] | 1510 | char buff[256]; |
---|
| 1511 | char buff1[1024]; |
---|
| 1512 | while (tmps != NULL) |
---|
| 1513 | { |
---|
| 1514 | int hasVal = -1; |
---|
| 1515 | char *corig = zStrdup (tmps); |
---|
[789] | 1516 | map* import = getMapFromMaps (m, IMPORTSERVICE, corig); |
---|
| 1517 | if (import != NULL && import->value != NULL) |
---|
[654] | 1518 | { |
---|
[822] | 1519 | #ifdef META_DB |
---|
[839] | 1520 | service* s2=extractServiceFromDb(m,import->name,0); |
---|
[822] | 1521 | if(s2==NULL){ |
---|
| 1522 | #endif |
---|
| 1523 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1524 | t = readServiceFile (m, import->value, &s1, import->name); |
---|
[789] | 1525 | |
---|
[822] | 1526 | if (t < 0) // failure reading zcfg |
---|
| 1527 | { |
---|
| 1528 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 1529 | char tmp01[1024]; |
---|
| 1530 | if (tmp00 != NULL) |
---|
| 1531 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); |
---|
| 1532 | else |
---|
| 1533 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); |
---|
| 1534 | |
---|
| 1535 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1536 | errorException (m, tmp01, "InternalError", NULL); |
---|
| 1537 | |
---|
| 1538 | freeMaps (&m); |
---|
| 1539 | free (m); |
---|
[541] | 1540 | |
---|
[822] | 1541 | if(zooRegistry!=NULL){ |
---|
| 1542 | freeRegistry(&zooRegistry); |
---|
| 1543 | free(zooRegistry); |
---|
| 1544 | } |
---|
| 1545 | free (orig); |
---|
| 1546 | free (REQUEST); |
---|
| 1547 | closedir (dirp); |
---|
[854] | 1548 | //xmlFreeDoc (doc); |
---|
[822] | 1549 | xmlCleanupParser (); |
---|
| 1550 | zooXmlCleanupNs (); |
---|
| 1551 | |
---|
| 1552 | return 1; |
---|
[789] | 1553 | } |
---|
| 1554 | #ifdef DEBUG |
---|
[822] | 1555 | dumpService (s1); |
---|
[789] | 1556 | #endif |
---|
[822] | 1557 | inheritance(zooRegistry,&s1); |
---|
[839] | 1558 | #ifdef USE_HPC |
---|
| 1559 | addNestedOutputs(&s1); |
---|
| 1560 | #endif |
---|
| 1561 | printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); |
---|
[822] | 1562 | freeService (&s1); |
---|
| 1563 | free (s1); |
---|
| 1564 | s1 = NULL; |
---|
| 1565 | scount++; |
---|
| 1566 | hasVal = 1; |
---|
| 1567 | #ifdef META_DB |
---|
| 1568 | } |
---|
| 1569 | #endif |
---|
| 1570 | } |
---|
[789] | 1571 | else if (strstr (corig, ".") != NULL) |
---|
| 1572 | { |
---|
| 1573 | |
---|
[654] | 1574 | parseIdentifier (m, conf_dir, corig, buff1); |
---|
| 1575 | map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); |
---|
| 1576 | if (tmpMap != NULL) |
---|
| 1577 | addToMap (request_inputs, "metapath", tmpMap->value); |
---|
| 1578 | map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); |
---|
[854] | 1579 | /** |
---|
| 1580 | * No support for dot in service name stored in metadb!? |
---|
[865] | 1581 | #ifdef META_DB |
---|
| 1582 | service* s2=extractServiceFromDb(m,tmpMapI->value,0); |
---|
| 1583 | if(s2==NULL){ |
---|
| 1584 | #endif |
---|
[854] | 1585 | */ |
---|
[865] | 1586 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1587 | t = readServiceFile (m, buff1, &s1, tmpMapI->value); |
---|
| 1588 | if (t < 0) |
---|
| 1589 | { |
---|
| 1590 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 1591 | char tmp01[1024]; |
---|
| 1592 | if (tmp00 != NULL) |
---|
| 1593 | sprintf (tmp01, |
---|
| 1594 | _ |
---|
| 1595 | ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"), |
---|
| 1596 | tmps, tmp00->value); |
---|
| 1597 | else |
---|
| 1598 | sprintf (tmp01, |
---|
| 1599 | _ |
---|
| 1600 | ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), |
---|
| 1601 | tmps); |
---|
| 1602 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1603 | errorException (m, tmp01, "InvalidParameterValue", |
---|
| 1604 | "identifier"); |
---|
| 1605 | freeMaps (&m); |
---|
| 1606 | free (m); |
---|
| 1607 | if(zooRegistry!=NULL){ |
---|
| 1608 | freeRegistry(&zooRegistry); |
---|
| 1609 | free(zooRegistry); |
---|
[654] | 1610 | } |
---|
[865] | 1611 | free (REQUEST); |
---|
| 1612 | free (corig); |
---|
| 1613 | free (orig); |
---|
| 1614 | free (SERVICE_URL); |
---|
| 1615 | free (s1); |
---|
| 1616 | closedir (dirp); |
---|
| 1617 | //xmlFreeDoc (doc); |
---|
| 1618 | xmlCleanupParser (); |
---|
| 1619 | zooXmlCleanupNs (); |
---|
| 1620 | return 1; |
---|
| 1621 | } |
---|
[9] | 1622 | #ifdef DEBUG |
---|
[865] | 1623 | dumpService (s1); |
---|
[9] | 1624 | #endif |
---|
[865] | 1625 | inheritance(zooRegistry,&s1); |
---|
[839] | 1626 | #ifdef USE_HPC |
---|
[865] | 1627 | addNestedOutputs(&s1); |
---|
[839] | 1628 | #endif |
---|
[865] | 1629 | printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); |
---|
| 1630 | freeService (&s1); |
---|
| 1631 | free (s1); |
---|
| 1632 | s1 = NULL; |
---|
| 1633 | scount++; |
---|
| 1634 | hasVal = 1; |
---|
| 1635 | setMapInMaps (m, "lenv", "level", "0"); |
---|
[654] | 1636 | } |
---|
| 1637 | else |
---|
| 1638 | { |
---|
[822] | 1639 | #ifdef META_DB |
---|
| 1640 | _init_sql(m,"metadb"); |
---|
[839] | 1641 | //FAILED CONNECTING DB |
---|
| 1642 | if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ |
---|
| 1643 | fprintf(stderr,"ERROR CONNECTING METADB"); |
---|
| 1644 | } |
---|
| 1645 | service* s2=extractServiceFromDb(m,corig,0); |
---|
[822] | 1646 | if(s2!=NULL){ |
---|
| 1647 | inheritance(zooRegistry,&s2); |
---|
[839] | 1648 | #ifdef USE_HPC |
---|
| 1649 | addNestedOutputs(&s2); |
---|
| 1650 | #endif |
---|
| 1651 | printDescribeProcessForProcess (zooRegistry,m, doc, n, s2); |
---|
[822] | 1652 | freeService (&s2); |
---|
| 1653 | free (s2); |
---|
| 1654 | s2 = NULL; |
---|
| 1655 | hasVal = 1; |
---|
| 1656 | }else /*TOTO*/{ |
---|
| 1657 | #endif |
---|
[865] | 1658 | memset (buff, 0, 256); |
---|
| 1659 | snprintf (buff, 256, "%s.zcfg", corig); |
---|
| 1660 | memset (buff1, 0, 1024); |
---|
[469] | 1661 | #ifdef DEBUG |
---|
[822] | 1662 | printf ("\n#######%s\n########\n", buff); |
---|
[469] | 1663 | #endif |
---|
[822] | 1664 | while ((dp = readdir (dirp)) != NULL) |
---|
| 1665 | { |
---|
| 1666 | if (strcasecmp (dp->d_name, buff) == 0) |
---|
| 1667 | { |
---|
| 1668 | memset (buff1, 0, 1024); |
---|
| 1669 | snprintf (buff1, 1024, "%s/%s", conf_dir, |
---|
| 1670 | dp->d_name); |
---|
| 1671 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1672 | if (s1 == NULL) |
---|
| 1673 | { |
---|
| 1674 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1675 | return errorException (m, |
---|
| 1676 | _ |
---|
| 1677 | ("Unable to allocate memory"), |
---|
| 1678 | "InternalError", |
---|
| 1679 | NULL); |
---|
| 1680 | } |
---|
[790] | 1681 | #ifdef DEBUG_SERVICE_CONF |
---|
[822] | 1682 | fprintf |
---|
| 1683 | (stderr,"#################\n(%s) %s\n#################\n", |
---|
| 1684 | r_inputs->value, buff1); |
---|
[469] | 1685 | #endif |
---|
[822] | 1686 | char *tmp0 = zStrdup (dp->d_name); |
---|
| 1687 | tmp0[strlen (tmp0) - 5] = 0; |
---|
| 1688 | t = readServiceFile (m, buff1, &s1, tmp0); |
---|
| 1689 | free (tmp0); |
---|
| 1690 | if (t < 0) |
---|
| 1691 | { |
---|
| 1692 | map *tmp00 = |
---|
| 1693 | getMapFromMaps (m, "lenv", "message"); |
---|
| 1694 | char tmp01[1024]; |
---|
| 1695 | if (tmp00 != NULL) |
---|
| 1696 | sprintf (tmp01, |
---|
| 1697 | _ |
---|
| 1698 | ("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 1699 | dp->d_name, tmp00->value); |
---|
| 1700 | else |
---|
| 1701 | sprintf (tmp01, |
---|
| 1702 | _ |
---|
| 1703 | ("Unable to parse the ZCFG file: %s."), |
---|
| 1704 | dp->d_name); |
---|
| 1705 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1706 | errorException (m, tmp01, "InternalError", |
---|
| 1707 | NULL); |
---|
| 1708 | freeMaps (&m); |
---|
| 1709 | free (m); |
---|
| 1710 | if(zooRegistry!=NULL){ |
---|
| 1711 | freeRegistry(&zooRegistry); |
---|
| 1712 | free(zooRegistry); |
---|
| 1713 | } |
---|
| 1714 | free (orig); |
---|
| 1715 | free (REQUEST); |
---|
| 1716 | closedir (dirp); |
---|
[854] | 1717 | //xmlFreeDoc (doc); |
---|
[822] | 1718 | xmlCleanupParser (); |
---|
| 1719 | zooXmlCleanupNs (); |
---|
| 1720 | return 1; |
---|
[654] | 1721 | } |
---|
[469] | 1722 | #ifdef DEBUG |
---|
[822] | 1723 | dumpService (s1); |
---|
[469] | 1724 | #endif |
---|
[822] | 1725 | inheritance(zooRegistry,&s1); |
---|
[839] | 1726 | #ifdef USE_HPC |
---|
| 1727 | addNestedOutputs(&s1); |
---|
| 1728 | #endif |
---|
[877] | 1729 | /*json_object* jobj=serviceToJson(s1); |
---|
[873] | 1730 | const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN); |
---|
[877] | 1731 | fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/ |
---|
[873] | 1732 | |
---|
[839] | 1733 | printDescribeProcessForProcess (zooRegistry,m, doc, n, s1); |
---|
[822] | 1734 | freeService (&s1); |
---|
| 1735 | free (s1); |
---|
| 1736 | s1 = NULL; |
---|
| 1737 | scount++; |
---|
| 1738 | hasVal = 1; |
---|
| 1739 | } |
---|
| 1740 | } |
---|
| 1741 | #ifdef META_DB |
---|
| 1742 | } |
---|
| 1743 | #endif |
---|
| 1744 | } |
---|
[654] | 1745 | if (hasVal < 0) |
---|
| 1746 | { |
---|
| 1747 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 1748 | char tmp01[1024]; |
---|
| 1749 | if (tmp00 != NULL) |
---|
| 1750 | sprintf (tmp01, |
---|
| 1751 | _("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 1752 | buff, tmp00->value); |
---|
| 1753 | else |
---|
| 1754 | sprintf (tmp01, |
---|
| 1755 | _("Unable to parse the ZCFG file: %s."), |
---|
| 1756 | buff); |
---|
| 1757 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1758 | errorException (m, tmp01, "InvalidParameterValue", |
---|
| 1759 | "Identifier"); |
---|
| 1760 | freeMaps (&m); |
---|
| 1761 | free (m); |
---|
| 1762 | if(zooRegistry!=NULL){ |
---|
| 1763 | freeRegistry(&zooRegistry); |
---|
| 1764 | free(zooRegistry); |
---|
| 1765 | } |
---|
| 1766 | free (orig); |
---|
| 1767 | free (REQUEST); |
---|
| 1768 | closedir (dirp); |
---|
[854] | 1769 | //xmlFreeDoc (doc); |
---|
[654] | 1770 | xmlCleanupParser (); |
---|
| 1771 | zooXmlCleanupNs (); |
---|
| 1772 | return 1; |
---|
| 1773 | } |
---|
| 1774 | rewinddir (dirp); |
---|
| 1775 | tmps = strtok_r (NULL, ",", &saveptr); |
---|
| 1776 | if (corig != NULL) |
---|
| 1777 | free (corig); |
---|
| 1778 | } |
---|
| 1779 | } |
---|
| 1780 | closedir (dirp); |
---|
| 1781 | fflush (stdout); |
---|
| 1782 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1783 | free (orig); |
---|
| 1784 | printDocument (m, doc, getpid ()); |
---|
| 1785 | freeMaps (&m); |
---|
| 1786 | free (m); |
---|
| 1787 | if(zooRegistry!=NULL){ |
---|
| 1788 | freeRegistry(&zooRegistry); |
---|
| 1789 | free(zooRegistry); |
---|
| 1790 | } |
---|
| 1791 | free (REQUEST); |
---|
| 1792 | free (SERVICE_URL); |
---|
| 1793 | fflush (stdout); |
---|
[839] | 1794 | #ifdef META_DB |
---|
| 1795 | close_sql(m,0); |
---|
[865] | 1796 | //end_sql(); |
---|
[839] | 1797 | #endif |
---|
[654] | 1798 | return 0; |
---|
[607] | 1799 | } |
---|
[654] | 1800 | else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) |
---|
| 1801 | { |
---|
| 1802 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
[738] | 1803 | int vid=getVersionId(version->value); |
---|
[865] | 1804 | int len = 0; |
---|
| 1805 | int j = 0; |
---|
[654] | 1806 | for(j=0;j<nbSupportedRequests;j++){ |
---|
| 1807 | if(requests[vid][j]!=NULL) |
---|
| 1808 | len+=strlen(requests[vid][j])+2; |
---|
| 1809 | else{ |
---|
| 1810 | len+=4; |
---|
| 1811 | break; |
---|
| 1812 | } |
---|
| 1813 | } |
---|
| 1814 | char *tmpStr=(char*)malloc(len*sizeof(char)); |
---|
| 1815 | int it=0; |
---|
| 1816 | for(j=0;j<nbSupportedRequests;j++){ |
---|
| 1817 | if(requests[vid][j]!=NULL){ |
---|
| 1818 | if(it==0){ |
---|
| 1819 | sprintf(tmpStr,"%s",requests[vid][j]); |
---|
| 1820 | it++; |
---|
| 1821 | }else{ |
---|
| 1822 | char *tmpS=zStrdup(tmpStr); |
---|
| 1823 | if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){ |
---|
| 1824 | sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]); |
---|
| 1825 | }else{ |
---|
| 1826 | sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]); |
---|
| 1827 | |
---|
| 1828 | } |
---|
| 1829 | free(tmpS); |
---|
| 1830 | } |
---|
| 1831 | } |
---|
| 1832 | else{ |
---|
| 1833 | len+=4; |
---|
| 1834 | break; |
---|
| 1835 | } |
---|
| 1836 | } |
---|
| 1837 | char* message=(char*)malloc((61+len)*sizeof(char)); |
---|
| 1838 | sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr); |
---|
| 1839 | errorException (m,_(message),"InvalidParameterValue", "request"); |
---|
[541] | 1840 | #ifdef DEBUG |
---|
[654] | 1841 | fprintf (stderr, "No request found %s", REQUEST); |
---|
[541] | 1842 | #endif |
---|
[654] | 1843 | closedir (dirp); |
---|
| 1844 | freeMaps (&m); |
---|
| 1845 | free (m); |
---|
| 1846 | if(zooRegistry!=NULL){ |
---|
| 1847 | freeRegistry(&zooRegistry); |
---|
| 1848 | free(zooRegistry); |
---|
| 1849 | } |
---|
| 1850 | free (REQUEST); |
---|
| 1851 | free (SERVICE_URL); |
---|
| 1852 | fflush (stdout); |
---|
| 1853 | return 0; |
---|
[607] | 1854 | } |
---|
[654] | 1855 | closedir (dirp); |
---|
| 1856 | } |
---|
[1] | 1857 | } |
---|
[541] | 1858 | |
---|
[654] | 1859 | map *postRequest = NULL; |
---|
| 1860 | postRequest = getMap (request_inputs, "xrequest"); |
---|
[790] | 1861 | |
---|
[654] | 1862 | if(vid==1 && postRequest==NULL){ |
---|
| 1863 | errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); |
---|
| 1864 | freeMaps (&m); |
---|
| 1865 | free (m); |
---|
| 1866 | if(zooRegistry!=NULL){ |
---|
| 1867 | freeRegistry(&zooRegistry); |
---|
| 1868 | free(zooRegistry); |
---|
| 1869 | } |
---|
| 1870 | free (REQUEST); |
---|
| 1871 | free (SERVICE_URL); |
---|
| 1872 | fflush (stdout); |
---|
| 1873 | return 0; |
---|
| 1874 | } |
---|
[541] | 1875 | s1 = NULL; |
---|
[854] | 1876 | |
---|
[541] | 1877 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
[789] | 1878 | map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); |
---|
| 1879 | if (import != NULL && import->value != NULL) { |
---|
[865] | 1880 | strncpy(tmps1, import->value, 1024); |
---|
| 1881 | setMapInMaps (m, "lenv", "Identifier", r_inputs->value); |
---|
| 1882 | setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); |
---|
[789] | 1883 | } |
---|
| 1884 | else { |
---|
| 1885 | snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value); |
---|
[1] | 1886 | #ifdef DEBUG |
---|
[789] | 1887 | fprintf (stderr, "Trying to load %s\n", tmps1); |
---|
[1] | 1888 | #endif |
---|
[789] | 1889 | if (strstr (r_inputs->value, ".") != NULL) |
---|
| 1890 | { |
---|
| 1891 | char *identifier = zStrdup (r_inputs->value); |
---|
| 1892 | parseIdentifier (m, conf_dir, identifier, tmps1); |
---|
| 1893 | map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); |
---|
| 1894 | if (tmpMap != NULL) |
---|
| 1895 | addToMap (request_inputs, "metapath", tmpMap->value); |
---|
| 1896 | free (identifier); |
---|
| 1897 | } |
---|
| 1898 | else |
---|
| 1899 | { |
---|
| 1900 | setMapInMaps (m, "lenv", "Identifier", r_inputs->value); |
---|
| 1901 | setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); |
---|
| 1902 | } |
---|
| 1903 | } |
---|
[539] | 1904 | |
---|
[541] | 1905 | r_inputs = getMapFromMaps (m, "lenv", "Identifier"); |
---|
[839] | 1906 | |
---|
| 1907 | #ifdef META_DB |
---|
| 1908 | int metadb_id=_init_sql(m,"metadb"); |
---|
| 1909 | //FAILED CONNECTING DB |
---|
[854] | 1910 | if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ |
---|
[839] | 1911 | fprintf(stderr,"ERROR CONNECTING METADB\n"); |
---|
| 1912 | } |
---|
[854] | 1913 | if(metadb_id>=0) |
---|
| 1914 | s1=extractServiceFromDb(m,r_inputs->value,0); |
---|
[839] | 1915 | //close_sql(m,0); |
---|
| 1916 | if(s1!=NULL){ |
---|
| 1917 | inheritance(zooRegistry,&s1); |
---|
| 1918 | #ifdef USE_HPC |
---|
| 1919 | addNestedOutputs(&s1); |
---|
| 1920 | #endif |
---|
| 1921 | if(zooRegistry!=NULL){ |
---|
| 1922 | freeRegistry(&zooRegistry); |
---|
| 1923 | free(zooRegistry); |
---|
| 1924 | } |
---|
| 1925 | }else /* Not found in MetaDB */{ |
---|
| 1926 | #endif |
---|
[865] | 1927 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1928 | if (s1 == NULL) |
---|
| 1929 | { |
---|
| 1930 | freeMaps (&m); |
---|
| 1931 | free (m); |
---|
| 1932 | if(zooRegistry!=NULL){ |
---|
| 1933 | freeRegistry(&zooRegistry); |
---|
| 1934 | free(zooRegistry); |
---|
| 1935 | } |
---|
| 1936 | free (REQUEST); |
---|
| 1937 | free (SERVICE_URL); |
---|
| 1938 | return errorException (m, _("Unable to allocate memory"), |
---|
| 1939 | "InternalError", NULL); |
---|
[839] | 1940 | } |
---|
| 1941 | |
---|
[865] | 1942 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1943 | dup2 (fileno (stderr), fileno (stdout)); |
---|
| 1944 | t = readServiceFile (m, tmps1, &s1, r_inputs->value); |
---|
[877] | 1945 | fprintf(stderr,"%d %s %d",t,__FILE__,__LINE__); |
---|
| 1946 | fflush(stderr); |
---|
| 1947 | if(t>=0){ |
---|
| 1948 | inheritance(zooRegistry,&s1); |
---|
[839] | 1949 | #ifdef USE_HPC |
---|
[877] | 1950 | addNestedOutputs(&s1); |
---|
[839] | 1951 | #endif |
---|
[877] | 1952 | } |
---|
[865] | 1953 | if(zooRegistry!=NULL){ |
---|
| 1954 | freeRegistry(&zooRegistry); |
---|
| 1955 | free(zooRegistry); |
---|
[541] | 1956 | } |
---|
[865] | 1957 | fflush (stdout); |
---|
| 1958 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1959 | if (t < 0) |
---|
| 1960 | { |
---|
| 1961 | char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); |
---|
| 1962 | sprintf (tmpMsg, |
---|
| 1963 | _ |
---|
| 1964 | ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), |
---|
| 1965 | r_inputs->value); |
---|
| 1966 | errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); |
---|
| 1967 | free (tmpMsg); |
---|
| 1968 | free (s1); |
---|
| 1969 | freeMaps (&m); |
---|
| 1970 | free (m); |
---|
| 1971 | free (REQUEST); |
---|
| 1972 | free (SERVICE_URL); |
---|
| 1973 | return 0; |
---|
| 1974 | } |
---|
| 1975 | close (saved_stdout); |
---|
[839] | 1976 | #ifdef META_DB |
---|
| 1977 | } |
---|
| 1978 | #endif |
---|
| 1979 | |
---|
[1] | 1980 | #ifdef DEBUG |
---|
[541] | 1981 | dumpService (s1); |
---|
[1] | 1982 | #endif |
---|
| 1983 | int j; |
---|
[381] | 1984 | |
---|
[541] | 1985 | |
---|
[1] | 1986 | /** |
---|
[344] | 1987 | * Create the input and output maps data structure |
---|
[1] | 1988 | */ |
---|
[541] | 1989 | int i = 0; |
---|
[1] | 1990 | HINTERNET hInternet; |
---|
| 1991 | HINTERNET res; |
---|
[541] | 1992 | hInternet = InternetOpen ( |
---|
[1] | 1993 | #ifndef WIN32 |
---|
[654] | 1994 | (LPCTSTR) |
---|
[1] | 1995 | #endif |
---|
[654] | 1996 | "ZooWPSClient\0", |
---|
| 1997 | INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); |
---|
[1] | 1998 | |
---|
| 1999 | #ifndef WIN32 |
---|
[541] | 2000 | if (!CHECK_INET_HANDLE (hInternet)) |
---|
| 2001 | fprintf (stderr, "WARNING : hInternet handle failed to initialize"); |
---|
[1] | 2002 | #endif |
---|
[541] | 2003 | maps *request_input_real_format = NULL; |
---|
| 2004 | maps *tmpmaps = request_input_real_format; |
---|
| 2005 | |
---|
[621] | 2006 | if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){ |
---|
| 2007 | freeMaps (&m); |
---|
| 2008 | free (m); |
---|
| 2009 | free (REQUEST); |
---|
| 2010 | free (SERVICE_URL); |
---|
| 2011 | InternetCloseHandle (&hInternet); |
---|
| 2012 | freeService (&s1); |
---|
| 2013 | free (s1); |
---|
| 2014 | return 0; |
---|
| 2015 | } |
---|
[839] | 2016 | //InternetCloseHandle (&hInternet); |
---|
| 2017 | |
---|
[652] | 2018 | // Define each env variable in runing environment |
---|
[541] | 2019 | maps *curs = getMaps (m, "env"); |
---|
| 2020 | if (curs != NULL) |
---|
| 2021 | { |
---|
| 2022 | map *mapcs = curs->content; |
---|
| 2023 | while (mapcs != NULLMAP) |
---|
| 2024 | { |
---|
[1] | 2025 | #ifndef WIN32 |
---|
[541] | 2026 | setenv (mapcs->name, mapcs->value, 1); |
---|
[1] | 2027 | #ifdef DEBUG |
---|
[541] | 2028 | fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, |
---|
| 2029 | mapcs->value); |
---|
[1] | 2030 | #endif |
---|
[767] | 2031 | #else |
---|
[541] | 2032 | if (mapcs->value[strlen (mapcs->value) - 2] == '\r') |
---|
| 2033 | { |
---|
[1] | 2034 | #ifdef DEBUG |
---|
[541] | 2035 | fprintf (stderr, "[ZOO: Env var finish with \r]\n"); |
---|
[1] | 2036 | #endif |
---|
[541] | 2037 | mapcs->value[strlen (mapcs->value) - 1] = 0; |
---|
| 2038 | } |
---|
[1] | 2039 | #ifdef DEBUG |
---|
[541] | 2040 | if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0) |
---|
| 2041 | { |
---|
| 2042 | fflush (stderr); |
---|
| 2043 | fprintf (stderr, "setting variable... %s\n", "OK"); |
---|
| 2044 | } |
---|
| 2045 | else |
---|
| 2046 | { |
---|
| 2047 | fflush (stderr); |
---|
| 2048 | fprintf (stderr, "setting variable... %s\n", "OK"); |
---|
| 2049 | } |
---|
[1] | 2050 | #else |
---|
[541] | 2051 | SetEnvironmentVariable (mapcs->name, mapcs->value); |
---|
[1] | 2052 | #endif |
---|
[541] | 2053 | char *toto = |
---|
| 2054 | (char *) |
---|
| 2055 | malloc ((strlen (mapcs->name) + strlen (mapcs->value) + |
---|
| 2056 | 2) * sizeof (char)); |
---|
| 2057 | sprintf (toto, "%s=%s", mapcs->name, mapcs->value); |
---|
| 2058 | putenv (toto); |
---|
[1] | 2059 | #ifdef DEBUG |
---|
[541] | 2060 | fflush (stderr); |
---|
[1] | 2061 | #endif |
---|
| 2062 | #endif |
---|
| 2063 | #ifdef DEBUG |
---|
[541] | 2064 | fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, |
---|
| 2065 | mapcs->value); |
---|
| 2066 | fflush (stderr); |
---|
[1] | 2067 | #endif |
---|
[541] | 2068 | mapcs = mapcs->next; |
---|
| 2069 | } |
---|
[1] | 2070 | } |
---|
[541] | 2071 | |
---|
[1] | 2072 | #ifdef DEBUG |
---|
[541] | 2073 | dumpMap (request_inputs); |
---|
[1] | 2074 | #endif |
---|
| 2075 | |
---|
[541] | 2076 | map *status = getMap (request_inputs, "status"); |
---|
[654] | 2077 | if(vid==0){ |
---|
| 2078 | // Need to check if we need to fork to load a status enabled |
---|
| 2079 | r_inputs = NULL; |
---|
| 2080 | map *store = getMap (request_inputs, "storeExecuteResponse"); |
---|
| 2081 | /** |
---|
| 2082 | * 05-007r7 WPS 1.0.0 page 57 : |
---|
| 2083 | * 'If status="true" and storeExecuteResponse is "false" then the service |
---|
| 2084 | * shall raise an exception.' |
---|
| 2085 | */ |
---|
| 2086 | if (status != NULL && strcmp (status->value, "true") == 0 && |
---|
| 2087 | store != NULL && strcmp (store->value, "false") == 0) |
---|
| 2088 | { |
---|
| 2089 | errorException (m, |
---|
| 2090 | _ |
---|
| 2091 | ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."), |
---|
| 2092 | "InvalidParameterValue", "storeExecuteResponse"); |
---|
| 2093 | freeService (&s1); |
---|
| 2094 | free (s1); |
---|
| 2095 | freeMaps (&m); |
---|
| 2096 | free (m); |
---|
| 2097 | |
---|
| 2098 | freeMaps (&request_input_real_format); |
---|
| 2099 | free (request_input_real_format); |
---|
| 2100 | |
---|
| 2101 | freeMaps (&request_output_real_format); |
---|
| 2102 | free (request_output_real_format); |
---|
[94] | 2103 | |
---|
[654] | 2104 | free (REQUEST); |
---|
| 2105 | free (SERVICE_URL); |
---|
| 2106 | return 1; |
---|
| 2107 | } |
---|
| 2108 | r_inputs = getMap (request_inputs, "storeExecuteResponse"); |
---|
| 2109 | }else{ |
---|
| 2110 | // Define status depending on the WPS 2.0.0 mode attribute |
---|
| 2111 | status = getMap (request_inputs, "mode"); |
---|
| 2112 | map* mode=getMap(s1->content,"mode"); |
---|
| 2113 | if(strcasecmp(status->value,"async")==0){ |
---|
| 2114 | if(mode!=NULL && strcasecmp(mode->value,"async")==0) |
---|
| 2115 | addToMap(request_inputs,"status","true"); |
---|
| 2116 | else{ |
---|
| 2117 | if(mode!=NULL){ |
---|
| 2118 | // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61 |
---|
| 2119 | errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); |
---|
| 2120 | fflush (stdout); |
---|
| 2121 | freeMaps (&m); |
---|
| 2122 | free (m); |
---|
| 2123 | if(zooRegistry!=NULL){ |
---|
| 2124 | freeRegistry(&zooRegistry); |
---|
| 2125 | free(zooRegistry); |
---|
| 2126 | } |
---|
| 2127 | freeMaps (&request_input_real_format); |
---|
| 2128 | free (request_input_real_format); |
---|
| 2129 | freeMaps (&request_output_real_format); |
---|
| 2130 | free (request_output_real_format); |
---|
| 2131 | free (REQUEST); |
---|
| 2132 | free (SERVICE_URL); |
---|
| 2133 | return 0; |
---|
| 2134 | }else |
---|
| 2135 | addToMap(request_inputs,"status","true"); |
---|
| 2136 | } |
---|
| 2137 | } |
---|
| 2138 | else{ |
---|
| 2139 | if(strcasecmp(status->value,"auto")==0){ |
---|
| 2140 | if(mode!=NULL){ |
---|
| 2141 | if(strcasecmp(mode->value,"async")==0) |
---|
| 2142 | addToMap(request_inputs,"status","false"); |
---|
| 2143 | else |
---|
| 2144 | addToMap(request_inputs,"status","true"); |
---|
| 2145 | } |
---|
| 2146 | else |
---|
| 2147 | addToMap(request_inputs,"status","false"); |
---|
| 2148 | }else |
---|
| 2149 | addToMap(request_inputs,"status","false"); |
---|
| 2150 | } |
---|
| 2151 | status = getMap (request_inputs, "status"); |
---|
| 2152 | } |
---|
[541] | 2153 | |
---|
| 2154 | int eres = SERVICE_STARTED; |
---|
| 2155 | int cpid = getpid (); |
---|
| 2156 | |
---|
[839] | 2157 | // Create a map containing a copy of the request map |
---|
| 2158 | maps *_tmpMaps = createMaps("request"); |
---|
| 2159 | addMapToMap(&_tmpMaps->content,request_inputs); |
---|
| 2160 | addMapsToMaps (&m, _tmpMaps); |
---|
| 2161 | freeMaps (&_tmpMaps); |
---|
| 2162 | free (_tmpMaps); |
---|
[453] | 2163 | /** |
---|
| 2164 | * Initialize the specific [lenv] section which contains runtime variables: |
---|
| 2165 | * |
---|
[682] | 2166 | * - usid : it is an universally unique identifier |
---|
| 2167 | * - osid : it is an idenfitication number |
---|
[453] | 2168 | * - sid : it is the process idenfitication number (OS) |
---|
[682] | 2169 | * - uusid : it is an universally unique identifier |
---|
[453] | 2170 | * - status : value between 0 and 100 to express the completude of |
---|
| 2171 | * the operations of the running service |
---|
| 2172 | * - message : is a string where you can store error messages, in case |
---|
| 2173 | * service is failing, or o provide details on the ongoing operation. |
---|
[784] | 2174 | * - cwd : the current working directory or servicePath if defined |
---|
[453] | 2175 | * - soap : is a boolean value, true if the request was contained in a SOAP |
---|
| 2176 | * Envelop |
---|
| 2177 | * - sessid : string storing the session identifier (only when cookie is |
---|
| 2178 | * used) |
---|
| 2179 | * - cgiSid : only defined on Window platforms (for being able to identify |
---|
| 2180 | * the created process) |
---|
| 2181 | * |
---|
| 2182 | */ |
---|
[839] | 2183 | _tmpMaps = createMaps("lenv"); |
---|
[32] | 2184 | char tmpBuff[100]; |
---|
[514] | 2185 | struct ztimeval tp; |
---|
[541] | 2186 | if (zGettimeofday (&tp, NULL) == 0) |
---|
| 2187 | sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec))); |
---|
[514] | 2188 | else |
---|
[541] | 2189 | sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); |
---|
[652] | 2190 | _tmpMaps->content = createMap ("osid", tmpBuff); |
---|
[541] | 2191 | sprintf (tmpBuff, "%i", cpid); |
---|
| 2192 | addToMap (_tmpMaps->content, "sid", tmpBuff); |
---|
[640] | 2193 | char* tmpUuid=get_uuid(); |
---|
| 2194 | addToMap (_tmpMaps->content, "uusid", tmpUuid); |
---|
[652] | 2195 | addToMap (_tmpMaps->content, "usid", tmpUuid); |
---|
[640] | 2196 | free(tmpUuid); |
---|
[541] | 2197 | addToMap (_tmpMaps->content, "status", "0"); |
---|
[784] | 2198 | if(cwdMap0!=NULL){ |
---|
| 2199 | addToMap (_tmpMaps->content, "cwd", cwdMap0->value); |
---|
| 2200 | addToMap (_tmpMaps->content, "rcwd", ntmp); |
---|
| 2201 | } |
---|
| 2202 | else |
---|
| 2203 | addToMap (_tmpMaps->content, "cwd", ntmp); |
---|
[541] | 2204 | addToMap (_tmpMaps->content, "message", _("No message provided")); |
---|
| 2205 | map *ltmp = getMap (request_inputs, "soap"); |
---|
| 2206 | if (ltmp != NULL) |
---|
| 2207 | addToMap (_tmpMaps->content, "soap", ltmp->value); |
---|
[280] | 2208 | else |
---|
[541] | 2209 | addToMap (_tmpMaps->content, "soap", "false"); |
---|
[654] | 2210 | |
---|
[850] | 2211 | // Parse the session file and add it to the main maps |
---|
| 2212 | char* originalCookie=NULL; |
---|
[541] | 2213 | if (cgiCookie != NULL && strlen (cgiCookie) > 0) |
---|
| 2214 | { |
---|
| 2215 | int hasValidCookie = -1; |
---|
[854] | 2216 | char *tcook = originalCookie = zStrdup (cgiCookie); |
---|
[541] | 2217 | map *testing = getMapFromMaps (m, "main", "cookiePrefix"); |
---|
[854] | 2218 | parseCookie(&m,originalCookie); |
---|
[860] | 2219 | map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value)); |
---|
| 2220 | if (sessId!=NULL) |
---|
[541] | 2221 | { |
---|
[860] | 2222 | addToMap (_tmpMaps->content, "sessid", sessId->value); |
---|
[541] | 2223 | char session_file_path[1024]; |
---|
| 2224 | map *tmpPath = getMapFromMaps (m, "main", "sessPath"); |
---|
| 2225 | if (tmpPath == NULL) |
---|
| 2226 | tmpPath = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 2227 | char *tmp1 = strtok (tcook, ";"); |
---|
| 2228 | if (tmp1 != NULL) |
---|
| 2229 | sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, |
---|
[860] | 2230 | sessId->value); |
---|
[541] | 2231 | else |
---|
| 2232 | sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, |
---|
[860] | 2233 | sessId->value); |
---|
[541] | 2234 | free (tcook); |
---|
| 2235 | maps *tmpSess = (maps *) malloc (MAPS_SIZE); |
---|
[790] | 2236 | tmpSess->child=NULL; |
---|
[541] | 2237 | struct stat file_status; |
---|
| 2238 | int istat = stat (session_file_path, &file_status); |
---|
| 2239 | if (istat == 0 && file_status.st_size > 0) |
---|
| 2240 | { |
---|
[854] | 2241 | int saved_stdout = dup (fileno (stdout)); |
---|
| 2242 | dup2 (fileno (stderr), fileno (stdout)); |
---|
[541] | 2243 | conf_read (session_file_path, tmpSess); |
---|
| 2244 | addMapsToMaps (&m, tmpSess); |
---|
| 2245 | freeMaps (&tmpSess); |
---|
[854] | 2246 | fflush(stdout); |
---|
| 2247 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 2248 | close(saved_stdout); |
---|
[541] | 2249 | } |
---|
[817] | 2250 | free (tmpSess); |
---|
[541] | 2251 | } |
---|
[92] | 2252 | } |
---|
[541] | 2253 | addMapsToMaps (&m, _tmpMaps); |
---|
| 2254 | freeMaps (&_tmpMaps); |
---|
| 2255 | free (_tmpMaps); |
---|
[654] | 2256 | maps* bmap=NULL; |
---|
[1] | 2257 | #ifdef DEBUG |
---|
[541] | 2258 | dumpMap (request_inputs); |
---|
[1] | 2259 | #endif |
---|
[772] | 2260 | int ei = 1; |
---|
[877] | 2261 | |
---|
[216] | 2262 | #ifdef WIN32 |
---|
[877] | 2263 | LPVOID orig = GetEnvironmentStrings(); |
---|
| 2264 | LPTSTR s = (LPTSTR) orig; |
---|
[772] | 2265 | #else |
---|
[877] | 2266 | char **orig = environ; |
---|
| 2267 | char *s=*orig; |
---|
[772] | 2268 | #endif |
---|
[877] | 2269 | |
---|
[790] | 2270 | _tmpMaps = createMaps("renv"); |
---|
[772] | 2271 | for (; s; ei++) { |
---|
[851] | 2272 | if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){ |
---|
| 2273 | int len=strlen(s); |
---|
| 2274 | char* tmpName=zStrdup(s); |
---|
| 2275 | char* tmpValue=strstr(s,"=")+1; |
---|
[854] | 2276 | char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); |
---|
| 2277 | snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); |
---|
[851] | 2278 | if(_tmpMaps->content == NULL) |
---|
| 2279 | _tmpMaps->content = createMap (tmpName1,tmpValue); |
---|
| 2280 | else |
---|
| 2281 | addToMap (_tmpMaps->content,tmpName1,tmpValue); |
---|
| 2282 | free(tmpName1); |
---|
| 2283 | free(tmpName); |
---|
| 2284 | } |
---|
[877] | 2285 | #ifdef WIN32 |
---|
| 2286 | s++; |
---|
| 2287 | #else |
---|
[839] | 2288 | s = *(orig+ei); |
---|
[877] | 2289 | #endif |
---|
[772] | 2290 | } |
---|
[850] | 2291 | if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ |
---|
| 2292 | addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); |
---|
| 2293 | } |
---|
[772] | 2294 | addMapsToMaps (&m, _tmpMaps); |
---|
| 2295 | freeMaps (&_tmpMaps); |
---|
| 2296 | free (_tmpMaps); |
---|
[877] | 2297 | |
---|
[854] | 2298 | if(postRequest!=NULL) |
---|
| 2299 | setMapInMaps (m, "renv", "xrequest", postRequest->value); |
---|
| 2300 | //dumpMaps(m); |
---|
[772] | 2301 | #ifdef WIN32 |
---|
[541] | 2302 | char *cgiSidL = NULL; |
---|
| 2303 | if (getenv ("CGISID") != NULL) |
---|
| 2304 | addToMap (request_inputs, "cgiSid", getenv ("CGISID")); |
---|
[554] | 2305 | |
---|
| 2306 | char* usidp; |
---|
| 2307 | if ( (usidp = getenv("USID")) != NULL ) { |
---|
| 2308 | setMapInMaps (m, "lenv", "usid", usidp); |
---|
| 2309 | } |
---|
| 2310 | |
---|
[541] | 2311 | map *test1 = getMap (request_inputs, "cgiSid"); |
---|
[680] | 2312 | if (test1 != NULL){ |
---|
[682] | 2313 | cgiSid = zStrdup(test1->value); |
---|
| 2314 | addToMap (request_inputs, "storeExecuteResponse", "true"); |
---|
| 2315 | addToMap (request_inputs, "status", "true"); |
---|
| 2316 | setMapInMaps (m, "lenv", "osid", test1->value); |
---|
| 2317 | status = getMap (request_inputs, "status"); |
---|
| 2318 | } |
---|
[680] | 2319 | test1 = getMap (request_inputs, "usid"); |
---|
| 2320 | if (test1 != NULL){ |
---|
| 2321 | setMapInMaps (m, "lenv", "usid", test1->value); |
---|
| 2322 | setMapInMaps (m, "lenv", "uusid", test1->value); |
---|
| 2323 | } |
---|
[216] | 2324 | #endif |
---|
[788] | 2325 | |
---|
[654] | 2326 | char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; |
---|
[541] | 2327 | FILE *f0, *f1; |
---|
| 2328 | if (status != NULL) |
---|
| 2329 | if (strcasecmp (status->value, "false") == 0) |
---|
| 2330 | status = NULLMAP; |
---|
| 2331 | if (status == NULLMAP) |
---|
| 2332 | { |
---|
[621] | 2333 | if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ |
---|
| 2334 | freeService (&s1); |
---|
| 2335 | free (s1); |
---|
| 2336 | freeMaps (&m); |
---|
| 2337 | free (m); |
---|
| 2338 | free (REQUEST); |
---|
| 2339 | free (SERVICE_URL); |
---|
| 2340 | freeMaps (&request_input_real_format); |
---|
| 2341 | free (request_input_real_format); |
---|
| 2342 | freeMaps (&request_output_real_format); |
---|
| 2343 | free (request_output_real_format); |
---|
| 2344 | freeMaps (&tmpmaps); |
---|
| 2345 | free (tmpmaps); |
---|
| 2346 | return -1; |
---|
| 2347 | } |
---|
[877] | 2348 | map* testMap=getMapFromMaps(m,"main","memory"); |
---|
| 2349 | if(testMap!=NULL && strcasecmp(testMap->value,"load")!=0) |
---|
| 2350 | dumpMapsValuesToFiles(&m,&request_input_real_format); |
---|
[541] | 2351 | loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, |
---|
| 2352 | &request_output_real_format, &eres); |
---|
[854] | 2353 | |
---|
[851] | 2354 | #ifdef META_DB |
---|
[854] | 2355 | close_sql(m,0); |
---|
| 2356 | #endif |
---|
[541] | 2357 | } |
---|
| 2358 | else |
---|
| 2359 | { |
---|
| 2360 | int pid; |
---|
[1] | 2361 | #ifdef DEBUG |
---|
[541] | 2362 | fprintf (stderr, "\nPID : %d\n", cpid); |
---|
[1] | 2363 | #endif |
---|
| 2364 | #ifndef WIN32 |
---|
[541] | 2365 | pid = fork (); |
---|
[1] | 2366 | #else |
---|
[541] | 2367 | if (cgiSid == NULL) |
---|
| 2368 | { |
---|
[865] | 2369 | createProcess (m, request_inputs, s1, NULL, cpid, |
---|
| 2370 | request_input_real_format, |
---|
| 2371 | request_output_real_format); |
---|
| 2372 | pid = cpid; |
---|
[541] | 2373 | } |
---|
| 2374 | else |
---|
| 2375 | { |
---|
[865] | 2376 | pid = 0; |
---|
| 2377 | cpid = atoi (cgiSid); |
---|
[680] | 2378 | updateStatus(m,0,_("Initializing")); |
---|
[541] | 2379 | } |
---|
[1] | 2380 | #endif |
---|
[541] | 2381 | if (pid > 0) |
---|
[865] | 2382 | { |
---|
| 2383 | // |
---|
| 2384 | // dady : |
---|
| 2385 | // set status to SERVICE_ACCEPTED |
---|
| 2386 | // |
---|
[1] | 2387 | #ifdef DEBUG |
---|
[865] | 2388 | fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, |
---|
| 2389 | getpid ()); |
---|
[1] | 2390 | #endif |
---|
[865] | 2391 | eres = SERVICE_ACCEPTED; |
---|
| 2392 | } |
---|
[541] | 2393 | else if (pid == 0) |
---|
[865] | 2394 | { |
---|
[877] | 2395 | eres = SERVICE_ACCEPTED; |
---|
[865] | 2396 | // |
---|
| 2397 | // son : have to close the stdout, stdin and stderr to let the parent |
---|
| 2398 | // process answer to http client. |
---|
| 2399 | // |
---|
[652] | 2400 | map* usid = getMapFromMaps (m, "lenv", "uusid"); |
---|
[865] | 2401 | map* tmpm = getMapFromMaps (m, "lenv", "osid"); |
---|
| 2402 | int cpid = atoi (tmpm->value); |
---|
| 2403 | pid=cpid; |
---|
| 2404 | r_inputs = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 2405 | setMapInMaps (m, "lenv", "async","true"); |
---|
[652] | 2406 | map* r_inputs1 = createMap("ServiceName", s1->name); |
---|
[605] | 2407 | |
---|
[654] | 2408 | // Create the filename for the result file (.res) |
---|
[865] | 2409 | fbkpres = |
---|
| 2410 | (char *) |
---|
| 2411 | malloc ((strlen (r_inputs->value) + |
---|
| 2412 | strlen (usid->value) + 7) * sizeof (char)); |
---|
| 2413 | sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); |
---|
[790] | 2414 | bmap = createMaps("status"); |
---|
[654] | 2415 | bmap->content=createMap("usid",usid->value); |
---|
| 2416 | addToMap(bmap->content,"sid",tmpm->value); |
---|
| 2417 | addIntToMap(bmap->content,"pid",getpid()); |
---|
| 2418 | |
---|
[652] | 2419 | // Create PID file referencing the OS process identifier |
---|
[865] | 2420 | fbkpid = |
---|
| 2421 | (char *) |
---|
| 2422 | malloc ((strlen (r_inputs->value) + |
---|
| 2423 | strlen (usid->value) + 7) * sizeof (char)); |
---|
| 2424 | sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); |
---|
[772] | 2425 | setMapInMaps (m, "lenv", "file.pid", fbkpid); |
---|
[652] | 2426 | |
---|
[865] | 2427 | f0 = freopen (fbkpid, "w+",stdout); |
---|
[680] | 2428 | printf("%d",getpid()); |
---|
[652] | 2429 | fflush(stdout); |
---|
| 2430 | |
---|
| 2431 | // Create SID file referencing the semaphore name |
---|
[865] | 2432 | fbkp = |
---|
| 2433 | (char *) |
---|
| 2434 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 2435 | strlen (usid->value) + 7) * sizeof (char)); |
---|
| 2436 | sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); |
---|
[772] | 2437 | setMapInMaps (m, "lenv", "file.sid", fbkp); |
---|
[865] | 2438 | FILE* f2 = freopen (fbkp, "w+",stdout); |
---|
[680] | 2439 | printf("%s",tmpm->value); |
---|
[652] | 2440 | fflush(f2); |
---|
| 2441 | free(fbkp); |
---|
| 2442 | |
---|
[865] | 2443 | fbkp = |
---|
| 2444 | (char *) |
---|
| 2445 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 2446 | strlen (usid->value) + 7) * sizeof (char)); |
---|
| 2447 | sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, |
---|
| 2448 | usid->value); |
---|
[772] | 2449 | setMapInMaps (m, "lenv", "file.responseInit", fbkp); |
---|
[865] | 2450 | flog = |
---|
| 2451 | (char *) |
---|
| 2452 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 2453 | strlen (usid->value) + 13) * sizeof (char)); |
---|
| 2454 | sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, |
---|
| 2455 | r_inputs1->value, usid->value); |
---|
[772] | 2456 | setMapInMaps (m, "lenv", "file.log", flog); |
---|
[1] | 2457 | #ifdef DEBUG |
---|
[865] | 2458 | fprintf (stderr, "RUN IN BACKGROUND MODE \n"); |
---|
| 2459 | fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, |
---|
| 2460 | getpid ()); |
---|
| 2461 | fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); |
---|
[1] | 2462 | #endif |
---|
[865] | 2463 | freopen (flog, "w+", stderr); |
---|
| 2464 | fflush (stderr); |
---|
[654] | 2465 | f0 = freopen (fbkp, "w+", stdout); |
---|
| 2466 | rewind (stdout); |
---|
[458] | 2467 | #ifndef WIN32 |
---|
[654] | 2468 | fclose (stdin); |
---|
[458] | 2469 | #endif |
---|
[652] | 2470 | #ifdef RELY_ON_DB |
---|
| 2471 | init_sql(m); |
---|
| 2472 | recordServiceStatus(m); |
---|
| 2473 | #endif |
---|
[877] | 2474 | #ifdef USE_HPC |
---|
[850] | 2475 | invokeCallback(m,NULL,NULL,0,0); |
---|
[877] | 2476 | #endif |
---|
[654] | 2477 | if(vid==0){ |
---|
[865] | 2478 | // |
---|
| 2479 | // set status to SERVICE_STARTED and flush stdout to ensure full |
---|
| 2480 | // content was outputed (the file used to store the ResponseDocument). |
---|
| 2481 | // Then, rewind stdout to restart writing from the begining of the file. |
---|
| 2482 | // This way, the data will be updated at the end of the process run. |
---|
| 2483 | // |
---|
[654] | 2484 | printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, |
---|
| 2485 | SERVICE_STARTED, request_input_real_format, |
---|
| 2486 | request_output_real_format); |
---|
| 2487 | fflush (stdout); |
---|
| 2488 | #ifdef RELY_ON_DB |
---|
| 2489 | recordResponse(m,fbkp); |
---|
| 2490 | #endif |
---|
| 2491 | } |
---|
| 2492 | |
---|
[865] | 2493 | fflush (stderr); |
---|
[654] | 2494 | |
---|
[865] | 2495 | fbkp1 = |
---|
| 2496 | (char *) |
---|
| 2497 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 2498 | strlen (usid->value) + 13) * sizeof (char)); |
---|
| 2499 | sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, |
---|
| 2500 | r_inputs1->value, usid->value); |
---|
[772] | 2501 | setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); |
---|
[631] | 2502 | |
---|
[865] | 2503 | f1 = freopen (fbkp1, "w+", stdout); |
---|
[631] | 2504 | |
---|
[839] | 2505 | map* serviceTypeMap=getMap(s1->content,"serviceType"); |
---|
| 2506 | if(serviceTypeMap!=NULL) |
---|
| 2507 | setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); |
---|
| 2508 | |
---|
[865] | 2509 | char *flenv = |
---|
| 2510 | (char *) |
---|
| 2511 | malloc ((strlen (r_inputs->value) + |
---|
| 2512 | strlen (usid->value) + 12) * sizeof (char)); |
---|
| 2513 | sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); |
---|
[839] | 2514 | maps* lenvMaps=getMaps(m,"lenv"); |
---|
| 2515 | dumpMapsToFile(lenvMaps,flenv,0); |
---|
| 2516 | free(flenv); |
---|
| 2517 | |
---|
[877] | 2518 | #ifdef USE_HPC |
---|
[839] | 2519 | invokeCallback(m,request_input_real_format,NULL,1,0); |
---|
[877] | 2520 | #endif |
---|
[621] | 2521 | if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ |
---|
| 2522 | freeService (&s1); |
---|
| 2523 | free (s1); |
---|
[854] | 2524 | fflush (stdout); |
---|
| 2525 | fflush (stderr); |
---|
[765] | 2526 | fclose (f0); |
---|
| 2527 | fclose (f1); |
---|
| 2528 | if(dumpBackFinalFile(m,fbkp,fbkp1)<0) |
---|
| 2529 | return -1; |
---|
[854] | 2530 | #ifndef RELY_ON_DB |
---|
| 2531 | dumpMapsToFile(bmap,fbkpres,1); |
---|
| 2532 | removeShmLock (m, 1); |
---|
| 2533 | #else |
---|
| 2534 | recordResponse(m,fbkp1); |
---|
[877] | 2535 | #ifdef USE_HPC |
---|
[854] | 2536 | invokeCallback(m,NULL,NULL,7,0); |
---|
| 2537 | #endif |
---|
[877] | 2538 | #endif |
---|
[765] | 2539 | unlink (fbkpid); |
---|
| 2540 | unhandleStatus (m); |
---|
[854] | 2541 | #ifdef RELY_ON_DB |
---|
| 2542 | #ifdef META_DB |
---|
| 2543 | cleanupCallbackThreads(); |
---|
| 2544 | close_sql(m,1); |
---|
| 2545 | #endif |
---|
| 2546 | close_sql(m,0); |
---|
| 2547 | #endif |
---|
[621] | 2548 | freeMaps (&m); |
---|
| 2549 | free (m); |
---|
| 2550 | free (REQUEST); |
---|
| 2551 | free (SERVICE_URL); |
---|
| 2552 | freeMaps (&request_input_real_format); |
---|
| 2553 | free (request_input_real_format); |
---|
| 2554 | freeMaps (&request_output_real_format); |
---|
| 2555 | free (request_output_real_format); |
---|
| 2556 | freeMaps (&tmpmaps); |
---|
| 2557 | free (tmpmaps); |
---|
| 2558 | return -1; |
---|
| 2559 | } |
---|
[865] | 2560 | if(getMapFromMaps(m,"lenv","mapError")!=NULL){ |
---|
| 2561 | setMapInMaps(m,"lenv","message",_("Issue with geographic data")); |
---|
[877] | 2562 | #ifdef USE_HPC |
---|
[865] | 2563 | invokeCallback(m,NULL,NULL,7,0); |
---|
[877] | 2564 | #endif |
---|
[865] | 2565 | eres=-1;//SERVICE_FAILED; |
---|
[854] | 2566 | }else{ |
---|
[877] | 2567 | map* testMap=getMapFromMaps(m,"main","memory"); |
---|
| 2568 | if(testMap!=NULL && strcasecmp(testMap->value,"load")!=0) |
---|
| 2569 | dumpMapsValuesToFiles(&m,&request_input_real_format); |
---|
[854] | 2570 | loadServiceAndRun (&m, s1, request_inputs, |
---|
| 2571 | &request_input_real_format, |
---|
| 2572 | &request_output_real_format, &eres); |
---|
| 2573 | } |
---|
[865] | 2574 | } |
---|
[541] | 2575 | else |
---|
| 2576 | { |
---|
[652] | 2577 | /** |
---|
| 2578 | * error server don't accept the process need to output a valid |
---|
| 2579 | * error response here !!! |
---|
| 2580 | */ |
---|
[865] | 2581 | eres = -1; |
---|
| 2582 | errorException (m, _("Unable to run the child process properly"), |
---|
| 2583 | "InternalError", NULL); |
---|
[541] | 2584 | } |
---|
[1] | 2585 | } |
---|
| 2586 | |
---|
[839] | 2587 | #ifdef DEBUG |
---|
| 2588 | fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); |
---|
[541] | 2589 | dumpMaps (request_output_real_format); |
---|
[839] | 2590 | fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); |
---|
| 2591 | #endif |
---|
[860] | 2592 | fflush(stdout); |
---|
| 2593 | rewind(stdout); |
---|
| 2594 | |
---|
[877] | 2595 | //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); |
---|
[873] | 2596 | |
---|
[541] | 2597 | if (eres != -1) |
---|
| 2598 | outputResponse (s1, request_input_real_format, |
---|
| 2599 | request_output_real_format, request_inputs, |
---|
| 2600 | cpid, m, eres); |
---|
| 2601 | fflush (stdout); |
---|
[788] | 2602 | |
---|
[105] | 2603 | /** |
---|
| 2604 | * Ensure that if error occurs when freeing memory, no signal will return |
---|
| 2605 | * an ExceptionReport document as the result was already returned to the |
---|
| 2606 | * client. |
---|
| 2607 | */ |
---|
| 2608 | #ifndef USE_GDB |
---|
[541] | 2609 | signal (SIGSEGV, donothing); |
---|
| 2610 | signal (SIGTERM, donothing); |
---|
| 2611 | signal (SIGINT, donothing); |
---|
| 2612 | signal (SIGILL, donothing); |
---|
| 2613 | signal (SIGFPE, donothing); |
---|
| 2614 | signal (SIGABRT, donothing); |
---|
[105] | 2615 | #endif |
---|
[788] | 2616 | |
---|
[541] | 2617 | if (((int) getpid ()) != cpid || cgiSid != NULL) |
---|
| 2618 | { |
---|
[854] | 2619 | if (eres == SERVICE_SUCCEEDED) |
---|
[877] | 2620 | #ifdef USE_HPC |
---|
[854] | 2621 | invokeCallback(m,NULL,request_output_real_format,5,1); |
---|
[877] | 2622 | #endif |
---|
[851] | 2623 | fflush(stderr); |
---|
[854] | 2624 | fflush(stdout); |
---|
[851] | 2625 | |
---|
[541] | 2626 | fclose (stdout); |
---|
[765] | 2627 | |
---|
[541] | 2628 | fclose (f0); |
---|
| 2629 | fclose (f1); |
---|
[654] | 2630 | |
---|
[765] | 2631 | if(dumpBackFinalFile(m,fbkp,fbkp1)<0) |
---|
| 2632 | return -1; |
---|
[652] | 2633 | unlink (fbkpid); |
---|
[654] | 2634 | switch(eres){ |
---|
| 2635 | default: |
---|
| 2636 | case SERVICE_FAILED: |
---|
| 2637 | setMapInMaps(bmap,"status","status",wpsStatus[1]); |
---|
| 2638 | setMapInMaps(m,"lenv","fstate",wpsStatus[1]); |
---|
| 2639 | break; |
---|
| 2640 | case SERVICE_SUCCEEDED: |
---|
| 2641 | setMapInMaps(bmap,"status","status",wpsStatus[0]); |
---|
| 2642 | setMapInMaps(m,"lenv","fstate",wpsStatus[0]); |
---|
| 2643 | break; |
---|
[865] | 2644 | } |
---|
[652] | 2645 | #ifndef RELY_ON_DB |
---|
[682] | 2646 | dumpMapsToFile(bmap,fbkpres,1); |
---|
[652] | 2647 | removeShmLock (m, 1); |
---|
| 2648 | #else |
---|
| 2649 | recordResponse(m,fbkp1); |
---|
[854] | 2650 | if (eres == SERVICE_SUCCEEDED) |
---|
[877] | 2651 | #ifdef USE_HPC |
---|
[854] | 2652 | invokeCallback(m,NULL,request_output_real_format,6,0); |
---|
[652] | 2653 | #endif |
---|
[877] | 2654 | #endif |
---|
[654] | 2655 | freeMaps(&bmap); |
---|
| 2656 | free(bmap); |
---|
[541] | 2657 | unlink (fbkp1); |
---|
[652] | 2658 | unhandleStatus (m); |
---|
[851] | 2659 | #ifdef RELY_ON_DB |
---|
[839] | 2660 | #ifdef META_DB |
---|
[851] | 2661 | cleanupCallbackThreads(); |
---|
| 2662 | close_sql(m,1); |
---|
[839] | 2663 | #endif |
---|
[851] | 2664 | close_sql(m,0); |
---|
[854] | 2665 | end_sql(); |
---|
[851] | 2666 | #endif |
---|
[652] | 2667 | free(fbkpid); |
---|
[788] | 2668 | free(fbkpres); |
---|
[541] | 2669 | free (fbkp1); |
---|
[682] | 2670 | if(cgiSid!=NULL) |
---|
| 2671 | free(cgiSid); |
---|
[851] | 2672 | //InternetCloseHandle (&hInternet); |
---|
[839] | 2673 | fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); |
---|
| 2674 | fflush(stderr); |
---|
| 2675 | fclose (stderr); |
---|
[854] | 2676 | unlink (flog); |
---|
| 2677 | free (flog); |
---|
[541] | 2678 | } |
---|
[839] | 2679 | else{ |
---|
| 2680 | //InternetCloseHandle (&hInternet); |
---|
| 2681 | #ifdef META_DB |
---|
[865] | 2682 | close_sql(m,0); |
---|
[839] | 2683 | #endif |
---|
| 2684 | } |
---|
| 2685 | |
---|
[541] | 2686 | freeService (&s1); |
---|
| 2687 | free (s1); |
---|
| 2688 | freeMaps (&m); |
---|
| 2689 | free (m); |
---|
| 2690 | |
---|
| 2691 | freeMaps (&request_input_real_format); |
---|
| 2692 | free (request_input_real_format); |
---|
| 2693 | |
---|
| 2694 | freeMaps (&request_output_real_format); |
---|
| 2695 | free (request_output_real_format); |
---|
| 2696 | |
---|
| 2697 | free (REQUEST); |
---|
| 2698 | free (SERVICE_URL); |
---|
[1] | 2699 | #ifdef DEBUG |
---|
[541] | 2700 | fprintf (stderr, "Processed response \n"); |
---|
| 2701 | fflush (stdout); |
---|
| 2702 | fflush (stderr); |
---|
[1] | 2703 | #endif |
---|
| 2704 | |
---|
[541] | 2705 | if (((int) getpid ()) != cpid || cgiSid != NULL) |
---|
| 2706 | { |
---|
| 2707 | exit (0); |
---|
| 2708 | } |
---|
[516] | 2709 | |
---|
[1] | 2710 | return 0; |
---|
| 2711 | } |
---|