- Timestamp:
- Feb 2, 2015, 10:04:56 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c
r532 r549 37 37 #include <libxml/xpath.h> 38 38 #include <libxml/xpathInternals.h> 39 #include "service_zcfg.h"40 39 #include <libgen.h> 41 40 } 42 41 #include "ulinet.h" 42 #include "service_zcfg.h" 43 43 #include <libintl.h> 44 44 #include <locale.h> 45 45 #include <string.h> 46 #include "service.h"47 #include "service_internal.h"46 //#include "service.h" 47 //#include "service_internal.h" 48 48 #ifdef USE_PYTHON 49 49 #include "service_internal_python.h" … … 172 172 ("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."), 173 173 mi->name, atoi (testMap->value)); 174 errorException (m, emsg, "InternalError", NULL);174 //errorException (m, emsg, "InternalError", NULL,stderr); 175 175 return -1; 176 176 } … … 193 193 ("ZOO-Kernel was unable to load your data for %s position %s."), 194 194 mi->name, tmpMap->value); 195 errorException (m, emsg, "InternalError", NULL);195 //errorException (m, emsg, "InternalError", NULL,stderr); 196 196 return -1; 197 197 } … … 204 204 ("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."), 205 205 mi->name); 206 errorException (m, emsg, "InternalError", NULL);206 //errorException (m, emsg, "InternalError", NULL,request->out); 207 207 return -1; 208 208 } … … 390 390 ("ZOO Kernel failed to process your request receiving signal %d = %s"), 391 391 sig, ssig); 392 errorException (NULL, tmp, "InternalError", NULL);392 //errorException (NULL, tmp, "InternalError", NULL,request->out); 393 393 #ifdef DEBUG 394 394 fprintf (stderr, "Not this time!\n"); … … 399 399 void 400 400 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, 401 maps ** inputs, maps ** ioutputs, int *eres )401 maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err) 402 402 { 403 char tmps1[1024]; 403 404 405 char tmps1[1024]; 404 406 char ntmp[1024]; 405 407 maps *m = *myMap; … … 523 525 (execute_t) GetProcAddress (so, s1->name); 524 526 #else 527 525 528 execute_t execute = (execute_t) dlsym (so, s1->name); 526 529 #endif … … 539 542 ("Error occured while running the %s function: %s"), 540 543 s1->name, errstr); 541 errorException (m, tmpMsg, "InternalError", NULL );544 errorException (m, tmpMsg, "InternalError", NULL,out); 542 545 free (tmpMsg); 543 546 #ifdef DEBUG 544 547 fprintf (stderr, "Function %s error %s\n", 545 548 s1->name, errstr); 546 #endif 549 #endif 550 547 551 *eres = -1; 548 552 return; 549 553 } 554 550 555 #ifdef DEBUG 551 556 #ifdef WIN32 … … 568 573 fflush (stderr); 569 574 #endif 575 576 577 570 578 } 571 579 #ifdef WIN32 … … 589 597 sprintf (tmps, _("C Library can't be loaded %s"), errstr); 590 598 map *tmps1 = createMap ("text", tmps); 591 printExceptionReportResponse (m, tmps1 );599 printExceptionReportResponse (m, tmps1,out); 592 600 *eres = -1; 593 601 freeMap (&tmps1); … … 602 610 zoo_python_support (&m, request_inputs, s1, 603 611 &request_input_real_format, 604 &request_output_real_format); 612 &request_output_real_format,err); 613 605 614 } 606 615 else … … 670 679 r_inputs->value); 671 680 map *tmps = createMap ("text", tmpv); 672 printExceptionReportResponse (m, tmps );681 printExceptionReportResponse (m, tmps,out); 673 682 *eres = -1; 674 683 } … … 794 803 795 804 int 796 runRequest (map ** inputs )805 runRequest (map ** inputs,struct cgi_env ** c,FCGX_Request *request) 797 806 { 798 807 808 809 struct cgi_env *cgi = *c; 799 810 #ifndef USE_GDB 800 811 (void) signal (SIGSEGV, sig_handler); … … 813 824 * Parsing service specfic configuration file 814 825 */ 826 815 827 m = (maps *) malloc (MAPS_SIZE); 816 828 if (m == NULL) 817 829 { 818 830 return errorException (m, _("Unable to allocate memory."), 819 "InternalError", NULL); 820 } 831 "InternalError", NULL,request->out); 832 } 833 821 834 char ntmp[1024]; 822 835 #ifndef WIN32 … … 827 840 r_inputs = getMapOrFill (&request_inputs, "metapath", ""); 828 841 829 830 char conf_file[10240]; 831 snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); 842 //m = get_main_conf(); 843 844 char conf_file[10240]; 845 snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value); 846 832 847 if (conf_read (conf_file, m) == 2) 833 848 { 834 849 errorException (NULL, _("Unable to load the main.cfg file."), 835 "InternalError", NULL );850 "InternalError", NULL,request->out); 836 851 free (m); 837 852 return 1; 838 853 } 854 855 839 856 #ifdef DEBUG 840 857 fprintf (stderr, "***** BEGIN MAPS\n"); … … 844 861 845 862 map *getPath = getMapFromMaps (m, "main", "gettextPath"); 863 864 865 866 846 867 if (getPath != NULL) 847 868 { … … 854 875 bindtextdomain ("zoo-services", "/usr/share/locale/"); 855 876 } 856 857 877 858 878 /** … … 878 898 ("The value %s is not supported for the <language> parameter"), 879 899 r_inputs->value); 880 errorException (m, tmp, "InvalidParameterValue", "language" );900 errorException (m, tmp, "InvalidParameterValue", "language",request->out); 881 901 freeMaps (&m); 882 902 free (m); … … 929 949 setMapInMaps (m, "main", "isSoap", "false"); 930 950 931 if (strlen (cgi ServerName) > 0)951 if (strlen (cgi->cgiServerName) > 0) 932 952 { 933 953 char tmpUrl[1024]; 934 if (strncmp (cgi ServerPort, "80", 2) == 0)935 { 936 sprintf (tmpUrl, "http://%s%s", cgi ServerName,cgiScriptName);954 if (strncmp (cgi->cgiServerPort, "80", 2) == 0) 955 { 956 sprintf (tmpUrl, "http://%s%s", cgi->cgiServerName, cgi->cgiScriptName); 937 957 } 938 958 else 939 959 { 940 sprintf (tmpUrl, "http://%s:%s%s", cgi ServerName,941 cgi ServerPort,cgiScriptName);960 sprintf (tmpUrl, "http://%s:%s%s", cgi->cgiServerName, 961 cgi->cgiServerPort, cgi->cgiScriptName); 942 962 } 943 963 #ifdef DEBUG … … 954 974 { 955 975 errorException (m, _("Parameter <request> was not specified"), 956 "MissingParameterValue", "request" );976 "MissingParameterValue", "request",request->out); 957 977 if (count (request_inputs) == 1) 958 978 { … … 974 994 _ 975 995 ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), 976 "OperationNotSupported", r_inputs->value );996 "OperationNotSupported", r_inputs->value,request->out); 977 997 freeMaps (&m); 978 998 free (m); … … 986 1006 { 987 1007 errorException (m, _("Parameter <service> was not specified"), 988 "MissingParameterValue", "service" );1008 "MissingParameterValue", "service",request->out); 989 1009 freeMaps (&m); 990 1010 free (m); … … 999 1019 _ 1000 1020 ("Unenderstood <service> value, WPS is the only acceptable value."), 1001 "InvalidParameterValue", "service" );1021 "InvalidParameterValue", "service",request->out); 1002 1022 freeMaps (&m); 1003 1023 free (m); … … 1012 1032 { 1013 1033 errorException (m, _("Parameter <version> was not specified"), 1014 "MissingParameterValue", "version" );1034 "MissingParameterValue", "version",request->out); 1015 1035 freeMaps (&m); 1016 1036 free (m); … … 1025 1045 _ 1026 1046 ("Unenderstood <version> value, 1.0.0 is the only acceptable value."), 1027 "InvalidParameterValue", "service" );1047 "InvalidParameterValue", "service",request->out); 1028 1048 freeMaps (&m); 1029 1049 free (m); … … 1043 1063 _ 1044 1064 ("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."), 1045 "VersionNegotiationFailed", NULL );1065 "VersionNegotiationFailed", NULL,request->out); 1046 1066 freeMaps (&m); 1047 1067 free (m); … … 1080 1100 else 1081 1101 snprintf (conf_dir, 1024, "%s", ntmp); 1102 1103 1104 1082 1105 1083 1106 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) … … 1098 1121 * has been found in the zcfg and then printed on stdout 1099 1122 */ 1100 int saved_stdout = dup (fileno (stdout));1101 dup2 (fileno (stderr), fileno (stdout));1102 1103 /**1104 if (int res =1105 recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,1106 printGetCapabilitiesForProcess) < 0)1107 {1108 freeMaps (&m);1109 free (m);1110 free (REQUEST);1111 free (SERVICE_URL);1112 fflush (stdout);1113 return res;1114 }1115 **/1116 1123 XML_CapabilitiesAllProcess (m, n); 1117 dup2 (saved_stdout, fileno (stdout)); 1118 printDocument (m, doc, getpid ()); 1124 printDocument (m, doc, getpid (),request->out); 1119 1125 freeMaps (&m); 1120 1126 free (m); 1121 1127 free (REQUEST); 1122 1128 free (SERVICE_URL); 1123 fflush (stdout);1124 1129 return 0; 1125 1130 } … … 1132 1137 errorException (m, 1133 1138 _("Mandatory <identifier> was not specified"), 1134 "MissingParameterValue", "identifier" );1139 "MissingParameterValue", "identifier",request->out); 1135 1140 freeMaps (&m); 1136 1141 free (m); … … 1146 1151 errorException (m, 1147 1152 _("The specified path path doesn't exist."), 1148 "InvalidParameterValue", conf_dir );1153 "InvalidParameterValue", conf_dir,request->out); 1149 1154 freeMaps (&m); 1150 1155 free (m); … … 1173 1178 1174 1179 1175 int saved_stdout = dup (fileno (stdout));1176 dup2 (fileno (stderr), fileno (stdout));1180 //int saved_stdout = dup (fileno (stdout)); 1181 //dup2 (fileno (stderr), fileno (stdout)); 1177 1182 XML_Describe_Process (m, n, orig); 1178 1183 closedir (dirp); 1179 fflush (stdout);1180 dup2 (saved_stdout, fileno (stdout));1184 //fflush (stdout); 1185 //dup2 (saved_stdout, fileno (stdout)); 1181 1186 free (orig); 1182 printDocument (m, doc, getpid () );1187 printDocument (m, doc, getpid (),request->out); 1183 1188 freeMaps (&m); 1184 1189 free (m); 1185 1190 free (REQUEST); 1186 1191 free (SERVICE_URL); 1187 fflush (stdout);1192 //fflush (stdout); 1188 1193 return 0; 1189 1194 … … 1191 1196 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 1192 1197 { 1198 1193 1199 errorException (m, 1194 1200 _ 1195 1201 ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), 1196 "InvalidParameterValue", "request" );1202 "InvalidParameterValue", "request",request->out); 1197 1203 #ifdef DEBUG 1198 1204 fprintf (stderr, "No request found %s", REQUEST); … … 1203 1209 free (REQUEST); 1204 1210 free (SERVICE_URL); 1205 fflush (stdout);1211 //fflush (stdout); 1206 1212 return 0; 1207 1213 } … … 1250 1256 fflush (stdout); 1251 1257 **/ 1252 int saved_stdout = dup (fileno (stdout));1253 dup2 (saved_stdout, fileno (stdout));1258 //int saved_stdout = dup (fileno (stdout)); 1259 //dup2 (saved_stdout, fileno (stdout)); 1254 1260 s1 = search_service (r_inputs->value); 1255 1261 if (s1 == NULL) … … 1260 1266 ("The value for <identifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."), 1261 1267 r_inputs->value); 1262 errorException (m, tmpMsg, "InvalidParameterValue", "identifier" );1268 errorException (m, tmpMsg, "InvalidParameterValue", "identifier",request->out); 1263 1269 free (tmpMsg); 1264 1270 //free (s1); … … 1269 1275 return 0; 1270 1276 } 1271 close (saved_stdout);1277 //close (saved_stdout); 1272 1278 1273 1279 #ifdef DEBUG … … 1339 1345 return errorException (m, 1340 1346 _("Unable to allocate memory"), 1341 "InternalError", NULL );1347 "InternalError", NULL,request->out); 1342 1348 } 1343 1349 i = 0; … … 1356 1362 _ 1357 1363 ("Unable to allocate memory"), 1358 "InternalError", NULL );1364 "InternalError", NULL,request->out); 1359 1365 } 1360 1366 snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s", … … 1382 1388 _ 1383 1389 ("Unable to allocate memory."), 1384 "InternalError", NULL );1390 "InternalError", NULL,request->out); 1385 1391 } 1386 1392 tmp_output->name = zStrdup (tmpc); … … 1447 1453 errorException (m, 1448 1454 _("Parameter <DataInputs> was not specified"), 1449 "MissingParameterValue", "DataInputs" );1455 "MissingParameterValue", "DataInputs",request->out); 1450 1456 freeMaps (&m); 1451 1457 free (m); … … 1479 1485 { 1480 1486 return errorException (m, _("Unable to allocate memory."), 1481 "InternalError", NULL );1487 "InternalError", NULL,request->out); 1482 1488 } 1483 1489 i = 0; … … 1498 1504 return errorException (m, 1499 1505 _("Unable to allocate memory."), 1500 "InternalError", NULL );1506 "InternalError", NULL,request->out); 1501 1507 } 1502 1508 pToken = strtok (NULL, ";"); … … 1540 1546 _ 1541 1547 ("Unable to allocate memory."), 1542 "InternalError", NULL );1548 "InternalError", NULL,request->out); 1543 1549 } 1544 1550 tmpmaps->name = zStrdup (tmpn); … … 1611 1617 ("Unable to find a valid protocol to download the remote file %s"), 1612 1618 tmpv1 + 1); 1613 errorException (m, emsg, "InternalError", NULL );1619 errorException (m, emsg, "InternalError", NULL,request->out); 1614 1620 freeMaps (&m); 1615 1621 free (m); … … 1702 1708 fflush (stderr); 1703 1709 #endif 1704 xmlDocPtr doc = xmlParseMemory (postRequest->value, cgi ContentLength);1710 xmlDocPtr doc = xmlParseMemory (postRequest->value, cgi->cgiContentLength); 1705 1711 #ifdef DEBUG 1706 1712 fprintf (stderr, "AFTER\n"); … … 1753 1759 _ 1754 1760 ("Unable to allocate memory."), 1755 "InternalError", NULL );1761 "InternalError", NULL,request->out); 1756 1762 } 1757 1763 tmpmaps->name = zStrdup ((char *) val); … … 1782 1788 _ 1783 1789 ("Unable to allocate memory."), 1784 "InternalError", NULL );1790 "InternalError", NULL,request->out); 1785 1791 } 1786 1792 tmpmaps->name = zStrdup ("missingIndentifier"); … … 1926 1932 _ 1927 1933 ("Unable to allocate memory."), 1928 "InternalError", NULL );1934 "InternalError", NULL,request->out); 1929 1935 } 1930 1936 snprintf (has, … … 1965 1971 (char *) 1966 1972 malloc 1967 (cgi ContentLength + 1 * sizeof (char));1968 memset (tmp, 0, cgi ContentLength);1973 (cgi->cgiContentLength + 1 * sizeof (char)); 1974 memset (tmp, 0, cgi->cgiContentLength); 1969 1975 xmlNodePtr cur4 = cur3->children; 1970 1976 while (cur4 != NULL) … … 2058 2064 _ 2059 2065 ("Unable to allocate memory."), 2060 "InternalError", NULL );2066 "InternalError", NULL,request->out); 2061 2067 } 2062 2068 size_t bRead; … … 2380 2386 _ 2381 2387 ("Unable to allocate memory."), 2382 "InternalError", NULL );2388 "InternalError", NULL,request->out); 2383 2389 } 2384 2390 tmpmaps->name = zStrdup ("unknownIdentifier"); … … 2464 2470 _ 2465 2471 ("Unable to allocate memory."), 2466 "InternalError", NULL );2472 "InternalError", NULL,request->out); 2467 2473 } 2468 2474 tmpmaps->name = zStrdup ("unknownIdentifier"); … … 2520 2526 _ 2521 2527 ("Unable to allocate memory."), 2522 "InternalError", NULL );2528 "InternalError", NULL,request->out); 2523 2529 } 2524 2530 tmpmaps->name = zStrdup ((char *) val); … … 2580 2586 _ 2581 2587 ("Unable to allocate memory."), 2582 "InternalError", NULL );2588 "InternalError", NULL,request->out); 2583 2589 } 2584 2590 tmpmaps->name = zStrdup ("missingIndetifier"); … … 2659 2665 _ 2660 2666 ("Unable to allocate memory."), 2661 "InternalError", NULL );2667 "InternalError", NULL,request->out); 2662 2668 } 2663 2669 tmpmaps->name = zStrdup ((char *) val); … … 2700 2706 _ 2701 2707 ("Unable to allocate memory."), 2702 "InternalError", NULL );2708 "InternalError", NULL,request->out); 2703 2709 } 2704 2710 tmpmaps->name = … … 2788 2794 addToMap (tmpe, "locator", ptr->name); 2789 2795 addToMap (tmpe, "text", tmps); 2790 printExceptionReportResponse (m, tmpe );2796 printExceptionReportResponse (m, tmpe,request->out); 2791 2797 //freeService (&s1); 2792 2798 //free (s1); … … 2832 2838 } 2833 2839 addToMap (tmpe, "text", tmps); 2834 printExceptionReportResponse (m, tmpe );2840 printExceptionReportResponse (m, tmpe,request->out); 2835 2841 //freeService (&s1); 2836 2842 free (s1); … … 2855 2861 if (getMap (tmpReqI->content, "isFile") != NULL) 2856 2862 { 2857 if (cgiFormFileName (tmpReqI->name, name, sizeof (name) ) ==2863 if (cgiFormFileName (tmpReqI->name, name, sizeof (name),&cgi) == 2858 2864 cgiFormSuccess) 2859 2865 { … … 2869 2875 int got, t; 2870 2876 map *path = getMapFromMaps (m, "main", "tmpPath"); 2871 cgiFormFileSize (tmpReqI->name, &size );2877 cgiFormFileSize (tmpReqI->name, &size,&cgi); 2872 2878 cgiFormFileContentType (tmpReqI->name, contentType, 2873 sizeof (contentType) );2874 if (cgiFormFileOpen (tmpReqI->name, &file ) == cgiFormSuccess)2879 sizeof (contentType),&cgi); 2880 if (cgiFormFileOpen (tmpReqI->name, &file,&cgi) == cgiFormSuccess) 2875 2881 { 2876 2882 t = -1; … … 3018 3024 _ 3019 3025 ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), 3020 "InvalidParameterValue", "storeExecuteResponse" );3026 "InvalidParameterValue", "storeExecuteResponse",request->out); 3021 3027 //freeService (&s1); 3022 3028 //free (s1); … … 3069 3075 else 3070 3076 addToMap (_tmpMaps->content, "soap", "false"); 3071 if (cgi Cookie != NULL && strlen (cgiCookie) > 0)3077 if (cgi->cgiCookie != NULL && strlen (cgi->cgiCookie) > 0) 3072 3078 { 3073 3079 int hasValidCookie = -1; 3074 char *tcook = zStrdup (cgi Cookie);3080 char *tcook = zStrdup (cgi->cgiCookie); 3075 3081 char *tmp = NULL; 3076 3082 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); … … 3085 3091 sprintf (tmp, "%s=", testing->value); 3086 3092 } 3087 if (strstr (cgi Cookie, ";") != NULL)3093 if (strstr (cgi->cgiCookie, ";") != NULL) 3088 3094 { 3089 3095 char *token, *saveptr; 3090 token = strtok_r (cgi Cookie, ";", &saveptr);3096 token = strtok_r (cgi->cgiCookie, ";", &saveptr); 3091 3097 while (token != NULL) 3092 3098 { … … 3104 3110 { 3105 3111 if (strstr 3106 (cgi Cookie, "=") != NULL && strcasestr (cgiCookie, tmp) != NULL)3112 (cgi->cgiCookie, "=") != NULL && strcasestr (cgi->cgiCookie, tmp) != NULL) 3107 3113 { 3108 tcook = zStrdup (cgi Cookie);3114 tcook = zStrdup (cgi->cgiCookie); 3109 3115 hasValidCookie = 1; 3110 3116 } … … 3131 3137 sprintf 3132 3138 (session_file_path, 3133 "%s/sess_%s.cfg", tmpPath->value, strstr (cgi Cookie, "=") + 1);3139 "%s/sess_%s.cfg", tmpPath->value, strstr (cgi->cgiCookie, "=") + 1); 3134 3140 free (tcook); 3135 3141 maps *tmpSess = (maps *) malloc (MAPS_SIZE); … … 3137 3143 int istat = stat (session_file_path, 3138 3144 &file_status); 3145 3139 3146 if (istat == 0 && file_status.st_size > 0) 3140 3147 { … … 3144 3151 free (tmpSess); 3145 3152 } 3153 3146 3154 } 3147 3155 } … … 3166 3174 } 3167 3175 #endif 3168 char *fbkp, *fbkp1; 3176 3177 3178 char *fbkp, *fbkp1; 3169 3179 FILE *f0, *f1; 3170 3180 if (status != NULL) … … 3176 3186 (&m, s1, 3177 3187 request_inputs, 3178 &request_input_real_format, &request_output_real_format, &eres );3188 &request_input_real_format, &request_output_real_format, &eres,request->out,request->err); 3179 3189 } 3180 3190 else … … 3261 3271 r_inputs1->value, 3262 3272 SERVICE_STARTED, 3263 request_input_real_format, request_output_real_format );3273 request_input_real_format, request_output_real_format,request->out); 3264 3274 #ifndef WIN32 3265 3275 fflush (stdout); … … 3277 3287 (&m, s1, 3278 3288 request_inputs, 3279 &request_input_real_format, &request_output_real_format, &eres );3289 &request_input_real_format, &request_output_real_format, &eres,request->out,request->err); 3280 3290 } 3281 3291 else … … 3289 3299 _ 3290 3300 ("Unable to run the child process properly"), 3291 "InternalError", NULL );3301 "InternalError", NULL,request->out); 3292 3302 } 3293 3303 } … … 3296 3306 dumpMaps (request_output_real_format); 3297 3307 #endif 3308 3298 3309 if (eres != -1) 3299 3310 outputResponse (s1, 3300 3311 request_input_real_format, 3301 3312 request_output_real_format, 3302 request_inputs, cpid, m, eres );3303 fflush (stdout);3313 request_inputs, cpid, m, eres,request->out,request->err); 3314 //fflush (stdout); 3304 3315 /** 3305 3316 * Ensure that if error occurs when freeing memory, no signal will return … … 3315 3326 (void) signal (SIGABRT, donothing); 3316 3327 #endif 3317 if (((int) getpid ()) != cpid || cgi Sid != NULL)3328 if (((int) getpid ()) != cpid || cgi->cgiSid != NULL) 3318 3329 { 3319 3330 fclose (stdout);
Note: See TracChangeset
for help on using the changeset viewer.