- Timestamp:
- Nov 21, 2017, 10:24:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
r851 r854 107 107 #include <dirent.h> 108 108 #include <signal.h> 109 #include <execinfo.h> 109 110 #include <unistd.h> 110 111 #ifndef WIN32 … … 122 123 #include <time.h> 123 124 #include <stdarg.h> 125 126 #include <libxml/tree.h> 127 #include <libxml/parser.h> 128 #include <libxml/xpath.h> 129 #include <libxml/xpathInternals.h> 130 131 #include <libxslt/xslt.h> 132 #include <libxslt/xsltInternals.h> 133 #include <libxslt/transform.h> 134 #include <libxslt/xsltutils.h> 124 135 125 136 #ifndef WIN32 … … 385 396 sig_handler (int sig) 386 397 { 398 387 399 char tmp[100]; 388 400 const char *ssig; … … 413 425 sprintf (tmp, 414 426 _ 415 ("ZOO Kernel failed to process your request, receiving signal %d = %s "),427 ("ZOO Kernel failed to process your request, receiving signal %d = %s "), 416 428 sig, ssig); 417 429 errorException (NULL, tmp, "InternalError", NULL); … … 990 1002 #ifdef ETC_DIR 991 1003 #ifndef WIN32 992 1004 getcwd (ntmp, 1024); 993 1005 #else 994 1006 _getcwd (ntmp, 1024); 995 1007 #endif 996 1008 #endif … … 1184 1196 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1185 1197 fflush(stderr); 1186 dumpMap(r_inputs);1198 //dumpMap(r_inputs); 1187 1199 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1188 1200 fflush(stderr); … … 1294 1306 } 1295 1307 1308 dumpMap(request_inputs); 1309 1296 1310 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 1297 1311 { … … 1348 1362 #ifdef META_DB 1349 1363 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1350 fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);1351 1364 close_sql(m,0); 1352 1365 #endif … … 1430 1443 r_inputs = NULL; 1431 1444 r_inputs = getMap (request_inputs, "version"); 1445 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1446 fflush(stderr); 1432 1447 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 1433 1448 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); … … 1519 1534 free (REQUEST); 1520 1535 closedir (dirp); 1521 xmlFreeDoc (doc);1536 //xmlFreeDoc (doc); 1522 1537 xmlCleanupParser (); 1523 1538 zooXmlCleanupNs (); … … 1550 1565 addToMap (request_inputs, "metapath", tmpMap->value); 1551 1566 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1567 /** 1568 * No support for dot in service name stored in metadb!? 1552 1569 #ifdef META_DB 1553 service* s2=extractServiceFromDb(m,tmpMapI-> name,0);1570 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 1554 1571 if(s2==NULL){ 1555 1572 #endif 1573 */ 1556 1574 s1 = (service *) malloc (SERVICE_SIZE); 1557 1575 t = readServiceFile (m, buff1, &s1, tmpMapI->value); … … 1585 1603 free (s1); 1586 1604 closedir (dirp); 1587 xmlFreeDoc (doc);1605 //xmlFreeDoc (doc); 1588 1606 xmlCleanupParser (); 1589 1607 zooXmlCleanupNs (); … … 1604 1622 hasVal = 1; 1605 1623 setMapInMaps (m, "lenv", "level", "0"); 1624 /* 1606 1625 #ifdef META_DB 1607 1626 } 1608 1627 #endif 1628 */ 1609 1629 } 1610 1630 else … … 1688 1708 free (REQUEST); 1689 1709 closedir (dirp); 1690 xmlFreeDoc (doc);1710 //xmlFreeDoc (doc); 1691 1711 xmlCleanupParser (); 1692 1712 zooXmlCleanupNs (); … … 1736 1756 free (REQUEST); 1737 1757 closedir (dirp); 1738 xmlFreeDoc (doc);1758 //xmlFreeDoc (doc); 1739 1759 xmlCleanupParser (); 1740 1760 zooXmlCleanupNs (); … … 1843 1863 } 1844 1864 s1 = NULL; 1845 if(postRequest!=NULL) 1846 setMapInMaps (m, "lenv", "xrequest", postRequest->value); 1847 1865 1848 1866 r_inputs = getMap (request_inputs, "Identifier"); 1849 1867 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); … … 1880 1898 fprintf(stderr,"CONNECTING METADB!\n"); 1881 1899 //FAILED CONNECTING DB 1882 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL ){1900 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 1883 1901 fprintf(stderr,"ERROR CONNECTING METADB\n"); 1884 1902 } 1885 s1=extractServiceFromDb(m,r_inputs->value,0); 1903 if(metadb_id>=0) 1904 s1=extractServiceFromDb(m,r_inputs->value,0); 1886 1905 //close_sql(m,0); 1887 1906 if(s1!=NULL){ … … 2181 2200 { 2182 2201 int hasValidCookie = -1; 2183 char *tcook = zStrdup (cgiCookie); 2202 char *tcook = originalCookie = zStrdup (cgiCookie); 2203 //fprintf(stderr,">>>>> %s %d %s\n",__FILE__,__LINE__,tcook ); 2184 2204 char *tmp = NULL; 2185 2205 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 2206 parseCookie(&m,originalCookie); 2186 2207 if (testing == NULL) 2187 2208 { … … 2197 2218 { 2198 2219 char *token, *saveptr; 2199 token = strtok_r ( cgiCookie, ";", &saveptr);2220 token = strtok_r (tcook, ";", &saveptr); 2200 2221 while (token != NULL) 2201 2222 { … … 2244 2265 if (istat == 0 && file_status.st_size > 0) 2245 2266 { 2267 int saved_stdout = dup (fileno (stdout)); 2268 dup2 (fileno (stderr), fileno (stdout)); 2246 2269 conf_read (session_file_path, tmpSess); 2247 2270 addMapsToMaps (&m, tmpSess); 2248 2271 freeMaps (&tmpSess); 2272 fflush(stdout); 2273 dup2 (saved_stdout, fileno (stdout)); 2274 close(saved_stdout); 2249 2275 } 2250 2276 free (tmpSess); … … 2273 2299 char* tmpName=zStrdup(s); 2274 2300 char* tmpValue=strstr(s,"=")+1; 2275 char* tmpName1=(char*)malloc((1+(len- strlen(tmpValue)))*sizeof(char));2276 snprintf(tmpName1,(len-strlen(tmpValue)) +1,"%s",tmpName);2301 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); 2302 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); 2277 2303 if(_tmpMaps->content == NULL) 2278 2304 _tmpMaps->content = createMap (tmpName1,tmpValue); … … 2285 2311 } 2286 2312 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ 2287 /*map* tmpMap1=getMap(_tmpMaps->content,"HTTP_COOKIE");2288 free(tmpMap1->value);2289 tmpMap1->value=zStrdup(cgiCookie);*/2290 fprintf(stderr,"[%s]\n",cgiCookie);2291 2313 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); 2292 dumpMap(_tmpMaps->content);2293 2314 } 2294 2315 addMapsToMaps (&m, _tmpMaps); 2295 2316 freeMaps (&_tmpMaps); 2296 2317 free (_tmpMaps); 2297 2318 if(postRequest!=NULL) 2319 setMapInMaps (m, "renv", "xrequest", postRequest->value); 2320 //dumpMaps(m); 2298 2321 #ifdef WIN32 2299 2322 char *cgiSidL = NULL; … … 2334 2357 "ZooWPSClient\0", 2335 2358 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/ 2336 2337 2359 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2338 2360 freeService (&s1); … … 2350 2372 return -1; 2351 2373 } 2352 fprintf(stderr,"*************************\n\n");2353 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapsToJson(request_input_real_format),JSON_C_TO_STRING_PLAIN));2354 fprintf(stderr,"*************************\n\n");2355 2374 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2356 2375 &request_output_real_format, &eres); 2357 #ifdef RELY_ON_DB 2376 2358 2377 #ifdef META_DB 2359 close_sql(m,1); 2378 close_sql(m,0); 2379 #endif 2380 2381 /*#ifdef RELY_ON_DB 2382 //close_sql(m,1); 2360 2383 //end_sql(); 2361 #endif 2362 close_sql(m,0); 2363 #endif 2384 #endif*/ 2364 2385 } 2365 2386 else … … 2387 2408 } 2388 2409 #endif 2410 //InternetCloseHandle (&hInternet); 2389 2411 if (pid > 0) 2390 2412 { … … 2411 2433 setMapInMaps (m, "lenv", "async","true"); 2412 2434 map* r_inputs1 = createMap("ServiceName", s1->name); 2435 2436 /*hInternet = InternetOpen ( 2437 #ifndef WIN32 2438 (LPCTSTR) 2439 #endif 2440 "ZooWPSClient\0", 2441 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 2442 #ifndef WIN32 2443 if (!CHECK_INET_HANDLE (hInternet)) 2444 fprintf (stderr, "WARNING : hInternet handle failed to initialize"); 2445 #endif*/ 2413 2446 2414 2447 // Create the filename for the result file (.res) … … 2525 2558 invokeCallback(m,request_input_real_format,NULL,1,0); 2526 2559 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2560 dumpMaps(request_output_real_format); 2527 2561 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2528 2562 freeService (&s1); 2529 2563 free (s1); 2564 fflush (stdout); 2565 fflush (stderr); 2530 2566 fclose (f0); 2531 2567 fclose (f1); 2532 2568 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2533 2569 return -1; 2570 //dumpBackFinalFile(m,fbkp,fbkp1); 2571 #ifndef RELY_ON_DB 2572 dumpMapsToFile(bmap,fbkpres,1); 2573 removeShmLock (m, 1); 2574 #else 2575 recordResponse(m,fbkp1); 2576 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2577 invokeCallback(m,NULL,NULL,7,0); 2578 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2579 #endif 2534 2580 unlink (fbkpid); 2535 2581 unhandleStatus (m); 2582 #ifdef RELY_ON_DB 2583 #ifdef META_DB 2584 cleanupCallbackThreads(); 2585 close_sql(m,1); 2586 //end_sql(); 2587 #endif 2588 close_sql(m,0); 2589 #endif 2536 2590 freeMaps (&m); 2537 2591 free (m); … … 2544 2598 freeMaps (&tmpmaps); 2545 2599 free (tmpmaps); 2546 fflush (stdout);2547 fflush (stderr);2548 2600 return -1; 2549 2601 } 2602 dumpMaps(request_output_real_format); 2550 2603 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2551 2604 invokeCallback(m,request_input_real_format,NULL,1,1); 2552 2605 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2553 setMapInMaps(m,"lenv","ds_nb","1"); 2554 loadServiceAndRun (&m, s1, request_inputs, 2555 &request_input_real_format, 2556 &request_output_real_format, &eres); 2606 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 2607 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 2608 invokeCallback(m,NULL,NULL,7,0); 2609 eres=-1;//SERVICE_FAILED; 2610 }else{ 2611 setMapInMaps(m,"lenv","ds_nb","0"); 2612 close_sql(m,0); 2613 loadServiceAndRun (&m, s1, request_inputs, 2614 &request_input_real_format, 2615 &request_output_real_format, &eres); 2616 setMapInMaps(m,"lenv","ds_nb","2"); 2617 } 2557 2618 } 2558 2619 else … … 2573 2634 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2574 2635 #endif 2636 fflush(stdout); 2637 rewind(stdout); 2575 2638 if (eres != -1) 2576 2639 outputResponse (s1, request_input_real_format, … … 2595 2658 if (((int) getpid ()) != cpid || cgiSid != NULL) 2596 2659 { 2597 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2660 if (eres == SERVICE_SUCCEEDED) 2661 invokeCallback(m,NULL,request_output_real_format,5,1); 2662 2598 2663 fflush(stderr); 2599 invokeCallback(m,NULL,request_output_real_format,5,1); 2600 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2601 fflush(stderr); 2664 fflush(stdout); 2602 2665 2603 2666 fclose (stdout); … … 2619 2682 setMapInMaps(m,"lenv","fstate",wpsStatus[0]); 2620 2683 break; 2621 } 2684 } 2622 2685 #ifndef RELY_ON_DB 2623 2686 dumpMapsToFile(bmap,fbkpres,1); … … 2625 2688 #else 2626 2689 recordResponse(m,fbkp1); 2627 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2628 invokeCallback(m,NULL,request_output_real_format,6,0); 2629 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2690 if (eres == SERVICE_SUCCEEDED) 2691 invokeCallback(m,NULL,request_output_real_format,6,0); 2630 2692 #endif 2631 2693 freeMaps(&bmap); … … 2637 2699 cleanupCallbackThreads(); 2638 2700 close_sql(m,1); 2639 //end_sql();2640 2701 #endif 2641 2702 close_sql(m,0); 2642 #endif 2643 unlink (flog); 2703 end_sql(); 2704 #endif 2644 2705 free(fbkpid); 2645 2706 free(fbkpres); 2646 free (flog);2647 2707 free (fbkp1); 2648 2708 // free (tmps1); // tmps1 is stack memory and should not be freed … … 2653 2713 fflush(stderr); 2654 2714 fclose (stderr); 2715 unlink (flog); 2716 free (flog); 2655 2717 } 2656 2718 else{
Note: See TracChangeset
for help on using the changeset viewer.