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