Changeset 917 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- May 7, 2019, 2:17:08 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r889 r917 26 26 extern "C" int crlex (); 27 27 28 #ifdef META_DB 29 #include "ogrsf_frmts.h" 30 #if GDAL_VERSION_MAJOR >= 2 31 #include <gdal_priv.h> 32 #endif 33 #endif 34 28 35 #ifdef USE_OTB 29 36 #include "service_internal_otb.h" 37 #endif 38 39 #ifdef USE_R 40 #include "service_internal_r.h" 41 #endif 42 43 #ifdef USE_HPC 44 #include "service_internal_hpc.h" 30 45 #endif 31 46 … … 55 70 #endif 56 71 72 #ifdef META_DB 73 #include "meta_sql.h" 74 #endif 75 57 76 #ifdef USE_PYTHON 58 77 #include "service_internal_python.h" … … 87 106 #endif 88 107 108 #ifdef USE_CALLBACK 109 #include "service_json.h" 110 #include "service_callback.h" 111 #endif 112 89 113 #include <dirent.h> 90 114 #include <signal.h> 115 #ifndef WIN32 116 #include <execinfo.h> 117 #endif 91 118 #include <unistd.h> 92 119 #ifndef WIN32 … … 105 132 #include <stdarg.h> 106 133 134 #include <libxml/tree.h> 135 #include <libxml/parser.h> 136 #include <libxml/xpath.h> 137 #include <libxml/xpathInternals.h> 138 139 #include <libxslt/xslt.h> 140 #include <libxslt/xsltInternals.h> 141 #include <libxslt/transform.h> 142 #include <libxslt/xsltutils.h> 143 107 144 #ifndef WIN32 108 145 extern char **environ; 146 #endif 147 148 149 #ifdef WIN32 150 extern "C" 151 { 152 __declspec (dllexport) char *strcasestr (char const *a, char const *b) 153 #ifndef USE_MS 154 { 155 char *x = zStrdup (a); 156 char *y = zStrdup (b); 157 158 x = _strlwr (x); 159 y = _strlwr (y); 160 char *pos = strstr (x, y); 161 char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); 162 free (x); 163 free (y); 164 return ret; 165 }; 166 #else 167 ; 168 #endif 169 } 109 170 #endif 110 171 … … 119 180 120 181 #ifdef WIN32 121 122 123 182 #ifndef PROGRAMNAME 183 #define PROGRAMNAME "zoo_loader.cgi" 184 #endif 124 185 #endif 125 186 … … 159 220 lockShm (lid); 160 221 #endif 161 FILE *f3 = fopen (fbkp, "wb+"); 162 free (fbkp); 222 FILE *f3 = fopen (fbkp, "wb+"); 223 free (fbkp); 163 224 fseek (f2, 0, SEEK_END); 164 225 long flen = ftell (f2); 165 226 fseek (f2, 0, SEEK_SET); 166 227 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 167 fread (tmps1, flen, 1, f2); 228 fread (tmps1, flen, 1, f2); 168 229 #ifdef WIN32 169 230 /* knut: I think this block can be dropped; pchr may be NULL if result is not in XML format 170 char *pchr=strrchr(tmps1,'>'); 171 flen=strlen(tmps1)-strlen(pchr)+1; 172 tmps1[flen]=0; 231 char *pchr=strrchr(tmps1,'>'); 232 flen=strlen(tmps1)-strlen(pchr)+1; 233 tmps1[flen]=0; 173 234 */ 174 #endif 235 #endif 175 236 fwrite (tmps1, 1, flen, f3); 237 fclose (f2); 238 fclose (f3); 176 239 free(tmps1); 177 fclose (f2);178 fclose (f3);179 240 return 1; 180 241 } … … 197 258 */ 198 259 int 199 recursReaddirF ( maps * m, registry *r, xml NodePtr n, char *conf_dir,260 recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 200 261 char *prefix, int saved_stdout, int level, 201 void (func) (registry *, maps *, xml NodePtr, service *) )262 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) 202 263 { 203 264 struct dirent *dp; … … 246 307 setMapInMaps (m, "lenv", "level", levels1); 247 308 res = 248 recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,309 recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1, 249 310 func); 250 311 sprintf (levels1, "%d", level); … … 264 325 { 265 326 char* extn = strstr(dp->d_name, ".zcfg"); 266 if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 )327 if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6) 267 328 { 268 329 int t; … … 271 332 snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name); 272 333 273 char *tmpsn = zStrdup (dp->d_name); 274 tmpsn[strlen (tmpsn) - 5] = 0; 334 char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name); 335 memset (tmpsn, 0, strlen(dp->d_name)-4); 336 snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name); 275 337 276 338 map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn); 277 339 if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block 278 service *s1 = (service *) malloc (SERVICE_SIZE);340 service *s1 = createService(); 279 341 if (s1 == NULL) 280 342 { 281 dup2 (saved_stdout, fileno (stdout));343 zDup2 (saved_stdout, fileno (stdout)); 282 344 errorException (m, _("Unable to allocate memory"), 283 345 "InternalError", NULL); … … 300 362 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 301 363 dp->d_name); 302 dup2 (saved_stdout, fileno (stdout));364 zDup2 (saved_stdout, fileno (stdout)); 303 365 errorException (m, tmp01, "InternalError", NULL); 304 366 return -1; … … 309 371 fflush (stderr); 310 372 #endif 311 inheritance(r,&s1); 312 func (r, m, n, s1); 373 if(s1!=NULL) 374 inheritance(r,&s1); 375 func (r, m, doc, n, s1); 313 376 freeService (&s1); 314 377 free (s1); … … 344 407 sig_handler (int sig) 345 408 { 409 346 410 char tmp[100]; 347 411 const char *ssig; … … 372 436 sprintf (tmp, 373 437 _ 374 ("ZOO Kernel failed to process your request, receiving signal %d = %s "),438 ("ZOO Kernel failed to process your request, receiving signal %d = %s "), 375 439 sig, ssig); 376 440 errorException (NULL, tmp, "InternalError", NULL); … … 420 484 #endif 421 485 422 map* libp = getMapFromMaps(m, "main", "libPath"); 423 486 map* libp = getMapFromMaps(m, "main", "libPath"); 424 487 if (strlen (r_inputs->value) == 1 425 488 && strncasecmp (r_inputs->value, "C", 1) == 0) … … 610 673 else 611 674 675 #ifdef USE_HPC 676 if (strncasecmp (r_inputs->value, "HPC", 3) == 0) 677 { 678 *eres = 679 zoo_hpc_support (&m, request_inputs, s1, 680 &request_input_real_format, 681 &request_output_real_format); 682 } 683 else 684 #endif 685 612 686 #ifdef USE_SAGA 613 if (strncasecmp (r_inputs->value, "SAGA", 6) == 0)687 if (strncasecmp (r_inputs->value, "SAGA", 4) == 0) 614 688 { 615 689 *eres = … … 622 696 623 697 #ifdef USE_OTB 624 if (strncasecmp (r_inputs->value, "OTB", 6) == 0)698 if (strncasecmp (r_inputs->value, "OTB", 3) == 0) 625 699 { 626 700 *eres = … … 633 707 #ifdef USE_PYTHON 634 708 if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0) 709 { 710 *eres = 711 zoo_python_support (&m, request_inputs, s1, 712 &request_input_real_format, 713 &request_output_real_format); 714 } 715 else 716 #endif 717 718 #ifdef USE_R 719 if (strncasecmp (r_inputs->value, "R", 6) == 0) 635 720 { 636 721 *eres = 637 zoo_ python_support (&m, request_inputs, s1,722 zoo_r_support (&m, request_inputs, s1, 638 723 &request_input_real_format, 639 724 &request_output_real_format); … … 713 798 } 714 799 *myMap = m; 715 *ioutputs = request_output_real_format; 800 *ioutputs = request_output_real_format; 716 801 } 717 802 … … 902 987 #endif 903 988 989 904 990 map *r_inputs = NULL; 905 991 map *request_inputs = *inputs; 992 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN)); 993 906 994 #ifdef IGNORE_METAPATH 907 995 addToMap(request_inputs, "metapath", ""); … … 935 1023 #ifdef ETC_DIR 936 1024 #ifndef WIN32 937 1025 getcwd (ntmp, 1024); 938 1026 #else 939 1027 _getcwd (ntmp, 1024); 940 1028 #endif 941 1029 #endif … … 1013 1101 char tmp1[13]; 1014 1102 sprintf (tmp1, "LC_ALL=%s", tmp); 1015 putenv (tmp1);1103 _putenv (tmp1); 1016 1104 #endif 1017 1105 free (tmp); … … 1025 1113 char tmp1[13]; 1026 1114 sprintf (tmp1, "LC_ALL=en_US"); 1027 putenv (tmp1);1115 _putenv (tmp1); 1028 1116 #endif 1029 1117 setMapInMaps (m, "main", "language", "en-US"); … … 1035 1123 char tmp1[17]; 1036 1124 sprintf (tmp1, "LC_NUMERIC=C"); 1037 putenv (tmp1);1125 _putenv (tmp1); 1038 1126 #endif 1039 1127 bind_textdomain_codeset ("zoo-kernel", "UTF-8"); … … 1127 1215 }; 1128 1216 r_inputs = getMap (request_inputs, "Request"); 1129 REQUEST = zStrdup (r_inputs->value); 1217 if(r_inputs!=NULL) 1218 REQUEST = zStrdup (r_inputs->value); 1130 1219 int reqId=-1; 1131 1220 if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ … … 1134 1223 for(j=0;j<nbSupportedRequests;j++){ 1135 1224 if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){ 1136 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen( REQUEST))==0){1225 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 1137 1226 checkValidValue(request_inputs,&err,"identifier",NULL,1); 1138 1227 reqId=j+1; … … 1141 1230 else 1142 1231 if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 1143 strncasecmp(REQUEST,requests[vid][j+1],strlen( REQUEST))==0){1232 strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 1144 1233 checkValidValue(request_inputs,&err,"jobid",NULL,1); 1145 1234 reqId=j+1; … … 1217 1306 registry* zooRegistry=NULL; 1218 1307 if(reg!=NULL){ 1219 int saved_stdout = dup (fileno (stdout)); 1220 dup2 (fileno (stderr), fileno (stdout)); 1308 #ifndef WIN32 1309 int saved_stdout = zDup (fileno (stdout)); 1310 zDup2 (fileno (stderr), fileno (stdout)); 1311 #endif 1221 1312 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1222 1313 map *message=getMapFromMaps(m,"lenv","message"); 1223 1314 map *type=getMapFromMaps(m,"lenv","type"); 1224 dup2 (saved_stdout, fileno (stdout)); 1315 #ifndef WIN32 1316 zDup2 (saved_stdout, fileno (stdout)); 1317 #endif 1225 1318 errorException (m, message->value, 1226 1319 type->value, NULL); 1227 1320 return 0; 1228 1321 } 1229 dup2 (saved_stdout, fileno (stdout)); 1230 close(saved_stdout); 1322 #ifndef WIN32 1323 zDup2 (saved_stdout, fileno (stdout)); 1324 zClose(saved_stdout); 1325 #endif 1231 1326 } 1232 1327 … … 1242 1337 * has been found in the zcfg and then printed on stdout 1243 1338 */ 1244 int saved_stdout = dup (fileno (stdout));1245 dup2 (fileno (stderr), fileno (stdout));1339 int saved_stdout = zDup (fileno (stdout)); 1340 zDup2 (fileno (stderr), fileno (stdout)); 1246 1341 1247 1342 maps* imports = getMaps(m, IMPORTSERVICE); … … 1258 1353 } 1259 1354 inheritance(zooRegistry, &svc); 1260 printGetCapabilitiesForProcess(zooRegistry, m, n, svc);1355 printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); 1261 1356 freeService(&svc); 1262 1357 free(svc); … … 1267 1362 1268 1363 if (int res = 1269 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1364 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1270 1365 printGetCapabilitiesForProcess) < 0) 1271 1366 { … … 1282 1377 } 1283 1378 fflush (stdout); 1284 dup2 (saved_stdout, fileno (stdout)); 1285 printDocument (m, doc, getpid ()); 1379 zDup2 (saved_stdout, fileno (stdout)); 1380 #ifdef META_DB 1381 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1382 close_sql(m,0); 1383 #endif 1384 printDocument (m, doc, zGetpid ()); 1286 1385 freeMaps (&m); 1287 1386 free (m); … … 1299 1398 r_inputs = getMap (request_inputs, "JobId"); 1300 1399 if(reqId>nbReqIdentifier){ 1301 if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||1302 strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){1400 if (strncasecmp (REQUEST, "GetStatus", 9) == 0 || 1401 strncasecmp (REQUEST, "GetResult", 9) == 0){ 1303 1402 runGetStatus(m,r_inputs->value,REQUEST); 1403 #ifdef RELY_ON_DB 1404 map* dsNb=getMapFromMaps(m,"lenv","ds_nb"); 1405 if(dsNb!=NULL && atoi(dsNb->value)>1) 1406 close_sql(m,1); 1407 close_sql(m,0); 1408 #endif 1409 1304 1410 freeMaps (&m); 1305 free 1411 free(m); 1306 1412 if(zooRegistry!=NULL){ 1307 1413 freeRegistry(&zooRegistry); … … 1355 1461 r_inputs = NULL; 1356 1462 r_inputs = getMap (request_inputs, "version"); 1463 #ifdef DEBUG 1464 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1465 fflush(stderr); 1466 #endif 1357 1467 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 1358 1468 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); … … 1362 1472 char *orig = zStrdup (r_inputs->value); 1363 1473 1364 int saved_stdout = dup (fileno (stdout));1365 dup2 (fileno (stderr), fileno (stdout));1474 int saved_stdout = zDup (fileno (stdout)); 1475 zDup2 (fileno (stderr), fileno (stdout)); 1366 1476 if (strcasecmp ("all", orig) == 0) 1367 1477 { … … 1379 1489 } 1380 1490 inheritance(zooRegistry, &svc); 1381 printDescribeProcessForProcess(zooRegistry, m, n, svc); 1491 #ifdef USE_HPC 1492 addNestedOutputs(&svc); 1493 #endif 1494 1495 printDescribeProcessForProcess(zooRegistry, m, doc, n, svc); 1382 1496 freeService(&svc); 1383 1497 free(svc); … … 1388 1502 1389 1503 if (int res = 1390 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1504 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1391 1505 printDescribeProcessForProcess) < 0) 1392 1506 return res; 1507 #ifdef META_DB 1508 fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0); 1509 close_sql(m,0); 1510 #endif 1511 1393 1512 } 1394 1513 else … … 1406 1525 if (import != NULL && import->value != NULL) 1407 1526 { 1408 s1 = (service *) malloc (SERVICE_SIZE); 1409 t = readServiceFile (m, import->value, &s1, import->name); 1527 #ifdef META_DB 1528 service* s2=extractServiceFromDb(m,import->name,0); 1529 if(s2==NULL){ 1530 #endif 1531 s1 = createService(); 1532 t = readServiceFile (m, import->value, &s1, import->name); 1410 1533 1411 if (t < 0) // failure reading zcfg 1412 { 1413 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1414 char tmp01[1024]; 1415 if (tmp00 != NULL) 1416 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); 1417 else 1418 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1419 1420 dup2 (saved_stdout, fileno (stdout)); 1421 errorException (m, tmp01, "InternalError", NULL); 1422 1423 freeMaps (&m); 1424 free (m); 1425 1426 if(zooRegistry!=NULL){ 1427 freeRegistry(&zooRegistry); 1428 free(zooRegistry); 1534 if (t < 0) // failure reading zcfg 1535 { 1536 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1537 char tmp01[1024]; 1538 if (tmp00 != NULL) 1539 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); 1540 else 1541 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1542 1543 zDup2 (saved_stdout, fileno (stdout)); 1544 errorException (m, tmp01, "InternalError", NULL); 1545 1546 freeMaps (&m); 1547 free (m); 1548 1549 if(zooRegistry!=NULL){ 1550 freeRegistry(&zooRegistry); 1551 free(zooRegistry); 1552 } 1553 free (orig); 1554 free (REQUEST); 1555 closedir (dirp); 1556 //xmlFreeDoc (doc); 1557 xmlCleanupParser (); 1558 zooXmlCleanupNs (); 1559 1560 return 1; 1429 1561 } 1430 free (orig); 1431 free (REQUEST); 1432 closedir (dirp); 1433 xmlFreeDoc (doc); 1434 xmlCleanupParser (); 1435 zooXmlCleanupNs (); 1436 1437 return 1; 1438 } 1439 #ifdef DEBUG 1440 dumpService (s1); 1441 #endif 1442 1443 inheritance(zooRegistry,&s1); 1444 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1445 freeService (&s1); 1446 free (s1); 1447 s1 = NULL; 1448 scount++; 1449 hasVal = 1; 1450 } 1562 #ifdef DEBUG 1563 dumpService (s1); 1564 #endif 1565 inheritance(zooRegistry,&s1); 1566 #ifdef USE_HPC 1567 addNestedOutputs(&s1); 1568 #endif 1569 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1570 freeService (&s1); 1571 free (s1); 1572 s1 = NULL; 1573 scount++; 1574 hasVal = 1; 1575 #ifdef META_DB 1576 } 1577 #endif 1578 } 1451 1579 else if (strstr (corig, ".") != NULL) 1452 1580 { … … 1457 1585 addToMap (request_inputs, "metapath", tmpMap->value); 1458 1586 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1459 1460 s1 = (service *) malloc (SERVICE_SIZE); 1587 /** 1588 * No support for dot in service name stored in metadb!? 1589 #ifdef META_DB 1590 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 1591 if(s2==NULL){ 1592 #endif 1593 */ 1594 s1 = createService(); 1461 1595 t = readServiceFile (m, buff1, &s1, tmpMapI->value); 1462 1596 if (t < 0) … … 1474 1608 ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), 1475 1609 tmps); 1476 dup2 (saved_stdout, fileno (stdout));1610 zDup2 (saved_stdout, fileno (stdout)); 1477 1611 errorException (m, tmp01, "InvalidParameterValue", 1478 1612 "identifier"); … … 1489 1623 free (s1); 1490 1624 closedir (dirp); 1491 xmlFreeDoc (doc);1625 //xmlFreeDoc (doc); 1492 1626 xmlCleanupParser (); 1493 1627 zooXmlCleanupNs (); … … 1498 1632 #endif 1499 1633 inheritance(zooRegistry,&s1); 1500 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1634 #ifdef USE_HPC 1635 addNestedOutputs(&s1); 1636 #endif 1637 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1501 1638 freeService (&s1); 1502 1639 free (s1); … … 1508 1645 else 1509 1646 { 1510 memset (buff, 0, 256); 1511 snprintf (buff, 256, "%s.zcfg", corig); 1512 memset (buff1, 0, 1024); 1513 #ifdef DEBUG 1514 printf ("\n#######%s\n########\n", buff); 1515 #endif 1516 while ((dp = readdir (dirp)) != NULL) 1517 { 1518 if (strcasecmp (dp->d_name, buff) == 0) 1519 { 1520 memset (buff1, 0, 1024); 1521 snprintf (buff1, 1024, "%s/%s", conf_dir, 1522 dp->d_name); 1523 s1 = (service *) malloc (SERVICE_SIZE); 1524 if (s1 == NULL) 1525 { 1526 dup2 (saved_stdout, fileno (stdout)); 1527 return errorException (m, 1528 _ 1529 ("Unable to allocate memory"), 1530 "InternalError", 1531 NULL); 1532 } 1647 #ifdef META_DB 1648 _init_sql(m,"metadb"); 1649 //FAILED CONNECTING DB 1650 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 1651 fprintf(stderr,"ERROR CONNECTING METADB"); 1652 } 1653 service* s2=extractServiceFromDb(m,corig,0); 1654 if(s2!=NULL){ 1655 inheritance(zooRegistry,&s2); 1656 #ifdef USE_HPC 1657 addNestedOutputs(&s2); 1658 #endif 1659 printDescribeProcessForProcess (zooRegistry,m, doc, n, s2); 1660 freeService (&s2); 1661 free (s2); 1662 s2 = NULL; 1663 hasVal = 1; 1664 }else /*TOTO*/{ 1665 #endif 1666 memset (buff, 0, 256); 1667 snprintf (buff, 256, "%s.zcfg", corig); 1668 memset (buff1, 0, 1024); 1669 #ifdef DEBUG 1670 printf ("\n#######%s\n########\n", buff); 1671 #endif 1672 while ((dp = readdir (dirp)) != NULL) 1673 { 1674 if (strcasecmp (dp->d_name, buff) == 0) 1675 { 1676 memset (buff1, 0, 1024); 1677 snprintf (buff1, 1024, "%s/%s", conf_dir, 1678 dp->d_name); 1679 s1 = createService(); 1680 if (s1 == NULL) 1681 { 1682 zDup2 (saved_stdout, fileno (stdout)); 1683 return errorException (m, 1684 _ 1685 ("Unable to allocate memory"), 1686 "InternalError", 1687 NULL); 1688 } 1533 1689 #ifdef DEBUG_SERVICE_CONF 1534 fprintf 1535 (stderr,"#################\n(%s) %s\n#################\n", 1536 r_inputs->value, buff1); 1537 #endif 1538 char *tmp0 = zStrdup (dp->d_name); 1539 tmp0[strlen (tmp0) - 5] = 0; 1540 t = readServiceFile (m, buff1, &s1, tmp0); 1541 free (tmp0); 1542 if (t < 0) 1543 { 1544 map *tmp00 = 1545 getMapFromMaps (m, "lenv", "message"); 1546 char tmp01[1024]; 1547 if (tmp00 != NULL) 1548 sprintf (tmp01, 1549 _ 1550 ("Unable to parse the ZCFG file: %s (%s)"), 1551 dp->d_name, tmp00->value); 1552 else 1553 sprintf (tmp01, 1554 _ 1555 ("Unable to parse the ZCFG file: %s."), 1556 dp->d_name); 1557 dup2 (saved_stdout, fileno (stdout)); 1558 errorException (m, tmp01, "InternalError", 1559 NULL); 1560 freeMaps (&m); 1561 free (m); 1562 if(zooRegistry!=NULL){ 1563 freeRegistry(&zooRegistry); 1564 free(zooRegistry); 1690 fprintf 1691 (stderr,"#################\n(%s) %s\n#################\n", 1692 r_inputs->value, buff1); 1693 #endif 1694 char *tmp0 = zStrdup (dp->d_name); 1695 tmp0[strlen (tmp0) - 5] = 0; 1696 t = readServiceFile (m, buff1, &s1, tmp0); 1697 free (tmp0); 1698 if (t < 0) 1699 { 1700 map *tmp00 = 1701 getMapFromMaps (m, "lenv", "message"); 1702 char tmp01[1024]; 1703 if (tmp00 != NULL) 1704 sprintf (tmp01, 1705 _ 1706 ("Unable to parse the ZCFG file: %s (%s)"), 1707 dp->d_name, tmp00->value); 1708 else 1709 sprintf (tmp01, 1710 _ 1711 ("Unable to parse the ZCFG file: %s."), 1712 dp->d_name); 1713 zDup2 (saved_stdout, fileno (stdout)); 1714 errorException (m, tmp01, "InternalError", 1715 NULL); 1716 freeMaps (&m); 1717 free (m); 1718 if(zooRegistry!=NULL){ 1719 freeRegistry(&zooRegistry); 1720 free(zooRegistry); 1721 } 1722 free (orig); 1723 free (REQUEST); 1724 closedir (dirp); 1725 //xmlFreeDoc (doc); 1726 xmlCleanupParser (); 1727 zooXmlCleanupNs (); 1728 return 1; 1565 1729 } 1566 free (orig); 1567 free (REQUEST); 1568 closedir (dirp); 1569 xmlFreeDoc (doc); 1570 xmlCleanupParser (); 1571 zooXmlCleanupNs (); 1572 return 1; 1573 } 1574 #ifdef DEBUG 1575 dumpService (s1); 1576 #endif 1577 inheritance(zooRegistry,&s1); 1578 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1579 freeService (&s1); 1580 free (s1); 1581 s1 = NULL; 1582 scount++; 1583 hasVal = 1; 1584 } 1585 } 1586 } 1730 #ifdef DEBUG 1731 dumpService (s1); 1732 #endif 1733 inheritance(zooRegistry,&s1); 1734 #ifdef USE_HPC 1735 addNestedOutputs(&s1); 1736 #endif 1737 /*json_object* jobj=serviceToJson(s1); 1738 const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN); 1739 fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/ 1740 1741 printDescribeProcessForProcess (zooRegistry,m, doc, n, s1); 1742 freeService (&s1); 1743 free (s1); 1744 s1 = NULL; 1745 scount++; 1746 hasVal = 1; 1747 } 1748 } 1749 #ifdef META_DB 1750 } 1751 #endif 1752 } 1587 1753 if (hasVal < 0) 1588 1754 { … … 1597 1763 _("Unable to parse the ZCFG file: %s."), 1598 1764 buff); 1599 dup2 (saved_stdout, fileno (stdout));1765 zDup2 (saved_stdout, fileno (stdout)); 1600 1766 errorException (m, tmp01, "InvalidParameterValue", 1601 1767 "Identifier"); … … 1609 1775 free (REQUEST); 1610 1776 closedir (dirp); 1777 if (corig != NULL) 1778 free (corig); 1611 1779 xmlFreeDoc (doc); 1612 1780 xmlCleanupParser (); … … 1618 1786 if (corig != NULL) 1619 1787 free (corig); 1620 } 1788 } 1621 1789 } 1622 1790 closedir (dirp); 1623 1791 fflush (stdout); 1624 dup2 (saved_stdout, fileno (stdout));1792 zDup2 (saved_stdout, fileno (stdout)); 1625 1793 free (orig); 1626 printDocument (m, doc, getpid ());1794 printDocument (m, doc, zGetpid ()); 1627 1795 freeMaps (&m); 1628 1796 free (m); … … 1634 1802 free (SERVICE_URL); 1635 1803 fflush (stdout); 1804 #ifdef META_DB 1805 close_sql(m,0); 1806 //end_sql(); 1807 #endif 1636 1808 return 0; 1637 1809 } … … 1640 1812 map* version=getMapFromMaps(m,"main","rversion"); 1641 1813 int vid=getVersionId(version->value); 1642 1643 1814 int len = 0; 1815 int j = 0; 1644 1816 for(j=0;j<nbSupportedRequests;j++){ 1645 1817 if(requests[vid][j]!=NULL) … … 1712 1884 } 1713 1885 s1 = NULL; 1714 s1 = (service *) malloc (SERVICE_SIZE); 1715 if (s1 == NULL) 1716 { 1717 freeMaps (&m); 1718 free (m); 1719 if(zooRegistry!=NULL){ 1720 freeRegistry(&zooRegistry); 1721 free(zooRegistry); 1722 } 1723 free (REQUEST); 1724 free (SERVICE_URL); 1725 return errorException (m, _("Unable to allocate memory"), 1726 "InternalError", NULL); 1727 } 1728 1886 1729 1887 r_inputs = getMap (request_inputs, "Identifier"); 1730 1731 1888 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 1732 1889 if (import != NULL && import->value != NULL) { 1733 1734 1735 1890 strncpy(tmps1, import->value, 1024); 1891 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 1892 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 1736 1893 } 1737 1894 else { … … 1757 1914 1758 1915 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 1759 int saved_stdout = dup (fileno (stdout)); 1760 dup2 (fileno (stderr), fileno (stdout)); 1761 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1762 inheritance(zooRegistry,&s1); 1763 if(zooRegistry!=NULL){ 1764 freeRegistry(&zooRegistry); 1765 free(zooRegistry); 1916 1917 #ifdef META_DB 1918 int metadb_id=_init_sql(m,"metadb"); 1919 //FAILED CONNECTING DB 1920 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 1921 fprintf(stderr,"ERROR CONNECTING METADB\n"); 1766 1922 } 1767 fflush (stdout); 1768 dup2 (saved_stdout, fileno (stdout)); 1769 if (t < 0) 1770 { 1771 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 1772 sprintf (tmpMsg, 1773 _ 1774 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 1775 r_inputs->value); 1776 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1777 free (tmpMsg); 1778 free (s1); 1779 freeMaps (&m); 1780 free (m); 1781 free (REQUEST); 1782 free (SERVICE_URL); 1783 return 0; 1784 } 1785 close (saved_stdout); 1786 1923 if(metadb_id>=0) 1924 s1=extractServiceFromDb(m,r_inputs->value,0); 1925 //close_sql(m,0); 1926 if(s1!=NULL){ 1927 inheritance(zooRegistry,&s1); 1928 #ifdef USE_HPC 1929 addNestedOutputs(&s1); 1930 #endif 1931 if(zooRegistry!=NULL){ 1932 freeRegistry(&zooRegistry); 1933 free(zooRegistry); 1934 } 1935 }else /* Not found in MetaDB */{ 1936 #endif 1937 s1 = createService(); 1938 if (s1 == NULL) 1939 { 1940 freeMaps (&m); 1941 free (m); 1942 if(zooRegistry!=NULL){ 1943 freeRegistry(&zooRegistry); 1944 free(zooRegistry); 1945 } 1946 free (REQUEST); 1947 free (SERVICE_URL); 1948 return errorException (m, _("Unable to allocate memory"), 1949 "InternalError", NULL); 1950 } 1951 1952 int saved_stdout = zDup (fileno (stdout)); 1953 zDup2 (fileno (stderr), fileno (stdout)); 1954 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1955 if(t>=0){ 1956 inheritance(zooRegistry,&s1); 1957 #ifdef USE_HPC 1958 addNestedOutputs(&s1); 1959 #endif 1960 } 1961 if(zooRegistry!=NULL){ 1962 freeRegistry(&zooRegistry); 1963 free(zooRegistry); 1964 } 1965 fflush (stdout); 1966 zDup2 (saved_stdout, fileno (stdout)); 1967 if (t < 0) 1968 { 1969 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 1970 sprintf (tmpMsg, 1971 _ 1972 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 1973 r_inputs->value); 1974 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1975 free (tmpMsg); 1976 free (s1); 1977 freeMaps (&m); 1978 free (m); 1979 free (REQUEST); 1980 free (SERVICE_URL); 1981 return 0; 1982 } 1983 zClose (saved_stdout); 1984 #ifdef META_DB 1985 } 1986 #endif 1987 1787 1988 #ifdef DEBUG 1788 1989 dumpService (s1); … … 1821 2022 return 0; 1822 2023 } 1823 2024 //InternetCloseHandle (&hInternet); 2025 1824 2026 // Define each env variable in runing environment 1825 2027 maps *curs = getMaps (m, "env"); … … 1862 2064 2) * sizeof (char)); 1863 2065 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 1864 putenv (toto);2066 _putenv (toto); 1865 2067 #ifdef DEBUG 1866 2068 fflush (stderr); 1867 2069 #endif 1868 2070 #endif 2071 1869 2072 #ifdef DEBUG 1870 2073 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, … … 1959 2162 1960 2163 int eres = SERVICE_STARTED; 1961 int cpid = getpid (); 1962 2164 int cpid = zGetpid (); 2165 2166 // Create a map containing a copy of the request map 2167 maps *_tmpMaps = createMaps("request"); 2168 addMapToMap(&_tmpMaps->content,request_inputs); 2169 addMapsToMaps (&m, _tmpMaps); 2170 freeMaps (&_tmpMaps); 2171 free (_tmpMaps); 1963 2172 /** 1964 2173 * Initialize the specific [lenv] section which contains runtime variables: … … 1981 2190 * 1982 2191 */ 1983 maps *_tmpMaps = createMaps("lenv");2192 _tmpMaps = createMaps("lenv"); 1984 2193 char tmpBuff[100]; 1985 2194 struct ztimeval tp; … … 2009 2218 addToMap (_tmpMaps->content, "soap", "false"); 2010 2219 2011 // Parse the session file and add it to the main maps 2220 // Parse the session file and add it to the main maps 2221 char* originalCookie=NULL; 2012 2222 if (cgiCookie != NULL && strlen (cgiCookie) > 0) 2013 2223 { 2014 2224 int hasValidCookie = -1; 2015 char *tcook = zStrdup (cgiCookie); 2016 char *tmp = NULL; 2225 char *tcook = originalCookie = zStrdup (cgiCookie); 2017 2226 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 2018 if (testing == NULL) 2227 parseCookie(&m,originalCookie); 2228 map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value)); 2229 if (sessId!=NULL) 2019 2230 { 2020 tmp = zStrdup ("ID="); 2021 } 2022 else 2023 { 2024 tmp = 2025 (char *) malloc ((strlen (testing->value) + 2) * sizeof (char)); 2026 sprintf (tmp, "%s=", testing->value); 2027 } 2028 if (strstr (cgiCookie, ";") != NULL) 2029 { 2030 char *token, *saveptr; 2031 token = strtok_r (cgiCookie, ";", &saveptr); 2032 while (token != NULL) 2033 { 2034 if (strcasestr (token, tmp) != NULL) 2035 { 2036 if (tcook != NULL) 2037 free (tcook); 2038 tcook = zStrdup (token); 2039 hasValidCookie = 1; 2040 } 2041 token = strtok_r (NULL, ";", &saveptr); 2042 } 2043 } 2044 else 2045 { 2046 if (strstr (cgiCookie, "=") != NULL 2047 && strcasestr (cgiCookie, tmp) != NULL) 2048 { 2049 tcook = zStrdup (cgiCookie); 2050 hasValidCookie = 1; 2051 } 2052 if (tmp != NULL) 2053 { 2054 free (tmp); 2055 } 2056 } 2057 if (hasValidCookie > 0) 2058 { 2059 addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1); 2231 addToMap (_tmpMaps->content, "sessid", sessId->value); 2060 2232 char session_file_path[1024]; 2061 2233 map *tmpPath = getMapFromMaps (m, "main", "sessPath"); … … 2065 2237 if (tmp1 != NULL) 2066 2238 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2067 s trstr (tmp1, "=") + 1);2239 sessId->value); 2068 2240 else 2069 2241 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2070 s trstr (cgiCookie, "=") + 1);2242 sessId->value); 2071 2243 free (tcook); 2072 2244 maps *tmpSess = (maps *) malloc (MAPS_SIZE); … … 2076 2248 if (istat == 0 && file_status.st_size > 0) 2077 2249 { 2250 int saved_stdout = zDup (fileno (stdout)); 2251 zDup2 (fileno (stderr), fileno (stdout)); 2078 2252 conf_read (session_file_path, tmpSess); 2079 2253 addMapsToMaps (&m, tmpSess); 2080 2254 freeMaps (&tmpSess); 2255 fflush(stdout); 2256 zDup2 (saved_stdout, fileno (stdout)); 2257 zClose(saved_stdout); 2081 2258 } 2082 2259 free (tmpSess); … … 2091 2268 #endif 2092 2269 int ei = 1; 2093 char *s =2270 2094 2271 #ifdef WIN32 2095 GetEnvironmentStrings(); 2272 LPVOID orig = GetEnvironmentStrings(); 2273 LPTSTR s = (LPTSTR) orig; 2096 2274 #else 2097 *environ; 2098 #endif 2275 char **orig = environ; 2276 char *s=*orig; 2277 #endif 2278 2099 2279 _tmpMaps = createMaps("renv"); 2100 for (; s; ei++) { 2101 char* tmpName=zStrdup(s); 2102 char* tmpValue=strstr(s,"=")+1; 2103 tmpName[strlen(tmpName)-strlen(tmpValue)-1]=0; 2104 if(_tmpMaps->content == NULL) 2105 _tmpMaps->content = createMap (tmpName,tmpValue); 2106 else 2107 addToMap (_tmpMaps->content,tmpName,tmpValue); 2108 free(tmpName); 2109 s = *(environ+ei); 2280 if(orig!=NULL) 2281 for (; 2282 #ifdef WIN32 2283 *s; 2284 s++ 2285 #else 2286 s; 2287 ei++ 2288 #endif 2289 ) { 2290 if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){ 2291 int len=strlen(s); 2292 char* tmpName=zStrdup(s); 2293 char* tmpValue=strstr(s,"=")+1; 2294 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); 2295 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); 2296 if(_tmpMaps->content == NULL) 2297 _tmpMaps->content = createMap (tmpName1,tmpValue); 2298 else 2299 addToMap (_tmpMaps->content,tmpName1,tmpValue); 2300 free(tmpName1); 2301 free(tmpName); 2302 } 2303 #ifndef WIN32 2304 s = *(orig+ei); 2305 #endif 2306 } 2307 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ 2308 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); 2110 2309 } 2111 2310 addMapsToMaps (&m, _tmpMaps); 2112 2311 freeMaps (&_tmpMaps); 2113 2312 free (_tmpMaps); 2114 2313 #ifdef WIN32 2314 FreeEnvironmentStrings((LPCH)orig); 2315 #endif 2316 if(postRequest!=NULL) 2317 setMapInMaps (m, "renv", "xrequest", postRequest->value); 2318 //dumpMaps(m); 2115 2319 #ifdef WIN32 2116 2320 char *cgiSidL = NULL; … … 2160 2364 return -1; 2161 2365 } 2366 map* testMap=getMapFromMaps(m,"main","memory"); 2367 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 2368 dumpMapsValuesToFiles(&m,&request_input_real_format); 2162 2369 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2163 &request_output_real_format, &eres); 2370 &request_output_real_format, &eres); 2371 2372 #ifdef META_DB 2373 close_sql(m,0); 2374 #endif 2164 2375 } 2165 2376 else … … 2169 2380 fprintf (stderr, "\nPID : %d\n", cpid); 2170 2381 #endif 2171 2172 2382 #ifndef WIN32 2173 2383 pid = fork (); … … 2175 2385 if (cgiSid == NULL) 2176 2386 { 2177 2178 2179 2180 2387 createProcess (m, request_inputs, s1, NULL, cpid, 2388 request_input_real_format, 2389 request_output_real_format); 2390 pid = cpid; 2181 2391 } 2182 2392 else 2183 2393 { 2184 2185 2394 pid = 0; 2395 cpid = atoi (cgiSid); 2186 2396 updateStatus(m,0,_("Initializing")); 2187 2397 } 2188 2398 #endif 2189 2399 if (pid > 0) 2190 2191 / **2192 *dady :2193 *set status to SERVICE_ACCEPTED2194 */2195 #ifdef DEBUG 2196 2197 getpid ());2198 #endif 2199 2200 2400 { 2401 // 2402 // dady : 2403 // set status to SERVICE_ACCEPTED 2404 // 2405 #ifdef DEBUG 2406 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2407 zGetpid ()); 2408 #endif 2409 eres = SERVICE_ACCEPTED; 2410 } 2201 2411 else if (pid == 0) 2202 { 2203 /** 2204 * son : have to close the stdout, stdin and stderr to let the parent 2205 * process answer to http client. 2206 */ 2412 { 2413 eres = SERVICE_ACCEPTED; 2414 // 2415 // son : have to close the stdout, stdin and stderr to let the parent 2416 // process answer to http client. 2417 // 2207 2418 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2208 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2209 int cpid = atoi (tmpm->value); 2210 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2419 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2420 int cpid = atoi (tmpm->value); 2421 pid=cpid; 2422 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2423 setMapInMaps (m, "lenv", "async","true"); 2211 2424 map* r_inputs1 = createMap("ServiceName", s1->name); 2212 2425 2213 2426 // Create the filename for the result file (.res) 2214 2215 2216 2217 2218 2427 fbkpres = 2428 (char *) 2429 malloc ((strlen (r_inputs->value) + 2430 strlen (usid->value) + 7) * sizeof (char)); 2431 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2219 2432 bmap = createMaps("status"); 2220 2433 bmap->content=createMap("usid",usid->value); 2221 2434 addToMap(bmap->content,"sid",tmpm->value); 2222 addIntToMap(bmap->content,"pid", getpid());2223 2435 addIntToMap(bmap->content,"pid",zGetpid()); 2436 2224 2437 // Create PID file referencing the OS process identifier 2225 2226 2227 2228 2229 2438 fbkpid = 2439 (char *) 2440 malloc ((strlen (r_inputs->value) + 2441 strlen (usid->value) + 7) * sizeof (char)); 2442 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 2230 2443 setMapInMaps (m, "lenv", "file.pid", fbkpid); 2231 2444 2232 2233 printf("%d", getpid());2445 f0 = freopen (fbkpid, "w+",stdout); 2446 printf("%d",zGetpid()); 2234 2447 fflush(stdout); 2235 2448 2236 2449 // Create SID file referencing the semaphore name 2237 2238 2239 2240 2241 2450 fbkp = 2451 (char *) 2452 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2453 strlen (usid->value) + 7) * sizeof (char)); 2454 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 2242 2455 setMapInMaps (m, "lenv", "file.sid", fbkp); 2243 2456 FILE* f2 = freopen (fbkp, "w+",stdout); 2244 2457 printf("%s",tmpm->value); 2245 2458 fflush(f2); 2246 2459 free(fbkp); 2247 2460 2248 2249 2250 2251 2252 2253 2461 fbkp = 2462 (char *) 2463 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2464 strlen (usid->value) + 7) * sizeof (char)); 2465 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 2466 usid->value); 2254 2467 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 2255 2256 2257 2258 2259 2260 2468 flog = 2469 (char *) 2470 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2471 strlen (usid->value) + 13) * sizeof (char)); 2472 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2473 r_inputs1->value, usid->value); 2261 2474 setMapInMaps (m, "lenv", "file.log", flog); 2262 2475 #ifdef DEBUG 2263 2264 2265 getpid ());2266 2267 #endif 2268 2269 2476 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 2477 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 2478 zGetpid ()); 2479 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 2480 #endif 2481 freopen (flog, "w+", stderr); 2482 fflush (stderr); 2270 2483 f0 = freopen (fbkp, "w+", stdout); 2271 2484 rewind (stdout); … … 2277 2490 recordServiceStatus(m); 2278 2491 #endif 2492 #ifdef USE_CALLBACK 2493 invokeCallback(m,NULL,NULL,0,0); 2494 #endif 2279 2495 if(vid==0){ 2280 / **2281 *set status to SERVICE_STARTED and flush stdout to ensure full2282 *content was outputed (the file used to store the ResponseDocument).2283 * The rewind stdout to restart writing from the bgining of the file,2284 * this waythe data will be updated at the end of the process run.2285 */2496 // 2497 // set status to SERVICE_STARTED and flush stdout to ensure full 2498 // content was outputed (the file used to store the ResponseDocument). 2499 // Then, rewind stdout to restart writing from the begining of the file. 2500 // This way, the data will be updated at the end of the process run. 2501 // 2286 2502 printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, 2287 2503 SERVICE_STARTED, request_input_real_format, … … 2293 2509 } 2294 2510 2295 2296 2297 2298 2299 2300 2301 2302 2511 fflush (stderr); 2512 2513 fbkp1 = 2514 (char *) 2515 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2516 strlen (usid->value) + 13) * sizeof (char)); 2517 sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, 2518 r_inputs1->value, usid->value); 2303 2519 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 2304 2520 2305 f1 = freopen (fbkp1, "w+", stdout); 2306 2521 f1 = freopen (fbkp1, "w+", stdout); 2522 2523 map* serviceTypeMap=getMap(s1->content,"serviceType"); 2524 if(serviceTypeMap!=NULL) 2525 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 2526 2527 char *flenv = 2528 (char *) 2529 malloc ((strlen (r_inputs->value) + 2530 strlen (usid->value) + 12) * sizeof (char)); 2531 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2532 maps* lenvMaps=getMaps(m,"lenv"); 2533 dumpMapsToFile(lenvMaps,flenv,0); 2534 free(flenv); 2535 2536 #ifdef USE_CALLBACK 2537 invokeCallback(m,request_input_real_format,NULL,1,0); 2538 #endif 2307 2539 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2308 2540 freeService (&s1); 2309 2541 free (s1); 2542 fflush (stdout); 2543 fflush (stderr); 2310 2544 fclose (f0); 2311 2545 fclose (f1); 2312 2546 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2313 2547 return -1; 2314 unlink (fbkpid); 2548 #ifndef RELY_ON_DB 2549 dumpMapsToFile(bmap,fbkpres,1); 2550 removeShmLock (m, 1); 2551 #else 2552 recordResponse(m,fbkp1); 2553 #ifdef USE_CALLBACK 2554 invokeCallback(m,NULL,NULL,7,0); 2555 #endif 2556 #endif 2557 zUnlink (fbkpid); 2315 2558 unhandleStatus (m); 2559 #ifdef RELY_ON_DB 2560 #ifdef META_DB 2561 cleanupCallbackThreads(); 2562 close_sql(m,1); 2563 #endif 2564 close_sql(m,0); 2565 #endif 2316 2566 freeMaps (&m); 2317 2567 free (m); … … 2324 2574 freeMaps (&tmpmaps); 2325 2575 free (tmpmaps); 2326 fflush (stdout);2327 fflush (stderr);2328 2576 return -1; 2329 2577 } 2330 loadServiceAndRun (&m, s1, request_inputs, 2331 &request_input_real_format, 2332 &request_output_real_format, &eres); 2333 } 2578 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 2579 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 2580 #ifdef USE_CALLBACK 2581 invokeCallback(m,NULL,NULL,7,0); 2582 #endif 2583 eres=-1;//SERVICE_FAILED; 2584 }else{ 2585 map* testMap=getMapFromMaps(m,"main","memory"); 2586 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 2587 dumpMapsValuesToFiles(&m,&request_input_real_format); 2588 loadServiceAndRun (&m, s1, request_inputs, 2589 &request_input_real_format, 2590 &request_output_real_format, &eres); 2591 } 2592 } 2334 2593 else 2335 2594 { … … 2338 2597 * error response here !!! 2339 2598 */ 2340 2341 2342 2599 eres = -1; 2600 errorException (m, _("Unable to run the child process properly"), 2601 "InternalError", NULL); 2343 2602 } 2344 2603 } 2345 2346 #ifdef DEBUG 2604 2605 #ifdef DEBUG 2606 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2347 2607 dumpMaps (request_output_real_format); 2348 #endif 2349 2608 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2609 #endif 2610 fflush(stdout); 2611 rewind(stdout); 2612 2613 //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); 2350 2614 if (eres != -1) 2351 2615 outputResponse (s1, request_input_real_format, … … 2353 2617 cpid, m, eres); 2354 2618 fflush (stdout); 2355 2619 2356 2620 /** 2357 2621 * Ensure that if error occurs when freeing memory, no signal will return … … 2367 2631 signal (SIGABRT, donothing); 2368 2632 #endif 2369 if (((int) getpid ()) != cpid || cgiSid != NULL) 2370 { 2633 2634 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2635 { 2636 if (eres == SERVICE_SUCCEEDED) 2637 #ifdef USE_CALLBACK 2638 invokeCallback(m,NULL,request_output_real_format,5,1); 2639 #endif 2640 fflush(stderr); 2641 fflush(stdout); 2642 2371 2643 fclose (stdout); 2372 fclose (stderr);2373 2644 2374 2645 fclose (f0); 2375 2646 fclose (f1); 2376 2377 if (dumpBackFinalFile(m, fbkp, fbkp1) < 0) 2378 return -1; 2379 2380 unlink (fbkpid); 2647 2648 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2649 return -1; 2650 zUnlink (fbkpid); 2381 2651 switch(eres){ 2382 2652 default: … … 2390 2660 break; 2391 2661 } 2392 #ifndef RELY_ON_DB 2662 #ifndef RELY_ON_DB 2393 2663 dumpMapsToFile(bmap,fbkpres,1); 2394 2664 removeShmLock (m, 1); 2395 2665 #else 2396 2666 recordResponse(m,fbkp1); 2667 if (eres == SERVICE_SUCCEEDED) 2668 #ifdef USE_CALLBACK 2669 invokeCallback(m,NULL,request_output_real_format,6,0); 2670 #endif 2397 2671 #endif 2398 2672 freeMaps(&bmap); 2399 2673 free(bmap); 2400 unlink (fbkp1); 2401 unlink (flog); 2674 zUnlink (fbkp1); 2402 2675 unhandleStatus (m); 2676 #ifdef RELY_ON_DB 2677 #ifdef META_DB 2678 cleanupCallbackThreads(); 2679 close_sql(m,1); 2680 #endif 2681 close_sql(m,0); 2682 end_sql(); 2683 #endif 2403 2684 free(fbkpid); 2404 2685 free(fbkpres); 2405 free (flog);2406 2686 free (fbkp1); 2407 // free (tmps1); // tmps1 is stack memory and should not be freed2408 2687 if(cgiSid!=NULL) 2409 2688 free(cgiSid); 2410 } 2411 2689 //InternetCloseHandle (&hInternet); 2690 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2691 fflush(stderr); 2692 fclose (stderr); 2693 zUnlink (flog); 2694 free (flog); 2695 } 2696 else{ 2697 //InternetCloseHandle (&hInternet); 2698 #ifdef META_DB 2699 close_sql(m,0); 2700 #endif 2701 } 2702 2412 2703 freeService (&s1); 2413 2704 free (s1); … … 2429 2720 #endif 2430 2721 2431 if (((int) getpid ()) != cpid || cgiSid != NULL)2722 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2432 2723 { 2433 2724 exit (0);
Note: See TracChangeset
for help on using the changeset viewer.