Changeset 949 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Sep 5, 2019, 10:16:21 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r943 r949 70 70 #include "request_parser.h" 71 71 #include "sqlapi.h" 72 #ifdef WIN3272 #ifdef USE_JSON 73 73 #include "caching.h" 74 74 #endif … … 107 107 108 108 #ifdef USE_CALLBACK 109 #include "service_callback.h" 110 #endif 111 112 #ifdef USE_JSON 109 113 #include "service_json.h" 110 #include " service_callback.h"114 #include "json_tokener.h" 111 115 #endif 112 116 … … 258 262 */ 259 263 int 260 recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 261 char *prefix, int saved_stdout, int level, 262 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) 264 recursReaddirF ( maps * m, registry *r, void* doc1, void* n1, char *conf_dir, 265 //( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 266 char *prefix, int saved_stdout, int level, 267 void (func) (registry *, maps *, void*, void*, service *) ) 268 //void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) 263 269 { 264 270 struct dirent *dp; 265 271 int scount = 0; 272 xmlDocPtr doc=(xmlDocPtr) doc1; 273 xmlNodePtr n=(xmlNodePtr) n1; 266 274 267 275 if (conf_dir == NULL) … … 385 393 386 394 /** 395 * When th zcfg file is not found, print error message and cleanup memory 396 * @param zooRegistry the populated registry 397 * @param m the maps pointer to the content of main.cfg file 398 * @param zcfg the zcfg file name 399 * @param code the string determining the nature of the error 400 * @param locator the string determining which parameter the error refer to 401 * @param orig the service name 402 * @param corig the current service name (in case multiple services was parsed) 403 * @param funcError the function used to print the error back 404 */ 405 void exitAndCleanUp(registry* zooRegistry, maps* m, 406 const char* zcfg,const char* code,const char* locator, 407 char* orig,char* corig, 408 void (funcError) (maps*, map*)){ 409 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 410 char tmp01[1024]; 411 if (tmp00 != NULL) 412 sprintf (tmp01, 413 _("Unable to parse the ZCFG file: %s (%s)"), 414 zcfg, tmp00->value); 415 else 416 sprintf (tmp01, 417 _("Unable to parse the ZCFG file: %s."), 418 zcfg); 419 map* errormap = createMap("text", tmp01); 420 addToMap(errormap,"code", code); 421 addToMap(errormap,"locator", locator); 422 funcError(m,errormap); 423 freeMaps (&m); 424 free (m); 425 if(zooRegistry!=NULL){ 426 freeRegistry(&zooRegistry); 427 free(zooRegistry); 428 } 429 free (orig); 430 if (corig != NULL) 431 free (corig); 432 //xmlFreeDoc (doc); 433 xmlCleanupParser (); 434 zooXmlCleanupNs (); 435 freeMap(&errormap); 436 free(errormap); 437 } 438 439 440 /** 441 * Search services from various possible sources 442 * 443 * @param zopRegistry the populated registry 444 * @param m the maps pointer to the content of main.cfg file 445 * @param r_inputs the service(s) name(s) 446 * @param func the function used to print the result back 447 * @param doc the xml document or NULL (for json) 448 * @param n the xmlNode of JSON object pointer to the current element 449 * @param conf_dir the directory where the main.cfg has been found 450 * @param request_inputs the map pointer to the request KVP if any 451 * @param funcError the function used to print the error back 452 * @return 0 in case of success, 1 otherwise 453 */ 454 int fetchServicesForDescription(registry* zooRegistry, maps* m, char* r_inputs, 455 void (func) (registry *, maps *, void*, void*, service *), 456 void* doc, void* n, char* conf_dir, map* request_inputs, 457 void (funcError) (maps*, map*) ){ 458 char *orig = zStrdup (r_inputs); 459 service* s1=NULL; 460 int saved_stdout = zDup (fileno (stdout)); 461 int t; 462 int scount = 0; 463 struct dirent *dp; 464 465 zDup2 (fileno (stderr), fileno (stdout)); 466 if (strcasecmp ("all", orig) == 0) 467 { 468 maps* imports = getMaps(m, IMPORTSERVICE); 469 if (imports != NULL) { 470 map* zcfg = imports->content; 471 472 while (zcfg != NULL) { 473 if (zcfg->value != NULL) { 474 service* svc = (service*) malloc(SERVICE_SIZE); 475 if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { 476 // pass over silently 477 zcfg = zcfg->next; 478 continue; 479 } 480 inheritance(zooRegistry, &svc); 481 #ifdef USE_HPC 482 addNestedOutputs(&svc); 483 #endif 484 485 func(zooRegistry, m, doc, n, svc); 486 freeService(&svc); 487 free(svc); 488 } 489 zcfg = zcfg->next; 490 } 491 } 492 if (int res = 493 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 494 func) < 0) 495 return res; 496 #ifdef META_DB 497 fetchServicesFromDb(zooRegistry,m,doc,n,func,0); 498 close_sql(m,0); 499 #endif 500 } 501 else 502 { 503 DIR *dirp = opendir (conf_dir); 504 char *saveptr; 505 char *tmps = strtok_r (orig, ",", &saveptr); 506 507 char buff[256]; 508 char buff1[1024]; 509 while (tmps != NULL) 510 { 511 int hasVal = -1; 512 char *corig = zStrdup (tmps); 513 map* import = getMapFromMaps (m, IMPORTSERVICE, corig); 514 if (import != NULL && import->value != NULL) 515 { 516 #ifdef META_DB 517 service* s2=extractServiceFromDb(m,import->name,0); 518 if(s2==NULL){ 519 #endif 520 s1 = createService(); 521 t = readServiceFile (m, import->value, &s1, import->name); 522 523 if (t < 0) // failure reading zcfg 524 { 525 zDup2 (saved_stdout, fileno (stdout)); 526 exitAndCleanUp(zooRegistry, m, 527 tmps,"InvalidParameterValue","identifier", 528 orig,corig, 529 funcError); 530 return 1; 531 } 532 #ifdef DEBUG 533 dumpService (s1); 534 #endif 535 inheritance(zooRegistry,&s1); 536 #ifdef USE_HPC 537 addNestedOutputs(&s1); 538 #endif 539 func (zooRegistry, m, doc, n, s1); 540 freeService (&s1); 541 free (s1); 542 s1 = NULL; 543 scount++; 544 hasVal = 1; 545 #ifdef META_DB 546 } 547 #endif 548 } 549 else if (strstr (corig, ".") != NULL) 550 { 551 parseIdentifier (m, conf_dir, corig, buff1); 552 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 553 if (tmpMap != NULL) 554 addToMap (request_inputs, "metapath", tmpMap->value); 555 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 556 /** 557 * No support for dot in service name stored in metadb!? 558 #ifdef META_DB 559 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 560 if(s2==NULL){ 561 #endif 562 */ 563 s1 = createService(); 564 t = readServiceFile (m, buff1, &s1, tmpMapI->value); 565 if (t < 0) 566 { 567 zDup2 (saved_stdout, fileno (stdout)); 568 exitAndCleanUp(zooRegistry, m, 569 tmps,"InvalidParameterValue","identifier", 570 orig,corig, 571 funcError); 572 return 1; 573 } 574 #ifdef DEBUG 575 dumpService (s1); 576 #endif 577 inheritance(zooRegistry,&s1); 578 #ifdef USE_HPC 579 addNestedOutputs(&s1); 580 #endif 581 func (zooRegistry, m, doc, n, s1); 582 freeService (&s1); 583 free (s1); 584 s1 = NULL; 585 scount++; 586 hasVal = 1; 587 setMapInMaps (m, "lenv", "level", "0"); 588 } 589 else 590 { 591 #ifdef META_DB 592 _init_sql(m,"metadb"); 593 //FAILED CONNECTING DB 594 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 595 fprintf(stderr,"ERROR CONNECTING METADB"); 596 } 597 service* s2=extractServiceFromDb(m,corig,0); 598 if(s2!=NULL){ 599 inheritance(zooRegistry,&s2); 600 #ifdef USE_HPC 601 addNestedOutputs(&s2); 602 #endif 603 func (zooRegistry,m, doc, n, s2); 604 freeService (&s2); 605 free (s2); 606 s2 = NULL; 607 hasVal = 1; 608 }else /*TOTO*/{ 609 #endif 610 memset (buff, 0, 256); 611 snprintf (buff, 256, "%s.zcfg", corig); 612 memset (buff1, 0, 1024); 613 #ifdef DEBUG 614 printf ("\n#######%s\n########\n", buff); 615 #endif 616 while ((dp = readdir (dirp)) != NULL) 617 { 618 if (strcasecmp (dp->d_name, buff) == 0) 619 { 620 memset (buff1, 0, 1024); 621 snprintf (buff1, 1024, "%s/%s", conf_dir, 622 dp->d_name); 623 s1 = createService(); 624 if (s1 == NULL) 625 { 626 zDup2 (saved_stdout, fileno (stdout)); 627 map* errormap = createMap("text", _("Unable to allocate memory")); 628 addToMap(errormap,"code", "InternalError"); 629 addToMap(errormap,"locator", "NULL"); 630 funcError(m,errormap); 631 return -1; 632 } 633 #ifdef DEBUG_SERVICE_CONF 634 fprintf 635 (stderr,"#################\n(%s) %s\n#################\n", 636 r_inputs->value, buff1); 637 #endif 638 char *tmp0 = zStrdup (dp->d_name); 639 tmp0[strlen (tmp0) - 5] = 0; 640 t = readServiceFile (m, buff1, &s1, tmp0); 641 free (tmp0); 642 if (t < 0) 643 { 644 zDup2 (saved_stdout, fileno (stdout)); 645 exitAndCleanUp(zooRegistry, m, 646 buff,"InternalError","NULL", 647 orig,corig, 648 funcError); 649 return 1; 650 } 651 #ifdef DEBUG 652 dumpService (s1); 653 #endif 654 inheritance(zooRegistry,&s1); 655 #ifdef USE_HPC 656 addNestedOutputs(&s1); 657 #endif 658 func (zooRegistry,m, doc, n, s1); 659 freeService (&s1); 660 free (s1); 661 s1 = NULL; 662 scount++; 663 hasVal = 1; 664 } 665 } 666 #ifdef META_DB 667 } 668 #endif 669 } 670 if (hasVal < 0) 671 { 672 zDup2 (saved_stdout, fileno (stdout)); 673 exitAndCleanUp(zooRegistry, m, 674 buff,"InvalidParameterValue","Identifier", 675 orig,corig, 676 funcError); 677 return 1; 678 } 679 rewinddir (dirp); 680 tmps = strtok_r (NULL, ",", &saveptr); 681 if (corig != NULL) 682 free (corig); 683 } 684 } 685 fflush (stdout); 686 zDup2 (saved_stdout, fileno (stdout)); 687 free (orig); 688 return 0; 689 } 690 691 /** 692 * Run every HTTP request to download inputs passed as reference 693 * 694 * @param conf the maps pointing to the main.cfg file content 695 * @param inputs the maps pointing to the inputs provided in the request 696 */ 697 int loadHttpRequests(maps* conf,maps* inputs){ 698 // Resolve reference 699 // TODO: add erro gesture 700 int eres; 701 maps* tmpMaps=getMaps(conf,"http_requests"); 702 if(tmpMaps!=NULL){ 703 map* lenMap=getMap(tmpMaps->content,"length"); 704 int len=0; 705 if(lenMap!=NULL){ 706 len=atoi(lenMap->value); 707 } 708 HINTERNET hInternet; 709 HINTERNET res; 710 if(len>0) 711 hInternet = InternetOpen ( 712 #ifndef WIN32 713 (LPCTSTR) 714 #endif 715 "ZOO-Project WPS Client\0", 716 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 717 for(int j=0;j<len;j++){ 718 map* tmpUrl=getMapArray(tmpMaps->content,"url",j); 719 map* tmpInput=getMapArray(tmpMaps->content,"input",j); 720 maps* currentMaps=getMaps(inputs,tmpInput->value); 721 loadRemoteFile(&conf,¤tMaps->content,&hInternet,tmpUrl->value); 722 addIntToMap(currentMaps->content,"Order",hInternet.nb); 723 addToMap(currentMaps->content,"Reference",tmpUrl->value); 724 } 725 if(len>0){ 726 map* error=NULL; 727 runHttpRequests(&conf,&inputs,&hInternet,&error); 728 InternetCloseHandle(&hInternet); 729 } 730 } 731 return 0; 732 } 733 734 /** 735 * Initialize environment sections, load env, and populate lenv and renv. 736 * 737 * @param conf the maps pointing to the main.cfg file content 738 * @param request_inputs the map pointing to the request KVP 739 * @param cPath a string pointing to the cwd 740 * @param request a string pointing to the request key (xrequest or jrequest) 741 */ 742 void initAllEnvironment(maps* conf,map* request_inputs, 743 const char* cPath,const char* request){ 744 // Define each env variable in runing environment 745 maps *curs = getMaps (conf, "env"); 746 if (curs != NULL) { 747 map *mapcs = curs->content; 748 while (mapcs != NULLMAP) 749 { 750 #ifndef WIN32 751 setenv (mapcs->name, mapcs->value, 1); 752 #ifdef DEBUG 753 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, 754 mapcs->value); 755 #endif 756 #else 757 if (mapcs->value[strlen (mapcs->value) - 2] == '\r') 758 { 759 #ifdef DEBUG 760 fprintf (stderr, "[ZOO: Env var finish with \r]\n"); 761 #endif 762 mapcs->value[strlen (mapcs->value) - 1] = 0; 763 } 764 #ifdef DEBUG 765 if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0) 766 { 767 fflush (stderr); 768 fprintf (stderr, "setting variable... %s\n", "OK"); 769 } 770 else 771 { 772 fflush (stderr); 773 fprintf (stderr, "setting variable... %s\n", "OK"); 774 } 775 #else 776 SetEnvironmentVariable (mapcs->name, mapcs->value); 777 #endif 778 char *toto = 779 (char *) 780 malloc ((strlen (mapcs->name) + strlen (mapcs->value) + 781 2) * sizeof (char)); 782 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 783 _putenv (toto); 784 #ifdef DEBUG 785 fflush (stderr); 786 #endif 787 #endif 788 789 #ifdef DEBUG 790 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, 791 mapcs->value); 792 fflush (stderr); 793 #endif 794 mapcs = mapcs->next; 795 } 796 } 797 798 799 800 int eres = SERVICE_STARTED; 801 int cpid = zGetpid (); 802 803 // Create a map containing a copy of the request map 804 maps *_tmpMaps = createMaps("request"); 805 addMapToMap(&_tmpMaps->content,request_inputs); 806 addMapsToMaps (&conf, _tmpMaps); 807 freeMaps (&_tmpMaps); 808 free (_tmpMaps); 809 /** 810 * Initialize the specific [lenv] section which contains runtime variables: 811 * 812 * - usid : it is an universally unique identifier 813 * - osid : it is an idenfitication number 814 * - sid : it is the process idenfitication number (OS) 815 * - uusid : it is an universally unique identifier 816 * - status : value between 0 and 100 to express the completude of 817 * the operations of the running service 818 * - message : is a string where you can store error messages, in case 819 * service is failing, or o provide details on the ongoing operation. 820 * - cwd : the current working directory or servicePath if defined 821 * - soap : is a boolean value, true if the request was contained in a SOAP 822 * Envelop 823 * - sessid : string storing the session identifier (only when cookie is 824 * used) 825 * - cgiSid : only defined on Window platforms (for being able to identify 826 * the created process) 827 * 828 */ 829 _tmpMaps = createMaps("lenv"); 830 char tmpBuff[100]; 831 struct ztimeval tp; 832 if (zGettimeofday (&tp, NULL) == 0) 833 sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec))); 834 else 835 sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); 836 _tmpMaps->content = createMap ("osid", tmpBuff); 837 sprintf (tmpBuff, "%i", cpid); 838 addToMap (_tmpMaps->content, "sid", tmpBuff); 839 char* tmpUuid=get_uuid(); 840 addToMap (_tmpMaps->content, "uusid", tmpUuid); 841 addToMap (_tmpMaps->content, "usid", tmpUuid); 842 free(tmpUuid); 843 addToMap (_tmpMaps->content, "status", "0"); 844 map* cwdMap0=getMapFromMaps(conf,"main","servicePath"); 845 if(cwdMap0!=NULL){ 846 addToMap (_tmpMaps->content, "cwd", cwdMap0->value); 847 addToMap (_tmpMaps->content, "rcwd", cPath); 848 } 849 else 850 addToMap (_tmpMaps->content, "cwd", cPath); 851 addToMap (_tmpMaps->content, "message", _("No message provided")); 852 map *ltmp = getMap (request_inputs, "soap"); 853 if (ltmp != NULL) 854 addToMap (_tmpMaps->content, "soap", ltmp->value); 855 else 856 addToMap (_tmpMaps->content, "soap", "false"); 857 858 // Parse the session file and add it to the main maps 859 char* originalCookie=NULL; 860 if (cgiCookie != NULL && strlen (cgiCookie) > 0) 861 { 862 int hasValidCookie = -1; 863 char *tcook = originalCookie = zStrdup (cgiCookie); 864 map *testing = getMapFromMaps (conf, "main", "cookiePrefix"); 865 parseCookie(&conf,originalCookie); 866 map *sessId=getMapFromMaps(conf,"cookies", 867 (testing==NULL?"ID":testing->value)); 868 if (sessId!=NULL) 869 { 870 addToMap (_tmpMaps->content, "sessid", sessId->value); 871 char session_file_path[1024]; 872 map *tmpPath = getMapFromMaps (conf, "main", "sessPath"); 873 if (tmpPath == NULL) 874 tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 875 char *tmp1 = strtok (tcook, ";"); 876 if (tmp1 != NULL) 877 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 878 sessId->value); 879 else 880 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 881 sessId->value); 882 free (tcook); 883 maps *tmpSess = (maps *) malloc (MAPS_SIZE); 884 tmpSess->child=NULL; 885 struct stat file_status; 886 int istat = stat (session_file_path, &file_status); 887 if (istat == 0 && file_status.st_size > 0) 888 { 889 int saved_stdout = zDup (fileno (stdout)); 890 zDup2 (fileno (stderr), fileno (stdout)); 891 conf_read (session_file_path, tmpSess); 892 addMapsToMaps (&conf, tmpSess); 893 freeMaps (&tmpSess); 894 fflush(stdout); 895 zDup2 (saved_stdout, fileno (stdout)); 896 zClose(saved_stdout); 897 } 898 free (tmpSess); 899 } 900 } 901 addMapsToMaps (&conf, _tmpMaps); 902 freeMaps (&_tmpMaps); 903 free (_tmpMaps); 904 maps* bmap=NULL; 905 #ifdef DEBUG 906 dumpMap (request_inputs); 907 #endif 908 int ei = 1; 909 910 _tmpMaps = createMaps("renv"); 911 912 #ifdef WIN32 913 LPVOID orig = GetEnvironmentStrings(); 914 LPTSTR s = (LPTSTR) orig; 915 916 while (*s != NULL) { 917 char* env = strdup(s); 918 char* delim = strchr(env,'='); 919 if (delim != NULL) { 920 char* val = delim+1; 921 *delim = '\0'; 922 if(_tmpMaps->content == NULL) { 923 _tmpMaps->content = createMap(env,val); 924 } 925 else { 926 addToMap(_tmpMaps->content,env,val); 927 } 928 } 929 s += strlen(s)+1; 930 } 931 FreeEnvironmentStrings((LPCH)orig); 932 #else 933 char **orig = environ; 934 char *s=*orig; 935 936 if(orig!=NULL) 937 for (; s; ei++ ) { 938 if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){ 939 int len=strlen(s); 940 char* tmpName=zStrdup(s); 941 char* tmpValue=strstr(s,"=")+1; 942 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); 943 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); 944 if(_tmpMaps->content == NULL) 945 _tmpMaps->content = createMap (tmpName1,tmpValue); 946 else 947 addToMap (_tmpMaps->content,tmpName1,tmpValue); 948 free(tmpName1); 949 free(tmpName); 950 } 951 s = *(orig+ei); 952 } 953 #endif 954 955 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ 956 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); 957 } 958 addMapsToMaps (&conf, _tmpMaps); 959 freeMaps (&_tmpMaps); 960 free (_tmpMaps); 961 map* postRequest=getMap(request_inputs,request); 962 if(postRequest!=NULL) 963 setMapInMaps (conf, "renv", request, postRequest->value); 964 #ifdef WIN32 965 char *cgiSidL = NULL; 966 if (getenv ("CGISID") != NULL) 967 addToMap (request_inputs, "cgiSid", getenv ("CGISID")); 968 969 char* usidp; 970 if ( (usidp = getenv("USID")) != NULL ) { 971 setMapInMaps (conf, "lenv", "usid", usidp); 972 } 973 974 map *test1 = getMap (request_inputs, "cgiSid"); 975 if (test1 != NULL){ 976 cgiSid = zStrdup(test1->value); 977 addToMap (request_inputs, "storeExecuteResponse", "true"); 978 addToMap (request_inputs, "status", "true"); 979 setMapInMaps (conf, "lenv", "osid", test1->value); 980 status = getMap (request_inputs, "status"); 981 } 982 test1 = getMap (request_inputs, "usid"); 983 if (test1 != NULL){ 984 setMapInMaps (conf, "lenv", "usid", test1->value); 985 setMapInMaps (conf, "lenv", "uusid", test1->value); 986 } 987 #endif 988 989 } 990 991 /** 387 992 * Signal handling function which simply call exit(0). 388 993 * … … 444 1049 exit (0); 445 1050 } 1051 1052 #ifdef USE_JSON 1053 /** 1054 * Signal handling function which create an ExceptionReport node containing the 1055 * information message corresponding to the signal number. 1056 * 1057 * @param sig the signal number 1058 */ 1059 void json_sig_handler (int sig){ 1060 char tmp[100]; 1061 const char *ssig; 1062 switch (sig) 1063 { 1064 case SIGSEGV: 1065 ssig = "SIGSEGV"; 1066 break; 1067 case SIGTERM: 1068 ssig = "SIGTERM"; 1069 break; 1070 case SIGINT: 1071 ssig = "SIGINT"; 1072 break; 1073 case SIGILL: 1074 ssig = "SIGILL"; 1075 break; 1076 case SIGFPE: 1077 ssig = "SIGFPE"; 1078 break; 1079 case SIGABRT: 1080 ssig = "SIGABRT"; 1081 break; 1082 default: 1083 ssig = "UNKNOWN"; 1084 break; 1085 } 1086 sprintf (tmp, 1087 _ 1088 ("ZOO Kernel failed to process your request, receiving signal %d = %s "), 1089 sig, ssig); 1090 map* tmpMap=createMap("decode","suze"); 1091 maps* tmpMaps=createMaps("lenv"); 1092 setMapInMaps(tmpMaps,"lenv","message",tmp); 1093 setMapInMaps(tmpMaps,"lenv","status","failed"); 1094 printExceptionReportResponseJ(tmpMaps,tmpMap); 1095 //errorException (NULL, tmp, "InternalError", NULL); 1096 #ifdef DEBUG 1097 fprintf (stderr, "Not this time!\n"); 1098 #endif 1099 exit (0); 1100 } 1101 1102 #endif 446 1103 447 1104 /** … … 509 1166 #ifdef WIN32 510 1167 HINSTANCE so = 511 LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 1168 LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 512 1169 #else 513 1170 void *so = dlopen (tmps1, RTLD_LAZY); … … 974 1631 runRequest (map ** inputs) 975 1632 { 976 1633 977 1634 #ifndef USE_GDB 978 1635 #ifndef WIN32 … … 990 1647 map *r_inputs = NULL; 991 1648 map *request_inputs = *inputs; 992 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN));993 994 1649 #ifdef IGNORE_METAPATH 995 1650 addToMap(request_inputs, "metapath", ""); … … 1021 1676 char conf_file[10240]; 1022 1677 snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); 1023 #ifdef ETC_DIR1024 #ifndef WIN321025 getcwd (ntmp, 1024);1026 #else1027 _getcwd (ntmp, 1024);1028 #endif1029 #endif1030 1031 1678 if (conf_read (conf_file, m) == 2) 1032 1679 { … … 1064 1711 fstde = freopen (fstdem->value, "a+", stderr); 1065 1712 1713 /** 1714 * Language gesture 1715 */ 1066 1716 r_inputs = getMap (request_inputs, "language"); 1067 1717 if (r_inputs == NULL) … … 1160 1810 fprintf(stderr,"*** %s ***\n",tmpUrl); 1161 1811 #endif 1162 setMapInMaps(m,"main","serverAddress",tmpUrl); 1812 if(getMapFromMaps(m,"main","proxied")==NULL) 1813 setMapInMaps(m,"main","serverAddress",tmpUrl); 1814 else 1815 setMapInMaps(m,"lenv","serverAddress",tmpUrl); 1163 1816 } 1164 1817 … … 1178 1831 } 1179 1832 1833 // Populate the Registry 1834 char conf_dir[1024]; 1835 int t; 1836 char tmps1[1024]; 1837 r_inputs = NULL; 1838 r_inputs = getMap (request_inputs, "metapath"); 1839 map* cwdMap0=getMapFromMaps(m,"main","servicePath"); 1840 if (r_inputs != NULL) 1841 if(cwdMap0!=NULL) 1842 snprintf (conf_dir, 1024, "%s/%s", cwdMap0->value, r_inputs->value); 1843 else 1844 snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value); 1845 else 1846 if(cwdMap0!=NULL) 1847 snprintf (conf_dir, 1024, "%s", cwdMap0->value); 1848 else 1849 snprintf (conf_dir, 1024, "%s", ntmp); 1850 map* reg = getMapFromMaps (m, "main", "registry"); 1851 registry* zooRegistry=NULL; 1852 if(reg!=NULL){ 1853 #ifndef WIN32 1854 int saved_stdout = zDup (fileno (stdout)); 1855 zDup2 (fileno (stderr), fileno (stdout)); 1856 #endif 1857 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1858 map *message=getMapFromMaps(m,"lenv","message"); 1859 map *type=getMapFromMaps(m,"lenv","type"); 1860 #ifndef WIN32 1861 zDup2 (saved_stdout, fileno (stdout)); 1862 #endif 1863 errorException (m, message->value, 1864 type->value, NULL); 1865 return 0; 1866 } 1867 #ifndef WIN32 1868 zDup2 (saved_stdout, fileno (stdout)); 1869 zClose(saved_stdout); 1870 #endif 1871 } 1872 1873 setMapInMaps(m,"lenv","executionType","xml"); 1874 if((strlen(cgiQueryString)>0 && cgiQueryString[0]=='/') || strstr(cgiAccept,"json")!=NULL){ 1875 // 1876 // OGC API - Processing starts here 1877 // 1878 #ifndef USE_JSON 1879 errorException (m, _("OGC API - Processing is not supported by this ZOO-Kernel."), "InternalError", NULL); 1880 return 1; 1881 #else 1882 #ifndef USE_GDB 1883 #ifndef WIN32 1884 signal (SIGCHLD, SIG_IGN); 1885 #endif 1886 signal (SIGSEGV, json_sig_handler); 1887 signal (SIGTERM, json_sig_handler); 1888 signal (SIGINT, json_sig_handler); 1889 signal (SIGILL, json_sig_handler); 1890 signal (SIGFPE, json_sig_handler); 1891 signal (SIGABRT, json_sig_handler); 1892 #endif 1893 r_inputs = getMapOrFill (&request_inputs, "metapath", ""); 1894 char conf_file1[10240]; 1895 maps* m1 = (maps *) malloc (MAPS_SIZE); 1896 snprintf (conf_file1, 10240, "%s/%s/oas.cfg", ntmp, r_inputs->value); 1897 if (conf_read (conf_file1, m1) == 2) 1898 { 1899 errorException (NULL, _("Unable to load the oas.cfg file."), 1900 "InternalError", NULL); 1901 free (m); 1902 return 1; 1903 } 1904 addMapsToMaps(&m,m1); 1905 setMapInMaps(m,"lenv","executionType","json"); 1906 1907 json_object *res=json_object_new_object(); 1908 setMapInMaps(m,"headers","Content-Type","application/json;charset=UTF-8"); 1909 /* - Root url */ 1910 if(cgiContentLength==1){ 1911 map* tmpMap=getMapFromMaps(m,"main","serverAddress"); 1912 json_object *res1=json_object_new_array(); 1913 const char* urls[4]={ 1914 "/","/api","/conformance","/processes" 1915 }; 1916 map* tmpUrl=getMapFromMaps(m,"main","serverAddress"); 1917 for(int kk=0;kk<4;kk++){ 1918 maps* tmpMaps=getMaps(m,urls[kk]); 1919 json_object *res2; 1920 if(tmpMaps!=NULL){ 1921 res2=mapToJson(tmpMaps->content); 1922 char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(urls[kk])+2)*sizeof(char)); 1923 sprintf(tmpStr,"%s%s",tmpUrl->value,urls[kk]); 1924 json_object_object_add(res2,"href",json_object_new_string(tmpStr)); 1925 json_object_array_add(res1,res2); 1926 } 1927 } 1928 json_object_object_add(res,"links",res1); 1929 }else if(strcmp(cgiQueryString,"/conformance")==0){ 1930 /* - /conformance url */ 1931 map* rootUrl=getMapFromMaps(m,"conformTo","rootUrl"); 1932 json_object *res1=json_object_new_array(); 1933 map* length=getMapFromMaps(m,"conformTo","length"); 1934 maps* tmpMaps=getMaps(m,"conformTo"); 1935 for(int kk=0;kk<atoi(length->value);kk++){ 1936 map* tmpMap1=getMapArray(tmpMaps->content,"link",kk); 1937 json_object *res2; 1938 if(tmpMap1!=NULL){ 1939 char* tmpStr=(char*) malloc((strlen(rootUrl->value)+strlen(tmpMap1->value)+1)*sizeof(char)); 1940 sprintf(tmpStr,"%s%s",rootUrl->value,tmpMap1->value); 1941 json_object_array_add(res1,json_object_new_string(tmpStr)); 1942 } 1943 } 1944 json_object_object_add(res,"conformTo",res1); 1945 }else if(strcmp(cgiQueryString,"/api")==0){ 1946 /* - /api url */ 1947 produceApi(m,res); 1948 }else if(strcmp(cgiQueryString,"/processes")==0 || strcmp(cgiQueryString,"/processes/")==0){ 1949 /* - /processes */ 1950 json_object *res3=json_object_new_array(); 1951 int saved_stdout = zDup (fileno (stdout)); 1952 zDup2 (fileno (stderr), fileno (stdout)); 1953 1954 if (int res = 1955 recursReaddirF (m, NULL, res3, NULL, ntmp, NULL, saved_stdout, 0, 1956 printGetCapabilitiesForProcessJ) < 0) 1957 { 1958 } 1959 zDup2 (saved_stdout, fileno (stdout)); 1960 zClose(saved_stdout); 1961 1962 json_object_object_add(res,"processes",res3); 1963 }else{ 1964 service* s1=NULL; 1965 int t=0; 1966 if(strstr(cgiQueryString,"/processes/")==NULL){ 1967 map* error=createMap("code","BadRequest"); 1968 addToMap(error,"message",_("The ressource is not available")); 1969 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 1970 printExceptionReportResponseJ(m,error); 1971 freeMaps (&m); 1972 free (m); 1973 free (REQUEST); 1974 xmlCleanupParser (); 1975 zooXmlCleanupNs (); 1976 return 1; 1977 } else 1978 if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){ 1979 /* - /processes/{id}/ */ 1980 DIR *dirp = opendir (ntmp); 1981 json_object *res3=json_object_new_object(); 1982 char *orig = zStrdup (strstr(cgiQueryString,"/processes/")+11); 1983 if(orig[strlen(orig)-1]=='/') 1984 orig[strlen(orig)-1]=0; 1985 json_object* res1=json_object_new_object(); 1986 int t=fetchServicesForDescription(NULL, m, orig, 1987 printGetCapabilitiesForProcessJ, 1988 NULL, (void*) res3, ntmp, 1989 request_inputs, 1990 printExceptionReportResponseJ); 1991 if(t==1){ 1992 /*map* error=createMap("code","BadRequest"); 1993 addToMap(error,"message",_("Failed to acces the requested service")); 1994 printExceptionReportResponseJ(m,error);*/ 1995 return 1; 1996 } 1997 res=json_object_get(res3); 1998 }else{ 1999 char* queryString=zStrdup(cgiQueryString); 2000 int len0=strlen(strstr(cgiQueryString,"/processes/")+11); 2001 int len1=strlen(cgiQueryString)-strlen(strstr(cgiQueryString,"/job")); 2002 char* cIdentifier=(char*)malloc((len1-10)*sizeof(char)); 2003 int cnt=0; 2004 for(int j=11;j<len1;j++){ 2005 fprintf(stderr,"%s %c\n",cIdentifier,cgiQueryString[j]); 2006 cIdentifier[cnt]=cgiQueryString[j]; 2007 cIdentifier[cnt+1]=0; 2008 cnt++; 2009 } 2010 char tmps1[1024]; 2011 2012 map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 2013 if (import != NULL && import->value != NULL) { 2014 strncpy(tmps1, import->value, 1024); 2015 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 2016 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2017 } 2018 else { 2019 snprintf (tmps1, 1024, "%s/%s.zcfg", ntmp, cIdentifier); 2020 #ifdef DEBUG 2021 fprintf (stderr, "Trying to load %s\n", tmps1); 2022 #endif 2023 if (strstr (cIdentifier, ".") != NULL) 2024 { 2025 char *identifier = zStrdup (cIdentifier); 2026 parseIdentifier (m, ntmp, identifier, tmps1); 2027 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 2028 if (tmpMap != NULL) 2029 addToMap (request_inputs, "metapath", tmpMap->value); 2030 free (identifier); 2031 } 2032 else 2033 { 2034 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2035 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 2036 } 2037 } 2038 2039 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 2040 2041 #ifdef META_DB 2042 int metadb_id=_init_sql(m,"metadb"); 2043 //FAILED CONNECTING DB 2044 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 2045 fprintf(stderr,"ERROR CONNECTING METADB\n"); 2046 } 2047 if(metadb_id>=0) 2048 s1=extractServiceFromDb(m,cIdentifier,0); 2049 if(s1!=NULL){ 2050 inheritance(zooRegistry,&s1); 2051 #ifdef USE_HPC 2052 addNestedOutputs(&s1); 2053 #endif 2054 if(zooRegistry!=NULL){ 2055 freeRegistry(&zooRegistry); 2056 free(zooRegistry); 2057 } 2058 }else /* Not found in MetaDB */{ 2059 #endif 2060 s1 = createService(); 2061 if (s1 == NULL) 2062 { 2063 freeMaps (&m); 2064 free (m); 2065 if(zooRegistry!=NULL){ 2066 freeRegistry(&zooRegistry); 2067 free(zooRegistry); 2068 } 2069 free (REQUEST); 2070 free (SERVICE_URL); 2071 map* error=createMap("code","InternalError"); 2072 addToMap(error,"message",_("Unable to allocate memory")); 2073 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2074 printExceptionReportResponseJ(m,error); 2075 2076 return 1; /*errorException (m, _("Unable to allocate memory"), 2077 "InternalError", NULL);*/ 2078 } 2079 2080 int saved_stdout = zDup (fileno (stdout)); 2081 zDup2 (fileno (stderr), fileno (stdout)); 2082 t = readServiceFile (m, tmps1, &s1, cIdentifier); 2083 if(t>=0){ 2084 inheritance(zooRegistry,&s1); 2085 #ifdef USE_HPC 2086 addNestedOutputs(&s1); 2087 #endif 2088 } 2089 if(zooRegistry!=NULL){ 2090 freeRegistry(&zooRegistry); 2091 free(zooRegistry); 2092 } 2093 fflush (stdout); 2094 zDup2 (saved_stdout, fileno (stdout)); 2095 if (t < 0) 2096 { 2097 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 2098 sprintf (tmpMsg, 2099 _ 2100 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 2101 r_inputs->value); 2102 map* error=createMap("code","InvalidParameterValue"); 2103 addToMap(error,"message",tmpMsg); 2104 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2105 printExceptionReportResponseJ(m,error); 2106 2107 //errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 2108 free (tmpMsg); 2109 free (s1); 2110 freeMaps (&m); 2111 free (m); 2112 free (REQUEST); 2113 free (SERVICE_URL); 2114 return 0; 2115 } 2116 zClose (saved_stdout); 2117 2118 #ifdef META_DB 2119 } 2120 #endif 2121 if(strstr(cgiQueryString,"/jobs/")!=NULL && strlen(strstr(cgiQueryString,"/jobs/"))>6){ 2122 /* - /jobs/{jobID} and /jobs/{jobID}/result urls */ 2123 if(strstr(cgiQueryString,"/result")!=NULL && strlen(strstr(cgiQueryString,"/result"))>=7){ 2124 fprintf(stderr,"For GetResult %s %d \n",__FILE__,__LINE__); 2125 }else{ 2126 char* tmpUrl=strstr(cgiQueryString,"/jobs/"); 2127 if(tmpUrl!=NULL && strlen(tmpUrl)>6){ 2128 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2129 setMapInMaps(m,"lenv","gs_usid",jobId); 2130 json_getStatusFile(m); 2131 free(jobId); 2132 return 1; 2133 } 2134 } 2135 }else{ 2136 /* - /jobs url */ 2137 fprintf(stderr,"For Execute or Job list %s %d \n",__FILE__,__LINE__); 2138 if(strcasecmp(cgiRequestMethod,"get")==0){ 2139 /* - /jobs List (GET) */ 2140 res=printJobList(m); 2141 }else if(strcasecmp(cgiRequestMethod,"post")==0){ 2142 /* - /jobs Execution (POST) */ 2143 int eres = SERVICE_STARTED; 2144 2145 initAllEnvironment(m,request_inputs,ntmp,"jrequest"); 2146 map* req=getMapFromMaps(m,"renv","jrequest"); 2147 json_object *jobj = NULL; 2148 const char *mystring = NULL; 2149 int slen = 0; 2150 enum json_tokener_error jerr; 2151 struct json_tokener* tok=json_tokener_new(); 2152 do { 2153 mystring = req->value; // get JSON string, e.g. read from file, etc... 2154 slen = strlen(mystring); 2155 jobj = json_tokener_parse_ex(tok, mystring, slen); 2156 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 2157 if (jerr != json_tokener_success) { 2158 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2159 return 1; 2160 } 2161 if (tok->char_offset < slen){ 2162 return 1; 2163 } 2164 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2165 // Success, use jobj here. 2166 maps* inputs_real_format=NULL, *outputs_real_format= NULL; 2167 parseJRequest(m,s1,jobj,&inputs_real_format,&outputs_real_format); 2168 map* preference=getMapFromMaps(m,"renv","HTTP_PREFER"); 2169 if(preference!=NULL && strcasecmp(preference->value,"respond-async")==0){ 2170 fprintf(stderr,"Asynchronous call!\n"); 2171 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; 2172 FILE *f0, *f1; 2173 int pid; 2174 #ifdef DEBUG 2175 fprintf (stderr, "\nPID : %d\n", cpid); 2176 #endif 2177 #ifndef WIN32 2178 pid = fork (); 2179 #else 2180 if (cgiSid == NULL) 2181 { 2182 createProcess (m, request_inputs, s1, NULL, cpid, 2183 request_input_real_format, 2184 request_output_real_format); 2185 pid = cpid; 2186 } 2187 else 2188 { 2189 pid = 0; 2190 cpid = atoi (cgiSid); 2191 updateStatus(m,0,_("Initializing")); 2192 } 2193 #endif 2194 if (pid > 0) 2195 { 2196 // 2197 // dady : 2198 // set status to SERVICE_ACCEPTED 2199 // 2200 #ifdef DEBUG 2201 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2202 zGetpid ()); 2203 #endif 2204 eres = SERVICE_ACCEPTED; 2205 createStatusFile(m,eres); 2206 printHeaders(m); 2207 printf("Status: 201 Created \r\n\r\n"); 2208 return 1; 2209 } 2210 else if (pid == 0) 2211 { 2212 eres = SERVICE_STARTED; 2213 // 2214 // son : have to close the stdout, stdin and stderr to let the parent 2215 // process answer to http client. 2216 // 2217 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2218 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2219 int cpid = atoi (tmpm->value); 2220 pid=cpid; 2221 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2222 setMapInMaps (m, "lenv", "async","true"); 2223 map* r_inputs1 = createMap("ServiceName", s1->name); 2224 // Create the filename for the result file (.res) 2225 fbkpres = 2226 (char *) 2227 malloc ((strlen (r_inputs->value) + 2228 strlen (usid->value) + 7) * sizeof (char)); 2229 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2230 maps* bmap = createMaps("status"); 2231 bmap->content=createMap("usid",usid->value); 2232 addToMap(bmap->content,"sid",tmpm->value); 2233 addIntToMap(bmap->content,"pid",zGetpid()); 2234 2235 // Create PID file referencing the OS process identifier 2236 fbkpid = 2237 (char *) 2238 malloc ((strlen (r_inputs->value) + 2239 strlen (usid->value) + 7) * sizeof (char)); 2240 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 2241 setMapInMaps (m, "lenv", "file.pid", fbkpid); 2242 2243 f0 = freopen (fbkpid, "w+",stdout); 2244 printf("%d",zGetpid()); 2245 fflush(stdout); 2246 2247 // Create SID file referencing the semaphore name 2248 fbkp = 2249 (char *) 2250 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2251 strlen (usid->value) + 7) * sizeof (char)); 2252 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 2253 setMapInMaps (m, "lenv", "file.sid", fbkp); 2254 FILE* f2 = freopen (fbkp, "w+",stdout); 2255 printf("%s",tmpm->value); 2256 fflush(f2); 2257 free(fbkp); 2258 2259 fbkp = 2260 (char *) 2261 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2262 strlen (usid->value) + 7) * sizeof (char)); 2263 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 2264 usid->value); 2265 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 2266 flog = 2267 (char *) 2268 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2269 strlen (usid->value) + 13) * sizeof (char)); 2270 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2271 r_inputs1->value, usid->value); 2272 setMapInMaps (m, "lenv", "file.log", flog); 2273 #ifdef DEBUG 2274 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 2275 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 2276 zGetpid ()); 2277 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 2278 #endif 2279 freopen (flog, "w+", stderr); 2280 fflush (stderr); 2281 f0 = freopen (fbkp, "w+", stdout); 2282 rewind (stdout); 2283 #ifndef WIN32 2284 fclose (stdin); 2285 #endif 2286 #ifdef RELY_ON_DB 2287 init_sql(m); 2288 recordServiceStatus(m); 2289 #endif 2290 #ifdef USE_CALLBACK 2291 invokeCallback(m,NULL,NULL,0,0); 2292 #endif 2293 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 2294 fflush(stderr); 2295 2296 createStatusFile(m,eres); 2297 2298 2299 fbkp1 = 2300 (char *) 2301 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2302 strlen (usid->value) + 15) * sizeof (char)); 2303 sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value, 2304 r_inputs1->value, usid->value); 2305 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 2306 2307 f1 = freopen (fbkp1, "w+", stdout); 2308 2309 map* serviceTypeMap=getMap(s1->content,"serviceType"); 2310 if(serviceTypeMap!=NULL) 2311 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 2312 2313 char *flenv = 2314 (char *) 2315 malloc ((strlen (r_inputs->value) + 2316 strlen (usid->value) + 12) * sizeof (char)); 2317 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2318 maps* lenvMaps=getMaps(m,"lenv"); 2319 dumpMapsToFile(lenvMaps,flenv,0); 2320 free(flenv); 2321 2322 map* testMap=getMapFromMaps(m,"main","memory"); 2323 loadHttpRequests(m,inputs_real_format); 2324 loadServiceAndRun (&m, s1, request_inputs, 2325 &inputs_real_format, 2326 &outputs_real_format, &eres); 2327 createStatusFile(m,eres); 2328 res=printJResult(m,s1,outputs_real_format,eres); 2329 char tmpUrl0[1024]; 2330 const char* jsonStr=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2331 printf(jsonStr); 2332 printf("\n"); 2333 return 1; 2334 2335 } 2336 }else{ 2337 loadHttpRequests(m,inputs_real_format); 2338 loadServiceAndRun (&m,s1,request_inputs,&inputs_real_format,&outputs_real_format,&eres); 2339 res=printJResult(m,s1,outputs_real_format,eres); 2340 2341 printHeaders(m); 2342 printf("Status: 201 Created \r\n\r\n"); 2343 const char* jsonStr=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2344 printf(jsonStr); 2345 printf("\n"); 2346 return 1; 2347 } 2348 2349 2350 }//else error 2351 2352 } 2353 } 2354 } 2355 printHeaders(m); 2356 printf("Status: 200 OK \r\n\r\n"); 2357 const char* jsonStr=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2358 printf(jsonStr); 2359 printf("\n"); 2360 return 1; 2361 #endif 2362 } 2363 2364 // 2365 // WPS 1.0.0 and 2.0.0 starts here 2366 // 1180 2367 //Check for minimum inputs 1181 2368 map* version=getMap(request_inputs,"version"); … … 1282 2469 1283 2470 2471 1284 2472 service *s1; 1285 2473 int scount = 0; … … 1287 2475 dumpMap (r_inputs); 1288 2476 #endif 1289 char conf_dir[1024]; 1290 int t; 1291 char tmps1[1024]; 1292 1293 r_inputs = NULL; 1294 r_inputs = getMap (request_inputs, "metapath"); 1295 map* cwdMap0=getMapFromMaps(m,"main","servicePath"); 1296 if (r_inputs != NULL) 1297 if(cwdMap0!=NULL) 1298 snprintf (conf_dir, 1024, "%s/%s", cwdMap0->value, r_inputs->value); 1299 else 1300 snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value); 1301 else 1302 if(cwdMap0!=NULL) 1303 snprintf (conf_dir, 1024, "%s", cwdMap0->value); 1304 else 1305 snprintf (conf_dir, 1024, "%s", ntmp); 1306 map* reg = getMapFromMaps (m, "main", "registry"); 1307 registry* zooRegistry=NULL; 1308 if(reg!=NULL){ 1309 #ifndef WIN32 1310 int saved_stdout = zDup (fileno (stdout)); 1311 zDup2 (fileno (stderr), fileno (stdout)); 1312 #endif 1313 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1314 map *message=getMapFromMaps(m,"lenv","message"); 1315 map *type=getMapFromMaps(m,"lenv","type"); 1316 #ifndef WIN32 1317 zDup2 (saved_stdout, fileno (stdout)); 1318 #endif 1319 errorException (m, message->value, 1320 type->value, NULL); 1321 return 0; 1322 } 1323 #ifndef WIN32 1324 zDup2 (saved_stdout, fileno (stdout)); 1325 zClose(saved_stdout); 1326 #endif 1327 } 1328 2477 1329 2478 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 1330 { 2479 { 1331 2480 #ifdef DEBUG 1332 2481 dumpMap (r_inputs); … … 1396 2545 } 1397 2546 else 1398 { 2547 { 1399 2548 r_inputs = getMap (request_inputs, "JobId"); 1400 2549 if(reqId>nbReqIdentifier){ … … 1471 2620 r_inputs = getMap (request_inputs, "Identifier"); 1472 2621 1473 char *orig = zStrdup (r_inputs->value); 1474 1475 int saved_stdout = zDup (fileno (stdout)); 1476 zDup2 (fileno (stderr), fileno (stdout)); 1477 if (strcasecmp ("all", orig) == 0) 1478 { 1479 maps* imports = getMaps(m, IMPORTSERVICE); 1480 if (imports != NULL) { 1481 map* zcfg = imports->content; 1482 1483 while (zcfg != NULL) { 1484 if (zcfg->value != NULL) { 1485 service* svc = (service*) malloc(SERVICE_SIZE); 1486 if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { 1487 // pass over silently 1488 zcfg = zcfg->next; 1489 continue; 1490 } 1491 inheritance(zooRegistry, &svc); 1492 #ifdef USE_HPC 1493 addNestedOutputs(&svc); 1494 #endif 1495 1496 printDescribeProcessForProcess(zooRegistry, m, doc, n, svc); 1497 freeService(&svc); 1498 free(svc); 1499 } 1500 zcfg = zcfg->next; 1501 } 1502 } 1503 1504 if (int res = 1505 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1506 printDescribeProcessForProcess) < 0) 1507 return res; 1508 #ifdef META_DB 1509 fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0); 1510 close_sql(m,0); 1511 #endif 1512 1513 } 1514 else 1515 { 1516 char *saveptr; 1517 char *tmps = strtok_r (orig, ",", &saveptr); 1518 1519 char buff[256]; 1520 char buff1[1024]; 1521 while (tmps != NULL) 1522 { 1523 int hasVal = -1; 1524 char *corig = zStrdup (tmps); 1525 map* import = getMapFromMaps (m, IMPORTSERVICE, corig); 1526 if (import != NULL && import->value != NULL) 1527 { 1528 #ifdef META_DB 1529 service* s2=extractServiceFromDb(m,import->name,0); 1530 if(s2==NULL){ 1531 #endif 1532 s1 = createService(); 1533 t = readServiceFile (m, import->value, &s1, import->name); 1534 1535 if (t < 0) // failure reading zcfg 1536 { 1537 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1538 char tmp01[1024]; 1539 if (tmp00 != NULL) 1540 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); 1541 else 1542 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1543 1544 zDup2 (saved_stdout, fileno (stdout)); 1545 errorException (m, tmp01, "InternalError", NULL); 1546 1547 freeMaps (&m); 1548 free (m); 1549 1550 if(zooRegistry!=NULL){ 1551 freeRegistry(&zooRegistry); 1552 free(zooRegistry); 1553 } 1554 free (orig); 1555 free (REQUEST); 1556 closedir (dirp); 1557 //xmlFreeDoc (doc); 1558 xmlCleanupParser (); 1559 zooXmlCleanupNs (); 1560 1561 return 1; 1562 } 1563 #ifdef DEBUG 1564 dumpService (s1); 1565 #endif 1566 inheritance(zooRegistry,&s1); 1567 #ifdef USE_HPC 1568 addNestedOutputs(&s1); 1569 #endif 1570 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1571 freeService (&s1); 1572 free (s1); 1573 s1 = NULL; 1574 scount++; 1575 hasVal = 1; 1576 #ifdef META_DB 1577 } 1578 #endif 1579 } 1580 else if (strstr (corig, ".") != NULL) 1581 { 1582 1583 parseIdentifier (m, conf_dir, corig, buff1); 1584 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 1585 if (tmpMap != NULL) 1586 addToMap (request_inputs, "metapath", tmpMap->value); 1587 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1588 /** 1589 * No support for dot in service name stored in metadb!? 1590 // #ifdef META_DB 1591 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 1592 if(s2==NULL){ 1593 // #endif 1594 */ 1595 s1 = createService(); 1596 t = readServiceFile (m, buff1, &s1, tmpMapI->value); 1597 if (t < 0) 1598 { 1599 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1600 char tmp01[1024]; 1601 if (tmp00 != NULL) 1602 sprintf (tmp01, 1603 _ 1604 ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"), 1605 tmps, tmp00->value); 1606 else 1607 sprintf (tmp01, 1608 _ 1609 ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), 1610 tmps); 1611 zDup2 (saved_stdout, fileno (stdout)); 1612 errorException (m, tmp01, "InvalidParameterValue", 1613 "identifier"); 1614 freeMaps (&m); 1615 free (m); 1616 if(zooRegistry!=NULL){ 1617 freeRegistry(&zooRegistry); 1618 free(zooRegistry); 1619 } 1620 free (REQUEST); 1621 free (corig); 1622 free (orig); 1623 free (SERVICE_URL); 1624 free (s1); 1625 closedir (dirp); 1626 //xmlFreeDoc (doc); 1627 xmlCleanupParser (); 1628 zooXmlCleanupNs (); 1629 return 1; 1630 } 1631 #ifdef DEBUG 1632 dumpService (s1); 1633 #endif 1634 inheritance(zooRegistry,&s1); 1635 #ifdef USE_HPC 1636 addNestedOutputs(&s1); 1637 #endif 1638 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1639 freeService (&s1); 1640 free (s1); 1641 s1 = NULL; 1642 scount++; 1643 hasVal = 1; 1644 setMapInMaps (m, "lenv", "level", "0"); 1645 } 1646 else 1647 { 1648 #ifdef META_DB 1649 _init_sql(m,"metadb"); 1650 //FAILED CONNECTING DB 1651 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 1652 fprintf(stderr,"ERROR CONNECTING METADB"); 1653 } 1654 service* s2=extractServiceFromDb(m,corig,0); 1655 if(s2!=NULL){ 1656 inheritance(zooRegistry,&s2); 1657 #ifdef USE_HPC 1658 addNestedOutputs(&s2); 1659 #endif 1660 printDescribeProcessForProcess (zooRegistry,m, doc, n, s2); 1661 freeService (&s2); 1662 free (s2); 1663 s2 = NULL; 1664 hasVal = 1; 1665 }else /*TOTO*/{ 1666 #endif 1667 memset (buff, 0, 256); 1668 snprintf (buff, 256, "%s.zcfg", corig); 1669 memset (buff1, 0, 1024); 1670 #ifdef DEBUG 1671 printf ("\n#######%s\n########\n", buff); 1672 #endif 1673 while ((dp = readdir (dirp)) != NULL) 1674 { 1675 if (strcasecmp (dp->d_name, buff) == 0) 1676 { 1677 memset (buff1, 0, 1024); 1678 snprintf (buff1, 1024, "%s/%s", conf_dir, 1679 dp->d_name); 1680 s1 = createService(); 1681 if (s1 == NULL) 1682 { 1683 zDup2 (saved_stdout, fileno (stdout)); 1684 return errorException (m, 1685 _ 1686 ("Unable to allocate memory"), 1687 "InternalError", 1688 NULL); 1689 } 1690 #ifdef DEBUG_SERVICE_CONF 1691 fprintf 1692 (stderr,"#################\n(%s) %s\n#################\n", 1693 r_inputs->value, buff1); 1694 #endif 1695 char *tmp0 = zStrdup (dp->d_name); 1696 tmp0[strlen (tmp0) - 5] = 0; 1697 t = readServiceFile (m, buff1, &s1, tmp0); 1698 free (tmp0); 1699 if (t < 0) 1700 { 1701 map *tmp00 = 1702 getMapFromMaps (m, "lenv", "message"); 1703 char tmp01[1024]; 1704 if (tmp00 != NULL) 1705 sprintf (tmp01, 1706 _ 1707 ("Unable to parse the ZCFG file: %s (%s)"), 1708 dp->d_name, tmp00->value); 1709 else 1710 sprintf (tmp01, 1711 _ 1712 ("Unable to parse the ZCFG file: %s."), 1713 dp->d_name); 1714 zDup2 (saved_stdout, fileno (stdout)); 1715 errorException (m, tmp01, "InternalError", 1716 NULL); 1717 freeMaps (&m); 1718 free (m); 1719 if(zooRegistry!=NULL){ 1720 freeRegistry(&zooRegistry); 1721 free(zooRegistry); 1722 } 1723 free (orig); 1724 free (REQUEST); 1725 closedir (dirp); 1726 //xmlFreeDoc (doc); 1727 xmlCleanupParser (); 1728 zooXmlCleanupNs (); 1729 return 1; 1730 } 1731 #ifdef DEBUG 1732 dumpService (s1); 1733 #endif 1734 inheritance(zooRegistry,&s1); 1735 #ifdef USE_HPC 1736 addNestedOutputs(&s1); 1737 #endif 1738 /*json_object* jobj=serviceToJson(s1); 1739 const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN); 1740 fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/ 1741 1742 printDescribeProcessForProcess (zooRegistry,m, doc, n, s1); 1743 freeService (&s1); 1744 free (s1); 1745 s1 = NULL; 1746 scount++; 1747 hasVal = 1; 1748 } 1749 } 1750 #ifdef META_DB 1751 } 1752 #endif 1753 } 1754 if (hasVal < 0) 1755 { 1756 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1757 char tmp01[1024]; 1758 if (tmp00 != NULL) 1759 sprintf (tmp01, 1760 _("Unable to parse the ZCFG file: %s (%s)"), 1761 buff, tmp00->value); 1762 else 1763 sprintf (tmp01, 1764 _("Unable to parse the ZCFG file: %s."), 1765 buff); 1766 zDup2 (saved_stdout, fileno (stdout)); 1767 errorException (m, tmp01, "InvalidParameterValue", 1768 "Identifier"); 1769 freeMaps (&m); 1770 free (m); 1771 if(zooRegistry!=NULL){ 1772 freeRegistry(&zooRegistry); 1773 free(zooRegistry); 1774 } 1775 free (orig); 1776 free (REQUEST); 1777 closedir (dirp); 1778 if (corig != NULL) 1779 free (corig); 1780 xmlFreeDoc (doc); 1781 xmlCleanupParser (); 1782 zooXmlCleanupNs (); 1783 return 1; 1784 } 1785 rewinddir (dirp); 1786 tmps = strtok_r (NULL, ",", &saveptr); 1787 if (corig != NULL) 1788 free (corig); 1789 } 1790 } 1791 closedir (dirp); 1792 fflush (stdout); 1793 zDup2 (saved_stdout, fileno (stdout)); 1794 free (orig); 2622 fetchServicesForDescription(zooRegistry, m, r_inputs->value, 2623 printDescribeProcessForProcess, 2624 (void*) doc, (void*) n, conf_dir, 2625 request_inputs,printExceptionReportResponse); 2626 1795 2627 printDocument (m, doc, zGetpid ()); 1796 2628 freeMaps (&m); … … 1810 2642 } 1811 2643 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 1812 { 2644 { 1813 2645 map* version=getMapFromMaps(m,"main","rversion"); 1814 2646 int vid=getVersionId(version->value); … … 1867 2699 } 1868 2700 } 1869 2701 1870 2702 map *postRequest = NULL; 1871 2703 postRequest = getMap (request_inputs, "xrequest"); … … 1950 2782 "InternalError", NULL); 1951 2783 } 1952 2784 1953 2785 int saved_stdout = zDup (fileno (stdout)); 1954 2786 zDup2 (fileno (stderr), fileno (stdout)); … … 2024 2856 } 2025 2857 //InternetCloseHandle (&hInternet); 2026 2027 // Define each env variable in runing environment 2028 maps *curs = getMaps (m, "env"); 2029 if (curs != NULL) 2030 { 2031 map *mapcs = curs->content; 2032 while (mapcs != NULLMAP) 2033 { 2034 #ifndef WIN32 2035 setenv (mapcs->name, mapcs->value, 1); 2036 #ifdef DEBUG 2037 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, 2038 mapcs->value); 2039 #endif 2040 #else 2041 if (mapcs->value[strlen (mapcs->value) - 2] == '\r') 2042 { 2043 #ifdef DEBUG 2044 fprintf (stderr, "[ZOO: Env var finish with \r]\n"); 2045 #endif 2046 mapcs->value[strlen (mapcs->value) - 1] = 0; 2047 } 2048 #ifdef DEBUG 2049 if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0) 2050 { 2051 fflush (stderr); 2052 fprintf (stderr, "setting variable... %s\n", "OK"); 2053 } 2054 else 2055 { 2056 fflush (stderr); 2057 fprintf (stderr, "setting variable... %s\n", "OK"); 2058 } 2059 #else 2060 SetEnvironmentVariable (mapcs->name, mapcs->value); 2061 #endif 2062 char *toto = 2063 (char *) 2064 malloc ((strlen (mapcs->name) + strlen (mapcs->value) + 2065 2) * sizeof (char)); 2066 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 2067 _putenv (toto); 2068 #ifdef DEBUG 2069 fflush (stderr); 2070 #endif 2071 #endif 2072 2073 #ifdef DEBUG 2074 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, 2075 mapcs->value); 2076 fflush (stderr); 2077 #endif 2078 mapcs = mapcs->next; 2079 } 2080 } 2858 2859 initAllEnvironment(m,request_inputs,ntmp,"xrequest"); 2860 2081 2861 2082 2862 #ifdef DEBUG 2083 2863 dumpMap (request_inputs); 2084 2864 #endif 2085 2865 2086 2866 map *status = getMap (request_inputs, "status"); 2087 2867 if(vid==0){ … … 2164 2944 int eres = SERVICE_STARTED; 2165 2945 int cpid = zGetpid (); 2166 2167 // Create a map containing a copy of the request map 2168 maps *_tmpMaps = createMaps("request"); 2169 addMapToMap(&_tmpMaps->content,request_inputs); 2170 addMapsToMaps (&m, _tmpMaps); 2171 freeMaps (&_tmpMaps); 2172 free (_tmpMaps); 2173 /** 2174 * Initialize the specific [lenv] section which contains runtime variables: 2175 * 2176 * - usid : it is an universally unique identifier 2177 * - osid : it is an idenfitication number 2178 * - sid : it is the process idenfitication number (OS) 2179 * - uusid : it is an universally unique identifier 2180 * - status : value between 0 and 100 to express the completude of 2181 * the operations of the running service 2182 * - message : is a string where you can store error messages, in case 2183 * service is failing, or o provide details on the ongoing operation. 2184 * - cwd : the current working directory or servicePath if defined 2185 * - soap : is a boolean value, true if the request was contained in a SOAP 2186 * Envelop 2187 * - sessid : string storing the session identifier (only when cookie is 2188 * used) 2189 * - cgiSid : only defined on Window platforms (for being able to identify 2190 * the created process) 2191 * 2192 */ 2193 _tmpMaps = createMaps("lenv"); 2194 char tmpBuff[100]; 2195 struct ztimeval tp; 2196 if (zGettimeofday (&tp, NULL) == 0) 2197 sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec))); 2198 else 2199 sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); 2200 _tmpMaps->content = createMap ("osid", tmpBuff); 2201 sprintf (tmpBuff, "%i", cpid); 2202 addToMap (_tmpMaps->content, "sid", tmpBuff); 2203 char* tmpUuid=get_uuid(); 2204 addToMap (_tmpMaps->content, "uusid", tmpUuid); 2205 addToMap (_tmpMaps->content, "usid", tmpUuid); 2206 free(tmpUuid); 2207 addToMap (_tmpMaps->content, "status", "0"); 2208 if(cwdMap0!=NULL){ 2209 addToMap (_tmpMaps->content, "cwd", cwdMap0->value); 2210 addToMap (_tmpMaps->content, "rcwd", ntmp); 2211 } 2212 else 2213 addToMap (_tmpMaps->content, "cwd", ntmp); 2214 addToMap (_tmpMaps->content, "message", _("No message provided")); 2215 map *ltmp = getMap (request_inputs, "soap"); 2216 if (ltmp != NULL) 2217 addToMap (_tmpMaps->content, "soap", ltmp->value); 2218 else 2219 addToMap (_tmpMaps->content, "soap", "false"); 2220 2221 // Parse the session file and add it to the main maps 2222 char* originalCookie=NULL; 2223 if (cgiCookie != NULL && strlen (cgiCookie) > 0) 2224 { 2225 int hasValidCookie = -1; 2226 char *tcook = originalCookie = zStrdup (cgiCookie); 2227 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 2228 parseCookie(&m,originalCookie); 2229 map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value)); 2230 if (sessId!=NULL) 2231 { 2232 addToMap (_tmpMaps->content, "sessid", sessId->value); 2233 char session_file_path[1024]; 2234 map *tmpPath = getMapFromMaps (m, "main", "sessPath"); 2235 if (tmpPath == NULL) 2236 tmpPath = getMapFromMaps (m, "main", "tmpPath"); 2237 char *tmp1 = strtok (tcook, ";"); 2238 if (tmp1 != NULL) 2239 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2240 sessId->value); 2241 else 2242 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2243 sessId->value); 2244 free (tcook); 2245 maps *tmpSess = (maps *) malloc (MAPS_SIZE); 2246 tmpSess->child=NULL; 2247 struct stat file_status; 2248 int istat = stat (session_file_path, &file_status); 2249 if (istat == 0 && file_status.st_size > 0) 2250 { 2251 int saved_stdout = zDup (fileno (stdout)); 2252 zDup2 (fileno (stderr), fileno (stdout)); 2253 conf_read (session_file_path, tmpSess); 2254 addMapsToMaps (&m, tmpSess); 2255 freeMaps (&tmpSess); 2256 fflush(stdout); 2257 zDup2 (saved_stdout, fileno (stdout)); 2258 zClose(saved_stdout); 2259 } 2260 free (tmpSess); 2261 } 2262 } 2263 addMapsToMaps (&m, _tmpMaps); 2264 freeMaps (&_tmpMaps); 2265 free (_tmpMaps); 2946 2266 2947 maps* bmap=NULL; 2267 #ifdef DEBUG2268 dumpMap (request_inputs);2269 #endif2270 int ei = 1;2271 2272 _tmpMaps = createMaps("renv");2273 2274 #ifdef WIN322275 LPVOID orig = GetEnvironmentStrings();2276 LPTSTR s = (LPTSTR) orig;2277 2278 while (*s != NULL) {2279 char* env = strdup(s);2280 char* delim = strchr(env,'=');2281 if (delim != NULL) {2282 char* val = delim+1;2283 *delim = '\0';2284 if(_tmpMaps->content == NULL) {2285 _tmpMaps->content = createMap(env,val);2286 }2287 else {2288 addToMap(_tmpMaps->content,env,val);2289 }2290 }2291 s += strlen(s)+1;2292 }2293 FreeEnvironmentStrings((LPCH)orig);2294 #else2295 char **orig = environ;2296 char *s=*orig;2297 2298 if(orig!=NULL)2299 for (;2300 s;2301 ei++2302 ) {2303 if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){2304 int len=strlen(s);2305 char* tmpName=zStrdup(s);2306 char* tmpValue=strstr(s,"=")+1;2307 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char));2308 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName);2309 if(_tmpMaps->content == NULL)2310 _tmpMaps->content = createMap (tmpName1,tmpValue);2311 else2312 addToMap (_tmpMaps->content,tmpName1,tmpValue);2313 free(tmpName1);2314 free(tmpName);2315 }2316 s = *(orig+ei);2317 }2318 #endif2319 2320 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){2321 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]);2322 }2323 addMapsToMaps (&m, _tmpMaps);2324 freeMaps (&_tmpMaps);2325 free (_tmpMaps);2326 2327 if(postRequest!=NULL)2328 setMapInMaps (m, "renv", "xrequest", postRequest->value);2329 //dumpMaps(m);2330 #ifdef WIN322331 char *cgiSidL = NULL;2332 if (getenv ("CGISID") != NULL)2333 addToMap (request_inputs, "cgiSid", getenv ("CGISID"));2334 2335 char* usidp;2336 if ( (usidp = getenv("USID")) != NULL ) {2337 setMapInMaps (m, "lenv", "usid", usidp);2338 }2339 2340 map *test1 = getMap (request_inputs, "cgiSid");2341 if (test1 != NULL){2342 cgiSid = zStrdup(test1->value);2343 addToMap (request_inputs, "storeExecuteResponse", "true");2344 addToMap (request_inputs, "status", "true");2345 setMapInMaps (m, "lenv", "osid", test1->value);2346 status = getMap (request_inputs, "status");2347 }2348 test1 = getMap (request_inputs, "usid");2349 if (test1 != NULL){2350 setMapInMaps (m, "lenv", "usid", test1->value);2351 setMapInMaps (m, "lenv", "uusid", test1->value);2352 }2353 #endif2354 2355 2948 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; 2356 2949 FILE *f0, *f1; … … 2360 2953 if (status == NULLMAP) 2361 2954 { 2362 2363 2955 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2364 2956 freeService (&s1); … … 2699 3291 if(cgiSid!=NULL) 2700 3292 free(cgiSid); 2701 //InternetCloseHandle (&hInternet);3293 InternetCloseHandle (&hInternet); 2702 3294 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2703 3295 fflush(stderr);
Note: See TracChangeset
for help on using the changeset viewer.