Changeset 741 for branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Oct 7, 2015, 8:41:43 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c
r677 r741 32 32 #endif 33 33 34 #include "cgic.h"34 //#include "cgic.h" 35 35 36 36 extern "C" … … 45 45 #include "ulinet.h" 46 46 47 #include <libintl.h>47 //#include <libintl.h> 48 48 #include <locale.h> 49 49 #include <string.h> … … 56 56 #include "request_parser.h" 57 57 #include "sqlapi.h" 58 #include "zoo_amqp.h" 59 #include "zoo_json.h" 58 60 59 61 #ifdef USE_PYTHON … … 237 239 ("ZOO Kernel failed to process your request, receiving signal %d = %s"), 238 240 sig, ssig); 239 errorException (NULL, tmp, "InternalError", NULL );241 errorException (NULL, tmp, "InternalError", NULL,NULL); 240 242 #ifdef DEBUG 241 243 fprintf (stderr, "Not this time!\n"); … … 256 258 void 257 259 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs, 258 maps ** inputs, maps ** ioutputs, int *eres )260 maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err) 259 261 { 260 262 char tmps1[1024]; … … 386 388 typedef int (*execute_t) (maps **, maps **, maps **); 387 389 388 fprintf(stderr,"%s \n",s1->name);389 390 #ifdef WIN32 390 391 execute_t execute = … … 407 408 ("Error occured while running the %s function: %s"), 408 409 s1->name, errstr); 409 errorException (m, tmpMsg, "InternalError", NULL );410 errorException (m, tmpMsg, "InternalError", NULL,out); 410 411 free (tmpMsg); 411 412 #ifdef DEBUG … … 457 458 #endif 458 459 sprintf (tmps, _("Unable to load C Library %s"), errstr); 459 errorException(m,tmps,"InternalError",NULL );460 errorException(m,tmps,"InternalError",NULL,out); 460 461 *eres = -1; 461 462 } … … 553 554 ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"), 554 555 r_inputs->value); 555 errorException (m, tmpv, "InternalError", NULL );556 errorException (m, tmpv, "InternalError", NULL,out); 556 557 *eres = -1; 557 558 } 559 fflush(stderr); 558 560 *myMap = m; 559 561 *ioutputs = request_output_real_format; … … 728 730 */ 729 731 int 730 runRequest (map ** inputs )732 runRequest (map ** inputs,struct cgi_env ** c,FCGX_Request *request) 731 733 { 732 734 struct cgi_env *cgi = *c; 735 char *cgiSid = cgi->cgiSid; 733 736 #ifndef USE_GDB 734 737 #ifndef WIN32 … … 757 760 { 758 761 return errorException (m, _("Unable to allocate memory."), 759 "InternalError", NULL );762 "InternalError", NULL,request->out); 760 763 } 761 764 char ntmp[1024]; … … 772 775 { 773 776 errorException (NULL, _("Unable to load the main.cfg file."), 774 "InternalError", NULL );777 "InternalError", NULL,request->out); 775 778 free (m); 776 779 return 1; … … 819 822 ("The value %s is not supported for the <language> parameter"), 820 823 r_inputs->value); 821 errorException (m, tmp, "InvalidParameterValue", "language" );824 errorException (m, tmp, "InvalidParameterValue", "language",request->out); 822 825 freeMaps (&m); 823 826 free (m); … … 870 873 setMapInMaps (m, "main", "isSoap", "false"); 871 874 872 if(strlen(cgi ServerName)>0)875 if(strlen(cgi->cgiServerName)>0) 873 876 { 874 877 char tmpUrl[1024]; 875 878 876 879 if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"? 877 if ( strncmp(cgi ServerPort, "443", 3) == 0 ) {878 sprintf(tmpUrl, "https://%s%s", cgi ServerName,cgiScriptName);880 if ( strncmp(cgi->cgiServerPort, "443", 3) == 0 ) { 881 sprintf(tmpUrl, "https://%s%s", cgi->cgiServerName, cgi->cgiScriptName); 879 882 } 880 883 else { 881 sprintf(tmpUrl, "https://%s:%s%s", cgi ServerName, cgiServerPort,cgiScriptName);884 sprintf(tmpUrl, "https://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName); 882 885 } 883 886 } 884 887 else { 885 if ( strncmp(cgi ServerPort, "80", 2) == 0 ) {886 sprintf(tmpUrl, "http://%s%s", cgi ServerName,cgiScriptName);888 if ( strncmp(cgi->cgiServerPort, "80", 2) == 0 ) { 889 sprintf(tmpUrl, "http://%s%s", cgi->cgiServerName, cgi->cgiScriptName); 887 890 } 888 891 else { 889 sprintf(tmpUrl, "http://%s:%s%s", cgi ServerName, cgiServerPort,cgiScriptName);892 sprintf(tmpUrl, "http://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName); 890 893 } 891 894 } … … 913 916 if(err!=NULL){ 914 917 checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); 915 printExceptionReportResponse (m, err );918 printExceptionReportResponse (m, err,request->out); 916 919 freeMap(&err); 917 920 free(err); … … 969 972 } 970 973 if(err!=NULL){ 971 printExceptionReportResponse (m, err );974 printExceptionReportResponse (m, err,request->out); 972 975 freeMap(&err); 973 976 free(err); … … 1024 1027 xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0")); 1025 1028 CapabilitiesAllProcess(m,n); 1029 1026 1030 /** 1027 1031 * Here we need to close stdout to ensure that unsupported chars 1028 1032 * has been found in the zcfg and then printed on stdout 1029 1033 */ 1030 /* 1031 int saved_stdout = dup (fileno (stdout)); 1032 dup2 (fileno (stderr), fileno (stdout)); 1033 if (int res = 1034 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0, 1035 printGetCapabilitiesForProcess) < 0) 1036 { 1037 freeMaps (&m); 1038 free (m); 1039 if(zooRegistry!=NULL){ 1040 freeRegistry(&zooRegistry); 1041 free(zooRegistry); 1042 } 1043 free (REQUEST); 1044 free (SERVICE_URL); 1045 fflush (stdout); 1046 return res; 1047 } 1048 fflush (stdout); 1049 dup2 (saved_stdout, fileno (stdout)); 1050 */ 1051 printDocument (m, doc, getpid ()); 1034 printDocument (m, doc, getpid (),request->out); 1052 1035 freeMaps (&m); 1053 1036 free (m); 1054 /*1055 if(zooRegistry!=NULL){1056 freeRegistry(&zooRegistry);1057 free(zooRegistry);1058 }1059 */1060 1037 free (REQUEST); 1061 1038 free (SERVICE_URL); 1062 fflush (stdout);1063 1039 return 0; 1064 1040 } … … 1069 1045 if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 || 1070 1046 strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){ 1071 runGetStatus(m,r_inputs->value,REQUEST );1047 runGetStatus(m,r_inputs->value,REQUEST,request->out); 1072 1048 freeMaps (&m); 1073 1049 free (m); … … 1078 1054 else 1079 1055 if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){ 1080 runDismiss(m,r_inputs->value );1056 runDismiss(m,r_inputs->value,request->out); 1081 1057 freeMaps (&m); 1082 1058 free (m); … … 1091 1067 r_inputs = getMap (request_inputs, "Identifier"); 1092 1068 1093 struct dirent *dp;1094 DIR *dirp = opendir (conf_dir);1095 if (dirp == NULL)1096 {1097 errorException (m, _("The specified path path does not exist."),1098 "InvalidParameterValue", conf_dir);1099 freeMaps (&m);1100 free (m);1101 free (REQUEST);1102 free (SERVICE_URL);1103 return 0;1104 }1105 1069 if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) 1106 1070 { … … 1119 1083 1120 1084 DescribeProcess(m,n,orig); 1121 fflush (stdout);1122 1085 int saved_stdout; 1123 dup2 (saved_stdout, fileno (stdout));1124 1086 free (orig); 1125 printDocument (m, doc, getpid () );1087 printDocument (m, doc, getpid (),request->out); 1126 1088 freeMaps (&m); 1127 1089 free (m); 1128 1090 free (REQUEST); 1129 1091 free (SERVICE_URL); 1130 fflush (stdout);1131 1092 return 0; 1132 1093 } 1133 1094 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 1134 1095 { 1135 1096 map* version=getMapFromMaps(m,"main","rversion"); 1136 1097 int vid=getVersionId(version->value); 1137 1098 int len,j=0; … … 1169 1130 char* message=(char*)malloc((61+len)*sizeof(char)); 1170 1131 sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr); 1171 errorException (m,_(message),"InvalidParameterValue", "request" );1132 errorException (m,_(message),"InvalidParameterValue", "request",request->out); 1172 1133 #ifdef DEBUG 1173 1134 fprintf (stderr, "No request found %s", REQUEST); 1174 1135 #endif 1175 closedir (dirp);1176 1136 freeMaps (&m); 1177 1137 free (m); 1178 1138 free (REQUEST); 1179 1139 free (SERVICE_URL); 1180 fflush (stdout);1181 1140 return 0; 1182 1141 } 1183 closedir (dirp);1184 1142 } 1185 1143 } … … 1187 1145 map *postRequest = NULL; 1188 1146 postRequest = getMap (request_inputs, "xrequest"); 1189 1147 /* 1190 1148 if(vid==1 && postRequest==NULL){ 1191 errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request" );1149 errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request",request->out); 1192 1150 freeMaps (&m); 1193 1151 free (m); 1194 1152 free (REQUEST); 1195 1153 free (SERVICE_URL); 1196 fflush (stdout);1197 1154 return 0; 1198 1155 } 1199 1156 */ 1200 1157 s1 = NULL; 1201 1158 r_inputs = getMap (request_inputs, "Identifier"); 1202 1159 s1 = search_service (r_inputs->value); 1203 int saved_stdout = dup (fileno (stdout));1160 int saved_stdout;// = dup (fileno (stdout)); 1204 1161 1205 1162 … … 1211 1168 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 1212 1169 r_inputs->value); 1213 errorException (m, tmpMsg, "InvalidParameterValue", "identifier" );1170 errorException (m, tmpMsg, "InvalidParameterValue", "identifier",request->out); 1214 1171 free (tmpMsg); 1215 1172 freeMaps (&m); … … 1219 1176 return 0; 1220 1177 } 1221 close (saved_stdout); 1178 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 1179 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 1180 1222 1181 1223 1182 #ifdef DEBUG … … 1248 1207 1249 1208 1250 if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet )<0){1209 if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){ 1251 1210 freeMaps (&m); 1252 1211 free (m); … … 1334 1293 _ 1335 1294 ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."), 1336 "InvalidParameterValue", "storeExecuteResponse"); 1337 //freeService (&s1); 1338 free (s1); 1295 "InvalidParameterValue", "storeExecuteResponse",request->out); 1339 1296 freeMaps (&m); 1340 1297 free (m); … … 1361 1318 if(mode!=NULL){ 1362 1319 // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61 1363 errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 1364 fflush (stdout); 1320 errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value,request->out); 1365 1321 freeMaps (&m); 1366 1322 free (m); … … 1440 1396 1441 1397 // Parse the session file and add it to the main maps 1442 if (cgi Cookie != NULL && strlen (cgiCookie) > 0)1398 if (cgi->cgiCookie != NULL && strlen (cgi->cgiCookie) > 0) 1443 1399 { 1444 1400 int hasValidCookie = -1; 1445 char *tcook = zStrdup (cgi Cookie);1401 char *tcook = zStrdup (cgi->cgiCookie); 1446 1402 char *tmp = NULL; 1447 1403 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); … … 1456 1412 sprintf (tmp, "%s=", testing->value); 1457 1413 } 1458 if (strstr (cgi Cookie, ";") != NULL)1414 if (strstr (cgi->cgiCookie, ";") != NULL) 1459 1415 { 1460 1416 char *token, *saveptr; 1461 token = strtok_r (cgi Cookie, ";", &saveptr);1417 token = strtok_r (cgi->cgiCookie, ";", &saveptr); 1462 1418 while (token != NULL) 1463 1419 { … … 1474 1430 else 1475 1431 { 1476 if (strstr (cgi Cookie, "=") != NULL1477 && strcasestr (cgi Cookie, tmp) != NULL)1432 if (strstr (cgi->cgiCookie, "=") != NULL 1433 && strcasestr (cgi->cgiCookie, tmp) != NULL) 1478 1434 { 1479 tcook = zStrdup (cgi Cookie);1435 tcook = zStrdup (cgi->cgiCookie); 1480 1436 hasValidCookie = 1; 1481 1437 } … … 1498 1454 else 1499 1455 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 1500 strstr (cgi Cookie, "=") + 1);1456 strstr (cgi->cgiCookie, "=") + 1); 1501 1457 free (tcook); 1502 1458 maps *tmpSess = (maps *) malloc (MAPS_SIZE); … … 1539 1495 } 1540 1496 #endif 1497 1541 1498 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; 1542 1499 FILE *f0, *f1; … … 1546 1503 if (status == NULLMAP) 1547 1504 { 1548 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 1549 free (s1); 1505 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){ 1550 1506 freeMaps (&m); 1551 1507 free (m); … … 1560 1516 return -1; 1561 1517 } 1562 1518 fflush(stderr); 1563 1519 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 1564 &request_output_real_format, &eres); 1565 } 1566 else 1567 { 1520 &request_output_real_format, &eres,request->out,request->err); 1521 } 1522 else 1523 { 1524 1525 eres = SERVICE_ACCEPTED; 1526 vid = 1; 1527 1528 #ifdef AMQP 1529 1530 1531 eres = SERVICE_ACCEPTED; 1532 json_object *msg_jobj = json_object_new_object(); 1533 json_object *maps_obj; 1534 mapstojson(&maps_obj,m); 1535 json_object_object_add(msg_jobj,"maps",maps_obj); 1536 1537 1538 json_object *req_format_jobj; 1539 mapstojson(&req_format_jobj,request_input_real_format); 1540 json_object_object_add(msg_jobj,"request_input_real_format",req_format_jobj); 1541 1542 json_object *req_jobj; 1543 maptojson(&req_jobj,request_inputs); 1544 json_object_object_add(msg_jobj,"request_inputs",req_jobj); 1545 1546 1547 dumpMaps(request_output_real_format); 1548 json_object *outputs_jobj; 1549 mapstojson(&outputs_jobj,request_output_real_format); 1550 json_object_object_add(msg_jobj,"request_output_real_format",outputs_jobj); 1551 1552 bind_amqp(); 1553 1554 if ( (send_msg(json_object_to_json_string(msg_jobj),"application/json") != 0) ){ 1555 eres = SERVICE_FAILED; 1556 } 1557 close_amqp(); 1558 json_object_put(msg_jobj); 1559 1560 init_sql(m); 1561 recordServiceStatus(m); 1562 1563 1564 1565 1566 #else 1568 1567 int pid; 1569 1568 #ifdef DEBUG … … 1687 1686 printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, 1688 1687 SERVICE_STARTED, request_input_real_format, 1689 request_output_real_format );1690 fflush (stdout); 1688 request_output_real_format,request->out); 1689 1691 1690 #ifdef RELY_ON_DB 1692 1691 recordResponse(m,fbkp); … … 1705 1704 f1 = freopen (fbkp1, "w+", stdout); 1706 1705 1707 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 1708 //freeService (&s1); 1709 free (s1); 1706 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){ 1710 1707 freeMaps (&m); 1711 1708 free (m); … … 1718 1715 freeMaps (&tmpmaps); 1719 1716 free (tmpmaps); 1720 fflush (stdout);1721 1717 fflush (stderr); 1722 1718 unhandleStatus (m); 1723 1719 return -1; 1724 1720 } 1721 1725 1722 loadServiceAndRun (&m, s1, request_inputs, 1726 1723 &request_input_real_format, 1727 &request_output_real_format, &eres );1724 &request_output_real_format, &eres,request->out,request->err); 1728 1725 1729 1726 } … … 1736 1733 eres = -1; 1737 1734 errorException (m, _("Unable to run the child process properly"), 1738 "InternalError", NULL );1735 "InternalError", NULL,request->out); 1739 1736 } 1740 } 1737 1738 #endif 1739 1740 } 1741 1742 1743 1741 1744 1742 1745 #ifdef DEBUG … … 1746 1749 outputResponse (s1, request_input_real_format, 1747 1750 request_output_real_format, request_inputs, 1748 cpid, m, eres );1749 fflush (stdout);1751 cpid, m, eres,request->out); 1752 //fflush (stdout); 1750 1753 1754 1751 1755 /** 1752 1756 * Ensure that if error occurs when freeing memory, no signal will return … … 1819 1823 free (tmps1); 1820 1824 } 1821 1822 //freeService (&s1);1823 free (s1);1824 1825 freeMaps (&m); 1825 1826 free (m);
Note: See TracChangeset
for help on using the changeset viewer.