[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 | */ |
---|
| 24 | |
---|
| 25 | |
---|
[550] | 26 | |
---|
[541] | 27 | extern "C" int yylex (); |
---|
| 28 | extern "C" int crlex (); |
---|
[9] | 29 | |
---|
[550] | 30 | #ifdef USE_OTB |
---|
| 31 | #include "service_internal_otb.h" |
---|
| 32 | #else |
---|
| 33 | #define length(x) (sizeof(x) / sizeof(x[0])) |
---|
| 34 | #endif |
---|
| 35 | |
---|
[376] | 36 | #include "cgic.h" |
---|
| 37 | |
---|
[541] | 38 | extern "C" |
---|
| 39 | { |
---|
[1] | 40 | #include <libxml/tree.h> |
---|
| 41 | #include <libxml/xmlmemory.h> |
---|
| 42 | #include <libxml/parser.h> |
---|
| 43 | #include <libxml/xpath.h> |
---|
| 44 | #include <libxml/xpathInternals.h> |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | #include "ulinet.h" |
---|
| 48 | |
---|
[34] | 49 | #include <libintl.h> |
---|
| 50 | #include <locale.h> |
---|
[1] | 51 | #include <string.h> |
---|
| 52 | |
---|
| 53 | #include "service.h" |
---|
[34] | 54 | |
---|
[1] | 55 | #include "service_internal.h" |
---|
[33] | 56 | |
---|
| 57 | #ifdef USE_PYTHON |
---|
[1] | 58 | #include "service_internal_python.h" |
---|
[33] | 59 | #endif |
---|
[1] | 60 | |
---|
| 61 | #ifdef USE_JAVA |
---|
| 62 | #include "service_internal_java.h" |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | #ifdef USE_PHP |
---|
| 66 | #include "service_internal_php.h" |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | #ifdef USE_JS |
---|
| 70 | #include "service_internal_js.h" |
---|
| 71 | #endif |
---|
| 72 | |
---|
[453] | 73 | #ifdef USE_RUBY |
---|
| 74 | #include "service_internal_ruby.h" |
---|
| 75 | #endif |
---|
| 76 | |
---|
[25] | 77 | #ifdef USE_PERL |
---|
| 78 | #include "service_internal_perl.h" |
---|
| 79 | #endif |
---|
[1] | 80 | |
---|
| 81 | #include <dirent.h> |
---|
| 82 | #include <signal.h> |
---|
| 83 | #include <unistd.h> |
---|
| 84 | #ifndef WIN32 |
---|
| 85 | #include <dlfcn.h> |
---|
| 86 | #include <libgen.h> |
---|
| 87 | #else |
---|
| 88 | #include <windows.h> |
---|
| 89 | #include <direct.h> |
---|
[364] | 90 | #include <sys/types.h> |
---|
| 91 | #include <sys/stat.h> |
---|
| 92 | #include <unistd.h> |
---|
| 93 | #define pid_t int; |
---|
[1] | 94 | #endif |
---|
| 95 | #include <fcntl.h> |
---|
| 96 | #include <time.h> |
---|
| 97 | #include <stdarg.h> |
---|
| 98 | |
---|
[364] | 99 | #ifdef WIN32 |
---|
[541] | 100 | extern "C" |
---|
| 101 | { |
---|
| 102 | __declspec (dllexport) char *strcasestr (char const *a, char const *b) |
---|
[370] | 103 | #ifndef USE_MS |
---|
[541] | 104 | { |
---|
| 105 | char *x = zStrdup (a); |
---|
| 106 | char *y = zStrdup (b); |
---|
| 107 | |
---|
| 108 | x = _strlwr (x); |
---|
| 109 | y = _strlwr (y); |
---|
| 110 | char *pos = strstr (x, y); |
---|
| 111 | char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); |
---|
| 112 | free (x); |
---|
| 113 | free (y); |
---|
| 114 | return ret; |
---|
| 115 | }; |
---|
[370] | 116 | #else |
---|
[541] | 117 | ; |
---|
[370] | 118 | #endif |
---|
[364] | 119 | } |
---|
| 120 | #endif |
---|
| 121 | |
---|
[34] | 122 | #define _(String) dgettext ("zoo-kernel",String) |
---|
[376] | 123 | #define __(String) dgettext ("zoo-service",String) |
---|
[34] | 124 | |
---|
[582] | 125 | #ifdef WIN32 |
---|
| 126 | #ifndef PROGRAMNAME |
---|
| 127 | #define PROGRAMNAME "zoo_loader.cgi" |
---|
| 128 | #endif |
---|
| 129 | #endif |
---|
| 130 | |
---|
[541] | 131 | extern int getServiceFromFile (maps *, const char *, service **); |
---|
[34] | 132 | |
---|
[541] | 133 | int |
---|
| 134 | readServiceFile (maps * conf, char *file, service ** service, char *name) |
---|
| 135 | { |
---|
| 136 | int t = getServiceFromFile (conf, file, service); |
---|
[467] | 137 | #ifdef YAML |
---|
[541] | 138 | if (t < 0) |
---|
| 139 | { |
---|
| 140 | t = getServiceFromYAML (conf, file, service, name); |
---|
| 141 | } |
---|
[467] | 142 | #endif |
---|
| 143 | return t; |
---|
| 144 | } |
---|
| 145 | |
---|
[541] | 146 | void |
---|
| 147 | translateChar (char *str, char toReplace, char toReplaceBy) |
---|
| 148 | { |
---|
| 149 | int i = 0, len = strlen (str); |
---|
| 150 | for (i = 0; i < len; i++) |
---|
| 151 | { |
---|
| 152 | if (str[i] == toReplace) |
---|
| 153 | str[i] = toReplaceBy; |
---|
| 154 | } |
---|
[34] | 155 | } |
---|
| 156 | |
---|
[360] | 157 | /** |
---|
| 158 | * Create (or append to) an array valued maps |
---|
| 159 | * value = "["",""]" |
---|
| 160 | */ |
---|
[541] | 161 | int |
---|
| 162 | appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem) |
---|
| 163 | { |
---|
| 164 | maps *tmpMaps = getMaps (mo, mi->name); |
---|
| 165 | map *tmap = getMapType (tmpMaps->content); |
---|
| 166 | elements *el = getElements (elem, mi->name); |
---|
| 167 | int hasEl = 1; |
---|
| 168 | if (el == NULL) |
---|
| 169 | hasEl = -1; |
---|
| 170 | if (tmap == NULL) |
---|
| 171 | { |
---|
| 172 | if (hasEl > 0) |
---|
| 173 | tmap = getMapType (el->defaults->content); |
---|
| 174 | } |
---|
[360] | 175 | |
---|
[541] | 176 | map *testMap = NULL; |
---|
| 177 | if (hasEl > 0) |
---|
| 178 | { |
---|
| 179 | testMap = getMap (el->content, "maxOccurs"); |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | testMap = createMap ("maxOccurs", "unbounded"); |
---|
| 184 | } |
---|
[362] | 185 | |
---|
[541] | 186 | if (testMap != NULL) |
---|
| 187 | { |
---|
| 188 | if (strncasecmp (testMap->value, "unbounded", 9) != 0 |
---|
| 189 | && atoi (testMap->value) > 1) |
---|
| 190 | { |
---|
[550] | 191 | addMapsArrayToMaps (&mo, mi, tmap->name); |
---|
| 192 | map* nb=getMapFromMaps(mo,mi->name,"length"); |
---|
| 193 | if (nb!=NULL && atoi(nb->value)>atoi(testMap->value)) |
---|
[541] | 194 | { |
---|
| 195 | char emsg[1024]; |
---|
| 196 | sprintf (emsg, |
---|
[550] | 197 | _("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."), |
---|
[541] | 198 | mi->name, atoi (testMap->value)); |
---|
| 199 | errorException (m, emsg, "InternalError", NULL); |
---|
| 200 | return -1; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | else |
---|
| 204 | { |
---|
| 205 | if (strncasecmp (testMap->value, "unbounded", 9) == 0) |
---|
| 206 | { |
---|
| 207 | if (hasEl < 0) |
---|
| 208 | { |
---|
| 209 | freeMap (&testMap); |
---|
| 210 | free (testMap); |
---|
| 211 | } |
---|
| 212 | if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0) |
---|
| 213 | { |
---|
| 214 | char emsg[1024]; |
---|
| 215 | map *tmpMap = getMap (mi->content, "length"); |
---|
| 216 | sprintf (emsg, |
---|
| 217 | _ |
---|
| 218 | ("ZOO-Kernel was unable to load your data for %s position %s."), |
---|
| 219 | mi->name, tmpMap->value); |
---|
| 220 | errorException (m, emsg, "InternalError", NULL); |
---|
| 221 | return -1; |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | else |
---|
| 225 | { |
---|
| 226 | char emsg[1024]; |
---|
| 227 | sprintf (emsg, |
---|
| 228 | _ |
---|
| 229 | ("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."), |
---|
| 230 | mi->name); |
---|
| 231 | errorException (m, emsg, "InternalError", NULL); |
---|
| 232 | return -1; |
---|
| 233 | } |
---|
| 234 | } |
---|
[360] | 235 | } |
---|
| 236 | return 0; |
---|
| 237 | } |
---|
| 238 | |
---|
[541] | 239 | int |
---|
| 240 | recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix, |
---|
| 241 | int saved_stdout, int level, void (func) (maps *, xmlNodePtr, |
---|
| 242 | service *)) |
---|
| 243 | { |
---|
[469] | 244 | struct dirent *dp; |
---|
[541] | 245 | int scount = 0; |
---|
[469] | 246 | |
---|
[541] | 247 | if (conf_dir == NULL) |
---|
[469] | 248 | return 1; |
---|
[541] | 249 | DIR *dirp = opendir (conf_dir); |
---|
| 250 | if (dirp == NULL) |
---|
| 251 | { |
---|
| 252 | if (level > 0) |
---|
| 253 | return 1; |
---|
| 254 | else |
---|
| 255 | return -1; |
---|
| 256 | } |
---|
[469] | 257 | char tmp1[25]; |
---|
[541] | 258 | sprintf (tmp1, "sprefix_%d", level); |
---|
[469] | 259 | char levels[17]; |
---|
[541] | 260 | sprintf (levels, "%d", level); |
---|
| 261 | setMapInMaps (m, "lenv", "level", levels); |
---|
| 262 | while ((dp = readdir (dirp)) != NULL) |
---|
| 263 | if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.' |
---|
| 264 | && strstr (dp->d_name, ".") == NULL) |
---|
| 265 | { |
---|
[469] | 266 | |
---|
[541] | 267 | char *tmp = |
---|
| 268 | (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) * |
---|
| 269 | sizeof (char)); |
---|
| 270 | sprintf (tmp, "%s/%s", conf_dir, dp->d_name); |
---|
[469] | 271 | |
---|
[541] | 272 | if (prefix != NULL) |
---|
| 273 | { |
---|
| 274 | prefix = NULL; |
---|
| 275 | } |
---|
| 276 | prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char)); |
---|
| 277 | sprintf (prefix, "%s.", dp->d_name); |
---|
| 278 | |
---|
| 279 | //map* tmpMap=getMapFromMaps(m,"lenv",tmp1); |
---|
| 280 | |
---|
| 281 | int res; |
---|
| 282 | if (prefix != NULL) |
---|
| 283 | { |
---|
| 284 | setMapInMaps (m, "lenv", tmp1, prefix); |
---|
| 285 | char levels1[17]; |
---|
| 286 | sprintf (levels1, "%d", level + 1); |
---|
| 287 | setMapInMaps (m, "lenv", "level", levels1); |
---|
| 288 | res = |
---|
| 289 | recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1, |
---|
| 290 | func); |
---|
| 291 | sprintf (levels1, "%d", level); |
---|
| 292 | setMapInMaps (m, "lenv", "level", levels1); |
---|
| 293 | free (prefix); |
---|
| 294 | prefix = NULL; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | res = -1; |
---|
| 298 | free (tmp); |
---|
| 299 | if (res < 0) |
---|
| 300 | { |
---|
| 301 | return res; |
---|
| 302 | } |
---|
[469] | 303 | } |
---|
[541] | 304 | else |
---|
| 305 | { |
---|
[557] | 306 | char* extn = strstr(dp->d_name, ".zcfg"); |
---|
| 307 | if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5) |
---|
[541] | 308 | { |
---|
| 309 | int t; |
---|
| 310 | char tmps1[1024]; |
---|
| 311 | memset (tmps1, 0, 1024); |
---|
| 312 | snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name); |
---|
| 313 | service *s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 314 | if (s1 == NULL) |
---|
| 315 | { |
---|
| 316 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 317 | errorException (m, _("Unable to allocate memory."), |
---|
| 318 | "InternalError", NULL); |
---|
| 319 | return -1; |
---|
| 320 | } |
---|
[469] | 321 | #ifdef DEBUG |
---|
[541] | 322 | fprintf (stderr, "#################\n%s\n#################\n", |
---|
| 323 | tmps1); |
---|
[469] | 324 | #endif |
---|
[541] | 325 | char *tmpsn = zStrdup (dp->d_name); |
---|
| 326 | tmpsn[strlen (tmpsn) - 5] = 0; |
---|
| 327 | t = readServiceFile (m, tmps1, &s1, tmpsn); |
---|
| 328 | free (tmpsn); |
---|
| 329 | if (t < 0) |
---|
| 330 | { |
---|
| 331 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 332 | char tmp01[1024]; |
---|
| 333 | if (tmp00 != NULL) |
---|
| 334 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 335 | dp->d_name, tmp00->value); |
---|
| 336 | else |
---|
| 337 | sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), |
---|
| 338 | dp->d_name); |
---|
| 339 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 340 | errorException (m, tmp01, "InternalError", NULL); |
---|
| 341 | return -1; |
---|
| 342 | } |
---|
[469] | 343 | #ifdef DEBUG |
---|
[541] | 344 | dumpService (s1); |
---|
| 345 | fflush (stdout); |
---|
| 346 | fflush (stderr); |
---|
[469] | 347 | #endif |
---|
[541] | 348 | func (m, n, s1); |
---|
| 349 | freeService (&s1); |
---|
| 350 | free (s1); |
---|
| 351 | scount++; |
---|
| 352 | } |
---|
[469] | 353 | } |
---|
[541] | 354 | (void) closedir (dirp); |
---|
[469] | 355 | return 1; |
---|
| 356 | } |
---|
| 357 | |
---|
[541] | 358 | xmlXPathObjectPtr |
---|
| 359 | extractFromDoc (xmlDocPtr doc, const char *search) |
---|
| 360 | { |
---|
[1] | 361 | xmlXPathContextPtr xpathCtx; |
---|
| 362 | xmlXPathObjectPtr xpathObj; |
---|
[541] | 363 | xpathCtx = xmlXPathNewContext (doc); |
---|
| 364 | xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx); |
---|
| 365 | xmlXPathFreeContext (xpathCtx); |
---|
[9] | 366 | return xpathObj; |
---|
[1] | 367 | } |
---|
| 368 | |
---|
[541] | 369 | void |
---|
| 370 | donothing (int sig) |
---|
| 371 | { |
---|
[478] | 372 | #ifdef DEBUG |
---|
[541] | 373 | fprintf (stderr, "Signal %d after the ZOO-Kernel returned result !\n", sig); |
---|
[478] | 374 | #endif |
---|
[541] | 375 | exit (0); |
---|
[105] | 376 | } |
---|
| 377 | |
---|
[541] | 378 | void |
---|
| 379 | sig_handler (int sig) |
---|
| 380 | { |
---|
[9] | 381 | char tmp[100]; |
---|
[114] | 382 | const char *ssig; |
---|
[541] | 383 | switch (sig) |
---|
| 384 | { |
---|
| 385 | case SIGSEGV: |
---|
| 386 | ssig = "SIGSEGV"; |
---|
| 387 | break; |
---|
| 388 | case SIGTERM: |
---|
| 389 | ssig = "SIGTERM"; |
---|
| 390 | break; |
---|
| 391 | case SIGINT: |
---|
| 392 | ssig = "SIGINT"; |
---|
| 393 | break; |
---|
| 394 | case SIGILL: |
---|
| 395 | ssig = "SIGILL"; |
---|
| 396 | break; |
---|
| 397 | case SIGFPE: |
---|
| 398 | ssig = "SIGFPE"; |
---|
| 399 | break; |
---|
| 400 | case SIGABRT: |
---|
| 401 | ssig = "SIGABRT"; |
---|
| 402 | break; |
---|
| 403 | default: |
---|
| 404 | ssig = "UNKNOWN"; |
---|
| 405 | break; |
---|
| 406 | } |
---|
| 407 | sprintf (tmp, |
---|
| 408 | _ |
---|
| 409 | ("ZOO Kernel failed to process your request receiving signal %d = %s"), |
---|
| 410 | sig, ssig); |
---|
| 411 | errorException (NULL, tmp, "InternalError", NULL); |
---|
[10] | 412 | #ifdef DEBUG |
---|
[541] | 413 | fprintf (stderr, "Not this time!\n"); |
---|
[10] | 414 | #endif |
---|
[541] | 415 | exit (0); |
---|
[1] | 416 | } |
---|
| 417 | |
---|
[541] | 418 | void |
---|
| 419 | loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, |
---|
| 420 | maps ** inputs, maps ** ioutputs, int *eres) |
---|
| 421 | { |
---|
[34] | 422 | char tmps1[1024]; |
---|
| 423 | char ntmp[1024]; |
---|
[541] | 424 | maps *m = *myMap; |
---|
| 425 | maps *request_output_real_format = *ioutputs; |
---|
| 426 | maps *request_input_real_format = *inputs; |
---|
[34] | 427 | /** |
---|
| 428 | * Extract serviceType to know what kind of service should be loaded |
---|
| 429 | */ |
---|
[541] | 430 | map *r_inputs = NULL; |
---|
[34] | 431 | #ifndef WIN32 |
---|
[541] | 432 | getcwd (ntmp, 1024); |
---|
[34] | 433 | #else |
---|
[541] | 434 | _getcwd (ntmp, 1024); |
---|
[34] | 435 | #endif |
---|
[541] | 436 | r_inputs = getMap (s1->content, "serviceType"); |
---|
[34] | 437 | #ifdef DEBUG |
---|
[541] | 438 | fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value); |
---|
| 439 | fflush (stderr); |
---|
[34] | 440 | #endif |
---|
[541] | 441 | if (strlen (r_inputs->value) == 1 |
---|
| 442 | && strncasecmp (r_inputs->value, "C", 1) == 0) |
---|
| 443 | { |
---|
| 444 | r_inputs = getMap (request_inputs, "metapath"); |
---|
| 445 | if (r_inputs != NULL) |
---|
| 446 | sprintf (tmps1, "%s/%s", ntmp, r_inputs->value); |
---|
| 447 | else |
---|
| 448 | sprintf (tmps1, "%s/", ntmp); |
---|
| 449 | char *altPath = zStrdup (tmps1); |
---|
| 450 | r_inputs = getMap (s1->content, "ServiceProvider"); |
---|
| 451 | sprintf (tmps1, "%s/%s", altPath, r_inputs->value); |
---|
| 452 | free (altPath); |
---|
[34] | 453 | #ifdef DEBUG |
---|
[541] | 454 | fprintf (stderr, "Trying to load %s\n", tmps1); |
---|
[34] | 455 | #endif |
---|
| 456 | #ifdef WIN32 |
---|
[541] | 457 | HINSTANCE so = |
---|
| 458 | LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); |
---|
[34] | 459 | #else |
---|
[541] | 460 | void *so = dlopen (tmps1, RTLD_LAZY); |
---|
[34] | 461 | #endif |
---|
[57] | 462 | #ifdef WIN32 |
---|
[578] | 463 | char* errstr = getLastErrorMessage(); |
---|
[34] | 464 | #else |
---|
[541] | 465 | char *errstr; |
---|
| 466 | errstr = dlerror (); |
---|
[34] | 467 | #endif |
---|
[478] | 468 | #ifdef DEBUG |
---|
[578] | 469 | fprintf (stderr, "%s loaded (%s) \n", tmps1, errstr); |
---|
[478] | 470 | #endif |
---|
[541] | 471 | if (so != NULL) |
---|
| 472 | { |
---|
[34] | 473 | #ifdef DEBUG |
---|
[541] | 474 | fprintf (stderr, "Library loaded %s \n", errstr); |
---|
| 475 | fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value); |
---|
[34] | 476 | #endif |
---|
[541] | 477 | r_inputs = getMap (s1->content, "serviceType"); |
---|
[34] | 478 | #ifdef DEBUG |
---|
[541] | 479 | dumpMap (r_inputs); |
---|
| 480 | fprintf (stderr, "%s\n", r_inputs->value); |
---|
| 481 | fflush (stderr); |
---|
[34] | 482 | #endif |
---|
[541] | 483 | if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0) |
---|
| 484 | { |
---|
| 485 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
| 486 | char fname[1024]; |
---|
| 487 | sprintf (fname, "%s_", r_inputs->value); |
---|
[34] | 488 | #ifdef DEBUG |
---|
[541] | 489 | fprintf (stderr, "Try to load function %s\n", fname); |
---|
[34] | 490 | #endif |
---|
| 491 | #ifdef WIN32 |
---|
[541] | 492 | typedef int (CALLBACK * execute_t) (char ***, char ***, |
---|
| 493 | char ***); |
---|
| 494 | execute_t execute = (execute_t) GetProcAddress (so, fname); |
---|
[34] | 495 | #else |
---|
[541] | 496 | typedef int (*execute_t) (char ***, char ***, char ***); |
---|
| 497 | execute_t execute = (execute_t) dlsym (so, fname); |
---|
[34] | 498 | #endif |
---|
| 499 | #ifdef DEBUG |
---|
| 500 | #ifdef WIN32 |
---|
[578] | 501 | errstr = getLastErrorMessage(); |
---|
[34] | 502 | #else |
---|
[541] | 503 | errstr = dlerror (); |
---|
[34] | 504 | #endif |
---|
[541] | 505 | fprintf (stderr, "Function loaded %s\n", errstr); |
---|
| 506 | #endif |
---|
[34] | 507 | |
---|
[541] | 508 | char main_conf[10][30][1024]; |
---|
| 509 | char inputs[10][30][1024]; |
---|
| 510 | char outputs[10][30][1024]; |
---|
| 511 | for (int i = 0; i < 10; i++) |
---|
| 512 | { |
---|
| 513 | for (int j = 0; j < 30; j++) |
---|
| 514 | { |
---|
| 515 | memset (main_conf[i][j], 0, 1024); |
---|
| 516 | memset (inputs[i][j], 0, 1024); |
---|
| 517 | memset (outputs[i][j], 0, 1024); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | mapsToCharXXX (m, (char ***) main_conf); |
---|
| 521 | mapsToCharXXX (request_input_real_format, (char ***) inputs); |
---|
| 522 | mapsToCharXXX (request_output_real_format, (char ***) outputs); |
---|
| 523 | *eres = |
---|
| 524 | execute ((char ***) &main_conf[0], (char ***) &inputs[0], |
---|
| 525 | (char ***) &outputs[0]); |
---|
[34] | 526 | #ifdef DEBUG |
---|
[541] | 527 | fprintf (stderr, "Function run successfully \n"); |
---|
[34] | 528 | #endif |
---|
[541] | 529 | charxxxToMaps ((char ***) &outputs[0], |
---|
| 530 | &request_output_real_format); |
---|
| 531 | } |
---|
| 532 | else |
---|
| 533 | { |
---|
[34] | 534 | #ifdef DEBUG |
---|
| 535 | #ifdef WIN32 |
---|
[578] | 536 | errstr = getLastErrorMessage(); |
---|
| 537 | fprintf (stderr, "Function %s failed to load because of %s\n", |
---|
[541] | 538 | r_inputs->value, errstr); |
---|
[34] | 539 | #endif |
---|
| 540 | #endif |
---|
[541] | 541 | r_inputs = getMapFromMaps (m, "lenv", "Identifier"); |
---|
[34] | 542 | #ifdef DEBUG |
---|
[541] | 543 | fprintf (stderr, "Try to load function %s\n", r_inputs->value); |
---|
[34] | 544 | #endif |
---|
[541] | 545 | typedef int (*execute_t) (maps **, maps **, maps **); |
---|
[34] | 546 | #ifdef WIN32 |
---|
[541] | 547 | execute_t execute = |
---|
| 548 | (execute_t) GetProcAddress (so, r_inputs->value); |
---|
[34] | 549 | #else |
---|
[541] | 550 | execute_t execute = (execute_t) dlsym (so, r_inputs->value); |
---|
[34] | 551 | #endif |
---|
| 552 | |
---|
[541] | 553 | if (execute == NULL) |
---|
| 554 | { |
---|
[469] | 555 | #ifdef WIN32 |
---|
[578] | 556 | errstr = getLastErrorMessage(); |
---|
[469] | 557 | #else |
---|
[541] | 558 | errstr = dlerror (); |
---|
[469] | 559 | #endif |
---|
[541] | 560 | char *tmpMsg = |
---|
| 561 | (char *) malloc (2048 + strlen (r_inputs->value)); |
---|
| 562 | sprintf (tmpMsg, |
---|
| 563 | _ |
---|
| 564 | ("Error occured while running the %s function: %s"), |
---|
| 565 | r_inputs->value, errstr); |
---|
| 566 | errorException (m, tmpMsg, "InternalError", NULL); |
---|
| 567 | free (tmpMsg); |
---|
[478] | 568 | #ifdef DEBUG |
---|
[541] | 569 | fprintf (stderr, "Function %s error %s\n", r_inputs->value, |
---|
| 570 | errstr); |
---|
[478] | 571 | #endif |
---|
[541] | 572 | *eres = -1; |
---|
| 573 | return; |
---|
| 574 | } |
---|
[469] | 575 | |
---|
[34] | 576 | #ifdef DEBUG |
---|
| 577 | #ifdef WIN32 |
---|
[578] | 578 | errstr = getLastErrorMessage(); |
---|
[34] | 579 | #else |
---|
[541] | 580 | errstr = dlerror (); |
---|
[34] | 581 | #endif |
---|
[541] | 582 | fprintf (stderr, "Function loaded %s\n", errstr); |
---|
| 583 | #endif |
---|
[34] | 584 | |
---|
| 585 | #ifdef DEBUG |
---|
[541] | 586 | fprintf (stderr, "Now run the function \n"); |
---|
| 587 | fflush (stderr); |
---|
[34] | 588 | #endif |
---|
[541] | 589 | *eres = |
---|
| 590 | execute (&m, &request_input_real_format, |
---|
| 591 | &request_output_real_format); |
---|
[34] | 592 | #ifdef DEBUG |
---|
[541] | 593 | fprintf (stderr, "Function loaded and returned %d\n", eres); |
---|
| 594 | fflush (stderr); |
---|
[34] | 595 | #endif |
---|
[541] | 596 | } |
---|
[216] | 597 | #ifdef WIN32 |
---|
[541] | 598 | *ioutputs = dupMaps (&request_output_real_format); |
---|
| 599 | FreeLibrary (so); |
---|
[216] | 600 | #else |
---|
[541] | 601 | dlclose (so); |
---|
[216] | 602 | #endif |
---|
[541] | 603 | } |
---|
| 604 | else |
---|
| 605 | { |
---|
[34] | 606 | /** |
---|
| 607 | * Unable to load the specified shared library |
---|
| 608 | */ |
---|
[541] | 609 | char tmps[1024]; |
---|
[34] | 610 | #ifdef WIN32 |
---|
[578] | 611 | errstr = getLastErrorMessage(); |
---|
[34] | 612 | #else |
---|
[578] | 613 | errstr = dlerror (); |
---|
[34] | 614 | #endif |
---|
[541] | 615 | sprintf (tmps, _("C Library can't be loaded %s"), errstr); |
---|
[576] | 616 | errorException(m,tmps,"InternalError",NULL); |
---|
[541] | 617 | *eres = -1; |
---|
| 618 | } |
---|
[34] | 619 | } |
---|
| 620 | else |
---|
[550] | 621 | |
---|
| 622 | #ifdef USE_OTB |
---|
| 623 | if (strncasecmp (r_inputs->value, "OTB", 6) == 0) |
---|
| 624 | { |
---|
| 625 | *eres = |
---|
| 626 | zoo_otb_support (&m, request_inputs, s1, |
---|
| 627 | &request_input_real_format, |
---|
| 628 | &request_output_real_format); |
---|
| 629 | } |
---|
| 630 | else |
---|
| 631 | #endif |
---|
| 632 | |
---|
[34] | 633 | #ifdef USE_PYTHON |
---|
[541] | 634 | if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0) |
---|
| 635 | { |
---|
| 636 | *eres = |
---|
| 637 | zoo_python_support (&m, request_inputs, s1, |
---|
| 638 | &request_input_real_format, |
---|
| 639 | &request_output_real_format); |
---|
[34] | 640 | } |
---|
[541] | 641 | else |
---|
[34] | 642 | #endif |
---|
[541] | 643 | |
---|
[34] | 644 | #ifdef USE_JAVA |
---|
[541] | 645 | if (strncasecmp (r_inputs->value, "JAVA", 4) == 0) |
---|
| 646 | { |
---|
| 647 | *eres = |
---|
| 648 | zoo_java_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 649 | &request_output_real_format); |
---|
| 650 | } |
---|
| 651 | else |
---|
[34] | 652 | #endif |
---|
| 653 | |
---|
| 654 | #ifdef USE_PHP |
---|
[541] | 655 | if (strncasecmp (r_inputs->value, "PHP", 3) == 0) |
---|
| 656 | { |
---|
| 657 | *eres = |
---|
| 658 | zoo_php_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 659 | &request_output_real_format); |
---|
| 660 | } |
---|
| 661 | else |
---|
[34] | 662 | #endif |
---|
[541] | 663 | |
---|
| 664 | |
---|
[34] | 665 | #ifdef USE_PERL |
---|
[541] | 666 | if (strncasecmp (r_inputs->value, "PERL", 4) == 0) |
---|
| 667 | { |
---|
| 668 | *eres = |
---|
| 669 | zoo_perl_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 670 | &request_output_real_format); |
---|
| 671 | } |
---|
| 672 | else |
---|
[34] | 673 | #endif |
---|
| 674 | |
---|
| 675 | #ifdef USE_JS |
---|
[541] | 676 | if (strncasecmp (r_inputs->value, "JS", 2) == 0) |
---|
| 677 | { |
---|
| 678 | *eres = |
---|
| 679 | zoo_js_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 680 | &request_output_real_format); |
---|
| 681 | } |
---|
| 682 | else |
---|
[34] | 683 | #endif |
---|
[453] | 684 | |
---|
| 685 | #ifdef USE_RUBY |
---|
[541] | 686 | if (strncasecmp (r_inputs->value, "Ruby", 4) == 0) |
---|
| 687 | { |
---|
| 688 | *eres = |
---|
| 689 | zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format, |
---|
| 690 | &request_output_real_format); |
---|
| 691 | } |
---|
| 692 | else |
---|
[453] | 693 | #endif |
---|
| 694 | |
---|
[541] | 695 | { |
---|
| 696 | char tmpv[1024]; |
---|
| 697 | sprintf (tmpv, |
---|
| 698 | _ |
---|
| 699 | ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"), |
---|
| 700 | r_inputs->value); |
---|
[576] | 701 | errorException (m, tmpv, "InternalError", NULL); |
---|
[541] | 702 | *eres = -1; |
---|
| 703 | } |
---|
| 704 | *myMap = m; |
---|
| 705 | *ioutputs = request_output_real_format; |
---|
[34] | 706 | } |
---|
| 707 | |
---|
[384] | 708 | |
---|
[216] | 709 | #ifdef WIN32 |
---|
| 710 | /** |
---|
| 711 | * createProcess function: create a new process after setting some env variables |
---|
| 712 | */ |
---|
[541] | 713 | void |
---|
| 714 | createProcess (maps * m, map * request_inputs, service * s1, char *opts, |
---|
| 715 | int cpid, maps * inputs, maps * outputs) |
---|
| 716 | { |
---|
[216] | 717 | STARTUPINFO si; |
---|
| 718 | PROCESS_INFORMATION pi; |
---|
[541] | 719 | ZeroMemory (&si, sizeof (si)); |
---|
| 720 | si.cb = sizeof (si); |
---|
| 721 | ZeroMemory (&pi, sizeof (pi)); |
---|
| 722 | char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); |
---|
| 723 | char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char)); |
---|
| 724 | map *req = getMap (request_inputs, "request"); |
---|
| 725 | map *id = getMap (request_inputs, "identifier"); |
---|
| 726 | map *di = getMap (request_inputs, "DataInputs"); |
---|
[216] | 727 | |
---|
[541] | 728 | char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength, 0); |
---|
| 729 | char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength, 1); |
---|
[384] | 730 | #ifdef DEBUG |
---|
[541] | 731 | fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP); |
---|
| 732 | fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP); |
---|
[384] | 733 | #endif |
---|
[541] | 734 | map *sid = getMapFromMaps (m, "lenv", "sid"); |
---|
| 735 | map *r_inputs = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 736 | map *r_inputs1 = getMap (request_inputs, "metapath"); |
---|
| 737 | int hasIn = -1; |
---|
| 738 | if (r_inputs1 == NULL) |
---|
| 739 | { |
---|
| 740 | r_inputs1 = createMap ("metapath", ""); |
---|
| 741 | hasIn = 1; |
---|
| 742 | } |
---|
| 743 | map *r_inputs2 = getMap (request_inputs, "ResponseDocument"); |
---|
| 744 | if (r_inputs2 == NULL) |
---|
| 745 | r_inputs2 = getMap (request_inputs, "RawDataOutput"); |
---|
| 746 | map *tmpPath = getMapFromMaps (m, "lenv", "cwd"); |
---|
[216] | 747 | |
---|
[541] | 748 | map *tmpReq = getMap (request_inputs, "xrequest"); |
---|
| 749 | if (r_inputs2 != NULL) |
---|
| 750 | { |
---|
| 751 | sprintf (tmp, |
---|
| 752 | "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"", |
---|
| 753 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
| 754 | r_inputs2->name, dataOutputsKVP, sid->value); |
---|
| 755 | sprintf (tmpq, |
---|
| 756 | "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s", |
---|
| 757 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
| 758 | r_inputs2->name, dataOutputsKVP); |
---|
| 759 | } |
---|
| 760 | else |
---|
| 761 | { |
---|
| 762 | sprintf (tmp, |
---|
| 763 | "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"", |
---|
| 764 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
| 765 | sid->value); |
---|
| 766 | sprintf (tmpq, |
---|
| 767 | "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s", |
---|
| 768 | r_inputs1->value, req->value, id->value, dataInputsKVP, |
---|
| 769 | sid->value); |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | if (hasIn > 0) |
---|
| 773 | { |
---|
| 774 | freeMap (&r_inputs1); |
---|
| 775 | free (r_inputs1); |
---|
| 776 | } |
---|
| 777 | char *tmp1 = zStrdup (tmp); |
---|
[582] | 778 | sprintf (tmp, "\"%s\" %s \"%s\"", PROGRAMNAME, tmp1, sid->value); |
---|
[541] | 779 | free (dataInputsKVP); |
---|
| 780 | free (dataOutputsKVP); |
---|
[384] | 781 | #ifdef DEBUG |
---|
[541] | 782 | fprintf (stderr, "REQUEST IS : %s \n", tmp); |
---|
[384] | 783 | #endif |
---|
[554] | 784 | |
---|
| 785 | map* usid = getMapFromMaps (m, "lenv", "usid"); |
---|
| 786 | if (usid != NULL && usid->value != NULL) { |
---|
| 787 | SetEnvironmentVariable("USID", TEXT (usid->value)); |
---|
| 788 | } |
---|
| 789 | |
---|
[541] | 790 | SetEnvironmentVariable ("CGISID", TEXT (sid->value)); |
---|
| 791 | SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq)); |
---|
[216] | 792 | char clen[1000]; |
---|
[541] | 793 | sprintf (clen, "%d", strlen (tmpq)); |
---|
| 794 | SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen)); |
---|
| 795 | |
---|
| 796 | if (!CreateProcess (NULL, // No module name (use command line) |
---|
| 797 | TEXT (tmp), // Command line |
---|
| 798 | NULL, // Process handle not inheritable |
---|
| 799 | NULL, // Thread handle not inheritable |
---|
| 800 | FALSE, // Set handle inheritance to FALSE |
---|
| 801 | CREATE_NO_WINDOW, // Apache won't wait until the end |
---|
| 802 | NULL, // Use parent's environment block |
---|
| 803 | NULL, // Use parent's starting directory |
---|
| 804 | &si, // Pointer to STARTUPINFO struct |
---|
| 805 | &pi) // Pointer to PROCESS_INFORMATION struct |
---|
| 806 | ) |
---|
| 807 | { |
---|
[384] | 808 | #ifdef DEBUG |
---|
[541] | 809 | fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ()); |
---|
[384] | 810 | #endif |
---|
[541] | 811 | return; |
---|
| 812 | } |
---|
| 813 | else |
---|
| 814 | { |
---|
[384] | 815 | #ifdef DEBUG |
---|
[541] | 816 | fprintf (stderr, "CreateProcess successfull (%d).\n\n\n\n", |
---|
| 817 | GetLastError ()); |
---|
[384] | 818 | #endif |
---|
[541] | 819 | } |
---|
| 820 | CloseHandle (pi.hProcess); |
---|
| 821 | CloseHandle (pi.hThread); |
---|
[384] | 822 | #ifdef DEBUG |
---|
[541] | 823 | fprintf (stderr, "CreateProcess finished !\n"); |
---|
[384] | 824 | #endif |
---|
[216] | 825 | } |
---|
| 826 | #endif |
---|
| 827 | |
---|
[541] | 828 | int |
---|
| 829 | runRequest (map ** inputs) |
---|
[1] | 830 | { |
---|
[541] | 831 | |
---|
[53] | 832 | #ifndef USE_GDB |
---|
[554] | 833 | #ifndef WIN32 |
---|
[541] | 834 | signal (SIGCHLD, SIG_IGN); |
---|
[554] | 835 | #endif |
---|
[541] | 836 | signal (SIGSEGV, sig_handler); |
---|
| 837 | signal (SIGTERM, sig_handler); |
---|
| 838 | signal (SIGINT, sig_handler); |
---|
| 839 | signal (SIGILL, sig_handler); |
---|
| 840 | signal (SIGFPE, sig_handler); |
---|
| 841 | signal (SIGABRT, sig_handler); |
---|
[53] | 842 | #endif |
---|
[9] | 843 | |
---|
[541] | 844 | map *r_inputs = NULL; |
---|
| 845 | map *request_inputs = *inputs; |
---|
| 846 | maps *m = NULL; |
---|
| 847 | char *REQUEST = NULL; |
---|
[1] | 848 | /** |
---|
| 849 | * Parsing service specfic configuration file |
---|
| 850 | */ |
---|
[541] | 851 | m = (maps *) malloc (MAPS_SIZE); |
---|
| 852 | if (m == NULL) |
---|
| 853 | { |
---|
| 854 | return errorException (m, _("Unable to allocate memory."), |
---|
| 855 | "InternalError", NULL); |
---|
| 856 | } |
---|
[1] | 857 | char ntmp[1024]; |
---|
| 858 | #ifndef WIN32 |
---|
[541] | 859 | getcwd (ntmp, 1024); |
---|
[1] | 860 | #else |
---|
[541] | 861 | _getcwd (ntmp, 1024); |
---|
[1] | 862 | #endif |
---|
[541] | 863 | r_inputs = getMapOrFill (&request_inputs, "metapath", ""); |
---|
[282] | 864 | |
---|
[381] | 865 | |
---|
[9] | 866 | char conf_file[10240]; |
---|
[541] | 867 | snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); |
---|
| 868 | if (conf_read (conf_file, m) == 2) |
---|
| 869 | { |
---|
| 870 | errorException (NULL, _("Unable to load the main.cfg file."), |
---|
| 871 | "InternalError", NULL); |
---|
| 872 | free (m); |
---|
| 873 | return 1; |
---|
| 874 | } |
---|
[9] | 875 | #ifdef DEBUG |
---|
[541] | 876 | fprintf (stderr, "***** BEGIN MAPS\n"); |
---|
| 877 | dumpMaps (m); |
---|
| 878 | fprintf (stderr, "***** END MAPS\n"); |
---|
[9] | 879 | #endif |
---|
| 880 | |
---|
[541] | 881 | map *getPath = getMapFromMaps (m, "main", "gettextPath"); |
---|
| 882 | if (getPath != NULL) |
---|
| 883 | { |
---|
| 884 | bindtextdomain ("zoo-kernel", getPath->value); |
---|
| 885 | bindtextdomain ("zoo-services", getPath->value); |
---|
| 886 | } |
---|
| 887 | else |
---|
| 888 | { |
---|
| 889 | bindtextdomain ("zoo-kernel", "/usr/share/locale/"); |
---|
| 890 | bindtextdomain ("zoo-services", "/usr/share/locale/"); |
---|
| 891 | } |
---|
[364] | 892 | |
---|
[381] | 893 | |
---|
[364] | 894 | /** |
---|
| 895 | * Manage our own error log file (usefull to separate standard apache debug |
---|
| 896 | * messages from the ZOO-Kernel ones but also for IIS users to avoid wrong |
---|
| 897 | * headers messages returned by the CGI due to wrong redirection of stderr) |
---|
| 898 | */ |
---|
[541] | 899 | FILE *fstde = NULL; |
---|
| 900 | map *fstdem = getMapFromMaps (m, "main", "logPath"); |
---|
| 901 | if (fstdem != NULL) |
---|
| 902 | fstde = freopen (fstdem->value, "a+", stderr); |
---|
[364] | 903 | |
---|
[541] | 904 | r_inputs = getMap (request_inputs, "language"); |
---|
| 905 | if (r_inputs == NULL) |
---|
| 906 | r_inputs = getMapFromMaps (m, "main", "language"); |
---|
| 907 | if (r_inputs != NULL) |
---|
| 908 | { |
---|
| 909 | if (isValidLang (m, r_inputs->value) < 0) |
---|
| 910 | { |
---|
| 911 | char tmp[1024]; |
---|
| 912 | sprintf (tmp, |
---|
| 913 | _ |
---|
| 914 | ("The value %s is not supported for the <language> parameter"), |
---|
| 915 | r_inputs->value); |
---|
| 916 | errorException (m, tmp, "InvalidParameterValue", "language"); |
---|
| 917 | freeMaps (&m); |
---|
| 918 | free (m); |
---|
| 919 | free (REQUEST); |
---|
| 920 | return 1; |
---|
[501] | 921 | |
---|
[541] | 922 | } |
---|
| 923 | char *tmp = zStrdup (r_inputs->value); |
---|
| 924 | setMapInMaps (m, "main", "language", tmp); |
---|
[466] | 925 | #ifdef DEB |
---|
[541] | 926 | char tmp2[12]; |
---|
| 927 | sprintf (tmp2, "%s.utf-8", tmp); |
---|
| 928 | translateChar (tmp2, '-', '_'); |
---|
| 929 | setlocale (LC_ALL, tmp2); |
---|
[466] | 930 | #else |
---|
[541] | 931 | translateChar (tmp, '-', '_'); |
---|
| 932 | setlocale (LC_ALL, tmp); |
---|
[466] | 933 | #endif |
---|
[444] | 934 | #ifndef WIN32 |
---|
[541] | 935 | setenv ("LC_ALL", tmp, 1); |
---|
[444] | 936 | #else |
---|
[541] | 937 | char tmp1[12]; |
---|
| 938 | sprintf (tmp1, "LC_ALL=%s", tmp); |
---|
| 939 | putenv (tmp1); |
---|
[376] | 940 | #endif |
---|
[541] | 941 | free (tmp); |
---|
| 942 | } |
---|
| 943 | else |
---|
| 944 | { |
---|
| 945 | setlocale (LC_ALL, "en_US"); |
---|
[444] | 946 | #ifndef WIN32 |
---|
[541] | 947 | setenv ("LC_ALL", "en_US", 1); |
---|
[444] | 948 | #else |
---|
[541] | 949 | char tmp1[12]; |
---|
| 950 | sprintf (tmp1, "LC_ALL=en_US"); |
---|
| 951 | putenv (tmp1); |
---|
[376] | 952 | #endif |
---|
[541] | 953 | setMapInMaps (m, "main", "language", "en-US"); |
---|
| 954 | } |
---|
[34] | 955 | setlocale (LC_NUMERIC, "en_US"); |
---|
[541] | 956 | bind_textdomain_codeset ("zoo-kernel", "UTF-8"); |
---|
| 957 | textdomain ("zoo-kernel"); |
---|
| 958 | bind_textdomain_codeset ("zoo-services", "UTF-8"); |
---|
| 959 | textdomain ("zoo-services"); |
---|
[34] | 960 | |
---|
[541] | 961 | map *lsoap = getMap (request_inputs, "soap"); |
---|
| 962 | if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0) |
---|
| 963 | setMapInMaps (m, "main", "isSoap", "true"); |
---|
[280] | 964 | else |
---|
[541] | 965 | setMapInMaps (m, "main", "isSoap", "false"); |
---|
[34] | 966 | |
---|
[541] | 967 | if (strlen (cgiServerName) > 0) |
---|
| 968 | { |
---|
| 969 | char tmpUrl[1024]; |
---|
| 970 | if (strncmp (cgiServerPort, "80", 2) == 0) |
---|
| 971 | { |
---|
| 972 | sprintf (tmpUrl, "http://%s%s", cgiServerName, cgiScriptName); |
---|
| 973 | } |
---|
| 974 | else |
---|
| 975 | { |
---|
| 976 | sprintf (tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, |
---|
| 977 | cgiScriptName); |
---|
| 978 | } |
---|
[445] | 979 | #ifdef DEBUG |
---|
[541] | 980 | fprintf (stderr, "*** %s ***\n", tmpUrl); |
---|
[445] | 981 | #endif |
---|
[541] | 982 | setMapInMaps (m, "main", "serverAddress", tmpUrl); |
---|
| 983 | } |
---|
[381] | 984 | |
---|
[1] | 985 | /** |
---|
| 986 | * Check for minimum inputs |
---|
| 987 | */ |
---|
[576] | 988 | map* err=NULL; |
---|
| 989 | const char *vvr[]={ |
---|
| 990 | "GetCapabilities", |
---|
| 991 | "DescribeProcess", |
---|
| 992 | "Execute", |
---|
| 993 | NULL |
---|
| 994 | }; |
---|
| 995 | checkValidValue(request_inputs,&err,"Request",(const char**)vvr,1); |
---|
| 996 | const char *vvs[]={ |
---|
| 997 | "WPS", |
---|
| 998 | NULL |
---|
| 999 | }; |
---|
| 1000 | if(err!=NULL){ |
---|
| 1001 | checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); |
---|
| 1002 | printExceptionReportResponse (m, err); |
---|
| 1003 | freeMap(&err); |
---|
| 1004 | free(err); |
---|
| 1005 | if (count (request_inputs) == 1) |
---|
| 1006 | { |
---|
| 1007 | freeMap (&request_inputs); |
---|
| 1008 | free (request_inputs); |
---|
| 1009 | } |
---|
| 1010 | freeMaps (&m); |
---|
| 1011 | free (m); |
---|
| 1012 | return 1; |
---|
| 1013 | } |
---|
| 1014 | checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); |
---|
| 1015 | const char *vvv[]={ |
---|
| 1016 | "1.0.0", |
---|
| 1017 | NULL |
---|
| 1018 | }; |
---|
[541] | 1019 | r_inputs = getMap (request_inputs, "Request"); |
---|
[576] | 1020 | REQUEST = zStrdup (r_inputs->value); |
---|
| 1021 | if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ |
---|
| 1022 | checkValidValue(request_inputs,&err,"version",(const char**)vvv,1); |
---|
| 1023 | checkValidValue(request_inputs,&err,"identifier",NULL,1); |
---|
| 1024 | }else{ |
---|
| 1025 | checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1); |
---|
| 1026 | } |
---|
| 1027 | if(err!=NULL){ |
---|
| 1028 | printExceptionReportResponse (m, err); |
---|
| 1029 | freeMap(&err); |
---|
| 1030 | free(err); |
---|
| 1031 | if (count (request_inputs) == 1) |
---|
| 1032 | { |
---|
| 1033 | freeMap (&request_inputs); |
---|
| 1034 | free (request_inputs); |
---|
| 1035 | } |
---|
| 1036 | free(REQUEST); |
---|
| 1037 | freeMaps (&m); |
---|
| 1038 | free (m); |
---|
| 1039 | return 1; |
---|
| 1040 | } |
---|
[1] | 1041 | |
---|
[541] | 1042 | r_inputs = getMap (request_inputs, "serviceprovider"); |
---|
| 1043 | if (r_inputs == NULL) |
---|
| 1044 | { |
---|
| 1045 | addToMap (request_inputs, "serviceprovider", ""); |
---|
| 1046 | } |
---|
[1] | 1047 | |
---|
[576] | 1048 | |
---|
[541] | 1049 | maps *request_output_real_format = NULL; |
---|
| 1050 | map *tmpm = getMapFromMaps (m, "main", "serverAddress"); |
---|
| 1051 | if (tmpm != NULL) |
---|
| 1052 | SERVICE_URL = zStrdup (tmpm->value); |
---|
[1] | 1053 | else |
---|
[541] | 1054 | SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); |
---|
[1] | 1055 | |
---|
[541] | 1056 | service *s1; |
---|
| 1057 | int scount = 0; |
---|
[1] | 1058 | #ifdef DEBUG |
---|
[541] | 1059 | dumpMap (r_inputs); |
---|
[1] | 1060 | #endif |
---|
| 1061 | char conf_dir[1024]; |
---|
| 1062 | int t; |
---|
| 1063 | char tmps1[1024]; |
---|
| 1064 | |
---|
[541] | 1065 | r_inputs = NULL; |
---|
| 1066 | r_inputs = getMap (request_inputs, "metapath"); |
---|
| 1067 | if (r_inputs != NULL) |
---|
| 1068 | snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value); |
---|
[9] | 1069 | else |
---|
[541] | 1070 | snprintf (conf_dir, 1024, "%s", ntmp); |
---|
[9] | 1071 | |
---|
[541] | 1072 | if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) |
---|
| 1073 | { |
---|
[1] | 1074 | #ifdef DEBUG |
---|
[541] | 1075 | dumpMap (r_inputs); |
---|
[1] | 1076 | #endif |
---|
[541] | 1077 | xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); |
---|
| 1078 | r_inputs = NULL; |
---|
[576] | 1079 | //r_inputs = getMap (request_inputs, "ServiceProvider"); |
---|
| 1080 | xmlNodePtr n=printGetCapabilitiesHeader(doc,m); |
---|
| 1081 | /** |
---|
| 1082 | * Here we need to close stdout to ensure that unsupported chars |
---|
| 1083 | * has been found in the zcfg and then printed on stdout |
---|
| 1084 | */ |
---|
[541] | 1085 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1086 | dup2 (fileno (stderr), fileno (stdout)); |
---|
| 1087 | if (int res = |
---|
| 1088 | recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0, |
---|
| 1089 | printGetCapabilitiesForProcess) < 0) |
---|
| 1090 | { |
---|
| 1091 | freeMaps (&m); |
---|
| 1092 | free (m); |
---|
| 1093 | free (REQUEST); |
---|
| 1094 | free (SERVICE_URL); |
---|
| 1095 | fflush (stdout); |
---|
| 1096 | return res; |
---|
| 1097 | } |
---|
| 1098 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1099 | printDocument (m, doc, getpid ()); |
---|
| 1100 | freeMaps (&m); |
---|
| 1101 | free (m); |
---|
| 1102 | free (REQUEST); |
---|
| 1103 | free (SERVICE_URL); |
---|
| 1104 | fflush (stdout); |
---|
[9] | 1105 | return 0; |
---|
[1] | 1106 | } |
---|
[541] | 1107 | else |
---|
| 1108 | { |
---|
| 1109 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
[1] | 1110 | |
---|
[541] | 1111 | struct dirent *dp; |
---|
| 1112 | DIR *dirp = opendir (conf_dir); |
---|
| 1113 | if (dirp == NULL) |
---|
| 1114 | { |
---|
| 1115 | errorException (m, _("The specified path path doesn't exist."), |
---|
| 1116 | "InvalidParameterValue", conf_dir); |
---|
| 1117 | freeMaps (&m); |
---|
| 1118 | free (m); |
---|
| 1119 | free (REQUEST); |
---|
| 1120 | free (SERVICE_URL); |
---|
| 1121 | return 0; |
---|
| 1122 | } |
---|
| 1123 | if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) |
---|
| 1124 | { |
---|
[576] | 1125 | /** |
---|
| 1126 | * Loop over Identifier list |
---|
| 1127 | */ |
---|
[541] | 1128 | xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); |
---|
| 1129 | r_inputs = NULL; |
---|
[576] | 1130 | xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", |
---|
| 1131 | "ProcessDescriptions"); |
---|
[9] | 1132 | |
---|
[541] | 1133 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
[469] | 1134 | |
---|
[541] | 1135 | char *orig = zStrdup (r_inputs->value); |
---|
[503] | 1136 | |
---|
[541] | 1137 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1138 | dup2 (fileno (stderr), fileno (stdout)); |
---|
| 1139 | if (strcasecmp ("all", orig) == 0) |
---|
| 1140 | { |
---|
| 1141 | if (int res = |
---|
| 1142 | recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0, |
---|
| 1143 | printDescribeProcessForProcess) < 0) |
---|
| 1144 | return res; |
---|
| 1145 | } |
---|
| 1146 | else |
---|
| 1147 | { |
---|
| 1148 | char *saveptr; |
---|
| 1149 | char *tmps = strtok_r (orig, ",", &saveptr); |
---|
| 1150 | |
---|
| 1151 | char buff[256]; |
---|
| 1152 | char buff1[1024]; |
---|
| 1153 | while (tmps != NULL) |
---|
| 1154 | { |
---|
| 1155 | int hasVal = -1; |
---|
| 1156 | char *corig = zStrdup (tmps); |
---|
| 1157 | if (strstr (corig, ".") != NULL) |
---|
| 1158 | { |
---|
| 1159 | |
---|
| 1160 | parseIdentifier (m, conf_dir, corig, buff1); |
---|
| 1161 | map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); |
---|
| 1162 | if (tmpMap != NULL) |
---|
| 1163 | addToMap (request_inputs, "metapath", tmpMap->value); |
---|
| 1164 | map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); |
---|
| 1165 | |
---|
| 1166 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1167 | t = readServiceFile (m, buff1, &s1, tmpMapI->value); |
---|
| 1168 | if (t < 0) |
---|
| 1169 | { |
---|
| 1170 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 1171 | char tmp01[1024]; |
---|
| 1172 | if (tmp00 != NULL) |
---|
| 1173 | sprintf (tmp01, |
---|
| 1174 | _ |
---|
| 1175 | ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"), |
---|
| 1176 | tmps, tmp00->value); |
---|
| 1177 | else |
---|
| 1178 | sprintf (tmp01, |
---|
| 1179 | _ |
---|
| 1180 | ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), |
---|
| 1181 | tmps); |
---|
| 1182 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1183 | errorException (m, tmp01, "InvalidParameterValue", |
---|
| 1184 | "identifier"); |
---|
| 1185 | freeMaps (&m); |
---|
| 1186 | free (m); |
---|
| 1187 | free (REQUEST); |
---|
| 1188 | free (corig); |
---|
| 1189 | free (orig); |
---|
| 1190 | free (SERVICE_URL); |
---|
| 1191 | free (s1); |
---|
| 1192 | closedir (dirp); |
---|
| 1193 | xmlFreeDoc (doc); |
---|
| 1194 | xmlCleanupParser (); |
---|
| 1195 | zooXmlCleanupNs (); |
---|
| 1196 | return 1; |
---|
| 1197 | } |
---|
[9] | 1198 | #ifdef DEBUG |
---|
[541] | 1199 | dumpService (s1); |
---|
[9] | 1200 | #endif |
---|
[541] | 1201 | printDescribeProcessForProcess (m, n, s1); |
---|
| 1202 | freeService (&s1); |
---|
| 1203 | free (s1); |
---|
| 1204 | s1 = NULL; |
---|
| 1205 | scount++; |
---|
| 1206 | hasVal = 1; |
---|
| 1207 | setMapInMaps (m, "lenv", "level", "0"); |
---|
| 1208 | } |
---|
| 1209 | else |
---|
| 1210 | { |
---|
| 1211 | memset (buff, 0, 256); |
---|
| 1212 | snprintf (buff, 256, "%s.zcfg", corig); |
---|
| 1213 | memset (buff1, 0, 1024); |
---|
[469] | 1214 | #ifdef DEBUG |
---|
[541] | 1215 | printf ("\n#######%s\n########\n", buff); |
---|
[469] | 1216 | #endif |
---|
[541] | 1217 | while ((dp = readdir (dirp)) != NULL) |
---|
| 1218 | { |
---|
| 1219 | if (strcasecmp (dp->d_name, buff) == 0) |
---|
| 1220 | { |
---|
| 1221 | memset (buff1, 0, 1024); |
---|
| 1222 | snprintf (buff1, 1024, "%s/%s", conf_dir, |
---|
| 1223 | dp->d_name); |
---|
| 1224 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1225 | if (s1 == NULL) |
---|
| 1226 | { |
---|
| 1227 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1228 | return errorException (m, |
---|
| 1229 | _ |
---|
| 1230 | ("Unable to allocate memory."), |
---|
| 1231 | "InternalError", |
---|
| 1232 | NULL); |
---|
| 1233 | } |
---|
[469] | 1234 | #ifdef DEBUG |
---|
[541] | 1235 | printf |
---|
| 1236 | ("#################\n(%s) %s\n#################\n", |
---|
| 1237 | r_inputs->value, buff1); |
---|
[469] | 1238 | #endif |
---|
[541] | 1239 | char *tmp0 = zStrdup (dp->d_name); |
---|
| 1240 | tmp0[strlen (tmp0) - 5] = 0; |
---|
| 1241 | t = readServiceFile (m, buff1, &s1, tmp0); |
---|
| 1242 | free (tmp0); |
---|
| 1243 | if (t < 0) |
---|
| 1244 | { |
---|
| 1245 | map *tmp00 = |
---|
| 1246 | getMapFromMaps (m, "lenv", "message"); |
---|
| 1247 | char tmp01[1024]; |
---|
| 1248 | if (tmp00 != NULL) |
---|
| 1249 | sprintf (tmp01, |
---|
| 1250 | _ |
---|
| 1251 | ("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 1252 | dp->d_name, tmp00->value); |
---|
| 1253 | else |
---|
| 1254 | sprintf (tmp01, |
---|
| 1255 | _ |
---|
| 1256 | ("Unable to parse the ZCFG file: %s."), |
---|
| 1257 | dp->d_name); |
---|
| 1258 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1259 | errorException (m, tmp01, "InternalError", |
---|
| 1260 | NULL); |
---|
| 1261 | freeMaps (&m); |
---|
| 1262 | free (m); |
---|
| 1263 | free (orig); |
---|
| 1264 | free (REQUEST); |
---|
| 1265 | closedir (dirp); |
---|
| 1266 | xmlFreeDoc (doc); |
---|
| 1267 | xmlCleanupParser (); |
---|
| 1268 | zooXmlCleanupNs (); |
---|
| 1269 | return 1; |
---|
| 1270 | } |
---|
[469] | 1271 | #ifdef DEBUG |
---|
[541] | 1272 | dumpService (s1); |
---|
[469] | 1273 | #endif |
---|
[541] | 1274 | printDescribeProcessForProcess (m, n, s1); |
---|
| 1275 | freeService (&s1); |
---|
| 1276 | free (s1); |
---|
| 1277 | s1 = NULL; |
---|
| 1278 | scount++; |
---|
| 1279 | hasVal = 1; |
---|
| 1280 | } |
---|
| 1281 | } |
---|
| 1282 | } |
---|
| 1283 | if (hasVal < 0) |
---|
| 1284 | { |
---|
| 1285 | map *tmp00 = getMapFromMaps (m, "lenv", "message"); |
---|
| 1286 | char tmp01[1024]; |
---|
| 1287 | if (tmp00 != NULL) |
---|
| 1288 | sprintf (tmp01, |
---|
| 1289 | _("Unable to parse the ZCFG file: %s (%s)"), |
---|
| 1290 | buff, tmp00->value); |
---|
| 1291 | else |
---|
| 1292 | sprintf (tmp01, |
---|
| 1293 | _("Unable to parse the ZCFG file: %s."), |
---|
| 1294 | buff); |
---|
| 1295 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1296 | errorException (m, tmp01, "InvalidParameterValue", |
---|
| 1297 | "Identifier"); |
---|
| 1298 | freeMaps (&m); |
---|
| 1299 | free (m); |
---|
| 1300 | free (orig); |
---|
| 1301 | free (REQUEST); |
---|
| 1302 | closedir (dirp); |
---|
| 1303 | xmlFreeDoc (doc); |
---|
| 1304 | xmlCleanupParser (); |
---|
| 1305 | zooXmlCleanupNs (); |
---|
| 1306 | return 1; |
---|
| 1307 | } |
---|
| 1308 | rewinddir (dirp); |
---|
| 1309 | tmps = strtok_r (NULL, ",", &saveptr); |
---|
| 1310 | if (corig != NULL) |
---|
| 1311 | free (corig); |
---|
| 1312 | } |
---|
| 1313 | } |
---|
| 1314 | closedir (dirp); |
---|
| 1315 | fflush (stdout); |
---|
| 1316 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1317 | free (orig); |
---|
| 1318 | printDocument (m, doc, getpid ()); |
---|
| 1319 | freeMaps (&m); |
---|
| 1320 | free (m); |
---|
| 1321 | free (REQUEST); |
---|
| 1322 | free (SERVICE_URL); |
---|
| 1323 | fflush (stdout); |
---|
| 1324 | return 0; |
---|
| 1325 | } |
---|
| 1326 | else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) |
---|
| 1327 | { |
---|
| 1328 | errorException (m, |
---|
| 1329 | _ |
---|
| 1330 | ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), |
---|
| 1331 | "InvalidParameterValue", "request"); |
---|
| 1332 | #ifdef DEBUG |
---|
| 1333 | fprintf (stderr, "No request found %s", REQUEST); |
---|
| 1334 | #endif |
---|
| 1335 | closedir (dirp); |
---|
| 1336 | freeMaps (&m); |
---|
| 1337 | free (m); |
---|
| 1338 | free (REQUEST); |
---|
| 1339 | free (SERVICE_URL); |
---|
| 1340 | fflush (stdout); |
---|
| 1341 | return 0; |
---|
| 1342 | } |
---|
| 1343 | closedir (dirp); |
---|
[1] | 1344 | } |
---|
[541] | 1345 | |
---|
| 1346 | s1 = NULL; |
---|
| 1347 | s1 = (service *) malloc (SERVICE_SIZE); |
---|
| 1348 | if (s1 == NULL) |
---|
| 1349 | { |
---|
| 1350 | freeMaps (&m); |
---|
| 1351 | free (m); |
---|
| 1352 | free (REQUEST); |
---|
| 1353 | free (SERVICE_URL); |
---|
| 1354 | return errorException (m, _("Unable to allocate memory."), |
---|
| 1355 | "InternalError", NULL); |
---|
| 1356 | } |
---|
| 1357 | r_inputs = getMap (request_inputs, "MetaPath"); |
---|
| 1358 | if (r_inputs != NULL) |
---|
| 1359 | snprintf (tmps1, 1024, "%s/%s", ntmp, r_inputs->value); |
---|
[9] | 1360 | else |
---|
[541] | 1361 | snprintf (tmps1, 1024, "%s/", ntmp); |
---|
| 1362 | r_inputs = getMap (request_inputs, "Identifier"); |
---|
| 1363 | char *ttmp = zStrdup (tmps1); |
---|
| 1364 | snprintf (tmps1, 1024, "%s/%s.zcfg", ttmp, r_inputs->value); |
---|
| 1365 | free (ttmp); |
---|
[1] | 1366 | #ifdef DEBUG |
---|
[541] | 1367 | fprintf (stderr, "Trying to load %s\n", tmps1); |
---|
[1] | 1368 | #endif |
---|
[541] | 1369 | if (strstr (r_inputs->value, ".") != NULL) |
---|
| 1370 | { |
---|
| 1371 | char *identifier = zStrdup (r_inputs->value); |
---|
| 1372 | parseIdentifier (m, conf_dir, identifier, tmps1); |
---|
| 1373 | map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); |
---|
| 1374 | if (tmpMap != NULL) |
---|
| 1375 | addToMap (request_inputs, "metapath", tmpMap->value); |
---|
| 1376 | free (identifier); |
---|
| 1377 | } |
---|
| 1378 | else |
---|
| 1379 | { |
---|
| 1380 | setMapInMaps (m, "lenv", "Identifier", r_inputs->value); |
---|
| 1381 | setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); |
---|
| 1382 | } |
---|
[539] | 1383 | |
---|
[541] | 1384 | r_inputs = getMapFromMaps (m, "lenv", "Identifier"); |
---|
| 1385 | int saved_stdout = dup (fileno (stdout)); |
---|
| 1386 | dup2 (fileno (stderr), fileno (stdout)); |
---|
| 1387 | t = readServiceFile (m, tmps1, &s1, r_inputs->value); |
---|
| 1388 | fflush (stdout); |
---|
| 1389 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 1390 | if (t < 0) |
---|
| 1391 | { |
---|
| 1392 | char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); |
---|
| 1393 | sprintf (tmpMsg, |
---|
| 1394 | _ |
---|
[576] | 1395 | ("The value for <identifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."), |
---|
[541] | 1396 | r_inputs->value); |
---|
| 1397 | errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); |
---|
| 1398 | free (tmpMsg); |
---|
| 1399 | free (s1); |
---|
| 1400 | freeMaps (&m); |
---|
| 1401 | free (m); |
---|
| 1402 | free (REQUEST); |
---|
| 1403 | free (SERVICE_URL); |
---|
| 1404 | return 0; |
---|
| 1405 | } |
---|
| 1406 | close (saved_stdout); |
---|
[1] | 1407 | |
---|
| 1408 | #ifdef DEBUG |
---|
[541] | 1409 | dumpService (s1); |
---|
[1] | 1410 | #endif |
---|
| 1411 | int j; |
---|
[381] | 1412 | |
---|
[541] | 1413 | |
---|
[1] | 1414 | /** |
---|
[344] | 1415 | * Create the input and output maps data structure |
---|
[1] | 1416 | */ |
---|
[541] | 1417 | int i = 0; |
---|
[1] | 1418 | HINTERNET hInternet; |
---|
| 1419 | HINTERNET res; |
---|
[541] | 1420 | hInternet = InternetOpen ( |
---|
[1] | 1421 | #ifndef WIN32 |
---|
[541] | 1422 | (LPCTSTR) |
---|
[1] | 1423 | #endif |
---|
[541] | 1424 | "ZooWPSClient\0", |
---|
| 1425 | INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); |
---|
[1] | 1426 | |
---|
| 1427 | #ifndef WIN32 |
---|
[541] | 1428 | if (!CHECK_INET_HANDLE (hInternet)) |
---|
| 1429 | fprintf (stderr, "WARNING : hInternet handle failed to initialize"); |
---|
[1] | 1430 | #endif |
---|
[541] | 1431 | maps *request_input_real_format = NULL; |
---|
| 1432 | maps *tmpmaps = request_input_real_format; |
---|
| 1433 | map *postRequest = NULL; |
---|
| 1434 | postRequest = getMap (request_inputs, "xrequest"); |
---|
| 1435 | if (postRequest == NULLMAP) |
---|
| 1436 | { |
---|
[1] | 1437 | /** |
---|
| 1438 | * Parsing outputs provided as KVP |
---|
| 1439 | */ |
---|
[541] | 1440 | r_inputs = NULL; |
---|
[1] | 1441 | #ifdef DEBUG |
---|
[541] | 1442 | fprintf (stderr, "OUTPUT Parsing ... \n"); |
---|
[1] | 1443 | #endif |
---|
[541] | 1444 | r_inputs = getMap (request_inputs, "ResponseDocument"); |
---|
| 1445 | if (r_inputs == NULL) |
---|
| 1446 | r_inputs = getMap (request_inputs, "RawDataOutput"); |
---|
| 1447 | |
---|
[32] | 1448 | #ifdef DEBUG |
---|
[541] | 1449 | fprintf (stderr, "OUTPUT Parsing ... \n"); |
---|
[32] | 1450 | #endif |
---|
[541] | 1451 | if (r_inputs != NULL) |
---|
| 1452 | { |
---|
[32] | 1453 | #ifdef DEBUG |
---|
[541] | 1454 | fprintf (stderr, "OUTPUT Parsing start now ... \n"); |
---|
[32] | 1455 | #endif |
---|
[541] | 1456 | char cursor_output[10240]; |
---|
| 1457 | char *cotmp = zStrdup (r_inputs->value); |
---|
| 1458 | snprintf (cursor_output, 10240, "%s", cotmp); |
---|
| 1459 | free (cotmp); |
---|
| 1460 | j = 0; |
---|
| 1461 | |
---|
[1] | 1462 | /** |
---|
| 1463 | * Put each Output into the outputs_as_text array |
---|
| 1464 | */ |
---|
[541] | 1465 | char *pToken; |
---|
| 1466 | maps *tmp_output = NULL; |
---|
[1] | 1467 | #ifdef DEBUG |
---|
[541] | 1468 | fprintf (stderr, "OUTPUT [%s]\n", cursor_output); |
---|
[1] | 1469 | #endif |
---|
[541] | 1470 | pToken = strtok (cursor_output, ";"); |
---|
| 1471 | char **outputs_as_text = (char **) malloc (128 * sizeof (char *)); |
---|
| 1472 | if (outputs_as_text == NULL) |
---|
| 1473 | { |
---|
| 1474 | return errorException (m, _("Unable to allocate memory"), |
---|
| 1475 | "InternalError", NULL); |
---|
| 1476 | } |
---|
| 1477 | i = 0; |
---|
| 1478 | while (pToken != NULL) |
---|
| 1479 | { |
---|
[1] | 1480 | #ifdef DEBUG |
---|
[541] | 1481 | fprintf (stderr, "***%s***\n", pToken); |
---|
| 1482 | fflush (stderr); |
---|
| 1483 | fprintf (stderr, "***%s***\n", pToken); |
---|
[1] | 1484 | #endif |
---|
[541] | 1485 | outputs_as_text[i] = |
---|
| 1486 | (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); |
---|
| 1487 | if (outputs_as_text[i] == NULL) |
---|
| 1488 | { |
---|
| 1489 | return errorException (m, _("Unable to allocate memory"), |
---|
| 1490 | "InternalError", NULL); |
---|
| 1491 | } |
---|
| 1492 | snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s", |
---|
| 1493 | pToken); |
---|
| 1494 | pToken = strtok (NULL, ";"); |
---|
| 1495 | i++; |
---|
| 1496 | } |
---|
| 1497 | for (j = 0; j < i; j++) |
---|
| 1498 | { |
---|
| 1499 | char *tmp = zStrdup (outputs_as_text[j]); |
---|
| 1500 | free (outputs_as_text[j]); |
---|
| 1501 | char *tmpc; |
---|
| 1502 | tmpc = strtok (tmp, "@"); |
---|
| 1503 | int k = 0; |
---|
| 1504 | while (tmpc != NULL) |
---|
| 1505 | { |
---|
| 1506 | if (k == 0) |
---|
| 1507 | { |
---|
| 1508 | if (tmp_output == NULL) |
---|
| 1509 | { |
---|
| 1510 | tmp_output = (maps *) malloc (MAPS_SIZE); |
---|
| 1511 | if (tmp_output == NULL) |
---|
| 1512 | { |
---|
| 1513 | return errorException (m, |
---|
| 1514 | _ |
---|
| 1515 | ("Unable to allocate memory."), |
---|
| 1516 | "InternalError", NULL); |
---|
| 1517 | } |
---|
| 1518 | tmp_output->name = zStrdup (tmpc); |
---|
| 1519 | tmp_output->content = NULL; |
---|
| 1520 | tmp_output->next = NULL; |
---|
| 1521 | } |
---|
| 1522 | } |
---|
| 1523 | else |
---|
| 1524 | { |
---|
| 1525 | char *tmpv = strstr (tmpc, "="); |
---|
| 1526 | char tmpn[256]; |
---|
| 1527 | memset (tmpn, 0, 256); |
---|
| 1528 | strncpy (tmpn, tmpc, |
---|
| 1529 | (strlen (tmpc) - |
---|
| 1530 | strlen (tmpv)) * sizeof (char)); |
---|
| 1531 | tmpn[strlen (tmpc) - strlen (tmpv)] = 0; |
---|
[1] | 1532 | #ifdef DEBUG |
---|
[541] | 1533 | fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn, |
---|
| 1534 | tmpv + 1); |
---|
[1] | 1535 | #endif |
---|
[541] | 1536 | if (tmp_output->content == NULL) |
---|
| 1537 | { |
---|
| 1538 | tmp_output->content = createMap (tmpn, tmpv + 1); |
---|
| 1539 | tmp_output->content->next = NULL; |
---|
| 1540 | } |
---|
| 1541 | else |
---|
| 1542 | addToMap (tmp_output->content, tmpn, tmpv + 1); |
---|
| 1543 | } |
---|
| 1544 | k++; |
---|
[1] | 1545 | #ifdef DEBUG |
---|
[541] | 1546 | fprintf (stderr, "***%s***\n", tmpc); |
---|
[1] | 1547 | #endif |
---|
[541] | 1548 | tmpc = strtok (NULL, "@"); |
---|
| 1549 | } |
---|
| 1550 | if (request_output_real_format == NULL) |
---|
| 1551 | request_output_real_format = dupMaps (&tmp_output); |
---|
| 1552 | else |
---|
| 1553 | addMapsToMaps (&request_output_real_format, tmp_output); |
---|
| 1554 | freeMaps (&tmp_output); |
---|
| 1555 | free (tmp_output); |
---|
| 1556 | tmp_output = NULL; |
---|
[1] | 1557 | #ifdef DEBUG |
---|
[541] | 1558 | dumpMaps (tmp_output); |
---|
| 1559 | fflush (stderr); |
---|
[1] | 1560 | #endif |
---|
[541] | 1561 | free (tmp); |
---|
| 1562 | } |
---|
| 1563 | free (outputs_as_text); |
---|
| 1564 | } |
---|
[1] | 1565 | |
---|
| 1566 | |
---|
| 1567 | /** |
---|
| 1568 | * Parsing inputs provided as KVP |
---|
| 1569 | */ |
---|
[541] | 1570 | r_inputs = getMap (request_inputs, "DataInputs"); |
---|
[1] | 1571 | #ifdef DEBUG |
---|
[541] | 1572 | fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value); |
---|
[1] | 1573 | #endif |
---|
[541] | 1574 | char cursor_input[40960]; |
---|
[576] | 1575 | if (r_inputs != NULL){ |
---|
[541] | 1576 | snprintf (cursor_input, 40960, "%s", r_inputs->value); |
---|
[576] | 1577 | j = 0; |
---|
[541] | 1578 | |
---|
[576] | 1579 | /** |
---|
| 1580 | * Put each DataInputs into the inputs_as_text array |
---|
| 1581 | */ |
---|
| 1582 | char *tmp1 = zStrdup (cursor_input); |
---|
| 1583 | char *pToken; |
---|
| 1584 | pToken = strtok (cursor_input, ";"); |
---|
| 1585 | if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0) |
---|
| 1586 | { |
---|
| 1587 | char *tmp2 = url_decode (tmp1); |
---|
| 1588 | snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s", |
---|
| 1589 | tmp2); |
---|
| 1590 | free (tmp2); |
---|
| 1591 | pToken = strtok (cursor_input, ";"); |
---|
| 1592 | } |
---|
| 1593 | free (tmp1); |
---|
| 1594 | |
---|
| 1595 | char **inputs_as_text = (char **) malloc (100 * sizeof (char *)); |
---|
| 1596 | if (inputs_as_text == NULL) |
---|
| 1597 | { |
---|
| 1598 | return errorException (m, _("Unable to allocate memory."), |
---|
| 1599 | "InternalError", NULL); |
---|
| 1600 | } |
---|
| 1601 | i = 0; |
---|
| 1602 | while (pToken != NULL) |
---|
| 1603 | { |
---|
[1] | 1604 | #ifdef DEBUG |
---|
[576] | 1605 | fprintf (stderr, "***%s***\n", pToken); |
---|
| 1606 | fflush (stderr); |
---|
| 1607 | fprintf (stderr, "***%s***\n", pToken); |
---|
[1] | 1608 | #endif |
---|
[576] | 1609 | inputs_as_text[i] = |
---|
| 1610 | (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); |
---|
| 1611 | if (inputs_as_text[i] == NULL) |
---|
| 1612 | { |
---|
| 1613 | return errorException (m, _("Unable to allocate memory."), |
---|
| 1614 | "InternalError", NULL); |
---|
| 1615 | } |
---|
| 1616 | snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken); |
---|
| 1617 | pToken = strtok (NULL, ";"); |
---|
| 1618 | i++; |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | for (j = 0; j < i; j++) |
---|
| 1622 | { |
---|
| 1623 | char *tmp = zStrdup (inputs_as_text[j]); |
---|
| 1624 | free (inputs_as_text[j]); |
---|
| 1625 | char *tmpc; |
---|
| 1626 | tmpc = strtok (tmp, "@"); |
---|
| 1627 | while (tmpc != NULL) |
---|
| 1628 | { |
---|
[1] | 1629 | #ifdef DEBUG |
---|
[576] | 1630 | fprintf (stderr, "***\n***%s***\n", tmpc); |
---|
[1] | 1631 | #endif |
---|
[576] | 1632 | char *tmpv = strstr (tmpc, "="); |
---|
| 1633 | char tmpn[256]; |
---|
| 1634 | memset (tmpn, 0, 256); |
---|
| 1635 | if (tmpv != NULL) |
---|
| 1636 | { |
---|
| 1637 | strncpy (tmpn, tmpc, |
---|
| 1638 | (strlen (tmpc) - strlen (tmpv)) * sizeof (char)); |
---|
| 1639 | tmpn[strlen (tmpc) - strlen (tmpv)] = 0; |
---|
| 1640 | } |
---|
| 1641 | else |
---|
| 1642 | { |
---|
| 1643 | strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char)); |
---|
| 1644 | tmpn[strlen (tmpc)] = 0; |
---|
| 1645 | } |
---|
[1] | 1646 | #ifdef DEBUG |
---|
[576] | 1647 | fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1); |
---|
[1] | 1648 | #endif |
---|
[576] | 1649 | if (tmpmaps == NULL) |
---|
| 1650 | { |
---|
| 1651 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 1652 | if (tmpmaps == NULL) |
---|
| 1653 | { |
---|
| 1654 | return errorException (m, |
---|
| 1655 | _("Unable to allocate memory."), |
---|
| 1656 | "InternalError", NULL); |
---|
| 1657 | } |
---|
| 1658 | tmpmaps->name = zStrdup (tmpn); |
---|
| 1659 | if (tmpv != NULL) |
---|
| 1660 | { |
---|
| 1661 | char *tmpvf = url_decode (tmpv + 1); |
---|
| 1662 | tmpmaps->content = createMap ("value", tmpvf); |
---|
| 1663 | free (tmpvf); |
---|
| 1664 | } |
---|
| 1665 | else |
---|
| 1666 | tmpmaps->content = createMap ("value", "Reference"); |
---|
| 1667 | tmpmaps->next = NULL; |
---|
| 1668 | } |
---|
| 1669 | tmpc = strtok (NULL, "@"); |
---|
| 1670 | while (tmpc != NULL) |
---|
| 1671 | { |
---|
[1] | 1672 | #ifdef DEBUG |
---|
[576] | 1673 | fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n", |
---|
| 1674 | tmpc); |
---|
[1] | 1675 | #endif |
---|
[576] | 1676 | char *tmpv1 = strstr (tmpc, "="); |
---|
[1] | 1677 | #ifdef DEBUG |
---|
[576] | 1678 | fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", |
---|
| 1679 | tmpv1 + 1); |
---|
[1] | 1680 | #endif |
---|
[576] | 1681 | char tmpn1[1024]; |
---|
| 1682 | memset (tmpn1, 0, 1024); |
---|
| 1683 | if (tmpv1 != NULL) |
---|
| 1684 | { |
---|
| 1685 | strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1)); |
---|
| 1686 | tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0; |
---|
| 1687 | addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); |
---|
| 1688 | } |
---|
| 1689 | else |
---|
| 1690 | { |
---|
| 1691 | strncpy (tmpn1, tmpc, strlen (tmpc)); |
---|
| 1692 | tmpn1[strlen (tmpc)] = 0; |
---|
| 1693 | map *lmap = getLastMap (tmpmaps->content); |
---|
| 1694 | char *tmpValue = |
---|
| 1695 | (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) * |
---|
| 1696 | sizeof (char)); |
---|
| 1697 | sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc); |
---|
| 1698 | free (lmap->value); |
---|
| 1699 | lmap->value = zStrdup (tmpValue); |
---|
| 1700 | free (tmpValue); |
---|
| 1701 | tmpc = strtok (NULL, "@"); |
---|
| 1702 | continue; |
---|
| 1703 | } |
---|
[1] | 1704 | #ifdef DEBUG |
---|
[576] | 1705 | fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n", |
---|
| 1706 | tmpn1); |
---|
| 1707 | fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", |
---|
| 1708 | tmpv1 + 1); |
---|
[1] | 1709 | #endif |
---|
[576] | 1710 | if (strcmp (tmpn1, "xlink:href") != 0) |
---|
| 1711 | addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); |
---|
| 1712 | else if (tmpv1 != NULL) |
---|
| 1713 | { |
---|
| 1714 | char *tmpx2 = url_decode (tmpv1 + 1); |
---|
| 1715 | if (strncasecmp (tmpx2, "http://", 7) != 0 && |
---|
| 1716 | strncasecmp (tmpx2, "ftp://", 6) != 0 && |
---|
| 1717 | strncasecmp (tmpx2, "https://", 8) != 0) |
---|
| 1718 | { |
---|
| 1719 | char emsg[1024]; |
---|
| 1720 | sprintf (emsg, |
---|
| 1721 | _ |
---|
| 1722 | ("Unable to find a valid protocol to download the remote file %s"), |
---|
| 1723 | tmpv1 + 1); |
---|
| 1724 | errorException (m, emsg, "InternalError", NULL); |
---|
| 1725 | freeMaps (&m); |
---|
| 1726 | free (m); |
---|
| 1727 | free (REQUEST); |
---|
| 1728 | free (SERVICE_URL); |
---|
| 1729 | InternetCloseHandle (&hInternet); |
---|
| 1730 | freeService (&s1); |
---|
| 1731 | free (s1); |
---|
| 1732 | return 0; |
---|
| 1733 | } |
---|
[1] | 1734 | #ifdef DEBUG |
---|
[576] | 1735 | fprintf (stderr, |
---|
| 1736 | "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n", |
---|
| 1737 | tmpv1 + 1); |
---|
[1] | 1738 | #endif |
---|
[576] | 1739 | addToMap (tmpmaps->content, tmpn1, tmpx2); |
---|
[1] | 1740 | #ifndef WIN32 |
---|
[576] | 1741 | if (CHECK_INET_HANDLE (hInternet)) |
---|
[1] | 1742 | #endif |
---|
[576] | 1743 | { |
---|
| 1744 | if (loadRemoteFile |
---|
| 1745 | (&m, &tmpmaps->content, &hInternet, tmpx2) < 0) |
---|
| 1746 | { |
---|
| 1747 | freeMaps (&m); |
---|
| 1748 | free (m); |
---|
| 1749 | free (REQUEST); |
---|
| 1750 | free (SERVICE_URL); |
---|
| 1751 | InternetCloseHandle (&hInternet); |
---|
| 1752 | freeService (&s1); |
---|
| 1753 | free (s1); |
---|
| 1754 | return 0; |
---|
| 1755 | } |
---|
| 1756 | } |
---|
| 1757 | free (tmpx2); |
---|
| 1758 | addToMap (tmpmaps->content, "Reference", tmpv1 + 1); |
---|
| 1759 | } |
---|
| 1760 | tmpc = strtok (NULL, "@"); |
---|
| 1761 | } |
---|
[1] | 1762 | #ifdef DEBUG |
---|
[576] | 1763 | dumpMaps (tmpmaps); |
---|
| 1764 | fflush (stderr); |
---|
[1] | 1765 | #endif |
---|
[576] | 1766 | if (request_input_real_format == NULL) |
---|
| 1767 | request_input_real_format = dupMaps (&tmpmaps); |
---|
| 1768 | else |
---|
| 1769 | { |
---|
| 1770 | maps *testPresence = |
---|
| 1771 | getMaps (request_input_real_format, tmpmaps->name); |
---|
| 1772 | if (testPresence != NULL) |
---|
| 1773 | { |
---|
| 1774 | elements *elem = |
---|
| 1775 | getElements (s1->inputs, tmpmaps->name); |
---|
| 1776 | if (elem != NULL) |
---|
| 1777 | { |
---|
| 1778 | if (appendMapsToMaps |
---|
| 1779 | (m, request_input_real_format, tmpmaps, |
---|
| 1780 | elem) < 0) |
---|
| 1781 | { |
---|
| 1782 | freeMaps (&m); |
---|
| 1783 | free (m); |
---|
| 1784 | free (REQUEST); |
---|
| 1785 | free (SERVICE_URL); |
---|
| 1786 | InternetCloseHandle (&hInternet); |
---|
| 1787 | freeService (&s1); |
---|
| 1788 | free (s1); |
---|
| 1789 | return 0; |
---|
| 1790 | } |
---|
| 1791 | } |
---|
| 1792 | } |
---|
| 1793 | else |
---|
| 1794 | addMapsToMaps (&request_input_real_format, tmpmaps); |
---|
| 1795 | } |
---|
| 1796 | freeMaps (&tmpmaps); |
---|
| 1797 | free (tmpmaps); |
---|
| 1798 | tmpmaps = NULL; |
---|
| 1799 | free (tmp); |
---|
| 1800 | } |
---|
| 1801 | } |
---|
| 1802 | free (inputs_as_text); |
---|
| 1803 | } |
---|
[1] | 1804 | } |
---|
[541] | 1805 | else |
---|
| 1806 | { |
---|
[9] | 1807 | /** |
---|
| 1808 | * Parse XML request |
---|
[541] | 1809 | */ |
---|
| 1810 | xmlInitParser (); |
---|
[1] | 1811 | #ifdef DEBUG |
---|
[541] | 1812 | fflush (stderr); |
---|
| 1813 | fprintf (stderr, "BEFORE %s\n", postRequest->value); |
---|
| 1814 | fflush (stderr); |
---|
[1] | 1815 | #endif |
---|
[541] | 1816 | xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength); |
---|
[1] | 1817 | #ifdef DEBUG |
---|
[541] | 1818 | fprintf (stderr, "AFTER\n"); |
---|
| 1819 | fflush (stderr); |
---|
[1] | 1820 | #endif |
---|
| 1821 | /** |
---|
| 1822 | * Parse every Input in DataInputs node. |
---|
| 1823 | */ |
---|
[541] | 1824 | xmlXPathObjectPtr tmpsptr = |
---|
| 1825 | extractFromDoc (doc, "/*/*/*[local-name()='Input']"); |
---|
| 1826 | xmlNodeSet *tmps = tmpsptr->nodesetval; |
---|
[1] | 1827 | #ifdef DEBUG |
---|
[541] | 1828 | fprintf (stderr, "*****%d*****\n", tmps->nodeNr); |
---|
[1] | 1829 | #endif |
---|
[541] | 1830 | for (int k = 0; k < tmps->nodeNr; k++) |
---|
| 1831 | { |
---|
| 1832 | maps *tmpmaps = NULL; |
---|
| 1833 | xmlNodePtr cur = tmps->nodeTab[k]; |
---|
| 1834 | if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE) |
---|
| 1835 | { |
---|
| 1836 | /** |
---|
[1] | 1837 | * A specific Input node. |
---|
| 1838 | */ |
---|
| 1839 | #ifdef DEBUG |
---|
[541] | 1840 | fprintf (stderr, "= element 0 node \"%s\"\n", cur->name); |
---|
[1] | 1841 | #endif |
---|
[541] | 1842 | xmlNodePtr cur2 = cur->children; |
---|
| 1843 | while (cur2 != NULL) |
---|
| 1844 | { |
---|
| 1845 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 1846 | cur2 = cur2->next; |
---|
| 1847 | if (cur2 == NULL) |
---|
| 1848 | break; |
---|
| 1849 | /** |
---|
[9] | 1850 | * Indentifier |
---|
| 1851 | */ |
---|
[541] | 1852 | if (xmlStrncasecmp |
---|
| 1853 | (cur2->name, BAD_CAST "Identifier", |
---|
| 1854 | xmlStrlen (cur2->name)) == 0) |
---|
| 1855 | { |
---|
| 1856 | xmlChar *val = |
---|
| 1857 | xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); |
---|
| 1858 | if (tmpmaps == NULL) |
---|
| 1859 | { |
---|
| 1860 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 1861 | if (tmpmaps == NULL) |
---|
| 1862 | { |
---|
| 1863 | return errorException (m, |
---|
| 1864 | _ |
---|
| 1865 | ("Unable to allocate memory."), |
---|
| 1866 | "InternalError", NULL); |
---|
| 1867 | } |
---|
| 1868 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 1869 | tmpmaps->content = NULL; |
---|
| 1870 | tmpmaps->next = NULL; |
---|
| 1871 | } |
---|
| 1872 | xmlFree (val); |
---|
| 1873 | } |
---|
| 1874 | /** |
---|
[9] | 1875 | * Title, Asbtract |
---|
| 1876 | */ |
---|
[541] | 1877 | if (xmlStrncasecmp |
---|
| 1878 | (cur2->name, BAD_CAST "Title", |
---|
| 1879 | xmlStrlen (cur2->name)) == 0 |
---|
| 1880 | || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract", |
---|
| 1881 | xmlStrlen (cur2->name)) == 0) |
---|
| 1882 | { |
---|
| 1883 | xmlChar *val = |
---|
| 1884 | xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); |
---|
| 1885 | if (tmpmaps == NULL) |
---|
| 1886 | { |
---|
| 1887 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 1888 | if (tmpmaps == NULL) |
---|
| 1889 | { |
---|
| 1890 | return errorException (m, |
---|
| 1891 | _ |
---|
| 1892 | ("Unable to allocate memory."), |
---|
| 1893 | "InternalError", NULL); |
---|
| 1894 | } |
---|
| 1895 | tmpmaps->name = zStrdup ("missingIndetifier"); |
---|
| 1896 | tmpmaps->content = |
---|
| 1897 | createMap ((char *) cur2->name, (char *) val); |
---|
| 1898 | tmpmaps->next = NULL; |
---|
| 1899 | } |
---|
| 1900 | else |
---|
| 1901 | { |
---|
| 1902 | if (tmpmaps->content != NULL) |
---|
| 1903 | addToMap (tmpmaps->content, |
---|
| 1904 | (char *) cur2->name, (char *) val); |
---|
| 1905 | else |
---|
| 1906 | tmpmaps->content = |
---|
| 1907 | createMap ((char *) cur2->name, (char *) val); |
---|
| 1908 | } |
---|
[1] | 1909 | #ifdef DEBUG |
---|
[541] | 1910 | dumpMaps (tmpmaps); |
---|
[1] | 1911 | #endif |
---|
[541] | 1912 | xmlFree (val); |
---|
| 1913 | } |
---|
| 1914 | /** |
---|
[9] | 1915 | * InputDataFormChoice (Reference or Data ?) |
---|
| 1916 | */ |
---|
[541] | 1917 | if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0) |
---|
| 1918 | { |
---|
| 1919 | /** |
---|
[9] | 1920 | * Get every attribute from a Reference node |
---|
| 1921 | * mimeType, encoding, schema, href, method |
---|
| 1922 | * Header and Body gesture should be added here |
---|
[1] | 1923 | */ |
---|
| 1924 | #ifdef DEBUG |
---|
[541] | 1925 | fprintf (stderr, "REFERENCE\n"); |
---|
[1] | 1926 | #endif |
---|
[541] | 1927 | const char *refs[5] = |
---|
| 1928 | { "mimeType", "encoding", "schema", "method", |
---|
| 1929 | "href" |
---|
| 1930 | }; |
---|
| 1931 | for (int l = 0; l < 5; l++) |
---|
| 1932 | { |
---|
[1] | 1933 | #ifdef DEBUG |
---|
[541] | 1934 | fprintf (stderr, "*** %s ***", refs[l]); |
---|
[1] | 1935 | #endif |
---|
[541] | 1936 | xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]); |
---|
| 1937 | if (val != NULL && xmlStrlen (val) > 0) |
---|
| 1938 | { |
---|
| 1939 | if (tmpmaps->content != NULL) |
---|
| 1940 | addToMap (tmpmaps->content, refs[l], |
---|
| 1941 | (char *) val); |
---|
| 1942 | else |
---|
| 1943 | tmpmaps->content = |
---|
| 1944 | createMap (refs[l], (char *) val); |
---|
| 1945 | map *ltmp = getMap (tmpmaps->content, "method"); |
---|
| 1946 | if (l == 4) |
---|
| 1947 | { |
---|
| 1948 | if (! |
---|
| 1949 | (ltmp != NULL |
---|
| 1950 | && strncmp (ltmp->value, "POST", |
---|
| 1951 | 4) == 0) |
---|
| 1952 | && CHECK_INET_HANDLE (hInternet)) |
---|
| 1953 | { |
---|
| 1954 | if (loadRemoteFile |
---|
| 1955 | (&m, &tmpmaps->content, &hInternet, |
---|
| 1956 | (char *) val) != 0) |
---|
| 1957 | { |
---|
| 1958 | freeMaps (&m); |
---|
| 1959 | free (m); |
---|
| 1960 | free (REQUEST); |
---|
| 1961 | free (SERVICE_URL); |
---|
| 1962 | InternetCloseHandle (&hInternet); |
---|
| 1963 | freeService (&s1); |
---|
| 1964 | free (s1); |
---|
| 1965 | return 0; |
---|
| 1966 | } |
---|
| 1967 | } |
---|
| 1968 | } |
---|
| 1969 | } |
---|
[1] | 1970 | #ifdef DEBUG |
---|
[541] | 1971 | fprintf (stderr, "%s\n", val); |
---|
[1] | 1972 | #endif |
---|
[541] | 1973 | xmlFree (val); |
---|
| 1974 | } |
---|
[1] | 1975 | #ifdef POST_DEBUG |
---|
[541] | 1976 | fprintf (stderr, |
---|
| 1977 | "Parse Header and Body from Reference \n"); |
---|
[1] | 1978 | #endif |
---|
[541] | 1979 | xmlNodePtr cur3 = cur2->children; |
---|
| 1980 | /* HINTERNET hInternetP; |
---|
| 1981 | hInternetP=InternetOpen( |
---|
| 1982 | #ifndef WIN32 |
---|
| 1983 | (LPCTSTR) |
---|
| 1984 | #endif |
---|
| 1985 | "ZooWPSClient\0", |
---|
| 1986 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 1987 | NULL,NULL, 0); */ |
---|
| 1988 | //hInternet.ihandle[hInternet.nb].header=NULL; |
---|
| 1989 | while (cur3 != NULL) |
---|
| 1990 | { |
---|
| 1991 | while (cur3 != NULL |
---|
| 1992 | && cur3->type != XML_ELEMENT_NODE) |
---|
| 1993 | cur3 = cur3->next; |
---|
| 1994 | if (cur3 == NULL) |
---|
| 1995 | break; |
---|
| 1996 | if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") == |
---|
| 1997 | 0) |
---|
| 1998 | { |
---|
| 1999 | const char *ha[2]; |
---|
| 2000 | ha[0] = "key"; |
---|
| 2001 | ha[1] = "value"; |
---|
| 2002 | int hai; |
---|
| 2003 | char *has; |
---|
| 2004 | char *key; |
---|
| 2005 | for (hai = 0; hai < 2; hai++) |
---|
| 2006 | { |
---|
| 2007 | xmlChar *val = |
---|
| 2008 | xmlGetProp (cur3, BAD_CAST ha[hai]); |
---|
[1] | 2009 | #ifdef POST_DEBUG |
---|
[541] | 2010 | fprintf (stderr, "%s = %s\n", ha[hai], |
---|
| 2011 | (char *) val); |
---|
[1] | 2012 | #endif |
---|
[541] | 2013 | if (hai == 0) |
---|
| 2014 | { |
---|
| 2015 | key = zStrdup ((char *) val); |
---|
| 2016 | } |
---|
| 2017 | else |
---|
| 2018 | { |
---|
| 2019 | has = |
---|
| 2020 | (char *) |
---|
| 2021 | malloc ((4 + xmlStrlen (val) + |
---|
| 2022 | strlen (key)) * |
---|
| 2023 | sizeof (char)); |
---|
| 2024 | if (has == NULL) |
---|
| 2025 | { |
---|
| 2026 | return errorException (m, |
---|
| 2027 | _ |
---|
| 2028 | ("Unable to allocate memory."), |
---|
| 2029 | "InternalError", |
---|
| 2030 | NULL); |
---|
| 2031 | } |
---|
| 2032 | snprintf (has, |
---|
| 2033 | (3 + xmlStrlen (val) + |
---|
| 2034 | strlen (key)), "%s: %s", key, |
---|
| 2035 | (char *) val); |
---|
| 2036 | free (key); |
---|
[1] | 2037 | #ifdef POST_DEBUG |
---|
[541] | 2038 | fprintf (stderr, "%s\n", has); |
---|
[1] | 2039 | #endif |
---|
[541] | 2040 | } |
---|
| 2041 | xmlFree (val); |
---|
| 2042 | } |
---|
| 2043 | hInternet.ihandle[hInternet.nb].header = |
---|
| 2044 | curl_slist_append (hInternet.ihandle |
---|
| 2045 | [hInternet.nb].header, |
---|
| 2046 | has); |
---|
| 2047 | if (has != NULL) |
---|
| 2048 | free (has); |
---|
| 2049 | } |
---|
| 2050 | else |
---|
| 2051 | { |
---|
[1] | 2052 | #ifdef POST_DEBUG |
---|
[541] | 2053 | fprintf (stderr, |
---|
| 2054 | "Try to fetch the body part of the request ...\n"); |
---|
[1] | 2055 | #endif |
---|
[541] | 2056 | if (xmlStrcasecmp (cur3->name, BAD_CAST "Body") |
---|
| 2057 | == 0) |
---|
| 2058 | { |
---|
[1] | 2059 | #ifdef POST_DEBUG |
---|
[541] | 2060 | fprintf (stderr, "Body part found !!!\n", |
---|
| 2061 | (char *) cur3->content); |
---|
[1] | 2062 | #endif |
---|
[541] | 2063 | char *tmp = |
---|
| 2064 | (char *) malloc (cgiContentLength + |
---|
| 2065 | 1 * sizeof (char)); |
---|
| 2066 | memset (tmp, 0, cgiContentLength); |
---|
| 2067 | xmlNodePtr cur4 = cur3->children; |
---|
| 2068 | while (cur4 != NULL) |
---|
| 2069 | { |
---|
| 2070 | while (cur4->type != XML_ELEMENT_NODE) |
---|
| 2071 | cur4 = cur4->next; |
---|
| 2072 | xmlDocPtr bdoc = |
---|
| 2073 | xmlNewDoc (BAD_CAST "1.0"); |
---|
| 2074 | bdoc->encoding = |
---|
| 2075 | xmlCharStrdup ("UTF-8"); |
---|
| 2076 | xmlDocSetRootElement (bdoc, cur4); |
---|
| 2077 | xmlChar *btmps; |
---|
| 2078 | int bsize; |
---|
| 2079 | xmlDocDumpMemory (bdoc, &btmps, &bsize); |
---|
[1] | 2080 | #ifdef POST_DEBUG |
---|
[541] | 2081 | fprintf (stderr, |
---|
| 2082 | "Body part found !!! %s %s\n", |
---|
| 2083 | tmp, (char *) btmps); |
---|
[1] | 2084 | #endif |
---|
[541] | 2085 | if (btmps != NULL) |
---|
| 2086 | sprintf (tmp, "%s", (char *) btmps); |
---|
| 2087 | xmlFree (btmps); |
---|
| 2088 | cur4 = cur4->next; |
---|
| 2089 | xmlFreeDoc (bdoc); |
---|
| 2090 | } |
---|
| 2091 | map *btmp = |
---|
| 2092 | getMap (tmpmaps->content, "href"); |
---|
| 2093 | if (btmp != NULL) |
---|
| 2094 | { |
---|
[9] | 2095 | #ifdef POST_DEBUG |
---|
[541] | 2096 | fprintf (stderr, "%s %s\n", btmp->value, |
---|
| 2097 | tmp); |
---|
| 2098 | curl_easy_setopt (hInternet.handle, |
---|
| 2099 | CURLOPT_VERBOSE, 1); |
---|
[9] | 2100 | #endif |
---|
[541] | 2101 | hInternet. |
---|
| 2102 | waitingRequests[hInternet.nb] = |
---|
| 2103 | strdup (tmp); |
---|
| 2104 | InternetOpenUrl (&hInternet, |
---|
| 2105 | btmp->value, |
---|
| 2106 | hInternet.waitingRequests |
---|
| 2107 | [hInternet.nb], |
---|
| 2108 | strlen |
---|
| 2109 | (hInternet.waitingRequests |
---|
| 2110 | [hInternet.nb]), |
---|
| 2111 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 2112 | 0); |
---|
| 2113 | } |
---|
| 2114 | free (tmp); |
---|
| 2115 | } |
---|
| 2116 | else |
---|
| 2117 | if (xmlStrcasecmp |
---|
| 2118 | (cur3->name, |
---|
| 2119 | BAD_CAST "BodyReference") == 0) |
---|
| 2120 | { |
---|
| 2121 | xmlChar *val = |
---|
| 2122 | xmlGetProp (cur3, BAD_CAST "href"); |
---|
| 2123 | HINTERNET bInternet, res1; |
---|
| 2124 | bInternet = InternetOpen ( |
---|
[9] | 2125 | #ifndef WIN32 |
---|
[541] | 2126 | (LPCTSTR) |
---|
[9] | 2127 | #endif |
---|
[541] | 2128 | "ZooWPSClient\0", |
---|
| 2129 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 2130 | NULL, NULL, 0); |
---|
| 2131 | if (!CHECK_INET_HANDLE (hInternet)) |
---|
| 2132 | fprintf (stderr, |
---|
| 2133 | "WARNING : hInternet handle failed to initialize"); |
---|
[9] | 2134 | #ifdef POST_DEBUG |
---|
[541] | 2135 | curl_easy_setopt (bInternet.handle, |
---|
| 2136 | CURLOPT_VERBOSE, 1); |
---|
[9] | 2137 | #endif |
---|
[541] | 2138 | bInternet.waitingRequests[0] = |
---|
| 2139 | strdup ((char *) val); |
---|
| 2140 | res1 = |
---|
| 2141 | InternetOpenUrl (&bInternet, |
---|
| 2142 | bInternet.waitingRequests |
---|
| 2143 | [0], NULL, 0, |
---|
| 2144 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 2145 | 0); |
---|
| 2146 | processDownloads (&bInternet); |
---|
| 2147 | char *tmp = |
---|
| 2148 | (char *) |
---|
| 2149 | malloc ((bInternet.ihandle[0].nDataLen + |
---|
| 2150 | 1) * sizeof (char)); |
---|
| 2151 | if (tmp == NULL) |
---|
| 2152 | { |
---|
| 2153 | return errorException (m, |
---|
| 2154 | _ |
---|
| 2155 | ("Unable to allocate memory."), |
---|
| 2156 | "InternalError", |
---|
| 2157 | NULL); |
---|
| 2158 | } |
---|
| 2159 | size_t bRead; |
---|
| 2160 | InternetReadFile (bInternet.ihandle[0], |
---|
| 2161 | (LPVOID) tmp, |
---|
| 2162 | bInternet. |
---|
| 2163 | ihandle[0].nDataLen, |
---|
| 2164 | &bRead); |
---|
| 2165 | tmp[bInternet.ihandle[0].nDataLen] = 0; |
---|
| 2166 | InternetCloseHandle (&bInternet); |
---|
| 2167 | map *btmp = |
---|
| 2168 | getMap (tmpmaps->content, "href"); |
---|
| 2169 | if (btmp != NULL) |
---|
| 2170 | { |
---|
[1] | 2171 | #ifdef POST_DEBUG |
---|
[541] | 2172 | fprintf (stderr, "%s %s\n", btmp->value, |
---|
| 2173 | tmp); |
---|
[1] | 2174 | #endif |
---|
[541] | 2175 | hInternet. |
---|
| 2176 | waitingRequests[hInternet.nb] = |
---|
| 2177 | strdup (tmp); |
---|
| 2178 | res = |
---|
| 2179 | InternetOpenUrl (&hInternet, |
---|
| 2180 | btmp->value, |
---|
| 2181 | hInternet.waitingRequests |
---|
| 2182 | [hInternet.nb], |
---|
| 2183 | strlen |
---|
| 2184 | (hInternet.waitingRequests |
---|
| 2185 | [hInternet.nb]), |
---|
| 2186 | INTERNET_FLAG_NO_CACHE_WRITE, |
---|
| 2187 | 0); |
---|
| 2188 | } |
---|
| 2189 | free (tmp); |
---|
| 2190 | } |
---|
| 2191 | } |
---|
| 2192 | cur3 = cur3->next; |
---|
| 2193 | } |
---|
[1] | 2194 | #ifdef POST_DEBUG |
---|
[541] | 2195 | fprintf (stderr, |
---|
| 2196 | "Header and Body was parsed from Reference \n"); |
---|
[1] | 2197 | #endif |
---|
| 2198 | #ifdef DEBUG |
---|
[541] | 2199 | dumpMap (tmpmaps->content); |
---|
| 2200 | fprintf (stderr, "= element 2 node \"%s\" = (%s)\n", |
---|
| 2201 | cur2->name, cur2->content); |
---|
[1] | 2202 | #endif |
---|
[541] | 2203 | } |
---|
| 2204 | else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0) |
---|
| 2205 | { |
---|
[1] | 2206 | #ifdef DEBUG |
---|
[541] | 2207 | fprintf (stderr, "DATA\n"); |
---|
[1] | 2208 | #endif |
---|
[541] | 2209 | xmlNodePtr cur4 = cur2->children; |
---|
| 2210 | while (cur4 != NULL) |
---|
| 2211 | { |
---|
| 2212 | while (cur4 != NULL |
---|
| 2213 | && cur4->type != XML_ELEMENT_NODE) |
---|
| 2214 | cur4 = cur4->next; |
---|
| 2215 | if (cur4 == NULL) |
---|
| 2216 | break; |
---|
| 2217 | if (xmlStrcasecmp |
---|
| 2218 | (cur4->name, BAD_CAST "LiteralData") == 0) |
---|
| 2219 | { |
---|
| 2220 | /** |
---|
[9] | 2221 | * Get every attribute from a LiteralData node |
---|
| 2222 | * dataType , uom |
---|
| 2223 | */ |
---|
[541] | 2224 | char *list[2]; |
---|
| 2225 | list[0] = zStrdup ("dataType"); |
---|
| 2226 | list[1] = zStrdup ("uom"); |
---|
| 2227 | for (int l = 0; l < 2; l++) |
---|
| 2228 | { |
---|
[1] | 2229 | #ifdef DEBUG |
---|
[541] | 2230 | fprintf (stderr, "*** LiteralData %s ***", |
---|
| 2231 | list[l]); |
---|
[1] | 2232 | #endif |
---|
[541] | 2233 | xmlChar *val = |
---|
| 2234 | xmlGetProp (cur4, BAD_CAST list[l]); |
---|
| 2235 | if (val != NULL |
---|
| 2236 | && strlen ((char *) val) > 0) |
---|
| 2237 | { |
---|
| 2238 | if (tmpmaps->content != NULL) |
---|
| 2239 | addToMap (tmpmaps->content, list[l], |
---|
| 2240 | (char *) val); |
---|
| 2241 | else |
---|
| 2242 | tmpmaps->content = |
---|
| 2243 | createMap (list[l], (char *) val); |
---|
[1] | 2244 | #ifdef DEBUG |
---|
[541] | 2245 | fprintf (stderr, "%s\n", val); |
---|
[1] | 2246 | #endif |
---|
[541] | 2247 | } |
---|
| 2248 | xmlFree (val); |
---|
| 2249 | free (list[l]); |
---|
| 2250 | } |
---|
| 2251 | } |
---|
| 2252 | else |
---|
| 2253 | if (xmlStrcasecmp |
---|
| 2254 | (cur4->name, BAD_CAST "ComplexData") == 0) |
---|
| 2255 | { |
---|
| 2256 | /** |
---|
[9] | 2257 | * Get every attribute from a Reference node |
---|
| 2258 | * mimeType, encoding, schema |
---|
| 2259 | */ |
---|
[541] | 2260 | const char *coms[3] = |
---|
| 2261 | { "mimeType", "encoding", "schema" }; |
---|
| 2262 | for (int l = 0; l < 3; l++) |
---|
| 2263 | { |
---|
[1] | 2264 | #ifdef DEBUG |
---|
[541] | 2265 | fprintf (stderr, "*** ComplexData %s ***\n", |
---|
| 2266 | coms[l]); |
---|
[1] | 2267 | #endif |
---|
[541] | 2268 | xmlChar *val = |
---|
| 2269 | xmlGetProp (cur4, BAD_CAST coms[l]); |
---|
| 2270 | if (val != NULL |
---|
| 2271 | && strlen ((char *) val) > 0) |
---|
| 2272 | { |
---|
| 2273 | if (tmpmaps->content != NULL) |
---|
| 2274 | addToMap (tmpmaps->content, coms[l], |
---|
| 2275 | (char *) val); |
---|
| 2276 | else |
---|
| 2277 | tmpmaps->content = |
---|
| 2278 | createMap (coms[l], (char *) val); |
---|
[1] | 2279 | #ifdef DEBUG |
---|
[541] | 2280 | fprintf (stderr, "%s\n", val); |
---|
[1] | 2281 | #endif |
---|
[541] | 2282 | } |
---|
| 2283 | xmlFree (val); |
---|
| 2284 | } |
---|
| 2285 | } |
---|
[280] | 2286 | |
---|
[541] | 2287 | map *test = getMap (tmpmaps->content, "encoding"); |
---|
| 2288 | if (test == NULL) |
---|
| 2289 | { |
---|
| 2290 | if (tmpmaps->content != NULL) |
---|
| 2291 | addToMap (tmpmaps->content, "encoding", |
---|
| 2292 | "utf-8"); |
---|
| 2293 | else |
---|
| 2294 | tmpmaps->content = |
---|
| 2295 | createMap ("encoding", "utf-8"); |
---|
| 2296 | test = getMap (tmpmaps->content, "encoding"); |
---|
| 2297 | } |
---|
[280] | 2298 | |
---|
[541] | 2299 | if (strcasecmp (test->value, "base64") != 0) |
---|
| 2300 | { |
---|
| 2301 | xmlChar *mv = xmlNodeListGetString (doc, |
---|
| 2302 | cur4-> |
---|
| 2303 | xmlChildrenNode, |
---|
| 2304 | 1); |
---|
| 2305 | map *ltmp = |
---|
| 2306 | getMap (tmpmaps->content, "mimeType"); |
---|
| 2307 | if (mv == NULL |
---|
| 2308 | || |
---|
| 2309 | (xmlStrcasecmp |
---|
| 2310 | (cur4->name, BAD_CAST "ComplexData") == 0 |
---|
| 2311 | && (ltmp == NULL |
---|
| 2312 | || strncasecmp (ltmp->value, |
---|
| 2313 | "text/xml", 8) == 0))) |
---|
| 2314 | { |
---|
| 2315 | xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); |
---|
| 2316 | int buffersize; |
---|
| 2317 | xmlNodePtr cur5 = cur4->children; |
---|
| 2318 | while (cur5 != NULL |
---|
| 2319 | && cur5->type != XML_ELEMENT_NODE |
---|
| 2320 | && cur5->type != |
---|
| 2321 | XML_CDATA_SECTION_NODE) |
---|
| 2322 | cur5 = cur5->next; |
---|
| 2323 | if (cur5 != NULL |
---|
| 2324 | && cur5->type != XML_CDATA_SECTION_NODE) |
---|
| 2325 | { |
---|
| 2326 | xmlDocSetRootElement (doc1, cur5); |
---|
| 2327 | xmlDocDumpFormatMemoryEnc (doc1, &mv, |
---|
| 2328 | &buffersize, |
---|
| 2329 | "utf-8", 1); |
---|
| 2330 | char size[1024]; |
---|
| 2331 | sprintf (size, "%d", buffersize); |
---|
| 2332 | addToMap (tmpmaps->content, "size", |
---|
| 2333 | size); |
---|
| 2334 | xmlFreeDoc (doc1); |
---|
| 2335 | } |
---|
| 2336 | } |
---|
| 2337 | if (mv != NULL) |
---|
| 2338 | { |
---|
| 2339 | addToMap (tmpmaps->content, "value", |
---|
| 2340 | (char *) mv); |
---|
| 2341 | xmlFree (mv); |
---|
| 2342 | } |
---|
| 2343 | } |
---|
| 2344 | else |
---|
| 2345 | { |
---|
| 2346 | xmlChar *tmp = xmlNodeListGetRawString (doc, |
---|
| 2347 | cur4->xmlChildrenNode, |
---|
| 2348 | 0); |
---|
| 2349 | addToMap (tmpmaps->content, "value", |
---|
| 2350 | (char *) tmp); |
---|
| 2351 | map *tmpv = getMap (tmpmaps->content, "value"); |
---|
| 2352 | char *res = NULL; |
---|
| 2353 | char *curs = tmpv->value; |
---|
| 2354 | for (int i = 0; i <= strlen (tmpv->value) / 64; |
---|
| 2355 | i++) |
---|
| 2356 | { |
---|
| 2357 | if (res == NULL) |
---|
| 2358 | res = |
---|
| 2359 | (char *) malloc (67 * sizeof (char)); |
---|
| 2360 | else |
---|
| 2361 | res = |
---|
| 2362 | (char *) realloc (res, |
---|
| 2363 | (((i + 1) * 65) + |
---|
| 2364 | i) * sizeof (char)); |
---|
| 2365 | int csize = i * 65; |
---|
| 2366 | strncpy (res + csize, curs, 64); |
---|
| 2367 | if (i == xmlStrlen (tmp) / 64) |
---|
| 2368 | strcat (res, "\n\0"); |
---|
| 2369 | else |
---|
| 2370 | { |
---|
| 2371 | strncpy (res + (((i + 1) * 64) + i), |
---|
| 2372 | "\n\0", 2); |
---|
| 2373 | curs += 64; |
---|
| 2374 | } |
---|
| 2375 | } |
---|
| 2376 | free (tmpv->value); |
---|
| 2377 | tmpv->value = zStrdup (res); |
---|
| 2378 | free (res); |
---|
| 2379 | xmlFree (tmp); |
---|
| 2380 | } |
---|
| 2381 | cur4 = cur4->next; |
---|
| 2382 | } |
---|
| 2383 | } |
---|
[1] | 2384 | #ifdef DEBUG |
---|
[541] | 2385 | fprintf (stderr, "cur2 next \n"); |
---|
| 2386 | fflush (stderr); |
---|
[1] | 2387 | #endif |
---|
[541] | 2388 | cur2 = cur2->next; |
---|
| 2389 | } |
---|
[1] | 2390 | #ifdef DEBUG |
---|
[541] | 2391 | fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n"); |
---|
| 2392 | fflush (stderr); |
---|
[1] | 2393 | #endif |
---|
[360] | 2394 | |
---|
[541] | 2395 | { |
---|
| 2396 | maps *testPresence = |
---|
| 2397 | getMaps (request_input_real_format, tmpmaps->name); |
---|
| 2398 | if (testPresence != NULL) |
---|
| 2399 | { |
---|
| 2400 | elements *elem = getElements (s1->inputs, tmpmaps->name); |
---|
| 2401 | if (elem != NULL) |
---|
| 2402 | { |
---|
| 2403 | if (appendMapsToMaps |
---|
| 2404 | (m, request_input_real_format, tmpmaps, elem) < 0) |
---|
| 2405 | { |
---|
| 2406 | freeMaps (&m); |
---|
| 2407 | free (m); |
---|
| 2408 | free (REQUEST); |
---|
| 2409 | free (SERVICE_URL); |
---|
| 2410 | InternetCloseHandle (&hInternet); |
---|
| 2411 | freeService (&s1); |
---|
| 2412 | free (s1); |
---|
| 2413 | return 0; |
---|
| 2414 | } |
---|
| 2415 | } |
---|
| 2416 | } |
---|
| 2417 | else |
---|
| 2418 | addMapsToMaps (&request_input_real_format, tmpmaps); |
---|
| 2419 | } |
---|
[418] | 2420 | |
---|
[1] | 2421 | #ifdef DEBUG |
---|
[541] | 2422 | fprintf (stderr, "******TMPMAPS*****\n"); |
---|
| 2423 | dumpMaps (tmpmaps); |
---|
| 2424 | fprintf (stderr, "******REQUESTMAPS*****\n"); |
---|
| 2425 | dumpMaps (request_input_real_format); |
---|
[1] | 2426 | #endif |
---|
[541] | 2427 | freeMaps (&tmpmaps); |
---|
| 2428 | free (tmpmaps); |
---|
| 2429 | tmpmaps = NULL; |
---|
| 2430 | } |
---|
[25] | 2431 | #ifdef DEBUG |
---|
[541] | 2432 | dumpMaps (tmpmaps); |
---|
[25] | 2433 | #endif |
---|
[541] | 2434 | } |
---|
[1] | 2435 | #ifdef DEBUG |
---|
[541] | 2436 | fprintf (stderr, "Search for response document node\n"); |
---|
[9] | 2437 | #endif |
---|
[541] | 2438 | xmlXPathFreeObject (tmpsptr); |
---|
| 2439 | |
---|
| 2440 | tmpsptr = |
---|
| 2441 | extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); |
---|
| 2442 | bool asRaw = false; |
---|
| 2443 | tmps = tmpsptr->nodesetval; |
---|
| 2444 | if (tmps->nodeNr == 0) |
---|
| 2445 | { |
---|
| 2446 | xmlXPathFreeObject (tmpsptr); |
---|
| 2447 | tmpsptr = |
---|
| 2448 | extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); |
---|
| 2449 | tmps = tmpsptr->nodesetval; |
---|
| 2450 | asRaw = true; |
---|
| 2451 | } |
---|
[9] | 2452 | #ifdef DEBUG |
---|
[541] | 2453 | fprintf (stderr, "*****%d*****\n", tmps->nodeNr); |
---|
[1] | 2454 | #endif |
---|
[541] | 2455 | if (asRaw == true) |
---|
| 2456 | { |
---|
| 2457 | addToMap (request_inputs, "RawDataOutput", ""); |
---|
| 2458 | xmlNodePtr cur0 = tmps->nodeTab[0]; |
---|
| 2459 | if (cur0->type == XML_ELEMENT_NODE) |
---|
| 2460 | { |
---|
| 2461 | |
---|
| 2462 | maps *tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2463 | if (tmpmaps == NULL) |
---|
| 2464 | { |
---|
| 2465 | return errorException (m, _("Unable to allocate memory."), |
---|
| 2466 | "InternalError", NULL); |
---|
| 2467 | } |
---|
| 2468 | tmpmaps->name = zStrdup ("unknownIdentifier"); |
---|
| 2469 | tmpmaps->content = NULL; |
---|
| 2470 | tmpmaps->next = NULL; |
---|
| 2471 | |
---|
| 2472 | /** |
---|
[502] | 2473 | * Get every attribute from a RawDataOutput node |
---|
| 2474 | * mimeType, encoding, schema, uom |
---|
[1] | 2475 | */ |
---|
[541] | 2476 | const char *outs[4] = |
---|
| 2477 | { "mimeType", "encoding", "schema", "uom" }; |
---|
| 2478 | for (int l = 0; l < 4; l++) |
---|
| 2479 | { |
---|
[1] | 2480 | #ifdef DEBUG |
---|
[541] | 2481 | fprintf (stderr, "*** %s ***\t", outs[l]); |
---|
[1] | 2482 | #endif |
---|
[541] | 2483 | xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]); |
---|
| 2484 | if (val != NULL) |
---|
| 2485 | { |
---|
| 2486 | if (strlen ((char *) val) > 0) |
---|
| 2487 | { |
---|
| 2488 | if (tmpmaps->content != NULL) |
---|
| 2489 | addToMap (tmpmaps->content, outs[l], |
---|
| 2490 | (char *) val); |
---|
| 2491 | else |
---|
| 2492 | tmpmaps->content = |
---|
| 2493 | createMap (outs[l], (char *) val); |
---|
| 2494 | } |
---|
| 2495 | xmlFree (val); |
---|
| 2496 | } |
---|
| 2497 | } |
---|
| 2498 | xmlNodePtr cur2 = cur0->children; |
---|
| 2499 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 2500 | cur2 = cur2->next; |
---|
| 2501 | while (cur2 != NULL) |
---|
| 2502 | { |
---|
| 2503 | if (xmlStrncasecmp |
---|
| 2504 | (cur2->name, BAD_CAST "Identifier", |
---|
| 2505 | xmlStrlen (cur2->name)) == 0) |
---|
| 2506 | { |
---|
| 2507 | xmlChar *val = |
---|
| 2508 | xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1); |
---|
| 2509 | free (tmpmaps->name); |
---|
| 2510 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 2511 | xmlFree (val); |
---|
| 2512 | } |
---|
| 2513 | cur2 = cur2->next; |
---|
| 2514 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 2515 | cur2 = cur2->next; |
---|
| 2516 | } |
---|
| 2517 | if (request_output_real_format == NULL) |
---|
| 2518 | request_output_real_format = dupMaps (&tmpmaps); |
---|
| 2519 | else |
---|
| 2520 | addMapsToMaps (&request_output_real_format, tmpmaps); |
---|
| 2521 | if (tmpmaps != NULL) |
---|
| 2522 | { |
---|
| 2523 | freeMaps (&tmpmaps); |
---|
| 2524 | free (tmpmaps); |
---|
| 2525 | tmpmaps = NULL; |
---|
| 2526 | } |
---|
| 2527 | } |
---|
| 2528 | } |
---|
| 2529 | else |
---|
| 2530 | for (int k = 0; k < tmps->nodeNr; k++) |
---|
| 2531 | { |
---|
| 2532 | //else |
---|
| 2533 | addToMap (request_inputs, "ResponseDocument", ""); |
---|
| 2534 | maps *tmpmaps = NULL; |
---|
| 2535 | xmlNodePtr cur = tmps->nodeTab[k]; |
---|
| 2536 | if (cur->type == XML_ELEMENT_NODE) |
---|
| 2537 | { |
---|
| 2538 | /** |
---|
[502] | 2539 | * A specific responseDocument node. |
---|
[280] | 2540 | */ |
---|
[541] | 2541 | if (tmpmaps == NULL) |
---|
| 2542 | { |
---|
| 2543 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2544 | if (tmpmaps == NULL) |
---|
| 2545 | { |
---|
| 2546 | return errorException (m, |
---|
| 2547 | _ |
---|
| 2548 | ("Unable to allocate memory."), |
---|
| 2549 | "InternalError", NULL); |
---|
| 2550 | } |
---|
| 2551 | tmpmaps->name = zStrdup ("unknownIdentifier"); |
---|
| 2552 | tmpmaps->content = NULL; |
---|
| 2553 | tmpmaps->next = NULL; |
---|
| 2554 | } |
---|
| 2555 | /** |
---|
[502] | 2556 | * Get every attribute: storeExecuteResponse, lineage, status |
---|
[280] | 2557 | */ |
---|
[541] | 2558 | const char *ress[3] = |
---|
| 2559 | { "storeExecuteResponse", "lineage", "status" }; |
---|
| 2560 | xmlChar *val; |
---|
| 2561 | for (int l = 0; l < 3; l++) |
---|
| 2562 | { |
---|
[502] | 2563 | #ifdef DEBUG |
---|
[541] | 2564 | fprintf (stderr, "*** %s ***\t", ress[l]); |
---|
[502] | 2565 | #endif |
---|
[541] | 2566 | val = xmlGetProp (cur, BAD_CAST ress[l]); |
---|
| 2567 | if (val != NULL && strlen ((char *) val) > 0) |
---|
| 2568 | { |
---|
| 2569 | if (tmpmaps->content != NULL) |
---|
| 2570 | addToMap (tmpmaps->content, ress[l], (char *) val); |
---|
| 2571 | else |
---|
| 2572 | tmpmaps->content = |
---|
| 2573 | createMap (ress[l], (char *) val); |
---|
| 2574 | addToMap (request_inputs, ress[l], (char *) val); |
---|
| 2575 | } |
---|
[502] | 2576 | #ifdef DEBUG |
---|
[541] | 2577 | fprintf (stderr, "%s\n", val); |
---|
[502] | 2578 | #endif |
---|
[541] | 2579 | xmlFree (val); |
---|
| 2580 | } |
---|
| 2581 | xmlNodePtr cur1 = cur->children; |
---|
| 2582 | while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE) |
---|
| 2583 | cur1 = cur1->next; |
---|
| 2584 | int cur1cnt = 0; |
---|
| 2585 | while (cur1) |
---|
| 2586 | { |
---|
| 2587 | /** |
---|
[502] | 2588 | * Indentifier |
---|
[1] | 2589 | */ |
---|
[541] | 2590 | if (xmlStrncasecmp |
---|
| 2591 | (cur1->name, BAD_CAST "Identifier", |
---|
| 2592 | xmlStrlen (cur1->name)) == 0) |
---|
| 2593 | { |
---|
| 2594 | xmlChar *val = |
---|
| 2595 | xmlNodeListGetString (doc, cur1->xmlChildrenNode, |
---|
| 2596 | 1); |
---|
| 2597 | if (tmpmaps == NULL) |
---|
| 2598 | { |
---|
| 2599 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2600 | if (tmpmaps == NULL) |
---|
| 2601 | { |
---|
| 2602 | return errorException (m, |
---|
| 2603 | _ |
---|
| 2604 | ("Unable to allocate memory."), |
---|
| 2605 | "InternalError", NULL); |
---|
| 2606 | } |
---|
| 2607 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 2608 | tmpmaps->content = NULL; |
---|
| 2609 | tmpmaps->next = NULL; |
---|
| 2610 | } |
---|
| 2611 | else |
---|
| 2612 | { |
---|
| 2613 | free (tmpmaps->name); |
---|
| 2614 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 2615 | } |
---|
| 2616 | if (asRaw == true) |
---|
| 2617 | addToMap (request_inputs, "RawDataOutput", |
---|
| 2618 | (char *) val); |
---|
| 2619 | else |
---|
| 2620 | { |
---|
| 2621 | if (cur1cnt == 0) |
---|
| 2622 | addToMap (request_inputs, "ResponseDocument", |
---|
| 2623 | (char *) val); |
---|
| 2624 | else |
---|
| 2625 | { |
---|
| 2626 | map *tt = |
---|
| 2627 | getMap (request_inputs, "ResponseDocument"); |
---|
| 2628 | char *tmp = zStrdup (tt->value); |
---|
| 2629 | free (tt->value); |
---|
| 2630 | tt->value = |
---|
| 2631 | (char *) |
---|
| 2632 | malloc ((strlen (tmp) + |
---|
| 2633 | strlen ((char *) val) + |
---|
| 2634 | 1) * sizeof (char)); |
---|
| 2635 | sprintf (tt->value, "%s;%s", tmp, |
---|
| 2636 | (char *) val); |
---|
| 2637 | free (tmp); |
---|
| 2638 | } |
---|
| 2639 | } |
---|
| 2640 | cur1cnt += 1; |
---|
| 2641 | xmlFree (val); |
---|
| 2642 | } |
---|
| 2643 | /** |
---|
[502] | 2644 | * Title, Asbtract |
---|
| 2645 | */ |
---|
[541] | 2646 | else |
---|
| 2647 | if (xmlStrncasecmp |
---|
| 2648 | (cur1->name, BAD_CAST "Title", |
---|
| 2649 | xmlStrlen (cur1->name)) == 0 |
---|
| 2650 | || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract", |
---|
| 2651 | xmlStrlen (cur1->name)) == 0) |
---|
| 2652 | { |
---|
| 2653 | xmlChar *val = |
---|
| 2654 | xmlNodeListGetString (doc, cur1->xmlChildrenNode, |
---|
| 2655 | 1); |
---|
| 2656 | if (tmpmaps == NULL) |
---|
| 2657 | { |
---|
| 2658 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2659 | if (tmpmaps == NULL) |
---|
| 2660 | { |
---|
| 2661 | return errorException (m, |
---|
| 2662 | _ |
---|
| 2663 | ("Unable to allocate memory."), |
---|
| 2664 | "InternalError", NULL); |
---|
| 2665 | } |
---|
| 2666 | tmpmaps->name = zStrdup ("missingIndetifier"); |
---|
| 2667 | tmpmaps->content = |
---|
| 2668 | createMap ((char *) cur1->name, (char *) val); |
---|
| 2669 | tmpmaps->next = NULL; |
---|
| 2670 | } |
---|
| 2671 | else |
---|
| 2672 | { |
---|
| 2673 | if (tmpmaps->content != NULL) |
---|
| 2674 | addToMap (tmpmaps->content, (char *) cur1->name, |
---|
| 2675 | (char *) val); |
---|
| 2676 | else |
---|
| 2677 | tmpmaps->content = |
---|
| 2678 | createMap ((char *) cur1->name, (char *) val); |
---|
| 2679 | } |
---|
| 2680 | xmlFree (val); |
---|
| 2681 | } |
---|
| 2682 | else |
---|
| 2683 | if (xmlStrncasecmp |
---|
| 2684 | (cur1->name, BAD_CAST "Output", |
---|
| 2685 | xmlStrlen (cur1->name)) == 0) |
---|
| 2686 | { |
---|
| 2687 | /** |
---|
[579] | 2688 | * Get every attribute from an Output node |
---|
[502] | 2689 | * mimeType, encoding, schema, uom, asReference |
---|
[1] | 2690 | */ |
---|
[541] | 2691 | const char *outs[5] = |
---|
| 2692 | { "mimeType", "encoding", "schema", "uom", |
---|
| 2693 | "asReference" |
---|
| 2694 | }; |
---|
| 2695 | for (int l = 0; l < 5; l++) |
---|
| 2696 | { |
---|
[502] | 2697 | #ifdef DEBUG |
---|
[541] | 2698 | fprintf (stderr, "*** %s ***\t", outs[l]); |
---|
[502] | 2699 | #endif |
---|
[541] | 2700 | xmlChar *val = |
---|
| 2701 | xmlGetProp (cur1, BAD_CAST outs[l]); |
---|
| 2702 | if (val != NULL && strlen ((char *) val) > 0) |
---|
| 2703 | { |
---|
| 2704 | if (tmpmaps->content != NULL) |
---|
| 2705 | addToMap (tmpmaps->content, outs[l], |
---|
| 2706 | (char *) val); |
---|
| 2707 | else |
---|
| 2708 | tmpmaps->content = |
---|
| 2709 | createMap (outs[l], (char *) val); |
---|
| 2710 | } |
---|
[502] | 2711 | #ifdef DEBUG |
---|
[541] | 2712 | fprintf (stderr, "%s\n", val); |
---|
[502] | 2713 | #endif |
---|
[541] | 2714 | xmlFree (val); |
---|
| 2715 | } |
---|
| 2716 | xmlNodePtr cur2 = cur1->children; |
---|
| 2717 | while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) |
---|
| 2718 | cur2 = cur2->next; |
---|
| 2719 | while (cur2) |
---|
| 2720 | { |
---|
| 2721 | /** |
---|
[502] | 2722 | * Indentifier |
---|
| 2723 | */ |
---|
[541] | 2724 | if (xmlStrncasecmp |
---|
| 2725 | (cur2->name, BAD_CAST "Identifier", |
---|
| 2726 | xmlStrlen (cur2->name)) == 0) |
---|
| 2727 | { |
---|
| 2728 | xmlChar *val = xmlNodeListGetString (doc, |
---|
| 2729 | cur2-> |
---|
| 2730 | xmlChildrenNode, |
---|
| 2731 | 1); |
---|
| 2732 | if (tmpmaps == NULL) |
---|
| 2733 | { |
---|
| 2734 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2735 | if (tmpmaps == NULL) |
---|
| 2736 | { |
---|
| 2737 | return errorException (m, |
---|
| 2738 | _ |
---|
| 2739 | ("Unable to allocate memory."), |
---|
| 2740 | "InternalError", |
---|
| 2741 | NULL); |
---|
| 2742 | } |
---|
| 2743 | tmpmaps->name = zStrdup ((char *) val); |
---|
| 2744 | tmpmaps->content = NULL; |
---|
| 2745 | tmpmaps->next = NULL; |
---|
| 2746 | } |
---|
| 2747 | else |
---|
| 2748 | { |
---|
| 2749 | if (tmpmaps->name != NULL) |
---|
| 2750 | free (tmpmaps->name); |
---|
| 2751 | tmpmaps->name = zStrdup ((char *) val);; |
---|
| 2752 | } |
---|
| 2753 | xmlFree (val); |
---|
| 2754 | } |
---|
| 2755 | /** |
---|
[502] | 2756 | * Title, Asbtract |
---|
| 2757 | */ |
---|
[541] | 2758 | else |
---|
| 2759 | if (xmlStrncasecmp |
---|
| 2760 | (cur2->name, BAD_CAST "Title", |
---|
| 2761 | xmlStrlen (cur2->name)) == 0 |
---|
| 2762 | || xmlStrncasecmp (cur2->name, |
---|
| 2763 | BAD_CAST "Abstract", |
---|
| 2764 | xmlStrlen (cur2->name)) |
---|
| 2765 | == 0) |
---|
| 2766 | { |
---|
| 2767 | xmlChar *val = xmlNodeListGetString (doc, |
---|
| 2768 | cur2-> |
---|
| 2769 | xmlChildrenNode, |
---|
| 2770 | 1); |
---|
| 2771 | if (tmpmaps == NULL) |
---|
| 2772 | { |
---|
| 2773 | tmpmaps = (maps *) malloc (MAPS_SIZE); |
---|
| 2774 | if (tmpmaps == NULL) |
---|
| 2775 | { |
---|
| 2776 | return errorException (m, |
---|
| 2777 | _ |
---|
| 2778 | ("Unable to allocate memory."), |
---|
| 2779 | "InternalError", |
---|
| 2780 | NULL); |
---|
| 2781 | } |
---|
| 2782 | tmpmaps->name = |
---|
| 2783 | zStrdup ("missingIndetifier"); |
---|
| 2784 | tmpmaps->content = |
---|
| 2785 | createMap ((char *) cur2->name, |
---|
| 2786 | (char *) val); |
---|
| 2787 | tmpmaps->next = NULL; |
---|
| 2788 | } |
---|
| 2789 | else |
---|
| 2790 | { |
---|
| 2791 | if (tmpmaps->content != NULL) |
---|
| 2792 | addToMap (tmpmaps->content, |
---|
| 2793 | (char *) cur2->name, |
---|
| 2794 | (char *) val); |
---|
| 2795 | else |
---|
| 2796 | tmpmaps->content = |
---|
| 2797 | createMap ((char *) cur2->name, |
---|
| 2798 | (char *) val); |
---|
| 2799 | } |
---|
| 2800 | xmlFree (val); |
---|
| 2801 | } |
---|
| 2802 | cur2 = cur2->next; |
---|
| 2803 | while (cur2 != NULL |
---|
| 2804 | && cur2->type != XML_ELEMENT_NODE) |
---|
| 2805 | cur2 = cur2->next; |
---|
| 2806 | } |
---|
| 2807 | } |
---|
| 2808 | cur1 = cur1->next; |
---|
| 2809 | while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE) |
---|
| 2810 | cur1 = cur1->next; |
---|
| 2811 | } |
---|
| 2812 | } |
---|
| 2813 | if (request_output_real_format == NULL) |
---|
| 2814 | request_output_real_format = dupMaps (&tmpmaps); |
---|
| 2815 | else |
---|
| 2816 | addMapsToMaps (&request_output_real_format, tmpmaps); |
---|
| 2817 | if (tmpmaps != NULL) |
---|
| 2818 | { |
---|
| 2819 | freeMaps (&tmpmaps); |
---|
| 2820 | free (tmpmaps); |
---|
| 2821 | tmpmaps = NULL; |
---|
| 2822 | } |
---|
| 2823 | } |
---|
| 2824 | xmlXPathFreeObject (tmpsptr); |
---|
| 2825 | xmlFreeDoc (doc); |
---|
| 2826 | xmlCleanupParser (); |
---|
| 2827 | } |
---|
[392] | 2828 | |
---|
[541] | 2829 | runHttpRequests (&m, &request_input_real_format, &hInternet); |
---|
| 2830 | |
---|
[392] | 2831 | // if(CHECK_INET_HANDLE(hInternet)) |
---|
[541] | 2832 | InternetCloseHandle (&hInternet); |
---|
[1] | 2833 | |
---|
| 2834 | #ifdef DEBUG |
---|
[541] | 2835 | fprintf (stderr, "\n%d\n", __LINE__); |
---|
| 2836 | fflush (stderr); |
---|
| 2837 | dumpMaps (request_input_real_format); |
---|
| 2838 | dumpMaps (request_output_real_format); |
---|
| 2839 | dumpMap (request_inputs); |
---|
| 2840 | fprintf (stderr, "\n%d\n", __LINE__); |
---|
| 2841 | fflush (stderr); |
---|
[1] | 2842 | #endif |
---|
| 2843 | |
---|
| 2844 | /** |
---|
| 2845 | * Ensure that each requested arguments are present in the request |
---|
| 2846 | * DataInputs and ResponseDocument / RawDataOutput |
---|
[92] | 2847 | */ |
---|
[576] | 2848 | map* errI=NULL; |
---|
[578] | 2849 | #ifdef DEBUG |
---|
[576] | 2850 | dumpMaps(request_input_real_format); |
---|
[578] | 2851 | #endif |
---|
[576] | 2852 | char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI); |
---|
[578] | 2853 | #ifdef DEBUG |
---|
[576] | 2854 | dumpMaps(request_input_real_format); |
---|
[578] | 2855 | #endif |
---|
[541] | 2856 | maps *ptr = request_input_real_format; |
---|
| 2857 | while (ptr != NULL) |
---|
| 2858 | { |
---|
| 2859 | map *tmp0 = getMap (ptr->content, "size"); |
---|
| 2860 | map *tmp1 = getMap (ptr->content, "maximumMegabytes"); |
---|
| 2861 | if (tmp1 != NULL && tmp0 != NULL) |
---|
| 2862 | { |
---|
| 2863 | float i = atof (tmp0->value) / 1048576.0; |
---|
| 2864 | if (i >= atoi (tmp1->value)) |
---|
| 2865 | { |
---|
| 2866 | char tmps[1024]; |
---|
| 2867 | map *tmpe = createMap ("code", "FileSizeExceeded"); |
---|
| 2868 | snprintf (tmps, 1024, |
---|
| 2869 | _ |
---|
| 2870 | ("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."), |
---|
| 2871 | ptr->name, tmp1->value, i); |
---|
| 2872 | addToMap (tmpe, "locator", ptr->name); |
---|
| 2873 | addToMap (tmpe, "text", tmps); |
---|
| 2874 | printExceptionReportResponse (m, tmpe); |
---|
| 2875 | freeService (&s1); |
---|
| 2876 | free (s1); |
---|
| 2877 | freeMap (&tmpe); |
---|
| 2878 | free (tmpe); |
---|
| 2879 | freeMaps (&m); |
---|
| 2880 | free (m); |
---|
| 2881 | free (REQUEST); |
---|
| 2882 | free (SERVICE_URL); |
---|
| 2883 | freeMaps (&request_input_real_format); |
---|
| 2884 | free (request_input_real_format); |
---|
| 2885 | freeMaps (&request_output_real_format); |
---|
| 2886 | free (request_output_real_format); |
---|
| 2887 | freeMaps (&tmpmaps); |
---|
| 2888 | free (tmpmaps); |
---|
| 2889 | return 1; |
---|
| 2890 | } |
---|
| 2891 | } |
---|
| 2892 | ptr = ptr->next; |
---|
[485] | 2893 | } |
---|
| 2894 | |
---|
[576] | 2895 | map* errO=NULL; |
---|
[541] | 2896 | char *dfv1 = |
---|
[576] | 2897 | addDefaultValues (&request_output_real_format, s1->outputs, m, 1,&errO); |
---|
[541] | 2898 | if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0) |
---|
| 2899 | { |
---|
| 2900 | char tmps[1024]; |
---|
[576] | 2901 | map *tmpe = NULL; |
---|
[541] | 2902 | if (strcmp (dfv, "") != 0) |
---|
| 2903 | { |
---|
[576] | 2904 | tmpe = createMap ("code", "MissingParameterValue"); |
---|
| 2905 | int nb=0; |
---|
| 2906 | int length=1; |
---|
| 2907 | map* len=getMap(errI,"length"); |
---|
| 2908 | if(len!=NULL) |
---|
| 2909 | length=atoi(len->value); |
---|
| 2910 | for(nb=0;nb<length;nb++){ |
---|
| 2911 | map* errp=getMapArray(errI,"value",nb); |
---|
| 2912 | snprintf (tmps, 1024, |
---|
| 2913 | _ |
---|
| 2914 | ("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."), |
---|
| 2915 | errp->value); |
---|
| 2916 | setMapArray (tmpe, "locator", nb , errp->value); |
---|
| 2917 | setMapArray (tmpe, "text", nb , tmps); |
---|
| 2918 | setMapArray (tmpe, "code", nb , "MissingParameterValue"); |
---|
| 2919 | } |
---|
| 2920 | } |
---|
| 2921 | if (strcmp (dfv1, "") != 0) |
---|
[541] | 2922 | { |
---|
[576] | 2923 | int ilength=0; |
---|
| 2924 | if(tmpe==NULL) |
---|
| 2925 | tmpe = createMap ("code", "InvalidParameterValue"); |
---|
| 2926 | else{ |
---|
| 2927 | map* len=getMap(tmpe,"length"); |
---|
| 2928 | if(len!=NULL) |
---|
| 2929 | ilength=atoi(len->value); |
---|
| 2930 | } |
---|
| 2931 | int nb=0; |
---|
| 2932 | int length=1; |
---|
| 2933 | map* len=getMap(errO,"length"); |
---|
| 2934 | if(len!=NULL) |
---|
| 2935 | length=atoi(len->value); |
---|
| 2936 | for(nb=0;nb<length;nb++){ |
---|
| 2937 | map* errp=getMapArray(errO,"value",nb); |
---|
| 2938 | snprintf (tmps, 1024, |
---|
| 2939 | _ |
---|
| 2940 | ("The <%s> argument was specified as %s identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."), |
---|
| 2941 | errp->value, |
---|
| 2942 | ((getMap(request_inputs,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument")); |
---|
| 2943 | setMapArray (tmpe, "locator", nb+ilength , errp->value); |
---|
| 2944 | setMapArray (tmpe, "text", nb+ilength , tmps); |
---|
| 2945 | setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue"); |
---|
| 2946 | } |
---|
| 2947 | } |
---|
[541] | 2948 | printExceptionReportResponse (m, tmpe); |
---|
| 2949 | freeService (&s1); |
---|
| 2950 | free (s1); |
---|
| 2951 | freeMap (&tmpe); |
---|
| 2952 | free (tmpe); |
---|
| 2953 | freeMaps (&m); |
---|
| 2954 | free (m); |
---|
| 2955 | free (REQUEST); |
---|
| 2956 | free (SERVICE_URL); |
---|
| 2957 | freeMaps (&request_input_real_format); |
---|
| 2958 | free (request_input_real_format); |
---|
| 2959 | freeMaps (&request_output_real_format); |
---|
| 2960 | free (request_output_real_format); |
---|
| 2961 | freeMaps (&tmpmaps); |
---|
| 2962 | free (tmpmaps); |
---|
[576] | 2963 | if(errI!=NULL){ |
---|
| 2964 | freeMap(&errI); |
---|
| 2965 | free(errI); |
---|
| 2966 | } |
---|
| 2967 | if(errO!=NULL){ |
---|
| 2968 | freeMap(&errO); |
---|
| 2969 | free(errO); |
---|
| 2970 | } |
---|
[541] | 2971 | return 1; |
---|
[280] | 2972 | } |
---|
[541] | 2973 | maps *tmpReqI = request_input_real_format; |
---|
| 2974 | while (tmpReqI != NULL) |
---|
| 2975 | { |
---|
| 2976 | char name[1024]; |
---|
| 2977 | if (getMap (tmpReqI->content, "isFile") != NULL) |
---|
| 2978 | { |
---|
| 2979 | if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) == |
---|
| 2980 | cgiFormSuccess) |
---|
| 2981 | { |
---|
| 2982 | int BufferLen = 1024; |
---|
| 2983 | cgiFilePtr file; |
---|
| 2984 | int targetFile; |
---|
| 2985 | char storageNameOnServer[2048]; |
---|
| 2986 | char fileNameOnServer[64]; |
---|
| 2987 | char contentType[1024]; |
---|
| 2988 | char buffer[1024]; |
---|
| 2989 | char *tmpStr = NULL; |
---|
| 2990 | int size; |
---|
| 2991 | int got, t; |
---|
| 2992 | map *path = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 2993 | cgiFormFileSize (tmpReqI->name, &size); |
---|
| 2994 | cgiFormFileContentType (tmpReqI->name, contentType, |
---|
| 2995 | sizeof (contentType)); |
---|
| 2996 | if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess) |
---|
| 2997 | { |
---|
| 2998 | t = -1; |
---|
| 2999 | while (1) |
---|
| 3000 | { |
---|
| 3001 | tmpStr = strstr (name + t + 1, "\\"); |
---|
| 3002 | if (NULL == tmpStr) |
---|
| 3003 | tmpStr = strstr (name + t + 1, "/"); |
---|
| 3004 | if (NULL != tmpStr) |
---|
| 3005 | t = (int) (tmpStr - name); |
---|
| 3006 | else |
---|
| 3007 | break; |
---|
| 3008 | } |
---|
| 3009 | strcpy (fileNameOnServer, name + t + 1); |
---|
| 3010 | |
---|
| 3011 | sprintf (storageNameOnServer, "%s/%s", path->value, |
---|
| 3012 | fileNameOnServer); |
---|
[375] | 3013 | #ifdef DEBUG |
---|
[541] | 3014 | fprintf (stderr, "Name on server %s\n", |
---|
| 3015 | storageNameOnServer); |
---|
| 3016 | fprintf (stderr, "fileNameOnServer: %s\n", |
---|
| 3017 | fileNameOnServer); |
---|
[375] | 3018 | #endif |
---|
[541] | 3019 | targetFile = |
---|
| 3020 | open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, |
---|
| 3021 | S_IRWXU | S_IRGRP | S_IROTH); |
---|
| 3022 | if (targetFile < 0) |
---|
| 3023 | { |
---|
[375] | 3024 | #ifdef DEBUG |
---|
[541] | 3025 | fprintf (stderr, "could not create the new file,%s\n", |
---|
| 3026 | fileNameOnServer); |
---|
[375] | 3027 | #endif |
---|
[541] | 3028 | } |
---|
| 3029 | else |
---|
| 3030 | { |
---|
| 3031 | while (cgiFormFileRead (file, buffer, BufferLen, &got) |
---|
| 3032 | == cgiFormSuccess) |
---|
| 3033 | { |
---|
| 3034 | if (got > 0) |
---|
| 3035 | write (targetFile, buffer, got); |
---|
| 3036 | } |
---|
| 3037 | } |
---|
| 3038 | addToMap (tmpReqI->content, "lref", storageNameOnServer); |
---|
| 3039 | cgiFormFileClose (file); |
---|
| 3040 | close (targetFile); |
---|
[375] | 3041 | #ifdef DEBUG |
---|
[541] | 3042 | fprintf (stderr, "File \"%s\" has been uploaded", |
---|
| 3043 | fileNameOnServer); |
---|
[375] | 3044 | #endif |
---|
[541] | 3045 | } |
---|
| 3046 | } |
---|
| 3047 | } |
---|
| 3048 | tmpReqI = tmpReqI->next; |
---|
[331] | 3049 | } |
---|
| 3050 | |
---|
[541] | 3051 | ensureDecodedBase64 (&request_input_real_format); |
---|
[88] | 3052 | |
---|
[9] | 3053 | #ifdef DEBUG |
---|
[541] | 3054 | fprintf (stderr, "REQUEST_INPUTS\n"); |
---|
| 3055 | dumpMaps (request_input_real_format); |
---|
| 3056 | fprintf (stderr, "REQUEST_OUTPUTS\n"); |
---|
| 3057 | dumpMaps (request_output_real_format); |
---|
[9] | 3058 | #endif |
---|
[1] | 3059 | |
---|
[541] | 3060 | maps *curs = getMaps (m, "env"); |
---|
| 3061 | if (curs != NULL) |
---|
| 3062 | { |
---|
| 3063 | map *mapcs = curs->content; |
---|
| 3064 | while (mapcs != NULLMAP) |
---|
| 3065 | { |
---|
[1] | 3066 | #ifndef WIN32 |
---|
[541] | 3067 | setenv (mapcs->name, mapcs->value, 1); |
---|
[1] | 3068 | #else |
---|
| 3069 | #ifdef DEBUG |
---|
[541] | 3070 | fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, |
---|
| 3071 | mapcs->value); |
---|
[1] | 3072 | #endif |
---|
[541] | 3073 | if (mapcs->value[strlen (mapcs->value) - 2] == '\r') |
---|
| 3074 | { |
---|
[1] | 3075 | #ifdef DEBUG |
---|
[541] | 3076 | fprintf (stderr, "[ZOO: Env var finish with \r]\n"); |
---|
[1] | 3077 | #endif |
---|
[541] | 3078 | mapcs->value[strlen (mapcs->value) - 1] = 0; |
---|
| 3079 | } |
---|
[1] | 3080 | #ifdef DEBUG |
---|
[541] | 3081 | if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0) |
---|
| 3082 | { |
---|
| 3083 | fflush (stderr); |
---|
| 3084 | fprintf (stderr, "setting variable... %s\n", "OK"); |
---|
| 3085 | } |
---|
| 3086 | else |
---|
| 3087 | { |
---|
| 3088 | fflush (stderr); |
---|
| 3089 | fprintf (stderr, "setting variable... %s\n", "OK"); |
---|
| 3090 | } |
---|
[1] | 3091 | #else |
---|
[541] | 3092 | |
---|
| 3093 | |
---|
| 3094 | SetEnvironmentVariable (mapcs->name, mapcs->value); |
---|
[1] | 3095 | #endif |
---|
[541] | 3096 | char *toto = |
---|
| 3097 | (char *) |
---|
| 3098 | malloc ((strlen (mapcs->name) + strlen (mapcs->value) + |
---|
| 3099 | 2) * sizeof (char)); |
---|
| 3100 | sprintf (toto, "%s=%s", mapcs->name, mapcs->value); |
---|
| 3101 | putenv (toto); |
---|
[1] | 3102 | #ifdef DEBUG |
---|
[541] | 3103 | fflush (stderr); |
---|
[1] | 3104 | #endif |
---|
| 3105 | #endif |
---|
| 3106 | #ifdef DEBUG |
---|
[541] | 3107 | fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, |
---|
| 3108 | mapcs->value); |
---|
| 3109 | fflush (stderr); |
---|
[1] | 3110 | #endif |
---|
[541] | 3111 | mapcs = mapcs->next; |
---|
| 3112 | } |
---|
[1] | 3113 | } |
---|
[541] | 3114 | |
---|
[1] | 3115 | #ifdef DEBUG |
---|
[541] | 3116 | dumpMap (request_inputs); |
---|
[1] | 3117 | #endif |
---|
| 3118 | |
---|
| 3119 | /** |
---|
| 3120 | * Need to check if we need to fork to load a status enabled |
---|
| 3121 | */ |
---|
[541] | 3122 | r_inputs = NULL; |
---|
| 3123 | map *store = getMap (request_inputs, "storeExecuteResponse"); |
---|
| 3124 | map *status = getMap (request_inputs, "status"); |
---|
[72] | 3125 | /** |
---|
| 3126 | * 05-007r7 WPS 1.0.0 page 57 : |
---|
| 3127 | * 'If status="true" and storeExecuteResponse is "false" then the service |
---|
| 3128 | * shall raise an exception.' |
---|
| 3129 | */ |
---|
[541] | 3130 | if (status != NULL && strcmp (status->value, "true") == 0 && |
---|
| 3131 | store != NULL && strcmp (store->value, "false") == 0) |
---|
| 3132 | { |
---|
| 3133 | errorException (m, |
---|
| 3134 | _ |
---|
| 3135 | ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), |
---|
| 3136 | "InvalidParameterValue", "storeExecuteResponse"); |
---|
| 3137 | freeService (&s1); |
---|
| 3138 | free (s1); |
---|
| 3139 | freeMaps (&m); |
---|
| 3140 | free (m); |
---|
[94] | 3141 | |
---|
[541] | 3142 | freeMaps (&request_input_real_format); |
---|
| 3143 | free (request_input_real_format); |
---|
| 3144 | |
---|
| 3145 | freeMaps (&request_output_real_format); |
---|
| 3146 | free (request_output_real_format); |
---|
| 3147 | |
---|
| 3148 | free (REQUEST); |
---|
| 3149 | free (SERVICE_URL); |
---|
| 3150 | return 1; |
---|
| 3151 | } |
---|
| 3152 | r_inputs = getMap (request_inputs, "storeExecuteResponse"); |
---|
| 3153 | int eres = SERVICE_STARTED; |
---|
| 3154 | int cpid = getpid (); |
---|
| 3155 | |
---|
[453] | 3156 | /** |
---|
| 3157 | * Initialize the specific [lenv] section which contains runtime variables: |
---|
| 3158 | * |
---|
| 3159 | * - usid : it is an unique identification number |
---|
| 3160 | * - sid : it is the process idenfitication number (OS) |
---|
| 3161 | * - status : value between 0 and 100 to express the completude of |
---|
| 3162 | * the operations of the running service |
---|
| 3163 | * - message : is a string where you can store error messages, in case |
---|
| 3164 | * service is failing, or o provide details on the ongoing operation. |
---|
| 3165 | * - cwd : is the current working directory |
---|
| 3166 | * - soap : is a boolean value, true if the request was contained in a SOAP |
---|
| 3167 | * Envelop |
---|
| 3168 | * - sessid : string storing the session identifier (only when cookie is |
---|
| 3169 | * used) |
---|
| 3170 | * - cgiSid : only defined on Window platforms (for being able to identify |
---|
| 3171 | * the created process) |
---|
| 3172 | * |
---|
| 3173 | */ |
---|
[541] | 3174 | maps *_tmpMaps = (maps *) malloc (MAPS_SIZE); |
---|
| 3175 | _tmpMaps->name = zStrdup ("lenv"); |
---|
[32] | 3176 | char tmpBuff[100]; |
---|
[554] | 3177 | semid lid = getShmLockId (NULL, 1); |
---|
[541] | 3178 | lockShm (lid); |
---|
[514] | 3179 | struct ztimeval tp; |
---|
[541] | 3180 | if (zGettimeofday (&tp, NULL) == 0) |
---|
| 3181 | sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec))); |
---|
[514] | 3182 | else |
---|
[541] | 3183 | sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); |
---|
| 3184 | unlockShm (lid); |
---|
| 3185 | removeShmLock (NULL, 1); |
---|
| 3186 | _tmpMaps->content = createMap ("usid", tmpBuff); |
---|
| 3187 | _tmpMaps->next = NULL; |
---|
| 3188 | sprintf (tmpBuff, "%i", cpid); |
---|
| 3189 | addToMap (_tmpMaps->content, "sid", tmpBuff); |
---|
| 3190 | addToMap (_tmpMaps->content, "status", "0"); |
---|
| 3191 | addToMap (_tmpMaps->content, "cwd", ntmp); |
---|
| 3192 | addToMap (_tmpMaps->content, "message", _("No message provided")); |
---|
| 3193 | map *ltmp = getMap (request_inputs, "soap"); |
---|
| 3194 | if (ltmp != NULL) |
---|
| 3195 | addToMap (_tmpMaps->content, "soap", ltmp->value); |
---|
[280] | 3196 | else |
---|
[541] | 3197 | addToMap (_tmpMaps->content, "soap", "false"); |
---|
| 3198 | if (cgiCookie != NULL && strlen (cgiCookie) > 0) |
---|
| 3199 | { |
---|
| 3200 | int hasValidCookie = -1; |
---|
| 3201 | char *tcook = zStrdup (cgiCookie); |
---|
| 3202 | char *tmp = NULL; |
---|
| 3203 | map *testing = getMapFromMaps (m, "main", "cookiePrefix"); |
---|
| 3204 | if (testing == NULL) |
---|
| 3205 | { |
---|
| 3206 | tmp = zStrdup ("ID="); |
---|
| 3207 | } |
---|
[390] | 3208 | else |
---|
[541] | 3209 | { |
---|
| 3210 | tmp = |
---|
| 3211 | (char *) malloc ((strlen (testing->value) + 2) * sizeof (char)); |
---|
| 3212 | sprintf (tmp, "%s=", testing->value); |
---|
| 3213 | } |
---|
| 3214 | if (strstr (cgiCookie, ";") != NULL) |
---|
| 3215 | { |
---|
| 3216 | char *token, *saveptr; |
---|
| 3217 | token = strtok_r (cgiCookie, ";", &saveptr); |
---|
| 3218 | while (token != NULL) |
---|
| 3219 | { |
---|
| 3220 | if (strcasestr (token, tmp) != NULL) |
---|
| 3221 | { |
---|
| 3222 | if (tcook != NULL) |
---|
| 3223 | free (tcook); |
---|
| 3224 | tcook = zStrdup (token); |
---|
| 3225 | hasValidCookie = 1; |
---|
| 3226 | } |
---|
| 3227 | token = strtok_r (NULL, ";", &saveptr); |
---|
| 3228 | } |
---|
| 3229 | } |
---|
| 3230 | else |
---|
| 3231 | { |
---|
| 3232 | if (strstr (cgiCookie, "=") != NULL |
---|
| 3233 | && strcasestr (cgiCookie, tmp) != NULL) |
---|
| 3234 | { |
---|
| 3235 | tcook = zStrdup (cgiCookie); |
---|
| 3236 | hasValidCookie = 1; |
---|
| 3237 | } |
---|
| 3238 | if (tmp != NULL) |
---|
| 3239 | { |
---|
| 3240 | free (tmp); |
---|
| 3241 | } |
---|
| 3242 | } |
---|
| 3243 | if (hasValidCookie > 0) |
---|
| 3244 | { |
---|
| 3245 | addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1); |
---|
| 3246 | char session_file_path[1024]; |
---|
| 3247 | map *tmpPath = getMapFromMaps (m, "main", "sessPath"); |
---|
| 3248 | if (tmpPath == NULL) |
---|
| 3249 | tmpPath = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 3250 | char *tmp1 = strtok (tcook, ";"); |
---|
| 3251 | if (tmp1 != NULL) |
---|
| 3252 | sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, |
---|
| 3253 | strstr (tmp1, "=") + 1); |
---|
| 3254 | else |
---|
| 3255 | sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, |
---|
| 3256 | strstr (cgiCookie, "=") + 1); |
---|
| 3257 | free (tcook); |
---|
| 3258 | maps *tmpSess = (maps *) malloc (MAPS_SIZE); |
---|
| 3259 | struct stat file_status; |
---|
| 3260 | int istat = stat (session_file_path, &file_status); |
---|
| 3261 | if (istat == 0 && file_status.st_size > 0) |
---|
| 3262 | { |
---|
| 3263 | conf_read (session_file_path, tmpSess); |
---|
| 3264 | addMapsToMaps (&m, tmpSess); |
---|
| 3265 | freeMaps (&tmpSess); |
---|
| 3266 | free (tmpSess); |
---|
| 3267 | } |
---|
| 3268 | } |
---|
[92] | 3269 | } |
---|
[541] | 3270 | addMapsToMaps (&m, _tmpMaps); |
---|
| 3271 | freeMaps (&_tmpMaps); |
---|
| 3272 | free (_tmpMaps); |
---|
[514] | 3273 | |
---|
[1] | 3274 | #ifdef DEBUG |
---|
[541] | 3275 | dumpMap (request_inputs); |
---|
[1] | 3276 | #endif |
---|
[216] | 3277 | #ifdef WIN32 |
---|
[541] | 3278 | char *cgiSidL = NULL; |
---|
| 3279 | if (getenv ("CGISID") != NULL) |
---|
| 3280 | addToMap (request_inputs, "cgiSid", getenv ("CGISID")); |
---|
[554] | 3281 | |
---|
| 3282 | char* usidp; |
---|
| 3283 | if ( (usidp = getenv("USID")) != NULL ) { |
---|
| 3284 | setMapInMaps (m, "lenv", "usid", usidp); |
---|
| 3285 | } |
---|
| 3286 | |
---|
[541] | 3287 | map *test1 = getMap (request_inputs, "cgiSid"); |
---|
| 3288 | if (test1 != NULL) |
---|
| 3289 | { |
---|
| 3290 | cgiSid = test1->value; |
---|
| 3291 | addToMap (request_inputs, "storeExecuteResponse", "true"); |
---|
| 3292 | addToMap (request_inputs, "status", "true"); |
---|
| 3293 | setMapInMaps (m, "lenv", "sid", test1->value); |
---|
| 3294 | status = getMap (request_inputs, "status"); |
---|
| 3295 | } |
---|
[216] | 3296 | #endif |
---|
[541] | 3297 | char *fbkp, *fbkp1; |
---|
| 3298 | FILE *f0, *f1; |
---|
| 3299 | if (status != NULL) |
---|
| 3300 | if (strcasecmp (status->value, "false") == 0) |
---|
| 3301 | status = NULLMAP; |
---|
| 3302 | if (status == NULLMAP) |
---|
| 3303 | { |
---|
| 3304 | loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, |
---|
| 3305 | &request_output_real_format, &eres); |
---|
| 3306 | } |
---|
| 3307 | else |
---|
| 3308 | { |
---|
| 3309 | int pid; |
---|
[1] | 3310 | #ifdef DEBUG |
---|
[541] | 3311 | fprintf (stderr, "\nPID : %d\n", cpid); |
---|
[1] | 3312 | #endif |
---|
[9] | 3313 | |
---|
[1] | 3314 | #ifndef WIN32 |
---|
[541] | 3315 | pid = fork (); |
---|
[1] | 3316 | #else |
---|
[541] | 3317 | if (cgiSid == NULL) |
---|
| 3318 | { |
---|
| 3319 | createProcess (m, request_inputs, s1, NULL, cpid, |
---|
| 3320 | request_input_real_format, |
---|
| 3321 | request_output_real_format); |
---|
| 3322 | pid = cpid; |
---|
| 3323 | } |
---|
| 3324 | else |
---|
| 3325 | { |
---|
| 3326 | pid = 0; |
---|
| 3327 | cpid = atoi (cgiSid); |
---|
| 3328 | } |
---|
[1] | 3329 | #endif |
---|
[541] | 3330 | if (pid > 0) |
---|
| 3331 | { |
---|
[1] | 3332 | /** |
---|
| 3333 | * dady : |
---|
| 3334 | * set status to SERVICE_ACCEPTED |
---|
| 3335 | */ |
---|
| 3336 | #ifdef DEBUG |
---|
[541] | 3337 | fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, |
---|
| 3338 | getpid ()); |
---|
[1] | 3339 | #endif |
---|
[541] | 3340 | eres = SERVICE_ACCEPTED; |
---|
| 3341 | } |
---|
| 3342 | else if (pid == 0) |
---|
| 3343 | { |
---|
[1] | 3344 | /** |
---|
| 3345 | * son : have to close the stdout, stdin and stderr to let the parent |
---|
| 3346 | * process answer to http client. |
---|
| 3347 | */ |
---|
[507] | 3348 | #ifndef WIN32 |
---|
[541] | 3349 | zSleep (1); |
---|
[507] | 3350 | #endif |
---|
[541] | 3351 | r_inputs = getMapFromMaps (m, "lenv", "usid"); |
---|
| 3352 | int cpid = atoi (r_inputs->value); |
---|
| 3353 | r_inputs = getMapFromMaps (m, "main", "tmpPath"); |
---|
| 3354 | map *r_inputs1 = getMap (s1->content, "ServiceProvider"); |
---|
| 3355 | fbkp = |
---|
| 3356 | (char *) |
---|
| 3357 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 3358 | 1024) * sizeof (char)); |
---|
| 3359 | sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, r_inputs1->value, |
---|
| 3360 | cpid); |
---|
| 3361 | char *flog = |
---|
| 3362 | (char *) |
---|
| 3363 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 3364 | 1024) * sizeof (char)); |
---|
| 3365 | sprintf (flog, "%s/%s_%d_error.log", r_inputs->value, |
---|
| 3366 | r_inputs1->value, cpid); |
---|
[1] | 3367 | #ifdef DEBUG |
---|
[541] | 3368 | fprintf (stderr, "RUN IN BACKGROUND MODE \n"); |
---|
| 3369 | fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, |
---|
| 3370 | getpid ()); |
---|
| 3371 | fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); |
---|
[1] | 3372 | #endif |
---|
[541] | 3373 | freopen (flog, "w+", stderr); |
---|
| 3374 | semid lid = getShmLockId (m, 1); |
---|
| 3375 | fflush (stderr); |
---|
| 3376 | if (lid < 0) |
---|
| 3377 | { |
---|
| 3378 | fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__); |
---|
| 3379 | fflush (stderr); |
---|
| 3380 | return -1; |
---|
| 3381 | } |
---|
| 3382 | else |
---|
| 3383 | { |
---|
| 3384 | if (lockShm (lid) < 0) |
---|
| 3385 | { |
---|
| 3386 | fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__); |
---|
| 3387 | fflush (stderr); |
---|
| 3388 | return -1; |
---|
| 3389 | } |
---|
| 3390 | fflush (stderr); |
---|
| 3391 | } |
---|
| 3392 | f0 = freopen (fbkp, "w+", stdout); |
---|
| 3393 | rewind (stdout); |
---|
[458] | 3394 | #ifndef WIN32 |
---|
[541] | 3395 | fclose (stdin); |
---|
[458] | 3396 | #endif |
---|
[541] | 3397 | free (flog); |
---|
[1] | 3398 | /** |
---|
| 3399 | * set status to SERVICE_STARTED and flush stdout to ensure full |
---|
| 3400 | * content was outputed (the file used to store the ResponseDocument). |
---|
| 3401 | * The rewind stdout to restart writing from the bgining of the file, |
---|
| 3402 | * this way the data will be updated at the end of the process run. |
---|
| 3403 | */ |
---|
[541] | 3404 | printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, |
---|
| 3405 | SERVICE_STARTED, request_input_real_format, |
---|
| 3406 | request_output_real_format); |
---|
| 3407 | fflush (stdout); |
---|
| 3408 | unlockShm (lid); |
---|
| 3409 | fflush (stderr); |
---|
| 3410 | fbkp1 = |
---|
| 3411 | (char *) |
---|
| 3412 | malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + |
---|
| 3413 | 1024) * sizeof (char)); |
---|
| 3414 | sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value, |
---|
| 3415 | r_inputs1->value, cpid); |
---|
| 3416 | f1 = freopen (fbkp1, "w+", stdout); |
---|
| 3417 | loadServiceAndRun (&m, s1, request_inputs, |
---|
| 3418 | &request_input_real_format, |
---|
| 3419 | &request_output_real_format, &eres); |
---|
| 3420 | } |
---|
| 3421 | else |
---|
| 3422 | { |
---|
[1] | 3423 | /** |
---|
| 3424 | * error server don't accept the process need to output a valid |
---|
| 3425 | * error response here !!! |
---|
| 3426 | */ |
---|
[541] | 3427 | eres = -1; |
---|
| 3428 | errorException (m, _("Unable to run the child process properly"), |
---|
| 3429 | "InternalError", NULL); |
---|
| 3430 | } |
---|
[1] | 3431 | } |
---|
| 3432 | |
---|
| 3433 | #ifdef DEBUG |
---|
[541] | 3434 | dumpMaps (request_output_real_format); |
---|
[1] | 3435 | #endif |
---|
[541] | 3436 | if (eres != -1) |
---|
| 3437 | outputResponse (s1, request_input_real_format, |
---|
| 3438 | request_output_real_format, request_inputs, |
---|
| 3439 | cpid, m, eres); |
---|
| 3440 | fflush (stdout); |
---|
[105] | 3441 | /** |
---|
| 3442 | * Ensure that if error occurs when freeing memory, no signal will return |
---|
| 3443 | * an ExceptionReport document as the result was already returned to the |
---|
| 3444 | * client. |
---|
| 3445 | */ |
---|
| 3446 | #ifndef USE_GDB |
---|
[541] | 3447 | signal (SIGSEGV, donothing); |
---|
| 3448 | signal (SIGTERM, donothing); |
---|
| 3449 | signal (SIGINT, donothing); |
---|
| 3450 | signal (SIGILL, donothing); |
---|
| 3451 | signal (SIGFPE, donothing); |
---|
| 3452 | signal (SIGABRT, donothing); |
---|
[105] | 3453 | #endif |
---|
[541] | 3454 | if (((int) getpid ()) != cpid || cgiSid != NULL) |
---|
| 3455 | { |
---|
| 3456 | fclose (stdout); |
---|
| 3457 | fclose (stderr); |
---|
[384] | 3458 | /** |
---|
| 3459 | * Dump back the final file fbkp1 to fbkp |
---|
| 3460 | */ |
---|
[541] | 3461 | fclose (f0); |
---|
| 3462 | fclose (f1); |
---|
| 3463 | FILE *f2 = fopen (fbkp1, "rb"); |
---|
| 3464 | semid lid = getShmLockId (m, 1); |
---|
| 3465 | if (lid < 0) |
---|
| 3466 | return -1; |
---|
| 3467 | lockShm (lid); |
---|
| 3468 | FILE *f3 = fopen (fbkp, "wb+"); |
---|
| 3469 | free (fbkp); |
---|
| 3470 | fseek (f2, 0, SEEK_END); |
---|
| 3471 | long flen = ftell (f2); |
---|
| 3472 | fseek (f2, 0, SEEK_SET); |
---|
| 3473 | char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); |
---|
| 3474 | fread (tmps1, flen, 1, f2); |
---|
| 3475 | fwrite (tmps1, 1, flen, f3); |
---|
| 3476 | fclose (f2); |
---|
| 3477 | fclose (f3); |
---|
| 3478 | unlockShm (lid); |
---|
| 3479 | unlink (fbkp1); |
---|
| 3480 | free (fbkp1); |
---|
| 3481 | free (tmps1); |
---|
| 3482 | unhandleStatus (m); |
---|
| 3483 | } |
---|
[32] | 3484 | |
---|
[541] | 3485 | freeService (&s1); |
---|
| 3486 | free (s1); |
---|
| 3487 | freeMaps (&m); |
---|
| 3488 | free (m); |
---|
| 3489 | |
---|
| 3490 | freeMaps (&request_input_real_format); |
---|
| 3491 | free (request_input_real_format); |
---|
| 3492 | |
---|
| 3493 | freeMaps (&request_output_real_format); |
---|
| 3494 | free (request_output_real_format); |
---|
| 3495 | |
---|
| 3496 | free (REQUEST); |
---|
| 3497 | free (SERVICE_URL); |
---|
[1] | 3498 | #ifdef DEBUG |
---|
[541] | 3499 | fprintf (stderr, "Processed response \n"); |
---|
| 3500 | fflush (stdout); |
---|
| 3501 | fflush (stderr); |
---|
[1] | 3502 | #endif |
---|
| 3503 | |
---|
[541] | 3504 | if (((int) getpid ()) != cpid || cgiSid != NULL) |
---|
| 3505 | { |
---|
| 3506 | exit (0); |
---|
| 3507 | } |
---|
[516] | 3508 | |
---|
[1] | 3509 | return 0; |
---|
| 3510 | } |
---|