- Timestamp:
- Aug 7, 2017, 2:56:24 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
r822 r839 102 102 #endif 103 103 104 #include "service_json.h" 105 #include "service_callback.h" 106 104 107 #include <dirent.h> 105 108 #include <signal.h> … … 158 161 159 162 #ifdef WIN32 160 161 162 163 #ifndef PROGRAMNAME 164 #define PROGRAMNAME "zoo_loader.cgi" 165 #endif 163 166 #endif 164 167 … … 213 216 fclose (f2); 214 217 fclose (f3); 218 free(tmps1); 215 219 return 1; 216 220 } … … 233 237 */ 234 238 int 235 recursReaddirF ( maps * m, registry *r, xml NodePtr n, char *conf_dir,239 recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 236 240 char *prefix, int saved_stdout, int level, 237 void (func) (registry *, maps *, xml NodePtr, service *) )241 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) 238 242 { 239 243 struct dirent *dp; … … 282 286 setMapInMaps (m, "lenv", "level", levels1); 283 287 res = 284 recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,288 recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1, 285 289 func); 286 290 sprintf (levels1, "%d", level); … … 320 324 return -1; 321 325 } 322 #if ndef DEBUG326 #ifdef DEBUG 323 327 fprintf (stderr, "#################\n%s\n#################\n", 324 328 tmps1); … … 346 350 #endif 347 351 inheritance(r,&s1); 348 func (r, m, n, s1);352 func (r, m, doc, n, s1); 349 353 freeService (&s1); 350 354 free (s1); … … 949 953 #endif 950 954 955 951 956 map *r_inputs = NULL; 952 957 map *request_inputs = *inputs; 958 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN)); 959 953 960 #ifdef IGNORE_METAPATH 954 961 addToMap(request_inputs, "metapath", ""); … … 1305 1312 } 1306 1313 inheritance(zooRegistry, &svc); 1307 printGetCapabilitiesForProcess(zooRegistry, m, n, svc);1314 printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); 1308 1315 freeService(&svc); 1309 1316 free(svc); … … 1314 1321 1315 1322 if (int res = 1316 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1323 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1317 1324 printGetCapabilitiesForProcess) < 0) 1318 1325 { … … 1331 1338 dup2 (saved_stdout, fileno (stdout)); 1332 1339 #ifdef META_DB 1333 fetchServicesFromDb(zooRegistry,m,n,printGetCapabilitiesForProcess); 1340 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1341 fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__); 1342 close_sql(m,0); 1334 1343 #endif 1335 1344 printDocument (m, doc, getpid ()); … … 1353 1362 runGetStatus(m,r_inputs->value,REQUEST); 1354 1363 freeMaps (&m); 1355 free 1364 free(m); 1356 1365 if(zooRegistry!=NULL){ 1357 1366 freeRegistry(&zooRegistry); … … 1429 1438 } 1430 1439 inheritance(zooRegistry, &svc); 1431 printDescribeProcessForProcess(zooRegistry, m, n, svc); 1440 #ifdef USE_HPC 1441 addNestedOutputs(&svc); 1442 #endif 1443 1444 printDescribeProcessForProcess(zooRegistry, m, doc, n, svc); 1432 1445 freeService(&svc); 1433 1446 free(svc); … … 1438 1451 1439 1452 if (int res = 1440 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1453 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1441 1454 printDescribeProcessForProcess) < 0) 1442 1455 return res; 1443 1456 #ifdef META_DB 1444 fetchServicesFromDb(zooRegistry,m,n,printDescribeProcessForProcess); 1457 fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0); 1458 close_sql(m,0); 1445 1459 #endif 1446 1460 … … 1461 1475 { 1462 1476 #ifdef META_DB 1463 service* s2=extractServiceFromDb(m,import->name); 1464 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 1465 fflush(stderr); 1477 service* s2=extractServiceFromDb(m,import->name,0); 1466 1478 if(s2==NULL){ 1467 1479 #endif … … 1500 1512 dumpService (s1); 1501 1513 #endif 1502 1503 1514 inheritance(zooRegistry,&s1); 1504 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1515 #ifdef USE_HPC 1516 addNestedOutputs(&s1); 1517 #endif 1518 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1505 1519 freeService (&s1); 1506 1520 free (s1); … … 1520 1534 addToMap (request_inputs, "metapath", tmpMap->value); 1521 1535 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1522 1523 1536 #ifdef META_DB 1524 service* s2=extractServiceFromDb(m,tmpMapI->name); 1525 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 1526 fflush(stderr); 1537 service* s2=extractServiceFromDb(m,tmpMapI->name,0); 1527 1538 if(s2==NULL){ 1528 1539 #endif … … 1567 1578 #endif 1568 1579 inheritance(zooRegistry,&s1); 1569 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1580 #ifdef USE_HPC 1581 addNestedOutputs(&s1); 1582 #endif 1583 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1570 1584 freeService (&s1); 1571 1585 free (s1); … … 1580 1594 else 1581 1595 { 1582 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);1583 fflush(stderr);1584 1596 #ifdef META_DB 1585 1597 _init_sql(m,"metadb"); 1586 service* s2=extractServiceFromDb(m,corig); 1598 //FAILED CONNECTING DB 1599 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 1600 fprintf(stderr,"ERROR CONNECTING METADB"); 1601 } 1602 service* s2=extractServiceFromDb(m,corig,0); 1587 1603 if(s2!=NULL){ 1588 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);1589 fflush(stderr);1590 1604 inheritance(zooRegistry,&s2); 1591 printDescribeProcessForProcess (zooRegistry,m, n, s2); 1605 #ifdef USE_HPC 1606 addNestedOutputs(&s2); 1607 #endif 1608 printDescribeProcessForProcess (zooRegistry,m, doc, n, s2); 1592 1609 freeService (&s2); 1593 1610 free (s2); … … 1664 1681 #endif 1665 1682 inheritance(zooRegistry,&s1); 1666 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1683 #ifdef USE_HPC 1684 addNestedOutputs(&s1); 1685 #endif 1686 printDescribeProcessForProcess (zooRegistry,m, doc, n, s1); 1667 1687 freeService (&s1); 1668 1688 free (s1); … … 1725 1745 free (SERVICE_URL); 1726 1746 fflush (stdout); 1747 #ifdef META_DB 1748 close_sql(m,0); 1749 //end_sql(); 1750 #endif 1727 1751 return 0; 1728 1752 } … … 1803 1827 } 1804 1828 s1 = NULL; 1805 s1 = (service *) malloc (SERVICE_SIZE); 1806 if (s1 == NULL) 1807 { 1808 freeMaps (&m); 1809 free (m); 1810 if(zooRegistry!=NULL){ 1811 freeRegistry(&zooRegistry); 1812 free(zooRegistry); 1813 } 1814 free (REQUEST); 1815 free (SERVICE_URL); 1816 return errorException (m, _("Unable to allocate memory"), 1817 "InternalError", NULL); 1818 } 1819 1829 if(postRequest!=NULL) 1830 setMapInMaps (m, "lenv", "xrequest", postRequest->value); 1831 1820 1832 r_inputs = getMap (request_inputs, "Identifier"); 1821 1822 1833 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 1823 1834 if (import != NULL && import->value != NULL) { … … 1848 1859 1849 1860 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 1861 1862 #ifdef META_DB 1863 int metadb_id=_init_sql(m,"metadb"); 1864 fprintf(stderr,"CONNECTING METADB!\n"); 1865 //FAILED CONNECTING DB 1866 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 1867 fprintf(stderr,"ERROR CONNECTING METADB\n"); 1868 } 1869 s1=extractServiceFromDb(m,r_inputs->value,0); 1870 //close_sql(m,0); 1871 if(s1!=NULL){ 1872 inheritance(zooRegistry,&s1); 1873 #ifdef USE_HPC 1874 addNestedOutputs(&s1); 1875 #endif 1876 if(zooRegistry!=NULL){ 1877 freeRegistry(&zooRegistry); 1878 free(zooRegistry); 1879 } 1880 }else /* Not found in MetaDB */{ 1881 #endif 1882 s1 = (service *) malloc (SERVICE_SIZE); 1883 if (s1 == NULL) 1884 { 1885 freeMaps (&m); 1886 free (m); 1887 if(zooRegistry!=NULL){ 1888 freeRegistry(&zooRegistry); 1889 free(zooRegistry); 1890 } 1891 free (REQUEST); 1892 free (SERVICE_URL); 1893 return errorException (m, _("Unable to allocate memory"), 1894 "InternalError", NULL); 1895 } 1896 1850 1897 int saved_stdout = dup (fileno (stdout)); 1851 1898 dup2 (fileno (stderr), fileno (stdout)); 1852 1899 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1853 1900 inheritance(zooRegistry,&s1); 1901 #ifdef USE_HPC 1902 addNestedOutputs(&s1); 1903 #endif 1854 1904 if(zooRegistry!=NULL){ 1855 1905 freeRegistry(&zooRegistry); … … 1875 1925 } 1876 1926 close (saved_stdout); 1877 1927 #ifdef META_DB 1928 } 1929 #endif 1930 1878 1931 #ifdef DEBUG 1879 1932 dumpService (s1); … … 1912 1965 return 0; 1913 1966 } 1914 1967 //InternetCloseHandle (&hInternet); 1968 1915 1969 // Define each env variable in runing environment 1916 1970 maps *curs = getMaps (m, "env"); … … 2052 2106 int cpid = getpid (); 2053 2107 2108 // Create a map containing a copy of the request map 2109 maps *_tmpMaps = createMaps("request"); 2110 addMapToMap(&_tmpMaps->content,request_inputs); 2111 addMapsToMaps (&m, _tmpMaps); 2112 freeMaps (&_tmpMaps); 2113 free (_tmpMaps); 2054 2114 /** 2055 2115 * Initialize the specific [lenv] section which contains runtime variables: … … 2072 2132 * 2073 2133 */ 2074 maps *_tmpMaps = createMaps("lenv");2134 _tmpMaps = createMaps("lenv"); 2075 2135 char tmpBuff[100]; 2076 2136 struct ztimeval tp; … … 2182 2242 #endif 2183 2243 int ei = 1; 2184 char * s=2244 char **orig = 2185 2245 #ifdef WIN32 2186 GetEnvironmentStrings() ;2246 GetEnvironmentStrings() 2187 2247 #else 2188 *environ; 2189 #endif 2248 environ 2249 #endif 2250 ; 2251 char *s=*orig; 2190 2252 _tmpMaps = createMaps("renv"); 2191 2253 for (; s; ei++) { 2192 2254 char* tmpName=zStrdup(s); 2193 2255 char* tmpValue=strstr(s,"=")+1; 2194 tmpName[strlen(tmpName)-strlen(tmpValue)-1]=0; 2256 char* tmpName1=(char*)malloc((1+(strlen(tmpName)-strlen(tmpValue)))*sizeof(char)); 2257 snprintf(tmpName1,(strlen(tmpName)-strlen(tmpValue)),"%s",tmpName); 2195 2258 if(_tmpMaps->content == NULL) 2196 _tmpMaps->content = createMap (tmpName ,tmpValue);2259 _tmpMaps->content = createMap (tmpName1,tmpValue); 2197 2260 else 2198 addToMap (_tmpMaps->content,tmpName ,tmpValue);2261 addToMap (_tmpMaps->content,tmpName1,tmpValue); 2199 2262 free(tmpName); 2200 s = *(environ+ei); 2263 free(tmpName1); 2264 s = *(orig+ei); 2201 2265 } 2202 2266 addMapsToMaps (&m, _tmpMaps); … … 2228 2292 } 2229 2293 #endif 2294 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2295 invokeCallback(m,NULL,NULL,0,0); 2296 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2230 2297 2231 2298 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; … … 2236 2303 if (status == NULLMAP) 2237 2304 { 2305 /* hInternet = InternetOpen ( 2306 #ifndef WIN32 2307 (LPCTSTR) 2308 #endif 2309 "ZooWPSClient\0", 2310 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/ 2311 2238 2312 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2239 2313 freeService (&s1); … … 2251 2325 return -1; 2252 2326 } 2327 fprintf(stderr,"*************************\n\n"); 2328 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapsToJson(request_input_real_format),JSON_C_TO_STRING_PLAIN)); 2329 fprintf(stderr,"*************************\n\n"); 2253 2330 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2254 2331 &request_output_real_format, &eres); … … 2300 2377 int cpid = atoi (tmpm->value); 2301 2378 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2379 setMapInMaps (m, "lenv", "async","true"); 2302 2380 map* r_inputs1 = createMap("ServiceName", s1->name); 2303 2381 … … 2396 2474 f1 = freopen (fbkp1, "w+", stdout); 2397 2475 2476 map* serviceTypeMap=getMap(s1->content,"serviceType"); 2477 if(serviceTypeMap!=NULL) 2478 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 2479 2480 char *flenv = 2481 (char *) 2482 malloc ((strlen (r_inputs->value) + 2483 strlen (usid->value) + 12) * sizeof (char)); 2484 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2485 maps* lenvMaps=getMaps(m,"lenv"); 2486 dumpMapsToFile(lenvMaps,flenv,0); 2487 free(flenv); 2488 2489 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2490 invokeCallback(m,request_input_real_format,NULL,1,0); 2491 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2398 2492 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2399 2493 freeService (&s1); … … 2419 2513 return -1; 2420 2514 } 2515 setMapInMaps(m,"lenv","ds_nb","1"); 2421 2516 loadServiceAndRun (&m, s1, request_inputs, 2422 2517 &request_input_real_format, … … 2435 2530 } 2436 2531 2437 //#ifdef DEBUG 2532 #ifdef DEBUG 2533 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2438 2534 dumpMaps (request_output_real_format); 2439 //#endif2440 //sleep(120); 2535 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2536 #endif 2441 2537 if (eres != -1) 2442 2538 outputResponse (s1, request_input_real_format, … … 2462 2558 { 2463 2559 fclose (stdout); 2464 fclose (stderr);2465 2560 2466 2561 fclose (f0); … … 2486 2581 #else 2487 2582 recordResponse(m,fbkp1); 2583 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2584 invokeCallback(m,NULL,request_output_real_format,5,1); 2585 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2488 2586 #endif 2489 2587 freeMaps(&bmap); … … 2492 2590 unlink (flog); 2493 2591 unhandleStatus (m); 2592 #ifdef META_DB 2593 close_sql(m,0); 2594 //end_sql(); 2595 #endif 2494 2596 free(fbkpid); 2495 2597 free(fbkpres); … … 2499 2601 if(cgiSid!=NULL) 2500 2602 free(cgiSid); 2501 } 2502 2603 //InternetCloseHandle (&hInternet); 2604 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2605 fflush(stderr); 2606 fclose (stderr); 2607 } 2608 else{ 2609 //InternetCloseHandle (&hInternet); 2610 #ifdef META_DB 2611 //close_sql(m,0); 2612 #endif 2613 } 2614 2503 2615 freeService (&s1); 2504 2616 free (s1);
Note: See TracChangeset
for help on using the changeset viewer.