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