Changeset 962 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Oct 21, 2020, 6:31:09 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.