Changeset 962 for trunk/zoo-project
- Timestamp:
- Oct 21, 2020, 6:31:09 PM (4 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 13 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/HISTORY.txt
r961 r962 1 1 Version 1.8.0-dev 2 * Update OGC API - Processes documentation 3 * Add open-api directory in utils services containing a reddis 4 subscription example, the HTML UI and the display service using 5 Cheetah templating system 6 * Update the oas.cfg file to reflect new api definition 7 * Include basic microdata in the HTML home page 8 * Add HTML support for basic interractions with OGC API - Processes 9 including execution of service from the service-desc link 10 * OGC API - Processes added support for syncrhonous Execute requests 11 * Reuse service_callback in OGC API - Processes when subscriber 12 object is provided in the JSON request 13 * OGC API - Processes implementation as available on 2020-10-19 2 14 * Produce value string only when memory=load for Python support. 3 15 * Make local files uris usable when cache is used 4 * Make GDAL/pr ilfe service usable in case memory=protect16 * Make GDAL/profile service usable in case memory=protect 5 17 * Add Dockerfile and docker-compose environment with pgbouncer, see #177 6 18 * Add documentation on how to use asyncrhonous execution using the Javascript -
trunk/zoo-project/zoo-kernel/Makefile.in
r952 r962 45 45 46 46 service_callback.o: service_callback.c 47 g ++-fPIC ${XML2CFLAGS} ${GDAL_CFLAGS} ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c47 gcc -fPIC ${XML2CFLAGS} ${GDAL_CFLAGS} ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c 48 48 49 49 request_parser.o: request_parser.c request_parser.h -
trunk/zoo-project/zoo-kernel/configure.ac
r953 r962 85 85 [], [AC_MSG_ERROR([could not find function in json-c library])]) 86 86 CPPFLAGS="$CPPFLAGS_SAVE" 87 JSON_FILE="service_json.o "87 JSON_FILE="service_json.o service_callback.o" 88 88 JSON_ENABLED="-DJSON" 89 89 if test "x$CALLBACK_ACTIVATED" == "xyes" 90 90 then 91 CALLBACK_FILE=" service_callback.o"91 CALLBACK_FILE="" 92 92 CALLBACK_USE="-DUSE_CALLBACK" 93 93 fi -
trunk/zoo-project/zoo-kernel/oas.cfg
r950 r962 1 1 [openapi] 2 rootUrl=https://demo.mapmint.com/wps3/ 2 use_content=false 3 rootUrl=https://myserver/ogc-api 3 4 links=/,/api,/conformance,/processes 4 paths=/root,/api,/conformance,/processes,/processes/{id},/processes/{id}/jobs,/processes/{id}/jobs/{jobID},/processes/{id}/jobs/{jobID}/result 5 paths=/root,/api,/conformance,/processes,/processes/{id},/processes/{id}/jobs,/processes/{id}/jobs/{jobID},/processes/{id}/jobs/{jobID}/results 5 6 parameters=id,jobID,resultID 6 header_parameters=oas-header1,oas-header2 7 version=3.0.1 8 9 [oas-header1] 10 in=header 11 name=Prefer 12 type=string 13 required=false 14 enum=respond-async 15 16 [oas-header2] 17 in=header 18 name=Prefer 19 type=string 20 required=false 21 enum=return=representation,return=minimal 7 version=3.0.2 8 license_name=OGC license 9 license_url=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/LICENSE 10 full_html_support=false 11 partial_html_support=true 12 wsUrl=wss://demo.mapmint.com:4430/ 13 publisherUrl=http://127.0.0.1/cgi-bin3/publish.py?jobid= 22 14 23 15 [/] … … 32 24 tags=Home 33 25 tags_description= 34 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/root.yaml 26 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/LandingPage.yaml 27 28 [/index.html] 29 rel=alternate 30 type=text/html 35 31 36 32 [/api] 37 rel=service 33 rel=service-desc 38 34 type=application/openapi+json;version=3.0 39 35 title=the API definition 36 37 [/api.html] 38 rel=service-doc 39 type=text/hml 40 41 [api.html] 42 href=https://demo.mapmint.com/swagger-ui/ogc-api-processes/ 40 43 41 44 [api] … … 55 58 method=get 56 59 title=information about standards that this API conforms to 57 abstract= =list all requirements classes specified in a standard (e.g., WPS REST/JSON Binding Core) that the server conforms to60 abstract=list all requirements classes specified in a standard (e.g., WPS REST/JSON Binding Core) that the server conforms to 58 61 tags=Conformance 59 62 tags_description= 60 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/req-classes.yaml 63 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ConformanceDeclaration.yaml 64 65 [/conformance.html] 66 rel=alternate 67 type=text/hml 61 68 62 69 [/processes] … … 71 78 tags=GetCapabilities 72 79 tags_description= 73 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/processCollection.yaml 80 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessList.yaml 81 82 [/processes.html] 83 rel=alternate 84 type=text/hml 74 85 75 86 [processes/{id}] … … 79 90 tags=ProcessDescription 80 91 tags_description= 81 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/process.yaml 92 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ProcessDescription.yaml 93 ecode=404 82 94 parameters=/components/parameters/id 83 95 … … 95 107 tags=JobList 96 108 tags_description= 97 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/ schemas/jobCollection.yaml109 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/JobList.yaml 98 110 parameters=/components/parameters/id 111 ecode=404,500 99 112 method_1=post 100 113 title_1=execute a job … … 102 115 tags_1=Execute Endpoint 103 116 tags_description_1= 104 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/result.yaml 105 parameters_1=/components/parameters/id,/components/parameters/oas-header1 117 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteSync.yaml 118 parameters_1=/components/parameters/id 119 ecode_1=400,404,500 120 eschema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ExecuteAsync.yaml 121 ep=,/components/parameters/oas-header1 106 122 107 123 [requestBody] … … 116 132 117 133 [processes/{id}/jobs/{jobID}] 134 length=2 118 135 method=get 119 136 title=The status of a job. … … 121 138 tags=GetStatus 122 139 tags_description= 123 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/ schemas/statusInfo.yaml140 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml 124 141 parameters=/components/parameters/id,/components/parameters/jobID 125 126 [/processes/{id}/jobs/{jobID}/result] 142 method_1=delete 143 title_1=Cancel a job 144 abstract_1=Cancel the job execution. 145 tags_1=Dismiss 146 tags_description_1=Cencel a job execution 147 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Status.yaml 148 parameters_1=/components/parameters/id,/components/parameters/jobID 149 ecode_1=404,500 150 151 152 [/processes/{id}/jobs/{jobID}/results] 127 153 rel=canonical 128 154 type=application/json 129 155 title=Get Result 130 156 131 [processes/{id}/jobs/{jobID}/result ]157 [processes/{id}/jobs/{jobID}/results] 132 158 method=get 133 159 title=The result of a job execution. … … 135 161 tags=GetResult 136 162 tags_description= 137 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/ schemas/result.yaml163 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/Results.yaml 138 164 parameters=/components/parameters/id,/components/parameters/jobID 165 ecode=404,500 139 166 ep=,/components/parameters/oas-header2 140 167 … … 151 178 tags_description= 152 179 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/valueType.yaml 153 parameters=/components/parameters/id,/components/parameters/jobID,/components/parameters/resultID,/components/parameters/oas-header2 180 parameters=/components/parameters/id,/components/parameters/jobID,/components/parameters/resultID 181 ep=,/components/parameters/oas-header2 154 182 155 183 … … 184 212 required=false 185 213 186 [conformTo] 187 rootUrl=http://www.opengis.net/spec/WPS/2.0/req/service/binding/rest-json/ 214 [conformsTo] 215 rootUrl=http://www.opengis.net/spec/ogcapi-processes/1.0/conf/ 216 rootUrl0=http://www.opengis.net/spec/WPS/2.0/req/service/binding/rest-json/ 188 217 link=core 189 218 link_1=oas30 190 219 link_2=json 191 length=3 220 link_3=job-list 221 link_4=dismiss 222 link_5=callback 223 length=6 192 224 193 225 [exception] 194 226 abstract=Exception 195 227 type=application/json 196 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/exception.yaml 228 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml 229 default_schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml 230 231 [responses] 232 length=5 233 code=404 234 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotFound.yaml 235 type=application/json 236 title=NotFound 237 code_1=500 238 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/ServerError.yaml 239 type_1=application/json 240 title_1=ServerError 241 code_2=400 242 schema_2=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/InvalidParameter.yaml 243 type_2=appliction/json 244 title_2=InvalidParameter 245 code_3=405 246 schema_3=https://github.com/opengeospatial/wps-rest-binding/blob/master/core/openapi/responses/NotAllowed.yaml 247 type_3=appliction/json 248 title_3=NotAllowed 249 code_4=406 250 schema_4=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/responses/NotSupported.yaml 251 type_4=appliction/json 252 title_4=NotSupported 253 254 [callbacks] 255 length=3 256 state=jobSuccess 257 uri=successUri 258 schema=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/result.yaml 259 type=application/json 260 title=Results received successfully 261 state_1=jobInProgress 262 uri_1=inProgressUri 263 schema_1=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/statusInfo.yaml 264 type_1=application/json 265 title_1=Results received successfully 266 state_2=jobFailed 267 uri_2=failedUrii 268 schema_2=https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas/exception.yaml 269 type_2=application/json 270 title_2=Exception received successfully 271 272 [links_title] 273 self=View this document in JSON. 274 alternate=View the alternative version in HTML. 275 conformance=View the specifications that the link’s context conforms to. 276 service-desc=View the service description. 277 service-doc=View service documentation. 278 processes=View the list of processes the API offers. 279 results=View the results of a process. 280 status=View the current status of a job execution. 281 execute=View the execution endpoint of a process. 282 283 [provider_alt] 284 addressDeliveryPoint=streetAddress 285 addressCity=addressLocality 286 addressAdministrativeArea=addressRegion 287 addressPostalCode=postalCode 288 addressCountry=addressCountry 289 addressElectronicMailAddress=email 290 phoneVoice=telephone 291 phoneFacsimile=faxNumber 292 hoursOfService=hoursAvailable 293 contactInstructions=contactOption 294 -
trunk/zoo-project/zoo-kernel/otbZooWatcher.cxx
r937 r962 45 45 { 46 46 int progressPercent = static_cast<int>(m_Process->GetProgress() * 100); 47 updateStatus(m_Conf,progressPercent,m_Comment.c_str()); 47 if(progressPercent>iCounter){ 48 updateStatus(m_Conf,progressPercent,m_Comment.c_str()); 49 iCounter=progressPercent; 50 } 48 51 } 49 52 } … … 56 59 m_TimeProbe.Start(); 57 60 #endif 61 iCounter=-1; 58 62 } 59 63 -
trunk/zoo-project/zoo-kernel/otbZooWatcher.h
r579 r962 87 87 maps* m_Conf; 88 88 89 /** Counter */ 90 int iCounter; 91 89 92 }; 90 93 -
trunk/zoo-project/zoo-kernel/request_parser.c
r957 r962 317 317 if (strncasecmp (tmpx2, "http://", 7) != 0 && 318 318 strncasecmp (tmpx2, "ftp://", 6) != 0 && 319 strncasecmp (tmpx2, "https://", 8) != 0) 319 strncasecmp (tmpx2, "https://", 8) != 0 && 320 strncasecmp (tmpx2, "file://", 7) != 0) 320 321 { 321 322 char emsg[1024]; -
trunk/zoo-project/zoo-kernel/response_print.c
r956 r962 2719 2719 } 2720 2720 if(res==SERVICE_FAILED){ 2721 map *lenv; 2722 lenv=getMapFromMaps(m,"lenv","message"); 2723 char *tmp0; 2724 if(lenv!=NULL){ 2725 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2726 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2727 } 2728 else{ 2729 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2730 sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service.")); 2731 } 2721 char* tmp0=produceErrorMessage(m); 2732 2722 errorException(m,tmp0,"InternalError",NULL); 2733 2723 free(tmp0); -
trunk/zoo-project/zoo-kernel/server_internal.c
r961 r962 952 952 free(res); 953 953 } 954 else 955 addToMap(statusInfo,"Status","Failed"); 954 else{ 955 addToMap(statusInfo,"Status","Failed"); 956 addToMap(statusInfo,"NotFound",pid); 957 } 956 958 free(fbkpid); 957 959 } … … 992 994 void runGetStatus(maps* conf,char* pid,char* req){ 993 995 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 996 map* e_type = getMapFromMaps (conf, "lenv", "executionType"); 994 997 char *sid=getStatusId(conf,pid); 995 998 if(sid==NULL){ 996 errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"), 997 "NoSuchJob", pid); 999 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1000 errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"), 1001 "NoSuchJob", pid); 1002 else{ 1003 setMapInMaps(conf,"lenv","error","true"); 1004 setMapInMaps(conf,"lenv","code","NoSuchJob"); 1005 setMapInMaps(conf,"lenv","message",_("The JobID from the request does not match any of the Jobs running on this server")); 1006 } 998 1007 }else{ 999 1008 map* statusInfo=createMap("JobID",pid); 1000 if(isRunning(conf,pid)>0){ 1009 if(isRunning(conf,pid)>0){ 1001 1010 if(strncasecmp(req,"GetResult",strlen(req))==0){ 1002 errorException (conf, _("The result for the requested JobID has not yet been generated. The service is currently running."), 1003 "ResultNotReady", pid); 1011 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1012 errorException (conf, _("The result for the requested JobID has not yet been generated. The service is currently running."), 1013 "ResultNotReady", pid); 1014 else{ 1015 setMapInMaps(conf,"lenv","error","true"); 1016 setMapInMaps(conf,"lenv","code","ResultNotReady"); 1017 setMapInMaps(conf,"lenv","message",_("The result for the requested JobID has not yet been generated. The service is currently running.")); 1018 } 1004 1019 return; 1005 1020 } 1006 else 1021 else{ 1007 1022 if(strncasecmp(req,"GetStatus",strlen(req))==0){ 1008 1023 addToMap(statusInfo,"Status","Running"); 1024 setMapInMaps(conf,"lenv","status","Running"); 1009 1025 char* tmpStr=_getStatus(conf,pid); 1010 1026 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ … … 1015 1031 addToMap(statusInfo,"PercentCompleted",tmpStr1); 1016 1032 addToMap(statusInfo,"Message",tmpStr0); 1033 setMapInMaps(conf,"lenv","PercentCompleted",tmpStr1); 1034 setMapInMaps(conf,"lenv","Message",tmpStr0); 1017 1035 free(tmpStr0); 1018 1036 free(tmpStr1); 1019 1037 } 1020 1038 } 1039 } 1021 1040 } 1022 1041 else{ … … 1043 1062 if(strncasecmp(req,"GetStatus",strlen(req))==0){ 1044 1063 readFinalRes(conf,pid,statusInfo); 1064 if(e_type==NULL || strncasecmp(e_type->value,"json",4)==0){ 1065 map* pmStatus=getMap(statusInfo,"status"); 1066 if(pmStatus!=NULL) 1067 setMapInMaps(conf,"lenv","status",pmStatus->value); 1068 } 1045 1069 char* tmpStr=_getStatus(conf,pid); 1046 1070 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ … … 1051 1075 addToMap(statusInfo,"PercentCompleted",tmpStr1); 1052 1076 addToMap(statusInfo,"Message",tmpStr0); 1077 setMapInMaps(conf,"lenv","PercentCompleted",tmpStr1); 1078 setMapInMaps(conf,"lenv","Message",tmpStr0); 1053 1079 free(tmpStr0); 1054 1080 free(tmpStr1); … … 1057 1083 } 1058 1084 free(sid); 1059 printStatusInfo(conf,statusInfo,req); 1085 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1086 printStatusInfo(conf,statusInfo,req); 1087 else 1088 setMapInMaps(conf,"lenv","error","false"); 1060 1089 freeMap(&statusInfo); 1061 1090 free(statusInfo); … … 1072 1101 void runDismiss(maps* conf,char* pid){ 1073 1102 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 1103 map* e_type = getMapFromMaps (conf, "lenv", "executionType"); 1074 1104 char *sid=getStatusId(conf,pid); 1075 1105 if(sid==NULL){ 1076 errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"), 1077 "NoSuchJob", pid); 1106 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1107 errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"), 1108 "NoSuchJob", pid); 1109 else{ 1110 setMapInMaps(conf,"lenv","error","true"); 1111 setMapInMaps(conf,"lenv","code","NoSuchJob"); 1112 setMapInMaps(conf,"lenv","message",_("The JobID from the request does not match any of the Jobs running on this server")); 1113 } 1114 return; 1078 1115 }else{ 1079 1116 // We should send the Dismiss request to the target host if it differs … … 1115 1152 sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name); 1116 1153 if(zUnlink(fileName)!=0){ 1117 errorException (conf, 1118 _("The job cannot be removed, a file cannot be removed"), 1119 "NoApplicableCode", NULL); 1154 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1155 errorException (conf, 1156 _("The job cannot be removed, a file cannot be removed"), 1157 "NoApplicableCode", NULL); 1158 else{ 1159 setMapInMaps(conf,"lenv","error","true"); 1160 setMapInMaps(conf,"lenv","code","NoApplicableCode"); 1161 setMapInMaps(conf,"lenv","message",_("The job cannot be removed, a file cannot be removed")); 1162 } 1120 1163 return; 1121 1164 } 1122 } 1123 } 1124 } 1165 1166 } 1167 } 1168 } 1169 map* pmStatusFile=getMapFromMaps(conf,"lenv","file.statusFile"); 1170 if(pmStatusFile!=NULL && zUnlink(pmStatusFile->value)!=0){ 1171 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0) 1172 errorException (conf, 1173 _("The job cannot be removed, a file cannot be removed"), 1174 "NoApplicableCode", NULL); 1175 else{ 1176 setMapInMaps(conf,"lenv","error","true"); 1177 setMapInMaps(conf,"lenv","code","NoApplicableCode"); 1178 setMapInMaps(conf,"lenv","message",_("The job cannot be removed, a file cannot be removed")); 1179 } 1180 return; 1181 } 1125 1182 #ifdef RELY_ON_DB 1126 1183 removeService(conf,pid); 1127 1184 #endif 1128 /* No need to call 7_1 when an execution is dismissed. 1129 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1130 invokeCallback(conf,NULL,NULL,7,1); 1131 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1132 */ 1133 map* statusInfo=createMap("JobID",pid); 1134 addToMap(statusInfo,"Status","Dismissed"); 1135 printStatusInfo(conf,statusInfo,"Dismiss"); 1136 free(statusInfo); 1185 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0){ 1186 /* No need to call 7_1 when an execution is dismissed. 1187 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1188 invokeCallback(conf,NULL,NULL,7,1); 1189 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1190 */ 1191 map* statusInfo=createMap("JobID",pid); 1192 addToMap(statusInfo,"Status","Dismissed"); 1193 printStatusInfo(conf,statusInfo,"Dismiss"); 1194 free(statusInfo); 1195 }else{ 1196 setMapInMaps(conf,"lenv","error","false"); 1197 } 1137 1198 } 1138 1199 return; … … 1249 1310 } 1250 1311 1312 /** 1313 * Create a string containing the basic error message. 1314 * 1315 * @param pmConf the main configuration maps pointer 1316 * @return a new char* containing the error message (ressource should be freed) 1317 */ 1318 char* produceErrorMessage(maps* pmConf){ 1319 char *pacTmp; 1320 map *pmLenv=getMapFromMaps(pmConf,"lenv","message"); 1321 if(pmLenv!=NULL){ 1322 pacTmp=(char*)malloc((strlen(pmLenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 1323 sprintf(pacTmp,_("Unable to run the Service. The message returned back by the Service was the following: %s"),pmLenv->value); 1324 } 1325 else{ 1326 pacTmp=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 1327 sprintf(pacTmp,"%s",_("Unable to run the Service. No more information was returned back by the Service.")); 1328 } 1329 return pacTmp; 1330 } 1331 1251 1332 #ifdef WIN32 1252 1333 /** -
trunk/zoo-project/zoo-kernel/server_internal.h
r921 r962 60 60 void dumpMapsValuesToFiles(maps**,maps**); 61 61 void runDismiss(maps*,char*); 62 int isRunning(maps*,char*); 62 63 void runGetStatus(maps*,char*,char*); 64 void readFinalRes(maps*,char*,map*); 63 65 64 66 int isValidLang(maps*,const char*); … … 67 69 int readServiceFile (maps *, char *, service **, char *); 68 70 int createRegistry (maps*,registry **,char *); 71 char* produceErrorMessage(maps*); 69 72 70 73 int zoo_path_compare(char* path1, char* path2); -
trunk/zoo-project/zoo-kernel/service.h
r957 r962 185 185 */ 186 186 #define SERVICE_FAILED 4 187 /** 188 * The global dismissed status for a service 189 */ 190 #define SERVICE_DISMISSED 5 187 191 188 192 /** -
trunk/zoo-project/zoo-kernel/service_callback.c
r955 r962 27 27 */ 28 28 29 #include "service_json.h"30 29 #include "service_internal_ms.h" 31 #include "sqlapi.h"32 30 #include <pthread.h> 33 31 #include <libxml/tree.h> … … 42 40 43 41 #include "service_callback.h" 42 #include "service_json.h" 43 #include "sqlapi.h" 44 #include <ulinet.h> 45 44 46 45 47 #ifdef __cplusplus … … 66 68 */ 67 69 int cStep=0; 70 /** 71 * Maximum value of PercentCompleted 72 */ 73 int maxProgress=0; 68 74 /** 69 75 * Is there any ongoing HTTP request … … 112 118 return false; 113 119 } 114 120 /** 121 * Practically invoke the callback, meaning sending the HTTP POST request. 122 * 123 * @param args local_params containing all the variables required 124 */ 125 void* _invokeBasicCallback(void* args){ 126 #ifdef CALLBACK_DEBUG 127 fprintf(stderr,"************************* From thread %d %s %d: REQUEST CONFIGURE (%s)\n",pthread_self(),__FILE__,__LINE__,arg->url->value); 128 fflush(stderr); 129 #endif 130 local_params* arg=(local_params*)args; 131 if(arg->state<cStep){ 132 #ifdef CALLBACK_DEBUG 133 fprintf(stderr,"************************* From thread %d %s %d: REQUEST CANCELLED (%s) EXIT!\n",pthread_self(),__FILE__,__LINE__,arg->url->value); 134 fflush(stderr); 135 #endif 136 freeMaps(&arg->conf); 137 free(arg->conf); 138 freeMap(&arg->url); 139 free(arg->url); 140 pthread_exit(NULL); 141 return NULL; 142 } 143 HINTERNET hInternet,res1; 144 const struct tm *tm; 145 size_t len; 146 char *tmp1; 147 map *tmpStatus; 148 map* pmTmp=getMapFromMaps(arg->conf,"lenv","status"); 149 hInternet=InternetOpen("ZooWPSClient\0", 150 INTERNET_OPEN_TYPE_PRECONFIG, 151 NULL,NULL, 0); 152 if(!CHECK_INET_HANDLE(hInternet)){ 153 InternetCloseHandle (&hInternet); 154 return NULL; 155 } 156 const char* jsonStr=json_object_to_json_string_ext(arg->res,JSON_C_TO_STRING_PLAIN); 157 while( arg->state != SERVICE_SUCCEEDED && arg->state != SERVICE_FAILED && isOngoing>0 ){ 158 zSleep(100); 159 } 160 if(arg->state==SERVICE_STARTED && pmTmp!=NULL){ 161 if(maxProgress<=atoi(pmTmp->value)){ 162 maxProgress=atoi(pmTmp->value); 163 }else{ 164 #ifdef CALLBACK_DEBUG 165 fprintf(stderr,"************************* From thread %d %s %d: REQUEST CANCELLED (%s) EXIT!\n",pthread_self(),__FILE__,__LINE__,arg->url->value); 166 fflush(stderr); 167 #endif 168 freeMaps(&arg->conf); 169 free(arg->conf); 170 freeMap(&arg->url); 171 free(arg->url); 172 pthread_exit(NULL); 173 return NULL; 174 } 175 }else 176 maxProgress=101; 177 isOngoing=1; 178 maps* tmpConf=createMaps("main"); 179 tmpConf->content=createMap("memory","load"); 180 181 hInternet.waitingRequests[0] = zStrdup(arg->url->value); 182 res1 = InternetOpenUrl (&hInternet, 183 hInternet.waitingRequests[0], 184 (char*)jsonStr, strlen(jsonStr), 185 INTERNET_FLAG_NO_CACHE_WRITE, 186 0,tmpConf); 187 AddHeaderEntries(&hInternet,arg->conf); 188 AddMissingHeaderEntry(&hInternet.ihandle[hInternet.nb-1],"Content-Type","application/json"); 189 #ifdef CALLBACK_DEBUG 190 curl_easy_setopt(hInternet.ihandle[hInternet.nb-1].handle, CURLOPT_VERBOSE, 1); 191 #endif 192 if(hInternet.ihandle[hInternet.nb-1].header!=NULL) 193 curl_easy_setopt(hInternet.ihandle[hInternet.nb-1].handle,CURLOPT_HTTPHEADER,hInternet.ihandle[hInternet.nb-1].header); 194 processDownloads(&hInternet); 195 freeMaps(&tmpConf); 196 free(tmpConf); 197 #ifdef CALLBACK_DEBUG 198 char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1) 199 * sizeof (char)); 200 if (tmp == NULL) 201 { 202 setMapInMaps(arg->conf,"lenv","message",_("Unable to allocate memory")); 203 setMapInMaps(arg->conf,"lenv","code","InternalError"); 204 return NULL; 205 } 206 size_t bRead; 207 InternetReadFile (hInternet.ihandle[0], 208 (LPVOID) tmp, 209 hInternet. 210 ihandle[0].nDataLen, 211 &bRead); 212 tmp[hInternet.ihandle[0].nDataLen] = 0; 213 fprintf(stderr,"************************* From thread %d %s %d: REQUEST END \n%s",pthread_self(),__FILE__,__LINE__,tmp); 214 fflush(stderr); 215 free(tmp); 216 #endif 217 json_object_put(arg->res); 218 InternetCloseHandle(&hInternet); 219 isOngoing=0; 220 freeMaps(&arg->conf); 221 free(arg->conf); 222 freeMap(&arg->url); 223 if(arg->url!=NULL) 224 free(arg->url); 225 pthread_exit(NULL); 226 } 227 228 /** 229 * Invoke the callback in case there is a [subscriber] section containing one 230 * or more url parameter. 231 * 232 * @param conf the maps containing the main configuration file definitions 233 * @param state the service state SERVICE_SUCCEEDED / STARTED / FAILED 234 * @return bool true in case of success, false in other cases 235 */ 236 bool invokeBasicCallback(maps* conf,int state){ 237 map* url=getMapFromMaps(conf,"subscriber","inProgressUri"); 238 if(state==SERVICE_SUCCEEDED) 239 url=getMapFromMaps(conf,"subscriber","successUri"); 240 else 241 if(state==SERVICE_FAILED) 242 url=getMapFromMaps(conf,"subscriber","failedUri"); 243 if(url==NULL) 244 return false; 245 map* url0=createMap("url",url->value); 246 map* sname=getMapFromMaps(conf,"lenv","identifier"); 247 if(sname!=NULL && isProhibited(conf,sname->value)) 248 return false; 249 if(state<cStep) 250 return true; 251 if(cStep!=state || isOngoing==0){ 252 json_object *res=NULL; 253 if(state==SERVICE_SUCCEEDED || state==SERVICE_FAILED){ 254 maps* pmsTmp=getMaps(conf,"lenv"); 255 setMapInMaps(conf,"lenv","no-write","true"); 256 map* pmTmp=getMapFromMaps(conf,"lenv","usid"); 257 if(pmTmp!=NULL){ 258 map* pmResponse=getMapFromMaps(conf,"lenv","jsonStr"); 259 res=parseJson(conf,pmResponse->value); 260 } 261 }else 262 res=createStatus(conf,state); 263 if(local_arguments==NULL) 264 local_arguments=(local_params**)malloc(sizeof(local_params*)); 265 else 266 local_arguments=(local_params**)realloc(local_arguments,(nbThreads+1)*sizeof(local_params*)); 267 local_arguments[nbThreads]=(local_params*)malloc(MAPS_SIZE+MAP_SIZE+sizeof(json_object*)+(2*sizeof(int))); 268 local_arguments[nbThreads]->conf=dupMaps(&conf); 269 local_arguments[nbThreads]->url=url0; 270 local_arguments[nbThreads]->res=res; 271 local_arguments[nbThreads]->step=0; 272 local_arguments[nbThreads]->state=state; 273 cStep=state; 274 if(myThreads==NULL) 275 myThreads=(pthread_t*)malloc((nbThreads+1)*sizeof(pthread_t)); 276 else 277 myThreads=(pthread_t*)realloc(myThreads,(nbThreads+1)*sizeof(pthread_t)); 278 if(pthread_create(&myThreads[nbThreads], NULL, _invokeBasicCallback, (void*)local_arguments[nbThreads])==-1){ 279 setMapInMaps(conf,"lenv","message",_("Unable to create a new thread")); 280 return false; 281 } 282 nbThreads++; 283 } 284 return true; 285 } 286 115 287 /** 116 288 * Practically invoke the callback, meaning sending the HTTP POST request. … … 336 508 map* tmpMap=getMapArray(curs->content,"value",ii); 337 509 char tmpStr[100]; 338 sprintf(tmpStr,"% d",strlen(tmpMap->value));510 sprintf(tmpStr,"%ld",strlen(tmpMap->value)); 339 511 setMapArray(curs->content,"size",ii,tmpStr); 340 512 tmpMap=getMapArray(curs->content,"mimeType",ii); … … 570 742 jsStr=json_object_new_string(tmp2->value); 571 743 json_object_object_add(res2,"target_path",jsStr); 572 json_object *res4=json_object_object_get(res1,tmp0->value); 573 if(json_object_is_type(res4,json_type_null)){ 574 json_object_object_add(res1,tmp0->value,res2); 575 }else{ 576 if(json_object_is_type(res4,json_type_object) && !json_object_is_type(res4, json_type_array)){ 577 json_object *res3=json_object_new_array(); 578 json_object_array_add(res3,json_object_get(res4)); 579 json_object_array_add(res3,res2); 580 json_object_object_del(res1,tmp0->value); 581 json_object_object_add(res1,tmp0->value,res3); 582 }else 583 json_object_array_add(res4,res2); 744 json_object *res4=NULL; 745 if(json_object_object_get_ex(res1,tmp0->value,&res4)!=FALSE){ 746 if(json_object_is_type(res4,json_type_null)){ 747 json_object_object_add(res1,tmp0->value,res2); 748 }else{ 749 if(json_object_is_type(res4,json_type_object) && !json_object_is_type(res4, json_type_array)){ 750 json_object *res3=json_object_new_array(); 751 json_object_array_add(res3,json_object_get(res4)); 752 json_object_array_add(res3,res2); 753 json_object_object_del(res1,tmp0->value); 754 json_object_object_add(res1,tmp0->value,res3); 755 }else 756 json_object_array_add(res4,res2); 757 } 584 758 } 585 759 } … … 866 1040 */ 867 1041 void cleanupCallbackThreads(){ 1042 while( isOngoing>0 ){ 1043 zSleep(100); 1044 } 868 1045 int i=0; 869 1046 for(i=0;i<nbThreads;i++){ -
trunk/zoo-project/zoo-kernel/service_callback.h
r955 r962 32 32 #pragma once 33 33 34 #include <ulinet.h>35 #include <stdio.h>36 #include <ctype.h>37 34 #include <service.h> 38 35 … … 41 38 #endif 42 39 40 bool invokeBasicCallback(maps*,int); 43 41 bool invokeCallback(maps*,maps*,maps*,int,int); 44 42 void cleanupCallbackThreads(); -
trunk/zoo-project/zoo-kernel/service_internal.c
r945 r962 412 412 free(fbkpid); 413 413 char* stat=getStatusId(conf,lid); 414 setMapInMaps(conf,"lenv","lid",stat); 414 if(stat!=NULL) 415 setMapInMaps(conf,"lenv","lid",stat); 415 416 removeShmLock(conf,1); 416 417 return NULL; … … 470 471 fflush(fstatus); 471 472 fclose(fstatus); 473 invokeBasicCallback(conf,SERVICE_STARTED); 472 474 } 473 475 if(stat!=NULL){ -
trunk/zoo-project/zoo-kernel/service_internal_otb.c
r647 r962 122 122 map* tmp=NULL; 123 123 int res=-1; 124 int saved_stdout = zDup (fileno (stdout)); 125 zDup2 (fileno (stderr), fileno (stdout)); 124 126 std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); 125 127 if (list.size() == 0){ 126 128 map* tmps=createMap("text","No OTB Application found."); 127 129 addToMap(tmps,"code","InternalError"); 130 zDup2 (saved_stdout, fileno (stdout)); 131 zClose(saved_stdout); 128 132 printExceptionReportResponse(m,tmps); 129 133 freeMap(&tmps); … … 142 146 map* tmps=createMap("text",tmpS); 143 147 addToMap(tmps,"code","InternalError"); 148 zDup2 (saved_stdout, fileno (stdout)); 149 zClose(saved_stdout); 144 150 printExceptionReportResponse(m,tmps); 145 151 freeMap(&tmps); … … 460 466 catch(std::exception& err){ 461 467 setMapInMaps(m,"lenv","message",err.what()); 468 zDup2 (saved_stdout, fileno (stdout)); 469 zClose(saved_stdout); 462 470 return SERVICE_FAILED; 463 471 … … 479 487 } 480 488 m_WatcherList.clear(); 481 489 fflush(stdout); 490 zDup2 (saved_stdout, fileno (stdout)); 491 zClose(saved_stdout); 482 492 return res; 483 493 } -
trunk/zoo-project/zoo-kernel/service_internal_python.c
r961 r962 446 446 Py_DECREF(name); 447 447 tmp=tmp->next; 448 } 448 } 449 449 return (PyDictObject*) res; 450 450 } … … 572 572 } 573 573 else{ 574 if(PyDict_GetItem(res,name)==NULL ){574 if(PyDict_GetItem(res,name)==NULL && strlen(tmp->value)>0){ 575 575 PyObject* value=PyString_FromString(tmp->value); 576 576 if(PyDict_SetItem(res,name,value)<0){ -
trunk/zoo-project/zoo-kernel/service_json.c
r954 r962 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright 2017-20 19GeoLabs SARL. All rights reserved.4 * Copyright 2017-2020 GeoLabs SARL. All rights reserved. 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 223 223 if(tmpMap1!=NULL){ 224 224 json_object_object_add(prop2,"name",json_object_new_string(tmpMap1->value)); 225 char *tmp=(char*)malloc((strlen(tmpMap1->value)+35)*sizeof(char)); 226 sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmpMap1->value); 227 json_object_object_add(prop2,"reference",json_object_new_string(tmp)); 228 free(tmp); 225 229 json_object_object_add(prop1,"dataType",prop2); 226 230 } … … 371 375 tmpMap=getMap(in->content,"abstract"); 372 376 if(tmpMap!=NULL) 373 json_object_object_add(input," abstract",json_object_new_string(tmpMap->value));377 json_object_object_add(input,"description",json_object_new_string(tmpMap->value)); 374 378 if(strcmp(io,"input")==0){ 375 379 tmpMap=getMap(in->content,"minOccurs"); 376 380 if(tmpMap!=NULL) 377 json_object_object_add(input,"minOccurs",json_object_new_ string(tmpMap->value));381 json_object_object_add(input,"minOccurs",json_object_new_int(atoi(tmpMap->value))); 378 382 tmpMap=getMap(in->content,"maxOccurs"); 379 if(tmpMap!=NULL) 380 json_object_object_add(input,"maxOccurs",json_object_new_string(tmpMap->value)); 383 if(tmpMap!=NULL){ 384 if(strncasecmp(tmpMap->value,"unbounded",9)==0) 385 json_object_object_add(input,"maxOccurs",json_object_new_string(tmpMap->value)); 386 else 387 json_object_object_add(input,"maxOccurs",json_object_new_int(atoi(tmpMap->value))); 388 } 381 389 } 382 390 if(in->format!=NULL){ … … 439 447 json_object* doc=(json_object*) doc0; 440 448 json_object* nc=(json_object*) nc0; 441 json_object *res=json_object_new_object(); 449 json_object *res; 450 if(doc!=NULL) 451 res=json_object_new_object(); 452 else 453 res=(json_object*) nc0; 454 442 455 map* tmpMap0=getMapFromMaps(m,"lenv","level"); 443 456 char* rUrl=serv->name; … … 486 499 tmpMap=getMap(serv->content,"abstract"); 487 500 if(tmpMap!=NULL){ 488 json_object_object_add(res," abstract",json_object_new_string(tmpMap->value));501 json_object_object_add(res,"description",json_object_new_string(tmpMap->value)); 489 502 } 490 503 tmpMap=getMap(serv->content,"processVersion"); … … 498 511 else 499 512 json_object_object_add(res,"version",json_object_new_string(tmpMap->value)); 500 } 513 }else 514 json_object_object_add(res,"version",json_object_new_string("1.0.0")); 501 515 int limit=4; 502 516 int i=0; … … 517 531 json_object *res1=json_object_new_array(); 518 532 json_object *res2=json_object_new_object(); 519 json_object_object_add(res2,"rel",json_object_new_string("canonical")); 533 json_object *res3=json_object_new_object(); 534 map* pmTmp=getMapFromMaps(m,"lenv","requestType"); 535 if(pmTmp!=NULL && strncasecmp(pmTmp->value,"desc",4)==0) 536 json_object_object_add(res2,"rel",json_object_new_string("process-desc")); 537 else{ 538 json_object_object_add(res2,"rel",json_object_new_string("execute")); 539 json_object_object_add(res3,"rel",json_object_new_string("alternate")); 540 json_object_object_add(res3,"type",json_object_new_string("text/html")); 541 } 520 542 json_object_object_add(res2,"type",json_object_new_string("application/json")); 521 543 json_object_object_add(res2,"title",json_object_new_string("Process Description")); … … 525 547 if(doc==NULL){ 526 548 json_object_object_add(res2,"title",json_object_new_string("Execute End Point")); 549 json_object_object_add(res3,"title",json_object_new_string("Execute End Point")); 527 550 char* tmpStr1=zStrdup(tmpStr); 528 551 tmpStr=(char*) realloc(tmpStr,(strlen(tmpStr)+6)*sizeof(char)); 529 sprintf(tmpStr,"%sjobs /",tmpStr1);552 sprintf(tmpStr,"%sjobs",tmpStr1); 530 553 free(tmpStr1); 554 char* tmpStr3=(char*) malloc((strlen(tmpStr)+6)*sizeof(char)); 555 sprintf(tmpStr3,"%s.html",tmpStr); 556 json_object_object_add(res3,"href",json_object_new_string(tmpStr3)); 557 free(tmpStr3); 531 558 } 532 559 json_object_object_add(res2,"href",json_object_new_string(tmpStr)); 533 560 free(tmpStr); 534 561 json_object_array_add(res1,res2); 562 tmpUrl=getMapFromMaps(m,"openapi","partial_html_support"); 563 if(tmpUrl!=NULL && strncasecmp(tmpUrl->value,"true",4)==0) 564 json_object_array_add(res1,res3); 565 else 566 json_object_put(res3); 535 567 json_object_object_add(res,"links",res1); 536 568 } … … 551 583 if(doc!=NULL) 552 584 json_object_array_add(doc,res); 553 else554 json_object_object_add(nc,"process",json_object_get(res));555 556 585 } 557 586 … … 577 606 if(strcmp(tmp->value,"OperationNotSupported")==0 || 578 607 strcmp(tmp->value,"NoApplicableCode")==0) 579 exceptionCode="50 1Not Implemented";608 exceptionCode="500 Not Implemented"; 580 609 else 581 610 if(strcmp(tmp->value,"MissingParameterValue")==0 || … … 586 615 exceptionCode="400 Bad request"; 587 616 else 588 if(strcmp(tmp->value,"NotFound")==0) 617 if(strcmp(tmp->value,"NotFound")==0 || 618 strcmp(tmp->value,"NoSuchProcess")==0 || 619 strcmp(tmp->value,"NoSuchJob")==0 || 620 strcmp(tmp->value,"ResultNotReady")==0) 589 621 exceptionCode="404 Not Found"; 590 622 else 591 exceptionCode="50 1Internal Server Error";623 exceptionCode="500 Internal Server Error"; 592 624 json_object_object_add(res,"code",json_object_new_string(tmp->value)); 593 625 } 594 else 595 exceptionCode="501 Internal Server Error"; 596 printHeaders(m); 626 else{ 627 exceptionCode="500 Internal Server Error"; 628 json_object_object_add(res,"code",json_object_new_string("NoApplicableCode")); 629 } 630 if(getMapFromMaps(m,"lenv","no-headers")==NULL) 631 printHeaders(m); 597 632 598 633 tmp=getMapFromMaps(m,"lenv","status_code"); 599 634 if(tmp!=NULL) 600 635 exceptionCode=tmp->value; 601 if(m!=NULL){ 602 map *tmpSid=getMapFromMaps(m,"lenv","sid"); 603 if(tmpSid!=NULL){ 604 if( getpid()==atoi(tmpSid->value) ){ 636 if(getMapFromMaps(m,"lenv","no-headers")==NULL){ 637 if(m!=NULL){ 638 map *tmpSid=getMapFromMaps(m,"lenv","sid"); 639 if(tmpSid!=NULL){ 640 if( getpid()==atoi(tmpSid->value) ){ 641 printf("Status: %s\r\n\r\n",exceptionCode); 642 } 643 } 644 else{ 605 645 printf("Status: %s\r\n\r\n",exceptionCode); 606 646 } 607 } 608 else{ 647 }else{ 609 648 printf("Status: %s\r\n\r\n",exceptionCode); 610 649 } 611 }else{612 printf("Status: %s\r\n\r\n",exceptionCode);613 650 } 614 651 tmp=getMap(s,"text"); … … 620 657 json_object_object_add(res,"description",json_object_new_string(tmp->value)); 621 658 const char* jsonStr=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 659 if(getMapFromMaps(m,"lenv","jsonStr")==NULL) 660 setMapInMaps(m,"lenv","jsonStr",jsonStr); 661 maps* pmsTmp=getMaps(m,"lenv"); 622 662 printf(jsonStr); 623 663 if(m!=NULL) … … 876 916 * @param outputs the produced maps 877 917 */ 878 void parseJRequest(maps* conf, service* s,json_object* req, maps** inputs,maps** outputs){918 void parseJRequest(maps* conf, service* s,json_object* req, map* request_inputs, maps** inputs,maps** outputs){ 879 919 elements* io=s->inputs; 880 920 … … 890 930 parseJIO(conf,req,s->outputs,outputs,"outputs"); 891 931 } 892 } 932 json_io=NULL; 933 if(json_object_object_get_ex(req,"mode",&json_io)!=FALSE){ 934 addToMap(request_inputs,"mode",json_object_get_string(json_io)); 935 setMapInMaps(conf,"request","mode",json_object_get_string(json_io)); 936 } 937 json_io=NULL; 938 if(json_object_object_get_ex(req,"response",&json_io)!=FALSE){ 939 addToMap(request_inputs,"response",json_object_get_string(json_io)); 940 setMapInMaps(conf,"request","response",json_object_get_string(json_io)); 941 } 942 json_io=NULL; 943 if(json_object_object_get_ex(req,"subscriber",&json_io)!=FALSE){ 944 maps* subscribers=createMaps("subscriber"); 945 json_object* json_subscriber=NULL; 946 if(json_object_object_get_ex(json_io,"successUri",&json_subscriber)!=FALSE){ 947 subscribers->content=createMap("successUri",json_object_get_string(json_subscriber)); 948 } 949 if(json_object_object_get_ex(json_io,"inProgressUri",&json_subscriber)!=FALSE){ 950 if(subscribers->content==NULL) 951 subscribers->content=createMap("inProgressUri",json_object_get_string(json_subscriber)); 952 else 953 addToMap(subscribers->content,"inProgressUri",json_object_get_string(json_subscriber)); 954 } 955 if(json_object_object_get_ex(json_io,"failedUri",&json_subscriber)!=FALSE){ 956 if(subscribers->content==NULL) 957 subscribers->content=createMap("failedUri",json_object_get_string(json_subscriber)); 958 else 959 addToMap(subscribers->content,"failedUri",json_object_get_string(json_subscriber)); 960 } 961 addMapsToMaps(&conf,subscribers); 962 freeMaps(&subscribers); 963 free(subscribers); 964 } 965 } 966 893 967 } 894 968 … … 934 1008 if (jerr != json_tokener_success) { 935 1009 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 936 return res;1010 return NULL; 937 1011 } 938 1012 if (tok->char_offset < slen){ 939 return res;1013 return NULL; 940 1014 } 941 1015 json_object_object_add(cjob,"infos",jobj); … … 951 1025 return res; 952 1026 } 953 1027 954 1028 /** 955 1029 * Print the result of an execution … … 958 1032 * @param s service pointer to metadata 959 1033 * @param result outputs of the service 960 * @param res the status of executi noSERVICE_FAILED/SERVICE_SUCCEEDED1034 * @param res the status of execution SERVICE_FAILED/SERVICE_SUCCEEDED 961 1035 * @return the JSON object pointer to the result 962 1036 */ 963 1037 json_object* printJResult(maps* conf,service* s,maps* result,int res){ 964 printHeaders(conf);965 1038 json_object* eres1=json_object_new_object(); 1039 if(res==SERVICE_FAILED){ 1040 char* pacTmp=produceErrorMessage(conf); 1041 map* pamTmp=createMap("message",pacTmp); 1042 free(pacTmp); 1043 map* pmTmp=getMapFromMaps(conf,"lenv","code"); 1044 if(pmTmp!=NULL) 1045 addToMap(pamTmp,"code",pmTmp->value); 1046 printExceptionReportResponseJ(conf,pamTmp); 1047 freeMap(&pamTmp); 1048 free(pamTmp); 1049 return NULL; 1050 } 1051 if(getMapFromMaps(conf,"lenv","no-headers")==NULL) 1052 printHeaders(conf); 966 1053 json_object* eres=json_object_new_array(); 967 1054 maps* resu=result; … … 970 1057 json_object* res1=json_object_new_object(); 971 1058 json_object_object_add(res1,"id",json_object_new_string(resu->name)); 972 map* tmpMap=NULL; 1059 map* tmpMap=getMap(resu->content,"mimeType"); 1060 json_object* res3=json_object_new_object(); 1061 if(tmpMap!=NULL) 1062 json_object_object_add(res3,"mimeType",json_object_new_string(tmpMap->value)); 973 1063 if((tmpMap=getMap(resu->content,"value"))!=NULL || 974 1064 (getMap(resu->content,"generated_file"))!=NULL){ … … 994 1084 return eres1; 995 1085 } 1086 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 996 1087 json_object_object_add(res2,"inlineValue",jobj); 997 }else 998 json_object_object_add(res2,"inlineValue",json_object_new_string(tmpMap->value)); 1088 }else{ 1089 map* tmp1=getMapFromMaps(conf,"main","tmpPath"); 1090 map *gfile=getMap(resu->content,"generated_file"); 1091 if(gfile!=NULL){ 1092 gfile=getMap(resu->content,"expected_generated_file"); 1093 if(gfile==NULL){ 1094 gfile=getMap(resu->content,"generated_file"); 1095 } 1096 FILE* pfData=fopen(gfile->value,"rb"); 1097 if(pfData!=NULL){ 1098 zStatStruct f_status; 1099 int s=zStat(gfile->value, &f_status); 1100 char* pcaTmp=(char*)malloc((f_status.st_size+1)*sizeof(char)); 1101 fread(pcaTmp,1,f_status.st_size,pfData); 1102 pcaTmp[f_status.st_size]=0; 1103 fclose(pfData); 1104 json_object_object_add(res2,"inlineValue",json_object_new_string(base64(pcaTmp,f_status.st_size))); 1105 json_object_object_add(res3,"encoding",json_object_new_string("base64")); 1106 free(pacTmp); 1107 } 1108 }else{ 1109 json_object_object_add(res3,"encoding",json_object_new_string("utf-8")); 1110 json_object_object_add(res2,"inlineValue",json_object_new_string(tmpMap->value)); 1111 } 1112 } 999 1113 } 1000 1114 else{ … … 1098 1212 } 1099 1213 json_object_object_add(res1,"value",res2); 1214 json_object_object_add(res1,"format",res3); 1100 1215 json_object_array_add(eres,res1); 1101 1216 } … … 1108 1223 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1109 1224 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1110 char tmp[1024];1111 sprintf( tmp,"%s/%s_%s.json",1225 char *pacTmp=(char*)malloc((strlen(tmpPath->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char)); 1226 sprintf(pacTmp,"%s/%s_%s.json", 1112 1227 tmpPath->value,cIdentifier->value,sessId->value); 1113 FILE* foutput=fopen(tmp,"w+"); 1114 if(foutput!=NULL){ 1115 fclose(foutput); 1116 char tmpUrl[1024]; 1228 zStatStruct zsFStatus; 1229 int iS=zStat(pacTmp, &zsFStatus); 1230 if(iS==0 && zsFStatus.st_size>0){ 1117 1231 map* tmpPath1 = getMapFromMaps (conf, "main", "tmpUrl"); 1118 sprintf(tmpUrl,"%s/%s_%s.json",tmpPath1->value, 1232 char* pacTmpUrl=(char*)malloc((strlen(tmpPath1->value)+strlen(cIdentifier->value)+strlen(sessId->value)+8)*sizeof(char));; 1233 sprintf(pacTmpUrl,"%s/%s_%s.json",tmpPath1->value, 1119 1234 cIdentifier->value,sessId->value); 1120 setMapInMaps(conf,"headers","Location",tmpUrl); 1121 } 1235 if(getMapFromMaps(conf,"lenv","gs_location")==NULL) 1236 setMapInMaps(conf,"headers","Location",pacTmpUrl); 1237 free(pacTmpUrl); 1238 } 1239 free(pacTmp); 1122 1240 if(res==3){ 1123 setMapInMaps(conf,"headers","Status","201 Created"); 1241 map* mode=getMapFromMaps(conf,"request","mode"); 1242 if(mode!=NULL && strncasecmp(mode->value,"async",5)==0) 1243 setMapInMaps(conf,"headers","Status","201 Created"); 1244 else 1245 setMapInMaps(conf,"headers","Status","200 Ok"); 1124 1246 } 1125 1247 else{ 1126 1248 setMapInMaps(conf,"headers","Status","500 Issue running your service"); 1127 1249 } 1128 1129 1250 return eres1; 1130 1251 } … … 1144 1265 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1145 1266 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1267 if(sessId==NULL){ 1268 sessId = getMapFromMaps (conf, "lenv", "gs_usid"); 1269 } 1146 1270 char *Url0=(char*) malloc((strlen(tmpPath->value)+ 1147 1271 strlen(cIdentifier->value)+ … … 1153 1277 cIdentifier->value, 1154 1278 sessId->value); 1155 setMapInMaps(conf,"headers","Location",Url0); 1279 if(getMapFromMaps(conf,"lenv","gs_location")==NULL) 1280 setMapInMaps(conf,"headers","Location",Url0); 1156 1281 json_object* val=json_object_new_object(); 1157 json_object_object_add(val," Title",1282 json_object_object_add(val,"title", 1158 1283 json_object_new_string(_("Status location"))); 1284 json_object_object_add(val,"rel", 1285 json_object_new_string(_("status"))); 1286 json_object_object_add(val,"type", 1287 json_object_new_string(_("application/json"))); 1159 1288 json_object_object_add(val,"href",json_object_new_string(Url0)); 1160 1289 json_object_array_add(res,val); … … 1164 1293 strlen(cIdentifier->value)+strlen(sessId->value)+ 1165 1294 25)*sizeof(char)); 1166 sprintf(Url0,"%s/processes/%s/jobs/%s/result ",1295 sprintf(Url0,"%s/processes/%s/jobs/%s/results", 1167 1296 tmpPath->value, 1168 1297 cIdentifier->value, 1169 1298 sessId->value); 1170 1299 json_object* val1=json_object_new_object(); 1171 json_object_object_add(val1," Title",1300 json_object_object_add(val1,"title", 1172 1301 json_object_new_string(_("Result location"))); 1302 json_object_object_add(val1,"rel", 1303 json_object_new_string(_("results"))); 1304 json_object_object_add(val1,"type", 1305 json_object_new_string(_("application/json"))); 1173 1306 json_object_object_add(val1,"href",json_object_new_string(Url0)); 1174 1307 json_object_array_add(res,val1); … … 1204 1337 return NULL; 1205 1338 } 1206 free(tmp1); 1207 tmp1=(char*) malloc((strlen(tmpPath->value)+ 1339 tmp1=(char*) realloc(tmp1,(strlen(tmpPath->value)+ 1208 1340 strlen(cIdentifier->value)+ 1209 strlen(sessId->value)+2 0)*sizeof(char));1341 strlen(sessId->value)+21)*sizeof(char)); 1210 1342 int needResult=0; 1211 1343 char *message, *rstatus; … … 1214 1346 cIdentifier->value, 1215 1347 sessId->value); 1216 1217 1348 return tmp1; 1218 1349 } 1350 1351 char* getResultPath(maps* conf,char* jobId){ 1352 map *tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 1353 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1354 char *pacUrl=(char*) malloc((strlen(tmpPath->value)+ 1355 strlen(cIdentifier->value)+ 1356 strlen(jobId)+8)*sizeof(char)); 1357 sprintf(pacUrl,"%s/%s_%s.json",tmpPath->value, 1358 cIdentifier->value,jobId); 1359 return pacUrl; 1360 } 1361 1362 json_object* parseJson(maps* conf,char* myString){ 1363 json_object *pajObj = NULL; 1364 enum json_tokener_error jerr; 1365 struct json_tokener* tok=json_tokener_new(); 1366 int slen = 0; 1367 do { 1368 slen = strlen(myString); 1369 pajObj = json_tokener_parse_ex(tok, myString, slen); 1370 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 1371 if (jerr != json_tokener_success) { 1372 setMapInMaps(conf,"lenv","message",json_tokener_error_desc(jerr)); 1373 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 1374 return NULL; 1375 } 1376 if (tok->char_offset < slen){ 1377 return NULL; 1378 } 1379 return pajObj; 1380 } 1219 1381 1220 /** 1221 * Create the status file 1222 * 1223 * @param conf the maps containing the settings of the main.cfg file 1224 * @param status an integer (SERVICE_ACCEPTED,SERVICE_STARTED...) 1225 * @return an integer (0 in case of success, 1 in case of failure) 1226 */ 1227 int createStatusFile(maps* conf,int status){ 1382 json_object* json_readFile(maps* conf,char* filePath){ 1383 json_object *pajObj = NULL; 1384 zStatStruct zsFStatus; 1385 int iS=zStat(filePath, &zsFStatus); 1386 if(iS==0 && zsFStatus.st_size>0){ 1387 FILE* cdat=fopen(filePath,"rb"); 1388 if(cdat!=NULL){ 1389 char* pacMyString=(char*)malloc((zsFStatus.st_size+1)*sizeof(char)); 1390 fread(pacMyString,1,zsFStatus.st_size,cdat); 1391 pacMyString[zsFStatus.st_size]=0; 1392 fclose(cdat); 1393 pajObj=parseJson(conf,pacMyString); 1394 free(pacMyString); 1395 } 1396 else 1397 return NULL; 1398 }else 1399 return NULL; 1400 return pajObj; 1401 } 1402 1403 json_object* createStatus(maps* conf,int status){ 1228 1404 int needResult=0; 1229 const char * message, *rstatus;1230 char * tmp1=json_getStatusFilePath(conf);1405 const char *rstatus; 1406 char *message; 1231 1407 // Create statusInfo JSON object 1232 1408 // cf. https://github.com/opengeospatial/wps-rest-binding/blob/master/core/ 1233 1409 // openapi/schemas/statusInfo.yaml 1234 1410 json_object* res=json_object_new_object(); 1235 json_object_object_add(res,"status",json_object_new_string("successful"));1236 1411 switch(status){ 1237 1412 case SERVICE_ACCEPTED: … … 1244 1419 { 1245 1420 message=_("ZOO-Kernel is currently running your service!"); 1421 map* pmStatus=getMapFromMaps(conf,"lenv","status"); 1422 if(pmStatus!=NULL) 1423 setMapInMaps(conf,"lenv","PercentCompleted",pmStatus->value); 1424 pmStatus=getMapFromMaps(conf,"lenv","message"); 1425 if(pmStatus!=NULL) 1426 setMapInMaps(conf,"lenv","gs_message",pmStatus->value); 1246 1427 rstatus="running"; 1247 1428 break; … … 1257 1438 message=_("ZOO-Kernel successfully run your service!"); 1258 1439 rstatus="successful"; 1440 setMapInMaps(conf,"lenv","PercentCompleted","100"); 1259 1441 needResult=1; 1260 1442 break; 1261 1443 } 1444 case SERVICE_DISMISSED: 1445 { 1446 message=_("ZOO-Kernel successfully dismissed your service!"); 1447 rstatus="dismissed"; 1448 needResult=1; 1449 break; 1450 } 1262 1451 default: 1263 1452 { 1264 message=_("ZOO-Kernel failed to run your service!"); 1453 map* pmTmp=getMapFromMaps(conf,"lenv","force"); 1454 if(pmTmp==NULL || strncasecmp(pmTmp->value,"false",5)==0){ 1455 char* pacTmp=json_getStatusFilePath(conf); 1456 json_object* pjoStatus=json_readFile(conf,pacTmp); 1457 free(pacTmp); 1458 if(pjoStatus!=NULL){ 1459 json_object* pjoMessage=NULL; 1460 if(json_object_object_get_ex(pjoStatus,"message",&pjoMessage)!=FALSE){ 1461 message=(char*)json_object_get_string(pjoMessage); 1462 } 1463 } 1464 // TODO: Error 1465 }else{ 1466 map* mMap=getMapFromMaps(conf,"lenv","gs_message"); 1467 if(mMap!=NULL) 1468 setMapInMaps(conf,"lenv","message",mMap->value); 1469 message=produceErrorMessage(conf); 1470 needResult=-1; 1471 } 1265 1472 rstatus="failed"; 1266 1473 break; … … 1269 1476 setMapInMaps(conf,"lenv","message",message); 1270 1477 setMapInMaps(conf,"lenv","status",rstatus); 1271 1272 map* mess=getMapFromMaps(conf,"lenv","message"); 1273 if(mess!=NULL) 1274 json_object_object_add(res,"message",json_object_new_string(mess->value)); 1275 1276 createStatusLinks(conf,needResult,res); 1277 1478 1479 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1480 if(sessId!=NULL){ 1481 sessId = getMapFromMaps (conf, "lenv", "gs_usid"); 1482 if(sessId==NULL) 1483 sessId = getMapFromMaps (conf, "lenv", "usid"); 1484 }else 1485 sessId = getMapFromMaps (conf, "lenv", "gs_usid"); 1486 if(sessId!=NULL) 1487 json_object_object_add(res,"jobID",json_object_new_string(sessId->value)); 1488 json_object_object_add(res,"status",json_object_new_string(rstatus)); 1489 map* mMap=getMapFromMaps(conf,"lenv","gs_message"); 1490 if(mMap==NULL) 1491 json_object_object_add(res,"message",json_object_new_string(message)); 1492 else{ 1493 json_object_object_add(res,"message",json_object_new_string(mMap->value)); 1494 if((mMap=getMapFromMaps(conf,"lenv","PercentCompleted"))!=NULL) 1495 json_object_object_add(res,"progress",json_object_new_int(atoi(mMap->value))); 1496 } 1497 if(status!=SERVICE_DISMISSED) 1498 createStatusLinks(conf,needResult,res); 1499 else{ 1500 json_object* res1=json_object_new_array(); 1501 map *tmpPath = getMapFromMaps (conf, "openapi", "rootUrl"); 1502 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1503 char *Url0=(char*) malloc((strlen(tmpPath->value)+ 1504 strlen(cIdentifier->value)+ 1505 17)*sizeof(char)); 1506 sprintf(Url0,"%s/processes/%s/jobs", 1507 tmpPath->value, 1508 cIdentifier->value); 1509 json_object* val=json_object_new_object(); 1510 json_object_object_add(val,"title", 1511 json_object_new_string(_("The job list for the current process"))); 1512 json_object_object_add(val,"rel", 1513 json_object_new_string(_("parent"))); 1514 json_object_object_add(val,"type", 1515 json_object_new_string(_("application/json"))); 1516 json_object_object_add(val,"href",json_object_new_string(Url0)); 1517 json_object_array_add(res1,val); 1518 free(Url0); 1519 json_object_object_add(res,"links",res1); 1520 } 1521 if(needResult<0) 1522 free(message); 1523 return res; 1524 } 1525 1526 /** 1527 * Create the status file 1528 * 1529 * @param conf the maps containing the settings of the main.cfg file 1530 * @param status an integer (SERVICE_ACCEPTED,SERVICE_STARTED...) 1531 * @return an integer (0 in case of success, 1 in case of failure) 1532 */ 1533 int createStatusFile(maps* conf,int status){ 1534 json_object* res=createStatus(conf,status); 1535 char* tmp1=json_getStatusFilePath(conf); 1278 1536 FILE* foutput1=fopen(tmp1,"w+"); 1279 1537 if(foutput1!=NULL){ … … 1303 1561 map* tmpMap=getMapFromMaps(conf,"lenv","gs_usid"); 1304 1562 if(tmpMap!=NULL){ 1305 char* tmpStr=_getStatus(conf,tmpMap->value); 1306 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1307 char *tmpStr1=zStrdup(tmpStr); 1308 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1309 free(tmpStr); 1310 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; 1311 setMapInMaps(conf,"lenv","PercentCompleted",tmpStr1); 1312 setMapInMaps(conf,"lenv","gs_message",tmpStr0); 1313 free(tmpStr0); 1314 free(tmpStr1); 1315 } 1316 } 1563 char* tmpStr=_getStatus(conf,tmpMap->value); 1564 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1565 char *tmpStr1=zStrdup(tmpStr); 1566 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1567 free(tmpStr); 1568 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; 1569 setMapInMaps(conf,"lenv","PercentCompleted",tmpStr1); 1570 setMapInMaps(conf,"lenv","gs_message",tmpStr0); 1571 free(tmpStr0); 1572 free(tmpStr1); 1573 return 0; 1574 }else{ 1575 1576 } 1577 } 1317 1578 } 1318 1579 … … 1371 1632 1372 1633 json_object *res4=json_object_new_object(); 1373 tmpMap=getMapFromMaps(conf," main","license_name");1634 tmpMap=getMapFromMaps(conf,"openapi","license_name"); 1374 1635 if(tmpMap!=NULL){ 1375 1636 json_object_object_add(res4,"name",json_object_new_string(tmpMap->value)); 1376 tmpMap=getMapFromMaps(conf," main","license_url");1637 tmpMap=getMapFromMaps(conf,"openapi","license_url"); 1377 1638 if(tmpMap!=NULL){ 1378 1639 json_object_object_add(res4,"url",json_object_new_string(tmpMap->value)); … … 1384 1645 } 1385 1646 1647 // addResponse(pmUseContent,cc3,vMap,tMap,"200","successful operation"); 1648 void addResponse(const map* useContent,json_object* res,const map* pmSchema,const map* pmType,const char* code,const char* msg){ 1649 json_object *cc=json_object_new_object(); 1650 if(pmSchema!=NULL) 1651 json_object_object_add(cc,"$ref",json_object_new_string(pmSchema->value)); 1652 if(useContent!=NULL && strncasecmp(useContent->value,"true",4)!=0){ 1653 json_object_object_add(res,code,cc); 1654 }else{ 1655 json_object *cc0=json_object_new_object(); 1656 if(pmSchema!=NULL) 1657 json_object_object_add(cc0,"schema",cc); 1658 json_object *cc1=json_object_new_object(); 1659 if(pmType!=NULL) 1660 json_object_object_add(cc1,pmType->value,cc0); 1661 else 1662 json_object_object_add(cc1,"application/json",cc0); 1663 json_object *cc2=json_object_new_object(); 1664 json_object_object_add(cc2,"content",cc1); 1665 json_object_object_add(cc2,"description",json_object_new_string(msg)); 1666 json_object_object_add(res,code,cc2); 1667 } 1668 } 1669 1670 void addParameter(maps* conf,const char* oName,const char* fName,const char* in,json_object* res){ 1671 maps* tmpMaps1=getMaps(conf,oName); 1672 json_object *res8=json_object_new_object(); 1673 if(tmpMaps1!=NULL){ 1674 map* tmpMap=getMap(tmpMaps1->content,"title"); 1675 if(tmpMap!=NULL) 1676 json_object_object_add(res8,"x-internal-summary",json_object_new_string(tmpMap->value)); 1677 tmpMap=getMap(tmpMaps1->content,"abstract"); 1678 if(tmpMap!=NULL) 1679 json_object_object_add(res8,"description",json_object_new_string(tmpMap->value)); 1680 tmpMap=getMap(tmpMaps1->content,"example"); 1681 if(tmpMap!=NULL) 1682 json_object_object_add(res8,"example",json_object_new_string(tmpMap->value)); 1683 tmpMap=getMap(tmpMaps1->content,"required"); 1684 if(tmpMap!=NULL){ 1685 if(strcmp(tmpMap->value,"true")==0) 1686 json_object_object_add(res8,"required",json_object_new_boolean(TRUE)); 1687 else 1688 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1689 } 1690 else 1691 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1692 json_object_object_add(res8,"in",json_object_new_string(in)); 1693 json_object_object_add(res8,"name",json_object_new_string(fName)); 1694 json_object *res6=json_object_new_object(); 1695 tmpMap=getMap(tmpMaps1->content,"type"); 1696 if(tmpMap!=NULL) 1697 json_object_object_add(res6,"type",json_object_new_string(tmpMap->value)); 1698 else 1699 json_object_object_add(res6,"type",json_object_new_string("string")); 1700 1701 json_object_object_add(res8,"schema",res6); 1702 1703 } 1704 json_object_object_add(res,fName,res8); 1705 } 1706 1386 1707 /** 1387 1708 * Produce the JSON object for api parameter … … 1397 1718 char *tmps12 = strtok_r (tmpMap2->value, ",", &saveptr12); 1398 1719 while(tmps12!=NULL){ 1399 char* tmpId=(char*) malloc((strlen(tmps12)+3)*sizeof(char)); 1400 sprintf(tmpId,"{%s}",tmps12); 1401 tmpMaps1=getMaps(conf,tmpId); 1402 json_object *res8=json_object_new_object(); 1403 if(tmpMaps1!=NULL){ 1404 map* tmpMap=getMap(tmpMaps1->content,"title"); 1405 if(tmpMap!=NULL) 1406 json_object_object_add(res8,"x-internal-summary",json_object_new_string(tmpMap->value)); 1407 tmpMap=getMap(tmpMaps1->content,"abstract"); 1408 if(tmpMap!=NULL) 1409 json_object_object_add(res8,"description",json_object_new_string(tmpMap->value)); 1410 tmpMap=getMap(tmpMaps1->content,"example"); 1411 if(tmpMap!=NULL) 1412 json_object_object_add(res8,"example",json_object_new_string(tmpMap->value)); 1413 tmpMap=getMap(tmpMaps1->content,"required"); 1414 if(tmpMap!=NULL){ 1415 if(strcmp(tmpMap->value,"true")==0) 1416 json_object_object_add(res8,"required",json_object_new_boolean(TRUE)); 1417 else 1418 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1419 } 1420 else 1421 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1422 json_object_object_add(res8,"in",json_object_new_string("path")); 1423 json_object_object_add(res8,"name",json_object_new_string(tmps12)); 1424 json_object *res6=json_object_new_object(); 1425 json_object *res7=json_object_new_object(); 1426 tmpMap=getMap(tmpMaps1->content,"type"); 1427 if(tmpMap!=NULL) 1428 json_object_object_add(res6,"type",json_object_new_string(tmpMap->value)); 1429 else 1430 json_object_object_add(res6,"type",json_object_new_string("string")); 1431 1432 json_object_object_add(res8,"schema",res6); 1433 1434 } 1435 1436 json_object_object_add(res9,tmps12,res8); 1720 char* pacId=(char*) malloc((strlen(tmps12)+3)*sizeof(char)); 1721 sprintf(pacId,"{%s}",tmps12); 1722 addParameter(conf,pacId,tmps12,"path",res9); 1723 free(pacId); 1437 1724 tmps12 = strtok_r (NULL, ",", &saveptr12); 1438 1725 } 1439 1726 tmpMap2=getMapFromMaps(conf,"openapi","header_parameters"); 1440 char *saveptr13; 1441 char *tmps13 = strtok_r (tmpMap2->value, ",", &saveptr13); 1442 while(tmps13!=NULL){ 1443 char* tmpId=zStrdup(tmps13); 1444 maps *tmpMaps2=getMaps(conf,tmpId); 1445 json_object *res8=json_object_new_object(); 1446 if(tmpMaps2!=NULL){ 1447 map* tmpMap=getMap(tmpMaps2->content,"title"); 1448 if(tmpMap!=NULL) 1449 json_object_object_add(res8,"x-internal-summary",json_object_new_string(tmpMap->value)); 1450 tmpMap=getMap(tmpMaps2->content,"abstract"); 1451 if(tmpMap!=NULL) 1452 json_object_object_add(res8,"description",json_object_new_string(tmpMap->value)); 1453 tmpMap=getMap(tmpMaps2->content,"example"); 1454 if(tmpMap!=NULL) 1455 json_object_object_add(res8,"example",json_object_new_string(tmpMap->value)); 1456 tmpMap=getMap(tmpMaps2->content,"required"); 1457 if(tmpMap!=NULL){ 1458 if(strcmp(tmpMap->value,"true")==0) 1459 json_object_object_add(res8,"required",json_object_new_boolean(TRUE)); 1460 else 1461 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1462 } 1463 else 1464 json_object_object_add(res8,"required",json_object_new_boolean(FALSE)); 1465 json_object_object_add(res8,"in",json_object_new_string("header")); 1466 tmpMap=getMap(tmpMaps2->content,"name"); 1467 if(tmpMap!=NULL) 1468 json_object_object_add(res8,"name",json_object_new_string(tmpMap->value)); 1469 json_object *res6=json_object_new_object(); 1470 json_object *res7=json_object_new_object(); 1471 tmpMap=getMap(tmpMaps2->content,"type"); 1472 if(tmpMap!=NULL) 1473 json_object_object_add(res6,"type",json_object_new_string(tmpMap->value)); 1474 else 1475 json_object_object_add(res6,"type",json_object_new_string("string")); 1476 1477 { 1478 tmpMap=getMap(tmpMaps2->content,"enum"); 1479 if(tmpMap!=NULL){ 1480 char *saveptr11; 1481 char *tmps11 = strtok_r (tmpMap->value, ",", &saveptr11); 1482 json_object *res71=json_object_new_array(); 1483 while(tmps11!=NULL){ 1484 json_object_array_add(res71,json_object_new_string(tmps11)); 1485 tmps11 = strtok_r (NULL, ",", &saveptr11); 1486 } 1487 json_object_object_add(res6,"enum",res71); 1488 } 1489 } 1490 1491 json_object_object_add(res8,"schema",res6); 1492 1493 } 1494 1495 json_object_object_add(res9,tmpId,res8); 1496 tmps13 = strtok_r (NULL, ",", &saveptr13); 1497 } 1498 json_object_object_add(res,"parameters",res9); 1727 if(tmpMap2!=NULL){ 1728 char *saveptr13; 1729 char *tmps13 = strtok_r (tmpMap2->value, ",", &saveptr13); 1730 while(tmps13!=NULL){ 1731 char* pacId=zStrdup(tmps13); 1732 addParameter(conf,pacId,pacId,"header",res9); 1733 free(pacId); 1734 tmps13 = strtok_r (NULL, ",", &saveptr13); 1735 } 1736 } 1737 json_object_object_add(res,"parameters",res9); 1738 maps* pmResponses=getMaps(conf,"responses"); 1739 if(pmResponses!=NULL){ 1740 json_object *cc=json_object_new_object(); 1741 map* pmLen=getMap(pmResponses->content,"length"); 1742 int iLen=atoi(pmLen->value); 1743 map* pmUseContent=getMapFromMaps(conf,"openapi","use_content"); 1744 for(int i=0;i<iLen;i++){ 1745 map* cMap=getMapArray(pmResponses->content,"code",i); 1746 map* vMap=getMapArray(pmResponses->content,"schema",i); 1747 map* tMap=getMapArray(pmResponses->content,"type",i); 1748 map* tMap0=getMapArray(pmResponses->content,"title",i); 1749 if(vMap!=NULL) 1750 addResponse(pmUseContent,cc,vMap,tMap,cMap->value,(tMap0==NULL)?"successful operation":tMap0->value); 1751 } 1752 json_object_object_add(res,"responses",cc); 1753 } 1499 1754 } 1500 1755 … … 1504 1759 json_object_object_add(res,"components",res1); 1505 1760 } 1506 1761 1507 1762 /** 1508 1763 * Produce the JSON object for /api … … 1512 1767 */ 1513 1768 void produceApi(maps* conf,json_object* res){ 1769 // TODO: add 401 Gone for dismiss request 1514 1770 json_object *res9=json_object_new_object(); 1515 1771 json_object *res10=json_object_new_object(); 1516 1772 maps* tmpMaps1=getMaps(conf,"{id}"); 1517 1518 1773 produceApiComponents(conf,res); 1519 1774 json_object *res4=json_object_new_object(); … … 1562 1817 json_object *responses=json_object_new_object(); 1563 1818 json_object *cc3=json_object_new_object(); 1819 map* pmUseContent=getMapFromMaps(conf,"openapi","use_content"); 1564 1820 vMap=getMapArray(tmpMaps->content,"schema",i); 1565 1821 if(vMap!=NULL){ 1566 json_object *cc=json_object_new_object(); 1567 json_object_object_add(cc,"$ref",json_object_new_string(vMap->value)); 1568 json_object *cc0=json_object_new_object(); 1569 json_object_object_add(cc0,"schema",cc); 1570 json_object *cc1=json_object_new_object(); 1571 map* tmpMap3=getMapFromMaps(conf,tmps,"type"); 1572 if(tmpMap3!=NULL) 1573 json_object_object_add(cc1,tmpMap3->value,cc0); 1574 else 1575 json_object_object_add(cc1,"application/json",cc0); 1576 json_object *cc2=json_object_new_object(); 1577 json_object_object_add(cc2,"content",cc1); 1578 json_object_object_add(cc2,"description",json_object_new_string("successful operation")); 1579 if(i==1) 1580 json_object_object_add(cc3,"201",cc2); 1581 else 1582 json_object_object_add(cc3,"200",cc2); 1822 map* tMap=getMapArray(tmpMaps->content,"type",i); 1823 addResponse(pmUseContent,cc3,vMap,tMap,"200","successful operation"); 1824 vMap=getMapArray(tmpMaps->content,"eschema",i); 1825 if(vMap!=NULL && cMap!=NULL && strncasecmp(cMap->value,"post",4)==0) 1826 addResponse(pmUseContent,cc3,vMap,tMap,"201","successful operation"); 1583 1827 }else{ 1584 json_object *cc1=json_object_new_object(); 1585 map* tmpMap3=getMapFromMaps(conf,tmps,"type"); 1586 if(tmpMap3!=NULL) 1587 json_object_object_add(cc1,tmpMap3->value,json_object_new_object()); 1588 else 1589 json_object_object_add(cc1,"application/json",json_object_new_object()); 1590 json_object *cc2=json_object_new_object(); 1591 json_object_object_add(cc2,"content",cc1); 1592 json_object_object_add(cc2,"description",json_object_new_string("successful operation")); 1593 if(i==1) 1594 json_object_object_add(cc3,"201",cc2); 1595 else 1596 json_object_object_add(cc3,"200",cc2); 1828 map* tMap=getMapFromMaps(conf,tmps,"type"); 1829 map* pMap=createMap("ok","true"); 1830 addResponse(pMap,cc3,vMap,tMap,"200","successful operation"); 1831 if(cMap!=NULL && strncasecmp(cMap->value,"post",4)==0) 1832 addResponse(pmUseContent,cc3,vMap,tMap,"201","successful operation"); 1597 1833 } 1598 if(strstr(tmps,"{id}")!=NULL){ 1599 vMap=getMapFromMaps(conf,"exception","schema"); 1600 json_object *cc=json_object_new_object(); 1601 json_object_object_add(cc,"$ref",json_object_new_string(vMap->value)); 1602 json_object *cc01=json_object_new_array(); 1603 json_object_array_add(cc01,cc); 1604 1605 json_object *cc0=json_object_new_object(); 1606 json_object_object_add(cc0,"schema",cc); 1607 json_object *cc1=json_object_new_object(); 1608 map* tmpMap3=getMapFromMaps(conf,"exception","type"); 1609 if(tmpMap3!=NULL) 1610 json_object_object_add(cc1,tmpMap3->value,cc0); 1611 else 1612 json_object_object_add(cc1,"application/json",cc0); 1613 1614 json_object *cc2=json_object_new_object(); 1615 json_object_object_add(cc2,"content",cc1); 1616 if(strstr(tmps,"{jobID}")==NULL) 1617 json_object_object_add(cc2,"description",json_object_new_string("The process with id {id} does not exist.")); 1618 else 1619 json_object_object_add(cc2,"description",json_object_new_string("The process with id {id} or job with id {jobID} does not exist.")); 1620 json_object_object_add(cc3,"404",cc2); 1621 json_object_object_add(cc3,"default",cc2); 1834 vMap=getMapArray(tmpMaps->content,"ecode",i); 1835 if(vMap!=NULL){ 1836 char *saveptr0; 1837 char *tmps1 = strtok_r (vMap->value, ",", &saveptr0); 1838 while(tmps1!=NULL){ 1839 char* tmpStr=(char*)malloc((strlen(tmps1)+24)*sizeof(char)); 1840 sprintf(tmpStr,"#/components/responses/%s",tmps1); 1841 vMap=createMap("ok",tmpStr); 1842 map* pMap=createMap("ok","false"); 1843 //TODO: fix successful operation with correct value 1844 addResponse(pMap,cc3,vMap,NULL,tmps1,"successful operation"); 1845 tmps1 = strtok_r (NULL, ",", &saveptr0); 1846 } 1847 }else{ 1848 if(strstr(tmps,"{id}")!=NULL){ 1849 vMap=getMapFromMaps(conf,"exception","schema"); 1850 map* tMap=getMapFromMaps(conf,"exception","type"); 1851 if(vMap!=NULL) 1852 addResponse(pmUseContent,cc3,vMap,tMap,"404", 1853 (strstr(tmps,"{jobID}")==NULL)?"The process with id {id} does not exist.":"The process with id {id} or job with id {jobID} does not exist."); 1854 } 1622 1855 } 1623 1856 json_object_object_add(methodc,"responses",cc3); … … 1640 1873 json_object_object_add(methodc,"parameters",cc2); 1641 1874 } 1642 if(i==1 ){1875 if(i==1 && cMap!=NULL && strncasecmp(cMap->value,"post",4)==0){ 1643 1876 maps* tmpMaps1=getMaps(conf,"requestBody"); 1644 1877 if(tmpMaps1!=NULL){ … … 1663 1896 json_object_object_add(methodc,"requestBody",cc2); 1664 1897 1898 } 1899 } 1900 // TODO: callbacks 1901 tmpMaps1=getMaps(conf,"callbacks"); 1902 if(tmpMaps1!=NULL){ 1903 map* pmTmp2=getMap(tmpMaps1->content,"length"); 1904 int iLen=atoi(pmTmp2->value); 1905 json_object *pajRes=json_object_new_object(); 1906 for(int i=0;i<iLen;i++){ 1907 map* pmState=getMapArray(tmpMaps1->content,"state",i); 1908 map* pmUri=getMapArray(tmpMaps1->content,"uri",i); 1909 map* pmSchema=getMapArray(tmpMaps1->content,"schema",i); 1910 map* pmType=getMapArray(tmpMaps1->content,"type",i); 1911 map* pmTitle=getMapArray(tmpMaps1->content,"title",i); 1912 json_object *pajSchema=json_object_new_object(); 1913 if(pmSchema!=NULL) 1914 json_object_object_add(pajSchema,"$ref",json_object_new_string(pmSchema->value)); 1915 json_object *pajType=json_object_new_object(); 1916 json_object_object_add(pajType,"schema",pajSchema); 1917 json_object *pajContent=json_object_new_object(); 1918 if(pmType!=NULL) 1919 json_object_object_add(pajContent,pmType->value,pajType); 1920 else 1921 json_object_object_add(pajContent,"application/json",pajType); 1922 json_object *pajRBody=json_object_new_object(); 1923 json_object_object_add(pajRBody,"content",pajContent); 1924 1925 json_object *pajDescription=json_object_new_object(); 1926 if(pmTitle!=NULL) 1927 json_object_object_add(pajDescription,"description",json_object_new_string(pmTitle->value)); 1928 json_object *pajResponse=json_object_new_object(); 1929 json_object_object_add(pajResponse,"200",pajDescription); 1930 1931 json_object *pajPost=json_object_new_object(); 1932 json_object_object_add(pajPost,"requestBody",pajRBody); 1933 json_object_object_add(pajPost,"responses",pajResponse); 1934 1935 json_object *pajMethod=json_object_new_object(); 1936 json_object_object_add(pajMethod,"post",pajPost); 1937 1938 1939 char* pacUri=(char*) malloc((strlen(pmUri->value)+29)*sizeof(char)); 1940 sprintf(pacUri,"{$request.body#/subscriber/%s}",pmUri->value); 1941 1942 json_object *pajFinal=json_object_new_object(); 1943 json_object_object_add(pajFinal,pacUri,pajMethod); 1944 1945 json_object_object_add(pajRes,pmState->value,pajFinal); 1946 1665 1947 } 1948 json_object_object_add(methodc,"callbacks",pajRes); 1666 1949 } 1667 1950 } -
trunk/zoo-project/zoo-kernel/service_json.h
r949 r962 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright 2014 GeoLabs SARL. All rights reserved.4 * Copyright 2014-2020 GeoLabs SARL. All rights reserved. 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 50 50 void printGetCapabilitiesForProcessJ(registry*, maps*,void*,void*,service*); 51 51 void printExceptionReportResponseJ(maps*,map*); 52 void parseJRequest(maps*,service* s,json_object*,map s**,maps**);52 void parseJRequest(maps*,service* s,json_object*,map*,maps**,maps**); 53 53 json_object* printJResult(maps*,service*,maps*,int); 54 54 json_object* printJobList(maps*); 55 55 int createStatusFile(maps*,int); 56 json_object* createStatus(maps*,int); 57 char* json_getStatusFilePath(maps*); 58 json_object* parseJson(maps*,char*); 59 json_object* json_readFile(maps*,char*); 60 char* getResultPath(maps*,char*); 56 61 int json_getStatusFile(maps*); 57 62 void produceApi(maps*,json_object*); -
trunk/zoo-project/zoo-kernel/sqlapi.c
r955 r962 33 33 #include <fcgi_stdio.h> 34 34 #include "sqlapi.h" 35 #include "service_callback.h" 35 36 36 37 /** … … 375 376 map *msg=getMapFromMaps(conf,"lenv","message"); 376 377 map *schema=getMapFromMaps(conf,"database","schema"); 377 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+6 4+1)*sizeof(char));378 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+62+1)*sizeof(char)); 378 379 sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value); 379 380 if( zoo_DS == NULL || zoo_DS[zoo_ds_nb-1]==NULL ){ 381 if(getMapFromMaps(conf,"lenv","file.log")==NULL){ 382 free(sqlQuery); 383 return 1; 384 } 380 385 init_sql(conf); 381 386 zoo_ds_nb++; … … 384 389 cleanUpResultSet(conf,zoo_ds_nb-1); 385 390 free(sqlQuery); 391 invokeBasicCallback(conf,SERVICE_STARTED); 386 392 return 0; 387 393 } … … 398 404 int created=-1; 399 405 map *schema=getMapFromMaps(conf,"database","schema"); 400 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+ 58+1)*sizeof(char));401 sprintf(sqlQuery,"select status||'|'||messagefrom %s.services where uuid=$$%s$$;",schema->value,pid);406 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+104+1)*sizeof(char)); 407 sprintf(sqlQuery,"select CASE WHEN message is null THEN '-1' ELSE status||'|'||message END from %s.services where uuid=$$%s$$;",schema->value,pid); 402 408 if( zoo_ds_nb== 403 409 #ifdef META_DB -
trunk/zoo-project/zoo-kernel/zoo_loader.c
r949 r962 105 105 int len=0; 106 106 while((r=fread(buffer,sizeof(char),1,cgiIn))>0){ 107 fprintf(stderr,"%s",buffer);108 107 buffer[1]=0; 109 108 if(res==NULL){ -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r955 r962 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright 2008-20 13GeoLabs SARL. All rights reserved.4 * Copyright 2008-2020 GeoLabs SARL. All rights reserved. 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 63 63 #include <string.h> 64 64 65 #include "service.h"66 67 65 #include "service_internal.h" 68 66 #include "server_internal.h" 69 67 #include "response_print.h" 70 68 #include "request_parser.h" 69 #include "service.h" 70 71 71 #ifdef USE_JSON 72 72 #include "caching.h" … … 106 106 #endif 107 107 108 #if def USE_CALLBACK108 #if defined(USE_CALLBACK) || defined(USE_JSON) 109 109 #include "service_callback.h" 110 110 #endif … … 417 417 _("Unable to parse the ZCFG file: %s."), 418 418 zcfg); 419 419 420 map* errormap = createMap("text", tmp01); 420 addToMap(errormap,"code", code); 421 map* tmpMap=getMapFromMaps(m,"lenv","executionType"); 422 char* errorCode=(char*)code; 423 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"json",4)==0) 424 errorCode="NoSuchProcess"; 425 426 addToMap(errormap,"code", errorCode); 421 427 addToMap(errormap,"locator", locator); 422 428 funcError(m,errormap); … … 685 691 fflush (stdout); 686 692 zDup2 (saved_stdout, fileno (stdout)); 693 zClose(saved_stdout); 687 694 free (orig); 688 695 return 0; … … 1870 1877 #endif 1871 1878 } 1872 1879 1880 int eres = SERVICE_STARTED; 1881 int cpid = zGetpid (); 1882 maps* bmap=NULL; 1883 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; 1884 FILE *f0, *f1; 1885 HINTERNET hInternet; 1886 service *s1; 1887 maps *request_output_real_format = NULL; 1888 maps *request_input_real_format = NULL; 1889 1873 1890 setMapInMaps(m,"lenv","executionType","xml"); 1874 if((strlen(cgiQueryString)>0 && cgiQueryString[0]=='/') && strstr(cgiAccept,"json")!=NULL){1875 //1876 // OGC API - Processing starts here1877 //1891 if((strlen(cgiQueryString)>0 && cgiQueryString[0]=='/') /*&& strstr(cgiAccept,"json")!=NULL*/){ 1892 // 1893 // OGC API - Processing starts here 1894 // 1878 1895 #ifndef USE_JSON 1879 1896 errorException (m, _("OGC API - Processing is not supported by this ZOO-Kernel."), "InternalError", NULL); … … 1904 1921 addMapsToMaps(&m,m1); 1905 1922 setMapInMaps(m,"lenv","executionType","json"); 1906 1923 map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support"); 1924 dumpMap(pmTmp0); 1925 if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){ 1926 map* pmTmpUrl=getMapFromMaps(m,"openapi","rootUrl"); 1927 char* pacTmpUrl=NULL; 1928 if(strcmp(cgiQueryString,"/")!=0){ 1929 pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char)); 1930 sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString); 1931 } 1932 else{ 1933 pacTmpUrl=(char*)malloc((strlen(pmTmpUrl->value)+6)*sizeof(char)); 1934 sprintf(pacTmpUrl,"%s/index.html",pmTmpUrl->value); 1935 } 1936 setMapInMaps(m,"headers","Location",pacTmpUrl); 1937 printHeaders(m); 1938 printf("Status: 302 Moved permanently \r\n\r\n"); 1939 fflush(stdout); 1940 free(pacTmpUrl); 1941 return 1; 1942 } 1907 1943 json_object *res=json_object_new_object(); 1908 1944 setMapInMaps(m,"headers","Content-Type","application/json;charset=UTF-8"); … … 1917 1953 for(int kk=0;kk<4;kk++){ 1918 1954 maps* tmpMaps=getMaps(m,urls[kk]); 1919 json_object *res2;1920 1955 if(tmpMaps!=NULL){ 1956 json_object *res2; 1921 1957 res2=mapToJson(tmpMaps->content); 1922 1958 char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(urls[kk])+2)*sizeof(char)); 1923 1959 sprintf(tmpStr,"%s%s",tmpUrl->value,urls[kk]); 1924 1960 json_object_object_add(res2,"href",json_object_new_string(tmpStr)); 1961 free(tmpStr); 1925 1962 json_object_array_add(res1,res2); 1963 1964 map* pmTmp=getMap(tmpMaps->content,"title"); 1965 char *pacTitle=NULL; 1966 if(pmTmp!=NULL) 1967 pacTitle=zStrdup(pmTmp->value); 1968 char* pacTmp=(char*) malloc((strlen(urls[kk])+6)*sizeof(char)); 1969 sprintf(pacTmp,"%s.html",urls[kk]); 1970 tmpMaps=getMaps(m,pacTmp); 1971 if(tmpMaps==NULL && strncasecmp(pacTmp,"/.html",6)==0) 1972 tmpMaps=getMaps(m,"/index.html"); 1973 if(tmpMaps!=NULL){ 1974 json_object *res3; 1975 res3=mapToJson(tmpMaps->content); 1976 if(getMap(tmpMaps->content,"title")==NULL && pacTitle!=NULL){ 1977 json_object_object_add(res3,"title",json_object_new_string(pacTitle)); 1978 } 1979 char* tmpStr=NULL; 1980 if(strncasecmp(pacTmp,"/.html",6)==0){ 1981 tmpStr=(char*) malloc((strlen(tmpUrl->value)+12)*sizeof(char)); 1982 sprintf(tmpStr,"%s/index.html",tmpUrl->value); 1983 }else{ 1984 tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(urls[kk])+6)*sizeof(char)); 1985 sprintf(tmpStr,"%s%s.html",tmpUrl->value,urls[kk]); 1986 } 1987 json_object_object_add(res3,"href",json_object_new_string(tmpStr)); 1988 free(tmpStr); 1989 json_object_array_add(res1,res3); 1990 } 1991 free(pacTmp); 1992 if(pacTitle!=NULL) 1993 free(pacTitle); 1926 1994 } 1927 1995 } 1996 map* pmTmp=getMapFromMaps(m,"identification","title"); 1997 if(pmTmp!=NULL) 1998 json_object_object_add(res,"title",json_object_new_string(pmTmp->value)); 1999 pmTmp=getMapFromMaps(m,"identification","abstract"); 2000 if(pmTmp!=NULL) 2001 json_object_object_add(res,"description",json_object_new_string(pmTmp->value)); 1928 2002 json_object_object_add(res,"links",res1); 1929 2003 }else if(strcmp(cgiQueryString,"/conformance")==0){ 1930 2004 /* - /conformance url */ 1931 map* rootUrl=getMapFromMaps(m,"conform To","rootUrl");2005 map* rootUrl=getMapFromMaps(m,"conformsTo","rootUrl"); 1932 2006 json_object *res1=json_object_new_array(); 1933 map* length=getMapFromMaps(m,"conform To","length");1934 maps* tmpMaps=getMaps(m,"conform To");2007 map* length=getMapFromMaps(m,"conformsTo","length"); 2008 maps* tmpMaps=getMaps(m,"conformsTo"); 1935 2009 for(int kk=0;kk<atoi(length->value);kk++){ 1936 2010 map* tmpMap1=getMapArray(tmpMaps->content,"link",kk); … … 1942 2016 } 1943 2017 } 1944 json_object_object_add(res,"conformTo",res1); 1945 }else if(strcmp(cgiQueryString,"/api")==0){ 1946 /* - /api url */ 1947 produceApi(m,res); 2018 json_object_object_add(res,"conformsTo",res1); 2019 }else if(strncasecmp(cgiQueryString,"/api",4)==0){ 2020 if(strstr(cgiQueryString,".html")==NULL) 2021 produceApi(m,res); 2022 else{ 2023 char* pacTmp=(char*)malloc(9*sizeof(char)); 2024 sprintf(pacTmp,"%s",cgiQueryString+1); 2025 map* pmTmp=getMapFromMaps(m,pacTmp,"href"); 2026 free(pacTmp); 2027 if(pmTmp!=NULL) 2028 setMapInMaps(m,"headers","Location",pmTmp->value); 2029 } 1948 2030 }else if(strcmp(cgiQueryString,"/processes")==0 || strcmp(cgiQueryString,"/processes/")==0){ 1949 2031 /* - /processes */ 2032 setMapInMaps(m,"lenv","requestType","desc"); 1950 2033 json_object *res3=json_object_new_array(); 1951 2034 int saved_stdout = zDup (fileno (stdout)); 1952 2035 zDup2 (fileno (stderr), fileno (stdout)); 1953 1954 if (int res = 2036 if (int res0 = 1955 2037 recursReaddirF (m, NULL, res3, NULL, ntmp, NULL, saved_stdout, 0, 1956 2038 printGetCapabilitiesForProcessJ) < 0) … … 1959 2041 zDup2 (saved_stdout, fileno (stdout)); 1960 2042 zClose(saved_stdout); 1961 1962 json_object_object_add(res,"processes",res3);2043 res=res3; 2044 //json_object_object_add(res,"processes",res3); 1963 2045 }else{ 1964 2046 service* s1=NULL; … … 1984 2066 orig[strlen(orig)-1]=0; 1985 2067 json_object* res1=json_object_new_object(); 2068 setMapInMaps(m,"lenv","requestType","GetCapabilities"); 1986 2069 int t=fetchServicesForDescription(NULL, m, orig, 1987 2070 printGetCapabilitiesForProcessJ, … … 1991 2074 if(t==1){ 1992 2075 /*map* error=createMap("code","BadRequest"); 1993 addToMap(error,"message",_("Failed to acces the requested service"));1994 printExceptionReportResponseJ(m,error);*/2076 addToMap(error,"message",_("Failed to acces the requested service")); 2077 printExceptionReportResponseJ(m,error);*/ 1995 2078 return 1; 1996 2079 } … … 2003 2086 int cnt=0; 2004 2087 for(int j=11;j<len1;j++){ 2005 fprintf(stderr,"%s %c\n",cIdentifier,cgiQueryString[j]);2006 2088 cIdentifier[cnt]=cgiQueryString[j]; 2007 2089 cIdentifier[cnt+1]=0; … … 2009 2091 } 2010 2092 char tmps1[1024]; 2011 2012 2093 map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 2013 2094 if (import != NULL && import->value != NULL) { … … 2023 2104 if (strstr (cIdentifier, ".") != NULL) 2024 2105 { 2106 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2025 2107 char *identifier = zStrdup (cIdentifier); 2026 2108 parseIdentifier (m, ntmp, identifier, tmps1); … … 2071 2153 map* error=createMap("code","InternalError"); 2072 2154 addToMap(error,"message",_("Unable to allocate memory")); 2073 //setMapInMaps(conf,"lenv","status_code","404 Bad Request");2155 setMapInMaps(m,"lenv","status_code","404 Bad Request"); 2074 2156 printExceptionReportResponseJ(m,error); 2075 2157 … … 2091 2173 free(zooRegistry); 2092 2174 } 2175 fflush(stderr); 2093 2176 fflush (stdout); 2094 2177 zDup2 (saved_stdout, fileno (stdout)); 2178 zClose (saved_stdout); 2095 2179 if (t < 0) 2096 2180 { 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; 2181 r_inputs = getMapFromMaps (m, "lenv", "oIdentifier"); 2182 if(r_inputs!=NULL){ 2183 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 2184 sprintf (tmpMsg, 2185 _ 2186 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 2187 r_inputs->value); 2188 map* error=createMap("code","NoSuchProcess"); 2189 addToMap(error,"message",tmpMsg); 2190 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2191 printExceptionReportResponseJ(m,error); 2192 2193 //errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 2194 free (tmpMsg); 2195 free (s1); 2196 freeMaps (&m); 2197 free (m); 2198 free (REQUEST); 2199 free (SERVICE_URL); 2200 return 0; 2201 } 2115 2202 } 2116 zClose (saved_stdout);2117 2118 2203 #ifdef META_DB 2119 2204 } 2120 2205 #endif 2121 if(strstr(cgiQueryString,"/jobs/")!=NULL && strlen(strstr(cgiQueryString,"/jobs/"))>6) {2206 if(strstr(cgiQueryString,"/jobs/")!=NULL && strlen(strstr(cgiQueryString,"/jobs/"))>6) { 2122 2207 /* - /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__); 2208 if(strstr(cgiQueryString,"/results")!=NULL){ 2209 // In case the service has run, then forward request to target result file 2210 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2211 jobId[strlen(jobId)-8]=0; 2212 char *sid=getStatusId(m,jobId); 2213 if(sid==NULL){ 2214 map* error=createMap("code","NoSuchJob"); 2215 addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server")); 2216 printExceptionReportResponseJ(m,error); 2217 return 1; 2218 }else{ 2219 if(isRunning(m,jobId)>0){ 2220 map* error=createMap("code","ResultNotReady"); 2221 addToMap(error,"message",_("The job is still running.")); 2222 printExceptionReportResponseJ(m,error); 2223 return 1; 2224 }else{ 2225 char *Url0=getResultPath(m,jobId); 2226 map *cIdentifier = getMapFromMaps (m, "lenv", "oIdentifier"); 2227 zStatStruct f_status; 2228 int s=zStat(Url0, &f_status); 2229 if(s==0 && f_status.st_size>0){ 2230 if(f_status.st_size>15){ 2231 json_object* pjoTmp=json_readFile(m,Url0); 2232 json_object* pjoCode=NULL; 2233 json_object* pjoMessage=NULL; 2234 if(pjoTmp!=NULL && 2235 json_object_object_get_ex(pjoTmp,"code",&pjoCode)!=FALSE && 2236 json_object_object_get_ex(pjoTmp,"description",&pjoMessage)!=FALSE){ 2237 map* error=createMap("code",json_object_get_string(pjoCode)); 2238 addToMap(error,"message",json_object_get_string(pjoMessage)); 2239 printExceptionReportResponseJ(m,error); 2240 return 1; 2241 }else{ 2242 2243 map* tmpPath = getMapFromMaps (m, "main", "tmpUrl"); 2244 Url0=(char*) realloc(Url0,(strlen(tmpPath->value)+ 2245 strlen(cIdentifier->value)+ 2246 strlen(jobId)+8)*sizeof(char)); 2247 sprintf(Url0,"%s/%s_%s.json",tmpPath->value, 2248 cIdentifier->value,jobId); 2249 setMapInMaps(m,"headers","Location",Url0); 2250 } 2251 free(Url0); 2252 }else{ 2253 // Service Failed 2254 map* statusInfo=createMap("JobID",jobId); 2255 readFinalRes(m,jobId,statusInfo); 2256 { 2257 map* pmStatus=getMap(statusInfo,"status"); 2258 if(pmStatus!=NULL) 2259 setMapInMaps(m,"lenv","status",pmStatus->value); 2260 } 2261 char* tmpStr=_getStatus(m,jobId); 2262 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 2263 char *tmpStr1=zStrdup(tmpStr); 2264 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 2265 free(tmpStr); 2266 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; 2267 addToMap(statusInfo,"PercentCompleted",tmpStr1); 2268 addToMap(statusInfo,"Message",tmpStr0); 2269 setMapInMaps(m,"lenv","PercentCompleted",tmpStr1); 2270 setMapInMaps(m,"lenv","Message",tmpStr0); 2271 free(tmpStr0); 2272 free(tmpStr1); 2273 } 2274 map* error=createMap("code","NoApplicableCode"); 2275 addToMap(error,"message",_("The service failed to execute.")); 2276 printExceptionReportResponseJ(m,error); 2277 return 1; 2278 } 2279 2280 }else{ 2281 map* error=createMap("code","NoSuchJob"); 2282 addToMap(error,"message",_("The JobID seem to be running on this server but not for this process id")); 2283 printExceptionReportResponseJ(m,error); 2284 return 1; 2285 } 2286 } 2287 } 2125 2288 }else{ 2126 2289 char* tmpUrl=strstr(cgiQueryString,"/jobs/"); 2127 2290 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; 2291 if(strncasecmp(cgiRequestMethod,"DELETE",6)==0){ 2292 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2293 setMapInMaps(m,"lenv","gs_usid",jobId); 2294 setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m)); 2295 runDismiss(m,jobId); 2296 map* pmError=getMapFromMaps(m,"lenv","error"); 2297 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2298 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2299 return 1; 2300 } 2301 else{ 2302 setMapInMaps(m,"lenv","gs_location","false"); 2303 res=createStatus(m,SERVICE_DISMISSED); 2304 } 2305 }else{ 2306 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2307 runGetStatus(m,jobId,"GetStatus"); 2308 map* pmError=getMapFromMaps(m,"lenv","error"); 2309 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2310 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2311 return 1; 2312 }else{ 2313 map* pmStatus=getMapFromMaps(m,"lenv","status"); 2314 setMapInMaps(m,"lenv","gs_location","false"); 2315 setMapInMaps(m,"lenv","gs_usid",jobId); 2316 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Failed",6)==0) 2317 res=createStatus(m,SERVICE_FAILED); 2318 else 2319 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Succeeded",9)==0) 2320 res=createStatus(m,SERVICE_SUCCEEDED); 2321 else 2322 if(pmStatus!=NULL && strncasecmp(pmStatus->value,"Running",7)==0){ 2323 map* tmpMap=getMapFromMaps(m,"lenv","Message"); 2324 if(tmpMap!=NULL) 2325 setMapInMaps(m,"lenv","gs_message",tmpMap->value); 2326 res=createStatus(m,SERVICE_STARTED); 2327 } 2328 else 2329 res=createStatus(m,SERVICE_FAILED); 2330 } 2331 free(jobId); 2332 } 2133 2333 } 2134 2334 } 2135 2335 }else{ 2136 2336 /* - /jobs url */ 2137 fprintf(stderr,"For Execute or Job list %s %d \n",__FILE__,__LINE__);2138 2337 if(strcasecmp(cgiRequestMethod,"get")==0){ 2139 2338 /* - /jobs List (GET) */ … … 2141 2340 }else if(strcasecmp(cgiRequestMethod,"post")==0){ 2142 2341 /* - /jobs Execution (POST) */ 2143 int eres = SERVICE_STARTED; 2144 2342 eres = SERVICE_STARTED; 2145 2343 initAllEnvironment(m,request_inputs,ntmp,"jrequest"); 2146 2344 map* req=getMapFromMaps(m,"renv","jrequest"); … … 2156 2354 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 2157 2355 if (jerr != json_tokener_success) { 2356 map* pamError=createMap("code","InvalidParameterValue"); 2357 const char* pcTmpErr=json_tokener_error_desc(jerr); 2358 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2359 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2360 sprintf(pacMessage,pccErr,pcTmpErr); 2361 addToMap(pamError,"message",pacMessage); 2362 printExceptionReportResponseJ(m,pamError); 2158 2363 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2159 2364 return 1; 2160 2365 } 2161 2366 if (tok->char_offset < slen){ 2367 map* pamError=createMap("code","InvalidParameterValue"); 2368 const char* pcTmpErr="None"; 2369 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2370 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2371 sprintf(pacMessage,pccErr,pcTmpErr); 2372 addToMap(pamError,"message",pacMessage); 2373 printExceptionReportResponseJ(m,pamError); 2374 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2162 2375 return 1; 2163 2376 } 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); 2377 //maps* inputs_real_format=NULL, *outputs_real_format= NULL; 2378 parseJRequest(m,s1,jobj,request_inputs,&request_input_real_format,&request_output_real_format); 2168 2379 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; 2380 map* mode=getMap(request_inputs,"mode"); 2381 if((preference!=NULL && strcasecmp(preference->value,"respond-async")==0) || 2382 (mode!=NULL && strncasecmp(mode->value,"async",5)==0)) { 2173 2383 int pid; 2174 2384 #ifdef DEBUG … … 2204 2414 eres = SERVICE_ACCEPTED; 2205 2415 createStatusFile(m,eres); 2416 //invokeBasicCallback(m,SERVICE_ACCEPTED); 2206 2417 printHeaders(m); 2207 2418 printf("Status: 201 Created \r\n\r\n"); … … 2215 2426 // process answer to http client. 2216 2427 // 2428 map* oid = getMapFromMaps (m, "lenv", "oIdentifier"); 2217 2429 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2218 2430 map* tmpm = getMapFromMaps (m, "lenv", "osid"); … … 2228 2440 strlen (usid->value) + 7) * sizeof (char)); 2229 2441 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2230 maps*bmap = createMaps("status");2442 bmap = createMaps("status"); 2231 2443 bmap->content=createMap("usid",usid->value); 2232 2444 addToMap(bmap->content,"sid",tmpm->value); … … 2248 2460 fbkp = 2249 2461 (char *) 2250 malloc ((strlen (r_inputs->value) + strlen ( r_inputs1->value) +2462 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2251 2463 strlen (usid->value) + 7) * sizeof (char)); 2252 2464 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); … … 2259 2471 fbkp = 2260 2472 (char *) 2261 malloc ((strlen (r_inputs->value) + strlen ( r_inputs1->value) +2473 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2262 2474 strlen (usid->value) + 7) * sizeof (char)); 2263 sprintf (fbkp, "%s/%s_%s. xml", r_inputs->value, r_inputs1->value,2475 sprintf (fbkp, "%s/%s_%s.json", r_inputs->value, oid->value, 2264 2476 usid->value); 2265 2477 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 2266 2478 flog = 2267 2479 (char *) 2268 malloc ((strlen (r_inputs->value) + strlen ( r_inputs1->value) +2480 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2269 2481 strlen (usid->value) + 13) * sizeof (char)); 2270 2482 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2271 r_inputs1->value, usid->value);2483 oid->value, usid->value); 2272 2484 setMapInMaps (m, "lenv", "file.log", flog); 2273 2485 #ifdef DEBUG … … 2291 2503 invokeCallback(m,NULL,NULL,0,0); 2292 2504 #endif 2293 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 2294 fflush(stderr); 2295 2296 createStatusFile(m,eres); 2297 2298 2505 invokeBasicCallback(m,SERVICE_STARTED); 2506 createStatusFile(m,SERVICE_STARTED); 2299 2507 fbkp1 = 2300 2508 (char *) 2301 malloc ((strlen (r_inputs->value) + strlen ( r_inputs1->value) +2509 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2302 2510 strlen (usid->value) + 15) * sizeof (char)); 2303 2511 sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value, 2304 r_inputs1->value, usid->value);2512 oid->value, usid->value); 2305 2513 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 2306 2514 … … 2317 2525 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2318 2526 maps* lenvMaps=getMaps(m,"lenv"); 2319 dumpMapsToFile(lenvMaps,flenv, 0);2527 dumpMapsToFile(lenvMaps,flenv,1); 2320 2528 free(flenv); 2321 2529 2322 2530 map* testMap=getMapFromMaps(m,"main","memory"); 2323 loadHttpRequests(m,inputs_real_format); 2531 loadHttpRequests(m,request_input_real_format); 2532 dumpMaps(request_input_real_format); 2324 2533 loadServiceAndRun (&m, s1, request_inputs, 2325 &inputs_real_format, 2326 &outputs_real_format, &eres); 2534 &request_input_real_format, 2535 &request_output_real_format, &eres); 2536 setMapInMaps(m,"lenv","force","true"); 2327 2537 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 2538 setMapInMaps(m,"lenv","force","false"); 2539 setMapInMaps(m,"lenv","no-headers","true"); 2540 fflush(stdout); 2541 rewind(stdout); 2542 res=printJResult(m,s1,request_output_real_format,eres); 2543 const char* jsonStr0=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2544 if(getMapFromMaps(m,"lenv","jsonStr")==NULL) 2545 setMapInMaps(m,"lenv","jsonStr",jsonStr0); 2546 invokeBasicCallback(m,eres); 2335 2547 } 2336 2548 }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; 2549 loadHttpRequests(m,request_input_real_format); 2550 loadServiceAndRun (&m,s1,request_inputs, 2551 &request_input_real_format, 2552 &request_output_real_format,&eres); 2553 res=printJResult(m,s1,request_output_real_format,eres); 2347 2554 } 2348 2555 … … 2353 2560 } 2354 2561 } 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 // 2367 //Check for minimum inputs 2368 map* version=getMap(request_inputs,"version"); 2369 if(version==NULL) 2370 version=getMapFromMaps(m,"main","version"); 2371 setMapInMaps(m,"main","rversion",version->value); 2372 int vid=getVersionId(version->value); 2373 if(vid<0) 2374 vid=0; 2375 map* err=NULL; 2376 const char **vvr=(const char**)requests[vid]; 2377 checkValidValue(request_inputs,&err,"request",vvr,1); 2378 const char *vvs[]={ 2379 "WPS", 2380 NULL 2381 }; 2382 if(err!=NULL){ 2562 if(res!=NULL){ 2563 if(getMapFromMaps(m,"lenv","no-headers")==NULL){ 2564 printHeaders(m); 2565 printf("Status: 200 OK \r\n\r\n"); 2566 } 2567 const char* jsonStr=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2568 printf(jsonStr); 2569 printf("\n"); 2570 fflush(stdout); 2571 } 2572 //return 1; 2573 #endif 2574 }else{ 2575 2576 // 2577 // WPS 1.0.0 and 2.0.0 starts here 2578 // 2579 //Check for minimum inputs 2580 map* version=getMap(request_inputs,"version"); 2581 if(version==NULL) 2582 version=getMapFromMaps(m,"main","version"); 2583 setMapInMaps(m,"main","rversion",version->value); 2584 int vid=getVersionId(version->value); 2585 if(vid<0) 2586 vid=0; 2587 map* err=NULL; 2588 const char **vvr=(const char**)requests[vid]; 2589 checkValidValue(request_inputs,&err,"request",vvr,1); 2590 const char *vvs[]={ 2591 "WPS", 2592 NULL 2593 }; 2594 if(err!=NULL){ 2595 checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); 2596 printExceptionReportResponse (m, err); 2597 freeMap(&err); 2598 free(err); 2599 if (count (request_inputs) == 1) 2600 { 2601 freeMap (&request_inputs); 2602 free (request_inputs); 2603 } 2604 freeMaps (&m); 2605 free (m); 2606 return 1; 2607 } 2383 2608 checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); 2384 printExceptionReportResponse (m, err); 2385 freeMap(&err); 2386 free(err); 2387 if (count (request_inputs) == 1) 2388 { 2389 freeMap (&request_inputs); 2390 free (request_inputs); 2391 } 2392 freeMaps (&m); 2393 free (m); 2394 return 1; 2395 } 2396 checkValidValue(request_inputs,&err,"service",(const char**)vvs,1); 2397 2398 const char *vvv[]={ 2399 "1.0.0", 2400 "2.0.0", 2401 NULL 2402 }; 2403 r_inputs = getMap (request_inputs, "Request"); 2404 if(r_inputs!=NULL) 2405 REQUEST = zStrdup (r_inputs->value); 2406 int reqId=-1; 2407 if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ 2408 checkValidValue(request_inputs,&err,"version",(const char**)vvv,1); 2409 int j=0; 2410 for(j=0;j<nbSupportedRequests;j++){ 2411 if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){ 2412 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 2413 checkValidValue(request_inputs,&err,"identifier",NULL,1); 2414 reqId=j+1; 2415 break; 2416 } 2417 else 2418 if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 2419 strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 2420 checkValidValue(request_inputs,&err,"jobid",NULL,1); 2609 2610 const char *vvv[]={ 2611 "1.0.0", 2612 "2.0.0", 2613 NULL 2614 }; 2615 r_inputs = getMap (request_inputs, "Request"); 2616 if(r_inputs!=NULL) 2617 REQUEST = zStrdup (r_inputs->value); 2618 int reqId=-1; 2619 if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ 2620 checkValidValue(request_inputs,&err,"version",(const char**)vvv,1); 2621 int j=0; 2622 for(j=0;j<nbSupportedRequests;j++){ 2623 if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){ 2624 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 2625 checkValidValue(request_inputs,&err,"identifier",NULL,1); 2421 2626 reqId=j+1; 2422 2627 break; 2423 2628 } 2424 }else 2425 break; 2426 } 2427 }else{ 2428 checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1); 2429 map* version1=getMap(request_inputs,"AcceptVersions"); 2430 if(version1!=NULL){ 2431 if(strstr(version1->value,schemas[1][0])!=NULL){ 2432 addToMap(request_inputs,"version",schemas[1][0]); 2433 setMapInMaps(m,"main","rversion",schemas[1][0]); 2629 else 2630 if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 2631 strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 2632 checkValidValue(request_inputs,&err,"jobid",NULL,1); 2633 reqId=j+1; 2634 break; 2635 } 2636 }else 2637 break; 2434 2638 } 2435 else{ 2436 addToMap(request_inputs,"version",version1->value); 2437 setMapInMaps(m,"main","rversion",version1->value); 2639 }else{ 2640 checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1); 2641 map* version1=getMap(request_inputs,"AcceptVersions"); 2642 if(version1!=NULL){ 2643 if(strstr(version1->value,schemas[1][0])!=NULL){ 2644 addToMap(request_inputs,"version",schemas[1][0]); 2645 setMapInMaps(m,"main","rversion",schemas[1][0]); 2646 } 2647 else{ 2648 addToMap(request_inputs,"version",version1->value); 2649 setMapInMaps(m,"main","rversion",version1->value); 2650 } 2651 version=getMap(request_inputs,"version"); 2438 2652 } 2439 version=getMap(request_inputs,"version"); 2440 } 2441 } 2442 if(err!=NULL){ 2443 printExceptionReportResponse (m, err); 2444 freeMap(&err); 2445 free(err); 2446 if (count (request_inputs) == 1) 2653 } 2654 if(err!=NULL){ 2655 printExceptionReportResponse (m, err); 2656 freeMap(&err); 2657 free(err); 2658 if (count (request_inputs) == 1) 2659 { 2660 freeMap (&request_inputs); 2661 free (request_inputs); 2662 } 2663 free(REQUEST); 2664 freeMaps (&m); 2665 free (m); 2666 return 1; 2667 } 2668 2669 r_inputs = getMap (request_inputs, "serviceprovider"); 2670 if (r_inputs == NULL) 2447 2671 { 2448 freeMap (&request_inputs); 2449 free (request_inputs); 2672 addToMap (request_inputs, "serviceprovider", ""); 2450 2673 } 2451 free(REQUEST); 2452 freeMaps (&m); 2453 free (m); 2454 return 1; 2455 } 2456 2457 r_inputs = getMap (request_inputs, "serviceprovider"); 2458 if (r_inputs == NULL) 2459 { 2460 addToMap (request_inputs, "serviceprovider", ""); 2461 } 2462 2463 maps *request_output_real_format = NULL; 2464 map *tmpm = getMapFromMaps (m, "main", "serverAddress"); 2465 if (tmpm != NULL) 2466 SERVICE_URL = zStrdup (tmpm->value); 2467 else 2468 SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); 2469 2470 2471 2472 service *s1; 2473 int scount = 0; 2474 #ifdef DEBUG 2475 dumpMap (r_inputs); 2476 #endif 2477 2478 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 2479 { 2480 #ifdef DEBUG 2481 dumpMap (r_inputs); 2482 #endif 2483 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 2484 xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0")); 2485 /** 2486 * Here we need to close stdout to ensure that unsupported chars 2487 * has been found in the zcfg and then printed on stdout 2488 */ 2489 int saved_stdout = zDup (fileno (stdout)); 2490 zDup2 (fileno (stderr), fileno (stdout)); 2491 2492 maps* imports = getMaps(m, IMPORTSERVICE); 2493 if (imports != NULL) { 2494 map* zcfg = imports->content; 2674 2675 map *tmpm = getMapFromMaps (m, "main", "serverAddress"); 2676 if (tmpm != NULL) 2677 SERVICE_URL = zStrdup (tmpm->value); 2678 else 2679 SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL); 2680 2681 2682 int scount = 0; 2683 #ifdef DEBUG 2684 dumpMap (r_inputs); 2685 #endif 2686 2687 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 2688 { 2689 #ifdef DEBUG 2690 dumpMap (r_inputs); 2691 #endif 2692 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 2693 xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0")); 2694 /** 2695 * Here we need to close stdout to ensure that unsupported chars 2696 * has been found in the zcfg and then printed on stdout 2697 */ 2698 int saved_stdout = zDup (fileno (stdout)); 2699 zDup2 (fileno (stderr), fileno (stdout)); 2700 2701 maps* imports = getMaps(m, IMPORTSERVICE); 2702 if (imports != NULL) { 2703 map* zcfg = imports->content; 2495 2704 2496 while (zcfg != NULL) { 2497 if (zcfg->value != NULL) { 2498 service* svc = (service*) malloc(SERVICE_SIZE); 2499 if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { 2500 // pass over silently 2501 zcfg = zcfg->next; 2502 continue; 2705 while (zcfg != NULL) { 2706 if (zcfg->value != NULL) { 2707 service* svc = (service*) malloc(SERVICE_SIZE); 2708 if (svc == NULL || readServiceFile(m, zcfg->value, &svc, zcfg->name) < 0) { 2709 // pass over silently 2710 zcfg = zcfg->next; 2711 continue; 2712 } 2713 inheritance(zooRegistry, &svc); 2714 printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); 2715 freeService(&svc); 2716 free(svc); 2503 2717 } 2504 inheritance(zooRegistry, &svc); 2505 printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); 2506 freeService(&svc); 2507 free(svc); 2718 zcfg = zcfg->next; 2719 } 2720 } 2721 2722 if (int res = 2723 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 2724 printGetCapabilitiesForProcess) < 0) 2725 { 2726 freeMaps (&m); 2727 free (m); 2728 if(zooRegistry!=NULL){ 2729 freeRegistry(&zooRegistry); 2730 free(zooRegistry); 2731 } 2732 free (REQUEST); 2733 free (SERVICE_URL); 2734 fflush (stdout); 2735 return res; 2508 2736 } 2509 zcfg = zcfg->next; 2510 } 2737 fflush (stdout); 2738 zDup2 (saved_stdout, fileno (stdout)); 2739 #ifdef META_DB 2740 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 2741 close_sql(m,0); 2742 #endif 2743 printDocument (m, doc, zGetpid ()); 2744 freeMaps (&m); 2745 free (m); 2746 if(zooRegistry!=NULL){ 2747 freeRegistry(&zooRegistry); 2748 free(zooRegistry); 2749 } 2750 free (REQUEST); 2751 free (SERVICE_URL); 2752 fflush (stdout); 2753 return 0; 2511 2754 } 2512 2513 if (int res = 2514 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 2515 printGetCapabilitiesForProcess) < 0) 2516 { 2517 freeMaps (&m); 2518 free (m); 2519 if(zooRegistry!=NULL){ 2520 freeRegistry(&zooRegistry); 2521 free(zooRegistry); 2755 else 2756 { 2757 r_inputs = getMap (request_inputs, "JobId"); 2758 if(reqId>nbReqIdentifier){ 2759 if (strncasecmp (REQUEST, "GetStatus", 9) == 0 || 2760 strncasecmp (REQUEST, "GetResult", 9) == 0){ 2761 runGetStatus(m,r_inputs->value,REQUEST); 2762 #ifdef RELY_ON_DB 2763 map* dsNb=getMapFromMaps(m,"lenv","ds_nb"); 2764 if(dsNb!=NULL && atoi(dsNb->value)>1) 2765 close_sql(m,1); 2766 close_sql(m,0); 2767 #endif 2768 2769 freeMaps (&m); 2770 free(m); 2771 if(zooRegistry!=NULL){ 2772 freeRegistry(&zooRegistry); 2773 free(zooRegistry); 2774 } 2775 free (REQUEST); 2776 free (SERVICE_URL); 2777 return 0; 2522 2778 } 2523 free (REQUEST); 2524 free (SERVICE_URL); 2525 fflush (stdout); 2526 return res; 2527 } 2528 fflush (stdout); 2529 zDup2 (saved_stdout, fileno (stdout)); 2779 else 2780 if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){ 2781 runDismiss(m,r_inputs->value); 2782 freeMaps (&m); 2783 free (m); 2784 if(zooRegistry!=NULL){ 2785 freeRegistry(&zooRegistry); 2786 free(zooRegistry); 2787 } 2788 free (REQUEST); 2789 free (SERVICE_URL); 2790 return 0; 2791 2792 } 2793 return 0; 2794 } 2795 if(reqId<=nbReqIdentifier){ 2796 r_inputs = getMap (request_inputs, "Identifier"); 2797 2798 struct dirent *dp; 2799 DIR *dirp = opendir (conf_dir); 2800 if (dirp == NULL) 2801 { 2802 errorException (m, _("The specified path does not exist."), 2803 "InternalError", NULL); 2804 freeMaps (&m); 2805 free (m); 2806 if(zooRegistry!=NULL){ 2807 freeRegistry(&zooRegistry); 2808 free(zooRegistry); 2809 } 2810 free (REQUEST); 2811 free (SERVICE_URL); 2812 return 0; 2813 } 2814 if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) 2815 { 2816 /** 2817 * Loop over Identifier list 2818 */ 2819 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 2820 r_inputs = NULL; 2821 r_inputs = getMap (request_inputs, "version"); 2822 #ifdef DEBUG 2823 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 2824 fflush(stderr); 2825 #endif 2826 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 2827 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); 2828 2829 r_inputs = getMap (request_inputs, "Identifier"); 2830 2831 fetchServicesForDescription(zooRegistry, m, r_inputs->value, 2832 printDescribeProcessForProcess, 2833 (void*) doc, (void*) n, conf_dir, 2834 request_inputs,printExceptionReportResponse); 2835 2836 printDocument (m, doc, zGetpid ()); 2837 freeMaps (&m); 2838 free (m); 2839 if(zooRegistry!=NULL){ 2840 freeRegistry(&zooRegistry); 2841 free(zooRegistry); 2842 } 2843 free (REQUEST); 2844 free (SERVICE_URL); 2845 fflush (stdout); 2530 2846 #ifdef META_DB 2531 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 2532 close_sql(m,0); 2533 #endif 2534 printDocument (m, doc, zGetpid ()); 2847 close_sql(m,0); 2848 //end_sql(); 2849 #endif 2850 return 0; 2851 } 2852 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 2853 { 2854 map* version=getMapFromMaps(m,"main","rversion"); 2855 int vid=getVersionId(version->value); 2856 int len = 0; 2857 int j = 0; 2858 for(j=0;j<nbSupportedRequests;j++){ 2859 if(requests[vid][j]!=NULL) 2860 len+=strlen(requests[vid][j])+2; 2861 else{ 2862 len+=4; 2863 break; 2864 } 2865 } 2866 char *tmpStr=(char*)malloc(len*sizeof(char)); 2867 int it=0; 2868 for(j=0;j<nbSupportedRequests;j++){ 2869 if(requests[vid][j]!=NULL){ 2870 if(it==0){ 2871 sprintf(tmpStr,"%s",requests[vid][j]); 2872 it++; 2873 }else{ 2874 char *tmpS=zStrdup(tmpStr); 2875 if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){ 2876 sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]); 2877 }else{ 2878 sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]); 2879 2880 } 2881 free(tmpS); 2882 } 2883 } 2884 else{ 2885 len+=4; 2886 break; 2887 } 2888 } 2889 char* message=(char*)malloc((61+len)*sizeof(char)); 2890 sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr); 2891 errorException (m,_(message),"InvalidParameterValue", "request"); 2892 #ifdef DEBUG 2893 fprintf (stderr, "No request found %s", REQUEST); 2894 #endif 2895 closedir (dirp); 2896 freeMaps (&m); 2897 free (m); 2898 if(zooRegistry!=NULL){ 2899 freeRegistry(&zooRegistry); 2900 free(zooRegistry); 2901 } 2902 free (REQUEST); 2903 free (SERVICE_URL); 2904 fflush (stdout); 2905 return 0; 2906 } 2907 closedir (dirp); 2908 } 2909 } 2910 2911 map *postRequest = NULL; 2912 postRequest = getMap (request_inputs, "xrequest"); 2913 2914 if(vid==1 && postRequest==NULL){ 2915 errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 2535 2916 freeMaps (&m); 2536 2917 free (m); … … 2544 2925 return 0; 2545 2926 } 2546 else 2547 { 2548 r_inputs = getMap (request_inputs, "JobId"); 2549 if(reqId>nbReqIdentifier){ 2550 if (strncasecmp (REQUEST, "GetStatus", 9) == 0 || 2551 strncasecmp (REQUEST, "GetResult", 9) == 0){ 2552 runGetStatus(m,r_inputs->value,REQUEST); 2553 #ifdef RELY_ON_DB 2554 map* dsNb=getMapFromMaps(m,"lenv","ds_nb"); 2555 if(dsNb!=NULL && atoi(dsNb->value)>1) 2556 close_sql(m,1); 2557 close_sql(m,0); 2558 #endif 2559 2927 s1 = NULL; 2928 2929 r_inputs = getMap (request_inputs, "Identifier"); 2930 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 2931 if (import != NULL && import->value != NULL) { 2932 strncpy(tmps1, import->value, 1024); 2933 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 2934 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 2935 } 2936 else { 2937 snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value); 2938 #ifdef DEBUG 2939 fprintf (stderr, "Trying to load %s\n", tmps1); 2940 #endif 2941 if (strstr (r_inputs->value, ".") != NULL) 2942 { 2943 char *identifier = zStrdup (r_inputs->value); 2944 parseIdentifier (m, conf_dir, identifier, tmps1); 2945 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 2946 if (tmpMap != NULL) 2947 addToMap (request_inputs, "metapath", tmpMap->value); 2948 free (identifier); 2949 } 2950 else 2951 { 2952 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 2953 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 2954 } 2955 } 2956 2957 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 2958 2959 #ifdef META_DB 2960 int metadb_id=_init_sql(m,"metadb"); 2961 //FAILED CONNECTING DB 2962 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 2963 fprintf(stderr,"ERROR CONNECTING METADB\n"); 2964 } 2965 if(metadb_id>=0) 2966 s1=extractServiceFromDb(m,r_inputs->value,0); 2967 //close_sql(m,0); 2968 if(s1!=NULL){ 2969 inheritance(zooRegistry,&s1); 2970 #ifdef USE_HPC 2971 addNestedOutputs(&s1); 2972 #endif 2973 if(zooRegistry!=NULL){ 2974 freeRegistry(&zooRegistry); 2975 free(zooRegistry); 2976 } 2977 }else /* Not found in MetaDB */{ 2978 #endif 2979 s1 = createService(); 2980 if (s1 == NULL) 2981 { 2560 2982 freeMaps (&m); 2561 free (m);2983 free (m); 2562 2984 if(zooRegistry!=NULL){ 2563 2985 freeRegistry(&zooRegistry); … … 2566 2988 free (REQUEST); 2567 2989 free (SERVICE_URL); 2990 return errorException (m, _("Unable to allocate memory"), 2991 "InternalError", NULL); 2992 } 2993 2994 int saved_stdout = zDup (fileno (stdout)); 2995 zDup2 (fileno (stderr), fileno (stdout)); 2996 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 2997 if(t>=0){ 2998 inheritance(zooRegistry,&s1); 2999 #ifdef USE_HPC 3000 addNestedOutputs(&s1); 3001 #endif 3002 } 3003 if(zooRegistry!=NULL){ 3004 freeRegistry(&zooRegistry); 3005 free(zooRegistry); 3006 } 3007 fflush (stdout); 3008 zDup2 (saved_stdout, fileno (stdout)); 3009 if (t < 0) 3010 { 3011 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 3012 sprintf (tmpMsg, 3013 _ 3014 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 3015 r_inputs->value); 3016 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 3017 free (tmpMsg); 3018 free (s1); 3019 freeMaps (&m); 3020 free (m); 3021 free (REQUEST); 3022 free (SERVICE_URL); 2568 3023 return 0; 2569 3024 } 2570 else 2571 if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){ 2572 runDismiss(m,r_inputs->value); 3025 zClose (saved_stdout); 3026 #ifdef META_DB 3027 } 3028 #endif 3029 3030 #ifdef DEBUG 3031 dumpService (s1); 3032 #endif 3033 int j; 3034 3035 3036 /** 3037 * Create the input and output maps data structure 3038 */ 3039 int i = 0; 3040 HINTERNET res; 3041 hInternet = InternetOpen ( 3042 #ifndef WIN32 3043 (LPCTSTR) 3044 #endif 3045 "ZooWPSClient\0", 3046 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 3047 3048 #ifndef WIN32 3049 if (!CHECK_INET_HANDLE (hInternet)) 3050 fprintf (stderr, "WARNING : hInternet handle failed to initialize"); 3051 #endif 3052 maps *tmpmaps = request_input_real_format; 3053 3054 if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){ 3055 freeMaps (&m); 3056 free (m); 3057 free (REQUEST); 3058 free (SERVICE_URL); 3059 InternetCloseHandle (&hInternet); 3060 freeService (&s1); 3061 free (s1); 3062 return 0; 3063 } 3064 //InternetCloseHandle (&hInternet); 3065 3066 initAllEnvironment(m,request_inputs,ntmp,"xrequest"); 3067 3068 3069 #ifdef DEBUG 3070 dumpMap (request_inputs); 3071 #endif 3072 3073 map *status = getMap (request_inputs, "status"); 3074 if(vid==0){ 3075 // Need to check if we need to fork to load a status enabled 3076 r_inputs = NULL; 3077 map *store = getMap (request_inputs, "storeExecuteResponse"); 3078 /** 3079 * 05-007r7 WPS 1.0.0 page 57 : 3080 * 'If status="true" and storeExecuteResponse is "false" then the service 3081 * shall raise an exception.' 3082 */ 3083 if (status != NULL && strcmp (status->value, "true") == 0 && 3084 store != NULL && strcmp (store->value, "false") == 0) 3085 { 3086 errorException (m, 3087 _ 3088 ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."), 3089 "InvalidParameterValue", "storeExecuteResponse"); 3090 freeService (&s1); 3091 free (s1); 3092 freeMaps (&m); 3093 free (m); 3094 3095 freeMaps (&request_input_real_format); 3096 free (request_input_real_format); 3097 3098 freeMaps (&request_output_real_format); 3099 free (request_output_real_format); 3100 3101 free (REQUEST); 3102 free (SERVICE_URL); 3103 return 1; 3104 } 3105 r_inputs = getMap (request_inputs, "storeExecuteResponse"); 3106 }else{ 3107 // Define status depending on the WPS 2.0.0 mode attribute 3108 status = getMap (request_inputs, "mode"); 3109 map* mode=getMap(s1->content,"mode"); 3110 if(strcasecmp(status->value,"async")==0){ 3111 if(mode!=NULL && strcasecmp(mode->value,"async")==0) 3112 addToMap(request_inputs,"status","true"); 3113 else{ 3114 if(mode!=NULL){ 3115 // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61 3116 errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 3117 fflush (stdout); 2573 3118 freeMaps (&m); 2574 3119 free (m); … … 2577 3122 free(zooRegistry); 2578 3123 } 3124 freeMaps (&request_input_real_format); 3125 free (request_input_real_format); 3126 freeMaps (&request_output_real_format); 3127 free (request_output_real_format); 2579 3128 free (REQUEST); 2580 3129 free (SERVICE_URL); 2581 3130 return 0; 2582 3131 }else 3132 addToMap(request_inputs,"status","true"); 3133 } 3134 } 3135 else{ 3136 if(strcasecmp(status->value,"auto")==0){ 3137 if(mode!=NULL){ 3138 if(strcasecmp(mode->value,"async")==0) 3139 addToMap(request_inputs,"status","false"); 3140 else 3141 addToMap(request_inputs,"status","true"); 2583 3142 } 2584 return 0; 3143 else 3144 addToMap(request_inputs,"status","false"); 3145 }else 3146 addToMap(request_inputs,"status","false"); 2585 3147 } 2586 if(reqId<=nbReqIdentifier){ 2587 r_inputs = getMap (request_inputs, "Identifier"); 2588 2589 struct dirent *dp; 2590 DIR *dirp = opendir (conf_dir); 2591 if (dirp == NULL) 2592 { 2593 errorException (m, _("The specified path does not exist."), 2594 "InternalError", NULL); 2595 freeMaps (&m); 2596 free (m); 2597 if(zooRegistry!=NULL){ 2598 freeRegistry(&zooRegistry); 2599 free(zooRegistry); 2600 } 2601 free (REQUEST); 2602 free (SERVICE_URL); 2603 return 0; 2604 } 2605 if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0) 2606 { 2607 /** 2608 * Loop over Identifier list 2609 */ 2610 xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); 2611 r_inputs = NULL; 2612 r_inputs = getMap (request_inputs, "version"); 2613 #ifdef DEBUG 2614 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 2615 fflush(stderr); 2616 #endif 2617 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 2618 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); 2619 2620 r_inputs = getMap (request_inputs, "Identifier"); 2621 2622 fetchServicesForDescription(zooRegistry, m, r_inputs->value, 2623 printDescribeProcessForProcess, 2624 (void*) doc, (void*) n, conf_dir, 2625 request_inputs,printExceptionReportResponse); 2626 2627 printDocument (m, doc, zGetpid ()); 2628 freeMaps (&m); 2629 free (m); 2630 if(zooRegistry!=NULL){ 2631 freeRegistry(&zooRegistry); 2632 free(zooRegistry); 2633 } 2634 free (REQUEST); 2635 free (SERVICE_URL); 2636 fflush (stdout); 2637 #ifdef META_DB 2638 close_sql(m,0); 2639 //end_sql(); 2640 #endif 2641 return 0; 2642 } 2643 else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0) 2644 { 2645 map* version=getMapFromMaps(m,"main","rversion"); 2646 int vid=getVersionId(version->value); 2647 int len = 0; 2648 int j = 0; 2649 for(j=0;j<nbSupportedRequests;j++){ 2650 if(requests[vid][j]!=NULL) 2651 len+=strlen(requests[vid][j])+2; 2652 else{ 2653 len+=4; 2654 break; 2655 } 2656 } 2657 char *tmpStr=(char*)malloc(len*sizeof(char)); 2658 int it=0; 2659 for(j=0;j<nbSupportedRequests;j++){ 2660 if(requests[vid][j]!=NULL){ 2661 if(it==0){ 2662 sprintf(tmpStr,"%s",requests[vid][j]); 2663 it++; 2664 }else{ 2665 char *tmpS=zStrdup(tmpStr); 2666 if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){ 2667 sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]); 2668 }else{ 2669 sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]); 2670 2671 } 2672 free(tmpS); 2673 } 2674 } 2675 else{ 2676 len+=4; 2677 break; 2678 } 2679 } 2680 char* message=(char*)malloc((61+len)*sizeof(char)); 2681 sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr); 2682 errorException (m,_(message),"InvalidParameterValue", "request"); 2683 #ifdef DEBUG 2684 fprintf (stderr, "No request found %s", REQUEST); 2685 #endif 2686 closedir (dirp); 2687 freeMaps (&m); 2688 free (m); 2689 if(zooRegistry!=NULL){ 2690 freeRegistry(&zooRegistry); 2691 free(zooRegistry); 2692 } 2693 free (REQUEST); 2694 free (SERVICE_URL); 2695 fflush (stdout); 2696 return 0; 2697 } 2698 closedir (dirp); 2699 } 2700 } 2701 2702 map *postRequest = NULL; 2703 postRequest = getMap (request_inputs, "xrequest"); 2704 2705 if(vid==1 && postRequest==NULL){ 2706 errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 2707 freeMaps (&m); 2708 free (m); 2709 if(zooRegistry!=NULL){ 2710 freeRegistry(&zooRegistry); 2711 free(zooRegistry); 2712 } 2713 free (REQUEST); 2714 free (SERVICE_URL); 2715 fflush (stdout); 2716 return 0; 2717 } 2718 s1 = NULL; 2719 2720 r_inputs = getMap (request_inputs, "Identifier"); 2721 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 2722 if (import != NULL && import->value != NULL) { 2723 strncpy(tmps1, import->value, 1024); 2724 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 2725 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 2726 } 2727 else { 2728 snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value); 2729 #ifdef DEBUG 2730 fprintf (stderr, "Trying to load %s\n", tmps1); 2731 #endif 2732 if (strstr (r_inputs->value, ".") != NULL) 3148 status = getMap (request_inputs, "status"); 3149 } 3150 3151 if (status != NULL) 3152 if (strcasecmp (status->value, "false") == 0) 3153 status = NULLMAP; 3154 if (status == NULLMAP) 2733 3155 { 2734 char *identifier = zStrdup (r_inputs->value); 2735 parseIdentifier (m, conf_dir, identifier, tmps1); 2736 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 2737 if (tmpMap != NULL) 2738 addToMap (request_inputs, "metapath", tmpMap->value); 2739 free (identifier); 2740 } 2741 else 2742 { 2743 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 2744 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 2745 } 2746 } 2747 2748 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 2749 2750 #ifdef META_DB 2751 int metadb_id=_init_sql(m,"metadb"); 2752 //FAILED CONNECTING DB 2753 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 2754 fprintf(stderr,"ERROR CONNECTING METADB\n"); 2755 } 2756 if(metadb_id>=0) 2757 s1=extractServiceFromDb(m,r_inputs->value,0); 2758 //close_sql(m,0); 2759 if(s1!=NULL){ 2760 inheritance(zooRegistry,&s1); 2761 #ifdef USE_HPC 2762 addNestedOutputs(&s1); 2763 #endif 2764 if(zooRegistry!=NULL){ 2765 freeRegistry(&zooRegistry); 2766 free(zooRegistry); 2767 } 2768 }else /* Not found in MetaDB */{ 2769 #endif 2770 s1 = createService(); 2771 if (s1 == NULL) 2772 { 2773 freeMaps (&m); 2774 free (m); 2775 if(zooRegistry!=NULL){ 2776 freeRegistry(&zooRegistry); 2777 free(zooRegistry); 2778 } 2779 free (REQUEST); 2780 free (SERVICE_URL); 2781 return errorException (m, _("Unable to allocate memory"), 2782 "InternalError", NULL); 2783 } 2784 2785 int saved_stdout = zDup (fileno (stdout)); 2786 zDup2 (fileno (stderr), fileno (stdout)); 2787 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 2788 if(t>=0){ 2789 inheritance(zooRegistry,&s1); 2790 #ifdef USE_HPC 2791 addNestedOutputs(&s1); 2792 #endif 2793 } 2794 if(zooRegistry!=NULL){ 2795 freeRegistry(&zooRegistry); 2796 free(zooRegistry); 2797 } 2798 fflush (stdout); 2799 zDup2 (saved_stdout, fileno (stdout)); 2800 if (t < 0) 2801 { 2802 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 2803 sprintf (tmpMsg, 2804 _ 2805 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 2806 r_inputs->value); 2807 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 2808 free (tmpMsg); 2809 free (s1); 2810 freeMaps (&m); 2811 free (m); 2812 free (REQUEST); 2813 free (SERVICE_URL); 2814 return 0; 2815 } 2816 zClose (saved_stdout); 2817 #ifdef META_DB 2818 } 2819 #endif 2820 2821 #ifdef DEBUG 2822 dumpService (s1); 2823 #endif 2824 int j; 2825 2826 2827 /** 2828 * Create the input and output maps data structure 2829 */ 2830 int i = 0; 2831 HINTERNET hInternet; 2832 HINTERNET res; 2833 hInternet = InternetOpen ( 2834 #ifndef WIN32 2835 (LPCTSTR) 2836 #endif 2837 "ZooWPSClient\0", 2838 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 2839 2840 #ifndef WIN32 2841 if (!CHECK_INET_HANDLE (hInternet)) 2842 fprintf (stderr, "WARNING : hInternet handle failed to initialize"); 2843 #endif 2844 maps *request_input_real_format = NULL; 2845 maps *tmpmaps = request_input_real_format; 2846 2847 if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){ 2848 freeMaps (&m); 2849 free (m); 2850 free (REQUEST); 2851 free (SERVICE_URL); 2852 InternetCloseHandle (&hInternet); 2853 freeService (&s1); 2854 free (s1); 2855 return 0; 2856 } 2857 //InternetCloseHandle (&hInternet); 2858 2859 initAllEnvironment(m,request_inputs,ntmp,"xrequest"); 2860 2861 2862 #ifdef DEBUG 2863 dumpMap (request_inputs); 2864 #endif 2865 2866 map *status = getMap (request_inputs, "status"); 2867 if(vid==0){ 2868 // Need to check if we need to fork to load a status enabled 2869 r_inputs = NULL; 2870 map *store = getMap (request_inputs, "storeExecuteResponse"); 2871 /** 2872 * 05-007r7 WPS 1.0.0 page 57 : 2873 * 'If status="true" and storeExecuteResponse is "false" then the service 2874 * shall raise an exception.' 2875 */ 2876 if (status != NULL && strcmp (status->value, "true") == 0 && 2877 store != NULL && strcmp (store->value, "false") == 0) 2878 { 2879 errorException (m, 2880 _ 2881 ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."), 2882 "InvalidParameterValue", "storeExecuteResponse"); 2883 freeService (&s1); 2884 free (s1); 2885 freeMaps (&m); 2886 free (m); 2887 2888 freeMaps (&request_input_real_format); 2889 free (request_input_real_format); 2890 2891 freeMaps (&request_output_real_format); 2892 free (request_output_real_format); 2893 2894 free (REQUEST); 2895 free (SERVICE_URL); 2896 return 1; 2897 } 2898 r_inputs = getMap (request_inputs, "storeExecuteResponse"); 2899 }else{ 2900 // Define status depending on the WPS 2.0.0 mode attribute 2901 status = getMap (request_inputs, "mode"); 2902 map* mode=getMap(s1->content,"mode"); 2903 if(strcasecmp(status->value,"async")==0){ 2904 if(mode!=NULL && strcasecmp(mode->value,"async")==0) 2905 addToMap(request_inputs,"status","true"); 2906 else{ 2907 if(mode!=NULL){ 2908 // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61 2909 errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value); 2910 fflush (stdout); 3156 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 3157 freeService (&s1); 3158 free (s1); 2911 3159 freeMaps (&m); 2912 3160 free (m); 2913 if(zooRegistry!=NULL){ 2914 freeRegistry(&zooRegistry); 2915 free(zooRegistry); 2916 } 3161 free (REQUEST); 3162 free (SERVICE_URL); 2917 3163 freeMaps (&request_input_real_format); 2918 3164 free (request_input_real_format); 2919 3165 freeMaps (&request_output_real_format); 2920 3166 free (request_output_real_format); 2921 free (REQUEST); 2922 free (SERVICE_URL); 2923 return 0; 2924 }else 2925 addToMap(request_inputs,"status","true"); 3167 freeMaps (&tmpmaps); 3168 free (tmpmaps); 3169 return -1; 3170 } 3171 map* testMap=getMapFromMaps(m,"main","memory"); 3172 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 3173 dumpMapsValuesToFiles(&m,&request_input_real_format); 3174 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 3175 &request_output_real_format, &eres); 3176 3177 #ifdef META_DB 3178 close_sql(m,0); 3179 #endif 2926 3180 } 2927 } 2928 else{ 2929 if(strcasecmp(status->value,"auto")==0){ 2930 if(mode!=NULL){ 2931 if(strcasecmp(mode->value,"async")==0) 2932 addToMap(request_inputs,"status","false"); 2933 else 2934 addToMap(request_inputs,"status","true"); 2935 } 3181 else 3182 { 3183 int pid; 3184 #ifdef DEBUG 3185 fprintf (stderr, "\nPID : %d\n", cpid); 3186 #endif 3187 #ifndef WIN32 3188 pid = fork (); 3189 #else 3190 if (cgiSid == NULL) 3191 { 3192 createProcess (m, request_inputs, s1, NULL, cpid, 3193 request_input_real_format, 3194 request_output_real_format); 3195 pid = cpid; 3196 } 2936 3197 else 2937 addToMap(request_inputs,"status","false"); 2938 }else 2939 addToMap(request_inputs,"status","false"); 2940 } 2941 status = getMap (request_inputs, "status"); 2942 } 2943 2944 int eres = SERVICE_STARTED; 2945 int cpid = zGetpid (); 2946 2947 maps* bmap=NULL; 2948 char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog; 2949 FILE *f0, *f1; 2950 if (status != NULL) 2951 if (strcasecmp (status->value, "false") == 0) 2952 status = NULLMAP; 2953 if (status == NULLMAP) 2954 { 2955 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2956 freeService (&s1); 2957 free (s1); 2958 freeMaps (&m); 2959 free (m); 2960 free (REQUEST); 2961 free (SERVICE_URL); 2962 freeMaps (&request_input_real_format); 2963 free (request_input_real_format); 2964 freeMaps (&request_output_real_format); 2965 free (request_output_real_format); 2966 freeMaps (&tmpmaps); 2967 free (tmpmaps); 2968 return -1; 2969 } 2970 map* testMap=getMapFromMaps(m,"main","memory"); 2971 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 2972 dumpMapsValuesToFiles(&m,&request_input_real_format); 2973 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2974 &request_output_real_format, &eres); 2975 2976 #ifdef META_DB 2977 close_sql(m,0); 2978 #endif 2979 } 2980 else 2981 { 2982 int pid; 2983 #ifdef DEBUG 2984 fprintf (stderr, "\nPID : %d\n", cpid); 2985 #endif 3198 { 3199 pid = 0; 3200 cpid = atoi (cgiSid); 3201 updateStatus(m,0,_("Initializing")); 3202 } 3203 #endif 3204 if (pid > 0) 3205 { 3206 // 3207 // dady : 3208 // set status to SERVICE_ACCEPTED 3209 // 3210 #ifdef DEBUG 3211 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 3212 zGetpid ()); 3213 #endif 3214 eres = SERVICE_ACCEPTED; 3215 } 3216 else if (pid == 0) 3217 { 3218 eres = SERVICE_ACCEPTED; 3219 // 3220 // son : have to close the stdout, stdin and stderr to let the parent 3221 // process answer to http client. 3222 // 3223 map* usid = getMapFromMaps (m, "lenv", "uusid"); 3224 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 3225 int cpid = atoi (tmpm->value); 3226 pid=cpid; 3227 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 3228 setMapInMaps (m, "lenv", "async","true"); 3229 map* r_inputs1 = createMap("ServiceName", s1->name); 3230 3231 // Create the filename for the result file (.res) 3232 fbkpres = 3233 (char *) 3234 malloc ((strlen (r_inputs->value) + 3235 strlen (usid->value) + 7) * sizeof (char)); 3236 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 3237 bmap = createMaps("status"); 3238 bmap->content=createMap("usid",usid->value); 3239 addToMap(bmap->content,"sid",tmpm->value); 3240 addIntToMap(bmap->content,"pid",zGetpid()); 3241 3242 // Create PID file referencing the OS process identifier 3243 fbkpid = 3244 (char *) 3245 malloc ((strlen (r_inputs->value) + 3246 strlen (usid->value) + 7) * sizeof (char)); 3247 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 3248 setMapInMaps (m, "lenv", "file.pid", fbkpid); 3249 3250 f0 = freopen (fbkpid, "w+",stdout); 3251 printf("%d",zGetpid()); 3252 fflush(stdout); 3253 3254 // Create SID file referencing the semaphore name 3255 fbkp = 3256 (char *) 3257 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3258 strlen (usid->value) + 7) * sizeof (char)); 3259 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 3260 setMapInMaps (m, "lenv", "file.sid", fbkp); 3261 FILE* f2 = freopen (fbkp, "w+",stdout); 3262 printf("%s",tmpm->value); 3263 fflush(f2); 3264 free(fbkp); 3265 3266 fbkp = 3267 (char *) 3268 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3269 strlen (usid->value) + 7) * sizeof (char)); 3270 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 3271 usid->value); 3272 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 3273 flog = 3274 (char *) 3275 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3276 strlen (usid->value) + 13) * sizeof (char)); 3277 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 3278 r_inputs1->value, usid->value); 3279 setMapInMaps (m, "lenv", "file.log", flog); 3280 #ifdef DEBUG 3281 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 3282 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 3283 zGetpid ()); 3284 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 3285 #endif 3286 freopen (flog, "w+", stderr); 3287 fflush (stderr); 3288 f0 = freopen (fbkp, "w+", stdout); 3289 rewind (stdout); 2986 3290 #ifndef WIN32 2987 pid = fork (); 3291 fclose (stdin); 3292 #endif 3293 #ifdef RELY_ON_DB 3294 init_sql(m); 3295 recordServiceStatus(m); 3296 #endif 3297 #ifdef USE_CALLBACK 3298 invokeCallback(m,NULL,NULL,0,0); 3299 #endif 3300 if(vid==0){ 3301 // 3302 // set status to SERVICE_STARTED and flush stdout to ensure full 3303 // content was outputed (the file used to store the ResponseDocument). 3304 // Then, rewind stdout to restart writing from the begining of the file. 3305 // This way, the data will be updated at the end of the process run. 3306 // 3307 printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, 3308 SERVICE_STARTED, request_input_real_format, 3309 request_output_real_format); 3310 fflush (stdout); 3311 #ifdef RELY_ON_DB 3312 recordResponse(m,fbkp); 3313 #endif 3314 } 3315 3316 fflush (stderr); 3317 3318 fbkp1 = 3319 (char *) 3320 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3321 strlen (usid->value) + 13) * sizeof (char)); 3322 sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, 3323 r_inputs1->value, usid->value); 3324 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 3325 3326 f1 = freopen (fbkp1, "w+", stdout); 3327 3328 map* serviceTypeMap=getMap(s1->content,"serviceType"); 3329 if(serviceTypeMap!=NULL) 3330 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 3331 3332 char *flenv = 3333 (char *) 3334 malloc ((strlen (r_inputs->value) + 3335 strlen (usid->value) + 12) * sizeof (char)); 3336 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 3337 maps* lenvMaps=getMaps(m,"lenv"); 3338 dumpMapsToFile(lenvMaps,flenv,0); 3339 free(flenv); 3340 3341 #ifdef USE_CALLBACK 3342 invokeCallback(m,request_input_real_format,NULL,1,0); 3343 #endif 3344 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 3345 freeService (&s1); 3346 free (s1); 3347 fflush (stdout); 3348 fflush (stderr); 3349 fclose (f0); 3350 fclose (f1); 3351 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 3352 return -1; 3353 #ifndef RELY_ON_DB 3354 dumpMapsToFile(bmap,fbkpres,1); 3355 removeShmLock (m, 1); 2988 3356 #else 2989 if (cgiSid == NULL) 2990 { 2991 createProcess (m, request_inputs, s1, NULL, cpid, 2992 request_input_real_format, 2993 request_output_real_format); 2994 pid = cpid; 2995 } 2996 else 2997 { 2998 pid = 0; 2999 cpid = atoi (cgiSid); 3000 updateStatus(m,0,_("Initializing")); 3001 } 3002 #endif 3003 if (pid > 0) 3004 { 3005 // 3006 // dady : 3007 // set status to SERVICE_ACCEPTED 3008 // 3009 #ifdef DEBUG 3010 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 3011 zGetpid ()); 3012 #endif 3013 eres = SERVICE_ACCEPTED; 3014 } 3015 else if (pid == 0) 3016 { 3017 eres = SERVICE_ACCEPTED; 3018 // 3019 // son : have to close the stdout, stdin and stderr to let the parent 3020 // process answer to http client. 3021 // 3022 map* usid = getMapFromMaps (m, "lenv", "uusid"); 3023 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 3024 int cpid = atoi (tmpm->value); 3025 pid=cpid; 3026 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 3027 setMapInMaps (m, "lenv", "async","true"); 3028 map* r_inputs1 = createMap("ServiceName", s1->name); 3029 3030 // Create the filename for the result file (.res) 3031 fbkpres = 3032 (char *) 3033 malloc ((strlen (r_inputs->value) + 3034 strlen (usid->value) + 7) * sizeof (char)); 3035 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 3036 bmap = createMaps("status"); 3037 bmap->content=createMap("usid",usid->value); 3038 addToMap(bmap->content,"sid",tmpm->value); 3039 addIntToMap(bmap->content,"pid",zGetpid()); 3040 3041 // Create PID file referencing the OS process identifier 3042 fbkpid = 3043 (char *) 3044 malloc ((strlen (r_inputs->value) + 3045 strlen (usid->value) + 7) * sizeof (char)); 3046 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 3047 setMapInMaps (m, "lenv", "file.pid", fbkpid); 3048 3049 f0 = freopen (fbkpid, "w+",stdout); 3050 printf("%d",zGetpid()); 3051 fflush(stdout); 3052 3053 // Create SID file referencing the semaphore name 3054 fbkp = 3055 (char *) 3056 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3057 strlen (usid->value) + 7) * sizeof (char)); 3058 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 3059 setMapInMaps (m, "lenv", "file.sid", fbkp); 3060 FILE* f2 = freopen (fbkp, "w+",stdout); 3061 printf("%s",tmpm->value); 3062 fflush(f2); 3063 free(fbkp); 3064 3065 fbkp = 3066 (char *) 3067 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3068 strlen (usid->value) + 7) * sizeof (char)); 3069 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 3070 usid->value); 3071 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 3072 flog = 3073 (char *) 3074 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3075 strlen (usid->value) + 13) * sizeof (char)); 3076 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 3077 r_inputs1->value, usid->value); 3078 setMapInMaps (m, "lenv", "file.log", flog); 3079 #ifdef DEBUG 3080 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 3081 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 3082 zGetpid ()); 3083 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 3084 #endif 3085 freopen (flog, "w+", stderr); 3086 fflush (stderr); 3087 f0 = freopen (fbkp, "w+", stdout); 3088 rewind (stdout); 3089 #ifndef WIN32 3090 fclose (stdin); 3091 #endif 3092 #ifdef RELY_ON_DB 3093 init_sql(m); 3094 recordServiceStatus(m); 3095 #endif 3357 recordResponse(m,fbkp1); 3096 3358 #ifdef USE_CALLBACK 3097 invokeCallback(m,NULL,NULL,0,0); 3098 #endif 3099 if(vid==0){ 3100 // 3101 // set status to SERVICE_STARTED and flush stdout to ensure full 3102 // content was outputed (the file used to store the ResponseDocument). 3103 // Then, rewind stdout to restart writing from the begining of the file. 3104 // This way, the data will be updated at the end of the process run. 3105 // 3106 printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, 3107 SERVICE_STARTED, request_input_real_format, 3108 request_output_real_format); 3109 fflush (stdout); 3110 #ifdef RELY_ON_DB 3111 recordResponse(m,fbkp); 3112 #endif 3113 } 3114 3115 fflush (stderr); 3116 3117 fbkp1 = 3118 (char *) 3119 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 3120 strlen (usid->value) + 13) * sizeof (char)); 3121 sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, 3122 r_inputs1->value, usid->value); 3123 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 3124 3125 f1 = freopen (fbkp1, "w+", stdout); 3126 3127 map* serviceTypeMap=getMap(s1->content,"serviceType"); 3128 if(serviceTypeMap!=NULL) 3129 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 3130 3131 char *flenv = 3132 (char *) 3133 malloc ((strlen (r_inputs->value) + 3134 strlen (usid->value) + 12) * sizeof (char)); 3135 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 3136 maps* lenvMaps=getMaps(m,"lenv"); 3137 dumpMapsToFile(lenvMaps,flenv,0); 3138 free(flenv); 3139 3140 #ifdef USE_CALLBACK 3141 invokeCallback(m,request_input_real_format,NULL,1,0); 3142 #endif 3143 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 3144 freeService (&s1); 3145 free (s1); 3146 fflush (stdout); 3147 fflush (stderr); 3148 fclose (f0); 3149 fclose (f1); 3150 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 3151 return -1; 3152 #ifndef RELY_ON_DB 3153 dumpMapsToFile(bmap,fbkpres,1); 3154 removeShmLock (m, 1); 3155 #else 3156 recordResponse(m,fbkp1); 3157 #ifdef USE_CALLBACK 3158 invokeCallback(m,NULL,NULL,7,0); 3159 #endif 3160 #endif 3161 zUnlink (fbkpid); 3162 unhandleStatus (m); 3359 invokeCallback(m,NULL,NULL,7,0); 3360 #endif 3361 #endif 3362 zUnlink (fbkpid); 3363 unhandleStatus (m); 3163 3364 #ifdef RELY_ON_DB 3164 3365 #ifdef META_DB 3165 cleanupCallbackThreads(); 3166 close_sql(m,1); 3167 #endif 3168 close_sql(m,0); 3169 #endif 3170 freeMaps (&m); 3171 free (m); 3172 free (REQUEST); 3173 free (SERVICE_URL); 3174 freeMaps (&request_input_real_format); 3175 free (request_input_real_format); 3176 freeMaps (&request_output_real_format); 3177 free (request_output_real_format); 3178 freeMaps (&tmpmaps); 3179 free (tmpmaps); 3180 return -1; 3366 cleanupCallbackThreads(); 3367 close_sql(m,1); 3368 #endif 3369 close_sql(m,0); 3370 #endif 3371 freeMaps (&m); 3372 free (m); 3373 free (REQUEST); 3374 free (SERVICE_URL); 3375 freeMaps (&request_input_real_format); 3376 free (request_input_real_format); 3377 freeMaps (&request_output_real_format); 3378 free (request_output_real_format); 3379 freeMaps (&tmpmaps); 3380 free (tmpmaps); 3381 return -1; 3382 } 3383 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 3384 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 3385 #ifdef USE_CALLBACK 3386 invokeCallback(m,NULL,NULL,7,0); 3387 #endif 3388 eres=-1;//SERVICE_FAILED; 3389 }else{ 3390 map* testMap=getMapFromMaps(m,"main","memory"); 3391 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 3392 dumpMapsValuesToFiles(&m,&request_input_real_format); 3393 loadServiceAndRun (&m, s1, request_inputs, 3394 &request_input_real_format, 3395 &request_output_real_format, &eres); 3396 } 3181 3397 } 3182 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 3183 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 3184 #ifdef USE_CALLBACK 3185 invokeCallback(m,NULL,NULL,7,0); 3186 #endif 3187 eres=-1;//SERVICE_FAILED; 3188 }else{ 3189 map* testMap=getMapFromMaps(m,"main","memory"); 3190 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 3191 dumpMapsValuesToFiles(&m,&request_input_real_format); 3192 loadServiceAndRun (&m, s1, request_inputs, 3193 &request_input_real_format, 3194 &request_output_real_format, &eres); 3398 else 3399 { 3400 /** 3401 * error server don't accept the process need to output a valid 3402 * error response here !!! 3403 */ 3404 eres = -1; 3405 errorException (m, _("Unable to run the child process properly"), 3406 "InternalError", NULL); 3195 3407 } 3196 } 3197 else 3198 { 3199 /** 3200 * error server don't accept the process need to output a valid 3201 * error response here !!! 3202 */ 3203 eres = -1; 3204 errorException (m, _("Unable to run the child process properly"), 3205 "InternalError", NULL); 3206 } 3207 } 3408 } 3208 3409 3209 3410 #ifdef DEBUG 3210 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 3211 dumpMaps (request_output_real_format); 3212 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 3213 #endif 3214 fflush(stdout); 3215 rewind(stdout); 3216 3217 //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); 3218 if (eres != -1) 3219 outputResponse (s1, request_input_real_format, 3220 request_output_real_format, request_inputs, 3221 cpid, m, eres); 3222 fflush (stdout); 3223 3411 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 3412 dumpMaps (request_output_real_format); 3413 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 3414 #endif 3415 fflush(stdout); 3416 rewind(stdout); 3417 3418 if (eres != -1) 3419 outputResponse (s1, request_input_real_format, 3420 request_output_real_format, request_inputs, 3421 cpid, m, eres); 3422 fflush (stdout); 3423 } 3224 3424 /** 3225 3425 * Ensure that if error occurs when freeing memory, no signal will return … … 3248 3448 3249 3449 fclose (f0); 3450 3250 3451 fclose (f1); 3251 3452 … … 3278 3479 zUnlink (fbkp1); 3279 3480 unhandleStatus (m); 3481 #if defined(USE_JSON) || defined(USE_CALLBACK) 3482 cleanupCallbackThreads(); 3483 #endif 3484 3280 3485 #ifdef RELY_ON_DB 3281 3486 #ifdef META_DB 3282 cleanupCallbackThreads();3283 3487 close_sql(m,1); 3284 3488 #endif … … 3287 3491 #endif 3288 3492 free(fbkpid); 3289 free(fbkpres); 3493 free(fbkpres); 3290 3494 free (fbkp1); 3291 3495 if(cgiSid!=NULL) 3292 3496 free(cgiSid); 3293 InternetCloseHandle (&hInternet); 3497 map* tMap=getMapFromMaps(m,"lenv","executionType"); 3498 if(tMap!=NULL && strncasecmp(tMap->value,"xml",3)==0) 3499 InternetCloseHandle (&hInternet); 3294 3500 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 3295 3501 fflush(stderr);
Note: See TracChangeset
for help on using the changeset viewer.