Changeset 917 for trunk/zoo-project
- Timestamp:
- May 7, 2019, 2:17:08 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 59 edited
- 20 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk ¶ ¶
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
TabularUnified trunk/zoo-project/HISTORY.txt ¶ ¶
r828 r917 1 1 Version 1.7.0-dev 2 * Fix issue with UOM definitions in zcfg2sql 3 * Make callback and HPC support independent from each other 4 * Update SAGA-GIS support to version 7.2.0 5 * Add support for custom MapServer style definition for raster output 6 * Fix returned bbox definition #170 7 * Store semaphore status in lenv section for future deletion 8 * Update Windows support to newer compiler 9 * Fix issue with UpdateStatus function from the Mono ZOO-API 10 * Add logging functionality and other utility functions to the C-API 11 * Return an exception for every output for which nb_pixel or 12 nb_features is 0 13 * Add a shared key to the security section to differentiate the 14 referenced data 15 * Add MapServer output style definition depending on the geometry 16 type 17 * Add ogr.tindex service 18 * Add support for literaldata input arrays and to call services 19 asyncrhonously from the JavaScript ZOO-API 20 * Expose a sleep function to the JavaScript ZOO-API 21 * Provide FinalizeHPC and FinalizeHPC1 services using scontrol and 22 sacct respectively 23 * Store md5sum of the cached file (so, local to the WPS server) to 24 compare before uploading (if different md5sum) on the HPC server 25 * Add support for R language 26 * Add support for using "file://" for referenced data input 27 * Add an optional ecookie key for returning third-party cookies 28 * Fix issue when parsing BoundingBox input #163 29 * Add memory key to the main section to force the ZOO-Kernel to load 30 data into memory or use local file 31 * Add the dialect input to the ogr2ogr service 32 * Store the list of generated mapfiles in a file (cf DeleteData service) 33 * Define the correct MS_IMAGEMODE in the generated mapfile 34 * Option to use MapServer support to publish heatmap 35 * Add status_code key to the lenv for setting Status HTTP response header 36 * Add the Creation Option inputs to the Gdal_Dem service 37 * Add prohibited key in the callback section to define a list of 38 services not requiring any invocation 39 * Produce zcfg for OTB applications using the correct default pixel type 40 * Add asynchronous callback invocation to send information about 41 the ongoing services to a third-party software 42 * Add mapsToJson, mapsToJson, and elementsToJson to the API 43 * Provide a zcfg2sql tool to convert a zcfg metadata file to SQL script 44 * Add support to store service metadata information into a database 45 * Add HPC Support for remote execution of SBATCH scripts through Slurm 46 * Add cookie reference to _HINTERNET 2 47 * Support headers for GET requests from the js ZOO-API 3 48 * Pass all headers listed in the attributes parameter from the -
TabularUnified trunk/zoo-project/zoo-api/js/ZOO-api.js ¶ ¶
r828 r917 3686 3686 } 3687 3687 var builder = this.parseData[data.localName().toLowerCase()]; 3688 if (builder) 3688 if (builder){ 3689 3689 res.push(builder.apply(this,[data])); 3690 } 3690 3691 else 3691 3692 res.push(null); 3693 data=null; 3692 3694 } 3693 3695 return res.length>1?res:res[0]; 3694 } else 3695 return null; 3696 } 3697 else{ 3698 var hasPercentCompleted=true; 3699 var status = node.*::Status.*::ProcessStarted; 3700 var msg = node.*::Status.*::ProcessStarted.*::*[0]; 3701 if(!status || !msg){ 3702 status = node.*::Status.*::ProcessAccepted; 3703 msg = node.*::Status.*::ProcessAccepted.*::*[0]; 3704 msg=msg.toString(); 3705 hasPercentCompleted=false; 3706 }else 3707 msg=msg.toString(); 3708 if(status!=null && node.@statusLocation){ 3709 var res={"status": node.@statusLocation.toXMLString(), "message": msg}; 3710 if(hasPercentCompleted) 3711 res["percentCompleted"]=status.@percentCompleted.toXMLString(); 3712 return res; 3713 }else 3714 return null; 3715 } 3696 3716 }, 3697 3717 /** … … 3748 3768 * {Object} A WPS reference response. 3749 3769 */ 3750 'reference': function(node) { 3751 var result = {type:'reference',value:node.@href}; 3770 'reference': function(lnode) { 3771 var lhref=lnode.@href; 3772 var lmimeType=lnode.@mimeType; 3773 var result = {type:'reference',value:lhref.toXMLString(),mimeType:lmimeType.toXMLString()}; 3752 3774 return result; 3753 3775 } … … 6147 6169 identifier: null, 6148 6170 /** 6171 * Property: async 6172 * {Bool} Define if the process should run asyncrhonously (true) or not (false, default). 6173 */ 6174 async: null, 6175 /** 6149 6176 * Constructor: ZOO.Process 6150 6177 * Create a new Process … … 6158 6185 this.url = url; 6159 6186 this.identifier = identifier; 6187 this.async = (arguments.length>2?arguments[2]:false); 6160 6188 }, 6161 6189 /** … … 6173 6201 if (this.identifier == null) 6174 6202 return null; 6175 var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>');6203 var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>'); 6176 6204 body = body.toXMLString(); 6177 6205 var headers=['Content-Type: text/xml; charset=UTF-8']; 6178 6179 6180 6206 if(arguments.length>2){ 6207 headers[headers.length]=arguments[2]; 6208 } 6181 6209 var response = ZOO.Request.Post(this.url,body,headers); 6182 6210 return response; … … 6195 6223 */ 6196 6224 'ResponseDocument': function(identifier,obj) { 6197 var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:ResponseDocument><wps:Output'+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output></wps:ResponseDocument></wps:ResponseForm>'); 6225 var output = new XML('<wps:Output xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output>'); 6226 output = output.toXMLString(); 6227 return output; 6228 }, 6229 'RawDataOutput': function(identifier,obj) { 6230 var output = new XML('<wps:RawDataOutput xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput>'); 6198 6231 if (obj.encoding) 6199 6232 output.*::Data.*::ComplexData.@encoding = obj.encoding; … … 6202 6235 output = output.toXMLString(); 6203 6236 return output; 6204 },6205 'RawDataOutput': function(identifier,obj) {6206 var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:RawDataOutput '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput></wps:ResponseForm>');6207 if (obj.encoding)6208 output.*::Data.*::ComplexData.@encoding = obj.encoding;6209 if (obj.schema)6210 output.*::Data.*::ComplexData.@schema = obj.schema;6211 output = output.toXMLString();6212 return output;6213 6237 } 6214 6238 … … 6231 6255 */ 6232 6256 'complex': function(identifier,data) { 6233 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData ><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>');6257 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>'); 6234 6258 if(data.xlink) 6235 6259 input.*::Reference.@mimeType = data.mimetype ? data.mimetype : 'application/json'; 6236 6260 else 6237 6261 input.*::Data.*::ComplexData.@mimeType = data.mimetype ? data.mimetype : 'application/json'; 6238 6262 if (data.encoding) 6239 6263 input.*::Data.*::ComplexData.@encoding = data.encoding; … … 6241 6265 input.*::Data.*::ComplexData.@schema = data.schema; 6242 6266 input = input.toXMLString(); 6243 return input; 6267 if(data.value) 6268 return (('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>')); 6269 else 6270 return input; 6244 6271 }, 6245 6272 /** … … 6269 6296 */ 6270 6297 'literal': function(identifier,data) { 6271 if(data && !eval(data["isArray"])){ 6272 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>'); 6273 if (data.type) 6274 input.*::Data.*::LiteralData.@dataType = data.type; 6275 if (data.uom) 6276 input.*::Data.*::LiteralData.@uom = data.uom; 6277 input = input.toXMLString(); 6278 return input; 6279 }else if(data){ 6280 var inputf=""; 6281 for(i=0;i<parseInt(data["length"]);i++){ 6282 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>'); 6283 if (data.type) 6284 input.*::Data.*::LiteralData.@dataType = data.type; 6285 if (data.uom) 6286 input.*::Data.*::LiteralData.@uom = data.uom; 6287 inputf += input.toXMLString(); 6288 } 6289 return inputf; 6298 if(data && !eval(data["isArray"])){ 6299 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>'); 6300 if (data.type) 6301 input.*::Data.*::LiteralData.@dataType = data.type; 6302 if (data.uom) 6303 input.*::Data.*::LiteralData.@uom = data.uom; 6304 input = input.toXMLString(); 6305 return input; 6306 }else if(data){ 6307 var inputf=""; 6308 for(i=0;i<parseInt(data["length"]);i++){ 6309 var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>'); 6310 if (data.type) 6311 input.*::Data.*::LiteralData.@dataType = data.type; 6312 if (data.uom) 6313 input.*::Data.*::LiteralData.@uom = data.uom; 6314 inputf += input.toXMLString(); 6290 6315 } 6291 6316 return inputf; 6317 } 6292 6318 } 6293 6319 }, … … 6318 6344 6319 6345 buildDataOutputsNode:function(outputs){ 6320 var data, builder, outputsArray=[ ];6346 var data, builder, outputsArray=[[],[]]; 6321 6347 for (var attr in outputs) { 6322 6348 data = outputs[attr]; 6323 6349 builder = this.buildOutput[data.type]; 6324 outputsArray.push(builder.apply(this,[attr,data])); 6325 } 6326 return outputsArray.join('\n'); 6350 if(data.type=="ResponseDocument") 6351 outputsArray[0].push(builder.apply(this,[attr,data])); 6352 else 6353 outputsArray[1].push(builder.apply(this,[attr,data])); 6354 } 6355 var responseDocuments=(outputsArray[0].length>0? 6356 new XML('<wps:ResponseDocument '+(this.async?'storeExecuteResponse="true" status="true"':'')+' xmlns:wps="'+this.namespaces['wps']+'">'+ 6357 outputsArray[0].join('\n')+ 6358 '</wps:ResponseDocument>') 6359 : 6360 null); 6361 var rawDataOutputs=(outputsArray[1].length>0? 6362 outputsArray[1].join('\n') 6363 : 6364 null); 6365 var res=new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'">'+ 6366 (responseDocuments!=null?responseDocuments.toXMLString():"")+ 6367 (rawDataOutputs!=null?rawDataOutputs:"")+ 6368 '</wps:ResponseForm>'); 6369 return res.toXMLString(); 6327 6370 }, 6328 6371 -
TabularUnified trunk/zoo-project/zoo-client/lib/js/wps-client/zoo.js ¶ ¶
r719 r917 679 679 680 680 $.ajax({ 681 url: closure.statusLocation[sid] 681 url: closure.statusLocation[sid]+"×tamp="++(new Date()).getTime() 682 682 }) 683 683 .fail( -
TabularUnified trunk/zoo-project/zoo-kernel/Makefile.in ¶ ¶
r815 r917 9 9 10 10 service.o: service.c service.h 11 g cc${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service.c11 g++ ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service.c 12 12 13 13 main_conf_read.tab.c: main_conf_read.y service.h … … 38 38 gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c 39 39 40 sshapi.o: sshapi.c 41 g++ -fPIC ${CFLAGS} -c sshapi.c 42 43 service_json.o: service_json.c 44 g++ -fPIC ${JSON_CFLAGS} ${CFLAGS} -c service_json.c 45 46 service_callback.o: service_callback.c 47 g++ -fPIC ${XML2CFLAGS} ${GDAL_CFLAGS} ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c 48 40 49 request_parser.o: request_parser.c request_parser.h 41 50 g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c 42 51 43 52 sqlapi.o: sqlapi.c sqlapi.h 44 g++ -fPIC ${ GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c53 g++ -fPIC ${METADB_ENABLED} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c 45 54 46 55 caching.o: caching.c … … 48 57 49 58 response_print.o: response_print.c response_print.h 50 g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c response_print.c59 g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c 51 60 52 61 server_internal.o: server_internal.c server_internal.h service.h mimetypes.h 53 g++ ${ GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c62 g++ ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c 54 63 55 64 service_internal.o: service_internal.c service_internal.h service.h 56 gcc ${ GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c65 gcc ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c 57 66 58 67 service_yaml.o: service_yaml.c service.h 59 68 gcc ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_yaml.c 69 70 meta_sql.o: meta_sql.c meta_sql.h service.h 71 g++ ${METADB_ENABLED} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -c meta_sql.c 60 72 61 73 service_internal_ms.o: service_internal_ms.c … … 66 78 g++ ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c service_internal_python.c 67 79 80 service_internal_r.o: service_internal_r.c service.h 81 g++ ${XML2CFLAGS} ${RCFLAGS} ${CFLAGS} -c service_internal_r.c 82 68 83 service_internal_otb.o: service_internal_otb.c service_internal_otb.h service.h 69 84 g++ ${XML2CFLAGS} ${OTBCFLAGS} ${CFLAGS} -c service_internal_otb.c 85 86 service_internal_hpc.o: service_internal_hpc.c service_internal_hpc.h service.h 87 g++ ${JSON_CFLAGS} ${XML2CFLAGS} ${HPCCFLAGS} ${CFLAGS} -c service_internal_hpc.c 70 88 71 89 service_internal_saga.o: service_internal_saga.c service_internal_saga.h service.h … … 99 117 g++ -c ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} service_loader.c 100 118 101 zoo_service_loader.o: zoo_service_loader.c service.h version.h ${MS_FILE} ${ PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE}102 g++ -g -O2 ${ XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED}-c zoo_service_loader.c -fno-common -DPIC -o zoo_service_loader.o119 zoo_service_loader.o: zoo_service_loader.c service.h version.h ${MS_FILE} ${R_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE} 120 g++ -g -O2 ${JSON_CFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${RCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${HPC_ENABLED} ${PYTHON_ENABLED} ${R_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED} ${METADB_ENABLED} -c zoo_service_loader.c -fno-common -DPIC -o zoo_service_loader.o 103 121 104 122 libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o 105 g cc -shared ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS} service_internal.o service.o sqlapi.o ${FCGI_LDFLAGS} ${GDAL_LIBS}123 g++ -shared ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS} service_internal.o service.o sqlapi.o ${FCGI_LDFLAGS} ${GDAL_LIBS} ${ZOO_LDFLAGS} ${MACOS_LD_FLAGS} 106 124 107 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${ SAGA_FILE}108 g++ -g -O2 ${JS CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${RUBYCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c -fno-common -DPIC -o zoo_loader.o109 g++ ${JS CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}125 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${R_FILE} ${SAGA_FILE} ${HPC_FILES} ${METADB_FILE} ${JSON_FILE} ${CALLBACK_FILE} 126 g++ -g -O2 ${JSON_CFLAGS} ${JSCFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${RUBYCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c -fno-common -DPIC -o zoo_loader.o 127 g++ ${JSON_CFLAGS} ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE} ${JSON_FILE} ${R_FILE} ${CALLBACK_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS} 110 128 111 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE} 129 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE} ${CALLBACK_FILE} 112 130 g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${CFLAGS} -c zcfg2yaml.c -fno-common -DPIC -o zcfg2yaml.o 113 g++ ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}131 g++ ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o caching.o ulinet.o ${CALLBACK_FILE} server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS} 114 132 115 133 install: zoo_loader.cgi -
TabularUnified trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in ¶ ¶
r866 r917 30 30 YAML_FILE1=@YAML_FILE1@ 31 31 32 JSON_CFLAGS=@JSON_CPPFLAGS@ 33 JSON_LDFLAGS=@JSON_LDFLAGS@ 34 JSON_FILE=@JSON_FILE@ 35 36 METADB_ENABLED=@METADB@ 37 METADB_FILE=@METADB_FILE@ 38 39 32 40 GDAL_CFLAGS=@GDAL_CFLAGS@ 33 41 GDAL_LIBS=@GDAL_LIBS@ … … 50 58 PYTHON_FILE=@PYTHON_FILE@ 51 59 60 RCFLAGS=@R_CPPFLAGS@ 61 RLDFLAGS=@R_LDFLAGS@ 62 R_ENABLED=@R_ENABLED@ 63 R_FILE=@R_FILE@ 64 52 65 RUBYCFLAGS=@RUBY_CPPFLAGS@ 53 66 RUBYLDFLAGS=@RUBY_LDFLAGS@ … … 68 81 69 82 ZOO_CFLAGS=-I${ZRPATH}/../thirds/cgic206/ -I${ZRPATH}/zoo-kernel/ 70 ZOO_LDFLAGS=@OPENSSL_LDFLAGS@ -luuid83 ZOO_LDFLAGS=@OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ 71 84 72 85 JAVACFLAGS=@JAVA_CPPFLAGS@ … … 80 93 PHP_FILE=@PHP_FILE@ 81 94 82 83 95 PERLCFLAGS=@PERL_CPPFLAGS@ 84 96 PERLLDFLAGS=@PERL_LDFLAGS@ 85 97 PERL_ENABLED=@PERL_ENABLED@ 86 98 PERL_FILE=@PERL_FILE@ 99 100 HPCCFLAGS=@SSH2_CPPFLAGS@ @HPC_CPPFLAGS@ 101 HPCLDFLAGS=@SSH2_LDFLAGS@ @HPC_LDFLAGS@ 102 HPC_ENABLED=@HPC_ENABLED@ 103 HPC_FILES=@HPC_FILES@ 104 105 CALLBACK_FILE=@CALLBACK_FILE@ 106 CALLBACK_USE=@CALLBACK_USE@ 87 107 88 108 OTBCFLAGS=@OTB_CPPFLAGS@ … … 101 121 MONO_FILE=@MONO_FILE@ 102 122 103 CFLAGS= -Wdeclaration-after-statement @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF104 LDFLAGS=-lzoo_service @ DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS}123 CFLAGS=@CALLBACK_USE@ @SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 124 LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} ${RLDFLAGS} @JSON_LDFLAGS@ @XSLT_LDFLAGS@ 105 125 106 126 DATAROOTDIR=@datarootdir@/zoo-project -
TabularUnified trunk/zoo-project/zoo-kernel/caching.c ¶ ¶
r837 r917 23 23 */ 24 24 25 #include <openssl/md5.h> 26 #include <openssl/evp.h> 25 27 #include "caching.h" 26 28 #include "service.h" 27 29 #include "service_internal.h" 28 30 #include "response_print.h" 29 #include <openssl/md5.h> 30 #include <openssl/hmac.h> 31 #include <openssl/evp.h> 32 #include <openssl/bio.h> 33 #include <openssl/buffer.h> 34 31 #ifdef MS_FORCE_LOCAL_FILE_USE 32 #include "ogr_api.h" 33 #include "mapserver.h" 34 #endif 35 35 /** 36 36 * Compute md5 … … 41 41 */ 42 42 char* getMd5(char* url){ 43 EVP_MD_CTX md5ctx;43 EVP_MD_CTX *md5ctx=EVP_MD_CTX_create(); 44 44 char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); 45 45 unsigned char result[EVP_MAX_MD_SIZE]; 46 46 unsigned int len; 47 EVP_DigestInit( &md5ctx, EVP_md5());48 EVP_DigestUpdate( &md5ctx, url, strlen(url));49 EVP_DigestFinal_ex( &md5ctx,result,&len);50 EVP_MD_CTX_ cleanup(&md5ctx);47 EVP_DigestInit(md5ctx, EVP_md5()); 48 EVP_DigestUpdate(md5ctx, url, strlen(url)); 49 EVP_DigestFinal_ex(md5ctx,result,&len); 50 EVP_MD_CTX_destroy(md5ctx); 51 51 int i; 52 52 for(i = 0; i < len; i++){ 53 53 if(i>0){ 54 char *tmp= strdup(fresult);54 char *tmp=zStrdup(fresult); 55 55 sprintf(fresult,"%s%02x", tmp,result[i]); 56 56 free(tmp); … … 62 62 } 63 63 64 /** 65 * Compute md5 of a file 66 * 67 * @param file the char* 68 * @return a char* representing the md5 of the url 69 * @warning make sure to free resources returned by this function 70 */ 71 char* getMd5f(char* file){ 72 EVP_MD_CTX *md5ctx=EVP_MD_CTX_create(); 73 char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); 74 unsigned char result[EVP_MAX_MD_SIZE]; 75 unsigned int len; 76 int bytes; 77 int dlen=65536; 78 unsigned char data[65537]; 79 FILE *inFile = fopen (file, "rb"); 80 EVP_DigestInit(md5ctx, EVP_md5()); 81 while ((bytes = fread (data, sizeof(unsigned char), dlen, inFile)) != 0) 82 EVP_DigestUpdate(md5ctx, data, bytes); 83 EVP_DigestFinal_ex(md5ctx,result,&len); 84 EVP_MD_CTX_destroy(md5ctx); 85 int i; 86 for(i = 0; i < len; i++){ 87 if(i>0){ 88 char *tmp=zStrdup(fresult); 89 sprintf(fresult,"%s%02x", tmp,result[i]); 90 free(tmp); 91 } 92 else 93 sprintf(fresult,"%02x",result[i]); 94 } 95 fclose (inFile); 96 return fresult; 97 } 98 99 100 101 /** 102 * Create a URL by appending every request header listed in the security 103 * section.This imply that the URL will contain any authentication 104 * informations that should be fowarded to the server from which de input 105 * was download. 106 * @param conf the main configuration maps 107 * @param request the URL to transform. 108 * @return a char* that contain the original URL plus potential header (only for 109 * hosts that are not shared). 110 * @warning Be sure to free the memory returned by this function. 111 */ 112 char* getFilenameForRequest(maps* conf, const char* request){ 113 map* passThrough=getMapFromMaps(conf,"security","attributes"); 114 map* targetHosts=getMapFromMaps(conf,"security","hosts"); 115 char* passedHeader[10]; 116 int cnt=0; 117 char *res=zStrdup(request); 118 char *toAppend=NULL; 119 if(passThrough!=NULL && targetHosts!=NULL){ 120 char *tmp=zStrdup(passThrough->value); 121 char *token, *saveptr; 122 token = strtok_r (tmp, ",", &saveptr); 123 int i; 124 if((strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,request)==1) && strncasecmp(getProvenance(conf,request),"SHARED",6)!=0){ 125 while (token != NULL){ 126 int length=strlen(token)+6; 127 char* tmp1=(char*)malloc(length*sizeof(char)); 128 map* tmpMap; 129 snprintf(tmp1,6,"HTTP_"); 130 int j; 131 for(j=0;token[j]!='\0';j++){ 132 if(token[j]!='-') 133 tmp1[5+j]=toupper(token[j]); 134 else 135 tmp1[5+j]='_'; 136 tmp1[5+j+1]='\0'; 137 } 138 tmpMap = getMapFromMaps(conf,"renv",tmp1); 139 if(tmpMap!=NULL){ 140 if(toAppend==NULL){ 141 toAppend=(char*)malloc((strlen(tmpMap->value)+1)*sizeof(char)); 142 sprintf(toAppend,"%s",tmpMap->value); 143 }else{ 144 char *tmp3=zStrdup(toAppend); 145 toAppend=(char*)realloc(toAppend,(strlen(tmpMap->value)+strlen(tmp3)+2)*sizeof(char)); 146 sprintf(toAppend,"%s,%s",tmp3,tmpMap->value); 147 free(tmp3); 148 } 149 } 150 free(tmp1); 151 cnt+=1; 152 token = strtok_r (NULL, ",", &saveptr); 153 } 154 } 155 free(tmp); 156 } 157 if(toAppend!=NULL){ 158 char *tmp3=zStrdup(res); 159 res=(char*)realloc(res,(strlen(tmp3)+strlen(toAppend)+1)*sizeof(char)); 160 sprintf(res,"%s%s",tmp3,toAppend); 161 free(tmp3); 162 free(toAppend); 163 } 164 return res; 165 } 166 167 /** 168 * Store MD5 of the content of a file 169 * @file char* the full path of the file 170 */ 171 int storeMd5(char* file){ 172 char* storage=zStrdup(file); 173 char* md5fstr=getMd5f(file); 174 storage[strlen(storage)-2]='m'; 175 storage[strlen(storage)-1]='d'; 176 FILE* fo=fopen(storage,"w+"); 177 if(fo==NULL) 178 return 1; 179 fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo); 180 free(md5fstr); 181 free(storage); 182 fclose(fo); 183 return 0; 184 } 64 185 65 186 /** … … 76 197 * @param max_path the size of the allocated filepath buffer 77 198 */ 199 void cacheFile(maps* conf,char* request,char* mimeType,int length,char* filename){ 200 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 201 char contentr[4096]; 202 int cred=0; 203 if(tmp!=NULL){ 204 char* myRequest=getFilenameForRequest(conf,request); 205 char* md5str=getMd5(myRequest); 206 free(myRequest); 207 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 208 // Store md5 209 char* md5fstr=getMd5f(filename); 210 sprintf(fname,"%s/%s.zmd",tmp->value,md5str); 211 FILE* fo=fopen(fname,"w+"); 212 #ifdef DEBUG 213 fprintf(stderr,"filename: %s\n",filename); 214 fprintf(stderr,"MD5: %s\n",md5fstr); 215 #endif 216 fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo); 217 free(md5fstr); 218 fclose(fo); 219 220 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 221 zooLock* lck=lockFile(conf,fname,'w'); 222 if(lck!=NULL){ 223 #ifdef DEBUG 224 fprintf(stderr,"Cache list : %s\n",fname); 225 fflush(stderr); 226 #endif 227 FILE* fi=fopen(filename,"rb"); 228 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 229 fo=fopen(fname,"w+"); 230 if(fo==NULL){ 231 #ifdef DEBUG 232 fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno)); 233 #endif 234 unlockFile(conf,lck); 235 return; 236 } 237 if(fi==NULL){ 238 #ifdef DEBUG 239 fprintf (stderr, "Failed to open %s for reading: %s\n",filename, strerror(errno)); 240 #endif 241 unlockFile(conf,lck); 242 return; 243 } 244 memset(contentr,0,4096); 245 while((cred=fread(contentr,sizeof(char),4096,fi))>0){ 246 fwrite(contentr,sizeof(char),cred,fo); 247 fflush(fo); 248 memset(contentr,0,4096); 249 } 250 unlockFile(conf,lck); 251 fclose(fo); 252 fclose(fi); 253 254 // Store mimeType 255 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 256 fo=fopen(fname,"w+"); 257 #ifdef DEBUG 258 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 259 #endif 260 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 261 fclose(fo); 262 263 // Store provenance 264 sprintf(fname,"%s/%s.zcp",tmp->value,md5str); 265 fo=fopen(fname,"w+"); 266 char* origin=getProvenance(conf,request); 267 #ifdef DEBUG 268 fprintf(stderr,"ORIGIN: %s\n",mimeType); 269 #endif 270 fwrite(origin,sizeof(char),strlen(origin),fo); 271 fclose(fo); 272 273 free(md5str); 274 275 } 276 free(fname); 277 } 278 } 279 280 /** 281 * Cache a file for a given request. 282 * For each cached file, the are two files stored, a .zca and a .zcm containing 283 * the downloaded content and the mimeType respectively. 284 * 285 * @param conf the maps containing the settings of the main.cfg file 286 * @param request the url used too fetch the content 287 * @param content the downloaded content 288 * @param mimeType the content mimeType 289 * @param length the content size 290 * @param filepath a buffer for storing the path of the cached file; may be NULL 291 * @param max_path the size of the allocated filepath buffer 292 */ 78 293 void addToCache(maps* conf,char* request,char* content,char* mimeType,int length, 79 294 char* filepath, size_t max_path){ 80 295 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 81 296 if(tmp!=NULL){ 82 char* md5str=getMd5(request); 297 char* myRequest=getFilenameForRequest(conf,request); 298 char* md5str=getMd5(myRequest); 299 free(myRequest); 83 300 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 84 301 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 85 #ifdef DEBUG 86 fprintf(stderr,"Cache list : %s\n",fname); 87 fflush(stderr); 88 #endif 89 FILE* fo=fopen(fname,"w+"); 90 if(fo==NULL){ 91 #ifdef DEBUG 92 fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno)); 93 #endif 94 filepath = NULL; 95 return; 96 } 97 fwrite(content,sizeof(char),length,fo); 98 fclose(fo); 302 zooLock* lck=lockFile(conf,fname,'w'); 303 if(lck!=NULL){ 304 #ifdef DEBUG 305 fprintf(stderr,"Cache list : %s\n",fname); 306 fflush(stderr); 307 #endif 308 FILE* fo=fopen(fname,"w+"); 309 if(fo==NULL){ 310 #ifdef DEBUG 311 fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno)); 312 #endif 313 filepath = NULL; 314 unlockFile(conf,lck); 315 return; 316 } 317 fwrite(content,sizeof(char),length,fo); 318 unlockFile(conf,lck); 319 fclose(fo); 99 320 100 if (filepath != NULL) { 101 strncpy(filepath, fname, max_path); 102 } 103 104 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 105 fo=fopen(fname,"w+"); 106 #ifdef DEBUG 107 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 108 #endif 109 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 110 fclose(fo); 111 112 free(md5str); 113 free(fname); 321 if (filepath != NULL) { 322 strncpy(filepath, fname, max_path); 323 } 324 325 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 326 fo=fopen(fname,"w+"); 327 #ifdef DEBUG 328 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 329 #endif 330 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 331 fclose(fo); 332 333 sprintf(fname,"%s/%s.zcp",tmp->value,md5str); 334 fo=fopen(fname,"w+"); 335 char* origin=getProvenance(conf,request); 336 #ifdef DEBUG 337 fprintf(stderr,"ORIGIN: %s\n",mimeType); 338 #endif 339 fwrite(origin,sizeof(char),strlen(origin),fo); 340 fclose(fo); 341 342 free(md5str); 343 free(fname); 344 } 114 345 } 115 346 else { 116 347 filepath = NULL; 117 348 } 118 349 } … … 127 358 */ 128 359 char* isInCache(maps* conf,char* request){ 360 map* tmpUrl=getMapFromMaps(conf,"main","tmpUrl"); 129 361 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 130 if(tmpM!=NULL){ 131 char* md5str=getMd5(request); 362 if(tmpM==NULL) 363 tmpM=getMapFromMaps(conf,"main","tmpPath"); 364 if(strstr(request,tmpUrl->value)!=NULL){ 365 map* tmpPath=getMapFromMaps(conf,"main","tmpPath"); 366 char* tmpStr=strstr(request,tmpUrl->value); 367 char* tmpStr1=zStrdup(tmpStr+strlen(tmpUrl->value)); 368 char* res=(char*) malloc((strlen(tmpPath->value)+strlen(tmpStr1)+2)*sizeof(char)); 369 sprintf(res,"%s/%s",tmpPath->value,tmpStr1); 370 free(tmpStr1); 371 return res; 372 } 373 #ifdef MS_FORCE_LOCAL_FILE_USE 374 map* msUrl=getMapFromMaps(conf,"main","mapserverAddress"); 375 if(msUrl!=NULL && strstr(request,msUrl->value)!=NULL){ 376 char *tmpStr=strstr(request,"?"); 377 char *cursor=zStrdup(tmpStr+1); 378 char *token, *saveptr; 379 token = strtok_r (cursor, "&", &saveptr); 380 while(token!=NULL){ 381 char *token1, *saveptr1; 382 token1 = strtok_r (token, "=", &saveptr1); 383 char *name=NULL; 384 while(token1!=NULL){ 385 if(name==NULL) 386 name=zStrdup(token1); 387 else 388 if(strcasecmp(name,"map")==0){ 389 mapObj *myMap=msLoadMap(token1,NULL); 390 char * res=zStrdup(myMap->layers[0]->data); 391 free(name); 392 free(cursor); 393 msFreeMap(myMap); 394 return res; 395 } 396 token1 = strtok_r (NULL, "=", &saveptr1); 397 } 398 token = strtok_r (NULL, "&", &saveptr); 399 } 400 free(cursor); 401 } 402 #endif 403 if(strncasecmp(request,"file://",7)==0){ 404 char* tmpStr=zStrdup(request+7); 405 fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr); 406 return tmpStr; 407 } 408 else{ 409 char* myRequest=getFilenameForRequest(conf,request); 410 char* md5str=getMd5(myRequest); 411 free(myRequest); 132 412 #ifdef DEBUG 133 413 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); … … 135 415 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6)); 136 416 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 137 struct stat f_status;138 int s= stat(fname, &f_status);417 zStatStruct f_status; 418 int s=zStat(fname, &f_status); 139 419 if(s==0 && f_status.st_size>0){ 140 420 free(md5str); … … 158 438 */ 159 439 int readCurrentInput(maps** m,maps** in,int* index,HINTERNET* hInternet,map** error){ 440 441 int shouldClean=-1; 160 442 map* tmp1; 161 443 char sindex[5]; 162 444 maps* content=*in; 163 445 map* length=getMap(content->content,"length"); 164 int shouldClean=-1;446 map* memUse=getMapFromMaps(*m,"main","memory"); 165 447 if(length==NULL){ 166 448 length=createMap("length","1"); … … 171 453 char *mimeType=NULL; 172 454 int fsize=0; 455 char oriname[12]; 173 456 char cname[15]; 174 457 char vname[11]; … … 178 461 char icname[14]; 179 462 char xname[16]; 463 char bname[8]; 464 char hname[11]; 180 465 char oname[12]; 466 char ufile[12]; 181 467 if(*index>0) 182 468 sprintf(vname1,"value_%d",*index); … … 185 471 186 472 if(i>0){ 473 sprintf(cname,"cache_file_%d",i); 187 474 tmp1=getMap(content->content,cname); 188 sprintf( cname,"cache_file_%d",i);475 sprintf(oriname,"origin_%d",i); 189 476 sprintf(vname,"value_%d",i); 190 477 sprintf(sname,"size_%d",i); … … 192 479 sprintf(icname,"isCached_%d",i); 193 480 sprintf(xname,"Reference_%d",i); 481 sprintf(bname,"body_%d",i); 482 sprintf(hname,"headers_%d",i); 194 483 sprintf(oname,"Order_%d",i); 484 sprintf(ufile,"use_file_%d",i); 195 485 }else{ 196 486 sprintf(cname,"cache_file"); 487 sprintf(oriname,"origin"); 197 488 sprintf(vname,"value"); 198 489 sprintf(sname,"size"); … … 200 491 sprintf(icname,"isCached"); 201 492 sprintf(xname,"Reference"); 493 sprintf(bname,"body"); 494 sprintf(hname,"headers"); 202 495 sprintf(oname,"Order"); 496 sprintf(ufile,"use_file"); 203 497 } 204 498 … … 206 500 sprintf(sindex,"%d",*index+1); 207 501 if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){ 208 209 if(getMap(content->content,icname)==NULL){ 210 fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char)); 211 if(fcontent == NULL){ 212 errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 213 return -1; 502 503 if(getMap(content->content,icname)==NULL) { 504 if(memUse==NULL || strcasecmp(memUse->value,"load")==0){ 505 fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char)); 506 if(fcontent == NULL){ 507 errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 508 return -1; 509 } 510 size_t dwRead; 511 InternetReadFile(hInternet->ihandle[*index], 512 (LPVOID)fcontent, 513 hInternet->ihandle[*index].nDataLen, 514 &dwRead); 515 fcontent[hInternet->ihandle[*index].nDataLen]=0; 214 516 } 215 size_t dwRead;216 InternetReadFile(hInternet->ihandle[*index],217 (LPVOID)fcontent,218 hInternet->ihandle[*index].nDataLen,219 &dwRead);220 fcontent[hInternet->ihandle[*index].nDataLen]=0;221 517 fsize=hInternet->ihandle[*index].nDataLen; 222 518 if(hInternet->ihandle[*index].mimeType==NULL) … … 226 522 227 523 map* tmpMap=getMapOrFill(&(*in)->content,vname,""); 228 free(tmpMap->value); 229 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 230 if(tmpMap->value==NULL){ 231 return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 232 } 233 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 524 if(memUse==NULL || strcasecmp(memUse->value,"load")==0){ 525 free(tmpMap->value); 526 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 527 if(tmpMap->value==NULL){ 528 return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 529 } 530 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 531 }else 532 addToMap((*in)->content,ufile,"true"); 234 533 if(hInternet->ihandle[*index].code!=200){ 235 534 const char *error_rep_str=_("Unable to download the file for the input <%s>, response code was : %d."); … … 255 554 sprintf(ltmp1,"%d",fsize); 256 555 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 556 char *request=NULL; 257 557 if(tmp!=NULL){ 258 char* md5str=getMd5(tmp1->value); 558 map* tmp2; 559 char* md5str=NULL; 560 if((tmp2=getMap(content->content,bname))!=NULL){ 561 char *tmpStr=(char*)malloc((strlen(tmp1->value)+strlen(tmp2->value)+1)*sizeof(char)); 562 sprintf(tmpStr,"%s%s",tmp1->value,tmp2->value); 563 if((tmp2=getMap(content->content,"headers"))!=NULL){ 564 char *tmpStr2=zStrdup(tmpStr); 565 free(tmpStr); 566 tmpStr=(char*)malloc((strlen(tmpStr2)+strlen(tmp2->value)+1)*sizeof(char)); 567 sprintf(tmpStr,"%s%s",tmpStr2,tmp2->value); 568 free(tmpStr2); 569 } 570 md5str=getMd5(tmpStr); 571 request=zStrdup(tmpStr); 572 free(tmpStr); 573 }else{ 574 char *myRequest=getFilenameForRequest(*m,tmp1->value); 575 md5str=getMd5(myRequest); 576 request=zStrdup(tmp1->value); 577 free(myRequest); 578 } 259 579 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 260 580 sprintf(fname,"%s/%s.zca",tmp->value,md5str); … … 264 584 addToMap((*in)->content,sname,ltmp1); 265 585 addToMap((*in)->content,mname,mimeType); 266 addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0); 267 free(fcontent); 586 char* origin=getProvenance(*m,request); 587 addToMap((*in)->content,oriname,origin); 588 if(memUse==NULL || strcasecmp(memUse->value,"load")==0){ 589 addToCache(*m,request,fcontent,mimeType,fsize, NULL, 0); 590 free(fcontent); 591 }else{ 592 addToMap((*in)->content,ufile,"true"); 593 cacheFile(*m,request,mimeType,fsize,hInternet->ihandle[*index].filename); 594 } 268 595 free(mimeType); 269 *index++;270 596 free(request); 597 (*index)++; 271 598 } 272 599 } … … 324 651 */ 325 652 void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){ 326 hInternet->waitingRequests[hInternet->nb]= strdup(url);653 hInternet->waitingRequests[hInternet->nb]=zStrdup(url); 327 654 if(req) 328 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0 );655 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0,*m); 329 656 maps *oreq=getMaps(*m,"orequests"); 330 657 if(oreq==NULL){ … … 335 662 free(oreq); 336 663 }else{ 337 setMapArray(oreq->content,"value",hInternet->nb -1,url);664 setMapArray(oreq->content,"value",hInternet->nb,url); 338 665 } 339 666 } … … 352 679 char* cached=isInCache(*m,url); 353 680 char *mimeType=NULL; 354 int fsize=0; 681 char *origin=NULL; 682 long long fsize=0; 683 map* memUse=getMapFromMaps(*m,"main","memory"); 355 684 356 685 map* t=getMap(*content,"xlink:href"); … … 361 690 362 691 if(cached!=NULL){ 363 364 struct stat f_status; 365 int s=stat(cached, &f_status); 692 zStatStruct f_status; 693 int s=zStat(cached, &f_status); 366 694 if(s==0){ 367 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));368 FILE* f=fopen(cached,"rb");369 fread(fcontent,f_status.st_size,1,f);695 zooLock* lck=lockFile(*m,cached,'r'); 696 if(lck==NULL) 697 return -1; 370 698 fsize=f_status.st_size; 371 fcontent[fsize]=0; 372 fclose(f); 699 if(memUse==NULL || strcasecmp(memUse->value,"load")==0){ 700 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 701 FILE* f=fopen(cached,"rb"); 702 if(f!=NULL){ 703 fread(fcontent,f_status.st_size,1,f); 704 fcontent[fsize]=0; 705 fclose(f); 706 } 707 } 373 708 addToMap(*content,"cache_file",cached); 709 unlockFile(*m,lck); 374 710 } 375 711 cached[strlen(cached)-1]='m'; 376 s= stat(cached, &f_status);712 s=zStat(cached, &f_status); 377 713 if(s==0){ 714 zooLock* lck=lockFile(*m,cached,'r'); 715 if(lck==NULL) 716 return -1; 378 717 mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 379 718 FILE* f=fopen(cached,"rb"); … … 381 720 mimeType[f_status.st_size]=0; 382 721 fclose(f); 383 } 384 722 unlockFile(*m,lck); 723 } 724 cached[strlen(cached)-1]='p'; 725 s=zStat(cached, &f_status); 726 if(s==0){ 727 zooLock* lck=lockFile(*m,cached,'r'); 728 if(lck==NULL) 729 return -1; 730 origin=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 731 FILE* f=fopen(cached,"rb"); 732 fread(origin,f_status.st_size,1,f); 733 mimeType[f_status.st_size]=0; 734 fclose(f); 735 unlockFile(*m,lck); 736 } 385 737 }else{ 386 738 addRequestToQueue(m,hInternet,url,true); … … 393 745 addToMap(*content,"fmimeType",mimeType); 394 746 } 747 if(origin!=NULL){ 748 addToMap(*content,"origin",origin); 749 } 395 750 396 751 map* tmpMap=getMapOrFill(content,"value",""); 397 398 free(tmpMap->value); 399 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 400 if(tmpMap->value==NULL || fcontent == NULL) 401 return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 402 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 403 752 if(memUse==NULL || strcasecmp(memUse->value,"load")==0){ 753 free(tmpMap->value); 754 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 755 if(tmpMap->value==NULL || fcontent == NULL) 756 return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL); 757 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 758 } 759 404 760 char ltmp1[256]; 405 sprintf(ltmp1,"% d",fsize);761 sprintf(ltmp1,"%ld",fsize); 406 762 addToMap(*content,"size",ltmp1); 407 763 if(cached==NULL){ 408 addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0); 764 if(memUse==NULL || strcasecmp(memUse->value,"load")==0) 765 addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0); 766 else 767 cacheFile(*m,url,mimeType,fsize,hInternet->ihandle[hInternet->nb-1].filename); 409 768 } 410 769 else{ 411 770 addToMap(*content,"isCached","true"); 412 771 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 413 if(tmp!=NULL){ 772 map* tmp1=getMap((*content),"cache_file"); 773 if(tmp!=NULL && tmp1==NULL){ 414 774 map *c=getMap((*content),"xlink:href"); 415 char* md5str=getMd5(c->value); 416 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 417 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 418 addToMap(*content,"cache_file",fname); 419 free(fname); 420 } 421 } 422 free(fcontent); 423 free(mimeType); 424 free(cached); 775 if(strncasecmp(c->value,"file://",7)!=0){ 776 char *myRequest=getFilenameForRequest(*m,c->value); 777 char* md5str=getMd5(myRequest); 778 free(myRequest); 779 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 780 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 781 addToMap(*content,"cache_file",fname); 782 free(fname); 783 free(md5str); 784 } 785 } 786 } 787 if(fcontent!=NULL) 788 free(fcontent); 789 if(mimeType!=NULL) 790 free(mimeType); 791 if(cached!=NULL) 792 free(cached); 425 793 return 0; 426 794 } -
TabularUnified trunk/zoo-project/zoo-kernel/caching.h ¶ ¶
r797 r917 35 35 void addRequestToQueue(maps**,HINTERNET*,const char*,bool); 36 36 int loadRemoteFile(maps**,map**,HINTERNET*,char*); 37 37 char* getMd5f(char*); 38 int storeMd5(char*); 39 38 40 #ifdef __cplusplus 39 41 } -
TabularUnified trunk/zoo-project/zoo-kernel/configure.ac ¶ ¶
r817 r917 1 1 AC_INIT([ZOO Kernel], [1.7.0], [bugs@zoo-project.org]) 2 3 AC_CONFIG_MACRO_DIR([macros]) 2 4 3 5 # Checks for programs. … … 12 14 AC_CHECK_LIB([dl], [dlopen,dlsym,dlerror,dlclose]) 13 15 AC_CHECK_LIB([crypto], [EVP_DigestInit,EVP_md5,EVP_DigestUpdate,BIO_f_base64,BIO_new]) 14 AC_CHECK_LIB([uuid], [uuid_generate_time])15 16 16 17 DEFAULT_LIBS="$LIBS" … … 20 21 # Checks for header files. 21 22 AC_FUNC_ALLOCA 22 AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.hmalloc.h stddef.h stdlib.h string.h unistd.h])23 AC_CHECK_HEADERS([fcntl.h inttypes.h malloc.h stddef.h stdlib.h string.h unistd.h]) 23 24 24 25 # Checks for typedefs, structures, and compiler characteristics. … … 38 39 AC_FUNC_REALLOC 39 40 AC_CHECK_FUNCS([dup2 getcwd memset setenv strdup strstr]) 41 42 #============================================================================ 43 # Detect if uuid is available 44 #============================================================================ 45 46 AC_ARG_WITH([uuid], 47 [AS_HELP_STRING([--with-uuid=PATH], [Specifies an alternative location for the ossp-uuid library])], 48 [UUID_DIR="$withval"], [UUID_DIR="/usr/"]) 49 UUID_CFLAGS="-I$UUID_DIR/include" 50 UUID_LDFLAGS="-L$UUID_DIR/lib -luuid" 51 CPPFLAGS_SAVE="$CPPFLAGS" 52 CPPFLAGS="$UUID_CFLAGS" 53 LIBS_SAVE="$LIBS" 54 LIBS="$UUID_LDFLAGS" 55 AC_CHECK_HEADERS([uuid/uuid.h], 56 [], [AC_MSG_ERROR([could not find header file uuid.h])]) 57 AC_CHECK_LIB([uuid], [uuid_generate_time], 58 [], [AC_MSG_ERROR([could not find function in uuid library])]) 59 CPPFLAGS="$CPPFLAGS_SAVE" 60 AC_SUBST([UUID_CFLAGS]) 61 AC_SUBST([UUID_LDFLAGS]) 62 63 #============================================================================ 64 # Detect if json-c is available 65 #============================================================================ 66 67 AC_ARG_WITH([callback], 68 [AS_HELP_STRING([--with-callback=yes], [Activate callback invocation during HPC execution])], 69 [CALLBACK_ACTIVATED="$withval"], [CALLBACK_ACTIVATED="no"]) 70 71 AC_ARG_WITH([json], 72 [AS_HELP_STRING([--with-json=PATH], [Specifies an alternative location for the json-c library])], 73 [JSON_DIR="$withval"], [JSON_DIR="/usr/"]) 74 if test "x$JSON_DIR" != "x" && test "x$CALLBACK_ACTIVATED" == "xyes" 75 then 76 JSON_CPPFLAGS="-I$JSON_DIR/include/json-c/" 77 JSON_LDFLAGS="-L$JSON_DIR/lib -ljson-c" 78 CPPFLAGS_SAVE="$CPPFLAGS" 79 CPPFLAGS="$JSON_CPPFLAGS" 80 LIBS_SAVE="$LIBS" 81 LIBS="$JSON_LDFLAGS" 82 AC_CHECK_HEADERS([json_object.h], 83 [], [AC_MSG_ERROR([could not find header file json_object.h])]) 84 AC_CHECK_LIB([json-c], [json_object_new_object], 85 [], [AC_MSG_ERROR([could not find function in json-c library])]) 86 CPPFLAGS="$CPPFLAGS_SAVE" 87 JSON_FILE="service_json.o" 88 JSON_ENABLED="-DJSON" 89 CALLBACK_FILE="service_callback.o" 90 CALLBACK_USE="-DUSE_CALLBACK" 91 fi 92 AC_SUBST([JSON_CPPFLAGS]) 93 AC_SUBST([JSON_LDFLAGS]) 94 AC_SUBST([JSON_FILE]) 95 AC_SUBST([JSON_ENABLED]) 96 AC_SUBST([CALLBACK_FILE]) 97 AC_SUBST([CALLBACK_USE]) 40 98 41 99 #============================================================================ … … 56 114 AC_CHECK_LIB(crypto, BIO_f_base64, 57 115 [], [AC_MSG_ERROR([could not find $i function in openssl library])]) 116 CPPFLAGS="$CPPFLAGS_SAVE" 58 117 AC_SUBST([OPENSSL_CFLAGS]) 59 118 AC_SUBST([OPENSSL_LDFLAGS]) 119 120 #============================================================================ 121 # Detect if gettext is available 122 #============================================================================ 123 124 #AC_ARG_WITH([gettext], 125 # [AS_HELP_STRING([--with-gettext=PATH], [Specifies an alternative location for the openssl library])], 126 # [GETTEXT_DIR="$withval"], [GETTEXT_DIR="/usr/"]) 127 128 #GETTEXT_CFLAGS="-I$GETTEXT_DIR/include" 129 #GETTEXT_LDFLAGS="-L$GETTEXT_DIR/lib -lintl" 130 #CFLAGS_SAVE="$CFLAGS" 131 #CFLAGS="$GETTEXT_CFLAGS" 132 #LIBS_SAVE="$LIBS" 133 #LIBS="$GETTEXT_LDFLAGS" 134 #AM_GNU_GETTEXT([external], [], []) 135 #AC_CHECK_LIB(intl, 136 # [dgettext], [] , [AC_MSG_ERROR([could not find $i function in gettext library])]) 137 #AC_SUBST([GETTEXT_CFLAGS]) 138 #AC_SUBST([GETTEXT_LDFLAGS]) 60 139 61 140 #============================================================================ … … 145 224 AC_SUBST([FCGI_LDFLAGS]) 146 225 226 AC_ARG_WITH([metadb], 227 [AS_HELP_STRING([--with-metadb=yes], [Activates the metadata database support])], 228 [WITHMETADB="$withval"], [WITHMETADB=""]) 229 230 if test "x$WITHMETADB" = "xyes"; then 231 METADB="-DMETA_DB" 232 METADB_FILE="meta_sql.o sqlapi.o" 233 else 234 METADB="" 235 METADB_FILE="" 236 fi 237 238 AC_SUBST([METADB]) 239 AC_SUBST([METADB_FILE]) 240 241 AC_ARG_WITH([hpc], 242 [AS_HELP_STRING([--with-hpc=yes], [Specifies if you need to activate HPC support])], 243 [HPCWITH="$withval"], [HPCWITH="no"]) 244 245 246 AC_ARG_WITH([ssh2], 247 [AS_HELP_STRING([--with-ssh2=PATH], [Specifies an alternative location for the ssh2 library])], 248 [SSH2PATH="$withval"], [SSH2PATH="/usr"]) 249 250 if test "x$HPCWITH" = "xyes"; then 251 HPC_FILES="service_internal_hpc.o sshapi.o" 252 HPC_ENABLED="-DUSE_HPC" 253 HPC_CPPFLAGS="" 254 HPC_LDFLAGS="" 255 # Extract the linker and include flags 256 SSH2_LDFLAGS="-L$SSH2PATH/lib -lssh2" 257 SSH2_CPPFLAGS="-I$SSH2PATH/include" 258 # Check headers file 259 CPPFLAGS_SAVE="$CPPFLAGS" 260 CPPFLAGS="$SSH2_CPPFLAGS" 261 LIBS_SAVE="$LIBS" 262 LIBS="$SSH2_LDFLAGS" 263 264 AC_CHECK_HEADERS([libssh2.h], 265 [], [AC_MSG_ERROR([could not find headers related to libssh2])]) 266 AC_CHECK_LIB([ssh2], [libssh2_session_init]) 267 268 LIBS="$LIBS_SAVE" 269 fi 270 271 AC_SUBST([HPC_CPPFLAGS]) 272 AC_SUBST([HPC_LDFLAGS]) 273 AC_SUBST([HPC_ENABLED]) 274 AC_SUBST([HPC_FILES]) 275 276 AC_SUBST([SSH2_CPPFLAGS]) 277 AC_SUBST([SSH2_LDFLAGS]) 278 147 279 # =========================================================================== 148 280 # Detect if libxml2 is installed … … 400 532 AC_SUBST([MS_LIBS]) 401 533 AC_SUBST([MS_FILE]) 534 AC_SUBST([MS_VERSION]) 535 536 # =========================================================================== 537 # Detect if R is installed 538 # =========================================================================== 539 540 AC_ARG_WITH([r], 541 [AS_HELP_STRING([--with-r=PATH], [To enable python support or Specifies an alternative directory for R installation, disabled by default])], 542 [R_PATH="$withval"; R_ENABLED="-DUSE_R"], [R_ENABLED=""]) 543 544 if test -z "$R_ENABLED" 545 then 546 R_FILE="" 547 else 548 R_FILE="service_internal_r.o" 549 # Extract the linker and include flags 550 R_LDFLAGS="-L$R_PATH/lib/ -lR" 551 R_CPPFLAGS="-I$R_PATH/include/" 552 553 # Check headers file 554 CPPFLAGS_SAVE="$CPPFLAGS" 555 CPPFLAGS="$R_CPPFLAGS" 556 AC_CHECK_HEADERS([RInternals.h], 557 [], [AC_MSG_ERROR([could not find headers include related to R])]) 558 559 # Ensure we can link against libphp 560 #LIBS_SAVE="$LIBS" 561 #LIBS="$R_LDFLAGS" 562 #AC_CHECK_LIB([$LIBS], [R_tryEval], [], [AC_MSG_ERROR([could not find libR])], []) 563 #LIBS="$LIBS_SAVE" 564 fi 565 566 AC_SUBST([R_CPPFLAGS]) 567 AC_SUBST([R_LDFLAGS]) 568 AC_SUBST([R_ENABLED]) 569 AC_SUBST([R_FILE]) 570 402 571 403 572 # =========================================================================== … … 646 815 647 816 AC_LANG([C++]) 648 echo $JAVA_CPPFLAGS817 #echo $JAVA_CPPFLAGS 649 818 # Check headers file (second time we check that in fact) 650 819 CPPFLAGS_SAVE="$CPPFLAGS" … … 696 865 697 866 AC_LANG([C++]) 698 echo $JAVA_CPPFLAGS867 #echo $JAVA_CPPFLAGS 699 868 # Check headers file (second time we check that in fact) 700 869 CPPFLAGS_SAVE="$CFLAGS" … … 888 1057 [SAGAPATH="$withval"], [SAGAPATH=""]) 889 1058 1059 AC_ARG_WITH([saga-version], 1060 [AS_HELP_STRING([--with-saga-version=VERSION], [Specifies the SAGA-GIS version number])], 1061 [SAGAVERS="$withval"], [SAGAVERS="2"]) 1062 890 1063 if test -z "$SAGAPATH" 891 1064 then … … 903 1076 WX_ISSUE="-D_WX_WXCRTVARARG_H_" 904 1077 SAGA_DEFS="-D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -DMODULE_LIBRARY_PATH=\\\"$SAGAPATH/lib/saga\\\"" 905 SAGA_CPPFLAGS=" -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"1078 SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE" 906 1079 SAGA_LDFLAGS="-fPIC `$WXCFG --unicode=yes --static=no --libs` -lsaga_api" 907 1080 SAGA_ENABLED="-DUSE_SAGA" … … 914 1087 LIBS_SAVE="$LIBS" 915 1088 LIBS="$SAGA_LDFLAGS" 916 AC_CHECK_HEADERS([module_library.h], 917 [], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])]) 918 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "module_library.h"],[SG_Get_Module_Library_Manager();]])], 919 [AC_MSG_RESULT([checking for SG_Get_Module_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Module_Library_Manager... failed])]) 1089 if test "$SAGAVERS" == "2"; then 1090 AC_CHECK_HEADERS([module_library.h], 1091 [], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])]) 1092 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "module_library.h"],[SG_Get_Module_Library_Manager();]])], 1093 [AC_MSG_RESULT([checking for SG_Get_Module_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Module_Library_Manager... failed])]) 1094 else 1095 AC_CHECK_HEADERS([tool_library.h], 1096 [], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])]) 1097 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "tool_library.h"],[SG_Get_Tool_Library_Manager();]])], 1098 [AC_MSG_RESULT([checking for SG_Get_Tool_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Tool_Library_Manager... failed])]) 1099 fi 1100 920 1101 LIBS="$LIBS_SAVE" 921 1102 AC_LANG_POP([C++]) -
TabularUnified trunk/zoo-project/zoo-kernel/main_conf_read.y ¶ ¶
r790 r917 87 87 ; 88 88 89 pair: PAIR { curr_key=zStrdup($1);}89 pair: PAIR {if(curr_key!=NULL) free(curr_key);curr_key=zStrdup($1);} 90 90 | EPAIR { 91 91 if(current_content==NULL) … … 99 99 } 100 100 free(curr_key); 101 curr_key=NULL; 101 102 } 102 | SPAIR { curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }103 | SPAIR {if(curr_key!=NULL) free(curr_key);curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); } 103 104 ; 104 105 … … 162 163 free(current_content); 163 164 } 165 if(curr_key!=NULL){ 166 free(curr_key); 167 } 164 168 165 169 fclose(crin); -
TabularUnified trunk/zoo-project/zoo-kernel/makefile.vc ¶ ¶
r788 r917 50 50 $(CPP) $(CFLAGS) /c caching.c 51 51 52 service_json.obj: service_json.c service_json.h 53 $(CPP) $(CFLAGS) /c service_json.c 54 52 55 request_parser.obj: request_parser.c request_parser.h 53 56 $(CPP) $(CFLAGS) /c request_parser.c … … 71 74 $(CPP) /c $(CFLAGS) service_internal_ruby.c 72 75 76 service_internal_mono.obj: service_internal_mono.c service_internal_mono.h service.h 77 $(CPP) /c $(MONO_CLAGS) $(CFLAGS) service_internal_mono.c 78 73 79 service_internal_python.obj: service_internal_python.c service.h 74 80 $(CPP) /c $(CFLAGS) service_internal_python.c … … 89 95 $(CPP) /c $(CFLAGS) $(PHP_CFLAGS) service_internal_php.c 90 96 97 service_callback.obj: service_callback.c service_callback.h service.h 98 $(CPP) /c $(CFLAGS) service_callback.c 99 91 100 service_internal_php7.obj: service_internal_php7.c service_internal_php.h service.h 92 101 $(CPP) /c $(CFLAGS) $(PHP_CFLAGS) service_internal_php7.c … … 95 104 link /dll /out:$(LIBZOO_SERVICE) ./service.obj ./service_internal.obj ./sqlapi.obj $(LDFLAGS) /FORCE:MULTIPLE 96 105 97 $(PROGRAMNAME): version.h $(LIBZOO_SERVICE) zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $( RUBY_FILE) $(PHP_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj request_parser.obj response_print.obj server_internal.obj caching.obj98 link zoo_loader.obj request_parser.obj response_print.obj server_internal.obj caching.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj zoo_service_loader.obj ./libzoo_service.lib /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI)106 $(PROGRAMNAME): version.h $(LIBZOO_SERVICE) zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(MONO_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj request_parser.obj response_print.obj server_internal.obj caching.obj service_json.obj service_callback.obj 107 link zoo_loader.obj request_parser.obj response_print.obj server_internal.obj caching.obj service_json.obj service_callback.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(MONO_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj zoo_service_loader.obj ./libzoo_service.lib /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI) $(JSONC_LIB) $(PTHREADS_LIB) $(XSLT_LIB) 99 108 100 zcfg2yaml: version.h zcfg2yaml.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj101 link zcfg2yaml.obj server_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj response_print.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj ./libzoo_service.lib /out:zcfg2yaml.exe $(LDFLAGS) $(LDFLAGSCGI)109 zcfg2yaml: version.h zcfg2yaml.obj zoo_service_loader.obj service_internal.obj caching.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(MONO_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj 110 link zcfg2yaml.obj server_internal.obj caching.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(MONO_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj response_print.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj ./libzoo_service.lib /out:zcfg2yaml.exe $(LDFLAGS) $(LDFLAGSCGI) 102 111 103 112 clean: … … 105 114 106 115 embed-manifest: zoo_loader.cgi 107 mt.exe -manifest zoo_loader.cgi.manifest -outputresource:zoo_loader.cgi; 1116 mt.exe -manifest zoo_loader.cgi.manifest -outputresource:zoo_loader.cgi; -
TabularUnified trunk/zoo-project/zoo-kernel/mimetypes.h ¶ ¶
r601 r917 180 180 { "application/vnd.dece.unspecified", "uvx" }, 181 181 { "application/vnd.dece.zip", "uvz" }, 182 { "application/vnd.denovo.fcselayout-link", "fe_launch" }, 182 { "application/vnd.denovo.fcselayout-link", "fe_launch" }, 183 183 { "application/vnd.dna", "dna" }, 184 184 { "application/vnd.dolby.mlp", "mlp" }, … … 818 818 */ 819 819 static map* getFileExtensionMap(const char* mimeType, bool* hasExt) { 820 map* ext = createMap("extension", "txt"); 821 *hasExt = false; 822 823 if (mimeType != NULL) { 824 for (int i = 0; i < NUM_MIME_TYPES; i++) { 825 if(strncmp(mimeType, MIME[i][M_Type], strlen(MIME[i][M_Type])) == 0) { 826 free(ext->value); 827 ext->value = zStrdup(MIME[i][M_Extension]); 828 *hasExt = true; 829 break; 830 } 831 } 832 if (*hasExt == false && strncmp(mimeType, "image/", 6) == 0) { 833 free(ext->value); 834 ext->value = zStrdup(strstr(mimeType, "/") + 1); 835 } 836 } 837 return ext; 838 } 820 839 821 map* ext = createMap("extension", "txt"); 822 *hasExt = false; 823 824 if (mimeType != NULL) { 825 for (int i = 0; i < NUM_MIME_TYPES; i++) { 826 if (strncmp(mimeType, MIME[i][M_Type], strlen(MIME[i][M_Type])) == 0) { 827 ext->value = zStrdup(MIME[i][M_Extension]); 828 *hasExt = true; 829 break; 830 } 831 } 832 if (*hasExt == false && strncmp(mimeType, "image/", 6) == 0) { 833 ext->value = zStrdup(strstr(mimeType, "/") + 1); 834 } 835 } 836 return ext; 840 static int isGeographic(const char* mimeType){ 841 char* imageMimeType[4]={ 842 "image/tiff", 843 "image/png", 844 "image/jpeg", 845 "application/vnd.google-earth.kmz" 846 }; 847 char* vectorMimeType[5]={ 848 "text/xml", 849 "application/json", 850 "application/gml+xml", 851 "application/zip", 852 "application/vnd.google-earth.kml+xml" 853 }; 854 int i=0; 855 for(;i<4;i++){ 856 if(strncmp(imageMimeType[i],mimeType,strlen(imageMimeType[i]))==0) 857 return 1; 858 } 859 i=0; 860 for(;i<5;i++){ 861 if(strncmp(vectorMimeType[i],mimeType,strlen(vectorMimeType[i]))==0) 862 return 2; 863 } 864 return -1; 837 865 } -
TabularUnified trunk/zoo-project/zoo-kernel/nmake.opt ¶ ¶
r788 r917 87 87 !ENDIF 88 88 89 !IFDEF MONO_DIR 90 MONO_CFLAGS=-DUSE_MONO -I"$(MONO_DIR)"\msvc -I"$(MONO_DIR)"\msvc\include -I"$(MONO_DIR)" 91 MONO_LDFLAGS=/LIBPATH:"$(MONO_DIR)/msvc/build/sgen/x64/lib/Release" mono-2.0-sgen.lib 92 MONO_FILE=service_internal_mono.obj 93 !ENDIF 94 89 95 !IFNDEF ZOOK_DIR 90 96 ZOOK_DIR=. … … 100 106 !ENDIF 101 107 102 CFLAGS= $(DB_FLAGS) $(MS_DEFS) $(INCLUDES) $(CFLAGS1) /nologo /MD /W3 /EHsc /Ox /D_CRT_SECURE_NO_WARNINGS /DWIN32 /DPROGRAMNAME=\"$(PROGRAMNAME)\" $(CJFLAGS) -I$(ZOOK_DIR) $(RUBY_CFLAGS) -I./ $(JAVA_CFLAGS) $(MS_CFLAGS) -I$(TROOT)\..\..\thirds\dirent-win32 -I$(INTL_DIR) -I$(CURL_DIR)\include -I$(XML2_DIR)\include -I$(GDAL_DIR)\port $(JS_CFLAGS) -I$(GDAL_DIR)\ogr -I$(GDAL_DIR)\gcore -I$(GD_DIR) -I$(ICONV_DIR) -I$(TROOT)\..\..\thirds\include -I$(TROOT)\..\..\thirds\cgic206 -I$(PYTHON_CPATH)\include -I$(SSL_DIR)/inc32 -I$(FCGI_DIR)\include $(PY_CFLAGS) $(PHP_CFLAGS) -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 108 !IFDEF WIN32_DEBUG 109 WIN32_DBG=-DWIN32_DEBUG 110 !ENDIF 111 112 CFLAGS=$(MONO_CFLAGS) $(WIN32_DBG) $(DB_FLAGS) $(MS_DEFS) $(INCLUDES) $(CFLAGS1) /nologo /MD /W3 /EHsc /Ox /D_CRT_SECURE_NO_WARNINGS /DWIN32 /DPROGRAMNAME=\"$(PROGRAMNAME)\" $(CJFLAGS) -I$(ZOOK_DIR) $(RUBY_CFLAGS) -I./ $(JAVA_CFLAGS) $(MS_CFLAGS) -I$(TROOT)\..\..\thirds\dirent-win32 -I$(INTL_DIR) -I$(CURL_DIR)\include -I$(XML2_DIR)\include -I$(GDAL_DIR)\port $(JS_CFLAGS) -I$(GDAL_DIR)\ogr -I$(GDAL_DIR)\gcore -I$(GD_DIR) -I$(ICONV_DIR) -I$(TROOT)\..\..\thirds\include -I$(TROOT)\..\..\thirds\cgic206 -I$(PYTHON_CPATH)\include -I$(SSL_DIR)/inc32 -I$(FCGI_DIR)\include $(PY_CFLAGS) $(PHP_CFLAGS) -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 103 113 104 114 LDFLAGSCGI=$(TROOT)/../../thirds/cgic206/libcgic.lib 105 LDFLAGS=$( FCGI_DIR)/libfcgi/Release/libfcgi.lib $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) $(RUBY_LDFLAGS) $(PHP_LDFLAGS) /machine:i386115 LDFLAGS=$(MONO_LDFLAGS) $(FCGI_DIR)/libfcgi/Release/libfcgi.lib $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) $(RUBY_LDFLAGS) $(PHP_LDFLAGS) /machine:i386 -
TabularUnified trunk/zoo-project/zoo-kernel/request_parser.c ¶ ¶
r889 r917 28 28 #include "response_print.h" 29 29 #include "caching.h" 30 #include "cgic.h" 30 31 31 32 /** … … 154 155 addToMap(cursor->content,"base64_value",tmp->value); 155 156 int size=0; 156 char *s= strdup(tmp->value);157 char *s=zStrdup(tmp->value); 157 158 free(tmp->value); 158 159 tmp->value=base64d(s,strlen(s),&size); … … 174 175 addToMap(cursor->content,key,tmp->value); 175 176 int size=0; 176 char *s= strdup(tmp->value);177 char *s=zStrdup(tmp->value); 177 178 free(tmp->value); 178 179 tmp->value=base64d(s,strlen(s),&size); … … 521 522 int l = 0; 522 523 map* version=getMapFromMaps(*main_conf,"main","rversion"); 524 map* memory=getMapFromMaps(*main_conf,"main","memory"); 523 525 int vid=getVersionId(version->value); 524 526 for (k=0; k < nodes->nodeNr; k++) … … 533 535 xmlChar *val = xmlGetProp (cur, BAD_CAST "id"); 534 536 tmpmaps = createMaps((char *) val); 537 xmlFree(val); 535 538 } 536 539 … … 624 627 tmpmaps->content = 625 628 createMap (refs[l], (char *) val); 626 627 629 map *ltmp = getMap (tmpmaps->content, "method"); 628 630 if (l == 4 ) 629 631 { 630 if ((ltmp==NULL || strncasecmp (ltmp->value, "POST",4) != 0)) // 631 //if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0)) 632 if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0)) 632 633 { 633 634 if (loadRemoteFile … … 751 752 map *btmp = 752 753 getMap (tmpmaps->content, "Reference"); 754 addToMap (tmpmaps->content, "Body", tmp); 753 755 if (btmp != NULL) 754 756 { … … 759 761 xmlStrlen(btmps), 760 762 INTERNET_FLAG_NO_CACHE_WRITE, 761 0); 763 0, 764 *main_conf); 762 765 addIntToMap (tmpmaps->content, "Order", hInternet->nb); 763 766 } … … 778 781 xmlGetProp (cur3, BAD_CAST "href"); 779 782 HINTERNET bInternet, res1, res; 783 maps *tmpConf=createMaps("main"); 784 tmpConf->content=createMap("memory","load"); 780 785 bInternet = InternetOpen ( 781 786 #ifndef WIN32 … … 785 790 INTERNET_OPEN_TYPE_PRECONFIG, 786 791 NULL, NULL, 0); 792 #ifndef WIN32 787 793 if (!CHECK_INET_HANDLE (bInternet)) 788 794 fprintf (stderr, 789 795 "WARNING : bInternet handle failed to initialize"); 796 #endif 790 797 bInternet.waitingRequests[0] = 791 strdup ((char *) val);798 zStrdup ((char *) val); 792 799 res1 = 793 800 InternetOpenUrl (&bInternet, … … 795 802 [0], NULL, 0, 796 803 INTERNET_FLAG_NO_CACHE_WRITE, 797 0); 804 0, 805 tmpConf); 798 806 processDownloads (&bInternet); 807 freeMaps(&tmpConf); 808 free(tmpConf); 799 809 char *tmp = 800 810 (char *) … … 816 826 &bRead); 817 827 tmp[bInternet.ihandle[0].nDataLen] = 0; 818 InternetCloseHandle (&bInternet); 828 InternetCloseHandle(&bInternet); 829 addToMap (tmpmaps->content, "Body", tmp); 819 830 map *btmp = 820 831 getMap (tmpmaps->content, "href"); … … 829 840 strlen(tmp), 830 841 INTERNET_FLAG_NO_CACHE_WRITE, 831 0); 842 0, 843 *main_conf); 832 844 addIntToMap (tmpmaps->content, "Order", hInternet->nb); 833 845 } 834 846 free (tmp); 847 xmlFree (val); 835 848 } 836 849 } … … 895 908 } 896 909 } 897 898 910 899 911 while (cur4 != NULL) … … 967 979 968 980 map *test = getMap (tmpmaps->content, "encoding"); 969 970 981 if (test == NULL) 971 { 982 { 972 983 if (tmpmaps->content != NULL) 973 984 addToMap (tmpmaps->content, "encoding", … … 979 990 } 980 991 981 if (getMap(tmpmaps->content,"dataType")==NULL && strcasecmp (test->value, "base64") != 0) 982 { 983 xmlChar *mv = xmlNodeListGetString (doc, 984 cur4->xmlChildrenNode, 985 1); 992 if (getMap(tmpmaps->content,"dataType")==NULL && test!=NULL && strcasecmp (test->value, "base64") != 0) 993 { 994 xmlChar *mv = NULL; 995 /*if(cur4!=NULL && cur4->xmlChildrenNode!=NULL) 996 xmlChar *mv = xmlNodeListGetString (doc, 997 cur4->xmlChildrenNode, 998 1);*/ 986 999 map *ltmp = 987 1000 getMap (tmpmaps->content, "mimeType"); 988 if ( mv == NULL989 || 1001 if (/*mv == NULL 1002 ||*/ 990 1003 (xmlStrcasecmp 991 1004 (cur4->name, BAD_CAST "ComplexData") == 0 … … 1025 1038 buffersize); 1026 1039 }else{ 1040 1027 1041 if(xmlStrcasecmp 1028 1042 (cur4->name, BAD_CAST "BoundingBoxData") == 0){ … … 1039 1053 xmlNodePtr cur5 = cur4->children; 1040 1054 while (cur5 != NULL 1055 && cur5->type != XML_ELEMENT_NODE 1056 && cur5->type != XML_TEXT_NODE 1041 1057 && cur5->type != XML_CDATA_SECTION_NODE) 1042 1058 cur5 = cur5->next; 1043 1059 if (cur5 != NULL 1044 && cur5->type == XML_CDATA_SECTION_NODE){ 1045 if(mv!=NULL) 1046 xmlFree(mv); 1047 mv=xmlStrdup(cur5->content); 1060 && cur5->type != XML_CDATA_SECTION_NODE 1061 && cur5->type != XML_TEXT_NODE) 1062 { 1063 xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); 1064 int buffersize; 1065 xmlDocSetRootElement (doc1, cur5); 1066 xmlDocDumpFormatMemoryEnc (doc1, &mv, 1067 &buffersize, 1068 "utf-8", 0); 1069 addIntToMap (tmpmaps->content, "size", 1070 buffersize); 1071 } 1072 else if (cur5 != NULL)/* 1073 && cur5->type == XML_CDATA_SECTION_NODE)*/{ 1074 xmlFree(mv); 1075 if(cur5->content!=NULL){ 1076 mv=xmlStrdup(cur5->content); 1077 } 1048 1078 } 1049 1079 } … … 1088 1118 cur2 = cur2->next; 1089 1119 } 1120 } 1121 if(memory!=NULL && strncasecmp(memory->value,"load",4)!=0) 1122 if(getMap(tmpmaps->content,"to_load")==NULL){ 1123 addToMap(tmpmaps->content,"to_load","false"); 1090 1124 } 1091 1125 { … … 1123 1157 } 1124 1158 } 1125 else 1159 else{ 1126 1160 addMapsToMaps (request_output, tmpmaps); 1161 } 1127 1162 } 1128 1163 freeMaps (&tmpmaps); … … 1198 1233 const char ress[4][13] = 1199 1234 { "mimeType", "encoding", "schema", "transmission" }; 1235 xmlFree (val); 1200 1236 for (l = 0; l < 4; l++){ 1201 1237 val = xmlGetProp (cur, BAD_CAST ress[l]); … … 1217 1253 while (ccur != NULL){ 1218 1254 if(ccur->type == XML_ELEMENT_NODE){ 1219 char *xpathExpr=(char*)malloc(6 5+strlen(tmpmaps->name));1220 sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name); 1255 char *xpathExpr=(char*)malloc(66+strlen(tmpmaps->name)); 1256 sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name); 1221 1257 xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr); 1222 1258 xmlNodeSet* cnodes = tmpsptr->nodesetval; 1223 1259 xmlParseOutputs2(main_conf,request_inputs,&tmpmaps->child,doc,cnodes); 1260 xmlXPathFreeObject (tmpsptr); 1261 free(xpathExpr); 1224 1262 break; 1225 1263 } … … 1470 1508 1471 1509 xmlInitParser (); 1472 //xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER); 1473 xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER | XML_PARSE_HUGE); // 1510 xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER); 1474 1511 1475 1512 /** … … 1503 1540 else 1504 1541 addToMap(*request_inputs,"mode","auto"); 1542 xmlFree(val); 1505 1543 val = xmlGetProp (cur, BAD_CAST "response"); 1506 1544 if(val!=NULL){ … … 1515 1553 addToMap(*request_inputs,"ResponseDocument",""); 1516 1554 } 1555 xmlFree(val); 1517 1556 } 1518 1557 } … … 1768 1807 #endif 1769 1808 targetFile = 1770 open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,1809 zOpen (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, 1771 1810 S_IRWXU | S_IRGRP | S_IROTH); 1772 1811 if (targetFile < 0) … … 1788 1827 addToMap (tmpReqI->content, "lref", storageNameOnServer); 1789 1828 cgiFormFileClose (file); 1790 close (targetFile);1829 zClose (targetFile); 1791 1830 free(fileNameOnServer); 1792 1831 free(storageNameOnServer); … … 1820 1859 if (r_inputs == NULL){ 1821 1860 if(mandatory>0){ 1822 c onst char *replace=_("Mandatory parameter <%s> was not specified");1861 char *replace=_("Mandatory parameter <%s> was not specified"); 1823 1862 char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char)); 1824 1863 sprintf(message,replace,toCheck); … … 1869 1908 } 1870 1909 if(hasValidValue<0){ 1871 c onst char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value.");1910 char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value."); 1872 1911 nb=0; 1873 1912 char *vvalues=NULL; 1874 c onst char* num=_("is");1913 char* num=_("is"); 1875 1914 while(avalues[nb]!=NULL){ 1876 1915 char *tvalues; … … 1920 1959 } 1921 1960 } 1961 1962 /** 1963 * Parse cookie contained in request headers. 1964 * 1965 * @param conf the conf maps containinfg the main.cfg 1966 * @param cookie the 1967 */ 1968 void parseCookie(maps** conf,const char* cookie){ 1969 char* tcook=zStrdup(cookie); 1970 char *token, *saveptr; 1971 token = strtok_r (tcook, "; ", &saveptr); 1972 maps* res=createMaps("cookies"); 1973 while (token != NULL){ 1974 char *token1, *saveptr1, *name; 1975 int i=0; 1976 token1 = strtok_r (token, "=", &saveptr1); 1977 while (token1 != NULL){ 1978 if(i==0){ 1979 name=zStrdup(token1); 1980 i++; 1981 } 1982 else{ 1983 if(res->content==NULL) 1984 res->content=createMap(name,token1); 1985 else 1986 addToMap(res->content,name,token1); 1987 free(name); 1988 name=NULL; 1989 i=0; 1990 } 1991 token1 = strtok_r (NULL, "=", &saveptr1); 1992 } 1993 if(name!=NULL) 1994 free(name); 1995 token = strtok_r (NULL, "; ", &saveptr); 1996 } 1997 addMapsToMaps(conf,res); 1998 freeMaps(&res); 1999 free(res); 2000 free(tcook); 2001 } -
TabularUnified trunk/zoo-project/zoo-kernel/request_parser.h ¶ ¶
r866 r917 45 45 int kvpParseOutputs(maps**,map *,maps**); 46 46 int xmlParseInputs(maps**,service*,maps**,xmlDocPtr,xmlNodeSet*,HINTERNET*); 47 int xmlParseBoundingBox(maps** main_conf,map** current_input,xmlDocPtr doc); 47 48 int xmlParseOutputs(maps**,map**,maps**,xmlDocPtr,xmlNodePtr,bool); 48 49 int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*); … … 50 51 void checkValidValue(map*,map**,const char*,const char**,int); 51 52 int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*); 52 53 void parseCookie(maps**,const char*); 54 53 55 #ifdef __cplusplus 54 56 } -
TabularUnified trunk/zoo-project/zoo-kernel/response_print.c ¶ ¶
r889 r917 23 23 */ 24 24 25 #include "service.h" 25 26 #include "response_print.h" 26 27 #include "request_parser.h" … … 31 32 #else 32 33 #include "cpl_vsi.h" 34 #endif 35 #ifdef USE_CALLBACK 36 #include "service_callback.h" 33 37 #endif 34 38 … … 75 79 } 76 80 if(prefix!=NULL){ 77 char* tmp0= strdup(serv->name);81 char* tmp0=zStrdup(serv->name); 78 82 free(serv->name); 79 83 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); … … 179 183 nbNs++; 180 184 currId=0; 181 nsName[currId]= strdup(name);185 nsName[currId]=zStrdup(name); 182 186 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 183 187 }else{ … … 186 190 nbNs++; 187 191 currId=nbNs-1; 188 nsName[currId]= strdup(name);192 nsName[currId]=zStrdup(name); 189 193 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 190 194 } … … 251 255 if(soap!=NULL && strcasecmp(soap->value,"true")==0){ 252 256 int lNbNs=nbNs; 253 nsName[lNbNs]= strdup("soap");257 nsName[lNbNs]=zStrdup("soap"); 254 258 usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 255 259 nbNs++; 256 260 xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); 257 nsName[nbNs]= strdup("soap");261 nsName[nbNs]=zStrdup("soap"); 258 262 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 259 263 nbNs++; 260 nsName[nbNs]= strdup("xsi");264 nsName[nbNs]=zStrdup("xsi"); 261 265 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 262 266 nbNs++; … … 338 342 } 339 343 else{ 340 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");341 xmlAddChild(nc4,xmlNewText(BAD_CAST buff));342 344 if(dcount==0){ 343 345 if(vid==0){ 346 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 347 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 344 348 xmlAddChild(nc2,nc4); 345 349 xmlAddChild(nc1,nc2); … … 361 365 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 362 366 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 363 364 365 366 367 if(vid==0) 368 xmlAddChild(nc3,nc4); 369 else 370 xmlAddChild(nc1,nc4); 367 371 } 368 372 } … … 590 594 map* tmp=getMap(toto1->content,"serverAddress"); 591 595 if(tmp!=NULL){ 592 SERVICE_URL = strdup(tmp->value);596 SERVICE_URL = zStrdup(tmp->value); 593 597 } 594 598 else 595 SERVICE_URL = strdup("not_defined");599 SERVICE_URL = zStrdup("not_defined"); 596 600 } 597 601 else 598 SERVICE_URL = strdup("not_defined");602 SERVICE_URL = zStrdup("not_defined"); 599 603 600 604 for(j=0;j<nbSupportedRequests;j++){ … … 644 648 * @return the generated wps:ProcessOfferings xmlNodePtr 645 649 */ 646 void printGetCapabilitiesForProcess(registry *reg, maps* m,xml NodePtr nc,service* serv){650 void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){ 647 651 xmlNsPtr ns,ns_ows,ns_xml,ns_xlink; 648 xmlNodePtr n=NULL,nc1,nc2 ;652 xmlNodePtr n=NULL,nc1,nc2,nc3; 649 653 map* version=getMapFromMaps(m,"main","rversion"); 650 654 int vid=getVersionId(version->value); … … 667 671 limit=7; 668 672 } 673 nc3=NULL; 674 map* sType=getMap(serv->content,"serviceType"); 669 675 for(;i<limit;i+=2){ 670 676 if(capabilities[vid][i]==NULL) … … 682 688 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value); 683 689 } 684 else 685 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 690 else{ 691 if(i==3 && vid==1 && sType!=NULL && strstr(sType->value,"HPC")!=NULL) 692 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss"); 693 else 694 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 695 } 686 696 } 687 697 } … … 690 700 printDescription(nc1,ns_ows,serv->name,serv->content,vid); 691 701 tmp1=serv->metadata; 692 while(tmp1!=NULL){ 693 nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 694 xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 695 xmlAddChild(nc1,nc2); 696 tmp1=tmp1->next; 697 } 698 702 703 addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink,vid); 704 tmp1=serv->additional_parameters; 705 int fromDb=-1; 706 map* test=getMap(serv->content,"fromDb"); 707 if(test!=NULL && strncasecmp(test->value,"true",4)==0) 708 fromDb=1; 709 addAdditionalParameters(tmp1,doc,nc1,ns_ows,ns_xlink,fromDb); 710 711 if(nc3!=NULL) 712 xmlAddChild(nc1,nc3); 699 713 xmlAddChild(nc,nc1); 700 714 } 715 701 716 } 702 717 … … 708 723 * @param content the servive main content created from the zcfg file 709 724 * @param vid the version identifier (0 for 1.0.0 and 1 for 2.0.0) 710 */ 711 void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid){ 725 * @param serviceType string containing the current service type 726 */ 727 void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid,map* serviceType){ 712 728 int limit=7; 713 729 for(int i=1;i<limit;i+=2){ … … 728 744 } 729 745 else{ 730 if( vid==0 && i>=2)731 xmlNew Prop(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);746 if(i==3 && vid==1 && serviceType!=NULL && strstr(serviceType->value,"HPC")!=NULL) 747 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss"); 732 748 else 733 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 734 } 749 if(vid==0 && i>=2) 750 xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 751 else 752 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 753 } 754 } 755 } 756 757 /** 758 * Add a Metadata node to any existing node. 759 * @param meta the map defining the additional parameters 760 * @param doc the XML document used 761 * @param nb the node to add the additional parameters 762 * @param ns_ows the OWS namespace 763 * @param ns_xlink the xlink namespace 764 * @param vid the version of WPS to use (0 for 1.0.0 and 1 for 2.0) 765 */ 766 void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int vid){ 767 int hasTitle=-1; 768 int hasValue=-1; 769 xmlNodePtr nc1; 770 map* oMeta=meta; 771 int isAdditionalParameters=-1; 772 int level=0; 773 map* test=getMap(meta,"title"); 774 if(test!=NULL) 775 level+=1; 776 test=getMap(meta,"href"); 777 if(test!=NULL) 778 level+=1; 779 test=getMap(meta,"role"); 780 if(test!=NULL) 781 level+=1; 782 if(count(oMeta)>level+1) 783 isAdditionalParameters=1; 784 char *ctitle=NULL; 785 while(meta!=NULL){ 786 if(hasTitle<0) 787 if(isAdditionalParameters<0) 788 nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 789 else 790 if(hasValue<0) 791 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 792 if(strncasecmp(meta->name,"title",5)==0 || 793 strcasecmp(meta->name,"href")==0 || 794 strcasecmp(meta->name,"role")==0 ){ 795 int index=5; 796 if(strncasecmp(meta->name,"title",5)==0){ 797 index=6; 798 hasTitle=1; 799 if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){ 800 xmlAddChild(nc,nc1); 801 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 802 free(ctitle); 803 ctitle=NULL; 804 } 805 if(ctitle==NULL){ 806 char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char)); 807 snprintf(tmp,index,"%s",meta->name); 808 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value); 809 free(tmp); 810 } 811 if(ctitle!=NULL) 812 free(ctitle); 813 ctitle=zStrdup(meta->value); 814 } 815 }else{ 816 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter"); 817 xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name"); 818 xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name)); 819 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 820 xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value)); 821 xmlAddChild(nc2,nc3); 822 xmlAddChild(nc2,nc4); 823 xmlAddChild(nc1,nc2); 824 hasTitle=-1; 825 } 826 meta=meta->next; 827 if(hasTitle<0){ 828 hasValue=1; 829 if(isAdditionalParameters){ 830 if(vid==0){ 831 meta=NULL; 832 break; 833 }else 834 xmlAddChild(nc,nc1); 835 } 836 } 837 } 838 if(oMeta!=NULL && hasValue<0 && nc1!=NULL){ 839 xmlAddChild(nc,nc1); 840 } 841 } 842 843 /** 844 * Add AdditionalParameters nodes to any existing node. 845 * @param meta the map defining the additional parameters 846 * @param doc the XML document used 847 * @param nb the node to add the additional parameters 848 * @param ns_ows the OWS namespace 849 * @param ns_xlink the xlink namespace 850 * @param fromDb 1 if the metadata has been extracted from the metadb, 851 * 0 otherwise 852 */ 853 void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){ 854 int hasTitle=-1; 855 int hasValue=-1; 856 int toAddAtEnd=-1; 857 int cnt=0; 858 xmlNodePtr* ncr=NULL; 859 xmlNodePtr nc1; 860 map* oMeta=meta; 861 int isAdditionalParameters=-1; 862 int level=0; 863 map* test=getMap(meta,"title"); 864 map* otitle=getMap(meta,"title"); 865 map* length=getMap(meta,"length"); 866 int len=0; 867 char *ctitle=NULL; 868 869 if(test!=NULL) 870 level+=1; 871 test=getMap(meta,"href"); 872 if(test!=NULL) 873 level+=1; 874 test=getMap(meta,"role"); 875 if(test!=NULL) 876 level+=1; 877 if(count(oMeta)>level+1) 878 isAdditionalParameters=1; 879 880 while(meta!=NULL){ 881 if(hasTitle<0 && hasValue<0){ 882 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 883 } 884 if(strncasecmp(meta->name,"title",5)==0 || 885 strcasecmp(meta->name,"href")==0 || 886 strcasecmp(meta->name,"role")==0 ){ 887 int index=5; 888 if(strncasecmp(meta->name,"title",5)==0){ 889 index=6; 890 hasTitle=1; 891 if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){ 892 xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1); 893 xmlAddChild(nc,ncTmp); 894 xmlFreeNode(nc1); 895 toAddAtEnd=1; 896 cnt++; 897 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 898 free(ctitle); 899 ctitle=NULL; 900 } 901 if(ctitle==NULL){ 902 char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char)); 903 snprintf(tmp,index,"%s",meta->name); 904 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value); 905 free(tmp); 906 } 907 if(ctitle!=NULL) 908 free(ctitle); 909 ctitle=zStrdup(meta->value); 910 }else{ 911 xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value); 912 } 913 }else{ 914 if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){ 915 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter"); 916 xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name"); 917 xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name)); 918 xmlAddChild(nc2,nc3); 919 if(fromDb<0){ 920 char *mptr; 921 char* meta_values=strtok_r(meta->value,",",&mptr); 922 while(meta_values!=NULL){ 923 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 924 xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values)); 925 xmlAddChild(nc2,nc4); 926 meta_values=strtok_r(NULL,",",&mptr); 927 } 928 }else{ 929 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 930 xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value))); 931 xmlAddChild(nc2,nc4); 932 } 933 xmlAddChild(nc1,nc2); 934 } 935 hasTitle=-1; 936 } 937 meta=meta->next; 938 if(hasTitle<0){ 939 //xmlAddChild(nc,nc1); 940 hasValue=1; 941 }/*else 942 if(ctitle!=NULL) 943 free(ctitle);*/ 944 } 945 if(length!=NULL) 946 len=atoi(length->value); 947 if(otitle!=NULL) 948 len=1; 949 if(cnt<len){ 950 xmlAddChild(nc,nc1); 951 free(ctitle); 735 952 } 736 953 } … … 792 1009 * @return the generated wps:ProcessOfferings xmlNodePtr 793 1010 */ 794 void printDescribeProcessForProcess(registry *reg, maps* m,xml NodePtr nc,service* serv){1011 void printDescribeProcessForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){ 795 1012 xmlNsPtr ns,ns_ows,ns_xlink; 796 1013 xmlNodePtr n,nc1; … … 798 1015 map* version=getMapFromMaps(m,"main","rversion"); 799 1016 int vid=getVersionId(version->value); 1017 int fromDb=-1; 1018 map* serviceType=getMap(serv->content,"serviceType"); 1019 map* test=getMap(serv->content,"fromDb"); 1020 if(test!=NULL && strncasecmp(test->value,"true",4)==0) 1021 fromDb=1; 800 1022 801 1023 n=nc; … … 811 1033 if(vid==0){ 812 1034 nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); 813 attachAttributes(nc,ns,serv->content,vid );1035 attachAttributes(nc,ns,serv->content,vid,NULL); 814 1036 } 815 1037 else{ … … 828 1050 } 829 1051 } 830 attachAttributes(nc2,NULL,serv->content,vid );1052 attachAttributes(nc2,NULL,serv->content,vid,serviceType); 831 1053 map* level=getMap(serv->content,"level"); 832 1054 if(level!=NULL && strcasecmp(level->value,"generic")==0) … … 843 1065 tmp1=serv->metadata; 844 1066 while(tmp1!=NULL){ 845 nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 846 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 847 xmlAddChild(nc,nc1); 1067 addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid); 848 1068 tmp1=tmp1->next; 849 1069 } … … 855 1075 } 856 1076 }else{ 1077 tmp1=serv->metadata; 1078 addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid); 857 1079 addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv); 1080 tmp1=serv->additional_parameters; 1081 if(vid!=0) 1082 addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb); 858 1083 } 859 1084 … … 862 1087 if(vid==0){ 863 1088 nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); 864 printFullDescription( 1,e,"Input",ns,ns_ows,nc1,vid);1089 printFullDescription(doc,1,e,"Input",ns,ns_ows,nc1,vid,fromDb,NULL); 865 1090 xmlAddChild(nc,nc1); 866 1091 } 867 1092 else{ 868 printFullDescription( 1,e,"wps:Input",ns,ns_ows,nc,vid);1093 printFullDescription(doc,1,e,"wps:Input",ns,ns_ows,nc,vid,fromDb,NULL); 869 1094 } 870 1095 } … … 873 1098 if(vid==0){ 874 1099 nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); 875 printFullDescription( 0,e,"Output",ns,ns_ows,nc1,vid);1100 printFullDescription(doc,0,e,"Output",ns,ns_ows,nc1,vid,fromDb,NULL); 876 1101 xmlAddChild(nc,nc1); 877 1102 } 878 1103 else{ 879 printFullDescription( 0,e,"wps:Output",ns,ns_ows,nc,vid);1104 printFullDescription(doc,0,e,"wps:Output",ns,ns_ows,nc,vid,fromDb,serviceType); 880 1105 } 881 1106 if(vid==0) … … 899 1124 * @param nc1 the XML node to use to add the created tree 900 1125 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0) 901 */ 902 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){ 1126 * @param fromDb 1 in case the metadata comes from the DB, -1 in other cases 1127 * @param serviceType the serviceType found in the ZCFG file or the DB 1128 */ 1129 void printFullDescription(xmlDocPtr doc,int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid,int fromDb,const map* serviceType){ 903 1130 xmlNsPtr ns1=NULL; 904 1131 if(vid==1) … … 913 1140 int isAnyValue=1; 914 1141 nc2 = xmlNewNode(NULL, BAD_CAST type); 1142 // Extract min/max Occurence information 915 1143 if(strstr(type,"Input")!=NULL){ 916 1144 tmp1=getMap(e->content,"minOccurs"); … … 935 1163 936 1164 if(e->format!=NULL){ 1165 #ifdef USE_HPC 1166 DEFAULT_OUT: 1167 #endif 937 1168 const char orderedFields[13][14]={ 938 1169 "mimeType", … … 952 1183 //Build the (Literal/Complex/BoundingBox)Data node 953 1184 if(strncmp(type,"Output",6)==0){ 954 if(strncasecmp(e->format,"LITERAL DATA",strlen(e->format))==0)1185 if(strncasecmp(e->format,"LITERAL",7)==0) 955 1186 nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput"); 956 1187 else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) … … 998 1229 strcmp(e->format,"BoundingBoxData")==0){ 999 1230 datatype=2; 1000 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1231 if(vid==0) 1232 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1233 else{ 1234 xmlNodePtr nc6 = xmlNewNode(ns1, BAD_CAST "Format"); 1235 xmlNewProp(nc6,BAD_CAST "mimeType",BAD_CAST "text/xml"); 1236 xmlNewProp(nc6,BAD_CAST "default",BAD_CAST "true"); 1237 xmlAddChild(nc3,nc6); 1238 nc5 = xmlNewNode(NULL, BAD_CAST "SupportedCRS"); 1239 } 1001 1240 } 1002 1241 else{ … … 1039 1278 while(token!=NULL){ 1040 1279 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1041 char *tmps= strdup(token);1280 char *tmps=zStrdup(token); 1042 1281 tmps[strlen(tmps)]=0; 1043 xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); 1282 nc8 = xmlNewText(BAD_CAST tmps); 1283 xmlAddChild(nc7,nc8); 1044 1284 free(tmps); 1045 1285 xmlAddChild(nc6,nc7); … … 1207 1447 strncasecmp(tmp1->name,"range",5)!=0){ 1208 1448 if(datatype!=1){ 1209 char *tmp2=zCapitalize1(tmp1->name); 1210 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1211 free(tmp2); 1449 if(datatype==2 && vid==1){ 1450 nc9 = xmlNewNode(ns, BAD_CAST "SupportedCRS"); 1451 xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true"); 1452 } 1453 else{ 1454 char *tmp2=zCapitalize1(tmp1->name); 1455 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1456 free(tmp2); 1457 } 1212 1458 } 1213 1459 else{ … … 1218 1464 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1219 1465 if(vid==0 || oI>=3){ 1220 if(vid==0 || oI!=4) 1221 xmlAddChild(nc5,nc9); 1466 if(vid==0 || oI!=4){ 1467 if(datatype==2 && vid==1) 1468 xmlAddChild(nc3,nc9); 1469 else 1470 xmlAddChild(nc5,nc9); 1471 } 1222 1472 if(oI==4 && vid==1){ 1223 1473 xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true"); 1224 1474 } 1225 1475 } 1226 else 1227 xmlFree(nc9); 1476 else{ 1477 xmlFreeNode(nc9); 1478 } 1228 1479 if(strcasecmp(tmp1->name,"uom")==0) 1229 1480 hasUOM1=true; 1230 1481 hasUOM=true; 1231 }else 1232 tmp1=tmp1->next; 1482 } 1233 1483 } 1234 1484 } … … 1245 1495 }else{ 1246 1496 if(hasUOM1==false && vid==0){ 1247 xmlFreeNode(nc5); 1248 if(datatype==1) 1497 if(nc5!=NULL) 1498 xmlFreeNode(nc5); 1499 if(datatype==1){ 1249 1500 xmlFreeNode(nc4); 1501 } 1250 1502 } 1251 else 1503 else{ 1252 1504 xmlAddChild(nc3,nc5); 1505 } 1253 1506 } 1254 1507 }else{ 1255 xmlAddChild(nc3,nc5); 1508 if(vid==0) 1509 xmlAddChild(nc3,nc5); 1510 else 1511 xmlFreeNode(nc5); 1256 1512 } 1257 1513 1258 if(datatype !=1&& default1<0){1514 if(datatype==0 && default1<0){ 1259 1515 xmlFreeNode(nc5); 1260 if(datatype!=2) 1516 if(datatype!=2){ 1261 1517 xmlFreeNode(nc4); 1518 } 1262 1519 } 1263 1520 … … 1310 1567 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); 1311 1568 free(tmp2); 1312 //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");1313 1569 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1314 1570 xmlAddChild(nc5,nc9); 1315 /*struct iotype * _ltmp=e->supported;1316 while(_ltmp!=NULL){1317 tmp1=getMap(_ltmp->content,"uom");1318 if(tmp1!=NULL){1319 char *tmp2=zCapitalize(tmp1->name);1320 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);1321 free(tmp2);1322 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));1323 xmlAddChild(nc5,nc9);1324 }1325 _ltmp=_ltmp->next;1326 }*/1327 1328 1571 } 1329 1572 } … … 1340 1583 xmlNsPtr ns_xlink=usedNs[xlinkId]; 1341 1584 1342 while(metadata!=NULL){ 1343 nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata"); 1344 xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value); 1345 xmlAddChild(nc2,nc6); 1346 metadata=metadata->next; 1347 } 1585 addMetadata(metadata,doc,nc2,ns_ows,ns_xlink,vid); 1586 if(vid!=0) 1587 addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb); 1348 1588 1349 1589 } 1350 1590 1351 1591 _tmp=e->supported; 1352 if(_tmp==NULL && datatype !=1)1592 if(_tmp==NULL && datatype==0) 1353 1593 _tmp=e->defaults; 1354 1594 … … 1396 1636 strcasecmp(tmp1->name,"extension")!=0){ 1397 1637 if(datatype!=1){ 1398 char *tmp2=zCapitalize1(tmp1->name); 1399 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1400 free(tmp2); 1638 if(datatype==2 && vid==1){ 1639 nc6 = xmlNewNode(ns, BAD_CAST "SupportedCRS"); 1640 } 1641 else{ 1642 char *tmp2=zCapitalize1(tmp1->name); 1643 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1644 free(tmp2); 1645 } 1401 1646 } 1402 1647 else{ … … 1422 1667 } 1423 1668 if(vid==0 || oI>=3){ 1424 if(vid==0 || oI!=4) 1425 xmlAddChild(nc5,nc6); 1426 else 1427 xmlFree(nc6); 1669 if(vid==0 || oI!=4){ 1670 if(datatype==2 && vid==1) 1671 xmlAddChild(nc3,nc6); 1672 else 1673 xmlAddChild(nc5,nc6); 1674 } 1675 else{ 1676 xmlFreeNode(nc6); 1677 } 1428 1678 } 1429 else 1430 xmlFree(nc6); 1679 else{ 1680 xmlFreeNode(nc6); 1681 } 1431 1682 } 1432 1683 tmp1=tmp1->next; … … 1439 1690 } 1440 1691 else{ 1441 xmlAddChild(nc3,nc5); 1692 if(datatype!=2) 1693 xmlAddChild(nc3,nc5); 1442 1694 } 1443 1695 1444 1696 }else{ 1445 if(datatype !=1)1697 if(datatype==2 && vid==0) 1446 1698 xmlAddChild(nc3,nc5); 1447 1699 } … … 1459 1711 } 1460 1712 else 1461 if(datatype!=1) 1713 if(datatype==0){ 1714 xmlFreeNode(nc4); 1462 1715 xmlAddChild(nc3,nc5); 1716 } 1463 1717 1464 1718 _tmp=_tmp->next; … … 1466 1720 1467 1721 if(hasSupported==0){ 1468 if(datatype==0 && vid!=0) 1722 if(datatype==0 && vid!=0){ 1469 1723 xmlFreeNode(nc4); 1724 } 1470 1725 xmlFreeNode(nc5); 1471 1726 } … … 1478 1733 } 1479 1734 else{ 1735 xmlFreeNode(nc4); 1480 1736 xmlAddChild(nc3,nc5); 1481 1737 } … … 1491 1747 }else{ 1492 1748 if(e->child!=NULL && vid!=0){ 1493 printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid); 1494 } 1495 } 1496 1749 printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL); 1750 } 1751 } 1497 1752 if(e->child!=NULL && vid==0){ 1498 1753 elements* children=dupElements(e->child); 1499 1754 elements* cursor=children; 1500 1755 while(cursor!=NULL){ 1501 char* tmp=strdup(cursor->name); 1502 free(cursor->name); 1503 cursor->name=(char*)malloc((strlen(cursor->name)+strlen(e->name)+2)*sizeof(char)); 1504 sprintf(cursor->name,"%s.%s",e->name,tmp); 1756 elements* ccursor=cursor; 1757 char* tmp=zStrdup(ccursor->name); 1758 free(ccursor->name); 1759 ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char)); 1760 sprintf(ccursor->name,"%s.%s",e->name,tmp); 1505 1761 cursor=cursor->next; 1506 1762 } 1507 printFullDescription(in,children,type,ns,ns_ows,nc2,vid); 1508 xmlAddChild(nc1,nc2); 1763 printFullDescription(doc,in,children,type,ns,ns_ows,nc1,vid,fromDb,serviceType); 1509 1764 freeElements(&children); 1510 1765 free(children); 1511 }else 1512 xmlAddChild(nc1,nc2); 1513 1766 }else{ 1767 if(nc2!=NULL){ 1768 xmlAddChild(nc1,nc2); 1769 } 1770 } 1514 1771 e=e->next; 1515 1772 } … … 1528 1785 * @param outputs the outputs generated by the service 1529 1786 */ 1530 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1787 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1531 1788 xmlNsPtr ns,ns_ows,ns_xlink; 1532 1789 xmlNodePtr nr,n,nc,nc1=NULL,nc3; … … 1549 1806 char stored_path[1024]; 1550 1807 memset(stored_path,0,1024); 1551 1808 1552 1809 if(vid==0){ 1553 1810 char tmp[256]; … … 1734 1991 } 1735 1992 } 1736 1993 1737 1994 /** 1738 1995 * Display the process output only when requested ! … … 1744 2001 maps* mcursor=outputs; 1745 2002 elements* scursor=serv->outputs; 1746 map* testResponse=getMap(request,"RawDataOutput"); 2003 map* testResponse=getMap(request,"RawDataOutput"); 1747 2004 if(testResponse==NULL) 1748 2005 testResponse=getMap(request,"ResponseDocument"); 1749 while(mcursor!=NULL){ 2006 while(mcursor!=NULL){ 1750 2007 map* tmp0=getMap(mcursor->content,"inRequest"); 1751 scursor=getElements(serv->outputs,mcursor->name); 1752 if(scursor!=NULL){ 1753 if(testResponse==NULL || tmp0==NULL){ 2008 scursor=getElements(serv->outputs,mcursor->name); 2009 if(scursor!=NULL){ 2010 if(testResponse==NULL || tmp0==NULL){ 1754 2011 if(vid==0) 1755 2012 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); … … 1758 2015 } 1759 2016 else 1760 1761 if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){ 2017 if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){ 1762 2018 if(vid==0) 1763 2019 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1764 2020 else 1765 2021 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1766 } 2022 } 1767 2023 }else 1768 2024 /** … … 1775 2031 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1776 2032 mcursor=mcursor->next; 1777 } 2033 } 1778 2034 if(vid==0) 1779 2035 xmlAddChild(n,nc); 1780 } 1781 2036 } 1782 2037 if(vid==0 && 1783 2038 hasStoredExecuteResponse==true … … 1834 2089 #endif 1835 2090 } 2091 1836 2092 printDocument(m,doc,pid); 1837 2093 … … 1891 2147 else{ 1892 2148 /* 1893 dumpElements(e);2149 dumpElements(e); 1894 2150 */ 1895 2151 return; … … 1900 2156 || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 1901 2157 || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) 1902 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);2158 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); 1903 2159 tmp=tmp->next; 1904 2160 } … … 1927 2183 * @param type the type 1928 2184 */ 1929 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){ 1930 2185 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){ 1931 2186 xmlNodePtr nc1,nc2,nc3; 1932 2187 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1935 2190 tmp=e->content; 1936 2191 else 1937 tmp=m->content; 1938 2192 tmp=m->content; 1939 2193 if(vid==0){ 1940 2194 nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); … … 1976 2230 xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name)); 1977 2231 } 1978 2232 1979 2233 // IO type nested outputs 1980 if(m->child!=NULL){ 2234 if(m->child!=NULL){ 1981 2235 maps* curs=m->child; 1982 2236 elements* ecurs=getElements(e,(e!=NULL?e->name:m->name)); 1983 2237 ecurs=ecurs->child; 1984 while(curs!=NULL ){2238 while(curs!=NULL/* && ecurs!=NULL*/){ 1985 2239 ecurs=getElements(ecurs,(curs->name)); 1986 2240 map* inRequest=getMap(curs->content,"inRequest"); … … 1992 2246 } 1993 2247 } 1994 else{ 2248 else{ 1995 2249 map *tmpMap=getMap(m->content,"Reference"); 1996 if(tmpMap==NULL){ 2250 if(tmpMap==NULL){ 1997 2251 nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); 1998 if(e!=NULL && e->format!=NULL){ 1999 if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)2000 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");2252 if(e!=NULL && e->format!=NULL){ 2253 if (strncasecmp(e->format, "LiteralOutput", strlen(e->format)) == 0) 2254 nc3 = xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2001 2255 else 2002 2256 if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) … … 2005 2259 nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); 2006 2260 else 2007 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 2008 } 2009 else { 2010 map* tmpV=getMapFromMaps(m,"format","value"); 2261 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 2262 } 2263 else { 2264 map* tmpV=getMapFromMaps(m,"format","value"); 2011 2265 if(tmpV!=NULL) 2012 2266 nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); … … 2014 2268 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2015 2269 } 2016 tmp=m->content; 2017 2270 tmp=m->content; 2271 2018 2272 while(tmp!=NULL){ 2019 2273 if(strcasecmp(tmp->name,"mimeType")==0 || … … 2021 2275 strcasecmp(tmp->name,"schema")==0 || 2022 2276 strcasecmp(tmp->name,"datatype")==0 || 2023 strcasecmp(tmp->name,"uom")==0) { 2024 2277 strcasecmp(tmp->name,"uom")==0) { 2025 2278 if(vid==0) 2026 2279 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); … … 2033 2286 } 2034 2287 } 2288 2035 2289 if(vid==0) 2036 2290 xmlAddChild(nc2,nc3); 2037 tmp=tmp->next; 2291 tmp=tmp->next; 2038 2292 } 2039 2293 if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) { … … 2046 2300 } 2047 2301 } 2048 else { 2049 if(e!=NULL) 2050 tmp=getMap(e->defaults->content,"mimeType"); 2302 else { 2303 //if (e != NULL) { 2304 if (e != NULL && e->defaults != NULL) { // knut: add extra NULL pointer check in case user omits <Default> block in config file 2305 tmp = getMap(e->defaults->content, "mimeType"); 2306 } 2051 2307 else 2052 tmp=NULL; 2053 2308 tmp=NULL; 2054 2309 map* tmp1=getMap(m->content,"encoding"); 2055 2310 map* tmp2=getMap(m->content,"mimeType"); … … 2106 2361 strstr(tmp2->value, "json") != NULL || // (will not be parsed by XML reader) 2107 2362 strstr(tmp2->value, "ecmascript") != NULL 2108 ) {2363 ) { 2109 2364 xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); 2110 2365 } … … 2112 2367 if (strstr(tmp2->value, "xml") != NULL || // if XML-based format 2113 2368 // include for backwards compatibility, 2114 2369 // although correct mime type is ...kml+xml: 2115 2370 strstr(tmp2->value, "google-earth.kml") != NULL 2116 2371 ) { … … 2241 2496 else 2242 2497 exceptionCode="501 Internal Server Error"; 2243 2498 tmp=getMapFromMaps(m,"lenv","status_code"); 2499 if(tmp!=NULL) 2500 exceptionCode=tmp->value; 2244 2501 if(m!=NULL){ 2245 2502 map *tmpSid=getMapFromMaps(m,"lenv","sid"); … … 2332 2589 2333 2590 tmp=getMapArray(s,"text",cnt); 2591 if(tmp==NULL) 2592 tmp=getMapArray(s,"message",cnt); 2334 2593 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2335 2594 if(tmp!=NULL){ 2336 2595 xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); 2337 2596 xmlAddChild(nc1,txt); 2597 if(cnt==0) 2598 setMapInMaps(m,"lenv","message",tmp->value); 2338 2599 } 2339 2600 else{ … … 2381 2642 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, 2382 2643 map* request_inputs1,int cpid,maps* m,int res){ 2383 2384 2644 #ifdef DEBUG 2385 2645 dumpMaps(request_inputs); 2386 2646 dumpMaps(request_outputs); 2387 2647 fprintf(stderr,"printProcessResponse\n"); 2388 #endif 2648 #endif 2389 2649 map* toto=getMap(request_inputs1,"RawDataOutput"); 2390 2650 int asRaw=0; … … 2396 2656 if(tmpSess!=NULL){ 2397 2657 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 2658 maps *tmps=getMaps(m,"senv"); 2398 2659 char* sessId=NULL; 2399 2660 if(_tmp!=NULL){ 2400 2661 printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value); 2662 map *_tmp1=getMapFromMaps(m,"senv","ecookie_length"); 2663 if(_tmp1!=NULL){ 2664 int len=atoi(_tmp1->value); 2665 int cnt=0; 2666 for(cnt=0;cnt<len;cnt++){ 2667 map* _tmp2=getMapArray(tmps->content,"ecookie",cnt); 2668 if(_tmp2!=NULL) 2669 printf("Set-Cookie: %s; HttpOnly\r\n",_tmp2->value); 2670 } 2671 } 2401 2672 printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 2402 2673 char session_file_path[100]; … … 2406 2677 else 2407 2678 sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1); 2408 sessId= strdup(session_file_path);2679 sessId=zStrdup(session_file_path); 2409 2680 }else{ 2410 2681 maps* t=getMaps(m,"senv"); … … 2412 2683 while(p!=NULL){ 2413 2684 if(strstr(p->name,"ID")!=NULL){ 2414 sessId= strdup(p->value);2685 sessId=zStrdup(p->value); 2415 2686 break; 2416 2687 } … … 2435 2706 } 2436 2707 } 2437 2438 2708 if(res==SERVICE_FAILED){ 2439 2709 map *lenv; … … 2462 2732 return; 2463 2733 } 2464 2734 2735 if(res!=SERVICE_SUCCEEDED){ 2736 printProcessResponse(m,request_inputs1,cpid, 2737 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2738 request_inputs, 2739 request_outputs); 2740 return; 2741 } 2742 2465 2743 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2466 2744 if(asRaw==0){ … … 2473 2751 map* usid=getMapFromMaps(m,"lenv","usid"); 2474 2752 int itn=0; 2753 int error=-1; 2475 2754 NESTED0: 2476 2755 while(tmpI!=NULL){ … … 2483 2762 #endif 2484 2763 map *gfile=getMap(tmpI->content,"generated_file"); 2485 char *file_name ;2764 char *file_name=NULL; 2486 2765 if(gfile!=NULL){ 2487 2766 gfile=getMap(tmpI->content,"expected_generated_file"); … … 2491 2770 readGeneratedFile(m,tmpI->content,gfile->value); 2492 2771 file_name=zStrdup((gfile->value)+strlen(tmp1->value)); 2493 } 2494 2772 } 2495 2773 toto=getMap(tmpI->content,"asReference"); 2496 2774 #ifdef USE_MS 2497 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL) 2775 map* geodatatype=getMap(tmpI->content,"geodatatype"); 2776 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && 2777 (testMap==NULL || 2778 strncasecmp(testMap->value,"true",4)!=0 || 2779 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 2498 2780 #else 2499 2781 if(toto!=NULL && strcasecmp(toto->value,"true")==0) 2500 2782 #endif 2501 { 2502 elements* in=getElements(s->outputs,tmpI->name); 2503 if(in==NULL && s->outputs->child!=NULL){ 2504 in=getElements(s->outputs->child,tmpI->name); 2783 { 2784 elements* in=getElements(s->outputs,tmpI->name); 2785 if(in==NULL && s->outputs->child!=NULL){ 2786 in=getElements(s->outputs->child,tmpI->name); 2787 } 2788 char *format=NULL; 2789 if(in!=NULL && in->format!=NULL){ 2790 format=in->format; 2791 }else 2792 format=(char*)"LiteralData"; 2793 if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){ 2794 addToMap(tmpI->content,"extension","xml"); 2795 addToMap(tmpI->content,"mimeType","text/xml"); 2796 addToMap(tmpI->content,"encoding","UTF-8"); 2797 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2798 } 2799 char *file_path=NULL; 2800 if(gfile==NULL) { 2801 map *ext=getMap(tmpI->content,"extension"); 2802 char file_ext[32]; 2803 2804 if( ext != NULL && ext->value != NULL) { 2805 strncpy(file_ext, ext->value, 32); 2806 } 2807 else { 2808 // Obtain default file extension (see mimetypes.h). 2809 // If the MIME type is not recognized, txt is used as the default extension 2810 map* mtype=getMap(tmpI->content,"mimeType"); 2811 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2812 } 2813 if(file_name!=NULL) 2814 free(file_name); 2815 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2816 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2817 itn++; 2818 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2819 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2820 2821 FILE *ofile=fopen(file_path,"wb"); 2822 if(ofile==NULL){ 2823 char tmpMsg[1024]; 2824 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name); 2825 errorException(m,tmpMsg,"InternalError",NULL); 2826 free(file_name); 2827 free(file_path); 2828 return; 2829 } 2830 2831 toto=getMap(tmpI->content,"value"); 2832 if(toto==NULL){ 2833 char tmpMsg[1024]; 2834 sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name); 2835 errorException(m,tmpMsg,"InternalError",NULL); 2836 fclose(ofile); 2837 free(file_name); 2838 free(file_path); 2839 return; 2840 } 2841 if(strcasecmp(format,"BoundingBoxData")!=0){ 2842 map* size=getMap(tmpI->content,"size"); 2843 if(size!=NULL && toto!=NULL) 2844 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); 2845 else 2846 if(toto!=NULL && toto->value!=NULL) 2847 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2848 }else{ 2849 printBoundingBoxDocument(m,tmpI,ofile); 2850 } 2851 fclose(ofile); 2852 } 2853 2854 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2855 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2856 char *file_url=NULL; 2857 if(strncasecmp(tmp2->value,"http://",7)==0 || 2858 strncasecmp(tmp2->value,"https://",8)==0){ 2859 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2860 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2861 }else{ 2862 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2863 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2864 } 2865 addToMap(tmpI->content,"Reference",file_url); 2866 if(file_name!=NULL) 2867 free(file_name); 2868 if(file_url!=NULL) 2869 free(file_url); 2870 file_name=NULL; 2505 2871 } 2506 char *format=NULL; 2507 if(in!=NULL && in->format!=NULL){ 2508 format=in->format; 2509 }else 2510 format=(char*)"LiteralData"; 2511 if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){ 2512 addToMap(tmpI->content,"extension","xml"); 2513 addToMap(tmpI->content,"mimeType","text/xml"); 2514 addToMap(tmpI->content,"encoding","UTF-8"); 2515 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2872 #ifdef USE_MS 2873 else{ 2874 if(testMap!=NULL){ 2875 map* nbFeatures; 2876 setMapInMaps(m,"lenv","state","out"); 2877 setReferenceUrl(m,tmpI); 2878 nbFeatures=getMap(tmpI->content,"nb_features"); 2879 geodatatype=getMap(tmpI->content,"geodatatype"); 2880 if((nbFeatures!=NULL && atoi(nbFeatures->value)==0) || 2881 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)){ 2882 error=1; 2883 res=SERVICE_FAILED; 2884 } 2516 2885 } 2517 2518 if(gfile==NULL) { 2519 map *ext=getMap(tmpI->content,"extension"); 2520 char *file_path; 2521 char file_ext[32]; 2522 2523 if( ext != NULL && ext->value != NULL) { 2524 strncpy(file_ext, ext->value, 32); 2525 } 2526 else { 2527 // Obtain default file extension (see mimetypes.h). 2528 // If the MIME type is not recognized, txt is used as the default extension 2529 map* mtype=getMap(tmpI->content,"mimeType"); 2530 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2531 } 2532 2533 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2534 sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2535 itn++; 2536 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2537 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2538 2539 FILE *ofile=fopen(file_path,"wb"); 2540 if(ofile==NULL){ 2541 char tmpMsg[1024]; 2542 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name); 2543 errorException(m,tmpMsg,"InternalError",NULL); 2544 free(file_name); 2545 free(file_path); 2546 return; 2547 } 2548 free(file_path); 2549 2550 toto=getMap(tmpI->content,"value"); 2551 if(strcasecmp(format,"BoundingBoxData")!=0){ 2552 map* size=getMap(tmpI->content,"size"); 2553 if(size!=NULL && toto!=NULL) 2554 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); 2555 else 2556 if(toto!=NULL && toto->value!=NULL) 2557 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2558 }else{ 2559 printBoundingBoxDocument(m,tmpI,ofile); 2560 } 2561 fclose(ofile); 2562 2563 } 2564 2565 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2566 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2567 char *file_url; 2568 if(strncasecmp(tmp2->value,"http://",7)==0 || 2569 strncasecmp(tmp2->value,"https://",8)==0){ 2570 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2571 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2572 }else{ 2573 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2574 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2575 } 2576 addToMap(tmpI->content,"Reference",file_url); 2577 free(file_name); 2578 free(file_url); 2579 2580 } 2581 #ifdef USE_MS 2582 else{ 2583 if(testMap!=NULL){ 2584 setReferenceUrl(m,tmpI); 2585 } 2586 } 2587 #endif 2886 } 2887 #endif 2888 if(file_name!=NULL){ 2889 free(file_name); 2890 file_name=NULL; 2891 } 2588 2892 tmpI=tmpI->next; 2589 2893 } … … 2593 2897 if(tmpI!=NULL) 2594 2898 goto NESTED0; 2595 } 2899 } 2596 2900 #ifdef DEBUG 2597 2901 fprintf(stderr,"SERVICE : %s\n",s->name); 2598 2902 dumpMaps(m); 2903 #endif 2904 if(error<0) 2905 printProcessResponse(m,request_inputs1,cpid, 2906 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2907 request_inputs, 2908 request_outputs); 2909 else{ 2910 maps* tmpMaps=getMaps(m,"lenv"); 2911 #ifdef USE_CALLBACK 2912 invokeCallback(m,NULL,NULL,7,0); 2599 2913 #endif 2600 printProcessResponse(m,request_inputs1,cpid, 2601 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2602 request_inputs, 2603 request_outputs); 2914 printExceptionReportResponse(m,tmpMaps->content); 2915 } 2604 2916 } 2605 2917 else{ -
TabularUnified trunk/zoo-project/zoo-kernel/response_print.h ¶ ¶
r785 r917 39 39 #include <libintl.h> 40 40 #include <locale.h> 41 41 42 /** 42 43 * ZOO-Kernel internal messages translation function … … 63 64 #include <sys/stat.h> 64 65 #include <sys/types.h> 65 #include "cgic.h"66 66 #ifndef WIN32 67 67 #include <sys/ipc.h> … … 80 80 #endif 81 81 #ifndef WIN32 82 #include <xlocale.h> 82 //#include <locale.h> 83 #include <locale.h> // knut: this appears to be a non-standard header file that has been removed in newer versions of glibc; it may be sufficient to include <locale.h> (see above) 83 84 #endif 84 85 #include "ulinet.h" … … 94 95 #include <libxml/parser.h> 95 96 #include <libxml/xpath.h> 97 98 #include "cgic.h" 96 99 97 100 #ifdef __cplusplus … … 209 212 xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int); 210 213 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*); 211 void printGetCapabilitiesForProcess(registry*,maps*,xml NodePtr,service*);212 void printDescribeProcessForProcess(registry*,maps*,xml NodePtr,service*);213 void printFullDescription( int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int);214 void printGetCapabilitiesForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*); 215 void printDescribeProcessForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*); 216 void printFullDescription(xmlDocPtr,int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int,int,const map*); 214 217 void printDocument(maps*,xmlDocPtr,int); 215 218 void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int); … … 220 223 void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); 221 224 void printStatusInfo(maps*,map*,char*); 225 void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int); 226 void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int); 222 227 223 228 void outputResponse(service*,maps*,maps*,map*,int,maps*,int); -
TabularUnified trunk/zoo-project/zoo-kernel/server_internal.c ¶ ¶
r889 r917 26 26 #include "service_internal.h" 27 27 #include "response_print.h" 28 //#include "service_callback.h" 28 29 #include "mimetypes.h" 29 30 #ifndef WIN32 … … 366 367 */ 367 368 void readGeneratedFile(maps* m,map* content,char* filename){ 369 char rsize[1024]; 368 370 FILE * file=fopen(filename,"rb"); 369 371 if(file==NULL){ 370 fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);371 372 setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later"); 372 373 return ; 373 374 } 374 375 fseek(file, 0, SEEK_END); 375 long count = ftell(file); 376 zStatStruct f_status; 377 int s=zStat(filename, &f_status); 378 sprintf(rsize,"%lld",f_status.st_size); 376 379 rewind(file); 377 struct stat file_status; 378 stat(filename, &file_status); 379 map* tmpMap1=getMap(content,"value"); 380 if(tmpMap1==NULL){ 381 addToMap(content,"value",""); 382 tmpMap1=getMap(content,"value"); 383 } 384 free(tmpMap1->value); 385 tmpMap1->value=(char*) malloc((count+1)*sizeof(char)); 386 fread(tmpMap1->value,1,count,file); 387 tmpMap1->value[count]=0; 388 fclose(file); 389 char rsize[1000]; 390 sprintf(rsize,"%ld",count); 380 if(getMap(content,"storage")==NULL){ 381 map* memUse=getMapFromMaps(m,"main","memory"); 382 if(memUse==NULL || strncmp(memUse->value,"load",4)==0){ 383 map* tmpMap1=getMap(content,"value"); 384 if(tmpMap1==NULL){ 385 addToMap(content,"value",""); 386 tmpMap1=getMap(content,"value"); 387 } 388 free(tmpMap1->value); 389 tmpMap1->value=(char*) malloc((f_status.st_size+1)*sizeof(char)); 390 if(tmpMap1->value==NULL){ 391 setMapInMaps(m,"lenv","message","Unable to allocate the memory required to read the produced file."); 392 } 393 fread(&tmpMap1->value,1,f_status.st_size,file); 394 tmpMap1->value[f_status.st_size]=0; 395 } 396 } 397 fclose(file); 391 398 addToMap(content,"size",rsize); 392 399 } … … 423 430 void dumpMapsValuesToFiles(maps** main_conf,maps** in){ 424 431 map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); 432 map* tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); 425 433 map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid"); 426 434 maps* inputs=*in; … … 445 453 if(cSize!=NULL){ 446 454 length=atoi(cSize->value); 447 } 455 }else 456 length=strlen(cValue->value); 448 457 writeFile(val,cValue->value,length); 449 458 setMapArray(cMap,"cache_file",k,val); 459 free(val); 460 val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char)); 461 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,k,file_ext); 462 setMapArray(cMap,"cache_url",k,val); 463 setMapArray(cMap,"byValue",k,"true"); 450 464 free(val); 451 465 } … … 461 475 if(cSize!=NULL){ 462 476 length=atoi(cSize->value); 463 } 477 }else 478 length=strlen(cValue->value); 464 479 writeFile(val,cValue->value,length); 465 480 addToMap(cMap,"cache_file",val); 481 free(val); 482 val=(char*)malloc((strlen(tmpUrl->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char)); 483 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpUrl->value,inputs->name,tmpSid->value,0,file_ext); 484 addToMap(cMap,"cache_url",val); 485 addToMap(cMap,"byValue",val); 466 486 free(val); 467 487 } … … 638 658 } 639 659 if(res==NULL){ 660 map* tmpMaxO0=getMap(tmpInputs->content,"useMapserver"); 661 if(tmpMaxO0!=NULL){ 662 if(tmpMaps2->content==NULL) 663 tmpMaps2->content=createMap("useMapserver",tmpMaxO0->value); 664 else 665 addToMap(tmpMaps2->content,"useMapserver",tmpMaxO0->value); 666 } 640 667 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 641 668 if(tmpMaxO!=NULL){ … … 701 728 } 702 729 } 703 else {730 else /*toto*/{ 704 731 iotype* tmpIoType=NULL; 705 732 if(tmpMaps->content!=NULL){ … … 711 738 * content map. 712 739 */ 713 map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); 714 if(tmpMap1!=NULL){ 715 if(tmpMaps->content==NULL) 716 tmpMaps->content=createMap("minOccurs",tmpMap1->value); 717 else 718 addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); 719 } 720 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 721 if(tmpMaxO!=NULL){ 722 if(tmpMaps->content==NULL) 723 tmpMaps->content=createMap("maxOccurs",tmpMaxO->value); 724 else 725 addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value); 726 } 727 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 728 if(tmpMaxMB!=NULL){ 729 if(tmpMaps->content==NULL) 730 tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value); 731 else 732 addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value); 740 char* keys[4]={ 741 "minOccurs", 742 "maxOccurs", 743 "maximumMegabytes", 744 "useMapserver" 745 }; 746 int i=0; 747 for(i=0;i<4;i++){ 748 map* tmpMap1=getMap(tmpInputs->content,keys[i]); 749 if(tmpMap1!=NULL){ 750 addToMap(tmpMaps->content,keys[i],tmpMap1->value); 751 } 733 752 } 734 753 /** … … 743 762 map* tmpV=getMap(tmpI->content,"value"); 744 763 if(tmpV!=NULL){ 745 char *tmpVS= strdup(tmpV->value);764 char *tmpVS=zStrdup(tmpV->value); 746 765 map* tmp=parseBoundingBox(tmpVS); 747 766 free(tmpVS); … … 780 799 map* length=getMap(tmpMaps->content,"length"); 781 800 int i; 782 char *tcn= strdup(tmpContent->name);801 char *tcn=zStrdup(tmpContent->name); 783 802 for(i=1;i<atoi(length->value);i++){ 784 803 #ifdef DEBUG … … 806 825 */ 807 826 if(tmpIoType!=NULL){ 808 map* tmpCheck=getMap(tmpIoType->content,"useMap Server");809 if(tmpCheck!=NULL ){827 map* tmpCheck=getMap(tmpIoType->content,"useMapserver"); 828 if(tmpCheck!=NULL && strncasecmp(tmpCheck->value,"true",4)==0){ 810 829 // Get the default value 830 addToMap(tmpMaps->content,"useMapserver","true"); 811 831 tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL); 812 832 tmpCheck=getMap(tmpMaps->content,"mimeType"); … … 834 854 addToMap(tmpMaps->content,"inRequest","true"); 835 855 elements* tmpElements=getElements(in,tmpMaps->name); 836 if( tmpElements!=NULL && tmpElements->child!=NULL){856 if(/*tmpMaps->child!=NULL && */tmpElements!=NULL && tmpElements->child!=NULL){ 837 857 char *res=addDefaultValues(&tmpMaps->child,tmpElements->child,m,type,err); 838 858 if(strlen(res)>0){ 839 859 return res; 840 860 } 861 } 862 } 863 if(tmpInputs->child!=NULL){ 864 tmpInputss=tmpInputs->next; 865 tmpInputs=tmpInputs->child; 866 if(tmpMaps!=NULL){ 867 out1=tmpMaps->child; 868 out1s=tmpMaps; 841 869 } 842 870 } … … 972 1000 if(isRunning(conf,pid)>0){ 973 1001 if(strncasecmp(req,"GetResult",strlen(req))==0){ 974 errorException (conf, _("The result for the requested JobID has not yet been generated. "),1002 errorException (conf, _("The result for the requested JobID has not yet been generated. The service is currently running."), 975 1003 "ResultNotReady", pid); 976 1004 return; … … 981 1009 char* tmpStr=_getStatus(conf,pid); 982 1010 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 983 char *tmpStr1= strdup(tmpStr);984 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1011 char *tmpStr1=zStrdup(tmpStr); 1012 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 985 1013 free(tmpStr); 986 1014 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; … … 1000 1028 printf("%s",result); 1001 1029 fflush(stdout); 1030 free(sid); 1002 1031 freeMap(&statusInfo); 1003 1032 free(statusInfo); 1033 free(result); 1004 1034 return; 1005 1035 }else{ 1006 errorException (conf, _("The result for the requested JobID has not yet been generated. "),1036 errorException (conf, _("The result for the requested JobID has not yet been generated. The service ends but it still needs to produce the outputs."), 1007 1037 "ResultNotReady", pid); 1008 1038 freeMap(&statusInfo); … … 1015 1045 char* tmpStr=_getStatus(conf,pid); 1016 1046 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1017 char *tmpStr1= strdup(tmpStr);1018 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1047 char *tmpStr1=zStrdup(tmpStr); 1048 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1019 1049 free(tmpStr); 1020 1050 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; … … 1026 1056 } 1027 1057 } 1058 free(sid); 1028 1059 printStatusInfo(conf,statusInfo,req); 1029 1060 freeMap(&statusInfo); … … 1083 1114 if(strstr(dp->d_name,pid)!=0){ 1084 1115 sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name); 1085 if( unlink(fileName)!=0){1116 if(zUnlink(fileName)!=0){ 1086 1117 errorException (conf, 1087 1118 _("The job cannot be removed, a file cannot be removed"), … … 1095 1126 removeService(conf,pid); 1096 1127 #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 */ 1097 1133 map* statusInfo=createMap("JobID",pid); 1098 1134 addToMap(statusInfo,"Status","Dismissed"); -
TabularUnified trunk/zoo-project/zoo-kernel/service.c ¶ ¶
r889 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2015 GeoLabs SARL4 * Copyright (c) 2015-2019 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 28 28 #include <ctime> 29 29 #include <chrono> 30 #ifdef WIN32 30 31 #include <process.h> 32 #endif 31 33 32 34 #if defined(_MSC_VER) && _MSC_VER < 1800 … … 102 104 fprintf(stderr," * CONTENT [%s] \n",tmp->name); 103 105 dumpMap(tmp->content); 104 fprintf(stderr," * CHILD [%s] \n",tmp->name); 105 dumpMaps(tmp->child); 106 if(tmp->child!=NULL){ 107 fprintf(stderr," * CHILD [%s] \n",tmp->name); 108 dumpMaps(tmp->child); 109 fprintf(stderr," * /CHILD [%s] \n",tmp->name); 110 } 106 111 tmp=tmp->next; 107 112 } … … 125 130 fflush(file); 126 131 tmp=tmp->next; 127 cnt++;128 132 if(limit>=0 && cnt==limit) 129 133 tmp=NULL; 134 cnt++; 130 135 } 131 136 fflush(file); … … 144 149 fflush(file); 145 150 fclose(file); 151 } 152 153 /** 154 * Create a new iotype* 155 * 156 * @return a pointer to the allocated iotype 157 */ 158 iotype* createIoType(){ 159 iotype* io=(iotype*)malloc(IOTYPE_SIZE); 160 io->content=NULL; 161 io->next=NULL; 162 return io; 146 163 } 147 164 … … 179 196 * Count number of map in a map 180 197 * 181 * @param m the map sto count198 * @param m the map to count 182 199 * @return number of map in a map 183 200 */ 184 201 int count(map* m){ 185 202 map* tmp=m; 203 int c=0; 204 while(tmp!=NULL){ 205 c++; 206 tmp=tmp->next; 207 } 208 return c; 209 } 210 211 /** 212 * Count number of maps in a maps 213 * 214 * @param m the maps to count 215 * @return number of maps in a maps 216 */ 217 int maps_length(maps* m){ 218 maps* tmp=m; 186 219 int c=0; 187 220 while(tmp!=NULL){ … … 401 434 if(tmp->metadata!=NULL) 402 435 free(tmp->metadata); 436 freeMap(&tmp->additional_parameters); 437 if(tmp->additional_parameters!=NULL) 438 free(tmp->additional_parameters); 403 439 if(tmp->format!=NULL) 404 440 free(tmp->format); 441 freeElements(&tmp->child); 405 442 if(tmp->child!=NULL){ 406 freeElements(&tmp->child);407 443 free(tmp->child); 408 444 } 409 freeIOType(&tmp->defaults);410 if(tmp->defaults!=NULL)445 if(tmp->defaults!=NULL){ 446 freeIOType(&tmp->defaults); 411 447 free(tmp->defaults); 412 freeIOType(&tmp->supported);448 } 413 449 if(tmp->supported!=NULL){ 450 freeIOType(&tmp->supported); 414 451 free(tmp->supported); 415 452 } 416 freeElements(&tmp->next);417 if(tmp->next!=NULL)453 if(tmp->next!=NULL){ 454 freeElements(&tmp->next); 418 455 free(tmp->next); 419 } 456 } 457 } 458 } 459 460 461 /** 462 * Allocate memory for a service. 463 * Require to call free after calling this function. 464 * 465 * @return the service 466 */ 467 service* createService(){ 468 service *s1 = (service *) malloc (SERVICE_SIZE); 469 s1->name=NULL; 470 s1->content=NULL; 471 s1->metadata=NULL; 472 s1->additional_parameters=NULL; 473 s1->inputs=NULL; 474 s1->outputs=NULL; 475 return s1; 420 476 } 421 477 422 478 /** 423 479 * Free allocated memory of a service. 424 * Require to call free on e after calling this function.480 * Require to be invoked for every createService call. 425 481 * 426 482 * @param s the service to free … … 437 493 if(tmp->metadata!=NULL) 438 494 free(tmp->metadata); 495 freeMap(&tmp->additional_parameters); 496 if(tmp->additional_parameters!=NULL) 497 free(tmp->additional_parameters); 439 498 freeElements(&tmp->inputs); 440 499 if(tmp->inputs!=NULL) … … 454 513 */ 455 514 void addToMap(map* m,const char* n,const char* v){ 456 if (m != NULL) { // knut: add NULL-pointer check457 if(hasKey(m,n)==false){458 map* _cursor=m;459 while(_cursor->next!=NULL){460 _cursor=_cursor->next;461 }462 _cursor->next=createMap(n,v);463 }464 else{465 map *tmp=getMap(m,n);466 if(tmp->value!=NULL)467 free(tmp->value);468 tmp->value=zStrdup(v);469 }470 }515 if (m != NULL) { // knut: add NULL-pointer check 516 if (hasKey(m, n) == false) { 517 map* _cursor = m; 518 while (_cursor->next != NULL) { 519 _cursor = _cursor->next; 520 } 521 _cursor->next = createMap(n, v); 522 } 523 else { 524 map *tmp = getMap(m, n); 525 if (tmp->value != NULL) 526 free(tmp->value); 527 tmp->value = zStrdup(v); 528 } 529 } 471 530 } 472 531 … … 506 565 */ 507 566 map* addToMapWithSize(map* m,const char* n,const char* v,int size){ 567 char sin[128]; 568 char sname[10]="size"; 569 map *tmp; 508 570 if(hasKey(m,n)==false){ 509 571 map* _cursor=m; … … 514 576 } 515 577 } 516 char sname[10]="size";517 578 if(strlen(n)>5) 518 579 sprintf(sname,"size_%s",n+6); 519 map *tmp=getMap(m,n);580 tmp=getMap(m,n); 520 581 if(tmp->value!=NULL) 521 582 free(tmp->value); … … 524 585 memmove(tmp->value,v,size*sizeof(char)); 525 586 tmp->value[size]=0; 526 char sin[128];527 587 sprintf(sin,"%d",size); 528 588 addToMap(m,sname,sin); … … 545 605 } 546 606 else{ 547 #ifdef DEBUG548 fprintf(stderr,"_CURSOR\n");549 dumpMap(_cursor);550 #endif551 while(_cursor->next!=NULL)552 _cursor=_cursor->next;553 607 map* tmp1=getMap(*mo,tmp->name); 554 608 if(tmp1==NULL){ 609 while(_cursor->next!=NULL) 610 _cursor=_cursor->next; 555 611 _cursor->next=createMap(tmp->name,tmp->value); 556 612 } … … 561 617 _cursor=*mo; 562 618 tmp=tmp->next; 563 #ifdef DEBUG564 fprintf(stderr,"MO\n");565 dumpMap(*mo);566 #endif567 619 } 568 620 } … … 678 730 map* size=getMap(in,"size"); 679 731 map *lout=*out; 732 map *tmpVin,*tmpVout; 680 733 if(size!=NULL && pos>0){ 681 734 char tmp[11]; … … 683 736 size=getMap(in,tmp); 684 737 sprintf(tmp,"value_%d",pos); 685 map*tmpVin=getMap(in,tmp);686 map*tmpVout=getMap(lout,tmp);738 tmpVin=getMap(in,tmp); 739 tmpVout=getMap(lout,tmp); 687 740 free(tmpVout->value); 688 741 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char)); … … 691 744 }else{ 692 745 if(size!=NULL){ 693 map*tmpVin=getMap(in,"value");694 map*tmpVout=getMap(lout,"value");746 tmpVin=getMap(in,"value"); 747 tmpVout=getMap(lout,"value"); 695 748 free(tmpVout->value); 696 749 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char)); … … 712 765 map* size=getMap(in,"size"); 713 766 map* length=getMap(in,"length"); 767 map* toload=getMap(in,"to_load"); 768 if(toload!=NULL && strcasecmp(toload->value,"false")==0){ 769 #ifdef DEBUG 770 fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__); 771 #endif 772 return ; 773 } 714 774 if(length!=NULL){ 715 775 int len=atoi(length->value); … … 734 794 maps* res=NULL; 735 795 if(_cursor!=NULL){ 796 map* mc=_cursor->content; 797 maps* mcs=_cursor->child; 736 798 res=createMaps(_cursor->name); 737 map* mc=_cursor->content;738 799 if(mc!=NULL){ 739 800 addMapToMap(&res->content,mc); 740 801 loadMapBinaries(&res->content,mc); 741 802 } 742 maps* mcs=_cursor->child;743 803 if(mcs!=NULL){ 744 804 res->child=dupMaps(&mcs); … … 764 824 } 765 825 else{ 826 maps* tmp1=getMaps(*mo,tmp->name); 766 827 while(_cursor->next!=NULL) 767 828 _cursor=_cursor->next; 768 maps* tmp1=getMaps(*mo,tmp->name);769 829 if(tmp1==NULL){ 770 830 _cursor->next=dupMaps(&tmp); … … 797 857 map* getMapArray(map* m,const char* key,int index){ 798 858 char tmp[1024]; 859 map* tmpMap; 799 860 if(index>0) 800 861 sprintf(tmp,"%s_%d",key,index); … … 804 865 fprintf(stderr,"** KEY %s\n",tmp); 805 866 #endif 806 map*tmpMap=getMap(m,tmp);867 tmpMap=getMap(m,tmp); 807 868 #ifdef DEBUG 808 869 if(tmpMap!=NULL) … … 823 884 void setMapArray(map* m,const char* key,int index,const char* value){ 824 885 char tmp[1024]; 886 map* tmpSize; 825 887 if(index>0){ 888 map* len=getMap(m,"length"); 826 889 sprintf(tmp,"%s_%d",key,index); 827 map* len=getMap(m,"length");828 890 if((len!=NULL && atoi(len->value)<index+1) || len==NULL){ 829 891 char tmp0[5]; … … 832 894 } 833 895 } 834 else 896 else{ 835 897 sprintf(tmp,"%s",key); 836 map* tmpSize=getMapArray(m,"size",index); 898 addToMap(m,"length","1"); 899 } 900 tmpSize=getMapArray(m,"size",index); 837 901 if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){ 902 map* ptr=getMapOrFill(&m,tmp,(char *)""); 838 903 #ifdef DEBUG 839 904 fprintf(stderr,"%s\n",tmpSize->value); 840 905 #endif 841 map* ptr=getMapOrFill(&m,tmp,(char *)"");842 906 free(ptr->value); 843 907 ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char)); … … 846 910 else 847 911 addToMap(m,tmp,value); 912 } 913 914 /** 915 * Add a key and an integer value to an existing map array. 916 * 917 * @param m the map to add the KVP 918 * @param n the key to add 919 * @param index the index of the MapArray 920 * @param v the corresponding value to add 921 */ 922 void addIntToMapArray(map* m,const char* n,int index,const int v){ 923 char svalue[10]; 924 sprintf(svalue,"%d",v); 925 setMapArray(m,n,index,svalue); 848 926 } 849 927 … … 881 959 maps* tmp=mi; 882 960 maps* _cursor=getMaps(*mo,tmp->name); 883 884 if(_cursor==NULL)885 return -1;886 887 map* tmpLength=getMap(_cursor->content,"length");888 961 char tmpLen[10]; 889 962 int len=1; 890 if(tmpLength!=NULL){891 len=atoi(tmpLength->value);892 }893 894 963 char *tmpV[14]={ 895 964 (char*)"size", … … 906 975 (char*)"isCached", 907 976 (char*)"LowerCorner", 908 (char*)"UpperCorner" 977 (char*)"UpperCorner" 909 978 }; 979 int i=0; 980 map* tmpLength; 981 982 if(_cursor==NULL) 983 return -1; 984 985 tmpLength=getMap(_cursor->content,"length"); 986 if(tmpLength!=NULL){ 987 len=atoi(tmpLength->value); 988 } 989 910 990 sprintf(tmpLen,"%d",len+1); 911 991 addToMap(_cursor->content,"length",tmpLen); 912 int i=0;913 992 for(i=0;i<14;i++){ 914 993 map* tmpVI=getMap(tmp->content,tmpV[i]); … … 967 1046 res->content=NULL; 968 1047 res->metadata=NULL; 1048 res->additional_parameters=NULL; 969 1049 res->format=NULL; 970 1050 res->defaults=NULL; … … 981 1061 * @return a pointer to the allocated elements 982 1062 */ 983 elements* createElements(c har* name){1063 elements* createElements(const char* name){ 984 1064 elements* res=(elements*)malloc(ELEMENTS_SIZE); 985 1065 res->name=zStrdup(name); 986 1066 res->content=NULL; 987 1067 res->metadata=NULL; 1068 res->additional_parameters=NULL; 988 1069 res->format=NULL; 989 1070 res->defaults=NULL; … … 1020 1101 elements* tmp=e; 1021 1102 while(tmp!=NULL){ 1103 iotype* tmpio=tmp->defaults; 1104 int ioc=0; 1022 1105 fprintf(stderr,"ELEMENT [%s]\n",tmp->name); 1023 1106 fprintf(stderr," > CONTENT [%s]\n",tmp->name); … … 1025 1108 fprintf(stderr," > METADATA [%s]\n",tmp->name); 1026 1109 dumpMap(tmp->metadata); 1110 fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name); 1111 dumpMap(tmp->additional_parameters); 1027 1112 fprintf(stderr," > FORMAT [%s]\n",tmp->format); 1028 iotype* tmpio=tmp->defaults;1029 int ioc=0;1030 1113 while(tmpio!=NULL){ 1031 1114 fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc); … … 1060 1143 int i; 1061 1144 while(tmp!=NULL){ 1145 map* mcurs=tmp->content; 1146 int ioc=0; 1147 iotype* tmpio; 1062 1148 for(i=0;i<2+(4*level);i++) 1063 1149 fprintf(stderr," "); 1064 1150 fprintf(stderr,"%s:\n",tmp->name); 1065 map* mcurs=tmp->content;1066 1151 while(mcurs!=NULL){ 1067 1152 for(i=0;i<4+(4*level);i++) … … 1091 1176 dumpElementsAsYAML(tmp->child,level+1); 1092 1177 } 1093 iotype* tmpio=tmp->defaults; 1094 int ioc=0; 1178 tmpio=tmp->defaults; 1095 1179 while(tmpio!=NULL){ 1096 1180 for(i=0;i<6+(4*level);i++) … … 1142 1226 elements* cursor=e; 1143 1227 elements* tmp=NULL; 1144 if(cursor!=NULL ){1228 if(cursor!=NULL && cursor->name!=NULL){ 1145 1229 #ifdef DEBUG 1146 1230 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); … … 1149 1233 #endif 1150 1234 tmp=(elements*)malloc(ELEMENTS_SIZE); 1151 tmp->name=zStrdup( e->name);1235 tmp->name=zStrdup(cursor->name); 1152 1236 tmp->content=NULL; 1153 addMapToMap(&tmp->content, e->content);1237 addMapToMap(&tmp->content,cursor->content); 1154 1238 tmp->metadata=NULL; 1155 addMapToMap(&tmp->metadata,e->metadata); 1156 if(e->format!=NULL) 1157 tmp->format=zStrdup(e->format); 1239 addMapToMap(&tmp->metadata,cursor->metadata); 1240 tmp->additional_parameters=NULL; 1241 addMapToMap(&tmp->additional_parameters,cursor->additional_parameters); 1242 if(cursor->format!=NULL) 1243 tmp->format=zStrdup(cursor->format); 1158 1244 else 1159 1245 tmp->format=NULL; 1160 if( e->defaults!=NULL){1246 if(cursor->defaults!=NULL){ 1161 1247 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); 1162 1248 tmp->defaults->content=NULL; 1163 addMapToMap(&tmp->defaults->content, e->defaults->content);1249 addMapToMap(&tmp->defaults->content,cursor->defaults->content); 1164 1250 tmp->defaults->next=NULL; 1165 1251 #ifdef DEBUG … … 1169 1255 }else 1170 1256 tmp->defaults=NULL; 1171 if(e->supported!=NULL){ 1257 if(cursor->supported!=NULL && cursor->supported->content!=NULL){ 1258 iotype *tmp2=cursor->supported->next; 1172 1259 tmp->supported=(iotype*)malloc(IOTYPE_SIZE); 1173 1260 tmp->supported->content=NULL; 1174 addMapToMap(&tmp->supported->content, e->supported->content);1261 addMapToMap(&tmp->supported->content,cursor->supported->content); 1175 1262 tmp->supported->next=NULL; 1176 iotype *tmp2=e->supported->next; 1177 while(tmp2!=NULL){ 1263 while(tmp2!=NULL){ 1178 1264 addMapToIoType(&tmp->supported,tmp2->content); 1179 1265 #ifdef DEBUG … … 1190 1276 else 1191 1277 tmp->child=NULL; 1192 tmp->next=dupElements(cursor->next); 1278 if(cursor->next!=NULL) 1279 tmp->next=dupElements(cursor->next); 1280 else 1281 tmp->next=NULL; 1193 1282 } 1194 1283 return tmp; … … 1205 1294 elements* tmp=e; 1206 1295 if(*m==NULL){ 1207 *m=dupElements(tmp);1296 (*m)=dupElements(tmp); 1208 1297 }else{ 1209 1298 addToElements(&(*m)->next,tmp); … … 1237 1326 fprintf(stderr,"CONTENT MAP\n"); 1238 1327 dumpMap(s->content); 1239 fprintf(stderr,"CONTENT METADATA\n"); 1328 if(s->metadata!=NULL) 1329 fprintf(stderr,"CONTENT METADATA\n"); 1240 1330 dumpMap(s->metadata); 1331 if(s->additional_parameters!=NULL) 1332 fprintf(stderr,"CONTENT AdditionalParameters\n"); 1333 dumpMap(s->additional_parameters); 1241 1334 } 1242 1335 if(s->inputs!=NULL){ … … 1296 1389 res->metadata=NULL; 1297 1390 addMapToMap(&res->metadata,s->metadata); 1391 res->additional_parameters=NULL; 1392 addMapToMap(&res->additional_parameters,s->additional_parameters); 1298 1393 res->inputs=dupElements(s->inputs); 1299 1394 res->outputs=dupElements(s->outputs); … … 1309 1404 registry* p=r; 1310 1405 while(p!=NULL){ 1406 services* s=p->content; 1311 1407 fprintf(stderr,"%s \n",p->name); 1312 services* s=p->content;1313 1408 s=p->content; 1314 1409 while(s!=NULL){ … … 1509 1604 */ 1510 1605 void inheritance(registry *r,service** s){ 1606 service* ls=*s; 1607 map *profile,*level; 1511 1608 if(r==NULL) 1512 1609 return; 1513 service* ls=*s; 1514 if(ls->content==NULL) 1610 if(ls==NULL || ls->content==NULL) 1515 1611 return; 1516 map*profile=getMap(ls->content,"extend");1517 map*level=getMap(ls->content,"level");1612 profile=getMap(ls->content,"extend"); 1613 level=getMap(ls->content,"level"); 1518 1614 if(profile!=NULL&&level!=NULL){ 1519 1615 service* s1; … … 1550 1646 memset(tmp,0,1024*10*10); 1551 1647 while(tm!=NULL){ 1648 map* tc=tm->content; 1552 1649 if(i>=10) 1553 1650 break; … … 1556 1653 strcpy(tmp[i][j],tm->name); 1557 1654 j++; 1558 map* tc=tm->content;1559 1655 while(tc!=NULL){ 1560 1656 if(j>=30) … … 1609 1705 * @return true if map has a value or false if value is missing/empty/NULL 1610 1706 */ 1611 bool nonempty( map* map) {1612 return ( map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);1613 } 1614 1615 /** 1616 * Verify that a particular map value exists in a maps 1707 bool nonempty(map* map) { 1708 return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0); 1709 } 1710 1711 /** 1712 * Verify that a particular map value exists in a maps 1617 1713 * data structure, and obtain that value 1618 1714 * … … 1620 1716 * @param node name of maps node to search 1621 1717 * @param key name of map node to find 1622 * @param address to the map* if it exists, otherwise NULL1718 * @param kvp address to the map* if it exists, otherwise NULL 1623 1719 * @return true if map has a value or false if value is missing/NULL 1624 */ 1625 bool hasvalue( maps* source, const char* node, const char* key, map** kvp ) { 1626 *kvp = getMapFromMaps(source, node, key); 1627 return ( *kvp != NULL && (*kvp)->value != NULL && 1628 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0 ); 1720 * 1721 * @note The map assigned to kvp is owned by the source maps 1722 */ 1723 bool hasvalue(maps* source, const char* node, const char* key, map** kvp) { 1724 *kvp = getMapFromMaps(source, node, key); 1725 return (*kvp != NULL && (*kvp)->value != NULL && 1726 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0); 1629 1727 } 1630 1728 … … 1633 1731 * 1634 1732 * @param conf reference to configuration maps 1635 * @param service name of service 1733 * @param service name of service 1636 1734 * @param exc WPSException code 1637 1735 * @param message exception text (default: exception text in WPS specification) 1638 1736 */ 1639 void setErrorMessage( maps*& conf, const char* service, WPSException exc, const char* message) {1640 1641 1642 1643 } 1644 1645 size_t len = strlen( service ) + strlen(": ") + strlen( message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;1646 char* msg = (char*) malloc( len * sizeof(char));1737 void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) { 1738 1739 if (message == NULL) { 1740 message = WPSExceptionText[exc]; 1741 } 1742 1743 size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16; 1744 char* msg = (char*)malloc(len * sizeof(char)); 1647 1745 1648 1746 if (msg != NULL) { 1649 snprintf( msg, len*sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]);1650 setMapInMaps( conf, "lenv", "message", msg);1651 free( msg);1652 } 1747 snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]); 1748 setMapInMaps(conf, "lenv", "message", msg); 1749 free(msg); 1750 } 1653 1751 } 1654 1752 1655 1753 void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) { 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 std::time_t now_t = std::chrono::system_clock::to_time_t( now);1672 std::tm* tm = localtime( &now_t);1754 1755 size_t msglen = 512; 1756 const char empty[] = ""; 1757 1758 FILE* log; 1759 1760 // system time, process time [nanoseconds] 1761 unsigned long long sys_t, proc_t; 1762 1763 // processor time consumed by the program: 1764 clock_t t = clock(); 1765 1766 // system time: 1767 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 1768 1769 std::time_t now_t = std::chrono::system_clock::to_time_t(now); 1770 std::tm* tm = localtime(&now_t); 1673 1771 char* str = asctime(tm); 1674 str[strlen(str)-1] = '\0'; // remove newline1675 1676 1677 1678 1679 1680 if ( message != NULL) {1681 1682 } 1683 1684 1685 1686 1687 char* text = (char*) malloc( sizeof(char)*msglen);1688 1689 snprintf( text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1690 _getpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ //1691 1692 if ( file != NULL && (log = fopen( file, "a+" )) != NULL) {1693 fputs( text, log);1694 fclose( log);1695 1696 1697 1698 if ( (log = fopen( MSG_LOG_FILE, "a+" )) != NULL) {1699 fputs( text, log);1700 fclose( log);1701 } 1702 1703 1704 1705 if ( text != NULL ) free( text);1772 str[strlen(str) - 1] = '\0'; // remove newline 1773 1774 sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); 1775 //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC); 1776 proc_t = t; 1777 1778 if (message != NULL) { 1779 msglen += strlen(message); 1780 } 1781 else { 1782 message = empty; 1783 } 1784 //getLastErrorMessage(); // cgiScriptName 1785 char* text = (char*)malloc(sizeof(char)*msglen); 1786 1787 snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1788 zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ // 1789 1790 if (file != NULL && (log = fopen(file, "a+")) != NULL) { 1791 fputs(text, log); 1792 fclose(log); 1793 } 1794 else { 1795 #ifdef MSG_LOG_FILE 1796 if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) { 1797 fputs(text, log); 1798 fclose(log); 1799 } 1800 #endif 1801 } 1802 1803 if (text != NULL) free(text); 1706 1804 } 1707 1805 … … 1710 1808 // zooLog; 1711 1809 // zooLogMsg(NULL, getLastErrorMessage()); 1712 // zooLogMsg(log.txt, getLastErrorMessage()); 1713 1714 #ifdef WIN32 1715 #ifndef USE_MS 1716 char *strcasestr (char const *a, char const *b) 1717 { 1718 char *x = zStrdup (a); 1719 char *y = zStrdup (b); 1720 1721 x = _strlwr (x); 1722 y = _strlwr (y); 1723 char *pos = strstr (x, y); 1724 char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); 1725 free (x); 1726 free (y); 1727 return ret; 1728 }; 1729 #else 1730 ; 1731 #endif 1732 #endif 1810 // zooLogMsg("log.txt", getLastErrorMessage()); -
TabularUnified trunk/zoo-project/zoo-kernel/service.h ¶ ¶
r889 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-201 5GeoLabs SARL4 * Copyright (c) 2009-2019 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 34 34 #endif 35 35 36 // knut: add bool if necessary 37 #ifndef __cplusplus 38 #ifndef WIN32 39 #include <stdbool.h> 40 #else 41 typedef int bool; 42 #define false 0 43 #define true 1 44 #endif 45 #endif 46 #ifndef __bool_true_false_are_defined 47 #define __bool_true_false_are_defined 1 48 #endif 49 36 50 #ifdef WIN32 37 #ifndef USE_MS 38 ZOO_DLL_EXPORT char *strcasestr (char const *,char const *); 39 #endif 40 #endif 41 42 // knut: add bool if necessary 43 #ifndef __cplusplus 44 #ifndef WIN32 45 #include <stdbool.h> 46 #else 47 typedef int bool; 48 #define false 0 49 #define true 1 50 #endif 51 #endif 52 #ifndef __bool_true_false_are_defined 53 #define __bool_true_false_are_defined 1 54 #endif 55 56 #ifdef WIN32 51 #define strtok_r strtok_s 57 52 #define strncasecmp _strnicmp 58 53 #define strcasecmp _stricmp 59 #define strtok_r strtok_s60 54 #if defined(_MSC_VER) && _MSC_VER < 1900 61 55 #define snprintf _snprintf 62 56 #endif 63 /* knut: see new definition of bool above64 #if defined(_MSC_VER) && _MSC_VER < 180065 #define false 066 #define true 167 #define bool int68 #endif69 */70 57 #define zStrdup _strdup 71 58 #define zMkdir _mkdir 59 #define zGetpid _getpid 72 60 #define zOpen _open 61 #define zClose _close 62 #define zUnlink _unlink 63 #define zDup _dup 64 #define zDup2 _dup2 73 65 #define zWrite _write 74 66 #define zSleep Sleep … … 80 72 static int zGettimeofday(struct ztimeval* tp, void* tzp) 81 73 { 82 struct _timeb theTime;83 74 if (tp == 0) { 84 75 return -1; 85 76 } 86 77 78 struct _timeb theTime; 87 79 _ftime(&theTime); 88 80 tp->tv_sec = theTime.time; … … 92 84 } 93 85 86 #define zStatStruct struct _stati64 87 #define zStat _stati64 88 94 89 #else 95 90 /** … … 106 101 #define zOpen open 107 102 /** 103 * The crossplatform close alias 104 */ 105 #define zClose close 106 /** 107 * The crossplatform unlink alias 108 */ 109 #define zUnlink unlink 110 /** 111 * The crossplatform dup alias 112 */ 113 #define zDup dup 114 /** 115 * The crossplatform dup2 alias 116 */ 117 #define zDup2 dup2 118 /** 108 119 * The crossplatform write alias 109 120 */ 110 121 #define zWrite write 122 #include "unistd.h" 111 123 /** 112 124 * The crossplatform sleep alias 113 125 */ 114 #define zSleep sleep 126 static int zSleep(const long millisecond){ 127 return usleep(millisecond*1000); 128 } 115 129 /** 116 130 * The crossplatform gettimeofday alias … … 121 135 */ 122 136 #define ztimeval timeval 137 /** 138 * The crossplatform getpid alias 139 */ 140 #define zGetpid getpid 141 142 #define zStatStruct struct stat64 143 #define zStat stat64 144 123 145 #endif 124 146 … … 140 162 #ifndef WIN32 141 163 #include <ctype.h> 142 //#include <stdbool.h> // knut: see new definition of bool above 164 #include <stdbool.h> 143 165 #endif 144 166 … … 167 189 * The memory size to create an elements 168 190 */ 169 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))* 2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))191 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+((sizeof(map*) + sizeof(iotype*))*2)+(2*sizeof(elements*))) 170 192 /** 171 193 * The memory size to create a map … … 187 209 */ 188 210 //#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) 189 #define SERVICE_SIZE sizeof(char*) + 2*sizeof(map*) + 2*sizeof(elements*)211 #define SERVICE_SIZE sizeof(char*) + 3*sizeof(map*) + 2*sizeof(elements*) 190 212 /** 191 213 * The memory size to create a services … … 221 243 #ifdef WIN32 222 244 #define NULLMAP ((map*) 0) 245 // knut: see new definition above 246 //#define bool int 247 //#define true 1 248 //#define false 0 223 249 #else 224 250 #define NULLMAP NULL … … 256 282 struct map* content; //!< the content map 257 283 struct map* metadata; //!< the metadata map 284 struct map* additional_parameters; //!< the additional parameters map 258 285 char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData 259 286 struct iotype* defaults; //!< the default iotype … … 270 297 struct map* content; //!< the content map 271 298 struct map* metadata; //!< the metadata map 299 struct map* additional_parameters; //!< the additional parameters map 272 300 struct elements* inputs; //!< the inputs elements 273 301 struct elements* outputs; //!< the outputs elements … … 290 318 struct registry* next; //!< the next registry pointer 291 319 } registry; 292 320 293 321 // knut 294 322 enum WPSException { 295 296 297 298 */ 299 StatusOK, 300 301 302 303 MissingParameterValue, 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 }; 328 323 /* 324 * StatusOK is not a WPS exception, it is added 325 * here for convenience. 326 */ 327 StatusOK, 328 /* 329 * See WPS 1.0 specification, Table 38 and Table 62. 330 */ 331 MissingParameterValue, 332 InvalidParameterValue, 333 NoApplicableCode, 334 NotEnoughStorage, 335 ServerBusy, 336 FileSizeExceeded, 337 StorageNotSupported, 338 VersionNegotiationFailed, 339 /* 340 * See WPS 2.0 specification, Tables 41, 46, 48, and 50. 341 */ 342 NoSuchProcess, 343 NoSuchMode, 344 NoSuchInput, 345 NoSuchOutput, 346 DataNotAccessible, 347 SizeExceeded, 348 TooManyInputs, 349 TooManyOutputs, 350 NoSuchFormat, 351 WrongInputData, 352 InternalServerError, 353 NoSuchJob, 354 ResultNotReady 355 }; 356 329 357 static const char* const WPSExceptionCode[] = { 330 331 "MissingParameterValue", 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 "ResultNotReady" 352 }; 358 "StatusOK", 359 "MissingParameterValue", 360 "InvalidParameterValue", 361 "NoApplicableCode", 362 "NotEnoughStorage", 363 "ServerBusy", 364 "FileSizeExceeded", 365 "StorageNotSupported", 366 "VersionNegotiationFailed", 367 "NoSuchProcess", 368 "NoSuchMode", 369 "NoSuchInput", 370 "NoSuchOutput", 371 "DataNotAccessible", 372 "SizeExceeded", 373 "TooManyInputs", 374 "TooManyOutputs", 375 "NoSuchFormat", 376 "WrongInputData", 377 "InternalServerError", 378 "NoSuchJob", 379 "ResultNotReady" 380 }; 353 381 354 382 static const char* const WPSExceptionText[] = { 355 356 "Operation request does not include a parameter value, and this server did not declare a default value for that parameter.", 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 383 "No problem detected", 384 "Operation request does not include a parameter value, and this server did not declare a default value for that parameter.", 385 "Operation request contains an invalid parameter value.", 386 "No other exceptionCode specified by this service and server applies to this exception.", 387 "The server does not have enough space available to store the inputs and outputs associated with the request.", 388 "The server is too busy to accept and queue the request at this time.", 389 "The file size of one of the input parameters was too large for this process to handle.", 390 "Execute operation request included transmission=”reference” for one of the outputs, but storage is not offered by this server.", 391 "Service version for a ComplexData xlink:href input was not supported by the referenced server, and version negotiation failed.", 392 "One of the identifiers passed does not match with any of the processes offered by this server.", 393 "The process does not permit the desired execution mode.", 394 "One or more of the input identifiers passed does not match with any of the input identifiers of this process.", 395 "One or more of the output identifiers passed does not match with any of the input identifiers of this process.", 396 "One of the referenced input data sets was inaccessible.", 397 "The size of one of the input parameters was too large for this process to handle.", 398 "Too many input items have been specified.", 399 "Too many output items have been specified.", 400 "One or more of the input or output formats specified in the request did not match with any of the formats defined for that particular input or output.", 401 "One or more of inputs for which the service was able to retrieve the data but could not read it.", 402 "", 403 "The JobID from the request does not match any of the Jobs running on this server.", 404 "The result for the requested JobID has not yet been generated." 377 405 }; 378 406 … … 392 420 ZOO_DLL_EXPORT void freeMap(map**); 393 421 ZOO_DLL_EXPORT void freeMaps(maps** mo); 394 395 422 ZOO_DLL_EXPORT iotype* createIoType(); 396 423 ZOO_DLL_EXPORT elements* createEmptyElements(); 397 ZOO_DLL_EXPORT elements* createElements(c har*);424 ZOO_DLL_EXPORT elements* createElements(const char*); 398 425 ZOO_DLL_EXPORT void setElementsName(elements**,char*); 399 426 ZOO_DLL_EXPORT bool hasElement(elements*,const char*); … … 402 429 ZOO_DLL_EXPORT void freeElements(elements**); 403 430 ZOO_DLL_EXPORT void setServiceName(service**,char*); 431 ZOO_DLL_EXPORT service* createService(); 404 432 ZOO_DLL_EXPORT void freeService(service**); 405 433 ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*); 406 434 ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int); 435 ZOO_DLL_EXPORT void addIntToMapArray(map*,const char*,int,const int); 407 436 ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int); 408 437 ZOO_DLL_EXPORT void addMapToMap(map**,map*); … … 446 475 ZOO_DLL_EXPORT bool nonempty(map* map); 447 476 ZOO_DLL_EXPORT bool hasvalue(maps* source, const char* node, const char* key, map** kvp); 477 #ifdef __cplusplus 448 478 ZOO_DLL_EXPORT void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message = NULL); 449 ZOO_DLL_EXPORT void logMessage(const char* source, const char* function, int line, const char* file = NULL, const char* message = NULL); 479 ZOO_DLL_EXPORT void logMessage(const char* source, const char* function, int line, const char* file = NULL, const char* message = NULL); 480 #endif 450 481 #define zooLogMsg(file,message) logMessage(__FILE__, __func__, __LINE__, (file), (message)) 451 482 #define zooLog logMessage(__FILE__, __func__, __LINE__) 452 483 453 484 #ifdef __cplusplus 454 485 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_conf.y ¶ ¶
r790 r917 33 33 static bool wait_maincontent=true; 34 34 static bool wait_mainmetadata=false; 35 static bool wait_mainap=false; 35 36 static bool wait_metadata=false; 37 static bool wait_ap=false; 36 38 static bool wait_nested=false; 37 39 static bool wait_inputs=false; … … 156 158 current_content=NULL; 157 159 my_service->metadata=NULL; 160 my_service->additional_parameters=NULL; 158 161 wait_maincontent=false; 159 162 } 160 163 if(strncasecmp($2,"EndNested",9)==0){ 161 164 #ifdef DEBUG_SERVICE_CONF 162 163 164 #endif 165 166 167 168 165 fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__); 166 fflush(stderr); 167 #endif 168 nested_level-=1; 169 if(nested_level==0){ 170 wait_nested=false; 171 } 169 172 } 170 173 … … 229 232 } 230 233 else 231 if(strncasecmp($2,"MetaData",8)==0){ 232 previous_data=current_data; 233 current_data=3; 234 if(current_element!=NULL){ 235 #ifdef DEBUG_SERVICE_CONF 236 fprintf(stderr,"add current_content to current_element->content\n"); 237 fprintf(stderr,"LINE %d",__LINE__); 238 #endif 239 addMapToMap(¤t_element->content,current_content); 240 freeMap(¤t_content); 241 free(current_content); 242 if(previous_data==1 || previous_data==2) 243 wait_metadata=true; 244 else 245 wait_mainmetadata=true; 246 } 247 else{ 248 if(previous_data==1 || previous_data==2) 249 wait_metadata=true; 250 else 251 wait_mainmetadata=true; 234 if(strncasecmp($2,"MetaData",8)==0 || 235 strncasecmp($2,"AdditionalParameters",8)==0){ 236 if(strncasecmp($2,"AdditionalParameters",8)==0){ 237 previous_data=current_data; 238 current_data=4; 239 if(current_element!=NULL){ 240 #ifdef DEBUG_SERVICE_CONF 241 fprintf(stderr,"add current_content to current_element->content\n"); 242 fprintf(stderr,"LINE %d",__LINE__); 243 #endif 244 if(wait_mainmetadata) 245 addMapToMap(&my_service->metadata,current_content); 246 else 247 if(wait_metadata) 248 addMapToMap(¤t_element->metadata,current_content); 249 else 250 addMapToMap(¤t_element->content,current_content); 251 freeMap(¤t_content); 252 free(current_content); 253 if(previous_data==1 || previous_data==2) 254 wait_ap=true; 255 else 256 wait_mainap=true; 257 } 258 else{ 259 if(previous_data==1 || previous_data==2) 260 wait_ap=true; 261 else 262 wait_mainap=true; 263 } 264 }else{ 265 previous_data=current_data; 266 current_data=3; 267 if(current_element!=NULL){ 268 #ifdef DEBUG_SERVICE_CONF 269 fprintf(stderr,"add current_content to current_element->content\n"); 270 fprintf(stderr,"LINE %d",__LINE__); 271 #endif 272 addMapToMap(¤t_element->content,current_content); 273 freeMap(¤t_content); 274 free(current_content); 275 if(previous_data==1 || previous_data==2) 276 wait_metadata=true; 277 else 278 wait_mainmetadata=true; 279 } 280 else{ 281 if(previous_data==1 || previous_data==2) 282 wait_metadata=true; 283 else 284 wait_mainmetadata=true; 285 } 252 286 } 253 287 current_content=NULL; … … 425 459 if(strcmp($3,"DataOutputs")==0){ 426 460 current_data=2; 461 } 462 if(strcmp($3,"AdditionalParameters")==0){ 463 if(current_content!=NULL){ 464 #ifdef DEBUG_SERVICE_CONF 465 fprintf(stderr,"add current_content to current_element->content\n"); 466 fprintf(stderr,"LINE %d",__LINE__); 467 #endif 468 if(wait_ap){ 469 current_element->additional_parameters=NULL; 470 addMapToMap(¤t_element->additional_parameters,current_content); 471 current_element->next=NULL; 472 current_element->defaults=NULL; 473 current_element->supported=NULL; 474 current_element->child=NULL; 475 }else{ 476 if(wait_mainap){ 477 addMapToMap(&my_service->additional_parameters,current_content); 478 } 479 } 480 481 freeMap(¤t_content); 482 free(current_content); 483 current_content=NULL; 484 } 485 current_data=previous_data; 486 wait_mainap=false; 487 wait_ap=false; 427 488 } 428 489 if(strcmp($3,"MetaData")==0){ … … 866 927 wait_mainmetadata=false; 867 928 wait_metadata=false; 929 wait_mainap=false; 930 wait_ap=false; 868 931 wait_inputs=false; 869 932 wait_defaults=false; -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal.c ¶ ¶
r889 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-201 5GeoLabs SARL4 * Copyright (c) 2009-2018 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 31 31 #include "service_internal.h" 32 32 33 #ifndef TRUE 34 #define TRUE 1 35 #endif 36 #ifndef FALSE 37 #define FALSE -1 38 #endif 39 33 #ifdef WIN32 34 // ref. https://docs.microsoft.com/en-us/windows/desktop/fileio/locking-and-unlocking-byte-ranges-in-files 35 __inline int fcntl(int fd, int cmd, ...) 36 { 37 va_list a; 38 va_start(a, cmd); 39 switch(cmd) 40 { 41 case F_SETLK: 42 { 43 HANDLE h = (HANDLE)_get_osfhandle(fd); 44 struct flock* l= va_arg(a, struct flock*); 45 OVERLAPPED sOverlapped; 46 sOverlapped.Offset = 0; 47 sOverlapped.OffsetHigh = 0; 48 switch(l->l_type) 49 { 50 case F_RDLCK: 51 { 52 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, l->l_len, 0, &sOverlapped)) 53 { 54 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 55 return -1; 56 } 57 } 58 break; 59 case F_WRLCK: 60 { 61 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, l->l_len, 0, &sOverlapped)) 62 { 63 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 64 return -1; 65 } 66 } 67 break; 68 case F_UNLCK: 69 { 70 UnlockFileEx(h, 0, l->l_len, 0, &sOverlapped); 71 } 72 break; 73 default: 74 _set_errno(ENOTSUP); 75 return -1; 76 } 77 } 78 break; 79 default: 80 _set_errno(ENOTSUP); 81 return -1; 82 } 83 return 0; 84 } 85 #endif 40 86 #define ERROR_MSG_MAX_LENGTH 1024 87 88 /** 89 * Lock a file for read, write and upload. 90 * @param conf the main configuration maps 91 * @param filename the file to lock 92 * @param mode define access: 'r' for read, 'w' for write 93 * @return a new zooLock structure on sucess, NULL on failure 94 */ 95 struct zooLock* lockFile(maps* conf,const char* filename,const char mode){ 96 struct stat f_status; 97 int itn=0; 98 int s; 99 struct zooLock* myLock=(struct zooLock*)malloc(sizeof(struct flock)+sizeof(FILE*)+sizeof(char*)); 100 int len=6; 101 char *myTemplate="%s.lock"; 102 int res=-1; 103 retryLockFile: 104 myLock->filename=(char*)malloc((strlen(filename)+len)*sizeof(char)); 105 sprintf(myLock->filename,myTemplate,filename); 106 s=stat(myLock->filename, &f_status); 107 if(s==0 && mode!='r'){ 108 if(itn<ZOO_LOCK_MAX_RETRY){ 109 itn++; 110 #ifdef DEBUG 111 fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",zGetpid(),myLock->filename,itn); 112 fflush(stderr); 113 #endif 114 zSleep(5); 115 free(myLock->filename); 116 goto retryLockFile; 117 }else{ 118 free(myLock->filename); 119 free(myLock); 120 return NULL; 121 } 122 }else{ 123 char local_mode[3]; 124 memset(local_mode,0,3); 125 if(mode=='w') 126 sprintf(local_mode,"%c+",mode); 127 else 128 sprintf(local_mode,"%c",mode); 129 myLock->lockfile=fopen(myLock->filename,local_mode); 130 char tmp[512]; 131 sprintf(tmp,"%d",zGetpid()); 132 if(myLock->lockfile==NULL){ 133 myLock->lockfile=fopen(myLock->filename,"w+"); 134 fwrite(tmp,sizeof(char),strlen(tmp),myLock->lockfile); 135 fflush(myLock->lockfile); 136 fclose(myLock->lockfile); 137 myLock->lockfile=fopen(myLock->filename,local_mode); 138 }/*else 139 fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,(myLock->lockfile==NULL));*/ 140 if(mode!='r'){ 141 fwrite(tmp,sizeof(char),strlen(tmp),myLock->lockfile); 142 fflush(myLock->lockfile); 143 } 144 int cnt=0; 145 if(mode=='r'){ 146 myLock->lock.l_type = F_RDLCK; 147 }else 148 myLock->lock.l_type = F_WRLCK; 149 myLock->lock.l_whence = 0; 150 myLock->lock.l_start = 0; 151 myLock->lock.l_len = strlen(tmp)*sizeof(char); 152 while (true) { 153 if((res=fcntl(fileno(myLock->lockfile), F_SETLK, &(myLock->lock)))==-1 && 154 (errno==EAGAIN || errno==EACCES)){ 155 if(cnt >= ZOO_LOCK_MAX_RETRY){ 156 char message[51]; 157 sprintf(message,"Unable to get the lock after %d attempts.\n",cnt); 158 setMapInMaps(conf,"lenv","message",message); 159 fclose(myLock->lockfile); 160 free(myLock->filename); 161 free(myLock); 162 return NULL; 163 } 164 #ifdef DEBUG 165 fprintf(stderr,"(%d) Wait for lock on %s, tried %d times ... \n",zGetpid(),myLock->filename,cnt); 166 fflush(stderr); 167 #endif 168 zSleep(1); 169 cnt++; 170 }else 171 break; 172 } 173 if(res<0){ 174 char *tmp; 175 if(errno==EBADF) 176 tmp="Either: the filedes argument is invalid; you requested a read lock but the filedes is not open for read access; or, you requested a write lock but the filedes is not open for write access."; 177 else 178 if(errno==EINVAL) 179 tmp="Either the lockp argument doesn’t specify valid lock information, or the file associated with filedes doesn’t support locks."; 180 else 181 tmp="The system has run out of file lock resources; there are already too many file locks in place."; 182 #ifdef DEBUG 183 fprintf(stderr,"Unable to get the lock on %s due to the following error: %s\n",myLock->filename,tmp); 184 #endif 185 return NULL; 186 } 187 return myLock; 188 } 189 } 190 191 /** 192 * Remove a lock. 193 * @param conf the main configuration maps 194 * @param s the zooLock structure 195 * @return 0 on success, -1 on failure. 196 */ 197 int unlockFile(maps* conf,struct zooLock* s){ 198 int res=-1; 199 if(s!=NULL){ 200 s->lock.l_type = F_UNLCK; 201 res=fcntl(fileno(s->lockfile), F_SETLK, &s->lock); 202 if(res==-1) 203 return res; 204 fclose(s->lockfile); 205 #ifndef WIN32 206 // Check if there is any process locking a file and delete the lock if not. 207 s->lock.l_type = F_WRLCK; 208 if(fcntl(fileno(s->lockfile), F_GETLK, &s->lock)!=-1 && s->lock.l_type == F_UNLCK){ 209 #endif 210 zUnlink(s->filename); 211 #ifndef WIN32 212 } 213 #endif 214 free(s->filename); 215 free(s); 216 } 217 return res; 218 } 219 41 220 #ifndef RELY_ON_DB 42 #include <dirent.h>221 #include "dirent.h" 43 222 44 223 /** … … 148 327 149 328 //FILE* f0 = fopen (fileName, "r"); 150 151 329 // knut: open file in binary mode to avoid conversion of line endings (yielding extra bytes) on Windows platforms 330 FILE* f0 = fopen(fileName, "rb"); 152 331 if(f0!=NULL){ 153 332 fseek (f0, 0, SEEK_END); … … 162 341 free(stat); 163 342 } 164 165 343 return tmps1; 166 344 } … … 250 428 * sizeof (char)); 251 429 sprintf (fbkpid, "%s/%s.status", r_inputs->value, usid->value); 252 unlink(fbkpid);430 zUnlink(fbkpid); 253 431 free(fbkpid); 254 432 } … … 510 688 } 511 689 } 690 setMapInMaps(conf,"lenv","semaphore","Created"); 512 691 } else if (errno == EEXIST) { /* someone else got it first */ 513 692 int ready = 0; … … 529 708 fprintf(stderr,"Retry to access the semaphore later ...\n"); 530 709 #endif 531 zSleep(1 );710 zSleep(1000); 532 711 } 533 712 } … … 540 719 return -1; 541 720 } 721 setMapInMaps(conf,"lenv","semaphore","Acquired"); 542 722 } else { 543 723 return sem_id; /* error, check errno */ … … 739 919 } 740 920 921 /** 922 * Check if file exists in specified folder 923 * 924 * @param dir the folder in which to search for file 925 * @param name the name of the file (not full path) 926 * @return a character string with the full path [dir/name], or NULL if the file does not exist 927 * 928 * @attention Caller is responsible for applying free() to the returned pointer 929 */ 930 char* file_exists(const char* dir, const char* name) { 931 const char* d = (dir != NULL ? dir : "."); 932 if (name != NULL) { 933 size_t length = strlen(d) + strlen(name) + 2; // including file separator and \0 character 934 char* path = (char*)calloc(length, sizeof(char)); 935 snprintf(path, length, "%s/%s", d, name); 936 937 struct stat buffer; 938 if (stat(path, &buffer) != 0) { 939 free(path); 940 path = NULL; 941 } 942 return path; 943 } 944 else { 945 return NULL; 946 } 947 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal.h ¶ ¶
r680 r917 63 63 * Number of time the ZOO-Kernel will try to acquire lock 64 64 */ 65 #define ZOO_LOCK_MAX_RETRY 1 065 #define ZOO_LOCK_MAX_RETRY 180 66 66 67 67 #include <sys/stat.h> 68 68 #include <sys/types.h> 69 #include "cgic.h"70 69 #ifndef WIN32 71 70 #include <sys/ipc.h> … … 82 81 #endif 83 82 #ifndef WIN32 84 #include < xlocale.h>83 #include <locale.h> 85 84 #endif 86 85 86 #include <fcntl.h> 87 87 88 #include "service.h" 88 89 … … 94 95 #endif 95 96 97 #ifdef WIN32 98 // fcntl flock definitions 99 #define F_SETLK 8 // Non-Blocking set or clear a lock 100 #define F_SETLKW 9 // Blocking set or clear a lock 101 #define F_GETLK 10 102 #define F_RDLCK 1 // read lock 103 #define F_WRLCK 2 // write lock 104 #define F_UNLCK 3 // remove lock 105 struct flock { 106 short l_type; // F_RDLCK, F_WRLCK, or F_UNLCK 107 short l_whence; // flag to choose starting offset, must be SEEK_SET 108 long l_start; // relative offset, in bytes, must be 0 109 long l_len; // length, in bytes; 0 means lock to EOF, must be 0 110 short l_pid; // unused (returned with the unsupported F_GETLK) 111 short l_xxx; // reserved for future use 112 }; 113 #endif 114 115 /** 116 * The lock structure used by the ZOO-Kernel to ensure atomicity of operations 117 * 118 */ 119 typedef struct zooLock{ 120 struct flock lock; //!< The lock 121 FILE* lockfile; //!< The pointer to the lock file 122 char* filename; //!< The filename to lock 123 } zooLock; 124 125 static zooLock** zoo_file_locks=NULL; 126 static int zoo_file_locks_cnt=0; 127 96 128 #ifdef __cplusplus 97 129 extern "C" { 98 130 #endif 99 131 132 100 133 ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*); 101 134 ZOO_DLL_EXPORT int setOutputValue( maps*, const char*, char*, size_t); 102 135 ZOO_DLL_EXPORT char* getInputValue( maps*,const char*,size_t*); 136 137 ZOO_DLL_EXPORT struct zooLock* lockFile(maps*,const char*,const char); 138 ZOO_DLL_EXPORT int unlockFile(maps*,struct zooLock*); 103 139 104 140 ZOO_DLL_EXPORT void unhandleStatus(maps*); … … 125 161 ZOO_DLL_EXPORT int unlockShm(semid); 126 162 163 ZOO_DLL_EXPORT char* file_exists(const char* dir, const char* name); 164 127 165 #ifdef __cplusplus 128 166 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_java.c ¶ ¶
r790 r917 208 208 #endif 209 209 #ifdef JAVA7 210 cls_gr = (*env) NewGlobalRef(cls);210 cls_gr = (*env).NewGlobalRef(cls); 211 211 #else 212 212 cls_gr = (*env)->NewGlobalRef(env, cls); … … 215 215 if (cls != NULL) { 216 216 #ifdef JAVA7 217 @(*env).ExceptionClear();217 (*env).ExceptionClear(); 218 218 pmid=(*env).GetStaticMethodID(cls, s->name, "(Ljava/util/HashMap;Ljava/util/HashMap;Ljava/util/HashMap;)I"); 219 219 #else … … 284 284 } 285 285 #ifdef JAVA7 286 286 (*jvm).DestroyJavaVM(); 287 287 #else 288 288 (*jvm)->DestroyJavaVM(jvm); … … 427 427 #endif 428 428 map* sizeV=getMap(tmp1,"size"); 429 map* useFile=getMap(tmp1,"use_file"); 430 map* cacheFile=getMap(tmp1,"cache_file"); 429 431 map* isArray=getMap(tmp1,"isArray"); 430 432 map* alen=getMap(tmp1,"length"); … … 432 434 if(strcmp(tmp1->name,"value")==0){ 433 435 if(isArray==NULL){ 434 if(sizeV!=NULL && strcmp(tmp1->name,"value")==0 ){436 if(sizeV!=NULL && strcmp(tmp1->name,"value")==0 && useFile==NULL){ 435 437 #ifdef JAVA7 436 438 jbyteArray tmpData=(*env).NewByteArray(atoi(sizeV->value)); 437 439 (*env).SetByteArrayRegion(tmpData,0,atoi(sizeV->value),(const jbyte *)tmp1->value); 438 (*env).CallObjectMethod( env,scObject1, put_mid, (*env).NewStringUTF(env,tmp1->name), tmpData);440 (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), tmpData); 439 441 #else 440 442 jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sizeV->value)); … … 448 450 (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), (*env)->NewStringUTF(env,tmp1->value)); 449 451 #endif 452 if(useFile!=NULL) 453 #ifdef JAVA7 454 (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF("cache_file"), (*env).NewStringUTF(cacheFile->value)); 455 #else 456 (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,"cache_file"), (*env)->NewStringUTF(env,cacheFile->value)); 457 #endif 458 450 459 } 451 460 else{ … … 455 464 jclass scArrayListClass,scArrayList_class; 456 465 jmethodID scArrayList_constructor; 457 jobject scObject2 ;466 jobject scObject2,scObject3; 458 467 #ifdef JAVA7 459 468 scArrayListClass = (*env).FindClass("java/util/ArrayList"); … … 462 471 jmethodID add_mid = 0; 463 472 scObject2 = (*env).NewObject(scArrayList_class, scArrayList_constructor); 473 scObject3 = (*env).NewObject(scArrayList_class, scArrayList_constructor); 464 474 465 475 add_mid = (*env).GetMethodID(scArrayListClass, … … 471 481 jmethodID add_mid = 0; 472 482 scObject2 = (*env)->NewObject(env, scArrayList_class, scArrayList_constructor); 483 scObject3 = (*env)->NewObject(env, scArrayList_class, scArrayList_constructor); 473 484 474 485 add_mid = (*env)->GetMethodID(env,scArrayListClass, … … 478 489 479 490 for(i=0;i<alen1;i++){ 491 map* cMap=getMapArray(tmp->content,"cache_file",i); 492 map* uMap=getMapArray(tmp->content,"use_file",i); 480 493 map* vMap=getMapArray(tmp->content,"value",i); 481 494 map* sMap=getMapArray(tmp->content,"size",i); 482 495 map* mMap=getMapArray(tmp->content,tmap->value,i); 483 496 484 if(sMap!=NULL && vMap!=NULL && strncmp(vMap->name,"value",5)==0 ){497 if(sMap!=NULL && vMap!=NULL && strncmp(vMap->name,"value",5)==0 && uMap==NULL){ 485 498 #ifdef JAVA7 486 499 jbyteArray tmpData=(*env).NewByteArray(atoi(sMap->value)); … … 501 514 #endif 502 515 } 503 516 517 if(cMap!=NULL){ 518 #ifdef JAVA7 519 jobject tmpData=(*env).NewStringUTF(cMap->value); 520 (*env).CallObjectMethod(scObject3, add_mid, tmpData); 521 #else 522 jobject tmpData=(*env)->NewStringUTF(env,cMap->value); 523 (*env)->CallObjectMethod(env,scObject3, add_mid, tmpData); 524 #endif 525 526 } 504 527 } 505 528 506 529 #ifdef JAVA7 507 530 (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), scObject2); 531 (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF("cache_file"), scObject3); 508 532 #else 509 533 (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), scObject2); 534 (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,"cache_file"), scObject3); 510 535 #endif 511 536 -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_js.c ¶ ¶
r828 r917 157 157 return 1; 158 158 if (!JS_DefineFunction(cx, global, "alert", JSAlert, 2, 0)) 159 return 1; 160 if (!JS_DefineFunction(cx, global, "sleep", JSSleep, 1, 0)) 159 161 return 1; 160 162 if (!JS_DefineFunction(cx, global, "importScripts", JSLoadScripts, 1, 0)) … … 901 903 char* tmpValue; 902 904 size_t dwRead; 905 maps *tmpConf=createMaps("main"); 906 tmpConf->content=createMap("memory","load"); 903 907 JS_MaybeGC(cx); 904 908 hInternet=InternetOpen("ZooWPSClient\0", … … 929 933 #endif 930 934 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body), 931 INTERNET_FLAG_NO_CACHE_WRITE,0 );935 INTERNET_FLAG_NO_CACHE_WRITE,0,tmpConf); 932 936 processDownloads(&hInternet); 933 937 free(body); … … 940 944 } 941 945 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0, 942 INTERNET_FLAG_NO_CACHE_WRITE,0 );946 INTERNET_FLAG_NO_CACHE_WRITE,0,tmpConf); 943 947 processDownloads(&hInternet); 944 948 }else{ 945 949 char *body=JSValToChar(cx,&argv[2]); 946 950 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body), 947 INTERNET_FLAG_NO_CACHE_WRITE,0 );951 INTERNET_FLAG_NO_CACHE_WRITE,0,tmpConf); 948 952 processDownloads(&hInternet); 949 953 free(body); … … 951 955 }else{ 952 956 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0, 953 INTERNET_FLAG_NO_CACHE_WRITE,0 );957 INTERNET_FLAG_NO_CACHE_WRITE,0,tmpConf); 954 958 processDownloads(&hInternet); 955 959 } … … 972 976 if(argc>=2) 973 977 free(method); 978 freeMaps(&tmpConf); 979 free(tmpConf); 974 980 InternetCloseHandle(&hInternet); 975 981 JS_MaybeGC(cx); … … 1023 1029 } 1024 1030 1031 /** 1032 * The function used as sleep from the JavaScript environment 1033 * (ZOO-API). 1034 * 1035 * @param cx the JavaScript context 1036 * @param argc the number of parameters 1037 * @param argv1 the parameter values 1038 * @return true 1039 */ 1040 JSBool 1041 JSSleep(JSContext *cx, uintN argc, jsval *argv1) 1042 { 1043 jsval *argv = JS_ARGV(cx,argv1); 1044 JS_MaybeGC(cx); 1045 int isleep=0; 1046 if(JS_ValueToInt32(cx,argv[0],&isleep)==JS_TRUE){ 1047 zSleep(isleep); 1048 } 1049 JS_MaybeGC(cx); 1050 return JS_TRUE; 1051 } 1052 -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_js.h ¶ ¶
r580 r917 49 49 JSBool JSRequest(JSContext*, uintN, jsval*); 50 50 JSBool JSUpdateStatus(JSContext*,uintN,jsval *); 51 JSBool JSSleep(JSContext*,uintN,jsval *); 51 52 52 53 void reportError(JSContext *cx, const char *message, JSErrorReport *report); -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_mono.c ¶ ¶
r794 r917 30 30 #include "response_print.h" 31 31 32 MonoClass *iclasses[4]; 33 MonoMethod *imethods[10]; 34 32 35 /** 33 36 * Load a Mono dll then run the static public method corresponding to the … … 69 72 mono_config_parse(NULL); 70 73 71 MonoDomain* monoDomain = mono_jit_init_version("ZOO_Embedded_Domain", 72 "v4.0.30319"); 73 74 map* cwdMap=getMapFromMaps(*main_conf,"main","servicePath"); 75 if(cwdMap==NULL) 76 cwdMap=getMapFromMaps(*main_conf,"lenv","cwd"); 77 78 char *zooAssembly=(char*)malloc((strlen(cwdMap->value)+11)*sizeof(char)); 79 sprintf(zooAssembly,"%s/ZMaps.dll",cwdMap->value); 80 assembly = mono_domain_assembly_open(monoDomain,zooAssembly); 81 if(assembly==NULL){ 82 setMapInMaps(*main_conf,"lenv","message",_("The ZMaps.dll assembly cannot be found!")); 83 return 4; 84 } 85 mono_add_internal_call ("ZOO_API::Translate", MonoTranslate); 86 mono_add_internal_call ("ZOO_API::UpdateStatus", MonoUpdateStatus); 87 74 MonoDomain* monoDomain; 75 map* mono; 76 if (hasvalue(*main_conf, "mono", "version", &mono)) { 77 monoDomain = mono_jit_init_version("ZOO_Embedded_Domain", mono->value); 78 } 79 else { 80 monoDomain = mono_jit_init("ZOO_Embedded_Domain"); // use default framework version 81 } 82 83 //MonoDomain* monoDomain = mono_jit_init_version("ZOO_Embedded_Domain", "v4.0.30319"); 84 //MonoDomain* monoDomain = mono_jit_init("ZOO_Embedded_Domain"); 85 86 char* ZMapsLib = "ZMaps.dll"; 87 char *zooAssembly = NULL; 88 89 map* config = NULL, *basedir = NULL; 90 if (hasvalue(*main_conf, "mono", "configdir", &basedir) && // knut: rename to e.g. "base_dir"? 91 hasvalue(*main_conf, "mono", "configfile", &config)) { 92 mono_domain_set_config(monoDomain, basedir->value, config->value); 93 zooAssembly = file_exists(basedir->value, ZMapsLib); 94 } 95 else { 96 mono_domain_set_config(monoDomain, "./", ""); 97 } 98 99 map* cwdMap; 100 if (! hasvalue(*main_conf, "main", "servicePath", &cwdMap) && 101 ! hasvalue(*main_conf, "main", "libPath", &cwdMap) ) { 102 cwdMap = getMapFromMaps(*main_conf, "lenv", "cwd"); 103 } 104 105 if (zooAssembly != NULL || (zooAssembly = file_exists(cwdMap->value, ZMapsLib)) != NULL) { 106 assembly = mono_domain_assembly_open(monoDomain, zooAssembly); 107 } 108 else { 109 // try to load from default locations (GAC?) 110 assembly = mono_domain_assembly_open(monoDomain, ZMapsLib); 111 } 112 free(zooAssembly); 113 114 if (assembly == NULL) { 115 setMapInMaps(*main_conf, "lenv", "message", _("The ZMaps.dll assembly cannot be found!")); 116 return 4; 117 } 118 119 mono_add_internal_call ("ZOO_API::Translate", MonoTranslate); 120 mono_add_internal_call("ZOO_API::UpdateStatus", MonoUpdateStatus); 121 88 122 monoImage = mono_assembly_get_image(assembly); 89 123 MonoClass *KeysList = mono_class_from_name(monoImage, "ZooGenerics", "KeysList"); … … 104 138 MonoClass *classes[3]={_ZMapsClass,ZMapsClass,ZMapClass}; 105 139 MonoMethod *methods[5]={ZMapsAdd,_ZMapsSetContent,_ZMapsSetChild,ZMapAdd,ZMapDisplay}; 106 140 107 141 MonoMethod *ZMapsGetKeys = mono_class_get_method_from_name(ZMapsClass, "getKeys", 0); 142 108 143 MonoMethod *ZMapsGetKeysCount = mono_class_get_method_from_name(ZMapsClass, "getKeysCount", 0); 109 144 MonoMethod *ZMapsGetKey = mono_class_get_method_from_name(ZMapsClass, "getKey", 1); … … 116 151 MonoClass *oclasses[4]={_ZMapsClass,ZMapsClass,ZMapClass,KeysList}; 117 152 MonoMethod *omethods[10]={ZMapsGetMaps,ZMapsGetKeysCount,ZMapsGetKey,ZMapGetMap,ZMapGetKeysCount,ZMapGetKey,_ZMapsGetContent,_ZMapsGetChild,ZMapGetSize,ZMapGetMapAsBytes}; 118 153 119 154 for(int i=0;i<4;i++){ 120 155 iclasses[i]=oclasses[i]; … … 131 166 132 167 MonoObject * out=ZMapsFromMaps(monoDomain,classes,methods,&exc,outputs); 133 168 134 169 args [0] = main; 135 170 args [1] = in; 136 171 args [2] = out; 137 172 138 tmp=getMap(s->content,"serviceProvider"); 139 char *sName=(char*)malloc((strlen(tmp->value)+strlen(cwdMap->value)+2)*sizeof(char)); 140 sprintf(sName,"%s/%s",cwdMap->value,tmp->value); 141 MonoAssembly* serviceAssembly = mono_domain_assembly_open(monoDomain,sName); 173 char* sName = NULL; 174 MonoAssembly* serviceAssembly = NULL; 175 176 tmp = getMap(s->content, "serviceProvider"); 177 char* test = file_exists(NULL, "log.txt"); 178 if ( (sName = file_exists(cwdMap->value, tmp->value)) != NULL || 179 (sName = file_exists(".", tmp->value)) != NULL || // in case servicePath is defined but serviceProvider is in working directory 180 (basedir != NULL && (sName = file_exists(basedir->value, tmp->value)) != NULL) ) { 181 182 serviceAssembly = mono_domain_assembly_open(monoDomain, sName); 183 } 184 else { 185 // try to open from default locations 186 serviceAssembly = mono_domain_assembly_open(monoDomain, tmp->value); 187 } 188 free(sName); 189 190 //char *sName=(char*)malloc((strlen(tmp->value)+strlen(cwdMap->value)+2)*sizeof(char)); 191 //sprintf(sName,"%s/%s",cwdMap->value,tmp->value); 192 //MonoAssembly* serviceAssembly = mono_domain_assembly_open(monoDomain,sName); 193 142 194 if(serviceAssembly==NULL){ 143 195 char *msg=(char*)malloc((strlen(_("Your service assembly: %s cannot be found!"))+strlen(tmp->value)+1)*sizeof(char)); … … 147 199 return 4; 148 200 } 149 201 150 202 MonoImage* serviceImage = mono_assembly_get_image(serviceAssembly); 151 203 152 204 map* tmp1=getMap(s->content,"serviceNameSpace"); 205 153 206 tmp=getMap(s->content,"serviceClass"); 154 207 MonoClass *serviceClass = mono_class_from_name(serviceImage, tmp1->value, tmp->value); … … 160 213 return 4; 161 214 } 215 162 216 MonoMethod *serviceFunction = mono_class_get_method_from_name(serviceClass, s->name, 3); 163 217 if(serviceFunction==NULL){ … … 168 222 return 4; 169 223 } 224 170 225 MonoObject *exception=NULL; 171 226 MonoObject *result = mono_runtime_invoke(serviceFunction,NULL,args,&exception); 227 228 if (exception != NULL) { // knut: add exception handling 229 MonoString* pMsg = mono_object_to_string(exception, NULL); 230 setErrorMessage(*main_conf, s->name, NoApplicableCode, mono_string_to_utf8(pMsg)); 231 return 4; 232 } 233 172 234 res=*(int*)mono_object_unbox (result); 235 173 236 if(res==3){ 174 237 freeMaps(&outputs); 175 238 free(outputs); 176 outputs=mapsFromZMaps(monoDomain,oclasses,omethods, args[2]);239 outputs=mapsFromZMaps(monoDomain,oclasses,omethods,(MonoObject*)args[2]); 177 240 *real_outputs=outputs; 178 241 } 242 179 243 freeMaps(&m); 180 244 free(m); 181 m=mapsFromZMaps(monoDomain,oclasses,omethods, args[0]);245 m=mapsFromZMaps(monoDomain,oclasses,omethods,(MonoObject*)args[0]); 182 246 *main_conf=m; 183 mono_jit_cleanup (monoDomain); 247 mono_jit_cleanup (monoDomain); 184 248 return res; 185 249 } … … 288 352 values[0]=&i; 289 353 exc=NULL; 290 Mono Object*okey = (MonoString*) mono_runtime_invoke(methods[2],m,values,&exc);354 MonoString *okey = (MonoString*) mono_runtime_invoke(methods[2],m,values,&exc); 291 355 char* key = mono_string_to_utf8(okey); 292 356 maps* tmp=createMaps(key); 293 357 values[0]=mono_string_new (domain, key); 294 Mono Object*content_ZMaps = (MonoString*) mono_runtime_invoke(methods[0],m,values,&exc);295 MonoObject *content = mono_runtime_invoke(methods[6], content_ZMaps,NULL,&exc);358 MonoString *content_ZMaps = (MonoString*) mono_runtime_invoke(methods[0],m,values,&exc); 359 MonoObject *content = mono_runtime_invoke(methods[6],(MonoObject*)content_ZMaps,NULL,&exc); 296 360 tmp->content=mapFromZMap(domain,classes,methods,content); 297 361 MonoObject *childs = mono_runtime_invoke(methods[7],content_ZMaps,NULL,&exc); … … 329 393 values[0]=&i; 330 394 exc=NULL; 331 Mono Object*okey = (MonoString*) mono_runtime_invoke(methods[5],m,values,&exc);395 MonoString *okey = (MonoString*) mono_runtime_invoke(methods[5],m,values,&exc); 332 396 char* key = mono_string_to_utf8(okey); 333 397 values[0]=mono_string_new (domain, key); 334 398 exc=NULL; 335 Mono Object*ovalue = (MonoString*) mono_runtime_invoke(methods[3],m,values,&exc);399 MonoString *ovalue = (MonoString*) mono_runtime_invoke(methods[3],m,values,&exc); 336 400 char* value = mono_string_to_utf8(ovalue); 337 401 if(res==NULL) … … 350 414 */ 351 415 static MonoString* MonoTranslate(MonoString *str){ 352 return mono_string_new (mono_domain_get(), mono_string_to_utf8(_(str)));416 return mono_string_new (mono_domain_get(), _(mono_string_to_utf8(str))); 353 417 } 354 418 … … 360 424 * @return the translated string 361 425 */ 362 static void MonoUpdateStatus(MonoObject* obj,MonoString *str,int* p){ 363 MonoDomain* domain = mono_object_get_domain (obj); 364 maps *confMaps=mapsFromZMaps(domain,iclasses,imethods,obj); 365 setMapInMaps(confMaps,"lenv","message",mono_string_to_utf8(str)); 366 int tmp=p; 367 if (p < 0 || p > 100){ 368 tmp=-1; 369 } 370 char tmpStatus[5]; 371 snprintf(tmpStatus, 4, "%d", tmp); 372 setMapInMaps(confMaps,"lenv","status",(char*)tmpStatus); 373 _updateStatus(confMaps); 374 freeMaps(&confMaps); 375 free(confMaps); 376 return; 377 } 426 static void MonoUpdateStatus(MonoObject* obj, MonoString *str, int p) { 427 MonoDomain* domain = mono_object_get_domain(obj); 428 maps *confMaps = mapsFromZMaps(domain, iclasses, imethods, obj); 429 setMapInMaps(confMaps, "lenv", "message", mono_string_to_utf8(str)); 430 int tmp = p > 100 || p < 0 ? -1 : p; 431 char tmpStatus[5]; 432 snprintf(tmpStatus, 4, "%d", tmp); 433 setMapInMaps(confMaps, "lenv", "status", (char*)tmpStatus); 434 _updateStatus(confMaps); 435 freeMaps(&confMaps); 436 free(confMaps); 437 return; 438 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_mono.h ¶ ¶
r794 r917 45 45 map* mapFromZMap(MonoDomain*,MonoClass**,MonoMethod**,MonoObject*); 46 46 static MonoString* MonoTranslate(MonoString*); 47 static void MonoUpdateStatus(MonoObject*,MonoString*,int*); 48 MonoClass *iclasses[4]; 49 MonoMethod *imethods[10]; 47 //static void MonoUpdateStatus(MonoObject*,MonoString*,int*); 48 static void MonoUpdateStatus(MonoObject*, MonoString*, int); 49 //MonoClass *iclasses[4]; // knut: move declarations to service_internal_mono.c 50 //MonoMethod *imethods[10]; 50 51 51 52 #ifdef __cplusplus -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_ms.c ¶ ¶
r781 r917 34 34 #include "server_internal.h" 35 35 #include "response_print.h" 36 #include "caching.h" 36 37 37 38 /** … … 76 77 77 78 /** 79 * Return the current publish_id value 80 * @param elem and maps pointer on which the search occur 81 * @return the integer value of the publish_id field, if any, 0 otherwise 82 */ 83 int getPublishedId(maps* elem){ 84 if(elem!=NULL && elem->content!=NULL){ 85 map* myIndex=getMap(elem->content,"published_id"); 86 if(myIndex!=NULL){ 87 return atoi(myIndex->value); 88 } 89 } 90 return 0; 91 } 92 93 /** 78 94 * Add width and height keys to an output maps containing the maximum width 79 95 * and height for displaying the full data extent. … … 87 103 */ 88 104 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){ 105 int imyIndex=getPublishedId(output); 89 106 double maxWidth=640; 90 107 double maxHeight=480; … … 118 135 #endif 119 136 if(output!=NULL){ 120 addToMap(output->content,"width",sWidth);121 addToMap(output->content,"height",sHeight);137 setMapArray(output->content,"width",imyIndex,sWidth); 138 setMapArray(output->content,"height",imyIndex,sHeight); 122 139 } 123 140 } … … 131 148 */ 132 149 void setReferenceUrl(maps* m,maps* tmpI){ 150 int imyIndex=getPublishedId(tmpI); 151 if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL) 152 return; 133 153 outputMapfile(m,tmpI); 134 154 map *msUrl=getMapFromMaps(m,"main","mapserverAddress"); … … 138 158 exit(-1); 139 159 } 160 if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL) 161 return; 162 int finalProto=-1; 140 163 map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion"); 141 164 map *dataPath=getMapFromMaps(m,"main","dataPath"); 142 165 map *sid=getMapFromMaps(m,"lenv","usid"); 143 map* format=getMap(tmpI->content,"mimeType"); 144 map* rformat=getMap(tmpI->content,"requestedMimeType"); 145 map* width=getMap(tmpI->content,"width"); 146 map* height=getMap(tmpI->content,"height"); 147 map* protoMap=getMap(tmpI->content,"msOgc"); 148 map* versionMap=getMap(tmpI->content,"msOgcVersion"); 149 char options[3][5][25]={ 166 map* format=getMapArray(tmpI->content,"mimeType",imyIndex); 167 map* rformat=getMapArray(tmpI->content,"requestedMimeType",imyIndex); 168 map* width=getMapArray(tmpI->content,"width",imyIndex); 169 map* height=getMapArray(tmpI->content,"height",imyIndex); 170 map* protoMap=getMapArray(tmpI->content,"msOgc",imyIndex); 171 map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex); 172 map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex); 173 map* layerName=getMapArray(tmpI->content,"msLayer",imyIndex); 174 char options[4][5][25]={ 150 175 {"WMS","1.3.0","GetMap","layers=%s","wms_extent"}, 151 {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"}, 152 {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"} 176 {"WFS","1.0.0","GetFeature","typename=%s","wcs_extent"}, 177 {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}, 178 {"WCS","1.0.0","GetCoverage","coverage=%s","wcs_extent"} 153 179 }; 180 map *nbElements=getMapArray(tmpI->content,"nb_features",imyIndex); 181 if(nbElements==NULL) 182 nbElements=getMapArray(tmpI->content,"nb_pixels",imyIndex); 183 if(datatype==NULL || strncmp(datatype->value,"other",5)==0 || (nbElements!=NULL && atoi(nbElements->value)==0)){ 184 map* minNb=getMap(tmpI->content,"minoccurs"); 185 map* useMs=getMap(tmpI->content,"useMapserver"); 186 if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){ 187 int lIndex=0; 188 maps* lenv=getMaps(m,"lenv"); 189 if(getMapFromMaps(m,"lenv","mapErrorNb")==NULL) 190 setMapInMaps(m,"lenv","mapErrorNb","0"); 191 else{ 192 map* tmpV=getMapFromMaps(m,"lenv","mapErrorNb"); 193 lIndex=atoi(tmpV->value)+1; 194 addIntToMap(lenv->content,"mapErrorNb",lIndex); 195 } 196 setMapInMaps(m,"lenv","mapError","true"); 197 setMapArray(lenv->content,"locator",lIndex,tmpI->name); 198 if(nbElements==NULL) 199 setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data.")); 200 else 201 setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file.")); 202 if(getMapFromMaps(m,"lenv","state")==NULL) 203 errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name); 204 } 205 return; 206 } 154 207 int proto=0; 155 208 if(rformat==NULL){ 156 rformat=getMap (tmpI->content,"mimeType");209 rformat=getMapArray(tmpI->content,"mimeType",imyIndex); 157 210 } 158 211 if(strncasecmp(rformat->value,"text/xml",8)==0) 159 212 proto=1; 160 if(strncasecmp(rformat->value,"image/tiff",10)==0) 213 if(strncasecmp(rformat->value,"image/tiff",10)==0 || 214 strncasecmp(rformat->value,"image/geotiff",10)==0) 161 215 proto=2; 216 int hasFormat=-1; 162 217 if(protoMap!=NULL){ 163 if(strncasecmp(protoMap->value,"WMS",3)==0) 218 hasFormat=1; 219 if(strncasecmp(protoMap->value,"WMS",3)==0){ 164 220 proto=0; 221 rformat=createMap("value","image/png"); 222 } 165 223 else{ 166 if(strncasecmp(protoMap->value,"WFS",3)==0) 224 if(strncasecmp(protoMap->value,"WFS",3)==0){ 167 225 proto=1; 168 else 226 rformat=createMap("value","text/xml"); 227 } 228 else { 169 229 proto=2; 230 rformat=createMap("value","image/tiff"); 231 } 170 232 } 171 233 } … … 178 240 } 179 241 180 map* extent=getMap(tmpI->content,options[proto][4]); 181 map* crs=getMap(tmpI->content,"crs"); 242 243 map* extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 244 map* crs=getMapArray(tmpI->content,"crs",imyIndex); 182 245 int hasCRS=1; 183 246 if(crs==NULL){ … … 189 252 } 190 253 char layers[128]; 191 sprintf(layers,options[proto][3],tmpI->name); 192 193 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 254 if(layerName==NULL) 255 sprintf(layers,options[proto][3],tmpI->name); 256 else 257 sprintf(layers,options[proto][3],layerName->value); 258 259 if(format==NULL || width==NULL || height==NULL || extent==NULL){ 260 char tmpStr[1024]; 261 sprintf(tmpStr,_("Unable to create the mapfile for %s because of missing values."),tmpI->name); 262 errorException (m, tmpStr, 263 "InternalError", NULL); 264 exit(-1); 265 return; 266 } 267 268 if(proto==0){ 269 hasFormat=1; 270 rformat=createMap("mimeType","image/png"); 271 }else{ 272 if(proto==1){ 273 rformat=createMap("mimeType","text/xml"); 274 hasFormat=1; 275 } 276 else 277 if(proto==2){ 278 rformat=createMap("mimeType","image/tiff"); 279 hasFormat=1; 280 finalProto=1; 281 } 282 } 283 284 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(rformat->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 285 194 286 195 287 if(proto>0){ 288 if(proto==2) 289 finalProto=1; 196 290 sprintf(webService_url, 197 "%s?map=%s/%s_% s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",291 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 198 292 msUrl->value, 199 293 dataPath->value, 200 294 tmpI->name, 295 imyIndex, 201 296 sid->value, 202 297 options[proto][2], … … 208 303 crs->value 209 304 ); 305 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 306 setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url); 307 } 308 else{ 309 setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url); 310 } 311 proto=0; 312 freeMap(&rformat); 313 free(rformat); 314 rformat=createMap("mimeType","image/png"); 210 315 } 211 316 else{ 212 317 sprintf(webService_url, 213 "%s?map=%s/%s_% s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",318 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", 214 319 msUrl->value, 215 320 dataPath->value, 216 321 tmpI->name, 322 imyIndex, 217 323 sid->value, 218 324 options[proto][2], … … 226 332 crs->value 227 333 ); 334 setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url); 335 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 336 proto=2; 337 freeMap(&rformat); 338 free(rformat); 339 rformat=createMap("mimeType","image/tiff"); 340 } 341 else{ 342 proto=1; 343 freeMap(&rformat); 344 free(rformat); 345 rformat=createMap("mimeType","text/xml"); 346 } 347 } 348 setMapArray(tmpI->content,"Reference",imyIndex,webService_url); 349 memset(layers,0,128); 350 sprintf(layers,options[proto][3],tmpI->name); 351 protoVersion=options[proto][1]; 352 extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 353 memset(webService_url,0,strlen(webService_url)); 354 if(proto>0){ 355 if(proto==2) 356 finalProto=1; 357 sprintf(webService_url, 358 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 359 msUrl->value, 360 dataPath->value, 361 tmpI->name, 362 imyIndex, 363 sid->value, 364 options[proto][2], 365 options[proto][0], 366 protoVersion, 367 layers, 368 rformat->value, 369 extent->value, 370 crs->value 371 ); 372 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 373 setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url); 374 } 375 else{ 376 setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url); 377 } 378 }else{ 379 sprintf(webService_url, 380 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", 381 msUrl->value, 382 dataPath->value, 383 tmpI->name, 384 imyIndex, 385 sid->value, 386 options[proto][2], 387 options[proto][0], 388 protoVersion, 389 layers, 390 width->value, 391 height->value, 392 rformat->value, 393 extent->value, 394 crs->value 395 ); 396 setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url); 397 } 398 if(finalProto>0){ 399 proto=3; 400 memset(layers,0,128); 401 sprintf(layers,options[proto][3],tmpI->name); 402 protoVersion=options[proto][1]; 403 extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 404 memset(webService_url,0,strlen(webService_url)); 405 freeMap(&rformat); 406 free(rformat); 407 rformat=createMap("value","image/tiff"); 408 sprintf(webService_url, 409 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 410 msUrl->value, 411 dataPath->value, 412 tmpI->name, 413 imyIndex, 414 sid->value, 415 options[proto][2], 416 options[proto][0], 417 protoVersion, 418 layers, 419 rformat->value, 420 extent->value, 421 crs->value 422 ); 423 setMapArray(tmpI->content,"ref_wcs_preview_link",imyIndex,webService_url); 228 424 } 229 425 if(hasCRS==0){ … … 231 427 free(crs); 232 428 } 233 addToMap(tmpI->content,"Reference",webService_url); 429 freeMap(&rformat); 430 free(rformat); 234 431 free(webService_url); 235 432 } … … 249 446 OGRSpatialReferenceH hSRS; 250 447 map* msSrs=NULL; 448 int imyIndex=getPublishedId(output); 251 449 hSRS = OSRNewSpatialReference(NULL); 252 450 if( pszProjection!=NULL && strlen(pszProjection)>1){ … … 272 470 if(output!=NULL){ 273 471 if(OSRIsGeographic(hSRS)==TRUE) 274 addToMap(output->content,"crs_isGeographic","true");472 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 275 473 else 276 addToMap(output->content,"crs_isGeographic","false");277 addToMap(output->content,"crs",tmpSrs);474 setMapArray(output->content,"crs_isGeographic",imyIndex,"false"); 475 setMapArray(output->content,"crs",imyIndex,tmpSrs); 278 476 } 279 477 } … … 288 486 if(output!=NULL){ 289 487 if(OSRIsGeographic(hSRS)==TRUE) 290 addToMap(output->content,"crs_isGeographic","true");488 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 291 489 else 292 addToMap(output->content,"crs_isGeographic","false");490 setMapArray(output->content,"crs_isGeographic",imyIndex,"false"); 293 491 } 294 492 free(proj4Str); … … 298 496 msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326"); 299 497 if(output!=NULL){ 300 addToMap(output->content,"crs_isGeographic","true");498 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 301 499 } 302 500 } 303 501 if(output!=NULL){ 304 addToMap(output->content,"crs","EPSG:4326");305 addToMap(output->content,"real_extent","true");502 setMapArray(output->content,"crs",imyIndex,"EPSG:4326"); 503 setMapArray(output->content,"real_extent",imyIndex,"true"); 306 504 } 307 505 msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); … … 312 510 else{ 313 511 if(output!=NULL){ 314 msSrs=getMap (output->content,"msSrs");512 msSrs=getMapArray(output->content,"msSrs",imyIndex); 315 513 } 316 514 if(msSrs!=NULL){ … … 328 526 } 329 527 if(output!=NULL){ 330 addToMap(output->content,"crs",msSrs->value);331 addToMap(output->content,"crs_isGeographic","true");528 setMapArray(output->content,"crs",imyIndex,msSrs->value); 529 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 332 530 } 333 531 } … … 351 549 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer, 352 550 double minX,double minY,double maxX,double maxY){ 551 int imyIndex=getPublishedId(output); 353 552 msMapSetExtent(m,minX,minY,maxX,maxY); 553 //m->maxsize=4096; 354 554 #ifdef DEBUGMS 355 555 fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY); … … 363 563 364 564 if(output!=NULL){ 365 map* test=getMap(output->content,"real_extent"); 565 map* test=getMapArray(output->content,"real_extent",imyIndex); 566 pointObj min, max; 567 projectionObj tempSrs; 568 min.x = m->extent.minx; 569 min.y = m->extent.miny; 570 max.x = m->extent.maxx; 571 max.y = m->extent.maxy; 572 char tmpSrsStr[1024]; 573 msInitProjection(&tempSrs); 574 msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326"); 575 576 msProjectPoint(&(myLayer->projection),&tempSrs,&min); 577 msProjectPoint(&myLayer->projection,&tempSrs,&max); 578 366 579 if(test!=NULL){ 367 pointObj min, max; 368 projectionObj tempSrs; 369 min.x = m->extent.minx; 370 min.y = m->extent.miny; 371 max.x = m->extent.maxx; 372 max.y = m->extent.maxy; 373 char tmpSrsStr[1024]; 374 msInitProjection(&tempSrs); 375 msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326"); 376 377 msProjectPoint(&(m->projection),&tempSrs,&min); 378 msProjectPoint(&m->projection,&tempSrs,&max); 379 380 sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x); 381 map* isGeo=getMap(output->content,"crs_isGeographic"); 580 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x); 581 map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex); 382 582 #ifdef DEBUGMS 383 583 fprintf(stderr,"isGeo = %s\n",isGeo->value); 384 584 #endif 385 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) 386 sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX); 387 addToMap(output->content,"wms_extent",tmpExtent); 388 sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y); 389 addToMap(output->content,"wcs_extent",tmpExtent); 585 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0){ 586 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x); 587 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 588 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX); 589 }else{ 590 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 591 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 592 } 593 setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 594 sprintf(tmpSrsStr,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 595 setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent); 390 596 }else{ 391 sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY); 392 map* isGeo=getMap(output->content,"crs_isGeographic"); 597 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 598 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 599 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX, minY, maxX, maxY); 600 map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex); 393 601 if(isGeo!=NULL){ 394 602 #ifdef DEBUGMS … … 396 604 #endif 397 605 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) 398 sprintf(tmpExtent,"% f,%f,%f,%f", minY,minX, maxY, maxX);399 } 400 addToMap(output->content,"wms_extent",tmpExtent);401 sprintf(tmpExtent,"%. 3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);402 addToMap(output->content,"wcs_extent",tmpExtent);606 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX); 607 } 608 setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 609 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX,minY,maxX,maxY); 610 setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent); 403 611 } 404 612 } … … 415 623 */ 416 624 int tryOgr(maps* conf,maps* output,mapObj* m){ 417 418 map* tmpMap=getMap (output->content,"storage");625 int imyIndex=getPublishedId(output); 626 map* tmpMap=getMapArray(output->content,"storage",imyIndex); 419 627 char *pszDataSource=tmpMap->value; 420 628 … … 425 633 /** 426 634 * Try to load the file as ZIP 427 */ 428 635 * 429 636 OGRDataSourceH poDS1 = NULL; 430 637 OGRSFDriverH *poDriver1 = NULL; … … 467 674 fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); 468 675 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 469 OGR_DS_Destroy(poDS1); 676 fprintf(stderr,"Remove ZIP File!\n"); 677 unlink(odsName); 678 //OGR_DS_Destroy(poDS1); 470 679 }else{ 471 680 #ifdef DEBUGMS … … 526 735 i++; 527 736 } 528 } 737 OGR_DS_Destroy(poDS1); 738 } 529 739 free(sdsName); 530 free(dsName); 531 740 free(dsName);*/ 741 532 742 OGRDataSourceH poDS = NULL; 533 743 OGRSFDriverH *poDriver = NULL; … … 538 748 #endif 539 749 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 540 OGR_DS_Destroy(poDS);541 OGRCleanupAll();542 750 #ifdef DEBUGMS 543 751 fprintf(stderr,"Unable to access the DataSource, exit! \n"); … … 546 754 } 547 755 756 setMapArray(output->content,"gdalType",imyIndex,OGR_Dr_GetName(OGR_DS_GetDriver(poDS))); 757 setMapArray(output->content,"geodatatype",imyIndex,"vector"); 548 758 int iLayer = 0; 549 759 for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){ … … 561 771 * Add a new layer set name, data 562 772 */ 563 if(msGrowMapLayers(m)==NULL){ 564 return -1; 565 } 566 if(initLayer((m->layers[m->numlayers]), m) == -1){ 567 return -1; 568 } 569 570 layerObj* myLayer=m->layers[m->numlayers]; 773 layerObj* myLayer=NULL; 774 if(getMapArray(output->content,"msInclude",imyIndex)==NULL){ 775 if(msGrowMapLayers(m)==NULL){ 776 return -1; 777 } 778 if(initLayer((m->layers[m->numlayers]), m) == -1){ 779 return -1; 780 } 781 myLayer=m->layers[m->numlayers]; 782 }else{ 783 myLayer=m->layers[m->numlayers-1]; 784 } 785 571 786 #ifdef DEBUGMS 572 787 dumpMaps(output); … … 580 795 myLayer->status = MS_ON; 581 796 msConnectLayer(myLayer,MS_OGR,pszDataSource); 797 798 addIntToMapArray(output->content,"nb_features",imyIndex,OGR_L_GetFeatureCount(poLayer,1)); 582 799 583 800 /** … … 631 848 } 632 849 else{ 633 addToMap(output->content,"crs","EPSG:4326");634 addToMap(output->content,"crs_isGeographic","true");850 setMapArray(output->content,"crs",imyIndex,"EPSG:4326"); 851 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 635 852 msLoadProjectionStringEPSG(&m->projection,"EPSG:4326"); 636 853 msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); … … 641 858 if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){ 642 859 setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); 860 char extent[1024]; 861 memset(&extent,0,1024); 862 sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); 863 setMapArray(output->content,"boundingbox",imyIndex,extent); 643 864 } 644 865 … … 659 880 msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all"); 660 881 msInsertHashTable(&(myLayer->metadata), "ows_name", output->name); 661 map* tmpMap=getMap (output->content,"title");882 map* tmpMap=getMapArray(output->content,"title",imyIndex); 662 883 if(tmpMap!=NULL) 663 884 msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value); 664 885 else 665 886 msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title"); 887 888 if(getMapArray(output->content,"msInclude",imyIndex)==NULL){ 889 if(msGrowLayerClasses(myLayer) == NULL) 890 return -1; 891 if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) 892 return -1; 893 if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) 894 return -1; 895 if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) 896 return -1; 897 /** 898 * Apply msStyle else fallback to the default style 899 */ 900 tmpMap=getMap(output->content,"msStyle"); 901 if(tmpMap==NULL){ 902 switch(myLayer->type){ 903 case MS_LAYER_POLYGON: 904 tmpMap=getMapFromMaps(conf,"main","msStylePoly"); 905 break; 906 case MS_LAYER_LINE: 907 tmpMap=getMapFromMaps(conf,"main","msStyleLine"); 908 break; 909 default: 910 tmpMap=getMapFromMaps(conf,"main","msStylePoint"); 911 break; 912 } 913 } 914 if(tmpMap!=NULL) 915 msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0); 916 else{ 917 /** 918 * Set style 919 */ 920 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125; 921 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125; 922 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255; 923 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80; 924 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80; 925 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80; 926 927 /** 928 * Set specific style depending on type 929 */ 930 if(myLayer->type == MS_LAYER_POLYGON) 931 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 932 if(myLayer->type == MS_LAYER_LINE){ 933 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 934 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5; 935 } 936 if(myLayer->type == MS_LAYER_POINT){ 937 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1; 938 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15; 939 } 940 941 } 942 myLayer->CLASS[myLayer->numclasses]->numstyles++; 943 myLayer->numclasses++; 666 944 667 if(msGrowLayerClasses(myLayer) == NULL) 668 return -1; 669 if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) 670 return -1; 671 if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) 672 return -1; 673 if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) 674 return -1; 675 /** 676 * Apply msStyle else fallback to the default style 677 */ 678 tmpMap=getMap(output->content,"msStyle"); 679 if(tmpMap!=NULL) 680 msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0); 681 else{ 682 /** 683 * Set style 684 */ 685 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125; 686 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125; 687 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255; 688 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80; 689 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80; 690 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80; 691 692 /** 693 * Set specific style depending on type 694 */ 695 if(myLayer->type == MS_LAYER_POLYGON) 696 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 697 if(myLayer->type == MS_LAYER_LINE){ 698 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 699 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5; 700 } 701 if(myLayer->type == MS_LAYER_POINT){ 702 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1; 703 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15; 704 } 705 706 } 707 myLayer->CLASS[myLayer->numclasses]->numstyles++; 708 myLayer->numclasses++; 709 710 m->layerorder[m->numlayers] = m->numlayers; 711 m->numlayers++; 712 713 } 714 945 m->layerorder[m->numlayers] = m->numlayers; 946 m->numlayers++; 947 948 } 949 } 715 950 OGR_DS_Destroy(poDS); 716 OGRCleanupAll();951 //OGRCleanupAll(); 717 952 718 953 return 1; … … 727 962 */ 728 963 int tryGdal(maps* conf,maps* output,mapObj* m){ 729 map* tmpMap=getMap(output->content,"storage"); 964 int imyIndex=getPublishedId(output); 965 map* tmpMap=getMapArray(output->content,"storage",imyIndex); 966 map* styleMap=getMap(output->content,"msStyle"); 730 967 char *pszFilename=tmpMap->value; 731 968 GDALDatasetH hDataset; … … 738 975 */ 739 976 GDALAllRegister(); 740 hDataset = GDALOpen( pszFilename, GA_ ReadOnly );977 hDataset = GDALOpen( pszFilename, GA_Update ); /*GA_ReadOnly*/ 741 978 if( hDataset == NULL ){ 742 979 #ifdef DEBUGMS 743 980 fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename); 744 981 #endif 982 setMapArray(output->content,"geodatatype",imyIndex,"other"); 745 983 setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open"); 746 984 GDALDestroyDriverManager(); … … 751 989 #endif 752 990 991 setMapArray(output->content,"geodatatype",imyIndex,"raster"); 753 992 /** 754 993 * Add a new layer set name, data … … 772 1011 773 1012 char *title=output->name; 774 tmpMap=getMap (output->content,"title");1013 tmpMap=getMapArray(output->content,"title",imyIndex); 775 1014 if(tmpMap!=NULL) 776 1015 title=tmpMap->value; 777 1016 char *abstract=output->name; 778 tmpMap=getMap (output->content,"abstract");1017 tmpMap=getMapArray(output->content,"abstract",imyIndex); 779 1018 if(tmpMap!=NULL) 780 1019 abstract=tmpMap->value; … … 791 1030 m->width=GDALGetRasterXSize( hDataset ); 792 1031 m->height=GDALGetRasterYSize( hDataset ); 793 1032 if(m->width>4096 || m->height>4096){ 1033 if(m->width>m->height) 1034 m->maxsize=m->width; 1035 else 1036 m->maxsize=m->height; 1037 }else 1038 m->maxsize=4096; 1039 addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset )); 1040 int pixel_type=GDALGetRasterDataType( hDataset ); 1041 addIntToMapArray(output->content,"pixel_data_type",imyIndex,pixel_type); 1042 1043 int outputIndex=msGetOutputFormatIndex(m,"tiff"); 1044 if(outputIndex>=0){ 1045 m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE))); 1046 outputIndex=msGetOutputFormatIndex(m,"geotiff"); 1047 if(outputIndex>=0) 1048 m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE))); 1049 } 1050 // 1051 794 1052 /** 795 1053 * Set projection using Authority Code and Name if available or fallback to … … 805 1063 setSrsInformations(output,m,myLayer,pszProjection); 806 1064 }else{ 807 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 808 } 809 1065 fprintf(stderr,"NO SRS FOUND %s %d ! %s\n",__FILE__,__LINE__,GDALGetProjectionRef( hDataset )); 1066 fflush(stderr); 1067 CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" ); 1068 if(sp!=CE_None){ 1069 fprintf(stderr,"NO SRS SET ! %s\n",CPLGetLastErrorMsg()); 1070 } 1071 } 810 1072 811 1073 /** … … 825 1087 + adfGeoTransform[4] * GDALGetRasterXSize(hDataset); 826 1088 827 setMsExtent(output,m,myLayer,minX,minY,maxX,maxY); 828 829 } 1089 setMsExtent(output,m,myLayer,minX,minY,maxX,maxY); 1090 char extent[1024]; 1091 memset(&extent,0,1024); 1092 sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY); 1093 setMapArray(output->content,"boundingbox",imyIndex,extent); 1094 } 1095 }else{ 1096 int scale=1; 1097 if(m->width>2048){ 1098 addIntToMapArray(output->content,"width",imyIndex,2048); 1099 scale=2048/m->width; 1100 }else 1101 addIntToMapArray(output->content,"width",imyIndex,m->width); 1102 addIntToMapArray(output->content,"height",imyIndex,m->height*scale); 830 1103 } 831 1104 … … 835 1108 */ 836 1109 char nBands[3]; 1110 memset(&nBands,0,3); 837 1111 int nBandsI=GDALGetRasterCount( hDataset ); 838 sprintf(nBands,"%d",GDALGetRasterCount( hDataset )); 839 msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands); 840 if(nBandsI>=3) 841 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 842 else if(nBandsI>=2) 843 msLayerAddProcessing(myLayer,"BANDS=1,2"); 844 else 845 msLayerAddProcessing(myLayer,"BANDS=1"); 1112 if(nBandsI<100){ 1113 sprintf(nBands,"%d",GDALGetRasterCount( hDataset )); 1114 msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands); 1115 } 1116 if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL){ 1117 if(nBandsI>=3) 1118 if(nBandsI==4) 1119 msLayerAddProcessing(myLayer,"BANDS=1,2,3,4"); 1120 else 1121 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 1122 else if(nBandsI>=2) 1123 msLayerAddProcessing(myLayer,"BANDS=1,2"); 1124 else 1125 msLayerAddProcessing(myLayer,"BANDS=1"); 1126 } 846 1127 847 1128 /** … … 851 1132 char *nameBands=NULL; 852 1133 for( iBand = 0; iBand < nBandsI; iBand++ ){ 853 sprintf(lBands,"Band%d",iBand+1); 1134 memset(&lBands,0,7); 1135 sprintf(lBands,"Band%d",iBand+1); 854 1136 if(nameBands==NULL){ 855 1137 nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char)); 856 1138 sprintf(nameBands,"%s",lBands); 857 1139 }else{ 858 if(iBand<4){1140 /*if(iBand<4)*/{ 859 1141 char *tmpS=zStrdup(nameBands); 860 nameBands=(char*)realloc(nameBands,(strlen( nameBands)+strlen(lBands)+1)*sizeof(char));1142 nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char)); 861 1143 sprintf(nameBands,"%s %s",tmpS,lBands); 862 1144 free(tmpS); … … 864 1146 } 865 1147 } 866 msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands); 867 1148 if(nameBands!=NULL){ 1149 msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands); 1150 free(nameBands); 1151 } 1152 868 1153 /** 869 1154 * Loops over metadata information to setup specific information 870 1155 */ 871 1156 for( iBand = 0; iBand < nBandsI; iBand++ ){ 872 //int bGotNodata;//, bSuccess; 873 double adfCMinMax[2]/*, dfNoData*/; 874 //int nBlockXSize, nBlockYSize, nMaskFlags; 875 //double /*dfMean, dfStdDev*/; 1157 double pdfMin, pdfMax, pdfMean, pdfStdDev; 876 1158 hBand = GDALGetRasterBand( hDataset, iBand+1 ); 877 1159 878 1160 CPLErrorReset(); 879 GDAL ComputeRasterMinMax( hBand, FALSE, adfCMinMax);1161 GDALGetRasterStatistics( hBand, TRUE, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev); 880 1162 char tmpN[21]; 881 1163 sprintf(tmpN,"Band%d",iBand+1); 882 1164 if (CPLGetLastErrorType() == CE_None){ 883 char tmpMm[100]; 884 sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]); 885 char tmpI[21]; 1165 char tmpMm[100],tmpMp[100],tmpNb[3]; 1166 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1167 if(pdfMin!=pdfMax && (styleMap==NULL || strstr(styleMap->value,"SCALE_")==NULL)){ 1168 sprintf(tmpNb,"%d",iBand+1); 1169 if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL || strstr(strstr(styleMap->value,"BANDS="),tmpNb)!=NULL){ 1170 if(pdfMean-(2*pdfStdDev)<0) 1171 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,0.0,pdfMean+(2*pdfStdDev)); 1172 else 1173 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 1174 msLayerAddProcessing(myLayer,tmpMp); 1175 } 1176 } 1177 char tmpI[31]; 886 1178 sprintf(tmpI,"%s_interval",tmpN); 887 1179 msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm); 888 889 1180 map* test=getMap(output->content,"msClassify"); 890 1181 if(test!=NULL && strncasecmp(test->value,"true",4)==0){ … … 906 1197 907 1198 if(nBandsI==1){ 908 double delta= adfCMinMax[1]-adfCMinMax[0];1199 double delta=pdfMax-pdfMin; 909 1200 double interval=delta/10; 910 double cstep= adfCMinMax[0];1201 double cstep=pdfMin; 911 1202 for(i=0;i<10;i++){ 912 1203 /** … … 952 1243 953 1244 char tmpMm[100]; 954 sprintf(tmpMm,"%.3f %.3f", adfCMinMax[0],adfCMinMax[1]);1245 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 955 1246 956 1247 } … … 962 1253 myLayer->offsite.blue=0; 963 1254 } 964 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");965 1255 } 966 1256 } 967 1257 if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){ 968 char tmpU[ 21];1258 char tmpU[31]; 969 1259 sprintf(tmpU,"%s_band_uom",tmpN); 970 1260 msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand)); … … 972 1262 973 1263 } 974 1264 if(styleMap==NULL || strstr(styleMap->value,"RESAMPLE")==NULL) 1265 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR"); 1266 1267 if(styleMap!=NULL && strlen(styleMap->value)>9){ 1268 msUpdateLayerFromString(myLayer,styleMap->value,MS_FALSE); 1269 } 1270 975 1271 m->layerorder[m->numlayers] = m->numlayers; 976 1272 m->numlayers++; … … 978 1274 GDALDestroyDriverManager(); 979 1275 CPLCleanupTLS(); 1276 storeMd5(pszFilename); 980 1277 return 1; 981 1278 } … … 988 1285 */ 989 1286 void outputMapfile(maps* conf,maps* outputs){ 990 991 1287 /** 992 1288 * First store the value on disk 993 1289 */ 994 map* mime=getMap(outputs->content,"mimeType"); 1290 int imyIndex=getPublishedId(outputs); 1291 map* mime=getMapArray(outputs->content,"mimeType",imyIndex); 1292 map* msUrl=getMapFromMaps(conf,"main","mapserverAddress"); 1293 map* dataPath=getMapFromMaps(conf,"main","dataPath"); 995 1294 char *ext="data"; 996 1295 if(mime!=NULL) … … 998 1297 ext="json"; 999 1298 1000 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1001 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1002 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1003 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1004 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1005 map *gfile=getMap(outputs->content,"generated_file"); 1006 if(gfile!=NULL){ 1007 readGeneratedFile(conf,outputs->content,gfile->value); 1008 } 1009 map* sizeMap=getMap(outputs->content,"size"); 1010 map* vData=getMap(outputs->content,"value"); 1011 if(sizeMap!=NULL){ 1012 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1013 } 1014 else{ 1015 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1016 } 1017 close(f); 1018 addToMap(outputs->content,"storage",pszDataSource); 1019 free(pszDataSource); 1299 map* storage=getMapArray(outputs->content,"storage",imyIndex); 1300 if(storage==NULL){ 1301 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1302 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1303 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1304 sprintf(pszDataSource,"%s/ZOO_DATA_%d_%s_%s.%s",tmpMap->value,imyIndex,outputs->name,sidMap->value,ext); 1305 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1306 map *gfile=getMapArray(outputs->content,"generated_file",imyIndex); 1307 if(gfile!=NULL){ 1308 readGeneratedFile(conf,outputs->content,gfile->value); 1309 } 1310 map* sizeMap=getMapArray(outputs->content,"size",imyIndex); 1311 map* vData=getMapArray(outputs->content,"value",imyIndex); 1312 if(sizeMap!=NULL){ 1313 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1314 } 1315 else{ 1316 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1317 } 1318 close(f); 1319 setMapArray(outputs->content,"storage",imyIndex,pszDataSource); 1320 free(pszDataSource); 1321 } 1020 1322 1021 1323 /* 1022 1324 * Create an empty map, set name, default size and extent 1023 1325 */ 1024 mapObj *myMap=msNewMapObj(); 1326 map* mapfileTemplate=getMapArray(outputs->content,"msInclude",imyIndex); 1327 mapObj *myMap=NULL; 1328 if(mapfileTemplate==NULL){ 1329 myMap=msNewMapObj(); 1330 } 1331 else{ 1332 map* dataPath=getMapFromMaps(conf,"main","dataPath"); 1333 map* sid=getMapFromMaps(conf,"lenv","sid"); 1334 char *mapfileTemplatePath=(char*)malloc(((strlen(dataPath->value)+strlen(sid->value)+strlen(outputs->name)+10)*sizeof(char))); 1335 sprintf(mapfileTemplatePath,"%s/%s_%s.map",dataPath->value,outputs->name,sid->value); 1336 myMap=msLoadMap(mapfileTemplate->value,mapfileTemplatePath); 1337 if(myMap==NULL){ 1338 setMapInMaps(conf,"lenv","message",_("Unable to open your template mapfile!")); 1339 return ; 1340 } 1341 } 1025 1342 free(myMap->name); 1026 1343 myMap->name=zStrdup("ZOO-Project_WXS_Server"); … … 1048 1365 #ifdef USE_KML 1049 1366 outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml"); 1050 o2->inmapfile=MS_TRUE; 1051 msAppendOutputFormat(myMap,msCloneOutputFormat(o2)); 1052 msFreeOutputFormat(o2); 1367 if(!o2){ 1368 perror("Unable to initialize KML driver"); 1369 fprintf(stderr,"Unable to initialize KML driver !\n"); 1370 }else{ 1371 o2->inmapfile=MS_TRUE; 1372 msAppendOutputFormat(myMap,msCloneOutputFormat(o2)); 1373 msFreeOutputFormat(o2); 1374 } 1053 1375 #endif 1054 1376 … … 1057 1379 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1058 1380 else{ 1059 o3->imagemode=MS_IMAGEMODE_ BYTE;1381 o3->imagemode=MS_IMAGEMODE_INT16; 1060 1382 o3->inmapfile=MS_TRUE; 1061 1383 msAppendOutputFormat(myMap,msCloneOutputFormat(o3)); … … 1067 1389 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1068 1390 else{ 1069 o4->imagemode=MS_IMAGEMODE_ INT16;1391 o4->imagemode=MS_IMAGEMODE_BYTE; 1070 1392 o4->inmapfile=MS_TRUE; 1071 1393 msAppendOutputFormat(myMap,msCloneOutputFormat(o4)); … … 1086 1408 #endif 1087 1409 1410 1411 outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff"); 1412 if(!o6) 1413 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1414 else{ 1415 o6->imagemode=MS_IMAGEMODE_BYTE; 1416 o6->mimetype=strdup("image/geotiff"); 1417 o6->inmapfile=MS_TRUE; 1418 msAppendOutputFormat(myMap,msCloneOutputFormat(o6)); 1419 msFreeOutputFormat(o6); 1420 } 1421 1422 1088 1423 /* 1089 1424 * Set default projection to EPSG:4326 … … 1091 1426 msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326"); 1092 1427 myMap->transparent=1; 1093 1094 /**1095 * Set metadata extracted from main.cfg file maps1096 */1097 maps* cursor=conf;1098 map* correspondance=getCorrespondance();1099 while(cursor!=NULL){1100 map* _cursor=cursor->content;1101 map* vMap;1102 while(_cursor!=NULL){1103 if((vMap=getMap(correspondance,_cursor->name))!=NULL){1104 if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){1105 #ifdef DEBUGMS1106 fprintf(stderr,"Unable to add metadata");1107 #endif1108 return;1109 }1110 }1111 _cursor=_cursor->next;1112 }1113 cursor=cursor->next;1114 }1115 freeMap(&correspondance);1116 free(correspondance);1117 1428 1118 1429 /* … … 1157 1468 msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326"); 1158 1469 1470 /** 1471 * Set metadata extracted from main.cfg file maps 1472 */ 1473 maps* cursor=conf; 1474 map* correspondance=getCorrespondance(); 1475 while(cursor!=NULL){ 1476 if(strstr(cursor->name,"_help")==NULL){ 1477 map* _cursor=cursor->content; 1478 map* vMap; 1479 while(_cursor!=NULL){ 1480 if((vMap=getMap(correspondance,_cursor->name))!=NULL){ 1481 if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){ 1482 #ifdef DEBUGMS 1483 fprintf(stderr,"Unable to add metadata"); 1484 #endif 1485 freeMap(&correspondance); 1486 free(correspondance); 1487 return; 1488 } 1489 } 1490 _cursor=_cursor->next; 1491 } 1492 } 1493 cursor=cursor->next; 1494 } 1495 freeMap(&correspondance); 1496 free(correspondance); 1497 1498 map* sid=getMapFromMaps(conf,"lenv","usid"); 1499 char *mapPath= 1500 (char*)malloc((14+strlen(sid->value)+strlen(outputs->name)+strlen(dataPath->value))*sizeof(char)); 1501 sprintf(mapPath,"%s/%s_%d_%s.map",dataPath->value,outputs->name,imyIndex,sid->value); 1502 char *mapUrl= 1503 (char*)malloc((6+strlen(mapPath)+strlen(msUrl->value))*sizeof(char)); 1504 sprintf(mapUrl,"%s?map=%s",msUrl->value,mapPath); 1505 1506 if (msInsertHashTable(&(myMap->web.metadata), "ows_onlineresource", mapUrl) == NULL){ 1507 #ifdef DEBUGMS 1508 fprintf(stderr,"Unable to add metadata"); 1509 #endif 1510 return; 1511 } 1512 1159 1513 if(tryOgr(conf,outputs,myMap)<0) 1160 1514 if(tryGdal(conf,outputs,myMap)<0) 1161 1515 return ; 1162 1516 1163 tmp1=getMapFromMaps(conf,"main","dataPath"); 1164 char *tmpPath=(char*)malloc((13+strlen(tmp1->value))*sizeof(char)); 1165 sprintf(tmpPath,"%s/symbols.sym",tmp1->value); 1517 char *tmpPath=(char*)malloc((13+strlen(dataPath->value))*sizeof(char)); 1518 sprintf(tmpPath,"%s/symbols.sym",dataPath->value); 1166 1519 msInitSymbolSet(&myMap->symbolset); 1167 1520 myMap->symbolset.filename=zStrdup(tmpPath); 1168 1521 free(tmpPath); 1169 1522 1170 map* sid=getMapFromMaps(conf,"lenv","usid");1171 char *mapPath=1172 (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));1173 sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);1174 1523 msSaveMap(myMap,mapPath); 1524 saveMapNames(conf,outputs,mapPath); 1175 1525 free(mapPath); 1526 //free(myMap->symbolset.filename); 1527 //msFreeSymbolSet(&myMap->symbolset); 1528 msFreeMap(myMap); 1529 //msFree(myMap); 1176 1530 msGDALCleanup(); 1177 msFreeMap(myMap);1178 1531 } 1179 1532 1533 /** 1534 * Save the map fullpath in a text file (.maps) 1535 * @param conf the main configuration map pointer 1536 * @param output the current output for which a mapfile has been generated 1537 * @param mapfile the mapfile saved to store in the text file 1538 */ 1539 void saveMapNames(maps* conf,maps* output,char* mapfile){ 1540 map* storage=getMap(output->content,"storage"); 1541 char *tmp=zStrdup(storage->value); 1542 tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0; 1543 char* mapName=(char*)malloc((strlen(tmp)+6)*sizeof(char*)); 1544 sprintf(mapName,"%s.maps",tmp); 1545 FILE* myMaps=fopen(mapName,"a"); 1546 if(myMaps!=NULL){ 1547 fprintf(myMaps,"%s\n",mapfile); 1548 fclose(myMaps); 1549 } 1550 free(mapName); 1551 free(tmp); 1552 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_ms.h ¶ ¶
r889 r917 56 56 int tryGdal(maps* conf,maps* output,mapObj* m); 57 57 void outputMapfile(maps* conf,maps* outputs); 58 void saveMapNames(maps*,maps*,char*); 59 58 60 #ifdef __cplusplus 59 61 } -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_php7.c ¶ ¶
r796 r917 25 25 #ifdef WIN32 26 26 #define NO_FCGI_DEFINES 27 #define ZEND_WIN32_KEEP_INLINE 27 28 #endif 28 29 -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_python.c ¶ ¶
r790 r917 57 57 * from the ZOO-Kernel Python environment: 58 58 * - "_" corresponding to the PythonTranslate function 59 * - "upd te_status" corresponding to the PythonUpdateStatus function59 * - "update_status" corresponding to the PythonUpdateStatus function 60 60 * @see PythonTranslate, PythonUpdateStatus 61 61 */ … … 146 146 */ 147 147 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 148 148 149 char *pythonpath; 149 150 char *python_path; 151 152 #ifdef WIN32 153 char* os_pathsep = ";"; 154 #else 155 char* os_pathsep = ":"; 156 #endif 157 150 158 maps* m=*main_conf; 151 159 maps* inputs=*real_inputs; 152 160 maps* outputs=*real_outputs; 153 161 map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd"); 154 char *ntmp=tmp0->value; 162 char *ntmp=tmp0->value; 155 163 map* tmp=NULL; 156 164 int hasToClean=0; 157 tmp=getMapFromMaps(*main_conf,"env","PYTHONPATH"); 165 tmp=getMapFromMaps(*main_conf,"env","PYTHONPATH"); 166 167 map* kvp = NULL; 168 char* libPath = NULL; 169 if (hasvalue(*main_conf, "main", "libPath", &kvp)) { 170 libPath = kvp->value; 171 } 172 else { 173 libPath = ""; 174 } 175 158 176 #ifdef DEBUG 159 177 fprintf(stderr,"PYTHON SUPPORT \n"); … … 163 181 fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value)); 164 182 #endif 165 python_path=(char*)malloc((strlen(tmp->value) )*sizeof(char));183 python_path=(char*)malloc((strlen(tmp->value)+1)*sizeof(char)); 166 184 sprintf(python_path,"%s",tmp->value); 167 185 hasToClean=1; … … 172 190 python_path=cwdMap->value; 173 191 else 174 python_path=(char*)"."; 192 python_path=(char*)"."; 175 193 } 176 194 tmp=NULL; 177 195 tmp=getMap(request,"metapath"); 178 196 if(tmp!=NULL && strcmp(tmp->value,"")!=0){ 179 pythonpath=(char*)malloc((4+strlen(python_path)+strlen(ntmp)+strlen(tmp->value))*sizeof(char)); 197 //pythonpath=(char*)malloc((4+strlen(python_path)+strlen(ntmp)+strlen(tmp->value))*sizeof(char)); 198 pythonpath = (char*)malloc((5 + strlen(python_path) + strlen(ntmp) + strlen(tmp->value) + strlen(libPath)) * sizeof(char)); 180 199 #ifdef WIN32 181 sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path); 200 //sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path); 201 sprintf(pythonpath, "%s/%s/;%s;%s", ntmp, tmp->value, python_path, libPath); 182 202 #else 183 sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path); 203 //sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path); 204 sprintf(pythonpath, "%s/%s/:%s:%s", ntmp, tmp->value, python_path, libPath); 184 205 #endif 185 206 } 186 207 else{ 187 pythonpath=(char*)malloc((2+strlen(python_path)+strlen(ntmp))*sizeof(char)); 208 //pythonpath=(char*)malloc((2+strlen(python_path)+strlen(ntmp))*sizeof(char)); 209 pythonpath = (char*)malloc((3 + strlen(python_path) + strlen(ntmp) + strlen(libPath)) * sizeof(char)); 188 210 #ifdef WIN32 189 sprintf(pythonpath,"%s;%s",ntmp,python_path); 211 //sprintf(pythonpath,"%s;%s",ntmp,python_path); 212 sprintf(pythonpath, "%s;%s;%s", ntmp, python_path, libPath); 190 213 #else 191 sprintf(pythonpath,"%s:%s",ntmp,python_path); 192 #endif 214 //sprintf(pythonpath,"%s:%s",ntmp,python_path); 215 sprintf(pythonpath, "%s:%s:%s", ntmp, python_path, libPath); 216 #endif 193 217 } 194 218 #ifdef DEBUG 195 219 fprintf(stderr,"PYTHONPATH=%s\n",pythonpath); 196 220 #endif 197 #ifndef WIN32 198 setenv("PYTHONPATH",pythonpath,1); 199 #else 221 map* home = NULL; 222 // knut: also set PYTHONHOME environment variable so that Python can load standard modules 223 #ifndef WIN32 224 setenv("PYTHONPATH",pythonpath,1); 225 //= getMapFromMaps(*main_conf, "env", "PYTHONHOME"); 226 if (hasvalue(*main_conf, "env", "PYTHONHOME", &home)) { 227 setenv("PYTHONHOME", home->value, 1); // overwrite 228 } 229 #else 200 230 SetEnvironmentVariable("PYTHONPATH",pythonpath); 201 231 char* toto=(char*)malloc((strlen(pythonpath)+12)*sizeof(char)); 202 232 sprintf(toto,"PYTHONPATH=%s",pythonpath); 203 putenv(toto);233 _putenv(toto); 204 234 free(toto); 205 #endif 235 if (hasvalue(*main_conf, "env", "PYTHONHOME", &home)) { 236 SetEnvironmentVariable("PYTHONHOME", home->value); 237 } 238 char buffer[128]; 239 #endif 206 240 if(hasToClean>0) 207 241 free(python_path); … … 209 243 210 244 PyThreadState *mainstate; 211 #if PY_MAJOR_VERSION >= 3 212 PyImport_AppendInittab("zoo", init_zoo); 245 #if PY_MAJOR_VERSION >= 3 246 PyImport_AppendInittab("zoo", init_zoo); 213 247 #else 214 248 PyEval_InitThreads(); 215 #endif 216 Py_Initialize(); 217 #if PY_MAJOR_VERSION >= 3 249 #endif 250 Py_Initialize(); 251 #if PY_MAJOR_VERSION >= 3 218 252 PyEval_InitThreads(); 219 PyImport_ImportModule("zoo"); 253 PyImport_ImportModule("zoo"); 220 254 #else 221 255 init_zoo(); 222 #endif 256 #endif 223 257 mainstate = PyThreadState_Swap(NULL); 224 258 PyEval_ReleaseLock(); … … 240 274 char *mn=(char*)malloc((strlen(mps)+strlen(tmp->value)+2)*sizeof(char)); 241 275 sprintf(mn,"%s.%s",mps,tmp->value); 242 pName = PyString_FromString(mn); 276 pName = PyString_FromString(mn); 243 277 free(mn); 244 278 free(mps); … … 251 285 errorException (m, "Unable to parse serviceProvider please check your zcfg file.", "NoApplicableCode", NULL); 252 286 exit(-1); 253 } 254 pModule = PyImport_Import(pName); 287 } 288 pModule = PyImport_Import(pName); 255 289 int res=SERVICE_FAILED; 256 290 if (pModule != NULL) { … … 267 301 PyTuple_SetItem(pArgs, 1, (PyObject *)arg2); 268 302 PyTuple_SetItem(pArgs, 2, (PyObject *)arg3); 269 pValue = PyObject_CallObject(pFunc, pArgs); 303 pValue = PyObject_CallObject(pFunc, pArgs); 270 304 if (pValue != NULL) { 271 305 res=PyInt_AsLong(pValue); … … 275 309 free(*main_conf); 276 310 *main_conf=mapsFromPyDict(arg1); 277 *real_outputs=mapsFromPyDict(arg3); 311 *real_outputs=mapsFromPyDict(arg3); 278 312 #ifdef DEBUG 279 313 fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue)); … … 281 315 dumpMaps(*real_outputs); 282 316 #endif 283 }else{ 317 }else{ 284 318 PythonZooReport(m,tmp->value,0); 285 319 res=-1; … … 301 335 #endif 302 336 PyThreadState_Swap(mainstate); 303 Py_Finalize(); 337 Py_Finalize(); 304 338 return res; 305 339 } … … 323 357 char *pbt=NULL; 324 358 if(PyString_Check(trace)){ 325 pbt=(char*)malloc(( 7+strlen(PyString_AsString(trace))+1)*sizeof(char));359 pbt=(char*)malloc((8+strlen(PyString_AsString(trace)))*sizeof(char)); 326 360 sprintf(pbt,"TRACE: %s",PyString_AsString(trace)); 327 361 } 328 362 else 329 363 fprintf(stderr,"EMPTY TRACE ?"); 330 364 331 365 trace=NULL; 332 366 … … 425 459 map* isArray=getMap(tmp,"isArray"); 426 460 map* size=getMap(tmp,"size"); 461 map* useFile=getMap(tmp,"use_file"); 462 map* cacheFile=getMap(tmp,"cache_file"); 427 463 map* tmap=getMapType(tmp); 428 464 while(tmp!=NULL){ … … 435 471 PyObject* mvalue=PyList_New(cnt); 436 472 PyObject* svalue=PyList_New(cnt); 473 PyObject* cvalue=PyList_New(cnt); 437 474 438 475 for(int i=0;i<cnt;i++){ 439 476 440 map* vMap=getMapArray(tmp,"value",i); 441 map* sMap=getMapArray(tmp,"size",i); 477 map* vMap=getMapArray(t,"value",i); 478 map* uMap=getMapArray(t,"use_file",i); 479 map* sMap=getMapArray(t,"size",i); 480 map* cMap=getMapArray(t,"cache_file",i); 442 481 443 482 if(vMap!=NULL){ … … 445 484 PyObject* lvalue; 446 485 PyObject* lsvalue; 447 if(sMap==NULL){ 486 PyObject* lcvalue; 487 if(sMap==NULL || uMap!=NULL){ 448 488 lvalue=PyString_FromString(vMap->value); 449 lsvalue=Py_None;450 489 } 451 490 else{ 452 491 lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value)); 492 } 493 if(sMap!=NULL){ 453 494 lsvalue=PyString_FromString(sMap->value); 454 495 hasSize=1; 455 496 } 497 else 498 lsvalue=Py_None; 499 if(uMap!=NULL){ 500 lcvalue=PyString_FromString(cMap->value);; 501 }else 502 lcvalue=Py_None; 456 503 457 504 if(PyList_SetItem(value,i,lvalue)<0){ … … 463 510 return NULL; 464 511 } 512 if(PyList_SetItem(cvalue,i,lcvalue)<0){ 513 fprintf(stderr,"Unable to set key value pair..."); 514 return NULL; 515 } 465 516 } 466 517 518 PyObject* lmvalue; 467 519 map* mMap=getMapArray(tmp,tmap->name,i); 468 PyObject* lmvalue;469 520 if(mMap!=NULL){ 470 521 lmvalue=PyString_FromString(mMap->value); … … 487 538 return NULL; 488 539 } 540 if(PyDict_SetItem(res,PyString_FromString("cache_file"),cvalue)<0){ 541 fprintf(stderr,"Unable to set key value pair..."); 542 return NULL; 543 } 489 544 if(hasSize>0) 490 545 if(PyDict_SetItem(res,PyString_FromString("size"),svalue)<0){ … … 493 548 } 494 549 } 495 else if(size!=NULL ){550 else if(size!=NULL && useFile==NULL){ 496 551 PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value)); 497 552 if(PyDict_SetItem(res,name,value)<0){ -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_python.h ¶ ¶
r640 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-201 0GeoLabs SARL4 * Copyright (c) 2009-2019 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 28 28 #pragma once 29 29 30 #include <Python.h> 30 31 #include "service_internal.h" 31 32 #include "response_print.h" 32 #include <Python.h>33 #include "cgic.h"34 33 #ifdef WIN32 35 34 #include <windows.h> -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_ruby.c ¶ ¶
r790 r917 260 260 int hasSize=0; 261 261 map* isArray=getMap(tmp,"isArray"); 262 map* useFile=getMap(tmp,"use_file"); 262 263 map* size=getMap(tmp,"size"); 263 264 map* tmap=getMapType(tmp); … … 271 272 VALUE mvalue=rb_ary_new2(cnt); 272 273 VALUE svalue=rb_ary_new2(cnt); 274 VALUE cvalue=rb_ary_new2(cnt); 273 275 274 276 for(int i=0;i<cnt;i++){ … … 276 278 map* vMap=getMapArray(tmp,"value",i); 277 279 map* sMap=getMapArray(tmp,"size",i); 280 map* uMap=getMapArray(tmp,"use_file",i); 281 map* cMap=getMapArray(tmp,"cache_file",i); 278 282 279 283 if(vMap!=NULL){ … … 281 285 VALUE lvalue; 282 286 VALUE lsvalue; 283 if(sMap==NULL){ 287 VALUE lcvalue; 288 if(sMap==NULL || uMap==NULL){ 284 289 lvalue=rb_str_new2(vMap->value); 285 lsvalue=Qnil; 290 if(sMap==NULL) 291 lsvalue=Qnil; 292 else 293 lsvalue=rb_str_new2(sMap->value); 286 294 } 287 295 else{ … … 290 298 hasSize=1; 291 299 } 300 if(uMap!=NULL) 301 lcvalue=rb_str_new2(cMap->value); 302 else 303 lcvalue=Qnil; 292 304 293 305 rb_ary_push(value,lvalue); 294 306 rb_ary_push(svalue,lsvalue); 307 rb_ary_push(cvalue,lcvalue); 295 308 } 296 309 … … 308 321 rb_hash_aset(res, name, mvalue); 309 322 rb_hash_aset(res, rb_str_new2(tmap->name), mvalue); 323 VALUE lname0=rb_str_new2("cache_size"); 324 rb_hash_aset(res, lname0, value); 310 325 311 326 if(hasSize>0){ -
TabularUnified trunk/zoo-project/zoo-kernel/service_internal_saga.c ¶ ¶
r790 r917 30 30 #include <api_core.h> 31 31 #include <data_manager.h> 32 #include < module_library.h>32 #include <saga_api.h> 33 33 #define _ZOO_SAGA 34 34 #include "service_internal_saga.h" … … 237 237 return false; 238 238 } 239 return( param->Set_Value(SG_Get_Data_Manager().Find(&fileName)) ); 239 fprintf(stderr,"%s %s\n",carg->name,carg->value); 240 fflush(stderr); 241 return( param->Set_Value(SG_Get_Data_Manager().Find(&fileName,false)) ); 240 242 } 241 243 else … … 250 252 SG_Get_Data_Manager().Add(&fileName); 251 253 } 252 param->asList()->Add_Item(SG_Get_Data_Manager().Find(&fileName ));254 param->asList()->Add_Item(SG_Get_Data_Manager().Find(&fileName,false)); 253 255 } 254 256 } … … 327 329 inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MIN").b_str()); 328 330 if(inmap!=NULL) 331 #if SAGA_MAJOR_VERSION == 2 329 332 param->asRange()->Set_LoVal(strtod(inmap->value,NULL)); 333 #else 334 param->asRange()->Set_Min(strtod(inmap->value,NULL)); 335 #endif 330 336 inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MAX").b_str()); 331 337 if(inmap!=NULL) 338 #if SAGA_MAJOR_VERSION == 2 332 339 param->asRange()->Set_HiVal(strtod(inmap->value,NULL)); 340 #else 341 param->asRange()->Set_Max(strtod(inmap->value,NULL)); 342 #endif 333 343 } 334 344 if(inmap==NULL){ … … 386 396 else if( param->is_DataObject_List() ) 387 397 { 388 for(int i=0; i<param->asList()->Get_Count(); i++) 398 for(int i=0; i< 399 #if SAGA_MAJOR_VERSION == 2 400 param->asList()->Get_Count() 401 #else 402 param->asList()->Get_Data_Count() 403 #endif 404 ; i++) 389 405 { 390 CSG_Data_Object *pObject = param->asList()->asDataObject(i); 406 CSG_Data_Object *pObject = 407 #if SAGA_MAJOR_VERSION == 2 408 param->asList()->asDataObject(i) 409 #else 410 param->asList()->Get_Data(i) 411 #endif 412 ; 391 413 392 414 if( pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) ) … … 439 461 } 440 462 } 441 463 #if SAGA_MAJOR_VERSION == 2 442 464 int nFileNames = param->asList()->Get_Count() <= fileNames.Get_Count() ? fileNames.Get_Count() : fileNames.Get_Count() - 1; 443 465 for(int i=0; i<param->asList()->Get_Count(); i++) … … 458 480 CSG_String(param->asList()->asDataObject(i)->Get_File_Name()).b_str()); 459 481 } 482 #else 483 int nFileNames = param->asList()->Get_Data_Count() <= fileNames.Get_Count() ? fileNames.Get_Count() : fileNames.Get_Count() - 1; 484 for(int i=0; i<param->asList()->Get_Data_Count(); i++) 485 { 486 if( i < nFileNames ) 487 { 488 param->asList()->Get_Data(i)->Save(fileNames[i]); 489 } 490 else 491 { 492 param->asList()->Get_Data(i)->Save(CSG_String::Format(SG_T("%s_%0*d"), 493 fileNames[fileNames.Get_Count() - 1].c_str(), 494 SG_Get_Digit_Count(param->asList()->Get_Data_Count()), 495 1 + i - nFileNames 496 )); 497 } 498 setMapArray(cMaps->content,"generated_file",i, 499 CSG_String(param->asList()->Get_Data(i)->Get_File_Name()).b_str()); 500 } 501 502 #endif 460 503 } 461 504 } … … 477 520 int res=SERVICE_FAILED; 478 521 522 #if SAGA_MAJOR_VERSION == 2 479 523 CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(lib_name),true); 524 #else 525 CSG_Tool_Library * library=SG_Get_Tool_Library_Manager().Get_Library(CSG_String(lib_name),true); 526 #endif 480 527 if( library == NULL){ 481 528 char tmp[255]; … … 486 533 } 487 534 535 #if SAGA_MAJOR_VERSION == 2 488 536 CSG_Module * module=library->Get_Module(atoi(module_name)); 537 #else 538 CSG_Tool * module=library->Get_Tool(atoi(module_name)); 539 #endif 489 540 if(module == NULL){ 490 541 char tmp[255]; … … 985 1036 SG_Set_UI_Callback(Get_Callback(watcher)); 986 1037 1038 #if SAGA_MAJOR_VERSION == 2 987 1039 int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false); 988 if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){ 1040 if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ) 1041 #else 1042 int n = SG_Get_Tool_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false); 1043 if( SG_Get_Tool_Library_Manager().Get_Count() <= 0 ) 1044 #endif 1045 { 989 1046 setMapInMaps(*main_conf,"lenv","message","Could not load any SAGA tool library"); 990 1047 res=SERVICE_FAILED; … … 995 1052 996 1053 // Load the SAGA-GIS library corresponding to the serviceProvider 1054 #if SAGA_MAJOR_VERSION == 2 997 1055 CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(serviceProvider->value),true); 1056 #else 1057 CSG_Tool_Library * library=SG_Get_Tool_Library_Manager().Get_Library(CSG_String(serviceProvider->value),true); 1058 #endif 998 1059 if( library == NULL){ 999 1060 char tmp[255]; … … 1005 1066 1006 1067 // Load the SAGA-GIS module corresponding to the service name from the library 1068 #if SAGA_MAJOR_VERSION == 2 1007 1069 CSG_Module * module=library->Get_Module(atoi(s->name)); 1070 #else 1071 CSG_Tool * module=library->Get_Tool(atoi(s->name)); 1072 #endif 1008 1073 if(module == NULL){ 1009 1074 char tmp[255]; … … 1017 1082 // Load all the parameters defined for the module 1018 1083 CSG_Parameters * params=module->Get_Parameters(); 1019 int pc=params->Get_Count();1020 1084 if(!params){ 1021 1085 char tmp[255]; … … 1026 1090 return res; 1027 1091 } 1092 int pc=params->Get_Count(); 1028 1093 1029 1094 // Loop over each inputs to transform raster files to grid when needed, -
TabularUnified trunk/zoo-project/zoo-kernel/service_yaml.c ¶ ¶
r790 r917 487 487 addMapToIoType(¤t_element->supported,current_content); 488 488 } 489 freeMap s(¤t_content);489 freeMap(¤t_content); 490 490 free(current_content); 491 491 current_content=NULL; -
TabularUnified trunk/zoo-project/zoo-kernel/sql/schema.sql ¶ ¶
r781 r917 31 31 -- Create a dedicated schema to store all tables 32 32 -- Uncomment the following 2 lines to activate the schema use 33 -- CREATE SCHEMA zoo;34 -- SET search_path TO zoo;33 -- CREATE SCHEMA processdb; 34 -- SET search_path TO processdb; 35 35 -------------------------------------------------------------------------------- 36 36 -- Services table -
TabularUnified trunk/zoo-project/zoo-kernel/sqlapi.c ¶ ¶
r786 r917 1 1 /* 2 * Author : David Saggiorato3 * Gérald Fenoy2 * Authors : David Saggiorato 3 * Gérald Fenoy 4 4 * Copyright 2015 GeoLabs SARL. All rights reserved. 5 5 * … … 23 23 */ 24 24 25 #ifdef RELY_ON_DB26 25 #include "ogr_api.h" 27 26 #include "ogrsf_frmts.h" … … 44 43 OGRDataSource 45 44 #endif 46 * zoo_DS = NULL;45 **zoo_DS = NULL; 47 46 48 47 /** … … 52 51 53 52 /** 54 * Create a GDAL / OGR string for connecting to the db backend 55 * (do not support active_schema) 56 * 57 * @param conf the maps containing the setting of the main.cfg file 58 */ 59 char* createInitString(maps* conf){ 53 * Create a GDAL / OGR string for connecting to a db backend defined in the 54 * key section. 55 * 56 * @param conf the maps containing the setting of the main.cfg file 57 * @param key the name of the section containing the connection setting 58 * @return the OGR connection string 59 */ 60 char* _createInitString(maps* conf,const char* key){ 60 61 char* res=NULL; 61 char keywords[ 5][9]={62 char keywords[6][14]={ 62 63 "dbname", 63 64 "host", 64 65 "port", 65 66 "user", 66 "password" 67 "password", 68 "active_schema" 67 69 }; 68 70 int i=0; 69 maps* cconf=getMaps(conf,"database"); 71 maps* cconf=getMaps(conf,key); 72 if(cconf==NULL){ 73 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 74 return "-1"; 75 } 70 76 int len=0; 71 for(i=0;i< 5;i++){77 for(i=0;i<6;i++){ 72 78 map* tmp=getMap(cconf->content,keywords[i]); 73 79 if(tmp!=NULL){ … … 98 104 99 105 /** 100 * Connect to the db backend. 106 * Create a GDAL / OGR string for connecting to the db backend 107 * 108 * @param conf the maps containing the setting of the main.cfg file 109 * @return the OGR connection string 110 */ 111 char* createInitString(maps* conf){ 112 return _createInitString(conf,"database"); 113 } 114 115 /** 116 * Connect to a db backend. 101 117 * 102 118 * @param conf the maps containing the setting of the main.cfg file 103 119 * @see createInitString 104 120 */ 105 void init_sql(maps* conf){ 106 char* sqlInitString=createInitString(conf); 121 int _init_sql(maps* conf,const char* key){ 122 char* sqlInitString=_createInitString(conf,key); 123 #ifdef SQL_DEBUG 124 fprintf(stderr,"Try to connect to: %s %s !\n",key,sqlInitString); 125 fflush(stderr); 126 #endif 127 if(strncmp(sqlInitString,"-1",2)==0) 128 return -1; 107 129 OGRSFDriver *poDriver = NULL; 108 130 OGRRegisterAll(); 109 131 int zoo_ds_nb=0; 132 map* dsNb=getMapFromMaps(conf,"lenv","ds_nb"); 133 if(dsNb==NULL){ 134 setMapInMaps(conf,"lenv","ds_nb","1"); 135 }else{ 136 zoo_ds_nb=atoi(dsNb->value); 137 char* tmp=(char*)malloc(11*sizeof(char)); 138 sprintf(tmp,"%d",zoo_ds_nb+1); 139 setMapInMaps(conf,"lenv","ds_nb",(const char*)tmp); 140 free(tmp); 141 } 142 if(zoo_DS==NULL) 143 zoo_DS= 110 144 #if GDAL_VERSION_MAJOR >= 2 111 zoo_DS = (GDALDataset*) GDALOpenEx( sqlInitString, 145 (GDALDataset**) malloc(sizeof(GDALDataset*)) 146 #else 147 (OGRDataSource**) malloc(sizeof(OGRDataSource*)) 148 #endif 149 ; 150 else 151 zoo_DS= 152 #if GDAL_VERSION_MAJOR >= 2 153 (GDALDataset**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(GDALDataset*)) 154 #else 155 (OGRDataSource**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(OGRDataSource*)) 156 #endif 157 ; 158 159 #if GDAL_VERSION_MAJOR >= 2 160 zoo_DS[zoo_ds_nb] = (GDALDataset*) GDALOpenEx( sqlInitString, 112 161 GDAL_OF_UPDATE | GDAL_OF_VECTOR, 113 162 NULL, NULL, NULL ); 114 163 #else 115 zoo_DS = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver);116 #endif 117 if( zoo_DS == NULL ){118 #ifdef DEBUG164 zoo_DS[zoo_ds_nb] = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver); 165 #endif 166 if( zoo_DS[zoo_ds_nb] == NULL ){ 167 #ifdef SQL_DEBUG 119 168 fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString); 120 169 fflush(stderr); 121 170 #endif 122 171 free(sqlInitString); 123 setMapInMaps(conf,"lenv","message","Failed to connect to the database backend"); 124 return; 125 } 126 #ifdef DEBUG 172 setMapInMaps(conf,"lenv","dbIssue","1"); 173 setMapInMaps(conf,"lenv","message",_("Failed to connect to the database backend")); 174 return -2; 175 } 176 #ifdef SQL_DEBUG 127 177 fprintf(stderr,"sqlInitString: %s SUCEED !\n",sqlInitString); 128 178 fflush(stderr); 129 179 #endif 130 180 free(sqlInitString); 181 zoo_ds_nb++; 182 return zoo_ds_nb; 183 } 184 185 /** 186 * Connect to the db backend. 187 * 188 * @param conf the maps containing the setting of the main.cfg file 189 * @see createInitString 190 */ 191 int init_sql(maps* conf){ 192 return _init_sql(conf,"database"); 131 193 } 132 194 … … 136 198 * @param conf the maps containing the setting of the main.cfg file 137 199 */ 138 void close_sql(maps* conf){ 139 if( zoo_ResultSet != NULL ) 140 zoo_DS->ReleaseResultSet( zoo_ResultSet ); 141 if(zoo_DS!=NULL){ 200 void close_sql(maps* conf,int cid){ 201 if( zoo_ResultSet != NULL ){ 202 zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet ); 203 zoo_ResultSet=NULL; 204 } 205 if(zoo_DS!=NULL && zoo_DS[cid]!=NULL){ 142 206 #if GDAL_VERSION_MAJOR >= 2 143 GDALClose(zoo_DS );144 #else 145 OGRDataSource::DestroyDataSource( zoo_DS );146 #endif 147 zoo_DS =NULL;207 GDALClose(zoo_DS[cid]); 208 #else 209 OGRDataSource::DestroyDataSource( zoo_DS[cid] ); 210 #endif 211 zoo_DS[cid]=NULL; 148 212 } 149 213 } … … 158 222 159 223 /** 224 * Fetch a tuple set by executing a SQL query to the Database Backend. 225 * 226 * @param conf the maps containing the setting of the main.cfg file 227 * @param sqlQuery the SQL query to run 228 * @return NULL in case of failure or an OGRLayer pointer if the query succeed. 229 */ 230 OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){ 231 if(zoo_DS==NULL || zoo_DS[cid]==NULL) 232 return NULL; 233 OGRLayer *res=NULL; 234 #ifdef SQL_DEBUG 235 fprintf(stderr,"************************* %s %s %d\n\n",sqlQuery,__FILE__,__LINE__); 236 fflush(stderr); 237 #endif 238 res = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL); 239 return res; 240 } 241 242 void cleanFetchSql(maps* conf,int cid,OGRLayer *objects){ 243 if( objects != NULL ){ 244 zoo_DS[cid]->ReleaseResultSet( objects ); 245 objects=NULL; 246 } 247 } 248 249 /** 160 250 * Execute a SQL query to the SQL Database Backend. 161 251 * … … 164 254 * @return -1 in case of failure and 1 if the query succeed. 165 255 */ 166 int execSql(maps* conf,const char* sqlQuery){ 167 zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL); 256 int execSql(maps* conf,int cid,const char* sqlQuery){ 257 int res=-1; 258 if(zoo_DS == NULL || zoo_DS[cid]==NULL) 259 return -1; 260 zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL); 168 261 if( zoo_ResultSet != NULL ){ 169 re turn1;170 } 171 return -1;262 res=1; 263 } 264 return res; 172 265 } 173 266 … … 179 272 * @return -1 in case of failure and 1 if the query succeed. 180 273 */ 181 void cleanUpResultSet(const maps* conf ){274 void cleanUpResultSet(const maps* conf,int cid){ 182 275 if( zoo_ResultSet != NULL ){ 183 zoo_DS ->ReleaseResultSet( zoo_ResultSet );276 zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet ); 184 277 zoo_ResultSet=NULL; 185 278 } 279 } 280 281 #ifdef RELY_ON_DB 282 int getCurrentId(maps* conf){ 283 int res=0; 284 map* dsNb=getMapFromMaps(conf,"lenv","ds_nb"); 285 if(dsNb!=NULL) 286 res=atoi(dsNb->value); 287 return res; 186 288 } 187 289 … … 195 297 */ 196 298 void recordStoredFile(maps* conf,const char* filename,const char* type,const char* name){ 299 int zoo_ds_nb=getCurrentId(conf); 197 300 map *uusid=getMapFromMaps(conf,"lenv","usid"); 198 301 map *schema=getMapFromMaps(conf,"database","schema"); … … 202 305 else 203 306 sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type); 204 execSql(conf, sqlQuery);205 free(sqlQuery); 206 cleanUpResultSet(conf );307 execSql(conf,zoo_ds_nb-1,sqlQuery); 308 free(sqlQuery); 309 cleanUpResultSet(conf,zoo_ds_nb-1); 207 310 } 208 311 … … 213 316 */ 214 317 void recordServiceStatus(maps* conf){ 318 int zoo_ds_nb=getCurrentId(conf); 215 319 map *sid=getMapFromMaps(conf,"lenv","sid"); 216 320 map *osid=getMapFromMaps(conf,"lenv","osid"); … … 230 334 osid->value, 231 335 wpsStatus[2]); 232 execSql(conf, sqlQuery);233 free(sqlQuery); 234 cleanUpResultSet(conf );336 execSql(conf,zoo_ds_nb-1,sqlQuery); 337 free(sqlQuery); 338 cleanUpResultSet(conf,zoo_ds_nb-1); 235 339 } 236 340 … … 242 346 */ 243 347 void recordResponse(maps* conf,char* filename){ 348 int zoo_ds_nb=getCurrentId(conf); 244 349 FILE *file = fopen (filename, "rb"); 245 350 fseek (file, 0, SEEK_END); … … 254 359 char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+57+1)*sizeof(char)); 255 360 sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value); 256 execSql(conf, sqlQuery);361 execSql(conf,zoo_ds_nb-1,sqlQuery); 257 362 free(sqlQuery); 258 363 free(tmps); 259 cleanUpResultSet(conf );364 cleanUpResultSet(conf,zoo_ds_nb-1); 260 365 } 261 366 … … 267 372 */ 268 373 int _updateStatus(maps* conf){ 374 int zoo_ds_nb=getCurrentId(conf); 269 375 map *sid=getMapFromMaps(conf,"lenv","usid"); 270 376 map *p=getMapFromMaps(conf,"lenv","status"); … … 273 379 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char)); 274 380 sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value); 275 fflush(stderr); 276 if( zoo_DS == NULL ) 381 if( zoo_DS == NULL || zoo_DS[zoo_ds_nb-1]==NULL ){ 277 382 init_sql(conf); 278 execSql(conf,sqlQuery); 279 cleanUpResultSet(conf); 383 zoo_ds_nb++; 384 } 385 execSql(conf,zoo_ds_nb-1,sqlQuery); 386 cleanUpResultSet(conf,zoo_ds_nb-1); 280 387 free(sqlQuery); 281 388 return 0; … … 290 397 */ 291 398 char* _getStatus(maps* conf,char* pid){ 399 int zoo_ds_nb=getCurrentId(conf); 400 int created=-1; 292 401 map *schema=getMapFromMaps(conf,"database","schema"); 293 402 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 294 403 sprintf(sqlQuery,"select status||'|'||message from %s.services where uuid=$$%s$$;",schema->value,pid); 295 if( zoo_DS == NULL ) 404 if( zoo_ds_nb== 405 #ifdef META_DB 406 1 407 #else 408 0 409 #endif 410 ){ 296 411 init_sql(conf); 297 execSql(conf,sqlQuery); 412 zoo_ds_nb++; 413 created=1; 414 } 415 execSql(conf,zoo_ds_nb-1,sqlQuery); 298 416 OGRFeature *poFeature = NULL; 299 417 const char *tmp1; … … 301 419 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 302 420 if( poFeature->IsFieldSet( iField ) ){ 303 tmp1= strdup(poFeature->GetFieldAsString( iField ));421 tmp1=zStrdup(poFeature->GetFieldAsString( iField )); 304 422 } 305 423 else … … 308 426 OGRFeature::DestroyFeature( poFeature ); 309 427 } 310 cleanUpResultSet(conf );428 cleanUpResultSet(conf,zoo_ds_nb-1); 311 429 free(sqlQuery); 312 430 return (char*)tmp1; … … 321 439 */ 322 440 char* _getStatusFile(maps* conf,char* pid){ 323 map *schema=getMapFromMaps(conf,"database","schema"); 441 int zoo_ds_nb=getCurrentId(conf); 442 map *schema=getMapFromMaps(conf,"database","schema"); 443 OGRFeature *poFeature = NULL; 444 const char *tmp1=NULL; 445 int hasRes=-1; 324 446 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char)); 325 447 sprintf(sqlQuery, 326 448 "select content from %s.responses where uuid=$$%s$$" 327 449 " order by creation_time desc limit 1",schema->value,pid); 328 if( zoo_DS == NULL ) 450 if( zoo_ds_nb== 451 #ifdef META_DB 452 1 453 #else 454 0 455 #endif 456 ){ 329 457 init_sql(conf); 330 execSql(conf,sqlQuery); 331 OGRFeature *poFeature = NULL; 332 const char *tmp1; 333 int hasRes=-1; 334 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 335 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 336 if( poFeature->IsFieldSet( iField ) ){ 337 tmp1=strdup(poFeature->GetFieldAsString( iField )); 338 hasRes=1; 458 zoo_ds_nb++; 459 } 460 execSql(conf,zoo_ds_nb-1,sqlQuery); 461 if(zoo_ResultSet!=NULL){ 462 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 463 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 464 if( poFeature->IsFieldSet( iField ) ){ 465 tmp1=zStrdup(poFeature->GetFieldAsString( iField )); 466 hasRes=1; 467 } 468 else 469 tmp1=NULL; 470 } 471 OGRFeature::DestroyFeature( poFeature ); 339 472 } 340 else341 tmp1=NULL;342 }343 OGRFeature::DestroyFeature( poFeature );344 473 } 345 474 if(hasRes<0) 346 475 tmp1=NULL; 347 cleanUpResultSet(conf );476 cleanUpResultSet(conf,zoo_ds_nb-1); 348 477 free(sqlQuery); 349 478 return (char*)tmp1; … … 357 486 */ 358 487 void removeService(maps* conf,char* pid){ 488 int zoo_ds_nb=getCurrentId(conf); 359 489 map *schema=getMapFromMaps(conf,"database","schema"); 360 490 char *sqlQuery=(char*) 361 491 malloc((strlen(pid)+strlen(schema->value)+38+1) 362 492 *sizeof(char)); 363 if( zoo_DS == NULL ) 493 if( zoo_ds_nb== 494 #ifdef META_DB 495 1 496 #else 497 0 498 #endif 499 ){ 364 500 init_sql(conf); 501 zoo_ds_nb++; 502 } 365 503 sprintf(sqlQuery, 366 504 "DELETE FROM %s.services where uuid=$$%s$$;", 367 505 schema->value,pid); 368 execSql(conf, sqlQuery);369 cleanUpResultSet(conf );370 close_sql(conf );506 execSql(conf,zoo_ds_nb-1,sqlQuery); 507 cleanUpResultSet(conf,zoo_ds_nb-1); 508 close_sql(conf,zoo_ds_nb-1); 371 509 free(sqlQuery); 372 510 end_sql(); … … 379 517 */ 380 518 void unhandleStatus(maps* conf){ 519 int zoo_ds_nb=getCurrentId(conf); 381 520 map *schema=getMapFromMaps(conf,"database","schema"); 382 521 map *sid=getMapFromMaps(conf,"lenv","usid"); … … 392 531 " where uuid=$$%s$$;", 393 532 schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value); 394 execSql(conf, sqlQuery);395 cleanUpResultSet(conf );396 close_sql(conf);397 free(sqlQuery); 398 end_sql();533 execSql(conf,zoo_ds_nb-1,sqlQuery); 534 cleanUpResultSet(conf,zoo_ds_nb-1); 535 //close_sql(conf,zoo_ds_nb-1); 536 free(sqlQuery); 537 //end_sql(); 399 538 } 400 539 … … 407 546 */ 408 547 char* getStatusId(maps* conf,char* pid){ 548 int zoo_ds_nb=getCurrentId(conf); 409 549 map *schema=getMapFromMaps(conf,"database","schema"); 410 550 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); … … 412 552 "select osid from %s.services where uuid=$$%s$$", 413 553 schema->value,pid); 414 if( zoo_ DS == NULL )554 if( zoo_ds_nb==0 ){ 415 555 init_sql(conf); 416 execSql(conf,sqlQuery); 556 zoo_ds_nb++; 557 } 558 if(execSql(conf,zoo_ds_nb-1,sqlQuery)<0) 559 return NULL; 417 560 OGRFeature *poFeature = NULL; 418 561 const char *tmp1; … … 431 574 tmp1=NULL; 432 575 free(sqlQuery); 576 cleanUpResultSet(conf,zoo_ds_nb-1); 433 577 return (char*)tmp1; 434 578 } … … 441 585 */ 442 586 void readFinalRes(maps* conf,char* pid,map* statusInfo){ 587 int zoo_ds_nb=getCurrentId(conf); 443 588 map *schema=getMapFromMaps(conf,"database","schema"); 444 589 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); … … 448 593 if( zoo_DS == NULL ) 449 594 init_sql(conf); 450 execSql(conf, sqlQuery);595 execSql(conf,zoo_ds_nb-1,sqlQuery); 451 596 OGRFeature *poFeature = NULL; 452 597 int hasRes=-1; … … 461 606 OGRFeature::DestroyFeature( poFeature ); 462 607 } 608 cleanUpResultSet(conf,zoo_ds_nb-1); 463 609 if(hasRes<0) 464 610 addToMap(statusInfo,"Status","Failed"); … … 476 622 int isRunning(maps* conf,char* pid){ 477 623 int res=0; 624 int zoo_ds_nb=getCurrentId(conf); 478 625 map *schema=getMapFromMaps(conf,"database","schema"); 479 626 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char)); 480 627 sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid); 481 if( zoo_ DS == NULL )628 if( zoo_ds_nb == 0 ){ 482 629 init_sql(conf); 483 execSql(conf,sqlQuery); 630 zoo_ds_nb++; 631 } 632 execSql(conf,zoo_ds_nb-1,sqlQuery); 484 633 OGRFeature *poFeature = NULL; 485 634 const char *tmp1; … … 494 643 OGRFeature::DestroyFeature( poFeature ); 495 644 } 496 cleanUpResultSet(conf );645 cleanUpResultSet(conf,zoo_ds_nb-1); 497 646 free(sqlQuery); 498 647 return res; -
TabularUnified trunk/zoo-project/zoo-kernel/sqlapi.h ¶ ¶
r784 r917 25 25 #ifndef ZOO_SQLAPI_H 26 26 #define ZOO_SQLAPI_H 1 27 #ifdef RELY_ON_DB 27 28 #ifdef META_DB 29 #include "ogrsf_frmts.h" 30 #include "ogr_p.h" 31 #if GDAL_VERSION_MAJOR >= 2 32 #include <gdal_priv.h> 33 #endif 34 #endif 35 28 36 #include "service.h" 29 37 #include "service_internal.h" 38 39 #ifdef META_DB 40 extern "C" 41 #if GDAL_VERSION_MAJOR >=2 42 GDALDataset 43 #else 44 OGRDataSource 45 #endif 46 **zoo_DS; 47 #endif 30 48 31 49 #ifdef __cplusplus 32 50 extern "C" { 33 51 #endif 34 ZOO_DLL_EXPORT void init_sql(maps*); 35 ZOO_DLL_EXPORT void close_sql(maps*); 36 ZOO_DLL_EXPORT int execSql(maps*,const char*); 52 53 54 #ifdef META_DB 55 ZOO_DLL_EXPORT char* _createInitString(maps*,const char*); 56 ZOO_DLL_EXPORT int _init_sql(maps*,const char*); 57 ZOO_DLL_EXPORT OGRLayer *fetchSql(maps*,int,const char*); 58 ZOO_DLL_EXPORT void cleanFetchSql(maps*,int,OGRLayer*); 59 #endif 60 #ifdef RELY_ON_DB 61 ZOO_DLL_EXPORT int init_sql(maps*); 62 ZOO_DLL_EXPORT void close_sql(maps*,int); 63 ZOO_DLL_EXPORT int execSql(maps*,int,const char*); 37 64 ZOO_DLL_EXPORT void recordStoredFile(maps*,const char*,const char*,const char*); 38 65 ZOO_DLL_EXPORT void recordServiceStatus(maps*); … … 42 69 ZOO_DLL_EXPORT char* getStatusId(maps*,char*); 43 70 ZOO_DLL_EXPORT void removeService(maps*,char*); 71 ZOO_DLL_EXPORT void end_sql(); 72 #endif 44 73 45 74 #ifdef __cplusplus … … 48 77 49 78 #endif 50 #endif -
TabularUnified trunk/zoo-project/zoo-kernel/ulinet.c ¶ ¶
r889 r917 4 4 * Author : Gérald FENOY 5 5 * 6 * Copyright (c) 2008-201 5GeoLabs SARL6 * Copyright (c) 2008-2019 GeoLabs SARL 7 7 * 8 8 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 29 29 #define MAX_WAIT_MSECS 180*1000 /* Wait max. 180 seconds */ 30 30 #include "ulinet.h" 31 #include "server_internal.h" 31 32 #include <assert.h> 32 33 #include <ctype.h> 34 #include "fcgi_stdio.h" 33 35 34 36 /** … … 69 71 70 72 /** 73 * Write the downloaded content in the file pouted by the _HINTERNET structure 74 * 75 * @param buffer the buffer to read 76 * @param size size of each member 77 * @param nmemb number of element to read 78 * @param data the _HINTERNET structure to write in 79 * @return the size red, -1 if buffer is NULL 80 */ 81 size_t write_data_into_file(void *buffer, size_t size, size_t nmemb, void *data) 82 { 83 size_t realsize = size * nmemb; 84 int writen=0; 85 _HINTERNET *psInternet; 86 if(buffer==NULL){ 87 buffer=NULL; 88 return -1; 89 } 90 psInternet=(_HINTERNET *)data; 91 writen+=fwrite(buffer, size, nmemb, psInternet->file); 92 fflush(psInternet->file); 93 psInternet->nDataLen += realsize; 94 95 buffer=NULL; 96 return realsize; 97 } 98 99 100 /** 71 101 * In case of presence of "Set-Cookie" in the headers red, store the cookie 72 102 * identifier in cookie … … 83 113 int i; 84 114 char* tmp; 85 int cnt;86 _HINTERNET *psInternet;87 115 for(i=0;i<12;i++) 88 116 #ifndef WIN32 … … 92 120 #endif 93 121 tmp=strtok((char*) buffer,";"); // knut: added cast to char* 94 cnt=0;95 psInternet=(_HINTERNET *)data;122 int cnt=0; 123 _HINTERNET *psInternet=(_HINTERNET *)data; 96 124 if(tmp!=NULL && psInternet!=NULL){ 97 125 psInternet->cookie=(char*)malloc(sizeof(char)*(strlen(tmp)+1)); … … 211 239 HINTERNET ret; 212 240 ret.handle=curl_multi_init(); 213 ret.agent= strdup(lpszAgent);241 ret.agent=zStrdup(lpszAgent); 214 242 ret.nb=0; 243 ret.waitingRequests[ret.nb] = NULL; 215 244 ret.ihandle[ret.nb].header=NULL; 245 ret.ihandle[ret.nb].handle=NULL; 246 ret.ihandle[ret.nb].hasCacheFile=0; 247 ret.ihandle[ret.nb].nDataAlloc = 0; 248 ret.ihandle[ret.nb].url = NULL; 249 ret.ihandle[ret.nb].mimeType = NULL; 250 ret.ihandle[ret.nb].cookie = NULL; 251 ret.ihandle[ret.nb].nDataLen = 0; 252 ret.ihandle[ret.nb].nDataAlloc = 0; 253 ret.ihandle[ret.nb].pabyData = NULL; 254 ret.ihandle[ret.nb].post = NULL; 216 255 return ret; 256 } 257 258 /** 259 * Verify if the URL should use a shared cache or not. 260 * 261 * In case the security section contains a key named "shared", then if the 262 * domain listed in the shared key are contained in the url given as parameter 263 * then it return "SHARED" in other cases, it returns "OTHER". 264 * 265 * @param conf the main configuration file maps 266 * @param url the URL to evaluate 267 * @return a string "SHARED" in case the host is in a domain listed in the 268 * shared key, "OTHER" in other cases. 269 */ 270 char* getProvenance(maps* conf,const char* url){ 271 map* sharedCache=getMapFromMaps(conf,"security","shared"); 272 char *res="OTHER"; 273 char *paths[2]={ 274 "mapserverAddress", 275 "tmpUrl" 276 }; 277 if(sharedCache!=NULL){ 278 char *hosts=sharedCache->value; 279 char *curs=strtok(hosts,","); 280 while(curs!=NULL){ 281 if(strstr(url,curs)==NULL){ 282 return "SHARED"; 283 } 284 curs=strtok(NULL,","); 285 } 286 } 287 for(int i=0;i<2;i++){ 288 sharedCache=getMapFromMaps(conf,"main",paths[i]); 289 if(sharedCache!=NULL){ 290 if(strstr(url,sharedCache->value)!=NULL){ 291 return "LOCAL"; 292 } 293 } 294 } 295 return res; 217 296 } 218 297 … … 244 323 * @return 1 if the host is listed as protected, 0 in other case 245 324 */ 246 int isProtectedHost(const char* protectedHosts, const char* url){247 248 249 char* host; 250 251 252 char* urlcpy = (char*) malloc(sizeof(char)*(strlen(url)+1)); 253 urlcpy = strncpy(urlcpy, url, strlen(url)+1); // since count > strlen(url), a null character is properly appended254 255 256 token = strtok_r(urlcpy, "//", &saveptr); // knut257 cnt=0;258 while(token!=NULL && cnt<=1){259 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,token);260 if(cnt==1)261 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token));262 263 if(cnt==1 && strstr(protectedHosts,token)!=NULL){264 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token));265 free(urlcpy); 266 267 268 token = strtok_r(NULL, "/", &saveptr);269 cnt+=1;270 271 272 325 int isProtectedHost(const char* protectedHosts, const char* url) { 326 char *token, *saveptr; 327 int cnt; 328 char* host; 329 330 // knut: make a copy of url since strtok family modifies first argument and cannot be used on constant strings 331 char* urlcpy = (char*)malloc(sizeof(char)*(strlen(url) + 1)); 332 urlcpy = strncpy(urlcpy, url, strlen(url) + 1); // since count > strlen(url), a null character is properly appended 333 334 //token = strtok_r (url, "//", &saveptr); 335 token = strtok_r(urlcpy, "//", &saveptr); // knut 336 cnt = 0; 337 while (token != NULL && cnt <= 1) { 338 fprintf(stderr, "%s %d %s \n", __FILE__, __LINE__, token); 339 if (cnt == 1) 340 fprintf(stderr, "%s %d %s \n", __FILE__, __LINE__, strstr(protectedHosts, token)); 341 fflush(stderr); 342 if (cnt == 1 && strstr(protectedHosts, token) != NULL) { 343 fprintf(stderr, "%s %d %s \n", __FILE__, __LINE__, strstr(protectedHosts, token)); 344 free(urlcpy); 345 return 1; 346 } 347 token = strtok_r(NULL, "/", &saveptr); 348 cnt += 1; 349 } 350 free(urlcpy); 351 return 0; 273 352 } 274 353 … … 289 368 if(passThrough!=NULL && targetHosts!=NULL){ 290 369 char *tmp=zStrdup(passThrough->value); 291 char *token, *saveptr; 292 int i; 293 token = strtok_r (tmp, ",", &saveptr); 370 int i; 294 371 for(i=0;i<handle->nb;i++){ 295 if(targetHosts->value[0]=='*' || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){ 372 if(strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){ 373 char *token, *saveptr; 374 token = strtok_r (tmp, ",", &saveptr); 296 375 while (token != NULL){ 297 int j;298 map* tmpMap;299 376 int length=strlen(token)+6; 300 377 char* tmp1=(char*)malloc(length*sizeof(char)); 378 map* tmpMap; 301 379 snprintf(tmp1,6,"HTTP_"); 380 int j; 302 381 for(j=0;token[j]!='\0';j++){ 303 382 if(token[j]!='-') 304 tmp1[5+j]=toupper(token[ i]);383 tmp1[5+j]=toupper(token[j]); 305 384 else 306 385 tmp1[5+j]='_'; 307 386 tmp1[5+j+1]='\0'; 308 387 } 309 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmp1);310 388 tmpMap = getMapFromMaps(conf,"renv",tmp1); 311 if(tmpMap!=NULL) 389 if(tmpMap!=NULL){ 312 390 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 313 free(tmp1);391 } 314 392 if(handle->ihandle[i].header!=NULL) 315 393 curl_easy_setopt(handle->ihandle[i].handle,CURLOPT_HTTPHEADER,handle->ihandle[i].header); 394 free(tmp1); 316 395 cnt+=1; 317 396 token = strtok_r (NULL, ",", &saveptr); … … 330 409 void InternetCloseHandle(HINTERNET* handle0){ 331 410 int i=0; 332 for(i=0;i<handle0->nb;i++){ 333 _HINTERNET handle=handle0->ihandle[i]; 334 if(handle.hasCacheFile>0){ 335 fclose(handle.file); 336 unlink(handle.filename); 337 } 338 else{ 339 handle.pabyData = NULL; 340 handle.nDataAlloc = handle.nDataLen = 0; 341 } 342 if(handle0->ihandle[i].header!=NULL){ 343 curl_slist_free_all(handle0->ihandle[i].header); 344 handle0->ihandle[i].header=NULL; 345 } 346 if(handle.post!=NULL) 347 free(handle.post); 348 if(handle.url!=NULL) 349 free(handle.url); 350 if(handle.mimeType!=NULL) 351 free(handle.mimeType); 352 if(handle.cookie!=NULL) 353 free(handle.cookie); 354 } 355 if(handle0->handle) 356 curl_multi_cleanup(handle0->handle); 357 free(handle0->agent); 358 for(i=handle0->nb-1;i>=0;i--){ 359 free(handle0->waitingRequests[i]); 411 if(handle0!=NULL){ 412 for(i=0;i<handle0->nb;i++){ 413 _HINTERNET handle=handle0->ihandle[i]; 414 if(handle.hasCacheFile>0){ 415 fclose(handle.file); 416 unlink(handle.filename); 417 free(handle.filename); 418 } 419 else{ 420 handle.pabyData = NULL; 421 handle.nDataAlloc = handle.nDataLen = 0; 422 } 423 if(handle.header!=NULL){ 424 curl_slist_free_all(handle.header); 425 handle.header=NULL; 426 } 427 if(handle.post!=NULL){ 428 free(handle.post); 429 handle.post=NULL; 430 } 431 if(handle.url!=NULL){ 432 free(handle.url); 433 handle.url=NULL; 434 } 435 if(handle.mimeType!=NULL){ 436 free(handle.mimeType); 437 handle.mimeType=NULL; 438 } 439 if(handle.cookie!=NULL){ 440 free(handle.cookie); 441 handle.cookie=NULL; 442 } 443 if(handle0->waitingRequests[i]!=NULL){ 444 free(handle0->waitingRequests[i]); 445 handle0->waitingRequests[i]=NULL; 446 } 447 } 448 if(handle0->handle) 449 curl_multi_cleanup(handle0->handle); 450 if(handle0->agent!=NULL){ 451 free(handle0->agent); 452 handle0->agent=NULL; 453 } 360 454 } 361 455 } … … 370 464 * @param dwFlags desired download mode (INTERNET_FLAG_NO_CACHE_WRITE for not using cache file) 371 465 * @param dwContext not used 372 */ 373 HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){ 466 * @param conf the main configuration file maps pointer 467 * @return the updated HINTERNET 468 */ 469 HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext,const maps* conf){ 374 470 375 471 char filename[255]; 472 int ldwFlags=INTERNET_FLAG_NEED_FILE; 376 473 struct MemoryStruct header; 474 map* memUse=getMapFromMaps((maps*) conf,"main","memory"); // knut: addad cast to maps* 377 475 378 476 hInternet->ihandle[hInternet->nb].handle=curl_easy_init( ); … … 407 505 #endif 408 506 409 410 switch(dwFlags) 507 if(memUse!=NULL && strcasecmp(memUse->value,"load")==0) 508 ldwFlags=INTERNET_FLAG_NO_CACHE_WRITE; 509 510 switch(ldwFlags) 411 511 { 412 512 case INTERNET_FLAG_NO_CACHE_WRITE: 413 hInternet->ihandle[hInternet->nb].hasCacheFile=-1;414 513 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, write_data_into); 415 514 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, (void*)&hInternet->ihandle[hInternet->nb]); 515 hInternet->ihandle[hInternet->nb].hasCacheFile=-1; 416 516 break; 417 517 default: 418 sprintf(hInternet->ihandle[hInternet->nb].filename,"/tmp/ZOO_Cache%d",(int)time(NULL)); 419 hInternet->ihandle[hInternet->nb].filename[24]=0; 420 #ifdef MSG_LAF_VERBOSE 421 fprintf(stderr,"file=%s",hInternet->ihandle[hInternet->nb].filename); 422 #endif 423 hInternet->ihandle[hInternet->nb].filename=filename; 518 memset(filename,0,255); 519 char* tmpUuid=get_uuid(); 520 map* tmpPath=NULL; 521 if(conf!=NULL){ 522 tmpPath=getMapFromMaps((maps*) conf,"main","tmpPath"); // knut added cast to maps* 523 } 524 if(tmpPath==NULL) 525 sprintf(filename,"/tmp/ZOO_Cache%s", tmpUuid); 526 else 527 sprintf(filename,"%s/ZOO_Cache%s", tmpPath->value,tmpUuid); 528 free(tmpUuid); 529 hInternet->ihandle[hInternet->nb].filename=zStrdup(filename); 424 530 hInternet->ihandle[hInternet->nb].file=fopen(hInternet->ihandle[hInternet->nb].filename,"w+"); 425 426 531 hInternet->ihandle[hInternet->nb].hasCacheFile=1; 427 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, NULL); 428 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, hInternet->ihandle[hInternet->nb].file); 429 hInternet->ihandle[hInternet->nb].nDataLen=0; 532 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, write_data_into_file); 533 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, (void*)&hInternet->ihandle[hInternet->nb]); 430 534 break; 431 535 } … … 443 547 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_VERBOSE,1); 444 548 #endif 445 hInternet->ihandle[hInternet->nb].post= strdup(lpszHeaders);549 hInternet->ihandle[hInternet->nb].post=zStrdup(lpszHeaders); 446 550 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,hInternet->ihandle[hInternet->nb].post); 447 551 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength); … … 457 561 hInternet->ihandle[hInternet->nb].header=NULL; 458 562 ++hInternet->nb; 563 hInternet->ihandle[hInternet->nb].header=NULL; 459 564 460 565 #ifdef ULINET_DEBUG … … 472 577 */ 473 578 int processDownloads(HINTERNET* hInternet){ 474 int still_running=0 ;579 int still_running=0,numfds; 475 580 int msgs_left=0; 476 581 int i=0; 477 582 do{ 478 curl_multi_perform(hInternet->handle, &still_running); 583 CURLMcode mc; 584 mc = curl_multi_perform(hInternet->handle, &still_running); 585 if(mc==CURLM_OK){ 586 #if LIBCURL_VERSION_MINOR >= 28 587 mc = curl_multi_wait(hInternet->handle, NULL, 0, 1000, &numfds); 588 #else 589 struct timeval timeout; 590 fd_set fdread; 591 fd_set fdwrite; 592 fd_set fdexcep; 593 int maxfd = -1; 594 595 long curl_timeo = -1; 596 597 FD_ZERO(&fdread); 598 FD_ZERO(&fdwrite); 599 FD_ZERO(&fdexcep); 600 601 /* set a suitable timeout to play around with */ 602 timeout.tv_sec = 1; 603 timeout.tv_usec = 0; 604 605 curl_multi_timeout(hInternet->handle, &curl_timeo); 606 if(curl_timeo >= 0) { 607 timeout.tv_sec = curl_timeo / 1000; 608 if(timeout.tv_sec > 1) 609 timeout.tv_sec = 1; 610 else 611 timeout.tv_usec = (curl_timeo % 1000) * 1000; 612 } 613 614 /* get file descriptors from the transfers */ 615 mc = curl_multi_fdset(hInternet->handle, &fdread, &fdwrite, &fdexcep, &maxfd); 616 #endif 617 } 618 if(mc != CURLM_OK) { 619 fprintf(stderr, "curl_multi failed, code %d.n", mc); 620 break; 621 } 479 622 }while(still_running); 480 623 for(i=0;i<hInternet->nb;i++){ … … 482 625 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp); 483 626 if(tmp!=NULL) 484 hInternet->ihandle[i].mimeType= strdup(tmp);627 hInternet->ihandle[i].mimeType=zStrdup(tmp); 485 628 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code); 486 629 curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle); … … 498 641 */ 499 642 int freeCookieList(HINTERNET hInternet){ 500 if(hInternet.ihandle[hInternet.nb].cookie) 501 free(hInternet.ihandle[hInternet.nb].cookie); 502 hInternet.ihandle[hInternet.nb].cookie=NULL; 643 hInternet.ihandle[hInternet.nb].cookie=zStrdup(""); 503 644 #ifndef TIGER 504 645 curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL"); … … 522 663 fseek (hInternet.file , 0 , SEEK_END); 523 664 dwDataSize=ftell(hInternet.file); //taille du ficher 524 rewind (hInternet.file); 665 //dwDataSize=hInternet.nDataLen; 666 //rewind (hInternet.file); 667 fseek(hInternet.file, 0, SEEK_SET); 525 668 } 526 669 else{ … … 532 675 } 533 676 534 if( dwNumberOfBytesToRead /* buffer size */ < dwDataSize ) 677 if( dwNumberOfBytesToRead /* buffer size */ < dwDataSize ){ 535 678 return 0; 679 } 536 680 537 681 #ifdef MSG_LAF_VERBOSE 538 printf("\nfile size : %dko\n",dwDataSize/1024);682 fprintf(stderr,"\nfile size : %dko\n",dwDataSize/1024); 539 683 #endif 540 684 541 685 if(hInternet.hasCacheFile>0){ 542 *lpdwNumberOfBytesRead = fread(lpBuffer,1,dwDataSize,hInternet.file); 686 int freadRes = fread(lpBuffer,dwDataSize+1,1,hInternet.file); 687 *lpdwNumberOfBytesRead = hInternet.nDataLen; 543 688 } 544 689 else{ -
TabularUnified trunk/zoo-project/zoo-kernel/ulinet.h ¶ ¶
r889 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright 2008-20 09 GeoLabs SARL. All rights reserved.4 * Copyright 2008-2019 GeoLabs SARL. All rights reserved. 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 26 26 #define _ULINET_H 27 27 28 #include "fcgi_stdio.h"29 28 #include <stdlib.h> 30 29 #include <fcntl.h> 31 30 #include <curl/curl.h> 31 #include <curl/curlver.h> 32 32 #include "service.h" 33 33 #ifndef WIN32 … … 44 44 #include "jsapi.h" 45 45 #endif 46 /* knut: see new definition of bool in service.h 47 #ifndef bool 48 #define bool int 46 #ifndef __cplusplus 47 // knut: see new def of bool in service.h 48 //#ifndef bool 49 //#define bool int 50 //#endif 51 //#ifndef true 52 //#define true 1 53 //#define false 0 54 //#endif 49 55 #endif 50 #ifndef true51 #define true 152 #define false 053 #endif54 */55 56 56 57 #define MAX_REQ 50 … … 102 103 size_t write_data_into(void*,size_t,size_t,void*); 103 104 105 size_t write_data_into_file(void*,size_t,size_t,void*); 106 104 107 size_t header_write_data(void*,size_t,size_t,void*); 105 108 … … 130 133 HINTERNET InternetOpen(char*,int,char*,char*,int); 131 134 135 char* getProvenance(maps*,const char*); 132 136 int isProtectedHost(const char*,const char*); 133 137 int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*); … … 153 157 typedef size_t* LPDWORD; 154 158 #endif 155 /* knut: see new definition of bool in service.h 156 #ifndef bool 157 #define bool int 158 #endif 159 */ 159 // knut: see new definition of bool in service.h 160 //#ifndef bool 161 //#define bool int 162 //#endif 160 163 161 164 # define CHECK_INET_HANDLE(h) (h.handle != 0) 162 165 163 HINTERNET InternetOpenUrl(HINTERNET*,LPCTSTR,LPCTSTR,size_t,size_t,size_t );166 HINTERNET InternetOpenUrl(HINTERNET*,LPCTSTR,LPCTSTR,size_t,size_t,size_t,const maps*); 164 167 165 168 int processDownloads(HINTERNET*); -
TabularUnified trunk/zoo-project/zoo-kernel/zoo_loader.c ¶ ¶
r843 r917 65 65 #endif 66 66 67 int cgiInit(){ 68 fprintf(FCGI_stderr,"ZOO-Kernel initialization %s %d ... \n",__FILE__,__LINE__); 69 fflush(FCGI_stderr); 70 return 0; 71 } 72 67 73 /** 68 74 * Main entry point for cgic. … … 117 123 if(res!=NULL) 118 124 free(res); 119 }else{ 125 }else{ 120 126 char *buffer=new char[cgiContentLength+1]; 121 127 if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){ … … 157 163 } 158 164 } 159 else{ 165 else{ 160 166 #ifdef DEBUG 161 167 dumpMap(tmpMap); … … 181 187 cgiStringArrayFree(array); 182 188 } 183 189 184 190 #ifdef WIN32 185 map *tmpReq=getMap(tmpMap,"rfile"); 186 if(tmpReq!=NULL){ 187 FILE *lf=fopen(tmpReq->value,"r"); 191 map *tmpReq=getMap(tmpMap,"rfile"); 192 if(tmpReq!=NULL){ 193 FILE *lf=fopen(tmpReq->value,"r"); 188 194 fseek(lf,0,SEEK_END); 189 195 long flen=ftell(lf); … … 389 395 } 390 396 } 391 397 392 398 if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){ 393 399 map* tmp=getMap(tmpMap,"dataInputs"); … … 402 408 if(strQuery!=NULL) 403 409 free(strQuery); 404 410 405 411 runRequest(&tmpMap); 406 412 -
TabularUnified trunk/zoo-project/zoo-kernel/zoo_service_loader.c ¶ ¶
r889 r917 26 26 extern "C" int crlex (); 27 27 28 #ifdef META_DB 29 #include "ogrsf_frmts.h" 30 #if GDAL_VERSION_MAJOR >= 2 31 #include <gdal_priv.h> 32 #endif 33 #endif 34 28 35 #ifdef USE_OTB 29 36 #include "service_internal_otb.h" 37 #endif 38 39 #ifdef USE_R 40 #include "service_internal_r.h" 41 #endif 42 43 #ifdef USE_HPC 44 #include "service_internal_hpc.h" 30 45 #endif 31 46 … … 55 70 #endif 56 71 72 #ifdef META_DB 73 #include "meta_sql.h" 74 #endif 75 57 76 #ifdef USE_PYTHON 58 77 #include "service_internal_python.h" … … 87 106 #endif 88 107 108 #ifdef USE_CALLBACK 109 #include "service_json.h" 110 #include "service_callback.h" 111 #endif 112 89 113 #include <dirent.h> 90 114 #include <signal.h> 115 #ifndef WIN32 116 #include <execinfo.h> 117 #endif 91 118 #include <unistd.h> 92 119 #ifndef WIN32 … … 105 132 #include <stdarg.h> 106 133 134 #include <libxml/tree.h> 135 #include <libxml/parser.h> 136 #include <libxml/xpath.h> 137 #include <libxml/xpathInternals.h> 138 139 #include <libxslt/xslt.h> 140 #include <libxslt/xsltInternals.h> 141 #include <libxslt/transform.h> 142 #include <libxslt/xsltutils.h> 143 107 144 #ifndef WIN32 108 145 extern char **environ; 146 #endif 147 148 149 #ifdef WIN32 150 extern "C" 151 { 152 __declspec (dllexport) char *strcasestr (char const *a, char const *b) 153 #ifndef USE_MS 154 { 155 char *x = zStrdup (a); 156 char *y = zStrdup (b); 157 158 x = _strlwr (x); 159 y = _strlwr (y); 160 char *pos = strstr (x, y); 161 char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); 162 free (x); 163 free (y); 164 return ret; 165 }; 166 #else 167 ; 168 #endif 169 } 109 170 #endif 110 171 … … 119 180 120 181 #ifdef WIN32 121 122 123 182 #ifndef PROGRAMNAME 183 #define PROGRAMNAME "zoo_loader.cgi" 184 #endif 124 185 #endif 125 186 … … 159 220 lockShm (lid); 160 221 #endif 161 FILE *f3 = fopen (fbkp, "wb+"); 162 free (fbkp); 222 FILE *f3 = fopen (fbkp, "wb+"); 223 free (fbkp); 163 224 fseek (f2, 0, SEEK_END); 164 225 long flen = ftell (f2); 165 226 fseek (f2, 0, SEEK_SET); 166 227 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 167 fread (tmps1, flen, 1, f2); 228 fread (tmps1, flen, 1, f2); 168 229 #ifdef WIN32 169 230 /* knut: I think this block can be dropped; pchr may be NULL if result is not in XML format 170 char *pchr=strrchr(tmps1,'>'); 171 flen=strlen(tmps1)-strlen(pchr)+1; 172 tmps1[flen]=0; 231 char *pchr=strrchr(tmps1,'>'); 232 flen=strlen(tmps1)-strlen(pchr)+1; 233 tmps1[flen]=0; 173 234 */ 174 #endif 235 #endif 175 236 fwrite (tmps1, 1, flen, f3); 237 fclose (f2); 238 fclose (f3); 176 239 free(tmps1); 177 fclose (f2);178 fclose (f3);179 240 return 1; 180 241 } … … 197 258 */ 198 259 int 199 recursReaddirF ( maps * m, registry *r, xml NodePtr n, char *conf_dir,260 recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir, 200 261 char *prefix, int saved_stdout, int level, 201 void (func) (registry *, maps *, xml NodePtr, service *) )262 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) ) 202 263 { 203 264 struct dirent *dp; … … 246 307 setMapInMaps (m, "lenv", "level", levels1); 247 308 res = 248 recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,309 recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1, 249 310 func); 250 311 sprintf (levels1, "%d", level); … … 264 325 { 265 326 char* extn = strstr(dp->d_name, ".zcfg"); 266 if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 )327 if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6) 267 328 { 268 329 int t; … … 271 332 snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name); 272 333 273 char *tmpsn = zStrdup (dp->d_name); 274 tmpsn[strlen (tmpsn) - 5] = 0; 334 char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name); 335 memset (tmpsn, 0, strlen(dp->d_name)-4); 336 snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name); 275 337 276 338 map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn); 277 339 if (import == NULL || import->value == NULL || zoo_path_compare(tmps1, import->value) != 0 ) { // service is not in [include] block 278 service *s1 = (service *) malloc (SERVICE_SIZE);340 service *s1 = createService(); 279 341 if (s1 == NULL) 280 342 { 281 dup2 (saved_stdout, fileno (stdout));343 zDup2 (saved_stdout, fileno (stdout)); 282 344 errorException (m, _("Unable to allocate memory"), 283 345 "InternalError", NULL); … … 300 362 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 301 363 dp->d_name); 302 dup2 (saved_stdout, fileno (stdout));364 zDup2 (saved_stdout, fileno (stdout)); 303 365 errorException (m, tmp01, "InternalError", NULL); 304 366 return -1; … … 309 371 fflush (stderr); 310 372 #endif 311 inheritance(r,&s1); 312 func (r, m, n, s1); 373 if(s1!=NULL) 374 inheritance(r,&s1); 375 func (r, m, doc, n, s1); 313 376 freeService (&s1); 314 377 free (s1); … … 344 407 sig_handler (int sig) 345 408 { 409 346 410 char tmp[100]; 347 411 const char *ssig; … … 372 436 sprintf (tmp, 373 437 _ 374 ("ZOO Kernel failed to process your request, receiving signal %d = %s "),438 ("ZOO Kernel failed to process your request, receiving signal %d = %s "), 375 439 sig, ssig); 376 440 errorException (NULL, tmp, "InternalError", NULL); … … 420 484 #endif 421 485 422 map* libp = getMapFromMaps(m, "main", "libPath"); 423 486 map* libp = getMapFromMaps(m, "main", "libPath"); 424 487 if (strlen (r_inputs->value) == 1 425 488 && strncasecmp (r_inputs->value, "C", 1) == 0) … … 610 673 else 611 674 675 #ifdef USE_HPC 676 if (strncasecmp (r_inputs->value, "HPC", 3) == 0) 677 { 678 *eres = 679 zoo_hpc_support (&m, request_inputs, s1, 680 &request_input_real_format, 681 &request_output_real_format); 682 } 683 else 684 #endif 685 612 686 #ifdef USE_SAGA 613 if (strncasecmp (r_inputs->value, "SAGA", 6) == 0)687 if (strncasecmp (r_inputs->value, "SAGA", 4) == 0) 614 688 { 615 689 *eres = … … 622 696 623 697 #ifdef USE_OTB 624 if (strncasecmp (r_inputs->value, "OTB", 6) == 0)698 if (strncasecmp (r_inputs->value, "OTB", 3) == 0) 625 699 { 626 700 *eres = … … 633 707 #ifdef USE_PYTHON 634 708 if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0) 709 { 710 *eres = 711 zoo_python_support (&m, request_inputs, s1, 712 &request_input_real_format, 713 &request_output_real_format); 714 } 715 else 716 #endif 717 718 #ifdef USE_R 719 if (strncasecmp (r_inputs->value, "R", 6) == 0) 635 720 { 636 721 *eres = 637 zoo_ python_support (&m, request_inputs, s1,722 zoo_r_support (&m, request_inputs, s1, 638 723 &request_input_real_format, 639 724 &request_output_real_format); … … 713 798 } 714 799 *myMap = m; 715 *ioutputs = request_output_real_format; 800 *ioutputs = request_output_real_format; 716 801 } 717 802 … … 902 987 #endif 903 988 989 904 990 map *r_inputs = NULL; 905 991 map *request_inputs = *inputs; 992 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN)); 993 906 994 #ifdef IGNORE_METAPATH 907 995 addToMap(request_inputs, "metapath", ""); … … 935 1023 #ifdef ETC_DIR 936 1024 #ifndef WIN32 937 1025 getcwd (ntmp, 1024); 938 1026 #else 939 1027 _getcwd (ntmp, 1024); 940 1028 #endif 941 1029 #endif … … 1013 1101 char tmp1[13]; 1014 1102 sprintf (tmp1, "LC_ALL=%s", tmp); 1015 putenv (tmp1);1103 _putenv (tmp1); 1016 1104 #endif 1017 1105 free (tmp); … … 1025 1113 char tmp1[13]; 1026 1114 sprintf (tmp1, "LC_ALL=en_US"); 1027 putenv (tmp1);1115 _putenv (tmp1); 1028 1116 #endif 1029 1117 setMapInMaps (m, "main", "language", "en-US"); … … 1035 1123 char tmp1[17]; 1036 1124 sprintf (tmp1, "LC_NUMERIC=C"); 1037 putenv (tmp1);1125 _putenv (tmp1); 1038 1126 #endif 1039 1127 bind_textdomain_codeset ("zoo-kernel", "UTF-8"); … … 1127 1215 }; 1128 1216 r_inputs = getMap (request_inputs, "Request"); 1129 REQUEST = zStrdup (r_inputs->value); 1217 if(r_inputs!=NULL) 1218 REQUEST = zStrdup (r_inputs->value); 1130 1219 int reqId=-1; 1131 1220 if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){ … … 1134 1223 for(j=0;j<nbSupportedRequests;j++){ 1135 1224 if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){ 1136 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen( REQUEST))==0){1225 if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 1137 1226 checkValidValue(request_inputs,&err,"identifier",NULL,1); 1138 1227 reqId=j+1; … … 1141 1230 else 1142 1231 if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 1143 strncasecmp(REQUEST,requests[vid][j+1],strlen( REQUEST))==0){1232 strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){ 1144 1233 checkValidValue(request_inputs,&err,"jobid",NULL,1); 1145 1234 reqId=j+1; … … 1217 1306 registry* zooRegistry=NULL; 1218 1307 if(reg!=NULL){ 1219 int saved_stdout = dup (fileno (stdout)); 1220 dup2 (fileno (stderr), fileno (stdout)); 1308 #ifndef WIN32 1309 int saved_stdout = zDup (fileno (stdout)); 1310 zDup2 (fileno (stderr), fileno (stdout)); 1311 #endif 1221 1312 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1222 1313 map *message=getMapFromMaps(m,"lenv","message"); 1223 1314 map *type=getMapFromMaps(m,"lenv","type"); 1224 dup2 (saved_stdout, fileno (stdout)); 1315 #ifndef WIN32 1316 zDup2 (saved_stdout, fileno (stdout)); 1317 #endif 1225 1318 errorException (m, message->value, 1226 1319 type->value, NULL); 1227 1320 return 0; 1228 1321 } 1229 dup2 (saved_stdout, fileno (stdout)); 1230 close(saved_stdout); 1322 #ifndef WIN32 1323 zDup2 (saved_stdout, fileno (stdout)); 1324 zClose(saved_stdout); 1325 #endif 1231 1326 } 1232 1327 … … 1242 1337 * has been found in the zcfg and then printed on stdout 1243 1338 */ 1244 int saved_stdout = dup (fileno (stdout));1245 dup2 (fileno (stderr), fileno (stdout));1339 int saved_stdout = zDup (fileno (stdout)); 1340 zDup2 (fileno (stderr), fileno (stdout)); 1246 1341 1247 1342 maps* imports = getMaps(m, IMPORTSERVICE); … … 1258 1353 } 1259 1354 inheritance(zooRegistry, &svc); 1260 printGetCapabilitiesForProcess(zooRegistry, m, n, svc);1355 printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc); 1261 1356 freeService(&svc); 1262 1357 free(svc); … … 1267 1362 1268 1363 if (int res = 1269 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1364 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1270 1365 printGetCapabilitiesForProcess) < 0) 1271 1366 { … … 1282 1377 } 1283 1378 fflush (stdout); 1284 dup2 (saved_stdout, fileno (stdout)); 1285 printDocument (m, doc, getpid ()); 1379 zDup2 (saved_stdout, fileno (stdout)); 1380 #ifdef META_DB 1381 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1382 close_sql(m,0); 1383 #endif 1384 printDocument (m, doc, zGetpid ()); 1286 1385 freeMaps (&m); 1287 1386 free (m); … … 1299 1398 r_inputs = getMap (request_inputs, "JobId"); 1300 1399 if(reqId>nbReqIdentifier){ 1301 if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||1302 strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){1400 if (strncasecmp (REQUEST, "GetStatus", 9) == 0 || 1401 strncasecmp (REQUEST, "GetResult", 9) == 0){ 1303 1402 runGetStatus(m,r_inputs->value,REQUEST); 1403 #ifdef RELY_ON_DB 1404 map* dsNb=getMapFromMaps(m,"lenv","ds_nb"); 1405 if(dsNb!=NULL && atoi(dsNb->value)>1) 1406 close_sql(m,1); 1407 close_sql(m,0); 1408 #endif 1409 1304 1410 freeMaps (&m); 1305 free 1411 free(m); 1306 1412 if(zooRegistry!=NULL){ 1307 1413 freeRegistry(&zooRegistry); … … 1355 1461 r_inputs = NULL; 1356 1462 r_inputs = getMap (request_inputs, "version"); 1463 #ifdef DEBUG 1464 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1465 fflush(stderr); 1466 #endif 1357 1467 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 1358 1468 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); … … 1362 1472 char *orig = zStrdup (r_inputs->value); 1363 1473 1364 int saved_stdout = dup (fileno (stdout));1365 dup2 (fileno (stderr), fileno (stdout));1474 int saved_stdout = zDup (fileno (stdout)); 1475 zDup2 (fileno (stderr), fileno (stdout)); 1366 1476 if (strcasecmp ("all", orig) == 0) 1367 1477 { … … 1379 1489 } 1380 1490 inheritance(zooRegistry, &svc); 1381 printDescribeProcessForProcess(zooRegistry, m, n, svc); 1491 #ifdef USE_HPC 1492 addNestedOutputs(&svc); 1493 #endif 1494 1495 printDescribeProcessForProcess(zooRegistry, m, doc, n, svc); 1382 1496 freeService(&svc); 1383 1497 free(svc); … … 1388 1502 1389 1503 if (int res = 1390 recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,1504 recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0, 1391 1505 printDescribeProcessForProcess) < 0) 1392 1506 return res; 1507 #ifdef META_DB 1508 fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0); 1509 close_sql(m,0); 1510 #endif 1511 1393 1512 } 1394 1513 else … … 1406 1525 if (import != NULL && import->value != NULL) 1407 1526 { 1408 s1 = (service *) malloc (SERVICE_SIZE); 1409 t = readServiceFile (m, import->value, &s1, import->name); 1527 #ifdef META_DB 1528 service* s2=extractServiceFromDb(m,import->name,0); 1529 if(s2==NULL){ 1530 #endif 1531 s1 = createService(); 1532 t = readServiceFile (m, import->value, &s1, import->name); 1410 1533 1411 if (t < 0) // failure reading zcfg 1412 { 1413 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1414 char tmp01[1024]; 1415 if (tmp00 != NULL) 1416 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); 1417 else 1418 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1419 1420 dup2 (saved_stdout, fileno (stdout)); 1421 errorException (m, tmp01, "InternalError", NULL); 1422 1423 freeMaps (&m); 1424 free (m); 1425 1426 if(zooRegistry!=NULL){ 1427 freeRegistry(&zooRegistry); 1428 free(zooRegistry); 1534 if (t < 0) // failure reading zcfg 1535 { 1536 map *tmp00 = getMapFromMaps (m, "lenv", "message"); 1537 char tmp01[1024]; 1538 if (tmp00 != NULL) 1539 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value); 1540 else 1541 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1542 1543 zDup2 (saved_stdout, fileno (stdout)); 1544 errorException (m, tmp01, "InternalError", NULL); 1545 1546 freeMaps (&m); 1547 free (m); 1548 1549 if(zooRegistry!=NULL){ 1550 freeRegistry(&zooRegistry); 1551 free(zooRegistry); 1552 } 1553 free (orig); 1554 free (REQUEST); 1555 closedir (dirp); 1556 //xmlFreeDoc (doc); 1557 xmlCleanupParser (); 1558 zooXmlCleanupNs (); 1559 1560 return 1; 1429 1561 } 1430 free (orig); 1431 free (REQUEST); 1432 closedir (dirp); 1433 xmlFreeDoc (doc); 1434 xmlCleanupParser (); 1435 zooXmlCleanupNs (); 1436 1437 return 1; 1438 } 1439 #ifdef DEBUG 1440 dumpService (s1); 1441 #endif 1442 1443 inheritance(zooRegistry,&s1); 1444 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1445 freeService (&s1); 1446 free (s1); 1447 s1 = NULL; 1448 scount++; 1449 hasVal = 1; 1450 } 1562 #ifdef DEBUG 1563 dumpService (s1); 1564 #endif 1565 inheritance(zooRegistry,&s1); 1566 #ifdef USE_HPC 1567 addNestedOutputs(&s1); 1568 #endif 1569 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1570 freeService (&s1); 1571 free (s1); 1572 s1 = NULL; 1573 scount++; 1574 hasVal = 1; 1575 #ifdef META_DB 1576 } 1577 #endif 1578 } 1451 1579 else if (strstr (corig, ".") != NULL) 1452 1580 { … … 1457 1585 addToMap (request_inputs, "metapath", tmpMap->value); 1458 1586 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1459 1460 s1 = (service *) malloc (SERVICE_SIZE); 1587 /** 1588 * No support for dot in service name stored in metadb!? 1589 #ifdef META_DB 1590 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 1591 if(s2==NULL){ 1592 #endif 1593 */ 1594 s1 = createService(); 1461 1595 t = readServiceFile (m, buff1, &s1, tmpMapI->value); 1462 1596 if (t < 0) … … 1474 1608 ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), 1475 1609 tmps); 1476 dup2 (saved_stdout, fileno (stdout));1610 zDup2 (saved_stdout, fileno (stdout)); 1477 1611 errorException (m, tmp01, "InvalidParameterValue", 1478 1612 "identifier"); … … 1489 1623 free (s1); 1490 1624 closedir (dirp); 1491 xmlFreeDoc (doc);1625 //xmlFreeDoc (doc); 1492 1626 xmlCleanupParser (); 1493 1627 zooXmlCleanupNs (); … … 1498 1632 #endif 1499 1633 inheritance(zooRegistry,&s1); 1500 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1634 #ifdef USE_HPC 1635 addNestedOutputs(&s1); 1636 #endif 1637 printDescribeProcessForProcess (zooRegistry, m, doc, n, s1); 1501 1638 freeService (&s1); 1502 1639 free (s1); … … 1508 1645 else 1509 1646 { 1510 memset (buff, 0, 256); 1511 snprintf (buff, 256, "%s.zcfg", corig); 1512 memset (buff1, 0, 1024); 1513 #ifdef DEBUG 1514 printf ("\n#######%s\n########\n", buff); 1515 #endif 1516 while ((dp = readdir (dirp)) != NULL) 1517 { 1518 if (strcasecmp (dp->d_name, buff) == 0) 1519 { 1520 memset (buff1, 0, 1024); 1521 snprintf (buff1, 1024, "%s/%s", conf_dir, 1522 dp->d_name); 1523 s1 = (service *) malloc (SERVICE_SIZE); 1524 if (s1 == NULL) 1525 { 1526 dup2 (saved_stdout, fileno (stdout)); 1527 return errorException (m, 1528 _ 1529 ("Unable to allocate memory"), 1530 "InternalError", 1531 NULL); 1532 } 1647 #ifdef META_DB 1648 _init_sql(m,"metadb"); 1649 //FAILED CONNECTING DB 1650 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){ 1651 fprintf(stderr,"ERROR CONNECTING METADB"); 1652 } 1653 service* s2=extractServiceFromDb(m,corig,0); 1654 if(s2!=NULL){ 1655 inheritance(zooRegistry,&s2); 1656 #ifdef USE_HPC 1657 addNestedOutputs(&s2); 1658 #endif 1659 printDescribeProcessForProcess (zooRegistry,m, doc, n, s2); 1660 freeService (&s2); 1661 free (s2); 1662 s2 = NULL; 1663 hasVal = 1; 1664 }else /*TOTO*/{ 1665 #endif 1666 memset (buff, 0, 256); 1667 snprintf (buff, 256, "%s.zcfg", corig); 1668 memset (buff1, 0, 1024); 1669 #ifdef DEBUG 1670 printf ("\n#######%s\n########\n", buff); 1671 #endif 1672 while ((dp = readdir (dirp)) != NULL) 1673 { 1674 if (strcasecmp (dp->d_name, buff) == 0) 1675 { 1676 memset (buff1, 0, 1024); 1677 snprintf (buff1, 1024, "%s/%s", conf_dir, 1678 dp->d_name); 1679 s1 = createService(); 1680 if (s1 == NULL) 1681 { 1682 zDup2 (saved_stdout, fileno (stdout)); 1683 return errorException (m, 1684 _ 1685 ("Unable to allocate memory"), 1686 "InternalError", 1687 NULL); 1688 } 1533 1689 #ifdef DEBUG_SERVICE_CONF 1534 fprintf 1535 (stderr,"#################\n(%s) %s\n#################\n", 1536 r_inputs->value, buff1); 1537 #endif 1538 char *tmp0 = zStrdup (dp->d_name); 1539 tmp0[strlen (tmp0) - 5] = 0; 1540 t = readServiceFile (m, buff1, &s1, tmp0); 1541 free (tmp0); 1542 if (t < 0) 1543 { 1544 map *tmp00 = 1545 getMapFromMaps (m, "lenv", "message"); 1546 char tmp01[1024]; 1547 if (tmp00 != NULL) 1548 sprintf (tmp01, 1549 _ 1550 ("Unable to parse the ZCFG file: %s (%s)"), 1551 dp->d_name, tmp00->value); 1552 else 1553 sprintf (tmp01, 1554 _ 1555 ("Unable to parse the ZCFG file: %s."), 1556 dp->d_name); 1557 dup2 (saved_stdout, fileno (stdout)); 1558 errorException (m, tmp01, "InternalError", 1559 NULL); 1560 freeMaps (&m); 1561 free (m); 1562 if(zooRegistry!=NULL){ 1563 freeRegistry(&zooRegistry); 1564 free(zooRegistry); 1690 fprintf 1691 (stderr,"#################\n(%s) %s\n#################\n", 1692 r_inputs->value, buff1); 1693 #endif 1694 char *tmp0 = zStrdup (dp->d_name); 1695 tmp0[strlen (tmp0) - 5] = 0; 1696 t = readServiceFile (m, buff1, &s1, tmp0); 1697 free (tmp0); 1698 if (t < 0) 1699 { 1700 map *tmp00 = 1701 getMapFromMaps (m, "lenv", "message"); 1702 char tmp01[1024]; 1703 if (tmp00 != NULL) 1704 sprintf (tmp01, 1705 _ 1706 ("Unable to parse the ZCFG file: %s (%s)"), 1707 dp->d_name, tmp00->value); 1708 else 1709 sprintf (tmp01, 1710 _ 1711 ("Unable to parse the ZCFG file: %s."), 1712 dp->d_name); 1713 zDup2 (saved_stdout, fileno (stdout)); 1714 errorException (m, tmp01, "InternalError", 1715 NULL); 1716 freeMaps (&m); 1717 free (m); 1718 if(zooRegistry!=NULL){ 1719 freeRegistry(&zooRegistry); 1720 free(zooRegistry); 1721 } 1722 free (orig); 1723 free (REQUEST); 1724 closedir (dirp); 1725 //xmlFreeDoc (doc); 1726 xmlCleanupParser (); 1727 zooXmlCleanupNs (); 1728 return 1; 1565 1729 } 1566 free (orig); 1567 free (REQUEST); 1568 closedir (dirp); 1569 xmlFreeDoc (doc); 1570 xmlCleanupParser (); 1571 zooXmlCleanupNs (); 1572 return 1; 1573 } 1574 #ifdef DEBUG 1575 dumpService (s1); 1576 #endif 1577 inheritance(zooRegistry,&s1); 1578 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1579 freeService (&s1); 1580 free (s1); 1581 s1 = NULL; 1582 scount++; 1583 hasVal = 1; 1584 } 1585 } 1586 } 1730 #ifdef DEBUG 1731 dumpService (s1); 1732 #endif 1733 inheritance(zooRegistry,&s1); 1734 #ifdef USE_HPC 1735 addNestedOutputs(&s1); 1736 #endif 1737 /*json_object* jobj=serviceToJson(s1); 1738 const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN); 1739 fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/ 1740 1741 printDescribeProcessForProcess (zooRegistry,m, doc, n, s1); 1742 freeService (&s1); 1743 free (s1); 1744 s1 = NULL; 1745 scount++; 1746 hasVal = 1; 1747 } 1748 } 1749 #ifdef META_DB 1750 } 1751 #endif 1752 } 1587 1753 if (hasVal < 0) 1588 1754 { … … 1597 1763 _("Unable to parse the ZCFG file: %s."), 1598 1764 buff); 1599 dup2 (saved_stdout, fileno (stdout));1765 zDup2 (saved_stdout, fileno (stdout)); 1600 1766 errorException (m, tmp01, "InvalidParameterValue", 1601 1767 "Identifier"); … … 1609 1775 free (REQUEST); 1610 1776 closedir (dirp); 1777 if (corig != NULL) 1778 free (corig); 1611 1779 xmlFreeDoc (doc); 1612 1780 xmlCleanupParser (); … … 1618 1786 if (corig != NULL) 1619 1787 free (corig); 1620 } 1788 } 1621 1789 } 1622 1790 closedir (dirp); 1623 1791 fflush (stdout); 1624 dup2 (saved_stdout, fileno (stdout));1792 zDup2 (saved_stdout, fileno (stdout)); 1625 1793 free (orig); 1626 printDocument (m, doc, getpid ());1794 printDocument (m, doc, zGetpid ()); 1627 1795 freeMaps (&m); 1628 1796 free (m); … … 1634 1802 free (SERVICE_URL); 1635 1803 fflush (stdout); 1804 #ifdef META_DB 1805 close_sql(m,0); 1806 //end_sql(); 1807 #endif 1636 1808 return 0; 1637 1809 } … … 1640 1812 map* version=getMapFromMaps(m,"main","rversion"); 1641 1813 int vid=getVersionId(version->value); 1642 1643 1814 int len = 0; 1815 int j = 0; 1644 1816 for(j=0;j<nbSupportedRequests;j++){ 1645 1817 if(requests[vid][j]!=NULL) … … 1712 1884 } 1713 1885 s1 = NULL; 1714 s1 = (service *) malloc (SERVICE_SIZE); 1715 if (s1 == NULL) 1716 { 1717 freeMaps (&m); 1718 free (m); 1719 if(zooRegistry!=NULL){ 1720 freeRegistry(&zooRegistry); 1721 free(zooRegistry); 1722 } 1723 free (REQUEST); 1724 free (SERVICE_URL); 1725 return errorException (m, _("Unable to allocate memory"), 1726 "InternalError", NULL); 1727 } 1728 1886 1729 1887 r_inputs = getMap (request_inputs, "Identifier"); 1730 1731 1888 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 1732 1889 if (import != NULL && import->value != NULL) { 1733 1734 1735 1890 strncpy(tmps1, import->value, 1024); 1891 setMapInMaps (m, "lenv", "Identifier", r_inputs->value); 1892 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value); 1736 1893 } 1737 1894 else { … … 1757 1914 1758 1915 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 1759 int saved_stdout = dup (fileno (stdout)); 1760 dup2 (fileno (stderr), fileno (stdout)); 1761 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1762 inheritance(zooRegistry,&s1); 1763 if(zooRegistry!=NULL){ 1764 freeRegistry(&zooRegistry); 1765 free(zooRegistry); 1916 1917 #ifdef META_DB 1918 int metadb_id=_init_sql(m,"metadb"); 1919 //FAILED CONNECTING DB 1920 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 1921 fprintf(stderr,"ERROR CONNECTING METADB\n"); 1766 1922 } 1767 fflush (stdout); 1768 dup2 (saved_stdout, fileno (stdout)); 1769 if (t < 0) 1770 { 1771 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 1772 sprintf (tmpMsg, 1773 _ 1774 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 1775 r_inputs->value); 1776 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1777 free (tmpMsg); 1778 free (s1); 1779 freeMaps (&m); 1780 free (m); 1781 free (REQUEST); 1782 free (SERVICE_URL); 1783 return 0; 1784 } 1785 close (saved_stdout); 1786 1923 if(metadb_id>=0) 1924 s1=extractServiceFromDb(m,r_inputs->value,0); 1925 //close_sql(m,0); 1926 if(s1!=NULL){ 1927 inheritance(zooRegistry,&s1); 1928 #ifdef USE_HPC 1929 addNestedOutputs(&s1); 1930 #endif 1931 if(zooRegistry!=NULL){ 1932 freeRegistry(&zooRegistry); 1933 free(zooRegistry); 1934 } 1935 }else /* Not found in MetaDB */{ 1936 #endif 1937 s1 = createService(); 1938 if (s1 == NULL) 1939 { 1940 freeMaps (&m); 1941 free (m); 1942 if(zooRegistry!=NULL){ 1943 freeRegistry(&zooRegistry); 1944 free(zooRegistry); 1945 } 1946 free (REQUEST); 1947 free (SERVICE_URL); 1948 return errorException (m, _("Unable to allocate memory"), 1949 "InternalError", NULL); 1950 } 1951 1952 int saved_stdout = zDup (fileno (stdout)); 1953 zDup2 (fileno (stderr), fileno (stdout)); 1954 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1955 if(t>=0){ 1956 inheritance(zooRegistry,&s1); 1957 #ifdef USE_HPC 1958 addNestedOutputs(&s1); 1959 #endif 1960 } 1961 if(zooRegistry!=NULL){ 1962 freeRegistry(&zooRegistry); 1963 free(zooRegistry); 1964 } 1965 fflush (stdout); 1966 zDup2 (saved_stdout, fileno (stdout)); 1967 if (t < 0) 1968 { 1969 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 1970 sprintf (tmpMsg, 1971 _ 1972 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 1973 r_inputs->value); 1974 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1975 free (tmpMsg); 1976 free (s1); 1977 freeMaps (&m); 1978 free (m); 1979 free (REQUEST); 1980 free (SERVICE_URL); 1981 return 0; 1982 } 1983 zClose (saved_stdout); 1984 #ifdef META_DB 1985 } 1986 #endif 1987 1787 1988 #ifdef DEBUG 1788 1989 dumpService (s1); … … 1821 2022 return 0; 1822 2023 } 1823 2024 //InternetCloseHandle (&hInternet); 2025 1824 2026 // Define each env variable in runing environment 1825 2027 maps *curs = getMaps (m, "env"); … … 1862 2064 2) * sizeof (char)); 1863 2065 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 1864 putenv (toto);2066 _putenv (toto); 1865 2067 #ifdef DEBUG 1866 2068 fflush (stderr); 1867 2069 #endif 1868 2070 #endif 2071 1869 2072 #ifdef DEBUG 1870 2073 fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name, … … 1959 2162 1960 2163 int eres = SERVICE_STARTED; 1961 int cpid = getpid (); 1962 2164 int cpid = zGetpid (); 2165 2166 // Create a map containing a copy of the request map 2167 maps *_tmpMaps = createMaps("request"); 2168 addMapToMap(&_tmpMaps->content,request_inputs); 2169 addMapsToMaps (&m, _tmpMaps); 2170 freeMaps (&_tmpMaps); 2171 free (_tmpMaps); 1963 2172 /** 1964 2173 * Initialize the specific [lenv] section which contains runtime variables: … … 1981 2190 * 1982 2191 */ 1983 maps *_tmpMaps = createMaps("lenv");2192 _tmpMaps = createMaps("lenv"); 1984 2193 char tmpBuff[100]; 1985 2194 struct ztimeval tp; … … 2009 2218 addToMap (_tmpMaps->content, "soap", "false"); 2010 2219 2011 // Parse the session file and add it to the main maps 2220 // Parse the session file and add it to the main maps 2221 char* originalCookie=NULL; 2012 2222 if (cgiCookie != NULL && strlen (cgiCookie) > 0) 2013 2223 { 2014 2224 int hasValidCookie = -1; 2015 char *tcook = zStrdup (cgiCookie); 2016 char *tmp = NULL; 2225 char *tcook = originalCookie = zStrdup (cgiCookie); 2017 2226 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 2018 if (testing == NULL) 2227 parseCookie(&m,originalCookie); 2228 map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value)); 2229 if (sessId!=NULL) 2019 2230 { 2020 tmp = zStrdup ("ID="); 2021 } 2022 else 2023 { 2024 tmp = 2025 (char *) malloc ((strlen (testing->value) + 2) * sizeof (char)); 2026 sprintf (tmp, "%s=", testing->value); 2027 } 2028 if (strstr (cgiCookie, ";") != NULL) 2029 { 2030 char *token, *saveptr; 2031 token = strtok_r (cgiCookie, ";", &saveptr); 2032 while (token != NULL) 2033 { 2034 if (strcasestr (token, tmp) != NULL) 2035 { 2036 if (tcook != NULL) 2037 free (tcook); 2038 tcook = zStrdup (token); 2039 hasValidCookie = 1; 2040 } 2041 token = strtok_r (NULL, ";", &saveptr); 2042 } 2043 } 2044 else 2045 { 2046 if (strstr (cgiCookie, "=") != NULL 2047 && strcasestr (cgiCookie, tmp) != NULL) 2048 { 2049 tcook = zStrdup (cgiCookie); 2050 hasValidCookie = 1; 2051 } 2052 if (tmp != NULL) 2053 { 2054 free (tmp); 2055 } 2056 } 2057 if (hasValidCookie > 0) 2058 { 2059 addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1); 2231 addToMap (_tmpMaps->content, "sessid", sessId->value); 2060 2232 char session_file_path[1024]; 2061 2233 map *tmpPath = getMapFromMaps (m, "main", "sessPath"); … … 2065 2237 if (tmp1 != NULL) 2066 2238 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2067 s trstr (tmp1, "=") + 1);2239 sessId->value); 2068 2240 else 2069 2241 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, 2070 s trstr (cgiCookie, "=") + 1);2242 sessId->value); 2071 2243 free (tcook); 2072 2244 maps *tmpSess = (maps *) malloc (MAPS_SIZE); … … 2076 2248 if (istat == 0 && file_status.st_size > 0) 2077 2249 { 2250 int saved_stdout = zDup (fileno (stdout)); 2251 zDup2 (fileno (stderr), fileno (stdout)); 2078 2252 conf_read (session_file_path, tmpSess); 2079 2253 addMapsToMaps (&m, tmpSess); 2080 2254 freeMaps (&tmpSess); 2255 fflush(stdout); 2256 zDup2 (saved_stdout, fileno (stdout)); 2257 zClose(saved_stdout); 2081 2258 } 2082 2259 free (tmpSess); … … 2091 2268 #endif 2092 2269 int ei = 1; 2093 char *s =2270 2094 2271 #ifdef WIN32 2095 GetEnvironmentStrings(); 2272 LPVOID orig = GetEnvironmentStrings(); 2273 LPTSTR s = (LPTSTR) orig; 2096 2274 #else 2097 *environ; 2098 #endif 2275 char **orig = environ; 2276 char *s=*orig; 2277 #endif 2278 2099 2279 _tmpMaps = createMaps("renv"); 2100 for (; s; ei++) { 2101 char* tmpName=zStrdup(s); 2102 char* tmpValue=strstr(s,"=")+1; 2103 tmpName[strlen(tmpName)-strlen(tmpValue)-1]=0; 2104 if(_tmpMaps->content == NULL) 2105 _tmpMaps->content = createMap (tmpName,tmpValue); 2106 else 2107 addToMap (_tmpMaps->content,tmpName,tmpValue); 2108 free(tmpName); 2109 s = *(environ+ei); 2280 if(orig!=NULL) 2281 for (; 2282 #ifdef WIN32 2283 *s; 2284 s++ 2285 #else 2286 s; 2287 ei++ 2288 #endif 2289 ) { 2290 if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){ 2291 int len=strlen(s); 2292 char* tmpName=zStrdup(s); 2293 char* tmpValue=strstr(s,"=")+1; 2294 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); 2295 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); 2296 if(_tmpMaps->content == NULL) 2297 _tmpMaps->content = createMap (tmpName1,tmpValue); 2298 else 2299 addToMap (_tmpMaps->content,tmpName1,tmpValue); 2300 free(tmpName1); 2301 free(tmpName); 2302 } 2303 #ifndef WIN32 2304 s = *(orig+ei); 2305 #endif 2306 } 2307 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ 2308 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); 2110 2309 } 2111 2310 addMapsToMaps (&m, _tmpMaps); 2112 2311 freeMaps (&_tmpMaps); 2113 2312 free (_tmpMaps); 2114 2313 #ifdef WIN32 2314 FreeEnvironmentStrings((LPCH)orig); 2315 #endif 2316 if(postRequest!=NULL) 2317 setMapInMaps (m, "renv", "xrequest", postRequest->value); 2318 //dumpMaps(m); 2115 2319 #ifdef WIN32 2116 2320 char *cgiSidL = NULL; … … 2160 2364 return -1; 2161 2365 } 2366 map* testMap=getMapFromMaps(m,"main","memory"); 2367 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 2368 dumpMapsValuesToFiles(&m,&request_input_real_format); 2162 2369 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2163 &request_output_real_format, &eres); 2370 &request_output_real_format, &eres); 2371 2372 #ifdef META_DB 2373 close_sql(m,0); 2374 #endif 2164 2375 } 2165 2376 else … … 2169 2380 fprintf (stderr, "\nPID : %d\n", cpid); 2170 2381 #endif 2171 2172 2382 #ifndef WIN32 2173 2383 pid = fork (); … … 2175 2385 if (cgiSid == NULL) 2176 2386 { 2177 2178 2179 2180 2387 createProcess (m, request_inputs, s1, NULL, cpid, 2388 request_input_real_format, 2389 request_output_real_format); 2390 pid = cpid; 2181 2391 } 2182 2392 else 2183 2393 { 2184 2185 2394 pid = 0; 2395 cpid = atoi (cgiSid); 2186 2396 updateStatus(m,0,_("Initializing")); 2187 2397 } 2188 2398 #endif 2189 2399 if (pid > 0) 2190 2191 / **2192 *dady :2193 *set status to SERVICE_ACCEPTED2194 */2195 #ifdef DEBUG 2196 2197 getpid ());2198 #endif 2199 2200 2400 { 2401 // 2402 // dady : 2403 // set status to SERVICE_ACCEPTED 2404 // 2405 #ifdef DEBUG 2406 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2407 zGetpid ()); 2408 #endif 2409 eres = SERVICE_ACCEPTED; 2410 } 2201 2411 else if (pid == 0) 2202 { 2203 /** 2204 * son : have to close the stdout, stdin and stderr to let the parent 2205 * process answer to http client. 2206 */ 2412 { 2413 eres = SERVICE_ACCEPTED; 2414 // 2415 // son : have to close the stdout, stdin and stderr to let the parent 2416 // process answer to http client. 2417 // 2207 2418 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2208 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2209 int cpid = atoi (tmpm->value); 2210 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2419 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2420 int cpid = atoi (tmpm->value); 2421 pid=cpid; 2422 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2423 setMapInMaps (m, "lenv", "async","true"); 2211 2424 map* r_inputs1 = createMap("ServiceName", s1->name); 2212 2425 2213 2426 // Create the filename for the result file (.res) 2214 2215 2216 2217 2218 2427 fbkpres = 2428 (char *) 2429 malloc ((strlen (r_inputs->value) + 2430 strlen (usid->value) + 7) * sizeof (char)); 2431 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2219 2432 bmap = createMaps("status"); 2220 2433 bmap->content=createMap("usid",usid->value); 2221 2434 addToMap(bmap->content,"sid",tmpm->value); 2222 addIntToMap(bmap->content,"pid", getpid());2223 2435 addIntToMap(bmap->content,"pid",zGetpid()); 2436 2224 2437 // Create PID file referencing the OS process identifier 2225 2226 2227 2228 2229 2438 fbkpid = 2439 (char *) 2440 malloc ((strlen (r_inputs->value) + 2441 strlen (usid->value) + 7) * sizeof (char)); 2442 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 2230 2443 setMapInMaps (m, "lenv", "file.pid", fbkpid); 2231 2444 2232 2233 printf("%d", getpid());2445 f0 = freopen (fbkpid, "w+",stdout); 2446 printf("%d",zGetpid()); 2234 2447 fflush(stdout); 2235 2448 2236 2449 // Create SID file referencing the semaphore name 2237 2238 2239 2240 2241 2450 fbkp = 2451 (char *) 2452 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2453 strlen (usid->value) + 7) * sizeof (char)); 2454 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 2242 2455 setMapInMaps (m, "lenv", "file.sid", fbkp); 2243 2456 FILE* f2 = freopen (fbkp, "w+",stdout); 2244 2457 printf("%s",tmpm->value); 2245 2458 fflush(f2); 2246 2459 free(fbkp); 2247 2460 2248 2249 2250 2251 2252 2253 2461 fbkp = 2462 (char *) 2463 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2464 strlen (usid->value) + 7) * sizeof (char)); 2465 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 2466 usid->value); 2254 2467 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 2255 2256 2257 2258 2259 2260 2468 flog = 2469 (char *) 2470 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2471 strlen (usid->value) + 13) * sizeof (char)); 2472 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2473 r_inputs1->value, usid->value); 2261 2474 setMapInMaps (m, "lenv", "file.log", flog); 2262 2475 #ifdef DEBUG 2263 2264 2265 getpid ());2266 2267 #endif 2268 2269 2476 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 2477 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 2478 zGetpid ()); 2479 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 2480 #endif 2481 freopen (flog, "w+", stderr); 2482 fflush (stderr); 2270 2483 f0 = freopen (fbkp, "w+", stdout); 2271 2484 rewind (stdout); … … 2277 2490 recordServiceStatus(m); 2278 2491 #endif 2492 #ifdef USE_CALLBACK 2493 invokeCallback(m,NULL,NULL,0,0); 2494 #endif 2279 2495 if(vid==0){ 2280 / **2281 *set status to SERVICE_STARTED and flush stdout to ensure full2282 *content was outputed (the file used to store the ResponseDocument).2283 * The rewind stdout to restart writing from the bgining of the file,2284 * this waythe data will be updated at the end of the process run.2285 */2496 // 2497 // set status to SERVICE_STARTED and flush stdout to ensure full 2498 // content was outputed (the file used to store the ResponseDocument). 2499 // Then, rewind stdout to restart writing from the begining of the file. 2500 // This way, the data will be updated at the end of the process run. 2501 // 2286 2502 printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value, 2287 2503 SERVICE_STARTED, request_input_real_format, … … 2293 2509 } 2294 2510 2295 2296 2297 2298 2299 2300 2301 2302 2511 fflush (stderr); 2512 2513 fbkp1 = 2514 (char *) 2515 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2516 strlen (usid->value) + 13) * sizeof (char)); 2517 sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, 2518 r_inputs1->value, usid->value); 2303 2519 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 2304 2520 2305 f1 = freopen (fbkp1, "w+", stdout); 2306 2521 f1 = freopen (fbkp1, "w+", stdout); 2522 2523 map* serviceTypeMap=getMap(s1->content,"serviceType"); 2524 if(serviceTypeMap!=NULL) 2525 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 2526 2527 char *flenv = 2528 (char *) 2529 malloc ((strlen (r_inputs->value) + 2530 strlen (usid->value) + 12) * sizeof (char)); 2531 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2532 maps* lenvMaps=getMaps(m,"lenv"); 2533 dumpMapsToFile(lenvMaps,flenv,0); 2534 free(flenv); 2535 2536 #ifdef USE_CALLBACK 2537 invokeCallback(m,request_input_real_format,NULL,1,0); 2538 #endif 2307 2539 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2308 2540 freeService (&s1); 2309 2541 free (s1); 2542 fflush (stdout); 2543 fflush (stderr); 2310 2544 fclose (f0); 2311 2545 fclose (f1); 2312 2546 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2313 2547 return -1; 2314 unlink (fbkpid); 2548 #ifndef RELY_ON_DB 2549 dumpMapsToFile(bmap,fbkpres,1); 2550 removeShmLock (m, 1); 2551 #else 2552 recordResponse(m,fbkp1); 2553 #ifdef USE_CALLBACK 2554 invokeCallback(m,NULL,NULL,7,0); 2555 #endif 2556 #endif 2557 zUnlink (fbkpid); 2315 2558 unhandleStatus (m); 2559 #ifdef RELY_ON_DB 2560 #ifdef META_DB 2561 cleanupCallbackThreads(); 2562 close_sql(m,1); 2563 #endif 2564 close_sql(m,0); 2565 #endif 2316 2566 freeMaps (&m); 2317 2567 free (m); … … 2324 2574 freeMaps (&tmpmaps); 2325 2575 free (tmpmaps); 2326 fflush (stdout);2327 fflush (stderr);2328 2576 return -1; 2329 2577 } 2330 loadServiceAndRun (&m, s1, request_inputs, 2331 &request_input_real_format, 2332 &request_output_real_format, &eres); 2333 } 2578 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 2579 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 2580 #ifdef USE_CALLBACK 2581 invokeCallback(m,NULL,NULL,7,0); 2582 #endif 2583 eres=-1;//SERVICE_FAILED; 2584 }else{ 2585 map* testMap=getMapFromMaps(m,"main","memory"); 2586 if(testMap==NULL || strcasecmp(testMap->value,"load")!=0) 2587 dumpMapsValuesToFiles(&m,&request_input_real_format); 2588 loadServiceAndRun (&m, s1, request_inputs, 2589 &request_input_real_format, 2590 &request_output_real_format, &eres); 2591 } 2592 } 2334 2593 else 2335 2594 { … … 2338 2597 * error response here !!! 2339 2598 */ 2340 2341 2342 2599 eres = -1; 2600 errorException (m, _("Unable to run the child process properly"), 2601 "InternalError", NULL); 2343 2602 } 2344 2603 } 2345 2346 #ifdef DEBUG 2604 2605 #ifdef DEBUG 2606 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2347 2607 dumpMaps (request_output_real_format); 2348 #endif 2349 2608 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2609 #endif 2610 fflush(stdout); 2611 rewind(stdout); 2612 2613 //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres); 2350 2614 if (eres != -1) 2351 2615 outputResponse (s1, request_input_real_format, … … 2353 2617 cpid, m, eres); 2354 2618 fflush (stdout); 2355 2619 2356 2620 /** 2357 2621 * Ensure that if error occurs when freeing memory, no signal will return … … 2367 2631 signal (SIGABRT, donothing); 2368 2632 #endif 2369 if (((int) getpid ()) != cpid || cgiSid != NULL) 2370 { 2633 2634 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2635 { 2636 if (eres == SERVICE_SUCCEEDED) 2637 #ifdef USE_CALLBACK 2638 invokeCallback(m,NULL,request_output_real_format,5,1); 2639 #endif 2640 fflush(stderr); 2641 fflush(stdout); 2642 2371 2643 fclose (stdout); 2372 fclose (stderr);2373 2644 2374 2645 fclose (f0); 2375 2646 fclose (f1); 2376 2377 if (dumpBackFinalFile(m, fbkp, fbkp1) < 0) 2378 return -1; 2379 2380 unlink (fbkpid); 2647 2648 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2649 return -1; 2650 zUnlink (fbkpid); 2381 2651 switch(eres){ 2382 2652 default: … … 2390 2660 break; 2391 2661 } 2392 #ifndef RELY_ON_DB 2662 #ifndef RELY_ON_DB 2393 2663 dumpMapsToFile(bmap,fbkpres,1); 2394 2664 removeShmLock (m, 1); 2395 2665 #else 2396 2666 recordResponse(m,fbkp1); 2667 if (eres == SERVICE_SUCCEEDED) 2668 #ifdef USE_CALLBACK 2669 invokeCallback(m,NULL,request_output_real_format,6,0); 2670 #endif 2397 2671 #endif 2398 2672 freeMaps(&bmap); 2399 2673 free(bmap); 2400 unlink (fbkp1); 2401 unlink (flog); 2674 zUnlink (fbkp1); 2402 2675 unhandleStatus (m); 2676 #ifdef RELY_ON_DB 2677 #ifdef META_DB 2678 cleanupCallbackThreads(); 2679 close_sql(m,1); 2680 #endif 2681 close_sql(m,0); 2682 end_sql(); 2683 #endif 2403 2684 free(fbkpid); 2404 2685 free(fbkpres); 2405 free (flog);2406 2686 free (fbkp1); 2407 // free (tmps1); // tmps1 is stack memory and should not be freed2408 2687 if(cgiSid!=NULL) 2409 2688 free(cgiSid); 2410 } 2411 2689 //InternetCloseHandle (&hInternet); 2690 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2691 fflush(stderr); 2692 fclose (stderr); 2693 zUnlink (flog); 2694 free (flog); 2695 } 2696 else{ 2697 //InternetCloseHandle (&hInternet); 2698 #ifdef META_DB 2699 close_sql(m,0); 2700 #endif 2701 } 2702 2412 2703 freeService (&s1); 2413 2704 free (s1); … … 2429 2720 #endif 2430 2721 2431 if (((int) getpid ()) != cpid || cgiSid != NULL)2722 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2432 2723 { 2433 2724 exit (0); -
TabularUnified trunk/zoo-project/zoo-services/cgal/Makefile ¶ ¶
r779 r917 1 1 ZRPATH=../.. 2 2 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts 3 CFLAGS= -I${INST_INCLUDE}${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG3 CFLAGS= ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG 4 4 CC=gcc 5 5 … … 7 7 g++ ${CFLAGS} -c ./delaunay.c 8 8 g++ ${CFLAGS} -c ./voronoi.c 9 g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${ MACOS_LD_FLAGS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service9 g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service -lfcgi 10 10 11 11 cgal_service.o: cgal_service.c cgal_service.h -
TabularUnified trunk/zoo-project/zoo-services/cgal/cgal_service.c ¶ ¶
r775 r917 24 24 #include "cgal_service.h" 25 25 26 int parseInput(maps* conf,maps* inputs, std::vector<Point >* points,char* filename){26 int parseInput(maps* conf,maps* inputs, std::vector<Pointz>* points,char* filename){ 27 27 map* tmpm=NULL; 28 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 29 VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE); 30 VSIFCloseL(ifile); 28 tmpm=getMapFromMaps(inputs,"InputPoints","cache_file"); 31 29 #if GDAL_VERSION_MAJOR >= 2 32 GDALDataset *ipoDS = 33 (GDALDataset*) GDALOpenEx( filename, 34 GDAL_OF_READONLY | GDAL_OF_VECTOR, 35 NULL, NULL, NULL ); 30 GDALDataset *ipoDS; 36 31 #else 37 OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);32 OGRDataSource* ipoDS; 38 33 #endif 34 if(tmpm==NULL){ 35 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 36 VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE); 37 VSIFCloseL(ifile); 38 #if GDAL_VERSION_MAJOR >= 2 39 ipoDS = (GDALDataset*) GDALOpenEx( filename, 40 GDAL_OF_READONLY | GDAL_OF_VECTOR, 41 NULL, NULL, NULL ); 42 #else 43 ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); 44 #endif 45 }else 46 #if GDAL_VERSION_MAJOR >= 2 47 ipoDS = (GDALDataset*) GDALOpenEx( tmpm->value, 48 GDAL_OF_READONLY | GDAL_OF_VECTOR, 49 NULL, NULL, NULL ); 50 #else 51 ipoDS = OGRSFDriverRegistrar::Open(tmpm->value,FALSE); 52 #endif 53 39 54 if( ipoDS == NULL ) 40 55 { … … 87 102 break; 88 103 if(poFeature->GetGeometryRef() != NULL){ 89 points->push_back(Point (OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));104 points->push_back(Pointz(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0))); 90 105 } 91 106 } -
TabularUnified trunk/zoo-project/zoo-services/cgal/cgal_service.h ¶ ¶
r469 r917 38 38 39 39 typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; 40 typedef Kernel::Point_2 Point ;40 typedef Kernel::Point_2 Pointz; 41 41 42 int parseInput(maps*,maps*, std::vector<Point >*,char*);42 int parseInput(maps*,maps*, std::vector<Pointz>*,char*); 43 43 44 44 #endif -
TabularUnified trunk/zoo-project/zoo-services/cgal/cgi-env/Voronoi.zcfg ¶ ¶
r536 r917 46 46 </Default> 47 47 <Supported> 48 mimeType = image/png 49 useMapserver = true 50 asReference = true 51 msStyle = STYLE COLOR 125 0 105 OUTLINECOLOR 0 0 0 WIDTH 0.3 OPACITY 65 END 52 </Supported> 53 <Supported> 48 54 mimeType = text/xml 49 55 encoding = base64 -
TabularUnified trunk/zoo-project/zoo-services/cgal/delaunay.c ¶ ¶
r775 r917 40 40 OGRRegisterAll(); 41 41 42 std::vector<Point > points;42 std::vector<Pointz> points; 43 43 if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED) 44 44 return res; -
TabularUnified trunk/zoo-project/zoo-services/cgal/voronoi.c ¶ ¶
r775 r917 24 24 25 25 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 26 #include <CGAL/Triangulation_euclidean_traits_xy_3.h>26 //#include <CGAL/Triangulation_euclidean_traits_2.h> 27 27 #include <CGAL/Delaunay_triangulation_2.h> 28 #include <CGAL/Constrained_Delaunay_triangulation_2.h>28 //#include <CGAL/Constrained_Delaunay_triangulation_2.h> 29 29 #include <CGAL/Triangulation_conformer_2.h> 30 30 #include <CGAL/Triangulation_face_base_2.h> … … 39 39 40 40 typedef CGAL::Delaunay_triangulation_2<Kernel> Triangulation; 41 typedef Triangulation::Face_iterator Face_iterator; 41 42 typedef Triangulation::Edge_iterator Edge_iterator; 42 43 typedef Triangulation::Vertex_circulator Vertex_circulator; … … 45 46 46 47 int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){ 47 #ifdef DEBUG48 //#ifdef DEBUG 48 49 fprintf(stderr,"\nService internal print\nStarting\n"); 49 #endif 50 //#endif 51 //return SERVICE_FAILED; 50 52 maps* cursor=inputs; 51 53 OGRGeometryH geometry,res; … … 54 56 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 55 57 58 fprintf(stderr," **** %s %d\n",__FILE__,__LINE__); 59 fflush(stderr); 60 56 61 OGRRegisterAll(); 57 62 58 std::vector<Point> points; 59 if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED) 60 return res; 63 std::vector<Pointz> points; 64 if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED){ 65 fprintf(stderr," **** %s %d\n",__FILE__,__LINE__); 66 fflush(stderr); 67 return SERVICE_FAILED; 68 } 69 fprintf(stderr," **** %s %d\n",__FILE__,__LINE__); 70 fflush(stderr); 61 71 62 72 Triangulation T; 63 73 T.insert(points.begin(), points.end()); 64 74 65 OGRRegisterAll();75 //OGRRegisterAll(); 66 76 /* -------------------------------------------------------------------- */ 67 77 /* Try opening the output datasource as an existing, writable */ … … 187 197 int ns = 0; 188 198 int nr = 0; 199 int nf = 0; 200 Face_iterator fit =T.faces_begin(); 201 FILE* f=fopen("/tmp/toto.log","w+"); 202 for ( ; fit !=T.faces_end(); ++fit) { 203 fprintf(stderr," *** %s %d %d %d\n",__FILE__,__LINE__,nf,fit.info()); 204 fflush(stderr); 205 206 nf++; 207 } 208 fclose(f); 189 209 Edge_iterator eit =T.edges_begin(); 190 210 for ( ; eit !=T.edges_end(); ++eit) { 191 211 CGAL::Object o = T.dual(eit); 192 212 if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) { 193 const Point p1=tmp->source(); 194 const Point p2=tmp->target(); 213 const Pointz p1=tmp->source(); 214 const Pointz p2=tmp->target(); 215 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); 195 216 #ifdef DEBUG 196 217 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); … … 210 231 } 211 232 else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) { 212 const Point p1=tmp->source();213 const Point p2=tmp->point(2);233 const Pointz p1=tmp->source(); 234 const Pointz p2=tmp->point(2); 214 235 OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 215 236 OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString); … … 250 271 fprintf(stderr,"\nService internal print\n===\n"); 251 272 #endif 252 OGRCleanupAll();273 //OGRCleanupAll(); 253 274 return SERVICE_SUCCEEDED; 254 275 } -
TabularUnified trunk/zoo-project/zoo-services/gdal/dem/cgi-env/Gdal_Dem.zcfg ¶ ¶
r412 r917 44 44 <Default /> 45 45 </LiteralData> 46 [co] 47 Title = Creation Option 48 Abstract = string representing options (NAME=VALUE) 49 minOccurs = 0 50 maxOccurs = 1 51 <LiteralData> 52 DataType = string 53 <Default /> 54 </LiteralData> 46 55 </DataInputs> 47 56 <DataOutputs> -
TabularUnified trunk/zoo-project/zoo-services/gdal/dem/service.c ¶ ¶
r444 r917 2486 2486 setMapInMaps(outputs,"Result","value",tmpMap->value); 2487 2487 } 2488 2489 tmpMap=getMapFromMaps(inputs,"co","value"); 2490 if(tmpMap!=NULL){ 2491 papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value ); 2492 map* tmpMap1; 2493 maps* tmpMaps=getMaps(inputs,"co"); 2494 if((tmpMap1=getMapFromMaps(inputs,"co","length"))!=NULL){ 2495 int i=1; 2496 int length=atoi(tmpMap1->value); 2497 for(;i<length;i++){ 2498 tmpMap=getMapArray(tmpMaps->content,"value",i); 2499 papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value ); 2500 } 2501 } 2502 } 2488 2503 2489 2504 tmpMap=NULL; -
TabularUnified trunk/zoo-project/zoo-services/hello-mono/cgi-env/longProcessMono.zcfg ¶ ¶
r794 r917 1 1 [longProcessMono] 2 Title = Create a welcome message string.3 Abstract = Create a welcome string.2 Title = Demo long process. 3 Abstract = This service doesn't do anything except taking its time, it demonstrates how to use the updateStatus function from your ZOO Service. 4 4 processVersion = 2 5 5 storeSupported = true … … 13 13 Title = Input string 14 14 Abstract = The name to display in the welcome message. 15 minOccurs = 115 minOccurs = 0 16 16 maxOccurs = 1 17 17 <LiteralData> 18 18 dataType = int 19 <Default> 20 AllowedValues = 101,202,303,404 21 rangeMin = -100 22 rangeMax = 100 23 rangeSpacing = 1 24 rangeClosure = co 25 value = 11 26 </Default> 27 <Supported> 28 AllowedValues = 405,502,503,504 29 </Supported> 30 <Supported> 31 AllowedValues = 540,502,603,604 32 </Supported> 19 <Default /> 33 20 </LiteralData> 34 21 </DataInputs> -
TabularUnified trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py ¶ ¶
r465 r917 95 95 96 96 def extractInputs(conf,obj): 97 if obj.keys().count("cache_file"): 98 print >> sys.stderr,obj 99 geometry=[] 100 ds = osgeo.ogr.Open(obj["cache_file"]) 101 lyr = ds.GetLayer(0) 102 feat = lyr.GetNextFeature() 103 while feat is not None: 104 geometry+=[feat.Clone()] 105 feat.Destroy() 106 feat = lyr.GetNextFeature() 107 ds.Destroy() 108 return geometry 97 109 if obj["mimeType"]=="application/json": 98 110 return createLayerFromJson(conf,obj["value"]) -
TabularUnified trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c ¶ ¶
r769 r917 473 473 { 474 474 475 if( EQUAL(475 if( 476 476 #if GDAL_VERSION_MAJOR >=2 477 poR->GetDriver(iDriver)->GetDescription()478 #else 479 poR->GetDriver(iDriver)->GetName()480 #endif 481 ,oDriver1))477 EQUAL(poR->GetDriver(iDriver)->GetDescription(),oDriver1) 478 #else 479 EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) 480 #endif 481 ) 482 482 { 483 483 poDriver = poR->GetDriver(iDriver); -
TabularUnified trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c ¶ ¶
r790 r917 96 96 #endif 97 97 { 98 char *pszDialect = NULL; 98 99 const char *pszFormat = "ESRI Shapefile"; 99 100 const char *pszDataSource = NULL; … … 155 156 sprintf(serverAddress,"%s",tmpMap->value); 156 157 } 157 158 158 159 tmpMap=NULL; 159 160 char tmpurl[1024]; … … 223 224 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 224 225 pszSQLStatement = tmpMap->value; 226 } 227 228 tmpMap=getMapFromMaps(inputs,"dialect","value"); 229 if(tmpMap!=NULL){ 230 pszDialect=strdup(tmpMap->value); 225 231 } 226 232 … … 360 366 dfMaxSegmentLength = atof(tmpMap->value); 361 367 } 362 363 /*tmpMap=NULL; 364 tmpMap=getMapFromMaps(inputs,"segmentize","value"); 365 if(tmpMap!=NULL){ 366 dfMaxSegmentLength = atof(tmpMap->value); 367 }*/ 368 368 369 369 tmpMap=NULL; 370 370 tmpMap=getMapFromMaps(inputs,"InputDSN","value"); … … 825 825 826 826 poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, 827 NULL);827 pszDialect ); 828 828 829 829 if( poResultSet != NULL ) … … 841 841 } 842 842 poDS->ReleaseResultSet( poResultSet ); 843 } 844 } 843 }else{ 844 setMapInMaps(conf,"lenv","message","There was an error when running yoru SQL query."); 845 if(pszDialect!=NULL) 846 free(pszDialect); 847 return SERVICE_FAILED; 848 } 849 } 850 if(pszDialect!=NULL) 851 free(pszDialect); 845 852 846 853 /* -------------------------------------------------------------------- */ … … 901 908 902 909 #ifdef ZOO_SERVICE 903 outputs->content=createMap("value",(char*)pszwebDestData); 910 setMapInMaps(outputs,"OutputedDataSourceName","value",(char*)pszwebDestData); 911 //outputs->content=createMap("value",(char*)pszwebDestData); 904 912 #endif 905 913 … … 930 938 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 931 939 932 OGRCleanupAll();940 //OGRCleanupAll(); 933 941 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 934 942 … … 939 947 940 948 #ifdef ZOO_SERVICE 949 //sleep(10); 941 950 return SERVICE_SUCCEEDED; 942 951 #else -
TabularUnified trunk/zoo-project/zoo-services/utils/registry/Makefile ¶ ¶
r779 r917 1 1 ZRPATH=../../.. 2 2 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts 3 CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG3 ZCFLAGS=-I${ZRPATH}/zoo-kernel/ ${CFLAGS} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG 4 4 5 5 YAML_FILES="" … … 16 16 17 17 cgi-env/wps_registry.zo: service.c 18 g++ ${ CFLAGS} -shared -fpic -o cgi-env/wps_registry.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} -lfcgi -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/server_internal.o ${ZRPATH}/zoo-kernel/lex.cr.o ${ZRPATH}/zoo-kernel/lex.sr.o ${ZRPATH}/zoo-kernel/service_conf.tab.o ${ZRPATH}/zoo-kernel/main_conf_read.tab.o ${ZRPATH}/zoo-kernel/response_print.o ${YAML_FILES} ${MS_FILES} ${MS_LDFLAGS} ${YAML_LDFLAGS}18 g++ ${ZCFLAGS} -shared -fpic -o cgi-env/wps_registry.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} -lfcgi -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/server_internal.o ${ZRPATH}/zoo-kernel/lex.cr.o ${ZRPATH}/zoo-kernel/lex.sr.o ${ZRPATH}/zoo-kernel/service_conf.tab.o ${ZRPATH}/zoo-kernel/main_conf_read.tab.o ${ZRPATH}/zoo-kernel/response_print.o ${YAML_FILES} ${MS_FILES} ${MS_LDFLAGS} ${YAML_LDFLAGS} 19 19 20 20 install: -
TabularUnified trunk/zoo-project/zoo-services/utils/registry/service.c ¶ ¶
r778 r917 80 80 root_nodes[1][1],"2.0.0",1); 81 81 setMapInMaps(conf,"main","rversion","2.0.0"); 82 printDescribeProcessForProcess(zooRegistry,conf, n,inherited);82 printDescribeProcessForProcess(zooRegistry,conf,doc,n,inherited); 83 83 setMapInMaps(conf,"main","rversion","1.0.0"); 84 84 -
TabularUnified trunk/zoo-project/zoo-services/utils/status/Makefile ¶ ¶
r811 r917 1 1 ZRPATH=../../.. 2 2 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts 3 CFLAGS =-I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG3 CFLAGS1=${CFLAGS} -I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG 4 4 5 5 cgi-env/wps_status.zo: service.c 6 g++ ${CFLAGS } -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service6 g++ ${CFLAGS1} -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service 7 7 8 8 install: -
TabularUnified trunk/zoo-project/zoo-services/utils/status/service.c ¶ ¶
r788 r917 72 72 return SERVICE_FAILED; 73 73 } 74 map* tmpMap1=getMapFromMaps(conf,"lenv","semaphore"); 75 if(tmpMap1!=NULL && strcasecmp(tmpMap1->value,"Created")==0) 76 removeShmLock(conf,1); 74 77 sprintf(xslFileName,"%s/updateStatus.xsl",tmpMmap->value); 75 78 xmlSubstituteEntitiesDefault(1); … … 85 88 */ 86 89 char *tmpStr=_getStatus(conf,tmpMap->value); 87 #ifdef DEBUG90 //#ifdef DEBUG 88 91 fprintf(stderr,"DEBUG: %s \n",tmpStr); 89 #endif92 //#endif 90 93 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 91 94 char *tmpStr1=strdup(tmpStr); … … 140 143 char message[10]; 141 144 sprintf(message,"Step %d",i); 145 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 146 fflush(stderr); 142 147 updateStatus(conf,i,message); 143 148 #ifndef WIN32
Note: See TracChangeset
for help on using the changeset viewer.